Add debug logging to disk mount modules
To assist in troubleshooting file injection code, add some LOG.debug() statements to the nova/virt/disk/mount/*.py modules blueprint: virt-disk-api-refactoring Change-Id: I75214145ef489a29a58f69abe6195ff01f36153c Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
d20d9cb66e
commit
14d97975af
|
@ -35,22 +35,32 @@ class Mount(object):
|
|||
|
||||
@staticmethod
|
||||
def instance_for_format(imgfile, mountdir, partition, imgfmt):
|
||||
LOG.debug(_("Instance for format imgfile=%(imgfile)s "
|
||||
"mountdir=%(mountdir)s partition=%(partition)s "
|
||||
"imgfmt=%(imgfmt)s") % locals())
|
||||
if imgfmt == "raw":
|
||||
LOG.debug(_("Using LoopMount"))
|
||||
return importutils.import_object(
|
||||
"nova.virt.disk.mount.loop.LoopMount",
|
||||
imgfile, mountdir, partition)
|
||||
else:
|
||||
LOG.debug(_("Using NbdMount"))
|
||||
return importutils.import_object(
|
||||
"nova.virt.disk.mount.nbd.NbdMount",
|
||||
imgfile, mountdir, partition)
|
||||
|
||||
@staticmethod
|
||||
def instance_for_device(imgfile, mountdir, partition, device):
|
||||
LOG.debug(_("Instance for device imgfile=%(imgfile)s "
|
||||
"mountdir=%(mountdir)s partition=%(partition)s "
|
||||
"device=%(device)s") % locals())
|
||||
if "loop" in device:
|
||||
LOG.debug(_("Using LoopMount"))
|
||||
return importutils.import_object(
|
||||
"nova.virt.disk.mount.loop.LoopMount",
|
||||
imgfile, mountdir, partition, device)
|
||||
else:
|
||||
LOG.debug(_("Using NbdMount"))
|
||||
return importutils.import_object(
|
||||
"nova.virt.disk.mount.nbd.NbdMount",
|
||||
imgfile, mountdir, partition, device)
|
||||
|
@ -99,6 +109,7 @@ class Mount(object):
|
|||
def map_dev(self):
|
||||
"""Map partitions of the device to the file system namespace."""
|
||||
assert(os.path.exists(self.device))
|
||||
LOG.debug(_("Map dev %s"), self.device)
|
||||
automapped_path = '/dev/%sp%s' % (os.path.basename(self.device),
|
||||
self.partition)
|
||||
|
||||
|
@ -142,6 +153,7 @@ class Mount(object):
|
|||
"""Remove partitions of the device from the file system namespace."""
|
||||
if not self.mapped:
|
||||
return
|
||||
LOG.debug(_("Unmap dev %s"), self.device)
|
||||
if self.partition and not self.automapped:
|
||||
utils.execute('kpartx', '-d', self.device, run_as_root=True)
|
||||
self.mapped = False
|
||||
|
@ -149,6 +161,8 @@ class Mount(object):
|
|||
|
||||
def mnt_dev(self):
|
||||
"""Mount the device into the file system."""
|
||||
LOG.debug(_("Mount %(dev)s on %(dir)s") %
|
||||
{'dev': self.mapped_device, 'dir': self.mount_dir})
|
||||
_out, err = utils.trycmd('mount', self.mapped_device, self.mount_dir,
|
||||
run_as_root=True)
|
||||
if err:
|
||||
|
@ -162,6 +176,7 @@ class Mount(object):
|
|||
"""Unmount the device from the file system."""
|
||||
if not self.mounted:
|
||||
return
|
||||
LOG.debug(_("Umount %s") % self.mapped_device)
|
||||
utils.execute('umount', self.mapped_device, run_as_root=True)
|
||||
self.mounted = False
|
||||
|
||||
|
@ -172,6 +187,7 @@ class Mount(object):
|
|||
status = self.get_dev() and self.map_dev() and self.mnt_dev()
|
||||
finally:
|
||||
if not status:
|
||||
LOG.debug(_("Fail to mount, tearing back down"))
|
||||
self.do_umount()
|
||||
return status
|
||||
|
||||
|
|
|
@ -15,9 +15,12 @@
|
|||
# under the License.
|
||||
"""Support for mounting images with the loop device"""
|
||||
|
||||
from nova.openstack.common import log as logging
|
||||
from nova import utils
|
||||
from nova.virt.disk.mount import api
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class LoopMount(api.Mount):
|
||||
"""loop back support for raw images."""
|
||||
|
@ -31,11 +34,13 @@ class LoopMount(api.Mount):
|
|||
return False
|
||||
|
||||
self.device = out.strip()
|
||||
LOG.debug(_("Got loop device %s"), self.device)
|
||||
self.linked = True
|
||||
return True
|
||||
|
||||
def unget_dev(self):
|
||||
if not self.linked:
|
||||
return
|
||||
LOG.debug(_("Release loop device %s"), self.device)
|
||||
utils.execute('losetup', '--detach', self.device, run_as_root=True)
|
||||
self.linked = False
|
||||
|
|
|
@ -19,9 +19,11 @@ import os
|
|||
import time
|
||||
|
||||
from nova.openstack.common import cfg
|
||||
from nova.openstack.common import log as logging
|
||||
from nova import utils
|
||||
from nova.virt.disk.mount import api
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
nbd_opts = [
|
||||
cfg.IntOpt('timeout_nbd',
|
||||
|
@ -78,6 +80,8 @@ class NbdMount(api.Mount):
|
|||
device = self._allocate_nbd()
|
||||
if not device:
|
||||
return False
|
||||
LOG.debug(_("Get nbd device %(dev)s for %(imgfile)s") %
|
||||
{'dev': device, 'imgfile': self.image})
|
||||
_out, err = utils.trycmd('qemu-nbd', '-c', device, self.image,
|
||||
run_as_root=True)
|
||||
if err:
|
||||
|
@ -103,6 +107,7 @@ class NbdMount(api.Mount):
|
|||
def unget_dev(self):
|
||||
if not self.linked:
|
||||
return
|
||||
LOG.debug(_("Release nbd device %s"), self.device)
|
||||
utils.execute('qemu-nbd', '-d', self.device, run_as_root=True)
|
||||
self._free_nbd(self.device)
|
||||
self.linked = False
|
||||
|
|
Loading…
Reference in New Issue