From 6e24b10364355916751e0f8376c1deca527ae575 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Tue, 2 Jun 2020 10:02:02 +0200 Subject: [PATCH] util: implement RemoveObject() with go-ceph Signed-off-by: Niels de Vos --- internal/util/cephcmds.go | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/internal/util/cephcmds.go b/internal/util/cephcmds.go index 45d67abd5..0e9790994 100644 --- a/internal/util/cephcmds.go +++ b/internal/util/cephcmds.go @@ -249,27 +249,31 @@ func CreateObject(ctx context.Context, monitors string, cr *Credentials, poolNam // RemoveObject removes the entire omap name passed in and returns ErrObjectNotFound is provided omap // is not found in rados func RemoveObject(ctx context.Context, monitors string, cr *Credentials, poolName, namespace, oMapName string) error { - // Command: "rados rm oMapName" - args := []string{ - "-m", monitors, - "--id", cr.ID, - "--keyfile=" + cr.KeyFile, - "-c", CephConfigPath, - "-p", poolName, - "rm", oMapName, + conn := ClusterConnection{} + err := conn.Connect(monitors, cr) + if err != nil { + return err } + defer conn.Destroy() + + ioctx, err := conn.GetIoctx(poolName) + if err != nil { + if _, ok := err.(ErrPoolNotFound); ok { + err = ErrObjectNotFound{poolName, err} + } + return err + } + defer ioctx.Destroy() if namespace != "" { - args = append(args, "--namespace="+namespace) + ioctx.SetNamespace(namespace) } - _, stderr, err := ExecCommand("rados", args[:]...) - if err != nil { + err = ioctx.Delete(oMapName) + if err == rados.ErrNotFound { + return ErrObjectNotFound{oMapName, err} + } else if err != nil { klog.Errorf(Log(ctx, "failed removing omap (%s) in pool (%s): (%v)"), oMapName, poolName, err) - if strings.Contains(string(stderr), "error removing "+poolName+">"+oMapName+ - ": (2) No such file or directory") { - return ErrObjectNotFound{oMapName, err} - } return err }