From 032db78d8a64a283efa20fe8e45ceeb5405e66b5 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Wed, 4 Nov 2020 14:21:22 +0100 Subject: [PATCH] cephfs: make deleteSnapshot() a method of volumeOptions Signed-off-by: Niels de Vos --- internal/cephfs/clone.go | 8 ++++---- internal/cephfs/controllerserver.go | 4 ++-- internal/cephfs/fsjournal.go | 2 +- internal/cephfs/snapshot.go | 10 +++++----- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/internal/cephfs/clone.go b/internal/cephfs/clone.go index 2350d4e61..dc2b32b39 100644 --- a/internal/cephfs/clone.go +++ b/internal/cephfs/clone.go @@ -58,7 +58,7 @@ func createCloneFromSubvolume(ctx context.Context, volID, cloneID volumeID, volO ) defer func() { if protectErr != nil { - err = deleteSnapshot(ctx, parentvolOpt, cr, snapshotID, volID) + err = parentvolOpt.deleteSnapshot(ctx, cr, snapshotID, volID) if err != nil { util.ErrorLog(ctx, "failed to delete snapshot %s %v", snapshotID, err) } @@ -76,7 +76,7 @@ func createCloneFromSubvolume(ctx context.Context, volID, cloneID volumeID, volO util.ErrorLog(ctx, "failed to unprotect snapshot %s %v", snapshotID, err) } } - if err = deleteSnapshot(ctx, parentvolOpt, cr, snapshotID, volID); err != nil { + if err = parentvolOpt.deleteSnapshot(ctx, cr, snapshotID, volID); err != nil { util.ErrorLog(ctx, "failed to delete snapshot %s %v", snapshotID, err) } } @@ -126,7 +126,7 @@ func createCloneFromSubvolume(ctx context.Context, volID, cloneID volumeID, volO return err } } - if err = deleteSnapshot(ctx, parentvolOpt, cr, snapshotID, volID); err != nil { + if err = parentvolOpt.deleteSnapshot(ctx, cr, snapshotID, volID); err != nil { util.ErrorLog(ctx, "failed to delete snapshot %s %v", snapshotID, err) return err } @@ -153,7 +153,7 @@ func cleanupCloneFromSubvolumeSnapshot(ctx context.Context, volID, cloneID volum return err } } - err = deleteSnapshot(ctx, parentVolOpt, cr, snapShotID, volID) + err = parentVolOpt.deleteSnapshot(ctx, cr, snapShotID, volID) if err != nil { util.ErrorLog(ctx, "failed to delete snapshot %s %v", snapShotID, err) return err diff --git a/internal/cephfs/controllerserver.go b/internal/cephfs/controllerserver.go index 3d2607aa5..978d397ce 100644 --- a/internal/cephfs/controllerserver.go +++ b/internal/cephfs/controllerserver.go @@ -594,7 +594,7 @@ func doSnapshot(ctx context.Context, volOpt *volumeOptions, subvolumeName, snaps } defer func() { if err != nil { - dErr := deleteSnapshot(ctx, volOpt, cr, snapID, volID) + dErr := volOpt.deleteSnapshot(ctx, cr, snapID, volID) if dErr != nil { util.ErrorLog(ctx, "failed to delete snapshot %s %v", snapID, err) } @@ -711,7 +711,7 @@ func (cs *ControllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteS return nil, status.Error(codes.Internal, err.Error()) } } - err = deleteSnapshot(ctx, volOpt, cr, volumeID(sid.FsSnapshotName), volumeID(sid.FsSubvolName)) + err = volOpt.deleteSnapshot(ctx, cr, volumeID(sid.FsSnapshotName), volumeID(sid.FsSubvolName)) if err != nil { return nil, status.Error(codes.Internal, err.Error()) } diff --git a/internal/cephfs/fsjournal.go b/internal/cephfs/fsjournal.go index 9e3280d2a..0fcda2c31 100644 --- a/internal/cephfs/fsjournal.go +++ b/internal/cephfs/fsjournal.go @@ -354,7 +354,7 @@ func checkSnapExists( defer func() { if err != nil { - err = deleteSnapshot(ctx, volOptions, cr, volumeID(snapID), volumeID(parentSubVolName)) + err = volOptions.deleteSnapshot(ctx, cr, volumeID(snapID), volumeID(parentSubVolName)) if err != nil { util.ErrorLog(ctx, "failed to delete snapshot %s: %v", snapID, err) return diff --git a/internal/cephfs/snapshot.go b/internal/cephfs/snapshot.go index 8fca42140..5429e61aa 100644 --- a/internal/cephfs/snapshot.go +++ b/internal/cephfs/snapshot.go @@ -61,18 +61,18 @@ func (vo *volumeOptions) createSnapshot(ctx context.Context, snapID, volID volum return nil } -func deleteSnapshot(ctx context.Context, volOptions *volumeOptions, cr *util.Credentials, snapID, volID volumeID) error { +func (vo *volumeOptions) deleteSnapshot(ctx context.Context, cr *util.Credentials, snapID, volID volumeID) error { args := []string{ "fs", "subvolume", "snapshot", "rm", - volOptions.FsName, + vo.FsName, string(volID), string(snapID), "--group_name", - volOptions.SubvolumeGroup, - "-m", volOptions.Monitors, + vo.SubvolumeGroup, + "-m", vo.Monitors, "-c", util.CephConfigPath, "-n", cephEntityClientPrefix + cr.ID, "--keyfile=" + cr.KeyFile, @@ -84,7 +84,7 @@ func deleteSnapshot(ctx context.Context, volOptions *volumeOptions, cr *util.Cre "ceph", args[:]...) if err != nil { - util.ErrorLog(ctx, "failed to delete subvolume snapshot %s %s(%s) in fs %s", string(snapID), string(volID), err, volOptions.FsName) + util.ErrorLog(ctx, "failed to delete subvolume snapshot %s %s(%s) in fs %s", string(snapID), string(volID), err, vo.FsName) return err } return nil