cephfs: implement purgeVolume with go-ceph

moved frm  ceph fs CLI to go-ceph for
purgeVolume.

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna 2020-12-09 11:59:10 +05:30 committed by mergify[bot]
parent 34d0ff0d70
commit 9a96370942
2 changed files with 14 additions and 23 deletions

View File

@ -22,10 +22,8 @@ import (
// Error strings for comparison with CLI errors. // Error strings for comparison with CLI errors.
const ( 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 is returned when the volume is not empty.
volumeNotEmpty = "Error ENOTEMPTY" volumeNotEmpty = "Directory not empty"
) )
var ( var (

View File

@ -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 { func (vo *volumeOptions) purgeVolume(ctx context.Context, volID volumeID, cr *util.Credentials, force bool) error {
arg := []string{ fsa, err := vo.conn.GetFSAdmin()
"fs", if err != nil {
"subvolume", util.ErrorLog(ctx, "could not get FSAdmin %s:", err)
"rm", return err
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")
} }
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 { if err != nil {
util.ErrorLog(ctx, "failed to purge subvolume %s in fs %s: %s", string(volID), vo.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)
} }
if strings.Contains(err.Error(), volumeNotFound) { if errors.Is(err, rados.ErrNotFound) {
return util.JoinErrors(ErrVolumeNotFound, err) return util.JoinErrors(ErrVolumeNotFound, err)
} }
return err return err