[v1.26] disk: avoid concurrent operation on the same disk #1325
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
/kind bug
What this PR does / why we need it:
If the umount takes extremely long time and the NodeUnstageVolume RPC times out, kubelet may invoke NodeStageVolume when it retries and we may mistake an unmounting path as a good one. This lock only protects us in one process. But fortunately, when restarting CSI, Kubernetes will wait for the previous process to exit before starting the new one, even if it stucks in uninterruptible syscall (D state). So, we will not have multiple processes on the same node and the lock should be safe enough.
Note that there is still small chance that the previous attach/detach OpenAPI is invoked by the terminated CSI process, but the state returned by DescribeDisks is not updated yet. We should fix this by switch attach/detach to controller.
This is a backport commit. We backport this to workaround another edge case in QEMU/Linux. If we call DetachDisk while unmounting, the disk will stuck at Detaching state, then QEMU will issue multiple interrupts to retry detaching. After unmount finished, Linux kernel will eject the PCI slot multiple times in response to the interrupts. But that may eject the disk that was just inserted to the same slot. This commit will ensure we don't call DetachDisk while unmounting in UnstageVolume.
Note that we may still call DetachDisk in DeleteVolume, which may be triggered by old KCM if unmounting takes over 6min. And this is still possible to trigger the above edge case.
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
backport of #1170 (partial)
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: