From 3e7fa93256c09f07d28f77521f51d3a050f21ad2 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Wed, 24 Jun 2020 12:07:53 +0530 Subject: [PATCH] rbd: Remove protect and unprotect function As we are using v2 cloning we dont need to do protect the snapshot before cloning and unprotect it before deleting. Signed-off-by: Madhu Rajanna --- internal/rbd/controllerserver.go | 25 ------------------------- internal/rbd/rbd_util.go | 30 ------------------------------ 2 files changed, 55 deletions(-) diff --git a/internal/rbd/controllerserver.go b/internal/rbd/controllerserver.go index 060399e33..82adfe4e3 100644 --- a/internal/rbd/controllerserver.go +++ b/internal/rbd/controllerserver.go @@ -641,23 +641,6 @@ func (cs *ControllerServer) doSnapshot(ctx context.Context, rbdSnap *rbdSnapshot err = status.Error(codes.Internal, err.Error()) } }() - err = protectSnapshot(ctx, rbdSnap, cr) - if err != nil { - klog.Errorf(util.Log(ctx, "failed to protect snapshot: %v"), err) - return status.Error(codes.Internal, err.Error()) - } - defer func() { - if err != nil { - errDefer := unprotectSnapshot(ctx, rbdSnap, cr) - if errDefer != nil { - klog.Errorf(util.Log(ctx, "failed to unprotect snapshot: %v"), errDefer) - err = fmt.Errorf("snapshot created but failed to unprotect snapshot due to"+ - " other failures: %v", err) - } - err = status.Error(codes.Internal, err.Error()) - } - }() - err = getSnapshotMetadata(ctx, rbdSnap, cr) if err != nil { klog.Errorf(util.Log(ctx, "failed to fetch snapshot metadata: %v"), err) @@ -736,14 +719,6 @@ func (cs *ControllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteS } defer cs.SnapshotLocks.Release(rbdSnap.RequestName) - // Unprotect snapshot - err = unprotectSnapshot(ctx, rbdSnap, cr) - if err != nil { - return nil, status.Errorf(codes.FailedPrecondition, - "failed to unprotect snapshot: %s with error: %v", - rbdSnap, err) - } - // Deleting snapshot klog.V(4).Infof(util.Log(ctx, "deleting Snaphot %s"), rbdSnap) if err := deleteSnapshot(ctx, rbdSnap, cr); err != nil { diff --git a/internal/rbd/rbd_util.go b/internal/rbd/rbd_util.go index bdf45c6af..eac5d834e 100644 --- a/internal/rbd/rbd_util.go +++ b/internal/rbd/rbd_util.go @@ -696,21 +696,6 @@ func (rv *rbdVolume) hasSnapshotFeature() bool { return (uint64(rv.imageFeatureSet) & librbd.FeatureLayering) == librbd.FeatureLayering } -func protectSnapshot(ctx context.Context, pOpts *rbdSnapshot, cr *util.Credentials) error { - var output []byte - - klog.V(4).Infof(util.Log(ctx, "rbd: snap protect %s using mon %s"), pOpts, pOpts.Monitors) - args := []string{"snap", "protect", pOpts.String(), "--id", cr.ID, "-m", pOpts.Monitors, "--keyfile=" + cr.KeyFile} - - output, err := execCommand("rbd", args) - - if err != nil { - return errors.Wrapf(err, "failed to protect snapshot, command output: %s", string(output)) - } - - return nil -} - func createSnapshot(ctx context.Context, pOpts *rbdSnapshot, cr *util.Credentials) error { var output []byte @@ -726,21 +711,6 @@ func createSnapshot(ctx context.Context, pOpts *rbdSnapshot, cr *util.Credential return nil } -func unprotectSnapshot(ctx context.Context, pOpts *rbdSnapshot, cr *util.Credentials) error { - var output []byte - - klog.V(4).Infof(util.Log(ctx, "rbd: snap unprotect %s using mon %s"), pOpts, pOpts.Monitors) - args := []string{"snap", "unprotect", pOpts.String(), "--id", cr.ID, "-m", pOpts.Monitors, "--keyfile=" + cr.KeyFile} - - output, err := execCommand("rbd", args) - - if err != nil { - return errors.Wrapf(err, "failed to unprotect snapshot, command output: %s", string(output)) - } - - return nil -} - func deleteSnapshot(ctx context.Context, pOpts *rbdSnapshot, cr *util.Credentials) error { var output []byte