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:
Humble Chirammal 2021-06-25 17:22:34 +05:30 committed by mergify[bot]
parent e829308249
commit 8f82a30c21
5 changed files with 158 additions and 36 deletions

View File

@ -96,7 +96,10 @@ func rbdGetDeviceList(ctx context.Context, accessType string) ([]rbdDeviceInfo,
err = json.Unmarshal([]byte(stdout), &nbdDeviceList) err = json.Unmarshal([]byte(stdout), &nbdDeviceList)
} }
if err != nil { 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 // 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) util.WarningLog(ctx, "rbd: map error %v, rbd output: %s", err, stderr)
// unmap rbd image if connection timeout // unmap rbd image if connection timeout
if strings.Contains(err.Error(), rbdMapConnectionTimeout) { 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 { if detErr != nil {
util.WarningLog(ctx, "rbd: %s unmap error %v", imagePath, detErr) 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 // detachRBDImageOrDeviceSpec detaches an rbd imageSpec or devicePath, with additional checking
// when imageSpec is used to decide if image is already unmapped. // 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 { if encrypted {
mapperFile, mapperPath := util.VolumeMapper(volumeID) mapperFile, mapperPath := util.VolumeMapper(volumeID)
mappedDevice, mapper, err := util.DeviceEncryptionStatus(ctx, mapperPath) mappedDevice, mapper, err := util.DeviceEncryptionStatus(ctx, mapperPath)

View File

@ -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 hence any stale omaps are leftovers from incomplete transactions and are hence
safe to garbage collect. 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) err := validateRbdSnap(rbdSnap)
if err != nil { if err != nil {
return false, err return false, err
@ -517,7 +521,9 @@ func undoVolReservation(ctx context.Context, rbdVol *rbdVolume, cr *util.Credent
// Generate new volume Handler // Generate new volume Handler
// The volume handler won't remain same as its contains poolID,clusterID etc // The volume handler won't remain same as its contains poolID,clusterID etc
// which are not same across clusters. // 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() ctx := context.Background()
var ( var (
options map[string]string options map[string]string

View File

@ -472,7 +472,13 @@ func isNotMountPoint(mounter mount.Interface, stagingTargetPath string) (bool, e
func addRbdManagerTask(ctx context.Context, pOpts *rbdVolume, arg []string) (bool, error) { func addRbdManagerTask(ctx context.Context, pOpts *rbdVolume, arg []string) (bool, error) {
args := []string{"rbd", "task", "add"} args := []string{"rbd", "task", "add"}
args = append(args, arg...) 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 supported := true
_, stderr, err := util.ExecCommand(ctx, "ceph", args...) _, stderr, err := util.ExecCommand(ctx, "ceph", args...)
@ -480,7 +486,11 @@ func addRbdManagerTask(ctx context.Context, pOpts *rbdVolume, arg []string) (boo
switch { switch {
case strings.Contains(stderr, rbdTaskRemoveCmdInvalidString1) && case strings.Contains(stderr, rbdTaskRemoveCmdInvalidString1) &&
strings.Contains(stderr, rbdTaskRemoveCmdInvalidString2): 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 supported = false
case strings.HasPrefix(stderr, rbdTaskRemoveCmdAccessDeniedMessage): case strings.HasPrefix(stderr, rbdTaskRemoveCmdAccessDeniedMessage):
util.WarningLog(ctx, "access denied to Ceph MGR-based rbd commands on cluster ID (%s)", pOpts.ClusterID) 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 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 := &rbdVolume{}
rv.Monitors = monitors rv.Monitors = monitors
rv.Pool = pool rv.Pool = pool
@ -636,7 +650,11 @@ func flattenClonedRbdImages(ctx context.Context, snaps []librbd.SnapInfo, pool,
return nil 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 depth uint
var err error var err error
@ -646,7 +664,13 @@ func (rv *rbdVolume) flattenRbdImage(ctx context.Context, cr *util.Credentials,
if err != nil { if err != nil {
return err 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) { if !forceFlatten && (depth < hardlimit) && (depth < softlimit) {
@ -669,7 +693,10 @@ func (rv *rbdVolume) flattenRbdImage(ctx context.Context, cr *util.Credentials,
} }
} }
if !supported { 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 { if forceFlatten || depth >= hardlimit {
err = rv.Connect(cr) err = rv.Connect(cr)
if err != nil { 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 // genSnapFromSnapID generates a rbdSnapshot structure from the provided identifier, updating
// the structure with elements from on-disk snapshot metadata as well. // 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 ( var (
options map[string]string options map[string]string
vi util.CSIIdentifier 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. // 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 ( var (
options map[string]string options map[string]string
vi util.CSIIdentifier 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 // genVolFromVolID generates a rbdVolume structure from the provided identifier, updating
// the structure with elements from on-disk image metadata as well. // 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) 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 return vol, err
} }
@ -974,7 +1015,10 @@ func genVolFromVolID(ctx context.Context, volumeID string, cr *util.Credentials,
return vol, err 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 ( var (
ok bool ok bool
err error err error
@ -1012,7 +1056,12 @@ func genVolFromVolumeOptions(ctx context.Context, volOptions, credentials map[st
return nil, err 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 rbdVol.DisableInUseChecks = disableInUseChecks
err = rbdVol.initKMS(ctx, volOptions, credentials) err = rbdVol.initKMS(ctx, volOptions, credentials)
@ -1110,7 +1159,10 @@ func (rv *rbdVolume) deleteSnapshot(ctx context.Context, pOpts *rbdSnapshot) err
return 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 var err error
logMsg := "rbd: clone %s %s (features: %s) using mon %s" 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) 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 { if err != nil {
return fmt.Errorf("failed to create rbd clone: %w", err) return fmt.Errorf("failed to create rbd clone: %w", err)
} }

View File

@ -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) { func getMirroringMode(ctx context.Context, parameters map[string]string) (librbd.ImageMirrorMode, error) {
val, ok := parameters[imageMirroringKey] val, ok := parameters[imageMirroringKey]
if !ok { 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 return librbd.ImageMirrorModeSnapshot, nil
} }
@ -286,7 +290,11 @@ func (rs *ReplicationServer) PromoteVolume(ctx context.Context,
} }
if mirroringInfo.State != librbd.MirrorImageEnabled { 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 // promote secondary to primary
@ -353,7 +361,11 @@ func (rs *ReplicationServer) DemoteVolume(ctx context.Context,
} }
if mirroringInfo.State != librbd.MirrorImageEnabled { 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 // demote image to secondary
@ -449,7 +461,13 @@ func (rs *ReplicationServer) ResyncVolume(ctx context.Context,
ready = true ready = true
for _, s := range mirrorStatus.PeerSites { for _, s := range mirrorStatus.PeerSites {
if imageMirroringState(s.State) != upAndUnknown { 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 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{ resp := &replication.ResyncVolumeResponse{
Ready: ready, Ready: ready,
} }

View File

@ -23,7 +23,11 @@ import (
"github.com/ceph/ceph-csi/internal/util" "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 // create snapshot
err := parentVol.createSnapshot(ctx, snap) err := parentVol.createSnapshot(ctx, snap)
if err != nil { if err != nil {
@ -35,8 +39,17 @@ func createRBDClone(ctx context.Context, parentVol, cloneRbdVol *rbdVolume, snap
// create clone image and delete snapshot // create clone image and delete snapshot
err = cloneRbdVol.cloneRbdImageFromSnapshot(ctx, snap, parentVol) err = cloneRbdVol.cloneRbdImageFromSnapshot(ctx, snap, parentVol)
if err != nil { if err != nil {
util.ErrorLog(ctx, "failed to clone rbd image %s from snapshot %s: %v", cloneRbdVol.RbdImageName, snap.RbdSnapName, err) util.ErrorLog(
err = fmt.Errorf("failed to clone rbd image %s from snapshot %s: %w", cloneRbdVol.RbdImageName, snap.RbdSnapName, err) 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) errSnap := parentVol.deleteSnapshot(ctx, snap)
if errSnap != nil { if errSnap != nil {
@ -63,8 +76,12 @@ func createRBDClone(ctx context.Context, parentVol, cloneRbdVol *rbdVolume, snap
// cleanUpSnapshot removes the RBD-snapshot (rbdSnap) from the RBD-image // cleanUpSnapshot removes the RBD-snapshot (rbdSnap) from the RBD-image
// (parentVol) and deletes the RBD-image rbdVol. // (parentVol) and deletes the RBD-image rbdVol.
func cleanUpSnapshot(ctx context.Context, parentVol *rbdVolume, rbdSnap *rbdSnapshot, rbdVol *rbdVolume, cr *util.Credentials) error { func cleanUpSnapshot(
if parentVol != nil && rbdSnap != nil { ctx context.Context,
parentVol *rbdVolume,
rbdSnap *rbdSnapshot,
rbdVol *rbdVolume,
cr *util.Credentials) error {
err := parentVol.deleteSnapshot(ctx, rbdSnap) err := parentVol.deleteSnapshot(ctx, rbdSnap)
if err != nil { if err != nil {
if !errors.Is(err, ErrSnapNotFound) { if !errors.Is(err, ErrSnapNotFound) {
@ -72,7 +89,6 @@ func cleanUpSnapshot(ctx context.Context, parentVol *rbdVolume, rbdSnap *rbdSnap
return err return err
} }
} }
}
if rbdVol != nil { if rbdVol != nil {
err := deleteImage(ctx, rbdVol, cr) err := deleteImage(ctx, rbdVol, cr)
@ -104,7 +120,12 @@ func generateVolFromSnap(rbdSnap *rbdSnapshot) *rbdVolume {
return vol 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) err := cleanUpSnapshot(ctx, parentVol, rbdSnap, cloneVol, cr)
if err != nil { if err != nil {
util.ErrorLog(ctx, "failed to clean up %s or %s: %v", cloneVol, rbdSnap, err) util.ErrorLog(ctx, "failed to clean up %s or %s: %v", cloneVol, rbdSnap, err)