Lines Matching refs:ls

36 static ssize_t dlm_control_store(struct dlm_ls *ls, const char *buf, size_t len)  in dlm_control_store()  argument
44 ls = dlm_find_lockspace_local(ls->ls_local_handle); in dlm_control_store()
45 if (!ls) in dlm_control_store()
50 dlm_ls_stop(ls); in dlm_control_store()
53 dlm_ls_start(ls); in dlm_control_store()
58 dlm_put_lockspace(ls); in dlm_control_store()
62 static ssize_t dlm_event_store(struct dlm_ls *ls, const char *buf, size_t len) in dlm_event_store() argument
64 int rc = kstrtoint(buf, 0, &ls->ls_uevent_result); in dlm_event_store()
68 set_bit(LSFL_UEVENT_WAIT, &ls->ls_flags); in dlm_event_store()
69 wake_up(&ls->ls_uevent_wait); in dlm_event_store()
73 static ssize_t dlm_id_show(struct dlm_ls *ls, char *buf) in dlm_id_show() argument
75 return snprintf(buf, PAGE_SIZE, "%u\n", ls->ls_global_id); in dlm_id_show()
78 static ssize_t dlm_id_store(struct dlm_ls *ls, const char *buf, size_t len) in dlm_id_store() argument
80 int rc = kstrtouint(buf, 0, &ls->ls_global_id); in dlm_id_store()
87 static ssize_t dlm_nodir_show(struct dlm_ls *ls, char *buf) in dlm_nodir_show() argument
89 return snprintf(buf, PAGE_SIZE, "%u\n", dlm_no_directory(ls)); in dlm_nodir_show()
92 static ssize_t dlm_nodir_store(struct dlm_ls *ls, const char *buf, size_t len) in dlm_nodir_store() argument
100 set_bit(LSFL_NODIR, &ls->ls_flags); in dlm_nodir_store()
104 static ssize_t dlm_recover_status_show(struct dlm_ls *ls, char *buf) in dlm_recover_status_show() argument
106 uint32_t status = dlm_recover_status(ls); in dlm_recover_status_show()
110 static ssize_t dlm_recover_nodeid_show(struct dlm_ls *ls, char *buf) in dlm_recover_nodeid_show() argument
112 return snprintf(buf, PAGE_SIZE, "%d\n", ls->ls_recover_nodeid); in dlm_recover_nodeid_show()
167 struct dlm_ls *ls = container_of(kobj, struct dlm_ls, ls_kobj); in dlm_attr_show() local
169 return a->show ? a->show(ls, buf) : 0; in dlm_attr_show()
175 struct dlm_ls *ls = container_of(kobj, struct dlm_ls, ls_kobj); in dlm_attr_store() local
177 return a->store ? a->store(ls, buf, len) : len; in dlm_attr_store()
182 struct dlm_ls *ls = container_of(k, struct dlm_ls, ls_kobj); in lockspace_kobj_release() local
183 kfree(ls); in lockspace_kobj_release()
199 static int do_uevent(struct dlm_ls *ls, int in) in do_uevent() argument
202 kobject_uevent(&ls->ls_kobj, KOBJ_ONLINE); in do_uevent()
204 kobject_uevent(&ls->ls_kobj, KOBJ_OFFLINE); in do_uevent()
206 log_rinfo(ls, "%s the lockspace group...", in ? "joining" : "leaving"); in do_uevent()
211 wait_event(ls->ls_uevent_wait, in do_uevent()
212 test_and_clear_bit(LSFL_UEVENT_WAIT, &ls->ls_flags)); in do_uevent()
214 log_rinfo(ls, "group event done %d", ls->ls_uevent_result); in do_uevent()
216 return ls->ls_uevent_result; in do_uevent()
221 struct dlm_ls *ls = container_of(kobj, struct dlm_ls, ls_kobj); in dlm_uevent() local
223 add_uevent_var(env, "LOCKSPACE=%s", ls->ls_name); in dlm_uevent()
253 struct dlm_ls *ls; in find_ls_to_scan() local
256 list_for_each_entry(ls, &lslist, ls_list) { in find_ls_to_scan()
257 if (time_after_eq(jiffies, ls->ls_scan_time + in find_ls_to_scan()
260 return ls; in find_ls_to_scan()
269 struct dlm_ls *ls; in dlm_scand() local
272 ls = find_ls_to_scan(); in dlm_scand()
273 if (ls) { in dlm_scand()
274 if (dlm_lock_recovery_try(ls)) { in dlm_scand()
275 ls->ls_scan_time = jiffies; in dlm_scand()
276 dlm_scan_rsbs(ls); in dlm_scand()
277 dlm_scan_timeout(ls); in dlm_scand()
278 dlm_scan_waiters(ls); in dlm_scand()
279 dlm_unlock_recovery(ls); in dlm_scand()
281 ls->ls_scan_time += HZ; in dlm_scand()
310 struct dlm_ls *ls; in dlm_find_lockspace_global() local
314 list_for_each_entry(ls, &lslist, ls_list) { in dlm_find_lockspace_global()
315 if (ls->ls_global_id == id) { in dlm_find_lockspace_global()
316 atomic_inc(&ls->ls_count); in dlm_find_lockspace_global()
320 ls = NULL; in dlm_find_lockspace_global()
323 return ls; in dlm_find_lockspace_global()
328 struct dlm_ls *ls; in dlm_find_lockspace_local() local
331 list_for_each_entry(ls, &lslist, ls_list) { in dlm_find_lockspace_local()
332 if (ls->ls_local_handle == lockspace) { in dlm_find_lockspace_local()
333 atomic_inc(&ls->ls_count); in dlm_find_lockspace_local()
337 ls = NULL; in dlm_find_lockspace_local()
340 return ls; in dlm_find_lockspace_local()
345 struct dlm_ls *ls; in dlm_find_lockspace_device() local
348 list_for_each_entry(ls, &lslist, ls_list) { in dlm_find_lockspace_device()
349 if (ls->ls_device.minor == minor) { in dlm_find_lockspace_device()
350 atomic_inc(&ls->ls_count); in dlm_find_lockspace_device()
354 ls = NULL; in dlm_find_lockspace_device()
357 return ls; in dlm_find_lockspace_device()
360 void dlm_put_lockspace(struct dlm_ls *ls) in dlm_put_lockspace() argument
362 if (atomic_dec_and_test(&ls->ls_count)) in dlm_put_lockspace()
363 wake_up(&ls->ls_count_wait); in dlm_put_lockspace()
366 static void remove_lockspace(struct dlm_ls *ls) in remove_lockspace() argument
369 wait_event(ls->ls_count_wait, atomic_read(&ls->ls_count) == 0); in remove_lockspace()
372 if (atomic_read(&ls->ls_count) != 0) { in remove_lockspace()
377 WARN_ON(ls->ls_create_count != 0); in remove_lockspace()
378 list_del(&ls->ls_list); in remove_lockspace()
412 struct dlm_ls *ls; in new_lockspace() local
455 list_for_each_entry(ls, &lslist, ls_list) { in new_lockspace()
456 WARN_ON(ls->ls_create_count <= 0); in new_lockspace()
457 if (ls->ls_namelen != namelen) in new_lockspace()
459 if (memcmp(ls->ls_name, name, namelen)) in new_lockspace()
465 ls->ls_create_count++; in new_lockspace()
466 *lockspace = ls; in new_lockspace()
477 ls = kzalloc(sizeof(struct dlm_ls) + namelen, GFP_NOFS); in new_lockspace()
478 if (!ls) in new_lockspace()
480 memcpy(ls->ls_name, name, namelen); in new_lockspace()
481 ls->ls_namelen = namelen; in new_lockspace()
482 ls->ls_lvblen = lvblen; in new_lockspace()
483 atomic_set(&ls->ls_count, 0); in new_lockspace()
484 init_waitqueue_head(&ls->ls_count_wait); in new_lockspace()
485 ls->ls_flags = 0; in new_lockspace()
486 ls->ls_scan_time = jiffies; in new_lockspace()
489 ls->ls_ops = ops; in new_lockspace()
490 ls->ls_ops_arg = ops_arg; in new_lockspace()
494 set_bit(LSFL_TIMEWARN, &ls->ls_flags); in new_lockspace()
498 ls->ls_exflags = (flags & ~(DLM_LSFL_TIMEWARN | DLM_LSFL_FS | in new_lockspace()
502 ls->ls_rsbtbl_size = size; in new_lockspace()
504 ls->ls_rsbtbl = vmalloc(array_size(size, sizeof(struct dlm_rsbtable))); in new_lockspace()
505 if (!ls->ls_rsbtbl) in new_lockspace()
508 ls->ls_rsbtbl[i].keep.rb_node = NULL; in new_lockspace()
509 ls->ls_rsbtbl[i].toss.rb_node = NULL; in new_lockspace()
510 spin_lock_init(&ls->ls_rsbtbl[i].lock); in new_lockspace()
513 spin_lock_init(&ls->ls_remove_spin); in new_lockspace()
514 init_waitqueue_head(&ls->ls_remove_wait); in new_lockspace()
517 ls->ls_remove_names[i] = kzalloc(DLM_RESNAME_MAXLEN+1, in new_lockspace()
519 if (!ls->ls_remove_names[i]) in new_lockspace()
523 idr_init(&ls->ls_lkbidr); in new_lockspace()
524 spin_lock_init(&ls->ls_lkbidr_spin); in new_lockspace()
526 INIT_LIST_HEAD(&ls->ls_waiters); in new_lockspace()
527 mutex_init(&ls->ls_waiters_mutex); in new_lockspace()
528 INIT_LIST_HEAD(&ls->ls_orphans); in new_lockspace()
529 mutex_init(&ls->ls_orphans_mutex); in new_lockspace()
530 INIT_LIST_HEAD(&ls->ls_timeout); in new_lockspace()
531 mutex_init(&ls->ls_timeout_mutex); in new_lockspace()
533 INIT_LIST_HEAD(&ls->ls_new_rsb); in new_lockspace()
534 spin_lock_init(&ls->ls_new_rsb_spin); in new_lockspace()
536 INIT_LIST_HEAD(&ls->ls_nodes); in new_lockspace()
537 INIT_LIST_HEAD(&ls->ls_nodes_gone); in new_lockspace()
538 ls->ls_num_nodes = 0; in new_lockspace()
539 ls->ls_low_nodeid = 0; in new_lockspace()
540 ls->ls_total_weight = 0; in new_lockspace()
541 ls->ls_node_array = NULL; in new_lockspace()
543 memset(&ls->ls_stub_rsb, 0, sizeof(struct dlm_rsb)); in new_lockspace()
544 ls->ls_stub_rsb.res_ls = ls; in new_lockspace()
546 ls->ls_debug_rsb_dentry = NULL; in new_lockspace()
547 ls->ls_debug_waiters_dentry = NULL; in new_lockspace()
549 init_waitqueue_head(&ls->ls_uevent_wait); in new_lockspace()
550 ls->ls_uevent_result = 0; in new_lockspace()
551 init_completion(&ls->ls_members_done); in new_lockspace()
552 ls->ls_members_result = -1; in new_lockspace()
554 mutex_init(&ls->ls_cb_mutex); in new_lockspace()
555 INIT_LIST_HEAD(&ls->ls_cb_delay); in new_lockspace()
557 ls->ls_recoverd_task = NULL; in new_lockspace()
558 mutex_init(&ls->ls_recoverd_active); in new_lockspace()
559 spin_lock_init(&ls->ls_recover_lock); in new_lockspace()
560 spin_lock_init(&ls->ls_rcom_spin); in new_lockspace()
561 get_random_bytes(&ls->ls_rcom_seq, sizeof(uint64_t)); in new_lockspace()
562 ls->ls_recover_status = 0; in new_lockspace()
563 ls->ls_recover_seq = 0; in new_lockspace()
564 ls->ls_recover_args = NULL; in new_lockspace()
565 init_rwsem(&ls->ls_in_recovery); in new_lockspace()
566 init_rwsem(&ls->ls_recv_active); in new_lockspace()
567 INIT_LIST_HEAD(&ls->ls_requestqueue); in new_lockspace()
568 atomic_set(&ls->ls_requestqueue_cnt, 0); in new_lockspace()
569 init_waitqueue_head(&ls->ls_requestqueue_wait); in new_lockspace()
570 mutex_init(&ls->ls_requestqueue_mutex); in new_lockspace()
571 mutex_init(&ls->ls_clear_proc_locks); in new_lockspace()
578 ls->ls_recover_buf = kmalloc(DLM_MAX_SOCKET_BUFSIZE, GFP_NOFS); in new_lockspace()
579 if (!ls->ls_recover_buf) in new_lockspace()
582 ls->ls_slot = 0; in new_lockspace()
583 ls->ls_num_slots = 0; in new_lockspace()
584 ls->ls_slots_size = 0; in new_lockspace()
585 ls->ls_slots = NULL; in new_lockspace()
587 INIT_LIST_HEAD(&ls->ls_recover_list); in new_lockspace()
588 spin_lock_init(&ls->ls_recover_list_lock); in new_lockspace()
589 idr_init(&ls->ls_recover_idr); in new_lockspace()
590 spin_lock_init(&ls->ls_recover_idr_lock); in new_lockspace()
591 ls->ls_recover_list_count = 0; in new_lockspace()
592 ls->ls_local_handle = ls; in new_lockspace()
593 init_waitqueue_head(&ls->ls_wait_general); in new_lockspace()
594 INIT_LIST_HEAD(&ls->ls_root_list); in new_lockspace()
595 init_rwsem(&ls->ls_root_sem); in new_lockspace()
598 ls->ls_create_count = 1; in new_lockspace()
599 list_add(&ls->ls_list, &lslist); in new_lockspace()
603 error = dlm_callback_start(ls); in new_lockspace()
605 log_error(ls, "can't start dlm_callback %d", error); in new_lockspace()
610 init_waitqueue_head(&ls->ls_recover_lock_wait); in new_lockspace()
619 error = dlm_recoverd_start(ls); in new_lockspace()
621 log_error(ls, "can't start dlm_recoverd %d", error); in new_lockspace()
625 wait_event(ls->ls_recover_lock_wait, in new_lockspace()
626 test_bit(LSFL_RECOVER_LOCK, &ls->ls_flags)); in new_lockspace()
631 ls->ls_kobj.kset = dlm_kset; in new_lockspace()
632 error = kobject_init_and_add(&ls->ls_kobj, &dlm_ktype, NULL, in new_lockspace()
633 "%s", ls->ls_name); in new_lockspace()
636 kobject_uevent(&ls->ls_kobj, KOBJ_ADD); in new_lockspace()
644 error = do_uevent(ls, 1); in new_lockspace()
648 wait_for_completion(&ls->ls_members_done); in new_lockspace()
649 error = ls->ls_members_result; in new_lockspace()
653 dlm_create_debug_file(ls); in new_lockspace()
655 log_rinfo(ls, "join complete"); in new_lockspace()
656 *lockspace = ls; in new_lockspace()
660 do_uevent(ls, 0); in new_lockspace()
661 dlm_clear_members(ls); in new_lockspace()
662 kfree(ls->ls_node_array); in new_lockspace()
664 dlm_recoverd_stop(ls); in new_lockspace()
666 dlm_callback_stop(ls); in new_lockspace()
669 list_del(&ls->ls_list); in new_lockspace()
671 idr_destroy(&ls->ls_recover_idr); in new_lockspace()
672 kfree(ls->ls_recover_buf); in new_lockspace()
674 idr_destroy(&ls->ls_lkbidr); in new_lockspace()
677 kfree(ls->ls_remove_names[i]); in new_lockspace()
678 vfree(ls->ls_rsbtbl); in new_lockspace()
681 kobject_put(&ls->ls_kobj); in new_lockspace()
683 kfree(ls); in new_lockspace()
745 static int lockspace_busy(struct dlm_ls *ls, int force) in lockspace_busy() argument
749 spin_lock(&ls->ls_lkbidr_spin); in lockspace_busy()
751 rv = idr_for_each(&ls->ls_lkbidr, lkb_idr_is_any, ls); in lockspace_busy()
753 rv = idr_for_each(&ls->ls_lkbidr, lkb_idr_is_local, ls); in lockspace_busy()
757 spin_unlock(&ls->ls_lkbidr_spin); in lockspace_busy()
761 static int release_lockspace(struct dlm_ls *ls, int force) in release_lockspace() argument
767 busy = lockspace_busy(ls, force); in release_lockspace()
770 if (ls->ls_create_count == 1) { in release_lockspace()
775 ls->ls_create_count = 0; in release_lockspace()
778 } else if (ls->ls_create_count > 1) { in release_lockspace()
779 rv = --ls->ls_create_count; in release_lockspace()
786 log_debug(ls, "release_lockspace no remove %d", rv); in release_lockspace()
790 dlm_device_deregister(ls); in release_lockspace()
793 do_uevent(ls, 0); in release_lockspace()
795 dlm_recoverd_stop(ls); in release_lockspace()
799 dlm_clear_members(ls); in release_lockspace()
803 dlm_callback_stop(ls); in release_lockspace()
805 remove_lockspace(ls); in release_lockspace()
807 dlm_delete_debug_file(ls); in release_lockspace()
809 idr_destroy(&ls->ls_recover_idr); in release_lockspace()
810 kfree(ls->ls_recover_buf); in release_lockspace()
816 idr_for_each(&ls->ls_lkbidr, lkb_idr_free, ls); in release_lockspace()
817 idr_destroy(&ls->ls_lkbidr); in release_lockspace()
823 for (i = 0; i < ls->ls_rsbtbl_size; i++) { in release_lockspace()
824 while ((n = rb_first(&ls->ls_rsbtbl[i].keep))) { in release_lockspace()
826 rb_erase(n, &ls->ls_rsbtbl[i].keep); in release_lockspace()
830 while ((n = rb_first(&ls->ls_rsbtbl[i].toss))) { in release_lockspace()
832 rb_erase(n, &ls->ls_rsbtbl[i].toss); in release_lockspace()
837 vfree(ls->ls_rsbtbl); in release_lockspace()
840 kfree(ls->ls_remove_names[i]); in release_lockspace()
842 while (!list_empty(&ls->ls_new_rsb)) { in release_lockspace()
843 rsb = list_first_entry(&ls->ls_new_rsb, struct dlm_rsb, in release_lockspace()
853 dlm_purge_requestqueue(ls); in release_lockspace()
854 kfree(ls->ls_recover_args); in release_lockspace()
855 dlm_clear_members(ls); in release_lockspace()
856 dlm_clear_members_gone(ls); in release_lockspace()
857 kfree(ls->ls_node_array); in release_lockspace()
858 log_rinfo(ls, "release_lockspace final free"); in release_lockspace()
859 kobject_put(&ls->ls_kobj); in release_lockspace()
882 struct dlm_ls *ls; in dlm_release_lockspace() local
885 ls = dlm_find_lockspace_local(lockspace); in dlm_release_lockspace()
886 if (!ls) in dlm_release_lockspace()
888 dlm_put_lockspace(ls); in dlm_release_lockspace()
891 error = release_lockspace(ls, force); in dlm_release_lockspace()
903 struct dlm_ls *ls; in dlm_stop_lockspaces() local
909 list_for_each_entry(ls, &lslist, ls_list) { in dlm_stop_lockspaces()
910 if (!test_bit(LSFL_RUNNING, &ls->ls_flags)) { in dlm_stop_lockspaces()
915 log_error(ls, "no userland control daemon, stopping lockspace"); in dlm_stop_lockspaces()
916 dlm_ls_stop(ls); in dlm_stop_lockspaces()
927 struct dlm_ls *ls; in dlm_stop_lockspaces_check() local
930 list_for_each_entry(ls, &lslist, ls_list) { in dlm_stop_lockspaces_check()
931 if (WARN_ON(!rwsem_is_locked(&ls->ls_in_recovery) || in dlm_stop_lockspaces_check()
932 !dlm_locking_stopped(ls))) in dlm_stop_lockspaces_check()