1SANLOCK(8) System Manager's Manual SANLOCK(8)
2
3
4
6 sanlock - shared storage lock manager
7
8
10 sanlock [COMMAND] [ACTION] ...
11
12
14 sanlock is a lock manager built on shared storage. Hosts with access
15 to the storage can perform locking. An application running on the
16 hosts is given a small amount of space on the shared block device or
17 file, and uses sanlock for its own application-specific synchroniza‐
18 tion. Internally, the sanlock daemon manages locks using two disk-
19 based lease algorithms: delta leases and paxos leases.
20
21
22 · delta leases are slow to acquire and demand regular i/o to shared
23 storage. sanlock only uses them internally to hold a lease on its
24 "host_id" (an integer host identifier from 1-2000). They prevent two
25 hosts from using the same host identifier. The delta lease renewals
26 also indicate if a host is alive. ("Light-Weight Leases for Storage-
27 Centric Coordination", Chockler and Malkhi.)
28
29
30 · paxos leases are fast to acquire and sanlock makes them available to
31 applications as general purpose resource leases. The disk paxos
32 algorithm uses host_id's internally to represent different hosts, and
33 the owner of a paxos lease. delta leases provide unique host_id's
34 for implementing paxos leases, and delta lease renewals serve as a
35 proxy for paxos lease renewal. ("Disk Paxos", Eli Gafni and Leslie
36 Lamport.)
37
38
39 Externally, the sanlock daemon exposes a locking interface through lib‐
40 sanlock in terms of "lockspaces" and "resources". A lockspace is a
41 locking context that an application creates for itself on shared stor‐
42 age. When the application on each host is started, it "joins" the
43 lockspace. It can then create "resources" on the shared storage. Each
44 resource represents an application-specific entity. The application
45 can acquire and release leases on resources.
46
47 To use sanlock from an application:
48
49
50 · Allocate shared storage for an application, e.g. a shared LUN or LV
51 from a SAN, or files from NFS.
52
53
54 · Provide the storage to the application.
55
56
57 · The application uses this storage with libsanlock to create a
58 lockspace and resources for itself.
59
60
61 · The application joins the lockspace when it starts.
62
63
64 · The application acquires and releases leases on resources.
65
66
67 How lockspaces and resources translate to delta leases and paxos leases
68 within sanlock:
69
70 Lockspaces
71
72
73 · A lockspace is based on delta leases held by each host using the
74 lockspace.
75
76
77 · A lockspace is a series of 2000 delta leases on disk, and requires
78 1MB of storage. (See Storage below for size variations.)
79
80
81 · A lockspace can support up to 2000 concurrent hosts using it, each
82 using a different delta lease.
83
84
85 · Applications can i) create, ii) join and iii) leave a lockspace,
86 which corresponds to i) initializing the set of delta leases on disk,
87 ii) acquiring one of the delta leases and iii) releasing the delta
88 lease.
89
90
91 · When a lockspace is created, a unique lockspace name and disk loca‐
92 tion is provided by the application.
93
94
95 · When a lockspace is created/initialized, sanlock formats the sequence
96 of 2000 on-disk delta lease structures on the file or disk, e.g.
97 /mnt/leasefile (NFS) or /dev/vg/lv (SAN).
98
99
100 · The 2000 individual delta leases in a lockspace are identified by
101 number: 1,2,3,...,2000.
102
103
104 · Each delta lease is a 512 byte sector in the 1MB lockspace, offset by
105 its number, e.g. delta lease 1 is offset 0, delta lease 2 is offset
106 512, delta lease 2000 is offset 1023488. (See Storage below for size
107 variations.)
108
109
110 · When an application joins a lockspace, it must specify the lockspace
111 name, the lockspace location on shared disk/file, and the local
112 host's host_id. sanlock then acquires the delta lease corresponding
113 to the host_id, e.g. joining the lockspace with host_id 1 acquires
114 delta lease 1.
115
116
117 · The terms delta lease, lockspace lease, and host_id lease are used
118 interchangably.
119
120
121 · sanlock acquires a delta lease by writing the host's unique name to
122 the delta lease disk sector, reading it back after a delay, and veri‐
123 fying it is the same.
124
125
126 · If a unique host name is not specified, sanlock generates a uuid to
127 use as the host's name. The delta lease algorithm depends on hosts
128 using unique names.
129
130
131 · The application on each host should be configured with a unique
132 host_id, where the host_id is an integer 1-2000.
133
134
135 · If hosts are misconfigured and have the same host_id, the delta lease
136 algorithm is designed to detect this conflict, and only one host will
137 be able to acquire the delta lease for that host_id.
138
139
140 · A delta lease ensures that a lockspace host_id is being used by a
141 single host with the unique name specified in the delta lease.
142
143
144 · Resolving delta lease conflicts is slow, because the algorithm is
145 based on waiting and watching for some time for other hosts to write
146 to the same delta lease sector. If multiple hosts try to use the
147 same delta lease, the delay is increased substantially. So, it is
148 best to configure applications to use unique host_id's that will not
149 conflict.
150
151
152 · After sanlock acquires a delta lease, the lease must be renewed until
153 the application leaves the lockspace (which corresponds to releasing
154 the delta lease on the host_id.)
155
156
157 · sanlock renews delta leases every 20 seconds (by default) by writing
158 a new timestamp into the delta lease sector.
159
160
161 · When a host acquires a delta lease in a lockspace, it can be referred
162 to as "joining" the lockspace. Once it has joined the lockspace, it
163 can use resources associated with the lockspace.
164
165
166 Resources
167
168
169 · A lockspace is a context for resources that can be locked and
170 unlocked by an application.
171
172
173 · sanlock uses paxos leases to implement leases on resources. The
174 terms paxos lease and resource lease are used interchangably.
175
176
177 · A paxos lease exists on shared storage and requires 1MB of space. It
178 contains a unique resource name and the name of the lockspace.
179
180
181 · An application assigns its own meaning to a sanlock resource and the
182 leases on it. A sanlock resource could represent some shared object
183 like a file, or some unique role among the hosts.
184
185
186 · Resource leases are associated with a specific lockspace and can only
187 be used by hosts that have joined that lockspace (they are holding a
188 delta lease on a host_id in that lockspace.)
189
190
191 · An application must keep track of the disk locations of its
192 lockspaces and resources. sanlock does not maintain any persistent
193 index or directory of lockspaces or resources that have been created
194 by applications, so applications need to remember where they have
195 placed their own leases (which files or disks and offsets).
196
197
198 · sanlock does not renew paxos leases directly (although it could).
199 Instead, the renewal of a host's delta lease represents the renewal
200 of all that host's paxos leases in the associated lockspace. In
201 effect, many paxos lease renewals are factored out into one delta
202 lease renewal. This reduces i/o when many paxos leases are used.
203
204
205 · The disk paxos algorithm allows multiple hosts to all attempt to
206 acquire the same paxos lease at once, and will produce a single win‐
207 ner/owner of the resource lease. (Shared resource leases are also
208 possible in addition to the default exclusive leases.)
209
210
211 · The disk paxos algorithm involves a specific sequence of reading and
212 writing the sectors of the paxos lease disk area. Each host has a
213 dedicated 512 byte sector in the paxos lease disk area where it
214 writes its own "ballot", and each host reads the entire disk area to
215 see the ballots of other hosts. The first sector of the disk area is
216 the "leader record" that holds the result of the last paxos ballot.
217 The winner of the paxos ballot writes the result of the ballot to the
218 leader record (the winner of the ballot may have selected another
219 contending host as the owner of the paxos lease.)
220
221
222 · After a paxos lease is acquired, no further i/o is done in the paxos
223 lease disk area.
224
225
226 · Releasing the paxos lease involves writing a single sector to clear
227 the current owner in the leader record.
228
229
230 · If a host holding a paxos lease fails, the disk area of the paxos
231 lease still indicates that the paxos lease is owned by the failed
232 host. If another host attempts to acquire the paxos lease, and finds
233 the lease is held by another host_id, it will check the delta lease
234 of that host_id. If the delta lease of the host_id is being renewed,
235 then the paxos lease is owned and cannot be acquired. If the delta
236 lease of the owner's host_id has expired, then the paxos lease is
237 expired and can be taken (by going through the paxos lease algo‐
238 rithm.)
239
240
241 · The "interaction" or "awareness" between hosts of each other is lim‐
242 ited to the case where they attempt to acquire the same paxos lease,
243 and need to check if the referenced delta lease has expired or not.
244
245
246 · When hosts do not attempt to lock the same resources concurrently,
247 there is no host interaction or awareness. The state or actions of
248 one host have no effect on others.
249
250
251 · To speed up checking delta lease expiration (in the case of a paxos
252 lease conflict), sanlock keeps track of past renewals of other delta
253 leases in the lockspace.
254
255
256 Resource Index
257
258 The resource index (rindex) is an optional sanlock feature that appli‐
259 cations can use to keep track of resource lease offsets. Without the
260 rindex, an application must keep track of where its resource leases
261 exist on disk and find available locations when creating new leases.
262
263 The sanlock rindex uses two align-size areas on disk following the
264 lockspace. The first area holds rindex entries; each entry records a
265 resource lease name and location. The second area holds a private
266 paxos lease, used by sanlock internally to protect rindex updates.
267
268 The application creates the rindex on disk with the "format" function.
269 Format is a disk-only operation and does not interact with the live
270 lockspace, so it can be called without first calling add_lockspace.
271 The application needs to follow the convention of writing the lockspace
272 at the start of the device (offset 0) and formatting the rindex immedi‐
273 ately following the lockspace area. When formatting, the application
274 must set flags for sector size and align size to match those for the
275 lockspace.
276
277 To use the rindex, the application:
278
279
280 · Uses the "create" function to create a new resource lease on disk.
281 This takes the place of the write_resource function. The create
282 function requires the location of the rindex and the name of the new
283 resource lease. sanlock finds a free lease area, writes the new
284 resource lease at that location, updates the rindex with the
285 name:offset, and returns the offset to the caller. The caller uses
286 this offset when acquiring the resource lease.
287
288
289 · Uses the "delete" function to remove a resource disk on disk (also
290 corresponding to the write_resource function.) sanlock clears the
291 resource lease and the rindex entry for it. A subsequent call to
292 create may use this same disk location for a different resource
293 lease.
294
295
296 · Uses the "lookup" function to discover the offset of a resource lease
297 given the resource lease name. The caller would typically call this
298 prior to acquiring the resource lease.
299
300
301 · Uses the "rebuild" function to recreate the rindex if it is damaged
302 or becomes inconsistent. This function scans the disk for resource
303 leases and creates new rindex entries to match the leases it finds.
304
305
306 · The "update" function manipulates rindex entries directly and should
307 not normally be used by the application. In normal usage, the create
308 and delete functions manipulate rindex entries. Update is mainly
309 useful for testing or repairs.
310
311
312 Expiration
313
314
315 · If a host fails to renew its delta lease, e.g. it looses access to
316 the storage, its delta lease will eventually expire and another host
317 will be able to take over any resource leases held by the host. san‐
318 lock must ensure that the application on two different hosts is not
319 holding and using the same lease concurrently.
320
321
322 · When sanlock has failed to renew a delta lease for a period of time,
323 it will begin taking measures to stop local processes (applications)
324 from using any resource leases associated with the expiring lockspace
325 delta lease. sanlock enters this "recovery mode" well ahead of the
326 time when another host could take over the locally owned leases.
327 sanlock must have sufficient time to stop all local processes that
328 are using the expiring leases.
329
330
331 · sanlock uses three methods to stop local processes that are using
332 expiring leases:
333
334 1. Graceful shutdown. sanlock will execute a "graceful shutdown"
335 program that the application previously specified for this case. The
336 shutdown program tells the application to shut down because its
337 leases are expiring. The application must respond by stopping its
338 activities and releasing its leases (or exit). If an application
339 does not specify a graceful shutdown program, sanlock sends SIGTERM
340 to the process instead. The process must release its leases or exit
341 in a prescribed amount of time (see -g), or sanlock proceeds to the
342 next method of stopping.
343
344 2. Forced shutdown. sanlock will send SIGKILL to processes using the
345 expiring leases. The processes have a fixed amount of time to exit
346 after receiving SIGKILL. If any do not exit in this time, sanlock
347 will proceed to the next method.
348
349 3. Host reset. sanlock will trigger the host's watchdog device to
350 forcibly reset it. sanlock carefully manages the timing of the
351 watchdog device so that it fires shortly before any other host could
352 take over the resource leases held by local processes.
353
354
355 Failures
356
357 If a process holding resource leases fails or exits without releasing
358 its leases, sanlock will release the leases for it automatically
359 (unless persistent resource leases were used.)
360
361 If the sanlock daemon cannot renew a lockspace delta lease for a spe‐
362 cific period of time (see Expiration), sanlock will enter "recovery
363 mode" where it attempts to stop and/or kill any processes holding
364 resource leases in the expiring lockspace. If the processes do not
365 exit in time, sanlock will force the host to be reset using the local
366 watchdog device.
367
368 If the sanlock daemon crashes or hangs, it will not renew the expiry
369 time of the per-lockspace connections it had to the wdmd daemon. This
370 will lead to the expiration of the local watchdog device, and the host
371 will be reset.
372
373 Watchdog
374
375 sanlock uses the wdmd(8) daemon to access /dev/watchdog. wdmd multi‐
376 plexes multiple timeouts onto the single watchdog timer. This is
377 required because delta leases for each lockspace are renewed and expire
378 independently.
379
380 sanlock maintains a wdmd connection for each lockspace delta lease
381 being renewed. Each connection has an expiry time for some seconds in
382 the future. After each successful delta lease renewal, the expiry time
383 is renewed for the associated wdmd connection. If wdmd finds any con‐
384 nection expired, it will not renew the /dev/watchdog timer. Given
385 enough successive failed renewals, the watchdog device will fire and
386 reset the host. (Given the multiplexing nature of wdmd, shorter over‐
387 lapping renewal failures from multiple lockspaces could cause spurious
388 watchdog firing.)
389
390 The direct link between delta lease renewals and watchdog renewals pro‐
391 vides a predictable watchdog firing time based on delta lease renewal
392 timestamps that are visible from other hosts. sanlock knows the time
393 the watchdog on another host has fired based on the delta lease time.
394 Furthermore, if the watchdog device on another host fails to fire when
395 it should, the continuation of delta lease renewals from the other host
396 will make this evident and prevent leases from being taken from the
397 failed host.
398
399 If sanlock is able to stop/kill all processing using an expiring
400 lockspace, the associated wdmd connection for that lockspace is
401 removed. The expired wdmd connection will no longer block /dev/watch‐
402 dog renewals, and the host should avoid being reset.
403
404 Storage
405
406 The sector size and the align size should be specified when creating
407 lockspaces and resources (and rindex). The "align size" is the size on
408 disk of a lockspace or a resource, i.e. the amount of disk space it
409 uses. Lockspaces and resources should use matching sector and align
410 sizes, and must use offsets in multiples of the align size. The max
411 number of hosts that can use a lockspace or resource depends on the
412 combination of sector size and align size, shown below. The host_id of
413 hosts using the lockspace can be no larger than the max_hosts value for
414 the lockspace.
415
416 Accepted combinations of sector size and align size, and the corre‐
417 sponding max_hosts (and max host_id) are:
418
419 sector_size 512, align_size 1M, max_hosts 2000
420 sector_size 4096, align_size 1M, max_hosts 250
421 sector_size 4096, align_size 2M, max_hosts 500
422 sector_size 4096, align_size 4M, max_hosts 1000
423 sector_size 4096, align_size 8M, max_hosts 2000
424
425 When sector_size and align_size are not specified, the behavior matches
426 the behavior before these sizes could be configured: on devices which
427 report sector size 512, 512/1M/2000 is used, on devices which report
428 sector size 4096, 4096/8M/2000 is used, and on files, 512/1M/2000 is
429 always used. (Other combinations are not compatible with sanlock ver‐
430 sion 3.6 or earlier.)
431
432 Using sanlock on shared block devices that do host based mirroring or
433 replication is not likely to work correctly. When using sanlock on
434 shared files, all sanlock io should go to one file server.
435
436 Example
437
438 This is an example of creating and using lockspaces and resources from
439 the command line. (Most applications would use sanlock through libsan‐
440 lock rather than through the command line.)
441
442
443 1. Allocate shared storage for sanlock leases.
444
445 This example assumes 512 byte sectors on the device, in which case
446 the lockspace needs 1MB and each resource needs 1MB.
447
448 The example shared block device accessible to all hosts is
449 /dev/leases.
450
451
452 2. Start sanlock on all hosts.
453
454 The -w 0 disables use of the watchdog for testing.
455
456 # sanlock daemon -w 0
457
458
459 3. Start a dummy application on all hosts.
460
461 This sanlock command registers with sanlock, then execs the sleep
462 command which inherits the registered fd. The sleep process acts
463 as the dummy application. Because the sleep process is registered
464 with sanlock, leases can be acquired for it.
465
466 # sanlock client command -c /bin/sleep 600 &
467
468
469 4. Create a lockspace for the application (from one host).
470
471 The lockspace is named "test".
472
473 # sanlock client init -s test:0:/dev/leases:0
474
475
476 5. Join the lockspace for the application.
477
478 Use a unique host_id on each host.
479
480 host1:
481 # sanlock client add_lockspace -s test:1:/dev/leases:0
482 host2:
483 # sanlock client add_lockspace -s test:2:/dev/leases:0
484
485
486 6. Create two resources for the application (from one host).
487
488 The resources are named "RA" and "RB". Offsets are used on the
489 same device as the lockspace. Different LVs or files could also be
490 used.
491
492 # sanlock client init -r test:RA:/dev/leases:1048576
493 # sanlock client init -r test:RB:/dev/leases:2097152
494
495
496 7. Acquire resource leases for the application on host1.
497
498 Acquire an exclusive lease (the default) on the first resource, and
499 a shared lease (SH) on the second resource.
500
501 # export P=`pidof sleep`
502 # sanlock client acquire -r test:RA:/dev/leases:1048576 -p $P
503 # sanlock client acquire -r test:RB:/dev/leases:2097152:SH -p $P
504
505
506 8. Acquire resource leases for the application on host2.
507
508 Acquiring the exclusive lease on the first resource will fail
509 because it is held by host1. Acquiring the shared lease on the
510 second resource will succeed.
511
512 # export P=`pidof sleep`
513 # sanlock client acquire -r test:RA:/dev/leases:1048576 -p $P
514 # sanlock client acquire -r test:RB:/dev/leases:2097152:SH -p $P
515
516
517 9. Release resource leases for the application on both hosts.
518
519 The sleep pid could also be killed, which will result in the san‐
520 lock daemon releasing its leases when it exits.
521
522 # sanlock client release -r test:RA:/dev/leases:1048576 -p $P
523 # sanlock client release -r test:RB:/dev/leases:2097152 -p $P
524
525
526 10. Leave the lockspace for the application.
527
528 host1:
529 # sanlock client rem_lockspace -s test:1:/dev/leases:0
530 host2:
531 # sanlock client rem_lockspace -s test:2:/dev/leases:0
532
533
534 11. Stop sanlock on all hosts.
535
536 # sanlock shutdown
537
538
539
541 COMMAND can be one of three primary top level choices
542
543 sanlock daemon start daemon
544 sanlock client send request to daemon (default command if none given)
545 sanlock direct access storage directly (no coordination with daemon)
546
547
548 Daemon Command
549 sanlock daemon [options]
550
551 -D no fork and print all logging to stderr
552
553 -Q 0|1 quiet error messages for common lock contention
554
555 -R 0|1 renewal debugging, log debug info for each renewal
556
557 -L pri write logging at priority level and up to logfile (-1 none)
558
559 -S pri write logging at priority level and up to syslog (-1 none)
560
561 -U uid user id
562
563 -G gid group id
564
565 -t num max worker threads
566
567 -g sec seconds for graceful recovery
568
569 -w 0|1 use watchdog through wdmd
570
571 -h 0|1 use high priority (RR) scheduling
572
573 -l num use mlockall (0 none, 1 current, 2 current and future)
574
575 -b sec seconds a host id bit will remain set in delta lease bitmap
576
577 -e str local host name used in delta leases
578
579
580
581 Client Command
582 sanlock client action [options]
583
584 sanlock client status
585
586 Print processes, lockspaces, and resources being managed by the sanlock
587 daemon. Add -D to show extra internal daemon status for debugging.
588 Add -o p to show resources by pid, or -o s to show resources by
589 lockspace.
590
591 sanlock client host_status
592
593 Print state of host_id delta leases read during the last renewal.
594 State of all lockspaces is shown (use -s to select one). Add -D to
595 show extra internal daemon status for debugging.
596
597 sanlock client gets
598
599 Print lockspaces being managed by the sanlock daemon. The LOCKSPACE
600 string will be followed by ADD or REM if the lockspace is currently
601 being added or removed. Add -h 1 to also show hosts in each lockspace.
602
603 sanlock client renewal -s LOCKSPACE
604
605 Print a history of renewals with timing details. See the Renewal his‐
606 tory section below.
607
608 sanlock client log_dump
609
610 Print the sanlock daemon internal debug log.
611
612 sanlock client shutdown
613
614 Ask the sanlock daemon to exit. Without the force option (-f 0), the
615 command will be ignored if any lockspaces exist. With the force option
616 (-f 1), any registered processes will be killed, their resource leases
617 released, and lockspaces removed. With the wait option (-w 1), the
618 command will wait for a result from the daemon indicating that it has
619 shut down and is exiting, or cannot shut down because lockspaces exist
620 (command fails).
621
622 sanlock client init -s LOCKSPACE
623
624 Tell the sanlock daemon to initialize a lockspace on disk. The -o
625 option can be used to specify the io timeout to be written in the
626 host_id leases. The -Z and -A options can be used to specify the sec‐
627 tor size and align size, and both should be set together. (Also see
628 sanlock direct init.)
629
630 sanlock client init -r RESOURCE
631
632 Tell the sanlock daemon to initialize a resource lease on disk. The -Z
633 and -A options can be used to specify the sector size and align size,
634 and both should be set together. (Also see sanlock direct init.)
635
636 sanlock client read -s LOCKSPACE
637
638 Tell the sanlock daemon to read a lockspace from disk. Only the
639 LOCKSPACE path and offset are required. If host_id is zero, the first
640 record at offset (host_id 1) is used. The complete LOCKSPACE is
641 printed. Add -D to print other details. (Also see sanlock direct
642 read_leader.)
643
644 sanlock client read -r RESOURCE
645
646 Tell the sanlock daemon to read a resource lease from disk. Only the
647 RESOURCE path and offset are required. The complete RESOURCE is
648 printed. Add -D to print other details. (Also see sanlock direct
649 read_leader.)
650
651 sanlock client add_lockspace -s LOCKSPACE
652
653 Tell the sanlock daemon to acquire the specified host_id in the
654 lockspace. This will allow resources to be acquired in the lockspace.
655 The -o option can be used to specify the io timeout of the acquiring
656 host, and will be written in the host_id lease.
657
658 sanlock client inq_lockspace -s LOCKSPACE
659
660 Inquire about the state of the lockspace in the sanlock daemon, whether
661 it is being added or removed, or is joined.
662
663 sanlock client rem_lockspace -s LOCKSPACE
664
665 Tell the sanlock daemon to release the specified host_id in the
666 lockspace. Any processes holding resource leases in this lockspace
667 will be killed, and the resource leases not released.
668
669 sanlock client command -r RESOURCE -c path args
670
671 Register with the sanlock daemon, acquire the specified resource lease,
672 and exec the command at path with args. When the command exits, the
673 sanlock daemon will release the lease. -c must be the final option.
674
675 sanlock client acquire -r RESOURCE -p pid
676 sanlock client release -r RESOURCE -p pid
677
678 Tell the sanlock daemon to acquire or release the specified resource
679 lease for the given pid. The pid must be registered with the sanlock
680 daemon. acquire can optionally take a versioned RESOURCE string
681 RESOURCE:lver, where lver is the version of the lease that must be
682 acquired, or fail.
683
684 sanlock client convert -r RESOURCE -p pid
685
686 Tell the sanlock daemon to convert the mode of the specified resource
687 lease for the given pid. If the existing mode is exclusive (default),
688 the mode of the lease can be converted to shared with RESOURCE:SH. If
689 the existing mode is shared, the mode of the lease can be converted to
690 exclusive with RESOURCE (no :SH suffix).
691
692 sanlock client inquire -p pid
693
694 Print the resource leases held the given pid. The format is a ver‐
695 sioned RESOURCE string "RESOURCE:lver" where lver is the version of the
696 lease held.
697
698 sanlock client request -r RESOURCE -f force_mode
699
700 Request the owner of a resource do something specified by force_mode.
701 A versioned RESOURCE:lver string must be used with a greater version
702 than is presently held. Zero lver and force_mode clears the request.
703
704 sanlock client examine -r RESOURCE
705
706 Examine the request record for the currently held resource lease and
707 carry out the action specified by the requested force_mode.
708
709 sanlock client examine -s LOCKSPACE
710
711 Examine requests for all resource leases currently held in the named
712 lockspace. Only lockspace_name is used from the LOCKSPACE argument.
713
714 sanlock client set_event -s LOCKSPACE -i host_id -g gen -e num -d num
715
716 Set an event for another host. When the sanlock daemon next renews its
717 delta lease for the lockspace it will: set the bit for the host_id in
718 its bitmap, and set the generation, event and data values in its own
719 delta lease. An application that has registered for events from this
720 lockspace on the destination host will get the event that has been set
721 when the destination sees the event during its next delta lease
722 renewal.
723
724 sanlock client set_config -s LOCKSPACE
725
726 Set a configuration value for a lockspace. Only lockspace_name is used
727 from the LOCKSPACE argument. The USED flag has the same effect on a
728 lockspace as a process holding a resource lease that will not exit.
729 The USED_BY_ORPHANS flag means that an orphan resource lease will have
730 the same effect as the USED.
731 -u 0|1 Set (1) or clear (0) the USED flag.
732 -O 0|1 Set (1) or clear (0) the USED_BY_ORPHANS flag.
733
734 sanlock client format -x RINDEX
735
736 Create a resource index on disk. Use -Z and -A to set the sector size
737 and align size to match the lockspace.
738
739 sanlock client create -x RINDEX -e resource_name
740
741 Create a new resource lease on disk, using the rindex to find a free
742 offset.
743
744 sanlock client delete -x RINDEX -e resource_name[:offset]
745
746 Delete an existing resource lease on disk.
747
748 sanlock client lookup -x RINDEX -e resource_name
749
750 Look up the offset of an existing resource lease by name on disk, using
751 the rindex. With no -e option, lookup returns the next free lease off‐
752 set. If -e specifes both name and offset, the lookup verifies both are
753 correct.
754
755 sanlock client update -x RINDEX -e resource_name[:offset] [-z 0|1]
756
757 Add (-z 0) or remove (-z 1) an rindex entry on disk.
758
759 sanlock client rebuild -x RINDEX
760
761 Rebuild the rindex entries by scanning the disk for resource leases.
762
763
764
765 Direct Command
766 sanlock direct action [options]
767
768
769 -o sec io timeout in seconds
770
771 sanlock direct init -s LOCKSPACE
772 sanlock direct init -r RESOURCE
773
774 Initialize storage for a lockspace or resource. Use the -Z and -A
775 flags to specify the sector size and align size. The max hosts that
776 can use the lockspace/resource (and the max possible host_id) is deter‐
777 mined by the sector/align size combination. Possible combinations are:
778 512/1M, 4096/1M, 4096/2M, 4096/4M, 4096/8M. Lockspaces and resources
779 both use the same amount of space (align_size) for each combination.
780 When initializing a lockspace, sanlock initializes delta leases for
781 max_hosts in the given space. When initializing a resource, sanlock
782 initializes a single paxos lease in the space. With -s, the -o option
783 specifies the io timeout to be written in the host_id leases. With -r,
784 the -z 1 option invalidates the resource lease on disk so it cannot be
785 used until reinitialized normally.
786
787 sanlock direct read_leader -s LOCKSPACE
788 sanlock direct read_leader -r RESOURCE
789
790 Read a leader record from disk and print the fields. The leader record
791 is the single sector of a delta lease, or the first sector of a paxos
792 lease.
793
794 sanlock direct dump path[:offset[:size]]
795
796 Read disk sectors and print leader records for delta or paxos leases.
797 Add -f 1 to print the request record values for paxos leases, host_ids
798 set in delta lease bitmaps, and rindex entries.
799
800 sanlock direct format -x RINDEX
801 sanlock direct lookup -x RINDEX -e resource_name
802 sanlock direct update -x RINDEX -e resource_name[:offset] [-z 0|1]
803 sanlock direct rebuild -x RINDEX
804
805 Access the resource index on disk without going through the sanlock
806 daemon. This precludes using the internal paxos lease to protect
807 rindex modifications. See client equivalents for descriptions.
808
809
810
811 LOCKSPACE option string
812 -s lockspace_name:host_id:path:offset
813
814 lockspace_name name of lockspace
815 host_id local host identifier in lockspace
816 path path to storage to use for leases
817 offset offset on path (bytes)
818
819
820 RESOURCE option string
821 -r lockspace_name:resource_name:path:offset
822
823 lockspace_name name of lockspace
824 resource_name name of resource
825 path path to storage to use leases
826 offset offset on path (bytes)
827
828
829 RESOURCE option string with suffix
830 -r lockspace_name:resource_name:path:offset:lver
831
832 lver leader version
833
834 -r lockspace_name:resource_name:path:offset:SH
835
836 SH indicates shared mode
837
838
839 RINDEX option string
840 -x lockspace_name:path:offset
841
842 lockspace_name name of lockspace
843 path path to storage to use for leases
844 offset offset on path (bytes) of rindex
845
846
847
848 Defaults
849 sanlock help shows the default values for the options above.
850
851 sanlock version shows the build version.
852
853
855 Request/Examine
856 The first part of making a request for a resource is writing the
857 request record of the resource (the sector following the leader
858 record). To make a successful request:
859
860 · RESOURCE:lver must be greater than the lver presently held by the
861 other host. This implies the leader record must be read to discover
862 the lver, prior to making a request.
863
864 · RESOURCE:lver must be greater than or equal to the lver presently
865 written to the request record. Two hosts may write a new request at
866 the same time for the same lver, in which case both would succeed,
867 but the force_mode from the last would win.
868
869 · The force_mode must be greater than zero.
870
871 · To unconditionally clear the request record (set both lver and
872 force_mode to 0), make request with RESOURCE:0 and force_mode 0.
873
874
875 The owner of the requested resource will not know of the request unless
876 it is explicitly told to examine its resources via the "examine"
877 api/command, or otherwise notfied.
878
879 The second part of making a request is notifying the resource lease
880 owner that it should examine the request records of its resource
881 leases. The notification will cause the lease owner to automatically
882 run the equivalent of "sanlock client examine -s LOCKSPACE" for the
883 lockspace of the requested resource.
884
885 The notification is made using a bitmap in each host_id delta lease.
886 Each bit represents each of the possible host_ids (1-2000). If host A
887 wants to notify host B to examine its resources, A sets the bit in its
888 own bitmap that corresponds to the host_id of B. When B next renews
889 its delta lease, it reads the delta leases for all hosts and checks
890 each bitmap to see if its own host_id has been set. It finds the bit
891 for its own host_id set in A's bitmap, and examines its resource
892 request records. (The bit remains set in A's bitmap for set_bit‐
893 map_seconds.)
894
895 force_mode determines the action the resource lease owner should take:
896
897
898 · FORCE (1): kill the process holding the resource lease. When the
899 process has exited, the resource lease will be released, and can then
900 be acquired by anyone. The kill signal is SIGKILL (or SIGTERM if
901 SIGKILL is restricted.)
902
903
904 · GRACEFUL (2): run the program configured by sanlock_killpath against
905 the process holding the resource lease. If no killpath is defined,
906 then FORCE is used.
907
908
909 Persistent and orphan resource leases
910 A resource lease can be acquired with the PERSISTENT flag (-P 1). If
911 the process holding the lease exits, the lease will not be released,
912 but kept on an orphan list. Another local process can acquire an
913 orphan lease using the ORPHAN flag (-O 1), or release the orphan lease
914 using the ORPHAN flag (-O 1). All orphan leases can be released by
915 setting the lockspace name (-s lockspace_name) with no resource name.
916
917
918 Renewal history
919 sanlock saves a limited history of lease renewal information in each
920 lockspace. See sanlock.conf renewal_history_size to set the amount of
921 history or to disable (set to 0).
922
923 IO times are measured in delta lease renewal (each delta lease renewal
924 includes one read and one write).
925
926 For each successful renewal, a record is saved that includes:
927
928 · the timestamp written in the delta lease by the renewal
929
930 · the time in milliseconds taken by the delta lease read
931
932 · the time in milliseconds taken by the delta lease write
933
934
935 Also counted and recorded are the number io timeouts and other io
936 errors that occur between successful renewals.
937
938 Two consecutive successful renewals would be recorded as:
939 timestamp=5332 read_ms=482 write_ms=5525 next_timeouts=0 next_errors=0
940 timestamp=5353 read_ms=99 write_ms=3161 next_timeouts=0 next_errors=0
941
942 Those fields are:
943
944
945 · timestamp is the value written into the delta lease during that
946 renewal.
947
948
949 · read_ms/write_ms are the milliseconds taken for the renewal
950 read/write ios.
951
952
953 · next_timeouts are the number of io timeouts that occured after the
954 renewal recorded on that line, and before the next successful renewal
955 on the following line.
956
957
958 · next_errors are the number of io errors (not timeouts) that occured
959 after renewal recorded on that line, and before the next successful
960 renewal on the following line.
961
962
963 The command 'sanlock client renewal -s lockspace_name' reports the full
964 history of renewals saved by sanlock, which by default is 180 records,
965 about 1 hour of history when using a 20 second renewal interval for a
966 10 second io timeout.
967
968
970 Disk Format
971 · This example uses 512 byte sectors.
972
973 · Each lockspace is 1MB. It holds 2000 delta_leases, one per sector,
974 supporting up to 2000 hosts.
975
976 · Each paxos_lease is 1MB. It is used as a lease for one resource.
977
978 · The leader_record structure is used differently by each lease type.
979
980 · To display all leader_record fields, see sanlock direct read_leader.
981
982 · A lockspace is often followed on disk by the paxos_leases used within
983 that lockspace, but this layout is not required.
984
985 · The request_record and host_id bitmap are used for requests/events.
986
987 · The mode_block contains the SHARED flag indicating a lease is held in
988 the shared mode.
989
990 · In a lockspace, the host using host_id N writes to a single
991 delta_lease in sector N-1. No other hosts write to this sector. All
992 hosts read all lockspace sectors when renewing their own delta_lease,
993 and are able to monitor renewals of all delta_leases.
994
995 · In a paxos_lease, each host has a dedicated sector it writes to, con‐
996 taining its own paxos_dblock and mode_block structures. Its sector
997 is based on its host_id; host_id 1 writes to the dblock/mode_block in
998 sector 2 of the paxos_lease.
999
1000 · The paxos_dblock structures are used by the paxos_lease algorithm,
1001 and the result is written to the leader_record.
1002
1003
1004 0x000000 lockspace foo:0:/path:0
1005
1006 (There is no representation on disk of the lockspace in general, only
1007 the sequence of specific delta_leases which collectively represent the
1008 lockspace.)
1009
1010 delta_lease foo:1:/path:0
1011 0x000 0 leader_record (sector 0, for host_id 1)
1012 magic: 0x12212010
1013 space_name: foo
1014 resource_name: host uuid/name
1015 ...
1016 host_id bitmap (leader_record + 256)
1017
1018 delta_lease foo:2:/path:0
1019 0x200 512 leader_record (sector 1, for host_id 2)
1020 magic: 0x12212010
1021 space_name: foo
1022 resource_name: host uuid/name
1023 ...
1024 host_id bitmap (leader_record + 256)
1025
1026 delta_lease foo:3:/path:0
1027 0x400 1024 leader_record (sector 2, for host_id 3)
1028 magic: 0x12212010
1029 space_name: foo
1030 resource_name: host uuid/name
1031 ...
1032 host_id bitmap (leader_record + 256)
1033
1034 delta_lease foo:2000:/path:0
1035 0xF9E00 leader_record (sector 1999, for host_id 2000)
1036 magic: 0x12212010
1037 space_name: foo
1038 resource_name: host uuid/name
1039 ...
1040 host_id bitmap (leader_record + 256)
1041
1042 0x100000 paxos_lease foo:example1:/path:1048576
1043 0x000 0 leader_record (sector 0)
1044 magic: 0x06152010
1045 space_name: foo
1046 resource_name: example1
1047
1048 0x200 512 request_record (sector 1)
1049 magic: 0x08292011
1050
1051 0x400 1024 paxos_dblock (sector 2, for host_id 1)
1052 0x480 1152 mode_block (paxos_dblock + 128)
1053
1054 0x600 1536 paxos_dblock (sector 3, for host_id 2)
1055 0x680 1664 mode_block (paxos_dblock + 128)
1056
1057 0x800 2048 paxos_dblock (sector 4, for host_id 3)
1058 0x880 2176 mode_block (paxos_dblock + 128)
1059
1060 0xFA200 paxos_dblock (sector 2001, for host_id 2000)
1061 0xFA280 mode_block (paxos_dblock + 128)
1062
1063 0x200000 paxos_lease foo:example2:/path:2097152
1064 0x000 0 leader_record (sector 0)
1065 magic: 0x06152010
1066 space_name: foo
1067 resource_name: example2
1068
1069 0x200 512 request_record (sector 1)
1070 magic: 0x08292011
1071
1072 0x400 1024 paxos_dblock (sector 2, for host_id 1)
1073 0x480 1152 mode_block (paxos_dblock + 128)
1074
1075 0x600 1536 paxos_dblock (sector 3, for host_id 2)
1076 0x680 1664 mode_block (paxos_dblock + 128)
1077
1078 0x800 2048 paxos_dblock (sector 4, for host_id 3)
1079 0x880 2176 mode_block (paxos_dblock + 128)
1080
1081 0xFA200 paxos_dblock (sector 2001, for host_id 2000)
1082 0xFA280 mode_block (paxos_dblock + 128)
1083
1084
1085 Lease ownership
1086 Not shown in the leader_record structures above are the owner_id,
1087 owner_generation and timestamp fields. These are the fields that
1088 define the lease owner.
1089
1090 The delta_lease at sector N for host_id N+1 has leader_record.owner_id
1091 N+1. The leader_record.owner_generation is incremented each time the
1092 delta_lease is acquired. When a delta_lease is acquired, the
1093 leader_record.timestamp field is set to the time of the host and the
1094 leader_record.resource_name is set to the unique name of the host.
1095 When the host renews the delta_lease, it writes a new
1096 leader_record.timestamp. When a host releases a delta_lease, it writes
1097 zero to leader_record.timestamp.
1098
1099 When a host acquires a paxos_lease, it uses the host_id/generation
1100 value from the delta_lease it holds in the lockspace. It uses this
1101 host_id/generation to identify itself in the paxos_dblock when running
1102 the paxos algorithm. The result of the algorithm is the winning
1103 host_id/generation - the new owner of the paxos_lease. The winning
1104 host_id/generation are written to the paxos_lease
1105 leader_record.owner_id and leader_record.owner_generation fields and
1106 leader_record.timestamp is set. When a host releases a paxos_lease, it
1107 sets leader_record.timestamp to 0.
1108
1109 When a paxos_lease is free (leader_record.timestamp is 0), multiple
1110 hosts may attempt to acquire it. The paxos algorithm, using the
1111 paxos_dblock structures, will select only one of the hosts as the new
1112 owner, and that owner is written in the leader_record. The paxos_lease
1113 will no longer be free (non-zero timestamp). Other hosts will see this
1114 and will not attempt to acquire the paxos_lease until it is free again.
1115
1116 If a paxos_lease is owned (non-zero timestamp), but the owner has not
1117 renewed its delta_lease for a specific length of time, then the owner
1118 value in the paxos_lease becomes expired, and other hosts will use the
1119 paxos algorithm to acquire the paxos_lease, and set a new owner.
1120
1121
1123 /etc/sanlock/sanlock.conf
1124
1125
1126 · quiet_fail = 1
1127 See -Q
1128
1129
1130 · debug_renew = 0
1131 See -R
1132
1133
1134 · logfile_priority = 4
1135 See -L
1136
1137
1138 · logfile_use_utc = 0
1139 Use UTC instead of local time in log messages.
1140
1141
1142 · syslog_priority = 3
1143 See -S
1144
1145
1146 · names_log_priority = 4
1147 Log resource names at this priority level (uses syslog priority num‐
1148 bers). If this is greater than or equal to logfile_priority, each
1149 requested resource name and location is recorded in sanlock.log.
1150
1151
1152 · use_watchdog = 1
1153 See -w
1154
1155
1156 · high_priority = 1
1157 See -h
1158
1159
1160 · mlock_level = 1
1161 See -l
1162
1163
1164 · sh_retries = 8
1165 The number of times to try acquiring a paxos lease when acquiring a
1166 shared lease when the paxos lease is held by another host acquiring a
1167 shared lease.
1168
1169
1170 · uname = sanlock
1171 See -U
1172
1173
1174 · gname = sanlock
1175 See -G
1176
1177
1178 · our_host_name = <str>
1179 See -e
1180
1181
1182 · renewal_read_extend_sec = <seconds>
1183 If a renewal read i/o times out, wait this many additional seconds
1184 for that read to complete at the start of the subsequent renewal
1185 attempt. When not configured, sanlock waits for an additional
1186 io_timeout seconds for a previous timed out read to complete.
1187
1188
1189 · renewal_history_size = 180
1190 See -H
1191
1192
1193 · paxos_debug_all = 0
1194 Include all details in the paxos debug logging.
1195
1196
1197 · debug_io = <str>
1198 Add debug logging for each i/o. "submit" (no quotes) produces debug
1199 output at submission time, "complete" produces debug output at com‐
1200 pletion time, and "submit,complete" (no space) produces both.
1201
1202
1203 · max_sectors_kb = <str>|<num>
1204 Set to "ignore" (no quotes) to prevent sanlock from checking or
1205 changing max_sectors_kb for the lockspace disk when starting a
1206 lockspace. Set to "align" (no quotes) to set max_sectors_kb for the
1207 lockspace disk to the align size of the lockspace. Set to a number
1208 to set a specific number of KB for all lockspace disks.
1209
1210
1211
1213 wdmd(8)
1214
1215
1216
1217
1218 2015-01-23 SANLOCK(8)