mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 02:33:34 +00:00
cleanup: resolve nlreturn linter issues
nlreturn linter requires a new line before return and branch statements except when the return is alone inside a statement group (such as an if statement) to increase code clarity. This commit addresses such issues. Updates: #1586 Signed-off-by: Rakshith R <rar@redhat.com>
This commit is contained in:
@ -27,12 +27,14 @@ func (vo *volumeOptions) getFscID(ctx context.Context) (int64, error) {
|
||||
fsa, err := vo.conn.GetFSAdmin()
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "could not get FSAdmin, can not fetch filesystem ID for %s:", vo.FsName, err)
|
||||
|
||||
return 0, err
|
||||
}
|
||||
|
||||
volumes, err := fsa.EnumerateVolumes()
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "could not list volumes, can not fetch filesystem ID for %s:", vo.FsName, err)
|
||||
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@ -43,6 +45,7 @@ func (vo *volumeOptions) getFscID(ctx context.Context) (int64, error) {
|
||||
}
|
||||
|
||||
util.ErrorLog(ctx, "failed to list volume %s", vo.FsName)
|
||||
|
||||
return 0, ErrVolumeNotFound
|
||||
}
|
||||
|
||||
@ -50,12 +53,14 @@ func (vo *volumeOptions) getMetadataPool(ctx context.Context) (string, error) {
|
||||
fsa, err := vo.conn.GetFSAdmin()
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "could not get FSAdmin, can not fetch metadata pool for %s:", vo.FsName, err)
|
||||
|
||||
return "", err
|
||||
}
|
||||
|
||||
fsPoolInfos, err := fsa.ListFileSystems()
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "could not list filesystems, can not fetch metadata pool for %s:", vo.FsName, err)
|
||||
|
||||
return "", err
|
||||
}
|
||||
|
||||
@ -72,12 +77,14 @@ func (vo *volumeOptions) getFsName(ctx context.Context) (string, error) {
|
||||
fsa, err := vo.conn.GetFSAdmin()
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "could not get FSAdmin, can not fetch filesystem name for ID %d:", vo.FscID, err)
|
||||
|
||||
return "", err
|
||||
}
|
||||
|
||||
volumes, err := fsa.EnumerateVolumes()
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "could not list volumes, can not fetch filesystem name for ID %d:", vo.FscID, err)
|
||||
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
@ -56,6 +56,7 @@ func (cs cephFSCloneState) toError() error {
|
||||
case cephFSCloneFailed:
|
||||
return ErrCloneFailed
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -64,6 +65,7 @@ func createCloneFromSubvolume(ctx context.Context, volID, cloneID volumeID, volO
|
||||
err := parentvolOpt.createSnapshot(ctx, snapshotID, volID)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to create snapshot %s %v", snapshotID, err)
|
||||
|
||||
return err
|
||||
}
|
||||
var (
|
||||
@ -100,29 +102,34 @@ func createCloneFromSubvolume(ctx context.Context, volID, cloneID volumeID, volO
|
||||
protectErr = parentvolOpt.protectSnapshot(ctx, snapshotID, volID)
|
||||
if protectErr != nil {
|
||||
util.ErrorLog(ctx, "failed to protect snapshot %s %v", snapshotID, protectErr)
|
||||
|
||||
return protectErr
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
cloneState, cloneErr := volOpt.getCloneState(ctx, cloneID)
|
||||
if cloneErr != nil {
|
||||
util.ErrorLog(ctx, "failed to get clone state: %v", cloneErr)
|
||||
|
||||
return cloneErr
|
||||
}
|
||||
|
||||
if cloneState != cephFSCloneComplete {
|
||||
util.ErrorLog(ctx, "clone %s did not complete: %v", cloneID, cloneState.toError())
|
||||
|
||||
return cloneState.toError()
|
||||
}
|
||||
// This is a work around to fix sizing issue for cloned images
|
||||
err = volOpt.resizeVolume(ctx, cloneID, volOpt.Size)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to expand volume %s: %v", cloneID, err)
|
||||
|
||||
return err
|
||||
}
|
||||
// As we completed clone, remove the intermediate snap
|
||||
@ -132,13 +139,16 @@ func createCloneFromSubvolume(ctx context.Context, volID, cloneID volumeID, volO
|
||||
// ahead with deletion
|
||||
if !errors.Is(err, ErrSnapProtectionExist) {
|
||||
util.ErrorLog(ctx, "failed to unprotect snapshot %s %v", snapshotID, err)
|
||||
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err = parentvolOpt.deleteSnapshot(ctx, snapshotID, volID); err != nil {
|
||||
util.ErrorLog(ctx, "failed to delete snapshot %s %v", snapshotID, err)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -154,6 +164,7 @@ func cleanupCloneFromSubvolumeSnapshot(
|
||||
if errors.Is(err, ErrSnapNotFound) {
|
||||
return nil
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@ -161,14 +172,17 @@ func cleanupCloneFromSubvolumeSnapshot(
|
||||
err = parentVolOpt.unprotectSnapshot(ctx, snapShotID, volID)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to unprotect snapshot %s %v", snapShotID, err)
|
||||
|
||||
return err
|
||||
}
|
||||
}
|
||||
err = parentVolOpt.deleteSnapshot(ctx, snapShotID, volID)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to delete snapshot %s %v", snapShotID, err)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -201,6 +215,7 @@ func createCloneFromSnapshot(
|
||||
cloneState, err := volOptions.getCloneState(ctx, volumeID(vID.FsSubvolName))
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to get clone state: %v", err)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@ -213,8 +228,10 @@ func createCloneFromSnapshot(
|
||||
err = volOptions.resizeVolume(ctx, volumeID(vID.FsSubvolName), volOptions.Size)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to expand volume %s with error: %v", vID.FsSubvolName, err)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -227,12 +244,14 @@ func (vo *volumeOptions) getCloneState(ctx context.Context, volID volumeID) (cep
|
||||
vo.FsName,
|
||||
string(volID),
|
||||
err)
|
||||
|
||||
return cephFSCloneError, err
|
||||
}
|
||||
|
||||
cs, err := fsa.CloneStatus(vo.FsName, vo.SubvolumeGroup, string(volID))
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "could not get clone state for volume %s with ID %s: %v", vo.FsName, string(volID), err)
|
||||
|
||||
return cephFSCloneError, err
|
||||
}
|
||||
|
||||
|
@ -60,6 +60,7 @@ func (cs *ControllerServer) createBackingVolume(
|
||||
if sID != nil {
|
||||
if err = cs.OperationLocks.GetRestoreLock(sID.SnapshotID); err != nil {
|
||||
util.ErrorLog(ctx, err.Error())
|
||||
|
||||
return status.Error(codes.Aborted, err.Error())
|
||||
}
|
||||
defer cs.OperationLocks.ReleaseRestoreLock(sID.SnapshotID)
|
||||
@ -67,13 +68,16 @@ func (cs *ControllerServer) createBackingVolume(
|
||||
err = createCloneFromSnapshot(ctx, parentVolOpt, volOptions, vID, sID)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to create clone from snapshot %s: %v", sID.FsSnapshotName, err)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
if parentVolOpt != nil {
|
||||
if err = cs.OperationLocks.GetCloneLock(pvID.VolumeID); err != nil {
|
||||
util.ErrorLog(ctx, err.Error())
|
||||
|
||||
return status.Error(codes.Aborted, err.Error())
|
||||
}
|
||||
defer cs.OperationLocks.ReleaseCloneLock(pvID.VolumeID)
|
||||
@ -85,15 +89,19 @@ func (cs *ControllerServer) createBackingVolume(
|
||||
parentVolOpt)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to create clone from subvolume %s: %v", volumeID(pvID.FsSubvolName), err)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
if err = createVolume(ctx, volOptions, volumeID(vID.FsSubvolName), volOptions.Size); err != nil {
|
||||
util.ErrorLog(ctx, "failed to create volume %s: %v", volOptions.RequestName, err)
|
||||
|
||||
return status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -113,8 +121,10 @@ func checkContentSource(
|
||||
if errors.Is(err, ErrSnapNotFound) {
|
||||
return nil, nil, nil, status.Error(codes.NotFound, err.Error())
|
||||
}
|
||||
|
||||
return nil, nil, nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
return volOpt, nil, sid, nil
|
||||
case *csi.VolumeContentSource_Volume:
|
||||
// Find the volume using the provided VolumeID
|
||||
@ -124,11 +134,13 @@ func checkContentSource(
|
||||
if !errors.Is(err, ErrVolumeNotFound) {
|
||||
return nil, nil, nil, status.Error(codes.NotFound, err.Error())
|
||||
}
|
||||
|
||||
return nil, nil, nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
return parentVol, pvID, nil, nil
|
||||
}
|
||||
|
||||
return nil, nil, nil, status.Errorf(codes.InvalidArgument, "not a proper volume source %v", volumeSource)
|
||||
}
|
||||
|
||||
@ -139,6 +151,7 @@ func (cs *ControllerServer) CreateVolume(
|
||||
req *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse, error) {
|
||||
if err := cs.validateCreateVolumeRequest(req); err != nil {
|
||||
util.ErrorLog(ctx, "CreateVolumeRequest validation failed: %v", err)
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -149,6 +162,7 @@ func (cs *ControllerServer) CreateVolume(
|
||||
cr, err := util.NewAdminCredentials(secret)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to retrieve admin credentials: %v", err)
|
||||
|
||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||
}
|
||||
defer cr.DeleteCredentials()
|
||||
@ -156,6 +170,7 @@ func (cs *ControllerServer) CreateVolume(
|
||||
// Existence and conflict checks
|
||||
if acquired := cs.VolumeLocks.TryAcquire(requestName); !acquired {
|
||||
util.ErrorLog(ctx, util.VolumeOperationAlreadyExistsFmt, requestName)
|
||||
|
||||
return nil, status.Errorf(codes.Aborted, util.VolumeOperationAlreadyExistsFmt, requestName)
|
||||
}
|
||||
defer cs.VolumeLocks.Release(requestName)
|
||||
@ -163,6 +178,7 @@ func (cs *ControllerServer) CreateVolume(
|
||||
volOptions, err := newVolumeOptions(ctx, requestName, req, cr)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "validation and extraction of volume options failed: %v", err)
|
||||
|
||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||
}
|
||||
defer volOptions.Destroy()
|
||||
@ -185,6 +201,7 @@ func (cs *ControllerServer) CreateVolume(
|
||||
if isCloneRetryError(err) {
|
||||
return nil, status.Error(codes.Aborted, err.Error())
|
||||
}
|
||||
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
// TODO return error message if requested vol size greater than found volume return error
|
||||
@ -211,6 +228,7 @@ func (cs *ControllerServer) CreateVolume(
|
||||
requestName, errUndo)
|
||||
}
|
||||
util.ErrorLog(ctx, "failed to expand volume %s: %v", volumeID(vID.FsSubvolName), err)
|
||||
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
}
|
||||
@ -231,6 +249,7 @@ func (cs *ControllerServer) CreateVolume(
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
return &csi.CreateVolumeResponse{Volume: volume}, nil
|
||||
}
|
||||
|
||||
@ -258,6 +277,7 @@ func (cs *ControllerServer) CreateVolume(
|
||||
if isCloneRetryError(err) {
|
||||
return nil, status.Error(codes.Aborted, err.Error())
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -273,10 +293,12 @@ func (cs *ControllerServer) CreateVolume(
|
||||
// set err=nil so that when we get the request again we can get
|
||||
// the subvolume info.
|
||||
err = nil
|
||||
|
||||
return nil, status.Error(codes.Internal, purgeErr.Error())
|
||||
}
|
||||
}
|
||||
util.ErrorLog(ctx, "failed to get subvolume path %s: %v", vID.FsSubvolName, err)
|
||||
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
@ -299,6 +321,7 @@ func (cs *ControllerServer) CreateVolume(
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
return &csi.CreateVolumeResponse{Volume: volume}, nil
|
||||
}
|
||||
|
||||
@ -308,6 +331,7 @@ func (cs *ControllerServer) DeleteVolume(
|
||||
req *csi.DeleteVolumeRequest) (*csi.DeleteVolumeResponse, error) {
|
||||
if err := cs.validateDeleteVolumeRequest(); err != nil {
|
||||
util.ErrorLog(ctx, "DeleteVolumeRequest validation failed: %v", err)
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -317,6 +341,7 @@ func (cs *ControllerServer) DeleteVolume(
|
||||
// lock out parallel delete operations
|
||||
if acquired := cs.VolumeLocks.TryAcquire(string(volID)); !acquired {
|
||||
util.ErrorLog(ctx, util.VolumeOperationAlreadyExistsFmt, volID)
|
||||
|
||||
return nil, status.Errorf(codes.Aborted, util.VolumeOperationAlreadyExistsFmt, string(volID))
|
||||
}
|
||||
defer cs.VolumeLocks.Release(string(volID))
|
||||
@ -324,6 +349,7 @@ func (cs *ControllerServer) DeleteVolume(
|
||||
// lock out volumeID for clone and expand operation
|
||||
if err := cs.OperationLocks.GetDeleteLock(req.GetVolumeId()); err != nil {
|
||||
util.ErrorLog(ctx, err.Error())
|
||||
|
||||
return nil, status.Error(codes.Aborted, err.Error())
|
||||
}
|
||||
defer cs.OperationLocks.ReleaseDeleteLock(req.GetVolumeId())
|
||||
@ -335,6 +361,7 @@ func (cs *ControllerServer) DeleteVolume(
|
||||
// need to worry about deleting subvolume or omap data, return success
|
||||
if errors.Is(err, util.ErrPoolNotFound) {
|
||||
util.WarningLog(ctx, "failed to get backend volume for %s: %v", string(volID), err)
|
||||
|
||||
return &csi.DeleteVolumeResponse{}, nil
|
||||
}
|
||||
// if error is ErrKeyNotFound, then a previous attempt at deletion was complete
|
||||
@ -362,6 +389,7 @@ func (cs *ControllerServer) DeleteVolume(
|
||||
if err = undoVolReservation(ctx, volOptions, *vID, secrets); err != nil {
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
return &csi.DeleteVolumeResponse{}, nil
|
||||
}
|
||||
defer volOptions.Destroy()
|
||||
@ -377,6 +405,7 @@ func (cs *ControllerServer) DeleteVolume(
|
||||
cr, err := util.NewAdminCredentials(secrets)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to retrieve admin credentials: %v", err)
|
||||
|
||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||
}
|
||||
defer cr.DeleteCredentials()
|
||||
@ -412,6 +441,7 @@ func (cs *ControllerServer) ValidateVolumeCapabilities(
|
||||
return &csi.ValidateVolumeCapabilitiesResponse{Message: ""}, nil
|
||||
}
|
||||
}
|
||||
|
||||
return &csi.ValidateVolumeCapabilitiesResponse{
|
||||
Confirmed: &csi.ValidateVolumeCapabilitiesResponse_Confirmed{
|
||||
VolumeCapabilities: req.VolumeCapabilities,
|
||||
@ -425,6 +455,7 @@ func (cs *ControllerServer) ControllerExpandVolume(
|
||||
req *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error) {
|
||||
if err := cs.validateExpandVolumeRequest(req); err != nil {
|
||||
util.ErrorLog(ctx, "ControllerExpandVolumeRequest validation failed: %v", err)
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -434,6 +465,7 @@ func (cs *ControllerServer) ControllerExpandVolume(
|
||||
// lock out parallel delete operations
|
||||
if acquired := cs.VolumeLocks.TryAcquire(volID); !acquired {
|
||||
util.ErrorLog(ctx, util.VolumeOperationAlreadyExistsFmt, volID)
|
||||
|
||||
return nil, status.Errorf(codes.Aborted, util.VolumeOperationAlreadyExistsFmt, volID)
|
||||
}
|
||||
defer cs.VolumeLocks.Release(volID)
|
||||
@ -441,6 +473,7 @@ func (cs *ControllerServer) ControllerExpandVolume(
|
||||
// lock out volumeID for clone and delete operation
|
||||
if err := cs.OperationLocks.GetExpandLock(volID); err != nil {
|
||||
util.ErrorLog(ctx, err.Error())
|
||||
|
||||
return nil, status.Error(codes.Aborted, err.Error())
|
||||
}
|
||||
defer cs.OperationLocks.ReleaseExpandLock(volID)
|
||||
@ -454,6 +487,7 @@ func (cs *ControllerServer) ControllerExpandVolume(
|
||||
volOptions, volIdentifier, err := newVolumeOptionsFromVolID(ctx, volID, nil, secret)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "validation and extraction of volume options failed: %v", err)
|
||||
|
||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||
}
|
||||
defer volOptions.Destroy()
|
||||
@ -462,6 +496,7 @@ func (cs *ControllerServer) ControllerExpandVolume(
|
||||
|
||||
if err = volOptions.resizeVolume(ctx, volumeID(volIdentifier.FsSubvolName), RoundOffSize); err != nil {
|
||||
util.ErrorLog(ctx, "failed to expand volume %s: %v", volumeID(volIdentifier.FsSubvolName), err)
|
||||
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
@ -496,12 +531,14 @@ func (cs *ControllerServer) CreateSnapshot(
|
||||
// Existence and conflict checks
|
||||
if acquired := cs.SnapshotLocks.TryAcquire(requestName); !acquired {
|
||||
util.ErrorLog(ctx, util.SnapshotOperationAlreadyExistsFmt, requestName)
|
||||
|
||||
return nil, status.Errorf(codes.Aborted, util.SnapshotOperationAlreadyExistsFmt, requestName)
|
||||
}
|
||||
defer cs.SnapshotLocks.Release(requestName)
|
||||
|
||||
if err = cs.OperationLocks.GetSnapshotCreateLock(sourceVolID); err != nil {
|
||||
util.ErrorLog(ctx, err.Error())
|
||||
|
||||
return nil, status.Error(codes.Aborted, err.Error())
|
||||
}
|
||||
|
||||
@ -512,12 +549,14 @@ func (cs *ControllerServer) CreateSnapshot(
|
||||
if err != nil {
|
||||
if errors.Is(err, util.ErrPoolNotFound) {
|
||||
util.WarningLog(ctx, "failed to get backend volume for %s: %v", sourceVolID, err)
|
||||
|
||||
return nil, status.Error(codes.NotFound, err.Error())
|
||||
}
|
||||
|
||||
if errors.Is(err, ErrVolumeNotFound) {
|
||||
return nil, status.Error(codes.NotFound, err.Error())
|
||||
}
|
||||
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
defer parentVolOptions.Destroy()
|
||||
@ -538,6 +577,7 @@ func (cs *ControllerServer) CreateSnapshot(
|
||||
// lock out parallel snapshot create operations
|
||||
if acquired := cs.VolumeLocks.TryAcquire(sourceVolID); !acquired {
|
||||
util.ErrorLog(ctx, util.VolumeOperationAlreadyExistsFmt, sourceVolID)
|
||||
|
||||
return nil, status.Errorf(codes.Aborted, util.VolumeOperationAlreadyExistsFmt, sourceVolID)
|
||||
}
|
||||
defer cs.VolumeLocks.Release(sourceVolID)
|
||||
@ -569,6 +609,7 @@ func (cs *ControllerServer) CreateSnapshot(
|
||||
requestName, errDefer)
|
||||
}
|
||||
}
|
||||
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
@ -613,6 +654,7 @@ func (cs *ControllerServer) CreateSnapshot(
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
return &csi.CreateSnapshotResponse{
|
||||
Snapshot: &csi.Snapshot{
|
||||
SizeBytes: info.BytesQuota,
|
||||
@ -631,6 +673,7 @@ func doSnapshot(ctx context.Context, volOpt *volumeOptions, subvolumeName, snaps
|
||||
err := volOpt.createSnapshot(ctx, snapID, volID)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to create snapshot %s %v", snapID, err)
|
||||
|
||||
return snap, err
|
||||
}
|
||||
defer func() {
|
||||
@ -644,6 +687,7 @@ func doSnapshot(ctx context.Context, volOpt *volumeOptions, subvolumeName, snaps
|
||||
snap, err = volOpt.getSnapshotInfo(ctx, snapID, volID)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to get snapshot info %s %v", snapID, err)
|
||||
|
||||
return snap, fmt.Errorf("failed to get snapshot info for snapshot:%s", snapID)
|
||||
}
|
||||
var t *timestamp.Timestamp
|
||||
@ -656,6 +700,7 @@ func doSnapshot(ctx context.Context, volOpt *volumeOptions, subvolumeName, snaps
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to protect snapshot %s %v", snapID, err)
|
||||
}
|
||||
|
||||
return snap, err
|
||||
}
|
||||
|
||||
@ -663,6 +708,7 @@ func (cs *ControllerServer) validateSnapshotReq(ctx context.Context, req *csi.Cr
|
||||
if err := cs.Driver.ValidateControllerServiceRequest(
|
||||
csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT); err != nil {
|
||||
util.ErrorLog(ctx, "invalid create snapshot req: %v", protosanitizer.StripSecrets(req))
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@ -685,6 +731,7 @@ func (cs *ControllerServer) DeleteSnapshot(
|
||||
if err := cs.Driver.ValidateControllerServiceRequest(
|
||||
csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT); err != nil {
|
||||
util.ErrorLog(ctx, "invalid delete snapshot req: %v", protosanitizer.StripSecrets(req))
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -700,6 +747,7 @@ func (cs *ControllerServer) DeleteSnapshot(
|
||||
|
||||
if acquired := cs.SnapshotLocks.TryAcquire(snapshotID); !acquired {
|
||||
util.ErrorLog(ctx, util.SnapshotOperationAlreadyExistsFmt, snapshotID)
|
||||
|
||||
return nil, status.Errorf(codes.Aborted, util.SnapshotOperationAlreadyExistsFmt, snapshotID)
|
||||
}
|
||||
defer cs.SnapshotLocks.Release(snapshotID)
|
||||
@ -707,6 +755,7 @@ func (cs *ControllerServer) DeleteSnapshot(
|
||||
// lock out snapshotID for restore operation
|
||||
if err = cs.OperationLocks.GetDeleteLock(snapshotID); err != nil {
|
||||
util.ErrorLog(ctx, err.Error())
|
||||
|
||||
return nil, status.Error(codes.Aborted, err.Error())
|
||||
}
|
||||
defer cs.OperationLocks.ReleaseDeleteLock(snapshotID)
|
||||
@ -718,6 +767,7 @@ func (cs *ControllerServer) DeleteSnapshot(
|
||||
// if error is ErrPoolNotFound, the pool is already deleted we dont
|
||||
// need to worry about deleting snapshot or omap data, return success
|
||||
util.WarningLog(ctx, "failed to get backend snapshot for %s: %v", snapshotID, err)
|
||||
|
||||
return &csi.DeleteSnapshotResponse{}, nil
|
||||
case errors.Is(err, util.ErrKeyNotFound):
|
||||
// if error is ErrKeyNotFound, then a previous attempt at deletion was complete
|
||||
@ -729,8 +779,10 @@ func (cs *ControllerServer) DeleteSnapshot(
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to remove reservation for snapname (%s) with backing snap (%s) (%s)",
|
||||
sid.FsSubvolName, sid.FsSnapshotName, err)
|
||||
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
return &csi.DeleteSnapshotResponse{}, nil
|
||||
case errors.Is(err, ErrVolumeNotFound):
|
||||
// if the error is ErrVolumeNotFound, the subvolume is already deleted
|
||||
@ -740,8 +792,10 @@ func (cs *ControllerServer) DeleteSnapshot(
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to remove reservation for snapname (%s) with backing snap (%s) (%s)",
|
||||
sid.FsSubvolName, sid.FsSnapshotName, err)
|
||||
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
return &csi.DeleteSnapshotResponse{}, nil
|
||||
default:
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
@ -753,6 +807,7 @@ func (cs *ControllerServer) DeleteSnapshot(
|
||||
// name
|
||||
if acquired := cs.SnapshotLocks.TryAcquire(sid.RequestName); !acquired {
|
||||
util.ErrorLog(ctx, util.SnapshotOperationAlreadyExistsFmt, sid.RequestName)
|
||||
|
||||
return nil, status.Errorf(codes.Aborted, util.VolumeOperationAlreadyExistsFmt, sid.RequestName)
|
||||
}
|
||||
defer cs.SnapshotLocks.Release(sid.RequestName)
|
||||
@ -774,6 +829,7 @@ func (cs *ControllerServer) DeleteSnapshot(
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to remove reservation for snapname (%s) with backing snap (%s) (%s)",
|
||||
sid.RequestName, sid.FsSnapshotName, err)
|
||||
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
|
@ -97,8 +97,10 @@ func checkVolExists(ctx context.Context,
|
||||
}
|
||||
err = j.UndoReservation(ctx, volOptions.MetadataPool,
|
||||
volOptions.MetadataPool, vid.FsSubvolName, volOptions.RequestName)
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
||||
if cloneState == cephFSCloneInprogress {
|
||||
@ -111,6 +113,7 @@ func checkVolExists(ctx context.Context,
|
||||
err = volOptions.purgeVolume(ctx, volumeID(vid.FsSubvolName), true)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to delete volume %s: %v", vid.FsSubvolName, err)
|
||||
|
||||
return nil, err
|
||||
}
|
||||
if pvID != nil {
|
||||
@ -124,6 +127,7 @@ func checkVolExists(ctx context.Context,
|
||||
}
|
||||
err = j.UndoReservation(ctx, volOptions.MetadataPool,
|
||||
volOptions.MetadataPool, vid.FsSubvolName, volOptions.RequestName)
|
||||
|
||||
return nil, err
|
||||
}
|
||||
if cloneState != cephFSCloneComplete {
|
||||
@ -147,8 +151,10 @@ func checkVolExists(ctx context.Context,
|
||||
}
|
||||
err = j.UndoReservation(ctx, volOptions.MetadataPool,
|
||||
volOptions.MetadataPool, vid.FsSubvolName, volOptions.RequestName)
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -327,6 +333,7 @@ func undoSnapReservation(
|
||||
|
||||
err = j.UndoReservation(ctx, volOptions.MetadataPool,
|
||||
volOptions.MetadataPool, vid.FsSnapshotName, snapName)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@ -374,8 +381,10 @@ func checkSnapExists(
|
||||
if errors.Is(err, ErrSnapNotFound) {
|
||||
err = j.UndoReservation(ctx, volOptions.MetadataPool,
|
||||
volOptions.MetadataPool, snapID, snap.RequestName)
|
||||
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
@ -384,6 +393,7 @@ func checkSnapExists(
|
||||
err = volOptions.deleteSnapshot(ctx, volumeID(snapID), volumeID(parentSubVolName))
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to delete snapshot %s: %v", snapID, err)
|
||||
|
||||
return
|
||||
}
|
||||
err = j.UndoReservation(ctx, volOptions.MetadataPool,
|
||||
|
@ -82,6 +82,7 @@ func (ns *NodeServer) NodeStageVolume(
|
||||
|
||||
if acquired := ns.VolumeLocks.TryAcquire(req.GetVolumeId()); !acquired {
|
||||
util.ErrorLog(ctx, util.VolumeOperationAlreadyExistsFmt, volID)
|
||||
|
||||
return nil, status.Errorf(codes.Aborted, util.VolumeOperationAlreadyExistsFmt, req.GetVolumeId())
|
||||
}
|
||||
defer ns.VolumeLocks.Release(req.GetVolumeId())
|
||||
@ -114,11 +115,13 @@ func (ns *NodeServer) NodeStageVolume(
|
||||
isMnt, err := util.IsMountPoint(stagingTargetPath)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "stat failed: %v", err)
|
||||
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
if isMnt {
|
||||
util.DebugLog(ctx, "cephfs: volume %s is already mounted to %s, skipping", volID, stagingTargetPath)
|
||||
|
||||
return &csi.NodeStageVolumeResponse{}, nil
|
||||
}
|
||||
|
||||
@ -139,6 +142,7 @@ func (*NodeServer) mount(ctx context.Context, volOptions *volumeOptions, req *cs
|
||||
cr, err := getCredentialsForVolume(volOptions, req)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to get ceph credentials for volume %s: %v", volID, err)
|
||||
|
||||
return status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
defer cr.DeleteCredentials()
|
||||
@ -146,6 +150,7 @@ func (*NodeServer) mount(ctx context.Context, volOptions *volumeOptions, req *cs
|
||||
m, err := newMounter(volOptions)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to create mounter for volume %s: %v", volID, err)
|
||||
|
||||
return status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
@ -176,6 +181,7 @@ func (*NodeServer) mount(ctx context.Context, volOptions *volumeOptions, req *cs
|
||||
"failed to mount volume %s: %v Check dmesg logs if required.",
|
||||
volID,
|
||||
err)
|
||||
|
||||
return status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
if !csicommon.MountOptionContains(kernelMountOptions, readOnly) &&
|
||||
@ -198,9 +204,11 @@ func (*NodeServer) mount(ctx context.Context, volOptions *volumeOptions, req *cs
|
||||
volID,
|
||||
uErr)
|
||||
}
|
||||
|
||||
return status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -222,6 +230,7 @@ func (ns *NodeServer) NodePublishVolume(
|
||||
|
||||
if err := util.CreateMountPoint(targetPath); err != nil {
|
||||
util.ErrorLog(ctx, "failed to create mount point at %s: %v", targetPath, err)
|
||||
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
@ -236,11 +245,13 @@ func (ns *NodeServer) NodePublishVolume(
|
||||
isMnt, err := util.IsMountPoint(targetPath)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "stat failed: %v", err)
|
||||
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
if isMnt {
|
||||
util.DebugLog(ctx, "cephfs: volume %s is already bind-mounted to %s", volID, targetPath)
|
||||
|
||||
return &csi.NodePublishVolumeResponse{}, nil
|
||||
}
|
||||
|
||||
@ -248,6 +259,7 @@ func (ns *NodeServer) NodePublishVolume(
|
||||
|
||||
if err = bindMount(ctx, req.GetStagingTargetPath(), req.GetTargetPath(), req.GetReadonly(), mountOptions); err != nil {
|
||||
util.ErrorLog(ctx, "failed to bind-mount volume %s: %v", volID, err)
|
||||
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
@ -272,14 +284,17 @@ func (ns *NodeServer) NodeUnpublishVolume(
|
||||
if os.IsNotExist(err) {
|
||||
// targetPath has already been deleted
|
||||
util.DebugLog(ctx, "targetPath: %s has already been deleted", targetPath)
|
||||
|
||||
return &csi.NodeUnpublishVolumeResponse{}, nil
|
||||
}
|
||||
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
if !isMnt {
|
||||
if err = os.RemoveAll(targetPath); err != nil {
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
|
||||
return &csi.NodeUnpublishVolumeResponse{}, nil
|
||||
}
|
||||
|
||||
@ -310,6 +325,7 @@ func (ns *NodeServer) NodeUnstageVolume(
|
||||
volID := req.GetVolumeId()
|
||||
if acquired := ns.VolumeLocks.TryAcquire(volID); !acquired {
|
||||
util.ErrorLog(ctx, util.VolumeOperationAlreadyExistsFmt, volID)
|
||||
|
||||
return nil, status.Errorf(codes.Aborted, util.VolumeOperationAlreadyExistsFmt, volID)
|
||||
}
|
||||
defer ns.VolumeLocks.Release(volID)
|
||||
@ -321,8 +337,10 @@ func (ns *NodeServer) NodeUnstageVolume(
|
||||
if os.IsNotExist(err) {
|
||||
// targetPath has already been deleted
|
||||
util.DebugLog(ctx, "targetPath: %s has already been deleted", stagingTargetPath)
|
||||
|
||||
return &csi.NodeUnstageVolumeResponse{}, nil
|
||||
}
|
||||
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
if !isMnt {
|
||||
@ -370,6 +388,7 @@ func (ns *NodeServer) NodeGetVolumeStats(
|
||||
targetPath := req.GetVolumePath()
|
||||
if targetPath == "" {
|
||||
err = fmt.Errorf("targetpath %v is empty", targetPath)
|
||||
|
||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||
}
|
||||
|
||||
|
@ -52,6 +52,7 @@ func (vo *volumeOptions) createSnapshot(ctx context.Context, snapID, volID volum
|
||||
fsa, err := vo.conn.GetFSAdmin()
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "could not get FSAdmin: %s", err)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@ -59,8 +60,10 @@ func (vo *volumeOptions) createSnapshot(ctx context.Context, snapID, volID volum
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to create subvolume snapshot %s %s in fs %s: %s",
|
||||
string(snapID), string(volID), vo.FsName, err)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -68,6 +71,7 @@ func (vo *volumeOptions) deleteSnapshot(ctx context.Context, snapID, volID volum
|
||||
fsa, err := vo.conn.GetFSAdmin()
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "could not get FSAdmin: %s", err)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@ -75,8 +79,10 @@ func (vo *volumeOptions) deleteSnapshot(ctx context.Context, snapID, volID volum
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to delete subvolume snapshot %s %s in fs %s: %s",
|
||||
string(snapID), string(volID), vo.FsName, err)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -92,6 +98,7 @@ func (vo *volumeOptions) getSnapshotInfo(ctx context.Context, snapID, volID volu
|
||||
fsa, err := vo.conn.GetFSAdmin()
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "could not get FSAdmin: %s", err)
|
||||
|
||||
return snap, err
|
||||
}
|
||||
|
||||
@ -107,11 +114,13 @@ func (vo *volumeOptions) getSnapshotInfo(ctx context.Context, snapID, volID volu
|
||||
string(snapID),
|
||||
vo.FsName,
|
||||
err)
|
||||
|
||||
return snap, err
|
||||
}
|
||||
snap.CreatedAt = info.CreatedAt.Time
|
||||
snap.HasPendingClones = info.HasPendingClones
|
||||
snap.Protected = info.Protected
|
||||
|
||||
return snap, nil
|
||||
}
|
||||
|
||||
@ -124,6 +133,7 @@ func (vo *volumeOptions) protectSnapshot(ctx context.Context, snapID, volID volu
|
||||
fsa, err := vo.conn.GetFSAdmin()
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "could not get FSAdmin: %s", err)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@ -140,8 +150,10 @@ func (vo *volumeOptions) protectSnapshot(ctx context.Context, snapID, volID volu
|
||||
string(snapID),
|
||||
vo.FsName,
|
||||
err)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -154,6 +166,7 @@ func (vo *volumeOptions) unprotectSnapshot(ctx context.Context, snapID, volID vo
|
||||
fsa, err := vo.conn.GetFSAdmin()
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "could not get FSAdmin: %s", err)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@ -172,8 +185,10 @@ func (vo *volumeOptions) unprotectSnapshot(ctx context.Context, snapID, volID vo
|
||||
string(snapID),
|
||||
vo.FsName,
|
||||
err)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -185,6 +200,7 @@ func (vo *volumeOptions) cloneSnapshot(
|
||||
fsa, err := vo.conn.GetFSAdmin()
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "could not get FSAdmin: %s", err)
|
||||
|
||||
return err
|
||||
}
|
||||
co := &admin.CloneOptions{
|
||||
@ -207,7 +223,9 @@ func (vo *volumeOptions) cloneSnapshot(
|
||||
if errors.Is(err, rados.ErrNotFound) {
|
||||
return ErrVolumeNotFound
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ type volumeID string
|
||||
|
||||
func execCommandErr(ctx context.Context, program string, args ...string) error {
|
||||
_, _, err := util.ExecCommand(ctx, program, args...)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@ -91,6 +92,7 @@ func (cs *ControllerServer) validateCreateVolumeRequest(req *csi.CreateVolumeReq
|
||||
return status.Error(codes.InvalidArgument, "unsupported volume data source")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -129,11 +131,13 @@ func genSnapFromOptions(ctx context.Context, req *csi.CreateSnapshotRequest) (sn
|
||||
cephfsSnap.Monitors, cephfsSnap.ClusterID, err = util.GetMonsAndClusterID(snapOptions)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed getting mons (%s)", err)
|
||||
|
||||
return nil, err
|
||||
}
|
||||
if namePrefix, ok := snapOptions["snapshotNamePrefix"]; ok {
|
||||
cephfsSnap.NamePrefix = namePrefix
|
||||
}
|
||||
|
||||
return cephfsSnap, nil
|
||||
}
|
||||
|
||||
@ -141,7 +145,9 @@ func parseTime(ctx context.Context, createTime time.Time) (*timestamp.Timestamp,
|
||||
tm, err := ptypes.TimestampProto(createTime)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to convert time %s %v", createTime, err)
|
||||
|
||||
return tm, err
|
||||
}
|
||||
|
||||
return tm, nil
|
||||
}
|
||||
|
@ -60,6 +60,7 @@ func (vo *volumeOptions) getVolumeRootPathCeph(ctx context.Context, volID volume
|
||||
fsa, err := vo.conn.GetFSAdmin()
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "could not get FSAdmin err %s", err)
|
||||
|
||||
return "", err
|
||||
}
|
||||
svPath, err := fsa.SubVolumePath(vo.FsName, vo.SubvolumeGroup, string(volID))
|
||||
@ -68,8 +69,10 @@ func (vo *volumeOptions) getVolumeRootPathCeph(ctx context.Context, volID volume
|
||||
if errors.Is(err, rados.ErrNotFound) {
|
||||
return "", util.JoinErrors(ErrVolumeNotFound, err)
|
||||
}
|
||||
|
||||
return "", err
|
||||
}
|
||||
|
||||
return svPath, nil
|
||||
}
|
||||
|
||||
@ -77,6 +80,7 @@ func (vo *volumeOptions) getSubVolumeInfo(ctx context.Context, volID volumeID) (
|
||||
fsa, err := vo.conn.GetFSAdmin()
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "could not get FSAdmin, can not fetch metadata pool for %s:", vo.FsName, err)
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -147,6 +151,7 @@ func createVolume(ctx context.Context, volOptions *volumeOptions, volID volumeID
|
||||
ca, err := volOptions.conn.GetFSAdmin()
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "could not get FSAdmin, can not create subvolume %s: %s", string(volID), err)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@ -161,6 +166,7 @@ func createVolume(ctx context.Context, volOptions *volumeOptions, volID volumeID
|
||||
volOptions.SubvolumeGroup,
|
||||
string(volID),
|
||||
err)
|
||||
|
||||
return err
|
||||
}
|
||||
util.DebugLog(ctx, "cephfs: created subvolume group %s", volOptions.SubvolumeGroup)
|
||||
@ -179,6 +185,7 @@ func createVolume(ctx context.Context, volOptions *volumeOptions, volID volumeID
|
||||
err = ca.CreateSubVolume(volOptions.FsName, volOptions.SubvolumeGroup, string(volID), &opts)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to create subvolume %s in fs %s: %s", string(volID), volOptions.FsName, err)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@ -203,21 +210,25 @@ func (vo *volumeOptions) resizeVolume(ctx context.Context, volID volumeID, bytes
|
||||
fsa, err := vo.conn.GetFSAdmin()
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "could not get FSAdmin, can not resize volume %s:", vo.FsName, err)
|
||||
|
||||
return err
|
||||
}
|
||||
_, err = fsa.ResizeSubVolume(vo.FsName, vo.SubvolumeGroup, string(volID), fsAdmin.ByteCount(bytesQuota), true)
|
||||
if err == nil {
|
||||
clusterAdditionalInfo[vo.ClusterID].resizeState = supported
|
||||
|
||||
return nil
|
||||
}
|
||||
var invalid fsAdmin.NotImplementedError
|
||||
// In case the error is other than invalid command return error to the caller.
|
||||
if !errors.As(err, &invalid) {
|
||||
util.ErrorLog(ctx, "failed to resize subvolume %s in fs %s: %s", string(volID), vo.FsName, err)
|
||||
|
||||
return err
|
||||
}
|
||||
}
|
||||
clusterAdditionalInfo[vo.ClusterID].resizeState = unsupported
|
||||
|
||||
return createVolume(ctx, vo, volID, bytesQuota)
|
||||
}
|
||||
|
||||
@ -225,6 +236,7 @@ func (vo *volumeOptions) purgeVolume(ctx context.Context, volID volumeID, force
|
||||
fsa, err := vo.conn.GetFSAdmin()
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "could not get FSAdmin %s:", err)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@ -244,6 +256,7 @@ func (vo *volumeOptions) purgeVolume(ctx context.Context, volID volumeID, force
|
||||
if errors.Is(err, rados.ErrNotFound) {
|
||||
return util.JoinErrors(ErrVolumeNotFound, err)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@ -260,5 +273,6 @@ func checkSubvolumeHasFeature(feature string, subVolFeatures []string) bool {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
@ -123,6 +123,7 @@ func newMounter(volOptions *volumeOptions) (volumeMounter, error) {
|
||||
for _, availMounter := range availableMounters {
|
||||
if availMounter == wantMounter {
|
||||
chosenMounter = wantMounter
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -235,6 +236,7 @@ func mountKernel(ctx context.Context, mountPoint string, cr *util.Credentials, v
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w stderr: %s", err, stderr)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@ -275,6 +277,7 @@ func unmountVolume(ctx context.Context, mountPoint string) error {
|
||||
strings.Contains(err.Error(), "No such file or directory") {
|
||||
return nil
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -67,6 +67,7 @@ func (vo *volumeOptions) Connect(cr *util.Credentials) error {
|
||||
}
|
||||
|
||||
vo.conn = conn
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -98,6 +99,7 @@ func extractOptionalOption(dest *string, optionLabel string, options map[string]
|
||||
}
|
||||
|
||||
*dest = opt
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -112,6 +114,7 @@ func extractOption(dest *string, optionLabel string, options map[string]string)
|
||||
}
|
||||
|
||||
*dest = opt
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -144,6 +147,7 @@ func getClusterInformation(options map[string]string) (*util.ClusterInfo, error)
|
||||
clusterID, ok := options["clusterID"]
|
||||
if !ok {
|
||||
err := fmt.Errorf("clusterID must be set")
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -154,12 +158,14 @@ func getClusterInformation(options map[string]string) (*util.ClusterInfo, error)
|
||||
monitors, err := util.Mons(util.CsiConfigFile, clusterID)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to fetch monitor list using clusterID (%s): %w", clusterID, err)
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
subvolumeGroup, err := util.CephFSSubvolumeGroup(util.CsiConfigFile, clusterID)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to fetch subvolumegroup using clusterID (%s): %w", clusterID, err)
|
||||
|
||||
return nil, err
|
||||
}
|
||||
clusterData := &util.ClusterInfo{
|
||||
@ -167,6 +173,7 @@ func getClusterInformation(options map[string]string) (*util.ClusterInfo, error)
|
||||
Monitors: strings.Split(monitors, ","),
|
||||
}
|
||||
clusterData.CephFS.SubvolumeGroup = subvolumeGroup
|
||||
|
||||
return clusterData, nil
|
||||
}
|
||||
|
||||
@ -265,6 +272,7 @@ func newVolumeOptionsFromVolID(
|
||||
err := vi.DecomposeCSIID(volID)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error decoding volume ID (%s): %w", volID, err)
|
||||
|
||||
return nil, nil, util.JoinErrors(ErrInvalidVolID, err)
|
||||
}
|
||||
volOptions.ClusterID = vi.ClusterID
|
||||
|
Reference in New Issue
Block a user