Skip to content

Commit

Permalink
lxd/storage/drivers: Fix linter errors
Browse files Browse the repository at this point in the history
Signed-off-by: Wesley Hershberger <wesley.hershberger@canonical.com>
  • Loading branch information
MggMuggins committed May 22, 2024
1 parent 034f8ec commit 9833d46
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
2 changes: 2 additions & 0 deletions lxd/storage/drivers/driver_lvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,8 @@ func (d *lvm) Delete(op *operations.Operation) error {
return nil
}

// Validate checks that all provide keys are supported and that no conflicting
// or missing configuration is present.
func (d *lvm) Validate(config map[string]string) error {
rules := map[string]func(value string) error{
"size": validate.Optional(validate.IsSize),
Expand Down
4 changes: 3 additions & 1 deletion lxd/storage/drivers/driver_zfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ func (d *zfs) Unmount() (bool, error) {
return true, nil
}

// GetResources returns utilization statistics for the storage pool.
func (d *zfs) GetResources() (*api.ResourcesStoragePool, error) {
// Get the total amount of space.
availableStr, err := d.getDatasetProperty(d.config["zfs.pool_name"], "available")
Expand Down Expand Up @@ -655,7 +656,8 @@ func (d *zfs) GetResources() (*api.ResourcesStoragePool, error) {
return &res, nil
}

// MigrationType returns the type of transfer methods to be used when doing migrations between pools in preference order.
// MigrationTypes returns the type of transfer methods to be used when doing
// migrations between pools in preference order.
func (d *zfs) MigrationTypes(contentType ContentType, refresh bool, copySnapshots bool) []migration.Type {
var rsyncFeatures []string

Expand Down
6 changes: 3 additions & 3 deletions lxd/storage/drivers/driver_zfs_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ func (d *zfs) CreateVolumeFromMigration(vol VolumeCopy, conn io.ReadWriteCloser,
return fmt.Errorf("Failed sending ZFS migration header: %w", err)
}

err = conn.Close() //End the frame.
err = conn.Close() // End the frame.
if err != nil {
return fmt.Errorf("Failed closing ZFS migration header frame: %w", err)
}
Expand Down Expand Up @@ -2517,7 +2517,7 @@ func (d *zfs) MigrateVolume(vol VolumeCopy, conn io.ReadWriteCloser, volSrcArgs
return fmt.Errorf("Failed sending ZFS migration header: %w", err)
}

err = conn.Close() //End the frame.
err = conn.Close() // End the frame.
if err != nil {
return fmt.Errorf("Failed closing ZFS migration header frame: %w", err)
}
Expand Down Expand Up @@ -3187,7 +3187,7 @@ func (d *zfs) mountVolumeSnapshot(snapVol Volume, snapshotDataset string, mountP
return cleanup, nil
}

// UnmountVolume simulates unmounting a volume snapshot.
// UnmountVolumeSnapshot simulates unmounting a volume snapshot.
func (d *zfs) UnmountVolumeSnapshot(snapVol Volume, op *operations.Operation) (bool, error) {
unlock, err := snapVol.MountLock()
if err != nil {
Expand Down
22 changes: 12 additions & 10 deletions lxd/storage/drivers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -819,18 +819,20 @@ func loopFileSizeDefault() (uint64, error) {
// It tries to enable direct I/O if supported.
func loopDeviceSetup(sourcePath string) (string, error) {
out, err := shared.RunCommand("losetup", "--find", "--nooverlap", "--direct-io=on", "--show", sourcePath)
if err != nil {
if strings.Contains(err.Error(), "direct io") || strings.Contains(err.Error(), "Invalid argument") {
out, err = shared.RunCommand("losetup", "--find", "--nooverlap", "--show", sourcePath)
if err != nil {
return "", err
}
} else {
return "", err
}
if err == nil {
return strings.TrimSpace(out), nil
}

if !(strings.Contains(err.Error(), "direct io") || strings.Contains(err.Error(), "Invalid argument")) {
return "", err
}

out, err = shared.RunCommand("losetup", "--find", "--nooverlap", "--show", sourcePath)
if err == nil {
return strings.TrimSpace(out), nil
}

return strings.TrimSpace(out), nil
return "", err
}

// loopFileAutoDetach enables auto detach mode for a loop device.
Expand Down

0 comments on commit 9833d46

Please sign in to comment.