rbd: copy passphrase for encrypted clones

When a source volume is encrypted, the passphrase needs to be copied and
stored for the newly cloned volume.

Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2021-01-26 16:47:14 +01:00 committed by mergify[bot]
parent 7b332a0184
commit 6b1285d38b

View File

@ -1079,6 +1079,29 @@ func (rv *rbdVolume) cloneRbdImageFromSnapshot(ctx context.Context, pSnapOpts *r
return fmt.Errorf("failed to create rbd clone: %w", err) return fmt.Errorf("failed to create rbd clone: %w", err)
} }
// delete the cloned image if a next step fails
deleteClone := true
defer func() {
if deleteClone {
err = librbd.RemoveImage(rv.ioctx, rv.RbdImageName)
if err != nil {
util.ErrorLog(ctx, "failed to delete temporary image %q: %v", rv.String(), err)
}
}
}()
if pSnapOpts.isEncrypted() {
pSnapOpts.conn = rv.conn.Copy()
err = pSnapOpts.copyEncryptionConfig(&rv.rbdImage)
if err != nil {
return fmt.Errorf("failed to clone encryption config: %w", err)
}
}
// Success! Do not delete the cloned image now :)
deleteClone = false
return nil return nil
} }