3 provide API to do non-blocking locks for single or all databases
5 Copyright (C) Amitay Isaacs 2012
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include "include/ctdb_private.h"
22 #include "include/ctdb_protocol.h"
25 #include "lib/tdb_wrap/tdb_wrap.h"
26 #include "system/filesys.h"
27 #include "lib/util/dlinklist.h"
30 * Non-blocking Locking API
32 * 1. Create a child process to do blocking locks.
33 * 2. Once the locks are obtained, signal parent process via fd.
34 * 3. Invoke registered callback routine with locking status.
35 * 4. If the child process cannot get locks within certain time,
36 * execute an external script to debug.
38 * ctdb_lock_record() - get a lock on a record
39 * ctdb_lock_db() - get a lock on a DB
40 * ctdb_lock_alldb_prio() - get a lock on all DBs with given priority
41 * ctdb_lock_alldb() - get a lock on all DBs
43 * auto_mark - whether to mark/unmark DBs in before/after callback
53 static const char * const lock_type_str[] = {
62 /* lock_context is the common part for a lock request */
64 struct lock_context *next, *prev;
66 struct ctdb_context *ctdb;
67 struct ctdb_db_context *ctdb_db;
71 struct lock_request *request;
74 struct tevent_fd *tfd;
75 struct tevent_timer *ttimer;
76 struct timeval start_time;
81 /* lock_request is the client specific part for a lock request */
83 struct lock_context *lctx;
84 void (*callback)(void *, bool);
90 * Support samba 3.6.x (and older) versions which do not set db priority.
92 * By default, all databases are set to priority 1. So only when priority
93 * is set to 1, check for databases that need higher priority.
95 static bool later_db(struct ctdb_context *ctdb, const char *name)
97 if (ctdb->tunable.samba3_hack == 0) {
101 if (strstr(name, "brlock") ||
102 strstr(name, "g_lock") ||
103 strstr(name, "notify_onelevel") ||
104 strstr(name, "serverid") ||
105 strstr(name, "xattr_tdb")) {
112 typedef int (*db_handler_t)(struct ctdb_db_context *ctdb_db,
116 static int ctdb_db_iterator(struct ctdb_context *ctdb, uint32_t priority,
117 db_handler_t handler, void *private_data)
119 struct ctdb_db_context *ctdb_db;
122 for (ctdb_db = ctdb->db_list; ctdb_db; ctdb_db = ctdb_db->next) {
123 if (ctdb_db->priority != priority) {
126 if (later_db(ctdb, ctdb_db->db_name)) {
129 ret = handler(ctdb_db, priority, private_data);
135 /* If priority != 1, later_db check is not required and can return */
140 for (ctdb_db = ctdb->db_list; ctdb_db; ctdb_db = ctdb_db->next) {
141 if (!later_db(ctdb, ctdb_db->db_name)) {
144 ret = handler(ctdb_db, priority, private_data);
155 * lock all databases - mark only
157 static int db_lock_mark_handler(struct ctdb_db_context *ctdb_db, uint32_t priority,
160 int tdb_transaction_write_lock_mark(struct tdb_context *);
162 DEBUG(DEBUG_INFO, ("marking locked database %s, priority:%u\n",
163 ctdb_db->db_name, priority));
165 if (tdb_transaction_write_lock_mark(ctdb_db->ltdb->tdb) != 0) {
166 DEBUG(DEBUG_ERR, ("Failed to mark (transaction lock) database %s\n",
171 if (tdb_lockall_mark(ctdb_db->ltdb->tdb) != 0) {
172 DEBUG(DEBUG_ERR, ("Failed to mark (all lock) database %s\n",
180 int ctdb_lockall_mark_prio(struct ctdb_context *ctdb, uint32_t priority)
183 * This function is only used by the main dameon during recovery.
184 * At this stage, the databases have already been locked, by a
185 * dedicated child process. The freeze_mode variable is used to track
186 * whether the actual locks are held by the child process or not.
189 if (ctdb->freeze_mode[priority] != CTDB_FREEZE_FROZEN) {
190 DEBUG(DEBUG_ERR, ("Attempt to mark all databases locked when not frozen\n"));
194 return ctdb_db_iterator(ctdb, priority, db_lock_mark_handler, NULL);
197 static int ctdb_lockall_mark(struct ctdb_context *ctdb)
201 for (priority=1; priority<=NUM_DB_PRIORITIES; priority++) {
202 if (ctdb_db_iterator(ctdb, priority, db_lock_mark_handler, NULL) != 0) {
212 * lock all databases - unmark only
214 static int db_lock_unmark_handler(struct ctdb_db_context *ctdb_db, uint32_t priority,
217 int tdb_transaction_write_lock_unmark(struct tdb_context *);
219 DEBUG(DEBUG_INFO, ("unmarking locked database %s, priority:%u\n",
220 ctdb_db->db_name, priority));
222 if (tdb_transaction_write_lock_unmark(ctdb_db->ltdb->tdb) != 0) {
223 DEBUG(DEBUG_ERR, ("Failed to unmark (transaction lock) database %s\n",
228 if (tdb_lockall_unmark(ctdb_db->ltdb->tdb) != 0) {
229 DEBUG(DEBUG_ERR, ("Failed to unmark (all lock) database %s\n",
237 int ctdb_lockall_unmark_prio(struct ctdb_context *ctdb, uint32_t priority)
240 * This function is only used by the main daemon during recovery.
241 * At this stage, the databases have already been locked, by a
242 * dedicated child process. The freeze_mode variable is used to track
243 * whether the actual locks are held by the child process or not.
246 if (ctdb->freeze_mode[priority] != CTDB_FREEZE_FROZEN) {
247 DEBUG(DEBUG_ERR, ("Attempt to unmark all databases locked when not frozen\n"));
251 return ctdb_db_iterator(ctdb, priority, db_lock_unmark_handler, NULL);
254 static int ctdb_lockall_unmark(struct ctdb_context *ctdb)
258 for (priority=NUM_DB_PRIORITIES; priority>0; priority--) {
259 if (ctdb_db_iterator(ctdb, priority, db_lock_unmark_handler, NULL) != 0) {
268 static void ctdb_lock_schedule(struct ctdb_context *ctdb);
271 * Destructor to kill the child locking process
273 static int ctdb_lock_context_destructor(struct lock_context *lock_ctx)
275 if (lock_ctx->request) {
276 lock_ctx->request->lctx = NULL;
278 if (lock_ctx->child > 0) {
279 ctdb_kill(lock_ctx->ctdb, lock_ctx->child, SIGKILL);
280 if (lock_ctx->type == LOCK_RECORD) {
281 DLIST_REMOVE(lock_ctx->ctdb_db->lock_current, lock_ctx);
283 DLIST_REMOVE(lock_ctx->ctdb->lock_current, lock_ctx);
285 if (lock_ctx->ctdb_db) {
286 lock_ctx->ctdb_db->lock_num_current--;
288 CTDB_DECREMENT_STAT(lock_ctx->ctdb, locks.num_current);
289 if (lock_ctx->ctdb_db) {
290 CTDB_DECREMENT_DB_STAT(lock_ctx->ctdb_db, locks.num_current);
293 if (lock_ctx->type == LOCK_RECORD) {
294 DLIST_REMOVE(lock_ctx->ctdb_db->lock_pending, lock_ctx);
296 DLIST_REMOVE(lock_ctx->ctdb->lock_pending, lock_ctx);
298 CTDB_DECREMENT_STAT(lock_ctx->ctdb, locks.num_pending);
299 if (lock_ctx->ctdb_db) {
300 CTDB_DECREMENT_DB_STAT(lock_ctx->ctdb_db, locks.num_pending);
304 ctdb_lock_schedule(lock_ctx->ctdb);
311 * Destructor to remove lock request
313 static int ctdb_lock_request_destructor(struct lock_request *lock_request)
315 TALLOC_FREE(lock_request->lctx);
320 * Process all the callbacks waiting for lock
322 * If lock has failed, callback is executed with locked=false
324 static void process_callbacks(struct lock_context *lock_ctx, bool locked)
326 struct lock_request *request;
328 if (lock_ctx->auto_mark && locked) {
329 switch (lock_ctx->type) {
331 tdb_chainlock_mark(lock_ctx->ctdb_db->ltdb->tdb, lock_ctx->key);
335 tdb_lockall_mark(lock_ctx->ctdb_db->ltdb->tdb);
338 case LOCK_ALLDB_PRIO:
339 ctdb_lockall_mark_prio(lock_ctx->ctdb, lock_ctx->priority);
343 ctdb_lockall_mark(lock_ctx->ctdb);
348 request = lock_ctx->request;
349 if (lock_ctx->auto_mark) {
350 /* Reset the destructor, so request is not removed from the list */
351 talloc_set_destructor(request, NULL);
353 request->callback(request->private_data, locked);
355 if (lock_ctx->auto_mark && locked) {
356 switch (lock_ctx->type) {
358 tdb_chainlock_unmark(lock_ctx->ctdb_db->ltdb->tdb, lock_ctx->key);
362 tdb_lockall_unmark(lock_ctx->ctdb_db->ltdb->tdb);
365 case LOCK_ALLDB_PRIO:
366 ctdb_lockall_unmark_prio(lock_ctx->ctdb, lock_ctx->priority);
370 ctdb_lockall_unmark(lock_ctx->ctdb);
377 static int lock_bucket_id(double t)
379 double ms = 1.e-3, s = 1;
384 } else if (t < 10*ms) {
386 } else if (t < 100*ms) {
388 } else if (t < 1*s) {
390 } else if (t < 2*s) {
392 } else if (t < 4*s) {
394 } else if (t < 8*s) {
396 } else if (t < 16*s) {
398 } else if (t < 32*s) {
400 } else if (t < 64*s) {
410 * Callback routine when the required locks are obtained.
411 * Called from parent context
413 static void ctdb_lock_handler(struct tevent_context *ev,
414 struct tevent_fd *tfd,
418 struct lock_context *lock_ctx;
419 TALLOC_CTX *tmp_ctx = NULL;
425 lock_ctx = talloc_get_type_abort(private_data, struct lock_context);
427 /* cancel the timeout event */
428 TALLOC_FREE(lock_ctx->ttimer);
430 t = timeval_elapsed(&lock_ctx->start_time);
431 id = lock_bucket_id(t);
433 if (lock_ctx->auto_mark) {
434 tmp_ctx = talloc_new(ev);
435 talloc_steal(tmp_ctx, lock_ctx);
438 /* Read the status from the child process */
439 if (sys_read(lock_ctx->fd[0], &c, 1) != 1) {
442 locked = (c == 0 ? true : false);
445 /* Update statistics */
446 CTDB_INCREMENT_STAT(lock_ctx->ctdb, locks.num_calls);
447 if (lock_ctx->ctdb_db) {
448 CTDB_INCREMENT_DB_STAT(lock_ctx->ctdb_db, locks.num_calls);
452 if (lock_ctx->ctdb_db) {
453 CTDB_INCREMENT_STAT(lock_ctx->ctdb, locks.buckets[id]);
454 CTDB_UPDATE_LATENCY(lock_ctx->ctdb, lock_ctx->ctdb_db,
455 lock_type_str[lock_ctx->type], locks.latency,
456 lock_ctx->start_time);
458 CTDB_UPDATE_DB_LATENCY(lock_ctx->ctdb_db, lock_type_str[lock_ctx->type], locks.latency, t);
459 CTDB_INCREMENT_DB_STAT(lock_ctx->ctdb_db, locks.buckets[id]);
462 CTDB_INCREMENT_STAT(lock_ctx->ctdb, locks.num_failed);
463 if (lock_ctx->ctdb_db) {
464 CTDB_INCREMENT_DB_STAT(lock_ctx->ctdb_db, locks.num_failed);
468 process_callbacks(lock_ctx, locked);
470 if (lock_ctx->auto_mark) {
471 talloc_free(tmp_ctx);
477 * Callback routine when required locks are not obtained within timeout
478 * Called from parent context
480 static void ctdb_lock_timeout_handler(struct tevent_context *ev,
481 struct tevent_timer *ttimer,
482 struct timeval current_time,
485 static const char * debug_locks = NULL;
486 struct lock_context *lock_ctx;
487 struct ctdb_context *ctdb;
490 lock_ctx = talloc_get_type_abort(private_data, struct lock_context);
491 ctdb = lock_ctx->ctdb;
493 /* If a node stopped/banned, don't spam the logs */
494 if (ctdb->nodes[ctdb->pnn]->flags & NODE_FLAGS_INACTIVE) {
495 lock_ctx->ttimer = NULL;
498 if (lock_ctx->ctdb_db) {
500 ("Unable to get %s lock on database %s for %.0lf seconds\n",
501 (lock_ctx->type == LOCK_RECORD ? "RECORD" : "DB"),
502 lock_ctx->ctdb_db->db_name,
503 timeval_elapsed(&lock_ctx->start_time)));
506 ("Unable to get ALLDB locks for %.0lf seconds\n",
507 timeval_elapsed(&lock_ctx->start_time)));
510 /* Fire a child process to find the blocking process. */
511 if (debug_locks == NULL) {
512 debug_locks = getenv("CTDB_DEBUG_LOCKS");
513 if (debug_locks == NULL) {
514 debug_locks = talloc_asprintf(ctdb,
516 getenv("CTDB_BASE"));
519 if (debug_locks != NULL) {
522 execl(debug_locks, debug_locks, NULL);
525 ctdb_track_child(ctdb, pid);
529 " Unable to setup lock debugging - no memory?\n"));
532 /* reset the timeout timer */
533 // talloc_free(lock_ctx->ttimer);
534 lock_ctx->ttimer = tevent_add_timer(ctdb->ev,
536 timeval_current_ofs(10, 0),
537 ctdb_lock_timeout_handler,
542 static int db_count_handler(struct ctdb_db_context *ctdb_db, uint32_t priority,
545 int *count = (int *)private_data;
557 static int db_name_handler(struct ctdb_db_context *ctdb_db, uint32_t priority,
560 struct db_namelist *list = (struct db_namelist *)private_data;
562 list->names[list->n] = talloc_strdup(list->names, ctdb_db->db_path);
568 static bool lock_helper_args(TALLOC_CTX *mem_ctx,
569 struct lock_context *lock_ctx, int fd,
570 int *argc, const char ***argv)
572 struct ctdb_context *ctdb = lock_ctx->ctdb;
573 const char **args = NULL;
576 struct db_namelist list;
578 switch (lock_ctx->type) {
587 case LOCK_ALLDB_PRIO:
589 ctdb_db_iterator(ctdb, lock_ctx->priority, db_count_handler, &nargs);
594 for (priority=1; priority<NUM_DB_PRIORITIES; priority++) {
595 ctdb_db_iterator(ctdb, priority, db_count_handler, &nargs);
600 /* Add extra argument for null termination */
603 args = talloc_array(mem_ctx, const char *, nargs);
608 args[0] = talloc_asprintf(args, "%d", getpid());
609 args[1] = talloc_asprintf(args, "%d", fd);
611 switch (lock_ctx->type) {
613 args[2] = talloc_strdup(args, "RECORD");
614 args[3] = talloc_strdup(args, lock_ctx->ctdb_db->db_path);
615 if (lock_ctx->key.dsize == 0) {
616 args[4] = talloc_strdup(args, "NULL");
618 args[4] = hex_encode_talloc(args, lock_ctx->key.dptr, lock_ctx->key.dsize);
623 args[2] = talloc_strdup(args, "DB");
624 args[3] = talloc_strdup(args, lock_ctx->ctdb_db->db_path);
627 case LOCK_ALLDB_PRIO:
628 args[2] = talloc_strdup(args, "DB");
631 ctdb_db_iterator(ctdb, lock_ctx->priority, db_name_handler, &list);
635 args[2] = talloc_strdup(args, "DB");
638 for (priority=1; priority<NUM_DB_PRIORITIES; priority++) {
639 ctdb_db_iterator(ctdb, priority, db_name_handler, &list);
644 /* Make sure last argument is NULL */
645 args[nargs-1] = NULL;
647 for (i=0; i<nargs-1; i++) {
648 if (args[i] == NULL) {
660 * Find a lock request that can be scheduled
662 static struct lock_context *ctdb_find_lock_context(struct ctdb_context *ctdb)
664 struct lock_context *lock_ctx, *next_ctx;
665 struct ctdb_db_context *ctdb_db;
667 /* First check if there are database lock requests */
669 for (lock_ctx = ctdb->lock_pending; lock_ctx != NULL;
670 lock_ctx = next_ctx) {
672 if (lock_ctx->request != NULL) {
673 /* Found a lock context with a request */
677 next_ctx = lock_ctx->next;
679 DEBUG(DEBUG_INFO, ("Removing lock context without lock "
681 DLIST_REMOVE(ctdb->lock_pending, lock_ctx);
682 CTDB_DECREMENT_STAT(ctdb, locks.num_pending);
683 if (lock_ctx->ctdb_db) {
684 CTDB_DECREMENT_DB_STAT(lock_ctx->ctdb_db,
687 talloc_free(lock_ctx);
690 /* Next check database queues */
691 for (ctdb_db = ctdb->db_list; ctdb_db; ctdb_db = ctdb_db->next) {
692 if (ctdb_db->lock_num_current ==
693 ctdb->tunable.lock_processes_per_db) {
697 for (lock_ctx = ctdb_db->lock_pending; lock_ctx != NULL;
698 lock_ctx = next_ctx) {
700 next_ctx = lock_ctx->next;
702 if (lock_ctx->request != NULL) {
706 DEBUG(DEBUG_INFO, ("Removing lock context without "
708 DLIST_REMOVE(ctdb_db->lock_pending, lock_ctx);
709 CTDB_DECREMENT_STAT(ctdb, locks.num_pending);
710 CTDB_DECREMENT_DB_STAT(ctdb_db, locks.num_pending);
711 talloc_free(lock_ctx);
719 * Schedule a new lock child process
720 * Set up callback handler and timeout handler
722 static void ctdb_lock_schedule(struct ctdb_context *ctdb)
724 struct lock_context *lock_ctx;
727 const char *helper = CTDB_HELPER_BINDIR "/ctdb_lock_helper";
728 static const char *prog = NULL;
734 t = getenv("CTDB_LOCK_HELPER");
736 prog = talloc_strdup(ctdb, t);
738 prog = talloc_strdup(ctdb, helper);
740 CTDB_NO_MEMORY_VOID(ctdb, prog);
743 /* Find a lock context with requests */
744 lock_ctx = ctdb_find_lock_context(ctdb);
745 if (lock_ctx == NULL) {
749 lock_ctx->child = -1;
750 ret = pipe(lock_ctx->fd);
752 DEBUG(DEBUG_ERR, ("Failed to create pipe in ctdb_lock_schedule\n"));
756 set_close_on_exec(lock_ctx->fd[0]);
758 /* Create data for child process */
759 tmp_ctx = talloc_new(lock_ctx);
760 if (tmp_ctx == NULL) {
761 DEBUG(DEBUG_ERR, ("Failed to allocate memory for helper args\n"));
762 close(lock_ctx->fd[0]);
763 close(lock_ctx->fd[1]);
767 /* Create arguments for lock helper */
768 if (!lock_helper_args(tmp_ctx, lock_ctx, lock_ctx->fd[1],
770 DEBUG(DEBUG_ERR, ("Failed to create lock helper args\n"));
771 close(lock_ctx->fd[0]);
772 close(lock_ctx->fd[1]);
773 talloc_free(tmp_ctx);
777 if (!ctdb_vfork_with_logging(lock_ctx, ctdb, "lock_helper",
778 prog, argc, (const char **)args,
779 NULL, NULL, &lock_ctx->child)) {
780 DEBUG(DEBUG_ERR, ("Failed to create a child in ctdb_lock_schedule\n"));
781 close(lock_ctx->fd[0]);
782 close(lock_ctx->fd[1]);
783 talloc_free(tmp_ctx);
788 close(lock_ctx->fd[1]);
790 talloc_set_destructor(lock_ctx, ctdb_lock_context_destructor);
792 talloc_free(tmp_ctx);
794 /* Set up timeout handler */
795 lock_ctx->ttimer = tevent_add_timer(ctdb->ev,
797 timeval_current_ofs(10, 0),
798 ctdb_lock_timeout_handler,
800 if (lock_ctx->ttimer == NULL) {
801 ctdb_kill(ctdb, lock_ctx->child, SIGKILL);
802 lock_ctx->child = -1;
803 talloc_set_destructor(lock_ctx, NULL);
804 close(lock_ctx->fd[0]);
808 /* Set up callback */
809 lock_ctx->tfd = tevent_add_fd(ctdb->ev,
815 if (lock_ctx->tfd == NULL) {
816 TALLOC_FREE(lock_ctx->ttimer);
817 ctdb_kill(ctdb, lock_ctx->child, SIGKILL);
818 lock_ctx->child = -1;
819 talloc_set_destructor(lock_ctx, NULL);
820 close(lock_ctx->fd[0]);
823 tevent_fd_set_auto_close(lock_ctx->tfd);
825 /* Move the context from pending to current */
826 if (lock_ctx->type == LOCK_RECORD) {
827 DLIST_REMOVE(lock_ctx->ctdb_db->lock_pending, lock_ctx);
828 DLIST_ADD_END(lock_ctx->ctdb_db->lock_current, lock_ctx, NULL);
830 DLIST_REMOVE(ctdb->lock_pending, lock_ctx);
831 DLIST_ADD_END(ctdb->lock_current, lock_ctx, NULL);
833 CTDB_DECREMENT_STAT(lock_ctx->ctdb, locks.num_pending);
834 CTDB_INCREMENT_STAT(lock_ctx->ctdb, locks.num_current);
835 if (lock_ctx->ctdb_db) {
836 lock_ctx->ctdb_db->lock_num_current++;
837 CTDB_DECREMENT_DB_STAT(lock_ctx->ctdb_db, locks.num_pending);
838 CTDB_INCREMENT_DB_STAT(lock_ctx->ctdb_db, locks.num_current);
844 * Lock record / db depending on type
846 static struct lock_request *ctdb_lock_internal(TALLOC_CTX *mem_ctx,
847 struct ctdb_context *ctdb,
848 struct ctdb_db_context *ctdb_db,
851 void (*callback)(void *, bool),
856 struct lock_context *lock_ctx = NULL;
857 struct lock_request *request;
859 if (callback == NULL) {
860 DEBUG(DEBUG_WARNING, ("No callback function specified, not locking\n"));
864 lock_ctx = talloc_zero(ctdb, struct lock_context);
865 if (lock_ctx == NULL) {
866 DEBUG(DEBUG_ERR, ("Failed to create a new lock context\n"));
870 if ((request = talloc_zero(mem_ctx, struct lock_request)) == NULL) {
871 talloc_free(lock_ctx);
875 lock_ctx->type = type;
876 lock_ctx->ctdb = ctdb;
877 lock_ctx->ctdb_db = ctdb_db;
878 lock_ctx->key.dsize = key.dsize;
880 lock_ctx->key.dptr = talloc_memdup(lock_ctx, key.dptr, key.dsize);
881 if (lock_ctx->key.dptr == NULL) {
882 DEBUG(DEBUG_ERR, (__location__ "Memory allocation error\n"));
883 talloc_free(lock_ctx);
886 lock_ctx->key_hash = ctdb_hash(&key);
888 lock_ctx->key.dptr = NULL;
890 lock_ctx->priority = priority;
891 lock_ctx->auto_mark = auto_mark;
893 lock_ctx->request = request;
894 lock_ctx->child = -1;
896 /* Non-record locks are required by recovery and should be scheduled
897 * immediately, so keep them at the head of the pending queue.
899 if (lock_ctx->type == LOCK_RECORD) {
900 DLIST_ADD_END(ctdb_db->lock_pending, lock_ctx, NULL);
902 DLIST_ADD_END(ctdb->lock_pending, lock_ctx, NULL);
904 CTDB_INCREMENT_STAT(ctdb, locks.num_pending);
906 CTDB_INCREMENT_DB_STAT(ctdb_db, locks.num_pending);
909 /* Start the timer when we activate the context */
910 lock_ctx->start_time = timeval_current();
912 request->lctx = lock_ctx;
913 request->callback = callback;
914 request->private_data = private_data;
916 talloc_set_destructor(request, ctdb_lock_request_destructor);
918 ctdb_lock_schedule(ctdb);
925 * obtain a lock on a record in a database
927 struct lock_request *ctdb_lock_record(TALLOC_CTX *mem_ctx,
928 struct ctdb_db_context *ctdb_db,
931 void (*callback)(void *, bool),
934 return ctdb_lock_internal(mem_ctx,
947 * obtain a lock on a database
949 struct lock_request *ctdb_lock_db(TALLOC_CTX *mem_ctx,
950 struct ctdb_db_context *ctdb_db,
952 void (*callback)(void *, bool),
955 return ctdb_lock_internal(mem_ctx,
968 * obtain locks on all databases of specified priority
970 struct lock_request *ctdb_lock_alldb_prio(TALLOC_CTX *mem_ctx,
971 struct ctdb_context *ctdb,
974 void (*callback)(void *, bool),
977 if (priority < 1 || priority > NUM_DB_PRIORITIES) {
978 DEBUG(DEBUG_ERR, ("Invalid db priority: %u\n", priority));
982 return ctdb_lock_internal(mem_ctx,
995 * obtain locks on all databases
997 struct lock_request *ctdb_lock_alldb(TALLOC_CTX *mem_ctx,
998 struct ctdb_context *ctdb,
1000 void (*callback)(void *, bool),
1003 return ctdb_lock_internal(mem_ctx,