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

Replies