mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-10 00:10:20 +00:00
rbd: move flattening to helper function
in NodeStage operation we are flattening the image to support mounting on the older clients. this commits moves it to a helper function to reduce code complexity. Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
parent
cda2abca5d
commit
fe9020260d
@ -386,8 +386,6 @@ func (ns *NodeServer) stageTransaction(
|
|||||||
|
|
||||||
var err error
|
var err error
|
||||||
var readOnly bool
|
var readOnly bool
|
||||||
var feature bool
|
|
||||||
var depth uint
|
|
||||||
|
|
||||||
var cr *util.Credentials
|
var cr *util.Credentials
|
||||||
cr, err = util.NewUserCredentials(req.GetSecrets())
|
cr, err = util.NewUserCredentials(req.GetSecrets())
|
||||||
@ -403,29 +401,11 @@ func (ns *NodeServer) stageTransaction(
|
|||||||
volOptions.readOnly = true
|
volOptions.readOnly = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if kernelRelease == "" {
|
err = flattenImageBeforeMapping(ctx, volOptions, cr)
|
||||||
// fetch the current running kernel info
|
if err != nil {
|
||||||
kernelRelease, err = util.GetKernelVersion()
|
return transaction, err
|
||||||
if err != nil {
|
|
||||||
return transaction, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !util.CheckKernelSupport(kernelRelease, deepFlattenSupport) && !skipForceFlatten {
|
|
||||||
feature, err = volOptions.checkImageChainHasFeature(ctx, librbd.FeatureDeepFlatten)
|
|
||||||
if err != nil {
|
|
||||||
return transaction, err
|
|
||||||
}
|
|
||||||
depth, err = volOptions.getCloneDepth(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return transaction, err
|
|
||||||
}
|
|
||||||
if feature || depth != 0 {
|
|
||||||
err = volOptions.flattenRbdImage(ctx, cr, true, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
|
|
||||||
if err != nil {
|
|
||||||
return transaction, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mapping RBD image
|
// Mapping RBD image
|
||||||
var devicePath string
|
var devicePath string
|
||||||
devicePath, err = attachRBDImage(ctx, volOptions, devicePath, cr)
|
devicePath, err = attachRBDImage(ctx, volOptions, devicePath, cr)
|
||||||
@ -481,6 +461,41 @@ func (ns *NodeServer) stageTransaction(
|
|||||||
return transaction, err
|
return transaction, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func flattenImageBeforeMapping(
|
||||||
|
ctx context.Context,
|
||||||
|
volOptions *rbdVolume,
|
||||||
|
cr *util.Credentials) error {
|
||||||
|
var err error
|
||||||
|
var feature bool
|
||||||
|
var depth uint
|
||||||
|
|
||||||
|
if kernelRelease == "" {
|
||||||
|
// fetch the current running kernel info
|
||||||
|
kernelRelease, err = util.GetKernelVersion()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !util.CheckKernelSupport(kernelRelease, deepFlattenSupport) && !skipForceFlatten {
|
||||||
|
feature, err = volOptions.checkImageChainHasFeature(ctx, librbd.FeatureDeepFlatten)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
depth, err = volOptions.getCloneDepth(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if feature || depth != 0 {
|
||||||
|
err = volOptions.flattenRbdImage(ctx, cr, true, rbdHardMaxCloneDepth, rbdSoftMaxCloneDepth)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (ns *NodeServer) undoStagingTransaction(
|
func (ns *NodeServer) undoStagingTransaction(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *csi.NodeStageVolumeRequest,
|
req *csi.NodeStageVolumeRequest,
|
||||||
|
Loading…
Reference in New Issue
Block a user