diff --git a/etc/manila/rootwrap.d/share.filters b/etc/manila/rootwrap.d/share.filters index 72345916ee..c3609cd72a 100644 --- a/etc/manila/rootwrap.d/share.filters +++ b/etc/manila/rootwrap.d/share.filters @@ -174,7 +174,9 @@ docker: CommandFilter, docker, root # manila/share/drivers/container/container.py: brctl brctl: CommandFilter, brctl, root -# manila/share/drivers/container/container.py: e2fsck +# manila/share/drivers/container/storage_helper.py: e2fsck +# manila/share/drivers/generic.py: e2fsck +# manila/share/drivers/lvm.py: e2fsck e2fsck: CommandFilter, e2fsck, root # manila/share/drivers/lvm.py: lvconvert --merge %s diff --git a/manila/share/drivers/generic.py b/manila/share/drivers/generic.py index c746ef42cc..1845f12747 100644 --- a/manila/share/drivers/generic.py +++ b/manila/share/drivers/generic.py @@ -357,6 +357,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, ) diff --git a/manila/share/drivers/lvm.py b/manila/share/drivers/lvm.py index e96f0d6be2..fe32d1be3e 100644 --- a/manila/share/drivers/lvm.py +++ b/manila/share/drivers/lvm.py @@ -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( diff --git a/manila/tests/share/drivers/test_generic.py b/manila/tests/share/drivers/test_generic.py index a40d4a577f..095f450233 100644 --- a/manila/tests/share/drivers/test_generic.py +++ b/manila/tests/share/drivers/test_generic.py @@ -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, ), diff --git a/manila/tests/share/drivers/test_lvm.py b/manila/tests/share/drivers/test_lvm.py index 21967730b9..addb1fc30e 100644 --- a/manila/tests/share/drivers/test_lvm.py +++ b/manila/tests/share/drivers/test_lvm.py @@ -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" % diff --git a/releasenotes/notes/bug-1798219-fix-snapshot-creation-lvm-and-generic-driver-55e349e02e7fa370.yaml b/releasenotes/notes/bug-1798219-fix-snapshot-creation-lvm-and-generic-driver-55e349e02e7fa370.yaml new file mode 100644 index 0000000000..742635cbdf --- /dev/null +++ b/releasenotes/notes/bug-1798219-fix-snapshot-creation-lvm-and-generic-driver-55e349e02e7fa370.yaml @@ -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 `_ + for more details.