Skip to content

Commit

Permalink
lxd/storage/drivers/zfs: Avoid deprecated RunCommand (staticcheck)
Browse files Browse the repository at this point in the history
Signed-off-by: hamistao <[email protected]>
  • Loading branch information
hamistao committed Feb 5, 2025
1 parent 86b2f4f commit 8a73064
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions lxd/storage/drivers/driver_zfs_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (d *zfs) CreateVolume(vol Volume, filler *VolumeFiller, op *operations.Oper
d.logger.Debug("Renaming deleted cached image volume so that regeneration is used", logger.Ctx{"fingerprint": vol.Name()})
randomVol := NewVolume(d, d.name, vol.volType, vol.contentType, d.randomVolumeName(vol), vol.config, vol.poolConfig)

_, err := shared.RunCommand("/proc/self/exe", "forkzfs", "--", "rename", d.dataset(vol, true), d.dataset(randomVol, true))
_, err := shared.RunCommandContext(d.state.ShutdownCtx, "/proc/self/exe", "forkzfs", "--", "rename", d.dataset(vol, true), d.dataset(randomVol, true))
if err != nil {
return err
}
Expand All @@ -102,7 +102,7 @@ func (d *zfs) CreateVolume(vol Volume, filler *VolumeFiller, op *operations.Oper
fsVol := vol.NewVMBlockFilesystemVolume()
randomFsVol := randomVol.NewVMBlockFilesystemVolume()

_, err := shared.RunCommand("/proc/self/exe", "forkzfs", "--", "rename", d.dataset(fsVol, true), d.dataset(randomFsVol, true))
_, err := shared.RunCommandContext(d.state.ShutdownCtx, "/proc/self/exe", "forkzfs", "--", "rename", d.dataset(fsVol, true), d.dataset(randomFsVol, true))
if err != nil {
return err
}
Expand All @@ -117,15 +117,15 @@ func (d *zfs) CreateVolume(vol Volume, filler *VolumeFiller, op *operations.Oper
// Restore the image.
if canRestore {
d.logger.Debug("Restoring previously deleted cached image volume", logger.Ctx{"fingerprint": vol.Name()})
_, err := shared.RunCommand("/proc/self/exe", "forkzfs", "--", "rename", d.dataset(vol, true), d.dataset(vol, false))
_, err := shared.RunCommandContext(d.state.ShutdownCtx, "/proc/self/exe", "forkzfs", "--", "rename", d.dataset(vol, true), d.dataset(vol, false))
if err != nil {
return err
}

if vol.IsVMBlock() {
fsVol := vol.NewVMBlockFilesystemVolume()

_, err := shared.RunCommand("/proc/self/exe", "forkzfs", "--", "rename", d.dataset(fsVol, true), d.dataset(fsVol, false))
_, err := shared.RunCommandContext(d.state.ShutdownCtx, "/proc/self/exe", "forkzfs", "--", "rename", d.dataset(fsVol, true), d.dataset(fsVol, false))
if err != nil {
return err
}
Expand Down Expand Up @@ -308,7 +308,7 @@ func (d *zfs) CreateVolume(vol Volume, filler *VolumeFiller, op *operations.Oper
// Setup snapshot and unset mountpoint on image.
if vol.volType == VolumeTypeImage {
// Create snapshot of the main dataset.
_, err := shared.RunCommand("zfs", "snapshot", "-r", d.dataset(vol, false)+"@readonly")
_, err := shared.RunCommandContext(d.state.ShutdownCtx, "zfs", "snapshot", "-r", d.dataset(vol, false)+"@readonly")
if err != nil {
return err
}
Expand All @@ -318,12 +318,12 @@ func (d *zfs) CreateVolume(vol Volume, filler *VolumeFiller, op *operations.Oper
// and unpacked into both config and block volumes.
fsVol := vol.NewVMBlockFilesystemVolume()

_, err := shared.RunCommand("zfs", "destroy", "-r", d.dataset(fsVol, false)+"@readonly")
_, err := shared.RunCommandContext(d.state.ShutdownCtx, "zfs", "destroy", "-r", d.dataset(fsVol, false)+"@readonly")
if err != nil {
return err
}

_, err = shared.RunCommand("zfs", "snapshot", "-r", d.dataset(fsVol, false)+"@readonly")
_, err = shared.RunCommandContext(d.state.ShutdownCtx, "zfs", "snapshot", "-r", d.dataset(fsVol, false)+"@readonly")
if err != nil {
return err
}
Expand Down Expand Up @@ -494,7 +494,7 @@ func (d *zfs) CreateVolumeFromBackup(vol VolumeCopy, srcBackup backup.Info, srcD
}

if strings.Contains(entry, "@") {
_, err := shared.RunCommand("zfs", "destroy", d.dataset(v, false)+entry)
_, err := shared.RunCommandContext(d.state.ShutdownCtx, "zfs", "destroy", d.dataset(v, false)+entry)
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -611,7 +611,7 @@ func (d *zfs) CreateVolumeFromCopy(vol VolumeCopy, srcVol VolumeCopy, allowIncon
// Create a new snapshot for copy.
srcSnapshot = d.dataset(srcVol.Volume, false) + "@copy-" + uuid.New().String()

_, err := shared.RunCommand("zfs", "snapshot", "-r", srcSnapshot)
_, err := shared.RunCommandContext(d.state.ShutdownCtx, "zfs", "snapshot", "-r", srcSnapshot)
if err != nil {
return err
}
Expand All @@ -621,7 +621,7 @@ func (d *zfs) CreateVolumeFromCopy(vol VolumeCopy, srcVol VolumeCopy, allowIncon
// Delete the snapshot at the end.
defer func() {
// Delete snapshot (or mark for deferred deletion if cannot be deleted currently).
_, err := shared.RunCommand("zfs", "destroy", "-r", "-d", srcSnapshot)
_, err := shared.RunCommandContext(d.state.ShutdownCtx, "zfs", "destroy", "-r", "-d", srcSnapshot)
if err != nil {
d.logger.Warn("Failed deleting temporary snapshot for copy", logger.Ctx{"snapshot": srcSnapshot, "err": err})
}
Expand All @@ -630,7 +630,7 @@ func (d *zfs) CreateVolumeFromCopy(vol VolumeCopy, srcVol VolumeCopy, allowIncon
// Delete the snapshot on revert.
revert.Add(func() {
// Delete snapshot (or mark for deferred deletion if cannot be deleted currently).
_, err := shared.RunCommand("zfs", "destroy", "-r", "-d", srcSnapshot)
_, err := shared.RunCommandContext(d.state.ShutdownCtx, "zfs", "destroy", "-r", "-d", srcSnapshot)
if err != nil {
d.logger.Warn("Failed deleting temporary snapshot for copy", logger.Ctx{"snapshot": srcSnapshot, "err": err})
}
Expand Down Expand Up @@ -773,7 +773,7 @@ func (d *zfs) CreateVolumeFromCopy(vol VolumeCopy, srcVol VolumeCopy, allowIncon
}

// Delete the snapshot.
_, err = shared.RunCommand("zfs", "destroy", "-r", d.dataset(vol.Volume, false)+"@"+snapName)
_, err = shared.RunCommandContext(d.state.ShutdownCtx, "zfs", "destroy", "-r", d.dataset(vol.Volume, false)+"@"+snapName)
if err != nil {
return err
}
Expand All @@ -795,7 +795,7 @@ func (d *zfs) CreateVolumeFromCopy(vol VolumeCopy, srcVol VolumeCopy, allowIncon
}

// Delete the rest.
_, err := shared.RunCommand("zfs", "destroy", d.dataset(vol.Volume, false)+entry)
_, err := shared.RunCommandContext(d.state.ShutdownCtx, "zfs", "destroy", d.dataset(vol.Volume, false)+entry)
if err != nil {
return err
}
Expand All @@ -813,7 +813,7 @@ func (d *zfs) CreateVolumeFromCopy(vol VolumeCopy, srcVol VolumeCopy, allowIncon
args = append(args, srcSnapshot, d.dataset(vol.Volume, false))

// Clone the snapshot.
_, err := shared.RunCommand("zfs", args...)
_, err := shared.RunCommandContext(d.state.ShutdownCtx, "zfs", args...)
if err != nil {
return err
}
Expand Down Expand Up @@ -1138,15 +1138,15 @@ func (d *zfs) createVolumeFromMigrationOptimized(vol Volume, conn io.ReadWriteCl

if volTargetArgs.Refresh {
// Only delete the latest migration snapshot.
_, err := shared.RunCommand("zfs", "destroy", "-r", d.dataset(vol, false)+entries[len(entries)-1])
_, err := shared.RunCommandContext(d.state.ShutdownCtx, "zfs", "destroy", "-r", d.dataset(vol, false)+entries[len(entries)-1])
if err != nil {
return err
}
} else {
// Remove any snapshots that were transferred but are not needed.
for _, entry := range entries {
if !keepDataset(entry) {
_, err := shared.RunCommand("zfs", "destroy", d.dataset(vol, false)+entry)
_, err := shared.RunCommandContext(d.state.ShutdownCtx, "zfs", "destroy", d.dataset(vol, false)+entry)
if err != nil {
return err
}
Expand Down Expand Up @@ -1507,7 +1507,7 @@ func (d *zfs) deleteVolume(vol Volume, op *operations.Operation) error {

if len(clones) > 0 {
// Move to the deleted path.
_, err := shared.RunCommand("/proc/self/exe", "forkzfs", "--", "rename", d.dataset(vol, false), d.dataset(vol, true))
_, err := shared.RunCommandContext(d.state.ShutdownCtx, "/proc/self/exe", "forkzfs", "--", "rename", d.dataset(vol, false), d.dataset(vol, true))
if err != nil {
return err
}
Expand Down Expand Up @@ -1968,7 +1968,7 @@ func (d *zfs) getVolumeDiskPathFromDataset(dataset string) (string, error) {

// Resolve the dataset path.
entryPath := filepath.Join("/dev", entryName)
output, err := shared.RunCommand(zvolid, entryPath)
output, err := shared.RunCommandContext(d.state.ShutdownCtx, zvolid, entryPath)
if err != nil {
continue
}
Expand Down Expand Up @@ -2410,13 +2410,13 @@ func (d *zfs) RenameVolume(vol Volume, newVolName string, op *operations.Operati
})

// Rename the ZFS datasets.
_, err = shared.RunCommand("zfs", "rename", d.dataset(vol, false), d.dataset(newVol, false))
_, err = shared.RunCommandContext(d.state.ShutdownCtx, "zfs", "rename", d.dataset(vol, false), d.dataset(newVol, false))
if err != nil {
return err
}

revert.Add(func() {
_, _ = shared.RunCommand("zfs", "rename", d.dataset(newVol, false), d.dataset(vol, false))
_, _ = shared.RunCommandContext(d.state.ShutdownCtx, "zfs", "rename", d.dataset(newVol, false), d.dataset(vol, false))
})

// Ensure the volume has correct mountpoint settings.
Expand Down Expand Up @@ -2674,14 +2674,14 @@ func (d *zfs) migrateVolumeOptimized(vol Volume, conn io.ReadWriteCloser, volSrc
if !vol.IsSnapshot() {
// Create a temporary read-only snapshot.
srcSnapshot = d.dataset(vol, false) + "@migration-" + uuid.New().String()
_, err := shared.RunCommand("zfs", "snapshot", "-r", srcSnapshot)
_, err := shared.RunCommandContext(d.state.ShutdownCtx, "zfs", "snapshot", "-r", srcSnapshot)
if err != nil {
return err
}

defer func() {
// Delete snapshot (or mark for deferred deletion if cannot be deleted currently).
_, err := shared.RunCommand("zfs", "destroy", "-r", "-d", srcSnapshot)
_, err := shared.RunCommandContext(d.state.ShutdownCtx, "zfs", "destroy", "-r", "-d", srcSnapshot)
if err != nil {
d.logger.Warn("Failed deleting temporary snapshot for migration", logger.Ctx{"snapshot": srcSnapshot, "err": err})
}
Expand Down Expand Up @@ -2738,14 +2738,14 @@ func (d *zfs) readonlySnapshot(vol Volume) (string, revert.Hook, error) {
snapshotDataset := d.dataset(vol, false) + "@" + snapshotOnlyName

// Create a temporary snapshot.
_, err = shared.RunCommand("zfs", "snapshot", "-r", snapshotDataset)
_, err = shared.RunCommandContext(d.state.ShutdownCtx, "zfs", "snapshot", "-r", snapshotDataset)
if err != nil {
return "", nil, err
}

revert.Add(func() {
// Delete snapshot (or mark for deferred deletion if cannot be deleted currently).
_, err := shared.RunCommand("zfs", "destroy", "-r", "-d", snapshotDataset)
_, err := shared.RunCommandContext(d.state.ShutdownCtx, "zfs", "destroy", "-r", "-d", snapshotDataset)
if err != nil {
d.logger.Warn("Failed deleting read-only snapshot", logger.Ctx{"snapshot": snapshotDataset, "err": err})
}
Expand Down Expand Up @@ -2895,14 +2895,14 @@ func (d *zfs) BackupVolume(vol VolumeCopy, tarWriter *instancewriter.InstanceTar

// Create a temporary read-only snapshot.
srcSnapshot := d.dataset(vol.Volume, false) + "@backup-" + uuid.New().String()
_, err := shared.RunCommand("zfs", "snapshot", "-r", srcSnapshot)
_, err := shared.RunCommandContext(d.state.ShutdownCtx, "zfs", "snapshot", "-r", srcSnapshot)
if err != nil {
return err
}

defer func() {
// Delete snapshot (or mark for deferred deletion if cannot be deleted currently).
_, err := shared.RunCommand("zfs", "destroy", "-r", "-d", srcSnapshot)
_, err := shared.RunCommandContext(d.state.ShutdownCtx, "zfs", "destroy", "-r", "-d", srcSnapshot)
if err != nil {
d.logger.Warn("Failed deleting temporary snapshot for backup", logger.Ctx{"snapshot": srcSnapshot, "err": err})
}
Expand Down Expand Up @@ -2949,7 +2949,7 @@ func (d *zfs) CreateVolumeSnapshot(vol Volume, op *operations.Operation) error {
}

// Make the snapshot.
_, err = shared.RunCommand("zfs", "snapshot", "-r", d.dataset(vol, false))
_, err = shared.RunCommandContext(d.state.ShutdownCtx, "zfs", "snapshot", "-r", d.dataset(vol, false))
if err != nil {
return err
}
Expand Down Expand Up @@ -2985,13 +2985,13 @@ func (d *zfs) DeleteVolumeSnapshot(vol Volume, op *operations.Operation) error {

if len(clones) > 0 {
// Move to the deleted path.
_, err := shared.RunCommand("zfs", "rename", d.dataset(vol, false), d.dataset(vol, true))
_, err := shared.RunCommandContext(d.state.ShutdownCtx, "zfs", "rename", d.dataset(vol, false), d.dataset(vol, true))
if err != nil {
return err
}
} else {
// Delete the snapshot.
_, err := shared.RunCommand("zfs", "destroy", "-r", d.dataset(vol, false))
_, err := shared.RunCommandContext(d.state.ShutdownCtx, "zfs", "destroy", "-r", d.dataset(vol, false))
if err != nil {
return err
}
Expand Down Expand Up @@ -3132,7 +3132,7 @@ func (d *zfs) mountVolumeSnapshot(snapVol Volume, snapshotDataset string, mountP
dataset = parentDataset + "_" + snapshotOnlyName + tmpVolSuffix

// Clone snapshot.
_, err = shared.RunCommand("zfs", "clone", snapshotDataset, dataset)
_, err = shared.RunCommandContext(d.state.ShutdownCtx, "zfs", "clone", snapshotDataset, dataset)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -3412,7 +3412,7 @@ func (d *zfs) restoreVolume(vol Volume, snapVol Volume, migration bool, op *oper
continue
}

_, err = shared.RunCommand("zfs", "rollback", d.dataset(vol, false)+dataset)
_, err = shared.RunCommandContext(d.state.ShutdownCtx, "zfs", "rollback", d.dataset(vol, false)+dataset)
if err != nil {
return err
}
Expand Down Expand Up @@ -3471,13 +3471,13 @@ func (d *zfs) RenameVolumeSnapshot(vol Volume, newSnapshotName string, op *opera
})

// Rename the ZFS datasets.
_, err = shared.RunCommand("zfs", "rename", d.dataset(vol, false), d.dataset(newVol, false))
_, err = shared.RunCommandContext(d.state.ShutdownCtx, "zfs", "rename", d.dataset(vol, false), d.dataset(newVol, false))
if err != nil {
return err
}

revert.Add(func() {
_, _ = shared.RunCommand("zfs", "rename", d.dataset(newVol, false), d.dataset(vol, false))
_, _ = shared.RunCommandContext(d.state.ShutdownCtx, "zfs", "rename", d.dataset(newVol, false), d.dataset(vol, false))
})

// For VM images, create a filesystem volume too.
Expand Down

0 comments on commit 8a73064

Please sign in to comment.