Skip to content

Commit

Permalink
lxd/storage/drivers: Simplify early return in 'copyThinpoolVolume'
Browse files Browse the repository at this point in the history
Signed-off-by: Kadin Sayani <[email protected]>
  • Loading branch information
kadinsayani committed Oct 7, 2024
1 parent 0dc112b commit 09b040b
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions lxd/storage/drivers/driver_lvm_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,27 +590,27 @@ func (d *lvm) copyThinpoolVolume(vol, srcVol Volume, srcSnapshots []string, refr
}

if volExists {
if refresh {
newVolDevPath := d.lvmDevPath(d.config["lvm.vg_name"], vol.volType, vol.contentType, vol.name)
tmpVolName := fmt.Sprintf("%s%s", vol.name, tmpVolSuffix)
tmpVolDevPath := d.lvmDevPath(d.config["lvm.vg_name"], vol.volType, vol.contentType, tmpVolName)

// Rename existing volume to temporary new name so we can revert if needed.
err := d.renameLogicalVolume(newVolDevPath, tmpVolDevPath)
if err != nil {
return fmt.Errorf("Error temporarily renaming original LVM logical volume: %w", err)
}
if !refresh {
return fmt.Errorf("LVM volume already exists %q", vol.name)
}

// Record this volume to be removed at the very end.
removeVols = append(removeVols, tmpVolName)
newVolDevPath := d.lvmDevPath(d.config["lvm.vg_name"], vol.volType, vol.contentType, vol.name)
tmpVolName := fmt.Sprintf("%s%s", vol.name, tmpVolSuffix)
tmpVolDevPath := d.lvmDevPath(d.config["lvm.vg_name"], vol.volType, vol.contentType, tmpVolName)

revert.Add(func() {
// Rename the original volume back to the original name.
_ = d.renameLogicalVolume(tmpVolDevPath, newVolDevPath)
})
} else {
return fmt.Errorf("LVM volume already exists %q", vol.name)
// Rename existing volume to temporary new name so we can revert if needed.
err := d.renameLogicalVolume(newVolDevPath, tmpVolDevPath)
if err != nil {
return fmt.Errorf("Error temporarily renaming original LVM logical volume: %w", err)
}

// Record this volume to be removed at the very end.
removeVols = append(removeVols, tmpVolName)

revert.Add(func() {
// Rename the original volume back to the original name.
_ = d.renameLogicalVolume(tmpVolDevPath, newVolDevPath)
})
} else {
volPath := vol.MountPath()
err := vol.EnsureMountPath()
Expand Down

0 comments on commit 09b040b

Please sign in to comment.