diff --git a/internal/cephfs/errors.go b/internal/cephfs/errors.go index 608d91b07..39e8e4fd1 100644 --- a/internal/cephfs/errors.go +++ b/internal/cephfs/errors.go @@ -22,10 +22,8 @@ import ( // Error strings for comparison with CLI errors. const ( - // volumeNotFound is returned when a subvolume is not found in CephFS. - volumeNotFound = "Error ENOENT" // volumeNotEmpty is returned when the volume is not empty. - volumeNotEmpty = "Error ENOTEMPTY" + volumeNotEmpty = "Directory not empty" ) var ( diff --git a/internal/cephfs/volume.go b/internal/cephfs/volume.go index 2cf1f1dd7..4de25c725 100644 --- a/internal/cephfs/volume.go +++ b/internal/cephfs/volume.go @@ -210,33 +210,26 @@ func (vo *volumeOptions) resizeVolume(ctx context.Context, volID volumeID, bytes } func (vo *volumeOptions) purgeVolume(ctx context.Context, volID volumeID, cr *util.Credentials, force bool) error { - arg := []string{ - "fs", - "subvolume", - "rm", - vo.FsName, - string(volID), - "--group_name", - vo.SubvolumeGroup, - "-m", vo.Monitors, - "-c", util.CephConfigPath, - "-n", cephEntityClientPrefix + cr.ID, - "--keyfile=" + cr.KeyFile, - } - if force { - arg = append(arg, "--force") - } - if checkSubvolumeHasFeature("snapshot-retention", vo.Features) { - arg = append(arg, "--retain-snapshots") + fsa, err := vo.conn.GetFSAdmin() + if err != nil { + util.ErrorLog(ctx, "could not get FSAdmin %s:", err) + return err } - err := execCommandErr(ctx, "ceph", arg...) + opt := fsAdmin.SubVolRmFlags{} + opt.Force = force + + if checkSubvolumeHasFeature("snapshot-retention", vo.Features) { + opt.RetainSnapshots = true + } + + err = fsa.RemoveSubVolumeWithFlags(vo.FsName, vo.SubvolumeGroup, string(volID), opt) if err != nil { 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) } - if strings.Contains(err.Error(), volumeNotFound) { + if errors.Is(err, rados.ErrNotFound) { return util.JoinErrors(ErrVolumeNotFound, err) } return err