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

Replies