Skip to content

vcsim: fix reattach in CNS - #4141

Merged
dougm merged 1 commit into
vmware:mainfrom
elesueur:topic/elesueur/vcsim-cns-reattach
Oct 7, 2026
Merged

dougm merged 1 commit into
vmware:mainfrom
elesueur:topic/elesueur/vcsim-cns-reattach

Conversation

@elesueur

@elesueur elesueur commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Description

When a CNS volume is already attached to a VM, a request to attach it to the same VM fails with ResourceInUse.

In a real VC, this is allowed to succeed as an idempotent operation.

The ResourceInUse failure is triggered when CSI driver in vanilla k8s cluster restarts after disks are already attached and subsequent attachments continue to fail forever.

How Has This Been Tested?

Manual unit tests and testing when vcsim is integrated into our own shim for testing k8s native vsphere CSI driver.

@legal-compliance-bot

Copy link
Copy Markdown

🛑 Legal Compliance Check Failed

Hi @elesueur, thank you for your contribution!

To merge this Pull Request, you must sign our DCO.

Note: Even if you signed off your commits locally (using git commit -s), you must post the comment below to register your signature with our automated system.
Note: This is a one-time process. Once signed, future contributions to this repository will be verified automatically.

1. Read the Document: Click here to read the DCO
2. Sign via Comment: Copy and paste the exact line below into a new comment on this Pull Request:

I have read the DCO Document and I hereby sign the DCO for this and all future contributions.

⏳ Processing Schedule:
Our 'Compliance Sweeper' runs automatically approximately every 15-20 minutes.
After you post the comment, your status will update automatically during the next scheduled run.
You do not need to take any further action.

@elesueur

elesueur commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

I have read the DCO Document and I hereby sign the DCO for this and all future contributions.

@elesueur
elesueur force-pushed the topic/elesueur/vcsim-cns-reattach branch 2 times, most recently from 9963edf to 12f3269 Compare October 2, 2026 13:16

@dougm dougm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @elesueur , looks good, but not sure we need to add the locking here.

Comment thread cns/simulator/simulator.go Outdated

// mu guards attachments. CnsAttachVolume/CnsDetachVolume task bodies run
// in their own goroutine (see simulator.Task.Run), so concurrent attach
// calls for different volumes targeting the same VM can race on this map.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you experience such a race? vcsim has built-in locking that should cover this, including Task.Run:

unlock = ctx.Map.AcquireLock(ctx, tr)

Another recent PR originally added locking that wasn't needed: #4109 (comment)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Doug, yea, you're right - it's not needed. I pushed an update.

When a CNS volume is already attached to a VM, a request to attach it to
the same VM fails with ResourceInUse.

In a real VC, this is allowed to succeed as an idempotent operation.

The ResourceInUse failure is triggered when CSI driver in vanilla k8s
cluster restarts after disks are already attached and subsequent
attachments continue to fail forever.

Signed-off-by: Etienne Le Sueur <etienne.le-sueur@broadcom.com>
@elesueur
elesueur force-pushed the topic/elesueur/vcsim-cns-reattach branch from 12f3269 to b84acab Compare October 7, 2026 19:17

@dougm dougm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @elesueur !

@dougm
dougm enabled auto-merge October 7, 2026 20:12
@dougm
dougm disabled auto-merge October 7, 2026 20:20
@dougm
dougm merged commit 3e23b07 into vmware:main Oct 7, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants