Skip to content

Commit

Permalink
lxd/storage/drivers/zfs: Fix content type detection for custom block …
Browse files Browse the repository at this point in the history
…volumes

This fixes an issue where custom block volumes would be listed as
datasets instead of volumes.

Fixes canonical#11984

Signed-off-by: Thomas Hipp <[email protected]>
  • Loading branch information
monstermunchkin committed Jul 12, 2023
1 parent 5ce222a commit 5f555ce
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lxd/storage/drivers/driver_zfs_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand Down

0 comments on commit 5f555ce

Please sign in to comment.