diff --git a/nova/virt/disk/api.py b/nova/virt/disk/api.py index 304781a64974..d4f8b6cc06bc 100644 --- a/nova/virt/disk/api.py +++ b/nova/virt/disk/api.py @@ -258,10 +258,16 @@ class _DiskImage(object): return bool(self._mounter) def umount(self): - """Unmount a disk image from the file system.""" + """Umount a mount point from the filesystem.""" + if self._mounter: + self._mounter.do_umount() + self._mounter = None + + def teardown(self): + """Remove a disk image from the file system.""" try: if self._mounter: - self._mounter.do_umount() + self._mounter.do_teardown() self._mounter = None finally: if self._mkdir: @@ -334,11 +340,24 @@ def teardown_container(container_dir): It will umount the container that is mounted, and delete any linked devices. """ + try: + img = _DiskImage(image=None, mount_dir=container_dir) + img.teardown() + except Exception, exn: + LOG.exception(_('Failed to teardown ntainer filesystem: %s'), exn) + + +def clean_lxc_namespace(container_dir): + """Clean up the container namespace rootfs mounting one spawned. + + It will umount the mounted names that is mounted + but leave the linked deivces alone. + """ try: img = _DiskImage(image=None, mount_dir=container_dir) img.umount() except Exception, exn: - LOG.exception(_('Failed to unmount container filesystem: %s'), exn) + LOG.exception(_('Failed to umount container filesystem: %s'), exn) def inject_data_into_fs(fs, key, net, metadata, admin_password, files, diff --git a/nova/virt/disk/mount/api.py b/nova/virt/disk/mount/api.py index 4de9d9c77e36..1d9d1fc20823 100644 --- a/nova/virt/disk/mount/api.py +++ b/nova/virt/disk/mount/api.py @@ -218,6 +218,11 @@ class Mount(object): """Call the unmnt, unmap and unget operations.""" if self.mounted: self.unmnt_dev() + + def do_teardown(self): + """Call the umnt, unmap, and unget operations.""" + if self.mounted: + self.unmnt_dev() if self.mapped: self.unmap_dev() if self.linked: diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index bd2f51e696d8..ff06a53b551d 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -2052,8 +2052,12 @@ class LibvirtDriver(driver.ComputeDriver): # namespace and so there is no need to keep the container rootfs # mounted in the host namespace if CONF.libvirt_type == 'lxc': + state = self.get_info(instance)['state'] container_dir = os.path.join(inst_path, 'rootfs') - disk.teardown_container(container_dir=container_dir) + if state == power_state.RUNNING: + disk.clean_lxc_namespace(container_dir=container_dir) + else: + disk.teardown_container(container_dir=container_dir) return domain