1 |
Cleans up all self.mounts, self.mountmap usage. |
2 |
Replace multiple path additions with one instance at the beginning of the function, reuse the result multiple times. |
3 |
Add some extra debug prints (to be converted to logging later) |
4 |
--- |
5 |
modules/generic_stage_target.py | 94 ++++++++++++++++++++++++++--------------- |
6 |
modules/stage1_target.py | 5 ++- |
7 |
2 files changed, 63 insertions(+), 36 deletions(-) |
8 |
|
9 |
diff --git a/modules/generic_stage_target.py b/modules/generic_stage_target.py |
10 |
index ce28ab8..c8d31e1 100644 |
11 |
--- a/modules/generic_stage_target.py |
12 |
+++ b/modules/generic_stage_target.py |
13 |
@@ -4,6 +4,23 @@ from generic_target import * |
14 |
from stat import * |
15 |
import catalyst_lock |
16 |
|
17 |
+# temporary location. It will be moved to a |
18 |
+# new defaults file in a later comit |
19 |
+TARGET_MOUNTS_DEFAULTS = { |
20 |
+ "proc": "/proc", |
21 |
+ "dev": "/dev", |
22 |
+ "devpts": "/dev/pts", |
23 |
+ "portdir": "/usr/portage", |
24 |
+ "distdir": "/usr/portage/distfiles", |
25 |
+ "packagedir": "/usr/portage/packages", |
26 |
+ "port_tmpdir": "/var/tmp/portage", |
27 |
+ "kerncache": "/tmp/kerncache", |
28 |
+ "ccache": "/var/tmp/ccache", |
29 |
+ "icecream": "/usr/lib/icecc/bin", |
30 |
+ "port_logdir": "/var/log/portage", |
31 |
+ } |
32 |
+ |
33 |
+ |
34 |
class generic_stage_target(generic_target): |
35 |
""" |
36 |
This class does all of the chroot setup, copying of files, etc. It is |
37 |
@@ -173,6 +190,10 @@ class generic_stage_target(generic_target): |
38 |
file_locate(self.settings,["portage_confdir"],expand=0) |
39 |
|
40 |
""" Setup our mount points """ |
41 |
+ # initialize our target mounts. |
42 |
+ # later I plan to make these configurable so the |
43 |
+ # defaults can be easily overridden if desired. |
44 |
+ self.target_mounts = TARGET_MOUNTS_DEFAULTS.copy() |
45 |
if "SNAPCACHE" in self.settings: |
46 |
self.mounts=["proc", "dev", "portdir", "distdir", "port_tmpdir"] |
47 |
self.mountmap={"proc":"/proc", "dev":"/dev", "devpts":"/dev/pts", |
48 |
@@ -219,17 +240,18 @@ class generic_stage_target(generic_target): |
49 |
self.mounts.append("ccache") |
50 |
self.mountmap["ccache"] = ccdir |
51 |
""" for the chroot: """ |
52 |
- self.env["CCACHE_DIR"]="/var/tmp/ccache" |
53 |
+ self.env["CCACHE_DIR"] = self.target_mounts["ccache"] |
54 |
|
55 |
if "ICECREAM" in self.settings: |
56 |
self.mounts.append("/var/cache/icecream") |
57 |
self.mountmap["/var/cache/icecream"]="/var/cache/icecream" |
58 |
- self.env["PATH"]="/usr/lib/icecc/bin:"+self.env["PATH"] |
59 |
+ self.env["PATH"] = self.target_mounts["icecream"] + ":" + \ |
60 |
+ self.env["PATH"] |
61 |
|
62 |
if "port_logdir" in self.settings: |
63 |
- self.mounts.append("/var/log/portage") |
64 |
- self.mountmap["/var/log/portage"]=self.settings["port_logdir"] |
65 |
- self.env["PORT_LOGDIR"]="/var/log/portage" |
66 |
+ self.mounts.append("port_logdir") |
67 |
+ self.mountmap["port_logdir"]=self.settings["port_logdir"] |
68 |
+ self.env["PORT_LOGDIR"]=self.target_mounts["port_logdir"] |
69 |
self.env["PORT_LOGDIR_CLEAN"]='find "${PORT_LOGDIR}" -type f ! -name "summary.log*" -mtime +30 -delete' |
70 |
|
71 |
def override_cbuild(self): |
72 |
@@ -603,33 +625,34 @@ class generic_stage_target(generic_target): |
73 |
"kill-chroot-pids script failed.",env=self.env) |
74 |
|
75 |
def mount_safety_check(self): |
76 |
- mypath=self.settings["chroot_path"] |
77 |
- |
78 |
""" |
79 |
Check and verify that none of our paths in mypath are mounted. We don't |
80 |
want to clean up with things still mounted, and this allows us to check. |
81 |
Returns 1 on ok, 0 on "something is still mounted" case. |
82 |
""" |
83 |
|
84 |
- if not os.path.exists(mypath): |
85 |
+ if not os.path.exists(self.settings["chroot_path"]): |
86 |
return |
87 |
|
88 |
+ print "self.mounts =", self.mounts |
89 |
for x in self.mounts: |
90 |
- if not os.path.exists(mypath + self.mountmap[x]): |
91 |
+ target = normpath(self.settings["chroot_path"] + self.target_mounts[x]) |
92 |
+ print "mount_safety_check() x =", x, target |
93 |
+ if not os.path.exists(target): |
94 |
continue |
95 |
|
96 |
- if ismount(mypath + self.mountmap[x]): |
97 |
+ if ismount(target): |
98 |
""" Something is still mounted "" """ |
99 |
try: |
100 |
- print self.mountmap[x] + " is still mounted; performing auto-bind-umount...", |
101 |
+ print target + " is still mounted; performing auto-bind-umount...", |
102 |
""" Try to umount stuff ourselves """ |
103 |
self.unbind() |
104 |
- if ismount(mypath + self.mountmap[x]): |
105 |
- raise CatalystError, "Auto-unbind failed for " + self.mountmap[x] |
106 |
+ if ismount(target): |
107 |
+ raise CatalystError, "Auto-unbind failed for " + target |
108 |
else: |
109 |
print "Auto-unbind successful..." |
110 |
except CatalystError: |
111 |
- raise CatalystError, "Unable to auto-unbind " + self.mountmap[x] |
112 |
+ raise CatalystError, "Unable to auto-unbind " + target |
113 |
|
114 |
def unpack(self): |
115 |
unpack=True |
116 |
@@ -897,12 +920,14 @@ class generic_stage_target(generic_target): |
117 |
|
118 |
def bind(self): |
119 |
for x in self.mounts: |
120 |
- if not os.path.exists(self.settings["chroot_path"] + self.mountmap[x]): |
121 |
- os.makedirs(self.settings["chroot_path"]+x,0755) |
122 |
+ #print "bind(); x =", x |
123 |
+ target = normpath(self.settings["chroot_path"] + self.target_mounts[x]) |
124 |
+ if not os.path.exists(target): |
125 |
+ os.makedirs(target, 0755) |
126 |
|
127 |
if not os.path.exists(self.mountmap[x]): |
128 |
if not self.mountmap[x] == "tmpfs": |
129 |
- os.makedirs(self.mountmap[x],0755) |
130 |
+ os.makedirs(self.mountmap[x], 0755) |
131 |
|
132 |
src=self.mountmap[x] |
133 |
#print "bind(); src =", src |
134 |
@@ -910,20 +935,22 @@ class generic_stage_target(generic_target): |
135 |
self.snapshot_lock_object.read_lock() |
136 |
if os.uname()[0] == "FreeBSD": |
137 |
if src == "/dev": |
138 |
- retval = os.system("mount -t devfs none " + |
139 |
- self.settings["chroot_path"] + src) |
140 |
+ cmd = "mount -t devfs none " + target |
141 |
+ retval=os.system(cmd) |
142 |
else: |
143 |
- retval = os.system("mount_nullfs " + src + " " + |
144 |
- self.settings["chroot_path"] + src) |
145 |
+ cmd = "mount_nullfs " + src + " " + target |
146 |
+ retval=os.system(cmd) |
147 |
else: |
148 |
if src == "tmpfs": |
149 |
if "var_tmpfs_portage" in self.settings: |
150 |
- retval=os.system("mount -t tmpfs -o size="+\ |
151 |
- self.settings["var_tmpfs_portage"]+"G "+src+" "+\ |
152 |
- self.settings["chroot_path"]+x) |
153 |
+ cmd = "mount -t tmpfs -o size=" + \ |
154 |
+ self.settings["var_tmpfs_portage"] + "G " + \ |
155 |
+ src + " " + target |
156 |
+ retval=os.system(cmd) |
157 |
else: |
158 |
- retval = os.system("mount --bind " + src + " " + |
159 |
- self.settings["chroot_path"] + src) |
160 |
+ cmd = "mount --bind " + src + " " + target |
161 |
+ #print "bind(); cmd =", cmd |
162 |
+ retval=os.system(cmd) |
163 |
if retval!=0: |
164 |
self.unbind() |
165 |
raise CatalystError,"Couldn't bind mount " + src |
166 |
@@ -935,26 +962,25 @@ class generic_stage_target(generic_target): |
167 |
myrevmounts.reverse() |
168 |
""" Unmount in reverse order for nested bind-mounts """ |
169 |
for x in myrevmounts: |
170 |
- if not os.path.exists(mypath + self.mountmap[x]): |
171 |
+ target = normpath(mypath + self.target_mounts[x]) |
172 |
+ if not os.path.exists(target): |
173 |
continue |
174 |
|
175 |
- if not ismount(mypath + self.mountmap[x]): |
176 |
+ if not ismount(target): |
177 |
continue |
178 |
|
179 |
- retval=os.system("umount "+\ |
180 |
- os.path.join(mypath, self.mountmap[x].lstrip(os.path.sep))) |
181 |
+ retval=os.system("umount " + target) |
182 |
|
183 |
if retval!=0: |
184 |
- warn("First attempt to unmount: " + mypath + |
185 |
- self.mountmap[x] +" failed.") |
186 |
+ warn("First attempt to unmount: " + target + " failed.") |
187 |
warn("Killing any pids still running in the chroot") |
188 |
|
189 |
self.kill_chroot_pids() |
190 |
|
191 |
- retval2 = os.system("umount " + mypath + self.mountmap[x]) |
192 |
+ retval2 = os.system("umount " + target) |
193 |
if retval2!=0: |
194 |
ouch=1 |
195 |
- warn("Couldn't umount bind mount: " + mypath + self.mountmap[x]) |
196 |
+ warn("Couldn't umount bind mount: " + target) |
197 |
|
198 |
if "SNAPCACHE" in self.settings and x == "/usr/portage": |
199 |
try: |
200 |
diff --git a/modules/stage1_target.py b/modules/stage1_target.py |
201 |
index aa43926..1e0d874 100644 |
202 |
--- a/modules/stage1_target.py |
203 |
+++ b/modules/stage1_target.py |
204 |
@@ -88,8 +88,9 @@ class stage1_target(generic_stage_target): |
205 |
os.makedirs(self.settings["stage_path"]+"/proc") |
206 |
|
207 |
# alter the mount mappings to bind mount proc onto it |
208 |
- self.mounts.append("/tmp/stage1root/proc") |
209 |
- self.mountmap["/tmp/stage1root/proc"]="/proc" |
210 |
+ self.mounts.append("stage1root/proc") |
211 |
+ self.target_mounts["stage1root/proc"] = "/tmp/stage1root/proc" |
212 |
+ self.mountmap["stage1root/proc"]="/proc" |
213 |
|
214 |
def register(foo): |
215 |
foo.update({"stage1":stage1_target}) |
216 |
-- |
217 |
1.8.3.2 |