Skip to content

Commit

Permalink
Merge pull request #12941 from roosterfish/fix_config_patch
Browse files Browse the repository at this point in the history
Storage: Fix block volume patch
  • Loading branch information
tomponline authored Feb 22, 2024
2 parents 1a07184 + 484f111 commit 8d82bfb
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 14 deletions.
14 changes: 3 additions & 11 deletions lxd/patches.go
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,6 @@ func patchStorageUnsetInvalidBlockSettings(_ string, d *Daemon) error {
}

volTypeCustom := dbCluster.StoragePoolVolumeTypeCustom
volTypeVM := dbCluster.StoragePoolVolumeTypeVM

poolIDNameMap := make(map[int64]string, 0)
poolVolumes := make(map[int64][]*db.StorageVolume, 0)
Expand Down Expand Up @@ -1309,7 +1308,7 @@ func patchStorageUnsetInvalidBlockSettings(_ string, d *Daemon) error {
}

// Get the pool's storage volumes.
volumes, err = tx.GetStoragePoolVolumes(ctx, poolID, false, db.StorageVolumeFilter{Type: &volTypeCustom}, db.StorageVolumeFilter{Type: &volTypeVM})
volumes, err = tx.GetStoragePoolVolumes(ctx, poolID, false, db.StorageVolumeFilter{Type: &volTypeCustom})
if err != nil {
return fmt.Errorf("Failed getting custom storage volumes of pool %q: %w", pool, err)
}
Expand All @@ -1328,12 +1327,9 @@ func patchStorageUnsetInvalidBlockSettings(_ string, d *Daemon) error {
poolVolumes[poolID] = append(poolVolumes[poolID], volumes...)
}

var volType int

for pool, volumes := range poolVolumes {
for _, vol := range volumes {
// Skip custom volumes with filesystem content type.
// VMs are always of type block.
if vol.Type == dbCluster.StoragePoolVolumeTypeNameCustom && vol.ContentType == dbCluster.StoragePoolVolumeContentTypeNameFS {
continue
}
Expand All @@ -1353,17 +1349,13 @@ func patchStorageUnsetInvalidBlockSettings(_ string, d *Daemon) error {
continue
}

if vol.Type == dbCluster.StoragePoolVolumeTypeNameVM {
volType = volTypeVM
} else if vol.Type == dbCluster.StoragePoolVolumeTypeNameCustom {
volType = volTypeCustom
} else {
if vol.Type != dbCluster.StoragePoolVolumeTypeNameCustom {
// Should not happen.
continue
}

err = s.DB.Cluster.Transaction(context.TODO(), func(ctx context.Context, tx *db.ClusterTx) error {
return tx.UpdateStoragePoolVolume(ctx, vol.Project, vol.Name, volType, pool, vol.Description, config)
return tx.UpdateStoragePoolVolume(ctx, vol.Project, vol.Name, volTypeCustom, pool, vol.Description, config)
})
if err != nil {
return fmt.Errorf("Failed updating volume %q in project %q on pool %q: %w", vol.Name, vol.Project, poolIDNameMap[pool], err)
Expand Down
2 changes: 1 addition & 1 deletion lxd/storage/drivers/driver_ceph_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ func (d *ceph) ValidateVolume(vol Volume, removeUnknownKeys bool) error {
// when using custom filesystem volumes. LXD will create the filesystem
// for these volumes, and use the mount options. When attaching a regular block volume to a VM,
// these are not mounted by LXD and therefore don't need these config keys.
if vol.IsVMBlock() || vol.volType == VolumeTypeCustom && vol.contentType == ContentTypeBlock {
if vol.volType == VolumeTypeCustom && vol.contentType == ContentTypeBlock {
delete(commonRules, "block.filesystem")
delete(commonRules, "block.mount_options")
}
Expand Down
2 changes: 1 addition & 1 deletion lxd/storage/drivers/driver_lvm_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func (d *lvm) ValidateVolume(vol Volume, removeUnknownKeys bool) error {
// when using custom filesystem volumes. LXD will create the filesystem
// for these volumes, and use the mount options. When attaching a regular block volume to a VM,
// these are not mounted by LXD and therefore don't need these config keys.
if vol.IsVMBlock() || vol.volType == VolumeTypeCustom && vol.contentType == ContentTypeBlock {
if vol.volType == VolumeTypeCustom && vol.contentType == ContentTypeBlock {
delete(commonRules, "block.filesystem")
delete(commonRules, "block.mount_options")
}
Expand Down
2 changes: 1 addition & 1 deletion lxd/storage/drivers/driver_powerflex_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ func (d *powerflex) ValidateVolume(vol Volume, removeUnknownKeys bool) error {
// when using custom filesystem volumes. LXD will create the filesystem
// for these volumes, and use the mount options. When attaching a regular block volume to a VM,
// these are not mounted by LXD and therefore don't need these config keys.
if vol.IsVMBlock() || vol.volType == VolumeTypeCustom && vol.contentType == ContentTypeBlock {
if vol.volType == VolumeTypeCustom && vol.contentType == ContentTypeBlock {
delete(commonRules, "block.filesystem")
delete(commonRules, "block.mount_options")
}
Expand Down

0 comments on commit 8d82bfb

Please sign in to comment.