diff --git a/lxd/storage/drivers/driver_zfs_volumes.go b/lxd/storage/drivers/driver_zfs_volumes.go index 2790df61e400..4b221701ac4c 100644 --- a/lxd/storage/drivers/driver_zfs_volumes.go +++ b/lxd/storage/drivers/driver_zfs_volumes.go @@ -1842,16 +1842,19 @@ func (d *zfs) ListVolumes() ([]Volume, error) { continue // Ignore unrecognised volume. } - // Detect if a volume is block content type using both the defined suffix and the dataset type. - isBlock := strings.HasSuffix(volName, zfsBlockVolSuffix) && zfsContentType == "volume" + // Detect if a volume is block content type using only the dataset type. + isBlock := zfsContentType == "volume" if volType == VolumeTypeVM && !isBlock { continue // Ignore VM filesystem volumes as we will just return the VM's block volume. } contentType := ContentTypeFS - if volType == VolumeTypeVM || isBlock { + if isBlock { contentType = ContentTypeBlock + } + + if volType == VolumeTypeVM || isBlock { volName = strings.TrimSuffix(volName, zfsBlockVolSuffix) } @@ -1863,7 +1866,7 @@ func (d *zfs) ListVolumes() ([]Volume, error) { if !foundExisting || (existingVol.Type() == VolumeTypeImage && existingVol.ContentType() == ContentTypeFS) { v := NewVolume(d, d.name, volType, contentType, volName, make(map[string]string), d.config) - if zfsContentType == "volume" { + if isBlock { v.SetMountFilesystemProbe(true) } diff --git a/test/main.sh b/test/main.sh index 06509da214fa..51b7803e51ff 100755 --- a/test/main.sh +++ b/test/main.sh @@ -345,6 +345,7 @@ if [ "${1:-"all"}" != "cluster" ]; then run_test test_filtering "API filtering" run_test test_warnings "Warnings" run_test test_metrics "Metrics" + run_test test_storage_volume_recover "Recover storage volumes" fi # shellcheck disable=SC2034 diff --git a/test/suites/backup.sh b/test/suites/backup.sh index 8bd993f532a2..8a339c6f775e 100644 --- a/test/suites/backup.sh +++ b/test/suites/backup.sh @@ -1,3 +1,34 @@ +test_storage_volume_recover() { + LXD_IMPORT_DIR=$(mktemp -d -p "${TEST_DIR}" XXX) + chmod +x "${LXD_IMPORT_DIR}" + spawn_lxd "${LXD_IMPORT_DIR}" true + + poolName=$(lxc profile device get default root pool) + + # Create custom block volume. + lxc storage volume create "${poolName}" vol1 --type=block + + # Delete database entry of the created custom block volume. + lxd sql global "PRAGMA foreign_keys=ON; DELETE FROM storage_volumes WHERE name='vol1'" + + # Ensure the custom block volume is no longer listed. + ! lxc storage volume show "${poolName}" vol1 || false + + # Recover custom block volume. + cat <