Skip to content

Commit

Permalink
lxd/storage/drivers: avoid redundant property value updates
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 f2ffa4e commit 58c673c
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions lxd/storage/drivers/driver_zfs_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,50 @@ func (d *zfs) getDatasets(dataset string, types string) ([]string, error) {

func (d *zfs) setDatasetProperties(dataset string, options ...string) error {
args := []string{"set"}
args = append(args, options...)
args = append(args, dataset)

_, err := shared.RunCommand("zfs", args...)
keys := []string{}
values := []string{}

// Extract keys and values from options.
for _, option := range options {
property := strings.Split(option, "=")

if len(property) != 2 {
continue
}

keys = append(keys, property[0])

// Handle "posixacl" and "posix" equivalency to avoid duplicate events.
if property[0] == "acltype" && property[1] == "posixacl" {
values = append(values, "posix")
} else {
values = append(values, property[1])
}
}

// Get current values for the keys.
currentProperties, err := d.getDatasetProperties(dataset, keys...)
if err != nil {
return err
}

// Change property values that are different from the current value.
for propertyIndex := range keys {
if currentProperties[keys[propertyIndex]] != values[propertyIndex] {
args = append(args, options[propertyIndex])
}
}

// Check if any property value needs to be changed.
if len(args) > 1 {
args = append(args, dataset)
_, err = shared.RunCommand("zfs", args...)
if err != nil {
return err
}
}

return nil
}

Expand Down

0 comments on commit 58c673c

Please sign in to comment.