mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-26 08: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 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)
|
util.ErrorLog(ctx, "failed to delete volume %s: %v", cloneID, err)
|
||||||
}
|
}
|
||||||
if err = parentvolOpt.unprotectSnapshot(ctx, snapshotID, volID); err != nil {
|
if err = parentvolOpt.unprotectSnapshot(ctx, snapshotID, volID); err != nil {
|
||||||
@ -176,7 +176,7 @@ func createCloneFromSnapshot(ctx context.Context, parentVolOpt, volOptions *volu
|
|||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !isCloneRetryError(err) {
|
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)
|
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
|
// explicitly
|
||||||
err = volOptions.resizeVolume(ctx, volumeID(vID.FsSubvolName), volOptions.Size)
|
err = volOptions.resizeVolume(ctx, volumeID(vID.FsSubvolName), volOptions.Size)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
purgeErr := purgeVolume(ctx, volumeID(vID.FsSubvolName), cr, volOptions, false)
|
purgeErr := volOptions.purgeVolume(ctx, volumeID(vID.FsSubvolName), cr, false)
|
||||||
if purgeErr != nil {
|
if purgeErr != nil {
|
||||||
util.ErrorLog(ctx, "failed to delete volume %s: %v", requestName, purgeErr)
|
util.ErrorLog(ctx, "failed to delete volume %s: %v", requestName, purgeErr)
|
||||||
// All errors other than ErrVolumeNotFound should return an error back to the caller
|
// 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()
|
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)
|
util.ErrorLog(ctx, "failed to delete volume %s: %v", volID, err)
|
||||||
if errors.Is(err, ErrVolumeHasSnapshots) {
|
if errors.Is(err, ErrVolumeHasSnapshots) {
|
||||||
return nil, status.Error(codes.FailedPrecondition, err.Error())
|
return nil, status.Error(codes.FailedPrecondition, err.Error())
|
||||||
|
@ -108,7 +108,7 @@ func checkVolExists(ctx context.Context,
|
|||||||
return nil, ErrClonePending
|
return nil, ErrClonePending
|
||||||
}
|
}
|
||||||
if cloneState == cephFSCloneFailed {
|
if cloneState == cephFSCloneFailed {
|
||||||
err = purgeVolume(ctx, volumeID(vid.FsSubvolName), cr, volOptions, true)
|
err = volOptions.purgeVolume(ctx, volumeID(vid.FsSubvolName), cr, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.ErrorLog(ctx, "failed to delete volume %s: %v", vid.FsSubvolName, err)
|
util.ErrorLog(ctx, "failed to delete volume %s: %v", vid.FsSubvolName, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -209,16 +209,16 @@ func (vo *volumeOptions) resizeVolume(ctx context.Context, volID volumeID, bytes
|
|||||||
return createVolume(ctx, vo, volID, bytesQuota)
|
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{
|
arg := []string{
|
||||||
"fs",
|
"fs",
|
||||||
"subvolume",
|
"subvolume",
|
||||||
"rm",
|
"rm",
|
||||||
volOptions.FsName,
|
vo.FsName,
|
||||||
string(volID),
|
string(volID),
|
||||||
"--group_name",
|
"--group_name",
|
||||||
volOptions.SubvolumeGroup,
|
vo.SubvolumeGroup,
|
||||||
"-m", volOptions.Monitors,
|
"-m", vo.Monitors,
|
||||||
"-c", util.CephConfigPath,
|
"-c", util.CephConfigPath,
|
||||||
"-n", cephEntityClientPrefix + cr.ID,
|
"-n", cephEntityClientPrefix + cr.ID,
|
||||||
"--keyfile=" + cr.KeyFile,
|
"--keyfile=" + cr.KeyFile,
|
||||||
@ -226,13 +226,13 @@ func purgeVolume(ctx context.Context, volID volumeID, cr *util.Credentials, volO
|
|||||||
if force {
|
if force {
|
||||||
arg = append(arg, "--force")
|
arg = append(arg, "--force")
|
||||||
}
|
}
|
||||||
if checkSubvolumeHasFeature("snapshot-retention", volOptions.Features) {
|
if checkSubvolumeHasFeature("snapshot-retention", vo.Features) {
|
||||||
arg = append(arg, "--retain-snapshots")
|
arg = append(arg, "--retain-snapshots")
|
||||||
}
|
}
|
||||||
|
|
||||||
err := execCommandErr(ctx, "ceph", arg...)
|
err := execCommandErr(ctx, "ceph", arg...)
|
||||||
if err != nil {
|
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) {
|
if strings.Contains(err.Error(), volumeNotEmpty) {
|
||||||
return util.JoinErrors(ErrVolumeHasSnapshots, err)
|
return util.JoinErrors(ErrVolumeHasSnapshots, err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user