1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
4 * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
7 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
9 #include <linux/sched.h>
10 #include <linux/slab.h>
11 #include <linux/spinlock.h>
12 #include <linux/buffer_head.h>
13 #include <linux/delay.h>
14 #include <linux/sort.h>
15 #include <linux/hash.h>
16 #include <linux/jhash.h>
17 #include <linux/kallsyms.h>
18 #include <linux/gfs2_ondisk.h>
19 #include <linux/list.h>
20 #include <linux/wait.h>
21 #include <linux/module.h>
22 #include <linux/uaccess.h>
23 #include <linux/seq_file.h>
24 #include <linux/debugfs.h>
25 #include <linux/kthread.h>
26 #include <linux/freezer.h>
27 #include <linux/workqueue.h>
28 #include <linux/jiffies.h>
29 #include <linux/rcupdate.h>
30 #include <linux/rculist_bl.h>
31 #include <linux/bit_spinlock.h>
32 #include <linux/percpu.h>
33 #include <linux/list_sort.h>
34 #include <linux/lockref.h>
35 #include <linux/rhashtable.h>
48 #define CREATE_TRACE_POINTS
49 #include "trace_gfs2.h"
51 struct gfs2_glock_iter {
52 struct gfs2_sbd *sdp; /* incore superblock */
53 struct rhashtable_iter hti; /* rhashtable iterator */
54 struct gfs2_glock *gl; /* current glock struct */
55 loff_t last_pos; /* last position */
58 typedef void (*glock_examiner) (struct gfs2_glock * gl);
60 static void do_xmote(struct gfs2_glock *gl, struct gfs2_holder *gh, unsigned int target);
62 static struct dentry *gfs2_root;
63 static struct workqueue_struct *glock_workqueue;
64 struct workqueue_struct *gfs2_delete_workqueue;
65 static LIST_HEAD(lru_list);
66 static atomic_t lru_count = ATOMIC_INIT(0);
67 static DEFINE_SPINLOCK(lru_lock);
69 #define GFS2_GL_HASH_SHIFT 15
70 #define GFS2_GL_HASH_SIZE BIT(GFS2_GL_HASH_SHIFT)
72 static const struct rhashtable_params ht_parms = {
73 .nelem_hint = GFS2_GL_HASH_SIZE * 3 / 4,
74 .key_len = offsetofend(struct lm_lockname, ln_type),
75 .key_offset = offsetof(struct gfs2_glock, gl_name),
76 .head_offset = offsetof(struct gfs2_glock, gl_node),
79 static struct rhashtable gl_hash_table;
81 #define GLOCK_WAIT_TABLE_BITS 12
82 #define GLOCK_WAIT_TABLE_SIZE (1 << GLOCK_WAIT_TABLE_BITS)
83 static wait_queue_head_t glock_wait_table[GLOCK_WAIT_TABLE_SIZE] __cacheline_aligned;
85 struct wait_glock_queue {
86 struct lm_lockname *name;
87 wait_queue_entry_t wait;
90 static int glock_wake_function(wait_queue_entry_t *wait, unsigned int mode,
93 struct wait_glock_queue *wait_glock =
94 container_of(wait, struct wait_glock_queue, wait);
95 struct lm_lockname *wait_name = wait_glock->name;
96 struct lm_lockname *wake_name = key;
98 if (wake_name->ln_sbd != wait_name->ln_sbd ||
99 wake_name->ln_number != wait_name->ln_number ||
100 wake_name->ln_type != wait_name->ln_type)
102 return autoremove_wake_function(wait, mode, sync, key);
105 static wait_queue_head_t *glock_waitqueue(struct lm_lockname *name)
107 u32 hash = jhash2((u32 *)name, ht_parms.key_len / 4, 0);
109 return glock_wait_table + hash_32(hash, GLOCK_WAIT_TABLE_BITS);
113 * wake_up_glock - Wake up waiters on a glock
116 static void wake_up_glock(struct gfs2_glock *gl)
118 wait_queue_head_t *wq = glock_waitqueue(&gl->gl_name);
120 if (waitqueue_active(wq))
121 __wake_up(wq, TASK_NORMAL, 1, &gl->gl_name);
124 static void gfs2_glock_dealloc(struct rcu_head *rcu)
126 struct gfs2_glock *gl = container_of(rcu, struct gfs2_glock, gl_rcu);
128 if (gl->gl_ops->go_flags & GLOF_ASPACE) {
129 kmem_cache_free(gfs2_glock_aspace_cachep, gl);
131 kfree(gl->gl_lksb.sb_lvbptr);
132 kmem_cache_free(gfs2_glock_cachep, gl);
137 * glock_blocked_by_withdraw - determine if we can still use a glock
140 * We need to allow some glocks to be enqueued, dequeued, promoted, and demoted
141 * when we're withdrawn. For example, to maintain metadata integrity, we should
142 * disallow the use of inode and rgrp glocks when withdrawn. Other glocks, like
143 * iopen or the transaction glocks may be safely used because none of their
144 * metadata goes through the journal. So in general, we should disallow all
145 * glocks that are journaled, and allow all the others. One exception is:
146 * we need to allow our active journal to be promoted and demoted so others
147 * may recover it and we can reacquire it when they're done.
149 static bool glock_blocked_by_withdraw(struct gfs2_glock *gl)
151 struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
153 if (likely(!gfs2_withdrawn(sdp)))
155 if (gl->gl_ops->go_flags & GLOF_NONDISK)
157 if (!sdp->sd_jdesc ||
158 gl->gl_name.ln_number == sdp->sd_jdesc->jd_no_addr)
163 void gfs2_glock_free(struct gfs2_glock *gl)
165 struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
167 BUG_ON(atomic_read(&gl->gl_revokes));
168 rhashtable_remove_fast(&gl_hash_table, &gl->gl_node, ht_parms);
171 call_rcu(&gl->gl_rcu, gfs2_glock_dealloc);
172 if (atomic_dec_and_test(&sdp->sd_glock_disposal))
173 wake_up(&sdp->sd_glock_wait);
177 * gfs2_glock_hold() - increment reference count on glock
178 * @gl: The glock to hold
182 void gfs2_glock_hold(struct gfs2_glock *gl)
184 GLOCK_BUG_ON(gl, __lockref_is_dead(&gl->gl_lockref));
185 lockref_get(&gl->gl_lockref);
189 * demote_ok - Check to see if it's ok to unlock a glock
192 * Returns: 1 if it's ok
195 static int demote_ok(const struct gfs2_glock *gl)
197 const struct gfs2_glock_operations *glops = gl->gl_ops;
199 if (gl->gl_state == LM_ST_UNLOCKED)
201 if (!list_empty(&gl->gl_holders))
203 if (glops->go_demote_ok)
204 return glops->go_demote_ok(gl);
209 void gfs2_glock_add_to_lru(struct gfs2_glock *gl)
211 if (!(gl->gl_ops->go_flags & GLOF_LRU))
214 spin_lock(&lru_lock);
216 list_del(&gl->gl_lru);
217 list_add_tail(&gl->gl_lru, &lru_list);
219 if (!test_bit(GLF_LRU, &gl->gl_flags)) {
220 set_bit(GLF_LRU, &gl->gl_flags);
221 atomic_inc(&lru_count);
224 spin_unlock(&lru_lock);
227 static void gfs2_glock_remove_from_lru(struct gfs2_glock *gl)
229 if (!(gl->gl_ops->go_flags & GLOF_LRU))
232 spin_lock(&lru_lock);
233 if (test_bit(GLF_LRU, &gl->gl_flags)) {
234 list_del_init(&gl->gl_lru);
235 atomic_dec(&lru_count);
236 clear_bit(GLF_LRU, &gl->gl_flags);
238 spin_unlock(&lru_lock);
242 * Enqueue the glock on the work queue. Passes one glock reference on to the
245 static void __gfs2_glock_queue_work(struct gfs2_glock *gl, unsigned long delay) {
246 if (!queue_delayed_work(glock_workqueue, &gl->gl_work, delay)) {
248 * We are holding the lockref spinlock, and the work was still
249 * queued above. The queued work (glock_work_func) takes that
250 * spinlock before dropping its glock reference(s), so it
251 * cannot have dropped them in the meantime.
253 GLOCK_BUG_ON(gl, gl->gl_lockref.count < 2);
254 gl->gl_lockref.count--;
258 static void gfs2_glock_queue_work(struct gfs2_glock *gl, unsigned long delay) {
259 spin_lock(&gl->gl_lockref.lock);
260 __gfs2_glock_queue_work(gl, delay);
261 spin_unlock(&gl->gl_lockref.lock);
264 static void __gfs2_glock_put(struct gfs2_glock *gl)
266 struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
267 struct address_space *mapping = gfs2_glock2aspace(gl);
269 lockref_mark_dead(&gl->gl_lockref);
271 gfs2_glock_remove_from_lru(gl);
272 spin_unlock(&gl->gl_lockref.lock);
273 GLOCK_BUG_ON(gl, !list_empty(&gl->gl_holders));
274 GLOCK_BUG_ON(gl, mapping && mapping->nrpages && !gfs2_withdrawn(sdp));
275 trace_gfs2_glock_put(gl);
276 sdp->sd_lockstruct.ls_ops->lm_put_lock(gl);
280 * Cause the glock to be put in work queue context.
282 void gfs2_glock_queue_put(struct gfs2_glock *gl)
284 gfs2_glock_queue_work(gl, 0);
288 * gfs2_glock_put() - Decrement reference count on glock
289 * @gl: The glock to put
293 void gfs2_glock_put(struct gfs2_glock *gl)
295 if (lockref_put_or_lock(&gl->gl_lockref))
298 __gfs2_glock_put(gl);
302 * may_grant - check if its ok to grant a new lock
304 * @gh: The lock request which we wish to grant
306 * Returns: true if its ok to grant the lock
309 static inline int may_grant(const struct gfs2_glock *gl, const struct gfs2_holder *gh)
311 const struct gfs2_holder *gh_head = list_first_entry(&gl->gl_holders, const struct gfs2_holder, gh_list);
312 if ((gh->gh_state == LM_ST_EXCLUSIVE ||
313 gh_head->gh_state == LM_ST_EXCLUSIVE) && gh != gh_head)
315 if (gl->gl_state == gh->gh_state)
317 if (gh->gh_flags & GL_EXACT)
319 if (gl->gl_state == LM_ST_EXCLUSIVE) {
320 if (gh->gh_state == LM_ST_SHARED && gh_head->gh_state == LM_ST_SHARED)
322 if (gh->gh_state == LM_ST_DEFERRED && gh_head->gh_state == LM_ST_DEFERRED)
325 if (gl->gl_state != LM_ST_UNLOCKED && (gh->gh_flags & LM_FLAG_ANY))
330 static void gfs2_holder_wake(struct gfs2_holder *gh)
332 clear_bit(HIF_WAIT, &gh->gh_iflags);
333 smp_mb__after_atomic();
334 wake_up_bit(&gh->gh_iflags, HIF_WAIT);
335 if (gh->gh_flags & GL_ASYNC) {
336 struct gfs2_sbd *sdp = gh->gh_gl->gl_name.ln_sbd;
338 wake_up(&sdp->sd_async_glock_wait);
343 * do_error - Something unexpected has happened during a lock request
347 static void do_error(struct gfs2_glock *gl, const int ret)
349 struct gfs2_holder *gh, *tmp;
351 list_for_each_entry_safe(gh, tmp, &gl->gl_holders, gh_list) {
352 if (test_bit(HIF_HOLDER, &gh->gh_iflags))
354 if (ret & LM_OUT_ERROR)
356 else if (gh->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB))
357 gh->gh_error = GLR_TRYFAILED;
360 list_del_init(&gh->gh_list);
361 trace_gfs2_glock_queue(gh, 0);
362 gfs2_holder_wake(gh);
367 * do_promote - promote as many requests as possible on the current queue
370 * Returns: 1 if there is a blocked holder at the head of the list, or 2
371 * if a type specific operation is underway.
374 static int do_promote(struct gfs2_glock *gl)
375 __releases(&gl->gl_lockref.lock)
376 __acquires(&gl->gl_lockref.lock)
378 const struct gfs2_glock_operations *glops = gl->gl_ops;
379 struct gfs2_holder *gh, *tmp;
383 list_for_each_entry_safe(gh, tmp, &gl->gl_holders, gh_list) {
384 if (test_bit(HIF_HOLDER, &gh->gh_iflags))
386 if (may_grant(gl, gh)) {
387 if (gh->gh_list.prev == &gl->gl_holders &&
389 spin_unlock(&gl->gl_lockref.lock);
390 /* FIXME: eliminate this eventually */
391 ret = glops->go_lock(gh);
392 spin_lock(&gl->gl_lockref.lock);
397 list_del_init(&gh->gh_list);
398 trace_gfs2_glock_queue(gh, 0);
399 gfs2_holder_wake(gh);
402 set_bit(HIF_HOLDER, &gh->gh_iflags);
403 trace_gfs2_promote(gh, 1);
404 gfs2_holder_wake(gh);
407 set_bit(HIF_HOLDER, &gh->gh_iflags);
408 trace_gfs2_promote(gh, 0);
409 gfs2_holder_wake(gh);
412 if (gh->gh_list.prev == &gl->gl_holders)
421 * find_first_waiter - find the first gh that's waiting for the glock
425 static inline struct gfs2_holder *find_first_waiter(const struct gfs2_glock *gl)
427 struct gfs2_holder *gh;
429 list_for_each_entry(gh, &gl->gl_holders, gh_list) {
430 if (!test_bit(HIF_HOLDER, &gh->gh_iflags))
437 * state_change - record that the glock is now in a different state
439 * @new_state the new state
443 static void state_change(struct gfs2_glock *gl, unsigned int new_state)
447 held1 = (gl->gl_state != LM_ST_UNLOCKED);
448 held2 = (new_state != LM_ST_UNLOCKED);
450 if (held1 != held2) {
451 GLOCK_BUG_ON(gl, __lockref_is_dead(&gl->gl_lockref));
453 gl->gl_lockref.count++;
455 gl->gl_lockref.count--;
457 if (held1 && held2 && list_empty(&gl->gl_holders))
458 clear_bit(GLF_QUEUED, &gl->gl_flags);
460 if (new_state != gl->gl_target)
461 /* shorten our minimum hold time */
462 gl->gl_hold_time = max(gl->gl_hold_time - GL_GLOCK_HOLD_DECR,
464 gl->gl_state = new_state;
465 gl->gl_tchange = jiffies;
468 static void gfs2_demote_wake(struct gfs2_glock *gl)
470 gl->gl_demote_state = LM_ST_EXCLUSIVE;
471 clear_bit(GLF_DEMOTE, &gl->gl_flags);
472 smp_mb__after_atomic();
473 wake_up_bit(&gl->gl_flags, GLF_DEMOTE);
477 * finish_xmote - The DLM has replied to one of our lock requests
479 * @ret: The status from the DLM
483 static void finish_xmote(struct gfs2_glock *gl, unsigned int ret)
485 const struct gfs2_glock_operations *glops = gl->gl_ops;
486 struct gfs2_holder *gh;
487 unsigned state = ret & LM_OUT_ST_MASK;
490 spin_lock(&gl->gl_lockref.lock);
491 trace_gfs2_glock_state_change(gl, state);
492 state_change(gl, state);
493 gh = find_first_waiter(gl);
495 /* Demote to UN request arrived during demote to SH or DF */
496 if (test_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags) &&
497 state != LM_ST_UNLOCKED && gl->gl_demote_state == LM_ST_UNLOCKED)
498 gl->gl_target = LM_ST_UNLOCKED;
500 /* Check for state != intended state */
501 if (unlikely(state != gl->gl_target)) {
502 if (gh && !test_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags)) {
503 /* move to back of queue and try next entry */
504 if (ret & LM_OUT_CANCELED) {
505 if ((gh->gh_flags & LM_FLAG_PRIORITY) == 0)
506 list_move_tail(&gh->gh_list, &gl->gl_holders);
507 gh = find_first_waiter(gl);
508 gl->gl_target = gh->gh_state;
511 /* Some error or failed "try lock" - report it */
512 if ((ret & LM_OUT_ERROR) ||
513 (gh->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB))) {
514 gl->gl_target = gl->gl_state;
520 /* Unlocked due to conversion deadlock, try again */
523 do_xmote(gl, gh, gl->gl_target);
525 /* Conversion fails, unlock and try again */
528 do_xmote(gl, gh, LM_ST_UNLOCKED);
530 default: /* Everything else */
531 fs_err(gl->gl_name.ln_sbd, "wanted %u got %u\n",
532 gl->gl_target, state);
535 spin_unlock(&gl->gl_lockref.lock);
539 /* Fast path - we got what we asked for */
540 if (test_and_clear_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags))
541 gfs2_demote_wake(gl);
542 if (state != LM_ST_UNLOCKED) {
543 if (glops->go_xmote_bh) {
544 spin_unlock(&gl->gl_lockref.lock);
545 rv = glops->go_xmote_bh(gl, gh);
546 spin_lock(&gl->gl_lockref.lock);
557 clear_bit(GLF_LOCK, &gl->gl_flags);
559 spin_unlock(&gl->gl_lockref.lock);
563 * do_xmote - Calls the DLM to change the state of a lock
564 * @gl: The lock state
565 * @gh: The holder (only for promotes)
566 * @target: The target lock state
570 static void do_xmote(struct gfs2_glock *gl, struct gfs2_holder *gh, unsigned int target)
571 __releases(&gl->gl_lockref.lock)
572 __acquires(&gl->gl_lockref.lock)
574 const struct gfs2_glock_operations *glops = gl->gl_ops;
575 struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
576 unsigned int lck_flags = (unsigned int)(gh ? gh->gh_flags : 0);
579 if (target != LM_ST_UNLOCKED && glock_blocked_by_withdraw(gl) &&
580 gh && !(gh->gh_flags & LM_FLAG_NOEXP))
582 lck_flags &= (LM_FLAG_TRY | LM_FLAG_TRY_1CB | LM_FLAG_NOEXP |
584 GLOCK_BUG_ON(gl, gl->gl_state == target);
585 GLOCK_BUG_ON(gl, gl->gl_state == gl->gl_target);
586 if ((target == LM_ST_UNLOCKED || target == LM_ST_DEFERRED) &&
589 * If another process is already doing the invalidate, let that
590 * finish first. The glock state machine will get back to this
591 * holder again later.
593 if (test_and_set_bit(GLF_INVALIDATE_IN_PROGRESS,
596 do_error(gl, 0); /* Fail queued try locks */
599 set_bit(GLF_BLOCKING, &gl->gl_flags);
600 if ((gl->gl_req == LM_ST_UNLOCKED) ||
601 (gl->gl_state == LM_ST_EXCLUSIVE) ||
602 (lck_flags & (LM_FLAG_TRY|LM_FLAG_TRY_1CB)))
603 clear_bit(GLF_BLOCKING, &gl->gl_flags);
604 spin_unlock(&gl->gl_lockref.lock);
605 if (glops->go_sync) {
606 ret = glops->go_sync(gl);
607 /* If we had a problem syncing (due to io errors or whatever,
608 * we should not invalidate the metadata or tell dlm to
609 * release the glock to other nodes.
612 if (cmpxchg(&sdp->sd_log_error, 0, ret)) {
613 fs_err(sdp, "Error %d syncing glock \n", ret);
614 gfs2_dump_glock(NULL, gl, true);
619 if (test_bit(GLF_INVALIDATE_IN_PROGRESS, &gl->gl_flags)) {
621 * The call to go_sync should have cleared out the ail list.
622 * If there are still items, we have a problem. We ought to
623 * withdraw, but we can't because the withdraw code also uses
624 * glocks. Warn about the error, dump the glock, then fall
625 * through and wait for logd to do the withdraw for us.
627 if ((atomic_read(&gl->gl_ail_count) != 0) &&
628 (!cmpxchg(&sdp->sd_log_error, 0, -EIO))) {
629 gfs2_assert_warn(sdp, !atomic_read(&gl->gl_ail_count));
630 gfs2_dump_glock(NULL, gl, true);
632 glops->go_inval(gl, target == LM_ST_DEFERRED ? 0 : DIO_METADATA);
633 clear_bit(GLF_INVALIDATE_IN_PROGRESS, &gl->gl_flags);
639 * Check for an error encountered since we called go_sync and go_inval.
640 * If so, we can't withdraw from the glock code because the withdraw
641 * code itself uses glocks (see function signal_our_withdraw) to
642 * change the mount to read-only. Most importantly, we must not call
643 * dlm to unlock the glock until the journal is in a known good state
644 * (after journal replay) otherwise other nodes may use the object
645 * (rgrp or dinode) and then later, journal replay will corrupt the
646 * file system. The best we can do here is wait for the logd daemon
647 * to see sd_log_error and withdraw, and in the meantime, requeue the
650 * However, if we're just unlocking the lock (say, for unmount, when
651 * gfs2_gl_hash_clear calls clear_glock) and recovery is complete
652 * then it's okay to tell dlm to unlock it.
654 if (unlikely(sdp->sd_log_error && !gfs2_withdrawn(sdp)))
655 gfs2_withdraw_delayed(sdp);
656 if (glock_blocked_by_withdraw(gl)) {
657 if (target != LM_ST_UNLOCKED ||
658 test_bit(SDF_WITHDRAW_RECOVERY, &sdp->sd_flags)) {
659 gfs2_glock_queue_work(gl, GL_GLOCK_DFT_HOLD);
664 if (sdp->sd_lockstruct.ls_ops->lm_lock) {
666 ret = sdp->sd_lockstruct.ls_ops->lm_lock(gl, target, lck_flags);
667 if (ret == -EINVAL && gl->gl_target == LM_ST_UNLOCKED &&
668 target == LM_ST_UNLOCKED &&
669 test_bit(SDF_SKIP_DLM_UNLOCK, &sdp->sd_flags)) {
670 finish_xmote(gl, target);
671 gfs2_glock_queue_work(gl, 0);
673 fs_err(sdp, "lm_lock ret %d\n", ret);
674 GLOCK_BUG_ON(gl, !gfs2_withdrawn(sdp));
676 } else { /* lock_nolock */
677 finish_xmote(gl, target);
678 gfs2_glock_queue_work(gl, 0);
681 spin_lock(&gl->gl_lockref.lock);
685 * find_first_holder - find the first "holder" gh
689 static inline struct gfs2_holder *find_first_holder(const struct gfs2_glock *gl)
691 struct gfs2_holder *gh;
693 if (!list_empty(&gl->gl_holders)) {
694 gh = list_first_entry(&gl->gl_holders, struct gfs2_holder, gh_list);
695 if (test_bit(HIF_HOLDER, &gh->gh_iflags))
702 * run_queue - do all outstanding tasks related to a glock
703 * @gl: The glock in question
704 * @nonblock: True if we must not block in run_queue
708 static void run_queue(struct gfs2_glock *gl, const int nonblock)
709 __releases(&gl->gl_lockref.lock)
710 __acquires(&gl->gl_lockref.lock)
712 struct gfs2_holder *gh = NULL;
715 if (test_and_set_bit(GLF_LOCK, &gl->gl_flags))
718 GLOCK_BUG_ON(gl, test_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags));
720 if (test_bit(GLF_DEMOTE, &gl->gl_flags) &&
721 gl->gl_demote_state != gl->gl_state) {
722 if (find_first_holder(gl))
727 if (atomic_read(&gl->gl_revokes) != 0)
729 set_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags);
730 GLOCK_BUG_ON(gl, gl->gl_demote_state == LM_ST_EXCLUSIVE);
731 gl->gl_target = gl->gl_demote_state;
733 if (test_bit(GLF_DEMOTE, &gl->gl_flags))
734 gfs2_demote_wake(gl);
735 ret = do_promote(gl);
740 gh = find_first_waiter(gl);
741 gl->gl_target = gh->gh_state;
742 if (!(gh->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB)))
743 do_error(gl, 0); /* Fail queued try locks */
745 do_xmote(gl, gh, gl->gl_target);
750 clear_bit(GLF_LOCK, &gl->gl_flags);
751 smp_mb__after_atomic();
752 gl->gl_lockref.count++;
753 __gfs2_glock_queue_work(gl, 0);
757 clear_bit(GLF_LOCK, &gl->gl_flags);
758 smp_mb__after_atomic();
762 static void delete_work_func(struct work_struct *work)
764 struct gfs2_glock *gl = container_of(work, struct gfs2_glock, gl_delete);
765 struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
767 u64 no_addr = gl->gl_name.ln_number;
769 /* If someone's using this glock to create a new dinode, the block must
770 have been freed by another node, then re-used, in which case our
771 iopen callback is too late after the fact. Ignore it. */
772 if (test_bit(GLF_INODE_CREATING, &gl->gl_flags))
775 inode = gfs2_lookup_by_inum(sdp, no_addr, NULL, GFS2_BLKST_UNLINKED);
776 if (!IS_ERR_OR_NULL(inode)) {
777 d_prune_aliases(inode);
784 static void glock_work_func(struct work_struct *work)
786 unsigned long delay = 0;
787 struct gfs2_glock *gl = container_of(work, struct gfs2_glock, gl_work.work);
788 unsigned int drop_refs = 1;
790 if (test_and_clear_bit(GLF_REPLY_PENDING, &gl->gl_flags)) {
791 finish_xmote(gl, gl->gl_reply);
794 spin_lock(&gl->gl_lockref.lock);
795 if (test_bit(GLF_PENDING_DEMOTE, &gl->gl_flags) &&
796 gl->gl_state != LM_ST_UNLOCKED &&
797 gl->gl_demote_state != LM_ST_EXCLUSIVE) {
798 unsigned long holdtime, now = jiffies;
800 holdtime = gl->gl_tchange + gl->gl_hold_time;
801 if (time_before(now, holdtime))
802 delay = holdtime - now;
805 clear_bit(GLF_PENDING_DEMOTE, &gl->gl_flags);
806 set_bit(GLF_DEMOTE, &gl->gl_flags);
811 /* Keep one glock reference for the work we requeue. */
813 if (gl->gl_name.ln_type != LM_TYPE_INODE)
815 __gfs2_glock_queue_work(gl, delay);
819 * Drop the remaining glock references manually here. (Mind that
820 * __gfs2_glock_queue_work depends on the lockref spinlock begin held
823 gl->gl_lockref.count -= drop_refs;
824 if (!gl->gl_lockref.count) {
825 __gfs2_glock_put(gl);
828 spin_unlock(&gl->gl_lockref.lock);
831 static struct gfs2_glock *find_insert_glock(struct lm_lockname *name,
832 struct gfs2_glock *new)
834 struct wait_glock_queue wait;
835 wait_queue_head_t *wq = glock_waitqueue(name);
836 struct gfs2_glock *gl;
839 init_wait(&wait.wait);
840 wait.wait.func = glock_wake_function;
843 prepare_to_wait(wq, &wait.wait, TASK_UNINTERRUPTIBLE);
846 gl = rhashtable_lookup_get_insert_fast(&gl_hash_table,
847 &new->gl_node, ht_parms);
851 gl = rhashtable_lookup_fast(&gl_hash_table,
854 if (gl && !lockref_get_not_dead(&gl->gl_lockref)) {
861 finish_wait(wq, &wait.wait);
866 * gfs2_glock_get() - Get a glock, or create one if one doesn't exist
867 * @sdp: The GFS2 superblock
868 * @number: the lock number
869 * @glops: The glock_operations to use
870 * @create: If 0, don't create the glock if it doesn't exist
871 * @glp: the glock is returned here
873 * This does not lock a glock, just finds/creates structures for one.
878 int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
879 const struct gfs2_glock_operations *glops, int create,
880 struct gfs2_glock **glp)
882 struct super_block *s = sdp->sd_vfs;
883 struct lm_lockname name = { .ln_number = number,
884 .ln_type = glops->go_type,
886 struct gfs2_glock *gl, *tmp;
887 struct address_space *mapping;
888 struct kmem_cache *cachep;
891 gl = find_insert_glock(&name, NULL);
899 if (glops->go_flags & GLOF_ASPACE)
900 cachep = gfs2_glock_aspace_cachep;
902 cachep = gfs2_glock_cachep;
903 gl = kmem_cache_alloc(cachep, GFP_NOFS);
907 memset(&gl->gl_lksb, 0, sizeof(struct dlm_lksb));
909 if (glops->go_flags & GLOF_LVB) {
910 gl->gl_lksb.sb_lvbptr = kzalloc(GDLM_LVB_SIZE, GFP_NOFS);
911 if (!gl->gl_lksb.sb_lvbptr) {
912 kmem_cache_free(cachep, gl);
917 atomic_inc(&sdp->sd_glock_disposal);
918 gl->gl_node.next = NULL;
921 gl->gl_lockref.count = 1;
922 gl->gl_state = LM_ST_UNLOCKED;
923 gl->gl_target = LM_ST_UNLOCKED;
924 gl->gl_demote_state = LM_ST_EXCLUSIVE;
928 /* We use the global stats to estimate the initial per-glock stats */
929 gl->gl_stats = this_cpu_ptr(sdp->sd_lkstats)->lkstats[glops->go_type];
931 gl->gl_stats.stats[GFS2_LKS_DCOUNT] = 0;
932 gl->gl_stats.stats[GFS2_LKS_QCOUNT] = 0;
933 gl->gl_tchange = jiffies;
934 gl->gl_object = NULL;
935 gl->gl_hold_time = GL_GLOCK_DFT_HOLD;
936 INIT_DELAYED_WORK(&gl->gl_work, glock_work_func);
937 INIT_WORK(&gl->gl_delete, delete_work_func);
939 mapping = gfs2_glock2aspace(gl);
941 mapping->a_ops = &gfs2_meta_aops;
942 mapping->host = s->s_bdev->bd_inode;
944 mapping_set_gfp_mask(mapping, GFP_NOFS);
945 mapping->private_data = NULL;
946 mapping->writeback_index = 0;
949 tmp = find_insert_glock(&name, gl);
961 kfree(gl->gl_lksb.sb_lvbptr);
962 kmem_cache_free(cachep, gl);
963 atomic_dec(&sdp->sd_glock_disposal);
970 * gfs2_holder_init - initialize a struct gfs2_holder in the default way
972 * @state: the state we're requesting
973 * @flags: the modifier flags
974 * @gh: the holder structure
978 void gfs2_holder_init(struct gfs2_glock *gl, unsigned int state, u16 flags,
979 struct gfs2_holder *gh)
981 INIT_LIST_HEAD(&gh->gh_list);
983 gh->gh_ip = _RET_IP_;
984 gh->gh_owner_pid = get_pid(task_pid(current));
985 gh->gh_state = state;
986 gh->gh_flags = flags;
993 * gfs2_holder_reinit - reinitialize a struct gfs2_holder so we can requeue it
994 * @state: the state we're requesting
995 * @flags: the modifier flags
996 * @gh: the holder structure
998 * Don't mess with the glock.
1002 void gfs2_holder_reinit(unsigned int state, u16 flags, struct gfs2_holder *gh)
1004 gh->gh_state = state;
1005 gh->gh_flags = flags;
1007 gh->gh_ip = _RET_IP_;
1008 put_pid(gh->gh_owner_pid);
1009 gh->gh_owner_pid = get_pid(task_pid(current));
1013 * gfs2_holder_uninit - uninitialize a holder structure (drop glock reference)
1014 * @gh: the holder structure
1018 void gfs2_holder_uninit(struct gfs2_holder *gh)
1020 put_pid(gh->gh_owner_pid);
1021 gfs2_glock_put(gh->gh_gl);
1022 gfs2_holder_mark_uninitialized(gh);
1026 static void gfs2_glock_update_hold_time(struct gfs2_glock *gl,
1027 unsigned long start_time)
1029 /* Have we waited longer that a second? */
1030 if (time_after(jiffies, start_time + HZ)) {
1031 /* Lengthen the minimum hold time. */
1032 gl->gl_hold_time = min(gl->gl_hold_time + GL_GLOCK_HOLD_INCR,
1038 * gfs2_glock_wait - wait on a glock acquisition
1039 * @gh: the glock holder
1041 * Returns: 0 on success
1044 int gfs2_glock_wait(struct gfs2_holder *gh)
1046 unsigned long start_time = jiffies;
1049 wait_on_bit(&gh->gh_iflags, HIF_WAIT, TASK_UNINTERRUPTIBLE);
1050 gfs2_glock_update_hold_time(gh->gh_gl, start_time);
1051 return gh->gh_error;
1054 static int glocks_pending(unsigned int num_gh, struct gfs2_holder *ghs)
1058 for (i = 0; i < num_gh; i++)
1059 if (test_bit(HIF_WAIT, &ghs[i].gh_iflags))
1065 * gfs2_glock_async_wait - wait on multiple asynchronous glock acquisitions
1066 * @num_gh: the number of holders in the array
1067 * @ghs: the glock holder array
1069 * Returns: 0 on success, meaning all glocks have been granted and are held.
1070 * -ESTALE if the request timed out, meaning all glocks were released,
1071 * and the caller should retry the operation.
1074 int gfs2_glock_async_wait(unsigned int num_gh, struct gfs2_holder *ghs)
1076 struct gfs2_sbd *sdp = ghs[0].gh_gl->gl_name.ln_sbd;
1077 int i, ret = 0, timeout = 0;
1078 unsigned long start_time = jiffies;
1083 * Total up the (minimum hold time * 2) of all glocks and use that to
1084 * determine the max amount of time we should wait.
1086 for (i = 0; i < num_gh; i++)
1087 timeout += ghs[i].gh_gl->gl_hold_time << 1;
1090 if (!wait_event_timeout(sdp->sd_async_glock_wait,
1091 !glocks_pending(num_gh, ghs), timeout))
1092 ret = -ESTALE; /* request timed out. */
1095 * If dlm granted all our requests, we need to adjust the glock
1096 * minimum hold time values according to how long we waited.
1098 * If our request timed out, we need to repeatedly release any held
1099 * glocks we acquired thus far to allow dlm to acquire the remaining
1100 * glocks without deadlocking. We cannot currently cancel outstanding
1101 * glock acquisitions.
1103 * The HIF_WAIT bit tells us which requests still need a response from
1106 * If dlm sent us any errors, we return the first error we find.
1108 keep_waiting = false;
1109 for (i = 0; i < num_gh; i++) {
1110 /* Skip holders we have already dequeued below. */
1111 if (!gfs2_holder_queued(&ghs[i]))
1113 /* Skip holders with a pending DLM response. */
1114 if (test_bit(HIF_WAIT, &ghs[i].gh_iflags)) {
1115 keep_waiting = true;
1119 if (test_bit(HIF_HOLDER, &ghs[i].gh_iflags)) {
1121 gfs2_glock_dq(&ghs[i]);
1123 gfs2_glock_update_hold_time(ghs[i].gh_gl,
1127 ret = ghs[i].gh_error;
1134 * At this point, we've either acquired all locks or released them all.
1140 * handle_callback - process a demote request
1142 * @state: the state the caller wants us to change to
1144 * There are only two requests that we are going to see in actual
1145 * practise: LM_ST_SHARED and LM_ST_UNLOCKED
1148 static void handle_callback(struct gfs2_glock *gl, unsigned int state,
1149 unsigned long delay, bool remote)
1151 int bit = delay ? GLF_PENDING_DEMOTE : GLF_DEMOTE;
1153 set_bit(bit, &gl->gl_flags);
1154 if (gl->gl_demote_state == LM_ST_EXCLUSIVE) {
1155 gl->gl_demote_state = state;
1156 gl->gl_demote_time = jiffies;
1157 } else if (gl->gl_demote_state != LM_ST_UNLOCKED &&
1158 gl->gl_demote_state != state) {
1159 gl->gl_demote_state = LM_ST_UNLOCKED;
1161 if (gl->gl_ops->go_callback)
1162 gl->gl_ops->go_callback(gl, remote);
1163 trace_gfs2_demote_rq(gl, remote);
1166 void gfs2_print_dbg(struct seq_file *seq, const char *fmt, ...)
1168 struct va_format vaf;
1171 va_start(args, fmt);
1174 seq_vprintf(seq, fmt, args);
1179 pr_err("%pV", &vaf);
1186 * add_to_queue - Add a holder to the wait queue (but look for recursion)
1187 * @gh: the holder structure to add
1189 * Eventually we should move the recursive locking trap to a
1190 * debugging option or something like that. This is the fast
1191 * path and needs to have the minimum number of distractions.
1195 static inline void add_to_queue(struct gfs2_holder *gh)
1196 __releases(&gl->gl_lockref.lock)
1197 __acquires(&gl->gl_lockref.lock)
1199 struct gfs2_glock *gl = gh->gh_gl;
1200 struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
1201 struct list_head *insert_pt = NULL;
1202 struct gfs2_holder *gh2;
1205 GLOCK_BUG_ON(gl, gh->gh_owner_pid == NULL);
1206 if (test_and_set_bit(HIF_WAIT, &gh->gh_iflags))
1207 GLOCK_BUG_ON(gl, true);
1209 if (gh->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB)) {
1210 if (test_bit(GLF_LOCK, &gl->gl_flags))
1211 try_futile = !may_grant(gl, gh);
1212 if (test_bit(GLF_INVALIDATE_IN_PROGRESS, &gl->gl_flags))
1216 list_for_each_entry(gh2, &gl->gl_holders, gh_list) {
1217 if (unlikely(gh2->gh_owner_pid == gh->gh_owner_pid &&
1218 (gh->gh_gl->gl_ops->go_type != LM_TYPE_FLOCK)))
1219 goto trap_recursive;
1221 !(gh2->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB))) {
1223 gh->gh_error = GLR_TRYFAILED;
1224 gfs2_holder_wake(gh);
1227 if (test_bit(HIF_HOLDER, &gh2->gh_iflags))
1229 if (unlikely((gh->gh_flags & LM_FLAG_PRIORITY) && !insert_pt))
1230 insert_pt = &gh2->gh_list;
1232 set_bit(GLF_QUEUED, &gl->gl_flags);
1233 trace_gfs2_glock_queue(gh, 1);
1234 gfs2_glstats_inc(gl, GFS2_LKS_QCOUNT);
1235 gfs2_sbstats_inc(gl, GFS2_LKS_QCOUNT);
1236 if (likely(insert_pt == NULL)) {
1237 list_add_tail(&gh->gh_list, &gl->gl_holders);
1238 if (unlikely(gh->gh_flags & LM_FLAG_PRIORITY))
1242 list_add_tail(&gh->gh_list, insert_pt);
1244 gh = list_first_entry(&gl->gl_holders, struct gfs2_holder, gh_list);
1245 if (!(gh->gh_flags & LM_FLAG_PRIORITY)) {
1246 spin_unlock(&gl->gl_lockref.lock);
1247 if (sdp->sd_lockstruct.ls_ops->lm_cancel)
1248 sdp->sd_lockstruct.ls_ops->lm_cancel(gl);
1249 spin_lock(&gl->gl_lockref.lock);
1254 fs_err(sdp, "original: %pSR\n", (void *)gh2->gh_ip);
1255 fs_err(sdp, "pid: %d\n", pid_nr(gh2->gh_owner_pid));
1256 fs_err(sdp, "lock type: %d req lock state : %d\n",
1257 gh2->gh_gl->gl_name.ln_type, gh2->gh_state);
1258 fs_err(sdp, "new: %pSR\n", (void *)gh->gh_ip);
1259 fs_err(sdp, "pid: %d\n", pid_nr(gh->gh_owner_pid));
1260 fs_err(sdp, "lock type: %d req lock state : %d\n",
1261 gh->gh_gl->gl_name.ln_type, gh->gh_state);
1262 gfs2_dump_glock(NULL, gl, true);
1267 * gfs2_glock_nq - enqueue a struct gfs2_holder onto a glock (acquire a glock)
1268 * @gh: the holder structure
1270 * if (gh->gh_flags & GL_ASYNC), this never returns an error
1272 * Returns: 0, GLR_TRYFAILED, or errno on failure
1275 int gfs2_glock_nq(struct gfs2_holder *gh)
1277 struct gfs2_glock *gl = gh->gh_gl;
1280 if (glock_blocked_by_withdraw(gl) && !(gh->gh_flags & LM_FLAG_NOEXP))
1283 if (test_bit(GLF_LRU, &gl->gl_flags))
1284 gfs2_glock_remove_from_lru(gl);
1286 spin_lock(&gl->gl_lockref.lock);
1288 if (unlikely((LM_FLAG_NOEXP & gh->gh_flags) &&
1289 test_and_clear_bit(GLF_FROZEN, &gl->gl_flags))) {
1290 set_bit(GLF_REPLY_PENDING, &gl->gl_flags);
1291 gl->gl_lockref.count++;
1292 __gfs2_glock_queue_work(gl, 0);
1295 spin_unlock(&gl->gl_lockref.lock);
1297 if (!(gh->gh_flags & GL_ASYNC))
1298 error = gfs2_glock_wait(gh);
1304 * gfs2_glock_poll - poll to see if an async request has been completed
1307 * Returns: 1 if the request is ready to be gfs2_glock_wait()ed on
1310 int gfs2_glock_poll(struct gfs2_holder *gh)
1312 return test_bit(HIF_WAIT, &gh->gh_iflags) ? 0 : 1;
1316 * gfs2_glock_dq - dequeue a struct gfs2_holder from a glock (release a glock)
1317 * @gh: the glock holder
1321 void gfs2_glock_dq(struct gfs2_holder *gh)
1323 struct gfs2_glock *gl = gh->gh_gl;
1324 struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
1328 spin_lock(&gl->gl_lockref.lock);
1330 * If we're in the process of file system withdraw, we cannot just
1331 * dequeue any glocks until our journal is recovered, lest we
1332 * introduce file system corruption. We need two exceptions to this
1333 * rule: We need to allow unlocking of nondisk glocks and the glock
1334 * for our own journal that needs recovery.
1336 if (test_bit(SDF_WITHDRAW_RECOVERY, &sdp->sd_flags) &&
1337 glock_blocked_by_withdraw(gl) &&
1338 gh->gh_gl != sdp->sd_jinode_gl) {
1339 sdp->sd_glock_dqs_held++;
1341 wait_on_bit(&sdp->sd_flags, SDF_WITHDRAW_RECOVERY,
1342 TASK_UNINTERRUPTIBLE);
1344 if (gh->gh_flags & GL_NOCACHE)
1345 handle_callback(gl, LM_ST_UNLOCKED, 0, false);
1347 list_del_init(&gh->gh_list);
1348 clear_bit(HIF_HOLDER, &gh->gh_iflags);
1349 if (find_first_holder(gl) == NULL) {
1350 if (list_empty(&gl->gl_holders) &&
1351 !test_bit(GLF_PENDING_DEMOTE, &gl->gl_flags) &&
1352 !test_bit(GLF_DEMOTE, &gl->gl_flags))
1355 if (!test_bit(GLF_LFLUSH, &gl->gl_flags) && demote_ok(gl))
1356 gfs2_glock_add_to_lru(gl);
1358 trace_gfs2_glock_queue(gh, 0);
1359 if (unlikely(!fast_path)) {
1360 gl->gl_lockref.count++;
1361 if (test_bit(GLF_PENDING_DEMOTE, &gl->gl_flags) &&
1362 !test_bit(GLF_DEMOTE, &gl->gl_flags) &&
1363 gl->gl_name.ln_type == LM_TYPE_INODE)
1364 delay = gl->gl_hold_time;
1365 __gfs2_glock_queue_work(gl, delay);
1367 spin_unlock(&gl->gl_lockref.lock);
1370 void gfs2_glock_dq_wait(struct gfs2_holder *gh)
1372 struct gfs2_glock *gl = gh->gh_gl;
1375 wait_on_bit(&gl->gl_flags, GLF_DEMOTE, TASK_UNINTERRUPTIBLE);
1379 * gfs2_glock_dq_uninit - dequeue a holder from a glock and initialize it
1380 * @gh: the holder structure
1384 void gfs2_glock_dq_uninit(struct gfs2_holder *gh)
1387 gfs2_holder_uninit(gh);
1391 * gfs2_glock_nq_num - acquire a glock based on lock number
1392 * @sdp: the filesystem
1393 * @number: the lock number
1394 * @glops: the glock operations for the type of glock
1395 * @state: the state to acquire the glock in
1396 * @flags: modifier flags for the acquisition
1397 * @gh: the struct gfs2_holder
1402 int gfs2_glock_nq_num(struct gfs2_sbd *sdp, u64 number,
1403 const struct gfs2_glock_operations *glops,
1404 unsigned int state, u16 flags, struct gfs2_holder *gh)
1406 struct gfs2_glock *gl;
1409 error = gfs2_glock_get(sdp, number, glops, CREATE, &gl);
1411 error = gfs2_glock_nq_init(gl, state, flags, gh);
1419 * glock_compare - Compare two struct gfs2_glock structures for sorting
1420 * @arg_a: the first structure
1421 * @arg_b: the second structure
1425 static int glock_compare(const void *arg_a, const void *arg_b)
1427 const struct gfs2_holder *gh_a = *(const struct gfs2_holder **)arg_a;
1428 const struct gfs2_holder *gh_b = *(const struct gfs2_holder **)arg_b;
1429 const struct lm_lockname *a = &gh_a->gh_gl->gl_name;
1430 const struct lm_lockname *b = &gh_b->gh_gl->gl_name;
1432 if (a->ln_number > b->ln_number)
1434 if (a->ln_number < b->ln_number)
1436 BUG_ON(gh_a->gh_gl->gl_ops->go_type == gh_b->gh_gl->gl_ops->go_type);
1441 * nq_m_sync - synchonously acquire more than one glock in deadlock free order
1442 * @num_gh: the number of structures
1443 * @ghs: an array of struct gfs2_holder structures
1445 * Returns: 0 on success (all glocks acquired),
1446 * errno on failure (no glocks acquired)
1449 static int nq_m_sync(unsigned int num_gh, struct gfs2_holder *ghs,
1450 struct gfs2_holder **p)
1455 for (x = 0; x < num_gh; x++)
1458 sort(p, num_gh, sizeof(struct gfs2_holder *), glock_compare, NULL);
1460 for (x = 0; x < num_gh; x++) {
1461 p[x]->gh_flags &= ~(LM_FLAG_TRY | GL_ASYNC);
1463 error = gfs2_glock_nq(p[x]);
1466 gfs2_glock_dq(p[x]);
1475 * gfs2_glock_nq_m - acquire multiple glocks
1476 * @num_gh: the number of structures
1477 * @ghs: an array of struct gfs2_holder structures
1480 * Returns: 0 on success (all glocks acquired),
1481 * errno on failure (no glocks acquired)
1484 int gfs2_glock_nq_m(unsigned int num_gh, struct gfs2_holder *ghs)
1486 struct gfs2_holder *tmp[4];
1487 struct gfs2_holder **pph = tmp;
1494 ghs->gh_flags &= ~(LM_FLAG_TRY | GL_ASYNC);
1495 return gfs2_glock_nq(ghs);
1499 pph = kmalloc_array(num_gh, sizeof(struct gfs2_holder *),
1505 error = nq_m_sync(num_gh, ghs, pph);
1514 * gfs2_glock_dq_m - release multiple glocks
1515 * @num_gh: the number of structures
1516 * @ghs: an array of struct gfs2_holder structures
1520 void gfs2_glock_dq_m(unsigned int num_gh, struct gfs2_holder *ghs)
1523 gfs2_glock_dq(&ghs[num_gh]);
1526 void gfs2_glock_cb(struct gfs2_glock *gl, unsigned int state)
1528 unsigned long delay = 0;
1529 unsigned long holdtime;
1530 unsigned long now = jiffies;
1532 gfs2_glock_hold(gl);
1533 holdtime = gl->gl_tchange + gl->gl_hold_time;
1534 if (test_bit(GLF_QUEUED, &gl->gl_flags) &&
1535 gl->gl_name.ln_type == LM_TYPE_INODE) {
1536 if (time_before(now, holdtime))
1537 delay = holdtime - now;
1538 if (test_bit(GLF_REPLY_PENDING, &gl->gl_flags))
1539 delay = gl->gl_hold_time;
1542 spin_lock(&gl->gl_lockref.lock);
1543 handle_callback(gl, state, delay, true);
1544 __gfs2_glock_queue_work(gl, delay);
1545 spin_unlock(&gl->gl_lockref.lock);
1549 * gfs2_should_freeze - Figure out if glock should be frozen
1550 * @gl: The glock in question
1552 * Glocks are not frozen if (a) the result of the dlm operation is
1553 * an error, (b) the locking operation was an unlock operation or
1554 * (c) if there is a "noexp" flagged request anywhere in the queue
1556 * Returns: 1 if freezing should occur, 0 otherwise
1559 static int gfs2_should_freeze(const struct gfs2_glock *gl)
1561 const struct gfs2_holder *gh;
1563 if (gl->gl_reply & ~LM_OUT_ST_MASK)
1565 if (gl->gl_target == LM_ST_UNLOCKED)
1568 list_for_each_entry(gh, &gl->gl_holders, gh_list) {
1569 if (test_bit(HIF_HOLDER, &gh->gh_iflags))
1571 if (LM_FLAG_NOEXP & gh->gh_flags)
1579 * gfs2_glock_complete - Callback used by locking
1580 * @gl: Pointer to the glock
1581 * @ret: The return value from the dlm
1583 * The gl_reply field is under the gl_lockref.lock lock so that it is ok
1584 * to use a bitfield shared with other glock state fields.
1587 void gfs2_glock_complete(struct gfs2_glock *gl, int ret)
1589 struct lm_lockstruct *ls = &gl->gl_name.ln_sbd->sd_lockstruct;
1591 spin_lock(&gl->gl_lockref.lock);
1594 if (unlikely(test_bit(DFL_BLOCK_LOCKS, &ls->ls_recover_flags))) {
1595 if (gfs2_should_freeze(gl)) {
1596 set_bit(GLF_FROZEN, &gl->gl_flags);
1597 spin_unlock(&gl->gl_lockref.lock);
1602 gl->gl_lockref.count++;
1603 set_bit(GLF_REPLY_PENDING, &gl->gl_flags);
1604 __gfs2_glock_queue_work(gl, 0);
1605 spin_unlock(&gl->gl_lockref.lock);
1608 static int glock_cmp(void *priv, struct list_head *a, struct list_head *b)
1610 struct gfs2_glock *gla, *glb;
1612 gla = list_entry(a, struct gfs2_glock, gl_lru);
1613 glb = list_entry(b, struct gfs2_glock, gl_lru);
1615 if (gla->gl_name.ln_number > glb->gl_name.ln_number)
1617 if (gla->gl_name.ln_number < glb->gl_name.ln_number)
1624 * gfs2_dispose_glock_lru - Demote a list of glocks
1625 * @list: The list to dispose of
1627 * Disposing of glocks may involve disk accesses, so that here we sort
1628 * the glocks by number (i.e. disk location of the inodes) so that if
1629 * there are any such accesses, they'll be sent in order (mostly).
1631 * Must be called under the lru_lock, but may drop and retake this
1632 * lock. While the lru_lock is dropped, entries may vanish from the
1633 * list, but no new entries will appear on the list (since it is
1637 static void gfs2_dispose_glock_lru(struct list_head *list)
1638 __releases(&lru_lock)
1639 __acquires(&lru_lock)
1641 struct gfs2_glock *gl;
1643 list_sort(NULL, list, glock_cmp);
1645 while(!list_empty(list)) {
1646 gl = list_first_entry(list, struct gfs2_glock, gl_lru);
1647 list_del_init(&gl->gl_lru);
1648 if (!spin_trylock(&gl->gl_lockref.lock)) {
1650 list_add(&gl->gl_lru, &lru_list);
1651 set_bit(GLF_LRU, &gl->gl_flags);
1652 atomic_inc(&lru_count);
1655 if (test_and_set_bit(GLF_LOCK, &gl->gl_flags)) {
1656 spin_unlock(&gl->gl_lockref.lock);
1657 goto add_back_to_lru;
1659 gl->gl_lockref.count++;
1661 handle_callback(gl, LM_ST_UNLOCKED, 0, false);
1662 WARN_ON(!test_and_clear_bit(GLF_LOCK, &gl->gl_flags));
1663 __gfs2_glock_queue_work(gl, 0);
1664 spin_unlock(&gl->gl_lockref.lock);
1665 cond_resched_lock(&lru_lock);
1670 * gfs2_scan_glock_lru - Scan the LRU looking for locks to demote
1671 * @nr: The number of entries to scan
1673 * This function selects the entries on the LRU which are able to
1674 * be demoted, and then kicks off the process by calling
1675 * gfs2_dispose_glock_lru() above.
1678 static long gfs2_scan_glock_lru(int nr)
1680 struct gfs2_glock *gl;
1685 spin_lock(&lru_lock);
1686 while ((nr-- >= 0) && !list_empty(&lru_list)) {
1687 gl = list_first_entry(&lru_list, struct gfs2_glock, gl_lru);
1689 /* Test for being demotable */
1690 if (!test_bit(GLF_LOCK, &gl->gl_flags)) {
1691 list_move(&gl->gl_lru, &dispose);
1692 atomic_dec(&lru_count);
1693 clear_bit(GLF_LRU, &gl->gl_flags);
1698 list_move(&gl->gl_lru, &skipped);
1700 list_splice(&skipped, &lru_list);
1701 if (!list_empty(&dispose))
1702 gfs2_dispose_glock_lru(&dispose);
1703 spin_unlock(&lru_lock);
1708 static unsigned long gfs2_glock_shrink_scan(struct shrinker *shrink,
1709 struct shrink_control *sc)
1711 if (!(sc->gfp_mask & __GFP_FS))
1713 return gfs2_scan_glock_lru(sc->nr_to_scan);
1716 static unsigned long gfs2_glock_shrink_count(struct shrinker *shrink,
1717 struct shrink_control *sc)
1719 return vfs_pressure_ratio(atomic_read(&lru_count));
1722 static struct shrinker glock_shrinker = {
1723 .seeks = DEFAULT_SEEKS,
1724 .count_objects = gfs2_glock_shrink_count,
1725 .scan_objects = gfs2_glock_shrink_scan,
1729 * examine_bucket - Call a function for glock in a hash bucket
1730 * @examiner: the function
1731 * @sdp: the filesystem
1732 * @bucket: the bucket
1734 * Note that the function can be called multiple times on the same
1735 * object. So the user must ensure that the function can cope with
1739 static void glock_hash_walk(glock_examiner examiner, const struct gfs2_sbd *sdp)
1741 struct gfs2_glock *gl;
1742 struct rhashtable_iter iter;
1744 rhashtable_walk_enter(&gl_hash_table, &iter);
1747 rhashtable_walk_start(&iter);
1749 while ((gl = rhashtable_walk_next(&iter)) && !IS_ERR(gl))
1750 if (gl->gl_name.ln_sbd == sdp &&
1751 lockref_get_not_dead(&gl->gl_lockref))
1754 rhashtable_walk_stop(&iter);
1755 } while (cond_resched(), gl == ERR_PTR(-EAGAIN));
1757 rhashtable_walk_exit(&iter);
1761 * thaw_glock - thaw out a glock which has an unprocessed reply waiting
1762 * @gl: The glock to thaw
1766 static void thaw_glock(struct gfs2_glock *gl)
1768 if (!test_and_clear_bit(GLF_FROZEN, &gl->gl_flags)) {
1772 set_bit(GLF_REPLY_PENDING, &gl->gl_flags);
1773 gfs2_glock_queue_work(gl, 0);
1777 * clear_glock - look at a glock and see if we can free it from glock cache
1778 * @gl: the glock to look at
1782 static void clear_glock(struct gfs2_glock *gl)
1784 gfs2_glock_remove_from_lru(gl);
1786 spin_lock(&gl->gl_lockref.lock);
1787 if (gl->gl_state != LM_ST_UNLOCKED)
1788 handle_callback(gl, LM_ST_UNLOCKED, 0, false);
1789 __gfs2_glock_queue_work(gl, 0);
1790 spin_unlock(&gl->gl_lockref.lock);
1794 * gfs2_glock_thaw - Thaw any frozen glocks
1795 * @sdp: The super block
1799 void gfs2_glock_thaw(struct gfs2_sbd *sdp)
1801 glock_hash_walk(thaw_glock, sdp);
1804 static void dump_glock(struct seq_file *seq, struct gfs2_glock *gl, bool fsid)
1806 spin_lock(&gl->gl_lockref.lock);
1807 gfs2_dump_glock(seq, gl, fsid);
1808 spin_unlock(&gl->gl_lockref.lock);
1811 static void dump_glock_func(struct gfs2_glock *gl)
1813 dump_glock(NULL, gl, true);
1817 * gfs2_gl_hash_clear - Empty out the glock hash table
1818 * @sdp: the filesystem
1819 * @wait: wait until it's all gone
1821 * Called when unmounting the filesystem.
1824 void gfs2_gl_hash_clear(struct gfs2_sbd *sdp)
1826 set_bit(SDF_SKIP_DLM_UNLOCK, &sdp->sd_flags);
1827 flush_workqueue(glock_workqueue);
1828 glock_hash_walk(clear_glock, sdp);
1829 flush_workqueue(glock_workqueue);
1830 wait_event_timeout(sdp->sd_glock_wait,
1831 atomic_read(&sdp->sd_glock_disposal) == 0,
1833 glock_hash_walk(dump_glock_func, sdp);
1836 void gfs2_glock_finish_truncate(struct gfs2_inode *ip)
1838 struct gfs2_glock *gl = ip->i_gl;
1841 ret = gfs2_truncatei_resume(ip);
1842 gfs2_assert_withdraw(gl->gl_name.ln_sbd, ret == 0);
1844 spin_lock(&gl->gl_lockref.lock);
1845 clear_bit(GLF_LOCK, &gl->gl_flags);
1847 spin_unlock(&gl->gl_lockref.lock);
1850 static const char *state2str(unsigned state)
1853 case LM_ST_UNLOCKED:
1857 case LM_ST_DEFERRED:
1859 case LM_ST_EXCLUSIVE:
1865 static const char *hflags2str(char *buf, u16 flags, unsigned long iflags)
1868 if (flags & LM_FLAG_TRY)
1870 if (flags & LM_FLAG_TRY_1CB)
1872 if (flags & LM_FLAG_NOEXP)
1874 if (flags & LM_FLAG_ANY)
1876 if (flags & LM_FLAG_PRIORITY)
1878 if (flags & GL_ASYNC)
1880 if (flags & GL_EXACT)
1882 if (flags & GL_NOCACHE)
1884 if (test_bit(HIF_HOLDER, &iflags))
1886 if (test_bit(HIF_WAIT, &iflags))
1888 if (test_bit(HIF_FIRST, &iflags))
1895 * dump_holder - print information about a glock holder
1896 * @seq: the seq_file struct
1897 * @gh: the glock holder
1898 * @fs_id_buf: pointer to file system id (if requested)
1902 static void dump_holder(struct seq_file *seq, const struct gfs2_holder *gh,
1903 const char *fs_id_buf)
1905 struct task_struct *gh_owner = NULL;
1909 if (gh->gh_owner_pid)
1910 gh_owner = pid_task(gh->gh_owner_pid, PIDTYPE_PID);
1911 gfs2_print_dbg(seq, "%s H: s:%s f:%s e:%d p:%ld [%s] %pS\n",
1912 fs_id_buf, state2str(gh->gh_state),
1913 hflags2str(flags_buf, gh->gh_flags, gh->gh_iflags),
1915 gh->gh_owner_pid ? (long)pid_nr(gh->gh_owner_pid) : -1,
1916 gh_owner ? gh_owner->comm : "(ended)",
1921 static const char *gflags2str(char *buf, const struct gfs2_glock *gl)
1923 const unsigned long *gflags = &gl->gl_flags;
1926 if (test_bit(GLF_LOCK, gflags))
1928 if (test_bit(GLF_DEMOTE, gflags))
1930 if (test_bit(GLF_PENDING_DEMOTE, gflags))
1932 if (test_bit(GLF_DEMOTE_IN_PROGRESS, gflags))
1934 if (test_bit(GLF_DIRTY, gflags))
1936 if (test_bit(GLF_LFLUSH, gflags))
1938 if (test_bit(GLF_INVALIDATE_IN_PROGRESS, gflags))
1940 if (test_bit(GLF_REPLY_PENDING, gflags))
1942 if (test_bit(GLF_INITIAL, gflags))
1944 if (test_bit(GLF_FROZEN, gflags))
1946 if (test_bit(GLF_QUEUED, gflags))
1948 if (test_bit(GLF_LRU, gflags))
1952 if (test_bit(GLF_BLOCKING, gflags))
1959 * gfs2_dump_glock - print information about a glock
1960 * @seq: The seq_file struct
1962 * @fsid: If true, also dump the file system id
1964 * The file format is as follows:
1965 * One line per object, capital letters are used to indicate objects
1966 * G = glock, I = Inode, R = rgrp, H = holder. Glocks are not indented,
1967 * other objects are indented by a single space and follow the glock to
1968 * which they are related. Fields are indicated by lower case letters
1969 * followed by a colon and the field value, except for strings which are in
1970 * [] so that its possible to see if they are composed of spaces for
1971 * example. The field's are n = number (id of the object), f = flags,
1972 * t = type, s = state, r = refcount, e = error, p = pid.
1976 void gfs2_dump_glock(struct seq_file *seq, struct gfs2_glock *gl, bool fsid)
1978 const struct gfs2_glock_operations *glops = gl->gl_ops;
1979 unsigned long long dtime;
1980 const struct gfs2_holder *gh;
1981 char gflags_buf[32];
1982 struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
1983 char fs_id_buf[sizeof(sdp->sd_fsname) + 7];
1985 memset(fs_id_buf, 0, sizeof(fs_id_buf));
1986 if (fsid && sdp) /* safety precaution */
1987 sprintf(fs_id_buf, "fsid=%s: ", sdp->sd_fsname);
1988 dtime = jiffies - gl->gl_demote_time;
1989 dtime *= 1000000/HZ; /* demote time in uSec */
1990 if (!test_bit(GLF_DEMOTE, &gl->gl_flags))
1992 gfs2_print_dbg(seq, "%sG: s:%s n:%u/%llx f:%s t:%s d:%s/%llu a:%d "
1993 "v:%d r:%d m:%ld\n", fs_id_buf, state2str(gl->gl_state),
1994 gl->gl_name.ln_type,
1995 (unsigned long long)gl->gl_name.ln_number,
1996 gflags2str(gflags_buf, gl),
1997 state2str(gl->gl_target),
1998 state2str(gl->gl_demote_state), dtime,
1999 atomic_read(&gl->gl_ail_count),
2000 atomic_read(&gl->gl_revokes),
2001 (int)gl->gl_lockref.count, gl->gl_hold_time);
2003 list_for_each_entry(gh, &gl->gl_holders, gh_list)
2004 dump_holder(seq, gh, fs_id_buf);
2006 if (gl->gl_state != LM_ST_UNLOCKED && glops->go_dump)
2007 glops->go_dump(seq, gl, fs_id_buf);
2010 static int gfs2_glstats_seq_show(struct seq_file *seq, void *iter_ptr)
2012 struct gfs2_glock *gl = iter_ptr;
2014 seq_printf(seq, "G: n:%u/%llx rtt:%llu/%llu rttb:%llu/%llu irt:%llu/%llu dcnt: %llu qcnt: %llu\n",
2015 gl->gl_name.ln_type,
2016 (unsigned long long)gl->gl_name.ln_number,
2017 (unsigned long long)gl->gl_stats.stats[GFS2_LKS_SRTT],
2018 (unsigned long long)gl->gl_stats.stats[GFS2_LKS_SRTTVAR],
2019 (unsigned long long)gl->gl_stats.stats[GFS2_LKS_SRTTB],
2020 (unsigned long long)gl->gl_stats.stats[GFS2_LKS_SRTTVARB],
2021 (unsigned long long)gl->gl_stats.stats[GFS2_LKS_SIRT],
2022 (unsigned long long)gl->gl_stats.stats[GFS2_LKS_SIRTVAR],
2023 (unsigned long long)gl->gl_stats.stats[GFS2_LKS_DCOUNT],
2024 (unsigned long long)gl->gl_stats.stats[GFS2_LKS_QCOUNT]);
2028 static const char *gfs2_gltype[] = {
2042 static const char *gfs2_stype[] = {
2043 [GFS2_LKS_SRTT] = "srtt",
2044 [GFS2_LKS_SRTTVAR] = "srttvar",
2045 [GFS2_LKS_SRTTB] = "srttb",
2046 [GFS2_LKS_SRTTVARB] = "srttvarb",
2047 [GFS2_LKS_SIRT] = "sirt",
2048 [GFS2_LKS_SIRTVAR] = "sirtvar",
2049 [GFS2_LKS_DCOUNT] = "dlm",
2050 [GFS2_LKS_QCOUNT] = "queue",
2053 #define GFS2_NR_SBSTATS (ARRAY_SIZE(gfs2_gltype) * ARRAY_SIZE(gfs2_stype))
2055 static int gfs2_sbstats_seq_show(struct seq_file *seq, void *iter_ptr)
2057 struct gfs2_sbd *sdp = seq->private;
2058 loff_t pos = *(loff_t *)iter_ptr;
2059 unsigned index = pos >> 3;
2060 unsigned subindex = pos & 0x07;
2063 if (index == 0 && subindex != 0)
2066 seq_printf(seq, "%-10s %8s:", gfs2_gltype[index],
2067 (index == 0) ? "cpu": gfs2_stype[subindex]);
2069 for_each_possible_cpu(i) {
2070 const struct gfs2_pcpu_lkstats *lkstats = per_cpu_ptr(sdp->sd_lkstats, i);
2073 seq_printf(seq, " %15u", i);
2075 seq_printf(seq, " %15llu", (unsigned long long)lkstats->
2076 lkstats[index - 1].stats[subindex]);
2078 seq_putc(seq, '\n');
2082 int __init gfs2_glock_init(void)
2086 ret = rhashtable_init(&gl_hash_table, &ht_parms);
2090 glock_workqueue = alloc_workqueue("glock_workqueue", WQ_MEM_RECLAIM |
2091 WQ_HIGHPRI | WQ_FREEZABLE, 0);
2092 if (!glock_workqueue) {
2093 rhashtable_destroy(&gl_hash_table);
2096 gfs2_delete_workqueue = alloc_workqueue("delete_workqueue",
2097 WQ_MEM_RECLAIM | WQ_FREEZABLE,
2099 if (!gfs2_delete_workqueue) {
2100 destroy_workqueue(glock_workqueue);
2101 rhashtable_destroy(&gl_hash_table);
2105 ret = register_shrinker(&glock_shrinker);
2107 destroy_workqueue(gfs2_delete_workqueue);
2108 destroy_workqueue(glock_workqueue);
2109 rhashtable_destroy(&gl_hash_table);
2113 for (i = 0; i < GLOCK_WAIT_TABLE_SIZE; i++)
2114 init_waitqueue_head(glock_wait_table + i);
2119 void gfs2_glock_exit(void)
2121 unregister_shrinker(&glock_shrinker);
2122 rhashtable_destroy(&gl_hash_table);
2123 destroy_workqueue(glock_workqueue);
2124 destroy_workqueue(gfs2_delete_workqueue);
2127 static void gfs2_glock_iter_next(struct gfs2_glock_iter *gi, loff_t n)
2129 struct gfs2_glock *gl = gi->gl;
2134 if (!lockref_put_not_zero(&gl->gl_lockref))
2135 gfs2_glock_queue_put(gl);
2138 gl = rhashtable_walk_next(&gi->hti);
2139 if (IS_ERR_OR_NULL(gl)) {
2140 if (gl == ERR_PTR(-EAGAIN)) {
2147 if (gl->gl_name.ln_sbd != gi->sdp)
2150 if (!lockref_get_not_dead(&gl->gl_lockref))
2154 if (__lockref_is_dead(&gl->gl_lockref))
2162 static void *gfs2_glock_seq_start(struct seq_file *seq, loff_t *pos)
2165 struct gfs2_glock_iter *gi = seq->private;
2169 * We can either stay where we are, skip to the next hash table
2170 * entry, or start from the beginning.
2172 if (*pos < gi->last_pos) {
2173 rhashtable_walk_exit(&gi->hti);
2174 rhashtable_walk_enter(&gl_hash_table, &gi->hti);
2177 n = *pos - gi->last_pos;
2180 rhashtable_walk_start(&gi->hti);
2182 gfs2_glock_iter_next(gi, n);
2183 gi->last_pos = *pos;
2187 static void *gfs2_glock_seq_next(struct seq_file *seq, void *iter_ptr,
2190 struct gfs2_glock_iter *gi = seq->private;
2193 gi->last_pos = *pos;
2194 gfs2_glock_iter_next(gi, 1);
2198 static void gfs2_glock_seq_stop(struct seq_file *seq, void *iter_ptr)
2201 struct gfs2_glock_iter *gi = seq->private;
2203 rhashtable_walk_stop(&gi->hti);
2206 static int gfs2_glock_seq_show(struct seq_file *seq, void *iter_ptr)
2208 dump_glock(seq, iter_ptr, false);
2212 static void *gfs2_sbstats_seq_start(struct seq_file *seq, loff_t *pos)
2215 if (*pos >= GFS2_NR_SBSTATS)
2220 static void *gfs2_sbstats_seq_next(struct seq_file *seq, void *iter_ptr,
2224 if (*pos >= GFS2_NR_SBSTATS)
2229 static void gfs2_sbstats_seq_stop(struct seq_file *seq, void *iter_ptr)
2234 static const struct seq_operations gfs2_glock_seq_ops = {
2235 .start = gfs2_glock_seq_start,
2236 .next = gfs2_glock_seq_next,
2237 .stop = gfs2_glock_seq_stop,
2238 .show = gfs2_glock_seq_show,
2241 static const struct seq_operations gfs2_glstats_seq_ops = {
2242 .start = gfs2_glock_seq_start,
2243 .next = gfs2_glock_seq_next,
2244 .stop = gfs2_glock_seq_stop,
2245 .show = gfs2_glstats_seq_show,
2248 static const struct seq_operations gfs2_sbstats_seq_ops = {
2249 .start = gfs2_sbstats_seq_start,
2250 .next = gfs2_sbstats_seq_next,
2251 .stop = gfs2_sbstats_seq_stop,
2252 .show = gfs2_sbstats_seq_show,
2255 #define GFS2_SEQ_GOODSIZE min(PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER, 65536UL)
2257 static int __gfs2_glocks_open(struct inode *inode, struct file *file,
2258 const struct seq_operations *ops)
2260 int ret = seq_open_private(file, ops, sizeof(struct gfs2_glock_iter));
2262 struct seq_file *seq = file->private_data;
2263 struct gfs2_glock_iter *gi = seq->private;
2265 gi->sdp = inode->i_private;
2266 seq->buf = kmalloc(GFS2_SEQ_GOODSIZE, GFP_KERNEL | __GFP_NOWARN);
2268 seq->size = GFS2_SEQ_GOODSIZE;
2270 * Initially, we are "before" the first hash table entry; the
2271 * first call to rhashtable_walk_next gets us the first entry.
2275 rhashtable_walk_enter(&gl_hash_table, &gi->hti);
2280 static int gfs2_glocks_open(struct inode *inode, struct file *file)
2282 return __gfs2_glocks_open(inode, file, &gfs2_glock_seq_ops);
2285 static int gfs2_glocks_release(struct inode *inode, struct file *file)
2287 struct seq_file *seq = file->private_data;
2288 struct gfs2_glock_iter *gi = seq->private;
2291 gfs2_glock_put(gi->gl);
2292 rhashtable_walk_exit(&gi->hti);
2293 return seq_release_private(inode, file);
2296 static int gfs2_glstats_open(struct inode *inode, struct file *file)
2298 return __gfs2_glocks_open(inode, file, &gfs2_glstats_seq_ops);
2301 static int gfs2_sbstats_open(struct inode *inode, struct file *file)
2303 int ret = seq_open(file, &gfs2_sbstats_seq_ops);
2305 struct seq_file *seq = file->private_data;
2306 seq->private = inode->i_private; /* sdp */
2311 static const struct file_operations gfs2_glocks_fops = {
2312 .owner = THIS_MODULE,
2313 .open = gfs2_glocks_open,
2315 .llseek = seq_lseek,
2316 .release = gfs2_glocks_release,
2319 static const struct file_operations gfs2_glstats_fops = {
2320 .owner = THIS_MODULE,
2321 .open = gfs2_glstats_open,
2323 .llseek = seq_lseek,
2324 .release = gfs2_glocks_release,
2327 static const struct file_operations gfs2_sbstats_fops = {
2328 .owner = THIS_MODULE,
2329 .open = gfs2_sbstats_open,
2331 .llseek = seq_lseek,
2332 .release = seq_release,
2335 void gfs2_create_debugfs_file(struct gfs2_sbd *sdp)
2337 sdp->debugfs_dir = debugfs_create_dir(sdp->sd_table_name, gfs2_root);
2339 debugfs_create_file("glocks", S_IFREG | S_IRUGO, sdp->debugfs_dir, sdp,
2342 debugfs_create_file("glstats", S_IFREG | S_IRUGO, sdp->debugfs_dir, sdp,
2343 &gfs2_glstats_fops);
2345 debugfs_create_file("sbstats", S_IFREG | S_IRUGO, sdp->debugfs_dir, sdp,
2346 &gfs2_sbstats_fops);
2349 void gfs2_delete_debugfs_file(struct gfs2_sbd *sdp)
2351 debugfs_remove_recursive(sdp->debugfs_dir);
2352 sdp->debugfs_dir = NULL;
2355 void gfs2_register_debugfs(void)
2357 gfs2_root = debugfs_create_dir("gfs2", NULL);
2360 void gfs2_unregister_debugfs(void)
2362 debugfs_remove(gfs2_root);