~raharper/curtin/trunk.vmtest_add_huge_disk_tests

« back to all changes in this revision

Viewing changes to curtin/util.py

  • Committer: Scott Moser
  • Date: 2017-04-12 01:38:04 UTC
  • mfrom: (483.2.1 trunk.umount_r)
  • Revision ID: smoser@ubuntu.com-20170412013804-5oarnqx8wnu1qq49
add recursive flag to do_umount, add --umount to block-meta

This adds a 'recursive' argument to util.do_umount, and utilizes
it from install.py. The basic idea of do_umount with recursive
is to walk through /proc/mounts in reverse and unmount anything
mounted under the provided mountpoint (or the mountpoint itself).

Also added here is use of that function from block-meta command.
We add a flag --umount to unmount filesystems at its end.


Show diffs side-by-side

added added

removed removed

Lines of Context:
330
330
    return True
331
331
 
332
332
 
333
 
def do_umount(mountpoint):
334
 
    if not is_mounted(mountpoint):
335
 
        return False
336
 
    subp(['umount', mountpoint])
337
 
    return True
 
333
def do_umount(mountpoint, recursive=False):
 
334
    # unmount mountpoint. if recursive, unmount all mounts under it.
 
335
    # return boolean indicating if mountpoint was previously mounted.
 
336
    mp = os.path.abspath(mountpoint)
 
337
    ret = False
 
338
    for line in reversed(load_file("/proc/mounts", decode=True).splitlines()):
 
339
        curmp = line.split()[1]
 
340
        if curmp == mp or (recursive and curmp.startswith(mp + os.path.sep)):
 
341
            subp(['umount', curmp])
 
342
        if curmp == mp:
 
343
            ret = True
 
344
    return ret
338
345
 
339
346
 
340
347
def ensure_dir(path, mode=None):