Gentoo Archives: gentoo-catalyst

From: Brian Dolbec <dolsen@g.o>
To: gentoo-catalyst@l.g.o
Cc: Brian Dolbec <dolsen@g.o>
Subject: [gentoo-catalyst] [PATCH] modules/generic_stage_target.py, modules/stage1_target.py: Add a target_mounts dictionary
Date: Wed, 18 Dec 2013 01:01:30
Message-Id: 1387328464-25678-2-git-send-email-dolsen@gentoo.org
In Reply to: [gentoo-catalyst] Mounts and Mountmap completions, fixes. by Brian Dolbec
1 Cleanup 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
4 ---
5 modules/generic_stage_target.py | 97 +++++++++++++++++++++++++----------------
6 modules/stage1_target.py | 5 ++-
7 2 files changed, 62 insertions(+), 40 deletions(-)
8
9 diff --git a/modules/generic_stage_target.py b/modules/generic_stage_target.py
10 index d7cffa9..d9cc499 100644
11 --- a/modules/generic_stage_target.py
12 +++ b/modules/generic_stage_target.py
13 @@ -4,6 +4,21 @@ from generic_target import *
14 from stat import *
15 import catalyst_lock
16
17 +target_mounts = {
18 + "proc": "/proc",
19 + "dev": "/dev",
20 + "devpts": "/dev/pts",
21 + "portdir": "/usr/portage",
22 + "distdir": "/usr/portage/distfiles",
23 + "packagedir": "/usr/portage/packages",
24 + "port_tmpdir": "/var/tmp/portage",
25 + "kerncache": "/tmp/kerncache",
26 + "ccache": "/var/tmp/ccache",
27 + "icecream": "/var/cache/icecream",
28 + "port_logdir": "/var/log/portage",
29 + }
30 +
31 +
32 class generic_stage_target(generic_target):
33 """
34 This class does all of the chroot setup, copying of files, etc. It is
35 @@ -173,11 +188,12 @@ class generic_stage_target(generic_target):
36 file_locate(self.settings,["portage_confdir"],expand=0)
37
38 """ Setup our mount points """
39 + self.target_mounts = target_mounts.copy()
40 if "SNAPCACHE" in self.settings:
41 self.mounts=["proc", "dev", "portdir", "distdir", "port_tmpdir"]
42 self.mountmap={"proc":"/proc", "dev":"/dev", "devpts":"/dev/pts",
43 - "portdir":self.settings["snapshot_cache_path"]+"/portage",\
44 - "distdir":self.settings["distdir"],"port_tmpdir":"tmpfs"}
45 + "portdir":normpath(self.settings["snapshot_cache_path"]+"/" + self.settings["repo_name"]),
46 + "distdir":self.settings["distdir"],"port_tmpdir":"tmpfs"}
47 else:
48 self.mounts = ["proc", "dev", "distdir", "port_tmpdir"]
49 self.mountmap = {"proc":"/proc", "dev":"/dev", "devpts":"/dev/pts",
50 @@ -218,17 +234,17 @@ class generic_stage_target(generic_target):
51 self.mounts.append("ccache")
52 self.mountmap["ccache"] = ccdir
53 """ for the chroot: """
54 - self.env["CCACHE_DIR"]="/var/tmp/ccache"
55 + self.env["CCACHE_DIR"] = self.target_mounts["ccache"]
56
57 if "ICECREAM" in self.settings:
58 - self.mounts.append("/var/cache/icecream")
59 - self.mountmap["/var/cache/icecream"]="/var/cache/icecream"
60 + self.mounts.append("icecream")
61 + self.mountmap["icecream"] = self.target_mounts["icecream"]
62 self.env["PATH"]="/usr/lib/icecc/bin:"+self.env["PATH"]
63
64 if "port_logdir" in self.settings:
65 - self.mounts.append("/var/log/portage")
66 - self.mountmap["/var/log/portage"]=self.settings["port_logdir"]
67 - self.env["PORT_LOGDIR"]="/var/log/portage"
68 + self.mounts.append("port_logdir")
69 + self.mountmap["port_logdir"]=self.settings["port_logdir"]
70 + self.env["PORT_LOGDIR"]=self.settings["port_logdir"]
71 self.env["PORT_LOGDIR_CLEAN"]='find "${PORT_LOGDIR}" -type f ! -name "summary.log*" -mtime +30 -delete'
72
73 def override_cbuild(self):
74 @@ -602,33 +618,34 @@ class generic_stage_target(generic_target):
75 "kill-chroot-pids script failed.",env=self.env)
76
77 def mount_safety_check(self):
78 - mypath=self.settings["chroot_path"]
79 -
80 """
81 Check and verify that none of our paths in mypath are mounted. We don't
82 want to clean up with things still mounted, and this allows us to check.
83 Returns 1 on ok, 0 on "something is still mounted" case.
84 """
85
86 - if not os.path.exists(mypath):
87 + if not os.path.exists(self.settings["chroot_path"]):
88 return
89
90 + print "self.mounts =", self.mounts
91 for x in self.mounts:
92 - if not os.path.exists(mypath + self.mountmap[x]):
93 + target = normpath(self.settings["chroot_path"] + self.target_mounts[x])
94 + print "mount_safety_check() x =", x, target
95 + if not os.path.exists(target):
96 continue
97
98 - if ismount(mypath + self.mountmap[x]):
99 + if ismount(target):
100 """ Something is still mounted "" """
101 try:
102 - print self.mountmap[x] + " is still mounted; performing auto-bind-umount...",
103 + print target + " is still mounted; performing auto-bind-umount...",
104 """ Try to umount stuff ourselves """
105 self.unbind()
106 - if ismount(mypath + self.mountmap[x]):
107 - raise CatalystError, "Auto-unbind failed for " + self.mountmap[x]
108 + if ismount(target):
109 + raise CatalystError, "Auto-unbind failed for " + target
110 else:
111 print "Auto-unbind successful..."
112 except CatalystError:
113 - raise CatalystError, "Unable to auto-unbind " + self.mountmap[x]
114 + raise CatalystError, "Unable to auto-unbind " + target
115
116 def unpack(self):
117 unpack=True
118 @@ -896,32 +913,37 @@ class generic_stage_target(generic_target):
119
120 def bind(self):
121 for x in self.mounts:
122 - if not os.path.exists(self.settings["chroot_path"] + self.mountmap[x]):
123 - os.makedirs(self.settings["chroot_path"]+x,0755)
124 + #print "bind(); x =", x
125 + target = normpath(self.settings["chroot_path"] + self.target_mounts[x])
126 + if not os.path.exists(target):
127 + os.makedirs(target, 0755)
128
129 if not os.path.exists(self.mountmap[x]):
130 if not self.mountmap[x] == "tmpfs":
131 - os.makedirs(self.mountmap[x],0755)
132 + os.makedirs(self.mountmap[x], 0755)
133
134 src=self.mountmap[x]
135 - if "SNAPCACHE" in self.settings and x == "/usr/portage":
136 + #print "bind(); src =", src
137 + if "SNAPCACHE" in self.settings and x == self.settings["portdir"]:
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 @@ -933,26 +955,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 diff --git a/modules/stage1_target.py b/modules/stage1_target.py
204 index aa43926..1e0d874 100644
205 --- a/modules/stage1_target.py
206 +++ b/modules/stage1_target.py
207 @@ -88,8 +88,9 @@ class stage1_target(generic_stage_target):
208 os.makedirs(self.settings["stage_path"]+"/proc")
209
210 # alter the mount mappings to bind mount proc onto it
211 - self.mounts.append("/tmp/stage1root/proc")
212 - self.mountmap["/tmp/stage1root/proc"]="/proc"
213 + self.mounts.append("stage1root/proc")
214 + self.target_mounts["stage1root/proc"] = "/tmp/stage1root/proc"
215 + self.mountmap["stage1root/proc"]="/proc"
216
217 def register(foo):
218 foo.update({"stage1":stage1_target})
219 --
220 1.8.3.2