mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-22 14:20:19 +00:00
cleanup: remove unnecessary calling of .String() when logging
This commit removes calling of .String() when logging since `%s`,`%v` or `%q` will call an existing .String() function automatically. Fixes: #2051 Signed-off-by: Rakshith R <rar@redhat.com>
This commit is contained in:
parent
19a4d12bec
commit
6618e2012d
@ -900,7 +900,7 @@ func (cs *ControllerServer) doSnapshotClone(ctx context.Context, parentVol *rbdV
|
||||
cryptErr := parentVol.copyEncryptionConfig(&cloneRbd.rbdImage)
|
||||
if cryptErr != nil {
|
||||
util.WarningLog(ctx, "failed copy encryption "+
|
||||
"config for %q: %v", cloneRbd.String(), cryptErr)
|
||||
"config for %q: %v", cloneRbd, cryptErr)
|
||||
return ready, nil, status.Errorf(codes.Internal,
|
||||
err.Error())
|
||||
}
|
||||
|
@ -64,15 +64,15 @@ const (
|
||||
func (ri *rbdImage) checkRbdImageEncrypted(ctx context.Context) (rbdEncryptionState, error) {
|
||||
value, err := ri.GetMetadata(encryptionMetaKey)
|
||||
if errors.Is(err, librbd.ErrNotFound) {
|
||||
util.DebugLog(ctx, "image %s encrypted state not set", ri.String())
|
||||
util.DebugLog(ctx, "image %s encrypted state not set", ri)
|
||||
return rbdImageEncryptionUnknown, nil
|
||||
} else if err != nil {
|
||||
util.ErrorLog(ctx, "checking image %s encrypted state metadata failed: %s", ri.String(), err)
|
||||
util.ErrorLog(ctx, "checking image %s encrypted state metadata failed: %s", ri, err)
|
||||
return rbdImageEncryptionUnknown, err
|
||||
}
|
||||
|
||||
encrypted := rbdEncryptionState(strings.TrimSpace(value))
|
||||
util.DebugLog(ctx, "image %s encrypted state metadata reports %q", ri.String(), encrypted)
|
||||
util.DebugLog(ctx, "image %s encrypted state metadata reports %q", ri, encrypted)
|
||||
return encrypted, nil
|
||||
}
|
||||
|
||||
@ -97,14 +97,14 @@ func (ri *rbdImage) setupEncryption(ctx context.Context) error {
|
||||
err := ri.encryption.StoreNewCryptoPassphrase(ri.VolID)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to save encryption passphrase for "+
|
||||
"image %s: %s", ri.String(), err)
|
||||
"image %s: %s", ri, err)
|
||||
return err
|
||||
}
|
||||
|
||||
err = ri.ensureEncryptionMetadataSet(rbdImageEncryptionPrepared)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to save encryption status, deleting "+
|
||||
"image %s: %s", ri.String(), err)
|
||||
"image %s: %s", ri, err)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -125,7 +125,7 @@ func (ri *rbdImage) copyEncryptionConfig(cp *rbdImage) error {
|
||||
passphrase, err := ri.encryption.GetCryptoPassphrase(ri.VolID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to fetch passphrase for %q: %w",
|
||||
ri.String(), err)
|
||||
ri, err)
|
||||
}
|
||||
|
||||
cp.encryption, err = util.NewVolumeEncryption(ri.encryption.GetID(), ri.encryption.KMS)
|
||||
@ -137,19 +137,19 @@ func (ri *rbdImage) copyEncryptionConfig(cp *rbdImage) error {
|
||||
err = cp.encryption.StoreCryptoPassphrase(cp.VolID, passphrase)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to store passphrase for %q: %w",
|
||||
cp.String(), err)
|
||||
cp, err)
|
||||
}
|
||||
|
||||
// copy encryption status for the original volume
|
||||
status, err := ri.checkRbdImageEncrypted(context.TODO())
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get encryption status for %q: %w",
|
||||
ri.String(), err)
|
||||
ri, err)
|
||||
}
|
||||
err = cp.ensureEncryptionMetadataSet(status)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to store encryption status for %q: "+
|
||||
"%w", cp.String(), err)
|
||||
"%w", cp, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -180,12 +180,12 @@ func (ri *rbdImage) encryptDevice(ctx context.Context, devicePath string) error
|
||||
passphrase, err := ri.encryption.GetCryptoPassphrase(ri.VolID)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to get crypto passphrase for %s: %v",
|
||||
ri.String(), err)
|
||||
ri, err)
|
||||
return err
|
||||
}
|
||||
|
||||
if err = util.EncryptVolume(ctx, devicePath, passphrase); err != nil {
|
||||
err = fmt.Errorf("failed to encrypt volume %s: %w", ri.String(), err)
|
||||
err = fmt.Errorf("failed to encrypt volume %s: %w", ri, err)
|
||||
util.ErrorLog(ctx, err.Error())
|
||||
return err
|
||||
}
|
||||
@ -203,7 +203,7 @@ func (rv *rbdVolume) openEncryptedDevice(ctx context.Context, devicePath string)
|
||||
passphrase, err := rv.encryption.GetCryptoPassphrase(rv.VolID)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to get passphrase for encrypted device %s: %v",
|
||||
rv.String(), err)
|
||||
rv, err)
|
||||
return "", err
|
||||
}
|
||||
|
||||
@ -220,7 +220,7 @@ func (rv *rbdVolume) openEncryptedDevice(ctx context.Context, devicePath string)
|
||||
err = util.OpenEncryptedVolume(ctx, devicePath, mapperFile, passphrase)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to open device %s: %v",
|
||||
rv.String(), err)
|
||||
rv, err)
|
||||
return devicePath, err
|
||||
}
|
||||
}
|
||||
@ -241,7 +241,7 @@ func (ri *rbdImage) initKMS(ctx context.Context, volOptions, credentials map[str
|
||||
// FIXME: this works only on Kubernetes, how do other CO supply metadata?
|
||||
ri.Owner, ok = volOptions["csi.storage.k8s.io/pvc/namespace"]
|
||||
if !ok {
|
||||
util.DebugLog(ctx, "could not detect owner for %s", ri.String())
|
||||
util.DebugLog(ctx, "could not detect owner for %s", ri)
|
||||
}
|
||||
|
||||
encrypted, ok = volOptions["encrypted"]
|
||||
@ -291,7 +291,7 @@ func (ri *rbdImage) StoreDEK(volumeID, dek string) error {
|
||||
"stack: %s", ri, util.CallStack())
|
||||
} else if ri.VolID != volumeID {
|
||||
return fmt.Errorf("volume %q can not store DEK for %q",
|
||||
ri.String(), volumeID)
|
||||
ri, volumeID)
|
||||
}
|
||||
|
||||
return ri.SetMetadata(metadataDEK, dek)
|
||||
@ -303,7 +303,7 @@ func (ri *rbdImage) FetchDEK(volumeID string) (string, error) {
|
||||
return "", fmt.Errorf("BUG: %q does not have VolID set, call "+
|
||||
"stack: %s", ri, util.CallStack())
|
||||
} else if ri.VolID != volumeID {
|
||||
return "", fmt.Errorf("volume %q can not fetch DEK for %q", ri.String(), volumeID)
|
||||
return "", fmt.Errorf("volume %q can not fetch DEK for %q", ri, volumeID)
|
||||
}
|
||||
|
||||
return ri.GetMetadata(metadataDEK)
|
||||
@ -317,7 +317,7 @@ func (ri *rbdImage) RemoveDEK(volumeID string) error {
|
||||
"stack: %s", ri, util.CallStack())
|
||||
} else if ri.VolID != volumeID {
|
||||
return fmt.Errorf("volume %q can not remove DEK for %q",
|
||||
ri.String(), volumeID)
|
||||
ri, volumeID)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -30,13 +30,13 @@ import (
|
||||
func (ri *rbdImage) enableImageMirroring(mode librbd.ImageMirrorMode) error {
|
||||
image, err := ri.open()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open image %q with error: %w", ri.String(), err)
|
||||
return fmt.Errorf("failed to open image %q with error: %w", ri, err)
|
||||
}
|
||||
defer image.Close()
|
||||
|
||||
err = image.MirrorEnable(mode)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to enable mirroring on %q with error: %w", ri.String(), err)
|
||||
return fmt.Errorf("failed to enable mirroring on %q with error: %w", ri, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -45,13 +45,13 @@ func (ri *rbdImage) enableImageMirroring(mode librbd.ImageMirrorMode) error {
|
||||
func (ri *rbdImage) disableImageMirroring(force bool) error {
|
||||
image, err := ri.open()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open image %q with error: %w", ri.String(), err)
|
||||
return fmt.Errorf("failed to open image %q with error: %w", ri, err)
|
||||
}
|
||||
defer image.Close()
|
||||
|
||||
err = image.MirrorDisable(force)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to disable mirroring on %q with error: %w", ri.String(), err)
|
||||
return fmt.Errorf("failed to disable mirroring on %q with error: %w", ri, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -60,13 +60,13 @@ func (ri *rbdImage) disableImageMirroring(force bool) error {
|
||||
func (ri *rbdImage) getImageMirroringInfo() (*librbd.MirrorImageInfo, error) {
|
||||
image, err := ri.open()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open image %q with error: %w", ri.String(), err)
|
||||
return nil, fmt.Errorf("failed to open image %q with error: %w", ri, err)
|
||||
}
|
||||
defer image.Close()
|
||||
|
||||
info, err := image.GetMirrorImageInfo()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get mirroring info of %q with error: %w", ri.String(), err)
|
||||
return nil, fmt.Errorf("failed to get mirroring info of %q with error: %w", ri, err)
|
||||
}
|
||||
return info, nil
|
||||
}
|
||||
@ -75,12 +75,12 @@ func (ri *rbdImage) getImageMirroringInfo() (*librbd.MirrorImageInfo, error) {
|
||||
func (ri *rbdImage) promoteImage(force bool) error {
|
||||
image, err := ri.open()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open image %q with error: %w", ri.String(), err)
|
||||
return fmt.Errorf("failed to open image %q with error: %w", ri, err)
|
||||
}
|
||||
defer image.Close()
|
||||
err = image.MirrorPromote(force)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to promote image %q with error: %w", ri.String(), err)
|
||||
return fmt.Errorf("failed to promote image %q with error: %w", ri, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -89,12 +89,12 @@ func (ri *rbdImage) promoteImage(force bool) error {
|
||||
func (ri *rbdImage) demoteImage() error {
|
||||
image, err := ri.open()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open image %q with error: %w", ri.String(), err)
|
||||
return fmt.Errorf("failed to open image %q with error: %w", ri, err)
|
||||
}
|
||||
defer image.Close()
|
||||
err = image.MirrorDemote()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to demote image %q with error: %w", ri.String(), err)
|
||||
return fmt.Errorf("failed to demote image %q with error: %w", ri, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -103,12 +103,12 @@ func (ri *rbdImage) demoteImage() error {
|
||||
func (ri *rbdImage) resyncImage() error {
|
||||
image, err := ri.open()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open image %q with error: %w", ri.String(), err)
|
||||
return fmt.Errorf("failed to open image %q with error: %w", ri, err)
|
||||
}
|
||||
defer image.Close()
|
||||
err = image.MirrorResync()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resync image %q with error: %w", ri.String(), err)
|
||||
return fmt.Errorf("failed to resync image %q with error: %w", ri, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -256,7 +256,7 @@ func createPath(ctx context.Context, volOpt *rbdVolume, cr *util.Credentials) (s
|
||||
// check if the image should stay thick-provisioned
|
||||
isThick, err := volOpt.isThickProvisioned()
|
||||
if err != nil {
|
||||
util.WarningLog(ctx, "failed to detect if image %q is thick-provisioned: %v", volOpt.String(), err)
|
||||
util.WarningLog(ctx, "failed to detect if image %q is thick-provisioned: %v", volOpt, err)
|
||||
}
|
||||
|
||||
mapArgs = appendDeviceTypeAndOptions(mapArgs, isNbd, isThick, volOpt.MapOptions)
|
||||
|
@ -485,7 +485,7 @@ func deleteImage(ctx context.Context, pOpts *rbdVolume, cr *util.Credentials) er
|
||||
}
|
||||
|
||||
if pOpts.isEncrypted() {
|
||||
util.DebugLog(ctx, "rbd: going to remove DEK for %q", pOpts.String())
|
||||
util.DebugLog(ctx, "rbd: going to remove DEK for %q", pOpts)
|
||||
if err = pOpts.encryption.RemoveDEK(pOpts.VolID); err != nil {
|
||||
util.WarningLog(ctx, "failed to clean the passphrase for volume %s: %s", pOpts.VolID, err)
|
||||
}
|
||||
@ -554,7 +554,7 @@ func (rv *rbdVolume) getCloneDepth(ctx context.Context) (uint, error) {
|
||||
if errors.Is(err, ErrImageNotFound) {
|
||||
return depth, nil
|
||||
}
|
||||
util.ErrorLog(ctx, "failed to check depth on image %s: %s", vol.String(), err)
|
||||
util.ErrorLog(ctx, "failed to check depth on image %s: %s", &vol, err)
|
||||
return depth, err
|
||||
}
|
||||
if vol.ParentName != "" {
|
||||
@ -807,14 +807,14 @@ func genSnapFromSnapID(ctx context.Context, rbdSnap *rbdSnapshot, snapshotID str
|
||||
}()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to connect to %q: %w",
|
||||
rbdSnap.String(), err)
|
||||
rbdSnap, err)
|
||||
}
|
||||
|
||||
if imageAttributes.KmsID != "" {
|
||||
err = rbdSnap.configureEncryption(imageAttributes.KmsID, secrets)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to configure encryption for "+
|
||||
"%q: %w", rbdSnap.String(), err)
|
||||
"%q: %w", rbdSnap, err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1119,7 +1119,7 @@ func (rv *rbdVolume) cloneRbdImageFromSnapshot(ctx context.Context, pSnapOpts *r
|
||||
if deleteClone {
|
||||
err = librbd.RemoveImage(rv.ioctx, rv.RbdImageName)
|
||||
if err != nil {
|
||||
util.ErrorLog(ctx, "failed to delete temporary image %q: %v", rv.String(), err)
|
||||
util.ErrorLog(ctx, "failed to delete temporary image %q: %v", rv, err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
@ -1254,7 +1254,7 @@ func (rv *rbdVolume) checkSnapExists(rbdSnap *rbdSnapshot) error {
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("%w: snap %s not found", ErrSnapNotFound, rbdSnap.String())
|
||||
return fmt.Errorf("%w: snap %s not found", ErrSnapNotFound, rbdSnap)
|
||||
}
|
||||
|
||||
// rbdImageMetadataStash strongly typed JSON spec for stashed RBD image metadata.
|
||||
@ -1416,7 +1416,7 @@ func (ri *rbdImage) SetMetadata(key, value string) error {
|
||||
func (rv *rbdVolume) setThickProvisioned() error {
|
||||
err := rv.SetMetadata(thickProvisionMetaKey, "true")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to set metadata %q for %q: %w", thickProvisionMetaKey, rv.String(), err)
|
||||
return fmt.Errorf("failed to set metadata %q for %q: %w", thickProvisionMetaKey, rv, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -1431,7 +1431,7 @@ func (rv *rbdVolume) isThickProvisioned() (bool, error) {
|
||||
if err == librbd.ErrNotFound {
|
||||
return false, nil
|
||||
}
|
||||
return false, fmt.Errorf("failed to get metadata %q for %q: %w", thickProvisionMetaKey, rv.String(), err)
|
||||
return false, fmt.Errorf("failed to get metadata %q for %q: %w", thickProvisionMetaKey, rv, err)
|
||||
}
|
||||
|
||||
thick, err := strconv.ParseBool(value)
|
||||
|
Loading…
Reference in New Issue
Block a user