Fix a race condition in add SCSI workflow #1483
Merged
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.
addSCSI currently uses a mutex only to check if a disk is already attached to the UVM. However, no mutex is
held when actually attaching the disk to the UVM. Because of this if two goroutines try to add the same SCSI
disk to a UVM at the same time, one of them will see that the disk is not already attached, will add an entry
into the controller/LUN map and continue with the attach process. The other goroutine will just see the entry
in the map and returns thinking that the SCSI disk is already attached to the UVM. At this point the disk
attach operation from the first goroutine is still in progress so if the second goroutine tries to use that
disk inside the UVM it fails with cryptic errors from overlayfs (or whatever other component in the guest that
tries to use this disk).
To get around this problem, we now include a channel in each SCSIMount struct that should be used by all the
goroutines (except for the very first goroutine that adds this disk) to wait until the mounting of that SCSI
disk is complete. Only the very first goroutine that adds this disk should close it.
Signed-off-by: Amit Barve ambarve@microsoft.com