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