mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-18 11:00:25 +00:00
rbd: call undoStagingTransaction() when NodeStageVolume() fails
On line 341 a `transaction` is created. This is passed to the deferred `undoStagingTransaction()` function when an error in the `NodeStageVolume` procedure is detected. So far, so good. However, on line 356 a new `transaction` is returned. This new `transaction` is not used for the defer call. By removing the empty `transaction` that is used in the defer call, and calling `undoStagingTransaction()` on an error of `stageTransaction()`, the code is a little simpler, and the cleanup of the transaction should be done correctly now. Updates: #2610 Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
parent
50832f4f06
commit
7e22180125
@ -335,22 +335,21 @@ func (ns *NodeServer) NodeStageVolume(
|
|||||||
return &csi.NodeStageVolumeResponse{}, nil
|
return &csi.NodeStageVolumeResponse{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
transaction := stageTransaction{}
|
|
||||||
// Stash image details prior to mapping the image (useful during Unstage as it has no
|
// Stash image details prior to mapping the image (useful during Unstage as it has no
|
||||||
// voloptions passed to the RPC as per the CSI spec)
|
// voloptions passed to the RPC as per the CSI spec)
|
||||||
err = stashRBDImageMetadata(rv, stagingParentPath)
|
err = stashRBDImageMetadata(rv, stagingParentPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, status.Error(codes.Internal, err.Error())
|
return nil, status.Error(codes.Internal, err.Error())
|
||||||
}
|
}
|
||||||
defer func() {
|
|
||||||
if err != nil {
|
|
||||||
ns.undoStagingTransaction(ctx, req, transaction, rv)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// perform the actual staging and if this fails, have undoStagingTransaction
|
// perform the actual staging and if this fails, have undoStagingTransaction
|
||||||
// cleans up for us
|
// cleans up for us
|
||||||
transaction, err = ns.stageTransaction(ctx, req, cr, rv, isStaticVol)
|
txn, err := ns.stageTransaction(ctx, req, cr, rv, isStaticVol)
|
||||||
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
ns.undoStagingTransaction(ctx, req, txn, rv)
|
||||||
|
}
|
||||||
|
}()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, status.Error(codes.Internal, err.Error())
|
return nil, status.Error(codes.Internal, err.Error())
|
||||||
}
|
}
|
||||||
@ -369,8 +368,8 @@ func (ns *NodeServer) stageTransaction(
|
|||||||
req *csi.NodeStageVolumeRequest,
|
req *csi.NodeStageVolumeRequest,
|
||||||
cr *util.Credentials,
|
cr *util.Credentials,
|
||||||
volOptions *rbdVolume,
|
volOptions *rbdVolume,
|
||||||
staticVol bool) (stageTransaction, error) {
|
staticVol bool) (*stageTransaction, error) {
|
||||||
transaction := stageTransaction{}
|
transaction := &stageTransaction{}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
var readOnly bool
|
var readOnly bool
|
||||||
@ -500,7 +499,7 @@ func flattenImageBeforeMapping(
|
|||||||
func (ns *NodeServer) undoStagingTransaction(
|
func (ns *NodeServer) undoStagingTransaction(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *csi.NodeStageVolumeRequest,
|
req *csi.NodeStageVolumeRequest,
|
||||||
transaction stageTransaction,
|
transaction *stageTransaction,
|
||||||
volOptions *rbdVolume) {
|
volOptions *rbdVolume) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user