From 827f1fce57898467b6b5d6eb909a5eb639e95c3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20Peliz=C3=A4us?= Date: Thu, 18 Jan 2024 18:15:18 +0100 Subject: [PATCH 1/2] lxd/storage/drivers/ceph: Restore the filesystems UUID on the volume MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ceph RBD snapshots are a read-only logical copy of the parent volume. Rewriting the filesystems UUID on the snapshot itself fails. Signed-off-by: Julian Pelizäus --- lxd/storage/drivers/driver_ceph_volumes.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/lxd/storage/drivers/driver_ceph_volumes.go b/lxd/storage/drivers/driver_ceph_volumes.go index 11419cd12c85..248cd873d134 100644 --- a/lxd/storage/drivers/driver_ceph_volumes.go +++ b/lxd/storage/drivers/driver_ceph_volumes.go @@ -1798,21 +1798,16 @@ func (d *ceph) RestoreVolume(vol Volume, snapshotName string, op *operations.Ope return err } - snapVol, err := vol.NewSnapshot(snapshotName) - if err != nil { - return err - } - // Map the RBD volume. - devPath, err := d.rbdMapVolume(snapVol) + devPath, err := d.rbdMapVolume(vol) if err != nil { return err } - defer func() { _ = d.rbdUnmapVolume(snapVol, true) }() + defer func() { _ = d.rbdUnmapVolume(vol, true) }() // Re-generate the UUID. - err = d.generateUUID(snapVol.ConfigBlockFilesystem(), devPath) + err = d.generateUUID(vol.ConfigBlockFilesystem(), devPath) if err != nil { return err } From 53e017a1db6a7f0667c55855b50220479f6fb827 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20Peliz=C3=A4us?= Date: Thu, 18 Jan 2024 18:40:50 +0100 Subject: [PATCH 2/2] test/suites/storage: Add check for UUID generation on restore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julian Pelizäus --- test/suites/storage.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/test/suites/storage.sh b/test/suites/storage.sh index 99dadda33ee1..28122f13cf55 100644 --- a/test/suites/storage.sh +++ b/test/suites/storage.sh @@ -66,8 +66,25 @@ test_storage() { fi lxc delete --force uuid1 lxc delete --force uuid2 - lxc image delete testimage + # Test UUID re-generation in case of restore. + lxc init testimage uuid1 -s "${POOL}" + lxc snapshot uuid1 + lxc start uuid1 + if [ "$lxd_backend" = "lvm" ]; then + uuid="$(blkid -s UUID -o value -p /dev/"${POOL}"/containers_uuid1)" + elif [ "$lxd_backend" = "ceph" ]; then + uuid="$(blkid -s UUID -o value -p /dev/rbd/"${POOL}"/container_uuid1)" + fi + lxc restore uuid1 snap0 + if [ "$lxd_backend" = "lvm" ]; then + [ "$(blkid -s UUID -o value -p /dev/"${POOL}"/containers_uuid1)" != "$uuid" ] + elif [ "$lxd_backend" = "ceph" ]; then + [ "$(blkid -s UUID -o value -p /dev/rbd/"${POOL}"/container_uuid1)" != "$uuid" ] + fi + lxc delete --force uuid1 + + lxc image delete testimage lxc storage delete "$btrfs_storage_pool" fi ensure_import_testimage