mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-10 00:10:20 +00:00
cephfs: make purgeVolume method of volumeOptions
converted purgeVolume from function to method of volumeOptions. Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
parent
eeec1213cb
commit
34d0ff0d70
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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())
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user