From 34d0ff0d702abe630dbf4de7209f85b1fea5c157 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Wed, 9 Dec 2020 11:31:55 +0530 Subject: [PATCH] cephfs: make purgeVolume method of volumeOptions converted purgeVolume from function to method of volumeOptions. Signed-off-by: Madhu Rajanna --- internal/cephfs/clone.go | 4 ++-- internal/cephfs/controllerserver.go | 4 ++-- internal/cephfs/fsjournal.go | 2 +- internal/cephfs/volume.go | 12 ++++++------ 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/internal/cephfs/clone.go b/internal/cephfs/clone.go index e00c9bf64..bbe897d14 100644 --- a/internal/cephfs/clone.go +++ b/internal/cephfs/clone.go @@ -65,7 +65,7 @@ func createCloneFromSubvolume(ctx context.Context, volID, cloneID volumeID, volO } if cloneErr != nil { - if err = purgeVolume(ctx, cloneID, cr, volOpt, true); err != nil { + if err = volOpt.purgeVolume(ctx, cloneID, cr, true); err != nil { util.ErrorLog(ctx, "failed to delete volume %s: %v", cloneID, err) } if err = parentvolOpt.unprotectSnapshot(ctx, snapshotID, volID); err != nil { @@ -176,7 +176,7 @@ func createCloneFromSnapshot(ctx context.Context, parentVolOpt, volOptions *volu defer func() { if err != nil { if !isCloneRetryError(err) { - if dErr := purgeVolume(ctx, volumeID(vID.FsSubvolName), cr, volOptions, true); dErr != nil { + if dErr := volOptions.purgeVolume(ctx, volumeID(vID.FsSubvolName), cr, true); dErr != nil { util.ErrorLog(ctx, "failed to delete volume %s: %v", vID.FsSubvolName, dErr) } } diff --git a/internal/cephfs/controllerserver.go b/internal/cephfs/controllerserver.go index 9d2c11555..c917647be 100644 --- a/internal/cephfs/controllerserver.go +++ b/internal/cephfs/controllerserver.go @@ -188,7 +188,7 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol // explicitly err = volOptions.resizeVolume(ctx, volumeID(vID.FsSubvolName), volOptions.Size) if err != nil { - purgeErr := purgeVolume(ctx, volumeID(vID.FsSubvolName), cr, volOptions, false) + purgeErr := volOptions.purgeVolume(ctx, volumeID(vID.FsSubvolName), cr, false) if purgeErr != nil { util.ErrorLog(ctx, "failed to delete volume %s: %v", requestName, purgeErr) // All errors other than ErrVolumeNotFound should return an error back to the caller @@ -349,7 +349,7 @@ func (cs *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol } defer cr.DeleteCredentials() - if err = purgeVolume(ctx, volumeID(vID.FsSubvolName), cr, volOptions, false); err != nil { + if err = volOptions.purgeVolume(ctx, volumeID(vID.FsSubvolName), cr, false); err != nil { util.ErrorLog(ctx, "failed to delete volume %s: %v", volID, err) if errors.Is(err, ErrVolumeHasSnapshots) { return nil, status.Error(codes.FailedPrecondition, err.Error()) diff --git a/internal/cephfs/fsjournal.go b/internal/cephfs/fsjournal.go index 4eee49f7e..d96d598ca 100644 --- a/internal/cephfs/fsjournal.go +++ b/internal/cephfs/fsjournal.go @@ -108,7 +108,7 @@ func checkVolExists(ctx context.Context, return nil, ErrClonePending } if cloneState == cephFSCloneFailed { - err = purgeVolume(ctx, volumeID(vid.FsSubvolName), cr, volOptions, true) + err = volOptions.purgeVolume(ctx, volumeID(vid.FsSubvolName), cr, true) if err != nil { util.ErrorLog(ctx, "failed to delete volume %s: %v", vid.FsSubvolName, err) return nil, err diff --git a/internal/cephfs/volume.go b/internal/cephfs/volume.go index f534f7411..2cf1f1dd7 100644 --- a/internal/cephfs/volume.go +++ b/internal/cephfs/volume.go @@ -209,16 +209,16 @@ func (vo *volumeOptions) resizeVolume(ctx context.Context, volID volumeID, bytes return createVolume(ctx, vo, volID, bytesQuota) } -func purgeVolume(ctx context.Context, volID volumeID, cr *util.Credentials, volOptions *volumeOptions, force bool) error { +func (vo *volumeOptions) purgeVolume(ctx context.Context, volID volumeID, cr *util.Credentials, force bool) error { arg := []string{ "fs", "subvolume", "rm", - volOptions.FsName, + vo.FsName, string(volID), "--group_name", - volOptions.SubvolumeGroup, - "-m", volOptions.Monitors, + vo.SubvolumeGroup, + "-m", vo.Monitors, "-c", util.CephConfigPath, "-n", cephEntityClientPrefix + cr.ID, "--keyfile=" + cr.KeyFile, @@ -226,13 +226,13 @@ func purgeVolume(ctx context.Context, volID volumeID, cr *util.Credentials, volO if force { arg = append(arg, "--force") } - if checkSubvolumeHasFeature("snapshot-retention", volOptions.Features) { + if checkSubvolumeHasFeature("snapshot-retention", vo.Features) { arg = append(arg, "--retain-snapshots") } err := execCommandErr(ctx, "ceph", arg...) if err != nil { - util.ErrorLog(ctx, "failed to purge subvolume %s in fs %s: %s", string(volID), volOptions.FsName, err) + util.ErrorLog(ctx, "failed to purge subvolume %s in fs %s: %s", string(volID), vo.FsName, err) if strings.Contains(err.Error(), volumeNotEmpty) { return util.JoinErrors(ErrVolumeHasSnapshots, err) }