Bug#898257 abstract out disk image access methods

Rather than providing two mutually exlusive image
access methods (loop and qemu-nbd), try each in turn.
This is to prepare for a follow up patch which will
add libguestfs as a method to try.

* nova/virt/mount.py: A new Mount class to abstract the
devce allocation, partition mapping and file sys mounting,
for each access type.
* nova/virt/disk/loop.py: A specialization of the base Mount class
to provide loop back mounting support.
* nova/virt/disk/nbd.py: A specialization of the base Mount class
to provide qemu-nbd mounting support.
* nova/virt/disk/api.py: A new file containing the nova.virt.disk
module interface.
(img_handlers): A new list of access methods to try,
with the order being honored.
(_DiskImage): An internal helper class that uses the plugin classes
above, to provide the operations available on a disk image file.
When mounting, iterate over each access method until one succeeds.
If a hint is provided about a CoW format image, the list of
methods to try will be reduced accordingly.
Note expected errors are no longer raised as exceptions during mounting.
Instead, on failure to mount an image, errors are collated and raised.
Interveining errors are logged in debug mode for successful mounts.
* nova/virt/libvirt/connection.py: Adjust the function parameter
names to be more general, rather than referencing specific
implementations like 'nbd' and 'tune2fs'.
Simplify the destroy_container() by storing and passing
back a reference to the _DiskImage object, which has the
necessary state to unmount.
* nova/utils.py (trycmd): A helper function to both deal with,
commands that issue ignorable warnings to stderr,
and commands that EXIT_SUCCESS while issuing errors to stderr.
nova/virt/xenapi/vm_utils.py: Adjust for the moved virt.disk package

Change-Id: If3a4b1c8f4e2f2e7300a21071340dcc839cb36d7
This commit is contained in:
Pádraig Brady
2011-11-30 17:00:17 +00:00
committed by Pádraig Brady
parent f52322589d
commit 2035bc1dab
3 changed files with 20 additions and 22 deletions

View File

@@ -112,6 +112,7 @@ Naveed Massjouni <naveedm9@gmail.com>
Nikolay Sokolov <nsokolov@griddynamics.com>
Nirmal Ranganathan <nirmal.ranganathan@rackspace.com>
Ollie Leahy <oliver.leahy@hp.com>
Pádraig Brady <pbrady@redhat.com>
Paul Voccio <paul@openstack.org>
Renuka Apte <renuka.apte@citrix.com>
Ricardo Carrillo Cruz <emaildericky@gmail.com>

View File

@@ -19,53 +19,50 @@
from nova.rootwrap.filters import CommandFilter, DnsmasqFilter
filters = [
# nova/virt/disk.py: 'kpartx', '-a', device
# nova/virt/disk.py: 'kpartx', '-d', device
# nova/virt/disk/mount.py: 'kpartx', '-a', device
# nova/virt/disk/mount.py: 'kpartx', '-d', device
CommandFilter("/sbin/kpartx", "root"),
# nova/virt/disk.py: 'tune2fs', '-c', 0, '-i', 0, mapped_device
# nova/virt/disk/mount.py: 'tune2fs', '-c', 0, '-i', 0, mapped_device
# nova/virt/xenapi/vm_utils.py: "tune2fs", "-O ^has_journal", part_path
# nova/virt/xenapi/vm_utils.py: "tune2fs", "-j", partition_path
CommandFilter("/sbin/tune2fs", "root"),
# nova/virt/disk.py: 'mount', mapped_device, tmpdir
# nova/virt/disk.py: 'mount', device, container_dir
# nova/virt/disk.py: 'mount'
# nova/virt/disk/mount.py: 'mount', mapped_device, mount_dir
# nova/virt/xenapi/vm_utils.py: 'mount', '-t', 'ext2,ext3,ext4,reiserfs'..
CommandFilter("/bin/mount", "root"),
# nova/virt/disk.py: 'umount', mapped_device
# nova/virt/disk.py: 'umount', container_dir
# nova/virt/disk/mount.py: 'umount', mapped_device
# nova/virt/xenapi/vm_utils.py: 'umount', dev_path
CommandFilter("/bin/umount", "root"),
# nova/virt/disk.py: 'qemu-nbd', '-c', device, image
# nova/virt/disk.py: 'qemu-nbd', '-d', device
# nova/virt/disk/nbd.py: 'qemu-nbd', '-c', device, image
# nova/virt/disk/nbd.py: 'qemu-nbd', '-d', device
CommandFilter("/usr/bin/qemu-nbd", "root"),
# nova/virt/disk.py: 'losetup', '--find', '--show', image
# nova/virt/disk.py: 'losetup', '--detach', device
# nova/virt/disk/loop.py: 'losetup', '--find', '--show', image
# nova/virt/disk/loop.py: 'losetup', '--detach', device
CommandFilter("/sbin/losetup", "root"),
# nova/virt/disk.py: 'tee', metadata_path
# nova/virt/disk.py: 'tee', '-a', keyfile
# nova/virt/disk.py: 'tee', netfile
# nova/virt/disk/api.py: 'tee', metadata_path
# nova/virt/disk/api.py: 'tee', '-a', keyfile
# nova/virt/disk/api.py: 'tee', netfile
CommandFilter("/usr/bin/tee", "root"),
# nova/virt/disk.py: 'mkdir', '-p', sshdir
# nova/virt/disk.py: 'mkdir', '-p', netdir
# nova/virt/disk/api.py: 'mkdir', '-p', sshdir
# nova/virt/disk/api.py: 'mkdir', '-p', netdir
CommandFilter("/bin/mkdir", "root"),
# nova/virt/disk.py: 'chown', 'root', sshdir
# nova/virt/disk.py: 'chown', 'root:root', netdir
# nova/virt/disk/api.py: 'chown', 'root', sshdir
# nova/virt/disk/api.py: 'chown', 'root:root', netdir
# nova/virt/libvirt/connection.py: 'chown', os.getuid(), console_log
# nova/virt/libvirt/connection.py: 'chown', os.getuid(), console_log
# nova/virt/libvirt/connection.py: 'chown', 'root', basepath('disk')
# nova/virt/xenapi/vm_utils.py: 'chown', os.getuid(), dev_path
CommandFilter("/bin/chown", "root"),
# nova/virt/disk.py: 'chmod', '700', sshdir
# nova/virt/disk.py: 'chmod', 755, netdir
# nova/virt/disk/api.py: 'chmod', '700', sshdir
# nova/virt/disk/api.py: 'chmod', 755, netdir
CommandFilter("/bin/chmod", "root"),
# nova/virt/libvirt/vif.py: 'ip', 'tuntap', 'add', dev, 'mode', 'tap'

View File

@@ -36,7 +36,7 @@ from nova import utils
from nova.api.ec2 import cloud
from nova.compute import power_state
from nova.compute import vm_states
from nova.virt import disk
from nova.virt.disk import api as disk
from nova.virt import images
from nova.virt import driver
from nova.virt.libvirt import connection