Browse Source

Fix for qemu-nbd hang

NBD device once used seem to run into intermittent trouble when
used with mount repeatedly. Adding code to explicitly flush the
device buffers using 'blockdev --flushbufs'.

Closes-Bug: #973413
Partial-Bug: #1254890
Change-Id: I2b7053b9a069d6e82f6f6baf9ad480efa4388d91
tags/2014.1.b2
Davanum Srinivas 6 years ago
parent
commit
dd3f96e915
4 changed files with 18 additions and 0 deletions
  1. +3
    -0
      etc/nova/rootwrap.d/compute.filters
  2. +2
    -0
      nova/tests/virt/test_virt.py
  3. +4
    -0
      nova/virt/disk/mount/api.py
  4. +9
    -0
      nova/virt/disk/mount/nbd.py

+ 3
- 0
etc/nova/rootwrap.d/compute.filters View File

@@ -27,6 +27,9 @@ umount: CommandFilter, umount, root
# nova/virt/disk/mount/nbd.py: 'qemu-nbd', '-d', device
qemu-nbd: CommandFilter, qemu-nbd, root

# nova/virt/disk/mount/nbd.py: 'blockdev', '--flushbufs', device
blockdev: CommandFilter, blockdev, root

# nova/virt/disk/mount/loop.py: 'losetup', '--find', '--show', image
# nova/virt/disk/mount/loop.py: 'losetup', '--detach', device
losetup: CommandFilter, losetup, root

+ 2
- 0
nova/tests/virt/test_virt.py View File

@@ -227,12 +227,14 @@ class TestVirtDisk(test.NoDBTestCase):

disk_api.teardown_container('/mnt/nbd/nopart')
expected_commands += [
('blockdev', '--flushbufs', '/dev/nbd15'),
('umount', '/dev/nbd15'),
('qemu-nbd', '-d', '/dev/nbd15'),
]

disk_api.teardown_container('/mnt/nbd/part')
expected_commands += [
('blockdev', '--flushbufs', '/dev/nbd15'),
('umount', '/dev/mapper/nbd15p1'),
('kpartx', '-d', '/dev/nbd15'),
('qemu-nbd', '-d', '/dev/nbd15'),

+ 4
- 0
nova/virt/disk/mount/api.py View File

@@ -205,10 +205,14 @@ class Mount(object):
"""Unmount the device from the file system."""
if not self.mounted:
return
self.flush_dev()
LOG.debug(_("Umount %s") % self.mapped_device)
utils.execute('umount', self.mapped_device, run_as_root=True)
self.mounted = False

def flush_dev(self):
pass

def do_mount(self):
"""Call the get, map and mnt operations."""
status = False

+ 9
- 0
nova/virt/disk/mount/nbd.py View File

@@ -129,3 +129,12 @@ class NbdMount(api.Mount):
utils.execute('qemu-nbd', '-d', self.device, run_as_root=True)
self.linked = False
self.device = None

def flush_dev(self):
"""flush NBD block device buffer."""
# Perform an explicit BLKFLSBUF to support older qemu-nbd(s).
# Without this flush, when a nbd device gets re-used the
# qemu-nbd intermittently hangs.
if self.device:
utils.execute('blockdev', '--flushbufs',
self.device, run_as_root=True)

Loading…
Cancel
Save