Skip to content

Commit

Permalink
rebase: extended volume copy
Browse files Browse the repository at this point in the history
Signed-off-by: Julian Pelizäus <[email protected]>
  • Loading branch information
roosterfish committed Oct 16, 2023
1 parent 74b68a3 commit 6ab94c8
Showing 1 changed file with 41 additions and 43 deletions.
84 changes: 41 additions & 43 deletions lxd/storage/drivers/driver_powerflex_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,64 +171,62 @@ func (d *powerflex) CreateVolumeFromCopy(vol Volume, srcVol Volume, copySnapshot
return nil
}

// Retrieve snapshots on the source.
snapshots := []string{}
if !srcVol.IsSnapshot() && copySnapshots {
snapshots, err = d.VolumeSnapshots(srcVol, op)
if err != nil {
return err
}
// Copy volume.
client := d.client()
sourceVolumeID, err := client.getVolumeID(d.getVolumeName(srcVol, ""))
if err != nil {
return err
}

// Copy without snapshots.
if !copySnapshots || len(snapshots) == 0 {
client := d.client()
pool, err := client.getStoragePool(d.config["powerflex.pool"])
if err != nil {
return err
}

domain, err := client.getProtectionDomain(pool.ProtectionDomainID)
if err != nil {
return err
}
// Get raw the volume size in GiB.
// PowerFlex accepts values without unit only.
sizeBytes, err := units.ParseByteSizeString(vol.ConfigSize())
if err != nil {
return err
}

volumeID, err := client.getVolumeID(d.getVolumeName(srcVol, ""))
if err != nil {
return err
}
sizeGiB := sizeBytes / factorGiB
copyVolumeID, err := client.createVolume(d.getVolumeName(vol, ""), sizeGiB, powerFlexVolumeThin, d.config["powerflex.pool"])
if err != nil {
return err
}

_, err = client.createVolumeSnapshot(domain.SystemID, volumeID, d.getVolumeName(vol, ""), "ReadWrite")
if err != nil {
return err
}
revert.Add(func() { _ = d.DeleteVolume(vol, op) })

revert.Add(func() { _ = d.DeleteVolume(vol, op) })
err = client.overwriteVolume(copyVolumeID, sourceVolumeID)
if err != nil {
return err
}

_, cleanup, err := d.getMappedDevPath(vol, true)
// For VMs, also copy the filesystem volume.
if vol.IsVMBlock() {
srcFSVol := srcVol.NewVMBlockFilesystemVolume()
fsVol := vol.NewVMBlockFilesystemVolume()
err := d.CreateVolumeFromCopy(fsVol, srcFSVol, false, false, op)
if err != nil {
return err
}
}

revert.Add(cleanup)

// For VMs, also copy the filesystem volume.
if vol.IsVMBlock() {
srcFSVol := srcVol.NewVMBlockFilesystemVolume()
fsVol := vol.NewVMBlockFilesystemVolume()
err := d.CreateVolumeFromCopy(fsVol, srcFSVol, false, false, op)
if err != nil {
return err
}
}
err = postCreateTasks(vol)
if err != nil {
return err
}

err = postCreateTasks(vol)
// Retrieve snapshots on the source.
snapshots := []string{}
if !srcVol.IsSnapshot() && copySnapshots {
snapshots, err = d.VolumeSnapshots(srcVol, op)
if err != nil {
return err
}
}

revert.Success()
return nil
// In PowerFlex volume snapshots aren't copied alongside its parent volume.
// After creating a new volume and copying the contents, the same process cannot be applied for snapshots
// since PowerFlex does not support content overwrites between different VTrees.
if len(snapshots) > 0 && copySnapshots {
return ErrNotSupported
}

revert.Success()
Expand Down

0 comments on commit 6ab94c8

Please sign in to comment.