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 52984a5
Showing 1 changed file with 65 additions and 35 deletions.
100 changes: 65 additions & 35 deletions lxd/storage/drivers/driver_powerflex_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,64 +171,94 @@ 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()
srcVolID, 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
}
pool, err := client.getStoragePool(d.config["powerflex.pool"])
if err != nil {
return err
}

domain, err := client.getProtectionDomain(pool.ProtectionDomainID)
domain, err := client.getProtectionDomain(pool.ProtectionDomainID)
if err != nil {
return err
}

_, err = client.createVolumeSnapshot(domain.SystemID, srcVolID, d.getVolumeName(vol, ""), "ReadWrite")
if err != nil {
return err
}

revert.Add(func() { _ = d.DeleteVolume(vol, op) })

// 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
}

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

_, err = client.createVolumeSnapshot(domain.SystemID, volumeID, d.getVolumeName(vol, ""), "ReadWrite")
// Copy snapshots.
if len(snapshots) > 0 && copySnapshots {
err := createParentSnapshotDirIfMissing(d.name, vol.volType, vol.name)
if err != nil {
return err
}

revert.Add(func() { _ = d.DeleteVolume(vol, op) })
for _, snap := range snapshots {
srcSnapVol, err := srcVol.NewSnapshot(snap)
if err != nil {
return err
}

_, cleanup, err := d.getMappedDevPath(vol, true)
if err != nil {
return err
}
srcSnapshotID, err := client.getVolumeID(d.getVolumeName(srcSnapVol, ""))
if err != nil {
return err
}

revert.Add(cleanup)
copySnapVol, err := vol.NewSnapshot(snap)
if err != nil {
return err
}

// For VMs, also copy the filesystem volume.
if vol.IsVMBlock() {
srcFSVol := srcVol.NewVMBlockFilesystemVolume()
fsVol := vol.NewVMBlockFilesystemVolume()
err := d.CreateVolumeFromCopy(fsVol, srcFSVol, false, false, op)
copySnapshotID, err := client.createVolumeSnapshot(domain.SystemID, srcVolID, d.getVolumeName(copySnapVol, ""), "ReadWrite")
if err != nil {
return err
}
}

err = postCreateTasks(vol)
if err != nil {
return err
}
revert.Add(func() { _ = d.DeleteVolumeSnapshot(copySnapVol, op) })

revert.Success()
return nil
err = client.overwriteVolume(copySnapshotID, srcSnapshotID)
if err != nil {
return err
}

err = copySnapVol.EnsureMountPath()
if err != nil {
return err
}
}
}

revert.Success()
Expand Down

0 comments on commit 52984a5

Please sign in to comment.