cephfs: replace Errorf with util.ErrorLog in createCloneFromSubvolume

replace Errorf with util.ErrorLog in createCloneFromSubvolume
for context based logging.

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna 2020-08-11 17:16:45 +05:30 committed by mergify[bot]
parent 20dbbe54b0
commit e1fb708d48

View File

@ -41,7 +41,7 @@ func createCloneFromSubvolume(ctx context.Context, volID, cloneID volumeID, volO
snapshotID := cloneID snapshotID := cloneID
err := createSnapshot(ctx, parentvolOpt, cr, snapshotID, volID) err := createSnapshot(ctx, parentvolOpt, cr, snapshotID, volID)
if err != nil { if err != nil {
klog.Errorf(util.Log(ctx, "failed to create snapshot %s %v"), snapshotID, err) util.ErrorLog(ctx, "failed to create snapshot %s %v", snapshotID, err)
return err return err
} }
var ( var (
@ -54,36 +54,36 @@ func createCloneFromSubvolume(ctx context.Context, volID, cloneID volumeID, volO
if protectErr != nil { if protectErr != nil {
err = deleteSnapshot(ctx, parentvolOpt, cr, snapshotID, volID) err = deleteSnapshot(ctx, parentvolOpt, cr, snapshotID, volID)
if err != nil { if err != nil {
klog.Errorf(util.Log(ctx, "failed to delete snapshot %s %v"), snapshotID, err) util.ErrorLog(ctx, "failed to delete snapshot %s %v", snapshotID, err)
} }
} }
if cloneErr != nil { if cloneErr != nil {
if err = purgeVolume(ctx, cloneID, cr, volOpt, true); err != nil { if err = purgeVolume(ctx, cloneID, cr, volOpt, true); err != nil {
klog.Errorf(util.Log(ctx, "failed to delete volume %s: %v"), cloneID, err) util.ErrorLog(ctx, "failed to delete volume %s: %v", cloneID, err)
} }
if err = unprotectSnapshot(ctx, parentvolOpt, cr, snapshotID, volID); err != nil { if err = unprotectSnapshot(ctx, parentvolOpt, cr, snapshotID, volID); err != nil {
// Incase the snap is already unprotected we get ErrSnapProtectionExist error code // Incase the snap is already unprotected we get ErrSnapProtectionExist error code
// in that case we are safe and we could discard this error and we are good to go // in that case we are safe and we could discard this error and we are good to go
// ahead with deletion // ahead with deletion
if !errors.Is(err, ErrSnapProtectionExist) { if !errors.Is(err, ErrSnapProtectionExist) {
klog.Errorf(util.Log(ctx, "failed to unprotect snapshot %s %v"), snapshotID, err) util.ErrorLog(ctx, "failed to unprotect snapshot %s %v", snapshotID, err)
} }
} }
if err = deleteSnapshot(ctx, parentvolOpt, cr, snapshotID, volID); err != nil { if err = deleteSnapshot(ctx, parentvolOpt, cr, snapshotID, volID); err != nil {
klog.Errorf(util.Log(ctx, "failed to delete snapshot %s %v"), snapshotID, err) util.ErrorLog(ctx, "failed to delete snapshot %s %v", snapshotID, err)
} }
} }
}() }()
protectErr = protectSnapshot(ctx, parentvolOpt, cr, snapshotID, volID) protectErr = protectSnapshot(ctx, parentvolOpt, cr, snapshotID, volID)
if protectErr != nil { if protectErr != nil {
klog.Errorf(util.Log(ctx, "failed to protect snapshot %s %v"), snapshotID, protectErr) util.ErrorLog(ctx, "failed to protect snapshot %s %v", snapshotID, protectErr)
return protectErr return protectErr
} }
cloneErr = cloneSnapshot(ctx, parentvolOpt, cr, volID, snapshotID, cloneID, volOpt) cloneErr = cloneSnapshot(ctx, parentvolOpt, cr, volID, snapshotID, cloneID, volOpt)
if cloneErr != nil { if cloneErr != nil {
klog.Errorf(util.Log(ctx, "failed to clone snapshot %s %s to %s %v"), volID, snapshotID, cloneID, cloneErr) util.ErrorLog(ctx, "failed to clone snapshot %s %s to %s %v", volID, snapshotID, cloneID, cloneErr)
return cloneErr return cloneErr
} }
var clone CloneStatus var clone CloneStatus
@ -94,17 +94,17 @@ func createCloneFromSubvolume(ctx context.Context, volID, cloneID volumeID, volO
switch clone.Status.State { switch clone.Status.State {
case cephFSCloneInprogress: case cephFSCloneInprogress:
klog.Errorf(util.Log(ctx, "clone is in progress for %v"), cloneID) util.ErrorLog(ctx, "clone is in progress for %v", cloneID)
return ErrCloneInProgress return ErrCloneInProgress
case cephFSCloneFailed: case cephFSCloneFailed:
klog.Errorf(util.Log(ctx, "clone failed for %v"), cloneID) util.ErrorLog(ctx, "clone failed for %v", cloneID)
cloneFailedErr := fmt.Errorf("clone %s is in %s state", cloneID, clone.Status.State) cloneFailedErr := fmt.Errorf("clone %s is in %s state", cloneID, clone.Status.State)
return cloneFailedErr return cloneFailedErr
case cephFSCloneComplete: case cephFSCloneComplete:
// This is a work around to fix sizing issue for cloned images // This is a work around to fix sizing issue for cloned images
err = resizeVolume(ctx, volOpt, cr, cloneID, volOpt.Size) err = resizeVolume(ctx, volOpt, cr, cloneID, volOpt.Size)
if err != nil { if err != nil {
klog.Errorf(util.Log(ctx, "failed to expand volume %s: %v"), cloneID, err) util.ErrorLog(ctx, "failed to expand volume %s: %v", cloneID, err)
return err return err
} }
// As we completed clone, remove the intermediate snap // As we completed clone, remove the intermediate snap
@ -113,12 +113,12 @@ func createCloneFromSubvolume(ctx context.Context, volID, cloneID volumeID, volO
// in that case we are safe and we could discard this error and we are good to go // in that case we are safe and we could discard this error and we are good to go
// ahead with deletion // ahead with deletion
if !errors.Is(err, ErrSnapProtectionExist) { if !errors.Is(err, ErrSnapProtectionExist) {
klog.Errorf(util.Log(ctx, "failed to unprotect snapshot %s %v"), snapshotID, err) util.ErrorLog(ctx, "failed to unprotect snapshot %s %v", snapshotID, err)
return err return err
} }
} }
if err = deleteSnapshot(ctx, parentvolOpt, cr, snapshotID, volID); err != nil { if err = deleteSnapshot(ctx, parentvolOpt, cr, snapshotID, volID); err != nil {
klog.Errorf(util.Log(ctx, "failed to delete snapshot %s %v"), snapshotID, err) util.ErrorLog(ctx, "failed to delete snapshot %s %v", snapshotID, err)
return err return err
} }
} }