mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-22 22:30:23 +00:00
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:
parent
814bf4459a
commit
ddf91de859
@ -87,7 +87,7 @@ func createCloneFromSubvolume(ctx context.Context, volID, cloneID volumeID, volO
|
|||||||
return protectErr
|
return protectErr
|
||||||
}
|
}
|
||||||
|
|
||||||
cloneErr = cloneSnapshot(ctx, parentvolOpt, cr, volID, snapshotID, cloneID, volOpt)
|
cloneErr = parentvolOpt.cloneSnapshot(ctx, volID, snapshotID, cloneID, volOpt)
|
||||||
if cloneErr != nil {
|
if cloneErr != nil {
|
||||||
util.ErrorLog(ctx, "failed to clone snapshot %s %s to %s %v", volID, snapshotID, cloneID, cloneErr)
|
util.ErrorLog(ctx, "failed to clone snapshot %s %s to %s %v", volID, snapshotID, cloneID, cloneErr)
|
||||||
return 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 {
|
func createCloneFromSnapshot(ctx context.Context, parentVolOpt, volOptions *volumeOptions, vID *volumeIdentifier, sID *snapshotIdentifier, cr *util.Credentials) error {
|
||||||
snapID := volumeID(sID.FsSnapshotName)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,9 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/ceph/ceph-csi/internal/util"
|
"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"
|
"github.com/golang/protobuf/ptypes/timestamp"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -171,37 +172,23 @@ func (vo *volumeOptions) unprotectSnapshot(ctx context.Context, snapID, volID vo
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func cloneSnapshot(ctx context.Context, parentVolOptions *volumeOptions, cr *util.Credentials, volID, snapID, cloneID volumeID, cloneVolOptions *volumeOptions) error {
|
func (vo *volumeOptions) cloneSnapshot(ctx context.Context, volID, snapID, cloneID volumeID, cloneVolOptions *volumeOptions) error {
|
||||||
args := []string{
|
fsa, err := vo.conn.GetFSAdmin()
|
||||||
"fs",
|
if err != nil {
|
||||||
"subvolume",
|
util.ErrorLog(ctx, "could not get FSAdmin: %s", err)
|
||||||
"snapshot",
|
return err
|
||||||
"clone",
|
}
|
||||||
parentVolOptions.FsName,
|
co := &admin.CloneOptions{
|
||||||
string(volID),
|
TargetGroup: cloneVolOptions.SubvolumeGroup,
|
||||||
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,
|
|
||||||
}
|
}
|
||||||
if cloneVolOptions.Pool != "" {
|
if cloneVolOptions.Pool != "" {
|
||||||
args = append(args, "--pool_layout", cloneVolOptions.Pool)
|
co.PoolLayout = cloneVolOptions.Pool
|
||||||
}
|
}
|
||||||
|
|
||||||
err := execCommandErr(
|
err = fsa.CloneSubVolumeSnapshot(vo.FsName, vo.SubvolumeGroup, string(volID), string(snapID), string(cloneID), co)
|
||||||
ctx,
|
|
||||||
"ceph",
|
|
||||||
args[:]...)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.ErrorLog(ctx, "failed to clone subvolume snapshot %s %s(%s) in fs %s", string(cloneID), string(volID), err, parentVolOptions.FsName)
|
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 strings.HasPrefix(err.Error(), volumeNotFound) {
|
if errors.Is(err, rados.ErrNotFound) {
|
||||||
return ErrVolumeNotFound
|
return ErrVolumeNotFound
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user