SANLOCK(8)
π SANLOCK(8) β shared storage lock manager π
okay bestie, welcome to the manual page for sanlock, straight outta the System Manager's Manual. grab a snack, we're locking shared storage together. π«Άβ¨
π NAME π
sanlock β shared storage lock manager ππΎ
β¨ SYNOPSIS β¨
sanlock [COMMAND] [ACTION] ...
πΈ DESCRIPTION πΈ
sanlock is a lock manager for shared storage environments. It lets applications running on multiple hosts coordinate access to shared resources β like data objects on shared storage systems such as a SAN β so you don't get data corruption and you do get data integrity. it's giving traffic cop for your storage, no cap. π¦π
π OPTIONS π
COMMAND can be one of three primary top level choices:
sanlock daemonβ start daemon πsanlock clientβ send request to daemon (default command if none given) π¨sanlock directβ access storage directly (no coordination with daemon) πΆοΈ
π Daemon Command π
sanlock daemon [options]
-Dβ no fork and print all logging tostderrπͺ΅-Q 0|1β quiet error messages for common lock contention π€«-R 0|1β renewal debugging, log debug info for each renewal π-L priβ write logging at priority level and up to logfile (-1none) π-S priβ write logging at priority level and up to syslog (-1none) π‘-U uidβ user id π€-G gidβ group id π₯-H numβ renewal history size π-t numβ max worker threads π§΅-g secβ seconds for graceful recovery π©Ή-w 0|1β use watchdog throughwdmdπ-o secβ io timeout β±οΈ-h 0|1β use high priority (RR) scheduling β‘-l numβ use mlockall (0none,1current,2current and future) π-b secβ seconds a host id bit will remain set in delta lease bitmap π-e strβ unique local host name used in delta leases as host_id owner π·οΈ
π¦ Client Command π¦
sanlock client action [options]
sanlock client statusβ Print processes, lockspaces, and resources being managed by the sanlock daemon. Add-Dto show extra internal daemon status for debugging. Add-o pto show resources by pid, or-o sto show resources by lockspace. πsanlock client host_statusβ Print state ofhost_idleases read during the last renewal. State of all lockspaces is shown (use-sto select one). Add-Dto show extra internal daemon status for debugging. πsanlock client getsβ Print lockspaces being managed by the sanlock daemon. TheLOCKSPACEstring will be followed byADDorREMif the lockspace is currently being added or removed. Add-h 1to also show hosts in each lockspace. πsanlock client renewal -s LOCKSPACEβ Print a history of renewals with timing details. See the Renewal history section below. β³sanlock client log_dumpβ Print the sanlock daemon internal debug log. πͺ΅sanlock client shutdownβ Ask the sanlock daemon to exit. Without the force option (-f 0), the command will be ignored if any lockspaces exist. With the force option (-f 1), any registered processes will be killed, their resource leases released, and lockspaces removed. With the wait option (-w 1), the command will wait for a result from the daemon indicating that it has shut down and is exiting, or cannot shut down because lockspaces exist (command fails). πsanlock client init -s LOCKSPACEβ Tell the sanlock daemon to initialize a lockspace on disk. The-ooption can be used to specify the io timeout to be written in thehost_idleases. The-Zand-Aoptions can be used to specify the sector size and align size, and both should be set together. Use-N 1to include theNO_TIMEOUTflag in the newly formatted leases. Use-C 1to request the use of CAW leases if supported, or-C 0to not use CAW leases. (Also seesanlock direct init.) π½sanlock client init -r RESOURCEβ Tell the sanlock daemon to initialize a resource lease on disk. The-Zand-Aoptions can be used to specify the sector size and align size, and both should be set together. Use-C 1to request the use of CAW leases if supported, or-C 0to not use CAW leases. (Also seesanlock direct init.) π§sanlock client read -s LOCKSPACEβ Tell the sanlock daemon to read a lockspace from disk. Only theLOCKSPACEpath and offset are required. Ifhost_idis zero, the first record at offset (host_id 1) is used. The completeLOCKSPACEis printed. Add-Dto print other details. (Also seesanlock direct read_leader.) πsanlock client read -r RESOURCEβ Tell the sanlock daemon to read a resource lease from disk. Only theRESOURCEpath and offset are required. The completeRESOURCEis printed. Add-Dto print other details. (Also seesanlock direct read_leader.) πsanlock client init_host -s LOCKSPACEβ Tell the sanlock daemon to initialize a singlehost_idlease on disk. Thehost_idspecified in the-sarg will be used, and written as the lease owner. Optionally specify host name with-e, generation with-g, and timestamp with-t. Use-Zto specify sector size. Use-N 1to include theNO_TIMEOUTflag in the reformatted lease. Use-C 1to request the use of CAW leases if supported, or-C 0to not use CAW leases. (Also seesanlock direct init_hostfor more information.) ποΈsanlock client add_lockspace -s LOCKSPACEβ Tell the sanlock daemon to acquire thehost_idlease for thehost_idspecified inLOCKSPACE. This is also referred to as "joining" the lockspace. With ahost_idlease held for the lockspace, the host is then able to acquire resource locks in the lockspace. Use-o <sec>to specify the io timeout of the acquiring host, which will be written in thehost_idlease. πͺsanlock client inq_lockspace -s LOCKSPACEβ Inquire about the state of the lockspace in the sanlock daemon, whether it is being added or removed, or is joined. πsanlock client rem_lockspace -s LOCKSPACEβ Tell the sanlock daemon to release the specifiedhost_idin the lockspace. Any processes holding resource leases in this lockspace will be killed, and the resource leases not released. πsanlock client command -r RESOURCE -c path argsβ Register with the sanlock daemon, acquire the specified resource lease, and exec the command atpathwithargs. When the command exits, the sanlock daemon will release the lease.-cmust be the final option. πsanlock client spawn -r RESOURCE -c COUNT CMD [ARG...] [-c COUNT CMD [ARG...]]...β Register with the sanlock daemon, acquire the specified resource lease, fork and exec each command specified by-csequentially as separate processes, checking the exit status of each process, and only moving to the next process on success. After all processes are successfully executed, or at the first failure, the lease is released explicitly before exiting. Use-P 1for persistent locks that will not be dropped if the spawn process dies while a child process is running. Use-h 1to report a conflicting lock owner. Use-O 1to acquire an orphan lock. Use-d 1to skip the on-disk resource lease update when releasing the resource lease after all commands complete successfully (useful when the commands have removed the lease storage.) π―sanlock client acquire -r RESOURCE -p pid/sanlock client release -r RESOURCE -p pidβ Tell the sanlock daemon to acquire or release the specified resource lease for the givenpid. Thepidmust be registered with the sanlock daemon.acquirecan optionally take a versionedRESOURCEstringRESOURCE:lver, wherelveris the version of the lease that must be acquired, or fail. Use-Cin place of-pto specifyclient_id. πsanlock client convert -r RESOURCE -p pidβ Tell the sanlock daemon to convert the mode of the specified resource lease for the givenpid. If the existing mode is exclusive (default), the mode of the lease can be converted to shared withRESOURCE:SH. If the existing mode is shared, the mode of the lease can be converted to exclusive withRESOURCE(no:SHsuffix). Use-Cin place of-pto specifyclient_id. πsanlock client inquire -p pidβ Print the resource leases held the givenpid. The format is a versionedRESOURCEstring"RESOURCE:lver"wherelveris the version of the lease held. Use-Cin place of-pto specifyclient_id. βsanlock client request -r RESOURCE -f force_modeβ Request the owner of a resource do something specified byforce_mode. A versionedRESOURCE:lverstring must be used with a greater version than is presently held. Zerolverandforce_modeclears the request. π¨sanlock client examine -r RESOURCEβ Examine the request record for the currently held resource lease and carry out the action specified by the requestedforce_mode. π΅οΈsanlock client examine -s LOCKSPACEβ Examine requests for all resource leases currently held in the named lockspace. Onlylockspace_nameis used from theLOCKSPACEargument. π΅οΈsanlock client set_event -s LOCKSPACE -i host_id -g gen -e num -d numβ Set an event for another host. When the sanlock daemon next renews itshost_idlease for the lockspace it will: set the bit for thehost_idin its bitmap, and set the generation, event and data values in its ownhost_idlease. An application that has registered for events from this lockspace on the destination host will get the event that has been set when the destination sees the event during its nexthost_idlease renewal. π£sanlock client set_config -s LOCKSPACEβ Set a configuration value for a lockspace. Onlylockspace_nameis used from theLOCKSPACEargument. TheUSEDflag has the same effect on a lockspace as a process holding a resource lease that will not exit. TheUSED_BY_ORPHANSflag means that an orphan resource lease will have the same effect as theUSED. The-o <sec>option can be used to update the lockspace's io timeout. π οΈ-u 0|1β Set (1) or clear (0) theUSEDflag.-O 0|1β Set (1) or clear (0) theUSED_BY_ORPHANSflag.
sanlock client set_host -s LOCKSPACE -i host_id -g gen -F flag_nameβ Whenflag_nameisDEAD_EXT, theDEAD_EXTflag is set in thehost_idlease for the specifiedhost_id. If the currenthost_idlease generation does not match the specified generation, then the command will fail. WithDEAD_EXTset, thehost_id+generationwill be considered dead, and resource locks held by the specifiedhost_id+generationwill be free for other hosts to acquire.DEAD_EXTshould only be set for a host if that host can no longer modify the shared resources that were protected by the resource locks in the lockspace. π
π Direct Command π
sanlock direct action [options]
-o secβ io timeout in seconds β±οΈ
sanlock direct init -s LOCKSPACE
sanlock direct init -r RESOURCE
LOCKSPACE option string π
-s lockspace_name:host_id:path:offset
lockspace_nameβ the name of the lockspace, bestie, that's literally ithost_idβ the local host identifier inside that lockspacepathβ where the storage lives that you're using for leasesoffsetβ the offset onpath, counted in bytes
Okay so back to the direct stuff β initializing storage for a lockspace or a resource, let's go π
Use the -Z and -A flags to set the sector size and the align size. The max number of hosts that can use the lockspace/resource (and the max possible host_id) is decided by whatever sector/align combo you picked. The possible combinations are: 512/1M, 4096/1M, 4096/2M, 4096/4M, 4096/8M. Both lockspaces and resources eat up the same amount of space (align_size) for each of those combos.
When you're initializing a lockspace, sanlock initializes host_id leases (delta leases) for max_hosts in the space you gave it. When you're initializing a resource, sanlock initializes a single resource lock (paxos lease) in that space. β¨
- With
-s, the-ooption tells it the io timeout to write into the host_id leases. - With
-r, the-z 1option invalidates the resource lease on disk, so it literally cannot be used until it gets reinitialized normally. β οΈ dramatic but true - Use
-N 1to includeNO_TIMEOUTin newly formatted lockspace host_id leases. - Use
-C 1to request the use ofCOMPARE AND WRITE(CAW) leases, if they're supported. Or-C 0to not use CAW leases. Your call, queen π
sanlock direct init_host -s LOCKSPACE
Initialize a single host_id lease. The host_id you put in the -s arg gets used, and written as the lease owner (leader.owner_id).
Optionally you can specify the host name (leader.resource_name) with -e, the generation number (leader.owner_generation) with -g, and the timestamp (leader.timestamp) with -t. Okay so about -t: a timestamp value of 1 is special and makes the current time get written into the timestamp field. And a timestamp value of 0 means the host_id lease is free, as usual. π
The -Z and -o options apply here the same way they do with direct init. Use -N 1 to include NO_TIMEOUT in the reformatted host_id lease. Use -C 1 to request the use of CAW leases if supported, or -C 0 to not use CAW leases.
sanlock direct read_leader -s LOCKSPACE
sanlock direct read_leader -r RESOURCE
Read a leader record off the disk and print the fields. The leader record is the single sector of a delta lease, or the first sector of a paxos lease. π
sanlock direct read -s LOCKSPACE
sanlock direct read -r RESOURCE
Read a complete lockspace or resource from disk and print the whole thing. The full meal, no crumbs left.
sanlock direct dump path[:offset[:size]]
Read disk sectors and print leader records for delta or paxos leases. Add -f 1 to also print the request record values for paxos leases, and the host_ids set in delta lease bitmaps. π
RESOURCE option string π¦
-r lockspace_name:resource_name:path:offset
lockspace_nameβ name of the lockspaceresource_nameβ name of the resourcepathβ path to storage to use for leasesoffsetβ offset onpath, in bytes
RESOURCE option string with suffix πΈ
-r lockspace_name:resource_name:path:offset:lver
lverβ the leader version
-r lockspace_name:resource_name:path:offset:SH
SHβ this indicates shared mode
Defaults π
sanlock help shows you the default values for all the options above, so if you're ever like "wait what's the default", that's your girl.
sanlock version shows the build version. sanlock help and sanlock version β literally your two besties for orientation. π«Ά
π₯ OTHER π₯
Request/Examine π
So the first part of making a request for a resource is writing the request record of the resource β that's the sector right after the leader record. To make a request actually succeed, here's the vibe check:
RESOURCE:lvermust be greater than thelverpresently held by the other host. Which means the leader record has to be read first so you can discover thelver, and that has to happen before you make the request.RESOURCE:lvermust be greater than or equal to thelverpresently written to the request record. Two hosts are allowed to write a new request at the same time for the samelverβ in that case both would succeed, but theforce_modefrom the last one wins. π- The
force_modemust be greater than zero. - To unconditionally clear the request record β setting both
lverandforce_modeto0β make the request withRESOURCE:0andforce_mode0.
Heads up bestie: the owner of the requested resource is NOT going to know about the request unless you explicitly tell it to examine its resources via the examine api/command, or otherwise notify it. It's not psychic. π
The second part of making a request is notifying the resource lease owner that it should go examine the request records of its resource leases. That notification makes the lease owner automatically run the equivalent of sanlock client examine -s LOCKSPACE for the lockspace of the requested resource.
The notification rides on a bitmap in each host_id lease. Each bit represents each of the possible host_ids (1-2000). So if host A wants to notify host B to examine its resources, A sets the bit in its own bitmap that corresponds to the host_id of B. When B next renews its host_id lease, it reads the host_id leases for all hosts and checks each bitmap to see if its own host_id has been set. It finds the bit for its own host_id set in A's bitmap, and then examines its resource request records. (The bit stays set in A's bitmap for set_bitmap_seconds.)
force_mode is what decides the action the resource lease owner should take:
FORCE(1) β kill the process holding the resource lease. Once the process has exited, the resource lease will be released, and then anyone can acquire it. The kill signal isSIGKILL(orSIGTERMifSIGKILLis restricted). πGRACEFUL(2) β run the program configured bysanlock_killpathagainst the process holding the resource lease. If no killpath is defined, thenFORCEis used.
Persistent and orphan resource leases π§
A resource lease can be acquired with the PERSISTENT flag (-P 1). If the process holding the lease exits, the lease does not get released β it's kept on an orphan list instead. Another local process can acquire an orphan lease using the ORPHAN flag (-O 1), or release the orphan lease using the ORPHAN flag (-O 1). And you can release all orphan leases by setting just the lockspace name (-s lockspace_name) with no resource name. Clean slate, slay. β¨
Renewal history β
sanlock saves a limited history of lease renewal info in each lockspace. Check sanlock.conf renewal_history_size to set how much history you want, or to disable it entirely (set it to 0).
IO times are measured in delta lease renewal β each delta lease renewal includes one read and one write.
For every successful renewal, a record gets saved that includes:
- the timestamp written in the delta lease by the renewal
- the time in milliseconds taken by the delta lease read
- the time in milliseconds taken by the delta lease write
Also counted and recorded are the number of io timeouts and other io errors that happen between successful renewals.
Two consecutive successful renewals would be recorded like this:
timestamp=5332 read_ms=482 write_ms=5525 next_timeouts=0 next_errors=0
timestamp=5353 read_ms=99 write_ms=3161 next_timeouts=0 next_errors=0
And those fields mean:
timestampis the value written into the delta lease during that renewal.read_ms/write_msare the milliseconds taken for the renewal read/write ios.next_timeoutsis the number of io timeouts that occurred after the renewal recorded on that line, and before the next successful renewal on the following line.next_errorsis the number of io errors (not timeouts) that occurred after the renewal recorded on that line, and before the next successful renewal on the following line.
The command sanlock client renewal -s lockspace_name reports the full history of renewals saved by sanlock β which by default is 180 records, about 1 hour of history when you're using a 20 second renewal interval for a 10 second io timeout. π°οΈ
Configurable watchdog timeout π
Watchdog devices usually have a 60 second timeout, but some devices have a configurable timeout. To use a different watchdog timeout, set sanlock.conf watchdog_fire_timeout (in seconds) to a value your device supports.
The same watchdog_fire_timeout must be configured on all hosts β so every host has to have watchdog devices that support the same timeout. Unmatching values will invalidate the lease protection that the watchdog provides. π¨
watchdog_fire_timeout and io_timeout should usually be configured together. By default, sanlock uses watchdog_fire_timeout=60 with io_timeout=10. Other combinations to consider are:
watchdog_fire_timeout=30 with io_timeout=5
watchdog_fire_timeout=10 with io_timeout=2
Smaller values make it more likely that a host will get reset by the watchdog while it's waiting for slow io to complete or for temporary io failures to get resolved. Spurious watchdog resets also become more likely because of independent, overlapping lockspace outages β each of which would be inconsequential all by itself. π so like, pick your values with intention, bestie.
Bestie. Last stretch of the page, and it's the fun one: the config file. Everything in here is stuff the daemon reads, and you can β¨alwaysβ¨ spy on what it's actually using right now by running:
sanlock status -D
ποΈ FILES ποΈ
πΈ /etc/sanlock/sanlock.conf πΈ
This is the config file. The values currently in use by the sanlock daemon can be seen in the output of sanlock status -D β so if you're ever like "wait, what is it actually doing rn", that command is your bestie. π
Here's everything it can hold, one gorgeous line at a time:
quiet_fail = 1β See-Q.debug_renew = 0β See-R.logfile_priority = 4β See-L.logfile_use_utc = 0β Use UTC instead of local time in log messages.syslog_priority = 3β See-S.names_log_priority = 6β Log resource names at this priority level (it uses syslog priority numbers). If this number is less than or equal tologfile_priority, then every requested resource name and location gets recorded insanlock.log. βοΈuse_watchdog = 1β See-w.high_priority = 1β See-h.mlock_level = 1β See-l.sh_retries = 8β The number of times to try acquiring a paxos lease when acquiring a shared lease when the paxos lease is held by another host that's acquiring a shared lease.uname = sanlockβ The sanlock daemon will attempt to use this user id. Ignored whenuse_compare_and_writeis enabled, which requires running as root. πgname = sanlockβ The sanlock daemon will attempt to use this group id. Ignored whenuse_compare_and_writeis enabled, which requires running as root. πour_host_name = <str>β A unique name that a host uses to ensure exclusive ownership of a lockspacehost_id(delta lease owner.) The maximum length is 48 characters. If no value is provided insanlock.confor on the command line (-e), sanlock attempts to setour_host_namefrom/sys/devices/virtual/dmi/id/product_uuid. If that isn't available, sanlock generates a random uuid to use asour_host_name. Using a fixedour_host_namevalue will reduce delays when using a lockspace. Usingproduct_uuidwill reduce delays further. π¦renewal_read_extend_sec = <seconds>β If a renewal read i/o times out, wait this many additional seconds for that read to complete at the start of the subsequent renewal attempt. When not configured, sanlock waits for an additionalio_timeoutseconds for a previous timed out read to complete.renewal_history_size = 180β See-H.paxos_debug_all = 0β Include all the details in the paxos debug logging.debug_io = <str>β Add debug logging for each i/o."submit"(no quotes) produces debug output at submission time,"complete"produces debug output at completion time, and"submit,complete"(no space!) produces both. πmax_sectors_kb = <str>|<num>β Set to"ignore"(no quotes) to prevent sanlock from checking or changingmax_sectors_kbfor the lockspace disk when starting a lockspace. Set to"align"(no quotes) to setmax_sectors_kbfor the lockspace disk to the align size of the lockspace. Set to a number to set a specific number of KB for all lockspace disks. A larger existingmax_sectors_kbvalue will not be reduced by this setting.debug_clients = 0β Enable or disable debug logging for all client connections to the sanlock daemon.debug_cmd = +|-<name>β Enable (+name) or disable (-name) debug logging at the command processing level for specifically named commands, e.g."debug_cmd = +acquire", or"debug_cmd = -inq_lockspace". Repeat this line for each command name. Use a plus prefix before the name to enable and a minus prefix to disable. By default sanlock disables some command level debugging for commands that are often repetitive and fill the in memory debug buffer. This only affects debug logging, not errors or warnings, and disabling command level debugging for a command does not disable lower level debugging for that command. Special values+alland-allcan be used to enable or disable all commands, and can be used before or after otherdebug_cmdlines. ποΈdebug_hosts = 1β Log information about otherhost_idlease renewals. When set to1(the default), messages are logged when ahost_idlease is observed reaching the failed and dead states. When set to2, messages are logged when any update (e.g. renewal) is observed for anotherhost_idlease. When set to0, neither are logged.write_init_io_timeout = <seconds>β The io timeout to use when initializing ondisk lease structures for a lockspace or resource. This timeout is not used as a part of either lease algorithm (as the standardio_timeoutis.)max_worker_threads = <num>β See-t.io_timeout = <seconds>β The io timeout for disk operations, most notably delta lease renewals. This value is basis for calculating most other timeout values. (Some special cases may use a different io timeout.) Tune this value with caution, it can substantially alter the overall sanlock behavior. β οΈ
bestie I'm serious, tune this with caution β it can substantially alter the overall sanlock behavior.
watchdog_fire_timeout = <seconds>β The watchdog device timeout. The watchdog device must support the specified value. It is critical that all hosts use the same value. Not doing so will invalidate the lease protection provided by sanlock. Theio_timeoutshould usually be tuned along with this value, e.g.watchdog_fire_timeout = 30withio_timeout = 5. ππ¦Ίuse_hugepages = <str>β Set to"all"to use transparent hugepages (2MB viaMADV_HUGEPAGE.) This should minimize, or prevent, splitting read io's on lease areas. 2MB is allocated for 1MB lease areas, causing some extra memory usage. Set to"none"to disable. π§use_compare_and_write = <str>β Set to"yes"to use CAW leases when supported by storage, unless the user/API requests that non-CAW leases be used. (opt-out) Set to"no"to not use CAW leases, even if requested by the user. Set to"allow"to use CAW if supported by storage and requested by the user/API. (opt-in)create_old_delta_disk_version = <X.Y>β Format delta leases using the specified old version number, e.g.3.4. This allows new versions to remain compatible with old versions. Some new features will not be usable with the old version. π°οΈcaw_fua = 1caw_dpo = 1β Set to0to disable the FUA and/or DPO flags for SCSICOMPARE AND WRITEcommands. Using FUA (Force Unit Access) ensures that an update is persistent on disk when the CAW command completes. This ensures a lock does not "disappear" if the device is abruptly restarted immediately after a lock is written (e.g. by power loss.) Using DPO (Disable Page Out) indicates to the device that CAW lock data is not useful to keep in the device cache. If a device does not support FUA/DPO flags, setting these to0may allow sanlock to use CAW.
π SEE ALSO π
And that's the whole page, bestie β you ate that. π This one's from the Sanlock manual, SANLOCK(8), dated 2026-02-27. Go forth and lock things exclusively, bestie. No cap. π
β¨π¦
π¦ where this page comes from
- alpine 3.24: sanlock-doc 5.1.0-r1 Β· LGPL-2.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later
- centos-stream 10: sanlock 5.1.1-1.el10 Β· GPL-2.0-only AND GPL-2.0-or-later AND LGPL-2.0-or-later
- ubuntu stonking: sanlock 5.1.0-1 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms