PVE: facility for a cluster-wide mutex?

jtru

New Member
Sep 11, 2025
17
6
3
johannes.truschnigg.info
I have a program that executes on proxmox PVE nodes and has to ensure that one of its critical sections will only run on *one* of all involved cluster node at the same time. It's a low-volume thing (the mutex will have to be acquired rarely), but it must work reliably. Will something to the effect of `mkdir /etc/pve/mycustommutexdir; do the criticial thing; rmdir /etc/pve/mycustommutexdir` work and be enough for this condition to be met, or is there a better way to do this with what PVE holds in store ootb?

I would very much like to avoid introducing another infrastructure component/service for this puporse alone, if possible.
 
  • Like
Reactions: jtru
Thanks a lot - my perl5 is a bit rusty, but the cfs_lock sub looks rather close to what I'd have in mind :)

https://git.proxmox.com/?p=pve-clus...e9052de3befa8ef551c6ef5c9e4b1427;hb=HEAD#l547 hints at the `priv/lock` pathname prefix to be special-cased to where this approach should work, but also implies other prefixes on /etc/pve would exhibit other semantics that are not suitable for a cluster-wide mutex - correct? :)
 
yes, the "priv/lock" dir is special-cased to handle lock expiry (after 120s, with calling code only holding the lock for 60s) - because otherwise if the node gets fenced or crashes between the mkdir and the rmdir you end up locked forever.
 
  • Like
Reactions: jtru