Skip to content

Commit

Permalink
lxd/storage/drivers/zfs: update setDatasetProperties usage
Browse files Browse the repository at this point in the history
Signed-off-by: hamistao <pedro.ribeiro@canonical.com>
  • Loading branch information
hamistao committed Apr 18, 2024
1 parent 1e83ba6 commit 9ade999
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions lxd/storage/drivers/driver_zfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (d zfs) ensureInitialDatasets(warnOnExistingPolicyApplyError bool) error {
args = append(args, fmt.Sprintf("%s=%s", k, v))
}

err := d.setDatasetProperties(d.config["zfs.pool_name"], args...)
err := d.setDatasetProperties(d.config["zfs.pool_name"], true, args...)
if err != nil {
if warnOnExistingPolicyApplyError {
d.logger.Warn("Failed applying policy to existing dataset", logger.Ctx{"dataset": d.config["zfs.pool_name"], "err": err})
Expand All @@ -166,7 +166,7 @@ func (d zfs) ensureInitialDatasets(warnOnExistingPolicyApplyError bool) error {
}

if exists {
err = d.setDatasetProperties(datasetPath, properties...)
err = d.setDatasetProperties(datasetPath, true, properties...)
if err != nil {
if warnOnExistingPolicyApplyError {
d.logger.Warn("Failed applying policy to existing dataset", logger.Ctx{"dataset": datasetPath, "err": err})
Expand Down
44 changes: 22 additions & 22 deletions lxd/storage/drivers/driver_zfs_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func (d *zfs) CreateVolume(vol Volume, filler *VolumeFiller, op *operations.Oper
return err
}

err = d.setDatasetProperties(d.dataset(vol, false), "volmode=none")
err = d.setDatasetProperties(d.dataset(vol, false), false, "volmode=none")
if err != nil {
return err
}
Expand Down Expand Up @@ -506,13 +506,13 @@ func (d *zfs) CreateVolumeFromBackup(vol VolumeCopy, srcBackup backup.Info, srcD
if v.contentType == ContentTypeFS {
if zfsDelegate {
// Unset the zoned property so the mountpoint property can be updated.
err := d.setDatasetProperties(d.dataset(v, false), "zoned=off")
err := d.setDatasetProperties(d.dataset(v, false), false, "zoned=off")
if err != nil {
return nil, nil, err
}
}

err := d.setDatasetProperties(d.dataset(v, false), "mountpoint=legacy", "canmount=noauto")
err := d.setDatasetProperties(d.dataset(v, false), false, "mountpoint=legacy", "canmount=noauto")
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -823,7 +823,7 @@ func (d *zfs) CreateVolumeFromCopy(vol VolumeCopy, srcVol VolumeCopy, allowIncon
// Apply the properties.
if vol.contentType == ContentTypeFS {
if !d.isBlockBacked(srcVol.Volume) {
err := d.setDatasetProperties(d.dataset(vol.Volume, false), "mountpoint=legacy", "canmount=noauto")
err := d.setDatasetProperties(d.dataset(vol.Volume, false), false, "mountpoint=legacy", "canmount=noauto")
if err != nil {
return err
}
Expand Down Expand Up @@ -1166,13 +1166,13 @@ func (d *zfs) createVolumeFromMigrationOptimized(vol Volume, conn io.ReadWriteCl
// Re-apply the base mount options.
if zfsDelegate {
// Unset the zoned property so the mountpoint property can be updated.
err := d.setDatasetProperties(d.dataset(vol, false), "zoned=off")
err := d.setDatasetProperties(d.dataset(vol, false), false, "zoned=off")
if err != nil {
return err
}
}

err = d.setDatasetProperties(d.dataset(vol, false), "mountpoint=legacy", "canmount=noauto")
err = d.setDatasetProperties(d.dataset(vol, false), false, "mountpoint=legacy", "canmount=noauto")
if err != nil {
return err
}
Expand Down Expand Up @@ -1805,13 +1805,13 @@ func (d *zfs) SetVolumeQuota(vol Volume, size string, allowUnsafeResize bool, op
l.Debug("ZFS volume filesystem shrunk")

// Shrink the block device.
err = d.setDatasetProperties(d.dataset(vol, false), fmt.Sprintf("volsize=%d", sizeBytes))
err = d.setDatasetProperties(d.dataset(vol, false), false, fmt.Sprintf("volsize=%d", sizeBytes))
if err != nil {
return err
}
} else if sizeBytes > oldVolSizeBytes {
// Grow block device first.
err = d.setDatasetProperties(d.dataset(vol, false), fmt.Sprintf("volsize=%d", sizeBytes))
err = d.setDatasetProperties(d.dataset(vol, false), false, fmt.Sprintf("volsize=%d", sizeBytes))
if err != nil {
return err
}
Expand Down Expand Up @@ -1844,7 +1844,7 @@ func (d *zfs) SetVolumeQuota(vol Volume, size string, allowUnsafeResize bool, op
}
}

err = d.setDatasetProperties(d.dataset(vol, false), fmt.Sprintf("volsize=%d", sizeBytes))
err = d.setDatasetProperties(d.dataset(vol, false), false, fmt.Sprintf("volsize=%d", sizeBytes))
if err != nil {
return err
}
Expand All @@ -1871,7 +1871,7 @@ func (d *zfs) SetVolumeQuota(vol Volume, size string, allowUnsafeResize bool, op

// Clear the existing quota.
for _, property := range []string{"quota", "refquota", "reservation", "refreservation"} {
err = d.setDatasetProperties(d.dataset(vol, false), fmt.Sprintf("%s=none", property))
err = d.setDatasetProperties(d.dataset(vol, false), false, fmt.Sprintf("%s=none", property))
if err != nil {
return err
}
Expand All @@ -1890,13 +1890,13 @@ func (d *zfs) SetVolumeQuota(vol Volume, size string, allowUnsafeResize bool, op
reservationKey = "refreservation"
}

err = d.setDatasetProperties(d.dataset(vol, false), fmt.Sprintf("%s=%s", quotaKey, value))
err = d.setDatasetProperties(d.dataset(vol, false), false, fmt.Sprintf("%s=%s", quotaKey, value))
if err != nil {
return err
}

if shared.IsTrue(vol.ExpandedConfig("zfs.reserve_space")) {
err = d.setDatasetProperties(d.dataset(vol, false), fmt.Sprintf("%s=%s", reservationKey, value))
err = d.setDatasetProperties(d.dataset(vol, false), false, fmt.Sprintf("%s=%s", reservationKey, value))
if err != nil {
return err
}
Expand Down Expand Up @@ -2095,7 +2095,7 @@ func (d *zfs) activateVolume(vol Volume) (bool, error) {

if current != "dev" {
// For block backed volumes, we make their associated device appear.
err = d.setDatasetProperties(dataset, "volmode=dev")
err = d.setDatasetProperties(dataset, false, "volmode=dev")
if err != nil {
return false, err
}
Expand Down Expand Up @@ -2138,7 +2138,7 @@ func (d *zfs) deactivateVolume(vol Volume) (bool, error) {
i := 0
for {
// Sometimes it takes multiple attempts for ZFS to actually apply this.
err = d.setDatasetProperties(dataset, "volmode=none")
err = d.setDatasetProperties(dataset, false, "volmode=none")
if err != nil {
return false, err
}
Expand Down Expand Up @@ -2189,13 +2189,13 @@ func (d *zfs) MountVolume(vol Volume, op *operations.Operation) error {
// Check if filesystem volume already mounted.
if vol.contentType == ContentTypeFS && !d.isBlockBacked(vol) {
if !filesystem.IsMountPoint(mountPath) {
err := d.setDatasetProperties(dataset, "mountpoint=legacy", "canmount=noauto")
err := d.setDatasetProperties(dataset, false, "mountpoint=legacy", "canmount=noauto")
if err != nil {
return err
}

if zfsDelegate && shared.IsTrue(vol.config["zfs.delegate"]) {
err = d.setDatasetProperties(dataset, "zoned=on")
err = d.setDatasetProperties(dataset, false, "zoned=on")
if err != nil {
return err
}
Expand Down Expand Up @@ -2309,7 +2309,7 @@ func (d *zfs) UnmountVolume(vol Volume, keepBlockDev bool, op *operations.Operat
}

if !blockBacked && zfsDelegate && shared.IsTrue(vol.config["zfs.delegate"]) {
err = d.setDatasetProperties(dataset, "zoned=off")
err = d.setDatasetProperties(dataset, false, "zoned=off")
if err != nil {
return false, err
}
Expand Down Expand Up @@ -2381,7 +2381,7 @@ func (d *zfs) RenameVolume(vol Volume, newVolName string, op *operations.Operati

// Ensure the volume has correct mountpoint settings.
if vol.contentType == ContentTypeFS && !d.isBlockBacked(vol) {
err = d.setDatasetProperties(d.dataset(newVol, false), "mountpoint=legacy", "canmount=noauto")
err = d.setDatasetProperties(d.dataset(newVol, false), false, "mountpoint=legacy", "canmount=noauto")
if err != nil {
return err
}
Expand Down Expand Up @@ -3053,7 +3053,7 @@ func (d *zfs) mountVolumeSnapshot(snapVol Volume, snapshotDataset string, mountP
}

if parentSnapdevMode != "visible" {
err = d.setDatasetProperties(parentDataset, "snapdev=visible")
err = d.setDatasetProperties(parentDataset, false, "snapdev=visible")
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -3100,13 +3100,13 @@ func (d *zfs) mountVolumeSnapshot(snapVol Volume, snapshotDataset string, mountP
// Delete on revert.
revert.Add(func() { _ = d.deleteDatasetRecursive(dataset) })

err := d.setDatasetProperties(dataset, "volmode=dev")
err := d.setDatasetProperties(dataset, false, "volmode=dev")
if err != nil {
return nil, err
}

defer func() {
_ = d.setDatasetProperties(dataset, "volmode=none")
_ = d.setDatasetProperties(dataset, false, "volmode=none")
}()

// Wait half a second to give udev a chance to kick in.
Expand Down Expand Up @@ -3258,7 +3258,7 @@ func (d *zfs) UnmountVolumeSnapshot(snapVol Volume, op *operations.Operation) (b
return false, ErrInUse
}

err := d.setDatasetProperties(parentDataset, "snapdev=hidden")
err := d.setDatasetProperties(parentDataset, false, "snapdev=hidden")
if err != nil {
return false, err
}
Expand Down

0 comments on commit 9ade999

Please sign in to comment.