Lines Matching refs:gl

57 	struct gfs2_glock *gl;		/* current glock struct        */  member
61 typedef void (*glock_examiner) (struct gfs2_glock * gl);
63 static void do_xmote(struct gfs2_glock *gl, struct gfs2_holder *gh, unsigned int target);
119 static void wake_up_glock(struct gfs2_glock *gl) in wake_up_glock() argument
121 wait_queue_head_t *wq = glock_waitqueue(&gl->gl_name); in wake_up_glock()
124 __wake_up(wq, TASK_NORMAL, 1, &gl->gl_name); in wake_up_glock()
129 struct gfs2_glock *gl = container_of(rcu, struct gfs2_glock, gl_rcu); in gfs2_glock_dealloc() local
131 if (gl->gl_ops->go_flags & GLOF_ASPACE) { in gfs2_glock_dealloc()
132 kmem_cache_free(gfs2_glock_aspace_cachep, gl); in gfs2_glock_dealloc()
134 kfree(gl->gl_lksb.sb_lvbptr); in gfs2_glock_dealloc()
135 kmem_cache_free(gfs2_glock_cachep, gl); in gfs2_glock_dealloc()
139 void gfs2_glock_free(struct gfs2_glock *gl) in gfs2_glock_free() argument
141 struct gfs2_sbd *sdp = gl->gl_name.ln_sbd; in gfs2_glock_free()
143 rhashtable_remove_fast(&gl_hash_table, &gl->gl_node, ht_parms); in gfs2_glock_free()
145 wake_up_glock(gl); in gfs2_glock_free()
146 call_rcu(&gl->gl_rcu, gfs2_glock_dealloc); in gfs2_glock_free()
157 void gfs2_glock_hold(struct gfs2_glock *gl) in gfs2_glock_hold() argument
159 GLOCK_BUG_ON(gl, __lockref_is_dead(&gl->gl_lockref)); in gfs2_glock_hold()
160 lockref_get(&gl->gl_lockref); in gfs2_glock_hold()
170 static int demote_ok(const struct gfs2_glock *gl) in demote_ok() argument
172 const struct gfs2_glock_operations *glops = gl->gl_ops; in demote_ok()
174 if (gl->gl_state == LM_ST_UNLOCKED) in demote_ok()
176 if (!list_empty(&gl->gl_holders)) in demote_ok()
179 return glops->go_demote_ok(gl); in demote_ok()
184 void gfs2_glock_add_to_lru(struct gfs2_glock *gl) in gfs2_glock_add_to_lru() argument
188 if (!list_empty(&gl->gl_lru)) in gfs2_glock_add_to_lru()
189 list_del_init(&gl->gl_lru); in gfs2_glock_add_to_lru()
193 list_add_tail(&gl->gl_lru, &lru_list); in gfs2_glock_add_to_lru()
194 set_bit(GLF_LRU, &gl->gl_flags); in gfs2_glock_add_to_lru()
198 static void gfs2_glock_remove_from_lru(struct gfs2_glock *gl) in gfs2_glock_remove_from_lru() argument
200 if (!(gl->gl_ops->go_flags & GLOF_LRU)) in gfs2_glock_remove_from_lru()
204 if (!list_empty(&gl->gl_lru)) { in gfs2_glock_remove_from_lru()
205 list_del_init(&gl->gl_lru); in gfs2_glock_remove_from_lru()
207 clear_bit(GLF_LRU, &gl->gl_flags); in gfs2_glock_remove_from_lru()
216 static void __gfs2_glock_queue_work(struct gfs2_glock *gl, unsigned long delay) { in __gfs2_glock_queue_work() argument
217 if (!queue_delayed_work(glock_workqueue, &gl->gl_work, delay)) { in __gfs2_glock_queue_work()
224 GLOCK_BUG_ON(gl, gl->gl_lockref.count < 2); in __gfs2_glock_queue_work()
225 gl->gl_lockref.count--; in __gfs2_glock_queue_work()
229 static void gfs2_glock_queue_work(struct gfs2_glock *gl, unsigned long delay) { in gfs2_glock_queue_work() argument
230 spin_lock(&gl->gl_lockref.lock); in gfs2_glock_queue_work()
231 __gfs2_glock_queue_work(gl, delay); in gfs2_glock_queue_work()
232 spin_unlock(&gl->gl_lockref.lock); in gfs2_glock_queue_work()
235 static void __gfs2_glock_put(struct gfs2_glock *gl) in __gfs2_glock_put() argument
237 struct gfs2_sbd *sdp = gl->gl_name.ln_sbd; in __gfs2_glock_put()
238 struct address_space *mapping = gfs2_glock2aspace(gl); in __gfs2_glock_put()
240 lockref_mark_dead(&gl->gl_lockref); in __gfs2_glock_put()
242 gfs2_glock_remove_from_lru(gl); in __gfs2_glock_put()
243 spin_unlock(&gl->gl_lockref.lock); in __gfs2_glock_put()
244 GLOCK_BUG_ON(gl, !list_empty(&gl->gl_holders)); in __gfs2_glock_put()
245 GLOCK_BUG_ON(gl, mapping && mapping->nrpages); in __gfs2_glock_put()
246 trace_gfs2_glock_put(gl); in __gfs2_glock_put()
247 sdp->sd_lockstruct.ls_ops->lm_put_lock(gl); in __gfs2_glock_put()
253 void gfs2_glock_queue_put(struct gfs2_glock *gl) in gfs2_glock_queue_put() argument
255 gfs2_glock_queue_work(gl, 0); in gfs2_glock_queue_put()
264 void gfs2_glock_put(struct gfs2_glock *gl) in gfs2_glock_put() argument
266 if (lockref_put_or_lock(&gl->gl_lockref)) in gfs2_glock_put()
269 __gfs2_glock_put(gl); in gfs2_glock_put()
280 static inline int may_grant(const struct gfs2_glock *gl, const struct gfs2_holder *gh) in may_grant() argument
282 …const struct gfs2_holder *gh_head = list_entry(gl->gl_holders.next, const struct gfs2_holder, gh_l… in may_grant()
286 if (gl->gl_state == gh->gh_state) in may_grant()
290 if (gl->gl_state == LM_ST_EXCLUSIVE) { in may_grant()
296 if (gl->gl_state != LM_ST_UNLOCKED && (gh->gh_flags & LM_FLAG_ANY)) in may_grant()
313 static void do_error(struct gfs2_glock *gl, const int ret) in do_error() argument
317 list_for_each_entry_safe(gh, tmp, &gl->gl_holders, gh_list) { in do_error()
340 static int do_promote(struct gfs2_glock *gl) in do_promote() argument
341 __releases(&gl->gl_lockref.lock) in do_promote()
342 __acquires(&gl->gl_lockref.lock) in do_promote()
344 const struct gfs2_glock_operations *glops = gl->gl_ops; in do_promote()
349 list_for_each_entry_safe(gh, tmp, &gl->gl_holders, gh_list) { in do_promote()
352 if (may_grant(gl, gh)) { in do_promote()
353 if (gh->gh_list.prev == &gl->gl_holders && in do_promote()
355 spin_unlock(&gl->gl_lockref.lock); in do_promote()
358 spin_lock(&gl->gl_lockref.lock); in do_promote()
378 if (gh->gh_list.prev == &gl->gl_holders) in do_promote()
380 do_error(gl, 0); in do_promote()
391 static inline struct gfs2_holder *find_first_waiter(const struct gfs2_glock *gl) in find_first_waiter() argument
395 list_for_each_entry(gh, &gl->gl_holders, gh_list) { in find_first_waiter()
409 static void state_change(struct gfs2_glock *gl, unsigned int new_state) in state_change() argument
413 held1 = (gl->gl_state != LM_ST_UNLOCKED); in state_change()
417 GLOCK_BUG_ON(gl, __lockref_is_dead(&gl->gl_lockref)); in state_change()
419 gl->gl_lockref.count++; in state_change()
421 gl->gl_lockref.count--; in state_change()
423 if (held1 && held2 && list_empty(&gl->gl_holders)) in state_change()
424 clear_bit(GLF_QUEUED, &gl->gl_flags); in state_change()
426 if (new_state != gl->gl_target) in state_change()
428 gl->gl_hold_time = max(gl->gl_hold_time - GL_GLOCK_HOLD_DECR, in state_change()
430 gl->gl_state = new_state; in state_change()
431 gl->gl_tchange = jiffies; in state_change()
434 static void gfs2_demote_wake(struct gfs2_glock *gl) in gfs2_demote_wake() argument
436 gl->gl_demote_state = LM_ST_EXCLUSIVE; in gfs2_demote_wake()
437 clear_bit(GLF_DEMOTE, &gl->gl_flags); in gfs2_demote_wake()
439 wake_up_bit(&gl->gl_flags, GLF_DEMOTE); in gfs2_demote_wake()
449 static void finish_xmote(struct gfs2_glock *gl, unsigned int ret) in finish_xmote() argument
451 const struct gfs2_glock_operations *glops = gl->gl_ops; in finish_xmote()
456 spin_lock(&gl->gl_lockref.lock); in finish_xmote()
457 trace_gfs2_glock_state_change(gl, state); in finish_xmote()
458 state_change(gl, state); in finish_xmote()
459 gh = find_first_waiter(gl); in finish_xmote()
462 if (test_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags) && in finish_xmote()
463 state != LM_ST_UNLOCKED && gl->gl_demote_state == LM_ST_UNLOCKED) in finish_xmote()
464 gl->gl_target = LM_ST_UNLOCKED; in finish_xmote()
467 if (unlikely(state != gl->gl_target)) { in finish_xmote()
468 if (gh && !test_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags)) { in finish_xmote()
472 list_move_tail(&gh->gh_list, &gl->gl_holders); in finish_xmote()
473 gh = find_first_waiter(gl); in finish_xmote()
474 gl->gl_target = gh->gh_state; in finish_xmote()
480 gl->gl_target = gl->gl_state; in finish_xmote()
481 do_error(gl, ret); in finish_xmote()
489 do_xmote(gl, gh, gl->gl_target); in finish_xmote()
494 do_xmote(gl, gh, LM_ST_UNLOCKED); in finish_xmote()
497 pr_err("wanted %u got %u\n", gl->gl_target, state); in finish_xmote()
498 GLOCK_BUG_ON(gl, 1); in finish_xmote()
500 spin_unlock(&gl->gl_lockref.lock); in finish_xmote()
505 if (test_and_clear_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags)) in finish_xmote()
506 gfs2_demote_wake(gl); in finish_xmote()
509 spin_unlock(&gl->gl_lockref.lock); in finish_xmote()
510 rv = glops->go_xmote_bh(gl, gh); in finish_xmote()
511 spin_lock(&gl->gl_lockref.lock); in finish_xmote()
513 do_error(gl, rv); in finish_xmote()
517 rv = do_promote(gl); in finish_xmote()
522 clear_bit(GLF_LOCK, &gl->gl_flags); in finish_xmote()
524 spin_unlock(&gl->gl_lockref.lock); in finish_xmote()
535 static void do_xmote(struct gfs2_glock *gl, struct gfs2_holder *gh, unsigned int target) in do_xmote() argument
536 __releases(&gl->gl_lockref.lock) in do_xmote()
537 __acquires(&gl->gl_lockref.lock) in do_xmote()
539 const struct gfs2_glock_operations *glops = gl->gl_ops; in do_xmote()
540 struct gfs2_sbd *sdp = gl->gl_name.ln_sbd; in do_xmote()
549 GLOCK_BUG_ON(gl, gl->gl_state == target); in do_xmote()
550 GLOCK_BUG_ON(gl, gl->gl_state == gl->gl_target); in do_xmote()
553 set_bit(GLF_INVALIDATE_IN_PROGRESS, &gl->gl_flags); in do_xmote()
554 do_error(gl, 0); /* Fail queued try locks */ in do_xmote()
556 gl->gl_req = target; in do_xmote()
557 set_bit(GLF_BLOCKING, &gl->gl_flags); in do_xmote()
558 if ((gl->gl_req == LM_ST_UNLOCKED) || in do_xmote()
559 (gl->gl_state == LM_ST_EXCLUSIVE) || in do_xmote()
561 clear_bit(GLF_BLOCKING, &gl->gl_flags); in do_xmote()
562 spin_unlock(&gl->gl_lockref.lock); in do_xmote()
564 glops->go_sync(gl); in do_xmote()
565 if (test_bit(GLF_INVALIDATE_IN_PROGRESS, &gl->gl_flags)) in do_xmote()
566 glops->go_inval(gl, target == LM_ST_DEFERRED ? 0 : DIO_METADATA); in do_xmote()
567 clear_bit(GLF_INVALIDATE_IN_PROGRESS, &gl->gl_flags); in do_xmote()
569 gfs2_glock_hold(gl); in do_xmote()
572 ret = sdp->sd_lockstruct.ls_ops->lm_lock(gl, target, lck_flags); in do_xmote()
573 if (ret == -EINVAL && gl->gl_target == LM_ST_UNLOCKED && in do_xmote()
576 finish_xmote(gl, target); in do_xmote()
577 gfs2_glock_queue_work(gl, 0); in do_xmote()
581 GLOCK_BUG_ON(gl, !test_bit(SDF_SHUTDOWN, in do_xmote()
585 finish_xmote(gl, target); in do_xmote()
586 gfs2_glock_queue_work(gl, 0); in do_xmote()
589 spin_lock(&gl->gl_lockref.lock); in do_xmote()
597 static inline struct gfs2_holder *find_first_holder(const struct gfs2_glock *gl) in find_first_holder() argument
601 if (!list_empty(&gl->gl_holders)) { in find_first_holder()
602 gh = list_entry(gl->gl_holders.next, struct gfs2_holder, gh_list); in find_first_holder()
616 static void run_queue(struct gfs2_glock *gl, const int nonblock) in run_queue() argument
617 __releases(&gl->gl_lockref.lock) in run_queue()
618 __acquires(&gl->gl_lockref.lock) in run_queue()
623 if (test_and_set_bit(GLF_LOCK, &gl->gl_flags)) in run_queue()
626 GLOCK_BUG_ON(gl, test_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags)); in run_queue()
628 if (test_bit(GLF_DEMOTE, &gl->gl_flags) && in run_queue()
629 gl->gl_demote_state != gl->gl_state) { in run_queue()
630 if (find_first_holder(gl)) in run_queue()
634 set_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags); in run_queue()
635 GLOCK_BUG_ON(gl, gl->gl_demote_state == LM_ST_EXCLUSIVE); in run_queue()
636 gl->gl_target = gl->gl_demote_state; in run_queue()
638 if (test_bit(GLF_DEMOTE, &gl->gl_flags)) in run_queue()
639 gfs2_demote_wake(gl); in run_queue()
640 ret = do_promote(gl); in run_queue()
645 gh = find_first_waiter(gl); in run_queue()
646 gl->gl_target = gh->gh_state; in run_queue()
648 do_error(gl, 0); /* Fail queued try locks */ in run_queue()
650 do_xmote(gl, gh, gl->gl_target); in run_queue()
655 clear_bit(GLF_LOCK, &gl->gl_flags); in run_queue()
657 gl->gl_lockref.count++; in run_queue()
658 __gfs2_glock_queue_work(gl, 0); in run_queue()
662 clear_bit(GLF_LOCK, &gl->gl_flags); in run_queue()
669 struct gfs2_glock *gl = container_of(work, struct gfs2_glock, gl_delete); in delete_work_func() local
670 struct gfs2_sbd *sdp = gl->gl_name.ln_sbd; in delete_work_func()
672 u64 no_addr = gl->gl_name.ln_number; in delete_work_func()
677 if (test_bit(GLF_INODE_CREATING, &gl->gl_flags)) in delete_work_func()
686 gfs2_glock_put(gl); in delete_work_func()
692 struct gfs2_glock *gl = container_of(work, struct gfs2_glock, gl_work.work); in glock_work_func() local
695 if (test_and_clear_bit(GLF_REPLY_PENDING, &gl->gl_flags)) { in glock_work_func()
696 finish_xmote(gl, gl->gl_reply); in glock_work_func()
699 spin_lock(&gl->gl_lockref.lock); in glock_work_func()
700 if (test_bit(GLF_PENDING_DEMOTE, &gl->gl_flags) && in glock_work_func()
701 gl->gl_state != LM_ST_UNLOCKED && in glock_work_func()
702 gl->gl_demote_state != LM_ST_EXCLUSIVE) { in glock_work_func()
705 holdtime = gl->gl_tchange + gl->gl_hold_time; in glock_work_func()
710 clear_bit(GLF_PENDING_DEMOTE, &gl->gl_flags); in glock_work_func()
711 set_bit(GLF_DEMOTE, &gl->gl_flags); in glock_work_func()
714 run_queue(gl, 0); in glock_work_func()
718 if (gl->gl_name.ln_type != LM_TYPE_INODE) in glock_work_func()
720 __gfs2_glock_queue_work(gl, delay); in glock_work_func()
728 gl->gl_lockref.count -= drop_refs; in glock_work_func()
729 if (!gl->gl_lockref.count) { in glock_work_func()
730 __gfs2_glock_put(gl); in glock_work_func()
733 spin_unlock(&gl->gl_lockref.lock); in glock_work_func()
741 struct gfs2_glock *gl; in find_insert_glock() local
751 gl = rhashtable_lookup_get_insert_fast(&gl_hash_table, in find_insert_glock()
753 if (IS_ERR(gl)) in find_insert_glock()
756 gl = rhashtable_lookup_fast(&gl_hash_table, in find_insert_glock()
759 if (gl && !lockref_get_not_dead(&gl->gl_lockref)) { in find_insert_glock()
767 return gl; in find_insert_glock()
791 struct gfs2_glock *gl, *tmp; in gfs2_glock_get() local
796 gl = find_insert_glock(&name, NULL); in gfs2_glock_get()
797 if (gl) { in gfs2_glock_get()
798 *glp = gl; in gfs2_glock_get()
808 gl = kmem_cache_alloc(cachep, GFP_NOFS); in gfs2_glock_get()
809 if (!gl) in gfs2_glock_get()
812 memset(&gl->gl_lksb, 0, sizeof(struct dlm_lksb)); in gfs2_glock_get()
815 gl->gl_lksb.sb_lvbptr = kzalloc(GFS2_MIN_LVB_SIZE, GFP_NOFS); in gfs2_glock_get()
816 if (!gl->gl_lksb.sb_lvbptr) { in gfs2_glock_get()
817 kmem_cache_free(cachep, gl); in gfs2_glock_get()
823 gl->gl_node.next = NULL; in gfs2_glock_get()
824 gl->gl_flags = 0; in gfs2_glock_get()
825 gl->gl_name = name; in gfs2_glock_get()
826 gl->gl_lockref.count = 1; in gfs2_glock_get()
827 gl->gl_state = LM_ST_UNLOCKED; in gfs2_glock_get()
828 gl->gl_target = LM_ST_UNLOCKED; in gfs2_glock_get()
829 gl->gl_demote_state = LM_ST_EXCLUSIVE; in gfs2_glock_get()
830 gl->gl_ops = glops; in gfs2_glock_get()
831 gl->gl_dstamp = 0; in gfs2_glock_get()
834 gl->gl_stats = this_cpu_ptr(sdp->sd_lkstats)->lkstats[glops->go_type]; in gfs2_glock_get()
836 gl->gl_stats.stats[GFS2_LKS_DCOUNT] = 0; in gfs2_glock_get()
837 gl->gl_stats.stats[GFS2_LKS_QCOUNT] = 0; in gfs2_glock_get()
838 gl->gl_tchange = jiffies; in gfs2_glock_get()
839 gl->gl_object = NULL; in gfs2_glock_get()
840 gl->gl_hold_time = GL_GLOCK_DFT_HOLD; in gfs2_glock_get()
841 INIT_DELAYED_WORK(&gl->gl_work, glock_work_func); in gfs2_glock_get()
842 INIT_WORK(&gl->gl_delete, delete_work_func); in gfs2_glock_get()
844 mapping = gfs2_glock2aspace(gl); in gfs2_glock_get()
854 tmp = find_insert_glock(&name, gl); in gfs2_glock_get()
856 *glp = gl; in gfs2_glock_get()
866 kfree(gl->gl_lksb.sb_lvbptr); in gfs2_glock_get()
867 kmem_cache_free(cachep, gl); in gfs2_glock_get()
883 void gfs2_holder_init(struct gfs2_glock *gl, unsigned int state, u16 flags, in gfs2_holder_init() argument
887 gh->gh_gl = gl; in gfs2_holder_init()
894 gfs2_glock_hold(gl); in gfs2_holder_init()
961 static void handle_callback(struct gfs2_glock *gl, unsigned int state, in handle_callback() argument
966 set_bit(bit, &gl->gl_flags); in handle_callback()
967 if (gl->gl_demote_state == LM_ST_EXCLUSIVE) { in handle_callback()
968 gl->gl_demote_state = state; in handle_callback()
969 gl->gl_demote_time = jiffies; in handle_callback()
970 } else if (gl->gl_demote_state != LM_ST_UNLOCKED && in handle_callback()
971 gl->gl_demote_state != state) { in handle_callback()
972 gl->gl_demote_state = LM_ST_UNLOCKED; in handle_callback()
974 if (gl->gl_ops->go_callback) in handle_callback()
975 gl->gl_ops->go_callback(gl, remote); in handle_callback()
976 trace_gfs2_demote_rq(gl, remote); in handle_callback()
1009 __releases(&gl->gl_lockref.lock) in add_to_queue()
1010 __acquires(&gl->gl_lockref.lock) in add_to_queue()
1012 struct gfs2_glock *gl = gh->gh_gl; in add_to_queue() local
1013 struct gfs2_sbd *sdp = gl->gl_name.ln_sbd; in add_to_queue()
1023 if (test_bit(GLF_LOCK, &gl->gl_flags)) in add_to_queue()
1024 try_futile = !may_grant(gl, gh); in add_to_queue()
1025 if (test_bit(GLF_INVALIDATE_IN_PROGRESS, &gl->gl_flags)) in add_to_queue()
1029 list_for_each_entry(gh2, &gl->gl_holders, gh_list) { in add_to_queue()
1045 set_bit(GLF_QUEUED, &gl->gl_flags); in add_to_queue()
1047 gfs2_glstats_inc(gl, GFS2_LKS_QCOUNT); in add_to_queue()
1048 gfs2_sbstats_inc(gl, GFS2_LKS_QCOUNT); in add_to_queue()
1050 list_add_tail(&gh->gh_list, &gl->gl_holders); in add_to_queue()
1057 gh = list_entry(gl->gl_holders.next, struct gfs2_holder, gh_list); in add_to_queue()
1059 spin_unlock(&gl->gl_lockref.lock); in add_to_queue()
1061 sdp->sd_lockstruct.ls_ops->lm_cancel(gl); in add_to_queue()
1062 spin_lock(&gl->gl_lockref.lock); in add_to_queue()
1075 gfs2_dump_glock(NULL, gl); in add_to_queue()
1090 struct gfs2_glock *gl = gh->gh_gl; in gfs2_glock_nq() local
1091 struct gfs2_sbd *sdp = gl->gl_name.ln_sbd; in gfs2_glock_nq()
1097 if (test_bit(GLF_LRU, &gl->gl_flags)) in gfs2_glock_nq()
1098 gfs2_glock_remove_from_lru(gl); in gfs2_glock_nq()
1100 spin_lock(&gl->gl_lockref.lock); in gfs2_glock_nq()
1103 test_and_clear_bit(GLF_FROZEN, &gl->gl_flags))) { in gfs2_glock_nq()
1104 set_bit(GLF_REPLY_PENDING, &gl->gl_flags); in gfs2_glock_nq()
1105 gl->gl_lockref.count++; in gfs2_glock_nq()
1106 __gfs2_glock_queue_work(gl, 0); in gfs2_glock_nq()
1108 run_queue(gl, 1); in gfs2_glock_nq()
1109 spin_unlock(&gl->gl_lockref.lock); in gfs2_glock_nq()
1137 struct gfs2_glock *gl = gh->gh_gl; in gfs2_glock_dq() local
1138 const struct gfs2_glock_operations *glops = gl->gl_ops; in gfs2_glock_dq()
1142 spin_lock(&gl->gl_lockref.lock); in gfs2_glock_dq()
1144 handle_callback(gl, LM_ST_UNLOCKED, 0, false); in gfs2_glock_dq()
1148 if (find_first_holder(gl) == NULL) { in gfs2_glock_dq()
1150 GLOCK_BUG_ON(gl, test_and_set_bit(GLF_LOCK, &gl->gl_flags)); in gfs2_glock_dq()
1151 spin_unlock(&gl->gl_lockref.lock); in gfs2_glock_dq()
1153 spin_lock(&gl->gl_lockref.lock); in gfs2_glock_dq()
1154 clear_bit(GLF_LOCK, &gl->gl_flags); in gfs2_glock_dq()
1156 if (list_empty(&gl->gl_holders) && in gfs2_glock_dq()
1157 !test_bit(GLF_PENDING_DEMOTE, &gl->gl_flags) && in gfs2_glock_dq()
1158 !test_bit(GLF_DEMOTE, &gl->gl_flags)) in gfs2_glock_dq()
1161 if (!test_bit(GLF_LFLUSH, &gl->gl_flags) && demote_ok(gl) && in gfs2_glock_dq()
1163 gfs2_glock_add_to_lru(gl); in gfs2_glock_dq()
1167 gl->gl_lockref.count++; in gfs2_glock_dq()
1168 if (test_bit(GLF_PENDING_DEMOTE, &gl->gl_flags) && in gfs2_glock_dq()
1169 !test_bit(GLF_DEMOTE, &gl->gl_flags) && in gfs2_glock_dq()
1170 gl->gl_name.ln_type == LM_TYPE_INODE) in gfs2_glock_dq()
1171 delay = gl->gl_hold_time; in gfs2_glock_dq()
1172 __gfs2_glock_queue_work(gl, delay); in gfs2_glock_dq()
1174 spin_unlock(&gl->gl_lockref.lock); in gfs2_glock_dq()
1179 struct gfs2_glock *gl = gh->gh_gl; in gfs2_glock_dq_wait() local
1182 wait_on_bit(&gl->gl_flags, GLF_DEMOTE, TASK_UNINTERRUPTIBLE); in gfs2_glock_dq_wait()
1213 struct gfs2_glock *gl; in gfs2_glock_nq_num() local
1216 error = gfs2_glock_get(sdp, number, glops, CREATE, &gl); in gfs2_glock_nq_num()
1218 error = gfs2_glock_nq_init(gl, state, flags, gh); in gfs2_glock_nq_num()
1219 gfs2_glock_put(gl); in gfs2_glock_nq_num()
1333 void gfs2_glock_cb(struct gfs2_glock *gl, unsigned int state) in gfs2_glock_cb() argument
1339 gfs2_glock_hold(gl); in gfs2_glock_cb()
1340 holdtime = gl->gl_tchange + gl->gl_hold_time; in gfs2_glock_cb()
1341 if (test_bit(GLF_QUEUED, &gl->gl_flags) && in gfs2_glock_cb()
1342 gl->gl_name.ln_type == LM_TYPE_INODE) { in gfs2_glock_cb()
1345 if (test_bit(GLF_REPLY_PENDING, &gl->gl_flags)) in gfs2_glock_cb()
1346 delay = gl->gl_hold_time; in gfs2_glock_cb()
1349 spin_lock(&gl->gl_lockref.lock); in gfs2_glock_cb()
1350 handle_callback(gl, state, delay, true); in gfs2_glock_cb()
1351 __gfs2_glock_queue_work(gl, delay); in gfs2_glock_cb()
1352 spin_unlock(&gl->gl_lockref.lock); in gfs2_glock_cb()
1366 static int gfs2_should_freeze(const struct gfs2_glock *gl) in gfs2_should_freeze() argument
1370 if (gl->gl_reply & ~LM_OUT_ST_MASK) in gfs2_should_freeze()
1372 if (gl->gl_target == LM_ST_UNLOCKED) in gfs2_should_freeze()
1375 list_for_each_entry(gh, &gl->gl_holders, gh_list) { in gfs2_should_freeze()
1394 void gfs2_glock_complete(struct gfs2_glock *gl, int ret) in gfs2_glock_complete() argument
1396 struct lm_lockstruct *ls = &gl->gl_name.ln_sbd->sd_lockstruct; in gfs2_glock_complete()
1398 spin_lock(&gl->gl_lockref.lock); in gfs2_glock_complete()
1399 gl->gl_reply = ret; in gfs2_glock_complete()
1402 if (gfs2_should_freeze(gl)) { in gfs2_glock_complete()
1403 set_bit(GLF_FROZEN, &gl->gl_flags); in gfs2_glock_complete()
1404 spin_unlock(&gl->gl_lockref.lock); in gfs2_glock_complete()
1409 gl->gl_lockref.count++; in gfs2_glock_complete()
1410 set_bit(GLF_REPLY_PENDING, &gl->gl_flags); in gfs2_glock_complete()
1411 __gfs2_glock_queue_work(gl, 0); in gfs2_glock_complete()
1412 spin_unlock(&gl->gl_lockref.lock); in gfs2_glock_complete()
1448 struct gfs2_glock *gl; in gfs2_dispose_glock_lru() local
1453 gl = list_entry(list->next, struct gfs2_glock, gl_lru); in gfs2_dispose_glock_lru()
1454 list_del_init(&gl->gl_lru); in gfs2_dispose_glock_lru()
1455 if (!spin_trylock(&gl->gl_lockref.lock)) { in gfs2_dispose_glock_lru()
1457 list_add(&gl->gl_lru, &lru_list); in gfs2_dispose_glock_lru()
1461 if (test_and_set_bit(GLF_LOCK, &gl->gl_flags)) { in gfs2_dispose_glock_lru()
1462 spin_unlock(&gl->gl_lockref.lock); in gfs2_dispose_glock_lru()
1465 clear_bit(GLF_LRU, &gl->gl_flags); in gfs2_dispose_glock_lru()
1466 gl->gl_lockref.count++; in gfs2_dispose_glock_lru()
1467 if (demote_ok(gl)) in gfs2_dispose_glock_lru()
1468 handle_callback(gl, LM_ST_UNLOCKED, 0, false); in gfs2_dispose_glock_lru()
1469 WARN_ON(!test_and_clear_bit(GLF_LOCK, &gl->gl_flags)); in gfs2_dispose_glock_lru()
1470 __gfs2_glock_queue_work(gl, 0); in gfs2_dispose_glock_lru()
1471 spin_unlock(&gl->gl_lockref.lock); in gfs2_dispose_glock_lru()
1487 struct gfs2_glock *gl; in gfs2_scan_glock_lru() local
1494 gl = list_entry(lru_list.next, struct gfs2_glock, gl_lru); in gfs2_scan_glock_lru()
1497 if (!test_bit(GLF_LOCK, &gl->gl_flags)) { in gfs2_scan_glock_lru()
1498 list_move(&gl->gl_lru, &dispose); in gfs2_scan_glock_lru()
1504 list_move(&gl->gl_lru, &skipped); in gfs2_scan_glock_lru()
1547 struct gfs2_glock *gl; in glock_hash_walk() local
1555 while ((gl = rhashtable_walk_next(&iter)) && !IS_ERR(gl)) in glock_hash_walk()
1556 if (gl->gl_name.ln_sbd == sdp && in glock_hash_walk()
1557 lockref_get_not_dead(&gl->gl_lockref)) in glock_hash_walk()
1558 examiner(gl); in glock_hash_walk()
1561 } while (cond_resched(), gl == ERR_PTR(-EAGAIN)); in glock_hash_walk()
1572 static void thaw_glock(struct gfs2_glock *gl) in thaw_glock() argument
1574 if (!test_and_clear_bit(GLF_FROZEN, &gl->gl_flags)) { in thaw_glock()
1575 gfs2_glock_put(gl); in thaw_glock()
1578 set_bit(GLF_REPLY_PENDING, &gl->gl_flags); in thaw_glock()
1579 gfs2_glock_queue_work(gl, 0); in thaw_glock()
1588 static void clear_glock(struct gfs2_glock *gl) in clear_glock() argument
1590 gfs2_glock_remove_from_lru(gl); in clear_glock()
1592 spin_lock(&gl->gl_lockref.lock); in clear_glock()
1593 if (gl->gl_state != LM_ST_UNLOCKED) in clear_glock()
1594 handle_callback(gl, LM_ST_UNLOCKED, 0, false); in clear_glock()
1595 __gfs2_glock_queue_work(gl, 0); in clear_glock()
1596 spin_unlock(&gl->gl_lockref.lock); in clear_glock()
1610 static void dump_glock(struct seq_file *seq, struct gfs2_glock *gl) in dump_glock() argument
1612 spin_lock(&gl->gl_lockref.lock); in dump_glock()
1613 gfs2_dump_glock(seq, gl); in dump_glock()
1614 spin_unlock(&gl->gl_lockref.lock); in dump_glock()
1617 static void dump_glock_func(struct gfs2_glock *gl) in dump_glock_func() argument
1619 dump_glock(NULL, gl); in dump_glock_func()
1644 struct gfs2_glock *gl = ip->i_gl; in gfs2_glock_finish_truncate() local
1648 gfs2_assert_withdraw(gl->gl_name.ln_sbd, ret == 0); in gfs2_glock_finish_truncate()
1650 spin_lock(&gl->gl_lockref.lock); in gfs2_glock_finish_truncate()
1651 clear_bit(GLF_LOCK, &gl->gl_flags); in gfs2_glock_finish_truncate()
1652 run_queue(gl, 1); in gfs2_glock_finish_truncate()
1653 spin_unlock(&gl->gl_lockref.lock); in gfs2_glock_finish_truncate()
1725 static const char *gflags2str(char *buf, const struct gfs2_glock *gl) in gflags2str() argument
1727 const unsigned long *gflags = &gl->gl_flags; in gflags2str()
1754 if (gl->gl_object) in gflags2str()
1779 void gfs2_dump_glock(struct seq_file *seq, const struct gfs2_glock *gl) in gfs2_dump_glock() argument
1781 const struct gfs2_glock_operations *glops = gl->gl_ops; in gfs2_dump_glock()
1786 dtime = jiffies - gl->gl_demote_time; in gfs2_dump_glock()
1788 if (!test_bit(GLF_DEMOTE, &gl->gl_flags)) in gfs2_dump_glock()
1791 state2str(gl->gl_state), in gfs2_dump_glock()
1792 gl->gl_name.ln_type, in gfs2_dump_glock()
1793 (unsigned long long)gl->gl_name.ln_number, in gfs2_dump_glock()
1794 gflags2str(gflags_buf, gl), in gfs2_dump_glock()
1795 state2str(gl->gl_target), in gfs2_dump_glock()
1796 state2str(gl->gl_demote_state), dtime, in gfs2_dump_glock()
1797 atomic_read(&gl->gl_ail_count), in gfs2_dump_glock()
1798 atomic_read(&gl->gl_revokes), in gfs2_dump_glock()
1799 (int)gl->gl_lockref.count, gl->gl_hold_time); in gfs2_dump_glock()
1801 list_for_each_entry(gh, &gl->gl_holders, gh_list) in gfs2_dump_glock()
1804 if (gl->gl_state != LM_ST_UNLOCKED && glops->go_dump) in gfs2_dump_glock()
1805 glops->go_dump(seq, gl); in gfs2_dump_glock()
1810 struct gfs2_glock *gl = iter_ptr; in gfs2_glstats_seq_show() local
1813 gl->gl_name.ln_type, in gfs2_glstats_seq_show()
1814 (unsigned long long)gl->gl_name.ln_number, in gfs2_glstats_seq_show()
1815 (unsigned long long)gl->gl_stats.stats[GFS2_LKS_SRTT], in gfs2_glstats_seq_show()
1816 (unsigned long long)gl->gl_stats.stats[GFS2_LKS_SRTTVAR], in gfs2_glstats_seq_show()
1817 (unsigned long long)gl->gl_stats.stats[GFS2_LKS_SRTTB], in gfs2_glstats_seq_show()
1818 (unsigned long long)gl->gl_stats.stats[GFS2_LKS_SRTTVARB], in gfs2_glstats_seq_show()
1819 (unsigned long long)gl->gl_stats.stats[GFS2_LKS_SIRT], in gfs2_glstats_seq_show()
1820 (unsigned long long)gl->gl_stats.stats[GFS2_LKS_SIRTVAR], in gfs2_glstats_seq_show()
1821 (unsigned long long)gl->gl_stats.stats[GFS2_LKS_DCOUNT], in gfs2_glstats_seq_show()
1822 (unsigned long long)gl->gl_stats.stats[GFS2_LKS_QCOUNT]); in gfs2_glstats_seq_show()
1927 struct gfs2_glock *gl = gi->gl; in gfs2_glock_iter_next() local
1929 if (gl) { in gfs2_glock_iter_next()
1932 if (!lockref_put_not_zero(&gl->gl_lockref)) in gfs2_glock_iter_next()
1933 gfs2_glock_queue_put(gl); in gfs2_glock_iter_next()
1936 gl = rhashtable_walk_next(&gi->hti); in gfs2_glock_iter_next()
1937 if (IS_ERR_OR_NULL(gl)) { in gfs2_glock_iter_next()
1938 if (gl == ERR_PTR(-EAGAIN)) { in gfs2_glock_iter_next()
1942 gl = NULL; in gfs2_glock_iter_next()
1945 if (gl->gl_name.ln_sbd != gi->sdp) in gfs2_glock_iter_next()
1948 if (!lockref_get_not_dead(&gl->gl_lockref)) in gfs2_glock_iter_next()
1952 if (__lockref_is_dead(&gl->gl_lockref)) in gfs2_glock_iter_next()
1957 gi->gl = gl; in gfs2_glock_iter_next()
1982 return gi->gl; in gfs2_glock_seq_start()
1993 return gi->gl; in gfs2_glock_seq_next()
2072 gi->gl = NULL; in __gfs2_glocks_open()
2088 if (gi->gl) in gfs2_glocks_release()
2089 gfs2_glock_put(gi->gl); in gfs2_glocks_release()