mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-09 16:00:22 +00:00
cephfs: check ENOTEMPTY when removing subvolume
return a proper error message to the user when the subvolume has the snapshots and it cannot be removed until the snapshots on the subvolume have to be deleted. Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
parent
f41cd105c4
commit
89b326c896
@ -343,7 +343,10 @@ func (cs *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol
|
||||
|
||||
if err = purgeVolume(ctx, volumeID(vID.FsSubvolName), cr, volOptions, false); err != nil {
|
||||
util.ErrorLog(ctx, "failed to delete volume %s: %v", volID, err)
|
||||
// All errors other than ErrVolumeNotFound should return an error back to the caller
|
||||
if errors.Is(err, ErrVolumeHasSnapshots) {
|
||||
return nil, status.Error(codes.FailedPrecondition, err.Error())
|
||||
}
|
||||
|
||||
if !errors.Is(err, ErrVolumeNotFound) {
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
@ -31,6 +31,8 @@ const (
|
||||
snapNotFound = "Error ENOENT"
|
||||
// snapProtectionExist is returned when the snapshot is already protected
|
||||
snapProtectionExist = "Error EEXIST"
|
||||
// volumeNotEmpty is returned when the volume is not empty.
|
||||
volumeNotEmpty = "Error ENOTEMPTY"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -56,4 +58,7 @@ var (
|
||||
|
||||
// ErrInvalidCommand is returned when a command is not known to the cluster
|
||||
ErrInvalidCommand = errors.New("invalid command")
|
||||
|
||||
// ErrVolumeHasSnapshots is returned when a subvolume has snapshots.
|
||||
ErrVolumeHasSnapshots = errors.New("volume has snapshots")
|
||||
)
|
||||
|
@ -261,6 +261,9 @@ func purgeVolume(ctx context.Context, volID volumeID, cr *util.Credentials, volO
|
||||
err := execCommandErr(ctx, "ceph", arg...)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to purge subvolume %s(%s) in fs %s", string(volID), err, volOptions.FsName)
|
||||
if strings.Contains(err.Error(), volumeNotEmpty) {
|
||||
return util.JoinErrors(ErrVolumeHasSnapshots, err)
|
||||
}
|
||||
if strings.Contains(err.Error(), volumeNotFound) {
|
||||
return util.JoinErrors(ErrVolumeNotFound, err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user