[LVM] Run filesystem check before assigning UUID

We assign a random UUID with tune2fs to snapshots
and shares created from snapshots so that they
don't conflict with the parent shares/snapshots
when both of them are being mounted.

tune2fs requires that a filesystem check be
performed "recently" before UUID assignments.
So, perform a filesystem check right away to
allow tune2fs to assign a random UUID.

Change-Id: I858a318f7a83e033cc3f2699859e38b6b74c8d24
Related-Bug: #1645751
Closes-Bug: #1798219
This commit is contained in:
Goutham Pacha Ravi 2018-10-16 16:48:58 -07:00
parent 33d9101131
commit 817cce347a
6 changed files with 35 additions and 7 deletions

View File

@ -174,7 +174,9 @@ docker: CommandFilter, docker, root
# manila/share/drivers/container/container.py: brctl <whatever>
brctl: CommandFilter, brctl, root
# manila/share/drivers/container/container.py: e2fsck <whatever>
# manila/share/drivers/container/storage_helper.py: e2fsck <whatever>
# manila/share/drivers/generic.py: e2fsck <whatever>
# manila/share/drivers/lvm.py: e2fsck <whatever>
e2fsck: CommandFilter, e2fsck, root
# manila/share/drivers/lvm.py: lvconvert --merge %s

View File

@ -355,6 +355,9 @@ class GenericShareDriver(driver.ExecuteMixin, driver.ShareDriver):
# 'tune2fs' command can be executed only when device
# is not mounted and also, in current case, it takes
# effect only after it was mounted. Closes #1645751
# NOTE(gouthamr): Executing tune2fs -U only works on
# a recently checked filesystem. See debian bug 857336
'&&', 'sudo', 'e2fsck', '-y', '-f', device_path,
'&&', 'sudo', 'tune2fs', '-U', 'random', device_path,
'&&', 'sudo', 'mount', device_path, mount_path,
)

View File

@ -131,9 +131,21 @@ class LVMMixin(driver.ExecuteMixin):
'lvcreate', '-L', '%sG' % snapshot['share']['size'],
'--name', snapshot['name'],
'--snapshot', orig_lv_name, run_as_root=True)
snapshot_device_name = self._get_local_path(snapshot)
self._set_random_uuid_to_device(snapshot)
def _set_random_uuid_to_device(self, share_or_snapshot):
# NOTE(vponomaryov): 'tune2fs' is required to make
# filesystem of share created from snapshot have
# unique ID, in case of LVM volumes, by default,
# it will have the same UUID as source volume. Closes #1645751
# NOTE(gouthamr): Executing tune2fs -U only works on
# a recently checked filesystem.
# See: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=857336
device_path = self._get_local_path(share_or_snapshot)
self._execute('e2fsck', '-y', '-f', device_path, run_as_root=True)
self._execute(
'tune2fs', '-U', 'random', snapshot_device_name, run_as_root=True,
'tune2fs', '-U', 'random', device_path, run_as_root=True,
)
def create_snapshot(self, context, snapshot, share_server=None):
@ -248,9 +260,7 @@ class LVMShareDriver(LVMMixin, driver.ShareDriver):
self._allocate_container(share)
snapshot_device_name = self._get_local_path(snapshot)
share_device_name = self._get_local_path(share)
self._execute(
'tune2fs', '-U', 'random', share_device_name, run_as_root=True,
)
self._set_random_uuid_to_device(share)
self._copy_volume(
snapshot_device_name, share_device_name, share['size'])
location = self._get_helper(share).create_exports(

View File

@ -323,6 +323,7 @@ class GenericShareDriverTestCase(test.TestCase):
'&&', 'sudo', 'mount', volume['mountpoint'], mount_path,
'&&', 'sudo', 'chmod', '777', mount_path,
'&&', 'sudo', 'umount', mount_path,
'&&', 'sudo', 'e2fsck', '-y', '-f', volume['mountpoint'],
'&&', 'sudo', 'tune2fs', '-U', 'random', volume['mountpoint'],
'&&', 'sudo', 'mount', volume['mountpoint'], mount_path,
),

View File

@ -228,6 +228,7 @@ class LVMShareDriverTestCase(test.TestCase):
expected_exec = [
'lvcreate -L 1G -n fakename fakevg',
'mkfs.ext4 /dev/mapper/fakevg-fakename',
'e2fsck -y -f %s' % mount_share,
'tune2fs -U random %s' % mount_share,
("dd count=0 if=%s of=%s iflag=direct oflag=direct" %
(mount_snapshot, mount_share)),
@ -333,6 +334,7 @@ class LVMShareDriverTestCase(test.TestCase):
expected_exec = [
("lvcreate -L 1G --name fakesnapshotname --snapshot "
"%s/fakename" % (CONF.lvm_share_volume_group,)),
"e2fsck -y -f /dev/mapper/fakevg-%s" % self.snapshot['name'],
"tune2fs -U random /dev/mapper/fakevg-%s" % self.snapshot['name'],
"mkdir -p " + mount_path,
"mount /dev/mapper/fakevg-fakesnapshotname " + mount_path,
@ -579,7 +581,9 @@ class LVMShareDriverTestCase(test.TestCase):
("lvconvert --merge %s" % snap_lv),
("lvcreate -L 1G --name fakesnapshotname --snapshot %s" %
share_lv),
('tune2fs -U random /dev/mapper/%s-fakesnapshotname' %
("e2fsck -y -f /dev/mapper/%s-fakesnapshotname" %
CONF.lvm_share_volume_group),
("tune2fs -U random /dev/mapper/%s-fakesnapshotname" %
CONF.lvm_share_volume_group),
("mkdir -p %s" % share_mount_path),
("mount /dev/mapper/%s-fakename %s" %

View File

@ -0,0 +1,8 @@
---
fixes:
- |
The generic and LVM drivers have been fixed to always perform a filesystem
check on newly created snapshots and derivative shares before attempting
to assign a UUID to them. See
`Launchpad bug 1798219 <https://bugs.launchpad.net/manila/+bug/1798219>`_
for more details.