From 52984a5ca8d89607ab994bd5f21e2681e1a891e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20Peliz=C3=A4us?= Date: Mon, 16 Oct 2023 11:53:41 +0200 Subject: [PATCH] rebase: extended volume copy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julian Pelizäus --- .../drivers/driver_powerflex_volumes.go | 100 ++++++++++++------ 1 file changed, 65 insertions(+), 35 deletions(-) diff --git a/lxd/storage/drivers/driver_powerflex_volumes.go b/lxd/storage/drivers/driver_powerflex_volumes.go index 56ce1d3cb9d7..68f25f814c01 100644 --- a/lxd/storage/drivers/driver_powerflex_volumes.go +++ b/lxd/storage/drivers/driver_powerflex_volumes.go @@ -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()