diff options
author | Gui Chen <gui.chen@intel.com> | 2013-05-15 03:08:09 -0400 |
---|---|---|
committer | Gui Chen <gui.chen@intel.com> | 2013-05-15 03:08:09 -0400 |
commit | 8374edede439c61e50625d1da18200d84a4322e5 (patch) | |
tree | 5a50279b1bf3a1ba48791e4735b1edf2e80b6f66 | |
parent | f10c515a82f361a4178a3a33182a664dc9c0b766 (diff) | |
download | mic-8374edede439c61e50625d1da18200d84a4322e5.tar.gz mic-8374edede439c61e50625d1da18200d84a4322e5.tar.bz2 mic-8374edede439c61e50625d1da18200d84a4322e5.zip |
fix symlink bind mount left issue
when bind mount point is symbolic link,
the umount will make it left when clean up
Signed-off-by: Gui Chen <gui.chen@intel.com>
-rw-r--r-- | mic/utils/fs_related.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/mic/utils/fs_related.py b/mic/utils/fs_related.py index b3ca7ec..e4e5c50 100644 --- a/mic/utils/fs_related.py +++ b/mic/utils/fs_related.py @@ -107,13 +107,16 @@ def my_fuser(fp): class BindChrootMount: """Represents a bind mount of a directory into a chroot.""" def __init__(self, src, chroot, dest = None, option = None): - self.src = src self.root = os.path.abspath(os.path.expanduser(chroot)) self.option = option + self.origsrc = self.src = src + if os.path.islink(src): + self.src = os.readlink(src) + if not dest: - dest = src - self.dest = self.root + "/" + dest + dest = self.src + self.dest = os.path.join(self.root, dest.lstrip('/')) self.mounted = False self.mountcmd = find_binary_path("mount") @@ -144,7 +147,13 @@ class BindChrootMount: rc = runner.show([self.mountcmd, "--bind", "-o", "remount,%s" % self.option, self.dest]) if rc != 0: raise MountError("Bind-remounting '%s' failed" % self.dest) + self.mounted = True + if os.path.islink(self.orig_src): + dest = os.path.join(self.root, self.orig_src.lstrip('/')) + if os.path.exists(dest): + os.unlink(dest) + os.symlink(self.src, dest) def unmount(self): if self.has_chroot_instance(): |