lxc: Clean up namespace mounts
5f697f64e5
introduced a regression
when using lxc containers with qcow2 and qemu-nbd.
When removing the rootfs from the host namespace, it would
terminate the qemu-nbd process as well. This would cause
the kernel too oops under Ubuntu 13.04. Since the underlying
device thtat the libvirt_lxc process disapears.
To get around this we just clean up the host namespace if the
instance is powered-on. When the instance terminates it will
teardown the whole container.
This fixes LP: #1115786
Change-Id: I98bec2338cb455dbd277295ab36767149e05634c
Signed-off-by: Chuck Short <chuck.short@canonical.com>
This commit is contained in:
parent
139d15a405
commit
00f6651369
|
@ -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,
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue