mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-18 11:00:25 +00:00
cephfs: do not export internal CloneStatus type
getCloneInfo() does not need to return a full CloneStatus struct that only has one member. Instead, it can just return the value of the single member, so the JSON type/struct does not need to be exposed. This makes the API for getCloneInfo() a little simpler, so it can be replaced by a go-ceph implementation later on. As the function does not return any of the unused attributes anymore, it is renamed to getCloneStatu() as well. Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
parent
91774fc936
commit
66aa595e77
@ -24,15 +24,21 @@ import (
|
|||||||
"github.com/ceph/ceph-csi/internal/util"
|
"github.com/ceph/ceph-csi/internal/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// cephFSCloneState describes the status of the clone.
|
||||||
|
type cephFSCloneState string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// cephFSCloneError indicates that fetching the clone state returned an error.
|
||||||
|
cephFSCloneError = cephFSCloneState("")
|
||||||
// cephFSCloneFailed indicates that clone is in failed state.
|
// cephFSCloneFailed indicates that clone is in failed state.
|
||||||
cephFSCloneFailed = "failed"
|
cephFSCloneFailed = cephFSCloneState("failed")
|
||||||
// cephFSClonePending indicates that clone is in pending state.
|
// cephFSClonePending indicates that clone is in pending state.
|
||||||
cephFSClonePending = "pending"
|
cephFSClonePending = cephFSCloneState("pending")
|
||||||
// cephFSCloneInprogress indicates that clone is in in-progress state.
|
// cephFSCloneInprogress indicates that clone is in in-progress state.
|
||||||
cephFSCloneInprogress = "in-progress"
|
cephFSCloneInprogress = cephFSCloneState("in-progress")
|
||||||
// cephFSCloneComplete indicates that clone is in complete state.
|
// cephFSCloneComplete indicates that clone is in complete state.
|
||||||
cephFSCloneComplete = "complete"
|
cephFSCloneComplete = cephFSCloneState("complete")
|
||||||
|
|
||||||
// snapshotIsProtected string indicates that the snapshot is currently protected.
|
// snapshotIsProtected string indicates that the snapshot is currently protected.
|
||||||
snapshotIsProtected = "yes"
|
snapshotIsProtected = "yes"
|
||||||
)
|
)
|
||||||
@ -86,13 +92,13 @@ func createCloneFromSubvolume(ctx context.Context, volID, cloneID volumeID, volO
|
|||||||
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
|
||||||
}
|
}
|
||||||
var clone CloneStatus
|
|
||||||
clone, cloneErr = getCloneInfo(ctx, volOpt, cr, cloneID)
|
cloneState, cloneErr := getCloneState(ctx, volOpt, cr, cloneID)
|
||||||
if cloneErr != nil {
|
if cloneErr != nil {
|
||||||
return cloneErr
|
return cloneErr
|
||||||
}
|
}
|
||||||
|
|
||||||
switch clone.Status.State {
|
switch cloneState {
|
||||||
case cephFSCloneInprogress:
|
case cephFSCloneInprogress:
|
||||||
util.ErrorLog(ctx, "clone is in progress for %v", cloneID)
|
util.ErrorLog(ctx, "clone is in progress for %v", cloneID)
|
||||||
return ErrCloneInProgress
|
return ErrCloneInProgress
|
||||||
@ -101,7 +107,7 @@ func createCloneFromSubvolume(ctx context.Context, volID, cloneID volumeID, volO
|
|||||||
return ErrClonePending
|
return ErrClonePending
|
||||||
case cephFSCloneFailed:
|
case cephFSCloneFailed:
|
||||||
util.ErrorLog(ctx, "clone failed for %v", cloneID)
|
util.ErrorLog(ctx, "clone failed for %v", cloneID)
|
||||||
cloneFailedErr := fmt.Errorf("clone %s is in %s state", cloneID, clone.Status.State)
|
cloneFailedErr := fmt.Errorf("clone %s is in %s state", cloneID, cloneState)
|
||||||
return cloneFailedErr
|
return cloneFailedErr
|
||||||
case cephFSCloneComplete:
|
case cephFSCloneComplete:
|
||||||
// This is a work around to fix sizing issue for cloned images
|
// This is a work around to fix sizing issue for cloned images
|
||||||
@ -176,18 +182,19 @@ func createCloneFromSnapshot(ctx context.Context, parentVolOpt, volOptions *volu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
var clone = CloneStatus{}
|
|
||||||
clone, err = getCloneInfo(ctx, volOptions, cr, volumeID(vID.FsSubvolName))
|
cloneState, err := getCloneState(ctx, volOptions, cr, volumeID(vID.FsSubvolName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
switch clone.Status.State {
|
|
||||||
|
switch cloneState {
|
||||||
case cephFSCloneInprogress:
|
case cephFSCloneInprogress:
|
||||||
return ErrCloneInProgress
|
return ErrCloneInProgress
|
||||||
case cephFSClonePending:
|
case cephFSClonePending:
|
||||||
return ErrClonePending
|
return ErrClonePending
|
||||||
case cephFSCloneFailed:
|
case cephFSCloneFailed:
|
||||||
return fmt.Errorf("clone %s is in %s state", vID.FsSubvolName, clone.Status.State)
|
return fmt.Errorf("clone %s is in %s state", vID.FsSubvolName, cloneState)
|
||||||
case cephFSCloneComplete:
|
case cephFSCloneComplete:
|
||||||
// The clonedvolume currently does not reflect the proper size due to an issue in cephfs
|
// The clonedvolume currently does not reflect the proper size due to an issue in cephfs
|
||||||
// however this is getting addressed in cephfs and the parentvolume size will be reflected
|
// however this is getting addressed in cephfs and the parentvolume size will be reflected
|
||||||
@ -201,15 +208,14 @@ func createCloneFromSnapshot(ctx context.Context, parentVolOpt, volOptions *volu
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CloneStatus represents the subvolume clone status.
|
func getCloneState(ctx context.Context, volOptions *volumeOptions, cr *util.Credentials, volID volumeID) (cephFSCloneState, error) {
|
||||||
type CloneStatus struct {
|
type cloneStatus struct {
|
||||||
Status struct {
|
Status struct {
|
||||||
State string `json:"state"`
|
State string `json:"state"`
|
||||||
} `json:"status"`
|
} `json:"status"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func getCloneInfo(ctx context.Context, volOptions *volumeOptions, cr *util.Credentials, volID volumeID) (CloneStatus, error) {
|
cs := cloneStatus{}
|
||||||
clone := CloneStatus{}
|
|
||||||
args := []string{
|
args := []string{
|
||||||
"fs",
|
"fs",
|
||||||
"clone",
|
"clone",
|
||||||
@ -226,12 +232,12 @@ func getCloneInfo(ctx context.Context, volOptions *volumeOptions, cr *util.Crede
|
|||||||
}
|
}
|
||||||
err := execCommandJSON(
|
err := execCommandJSON(
|
||||||
ctx,
|
ctx,
|
||||||
&clone,
|
&cs,
|
||||||
"ceph",
|
"ceph",
|
||||||
args[:]...)
|
args[:]...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.ErrorLog(ctx, "failed to get subvolume clone info %s(%s) in fs %s", string(volID), err, volOptions.FsName)
|
util.ErrorLog(ctx, "failed to get subvolume clone info %s(%s) in fs %s", string(volID), err, volOptions.FsName)
|
||||||
return clone, err
|
return cephFSCloneError, err
|
||||||
}
|
}
|
||||||
return clone, nil
|
return cephFSCloneState(cs.Status.State), nil
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ func checkVolExists(ctx context.Context,
|
|||||||
vid.FsSubvolName = imageData.ImageAttributes.ImageName
|
vid.FsSubvolName = imageData.ImageAttributes.ImageName
|
||||||
|
|
||||||
if sID != nil || pvID != nil {
|
if sID != nil || pvID != nil {
|
||||||
clone, cloneInfoErr := getCloneInfo(ctx, volOptions, cr, volumeID(vid.FsSubvolName))
|
cloneState, cloneInfoErr := getCloneState(ctx, volOptions, cr, volumeID(vid.FsSubvolName))
|
||||||
if cloneInfoErr != nil {
|
if cloneInfoErr != nil {
|
||||||
if errors.Is(cloneInfoErr, ErrVolumeNotFound) {
|
if errors.Is(cloneInfoErr, ErrVolumeNotFound) {
|
||||||
if pvID != nil {
|
if pvID != nil {
|
||||||
@ -102,13 +102,13 @@ func checkVolExists(ctx context.Context,
|
|||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if clone.Status.State == cephFSCloneInprogress {
|
if cloneState == cephFSCloneInprogress {
|
||||||
return nil, ErrCloneInProgress
|
return nil, ErrCloneInProgress
|
||||||
}
|
}
|
||||||
if clone.Status.State == cephFSClonePending {
|
if cloneState == cephFSClonePending {
|
||||||
return nil, ErrClonePending
|
return nil, ErrClonePending
|
||||||
}
|
}
|
||||||
if clone.Status.State == cephFSCloneFailed {
|
if cloneState == cephFSCloneFailed {
|
||||||
err = purgeVolume(ctx, volumeID(vid.FsSubvolName), cr, volOptions, true)
|
err = purgeVolume(ctx, volumeID(vid.FsSubvolName), cr, volOptions, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.ErrorLog(ctx, "failed to delete volume %s: %v", vid.FsSubvolName, err)
|
util.ErrorLog(ctx, "failed to delete volume %s: %v", vid.FsSubvolName, err)
|
||||||
@ -128,7 +128,7 @@ func checkVolExists(ctx context.Context,
|
|||||||
volOptions.MetadataPool, vid.FsSubvolName, volOptions.RequestName)
|
volOptions.MetadataPool, vid.FsSubvolName, volOptions.RequestName)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if clone.Status.State != cephFSCloneComplete {
|
if cloneState != cephFSCloneComplete {
|
||||||
return nil, fmt.Errorf("clone is not in complete state for %s", vid.FsSubvolName)
|
return nil, fmt.Errorf("clone is not in complete state for %s", vid.FsSubvolName)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user