Skip to content

Commit

Permalink
Merge pull request #12745 from roosterfish/rbd_restore_uuid
Browse files Browse the repository at this point in the history
Ceph RBD: Restore the filesystems UUID on the volume
  • Loading branch information
tomponline authored Jan 19, 2024
2 parents 4a78476 + 53e017a commit 9ffad53
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
11 changes: 3 additions & 8 deletions lxd/storage/drivers/driver_ceph_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -1813,21 +1813,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
}
Expand Down
19 changes: 18 additions & 1 deletion test/suites/storage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9ffad53

Please sign in to comment.