~mvo/update-manager/aufs

« back to all changes in this revision

Viewing changes to DistUpgrade/DistUpgradeController.py

  • Committer: Michael Vogt
  • Date: 2009-01-07 15:44:37 UTC
  • Revision ID: michael.vogt@ubuntu.com-20090107154437-wnd205g2nc4t0gyx
DistUpgrade/DistUpgradeController.py: ensure that varrun and varlock keep working when the aufs overlay is done

Show diffs side-by-side

added added

removed removed

Lines of Context:
299
299
                return False
300
300
        return True
301
301
 
302
 
    # FIXME: this is currently run *after* /var/log/dist-upgrade/main.log
303
 
    #        is opened and its not in the aufs file    
 
302
    def _bindMount(self, from_dir, to_dir):
 
303
        " helper that bind mounts a given dir to a new place "
 
304
        if not os.path.exists(to_dir):
 
305
            os.makedirs(to_dir)
 
306
        cmd = ["mount","--bind", from_dir, to_dir]
 
307
        res = subprocess.call(cmd)
 
308
        if res != 0:
 
309
            # FIXME: revert already mounted stuff
 
310
            logging.error("Failed to bind mount from '%s' to '%s'" % (from_dir, to_dir))
 
311
            return False
 
312
        return True
 
313
 
 
314
    def _aufsOverlayMount(self, target, rwdir):
 
315
        """ 
 
316
        helper that takes a target dir and mounts a rw dir over it, e.g.
 
317
        /var , /tmp/upgrade-rw
 
318
        """
 
319
        if not os.path.exists(rw_dir+target):
 
320
            os.makedirs(rw_dir+target)
 
321
        cmd = ["mount",
 
322
               "-t","aufs",
 
323
               "-o","br:%s:%s=ro" % (rw_dir+target, target),
 
324
               "none",
 
325
               d,]
 
326
        res = subprocess.call(cmd)
 
327
        if res != 0:
 
328
            # FIXME: revert already mounted stuff
 
329
            logging.error("Failed to mount rw aufs overlay for '%s'" % target)
 
330
            return False
 
331
        return True
 
332
 
304
333
    def setupAufs(self):
305
334
        " setup aufs overlay "
 
335
        # FIXME: this is currently run *after* /var/log/dist-upgrade/main.log
 
336
        #        is opened and its not in the aufs file    
306
337
        logging.debug("setupAufs")
 
338
        rw_dir = self.aufs_rw_dir
 
339
        # aufs mounts do not support stacked filesystems, so
 
340
        # if we mount /var we will loose the tmpfs stuff
 
341
        # first bind mount varun and varlock into the tmpfs
 
342
        tmpfses = ["/var/run","/var/lock"]
 
343
        for d in tmpfses:
 
344
            if not self._bindMount(d, rw_dir+"/tmpfs/"+d):
 
345
                return False
307
346
        # setup writable overlay into /tmp/upgrade-rw so that all 
308
347
        # changes are written there instead of the real fs
309
 
        rw_dir = self.aufs_rw_dir
310
348
        for d in ["/bin","/boot","/etc","/lib","/sbin","/usr","/var"]:
311
 
            if not os.path.exists(rw_dir+d):
312
 
                os.makedirs(rw_dir+d)
313
 
            cmd = ["mount",
314
 
                   "-t","aufs",
315
 
                   "-o","br:%s:%s=ro" % (rw_dir+d, d),
316
 
                   "none",
317
 
                   d,]
318
 
            res = subprocess.call(cmd)
319
 
            if res != 0:
320
 
                # FIXME: revert already mounted stuff
321
 
                logging.error("Failed to mount %s with aufs" % d)
 
349
            if not self._aufsOverlayMount(d, rw_dir):
 
350
                return False
 
351
        # now bind back the tempfs to the original location
 
352
        for d in tmpfses:
 
353
            if not self._bindMount(rw_dir+"/tmpfs/"+d, d):
322
354
                return False
323
355
        # FIXME: now what we *could* do to apply the changes is to
324
356
        #        mount -o bind / /orig