cephfs: implement clonesnapshot with go-ceph

updated ceph fs CLI implementaion of cloning
with go-ceph.

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna 2020-12-02 16:12:56 +05:30 committed by mergify[bot]
parent 814bf4459a
commit ddf91de859
2 changed files with 16 additions and 29 deletions

View File

@ -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
}

View File

@ -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