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