7336d0e654f7a (Thomas Gleixner 2019-05-31 01:09:56 -0700 1) // SPDX-License-Identifier: GPL-2.0-only
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 2) /*
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 3) * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
cf45b752c9f23 (Bob Peterson 2008-01-31 10:31:39 -0600 4) * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 5) */
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 6)
d77d1b58aaf44 (Joe Perches 2014-03-06 12:10:45 -0800 7) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
d77d1b58aaf44 (Joe Perches 2014-03-06 12:10:45 -0800 8)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 9) #include <linux/sched.h>
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 10) #include <linux/slab.h>
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 11) #include <linux/spinlock.h>
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 12) #include <linux/buffer_head.h>
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 13) #include <linux/delay.h>
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 14) #include <linux/sort.h>
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 15) #include <linux/hash.h>
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 16) #include <linux/jhash.h>
d0dc80dbafb5c (Steven Whitehouse 2006-03-29 14:36:49 -0500 17) #include <linux/kallsyms.h>
5c676f6d359b0 (Steven Whitehouse 2006-02-27 17:23:27 -0500 18) #include <linux/gfs2_ondisk.h>
24264434603cc (Steven Whitehouse 2006-09-11 21:40:30 -0400 19) #include <linux/list.h>
fee852e374fb3 (Steven Whitehouse 2007-01-17 15:33:23 +0000 20) #include <linux/wait.h>
95d97b7dd7d7a (Andrew Morton 2007-03-05 23:10:39 -0800 21) #include <linux/module.h>
7c0f6ba682b9c (Linus Torvalds 2016-12-24 11:46:01 -0800 22) #include <linux/uaccess.h>
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 23) #include <linux/seq_file.h>
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 24) #include <linux/debugfs.h>
8fbbfd214c853 (Steven Whitehouse 2007-08-01 13:57:10 +0100 25) #include <linux/kthread.h>
8fbbfd214c853 (Steven Whitehouse 2007-08-01 13:57:10 +0100 26) #include <linux/freezer.h>
c4f68a130fc17 (Benjamin Marzinski 2007-08-23 13:19:05 -0500 27) #include <linux/workqueue.h>
c4f68a130fc17 (Benjamin Marzinski 2007-08-23 13:19:05 -0500 28) #include <linux/jiffies.h>
bc015cb84129e (Steven Whitehouse 2011-01-19 09:30:01 +0000 29) #include <linux/rcupdate.h>
bc015cb84129e (Steven Whitehouse 2011-01-19 09:30:01 +0000 30) #include <linux/rculist_bl.h>
bc015cb84129e (Steven Whitehouse 2011-01-19 09:30:01 +0000 31) #include <linux/bit_spinlock.h>
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 32) #include <linux/percpu.h>
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 33) #include <linux/list_sort.h>
e66cf161098a6 (Steven Whitehouse 2013-10-15 15:18:08 +0100 34) #include <linux/lockref.h>
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 35) #include <linux/rhashtable.h>
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 36)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 37) #include "gfs2.h"
5c676f6d359b0 (Steven Whitehouse 2006-02-27 17:23:27 -0500 38) #include "incore.h"
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 39) #include "glock.h"
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 40) #include "glops.h"
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 41) #include "inode.h"
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 42) #include "lops.h"
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 43) #include "meta_io.h"
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 44) #include "quota.h"
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 45) #include "super.h"
5c676f6d359b0 (Steven Whitehouse 2006-02-27 17:23:27 -0500 46) #include "util.h"
813e0c46c9e2a (Steven Whitehouse 2008-11-18 13:38:48 +0000 47) #include "bmap.h"
63997775b795f (Steven Whitehouse 2009-06-12 08:49:20 +0100 48) #define CREATE_TRACE_POINTS
63997775b795f (Steven Whitehouse 2009-06-12 08:49:20 +0100 49) #include "trace_gfs2.h"
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 50)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 51) struct gfs2_glock_iter {
ba1ddcb6ca0c4 (Steven Whitehouse 2012-06-08 11:16:22 +0100 52) struct gfs2_sbd *sdp; /* incore superblock */
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 53) struct rhashtable_iter hti; /* rhashtable iterator */
ba1ddcb6ca0c4 (Steven Whitehouse 2012-06-08 11:16:22 +0100 54) struct gfs2_glock *gl; /* current glock struct */
ba1ddcb6ca0c4 (Steven Whitehouse 2012-06-08 11:16:22 +0100 55) loff_t last_pos; /* last position */
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 56) };
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 57)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 58) typedef void (*glock_examiner) (struct gfs2_glock * gl);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 59)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 60) static void do_xmote(struct gfs2_glock *gl, struct gfs2_holder *gh, unsigned int target);
c4f68a130fc17 (Benjamin Marzinski 2007-08-23 13:19:05 -0500 61)
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 62) static struct dentry *gfs2_root;
c4f68a130fc17 (Benjamin Marzinski 2007-08-23 13:19:05 -0500 63) static struct workqueue_struct *glock_workqueue;
b94a170e96dc4 (Benjamin Marzinski 2009-07-23 18:52:34 -0500 64) struct workqueue_struct *gfs2_delete_workqueue;
97cc1025b1a91 (Steven Whitehouse 2008-11-20 13:39:47 +0000 65) static LIST_HEAD(lru_list);
97cc1025b1a91 (Steven Whitehouse 2008-11-20 13:39:47 +0000 66) static atomic_t lru_count = ATOMIC_INIT(0);
eb8374e71f941 (Julia Lawall 2008-12-25 15:35:27 +0100 67) static DEFINE_SPINLOCK(lru_lock);
08bc2dbc7327e (Adrian Bunk 2006-04-28 10:59:12 -0400 68)
b6397893a5ed8 (Steven Whitehouse 2006-09-12 10:10:01 -0400 69) #define GFS2_GL_HASH_SHIFT 15
47a9a52794684 (Fabian Frederick 2016-08-02 12:05:27 -0500 70) #define GFS2_GL_HASH_SIZE BIT(GFS2_GL_HASH_SHIFT)
087efdd391f47 (Steven Whitehouse 2006-09-09 16:59:11 -0400 71)
d296b15ed5823 (Arvind Yadav 2017-08-30 07:50:03 -0500 72) static const struct rhashtable_params ht_parms = {
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 73) .nelem_hint = GFS2_GL_HASH_SIZE * 3 / 4,
972b044eeca58 (Andreas Gruenbacher 2017-03-16 09:54:57 -0400 74) .key_len = offsetofend(struct lm_lockname, ln_type),
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 75) .key_offset = offsetof(struct gfs2_glock, gl_name),
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 76) .head_offset = offsetof(struct gfs2_glock, gl_node),
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 77) };
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 78)
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 79) static struct rhashtable gl_hash_table;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 80)
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 81) #define GLOCK_WAIT_TABLE_BITS 12
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 82) #define GLOCK_WAIT_TABLE_SIZE (1 << GLOCK_WAIT_TABLE_BITS)
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 83) static wait_queue_head_t glock_wait_table[GLOCK_WAIT_TABLE_SIZE] __cacheline_aligned;
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 84)
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 85) struct wait_glock_queue {
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 86) struct lm_lockname *name;
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 87) wait_queue_entry_t wait;
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 88) };
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 89)
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 90) static int glock_wake_function(wait_queue_entry_t *wait, unsigned int mode,
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 91) int sync, void *key)
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 92) {
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 93) struct wait_glock_queue *wait_glock =
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 94) container_of(wait, struct wait_glock_queue, wait);
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 95) struct lm_lockname *wait_name = wait_glock->name;
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 96) struct lm_lockname *wake_name = key;
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 97)
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 98) if (wake_name->ln_sbd != wait_name->ln_sbd ||
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 99) wake_name->ln_number != wait_name->ln_number ||
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 100) wake_name->ln_type != wait_name->ln_type)
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 101) return 0;
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 102) return autoremove_wake_function(wait, mode, sync, key);
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 103) }
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 104)
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 105) static wait_queue_head_t *glock_waitqueue(struct lm_lockname *name)
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 106) {
605b0487f0bc1 (Andreas Gruenbacher 2019-03-06 15:41:57 +0100 107) u32 hash = jhash2((u32 *)name, ht_parms.key_len / 4, 0);
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 108)
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 109) return glock_wait_table + hash_32(hash, GLOCK_WAIT_TABLE_BITS);
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 110) }
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 111)
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 112) /**
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 113) * wake_up_glock - Wake up waiters on a glock
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 114) * @gl: the glock
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 115) */
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 116) static void wake_up_glock(struct gfs2_glock *gl)
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 117) {
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 118) wait_queue_head_t *wq = glock_waitqueue(&gl->gl_name);
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 119)
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 120) if (waitqueue_active(wq))
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 121) __wake_up(wq, TASK_NORMAL, 1, &gl->gl_name);
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 122) }
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 123)
961ae1d83d055 (Andreas Gruenbacher 2017-07-07 13:22:05 -0500 124) static void gfs2_glock_dealloc(struct rcu_head *rcu)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 125) {
961ae1d83d055 (Andreas Gruenbacher 2017-07-07 13:22:05 -0500 126) struct gfs2_glock *gl = container_of(rcu, struct gfs2_glock, gl_rcu);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 127)
15f2547b4157a (Bob Peterson 2020-01-15 12:47:46 -0600 128) kfree(gl->gl_lksb.sb_lvbptr);
15f2547b4157a (Bob Peterson 2020-01-15 12:47:46 -0600 129) if (gl->gl_ops->go_flags & GLOF_ASPACE)
bc015cb84129e (Steven Whitehouse 2011-01-19 09:30:01 +0000 130) kmem_cache_free(gfs2_glock_aspace_cachep, gl);
15f2547b4157a (Bob Peterson 2020-01-15 12:47:46 -0600 131) else
bc015cb84129e (Steven Whitehouse 2011-01-19 09:30:01 +0000 132) kmem_cache_free(gfs2_glock_cachep, gl);
961ae1d83d055 (Andreas Gruenbacher 2017-07-07 13:22:05 -0500 133) }
961ae1d83d055 (Andreas Gruenbacher 2017-07-07 13:22:05 -0500 134)
a72d2401f54b7 (Bob Peterson 2019-06-13 13:28:45 -0500 135) /**
a72d2401f54b7 (Bob Peterson 2019-06-13 13:28:45 -0500 136) * glock_blocked_by_withdraw - determine if we can still use a glock
a72d2401f54b7 (Bob Peterson 2019-06-13 13:28:45 -0500 137) * @gl: the glock
a72d2401f54b7 (Bob Peterson 2019-06-13 13:28:45 -0500 138) *
a72d2401f54b7 (Bob Peterson 2019-06-13 13:28:45 -0500 139) * We need to allow some glocks to be enqueued, dequeued, promoted, and demoted
a72d2401f54b7 (Bob Peterson 2019-06-13 13:28:45 -0500 140) * when we're withdrawn. For example, to maintain metadata integrity, we should
a72d2401f54b7 (Bob Peterson 2019-06-13 13:28:45 -0500 141) * disallow the use of inode and rgrp glocks when withdrawn. Other glocks, like
a72d2401f54b7 (Bob Peterson 2019-06-13 13:28:45 -0500 142) * iopen or the transaction glocks may be safely used because none of their
a72d2401f54b7 (Bob Peterson 2019-06-13 13:28:45 -0500 143) * metadata goes through the journal. So in general, we should disallow all
a72d2401f54b7 (Bob Peterson 2019-06-13 13:28:45 -0500 144) * glocks that are journaled, and allow all the others. One exception is:
a72d2401f54b7 (Bob Peterson 2019-06-13 13:28:45 -0500 145) * we need to allow our active journal to be promoted and demoted so others
a72d2401f54b7 (Bob Peterson 2019-06-13 13:28:45 -0500 146) * may recover it and we can reacquire it when they're done.
a72d2401f54b7 (Bob Peterson 2019-06-13 13:28:45 -0500 147) */
a72d2401f54b7 (Bob Peterson 2019-06-13 13:28:45 -0500 148) static bool glock_blocked_by_withdraw(struct gfs2_glock *gl)
a72d2401f54b7 (Bob Peterson 2019-06-13 13:28:45 -0500 149) {
a72d2401f54b7 (Bob Peterson 2019-06-13 13:28:45 -0500 150) struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
a72d2401f54b7 (Bob Peterson 2019-06-13 13:28:45 -0500 151)
a72d2401f54b7 (Bob Peterson 2019-06-13 13:28:45 -0500 152) if (likely(!gfs2_withdrawn(sdp)))
a72d2401f54b7 (Bob Peterson 2019-06-13 13:28:45 -0500 153) return false;
a72d2401f54b7 (Bob Peterson 2019-06-13 13:28:45 -0500 154) if (gl->gl_ops->go_flags & GLOF_NONDISK)
a72d2401f54b7 (Bob Peterson 2019-06-13 13:28:45 -0500 155) return false;
a72d2401f54b7 (Bob Peterson 2019-06-13 13:28:45 -0500 156) if (!sdp->sd_jdesc ||
a72d2401f54b7 (Bob Peterson 2019-06-13 13:28:45 -0500 157) gl->gl_name.ln_number == sdp->sd_jdesc->jd_no_addr)
a72d2401f54b7 (Bob Peterson 2019-06-13 13:28:45 -0500 158) return false;
a72d2401f54b7 (Bob Peterson 2019-06-13 13:28:45 -0500 159) return true;
a72d2401f54b7 (Bob Peterson 2019-06-13 13:28:45 -0500 160) }
a72d2401f54b7 (Bob Peterson 2019-06-13 13:28:45 -0500 161)
961ae1d83d055 (Andreas Gruenbacher 2017-07-07 13:22:05 -0500 162) void gfs2_glock_free(struct gfs2_glock *gl)
961ae1d83d055 (Andreas Gruenbacher 2017-07-07 13:22:05 -0500 163) {
961ae1d83d055 (Andreas Gruenbacher 2017-07-07 13:22:05 -0500 164) struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
961ae1d83d055 (Andreas Gruenbacher 2017-07-07 13:22:05 -0500 165)
ea4e61c7f46d3 (Bob Peterson 2020-05-23 08:13:50 -0500 166) gfs2_glock_assert_withdraw(gl, atomic_read(&gl->gl_revokes) == 0);
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 167) rhashtable_remove_fast(&gl_hash_table, &gl->gl_node, ht_parms);
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 168) smp_mb();
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 169) wake_up_glock(gl);
961ae1d83d055 (Andreas Gruenbacher 2017-07-07 13:22:05 -0500 170) call_rcu(&gl->gl_rcu, gfs2_glock_dealloc);
bc015cb84129e (Steven Whitehouse 2011-01-19 09:30:01 +0000 171) if (atomic_dec_and_test(&sdp->sd_glock_disposal))
bc015cb84129e (Steven Whitehouse 2011-01-19 09:30:01 +0000 172) wake_up(&sdp->sd_glock_wait);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 173) }
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 174)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 175) /**
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 176) * gfs2_glock_hold() - increment reference count on glock
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 177) * @gl: The glock to hold
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 178) *
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 179) */
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 180)
71c1b2136835c (Andreas Gruenbacher 2017-08-01 11:45:23 -0500 181) void gfs2_glock_hold(struct gfs2_glock *gl)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 182) {
e66cf161098a6 (Steven Whitehouse 2013-10-15 15:18:08 +0100 183) GLOCK_BUG_ON(gl, __lockref_is_dead(&gl->gl_lockref));
e66cf161098a6 (Steven Whitehouse 2013-10-15 15:18:08 +0100 184) lockref_get(&gl->gl_lockref);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 185) }
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 186)
8ff22a6f9bdaa (Benjamin Marzinski 2009-07-10 18:04:24 -0500 187) /**
8ff22a6f9bdaa (Benjamin Marzinski 2009-07-10 18:04:24 -0500 188) * demote_ok - Check to see if it's ok to unlock a glock
8ff22a6f9bdaa (Benjamin Marzinski 2009-07-10 18:04:24 -0500 189) * @gl: the glock
8ff22a6f9bdaa (Benjamin Marzinski 2009-07-10 18:04:24 -0500 190) *
8ff22a6f9bdaa (Benjamin Marzinski 2009-07-10 18:04:24 -0500 191) * Returns: 1 if it's ok
8ff22a6f9bdaa (Benjamin Marzinski 2009-07-10 18:04:24 -0500 192) */
8ff22a6f9bdaa (Benjamin Marzinski 2009-07-10 18:04:24 -0500 193)
8ff22a6f9bdaa (Benjamin Marzinski 2009-07-10 18:04:24 -0500 194) static int demote_ok(const struct gfs2_glock *gl)
8ff22a6f9bdaa (Benjamin Marzinski 2009-07-10 18:04:24 -0500 195) {
8ff22a6f9bdaa (Benjamin Marzinski 2009-07-10 18:04:24 -0500 196) const struct gfs2_glock_operations *glops = gl->gl_ops;
8ff22a6f9bdaa (Benjamin Marzinski 2009-07-10 18:04:24 -0500 197)
8ff22a6f9bdaa (Benjamin Marzinski 2009-07-10 18:04:24 -0500 198) if (gl->gl_state == LM_ST_UNLOCKED)
8ff22a6f9bdaa (Benjamin Marzinski 2009-07-10 18:04:24 -0500 199) return 0;
f42ab0852946c (Steven Whitehouse 2011-04-14 16:50:31 +0100 200) if (!list_empty(&gl->gl_holders))
8ff22a6f9bdaa (Benjamin Marzinski 2009-07-10 18:04:24 -0500 201) return 0;
8ff22a6f9bdaa (Benjamin Marzinski 2009-07-10 18:04:24 -0500 202) if (glops->go_demote_ok)
8ff22a6f9bdaa (Benjamin Marzinski 2009-07-10 18:04:24 -0500 203) return glops->go_demote_ok(gl);
8ff22a6f9bdaa (Benjamin Marzinski 2009-07-10 18:04:24 -0500 204) return 1;
8ff22a6f9bdaa (Benjamin Marzinski 2009-07-10 18:04:24 -0500 205) }
8ff22a6f9bdaa (Benjamin Marzinski 2009-07-10 18:04:24 -0500 206)
bc015cb84129e (Steven Whitehouse 2011-01-19 09:30:01 +0000 207)
29687a2ac8dfc (Steven Whitehouse 2011-03-30 16:33:25 +0100 208) void gfs2_glock_add_to_lru(struct gfs2_glock *gl)
29687a2ac8dfc (Steven Whitehouse 2011-03-30 16:33:25 +0100 209) {
7881ef3f33bb8 (Ross Lagerwall 2019-03-27 17:09:17 +0000 210) if (!(gl->gl_ops->go_flags & GLOF_LRU))
7881ef3f33bb8 (Ross Lagerwall 2019-03-27 17:09:17 +0000 211) return;
7881ef3f33bb8 (Ross Lagerwall 2019-03-27 17:09:17 +0000 212)
29687a2ac8dfc (Steven Whitehouse 2011-03-30 16:33:25 +0100 213) spin_lock(&lru_lock);
29687a2ac8dfc (Steven Whitehouse 2011-03-30 16:33:25 +0100 214)
7881ef3f33bb8 (Ross Lagerwall 2019-03-27 17:09:17 +0000 215) list_del(&gl->gl_lru);
7881ef3f33bb8 (Ross Lagerwall 2019-03-27 17:09:17 +0000 216) list_add_tail(&gl->gl_lru, &lru_list);
7881ef3f33bb8 (Ross Lagerwall 2019-03-27 17:09:17 +0000 217)
7881ef3f33bb8 (Ross Lagerwall 2019-03-27 17:09:17 +0000 218) if (!test_bit(GLF_LRU, &gl->gl_flags)) {
7881ef3f33bb8 (Ross Lagerwall 2019-03-27 17:09:17 +0000 219) set_bit(GLF_LRU, &gl->gl_flags);
29687a2ac8dfc (Steven Whitehouse 2011-03-30 16:33:25 +0100 220) atomic_inc(&lru_count);
7881ef3f33bb8 (Ross Lagerwall 2019-03-27 17:09:17 +0000 221) }
29687a2ac8dfc (Steven Whitehouse 2011-03-30 16:33:25 +0100 222)
29687a2ac8dfc (Steven Whitehouse 2011-03-30 16:33:25 +0100 223) spin_unlock(&lru_lock);
29687a2ac8dfc (Steven Whitehouse 2011-03-30 16:33:25 +0100 224) }
29687a2ac8dfc (Steven Whitehouse 2011-03-30 16:33:25 +0100 225)
8f6cb409f016e (Bob Peterson 2015-01-05 13:25:10 -0500 226) static void gfs2_glock_remove_from_lru(struct gfs2_glock *gl)
f42ab0852946c (Steven Whitehouse 2011-04-14 16:50:31 +0100 227) {
645ebd49f0583 (Bob Peterson 2017-07-26 10:57:35 -0500 228) if (!(gl->gl_ops->go_flags & GLOF_LRU))
645ebd49f0583 (Bob Peterson 2017-07-26 10:57:35 -0500 229) return;
645ebd49f0583 (Bob Peterson 2017-07-26 10:57:35 -0500 230)
8f6cb409f016e (Bob Peterson 2015-01-05 13:25:10 -0500 231) spin_lock(&lru_lock);
7881ef3f33bb8 (Ross Lagerwall 2019-03-27 17:09:17 +0000 232) if (test_bit(GLF_LRU, &gl->gl_flags)) {
f42ab0852946c (Steven Whitehouse 2011-04-14 16:50:31 +0100 233) list_del_init(&gl->gl_lru);
f42ab0852946c (Steven Whitehouse 2011-04-14 16:50:31 +0100 234) atomic_dec(&lru_count);
f42ab0852946c (Steven Whitehouse 2011-04-14 16:50:31 +0100 235) clear_bit(GLF_LRU, &gl->gl_flags);
f42ab0852946c (Steven Whitehouse 2011-04-14 16:50:31 +0100 236) }
f42ab0852946c (Steven Whitehouse 2011-04-14 16:50:31 +0100 237) spin_unlock(&lru_lock);
f42ab0852946c (Steven Whitehouse 2011-04-14 16:50:31 +0100 238) }
f42ab0852946c (Steven Whitehouse 2011-04-14 16:50:31 +0100 239)
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 240) /*
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 241) * Enqueue the glock on the work queue. Passes one glock reference on to the
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 242) * work queue.
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 243) */
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 244) static void __gfs2_glock_queue_work(struct gfs2_glock *gl, unsigned long delay) {
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 245) if (!queue_delayed_work(glock_workqueue, &gl->gl_work, delay)) {
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 246) /*
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 247) * We are holding the lockref spinlock, and the work was still
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 248) * queued above. The queued work (glock_work_func) takes that
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 249) * spinlock before dropping its glock reference(s), so it
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 250) * cannot have dropped them in the meantime.
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 251) */
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 252) GLOCK_BUG_ON(gl, gl->gl_lockref.count < 2);
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 253) gl->gl_lockref.count--;
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 254) }
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 255) }
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 256)
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 257) static void gfs2_glock_queue_work(struct gfs2_glock *gl, unsigned long delay) {
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 258) spin_lock(&gl->gl_lockref.lock);
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 259) __gfs2_glock_queue_work(gl, delay);
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 260) spin_unlock(&gl->gl_lockref.lock);
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 261) }
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 262)
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 263) static void __gfs2_glock_put(struct gfs2_glock *gl)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 264) {
15562c439d0a1 (Bob Peterson 2015-03-16 11:52:05 -0500 265) struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
bc015cb84129e (Steven Whitehouse 2011-01-19 09:30:01 +0000 266) struct address_space *mapping = gfs2_glock2aspace(gl);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 267)
e66cf161098a6 (Steven Whitehouse 2013-10-15 15:18:08 +0100 268) lockref_mark_dead(&gl->gl_lockref);
e66cf161098a6 (Steven Whitehouse 2013-10-15 15:18:08 +0100 269)
8f6cb409f016e (Bob Peterson 2015-01-05 13:25:10 -0500 270) gfs2_glock_remove_from_lru(gl);
e66cf161098a6 (Steven Whitehouse 2013-10-15 15:18:08 +0100 271) spin_unlock(&gl->gl_lockref.lock);
e66cf161098a6 (Steven Whitehouse 2013-10-15 15:18:08 +0100 272) GLOCK_BUG_ON(gl, !list_empty(&gl->gl_holders));
ee1e2c773e4f4 (Bob Peterson 2020-09-16 11:06:23 -0500 273) if (mapping) {
ee1e2c773e4f4 (Bob Peterson 2020-09-16 11:06:23 -0500 274) truncate_inode_pages_final(mapping);
ee1e2c773e4f4 (Bob Peterson 2020-09-16 11:06:23 -0500 275) if (!gfs2_withdrawn(sdp))
7716506adac46 (Matthew Wilcox (Oracle) 2021-05-04 18:32:45 -0700 276) GLOCK_BUG_ON(gl, !mapping_empty(mapping));
ee1e2c773e4f4 (Bob Peterson 2020-09-16 11:06:23 -0500 277) }
e66cf161098a6 (Steven Whitehouse 2013-10-15 15:18:08 +0100 278) trace_gfs2_glock_put(gl);
e66cf161098a6 (Steven Whitehouse 2013-10-15 15:18:08 +0100 279) sdp->sd_lockstruct.ls_ops->lm_put_lock(gl);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 280) }
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 281)
71c1b2136835c (Andreas Gruenbacher 2017-08-01 11:45:23 -0500 282) /*
71c1b2136835c (Andreas Gruenbacher 2017-08-01 11:45:23 -0500 283) * Cause the glock to be put in work queue context.
71c1b2136835c (Andreas Gruenbacher 2017-08-01 11:45:23 -0500 284) */
71c1b2136835c (Andreas Gruenbacher 2017-08-01 11:45:23 -0500 285) void gfs2_glock_queue_put(struct gfs2_glock *gl)
71c1b2136835c (Andreas Gruenbacher 2017-08-01 11:45:23 -0500 286) {
71c1b2136835c (Andreas Gruenbacher 2017-08-01 11:45:23 -0500 287) gfs2_glock_queue_work(gl, 0);
71c1b2136835c (Andreas Gruenbacher 2017-08-01 11:45:23 -0500 288) }
71c1b2136835c (Andreas Gruenbacher 2017-08-01 11:45:23 -0500 289)
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 290) /**
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 291) * gfs2_glock_put() - Decrement reference count on glock
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 292) * @gl: The glock to put
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 293) *
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 294) */
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 295)
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 296) void gfs2_glock_put(struct gfs2_glock *gl)
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 297) {
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 298) if (lockref_put_or_lock(&gl->gl_lockref))
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 299) return;
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 300)
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 301) __gfs2_glock_put(gl);
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 302) }
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 303)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 304) /**
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 305) * may_grant - check if its ok to grant a new lock
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 306) * @gl: The glock
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 307) * @gh: The lock request which we wish to grant
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 308) *
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 309) * Returns: true if its ok to grant the lock
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 310) */
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 311)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 312) static inline int may_grant(const struct gfs2_glock *gl, const struct gfs2_holder *gh)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 313) {
969183bc68bc2 (Andreas Gruenbacher 2020-02-03 19:22:45 +0100 314) const struct gfs2_holder *gh_head = list_first_entry(&gl->gl_holders, const struct gfs2_holder, gh_list);
06e908cd9ead1 (Bob Peterson 2018-04-18 13:58:19 -0700 315)
06e908cd9ead1 (Bob Peterson 2018-04-18 13:58:19 -0700 316) if (gh != gh_head) {
06e908cd9ead1 (Bob Peterson 2018-04-18 13:58:19 -0700 317) /**
06e908cd9ead1 (Bob Peterson 2018-04-18 13:58:19 -0700 318) * Here we make a special exception to grant holders who agree
06e908cd9ead1 (Bob Peterson 2018-04-18 13:58:19 -0700 319) * to share the EX lock with other holders who also have the
06e908cd9ead1 (Bob Peterson 2018-04-18 13:58:19 -0700 320) * bit set. If the original holder has the LM_FLAG_NODE_SCOPE bit
06e908cd9ead1 (Bob Peterson 2018-04-18 13:58:19 -0700 321) * is set, we grant more holders with the bit set.
06e908cd9ead1 (Bob Peterson 2018-04-18 13:58:19 -0700 322) */
06e908cd9ead1 (Bob Peterson 2018-04-18 13:58:19 -0700 323) if (gh_head->gh_state == LM_ST_EXCLUSIVE &&
06e908cd9ead1 (Bob Peterson 2018-04-18 13:58:19 -0700 324) (gh_head->gh_flags & LM_FLAG_NODE_SCOPE) &&
06e908cd9ead1 (Bob Peterson 2018-04-18 13:58:19 -0700 325) gh->gh_state == LM_ST_EXCLUSIVE &&
06e908cd9ead1 (Bob Peterson 2018-04-18 13:58:19 -0700 326) (gh->gh_flags & LM_FLAG_NODE_SCOPE))
06e908cd9ead1 (Bob Peterson 2018-04-18 13:58:19 -0700 327) return 1;
06e908cd9ead1 (Bob Peterson 2018-04-18 13:58:19 -0700 328) if ((gh->gh_state == LM_ST_EXCLUSIVE ||
06e908cd9ead1 (Bob Peterson 2018-04-18 13:58:19 -0700 329) gh_head->gh_state == LM_ST_EXCLUSIVE))
06e908cd9ead1 (Bob Peterson 2018-04-18 13:58:19 -0700 330) return 0;
06e908cd9ead1 (Bob Peterson 2018-04-18 13:58:19 -0700 331) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 332) if (gl->gl_state == gh->gh_state)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 333) return 1;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 334) if (gh->gh_flags & GL_EXACT)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 335) return 0;
209806aba9d54 (Steven Whitehouse 2008-07-07 10:07:28 +0100 336) if (gl->gl_state == LM_ST_EXCLUSIVE) {
209806aba9d54 (Steven Whitehouse 2008-07-07 10:07:28 +0100 337) if (gh->gh_state == LM_ST_SHARED && gh_head->gh_state == LM_ST_SHARED)
209806aba9d54 (Steven Whitehouse 2008-07-07 10:07:28 +0100 338) return 1;
209806aba9d54 (Steven Whitehouse 2008-07-07 10:07:28 +0100 339) if (gh->gh_state == LM_ST_DEFERRED && gh_head->gh_state == LM_ST_DEFERRED)
209806aba9d54 (Steven Whitehouse 2008-07-07 10:07:28 +0100 340) return 1;
209806aba9d54 (Steven Whitehouse 2008-07-07 10:07:28 +0100 341) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 342) if (gl->gl_state != LM_ST_UNLOCKED && (gh->gh_flags & LM_FLAG_ANY))
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 343) return 1;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 344) return 0;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 345) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 346)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 347) static void gfs2_holder_wake(struct gfs2_holder *gh)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 348) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 349) clear_bit(HIF_WAIT, &gh->gh_iflags);
4e857c58efeb9 (Peter Zijlstra 2014-03-17 18:06:10 +0100 350) smp_mb__after_atomic();
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 351) wake_up_bit(&gh->gh_iflags, HIF_WAIT);
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 352) if (gh->gh_flags & GL_ASYNC) {
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 353) struct gfs2_sbd *sdp = gh->gh_gl->gl_name.ln_sbd;
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 354)
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 355) wake_up(&sdp->sd_async_glock_wait);
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 356) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 357) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 358)
d5341a9241670 (Steven Whitehouse 2010-07-23 14:05:51 +0100 359) /**
d5341a9241670 (Steven Whitehouse 2010-07-23 14:05:51 +0100 360) * do_error - Something unexpected has happened during a lock request
c551f66c5dfef (Lee Jones 2021-03-30 17:44:29 +0100 361) * @gl: The glock
c551f66c5dfef (Lee Jones 2021-03-30 17:44:29 +0100 362) * @ret: The status from the DLM
d5341a9241670 (Steven Whitehouse 2010-07-23 14:05:51 +0100 363) */
d5341a9241670 (Steven Whitehouse 2010-07-23 14:05:51 +0100 364)
a527b38e14752 (Denys Vlasenko 2016-04-12 12:39:12 -0400 365) static void do_error(struct gfs2_glock *gl, const int ret)
d5341a9241670 (Steven Whitehouse 2010-07-23 14:05:51 +0100 366) {
d5341a9241670 (Steven Whitehouse 2010-07-23 14:05:51 +0100 367) struct gfs2_holder *gh, *tmp;
d5341a9241670 (Steven Whitehouse 2010-07-23 14:05:51 +0100 368)
d5341a9241670 (Steven Whitehouse 2010-07-23 14:05:51 +0100 369) list_for_each_entry_safe(gh, tmp, &gl->gl_holders, gh_list) {
d5341a9241670 (Steven Whitehouse 2010-07-23 14:05:51 +0100 370) if (test_bit(HIF_HOLDER, &gh->gh_iflags))
d5341a9241670 (Steven Whitehouse 2010-07-23 14:05:51 +0100 371) continue;
d5341a9241670 (Steven Whitehouse 2010-07-23 14:05:51 +0100 372) if (ret & LM_OUT_ERROR)
d5341a9241670 (Steven Whitehouse 2010-07-23 14:05:51 +0100 373) gh->gh_error = -EIO;
d5341a9241670 (Steven Whitehouse 2010-07-23 14:05:51 +0100 374) else if (gh->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB))
d5341a9241670 (Steven Whitehouse 2010-07-23 14:05:51 +0100 375) gh->gh_error = GLR_TRYFAILED;
d5341a9241670 (Steven Whitehouse 2010-07-23 14:05:51 +0100 376) else
d5341a9241670 (Steven Whitehouse 2010-07-23 14:05:51 +0100 377) continue;
d5341a9241670 (Steven Whitehouse 2010-07-23 14:05:51 +0100 378) list_del_init(&gh->gh_list);
d5341a9241670 (Steven Whitehouse 2010-07-23 14:05:51 +0100 379) trace_gfs2_glock_queue(gh, 0);
d5341a9241670 (Steven Whitehouse 2010-07-23 14:05:51 +0100 380) gfs2_holder_wake(gh);
d5341a9241670 (Steven Whitehouse 2010-07-23 14:05:51 +0100 381) }
d5341a9241670 (Steven Whitehouse 2010-07-23 14:05:51 +0100 382) }
d5341a9241670 (Steven Whitehouse 2010-07-23 14:05:51 +0100 383)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 384) /**
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 385) * do_promote - promote as many requests as possible on the current queue
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 386) * @gl: The glock
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 387) *
813e0c46c9e2a (Steven Whitehouse 2008-11-18 13:38:48 +0000 388) * Returns: 1 if there is a blocked holder at the head of the list, or 2
813e0c46c9e2a (Steven Whitehouse 2008-11-18 13:38:48 +0000 389) * if a type specific operation is underway.
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 390) */
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 391)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 392) static int do_promote(struct gfs2_glock *gl)
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 393) __releases(&gl->gl_lockref.lock)
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 394) __acquires(&gl->gl_lockref.lock)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 395) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 396) const struct gfs2_glock_operations *glops = gl->gl_ops;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 397) struct gfs2_holder *gh, *tmp;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 398) int ret;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 399)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 400) restart:
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 401) list_for_each_entry_safe(gh, tmp, &gl->gl_holders, gh_list) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 402) if (test_bit(HIF_HOLDER, &gh->gh_iflags))
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 403) continue;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 404) if (may_grant(gl, gh)) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 405) if (gh->gh_list.prev == &gl->gl_holders &&
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 406) glops->go_lock) {
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 407) spin_unlock(&gl->gl_lockref.lock);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 408) /* FIXME: eliminate this eventually */
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 409) ret = glops->go_lock(gh);
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 410) spin_lock(&gl->gl_lockref.lock);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 411) if (ret) {
813e0c46c9e2a (Steven Whitehouse 2008-11-18 13:38:48 +0000 412) if (ret == 1)
813e0c46c9e2a (Steven Whitehouse 2008-11-18 13:38:48 +0000 413) return 2;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 414) gh->gh_error = ret;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 415) list_del_init(&gh->gh_list);
63997775b795f (Steven Whitehouse 2009-06-12 08:49:20 +0100 416) trace_gfs2_glock_queue(gh, 0);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 417) gfs2_holder_wake(gh);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 418) goto restart;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 419) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 420) set_bit(HIF_HOLDER, &gh->gh_iflags);
63997775b795f (Steven Whitehouse 2009-06-12 08:49:20 +0100 421) trace_gfs2_promote(gh, 1);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 422) gfs2_holder_wake(gh);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 423) goto restart;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 424) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 425) set_bit(HIF_HOLDER, &gh->gh_iflags);
63997775b795f (Steven Whitehouse 2009-06-12 08:49:20 +0100 426) trace_gfs2_promote(gh, 0);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 427) gfs2_holder_wake(gh);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 428) continue;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 429) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 430) if (gh->gh_list.prev == &gl->gl_holders)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 431) return 1;
d5341a9241670 (Steven Whitehouse 2010-07-23 14:05:51 +0100 432) do_error(gl, 0);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 433) break;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 434) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 435) return 0;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 436) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 437)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 438) /**
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 439) * find_first_waiter - find the first gh that's waiting for the glock
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 440) * @gl: the glock
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 441) */
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 442)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 443) static inline struct gfs2_holder *find_first_waiter(const struct gfs2_glock *gl)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 444) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 445) struct gfs2_holder *gh;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 446)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 447) list_for_each_entry(gh, &gl->gl_holders, gh_list) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 448) if (!test_bit(HIF_HOLDER, &gh->gh_iflags))
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 449) return gh;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 450) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 451) return NULL;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 452) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 453)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 454) /**
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 455) * state_change - record that the glock is now in a different state
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 456) * @gl: the glock
c551f66c5dfef (Lee Jones 2021-03-30 17:44:29 +0100 457) * @new_state: the new state
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 458) */
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 459)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 460) static void state_change(struct gfs2_glock *gl, unsigned int new_state)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 461) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 462) int held1, held2;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 463)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 464) held1 = (gl->gl_state != LM_ST_UNLOCKED);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 465) held2 = (new_state != LM_ST_UNLOCKED);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 466)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 467) if (held1 != held2) {
e66cf161098a6 (Steven Whitehouse 2013-10-15 15:18:08 +0100 468) GLOCK_BUG_ON(gl, __lockref_is_dead(&gl->gl_lockref));
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 469) if (held2)
e66cf161098a6 (Steven Whitehouse 2013-10-15 15:18:08 +0100 470) gl->gl_lockref.count++;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 471) else
e66cf161098a6 (Steven Whitehouse 2013-10-15 15:18:08 +0100 472) gl->gl_lockref.count--;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 473) }
7cf8dcd3b68a7 (Bob Peterson 2011-06-15 11:41:48 -0400 474) if (new_state != gl->gl_target)
7cf8dcd3b68a7 (Bob Peterson 2011-06-15 11:41:48 -0400 475) /* shorten our minimum hold time */
7cf8dcd3b68a7 (Bob Peterson 2011-06-15 11:41:48 -0400 476) gl->gl_hold_time = max(gl->gl_hold_time - GL_GLOCK_HOLD_DECR,
7cf8dcd3b68a7 (Bob Peterson 2011-06-15 11:41:48 -0400 477) GL_GLOCK_MIN_HOLD);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 478) gl->gl_state = new_state;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 479) gl->gl_tchange = jiffies;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 480) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 481)
35b6f8fbcf9b2 (Andreas Gruenbacher 2020-01-17 13:48:49 +0100 482) static void gfs2_set_demote(struct gfs2_glock *gl)
35b6f8fbcf9b2 (Andreas Gruenbacher 2020-01-17 13:48:49 +0100 483) {
35b6f8fbcf9b2 (Andreas Gruenbacher 2020-01-17 13:48:49 +0100 484) struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
35b6f8fbcf9b2 (Andreas Gruenbacher 2020-01-17 13:48:49 +0100 485)
35b6f8fbcf9b2 (Andreas Gruenbacher 2020-01-17 13:48:49 +0100 486) set_bit(GLF_DEMOTE, &gl->gl_flags);
35b6f8fbcf9b2 (Andreas Gruenbacher 2020-01-17 13:48:49 +0100 487) smp_mb();
35b6f8fbcf9b2 (Andreas Gruenbacher 2020-01-17 13:48:49 +0100 488) wake_up(&sdp->sd_async_glock_wait);
35b6f8fbcf9b2 (Andreas Gruenbacher 2020-01-17 13:48:49 +0100 489) }
35b6f8fbcf9b2 (Andreas Gruenbacher 2020-01-17 13:48:49 +0100 490)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 491) static void gfs2_demote_wake(struct gfs2_glock *gl)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 492) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 493) gl->gl_demote_state = LM_ST_EXCLUSIVE;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 494) clear_bit(GLF_DEMOTE, &gl->gl_flags);
4e857c58efeb9 (Peter Zijlstra 2014-03-17 18:06:10 +0100 495) smp_mb__after_atomic();
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 496) wake_up_bit(&gl->gl_flags, GLF_DEMOTE);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 497) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 498)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 499) /**
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 500) * finish_xmote - The DLM has replied to one of our lock requests
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 501) * @gl: The glock
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 502) * @ret: The status from the DLM
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 503) *
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 504) */
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 505)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 506) static void finish_xmote(struct gfs2_glock *gl, unsigned int ret)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 507) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 508) const struct gfs2_glock_operations *glops = gl->gl_ops;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 509) struct gfs2_holder *gh;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 510) unsigned state = ret & LM_OUT_ST_MASK;
813e0c46c9e2a (Steven Whitehouse 2008-11-18 13:38:48 +0000 511) int rv;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 512)
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 513) spin_lock(&gl->gl_lockref.lock);
63997775b795f (Steven Whitehouse 2009-06-12 08:49:20 +0100 514) trace_gfs2_glock_state_change(gl, state);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 515) state_change(gl, state);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 516) gh = find_first_waiter(gl);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 517)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 518) /* Demote to UN request arrived during demote to SH or DF */
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 519) if (test_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags) &&
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 520) state != LM_ST_UNLOCKED && gl->gl_demote_state == LM_ST_UNLOCKED)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 521) gl->gl_target = LM_ST_UNLOCKED;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 522)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 523) /* Check for state != intended state */
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 524) if (unlikely(state != gl->gl_target)) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 525) if (gh && !test_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags)) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 526) /* move to back of queue and try next entry */
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 527) if (ret & LM_OUT_CANCELED) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 528) if ((gh->gh_flags & LM_FLAG_PRIORITY) == 0)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 529) list_move_tail(&gh->gh_list, &gl->gl_holders);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 530) gh = find_first_waiter(gl);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 531) gl->gl_target = gh->gh_state;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 532) goto retry;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 533) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 534) /* Some error or failed "try lock" - report it */
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 535) if ((ret & LM_OUT_ERROR) ||
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 536) (gh->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB))) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 537) gl->gl_target = gl->gl_state;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 538) do_error(gl, ret);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 539) goto out;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 540) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 541) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 542) switch(state) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 543) /* Unlocked due to conversion deadlock, try again */
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 544) case LM_ST_UNLOCKED:
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 545) retry:
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 546) do_xmote(gl, gh, gl->gl_target);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 547) break;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 548) /* Conversion fails, unlock and try again */
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 549) case LM_ST_SHARED:
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 550) case LM_ST_DEFERRED:
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 551) do_xmote(gl, gh, LM_ST_UNLOCKED);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 552) break;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 553) default: /* Everything else */
e54c78a27fcde (Bob Peterson 2018-10-03 08:47:36 -0500 554) fs_err(gl->gl_name.ln_sbd, "wanted %u got %u\n",
e54c78a27fcde (Bob Peterson 2018-10-03 08:47:36 -0500 555) gl->gl_target, state);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 556) GLOCK_BUG_ON(gl, 1);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 557) }
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 558) spin_unlock(&gl->gl_lockref.lock);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 559) return;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 560) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 561)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 562) /* Fast path - we got what we asked for */
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 563) if (test_and_clear_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags))
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 564) gfs2_demote_wake(gl);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 565) if (state != LM_ST_UNLOCKED) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 566) if (glops->go_xmote_bh) {
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 567) spin_unlock(&gl->gl_lockref.lock);
f68effb308c73 (Bob Peterson 2021-03-19 07:56:44 -0400 568) rv = glops->go_xmote_bh(gl);
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 569) spin_lock(&gl->gl_lockref.lock);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 570) if (rv) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 571) do_error(gl, rv);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 572) goto out;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 573) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 574) }
813e0c46c9e2a (Steven Whitehouse 2008-11-18 13:38:48 +0000 575) rv = do_promote(gl);
813e0c46c9e2a (Steven Whitehouse 2008-11-18 13:38:48 +0000 576) if (rv == 2)
813e0c46c9e2a (Steven Whitehouse 2008-11-18 13:38:48 +0000 577) goto out_locked;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 578) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 579) out:
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 580) clear_bit(GLF_LOCK, &gl->gl_flags);
813e0c46c9e2a (Steven Whitehouse 2008-11-18 13:38:48 +0000 581) out_locked:
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 582) spin_unlock(&gl->gl_lockref.lock);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 583) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 584)
865cc3e9cc0b1 (Bob Peterson 2021-05-18 09:14:31 -0400 585) static bool is_system_glock(struct gfs2_glock *gl)
865cc3e9cc0b1 (Bob Peterson 2021-05-18 09:14:31 -0400 586) {
865cc3e9cc0b1 (Bob Peterson 2021-05-18 09:14:31 -0400 587) struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
865cc3e9cc0b1 (Bob Peterson 2021-05-18 09:14:31 -0400 588) struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode);
865cc3e9cc0b1 (Bob Peterson 2021-05-18 09:14:31 -0400 589)
865cc3e9cc0b1 (Bob Peterson 2021-05-18 09:14:31 -0400 590) if (gl == m_ip->i_gl)
865cc3e9cc0b1 (Bob Peterson 2021-05-18 09:14:31 -0400 591) return true;
865cc3e9cc0b1 (Bob Peterson 2021-05-18 09:14:31 -0400 592) return false;
865cc3e9cc0b1 (Bob Peterson 2021-05-18 09:14:31 -0400 593) }
865cc3e9cc0b1 (Bob Peterson 2021-05-18 09:14:31 -0400 594)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 595) /**
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 596) * do_xmote - Calls the DLM to change the state of a lock
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 597) * @gl: The lock state
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 598) * @gh: The holder (only for promotes)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 599) * @target: The target lock state
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 600) *
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 601) */
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 602)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 603) static void do_xmote(struct gfs2_glock *gl, struct gfs2_holder *gh, unsigned int target)
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 604) __releases(&gl->gl_lockref.lock)
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 605) __acquires(&gl->gl_lockref.lock)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 606) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 607) const struct gfs2_glock_operations *glops = gl->gl_ops;
15562c439d0a1 (Bob Peterson 2015-03-16 11:52:05 -0500 608) struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
b58bf407ca466 (Bob Peterson 2015-07-24 09:45:43 -0500 609) unsigned int lck_flags = (unsigned int)(gh ? gh->gh_flags : 0);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 610) int ret;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 611)
601ef0d52e961 (Bob Peterson 2020-01-28 20:23:45 +0100 612) if (target != LM_ST_UNLOCKED && glock_blocked_by_withdraw(gl) &&
601ef0d52e961 (Bob Peterson 2020-01-28 20:23:45 +0100 613) gh && !(gh->gh_flags & LM_FLAG_NOEXP))
0d1c7ae9d849b (Bob Peterson 2017-03-03 12:37:14 -0500 614) return;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 615) lck_flags &= (LM_FLAG_TRY | LM_FLAG_TRY_1CB | LM_FLAG_NOEXP |
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 616) LM_FLAG_PRIORITY);
921169ca2f7c8 (Steven Whitehouse 2010-11-29 12:50:38 +0000 617) GLOCK_BUG_ON(gl, gl->gl_state == target);
921169ca2f7c8 (Steven Whitehouse 2010-11-29 12:50:38 +0000 618) GLOCK_BUG_ON(gl, gl->gl_state == gl->gl_target);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 619) if ((target == LM_ST_UNLOCKED || target == LM_ST_DEFERRED) &&
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 620) glops->go_inval) {
d99724c3c36ae (Bob Peterson 2019-11-15 10:45:41 -0500 621) /*
d99724c3c36ae (Bob Peterson 2019-11-15 10:45:41 -0500 622) * If another process is already doing the invalidate, let that
d99724c3c36ae (Bob Peterson 2019-11-15 10:45:41 -0500 623) * finish first. The glock state machine will get back to this
d99724c3c36ae (Bob Peterson 2019-11-15 10:45:41 -0500 624) * holder again later.
d99724c3c36ae (Bob Peterson 2019-11-15 10:45:41 -0500 625) */
d99724c3c36ae (Bob Peterson 2019-11-15 10:45:41 -0500 626) if (test_and_set_bit(GLF_INVALIDATE_IN_PROGRESS,
d99724c3c36ae (Bob Peterson 2019-11-15 10:45:41 -0500 627) &gl->gl_flags))
d99724c3c36ae (Bob Peterson 2019-11-15 10:45:41 -0500 628) return;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 629) do_error(gl, 0); /* Fail queued try locks */
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 630) }
47a25380e37f4 (Steven Whitehouse 2010-11-30 15:49:31 +0000 631) gl->gl_req = target;
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 632) set_bit(GLF_BLOCKING, &gl->gl_flags);
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 633) if ((gl->gl_req == LM_ST_UNLOCKED) ||
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 634) (gl->gl_state == LM_ST_EXCLUSIVE) ||
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 635) (lck_flags & (LM_FLAG_TRY|LM_FLAG_TRY_1CB)))
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 636) clear_bit(GLF_BLOCKING, &gl->gl_flags);
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 637) spin_unlock(&gl->gl_lockref.lock);
1c634f94c3da3 (Bob Peterson 2019-11-13 14:09:28 -0600 638) if (glops->go_sync) {
1c634f94c3da3 (Bob Peterson 2019-11-13 14:09:28 -0600 639) ret = glops->go_sync(gl);
1c634f94c3da3 (Bob Peterson 2019-11-13 14:09:28 -0600 640) /* If we had a problem syncing (due to io errors or whatever,
1c634f94c3da3 (Bob Peterson 2019-11-13 14:09:28 -0600 641) * we should not invalidate the metadata or tell dlm to
1c634f94c3da3 (Bob Peterson 2019-11-13 14:09:28 -0600 642) * release the glock to other nodes.
1c634f94c3da3 (Bob Peterson 2019-11-13 14:09:28 -0600 643) */
1c634f94c3da3 (Bob Peterson 2019-11-13 14:09:28 -0600 644) if (ret) {
1c634f94c3da3 (Bob Peterson 2019-11-13 14:09:28 -0600 645) if (cmpxchg(&sdp->sd_log_error, 0, ret)) {
1c634f94c3da3 (Bob Peterson 2019-11-13 14:09:28 -0600 646) fs_err(sdp, "Error %d syncing glock \n", ret);
1c634f94c3da3 (Bob Peterson 2019-11-13 14:09:28 -0600 647) gfs2_dump_glock(NULL, gl, true);
1c634f94c3da3 (Bob Peterson 2019-11-13 14:09:28 -0600 648) }
b11e1a84f3708 (Bob Peterson 2020-05-07 12:12:23 -0500 649) goto skip_inval;
1c634f94c3da3 (Bob Peterson 2019-11-13 14:09:28 -0600 650) }
1c634f94c3da3 (Bob Peterson 2019-11-13 14:09:28 -0600 651) }
33dbd1e41a1dd (Bob Peterson 2019-05-22 09:21:21 -0500 652) if (test_bit(GLF_INVALIDATE_IN_PROGRESS, &gl->gl_flags)) {
33dbd1e41a1dd (Bob Peterson 2019-05-22 09:21:21 -0500 653) /*
33dbd1e41a1dd (Bob Peterson 2019-05-22 09:21:21 -0500 654) * The call to go_sync should have cleared out the ail list.
33dbd1e41a1dd (Bob Peterson 2019-05-22 09:21:21 -0500 655) * If there are still items, we have a problem. We ought to
33dbd1e41a1dd (Bob Peterson 2019-05-22 09:21:21 -0500 656) * withdraw, but we can't because the withdraw code also uses
33dbd1e41a1dd (Bob Peterson 2019-05-22 09:21:21 -0500 657) * glocks. Warn about the error, dump the glock, then fall
33dbd1e41a1dd (Bob Peterson 2019-05-22 09:21:21 -0500 658) * through and wait for logd to do the withdraw for us.
33dbd1e41a1dd (Bob Peterson 2019-05-22 09:21:21 -0500 659) */
33dbd1e41a1dd (Bob Peterson 2019-05-22 09:21:21 -0500 660) if ((atomic_read(&gl->gl_ail_count) != 0) &&
33dbd1e41a1dd (Bob Peterson 2019-05-22 09:21:21 -0500 661) (!cmpxchg(&sdp->sd_log_error, 0, -EIO))) {
ea4e61c7f46d3 (Bob Peterson 2020-05-23 08:13:50 -0500 662) gfs2_glock_assert_warn(gl,
ea4e61c7f46d3 (Bob Peterson 2020-05-23 08:13:50 -0500 663) !atomic_read(&gl->gl_ail_count));
33dbd1e41a1dd (Bob Peterson 2019-05-22 09:21:21 -0500 664) gfs2_dump_glock(NULL, gl, true);
33dbd1e41a1dd (Bob Peterson 2019-05-22 09:21:21 -0500 665) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 666) glops->go_inval(gl, target == LM_ST_DEFERRED ? 0 : DIO_METADATA);
33dbd1e41a1dd (Bob Peterson 2019-05-22 09:21:21 -0500 667) clear_bit(GLF_INVALIDATE_IN_PROGRESS, &gl->gl_flags);
33dbd1e41a1dd (Bob Peterson 2019-05-22 09:21:21 -0500 668) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 669)
b11e1a84f3708 (Bob Peterson 2020-05-07 12:12:23 -0500 670) skip_inval:
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 671) gfs2_glock_hold(gl);
d93ae386ef3d1 (Bob Peterson 2019-04-29 13:14:58 -0600 672) /*
d93ae386ef3d1 (Bob Peterson 2019-04-29 13:14:58 -0600 673) * Check for an error encountered since we called go_sync and go_inval.
d93ae386ef3d1 (Bob Peterson 2019-04-29 13:14:58 -0600 674) * If so, we can't withdraw from the glock code because the withdraw
d93ae386ef3d1 (Bob Peterson 2019-04-29 13:14:58 -0600 675) * code itself uses glocks (see function signal_our_withdraw) to
d93ae386ef3d1 (Bob Peterson 2019-04-29 13:14:58 -0600 676) * change the mount to read-only. Most importantly, we must not call
d93ae386ef3d1 (Bob Peterson 2019-04-29 13:14:58 -0600 677) * dlm to unlock the glock until the journal is in a known good state
d93ae386ef3d1 (Bob Peterson 2019-04-29 13:14:58 -0600 678) * (after journal replay) otherwise other nodes may use the object
d93ae386ef3d1 (Bob Peterson 2019-04-29 13:14:58 -0600 679) * (rgrp or dinode) and then later, journal replay will corrupt the
d93ae386ef3d1 (Bob Peterson 2019-04-29 13:14:58 -0600 680) * file system. The best we can do here is wait for the logd daemon
d93ae386ef3d1 (Bob Peterson 2019-04-29 13:14:58 -0600 681) * to see sd_log_error and withdraw, and in the meantime, requeue the
d93ae386ef3d1 (Bob Peterson 2019-04-29 13:14:58 -0600 682) * work for later.
d93ae386ef3d1 (Bob Peterson 2019-04-29 13:14:58 -0600 683) *
865cc3e9cc0b1 (Bob Peterson 2021-05-18 09:14:31 -0400 684) * We make a special exception for some system glocks, such as the
865cc3e9cc0b1 (Bob Peterson 2021-05-18 09:14:31 -0400 685) * system statfs inode glock, which needs to be granted before the
865cc3e9cc0b1 (Bob Peterson 2021-05-18 09:14:31 -0400 686) * gfs2_quotad daemon can exit, and that exit needs to finish before
865cc3e9cc0b1 (Bob Peterson 2021-05-18 09:14:31 -0400 687) * we can unmount the withdrawn file system.
865cc3e9cc0b1 (Bob Peterson 2021-05-18 09:14:31 -0400 688) *
d93ae386ef3d1 (Bob Peterson 2019-04-29 13:14:58 -0600 689) * However, if we're just unlocking the lock (say, for unmount, when
d93ae386ef3d1 (Bob Peterson 2019-04-29 13:14:58 -0600 690) * gfs2_gl_hash_clear calls clear_glock) and recovery is complete
d93ae386ef3d1 (Bob Peterson 2019-04-29 13:14:58 -0600 691) * then it's okay to tell dlm to unlock it.
d93ae386ef3d1 (Bob Peterson 2019-04-29 13:14:58 -0600 692) */
d93ae386ef3d1 (Bob Peterson 2019-04-29 13:14:58 -0600 693) if (unlikely(sdp->sd_log_error && !gfs2_withdrawn(sdp)))
d93ae386ef3d1 (Bob Peterson 2019-04-29 13:14:58 -0600 694) gfs2_withdraw_delayed(sdp);
865cc3e9cc0b1 (Bob Peterson 2021-05-18 09:14:31 -0400 695) if (glock_blocked_by_withdraw(gl) &&
865cc3e9cc0b1 (Bob Peterson 2021-05-18 09:14:31 -0400 696) (target != LM_ST_UNLOCKED ||
865cc3e9cc0b1 (Bob Peterson 2021-05-18 09:14:31 -0400 697) test_bit(SDF_WITHDRAW_RECOVERY, &sdp->sd_flags))) {
865cc3e9cc0b1 (Bob Peterson 2021-05-18 09:14:31 -0400 698) if (!is_system_glock(gl)) {
d93ae386ef3d1 (Bob Peterson 2019-04-29 13:14:58 -0600 699) gfs2_glock_queue_work(gl, GL_GLOCK_DFT_HOLD);
d93ae386ef3d1 (Bob Peterson 2019-04-29 13:14:58 -0600 700) goto out;
865cc3e9cc0b1 (Bob Peterson 2021-05-18 09:14:31 -0400 701) } else {
865cc3e9cc0b1 (Bob Peterson 2021-05-18 09:14:31 -0400 702) clear_bit(GLF_INVALIDATE_IN_PROGRESS, &gl->gl_flags);
d93ae386ef3d1 (Bob Peterson 2019-04-29 13:14:58 -0600 703) }
d93ae386ef3d1 (Bob Peterson 2019-04-29 13:14:58 -0600 704) }
d93ae386ef3d1 (Bob Peterson 2019-04-29 13:14:58 -0600 705)
921169ca2f7c8 (Steven Whitehouse 2010-11-29 12:50:38 +0000 706) if (sdp->sd_lockstruct.ls_ops->lm_lock) {
921169ca2f7c8 (Steven Whitehouse 2010-11-29 12:50:38 +0000 707) /* lock_dlm */
921169ca2f7c8 (Steven Whitehouse 2010-11-29 12:50:38 +0000 708) ret = sdp->sd_lockstruct.ls_ops->lm_lock(gl, target, lck_flags);
3e11e53041502 (Benjamin Marzinski 2016-03-23 14:29:59 -0400 709) if (ret == -EINVAL && gl->gl_target == LM_ST_UNLOCKED &&
3e11e53041502 (Benjamin Marzinski 2016-03-23 14:29:59 -0400 710) target == LM_ST_UNLOCKED &&
3e11e53041502 (Benjamin Marzinski 2016-03-23 14:29:59 -0400 711) test_bit(SDF_SKIP_DLM_UNLOCK, &sdp->sd_flags)) {
3e11e53041502 (Benjamin Marzinski 2016-03-23 14:29:59 -0400 712) finish_xmote(gl, target);
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 713) gfs2_glock_queue_work(gl, 0);
d93ae386ef3d1 (Bob Peterson 2019-04-29 13:14:58 -0600 714) } else if (ret) {
e54c78a27fcde (Bob Peterson 2018-10-03 08:47:36 -0500 715) fs_err(sdp, "lm_lock ret %d\n", ret);
eb43e660c0940 (Bob Peterson 2019-11-14 09:52:15 -0500 716) GLOCK_BUG_ON(gl, !gfs2_withdrawn(sdp));
dba2d70c5dc52 (David Teigland 2012-11-14 13:46:53 -0500 717) }
921169ca2f7c8 (Steven Whitehouse 2010-11-29 12:50:38 +0000 718) } else { /* lock_nolock */
921169ca2f7c8 (Steven Whitehouse 2010-11-29 12:50:38 +0000 719) finish_xmote(gl, target);
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 720) gfs2_glock_queue_work(gl, 0);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 721) }
d93ae386ef3d1 (Bob Peterson 2019-04-29 13:14:58 -0600 722) out:
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 723) spin_lock(&gl->gl_lockref.lock);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 724) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 725)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 726) /**
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 727) * find_first_holder - find the first "holder" gh
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 728) * @gl: the glock
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 729) */
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 730)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 731) static inline struct gfs2_holder *find_first_holder(const struct gfs2_glock *gl)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 732) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 733) struct gfs2_holder *gh;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 734)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 735) if (!list_empty(&gl->gl_holders)) {
969183bc68bc2 (Andreas Gruenbacher 2020-02-03 19:22:45 +0100 736) gh = list_first_entry(&gl->gl_holders, struct gfs2_holder, gh_list);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 737) if (test_bit(HIF_HOLDER, &gh->gh_iflags))
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 738) return gh;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 739) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 740) return NULL;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 741) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 742)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 743) /**
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 744) * run_queue - do all outstanding tasks related to a glock
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 745) * @gl: The glock in question
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 746) * @nonblock: True if we must not block in run_queue
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 747) *
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 748) */
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 749)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 750) static void run_queue(struct gfs2_glock *gl, const int nonblock)
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 751) __releases(&gl->gl_lockref.lock)
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 752) __acquires(&gl->gl_lockref.lock)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 753) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 754) struct gfs2_holder *gh = NULL;
813e0c46c9e2a (Steven Whitehouse 2008-11-18 13:38:48 +0000 755) int ret;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 756)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 757) if (test_and_set_bit(GLF_LOCK, &gl->gl_flags))
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 758) return;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 759)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 760) GLOCK_BUG_ON(gl, test_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags));
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 761)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 762) if (test_bit(GLF_DEMOTE, &gl->gl_flags) &&
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 763) gl->gl_demote_state != gl->gl_state) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 764) if (find_first_holder(gl))
d8348de06f704 (Steven Whitehouse 2009-02-05 10:12:38 +0000 765) goto out_unlock;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 766) if (nonblock)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 767) goto out_sched;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 768) set_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags);
265d529cef6fd (Steven Whitehouse 2008-07-07 10:02:36 +0100 769) GLOCK_BUG_ON(gl, gl->gl_demote_state == LM_ST_EXCLUSIVE);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 770) gl->gl_target = gl->gl_demote_state;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 771) } else {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 772) if (test_bit(GLF_DEMOTE, &gl->gl_flags))
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 773) gfs2_demote_wake(gl);
813e0c46c9e2a (Steven Whitehouse 2008-11-18 13:38:48 +0000 774) ret = do_promote(gl);
813e0c46c9e2a (Steven Whitehouse 2008-11-18 13:38:48 +0000 775) if (ret == 0)
d8348de06f704 (Steven Whitehouse 2009-02-05 10:12:38 +0000 776) goto out_unlock;
813e0c46c9e2a (Steven Whitehouse 2008-11-18 13:38:48 +0000 777) if (ret == 2)
a228df6339e0d (Steven Whitehouse 2009-04-07 14:01:34 +0100 778) goto out;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 779) gh = find_first_waiter(gl);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 780) gl->gl_target = gh->gh_state;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 781) if (!(gh->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB)))
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 782) do_error(gl, 0); /* Fail queued try locks */
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 783) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 784) do_xmote(gl, gh, gl->gl_target);
a228df6339e0d (Steven Whitehouse 2009-04-07 14:01:34 +0100 785) out:
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 786) return;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 787)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 788) out_sched:
7e71c55ee7398 (Steven Whitehouse 2009-09-22 10:56:16 +0100 789) clear_bit(GLF_LOCK, &gl->gl_flags);
4e857c58efeb9 (Peter Zijlstra 2014-03-17 18:06:10 +0100 790) smp_mb__after_atomic();
e66cf161098a6 (Steven Whitehouse 2013-10-15 15:18:08 +0100 791) gl->gl_lockref.count++;
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 792) __gfs2_glock_queue_work(gl, 0);
7e71c55ee7398 (Steven Whitehouse 2009-09-22 10:56:16 +0100 793) return;
7e71c55ee7398 (Steven Whitehouse 2009-09-22 10:56:16 +0100 794)
d8348de06f704 (Steven Whitehouse 2009-02-05 10:12:38 +0000 795) out_unlock:
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 796) clear_bit(GLF_LOCK, &gl->gl_flags);
4e857c58efeb9 (Peter Zijlstra 2014-03-17 18:06:10 +0100 797) smp_mb__after_atomic();
7e71c55ee7398 (Steven Whitehouse 2009-09-22 10:56:16 +0100 798) return;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 799) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 800)
f286d627ef026 (Andreas Gruenbacher 2020-01-13 21:21:49 +0100 801) void gfs2_inode_remember_delete(struct gfs2_glock *gl, u64 generation)
f286d627ef026 (Andreas Gruenbacher 2020-01-13 21:21:49 +0100 802) {
f286d627ef026 (Andreas Gruenbacher 2020-01-13 21:21:49 +0100 803) struct gfs2_inode_lvb *ri = (void *)gl->gl_lksb.sb_lvbptr;
f286d627ef026 (Andreas Gruenbacher 2020-01-13 21:21:49 +0100 804)
f286d627ef026 (Andreas Gruenbacher 2020-01-13 21:21:49 +0100 805) if (ri->ri_magic == 0)
f286d627ef026 (Andreas Gruenbacher 2020-01-13 21:21:49 +0100 806) ri->ri_magic = cpu_to_be32(GFS2_MAGIC);
f286d627ef026 (Andreas Gruenbacher 2020-01-13 21:21:49 +0100 807) if (ri->ri_magic == cpu_to_be32(GFS2_MAGIC))
f286d627ef026 (Andreas Gruenbacher 2020-01-13 21:21:49 +0100 808) ri->ri_generation_deleted = cpu_to_be64(generation);
f286d627ef026 (Andreas Gruenbacher 2020-01-13 21:21:49 +0100 809) }
f286d627ef026 (Andreas Gruenbacher 2020-01-13 21:21:49 +0100 810)
f286d627ef026 (Andreas Gruenbacher 2020-01-13 21:21:49 +0100 811) bool gfs2_inode_already_deleted(struct gfs2_glock *gl, u64 generation)
f286d627ef026 (Andreas Gruenbacher 2020-01-13 21:21:49 +0100 812) {
f286d627ef026 (Andreas Gruenbacher 2020-01-13 21:21:49 +0100 813) struct gfs2_inode_lvb *ri = (void *)gl->gl_lksb.sb_lvbptr;
f286d627ef026 (Andreas Gruenbacher 2020-01-13 21:21:49 +0100 814)
f286d627ef026 (Andreas Gruenbacher 2020-01-13 21:21:49 +0100 815) if (ri->ri_magic != cpu_to_be32(GFS2_MAGIC))
f286d627ef026 (Andreas Gruenbacher 2020-01-13 21:21:49 +0100 816) return false;
f286d627ef026 (Andreas Gruenbacher 2020-01-13 21:21:49 +0100 817) return generation <= be64_to_cpu(ri->ri_generation_deleted);
f286d627ef026 (Andreas Gruenbacher 2020-01-13 21:21:49 +0100 818) }
f286d627ef026 (Andreas Gruenbacher 2020-01-13 21:21:49 +0100 819)
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 820) static void gfs2_glock_poke(struct gfs2_glock *gl)
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 821) {
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 822) int flags = LM_FLAG_TRY_1CB | LM_FLAG_ANY | GL_SKIP;
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 823) struct gfs2_holder gh;
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 824) int error;
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 825)
c07bfb4d8fa1e (Andreas Gruenbacher 2020-07-27 19:18:57 +0200 826) gfs2_holder_init(gl, LM_ST_SHARED, flags, &gh);
c07bfb4d8fa1e (Andreas Gruenbacher 2020-07-27 19:18:57 +0200 827) error = gfs2_glock_nq(&gh);
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 828) if (!error)
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 829) gfs2_glock_dq(&gh);
c07bfb4d8fa1e (Andreas Gruenbacher 2020-07-27 19:18:57 +0200 830) gfs2_holder_uninit(&gh);
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 831) }
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 832)
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 833) static bool gfs2_try_evict(struct gfs2_glock *gl)
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 834) {
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 835) struct gfs2_inode *ip;
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 836) bool evicted = false;
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 837)
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 838) /*
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 839) * If there is contention on the iopen glock and we have an inode, try
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 840) * to grab and release the inode so that it can be evicted. This will
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 841) * allow the remote node to go ahead and delete the inode without us
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 842) * having to do it, which will avoid rgrp glock thrashing.
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 843) *
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 844) * The remote node is likely still holding the corresponding inode
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 845) * glock, so it will run before we get to verify that the delete has
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 846) * happened below.
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 847) */
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 848) spin_lock(&gl->gl_lockref.lock);
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 849) ip = gl->gl_object;
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 850) if (ip && !igrab(&ip->i_inode))
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 851) ip = NULL;
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 852) spin_unlock(&gl->gl_lockref.lock);
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 853) if (ip) {
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 854) struct gfs2_glock *inode_gl = NULL;
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 855)
b0dcffd8da333 (Andreas Gruenbacher 2020-01-15 09:54:14 +0100 856) gl->gl_no_formal_ino = ip->i_no_formal_ino;
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 857) set_bit(GIF_DEFERRED_DELETE, &ip->i_flags);
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 858) d_prune_aliases(&ip->i_inode);
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 859) iput(&ip->i_inode);
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 860)
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 861) /* If the inode was evicted, gl->gl_object will now be NULL. */
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 862) spin_lock(&gl->gl_lockref.lock);
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 863) ip = gl->gl_object;
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 864) if (ip) {
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 865) inode_gl = ip->i_gl;
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 866) lockref_get(&inode_gl->gl_lockref);
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 867) clear_bit(GIF_DEFERRED_DELETE, &ip->i_flags);
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 868) }
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 869) spin_unlock(&gl->gl_lockref.lock);
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 870) if (inode_gl) {
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 871) gfs2_glock_poke(inode_gl);
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 872) gfs2_glock_put(inode_gl);
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 873) }
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 874) evicted = !ip;
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 875) }
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 876) return evicted;
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 877) }
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 878)
b94a170e96dc4 (Benjamin Marzinski 2009-07-23 18:52:34 -0500 879) static void delete_work_func(struct work_struct *work)
b94a170e96dc4 (Benjamin Marzinski 2009-07-23 18:52:34 -0500 880) {
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 881) struct delayed_work *dwork = to_delayed_work(work);
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 882) struct gfs2_glock *gl = container_of(dwork, struct gfs2_glock, gl_delete);
15562c439d0a1 (Bob Peterson 2015-03-16 11:52:05 -0500 883) struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
ec5ec66ba48bd (Andreas Gruenbacher 2016-06-14 12:23:59 -0500 884) struct inode *inode;
044b9414c7caf (Steven Whitehouse 2010-11-03 20:01:07 +0000 885) u64 no_addr = gl->gl_name.ln_number;
044b9414c7caf (Steven Whitehouse 2010-11-03 20:01:07 +0000 886)
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 887) spin_lock(&gl->gl_lockref.lock);
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 888) clear_bit(GLF_PENDING_DELETE, &gl->gl_flags);
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 889) spin_unlock(&gl->gl_lockref.lock);
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 890)
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 891) if (test_bit(GLF_DEMOTE, &gl->gl_flags)) {
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 892) /*
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 893) * If we can evict the inode, give the remote node trying to
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 894) * delete the inode some time before verifying that the delete
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 895) * has happened. Otherwise, if we cause contention on the inode glock
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 896) * immediately, the remote node will think that we still have
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 897) * the inode in use, and so it will give up waiting.
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 898) *
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 899) * If we can't evict the inode, signal to the remote node that
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 900) * the inode is still in use. We'll later try to delete the
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 901) * inode locally in gfs2_evict_inode.
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 902) *
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 903) * FIXME: We only need to verify that the remote node has
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 904) * deleted the inode because nodes before this remote delete
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 905) * rework won't cooperate. At a later time, when we no longer
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 906) * care about compatibility with such nodes, we can skip this
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 907) * step entirely.
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 908) */
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 909) if (gfs2_try_evict(gl)) {
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 910) if (gfs2_queue_delete_work(gl, 5 * HZ))
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 911) return;
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 912) }
9e8990dea9266 (Andreas Gruenbacher 2020-01-17 10:53:23 +0100 913) goto out;
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 914) }
8c7b9262a8607 (Andreas Gruenbacher 2020-01-13 22:16:17 +0100 915)
b0dcffd8da333 (Andreas Gruenbacher 2020-01-15 09:54:14 +0100 916) inode = gfs2_lookup_by_inum(sdp, no_addr, gl->gl_no_formal_ino,
b0dcffd8da333 (Andreas Gruenbacher 2020-01-15 09:54:14 +0100 917) GFS2_BLKST_UNLINKED);
15a798f7deb39 (Kefeng Wang 2019-06-05 22:24:24 +0800 918) if (!IS_ERR_OR_NULL(inode)) {
044b9414c7caf (Steven Whitehouse 2010-11-03 20:01:07 +0000 919) d_prune_aliases(inode);
044b9414c7caf (Steven Whitehouse 2010-11-03 20:01:07 +0000 920) iput(inode);
b94a170e96dc4 (Benjamin Marzinski 2009-07-23 18:52:34 -0500 921) }
a4923865ea071 (Bob Peterson 2015-12-07 16:24:27 -0600 922) out:
b94a170e96dc4 (Benjamin Marzinski 2009-07-23 18:52:34 -0500 923) gfs2_glock_put(gl);
b94a170e96dc4 (Benjamin Marzinski 2009-07-23 18:52:34 -0500 924) }
b94a170e96dc4 (Benjamin Marzinski 2009-07-23 18:52:34 -0500 925)
c4f68a130fc17 (Benjamin Marzinski 2007-08-23 13:19:05 -0500 926) static void glock_work_func(struct work_struct *work)
c4f68a130fc17 (Benjamin Marzinski 2007-08-23 13:19:05 -0500 927) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 928) unsigned long delay = 0;
c4f68a130fc17 (Benjamin Marzinski 2007-08-23 13:19:05 -0500 929) struct gfs2_glock *gl = container_of(work, struct gfs2_glock, gl_work.work);
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 930) unsigned int drop_refs = 1;
c4f68a130fc17 (Benjamin Marzinski 2007-08-23 13:19:05 -0500 931)
26bb7505cf7db (Steven Whitehouse 2009-11-27 10:31:11 +0000 932) if (test_and_clear_bit(GLF_REPLY_PENDING, &gl->gl_flags)) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 933) finish_xmote(gl, gl->gl_reply);
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 934) drop_refs++;
26bb7505cf7db (Steven Whitehouse 2009-11-27 10:31:11 +0000 935) }
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 936) spin_lock(&gl->gl_lockref.lock);
f90e5b5b136ed (Bob Peterson 2011-05-24 10:44:42 -0400 937) if (test_bit(GLF_PENDING_DEMOTE, &gl->gl_flags) &&
265d529cef6fd (Steven Whitehouse 2008-07-07 10:02:36 +0100 938) gl->gl_state != LM_ST_UNLOCKED &&
265d529cef6fd (Steven Whitehouse 2008-07-07 10:02:36 +0100 939) gl->gl_demote_state != LM_ST_EXCLUSIVE) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 940) unsigned long holdtime, now = jiffies;
f90e5b5b136ed (Bob Peterson 2011-05-24 10:44:42 -0400 941)
7cf8dcd3b68a7 (Bob Peterson 2011-06-15 11:41:48 -0400 942) holdtime = gl->gl_tchange + gl->gl_hold_time;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 943) if (time_before(now, holdtime))
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 944) delay = holdtime - now;
f90e5b5b136ed (Bob Peterson 2011-05-24 10:44:42 -0400 945)
f90e5b5b136ed (Bob Peterson 2011-05-24 10:44:42 -0400 946) if (!delay) {
f90e5b5b136ed (Bob Peterson 2011-05-24 10:44:42 -0400 947) clear_bit(GLF_PENDING_DEMOTE, &gl->gl_flags);
35b6f8fbcf9b2 (Andreas Gruenbacher 2020-01-17 13:48:49 +0100 948) gfs2_set_demote(gl);
f90e5b5b136ed (Bob Peterson 2011-05-24 10:44:42 -0400 949) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 950) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 951) run_queue(gl, 0);
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 952) if (delay) {
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 953) /* Keep one glock reference for the work we requeue. */
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 954) drop_refs--;
7cf8dcd3b68a7 (Bob Peterson 2011-06-15 11:41:48 -0400 955) if (gl->gl_name.ln_type != LM_TYPE_INODE)
7cf8dcd3b68a7 (Bob Peterson 2011-06-15 11:41:48 -0400 956) delay = 0;
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 957) __gfs2_glock_queue_work(gl, delay);
7cf8dcd3b68a7 (Bob Peterson 2011-06-15 11:41:48 -0400 958) }
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 959)
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 960) /*
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 961) * Drop the remaining glock references manually here. (Mind that
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 962) * __gfs2_glock_queue_work depends on the lockref spinlock begin held
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 963) * here as well.)
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 964) */
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 965) gl->gl_lockref.count -= drop_refs;
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 966) if (!gl->gl_lockref.count) {
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 967) __gfs2_glock_put(gl);
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 968) return;
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 969) }
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 970) spin_unlock(&gl->gl_lockref.lock);
c4f68a130fc17 (Benjamin Marzinski 2007-08-23 13:19:05 -0500 971) }
c4f68a130fc17 (Benjamin Marzinski 2007-08-23 13:19:05 -0500 972)
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 973) static struct gfs2_glock *find_insert_glock(struct lm_lockname *name,
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 974) struct gfs2_glock *new)
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 975) {
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 976) struct wait_glock_queue wait;
a91323e255fa8 (Andreas Gruenbacher 2017-08-04 07:40:45 -0500 977) wait_queue_head_t *wq = glock_waitqueue(name);
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 978) struct gfs2_glock *gl;
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 979)
a91323e255fa8 (Andreas Gruenbacher 2017-08-04 07:40:45 -0500 980) wait.name = name;
a91323e255fa8 (Andreas Gruenbacher 2017-08-04 07:40:45 -0500 981) init_wait(&wait.wait);
a91323e255fa8 (Andreas Gruenbacher 2017-08-04 07:40:45 -0500 982) wait.wait.func = glock_wake_function;
a91323e255fa8 (Andreas Gruenbacher 2017-08-04 07:40:45 -0500 983)
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 984) again:
a91323e255fa8 (Andreas Gruenbacher 2017-08-04 07:40:45 -0500 985) prepare_to_wait(wq, &wait.wait, TASK_UNINTERRUPTIBLE);
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 986) rcu_read_lock();
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 987) if (new) {
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 988) gl = rhashtable_lookup_get_insert_fast(&gl_hash_table,
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 989) &new->gl_node, ht_parms);
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 990) if (IS_ERR(gl))
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 991) goto out;
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 992) } else {
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 993) gl = rhashtable_lookup_fast(&gl_hash_table,
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 994) name, ht_parms);
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 995) }
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 996) if (gl && !lockref_get_not_dead(&gl->gl_lockref)) {
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 997) rcu_read_unlock();
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 998) schedule();
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 999) goto again;
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 1000) }
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 1001) out:
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 1002) rcu_read_unlock();
a91323e255fa8 (Andreas Gruenbacher 2017-08-04 07:40:45 -0500 1003) finish_wait(wq, &wait.wait);
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 1004) return gl;
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 1005) }
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 1006)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1007) /**
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1008) * gfs2_glock_get() - Get a glock, or create one if one doesn't exist
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1009) * @sdp: The GFS2 superblock
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1010) * @number: the lock number
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1011) * @glops: The glock_operations to use
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1012) * @create: If 0, don't create the glock if it doesn't exist
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1013) * @glp: the glock is returned here
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1014) *
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1015) * This does not lock a glock, just finds/creates structures for one.
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1016) *
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1017) * Returns: errno
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1018) */
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1019)
cd915493fce91 (Steven Whitehouse 2006-09-04 12:49:07 -0400 1020) int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
8fb4b536e7b9d (Steven Whitehouse 2006-08-30 09:30:00 -0400 1021) const struct gfs2_glock_operations *glops, int create,
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1022) struct gfs2_glock **glp)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1023) {
009d851837ab2 (Steven Whitehouse 2009-12-08 12:12:13 +0000 1024) struct super_block *s = sdp->sd_vfs;
15562c439d0a1 (Bob Peterson 2015-03-16 11:52:05 -0500 1025) struct lm_lockname name = { .ln_number = number,
15562c439d0a1 (Bob Peterson 2015-03-16 11:52:05 -0500 1026) .ln_type = glops->go_type,
15562c439d0a1 (Bob Peterson 2015-03-16 11:52:05 -0500 1027) .ln_sbd = sdp };
0a52aba7c2168 (Andreas Gruenbacher 2017-02-21 23:19:10 +0100 1028) struct gfs2_glock *gl, *tmp;
009d851837ab2 (Steven Whitehouse 2009-12-08 12:12:13 +0000 1029) struct address_space *mapping;
bc015cb84129e (Steven Whitehouse 2011-01-19 09:30:01 +0000 1030) struct kmem_cache *cachep;
0a52aba7c2168 (Andreas Gruenbacher 2017-02-21 23:19:10 +0100 1031) int ret = 0;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1032)
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 1033) gl = find_insert_glock(&name, NULL);
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 1034) if (gl) {
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 1035) *glp = gl;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1036) return 0;
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 1037) }
64d576ba23bfd (Steven Whitehouse 2009-02-12 13:31:58 +0000 1038) if (!create)
64d576ba23bfd (Steven Whitehouse 2009-02-12 13:31:58 +0000 1039) return -ENOENT;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1040)
009d851837ab2 (Steven Whitehouse 2009-12-08 12:12:13 +0000 1041) if (glops->go_flags & GLOF_ASPACE)
bc015cb84129e (Steven Whitehouse 2011-01-19 09:30:01 +0000 1042) cachep = gfs2_glock_aspace_cachep;
009d851837ab2 (Steven Whitehouse 2009-12-08 12:12:13 +0000 1043) else
bc015cb84129e (Steven Whitehouse 2011-01-19 09:30:01 +0000 1044) cachep = gfs2_glock_cachep;
fe0bbd2986996 (Steven Whitehouse 2014-06-23 14:50:20 +0100 1045) gl = kmem_cache_alloc(cachep, GFP_NOFS);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1046) if (!gl)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1047) return -ENOMEM;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1048)
dba2d70c5dc52 (David Teigland 2012-11-14 13:46:53 -0500 1049) memset(&gl->gl_lksb, 0, sizeof(struct dlm_lksb));
dba2d70c5dc52 (David Teigland 2012-11-14 13:46:53 -0500 1050)
dba2d70c5dc52 (David Teigland 2012-11-14 13:46:53 -0500 1051) if (glops->go_flags & GLOF_LVB) {
f7be987b82543 (Andreas Gruenbacher 2020-01-16 00:25:32 +0100 1052) gl->gl_lksb.sb_lvbptr = kzalloc(GDLM_LVB_SIZE, GFP_NOFS);
4e2f8849def73 (David Teigland 2012-11-14 13:47:37 -0500 1053) if (!gl->gl_lksb.sb_lvbptr) {
dba2d70c5dc52 (David Teigland 2012-11-14 13:46:53 -0500 1054) kmem_cache_free(cachep, gl);
dba2d70c5dc52 (David Teigland 2012-11-14 13:46:53 -0500 1055) return -ENOMEM;
dba2d70c5dc52 (David Teigland 2012-11-14 13:46:53 -0500 1056) }
dba2d70c5dc52 (David Teigland 2012-11-14 13:46:53 -0500 1057) }
dba2d70c5dc52 (David Teigland 2012-11-14 13:46:53 -0500 1058)
8f05228ee7c8f (Steven Whitehouse 2010-01-29 15:21:27 +0000 1059) atomic_inc(&sdp->sd_glock_disposal);
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 1060) gl->gl_node.next = NULL;
ec45d9f583b36 (Steven Whitehouse 2006-08-30 10:36:52 -0400 1061) gl->gl_flags = 0;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1062) gl->gl_name = name;
515b269d5bd29 (Alexander Aring 2020-11-23 10:53:35 -0500 1063) lockdep_set_subclass(&gl->gl_lockref.lock, glops->go_subclass);
e66cf161098a6 (Steven Whitehouse 2013-10-15 15:18:08 +0100 1064) gl->gl_lockref.count = 1;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1065) gl->gl_state = LM_ST_UNLOCKED;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1066) gl->gl_target = LM_ST_UNLOCKED;
c4f68a130fc17 (Benjamin Marzinski 2007-08-23 13:19:05 -0500 1067) gl->gl_demote_state = LM_ST_EXCLUSIVE;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1068) gl->gl_ops = glops;
8b0e195314fab (Thomas Gleixner 2016-12-25 12:30:41 +0100 1069) gl->gl_dstamp = 0;
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 1070) preempt_disable();
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 1071) /* We use the global stats to estimate the initial per-glock stats */
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 1072) gl->gl_stats = this_cpu_ptr(sdp->sd_lkstats)->lkstats[glops->go_type];
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 1073) preempt_enable();
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 1074) gl->gl_stats.stats[GFS2_LKS_DCOUNT] = 0;
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 1075) gl->gl_stats.stats[GFS2_LKS_QCOUNT] = 0;
c4f68a130fc17 (Benjamin Marzinski 2007-08-23 13:19:05 -0500 1076) gl->gl_tchange = jiffies;
ec45d9f583b36 (Steven Whitehouse 2006-08-30 10:36:52 -0400 1077) gl->gl_object = NULL;
7cf8dcd3b68a7 (Bob Peterson 2011-06-15 11:41:48 -0400 1078) gl->gl_hold_time = GL_GLOCK_DFT_HOLD;
c4f68a130fc17 (Benjamin Marzinski 2007-08-23 13:19:05 -0500 1079) INIT_DELAYED_WORK(&gl->gl_work, glock_work_func);
2ffed5290b3bf (Bob Peterson 2020-10-15 11:16:48 -0500 1080) if (gl->gl_name.ln_type == LM_TYPE_IOPEN)
2ffed5290b3bf (Bob Peterson 2020-10-15 11:16:48 -0500 1081) INIT_DELAYED_WORK(&gl->gl_delete, delete_work_func);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1082)
009d851837ab2 (Steven Whitehouse 2009-12-08 12:12:13 +0000 1083) mapping = gfs2_glock2aspace(gl);
009d851837ab2 (Steven Whitehouse 2009-12-08 12:12:13 +0000 1084) if (mapping) {
009d851837ab2 (Steven Whitehouse 2009-12-08 12:12:13 +0000 1085) mapping->a_ops = &gfs2_meta_aops;
009d851837ab2 (Steven Whitehouse 2009-12-08 12:12:13 +0000 1086) mapping->host = s->s_bdev->bd_inode;
009d851837ab2 (Steven Whitehouse 2009-12-08 12:12:13 +0000 1087) mapping->flags = 0;
009d851837ab2 (Steven Whitehouse 2009-12-08 12:12:13 +0000 1088) mapping_set_gfp_mask(mapping, GFP_NOFS);
252aa6f5be64c (Rafael Aquini 2012-12-11 16:02:35 -0800 1089) mapping->private_data = NULL;
009d851837ab2 (Steven Whitehouse 2009-12-08 12:12:13 +0000 1090) mapping->writeback_index = 0;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1091) }
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1092)
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 1093) tmp = find_insert_glock(&name, gl);
0a52aba7c2168 (Andreas Gruenbacher 2017-02-21 23:19:10 +0100 1094) if (!tmp) {
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 1095) *glp = gl;
0a52aba7c2168 (Andreas Gruenbacher 2017-02-21 23:19:10 +0100 1096) goto out;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1097) }
0a52aba7c2168 (Andreas Gruenbacher 2017-02-21 23:19:10 +0100 1098) if (IS_ERR(tmp)) {
0a52aba7c2168 (Andreas Gruenbacher 2017-02-21 23:19:10 +0100 1099) ret = PTR_ERR(tmp);
0a52aba7c2168 (Andreas Gruenbacher 2017-02-21 23:19:10 +0100 1100) goto out_free;
0a52aba7c2168 (Andreas Gruenbacher 2017-02-21 23:19:10 +0100 1101) }
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 1102) *glp = tmp;
0a52aba7c2168 (Andreas Gruenbacher 2017-02-21 23:19:10 +0100 1103)
0a52aba7c2168 (Andreas Gruenbacher 2017-02-21 23:19:10 +0100 1104) out_free:
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 1105) kfree(gl->gl_lksb.sb_lvbptr);
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 1106) kmem_cache_free(cachep, gl);
da7d554f7c62d (Alexander Aring 2020-10-26 10:52:29 -0400 1107) if (atomic_dec_and_test(&sdp->sd_glock_disposal))
da7d554f7c62d (Alexander Aring 2020-10-26 10:52:29 -0400 1108) wake_up(&sdp->sd_glock_wait);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1109)
0a52aba7c2168 (Andreas Gruenbacher 2017-02-21 23:19:10 +0100 1110) out:
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 1111) return ret;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1112) }
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1113)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1114) /**
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1115) * gfs2_holder_init - initialize a struct gfs2_holder in the default way
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1116) * @gl: the glock
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1117) * @state: the state we're requesting
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1118) * @flags: the modifier flags
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1119) * @gh: the holder structure
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1120) *
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1121) */
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1122)
b58bf407ca466 (Bob Peterson 2015-07-24 09:45:43 -0500 1123) void gfs2_holder_init(struct gfs2_glock *gl, unsigned int state, u16 flags,
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1124) struct gfs2_holder *gh)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1125) {
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1126) INIT_LIST_HEAD(&gh->gh_list);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1127) gh->gh_gl = gl;
d29c0afe4db72 (Fabian Frederick 2014-10-03 20:15:36 +0200 1128) gh->gh_ip = _RET_IP_;
b1e058da50f79 (Pavel Emelyanov 2008-02-07 00:13:19 -0800 1129) gh->gh_owner_pid = get_pid(task_pid(current));
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1130) gh->gh_state = state;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1131) gh->gh_flags = flags;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1132) gh->gh_error = 0;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1133) gh->gh_iflags = 0;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1134) gfs2_glock_hold(gl);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1135) }
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1136)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1137) /**
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1138) * gfs2_holder_reinit - reinitialize a struct gfs2_holder so we can requeue it
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1139) * @state: the state we're requesting
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1140) * @flags: the modifier flags
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1141) * @gh: the holder structure
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1142) *
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1143) * Don't mess with the glock.
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1144) *
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1145) */
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1146)
b58bf407ca466 (Bob Peterson 2015-07-24 09:45:43 -0500 1147) void gfs2_holder_reinit(unsigned int state, u16 flags, struct gfs2_holder *gh)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1148) {
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1149) gh->gh_state = state;
579b78a43b366 (Steven Whitehouse 2006-04-26 14:58:26 -0400 1150) gh->gh_flags = flags;
3b8249f6178cb (Steven Whitehouse 2007-03-16 09:40:31 +0000 1151) gh->gh_iflags = 0;
d29c0afe4db72 (Fabian Frederick 2014-10-03 20:15:36 +0200 1152) gh->gh_ip = _RET_IP_;
30badc9543490 (Markus Elfring 2014-11-18 11:31:23 +0100 1153) put_pid(gh->gh_owner_pid);
1a0eae8848cde (Bob Peterson 2010-04-14 11:58:16 -0400 1154) gh->gh_owner_pid = get_pid(task_pid(current));
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1155) }
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1156)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1157) /**
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1158) * gfs2_holder_uninit - uninitialize a holder structure (drop glock reference)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1159) * @gh: the holder structure
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1160) *
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1161) */
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1162)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1163) void gfs2_holder_uninit(struct gfs2_holder *gh)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1164) {
b1e058da50f79 (Pavel Emelyanov 2008-02-07 00:13:19 -0800 1165) put_pid(gh->gh_owner_pid);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1166) gfs2_glock_put(gh->gh_gl);
6df9f9a253c7d (Andreas Gruenbacher 2016-06-17 07:31:27 -0500 1167) gfs2_holder_mark_uninitialized(gh);
d0dc80dbafb5c (Steven Whitehouse 2006-03-29 14:36:49 -0500 1168) gh->gh_ip = 0;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1169) }
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1170)
01123cf17cfa7 (Andreas Gruenbacher 2019-08-30 12:31:01 -0500 1171) static void gfs2_glock_update_hold_time(struct gfs2_glock *gl,
01123cf17cfa7 (Andreas Gruenbacher 2019-08-30 12:31:01 -0500 1172) unsigned long start_time)
01123cf17cfa7 (Andreas Gruenbacher 2019-08-30 12:31:01 -0500 1173) {
01123cf17cfa7 (Andreas Gruenbacher 2019-08-30 12:31:01 -0500 1174) /* Have we waited longer that a second? */
01123cf17cfa7 (Andreas Gruenbacher 2019-08-30 12:31:01 -0500 1175) if (time_after(jiffies, start_time + HZ)) {
01123cf17cfa7 (Andreas Gruenbacher 2019-08-30 12:31:01 -0500 1176) /* Lengthen the minimum hold time. */
01123cf17cfa7 (Andreas Gruenbacher 2019-08-30 12:31:01 -0500 1177) gl->gl_hold_time = min(gl->gl_hold_time + GL_GLOCK_HOLD_INCR,
01123cf17cfa7 (Andreas Gruenbacher 2019-08-30 12:31:01 -0500 1178) GL_GLOCK_MAX_HOLD);
01123cf17cfa7 (Andreas Gruenbacher 2019-08-30 12:31:01 -0500 1179) }
01123cf17cfa7 (Andreas Gruenbacher 2019-08-30 12:31:01 -0500 1180) }
01123cf17cfa7 (Andreas Gruenbacher 2019-08-30 12:31:01 -0500 1181)
07a790494260e (Bob Peterson 2012-08-09 12:48:44 -0500 1182) /**
07a790494260e (Bob Peterson 2012-08-09 12:48:44 -0500 1183) * gfs2_glock_wait - wait on a glock acquisition
07a790494260e (Bob Peterson 2012-08-09 12:48:44 -0500 1184) * @gh: the glock holder
07a790494260e (Bob Peterson 2012-08-09 12:48:44 -0500 1185) *
07a790494260e (Bob Peterson 2012-08-09 12:48:44 -0500 1186) * Returns: 0 on success
07a790494260e (Bob Peterson 2012-08-09 12:48:44 -0500 1187) */
07a790494260e (Bob Peterson 2012-08-09 12:48:44 -0500 1188)
07a790494260e (Bob Peterson 2012-08-09 12:48:44 -0500 1189) int gfs2_glock_wait(struct gfs2_holder *gh)
da755fdb41447 (Steven Whitehouse 2008-01-30 15:34:04 +0000 1190) {
01123cf17cfa7 (Andreas Gruenbacher 2019-08-30 12:31:01 -0500 1191) unsigned long start_time = jiffies;
7cf8dcd3b68a7 (Bob Peterson 2011-06-15 11:41:48 -0400 1192)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1193) might_sleep();
743162013d40c (NeilBrown 2014-07-07 15:16:04 +1000 1194) wait_on_bit(&gh->gh_iflags, HIF_WAIT, TASK_UNINTERRUPTIBLE);
01123cf17cfa7 (Andreas Gruenbacher 2019-08-30 12:31:01 -0500 1195) gfs2_glock_update_hold_time(gh->gh_gl, start_time);
07a790494260e (Bob Peterson 2012-08-09 12:48:44 -0500 1196) return gh->gh_error;
da755fdb41447 (Steven Whitehouse 2008-01-30 15:34:04 +0000 1197) }
da755fdb41447 (Steven Whitehouse 2008-01-30 15:34:04 +0000 1198)
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1199) static int glocks_pending(unsigned int num_gh, struct gfs2_holder *ghs)
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1200) {
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1201) int i;
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1202)
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1203) for (i = 0; i < num_gh; i++)
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1204) if (test_bit(HIF_WAIT, &ghs[i].gh_iflags))
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1205) return 1;
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1206) return 0;
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1207) }
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1208)
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1209) /**
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1210) * gfs2_glock_async_wait - wait on multiple asynchronous glock acquisitions
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1211) * @num_gh: the number of holders in the array
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1212) * @ghs: the glock holder array
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1213) *
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1214) * Returns: 0 on success, meaning all glocks have been granted and are held.
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1215) * -ESTALE if the request timed out, meaning all glocks were released,
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1216) * and the caller should retry the operation.
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1217) */
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1218)
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1219) int gfs2_glock_async_wait(unsigned int num_gh, struct gfs2_holder *ghs)
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1220) {
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1221) struct gfs2_sbd *sdp = ghs[0].gh_gl->gl_name.ln_sbd;
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1222) int i, ret = 0, timeout = 0;
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1223) unsigned long start_time = jiffies;
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1224) bool keep_waiting;
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1225)
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1226) might_sleep();
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1227) /*
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1228) * Total up the (minimum hold time * 2) of all glocks and use that to
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1229) * determine the max amount of time we should wait.
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1230) */
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1231) for (i = 0; i < num_gh; i++)
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1232) timeout += ghs[i].gh_gl->gl_hold_time << 1;
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1233)
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1234) wait_for_dlm:
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1235) if (!wait_event_timeout(sdp->sd_async_glock_wait,
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1236) !glocks_pending(num_gh, ghs), timeout))
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1237) ret = -ESTALE; /* request timed out. */
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1238)
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1239) /*
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1240) * If dlm granted all our requests, we need to adjust the glock
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1241) * minimum hold time values according to how long we waited.
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1242) *
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1243) * If our request timed out, we need to repeatedly release any held
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1244) * glocks we acquired thus far to allow dlm to acquire the remaining
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1245) * glocks without deadlocking. We cannot currently cancel outstanding
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1246) * glock acquisitions.
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1247) *
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1248) * The HIF_WAIT bit tells us which requests still need a response from
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1249) * dlm.
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1250) *
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1251) * If dlm sent us any errors, we return the first error we find.
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1252) */
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1253) keep_waiting = false;
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1254) for (i = 0; i < num_gh; i++) {
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1255) /* Skip holders we have already dequeued below. */
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1256) if (!gfs2_holder_queued(&ghs[i]))
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1257) continue;
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1258) /* Skip holders with a pending DLM response. */
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1259) if (test_bit(HIF_WAIT, &ghs[i].gh_iflags)) {
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1260) keep_waiting = true;
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1261) continue;
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1262) }
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1263)
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1264) if (test_bit(HIF_HOLDER, &ghs[i].gh_iflags)) {
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1265) if (ret == -ESTALE)
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1266) gfs2_glock_dq(&ghs[i]);
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1267) else
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1268) gfs2_glock_update_hold_time(ghs[i].gh_gl,
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1269) start_time);
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1270) }
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1271) if (!ret)
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1272) ret = ghs[i].gh_error;
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1273) }
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1274)
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1275) if (keep_waiting)
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1276) goto wait_for_dlm;
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1277)
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1278) /*
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1279) * At this point, we've either acquired all locks or released them all.
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1280) */
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1281) return ret;
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1282) }
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1283)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1284) /**
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1285) * handle_callback - process a demote request
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1286) * @gl: the glock
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1287) * @state: the state the caller wants us to change to
c551f66c5dfef (Lee Jones 2021-03-30 17:44:29 +0100 1288) * @delay: zero to demote immediately; otherwise pending demote
c551f66c5dfef (Lee Jones 2021-03-30 17:44:29 +0100 1289) * @remote: true if this came from a different cluster node
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1290) *
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1291) * There are only two requests that we are going to see in actual
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1292) * practise: LM_ST_SHARED and LM_ST_UNLOCKED
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1293) */
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1294)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1295) static void handle_callback(struct gfs2_glock *gl, unsigned int state,
81ffbf654f0cf (Steven Whitehouse 2013-04-10 10:26:55 +0100 1296) unsigned long delay, bool remote)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1297) {
35b6f8fbcf9b2 (Andreas Gruenbacher 2020-01-17 13:48:49 +0100 1298) if (delay)
35b6f8fbcf9b2 (Andreas Gruenbacher 2020-01-17 13:48:49 +0100 1299) set_bit(GLF_PENDING_DEMOTE, &gl->gl_flags);
35b6f8fbcf9b2 (Andreas Gruenbacher 2020-01-17 13:48:49 +0100 1300) else
35b6f8fbcf9b2 (Andreas Gruenbacher 2020-01-17 13:48:49 +0100 1301) gfs2_set_demote(gl);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1302) if (gl->gl_demote_state == LM_ST_EXCLUSIVE) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1303) gl->gl_demote_state = state;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1304) gl->gl_demote_time = jiffies;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1305) } else if (gl->gl_demote_state != LM_ST_UNLOCKED &&
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1306) gl->gl_demote_state != state) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1307) gl->gl_demote_state = LM_ST_UNLOCKED;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1308) }
b94a170e96dc4 (Benjamin Marzinski 2009-07-23 18:52:34 -0500 1309) if (gl->gl_ops->go_callback)
81ffbf654f0cf (Steven Whitehouse 2013-04-10 10:26:55 +0100 1310) gl->gl_ops->go_callback(gl, remote);
7bd8b2eb32c40 (Steven Whitehouse 2013-04-10 10:32:05 +0100 1311) trace_gfs2_demote_rq(gl, remote);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1312) }
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1313)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1314) void gfs2_print_dbg(struct seq_file *seq, const char *fmt, ...)
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 1315) {
5e69069c1afb6 (Joe Perches 2010-11-09 16:35:20 -0800 1316) struct va_format vaf;
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 1317) va_list args;
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 1318)
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 1319) va_start(args, fmt);
5e69069c1afb6 (Joe Perches 2010-11-09 16:35:20 -0800 1320)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1321) if (seq) {
1bb49303b7a82 (Steven Whitehouse 2012-06-11 13:26:50 +0100 1322) seq_vprintf(seq, fmt, args);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1323) } else {
5e69069c1afb6 (Joe Perches 2010-11-09 16:35:20 -0800 1324) vaf.fmt = fmt;
5e69069c1afb6 (Joe Perches 2010-11-09 16:35:20 -0800 1325) vaf.va = &args;
5e69069c1afb6 (Joe Perches 2010-11-09 16:35:20 -0800 1326)
d77d1b58aaf44 (Joe Perches 2014-03-06 12:10:45 -0800 1327) pr_err("%pV", &vaf);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1328) }
5e69069c1afb6 (Joe Perches 2010-11-09 16:35:20 -0800 1329)
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 1330) va_end(args);
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 1331) }
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 1332)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1333) /**
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1334) * add_to_queue - Add a holder to the wait queue (but look for recursion)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1335) * @gh: the holder structure to add
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1336) *
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1337) * Eventually we should move the recursive locking trap to a
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1338) * debugging option or something like that. This is the fast
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1339) * path and needs to have the minimum number of distractions.
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1340) *
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1341) */
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1342)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1343) static inline void add_to_queue(struct gfs2_holder *gh)
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 1344) __releases(&gl->gl_lockref.lock)
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 1345) __acquires(&gl->gl_lockref.lock)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1346) {
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1347) struct gfs2_glock *gl = gh->gh_gl;
15562c439d0a1 (Bob Peterson 2015-03-16 11:52:05 -0500 1348) struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1349) struct list_head *insert_pt = NULL;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1350) struct gfs2_holder *gh2;
e5dc76b9afcfb (Bob Peterson 2012-08-09 12:48:46 -0500 1351) int try_futile = 0;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1352)
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1353) GLOCK_BUG_ON(gl, gh->gh_owner_pid == NULL);
fee852e374fb3 (Steven Whitehouse 2007-01-17 15:33:23 +0000 1354) if (test_and_set_bit(HIF_WAIT, &gh->gh_iflags))
ad26967b9afa7 (Bob Peterson 2019-08-30 12:31:02 -0500 1355) GLOCK_BUG_ON(gl, true);
190562bd84a48 (Steven Whitehouse 2006-04-20 16:57:23 -0400 1356)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1357) if (gh->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB)) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1358) if (test_bit(GLF_LOCK, &gl->gl_flags))
e5dc76b9afcfb (Bob Peterson 2012-08-09 12:48:46 -0500 1359) try_futile = !may_grant(gl, gh);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1360) if (test_bit(GLF_INVALIDATE_IN_PROGRESS, &gl->gl_flags))
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1361) goto fail;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1362) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1363)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1364) list_for_each_entry(gh2, &gl->gl_holders, gh_list) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1365) if (unlikely(gh2->gh_owner_pid == gh->gh_owner_pid &&
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1366) (gh->gh_gl->gl_ops->go_type != LM_TYPE_FLOCK)))
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1367) goto trap_recursive;
e5dc76b9afcfb (Bob Peterson 2012-08-09 12:48:46 -0500 1368) if (try_futile &&
e5dc76b9afcfb (Bob Peterson 2012-08-09 12:48:46 -0500 1369) !(gh2->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB))) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1370) fail:
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1371) gh->gh_error = GLR_TRYFAILED;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1372) gfs2_holder_wake(gh);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1373) return;
b4c20166dcfca (Abhijith Das 2007-09-13 23:35:27 -0500 1374) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1375) if (test_bit(HIF_HOLDER, &gh2->gh_iflags))
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1376) continue;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1377) if (unlikely((gh->gh_flags & LM_FLAG_PRIORITY) && !insert_pt))
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1378) insert_pt = &gh2->gh_list;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1379) }
edae38a643127 (Steven Whitehouse 2011-01-31 09:38:12 +0000 1380) trace_gfs2_glock_queue(gh, 1);
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 1381) gfs2_glstats_inc(gl, GFS2_LKS_QCOUNT);
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 1382) gfs2_sbstats_inc(gl, GFS2_LKS_QCOUNT);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1383) if (likely(insert_pt == NULL)) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1384) list_add_tail(&gh->gh_list, &gl->gl_holders);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1385) if (unlikely(gh->gh_flags & LM_FLAG_PRIORITY))
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1386) goto do_cancel;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1387) return;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1388) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1389) list_add_tail(&gh->gh_list, insert_pt);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1390) do_cancel:
969183bc68bc2 (Andreas Gruenbacher 2020-02-03 19:22:45 +0100 1391) gh = list_first_entry(&gl->gl_holders, struct gfs2_holder, gh_list);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1392) if (!(gh->gh_flags & LM_FLAG_PRIORITY)) {
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 1393) spin_unlock(&gl->gl_lockref.lock);
048bca2237393 (Steven Whitehouse 2008-05-23 14:46:04 +0100 1394) if (sdp->sd_lockstruct.ls_ops->lm_cancel)
f057f6cdf6417 (Steven Whitehouse 2009-01-12 10:43:39 +0000 1395) sdp->sd_lockstruct.ls_ops->lm_cancel(gl);
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 1396) spin_lock(&gl->gl_lockref.lock);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1397) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1398) return;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1399)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1400) trap_recursive:
e54c78a27fcde (Bob Peterson 2018-10-03 08:47:36 -0500 1401) fs_err(sdp, "original: %pSR\n", (void *)gh2->gh_ip);
e54c78a27fcde (Bob Peterson 2018-10-03 08:47:36 -0500 1402) fs_err(sdp, "pid: %d\n", pid_nr(gh2->gh_owner_pid));
e54c78a27fcde (Bob Peterson 2018-10-03 08:47:36 -0500 1403) fs_err(sdp, "lock type: %d req lock state : %d\n",
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1404) gh2->gh_gl->gl_name.ln_type, gh2->gh_state);
e54c78a27fcde (Bob Peterson 2018-10-03 08:47:36 -0500 1405) fs_err(sdp, "new: %pSR\n", (void *)gh->gh_ip);
e54c78a27fcde (Bob Peterson 2018-10-03 08:47:36 -0500 1406) fs_err(sdp, "pid: %d\n", pid_nr(gh->gh_owner_pid));
e54c78a27fcde (Bob Peterson 2018-10-03 08:47:36 -0500 1407) fs_err(sdp, "lock type: %d req lock state : %d\n",
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1408) gh->gh_gl->gl_name.ln_type, gh->gh_state);
3792ce973f07a (Bob Peterson 2019-05-09 09:21:48 -0500 1409) gfs2_dump_glock(NULL, gl, true);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1410) BUG();
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1411) }
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1412)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1413) /**
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1414) * gfs2_glock_nq - enqueue a struct gfs2_holder onto a glock (acquire a glock)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1415) * @gh: the holder structure
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1416) *
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1417) * if (gh->gh_flags & GL_ASYNC), this never returns an error
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1418) *
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1419) * Returns: 0, GLR_TRYFAILED, or errno on failure
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1420) */
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1421)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1422) int gfs2_glock_nq(struct gfs2_holder *gh)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1423) {
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1424) struct gfs2_glock *gl = gh->gh_gl;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1425) int error = 0;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1426)
601ef0d52e961 (Bob Peterson 2020-01-28 20:23:45 +0100 1427) if (glock_blocked_by_withdraw(gl) && !(gh->gh_flags & LM_FLAG_NOEXP))
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1428) return -EIO;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1429)
f42ab0852946c (Steven Whitehouse 2011-04-14 16:50:31 +0100 1430) if (test_bit(GLF_LRU, &gl->gl_flags))
f42ab0852946c (Steven Whitehouse 2011-04-14 16:50:31 +0100 1431) gfs2_glock_remove_from_lru(gl);
f42ab0852946c (Steven Whitehouse 2011-04-14 16:50:31 +0100 1432)
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 1433) spin_lock(&gl->gl_lockref.lock);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1434) add_to_queue(gh);
01b172b7b1014 (Bob Peterson 2014-03-12 10:32:20 -0400 1435) if (unlikely((LM_FLAG_NOEXP & gh->gh_flags) &&
01b172b7b1014 (Bob Peterson 2014-03-12 10:32:20 -0400 1436) test_and_clear_bit(GLF_FROZEN, &gl->gl_flags))) {
0809f6ec18bbc (Steven Whitehouse 2010-08-02 10:15:17 +0100 1437) set_bit(GLF_REPLY_PENDING, &gl->gl_flags);
01b172b7b1014 (Bob Peterson 2014-03-12 10:32:20 -0400 1438) gl->gl_lockref.count++;
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 1439) __gfs2_glock_queue_work(gl, 0);
01b172b7b1014 (Bob Peterson 2014-03-12 10:32:20 -0400 1440) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1441) run_queue(gl, 1);
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 1442) spin_unlock(&gl->gl_lockref.lock);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1443)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1444) if (!(gh->gh_flags & GL_ASYNC))
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1445) error = gfs2_glock_wait(gh);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1446)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1447) return error;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1448) }
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1449)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1450) /**
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1451) * gfs2_glock_poll - poll to see if an async request has been completed
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1452) * @gh: the holder
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1453) *
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1454) * Returns: 1 if the request is ready to be gfs2_glock_wait()ed on
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1455) */
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1456)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1457) int gfs2_glock_poll(struct gfs2_holder *gh)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1458) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1459) return test_bit(HIF_WAIT, &gh->gh_iflags) ? 0 : 1;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1460) }
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1461)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1462) /**
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1463) * gfs2_glock_dq - dequeue a struct gfs2_holder from a glock (release a glock)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1464) * @gh: the glock holder
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1465) *
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1466) */
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1467)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1468) void gfs2_glock_dq(struct gfs2_holder *gh)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1469) {
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1470) struct gfs2_glock *gl = gh->gh_gl;
601ef0d52e961 (Bob Peterson 2020-01-28 20:23:45 +0100 1471) struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
c4f68a130fc17 (Benjamin Marzinski 2007-08-23 13:19:05 -0500 1472) unsigned delay = 0;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1473) int fast_path = 0;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1474)
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 1475) spin_lock(&gl->gl_lockref.lock);
601ef0d52e961 (Bob Peterson 2020-01-28 20:23:45 +0100 1476) /*
601ef0d52e961 (Bob Peterson 2020-01-28 20:23:45 +0100 1477) * If we're in the process of file system withdraw, we cannot just
601ef0d52e961 (Bob Peterson 2020-01-28 20:23:45 +0100 1478) * dequeue any glocks until our journal is recovered, lest we
601ef0d52e961 (Bob Peterson 2020-01-28 20:23:45 +0100 1479) * introduce file system corruption. We need two exceptions to this
601ef0d52e961 (Bob Peterson 2020-01-28 20:23:45 +0100 1480) * rule: We need to allow unlocking of nondisk glocks and the glock
601ef0d52e961 (Bob Peterson 2020-01-28 20:23:45 +0100 1481) * for our own journal that needs recovery.
601ef0d52e961 (Bob Peterson 2020-01-28 20:23:45 +0100 1482) */
601ef0d52e961 (Bob Peterson 2020-01-28 20:23:45 +0100 1483) if (test_bit(SDF_WITHDRAW_RECOVERY, &sdp->sd_flags) &&
601ef0d52e961 (Bob Peterson 2020-01-28 20:23:45 +0100 1484) glock_blocked_by_withdraw(gl) &&
601ef0d52e961 (Bob Peterson 2020-01-28 20:23:45 +0100 1485) gh->gh_gl != sdp->sd_jinode_gl) {
601ef0d52e961 (Bob Peterson 2020-01-28 20:23:45 +0100 1486) sdp->sd_glock_dqs_held++;
20265d9a67e40 (Bob Peterson 2021-05-18 09:12:10 -0400 1487) spin_unlock(&gl->gl_lockref.lock);
601ef0d52e961 (Bob Peterson 2020-01-28 20:23:45 +0100 1488) might_sleep();
601ef0d52e961 (Bob Peterson 2020-01-28 20:23:45 +0100 1489) wait_on_bit(&sdp->sd_flags, SDF_WITHDRAW_RECOVERY,
601ef0d52e961 (Bob Peterson 2020-01-28 20:23:45 +0100 1490) TASK_UNINTERRUPTIBLE);
20265d9a67e40 (Bob Peterson 2021-05-18 09:12:10 -0400 1491) spin_lock(&gl->gl_lockref.lock);
601ef0d52e961 (Bob Peterson 2020-01-28 20:23:45 +0100 1492) }
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1493) if (gh->gh_flags & GL_NOCACHE)
81ffbf654f0cf (Steven Whitehouse 2013-04-10 10:26:55 +0100 1494) handle_callback(gl, LM_ST_UNLOCKED, 0, false);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1495)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1496) list_del_init(&gh->gh_list);
7508abc4bdac4 (Bob Peterson 2015-12-18 11:54:55 -0600 1497) clear_bit(HIF_HOLDER, &gh->gh_iflags);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1498) if (find_first_holder(gl) == NULL) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1499) if (list_empty(&gl->gl_holders) &&
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1500) !test_bit(GLF_PENDING_DEMOTE, &gl->gl_flags) &&
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1501) !test_bit(GLF_DEMOTE, &gl->gl_flags))
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 1502) fast_path = 1;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1503) }
7881ef3f33bb8 (Ross Lagerwall 2019-03-27 17:09:17 +0000 1504) if (!test_bit(GLF_LFLUSH, &gl->gl_flags) && demote_ok(gl))
4abb6ad9eae0a (Bob Peterson 2012-08-09 12:48:43 -0500 1505) gfs2_glock_add_to_lru(gl);
4abb6ad9eae0a (Bob Peterson 2012-08-09 12:48:43 -0500 1506)
63997775b795f (Steven Whitehouse 2009-06-12 08:49:20 +0100 1507) trace_gfs2_glock_queue(gh, 0);
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 1508) if (unlikely(!fast_path)) {
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 1509) gl->gl_lockref.count++;
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 1510) if (test_bit(GLF_PENDING_DEMOTE, &gl->gl_flags) &&
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 1511) !test_bit(GLF_DEMOTE, &gl->gl_flags) &&
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 1512) gl->gl_name.ln_type == LM_TYPE_INODE)
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 1513) delay = gl->gl_hold_time;
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 1514) __gfs2_glock_queue_work(gl, delay);
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 1515) }
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 1516) spin_unlock(&gl->gl_lockref.lock);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1517) }
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1518)
d93cfa9884354 (Abhijith Das 2007-06-11 08:22:32 +0100 1519) void gfs2_glock_dq_wait(struct gfs2_holder *gh)
d93cfa9884354 (Abhijith Das 2007-06-11 08:22:32 +0100 1520) {
d93cfa9884354 (Abhijith Das 2007-06-11 08:22:32 +0100 1521) struct gfs2_glock *gl = gh->gh_gl;
d93cfa9884354 (Abhijith Das 2007-06-11 08:22:32 +0100 1522) gfs2_glock_dq(gh);
81e1d45061d09 (Bob Peterson 2012-08-09 12:48:45 -0500 1523) might_sleep();
743162013d40c (NeilBrown 2014-07-07 15:16:04 +1000 1524) wait_on_bit(&gl->gl_flags, GLF_DEMOTE, TASK_UNINTERRUPTIBLE);
d93cfa9884354 (Abhijith Das 2007-06-11 08:22:32 +0100 1525) }
d93cfa9884354 (Abhijith Das 2007-06-11 08:22:32 +0100 1526)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1527) /**
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1528) * gfs2_glock_dq_uninit - dequeue a holder from a glock and initialize it
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1529) * @gh: the holder structure
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1530) *
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1531) */
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1532)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1533) void gfs2_glock_dq_uninit(struct gfs2_holder *gh)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1534) {
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1535) gfs2_glock_dq(gh);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1536) gfs2_holder_uninit(gh);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1537) }
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1538)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1539) /**
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1540) * gfs2_glock_nq_num - acquire a glock based on lock number
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1541) * @sdp: the filesystem
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1542) * @number: the lock number
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1543) * @glops: the glock operations for the type of glock
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1544) * @state: the state to acquire the glock in
25985edcedea6 (Lucas De Marchi 2011-03-30 22:57:33 -0300 1545) * @flags: modifier flags for the acquisition
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1546) * @gh: the struct gfs2_holder
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1547) *
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1548) * Returns: errno
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1549) */
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1550)
cd915493fce91 (Steven Whitehouse 2006-09-04 12:49:07 -0400 1551) int gfs2_glock_nq_num(struct gfs2_sbd *sdp, u64 number,
8fb4b536e7b9d (Steven Whitehouse 2006-08-30 09:30:00 -0400 1552) const struct gfs2_glock_operations *glops,
b58bf407ca466 (Bob Peterson 2015-07-24 09:45:43 -0500 1553) unsigned int state, u16 flags, struct gfs2_holder *gh)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1554) {
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1555) struct gfs2_glock *gl;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1556) int error;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1557)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1558) error = gfs2_glock_get(sdp, number, glops, CREATE, &gl);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1559) if (!error) {
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1560) error = gfs2_glock_nq_init(gl, state, flags, gh);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1561) gfs2_glock_put(gl);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1562) }
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1563)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1564) return error;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1565) }
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1566)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1567) /**
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1568) * glock_compare - Compare two struct gfs2_glock structures for sorting
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1569) * @arg_a: the first structure
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1570) * @arg_b: the second structure
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1571) *
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1572) */
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1573)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1574) static int glock_compare(const void *arg_a, const void *arg_b)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1575) {
a5e08a9ef50e8 (Steven Whitehouse 2006-09-09 17:07:05 -0400 1576) const struct gfs2_holder *gh_a = *(const struct gfs2_holder **)arg_a;
a5e08a9ef50e8 (Steven Whitehouse 2006-09-09 17:07:05 -0400 1577) const struct gfs2_holder *gh_b = *(const struct gfs2_holder **)arg_b;
a5e08a9ef50e8 (Steven Whitehouse 2006-09-09 17:07:05 -0400 1578) const struct lm_lockname *a = &gh_a->gh_gl->gl_name;
a5e08a9ef50e8 (Steven Whitehouse 2006-09-09 17:07:05 -0400 1579) const struct lm_lockname *b = &gh_b->gh_gl->gl_name;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1580)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1581) if (a->ln_number > b->ln_number)
a5e08a9ef50e8 (Steven Whitehouse 2006-09-09 17:07:05 -0400 1582) return 1;
a5e08a9ef50e8 (Steven Whitehouse 2006-09-09 17:07:05 -0400 1583) if (a->ln_number < b->ln_number)
a5e08a9ef50e8 (Steven Whitehouse 2006-09-09 17:07:05 -0400 1584) return -1;
1c0f4872dc4bb (Steven Whitehouse 2007-01-22 12:10:39 -0500 1585) BUG_ON(gh_a->gh_gl->gl_ops->go_type == gh_b->gh_gl->gl_ops->go_type);
a5e08a9ef50e8 (Steven Whitehouse 2006-09-09 17:07:05 -0400 1586) return 0;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1587) }
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1588)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1589) /**
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1590) * nq_m_sync - synchonously acquire more than one glock in deadlock free order
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1591) * @num_gh: the number of structures
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1592) * @ghs: an array of struct gfs2_holder structures
c551f66c5dfef (Lee Jones 2021-03-30 17:44:29 +0100 1593) * @p: placeholder for the holder structure to pass back
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1594) *
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1595) * Returns: 0 on success (all glocks acquired),
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1596) * errno on failure (no glocks acquired)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1597) */
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1598)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1599) static int nq_m_sync(unsigned int num_gh, struct gfs2_holder *ghs,
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1600) struct gfs2_holder **p)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1601) {
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1602) unsigned int x;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1603) int error = 0;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1604)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1605) for (x = 0; x < num_gh; x++)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1606) p[x] = &ghs[x];
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1607)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1608) sort(p, num_gh, sizeof(struct gfs2_holder *), glock_compare, NULL);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1609)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1610) for (x = 0; x < num_gh; x++) {
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1611) p[x]->gh_flags &= ~(LM_FLAG_TRY | GL_ASYNC);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1612)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1613) error = gfs2_glock_nq(p[x]);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1614) if (error) {
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1615) while (x--)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1616) gfs2_glock_dq(p[x]);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1617) break;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1618) }
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1619) }
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1620)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1621) return error;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1622) }
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1623)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1624) /**
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1625) * gfs2_glock_nq_m - acquire multiple glocks
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1626) * @num_gh: the number of structures
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1627) * @ghs: an array of struct gfs2_holder structures
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1628) *
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1629) *
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1630) * Returns: 0 on success (all glocks acquired),
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1631) * errno on failure (no glocks acquired)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1632) */
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1633)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1634) int gfs2_glock_nq_m(unsigned int num_gh, struct gfs2_holder *ghs)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1635) {
eaf5bd3cac921 (Steven Whitehouse 2007-06-19 15:38:17 +0100 1636) struct gfs2_holder *tmp[4];
eaf5bd3cac921 (Steven Whitehouse 2007-06-19 15:38:17 +0100 1637) struct gfs2_holder **pph = tmp;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1638) int error = 0;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1639)
eaf5bd3cac921 (Steven Whitehouse 2007-06-19 15:38:17 +0100 1640) switch(num_gh) {
eaf5bd3cac921 (Steven Whitehouse 2007-06-19 15:38:17 +0100 1641) case 0:
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1642) return 0;
eaf5bd3cac921 (Steven Whitehouse 2007-06-19 15:38:17 +0100 1643) case 1:
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1644) ghs->gh_flags &= ~(LM_FLAG_TRY | GL_ASYNC);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1645) return gfs2_glock_nq(ghs);
eaf5bd3cac921 (Steven Whitehouse 2007-06-19 15:38:17 +0100 1646) default:
eaf5bd3cac921 (Steven Whitehouse 2007-06-19 15:38:17 +0100 1647) if (num_gh <= 4)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1648) break;
6da2ec56059c3 (Kees Cook 2018-06-12 13:55:00 -0700 1649) pph = kmalloc_array(num_gh, sizeof(struct gfs2_holder *),
6da2ec56059c3 (Kees Cook 2018-06-12 13:55:00 -0700 1650) GFP_NOFS);
eaf5bd3cac921 (Steven Whitehouse 2007-06-19 15:38:17 +0100 1651) if (!pph)
eaf5bd3cac921 (Steven Whitehouse 2007-06-19 15:38:17 +0100 1652) return -ENOMEM;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1653) }
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1654)
eaf5bd3cac921 (Steven Whitehouse 2007-06-19 15:38:17 +0100 1655) error = nq_m_sync(num_gh, ghs, pph);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1656)
eaf5bd3cac921 (Steven Whitehouse 2007-06-19 15:38:17 +0100 1657) if (pph != tmp)
eaf5bd3cac921 (Steven Whitehouse 2007-06-19 15:38:17 +0100 1658) kfree(pph);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1659)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1660) return error;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1661) }
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1662)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1663) /**
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1664) * gfs2_glock_dq_m - release multiple glocks
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1665) * @num_gh: the number of structures
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1666) * @ghs: an array of struct gfs2_holder structures
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1667) *
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1668) */
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1669)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1670) void gfs2_glock_dq_m(unsigned int num_gh, struct gfs2_holder *ghs)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1671) {
fa1bbdea300a1 (Bob Peterson 2011-03-10 11:41:57 -0500 1672) while (num_gh--)
fa1bbdea300a1 (Bob Peterson 2011-03-10 11:41:57 -0500 1673) gfs2_glock_dq(&ghs[num_gh]);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1674) }
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1675)
f057f6cdf6417 (Steven Whitehouse 2009-01-12 10:43:39 +0000 1676) void gfs2_glock_cb(struct gfs2_glock *gl, unsigned int state)
da755fdb41447 (Steven Whitehouse 2008-01-30 15:34:04 +0000 1677) {
c4f68a130fc17 (Benjamin Marzinski 2007-08-23 13:19:05 -0500 1678) unsigned long delay = 0;
c4f68a130fc17 (Benjamin Marzinski 2007-08-23 13:19:05 -0500 1679) unsigned long holdtime;
c4f68a130fc17 (Benjamin Marzinski 2007-08-23 13:19:05 -0500 1680) unsigned long now = jiffies;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1681)
f057f6cdf6417 (Steven Whitehouse 2009-01-12 10:43:39 +0000 1682) gfs2_glock_hold(gl);
e2c6c8a797eea (Bob Peterson 2020-10-12 13:57:37 -0500 1683) spin_lock(&gl->gl_lockref.lock);
7cf8dcd3b68a7 (Bob Peterson 2011-06-15 11:41:48 -0400 1684) holdtime = gl->gl_tchange + gl->gl_hold_time;
e2c6c8a797eea (Bob Peterson 2020-10-12 13:57:37 -0500 1685) if (!list_empty(&gl->gl_holders) &&
7cf8dcd3b68a7 (Bob Peterson 2011-06-15 11:41:48 -0400 1686) gl->gl_name.ln_type == LM_TYPE_INODE) {
7b5e3d5fcf0d6 (Steven Whitehouse 2010-09-03 09:39:20 +0100 1687) if (time_before(now, holdtime))
7b5e3d5fcf0d6 (Steven Whitehouse 2010-09-03 09:39:20 +0100 1688) delay = holdtime - now;
7b5e3d5fcf0d6 (Steven Whitehouse 2010-09-03 09:39:20 +0100 1689) if (test_bit(GLF_REPLY_PENDING, &gl->gl_flags))
7cf8dcd3b68a7 (Bob Peterson 2011-06-15 11:41:48 -0400 1690) delay = gl->gl_hold_time;
7b5e3d5fcf0d6 (Steven Whitehouse 2010-09-03 09:39:20 +0100 1691) }
81ffbf654f0cf (Steven Whitehouse 2013-04-10 10:26:55 +0100 1692) handle_callback(gl, state, delay, true);
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 1693) __gfs2_glock_queue_work(gl, delay);
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 1694) spin_unlock(&gl->gl_lockref.lock);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1695) }
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1696)
0809f6ec18bbc (Steven Whitehouse 2010-08-02 10:15:17 +0100 1697) /**
0809f6ec18bbc (Steven Whitehouse 2010-08-02 10:15:17 +0100 1698) * gfs2_should_freeze - Figure out if glock should be frozen
0809f6ec18bbc (Steven Whitehouse 2010-08-02 10:15:17 +0100 1699) * @gl: The glock in question
0809f6ec18bbc (Steven Whitehouse 2010-08-02 10:15:17 +0100 1700) *
0809f6ec18bbc (Steven Whitehouse 2010-08-02 10:15:17 +0100 1701) * Glocks are not frozen if (a) the result of the dlm operation is
0809f6ec18bbc (Steven Whitehouse 2010-08-02 10:15:17 +0100 1702) * an error, (b) the locking operation was an unlock operation or
0809f6ec18bbc (Steven Whitehouse 2010-08-02 10:15:17 +0100 1703) * (c) if there is a "noexp" flagged request anywhere in the queue
0809f6ec18bbc (Steven Whitehouse 2010-08-02 10:15:17 +0100 1704) *
0809f6ec18bbc (Steven Whitehouse 2010-08-02 10:15:17 +0100 1705) * Returns: 1 if freezing should occur, 0 otherwise
0809f6ec18bbc (Steven Whitehouse 2010-08-02 10:15:17 +0100 1706) */
0809f6ec18bbc (Steven Whitehouse 2010-08-02 10:15:17 +0100 1707)
0809f6ec18bbc (Steven Whitehouse 2010-08-02 10:15:17 +0100 1708) static int gfs2_should_freeze(const struct gfs2_glock *gl)
0809f6ec18bbc (Steven Whitehouse 2010-08-02 10:15:17 +0100 1709) {
0809f6ec18bbc (Steven Whitehouse 2010-08-02 10:15:17 +0100 1710) const struct gfs2_holder *gh;
0809f6ec18bbc (Steven Whitehouse 2010-08-02 10:15:17 +0100 1711)
0809f6ec18bbc (Steven Whitehouse 2010-08-02 10:15:17 +0100 1712) if (gl->gl_reply & ~LM_OUT_ST_MASK)
0809f6ec18bbc (Steven Whitehouse 2010-08-02 10:15:17 +0100 1713) return 0;
0809f6ec18bbc (Steven Whitehouse 2010-08-02 10:15:17 +0100 1714) if (gl->gl_target == LM_ST_UNLOCKED)
0809f6ec18bbc (Steven Whitehouse 2010-08-02 10:15:17 +0100 1715) return 0;
0809f6ec18bbc (Steven Whitehouse 2010-08-02 10:15:17 +0100 1716)
0809f6ec18bbc (Steven Whitehouse 2010-08-02 10:15:17 +0100 1717) list_for_each_entry(gh, &gl->gl_holders, gh_list) {
0809f6ec18bbc (Steven Whitehouse 2010-08-02 10:15:17 +0100 1718) if (test_bit(HIF_HOLDER, &gh->gh_iflags))
0809f6ec18bbc (Steven Whitehouse 2010-08-02 10:15:17 +0100 1719) continue;
0809f6ec18bbc (Steven Whitehouse 2010-08-02 10:15:17 +0100 1720) if (LM_FLAG_NOEXP & gh->gh_flags)
0809f6ec18bbc (Steven Whitehouse 2010-08-02 10:15:17 +0100 1721) return 0;
0809f6ec18bbc (Steven Whitehouse 2010-08-02 10:15:17 +0100 1722) }
0809f6ec18bbc (Steven Whitehouse 2010-08-02 10:15:17 +0100 1723)
0809f6ec18bbc (Steven Whitehouse 2010-08-02 10:15:17 +0100 1724) return 1;
0809f6ec18bbc (Steven Whitehouse 2010-08-02 10:15:17 +0100 1725) }
0809f6ec18bbc (Steven Whitehouse 2010-08-02 10:15:17 +0100 1726)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1727) /**
f057f6cdf6417 (Steven Whitehouse 2009-01-12 10:43:39 +0000 1728) * gfs2_glock_complete - Callback used by locking
f057f6cdf6417 (Steven Whitehouse 2009-01-12 10:43:39 +0000 1729) * @gl: Pointer to the glock
f057f6cdf6417 (Steven Whitehouse 2009-01-12 10:43:39 +0000 1730) * @ret: The return value from the dlm
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1731) *
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 1732) * The gl_reply field is under the gl_lockref.lock lock so that it is ok
47a25380e37f4 (Steven Whitehouse 2010-11-30 15:49:31 +0000 1733) * to use a bitfield shared with other glock state fields.
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1734) */
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1735)
f057f6cdf6417 (Steven Whitehouse 2009-01-12 10:43:39 +0000 1736) void gfs2_glock_complete(struct gfs2_glock *gl, int ret)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1737) {
15562c439d0a1 (Bob Peterson 2015-03-16 11:52:05 -0500 1738) struct lm_lockstruct *ls = &gl->gl_name.ln_sbd->sd_lockstruct;
0809f6ec18bbc (Steven Whitehouse 2010-08-02 10:15:17 +0100 1739)
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 1740) spin_lock(&gl->gl_lockref.lock);
f057f6cdf6417 (Steven Whitehouse 2009-01-12 10:43:39 +0000 1741) gl->gl_reply = ret;
0809f6ec18bbc (Steven Whitehouse 2010-08-02 10:15:17 +0100 1742)
e0c2a9aa1e684 (David Teigland 2012-01-09 17:18:05 -0500 1743) if (unlikely(test_bit(DFL_BLOCK_LOCKS, &ls->ls_recover_flags))) {
0809f6ec18bbc (Steven Whitehouse 2010-08-02 10:15:17 +0100 1744) if (gfs2_should_freeze(gl)) {
f057f6cdf6417 (Steven Whitehouse 2009-01-12 10:43:39 +0000 1745) set_bit(GLF_FROZEN, &gl->gl_flags);
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 1746) spin_unlock(&gl->gl_lockref.lock);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1747) return;
0809f6ec18bbc (Steven Whitehouse 2010-08-02 10:15:17 +0100 1748) }
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1749) }
47a25380e37f4 (Steven Whitehouse 2010-11-30 15:49:31 +0000 1750)
e66cf161098a6 (Steven Whitehouse 2013-10-15 15:18:08 +0100 1751) gl->gl_lockref.count++;
f057f6cdf6417 (Steven Whitehouse 2009-01-12 10:43:39 +0000 1752) set_bit(GLF_REPLY_PENDING, &gl->gl_flags);
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 1753) __gfs2_glock_queue_work(gl, 0);
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 1754) spin_unlock(&gl->gl_lockref.lock);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1755) }
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1756)
4f0f586bf0c89 (Sami Tolvanen 2021-04-08 11:28:34 -0700 1757) static int glock_cmp(void *priv, const struct list_head *a,
4f0f586bf0c89 (Sami Tolvanen 2021-04-08 11:28:34 -0700 1758) const struct list_head *b)
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1759) {
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1760) struct gfs2_glock *gla, *glb;
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1761)
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1762) gla = list_entry(a, struct gfs2_glock, gl_lru);
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1763) glb = list_entry(b, struct gfs2_glock, gl_lru);
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1764)
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1765) if (gla->gl_name.ln_number > glb->gl_name.ln_number)
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1766) return 1;
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1767) if (gla->gl_name.ln_number < glb->gl_name.ln_number)
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1768) return -1;
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1769)
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1770) return 0;
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1771) }
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1772)
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1773) /**
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1774) * gfs2_dispose_glock_lru - Demote a list of glocks
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1775) * @list: The list to dispose of
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1776) *
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1777) * Disposing of glocks may involve disk accesses, so that here we sort
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1778) * the glocks by number (i.e. disk location of the inodes) so that if
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1779) * there are any such accesses, they'll be sent in order (mostly).
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1780) *
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1781) * Must be called under the lru_lock, but may drop and retake this
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1782) * lock. While the lru_lock is dropped, entries may vanish from the
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1783) * list, but no new entries will appear on the list (since it is
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1784) * private)
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1785) */
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1786)
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1787) static void gfs2_dispose_glock_lru(struct list_head *list)
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1788) __releases(&lru_lock)
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1789) __acquires(&lru_lock)
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1790) {
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1791) struct gfs2_glock *gl;
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1792)
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1793) list_sort(NULL, list, glock_cmp);
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1794)
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1795) while(!list_empty(list)) {
969183bc68bc2 (Andreas Gruenbacher 2020-02-03 19:22:45 +0100 1796) gl = list_first_entry(list, struct gfs2_glock, gl_lru);
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1797) list_del_init(&gl->gl_lru);
1ab19c5de4c53 (Hillf Danton 2021-05-18 16:46:25 +0800 1798) clear_bit(GLF_LRU, &gl->gl_flags);
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 1799) if (!spin_trylock(&gl->gl_lockref.lock)) {
94a09a3999ee9 (Steven Whitehouse 2014-06-23 14:43:32 +0100 1800) add_back_to_lru:
e66cf161098a6 (Steven Whitehouse 2013-10-15 15:18:08 +0100 1801) list_add(&gl->gl_lru, &lru_list);
7881ef3f33bb8 (Ross Lagerwall 2019-03-27 17:09:17 +0000 1802) set_bit(GLF_LRU, &gl->gl_flags);
e66cf161098a6 (Steven Whitehouse 2013-10-15 15:18:08 +0100 1803) atomic_inc(&lru_count);
e66cf161098a6 (Steven Whitehouse 2013-10-15 15:18:08 +0100 1804) continue;
e66cf161098a6 (Steven Whitehouse 2013-10-15 15:18:08 +0100 1805) }
94a09a3999ee9 (Steven Whitehouse 2014-06-23 14:43:32 +0100 1806) if (test_and_set_bit(GLF_LOCK, &gl->gl_flags)) {
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 1807) spin_unlock(&gl->gl_lockref.lock);
94a09a3999ee9 (Steven Whitehouse 2014-06-23 14:43:32 +0100 1808) goto add_back_to_lru;
94a09a3999ee9 (Steven Whitehouse 2014-06-23 14:43:32 +0100 1809) }
e66cf161098a6 (Steven Whitehouse 2013-10-15 15:18:08 +0100 1810) gl->gl_lockref.count++;
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1811) if (demote_ok(gl))
81ffbf654f0cf (Steven Whitehouse 2013-04-10 10:26:55 +0100 1812) handle_callback(gl, LM_ST_UNLOCKED, 0, false);
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1813) WARN_ON(!test_and_clear_bit(GLF_LOCK, &gl->gl_flags));
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 1814) __gfs2_glock_queue_work(gl, 0);
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 1815) spin_unlock(&gl->gl_lockref.lock);
94a09a3999ee9 (Steven Whitehouse 2014-06-23 14:43:32 +0100 1816) cond_resched_lock(&lru_lock);
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1817) }
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1818) }
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1819)
2a00585593823 (Steven Whitehouse 2012-12-14 12:28:30 +0000 1820) /**
2a00585593823 (Steven Whitehouse 2012-12-14 12:28:30 +0000 1821) * gfs2_scan_glock_lru - Scan the LRU looking for locks to demote
2a00585593823 (Steven Whitehouse 2012-12-14 12:28:30 +0000 1822) * @nr: The number of entries to scan
2a00585593823 (Steven Whitehouse 2012-12-14 12:28:30 +0000 1823) *
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1824) * This function selects the entries on the LRU which are able to
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1825) * be demoted, and then kicks off the process by calling
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1826) * gfs2_dispose_glock_lru() above.
2a00585593823 (Steven Whitehouse 2012-12-14 12:28:30 +0000 1827) */
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1828)
1ab6c4997e04a (Dave Chinner 2013-08-28 10:18:09 +1000 1829) static long gfs2_scan_glock_lru(int nr)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1830) {
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1831) struct gfs2_glock *gl;
97cc1025b1a91 (Steven Whitehouse 2008-11-20 13:39:47 +0000 1832) LIST_HEAD(skipped);
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1833) LIST_HEAD(dispose);
1ab6c4997e04a (Dave Chinner 2013-08-28 10:18:09 +1000 1834) long freed = 0;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1835)
97cc1025b1a91 (Steven Whitehouse 2008-11-20 13:39:47 +0000 1836) spin_lock(&lru_lock);
1ab6c4997e04a (Dave Chinner 2013-08-28 10:18:09 +1000 1837) while ((nr-- >= 0) && !list_empty(&lru_list)) {
969183bc68bc2 (Andreas Gruenbacher 2020-02-03 19:22:45 +0100 1838) gl = list_first_entry(&lru_list, struct gfs2_glock, gl_lru);
97cc1025b1a91 (Steven Whitehouse 2008-11-20 13:39:47 +0000 1839)
97cc1025b1a91 (Steven Whitehouse 2008-11-20 13:39:47 +0000 1840) /* Test for being demotable */
94a09a3999ee9 (Steven Whitehouse 2014-06-23 14:43:32 +0100 1841) if (!test_bit(GLF_LOCK, &gl->gl_flags)) {
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1842) list_move(&gl->gl_lru, &dispose);
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1843) atomic_dec(&lru_count);
1ab6c4997e04a (Dave Chinner 2013-08-28 10:18:09 +1000 1844) freed++;
2163b1e616c41 (Steven Whitehouse 2009-06-25 16:30:26 +0100 1845) continue;
97cc1025b1a91 (Steven Whitehouse 2008-11-20 13:39:47 +0000 1846) }
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1847)
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1848) list_move(&gl->gl_lru, &skipped);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1849) }
97cc1025b1a91 (Steven Whitehouse 2008-11-20 13:39:47 +0000 1850) list_splice(&skipped, &lru_list);
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1851) if (!list_empty(&dispose))
4506a519f2a76 (Steven Whitehouse 2013-02-01 20:36:03 +0000 1852) gfs2_dispose_glock_lru(&dispose);
97cc1025b1a91 (Steven Whitehouse 2008-11-20 13:39:47 +0000 1853) spin_unlock(&lru_lock);
1ab6c4997e04a (Dave Chinner 2013-08-28 10:18:09 +1000 1854)
1ab6c4997e04a (Dave Chinner 2013-08-28 10:18:09 +1000 1855) return freed;
2a00585593823 (Steven Whitehouse 2012-12-14 12:28:30 +0000 1856) }
2a00585593823 (Steven Whitehouse 2012-12-14 12:28:30 +0000 1857)
1ab6c4997e04a (Dave Chinner 2013-08-28 10:18:09 +1000 1858) static unsigned long gfs2_glock_shrink_scan(struct shrinker *shrink,
1ab6c4997e04a (Dave Chinner 2013-08-28 10:18:09 +1000 1859) struct shrink_control *sc)
2a00585593823 (Steven Whitehouse 2012-12-14 12:28:30 +0000 1860) {
1ab6c4997e04a (Dave Chinner 2013-08-28 10:18:09 +1000 1861) if (!(sc->gfp_mask & __GFP_FS))
1ab6c4997e04a (Dave Chinner 2013-08-28 10:18:09 +1000 1862) return SHRINK_STOP;
1ab6c4997e04a (Dave Chinner 2013-08-28 10:18:09 +1000 1863) return gfs2_scan_glock_lru(sc->nr_to_scan);
1ab6c4997e04a (Dave Chinner 2013-08-28 10:18:09 +1000 1864) }
2a00585593823 (Steven Whitehouse 2012-12-14 12:28:30 +0000 1865)
1ab6c4997e04a (Dave Chinner 2013-08-28 10:18:09 +1000 1866) static unsigned long gfs2_glock_shrink_count(struct shrinker *shrink,
1ab6c4997e04a (Dave Chinner 2013-08-28 10:18:09 +1000 1867) struct shrink_control *sc)
1ab6c4997e04a (Dave Chinner 2013-08-28 10:18:09 +1000 1868) {
55f841ce9395a (Glauber Costa 2013-08-28 10:17:53 +1000 1869) return vfs_pressure_ratio(atomic_read(&lru_count));
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1870) }
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1871)
97cc1025b1a91 (Steven Whitehouse 2008-11-20 13:39:47 +0000 1872) static struct shrinker glock_shrinker = {
97cc1025b1a91 (Steven Whitehouse 2008-11-20 13:39:47 +0000 1873) .seeks = DEFAULT_SEEKS,
1ab6c4997e04a (Dave Chinner 2013-08-28 10:18:09 +1000 1874) .count_objects = gfs2_glock_shrink_count,
1ab6c4997e04a (Dave Chinner 2013-08-28 10:18:09 +1000 1875) .scan_objects = gfs2_glock_shrink_scan,
97cc1025b1a91 (Steven Whitehouse 2008-11-20 13:39:47 +0000 1876) };
97cc1025b1a91 (Steven Whitehouse 2008-11-20 13:39:47 +0000 1877)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1878) /**
dbffb29dac6a8 (Bob Peterson 2020-10-12 15:04:20 -0500 1879) * glock_hash_walk - Call a function for glock in a hash bucket
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1880) * @examiner: the function
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1881) * @sdp: the filesystem
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1882) *
98687f426bb3e (Herbert Xu 2017-02-11 19:26:45 +0800 1883) * Note that the function can be called multiple times on the same
98687f426bb3e (Herbert Xu 2017-02-11 19:26:45 +0800 1884) * object. So the user must ensure that the function can cope with
98687f426bb3e (Herbert Xu 2017-02-11 19:26:45 +0800 1885) * that.
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1886) */
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1887)
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 1888) static void glock_hash_walk(glock_examiner examiner, const struct gfs2_sbd *sdp)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1889) {
bc015cb84129e (Steven Whitehouse 2011-01-19 09:30:01 +0000 1890) struct gfs2_glock *gl;
98687f426bb3e (Herbert Xu 2017-02-11 19:26:45 +0800 1891) struct rhashtable_iter iter;
98687f426bb3e (Herbert Xu 2017-02-11 19:26:45 +0800 1892)
98687f426bb3e (Herbert Xu 2017-02-11 19:26:45 +0800 1893) rhashtable_walk_enter(&gl_hash_table, &iter);
98687f426bb3e (Herbert Xu 2017-02-11 19:26:45 +0800 1894)
98687f426bb3e (Herbert Xu 2017-02-11 19:26:45 +0800 1895) do {
97a6ec4ac021f (Tom Herbert 2017-12-04 10:31:41 -0800 1896) rhashtable_walk_start(&iter);
98687f426bb3e (Herbert Xu 2017-02-11 19:26:45 +0800 1897)
98687f426bb3e (Herbert Xu 2017-02-11 19:26:45 +0800 1898) while ((gl = rhashtable_walk_next(&iter)) && !IS_ERR(gl))
27c3b415f6ffe (Bob Peterson 2017-08-18 09:15:13 -0500 1899) if (gl->gl_name.ln_sbd == sdp &&
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 1900) lockref_get_not_dead(&gl->gl_lockref))
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 1901) examiner(gl);
98687f426bb3e (Herbert Xu 2017-02-11 19:26:45 +0800 1902)
98687f426bb3e (Herbert Xu 2017-02-11 19:26:45 +0800 1903) rhashtable_walk_stop(&iter);
98687f426bb3e (Herbert Xu 2017-02-11 19:26:45 +0800 1904) } while (cond_resched(), gl == ERR_PTR(-EAGAIN));
98687f426bb3e (Herbert Xu 2017-02-11 19:26:45 +0800 1905)
98687f426bb3e (Herbert Xu 2017-02-11 19:26:45 +0800 1906) rhashtable_walk_exit(&iter);
bc015cb84129e (Steven Whitehouse 2011-01-19 09:30:01 +0000 1907) }
bc015cb84129e (Steven Whitehouse 2011-01-19 09:30:01 +0000 1908)
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1909) bool gfs2_queue_delete_work(struct gfs2_glock *gl, unsigned long delay)
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1910) {
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1911) bool queued;
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1912)
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1913) spin_lock(&gl->gl_lockref.lock);
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1914) queued = queue_delayed_work(gfs2_delete_workqueue,
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1915) &gl->gl_delete, delay);
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1916) if (queued)
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1917) set_bit(GLF_PENDING_DELETE, &gl->gl_flags);
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1918) spin_unlock(&gl->gl_lockref.lock);
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1919) return queued;
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1920) }
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1921)
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1922) void gfs2_cancel_delete_work(struct gfs2_glock *gl)
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1923) {
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1924) if (cancel_delayed_work_sync(&gl->gl_delete)) {
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1925) clear_bit(GLF_PENDING_DELETE, &gl->gl_flags);
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1926) gfs2_glock_put(gl);
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1927) }
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1928) }
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1929)
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1930) bool gfs2_delete_work_queued(const struct gfs2_glock *gl)
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1931) {
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1932) return test_bit(GLF_PENDING_DELETE, &gl->gl_flags);
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1933) }
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1934)
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1935) static void flush_delete_work(struct gfs2_glock *gl)
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1936) {
2ffed5290b3bf (Bob Peterson 2020-10-15 11:16:48 -0500 1937) if (gl->gl_name.ln_type == LM_TYPE_IOPEN) {
2ffed5290b3bf (Bob Peterson 2020-10-15 11:16:48 -0500 1938) if (cancel_delayed_work(&gl->gl_delete)) {
2ffed5290b3bf (Bob Peterson 2020-10-15 11:16:48 -0500 1939) queue_delayed_work(gfs2_delete_workqueue,
2ffed5290b3bf (Bob Peterson 2020-10-15 11:16:48 -0500 1940) &gl->gl_delete, 0);
2ffed5290b3bf (Bob Peterson 2020-10-15 11:16:48 -0500 1941) }
34244d711dea5 (Andreas Gruenbacher 2020-06-10 18:31:56 +0200 1942) }
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1943) gfs2_glock_queue_work(gl, 0);
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1944) }
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1945)
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1946) void gfs2_flush_delete_work(struct gfs2_sbd *sdp)
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1947) {
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1948) glock_hash_walk(flush_delete_work, sdp);
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1949) flush_workqueue(gfs2_delete_workqueue);
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1950) }
a0e3cc65fa29f (Andreas Gruenbacher 2020-01-16 20:12:26 +0100 1951)
f057f6cdf6417 (Steven Whitehouse 2009-01-12 10:43:39 +0000 1952) /**
f057f6cdf6417 (Steven Whitehouse 2009-01-12 10:43:39 +0000 1953) * thaw_glock - thaw out a glock which has an unprocessed reply waiting
f057f6cdf6417 (Steven Whitehouse 2009-01-12 10:43:39 +0000 1954) * @gl: The glock to thaw
f057f6cdf6417 (Steven Whitehouse 2009-01-12 10:43:39 +0000 1955) *
f057f6cdf6417 (Steven Whitehouse 2009-01-12 10:43:39 +0000 1956) */
f057f6cdf6417 (Steven Whitehouse 2009-01-12 10:43:39 +0000 1957)
f057f6cdf6417 (Steven Whitehouse 2009-01-12 10:43:39 +0000 1958) static void thaw_glock(struct gfs2_glock *gl)
f057f6cdf6417 (Steven Whitehouse 2009-01-12 10:43:39 +0000 1959) {
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 1960) if (!test_and_clear_bit(GLF_FROZEN, &gl->gl_flags)) {
f057f6cdf6417 (Steven Whitehouse 2009-01-12 10:43:39 +0000 1961) gfs2_glock_put(gl);
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 1962) return;
7286b31eaba64 (Steven Whitehouse 2013-08-20 09:35:09 +0100 1963) }
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 1964) set_bit(GLF_REPLY_PENDING, &gl->gl_flags);
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 1965) gfs2_glock_queue_work(gl, 0);
f057f6cdf6417 (Steven Whitehouse 2009-01-12 10:43:39 +0000 1966) }
f057f6cdf6417 (Steven Whitehouse 2009-01-12 10:43:39 +0000 1967)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1968) /**
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1969) * clear_glock - look at a glock and see if we can free it from glock cache
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1970) * @gl: the glock to look at
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1971) *
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1972) */
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1973)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1974) static void clear_glock(struct gfs2_glock *gl)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1975) {
f42ab0852946c (Steven Whitehouse 2011-04-14 16:50:31 +0100 1976) gfs2_glock_remove_from_lru(gl);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1977)
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 1978) spin_lock(&gl->gl_lockref.lock);
c741c4551237f (Steven Whitehouse 2010-09-29 14:20:52 +0100 1979) if (gl->gl_state != LM_ST_UNLOCKED)
81ffbf654f0cf (Steven Whitehouse 2013-04-10 10:26:55 +0100 1980) handle_callback(gl, LM_ST_UNLOCKED, 0, false);
6b0c7440bcb4b (Andreas Gruenbacher 2017-06-30 08:10:01 -0500 1981) __gfs2_glock_queue_work(gl, 0);
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 1982) spin_unlock(&gl->gl_lockref.lock);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1983) }
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 1984)
f057f6cdf6417 (Steven Whitehouse 2009-01-12 10:43:39 +0000 1985) /**
f057f6cdf6417 (Steven Whitehouse 2009-01-12 10:43:39 +0000 1986) * gfs2_glock_thaw - Thaw any frozen glocks
f057f6cdf6417 (Steven Whitehouse 2009-01-12 10:43:39 +0000 1987) * @sdp: The super block
f057f6cdf6417 (Steven Whitehouse 2009-01-12 10:43:39 +0000 1988) *
f057f6cdf6417 (Steven Whitehouse 2009-01-12 10:43:39 +0000 1989) */
f057f6cdf6417 (Steven Whitehouse 2009-01-12 10:43:39 +0000 1990)
f057f6cdf6417 (Steven Whitehouse 2009-01-12 10:43:39 +0000 1991) void gfs2_glock_thaw(struct gfs2_sbd *sdp)
f057f6cdf6417 (Steven Whitehouse 2009-01-12 10:43:39 +0000 1992) {
bc015cb84129e (Steven Whitehouse 2011-01-19 09:30:01 +0000 1993) glock_hash_walk(thaw_glock, sdp);
bc015cb84129e (Steven Whitehouse 2011-01-19 09:30:01 +0000 1994) }
f057f6cdf6417 (Steven Whitehouse 2009-01-12 10:43:39 +0000 1995)
3792ce973f07a (Bob Peterson 2019-05-09 09:21:48 -0500 1996) static void dump_glock(struct seq_file *seq, struct gfs2_glock *gl, bool fsid)
bc015cb84129e (Steven Whitehouse 2011-01-19 09:30:01 +0000 1997) {
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 1998) spin_lock(&gl->gl_lockref.lock);
3792ce973f07a (Bob Peterson 2019-05-09 09:21:48 -0500 1999) gfs2_dump_glock(seq, gl, fsid);
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 2000) spin_unlock(&gl->gl_lockref.lock);
bc015cb84129e (Steven Whitehouse 2011-01-19 09:30:01 +0000 2001) }
bc015cb84129e (Steven Whitehouse 2011-01-19 09:30:01 +0000 2002)
bc015cb84129e (Steven Whitehouse 2011-01-19 09:30:01 +0000 2003) static void dump_glock_func(struct gfs2_glock *gl)
bc015cb84129e (Steven Whitehouse 2011-01-19 09:30:01 +0000 2004) {
3792ce973f07a (Bob Peterson 2019-05-09 09:21:48 -0500 2005) dump_glock(NULL, gl, true);
f057f6cdf6417 (Steven Whitehouse 2009-01-12 10:43:39 +0000 2006) }
f057f6cdf6417 (Steven Whitehouse 2009-01-12 10:43:39 +0000 2007)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 2008) /**
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 2009) * gfs2_gl_hash_clear - Empty out the glock hash table
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 2010) * @sdp: the filesystem
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 2011) *
1bdad606338de (Steven Whitehouse 2008-06-03 14:09:53 +0100 2012) * Called when unmounting the filesystem.
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 2013) */
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 2014)
fefc03bfedeff (Steven Whitehouse 2008-12-19 15:32:06 +0000 2015) void gfs2_gl_hash_clear(struct gfs2_sbd *sdp)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 2016) {
fb6791d100d1b (David Teigland 2012-11-13 10:58:56 -0500 2017) set_bit(SDF_SKIP_DLM_UNLOCK, &sdp->sd_flags);
222cb538f5f18 (Bob Peterson 2013-04-25 12:49:17 -0400 2018) flush_workqueue(glock_workqueue);
bc015cb84129e (Steven Whitehouse 2011-01-19 09:30:01 +0000 2019) glock_hash_walk(clear_glock, sdp);
8f05228ee7c8f (Steven Whitehouse 2010-01-29 15:21:27 +0000 2020) flush_workqueue(glock_workqueue);
2aba1b5b4f78d (Bob Peterson 2015-05-19 09:11:23 -0500 2021) wait_event_timeout(sdp->sd_glock_wait,
2aba1b5b4f78d (Bob Peterson 2015-05-19 09:11:23 -0500 2022) atomic_read(&sdp->sd_glock_disposal) == 0,
2aba1b5b4f78d (Bob Peterson 2015-05-19 09:11:23 -0500 2023) HZ * 600);
bc015cb84129e (Steven Whitehouse 2011-01-19 09:30:01 +0000 2024) glock_hash_walk(dump_glock_func, sdp);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 2025) }
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 2026)
813e0c46c9e2a (Steven Whitehouse 2008-11-18 13:38:48 +0000 2027) void gfs2_glock_finish_truncate(struct gfs2_inode *ip)
813e0c46c9e2a (Steven Whitehouse 2008-11-18 13:38:48 +0000 2028) {
813e0c46c9e2a (Steven Whitehouse 2008-11-18 13:38:48 +0000 2029) struct gfs2_glock *gl = ip->i_gl;
813e0c46c9e2a (Steven Whitehouse 2008-11-18 13:38:48 +0000 2030) int ret;
813e0c46c9e2a (Steven Whitehouse 2008-11-18 13:38:48 +0000 2031)
813e0c46c9e2a (Steven Whitehouse 2008-11-18 13:38:48 +0000 2032) ret = gfs2_truncatei_resume(ip);
ea4e61c7f46d3 (Bob Peterson 2020-05-23 08:13:50 -0500 2033) gfs2_glock_assert_withdraw(gl, ret == 0);
813e0c46c9e2a (Steven Whitehouse 2008-11-18 13:38:48 +0000 2034)
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 2035) spin_lock(&gl->gl_lockref.lock);
813e0c46c9e2a (Steven Whitehouse 2008-11-18 13:38:48 +0000 2036) clear_bit(GLF_LOCK, &gl->gl_flags);
813e0c46c9e2a (Steven Whitehouse 2008-11-18 13:38:48 +0000 2037) run_queue(gl, 1);
f3dd1649122b9 (Andreas Gruenbacher 2015-10-29 10:58:09 -0500 2038) spin_unlock(&gl->gl_lockref.lock);
813e0c46c9e2a (Steven Whitehouse 2008-11-18 13:38:48 +0000 2039) }
813e0c46c9e2a (Steven Whitehouse 2008-11-18 13:38:48 +0000 2040)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2041) static const char *state2str(unsigned state)
04b933f27bc8e (Robert Peterson 2007-03-23 17:05:15 -0500 2042) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2043) switch(state) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2044) case LM_ST_UNLOCKED:
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2045) return "UN";
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2046) case LM_ST_SHARED:
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2047) return "SH";
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2048) case LM_ST_DEFERRED:
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2049) return "DF";
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2050) case LM_ST_EXCLUSIVE:
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2051) return "EX";
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2052) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2053) return "??";
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2054) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2055)
b58bf407ca466 (Bob Peterson 2015-07-24 09:45:43 -0500 2056) static const char *hflags2str(char *buf, u16 flags, unsigned long iflags)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2057) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2058) char *p = buf;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2059) if (flags & LM_FLAG_TRY)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2060) *p++ = 't';
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2061) if (flags & LM_FLAG_TRY_1CB)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2062) *p++ = 'T';
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2063) if (flags & LM_FLAG_NOEXP)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2064) *p++ = 'e';
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2065) if (flags & LM_FLAG_ANY)
f057f6cdf6417 (Steven Whitehouse 2009-01-12 10:43:39 +0000 2066) *p++ = 'A';
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2067) if (flags & LM_FLAG_PRIORITY)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2068) *p++ = 'p';
06e908cd9ead1 (Bob Peterson 2018-04-18 13:58:19 -0700 2069) if (flags & LM_FLAG_NODE_SCOPE)
06e908cd9ead1 (Bob Peterson 2018-04-18 13:58:19 -0700 2070) *p++ = 'n';
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2071) if (flags & GL_ASYNC)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2072) *p++ = 'a';
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2073) if (flags & GL_EXACT)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2074) *p++ = 'E';
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2075) if (flags & GL_NOCACHE)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2076) *p++ = 'c';
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2077) if (test_bit(HIF_HOLDER, &iflags))
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2078) *p++ = 'H';
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2079) if (test_bit(HIF_WAIT, &iflags))
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2080) *p++ = 'W';
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2081) if (test_bit(HIF_FIRST, &iflags))
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2082) *p++ = 'F';
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2083) *p = 0;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2084) return buf;
04b933f27bc8e (Robert Peterson 2007-03-23 17:05:15 -0500 2085) }
04b933f27bc8e (Robert Peterson 2007-03-23 17:05:15 -0500 2086)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 2087) /**
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 2088) * dump_holder - print information about a glock holder
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2089) * @seq: the seq_file struct
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 2090) * @gh: the glock holder
3792ce973f07a (Bob Peterson 2019-05-09 09:21:48 -0500 2091) * @fs_id_buf: pointer to file system id (if requested)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 2092) *
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 2093) */
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 2094)
3792ce973f07a (Bob Peterson 2019-05-09 09:21:48 -0500 2095) static void dump_holder(struct seq_file *seq, const struct gfs2_holder *gh,
3792ce973f07a (Bob Peterson 2019-05-09 09:21:48 -0500 2096) const char *fs_id_buf)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 2097) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2098) struct task_struct *gh_owner = NULL;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2099) char flags_buf[32];
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 2100)
0b3a2c9968d45 (Tetsuo Handa 2014-01-02 19:52:20 +0900 2101) rcu_read_lock();
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2102) if (gh->gh_owner_pid)
b1e058da50f79 (Pavel Emelyanov 2008-02-07 00:13:19 -0800 2103) gh_owner = pid_task(gh->gh_owner_pid, PIDTYPE_PID);
3792ce973f07a (Bob Peterson 2019-05-09 09:21:48 -0500 2104) gfs2_print_dbg(seq, "%s H: s:%s f:%s e:%d p:%ld [%s] %pS\n",
3792ce973f07a (Bob Peterson 2019-05-09 09:21:48 -0500 2105) fs_id_buf, state2str(gh->gh_state),
cc18152eb7c27 (Joe Perches 2010-11-05 16:12:36 -0700 2106) hflags2str(flags_buf, gh->gh_flags, gh->gh_iflags),
cc18152eb7c27 (Joe Perches 2010-11-05 16:12:36 -0700 2107) gh->gh_error,
cc18152eb7c27 (Joe Perches 2010-11-05 16:12:36 -0700 2108) gh->gh_owner_pid ? (long)pid_nr(gh->gh_owner_pid) : -1,
cc18152eb7c27 (Joe Perches 2010-11-05 16:12:36 -0700 2109) gh_owner ? gh_owner->comm : "(ended)",
cc18152eb7c27 (Joe Perches 2010-11-05 16:12:36 -0700 2110) (void *)gh->gh_ip);
0b3a2c9968d45 (Tetsuo Handa 2014-01-02 19:52:20 +0900 2111) rcu_read_unlock();
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 2112) }
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 2113)
627c10b7e471b (Steven Whitehouse 2011-04-14 14:09:52 +0100 2114) static const char *gflags2str(char *buf, const struct gfs2_glock *gl)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2115) {
627c10b7e471b (Steven Whitehouse 2011-04-14 14:09:52 +0100 2116) const unsigned long *gflags = &gl->gl_flags;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2117) char *p = buf;
627c10b7e471b (Steven Whitehouse 2011-04-14 14:09:52 +0100 2118)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2119) if (test_bit(GLF_LOCK, gflags))
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2120) *p++ = 'l';
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2121) if (test_bit(GLF_DEMOTE, gflags))
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2122) *p++ = 'D';
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2123) if (test_bit(GLF_PENDING_DEMOTE, gflags))
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2124) *p++ = 'd';
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2125) if (test_bit(GLF_DEMOTE_IN_PROGRESS, gflags))
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2126) *p++ = 'p';
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2127) if (test_bit(GLF_DIRTY, gflags))
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2128) *p++ = 'y';
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2129) if (test_bit(GLF_LFLUSH, gflags))
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2130) *p++ = 'f';
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2131) if (test_bit(GLF_INVALIDATE_IN_PROGRESS, gflags))
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2132) *p++ = 'i';
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2133) if (test_bit(GLF_REPLY_PENDING, gflags))
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2134) *p++ = 'r';
f057f6cdf6417 (Steven Whitehouse 2009-01-12 10:43:39 +0000 2135) if (test_bit(GLF_INITIAL, gflags))
d8348de06f704 (Steven Whitehouse 2009-02-05 10:12:38 +0000 2136) *p++ = 'I';
f057f6cdf6417 (Steven Whitehouse 2009-01-12 10:43:39 +0000 2137) if (test_bit(GLF_FROZEN, gflags))
f057f6cdf6417 (Steven Whitehouse 2009-01-12 10:43:39 +0000 2138) *p++ = 'F';
e2c6c8a797eea (Bob Peterson 2020-10-12 13:57:37 -0500 2139) if (!list_empty(&gl->gl_holders))
7b5e3d5fcf0d6 (Steven Whitehouse 2010-09-03 09:39:20 +0100 2140) *p++ = 'q';
627c10b7e471b (Steven Whitehouse 2011-04-14 14:09:52 +0100 2141) if (test_bit(GLF_LRU, gflags))
627c10b7e471b (Steven Whitehouse 2011-04-14 14:09:52 +0100 2142) *p++ = 'L';
627c10b7e471b (Steven Whitehouse 2011-04-14 14:09:52 +0100 2143) if (gl->gl_object)
627c10b7e471b (Steven Whitehouse 2011-04-14 14:09:52 +0100 2144) *p++ = 'o';
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2145) if (test_bit(GLF_BLOCKING, gflags))
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2146) *p++ = 'b';
5deaf1f63bafc (Bob Peterson 2020-06-09 13:29:08 -0400 2147) if (test_bit(GLF_PENDING_DELETE, gflags))
5deaf1f63bafc (Bob Peterson 2020-06-09 13:29:08 -0400 2148) *p++ = 'P';
5deaf1f63bafc (Bob Peterson 2020-06-09 13:29:08 -0400 2149) if (test_bit(GLF_FREEING, gflags))
5deaf1f63bafc (Bob Peterson 2020-06-09 13:29:08 -0400 2150) *p++ = 'x';
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2151) *p = 0;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2152) return buf;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 2153) }
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 2154)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 2155) /**
8eae1ca0034cc (Steven Whitehouse 2012-10-15 10:57:02 +0100 2156) * gfs2_dump_glock - print information about a glock
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2157) * @seq: The seq_file struct
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 2158) * @gl: the glock
3792ce973f07a (Bob Peterson 2019-05-09 09:21:48 -0500 2159) * @fsid: If true, also dump the file system id
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2160) *
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2161) * The file format is as follows:
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2162) * One line per object, capital letters are used to indicate objects
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2163) * G = glock, I = Inode, R = rgrp, H = holder. Glocks are not indented,
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2164) * other objects are indented by a single space and follow the glock to
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2165) * which they are related. Fields are indicated by lower case letters
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2166) * followed by a colon and the field value, except for strings which are in
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2167) * [] so that its possible to see if they are composed of spaces for
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2168) * example. The field's are n = number (id of the object), f = flags,
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2169) * t = type, s = state, r = refcount, e = error, p = pid.
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 2170) *
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 2171) */
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 2172)
3792ce973f07a (Bob Peterson 2019-05-09 09:21:48 -0500 2173) void gfs2_dump_glock(struct seq_file *seq, struct gfs2_glock *gl, bool fsid)
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 2174) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2175) const struct gfs2_glock_operations *glops = gl->gl_ops;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2176) unsigned long long dtime;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2177) const struct gfs2_holder *gh;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2178) char gflags_buf[32];
3792ce973f07a (Bob Peterson 2019-05-09 09:21:48 -0500 2179) struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
98fb057487a80 (Bob Peterson 2019-08-13 09:25:15 -0400 2180) char fs_id_buf[sizeof(sdp->sd_fsname) + 7];
7e901d6e9519d (Bob Peterson 2020-05-22 13:57:41 -0500 2181) unsigned long nrpages = 0;
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 2182)
7e901d6e9519d (Bob Peterson 2020-05-22 13:57:41 -0500 2183) if (gl->gl_ops->go_flags & GLOF_ASPACE) {
7e901d6e9519d (Bob Peterson 2020-05-22 13:57:41 -0500 2184) struct address_space *mapping = gfs2_glock2aspace(gl);
7e901d6e9519d (Bob Peterson 2020-05-22 13:57:41 -0500 2185)
7e901d6e9519d (Bob Peterson 2020-05-22 13:57:41 -0500 2186) nrpages = mapping->nrpages;
7e901d6e9519d (Bob Peterson 2020-05-22 13:57:41 -0500 2187) }
3792ce973f07a (Bob Peterson 2019-05-09 09:21:48 -0500 2188) memset(fs_id_buf, 0, sizeof(fs_id_buf));
3792ce973f07a (Bob Peterson 2019-05-09 09:21:48 -0500 2189) if (fsid && sdp) /* safety precaution */
3792ce973f07a (Bob Peterson 2019-05-09 09:21:48 -0500 2190) sprintf(fs_id_buf, "fsid=%s: ", sdp->sd_fsname);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2191) dtime = jiffies - gl->gl_demote_time;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2192) dtime *= 1000000/HZ; /* demote time in uSec */
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2193) if (!test_bit(GLF_DEMOTE, &gl->gl_flags))
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2194) dtime = 0;
3792ce973f07a (Bob Peterson 2019-05-09 09:21:48 -0500 2195) gfs2_print_dbg(seq, "%sG: s:%s n:%u/%llx f:%s t:%s d:%s/%llu a:%d "
7e901d6e9519d (Bob Peterson 2020-05-22 13:57:41 -0500 2196) "v:%d r:%d m:%ld p:%lu\n",
7e901d6e9519d (Bob Peterson 2020-05-22 13:57:41 -0500 2197) fs_id_buf, state2str(gl->gl_state),
7e901d6e9519d (Bob Peterson 2020-05-22 13:57:41 -0500 2198) gl->gl_name.ln_type,
7e901d6e9519d (Bob Peterson 2020-05-22 13:57:41 -0500 2199) (unsigned long long)gl->gl_name.ln_number,
7e901d6e9519d (Bob Peterson 2020-05-22 13:57:41 -0500 2200) gflags2str(gflags_buf, gl),
7e901d6e9519d (Bob Peterson 2020-05-22 13:57:41 -0500 2201) state2str(gl->gl_target),
7e901d6e9519d (Bob Peterson 2020-05-22 13:57:41 -0500 2202) state2str(gl->gl_demote_state), dtime,
7e901d6e9519d (Bob Peterson 2020-05-22 13:57:41 -0500 2203) atomic_read(&gl->gl_ail_count),
7e901d6e9519d (Bob Peterson 2020-05-22 13:57:41 -0500 2204) atomic_read(&gl->gl_revokes),
7e901d6e9519d (Bob Peterson 2020-05-22 13:57:41 -0500 2205) (int)gl->gl_lockref.count, gl->gl_hold_time, nrpages);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 2206)
ac3beb6a5de04 (Steven Whitehouse 2014-01-16 10:31:13 +0000 2207) list_for_each_entry(gh, &gl->gl_holders, gh_list)
3792ce973f07a (Bob Peterson 2019-05-09 09:21:48 -0500 2208) dump_holder(seq, gh, fs_id_buf);
ac3beb6a5de04 (Steven Whitehouse 2014-01-16 10:31:13 +0000 2209)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2210) if (gl->gl_state != LM_ST_UNLOCKED && glops->go_dump)
3792ce973f07a (Bob Peterson 2019-05-09 09:21:48 -0500 2211) glops->go_dump(seq, gl, fs_id_buf);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 2212) }
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 2213)
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2214) static int gfs2_glstats_seq_show(struct seq_file *seq, void *iter_ptr)
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2215) {
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2216) struct gfs2_glock *gl = iter_ptr;
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2217)
4d207133e9c36 (Ben Hutchings 2015-08-27 12:51:45 -0500 2218) seq_printf(seq, "G: n:%u/%llx rtt:%llu/%llu rttb:%llu/%llu irt:%llu/%llu dcnt: %llu qcnt: %llu\n",
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2219) gl->gl_name.ln_type,
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2220) (unsigned long long)gl->gl_name.ln_number,
4d207133e9c36 (Ben Hutchings 2015-08-27 12:51:45 -0500 2221) (unsigned long long)gl->gl_stats.stats[GFS2_LKS_SRTT],
4d207133e9c36 (Ben Hutchings 2015-08-27 12:51:45 -0500 2222) (unsigned long long)gl->gl_stats.stats[GFS2_LKS_SRTTVAR],
4d207133e9c36 (Ben Hutchings 2015-08-27 12:51:45 -0500 2223) (unsigned long long)gl->gl_stats.stats[GFS2_LKS_SRTTB],
4d207133e9c36 (Ben Hutchings 2015-08-27 12:51:45 -0500 2224) (unsigned long long)gl->gl_stats.stats[GFS2_LKS_SRTTVARB],
4d207133e9c36 (Ben Hutchings 2015-08-27 12:51:45 -0500 2225) (unsigned long long)gl->gl_stats.stats[GFS2_LKS_SIRT],
4d207133e9c36 (Ben Hutchings 2015-08-27 12:51:45 -0500 2226) (unsigned long long)gl->gl_stats.stats[GFS2_LKS_SIRTVAR],
4d207133e9c36 (Ben Hutchings 2015-08-27 12:51:45 -0500 2227) (unsigned long long)gl->gl_stats.stats[GFS2_LKS_DCOUNT],
4d207133e9c36 (Ben Hutchings 2015-08-27 12:51:45 -0500 2228) (unsigned long long)gl->gl_stats.stats[GFS2_LKS_QCOUNT]);
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2229) return 0;
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2230) }
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2231)
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2232) static const char *gfs2_gltype[] = {
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2233) "type",
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2234) "reserved",
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2235) "nondisk",
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2236) "inode",
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2237) "rgrp",
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2238) "meta",
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2239) "iopen",
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2240) "flock",
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2241) "plock",
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2242) "quota",
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2243) "journal",
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2244) };
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2245)
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2246) static const char *gfs2_stype[] = {
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2247) [GFS2_LKS_SRTT] = "srtt",
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2248) [GFS2_LKS_SRTTVAR] = "srttvar",
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2249) [GFS2_LKS_SRTTB] = "srttb",
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2250) [GFS2_LKS_SRTTVARB] = "srttvarb",
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2251) [GFS2_LKS_SIRT] = "sirt",
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2252) [GFS2_LKS_SIRTVAR] = "sirtvar",
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2253) [GFS2_LKS_DCOUNT] = "dlm",
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2254) [GFS2_LKS_QCOUNT] = "queue",
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2255) };
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2256)
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2257) #define GFS2_NR_SBSTATS (ARRAY_SIZE(gfs2_gltype) * ARRAY_SIZE(gfs2_stype))
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2258)
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2259) static int gfs2_sbstats_seq_show(struct seq_file *seq, void *iter_ptr)
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2260) {
81648d043191e (Andreas Gruenbacher 2015-08-27 11:43:00 -0500 2261) struct gfs2_sbd *sdp = seq->private;
81648d043191e (Andreas Gruenbacher 2015-08-27 11:43:00 -0500 2262) loff_t pos = *(loff_t *)iter_ptr;
81648d043191e (Andreas Gruenbacher 2015-08-27 11:43:00 -0500 2263) unsigned index = pos >> 3;
81648d043191e (Andreas Gruenbacher 2015-08-27 11:43:00 -0500 2264) unsigned subindex = pos & 0x07;
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2265) int i;
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2266)
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2267) if (index == 0 && subindex != 0)
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2268) return 0;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2269)
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2270) seq_printf(seq, "%-10s %8s:", gfs2_gltype[index],
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2271) (index == 0) ? "cpu": gfs2_stype[subindex]);
b3b94faa5fe59 (David Teigland 2006-01-16 16:50:04 +0000 2272)
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2273) for_each_possible_cpu(i) {
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2274) const struct gfs2_pcpu_lkstats *lkstats = per_cpu_ptr(sdp->sd_lkstats, i);
8f7e0a806db0a (Andreas Gruenbacher 2015-08-27 13:02:54 -0500 2275)
8f7e0a806db0a (Andreas Gruenbacher 2015-08-27 13:02:54 -0500 2276) if (index == 0)
8f7e0a806db0a (Andreas Gruenbacher 2015-08-27 13:02:54 -0500 2277) seq_printf(seq, " %15u", i);
8f7e0a806db0a (Andreas Gruenbacher 2015-08-27 13:02:54 -0500 2278) else
8f7e0a806db0a (Andreas Gruenbacher 2015-08-27 13:02:54 -0500 2279) seq_printf(seq, " %15llu", (unsigned long long)lkstats->
8f7e0a806db0a (Andreas Gruenbacher 2015-08-27 13:02:54 -0500 2280) lkstats[index - 1].stats[subindex]);
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2281) }
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2282) seq_putc(seq, '\n');
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2283) return 0;
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2284) }
8fbbfd214c853 (Steven Whitehouse 2007-08-01 13:57:10 +0100 2285)
85d1da67f7e12 (Steven Whitehouse 2006-09-07 14:40:21 -0400 2286) int __init gfs2_glock_init(void)
85d1da67f7e12 (Steven Whitehouse 2006-09-07 14:40:21 -0400 2287) {
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 2288) int i, ret;
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 2289)
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 2290) ret = rhashtable_init(&gl_hash_table, &ht_parms);
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 2291) if (ret < 0)
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 2292) return ret;
8fbbfd214c853 (Steven Whitehouse 2007-08-01 13:57:10 +0100 2293)
d2115778c7ea0 (Steven Whitehouse 2010-11-03 19:58:53 +0000 2294) glock_workqueue = alloc_workqueue("glock_workqueue", WQ_MEM_RECLAIM |
58a69cb47ec69 (Tejun Heo 2011-02-16 09:25:31 +0100 2295) WQ_HIGHPRI | WQ_FREEZABLE, 0);
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 2296) if (!glock_workqueue) {
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 2297) rhashtable_destroy(&gl_hash_table);
dfc4616ddeb13 (Dan Carpenter 2013-08-15 10:54:43 +0300 2298) return -ENOMEM;
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 2299) }
d2115778c7ea0 (Steven Whitehouse 2010-11-03 19:58:53 +0000 2300) gfs2_delete_workqueue = alloc_workqueue("delete_workqueue",
58a69cb47ec69 (Tejun Heo 2011-02-16 09:25:31 +0100 2301) WQ_MEM_RECLAIM | WQ_FREEZABLE,
d2115778c7ea0 (Steven Whitehouse 2010-11-03 19:58:53 +0000 2302) 0);
dfc4616ddeb13 (Dan Carpenter 2013-08-15 10:54:43 +0300 2303) if (!gfs2_delete_workqueue) {
b94a170e96dc4 (Benjamin Marzinski 2009-07-23 18:52:34 -0500 2304) destroy_workqueue(glock_workqueue);
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 2305) rhashtable_destroy(&gl_hash_table);
dfc4616ddeb13 (Dan Carpenter 2013-08-15 10:54:43 +0300 2306) return -ENOMEM;
b94a170e96dc4 (Benjamin Marzinski 2009-07-23 18:52:34 -0500 2307) }
97cc1025b1a91 (Steven Whitehouse 2008-11-20 13:39:47 +0000 2308)
e0d735c1cc274 (Chao Yu 2016-09-21 12:09:40 -0500 2309) ret = register_shrinker(&glock_shrinker);
e0d735c1cc274 (Chao Yu 2016-09-21 12:09:40 -0500 2310) if (ret) {
e0d735c1cc274 (Chao Yu 2016-09-21 12:09:40 -0500 2311) destroy_workqueue(gfs2_delete_workqueue);
e0d735c1cc274 (Chao Yu 2016-09-21 12:09:40 -0500 2312) destroy_workqueue(glock_workqueue);
e0d735c1cc274 (Chao Yu 2016-09-21 12:09:40 -0500 2313) rhashtable_destroy(&gl_hash_table);
e0d735c1cc274 (Chao Yu 2016-09-21 12:09:40 -0500 2314) return ret;
e0d735c1cc274 (Chao Yu 2016-09-21 12:09:40 -0500 2315) }
c4f68a130fc17 (Benjamin Marzinski 2007-08-23 13:19:05 -0500 2316)
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 2317) for (i = 0; i < GLOCK_WAIT_TABLE_SIZE; i++)
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 2318) init_waitqueue_head(glock_wait_table + i);
0515480ad424f (Andreas Gruenbacher 2017-08-01 11:18:26 -0500 2319)
85d1da67f7e12 (Steven Whitehouse 2006-09-07 14:40:21 -0400 2320) return 0;
85d1da67f7e12 (Steven Whitehouse 2006-09-07 14:40:21 -0400 2321) }
85d1da67f7e12 (Steven Whitehouse 2006-09-07 14:40:21 -0400 2322)
8fbbfd214c853 (Steven Whitehouse 2007-08-01 13:57:10 +0100 2323) void gfs2_glock_exit(void)
8fbbfd214c853 (Steven Whitehouse 2007-08-01 13:57:10 +0100 2324) {
97cc1025b1a91 (Steven Whitehouse 2008-11-20 13:39:47 +0000 2325) unregister_shrinker(&glock_shrinker);
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 2326) rhashtable_destroy(&gl_hash_table);
c4f68a130fc17 (Benjamin Marzinski 2007-08-23 13:19:05 -0500 2327) destroy_workqueue(glock_workqueue);
b94a170e96dc4 (Benjamin Marzinski 2009-07-23 18:52:34 -0500 2328) destroy_workqueue(gfs2_delete_workqueue);
8fbbfd214c853 (Steven Whitehouse 2007-08-01 13:57:10 +0100 2329) }
8fbbfd214c853 (Steven Whitehouse 2007-08-01 13:57:10 +0100 2330)
7ac07fdaf840f (Andreas Gruenbacher 2018-01-08 22:35:43 +0100 2331) static void gfs2_glock_iter_next(struct gfs2_glock_iter *gi, loff_t n)
bc015cb84129e (Steven Whitehouse 2011-01-19 09:30:01 +0000 2332) {
3fd5d3ad35dc4 (Andreas Gruenbacher 2018-03-28 12:05:35 +0200 2333) struct gfs2_glock *gl = gi->gl;
3fd5d3ad35dc4 (Andreas Gruenbacher 2018-03-28 12:05:35 +0200 2334)
3fd5d3ad35dc4 (Andreas Gruenbacher 2018-03-28 12:05:35 +0200 2335) if (gl) {
3fd5d3ad35dc4 (Andreas Gruenbacher 2018-03-28 12:05:35 +0200 2336) if (n == 0)
3fd5d3ad35dc4 (Andreas Gruenbacher 2018-03-28 12:05:35 +0200 2337) return;
3fd5d3ad35dc4 (Andreas Gruenbacher 2018-03-28 12:05:35 +0200 2338) if (!lockref_put_not_zero(&gl->gl_lockref))
3fd5d3ad35dc4 (Andreas Gruenbacher 2018-03-28 12:05:35 +0200 2339) gfs2_glock_queue_put(gl);
7ac07fdaf840f (Andreas Gruenbacher 2018-01-08 22:35:43 +0100 2340) }
7ac07fdaf840f (Andreas Gruenbacher 2018-01-08 22:35:43 +0100 2341) for (;;) {
3fd5d3ad35dc4 (Andreas Gruenbacher 2018-03-28 12:05:35 +0200 2342) gl = rhashtable_walk_next(&gi->hti);
3fd5d3ad35dc4 (Andreas Gruenbacher 2018-03-28 12:05:35 +0200 2343) if (IS_ERR_OR_NULL(gl)) {
3fd5d3ad35dc4 (Andreas Gruenbacher 2018-03-28 12:05:35 +0200 2344) if (gl == ERR_PTR(-EAGAIN)) {
3fd5d3ad35dc4 (Andreas Gruenbacher 2018-03-28 12:05:35 +0200 2345) n = 1;
3fd5d3ad35dc4 (Andreas Gruenbacher 2018-03-28 12:05:35 +0200 2346) continue;
7ac07fdaf840f (Andreas Gruenbacher 2018-01-08 22:35:43 +0100 2347) }
3fd5d3ad35dc4 (Andreas Gruenbacher 2018-03-28 12:05:35 +0200 2348) gl = NULL;
3fd5d3ad35dc4 (Andreas Gruenbacher 2018-03-28 12:05:35 +0200 2349) break;
3fd5d3ad35dc4 (Andreas Gruenbacher 2018-03-28 12:05:35 +0200 2350) }
3fd5d3ad35dc4 (Andreas Gruenbacher 2018-03-28 12:05:35 +0200 2351) if (gl->gl_name.ln_sbd != gi->sdp)
3fd5d3ad35dc4 (Andreas Gruenbacher 2018-03-28 12:05:35 +0200 2352) continue;
3fd5d3ad35dc4 (Andreas Gruenbacher 2018-03-28 12:05:35 +0200 2353) if (n <= 1) {
3fd5d3ad35dc4 (Andreas Gruenbacher 2018-03-28 12:05:35 +0200 2354) if (!lockref_get_not_dead(&gl->gl_lockref))
3fd5d3ad35dc4 (Andreas Gruenbacher 2018-03-28 12:05:35 +0200 2355) continue;
3fd5d3ad35dc4 (Andreas Gruenbacher 2018-03-28 12:05:35 +0200 2356) break;
3fd5d3ad35dc4 (Andreas Gruenbacher 2018-03-28 12:05:35 +0200 2357) } else {
3fd5d3ad35dc4 (Andreas Gruenbacher 2018-03-28 12:05:35 +0200 2358) if (__lockref_is_dead(&gl->gl_lockref))
3fd5d3ad35dc4 (Andreas Gruenbacher 2018-03-28 12:05:35 +0200 2359) continue;
3fd5d3ad35dc4 (Andreas Gruenbacher 2018-03-28 12:05:35 +0200 2360) n--;
bc015cb84129e (Steven Whitehouse 2011-01-19 09:30:01 +0000 2361) }
14d37564fa3dc (Dan Carpenter 2016-12-14 08:02:03 -0600 2362) }
3fd5d3ad35dc4 (Andreas Gruenbacher 2018-03-28 12:05:35 +0200 2363) gi->gl = gl;
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2364) }
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2365)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2366) static void *gfs2_glock_seq_start(struct seq_file *seq, loff_t *pos)
27c3b415f6ffe (Bob Peterson 2017-08-18 09:15:13 -0500 2367) __acquires(RCU)
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2368) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2369) struct gfs2_glock_iter *gi = seq->private;
7ac07fdaf840f (Andreas Gruenbacher 2018-01-08 22:35:43 +0100 2370) loff_t n;
ba1ddcb6ca0c4 (Steven Whitehouse 2012-06-08 11:16:22 +0100 2371)
7ac07fdaf840f (Andreas Gruenbacher 2018-01-08 22:35:43 +0100 2372) /*
7ac07fdaf840f (Andreas Gruenbacher 2018-01-08 22:35:43 +0100 2373) * We can either stay where we are, skip to the next hash table
7ac07fdaf840f (Andreas Gruenbacher 2018-01-08 22:35:43 +0100 2374) * entry, or start from the beginning.
7ac07fdaf840f (Andreas Gruenbacher 2018-01-08 22:35:43 +0100 2375) */
7ac07fdaf840f (Andreas Gruenbacher 2018-01-08 22:35:43 +0100 2376) if (*pos < gi->last_pos) {
7ac07fdaf840f (Andreas Gruenbacher 2018-01-08 22:35:43 +0100 2377) rhashtable_walk_exit(&gi->hti);
7ac07fdaf840f (Andreas Gruenbacher 2018-01-08 22:35:43 +0100 2378) rhashtable_walk_enter(&gl_hash_table, &gi->hti);
7ac07fdaf840f (Andreas Gruenbacher 2018-01-08 22:35:43 +0100 2379) n = *pos + 1;
7ac07fdaf840f (Andreas Gruenbacher 2018-01-08 22:35:43 +0100 2380) } else {
7ac07fdaf840f (Andreas Gruenbacher 2018-01-08 22:35:43 +0100 2381) n = *pos - gi->last_pos;
7ac07fdaf840f (Andreas Gruenbacher 2018-01-08 22:35:43 +0100 2382) }
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2383)
7ac07fdaf840f (Andreas Gruenbacher 2018-01-08 22:35:43 +0100 2384) rhashtable_walk_start(&gi->hti);
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2385)
7ac07fdaf840f (Andreas Gruenbacher 2018-01-08 22:35:43 +0100 2386) gfs2_glock_iter_next(gi, n);
ba1ddcb6ca0c4 (Steven Whitehouse 2012-06-08 11:16:22 +0100 2387) gi->last_pos = *pos;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2388) return gi->gl;
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2389) }
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2390)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2391) static void *gfs2_glock_seq_next(struct seq_file *seq, void *iter_ptr,
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2392) loff_t *pos)
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2393) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2394) struct gfs2_glock_iter *gi = seq->private;
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2395)
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2396) (*pos)++;
ba1ddcb6ca0c4 (Steven Whitehouse 2012-06-08 11:16:22 +0100 2397) gi->last_pos = *pos;
7ac07fdaf840f (Andreas Gruenbacher 2018-01-08 22:35:43 +0100 2398) gfs2_glock_iter_next(gi, 1);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2399) return gi->gl;
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2400) }
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2401)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2402) static void gfs2_glock_seq_stop(struct seq_file *seq, void *iter_ptr)
27c3b415f6ffe (Bob Peterson 2017-08-18 09:15:13 -0500 2403) __releases(RCU)
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2404) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2405) struct gfs2_glock_iter *gi = seq->private;
bc015cb84129e (Steven Whitehouse 2011-01-19 09:30:01 +0000 2406)
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 2407) rhashtable_walk_stop(&gi->hti);
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2408) }
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2409)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2410) static int gfs2_glock_seq_show(struct seq_file *seq, void *iter_ptr)
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2411) {
3792ce973f07a (Bob Peterson 2019-05-09 09:21:48 -0500 2412) dump_glock(seq, iter_ptr, false);
ac3beb6a5de04 (Steven Whitehouse 2014-01-16 10:31:13 +0000 2413) return 0;
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2414) }
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2415)
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2416) static void *gfs2_sbstats_seq_start(struct seq_file *seq, loff_t *pos)
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2417) {
81648d043191e (Andreas Gruenbacher 2015-08-27 11:43:00 -0500 2418) preempt_disable();
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2419) if (*pos >= GFS2_NR_SBSTATS)
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2420) return NULL;
81648d043191e (Andreas Gruenbacher 2015-08-27 11:43:00 -0500 2421) return pos;
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2422) }
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2423)
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2424) static void *gfs2_sbstats_seq_next(struct seq_file *seq, void *iter_ptr,
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2425) loff_t *pos)
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2426) {
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2427) (*pos)++;
81648d043191e (Andreas Gruenbacher 2015-08-27 11:43:00 -0500 2428) if (*pos >= GFS2_NR_SBSTATS)
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2429) return NULL;
81648d043191e (Andreas Gruenbacher 2015-08-27 11:43:00 -0500 2430) return pos;
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2431) }
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2432)
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2433) static void gfs2_sbstats_seq_stop(struct seq_file *seq, void *iter_ptr)
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2434) {
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2435) preempt_enable();
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2436) }
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2437)
4ef290025ccde (Denis Cheng 2007-07-31 18:31:11 +0800 2438) static const struct seq_operations gfs2_glock_seq_ops = {
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2439) .start = gfs2_glock_seq_start,
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2440) .next = gfs2_glock_seq_next,
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2441) .stop = gfs2_glock_seq_stop,
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2442) .show = gfs2_glock_seq_show,
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2443) };
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2444)
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2445) static const struct seq_operations gfs2_glstats_seq_ops = {
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2446) .start = gfs2_glock_seq_start,
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2447) .next = gfs2_glock_seq_next,
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2448) .stop = gfs2_glock_seq_stop,
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2449) .show = gfs2_glstats_seq_show,
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2450) };
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2451)
e8a8023ee0bda (Liu Shixin 2020-09-16 10:50:21 +0800 2452) static const struct seq_operations gfs2_sbstats_sops = {
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2453) .start = gfs2_sbstats_seq_start,
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2454) .next = gfs2_sbstats_seq_next,
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2455) .stop = gfs2_sbstats_seq_stop,
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2456) .show = gfs2_sbstats_seq_show,
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2457) };
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2458)
0fe2f1e929eca (Steven Whitehouse 2012-06-11 13:49:47 +0100 2459) #define GFS2_SEQ_GOODSIZE min(PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER, 65536UL)
0fe2f1e929eca (Steven Whitehouse 2012-06-11 13:49:47 +0100 2460)
92ecd73a887c4 (Andreas Gruenbacher 2017-03-09 09:48:05 -0500 2461) static int __gfs2_glocks_open(struct inode *inode, struct file *file,
92ecd73a887c4 (Andreas Gruenbacher 2017-03-09 09:48:05 -0500 2462) const struct seq_operations *ops)
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2463) {
92ecd73a887c4 (Andreas Gruenbacher 2017-03-09 09:48:05 -0500 2464) int ret = seq_open_private(file, ops, sizeof(struct gfs2_glock_iter));
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2465) if (ret == 0) {
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2466) struct seq_file *seq = file->private_data;
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2467) struct gfs2_glock_iter *gi = seq->private;
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 2468)
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2469) gi->sdp = inode->i_private;
0fe2f1e929eca (Steven Whitehouse 2012-06-11 13:49:47 +0100 2470) seq->buf = kmalloc(GFS2_SEQ_GOODSIZE, GFP_KERNEL | __GFP_NOWARN);
df5d2f5560a9c (Steven Whitehouse 2012-06-07 13:30:16 +0100 2471) if (seq->buf)
0fe2f1e929eca (Steven Whitehouse 2012-06-11 13:49:47 +0100 2472) seq->size = GFS2_SEQ_GOODSIZE;
7ac07fdaf840f (Andreas Gruenbacher 2018-01-08 22:35:43 +0100 2473) /*
7ac07fdaf840f (Andreas Gruenbacher 2018-01-08 22:35:43 +0100 2474) * Initially, we are "before" the first hash table entry; the
7ac07fdaf840f (Andreas Gruenbacher 2018-01-08 22:35:43 +0100 2475) * first call to rhashtable_walk_next gets us the first entry.
7ac07fdaf840f (Andreas Gruenbacher 2018-01-08 22:35:43 +0100 2476) */
7ac07fdaf840f (Andreas Gruenbacher 2018-01-08 22:35:43 +0100 2477) gi->last_pos = -1;
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 2478) gi->gl = NULL;
7ac07fdaf840f (Andreas Gruenbacher 2018-01-08 22:35:43 +0100 2479) rhashtable_walk_enter(&gl_hash_table, &gi->hti);
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2480) }
6802e3400ff45 (Steven Whitehouse 2008-05-21 17:03:22 +0100 2481) return ret;
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2482) }
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2483)
92ecd73a887c4 (Andreas Gruenbacher 2017-03-09 09:48:05 -0500 2484) static int gfs2_glocks_open(struct inode *inode, struct file *file)
92ecd73a887c4 (Andreas Gruenbacher 2017-03-09 09:48:05 -0500 2485) {
92ecd73a887c4 (Andreas Gruenbacher 2017-03-09 09:48:05 -0500 2486) return __gfs2_glocks_open(inode, file, &gfs2_glock_seq_ops);
92ecd73a887c4 (Andreas Gruenbacher 2017-03-09 09:48:05 -0500 2487) }
92ecd73a887c4 (Andreas Gruenbacher 2017-03-09 09:48:05 -0500 2488)
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 2489) static int gfs2_glocks_release(struct inode *inode, struct file *file)
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 2490) {
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 2491) struct seq_file *seq = file->private_data;
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 2492) struct gfs2_glock_iter *gi = seq->private;
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 2493)
3fd5d3ad35dc4 (Andreas Gruenbacher 2018-03-28 12:05:35 +0200 2494) if (gi->gl)
3fd5d3ad35dc4 (Andreas Gruenbacher 2018-03-28 12:05:35 +0200 2495) gfs2_glock_put(gi->gl);
7ac07fdaf840f (Andreas Gruenbacher 2018-01-08 22:35:43 +0100 2496) rhashtable_walk_exit(&gi->hti);
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 2497) return seq_release_private(inode, file);
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 2498) }
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 2499)
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2500) static int gfs2_glstats_open(struct inode *inode, struct file *file)
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2501) {
92ecd73a887c4 (Andreas Gruenbacher 2017-03-09 09:48:05 -0500 2502) return __gfs2_glocks_open(inode, file, &gfs2_glstats_seq_ops);
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2503) }
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2504)
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2505) static const struct file_operations gfs2_glocks_fops = {
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2506) .owner = THIS_MODULE,
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2507) .open = gfs2_glocks_open,
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2508) .read = seq_read,
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2509) .llseek = seq_lseek,
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 2510) .release = gfs2_glocks_release,
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2511) };
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2512)
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2513) static const struct file_operations gfs2_glstats_fops = {
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2514) .owner = THIS_MODULE,
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2515) .open = gfs2_glstats_open,
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2516) .read = seq_read,
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2517) .llseek = seq_lseek,
88ffbf3e037e6 (Bob Peterson 2015-03-16 11:02:46 -0500 2518) .release = gfs2_glocks_release,
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2519) };
a245769f254bb (Steven Whitehouse 2012-01-20 10:38:36 +0000 2520)
e8a8023ee0bda (Liu Shixin 2020-09-16 10:50:21 +0800 2521) DEFINE_SEQ_ATTRIBUTE(gfs2_sbstats);
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2522)
2abbf9a4d2625 (Greg Kroah-Hartman 2019-01-22 16:21:51 +0100 2523) void gfs2_create_debugfs_file(struct gfs2_sbd *sdp)
2abbf9a4d2625 (Greg Kroah-Hartman 2019-01-22 16:21:51 +0100 2524) {
2abbf9a4d2625 (Greg Kroah-Hartman 2019-01-22 16:21:51 +0100 2525) sdp->debugfs_dir = debugfs_create_dir(sdp->sd_table_name, gfs2_root);
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2526)
2abbf9a4d2625 (Greg Kroah-Hartman 2019-01-22 16:21:51 +0100 2527) debugfs_create_file("glocks", S_IFREG | S_IRUGO, sdp->debugfs_dir, sdp,
2abbf9a4d2625 (Greg Kroah-Hartman 2019-01-22 16:21:51 +0100 2528) &gfs2_glocks_fops);
2abbf9a4d2625 (Greg Kroah-Hartman 2019-01-22 16:21:51 +0100 2529)
2abbf9a4d2625 (Greg Kroah-Hartman 2019-01-22 16:21:51 +0100 2530) debugfs_create_file("glstats", S_IFREG | S_IRUGO, sdp->debugfs_dir, sdp,
2abbf9a4d2625 (Greg Kroah-Hartman 2019-01-22 16:21:51 +0100 2531) &gfs2_glstats_fops);
2abbf9a4d2625 (Greg Kroah-Hartman 2019-01-22 16:21:51 +0100 2532)
2abbf9a4d2625 (Greg Kroah-Hartman 2019-01-22 16:21:51 +0100 2533) debugfs_create_file("sbstats", S_IFREG | S_IRUGO, sdp->debugfs_dir, sdp,
2abbf9a4d2625 (Greg Kroah-Hartman 2019-01-22 16:21:51 +0100 2534) &gfs2_sbstats_fops);
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2535) }
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2536)
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2537) void gfs2_delete_debugfs_file(struct gfs2_sbd *sdp)
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2538) {
2abbf9a4d2625 (Greg Kroah-Hartman 2019-01-22 16:21:51 +0100 2539) debugfs_remove_recursive(sdp->debugfs_dir);
2abbf9a4d2625 (Greg Kroah-Hartman 2019-01-22 16:21:51 +0100 2540) sdp->debugfs_dir = NULL;
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2541) }
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2542)
2abbf9a4d2625 (Greg Kroah-Hartman 2019-01-22 16:21:51 +0100 2543) void gfs2_register_debugfs(void)
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2544) {
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2545) gfs2_root = debugfs_create_dir("gfs2", NULL);
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2546) }
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2547)
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2548) void gfs2_unregister_debugfs(void)
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2549) {
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2550) debugfs_remove(gfs2_root);
5f8820960cf4f (Robert Peterson 2007-04-18 11:41:11 -0500 2551) gfs2_root = NULL;
7c52b166c588c (Robert Peterson 2007-03-16 10:26:37 +0000 2552) }