mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-23 21:40:20 +00:00
internal: reformat long lines in internal/rbd package to 120 chars
We have many declarations and invocations..etc with long lines which are very difficult to follow while doing code reading. This address the issues in below files, and restrict the line length to 120 chars. -internal/rbd/rbd_attach.go -internal/rbd/rbd_journal.go -internal/rbd/rbd_util.go -internal/rbd/replicationcontrollerserver.go -internal/rbd/snapshot.go Signed-off-by: Humble Chirammal <hchiramm@redhat.com>
This commit is contained in:
parent
e829308249
commit
8f82a30c21
@ -96,7 +96,10 @@ func rbdGetDeviceList(ctx context.Context, accessType string) ([]rbdDeviceInfo,
|
||||
err = json.Unmarshal([]byte(stdout), &nbdDeviceList)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error to parse JSON output of device list for devices of type (%s): %w", accessType, err)
|
||||
return nil, fmt.Errorf(
|
||||
"error to parse JSON output of device list for devices of type (%s): %w",
|
||||
accessType,
|
||||
err)
|
||||
}
|
||||
|
||||
// convert output to a rbdDeviceInfo list for consumers
|
||||
@ -270,7 +273,14 @@ func createPath(ctx context.Context, volOpt *rbdVolume, cr *util.Credentials) (s
|
||||
util.WarningLog(ctx, "rbd: map error %v, rbd output: %s", err, stderr)
|
||||
// unmap rbd image if connection timeout
|
||||
if strings.Contains(err.Error(), rbdMapConnectionTimeout) {
|
||||
detErr := detachRBDImageOrDeviceSpec(ctx, imagePath, true, isNbd, volOpt.isEncrypted(), volOpt.VolID, volOpt.UnmapOptions)
|
||||
detErr := detachRBDImageOrDeviceSpec(
|
||||
ctx,
|
||||
imagePath,
|
||||
true,
|
||||
isNbd,
|
||||
volOpt.isEncrypted(),
|
||||
volOpt.VolID,
|
||||
volOpt.UnmapOptions)
|
||||
if detErr != nil {
|
||||
util.WarningLog(ctx, "rbd: %s unmap error %v", imagePath, detErr)
|
||||
}
|
||||
@ -315,7 +325,11 @@ func detachRBDDevice(ctx context.Context, devicePath, volumeID, unmapOptions str
|
||||
|
||||
// detachRBDImageOrDeviceSpec detaches an rbd imageSpec or devicePath, with additional checking
|
||||
// when imageSpec is used to decide if image is already unmapped.
|
||||
func detachRBDImageOrDeviceSpec(ctx context.Context, imageOrDeviceSpec string, isImageSpec, isNbd, encrypted bool, volumeID, unmapOptions string) error {
|
||||
func detachRBDImageOrDeviceSpec(
|
||||
ctx context.Context,
|
||||
imageOrDeviceSpec string,
|
||||
isImageSpec, isNbd, encrypted bool,
|
||||
volumeID, unmapOptions string) error {
|
||||
if encrypted {
|
||||
mapperFile, mapperPath := util.VolumeMapper(volumeID)
|
||||
mappedDevice, mapper, err := util.DeviceEncryptionStatus(ctx, mapperPath)
|
||||
|
@ -119,7 +119,11 @@ deletion are inverse of each other, and protected by the request name lock, and
|
||||
hence any stale omaps are leftovers from incomplete transactions and are hence
|
||||
safe to garbage collect.
|
||||
*/
|
||||
func checkSnapCloneExists(ctx context.Context, parentVol *rbdVolume, rbdSnap *rbdSnapshot, cr *util.Credentials) (bool, error) {
|
||||
func checkSnapCloneExists(
|
||||
ctx context.Context,
|
||||
parentVol *rbdVolume,
|
||||
rbdSnap *rbdSnapshot,
|
||||
cr *util.Credentials) (bool, error) {
|
||||
err := validateRbdSnap(rbdSnap)
|
||||
if err != nil {
|
||||
return false, err
|
||||
@ -517,7 +521,9 @@ func undoVolReservation(ctx context.Context, rbdVol *rbdVolume, cr *util.Credent
|
||||
// Generate new volume Handler
|
||||
// The volume handler won't remain same as its contains poolID,clusterID etc
|
||||
// which are not same across clusters.
|
||||
func RegenerateJournal(imageName, volumeID, pool, journalPool, requestName string, cr *util.Credentials) (string, error) {
|
||||
func RegenerateJournal(
|
||||
imageName, volumeID, pool, journalPool, requestName string,
|
||||
cr *util.Credentials) (string, error) {
|
||||
ctx := context.Background()
|
||||
var (
|
||||
options map[string]string
|
||||
|
@ -472,7 +472,13 @@ func isNotMountPoint(mounter mount.Interface, stagingTargetPath string) (bool, e
|
||||
func addRbdManagerTask(ctx context.Context, pOpts *rbdVolume, arg []string) (bool, error) {
|
||||
args := []string{"rbd", "task", "add"}
|
||||
args = append(args, arg...)
|
||||
util.DebugLog(ctx, "executing %v for image (%s) using mon %s, pool %s", args, pOpts.RbdImageName, pOpts.Monitors, pOpts.Pool)
|
||||
util.DebugLog(
|
||||
ctx,
|
||||
"executing %v for image (%s) using mon %s, pool %s",
|
||||
args,
|
||||
pOpts.RbdImageName,
|
||||
pOpts.Monitors,
|
||||
pOpts.Pool)
|
||||
supported := true
|
||||
_, stderr, err := util.ExecCommand(ctx, "ceph", args...)
|
||||
|
||||
@ -480,7 +486,11 @@ func addRbdManagerTask(ctx context.Context, pOpts *rbdVolume, arg []string) (boo
|
||||
switch {
|
||||
case strings.Contains(stderr, rbdTaskRemoveCmdInvalidString1) &&
|
||||
strings.Contains(stderr, rbdTaskRemoveCmdInvalidString2):
|
||||
util.WarningLog(ctx, "cluster with cluster ID (%s) does not support Ceph manager based rbd commands (minimum ceph version required is v14.2.3)", pOpts.ClusterID)
|
||||
util.WarningLog(
|
||||
ctx,
|
||||
"cluster with cluster ID (%s) does not support Ceph manager based rbd commands"+
|
||||
"(minimum ceph version required is v14.2.3)",
|
||||
pOpts.ClusterID)
|
||||
supported = false
|
||||
case strings.HasPrefix(stderr, rbdTaskRemoveCmdAccessDeniedMessage):
|
||||
util.WarningLog(ctx, "access denied to Ceph MGR-based rbd commands on cluster ID (%s)", pOpts.ClusterID)
|
||||
@ -595,7 +605,11 @@ type trashSnapInfo struct {
|
||||
origSnapName string
|
||||
}
|
||||
|
||||
func flattenClonedRbdImages(ctx context.Context, snaps []librbd.SnapInfo, pool, monitors, rbdImageName string, cr *util.Credentials) error {
|
||||
func flattenClonedRbdImages(
|
||||
ctx context.Context,
|
||||
snaps []librbd.SnapInfo,
|
||||
pool, monitors, rbdImageName string,
|
||||
cr *util.Credentials) error {
|
||||
rv := &rbdVolume{}
|
||||
rv.Monitors = monitors
|
||||
rv.Pool = pool
|
||||
@ -636,7 +650,11 @@ func flattenClonedRbdImages(ctx context.Context, snaps []librbd.SnapInfo, pool,
|
||||
return nil
|
||||
}
|
||||
|
||||
func (rv *rbdVolume) flattenRbdImage(ctx context.Context, cr *util.Credentials, forceFlatten bool, hardlimit, softlimit uint) error {
|
||||
func (rv *rbdVolume) flattenRbdImage(
|
||||
ctx context.Context,
|
||||
cr *util.Credentials,
|
||||
forceFlatten bool,
|
||||
hardlimit, softlimit uint) error {
|
||||
var depth uint
|
||||
var err error
|
||||
|
||||
@ -646,7 +664,13 @@ func (rv *rbdVolume) flattenRbdImage(ctx context.Context, cr *util.Credentials,
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
util.ExtendedLog(ctx, "clone depth is (%d), configured softlimit (%d) and hardlimit (%d) for %s", depth, softlimit, hardlimit, rv)
|
||||
util.ExtendedLog(
|
||||
ctx,
|
||||
"clone depth is (%d), configured softlimit (%d) and hardlimit (%d) for %s",
|
||||
depth,
|
||||
softlimit,
|
||||
hardlimit,
|
||||
rv)
|
||||
}
|
||||
|
||||
if !forceFlatten && (depth < hardlimit) && (depth < softlimit) {
|
||||
@ -669,7 +693,10 @@ func (rv *rbdVolume) flattenRbdImage(ctx context.Context, cr *util.Credentials,
|
||||
}
|
||||
}
|
||||
if !supported {
|
||||
util.ErrorLog(ctx, "task manager does not support flatten,image will be flattened once hardlimit is reached: %v", err)
|
||||
util.ErrorLog(
|
||||
ctx,
|
||||
"task manager does not support flatten,image will be flattened once hardlimit is reached: %v",
|
||||
err)
|
||||
if forceFlatten || depth >= hardlimit {
|
||||
err = rv.Connect(cr)
|
||||
if err != nil {
|
||||
@ -769,7 +796,12 @@ func (rv *rbdVolume) checkImageChainHasFeature(ctx context.Context, feature uint
|
||||
|
||||
// genSnapFromSnapID generates a rbdSnapshot structure from the provided identifier, updating
|
||||
// the structure with elements from on-disk snapshot metadata as well.
|
||||
func genSnapFromSnapID(ctx context.Context, rbdSnap *rbdSnapshot, snapshotID string, cr *util.Credentials, secrets map[string]string) error {
|
||||
func genSnapFromSnapID(
|
||||
ctx context.Context,
|
||||
rbdSnap *rbdSnapshot,
|
||||
snapshotID string,
|
||||
cr *util.Credentials,
|
||||
secrets map[string]string) error {
|
||||
var (
|
||||
options map[string]string
|
||||
vi util.CSIIdentifier
|
||||
@ -853,7 +885,11 @@ func genSnapFromSnapID(ctx context.Context, rbdSnap *rbdSnapshot, snapshotID str
|
||||
}
|
||||
|
||||
// generateVolumeFromVolumeID generates a rbdVolume structure from the provided identifier.
|
||||
func generateVolumeFromVolumeID(ctx context.Context, volumeID string, cr *util.Credentials, secrets map[string]string) (*rbdVolume, error) {
|
||||
func generateVolumeFromVolumeID(
|
||||
ctx context.Context,
|
||||
volumeID string,
|
||||
cr *util.Credentials,
|
||||
secrets map[string]string) (*rbdVolume, error) {
|
||||
var (
|
||||
options map[string]string
|
||||
vi util.CSIIdentifier
|
||||
@ -944,9 +980,14 @@ func generateVolumeFromVolumeID(ctx context.Context, volumeID string, cr *util.C
|
||||
|
||||
// genVolFromVolID generates a rbdVolume structure from the provided identifier, updating
|
||||
// the structure with elements from on-disk image metadata as well.
|
||||
func genVolFromVolID(ctx context.Context, volumeID string, cr *util.Credentials, secrets map[string]string) (*rbdVolume, error) {
|
||||
func genVolFromVolID(
|
||||
ctx context.Context,
|
||||
volumeID string,
|
||||
cr *util.Credentials,
|
||||
secrets map[string]string) (*rbdVolume, error) {
|
||||
vol, err := generateVolumeFromVolumeID(ctx, volumeID, cr, secrets)
|
||||
if !errors.Is(err, util.ErrKeyNotFound) && !errors.Is(err, util.ErrPoolNotFound) && !errors.Is(err, ErrImageNotFound) {
|
||||
if !errors.Is(err, util.ErrKeyNotFound) && !errors.Is(err, util.ErrPoolNotFound) &&
|
||||
!errors.Is(err, ErrImageNotFound) {
|
||||
return vol, err
|
||||
}
|
||||
|
||||
@ -974,7 +1015,10 @@ func genVolFromVolID(ctx context.Context, volumeID string, cr *util.Credentials,
|
||||
return vol, err
|
||||
}
|
||||
|
||||
func genVolFromVolumeOptions(ctx context.Context, volOptions, credentials map[string]string, disableInUseChecks bool) (*rbdVolume, error) {
|
||||
func genVolFromVolumeOptions(
|
||||
ctx context.Context,
|
||||
volOptions, credentials map[string]string,
|
||||
disableInUseChecks bool) (*rbdVolume, error) {
|
||||
var (
|
||||
ok bool
|
||||
err error
|
||||
@ -1012,7 +1056,12 @@ func genVolFromVolumeOptions(ctx context.Context, volOptions, credentials map[st
|
||||
return nil, err
|
||||
}
|
||||
|
||||
util.ExtendedLog(ctx, "setting disableInUseChecks: %t image features: %v mounter: %s", disableInUseChecks, rbdVol.imageFeatureSet.Names(), rbdVol.Mounter)
|
||||
util.ExtendedLog(
|
||||
ctx,
|
||||
"setting disableInUseChecks: %t image features: %v mounter: %s",
|
||||
disableInUseChecks,
|
||||
rbdVol.imageFeatureSet.Names(),
|
||||
rbdVol.Mounter)
|
||||
rbdVol.DisableInUseChecks = disableInUseChecks
|
||||
|
||||
err = rbdVol.initKMS(ctx, volOptions, credentials)
|
||||
@ -1110,7 +1159,10 @@ func (rv *rbdVolume) deleteSnapshot(ctx context.Context, pOpts *rbdSnapshot) err
|
||||
return err
|
||||
}
|
||||
|
||||
func (rv *rbdVolume) cloneRbdImageFromSnapshot(ctx context.Context, pSnapOpts *rbdSnapshot, parentVol *rbdVolume) error {
|
||||
func (rv *rbdVolume) cloneRbdImageFromSnapshot(
|
||||
ctx context.Context,
|
||||
pSnapOpts *rbdSnapshot,
|
||||
parentVol *rbdVolume) error {
|
||||
var err error
|
||||
logMsg := "rbd: clone %s %s (features: %s) using mon %s"
|
||||
|
||||
@ -1155,7 +1207,13 @@ func (rv *rbdVolume) cloneRbdImageFromSnapshot(ctx context.Context, pSnapOpts *r
|
||||
return fmt.Errorf("failed to get IOContext: %w", err)
|
||||
}
|
||||
|
||||
err = librbd.CloneImage(parentVol.ioctx, pSnapOpts.RbdImageName, pSnapOpts.RbdSnapName, rv.ioctx, rv.RbdImageName, options)
|
||||
err = librbd.CloneImage(
|
||||
parentVol.ioctx,
|
||||
pSnapOpts.RbdImageName,
|
||||
pSnapOpts.RbdSnapName,
|
||||
rv.ioctx,
|
||||
rv.RbdImageName,
|
||||
options)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create rbd clone: %w", err)
|
||||
}
|
||||
|
@ -90,7 +90,11 @@ func getForceOption(ctx context.Context, parameters map[string]string) (bool, er
|
||||
func getMirroringMode(ctx context.Context, parameters map[string]string) (librbd.ImageMirrorMode, error) {
|
||||
val, ok := parameters[imageMirroringKey]
|
||||
if !ok {
|
||||
util.WarningLog(ctx, "%s is not set in parameters, setting to mirroringMode to default (%s)", imageMirroringKey, imageMirrorModeSnapshot)
|
||||
util.WarningLog(
|
||||
ctx,
|
||||
"%s is not set in parameters, setting to mirroringMode to default (%s)",
|
||||
imageMirroringKey,
|
||||
imageMirrorModeSnapshot)
|
||||
return librbd.ImageMirrorModeSnapshot, nil
|
||||
}
|
||||
|
||||
@ -286,7 +290,11 @@ func (rs *ReplicationServer) PromoteVolume(ctx context.Context,
|
||||
}
|
||||
|
||||
if mirroringInfo.State != librbd.MirrorImageEnabled {
|
||||
return nil, status.Errorf(codes.InvalidArgument, "mirroring is not enabled on %s, image is in %d Mode", rbdVol.VolID, mirroringInfo.State)
|
||||
return nil, status.Errorf(
|
||||
codes.InvalidArgument,
|
||||
"mirroring is not enabled on %s, image is in %d Mode",
|
||||
rbdVol.VolID,
|
||||
mirroringInfo.State)
|
||||
}
|
||||
|
||||
// promote secondary to primary
|
||||
@ -353,7 +361,11 @@ func (rs *ReplicationServer) DemoteVolume(ctx context.Context,
|
||||
}
|
||||
|
||||
if mirroringInfo.State != librbd.MirrorImageEnabled {
|
||||
return nil, status.Errorf(codes.InvalidArgument, "mirroring is not enabled on %s, image is in %d Mode", rbdVol.VolID, mirroringInfo.State)
|
||||
return nil, status.Errorf(
|
||||
codes.InvalidArgument,
|
||||
"mirroring is not enabled on %s, image is in %d Mode",
|
||||
rbdVol.VolID,
|
||||
mirroringInfo.State)
|
||||
}
|
||||
|
||||
// demote image to secondary
|
||||
@ -449,7 +461,13 @@ func (rs *ReplicationServer) ResyncVolume(ctx context.Context,
|
||||
ready = true
|
||||
for _, s := range mirrorStatus.PeerSites {
|
||||
if imageMirroringState(s.State) != upAndUnknown {
|
||||
util.UsefulLog(ctx, "peer site name=%s, mirroring state=%s, description=%s and lastUpdate=%s", s.SiteName, s.State, s.Description, s.LastUpdate)
|
||||
util.UsefulLog(
|
||||
ctx,
|
||||
"peer site name=%s, mirroring state=%s, description=%s and lastUpdate=%s",
|
||||
s.SiteName,
|
||||
s.State,
|
||||
s.Description,
|
||||
s.LastUpdate)
|
||||
ready = false
|
||||
}
|
||||
}
|
||||
@ -464,7 +482,12 @@ func (rs *ReplicationServer) ResyncVolume(ctx context.Context,
|
||||
}
|
||||
}
|
||||
|
||||
util.UsefulLog(ctx, "image mirroring state=%s, description=%s and lastUpdate=%s", mirrorStatus.State, mirrorStatus.Description, mirrorStatus.LastUpdate)
|
||||
util.UsefulLog(
|
||||
ctx,
|
||||
"image mirroring state=%s, description=%s and lastUpdate=%s",
|
||||
mirrorStatus.State,
|
||||
mirrorStatus.Description,
|
||||
mirrorStatus.LastUpdate)
|
||||
resp := &replication.ResyncVolumeResponse{
|
||||
Ready: ready,
|
||||
}
|
||||
|
@ -23,7 +23,11 @@ import (
|
||||
"github.com/ceph/ceph-csi/internal/util"
|
||||
)
|
||||
|
||||
func createRBDClone(ctx context.Context, parentVol, cloneRbdVol *rbdVolume, snap *rbdSnapshot, cr *util.Credentials) error {
|
||||
func createRBDClone(
|
||||
ctx context.Context,
|
||||
parentVol, cloneRbdVol *rbdVolume,
|
||||
snap *rbdSnapshot,
|
||||
cr *util.Credentials) error {
|
||||
// create snapshot
|
||||
err := parentVol.createSnapshot(ctx, snap)
|
||||
if err != nil {
|
||||
@ -35,8 +39,17 @@ func createRBDClone(ctx context.Context, parentVol, cloneRbdVol *rbdVolume, snap
|
||||
// create clone image and delete snapshot
|
||||
err = cloneRbdVol.cloneRbdImageFromSnapshot(ctx, snap, parentVol)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to clone rbd image %s from snapshot %s: %v", cloneRbdVol.RbdImageName, snap.RbdSnapName, err)
|
||||
err = fmt.Errorf("failed to clone rbd image %s from snapshot %s: %w", cloneRbdVol.RbdImageName, snap.RbdSnapName, err)
|
||||
util.ErrorLog(
|
||||
ctx,
|
||||
"failed to clone rbd image %s from snapshot %s: %v",
|
||||
cloneRbdVol.RbdImageName,
|
||||
snap.RbdSnapName,
|
||||
err)
|
||||
err = fmt.Errorf(
|
||||
"failed to clone rbd image %s from snapshot %s: %w",
|
||||
cloneRbdVol.RbdImageName,
|
||||
snap.RbdSnapName,
|
||||
err)
|
||||
}
|
||||
errSnap := parentVol.deleteSnapshot(ctx, snap)
|
||||
if errSnap != nil {
|
||||
@ -63,14 +76,17 @@ func createRBDClone(ctx context.Context, parentVol, cloneRbdVol *rbdVolume, snap
|
||||
|
||||
// cleanUpSnapshot removes the RBD-snapshot (rbdSnap) from the RBD-image
|
||||
// (parentVol) and deletes the RBD-image rbdVol.
|
||||
func cleanUpSnapshot(ctx context.Context, parentVol *rbdVolume, rbdSnap *rbdSnapshot, rbdVol *rbdVolume, cr *util.Credentials) error {
|
||||
if parentVol != nil && rbdSnap != nil {
|
||||
err := parentVol.deleteSnapshot(ctx, rbdSnap)
|
||||
if err != nil {
|
||||
if !errors.Is(err, ErrSnapNotFound) {
|
||||
util.ErrorLog(ctx, "failed to delete snapshot %q: %v", rbdSnap, err)
|
||||
return err
|
||||
}
|
||||
func cleanUpSnapshot(
|
||||
ctx context.Context,
|
||||
parentVol *rbdVolume,
|
||||
rbdSnap *rbdSnapshot,
|
||||
rbdVol *rbdVolume,
|
||||
cr *util.Credentials) error {
|
||||
err := parentVol.deleteSnapshot(ctx, rbdSnap)
|
||||
if err != nil {
|
||||
if !errors.Is(err, ErrSnapNotFound) {
|
||||
util.ErrorLog(ctx, "failed to delete snapshot %q: %v", rbdSnap, err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@ -104,7 +120,12 @@ func generateVolFromSnap(rbdSnap *rbdSnapshot) *rbdVolume {
|
||||
return vol
|
||||
}
|
||||
|
||||
func undoSnapshotCloning(ctx context.Context, parentVol *rbdVolume, rbdSnap *rbdSnapshot, cloneVol *rbdVolume, cr *util.Credentials) error {
|
||||
func undoSnapshotCloning(
|
||||
ctx context.Context,
|
||||
parentVol *rbdVolume,
|
||||
rbdSnap *rbdSnapshot,
|
||||
cloneVol *rbdVolume,
|
||||
cr *util.Credentials) error {
|
||||
err := cleanUpSnapshot(ctx, parentVol, rbdSnap, cloneVol, cr)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to clean up %s or %s: %v", cloneVol, rbdSnap, err)
|
||||
|
Loading…
Reference in New Issue
Block a user