diff --git a/internal/cephfs/clone.go b/internal/cephfs/clone.go index 33fa25e1e..f725a6b45 100644 --- a/internal/cephfs/clone.go +++ b/internal/cephfs/clone.go @@ -87,7 +87,7 @@ func createCloneFromSubvolume(ctx context.Context, volID, cloneID volumeID, volO return protectErr } - cloneErr = cloneSnapshot(ctx, parentvolOpt, cr, volID, snapshotID, cloneID, volOpt) + cloneErr = parentvolOpt.cloneSnapshot(ctx, volID, snapshotID, cloneID, volOpt) if cloneErr != nil { util.ErrorLog(ctx, "failed to clone snapshot %s %s to %s %v", volID, snapshotID, cloneID, cloneErr) return cloneErr @@ -169,7 +169,7 @@ func isCloneRetryError(err error) bool { func createCloneFromSnapshot(ctx context.Context, parentVolOpt, volOptions *volumeOptions, vID *volumeIdentifier, sID *snapshotIdentifier, cr *util.Credentials) error { snapID := volumeID(sID.FsSnapshotName) - err := cloneSnapshot(ctx, parentVolOpt, cr, volumeID(sID.FsSubvolName), snapID, volumeID(vID.FsSubvolName), volOptions) + err := parentVolOpt.cloneSnapshot(ctx, volumeID(sID.FsSubvolName), snapID, volumeID(vID.FsSubvolName), volOptions) if err != nil { return err } diff --git a/internal/cephfs/snapshot.go b/internal/cephfs/snapshot.go index 88cd7790a..5c5823f35 100644 --- a/internal/cephfs/snapshot.go +++ b/internal/cephfs/snapshot.go @@ -22,8 +22,9 @@ import ( "strings" "github.com/ceph/ceph-csi/internal/util" - "github.com/ceph/go-ceph/rados" + "github.com/ceph/go-ceph/cephfs/admin" + "github.com/ceph/go-ceph/rados" "github.com/golang/protobuf/ptypes/timestamp" ) @@ -171,37 +172,23 @@ func (vo *volumeOptions) unprotectSnapshot(ctx context.Context, snapID, volID vo return nil } -func cloneSnapshot(ctx context.Context, parentVolOptions *volumeOptions, cr *util.Credentials, volID, snapID, cloneID volumeID, cloneVolOptions *volumeOptions) error { - args := []string{ - "fs", - "subvolume", - "snapshot", - "clone", - parentVolOptions.FsName, - string(volID), - string(snapID), - string(cloneID), - "--group_name", - parentVolOptions.SubvolumeGroup, - "--target_group_name", - cloneVolOptions.SubvolumeGroup, - "-m", parentVolOptions.Monitors, - "-c", util.CephConfigPath, - "-n", cephEntityClientPrefix + cr.ID, - "--keyfile=" + cr.KeyFile, +func (vo *volumeOptions) cloneSnapshot(ctx context.Context, volID, snapID, cloneID volumeID, cloneVolOptions *volumeOptions) error { + fsa, err := vo.conn.GetFSAdmin() + if err != nil { + util.ErrorLog(ctx, "could not get FSAdmin: %s", err) + return err + } + co := &admin.CloneOptions{ + TargetGroup: cloneVolOptions.SubvolumeGroup, } if cloneVolOptions.Pool != "" { - args = append(args, "--pool_layout", cloneVolOptions.Pool) + co.PoolLayout = cloneVolOptions.Pool } - err := execCommandErr( - ctx, - "ceph", - args[:]...) - + err = fsa.CloneSubVolumeSnapshot(vo.FsName, vo.SubvolumeGroup, string(volID), string(snapID), string(cloneID), co) if err != nil { - util.ErrorLog(ctx, "failed to clone subvolume snapshot %s %s(%s) in fs %s", string(cloneID), string(volID), err, parentVolOptions.FsName) - if strings.HasPrefix(err.Error(), volumeNotFound) { + util.ErrorLog(ctx, "failed to clone subvolume snapshot %s %s in fs %s with error: %s", string(volID), string(snapID), string(cloneID), vo.FsName, err) + if errors.Is(err, rados.ErrNotFound) { return ErrVolumeNotFound } return err