rbd: copy encryption configuration in CreateSnapshot

Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2021-03-29 15:18:10 +02:00 committed by mergify[bot]
parent 6b1285d38b
commit 0a046c5b6d

View File

@ -718,7 +718,7 @@ func (cs *ControllerServer) ValidateVolumeCapabilities(ctx context.Context, req
// CreateSnapshot creates the snapshot in backend and stores metadata // CreateSnapshot creates the snapshot in backend and stores metadata
// in store // in store
// TODO: make this function less complex // TODO: make this function less complex
// nolint:gocyclo // complexity needs to be reduced. // nolint:gocyclo,nestif // complexity needs to be reduced.
func (cs *ControllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequest) (*csi.CreateSnapshotResponse, error) { func (cs *ControllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequest) (*csi.CreateSnapshotResponse, error) {
if err := cs.validateSnapshotReq(ctx, req); err != nil { if err := cs.validateSnapshotReq(ctx, req); err != nil {
return nil, err return nil, err
@ -747,12 +747,6 @@ func (cs *ControllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
return nil, err return nil, err
} }
// TODO: re-encrypt snapshot with a new passphrase
if rbdVol.isEncrypted() {
return nil, status.Errorf(codes.Unimplemented, "source Volume %s is encrypted, "+
"snapshotting is not supported currently", rbdVol.VolID)
}
// Check if source volume was created with required image features for snaps // Check if source volume was created with required image features for snaps
if !rbdVol.hasSnapshotFeature() { if !rbdVol.hasSnapshotFeature() {
return nil, status.Errorf(codes.InvalidArgument, "volume(%s) has not snapshot feature(layering)", req.GetSourceVolumeId()) return nil, status.Errorf(codes.InvalidArgument, "volume(%s) has not snapshot feature(layering)", req.GetSourceVolumeId())
@ -801,6 +795,17 @@ func (cs *ControllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
} }
defer vol.Destroy() defer vol.Destroy()
if rbdVol.isEncrypted() {
cryptErr := rbdVol.copyEncryptionConfig(&vol.rbdImage)
if cryptErr != nil {
util.WarningLog(ctx, "failed copy encryption "+
"config for %q: %v", vol.String(),
req.GetName(), cryptErr)
return nil, status.Errorf(codes.Internal,
err.Error())
}
}
err = vol.flattenRbdImage(ctx, cr, false, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth) err = vol.flattenRbdImage(ctx, cr, false, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
switch { switch {
case errors.Is(err, ErrFlattenInProgress): case errors.Is(err, ErrFlattenInProgress):