Thomas Gleixner | 7336d0e | 2019-05-31 01:09:56 -0700 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. |
Bob Peterson | cf45b75 | 2008-01-31 10:31:39 -0600 | [diff] [blame] | 4 | * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved. |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
Joe Perches | d77d1b5 | 2014-03-06 12:10:45 -0800 | [diff] [blame] | 7 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 8 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 9 | #include <linux/sched.h> |
| 10 | #include <linux/slab.h> |
| 11 | #include <linux/spinlock.h> |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 12 | #include <linux/buffer_head.h> |
| 13 | #include <linux/delay.h> |
| 14 | #include <linux/sort.h> |
Andreas Gruenbacher | 0515480 | 2017-08-01 11:18:26 -0500 | [diff] [blame] | 15 | #include <linux/hash.h> |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 16 | #include <linux/jhash.h> |
Steven Whitehouse | d0dc80d | 2006-03-29 14:36:49 -0500 | [diff] [blame] | 17 | #include <linux/kallsyms.h> |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 18 | #include <linux/gfs2_ondisk.h> |
Steven Whitehouse | 2426443 | 2006-09-11 21:40:30 -0400 | [diff] [blame] | 19 | #include <linux/list.h> |
Steven Whitehouse | fee852e | 2007-01-17 15:33:23 +0000 | [diff] [blame] | 20 | #include <linux/wait.h> |
akpm@linux-foundation.org | 95d97b7 | 2007-03-05 23:10:39 -0800 | [diff] [blame] | 21 | #include <linux/module.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 22 | #include <linux/uaccess.h> |
Robert Peterson | 7c52b16 | 2007-03-16 10:26:37 +0000 | [diff] [blame] | 23 | #include <linux/seq_file.h> |
| 24 | #include <linux/debugfs.h> |
Steven Whitehouse | 8fbbfd2 | 2007-08-01 13:57:10 +0100 | [diff] [blame] | 25 | #include <linux/kthread.h> |
| 26 | #include <linux/freezer.h> |
Benjamin Marzinski | c4f68a1 | 2007-08-23 13:19:05 -0500 | [diff] [blame] | 27 | #include <linux/workqueue.h> |
| 28 | #include <linux/jiffies.h> |
Steven Whitehouse | bc015cb | 2011-01-19 09:30:01 +0000 | [diff] [blame] | 29 | #include <linux/rcupdate.h> |
| 30 | #include <linux/rculist_bl.h> |
| 31 | #include <linux/bit_spinlock.h> |
Steven Whitehouse | a245769 | 2012-01-20 10:38:36 +0000 | [diff] [blame] | 32 | #include <linux/percpu.h> |
Steven Whitehouse | 4506a519 | 2013-02-01 20:36:03 +0000 | [diff] [blame] | 33 | #include <linux/list_sort.h> |
Steven Whitehouse | e66cf16 | 2013-10-15 15:18:08 +0100 | [diff] [blame] | 34 | #include <linux/lockref.h> |
Bob Peterson | 88ffbf3 | 2015-03-16 11:02:46 -0500 | [diff] [blame] | 35 | #include <linux/rhashtable.h> |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 36 | |
| 37 | #include "gfs2.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 38 | #include "incore.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 39 | #include "glock.h" |
| 40 | #include "glops.h" |
| 41 | #include "inode.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 42 | #include "lops.h" |
| 43 | #include "meta_io.h" |
| 44 | #include "quota.h" |
| 45 | #include "super.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 46 | #include "util.h" |
Steven Whitehouse | 813e0c4 | 2008-11-18 13:38:48 +0000 | [diff] [blame] | 47 | #include "bmap.h" |
Steven Whitehouse | 6399777 | 2009-06-12 08:49:20 +0100 | [diff] [blame] | 48 | #define CREATE_TRACE_POINTS |
| 49 | #include "trace_gfs2.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 50 | |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 51 | struct gfs2_glock_iter { |
Steven Whitehouse | ba1ddcb | 2012-06-08 11:16:22 +0100 | [diff] [blame] | 52 | struct gfs2_sbd *sdp; /* incore superblock */ |
Bob Peterson | 88ffbf3 | 2015-03-16 11:02:46 -0500 | [diff] [blame] | 53 | struct rhashtable_iter hti; /* rhashtable iterator */ |
Steven Whitehouse | ba1ddcb | 2012-06-08 11:16:22 +0100 | [diff] [blame] | 54 | struct gfs2_glock *gl; /* current glock struct */ |
| 55 | loff_t last_pos; /* last position */ |
Robert Peterson | 7c52b16 | 2007-03-16 10:26:37 +0000 | [diff] [blame] | 56 | }; |
| 57 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 58 | typedef void (*glock_examiner) (struct gfs2_glock * gl); |
| 59 | |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 60 | static void do_xmote(struct gfs2_glock *gl, struct gfs2_holder *gh, unsigned int target); |
Benjamin Marzinski | c4f68a1 | 2007-08-23 13:19:05 -0500 | [diff] [blame] | 61 | |
Robert Peterson | 7c52b16 | 2007-03-16 10:26:37 +0000 | [diff] [blame] | 62 | static struct dentry *gfs2_root; |
Benjamin Marzinski | c4f68a1 | 2007-08-23 13:19:05 -0500 | [diff] [blame] | 63 | static struct workqueue_struct *glock_workqueue; |
Benjamin Marzinski | b94a170 | 2009-07-23 18:52:34 -0500 | [diff] [blame] | 64 | struct workqueue_struct *gfs2_delete_workqueue; |
Steven Whitehouse | 97cc1025 | 2008-11-20 13:39:47 +0000 | [diff] [blame] | 65 | static LIST_HEAD(lru_list); |
| 66 | static atomic_t lru_count = ATOMIC_INIT(0); |
Julia Lawall | eb8374e | 2008-12-25 15:35:27 +0100 | [diff] [blame] | 67 | static DEFINE_SPINLOCK(lru_lock); |
Adrian Bunk | 08bc2db | 2006-04-28 10:59:12 -0400 | [diff] [blame] | 68 | |
Steven Whitehouse | b639789 | 2006-09-12 10:10:01 -0400 | [diff] [blame] | 69 | #define GFS2_GL_HASH_SHIFT 15 |
Fabian Frederick | 47a9a52 | 2016-08-02 12:05:27 -0500 | [diff] [blame] | 70 | #define GFS2_GL_HASH_SIZE BIT(GFS2_GL_HASH_SHIFT) |
Steven Whitehouse | 087efdd | 2006-09-09 16:59:11 -0400 | [diff] [blame] | 71 | |
Arvind Yadav | d296b15 | 2017-08-30 07:50:03 -0500 | [diff] [blame] | 72 | static const struct rhashtable_params ht_parms = { |
Bob Peterson | 88ffbf3 | 2015-03-16 11:02:46 -0500 | [diff] [blame] | 73 | .nelem_hint = GFS2_GL_HASH_SIZE * 3 / 4, |
Andreas Gruenbacher | 972b044 | 2017-03-16 09:54:57 -0400 | [diff] [blame] | 74 | .key_len = offsetofend(struct lm_lockname, ln_type), |
Bob Peterson | 88ffbf3 | 2015-03-16 11:02:46 -0500 | [diff] [blame] | 75 | .key_offset = offsetof(struct gfs2_glock, gl_name), |
| 76 | .head_offset = offsetof(struct gfs2_glock, gl_node), |
| 77 | }; |
Steven Whitehouse | 087efdd | 2006-09-09 16:59:11 -0400 | [diff] [blame] | 78 | |
Bob Peterson | 88ffbf3 | 2015-03-16 11:02:46 -0500 | [diff] [blame] | 79 | static struct rhashtable gl_hash_table; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 80 | |
Andreas Gruenbacher | 0515480 | 2017-08-01 11:18:26 -0500 | [diff] [blame] | 81 | #define GLOCK_WAIT_TABLE_BITS 12 |
| 82 | #define GLOCK_WAIT_TABLE_SIZE (1 << GLOCK_WAIT_TABLE_BITS) |
| 83 | static wait_queue_head_t glock_wait_table[GLOCK_WAIT_TABLE_SIZE] __cacheline_aligned; |
| 84 | |
| 85 | struct wait_glock_queue { |
| 86 | struct lm_lockname *name; |
| 87 | wait_queue_entry_t wait; |
| 88 | }; |
| 89 | |
| 90 | static int glock_wake_function(wait_queue_entry_t *wait, unsigned int mode, |
| 91 | int sync, void *key) |
| 92 | { |
| 93 | struct wait_glock_queue *wait_glock = |
| 94 | container_of(wait, struct wait_glock_queue, wait); |
| 95 | struct lm_lockname *wait_name = wait_glock->name; |
| 96 | struct lm_lockname *wake_name = key; |
| 97 | |
| 98 | if (wake_name->ln_sbd != wait_name->ln_sbd || |
| 99 | wake_name->ln_number != wait_name->ln_number || |
| 100 | wake_name->ln_type != wait_name->ln_type) |
| 101 | return 0; |
| 102 | return autoremove_wake_function(wait, mode, sync, key); |
| 103 | } |
| 104 | |
| 105 | static wait_queue_head_t *glock_waitqueue(struct lm_lockname *name) |
| 106 | { |
Andreas Gruenbacher | 605b048 | 2019-03-06 15:41:57 +0100 | [diff] [blame] | 107 | u32 hash = jhash2((u32 *)name, ht_parms.key_len / 4, 0); |
Andreas Gruenbacher | 0515480 | 2017-08-01 11:18:26 -0500 | [diff] [blame] | 108 | |
| 109 | return glock_wait_table + hash_32(hash, GLOCK_WAIT_TABLE_BITS); |
| 110 | } |
| 111 | |
Andreas Gruenbacher | 0515480 | 2017-08-01 11:18:26 -0500 | [diff] [blame] | 112 | /** |
| 113 | * wake_up_glock - Wake up waiters on a glock |
| 114 | * @gl: the glock |
| 115 | */ |
| 116 | static void wake_up_glock(struct gfs2_glock *gl) |
| 117 | { |
| 118 | wait_queue_head_t *wq = glock_waitqueue(&gl->gl_name); |
| 119 | |
| 120 | if (waitqueue_active(wq)) |
| 121 | __wake_up(wq, TASK_NORMAL, 1, &gl->gl_name); |
| 122 | } |
| 123 | |
Andreas Gruenbacher | 961ae1d | 2017-07-07 13:22:05 -0500 | [diff] [blame] | 124 | static void gfs2_glock_dealloc(struct rcu_head *rcu) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 125 | { |
Andreas Gruenbacher | 961ae1d | 2017-07-07 13:22:05 -0500 | [diff] [blame] | 126 | struct gfs2_glock *gl = container_of(rcu, struct gfs2_glock, gl_rcu); |
Steven Whitehouse | bc015cb | 2011-01-19 09:30:01 +0000 | [diff] [blame] | 127 | |
David Teigland | dba2d70 | 2012-11-14 13:46:53 -0500 | [diff] [blame] | 128 | if (gl->gl_ops->go_flags & GLOF_ASPACE) { |
Steven Whitehouse | bc015cb | 2011-01-19 09:30:01 +0000 | [diff] [blame] | 129 | kmem_cache_free(gfs2_glock_aspace_cachep, gl); |
David Teigland | dba2d70 | 2012-11-14 13:46:53 -0500 | [diff] [blame] | 130 | } else { |
David Teigland | 4e2f884 | 2012-11-14 13:47:37 -0500 | [diff] [blame] | 131 | kfree(gl->gl_lksb.sb_lvbptr); |
Steven Whitehouse | bc015cb | 2011-01-19 09:30:01 +0000 | [diff] [blame] | 132 | kmem_cache_free(gfs2_glock_cachep, gl); |
David Teigland | dba2d70 | 2012-11-14 13:46:53 -0500 | [diff] [blame] | 133 | } |
Andreas Gruenbacher | 961ae1d | 2017-07-07 13:22:05 -0500 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | void gfs2_glock_free(struct gfs2_glock *gl) |
| 137 | { |
| 138 | struct gfs2_sbd *sdp = gl->gl_name.ln_sbd; |
| 139 | |
Bob Peterson | 73118ca | 2019-04-05 04:41:38 +0100 | [diff] [blame] | 140 | BUG_ON(test_bit(GLF_REVOKES, &gl->gl_flags)); |
Andreas Gruenbacher | 0515480 | 2017-08-01 11:18:26 -0500 | [diff] [blame] | 141 | rhashtable_remove_fast(&gl_hash_table, &gl->gl_node, ht_parms); |
| 142 | smp_mb(); |
| 143 | wake_up_glock(gl); |
Andreas Gruenbacher | 961ae1d | 2017-07-07 13:22:05 -0500 | [diff] [blame] | 144 | call_rcu(&gl->gl_rcu, gfs2_glock_dealloc); |
Steven Whitehouse | bc015cb | 2011-01-19 09:30:01 +0000 | [diff] [blame] | 145 | if (atomic_dec_and_test(&sdp->sd_glock_disposal)) |
| 146 | wake_up(&sdp->sd_glock_wait); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | /** |
| 150 | * gfs2_glock_hold() - increment reference count on glock |
| 151 | * @gl: The glock to hold |
| 152 | * |
| 153 | */ |
| 154 | |
Andreas Gruenbacher | 71c1b213 | 2017-08-01 11:45:23 -0500 | [diff] [blame] | 155 | void gfs2_glock_hold(struct gfs2_glock *gl) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 156 | { |
Steven Whitehouse | e66cf16 | 2013-10-15 15:18:08 +0100 | [diff] [blame] | 157 | GLOCK_BUG_ON(gl, __lockref_is_dead(&gl->gl_lockref)); |
| 158 | lockref_get(&gl->gl_lockref); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | /** |
Benjamin Marzinski | 8ff22a6 | 2009-07-10 18:04:24 -0500 | [diff] [blame] | 162 | * demote_ok - Check to see if it's ok to unlock a glock |
| 163 | * @gl: the glock |
| 164 | * |
| 165 | * Returns: 1 if it's ok |
| 166 | */ |
| 167 | |
| 168 | static int demote_ok(const struct gfs2_glock *gl) |
| 169 | { |
| 170 | const struct gfs2_glock_operations *glops = gl->gl_ops; |
| 171 | |
| 172 | if (gl->gl_state == LM_ST_UNLOCKED) |
| 173 | return 0; |
Steven Whitehouse | f42ab08 | 2011-04-14 16:50:31 +0100 | [diff] [blame] | 174 | if (!list_empty(&gl->gl_holders)) |
Benjamin Marzinski | 8ff22a6 | 2009-07-10 18:04:24 -0500 | [diff] [blame] | 175 | return 0; |
| 176 | if (glops->go_demote_ok) |
| 177 | return glops->go_demote_ok(gl); |
| 178 | return 1; |
| 179 | } |
| 180 | |
Steven Whitehouse | bc015cb | 2011-01-19 09:30:01 +0000 | [diff] [blame] | 181 | |
Steven Whitehouse | 29687a2 | 2011-03-30 16:33:25 +0100 | [diff] [blame] | 182 | void gfs2_glock_add_to_lru(struct gfs2_glock *gl) |
| 183 | { |
Ross Lagerwall | 7881ef3 | 2019-03-27 17:09:17 +0000 | [diff] [blame] | 184 | if (!(gl->gl_ops->go_flags & GLOF_LRU)) |
| 185 | return; |
| 186 | |
Steven Whitehouse | 29687a2 | 2011-03-30 16:33:25 +0100 | [diff] [blame] | 187 | spin_lock(&lru_lock); |
| 188 | |
Ross Lagerwall | 7881ef3 | 2019-03-27 17:09:17 +0000 | [diff] [blame] | 189 | list_del(&gl->gl_lru); |
Steven Whitehouse | 29687a2 | 2011-03-30 16:33:25 +0100 | [diff] [blame] | 190 | list_add_tail(&gl->gl_lru, &lru_list); |
Ross Lagerwall | 7881ef3 | 2019-03-27 17:09:17 +0000 | [diff] [blame] | 191 | |
| 192 | if (!test_bit(GLF_LRU, &gl->gl_flags)) { |
| 193 | set_bit(GLF_LRU, &gl->gl_flags); |
| 194 | atomic_inc(&lru_count); |
| 195 | } |
| 196 | |
Steven Whitehouse | 29687a2 | 2011-03-30 16:33:25 +0100 | [diff] [blame] | 197 | spin_unlock(&lru_lock); |
| 198 | } |
| 199 | |
Bob Peterson | 8f6cb40 | 2015-01-05 13:25:10 -0500 | [diff] [blame] | 200 | static void gfs2_glock_remove_from_lru(struct gfs2_glock *gl) |
Steven Whitehouse | f42ab08 | 2011-04-14 16:50:31 +0100 | [diff] [blame] | 201 | { |
Bob Peterson | 645ebd4 | 2017-07-26 10:57:35 -0500 | [diff] [blame] | 202 | if (!(gl->gl_ops->go_flags & GLOF_LRU)) |
| 203 | return; |
| 204 | |
Bob Peterson | 8f6cb40 | 2015-01-05 13:25:10 -0500 | [diff] [blame] | 205 | spin_lock(&lru_lock); |
Ross Lagerwall | 7881ef3 | 2019-03-27 17:09:17 +0000 | [diff] [blame] | 206 | if (test_bit(GLF_LRU, &gl->gl_flags)) { |
Steven Whitehouse | f42ab08 | 2011-04-14 16:50:31 +0100 | [diff] [blame] | 207 | list_del_init(&gl->gl_lru); |
| 208 | atomic_dec(&lru_count); |
| 209 | clear_bit(GLF_LRU, &gl->gl_flags); |
| 210 | } |
| 211 | spin_unlock(&lru_lock); |
| 212 | } |
| 213 | |
Andreas Gruenbacher | 6b0c744 | 2017-06-30 08:10:01 -0500 | [diff] [blame] | 214 | /* |
| 215 | * Enqueue the glock on the work queue. Passes one glock reference on to the |
| 216 | * work queue. |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 217 | */ |
Andreas Gruenbacher | 6b0c744 | 2017-06-30 08:10:01 -0500 | [diff] [blame] | 218 | static void __gfs2_glock_queue_work(struct gfs2_glock *gl, unsigned long delay) { |
| 219 | if (!queue_delayed_work(glock_workqueue, &gl->gl_work, delay)) { |
| 220 | /* |
| 221 | * We are holding the lockref spinlock, and the work was still |
| 222 | * queued above. The queued work (glock_work_func) takes that |
| 223 | * spinlock before dropping its glock reference(s), so it |
| 224 | * cannot have dropped them in the meantime. |
| 225 | */ |
| 226 | GLOCK_BUG_ON(gl, gl->gl_lockref.count < 2); |
| 227 | gl->gl_lockref.count--; |
| 228 | } |
| 229 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 230 | |
Andreas Gruenbacher | 6b0c744 | 2017-06-30 08:10:01 -0500 | [diff] [blame] | 231 | static void gfs2_glock_queue_work(struct gfs2_glock *gl, unsigned long delay) { |
| 232 | spin_lock(&gl->gl_lockref.lock); |
| 233 | __gfs2_glock_queue_work(gl, delay); |
| 234 | spin_unlock(&gl->gl_lockref.lock); |
| 235 | } |
| 236 | |
| 237 | static void __gfs2_glock_put(struct gfs2_glock *gl) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 238 | { |
Bob Peterson | 15562c4 | 2015-03-16 11:52:05 -0500 | [diff] [blame] | 239 | struct gfs2_sbd *sdp = gl->gl_name.ln_sbd; |
Steven Whitehouse | bc015cb | 2011-01-19 09:30:01 +0000 | [diff] [blame] | 240 | struct address_space *mapping = gfs2_glock2aspace(gl); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 241 | |
Steven Whitehouse | e66cf16 | 2013-10-15 15:18:08 +0100 | [diff] [blame] | 242 | lockref_mark_dead(&gl->gl_lockref); |
| 243 | |
Bob Peterson | 8f6cb40 | 2015-01-05 13:25:10 -0500 | [diff] [blame] | 244 | gfs2_glock_remove_from_lru(gl); |
Steven Whitehouse | e66cf16 | 2013-10-15 15:18:08 +0100 | [diff] [blame] | 245 | spin_unlock(&gl->gl_lockref.lock); |
Steven Whitehouse | e66cf16 | 2013-10-15 15:18:08 +0100 | [diff] [blame] | 246 | GLOCK_BUG_ON(gl, !list_empty(&gl->gl_holders)); |
| 247 | GLOCK_BUG_ON(gl, mapping && mapping->nrpages); |
| 248 | trace_gfs2_glock_put(gl); |
| 249 | sdp->sd_lockstruct.ls_ops->lm_put_lock(gl); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 250 | } |
| 251 | |
Andreas Gruenbacher | 71c1b213 | 2017-08-01 11:45:23 -0500 | [diff] [blame] | 252 | /* |
| 253 | * Cause the glock to be put in work queue context. |
| 254 | */ |
| 255 | void gfs2_glock_queue_put(struct gfs2_glock *gl) |
| 256 | { |
| 257 | gfs2_glock_queue_work(gl, 0); |
| 258 | } |
| 259 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 260 | /** |
Andreas Gruenbacher | 6b0c744 | 2017-06-30 08:10:01 -0500 | [diff] [blame] | 261 | * gfs2_glock_put() - Decrement reference count on glock |
| 262 | * @gl: The glock to put |
| 263 | * |
| 264 | */ |
| 265 | |
| 266 | void gfs2_glock_put(struct gfs2_glock *gl) |
| 267 | { |
| 268 | if (lockref_put_or_lock(&gl->gl_lockref)) |
| 269 | return; |
| 270 | |
| 271 | __gfs2_glock_put(gl); |
| 272 | } |
| 273 | |
| 274 | /** |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 275 | * may_grant - check if its ok to grant a new lock |
| 276 | * @gl: The glock |
| 277 | * @gh: The lock request which we wish to grant |
| 278 | * |
| 279 | * Returns: true if its ok to grant the lock |
| 280 | */ |
| 281 | |
| 282 | static inline int may_grant(const struct gfs2_glock *gl, const struct gfs2_holder *gh) |
Benjamin Marzinski | c4f68a1 | 2007-08-23 13:19:05 -0500 | [diff] [blame] | 283 | { |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 284 | const struct gfs2_holder *gh_head = list_entry(gl->gl_holders.next, const struct gfs2_holder, gh_list); |
| 285 | if ((gh->gh_state == LM_ST_EXCLUSIVE || |
| 286 | gh_head->gh_state == LM_ST_EXCLUSIVE) && gh != gh_head) |
| 287 | return 0; |
| 288 | if (gl->gl_state == gh->gh_state) |
| 289 | return 1; |
| 290 | if (gh->gh_flags & GL_EXACT) |
| 291 | return 0; |
Steven Whitehouse | 209806a | 2008-07-07 10:07:28 +0100 | [diff] [blame] | 292 | if (gl->gl_state == LM_ST_EXCLUSIVE) { |
| 293 | if (gh->gh_state == LM_ST_SHARED && gh_head->gh_state == LM_ST_SHARED) |
| 294 | return 1; |
| 295 | if (gh->gh_state == LM_ST_DEFERRED && gh_head->gh_state == LM_ST_DEFERRED) |
| 296 | return 1; |
| 297 | } |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 298 | if (gl->gl_state != LM_ST_UNLOCKED && (gh->gh_flags & LM_FLAG_ANY)) |
| 299 | return 1; |
| 300 | return 0; |
| 301 | } |
| 302 | |
| 303 | static void gfs2_holder_wake(struct gfs2_holder *gh) |
| 304 | { |
| 305 | clear_bit(HIF_WAIT, &gh->gh_iflags); |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 306 | smp_mb__after_atomic(); |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 307 | wake_up_bit(&gh->gh_iflags, HIF_WAIT); |
| 308 | } |
| 309 | |
| 310 | /** |
Steven Whitehouse | d5341a9 | 2010-07-23 14:05:51 +0100 | [diff] [blame] | 311 | * do_error - Something unexpected has happened during a lock request |
| 312 | * |
| 313 | */ |
| 314 | |
Denys Vlasenko | a527b38 | 2016-04-12 12:39:12 -0400 | [diff] [blame] | 315 | static void do_error(struct gfs2_glock *gl, const int ret) |
Steven Whitehouse | d5341a9 | 2010-07-23 14:05:51 +0100 | [diff] [blame] | 316 | { |
| 317 | struct gfs2_holder *gh, *tmp; |
| 318 | |
| 319 | list_for_each_entry_safe(gh, tmp, &gl->gl_holders, gh_list) { |
| 320 | if (test_bit(HIF_HOLDER, &gh->gh_iflags)) |
| 321 | continue; |
| 322 | if (ret & LM_OUT_ERROR) |
| 323 | gh->gh_error = -EIO; |
| 324 | else if (gh->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB)) |
| 325 | gh->gh_error = GLR_TRYFAILED; |
| 326 | else |
| 327 | continue; |
| 328 | list_del_init(&gh->gh_list); |
| 329 | trace_gfs2_glock_queue(gh, 0); |
| 330 | gfs2_holder_wake(gh); |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | /** |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 335 | * do_promote - promote as many requests as possible on the current queue |
| 336 | * @gl: The glock |
| 337 | * |
Steven Whitehouse | 813e0c4 | 2008-11-18 13:38:48 +0000 | [diff] [blame] | 338 | * Returns: 1 if there is a blocked holder at the head of the list, or 2 |
| 339 | * if a type specific operation is underway. |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 340 | */ |
| 341 | |
| 342 | static int do_promote(struct gfs2_glock *gl) |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 343 | __releases(&gl->gl_lockref.lock) |
| 344 | __acquires(&gl->gl_lockref.lock) |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 345 | { |
| 346 | const struct gfs2_glock_operations *glops = gl->gl_ops; |
| 347 | struct gfs2_holder *gh, *tmp; |
| 348 | int ret; |
| 349 | |
| 350 | restart: |
| 351 | list_for_each_entry_safe(gh, tmp, &gl->gl_holders, gh_list) { |
| 352 | if (test_bit(HIF_HOLDER, &gh->gh_iflags)) |
| 353 | continue; |
| 354 | if (may_grant(gl, gh)) { |
| 355 | if (gh->gh_list.prev == &gl->gl_holders && |
| 356 | glops->go_lock) { |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 357 | spin_unlock(&gl->gl_lockref.lock); |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 358 | /* FIXME: eliminate this eventually */ |
| 359 | ret = glops->go_lock(gh); |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 360 | spin_lock(&gl->gl_lockref.lock); |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 361 | if (ret) { |
Steven Whitehouse | 813e0c4 | 2008-11-18 13:38:48 +0000 | [diff] [blame] | 362 | if (ret == 1) |
| 363 | return 2; |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 364 | gh->gh_error = ret; |
| 365 | list_del_init(&gh->gh_list); |
Steven Whitehouse | 6399777 | 2009-06-12 08:49:20 +0100 | [diff] [blame] | 366 | trace_gfs2_glock_queue(gh, 0); |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 367 | gfs2_holder_wake(gh); |
| 368 | goto restart; |
| 369 | } |
| 370 | set_bit(HIF_HOLDER, &gh->gh_iflags); |
Steven Whitehouse | 6399777 | 2009-06-12 08:49:20 +0100 | [diff] [blame] | 371 | trace_gfs2_promote(gh, 1); |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 372 | gfs2_holder_wake(gh); |
| 373 | goto restart; |
| 374 | } |
| 375 | set_bit(HIF_HOLDER, &gh->gh_iflags); |
Steven Whitehouse | 6399777 | 2009-06-12 08:49:20 +0100 | [diff] [blame] | 376 | trace_gfs2_promote(gh, 0); |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 377 | gfs2_holder_wake(gh); |
| 378 | continue; |
| 379 | } |
| 380 | if (gh->gh_list.prev == &gl->gl_holders) |
| 381 | return 1; |
Steven Whitehouse | d5341a9 | 2010-07-23 14:05:51 +0100 | [diff] [blame] | 382 | do_error(gl, 0); |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 383 | break; |
| 384 | } |
| 385 | return 0; |
| 386 | } |
| 387 | |
| 388 | /** |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 389 | * find_first_waiter - find the first gh that's waiting for the glock |
| 390 | * @gl: the glock |
| 391 | */ |
| 392 | |
| 393 | static inline struct gfs2_holder *find_first_waiter(const struct gfs2_glock *gl) |
| 394 | { |
| 395 | struct gfs2_holder *gh; |
| 396 | |
| 397 | list_for_each_entry(gh, &gl->gl_holders, gh_list) { |
| 398 | if (!test_bit(HIF_HOLDER, &gh->gh_iflags)) |
| 399 | return gh; |
| 400 | } |
| 401 | return NULL; |
| 402 | } |
| 403 | |
| 404 | /** |
| 405 | * state_change - record that the glock is now in a different state |
| 406 | * @gl: the glock |
| 407 | * @new_state the new state |
| 408 | * |
| 409 | */ |
| 410 | |
| 411 | static void state_change(struct gfs2_glock *gl, unsigned int new_state) |
| 412 | { |
| 413 | int held1, held2; |
| 414 | |
| 415 | held1 = (gl->gl_state != LM_ST_UNLOCKED); |
| 416 | held2 = (new_state != LM_ST_UNLOCKED); |
| 417 | |
| 418 | if (held1 != held2) { |
Steven Whitehouse | e66cf16 | 2013-10-15 15:18:08 +0100 | [diff] [blame] | 419 | GLOCK_BUG_ON(gl, __lockref_is_dead(&gl->gl_lockref)); |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 420 | if (held2) |
Steven Whitehouse | e66cf16 | 2013-10-15 15:18:08 +0100 | [diff] [blame] | 421 | gl->gl_lockref.count++; |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 422 | else |
Steven Whitehouse | e66cf16 | 2013-10-15 15:18:08 +0100 | [diff] [blame] | 423 | gl->gl_lockref.count--; |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 424 | } |
Steven Whitehouse | 7b5e3d5 | 2010-09-03 09:39:20 +0100 | [diff] [blame] | 425 | if (held1 && held2 && list_empty(&gl->gl_holders)) |
| 426 | clear_bit(GLF_QUEUED, &gl->gl_flags); |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 427 | |
Bob Peterson | 7cf8dcd | 2011-06-15 11:41:48 -0400 | [diff] [blame] | 428 | if (new_state != gl->gl_target) |
| 429 | /* shorten our minimum hold time */ |
| 430 | gl->gl_hold_time = max(gl->gl_hold_time - GL_GLOCK_HOLD_DECR, |
| 431 | GL_GLOCK_MIN_HOLD); |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 432 | gl->gl_state = new_state; |
| 433 | gl->gl_tchange = jiffies; |
| 434 | } |
| 435 | |
| 436 | static void gfs2_demote_wake(struct gfs2_glock *gl) |
| 437 | { |
| 438 | gl->gl_demote_state = LM_ST_EXCLUSIVE; |
| 439 | clear_bit(GLF_DEMOTE, &gl->gl_flags); |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 440 | smp_mb__after_atomic(); |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 441 | wake_up_bit(&gl->gl_flags, GLF_DEMOTE); |
| 442 | } |
| 443 | |
| 444 | /** |
| 445 | * finish_xmote - The DLM has replied to one of our lock requests |
| 446 | * @gl: The glock |
| 447 | * @ret: The status from the DLM |
| 448 | * |
| 449 | */ |
| 450 | |
| 451 | static void finish_xmote(struct gfs2_glock *gl, unsigned int ret) |
| 452 | { |
| 453 | const struct gfs2_glock_operations *glops = gl->gl_ops; |
| 454 | struct gfs2_holder *gh; |
| 455 | unsigned state = ret & LM_OUT_ST_MASK; |
Steven Whitehouse | 813e0c4 | 2008-11-18 13:38:48 +0000 | [diff] [blame] | 456 | int rv; |
Benjamin Marzinski | c4f68a1 | 2007-08-23 13:19:05 -0500 | [diff] [blame] | 457 | |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 458 | spin_lock(&gl->gl_lockref.lock); |
Steven Whitehouse | 6399777 | 2009-06-12 08:49:20 +0100 | [diff] [blame] | 459 | trace_gfs2_glock_state_change(gl, state); |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 460 | state_change(gl, state); |
| 461 | gh = find_first_waiter(gl); |
| 462 | |
| 463 | /* Demote to UN request arrived during demote to SH or DF */ |
| 464 | if (test_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags) && |
| 465 | state != LM_ST_UNLOCKED && gl->gl_demote_state == LM_ST_UNLOCKED) |
| 466 | gl->gl_target = LM_ST_UNLOCKED; |
| 467 | |
| 468 | /* Check for state != intended state */ |
| 469 | if (unlikely(state != gl->gl_target)) { |
| 470 | if (gh && !test_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags)) { |
| 471 | /* move to back of queue and try next entry */ |
| 472 | if (ret & LM_OUT_CANCELED) { |
| 473 | if ((gh->gh_flags & LM_FLAG_PRIORITY) == 0) |
| 474 | list_move_tail(&gh->gh_list, &gl->gl_holders); |
| 475 | gh = find_first_waiter(gl); |
| 476 | gl->gl_target = gh->gh_state; |
| 477 | goto retry; |
| 478 | } |
| 479 | /* Some error or failed "try lock" - report it */ |
| 480 | if ((ret & LM_OUT_ERROR) || |
| 481 | (gh->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB))) { |
| 482 | gl->gl_target = gl->gl_state; |
| 483 | do_error(gl, ret); |
| 484 | goto out; |
| 485 | } |
| 486 | } |
| 487 | switch(state) { |
| 488 | /* Unlocked due to conversion deadlock, try again */ |
| 489 | case LM_ST_UNLOCKED: |
| 490 | retry: |
| 491 | do_xmote(gl, gh, gl->gl_target); |
| 492 | break; |
| 493 | /* Conversion fails, unlock and try again */ |
| 494 | case LM_ST_SHARED: |
| 495 | case LM_ST_DEFERRED: |
| 496 | do_xmote(gl, gh, LM_ST_UNLOCKED); |
| 497 | break; |
| 498 | default: /* Everything else */ |
Bob Peterson | e54c78a | 2018-10-03 08:47:36 -0500 | [diff] [blame] | 499 | fs_err(gl->gl_name.ln_sbd, "wanted %u got %u\n", |
| 500 | gl->gl_target, state); |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 501 | GLOCK_BUG_ON(gl, 1); |
| 502 | } |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 503 | spin_unlock(&gl->gl_lockref.lock); |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 504 | return; |
| 505 | } |
| 506 | |
| 507 | /* Fast path - we got what we asked for */ |
| 508 | if (test_and_clear_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags)) |
| 509 | gfs2_demote_wake(gl); |
| 510 | if (state != LM_ST_UNLOCKED) { |
| 511 | if (glops->go_xmote_bh) { |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 512 | spin_unlock(&gl->gl_lockref.lock); |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 513 | rv = glops->go_xmote_bh(gl, gh); |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 514 | spin_lock(&gl->gl_lockref.lock); |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 515 | if (rv) { |
| 516 | do_error(gl, rv); |
| 517 | goto out; |
| 518 | } |
| 519 | } |
Steven Whitehouse | 813e0c4 | 2008-11-18 13:38:48 +0000 | [diff] [blame] | 520 | rv = do_promote(gl); |
| 521 | if (rv == 2) |
| 522 | goto out_locked; |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 523 | } |
| 524 | out: |
| 525 | clear_bit(GLF_LOCK, &gl->gl_flags); |
Steven Whitehouse | 813e0c4 | 2008-11-18 13:38:48 +0000 | [diff] [blame] | 526 | out_locked: |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 527 | spin_unlock(&gl->gl_lockref.lock); |
Benjamin Marzinski | c4f68a1 | 2007-08-23 13:19:05 -0500 | [diff] [blame] | 528 | } |
| 529 | |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 530 | /** |
| 531 | * do_xmote - Calls the DLM to change the state of a lock |
| 532 | * @gl: The lock state |
| 533 | * @gh: The holder (only for promotes) |
| 534 | * @target: The target lock state |
| 535 | * |
| 536 | */ |
| 537 | |
| 538 | static void do_xmote(struct gfs2_glock *gl, struct gfs2_holder *gh, unsigned int target) |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 539 | __releases(&gl->gl_lockref.lock) |
| 540 | __acquires(&gl->gl_lockref.lock) |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 541 | { |
| 542 | const struct gfs2_glock_operations *glops = gl->gl_ops; |
Bob Peterson | 15562c4 | 2015-03-16 11:52:05 -0500 | [diff] [blame] | 543 | struct gfs2_sbd *sdp = gl->gl_name.ln_sbd; |
Bob Peterson | b58bf40 | 2015-07-24 09:45:43 -0500 | [diff] [blame] | 544 | unsigned int lck_flags = (unsigned int)(gh ? gh->gh_flags : 0); |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 545 | int ret; |
| 546 | |
Bob Peterson | ed17545 | 2017-05-05 09:43:02 -0500 | [diff] [blame] | 547 | if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags)) && |
| 548 | target != LM_ST_UNLOCKED) |
Bob Peterson | 0d1c7ae | 2017-03-03 12:37:14 -0500 | [diff] [blame] | 549 | return; |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 550 | lck_flags &= (LM_FLAG_TRY | LM_FLAG_TRY_1CB | LM_FLAG_NOEXP | |
| 551 | LM_FLAG_PRIORITY); |
Steven Whitehouse | 921169c | 2010-11-29 12:50:38 +0000 | [diff] [blame] | 552 | GLOCK_BUG_ON(gl, gl->gl_state == target); |
| 553 | GLOCK_BUG_ON(gl, gl->gl_state == gl->gl_target); |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 554 | if ((target == LM_ST_UNLOCKED || target == LM_ST_DEFERRED) && |
| 555 | glops->go_inval) { |
| 556 | set_bit(GLF_INVALIDATE_IN_PROGRESS, &gl->gl_flags); |
| 557 | do_error(gl, 0); /* Fail queued try locks */ |
| 558 | } |
Steven Whitehouse | 47a2538 | 2010-11-30 15:49:31 +0000 | [diff] [blame] | 559 | gl->gl_req = target; |
Steven Whitehouse | a245769 | 2012-01-20 10:38:36 +0000 | [diff] [blame] | 560 | set_bit(GLF_BLOCKING, &gl->gl_flags); |
| 561 | if ((gl->gl_req == LM_ST_UNLOCKED) || |
| 562 | (gl->gl_state == LM_ST_EXCLUSIVE) || |
| 563 | (lck_flags & (LM_FLAG_TRY|LM_FLAG_TRY_1CB))) |
| 564 | clear_bit(GLF_BLOCKING, &gl->gl_flags); |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 565 | spin_unlock(&gl->gl_lockref.lock); |
Bob Peterson | 06dfc30 | 2012-10-24 14:41:05 -0400 | [diff] [blame] | 566 | if (glops->go_sync) |
| 567 | glops->go_sync(gl); |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 568 | if (test_bit(GLF_INVALIDATE_IN_PROGRESS, &gl->gl_flags)) |
| 569 | glops->go_inval(gl, target == LM_ST_DEFERRED ? 0 : DIO_METADATA); |
| 570 | clear_bit(GLF_INVALIDATE_IN_PROGRESS, &gl->gl_flags); |
| 571 | |
| 572 | gfs2_glock_hold(gl); |
Steven Whitehouse | 921169c | 2010-11-29 12:50:38 +0000 | [diff] [blame] | 573 | if (sdp->sd_lockstruct.ls_ops->lm_lock) { |
| 574 | /* lock_dlm */ |
| 575 | ret = sdp->sd_lockstruct.ls_ops->lm_lock(gl, target, lck_flags); |
Benjamin Marzinski | 3e11e53 | 2016-03-23 14:29:59 -0400 | [diff] [blame] | 576 | if (ret == -EINVAL && gl->gl_target == LM_ST_UNLOCKED && |
| 577 | target == LM_ST_UNLOCKED && |
| 578 | test_bit(SDF_SKIP_DLM_UNLOCK, &sdp->sd_flags)) { |
| 579 | finish_xmote(gl, target); |
Andreas Gruenbacher | 6b0c744 | 2017-06-30 08:10:01 -0500 | [diff] [blame] | 580 | gfs2_glock_queue_work(gl, 0); |
Benjamin Marzinski | 3e11e53 | 2016-03-23 14:29:59 -0400 | [diff] [blame] | 581 | } |
| 582 | else if (ret) { |
Bob Peterson | e54c78a | 2018-10-03 08:47:36 -0500 | [diff] [blame] | 583 | fs_err(sdp, "lm_lock ret %d\n", ret); |
Bob Peterson | ed17545 | 2017-05-05 09:43:02 -0500 | [diff] [blame] | 584 | GLOCK_BUG_ON(gl, !test_bit(SDF_SHUTDOWN, |
| 585 | &sdp->sd_flags)); |
David Teigland | dba2d70 | 2012-11-14 13:46:53 -0500 | [diff] [blame] | 586 | } |
Steven Whitehouse | 921169c | 2010-11-29 12:50:38 +0000 | [diff] [blame] | 587 | } else { /* lock_nolock */ |
| 588 | finish_xmote(gl, target); |
Andreas Gruenbacher | 6b0c744 | 2017-06-30 08:10:01 -0500 | [diff] [blame] | 589 | gfs2_glock_queue_work(gl, 0); |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 590 | } |
Steven Whitehouse | 921169c | 2010-11-29 12:50:38 +0000 | [diff] [blame] | 591 | |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 592 | spin_lock(&gl->gl_lockref.lock); |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | /** |
| 596 | * find_first_holder - find the first "holder" gh |
| 597 | * @gl: the glock |
| 598 | */ |
| 599 | |
| 600 | static inline struct gfs2_holder *find_first_holder(const struct gfs2_glock *gl) |
| 601 | { |
| 602 | struct gfs2_holder *gh; |
| 603 | |
| 604 | if (!list_empty(&gl->gl_holders)) { |
| 605 | gh = list_entry(gl->gl_holders.next, struct gfs2_holder, gh_list); |
| 606 | if (test_bit(HIF_HOLDER, &gh->gh_iflags)) |
| 607 | return gh; |
| 608 | } |
| 609 | return NULL; |
| 610 | } |
| 611 | |
| 612 | /** |
| 613 | * run_queue - do all outstanding tasks related to a glock |
| 614 | * @gl: The glock in question |
| 615 | * @nonblock: True if we must not block in run_queue |
| 616 | * |
| 617 | */ |
| 618 | |
| 619 | static void run_queue(struct gfs2_glock *gl, const int nonblock) |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 620 | __releases(&gl->gl_lockref.lock) |
| 621 | __acquires(&gl->gl_lockref.lock) |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 622 | { |
| 623 | struct gfs2_holder *gh = NULL; |
Steven Whitehouse | 813e0c4 | 2008-11-18 13:38:48 +0000 | [diff] [blame] | 624 | int ret; |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 625 | |
| 626 | if (test_and_set_bit(GLF_LOCK, &gl->gl_flags)) |
| 627 | return; |
| 628 | |
| 629 | GLOCK_BUG_ON(gl, test_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags)); |
| 630 | |
| 631 | if (test_bit(GLF_DEMOTE, &gl->gl_flags) && |
| 632 | gl->gl_demote_state != gl->gl_state) { |
| 633 | if (find_first_holder(gl)) |
Steven Whitehouse | d8348de | 2009-02-05 10:12:38 +0000 | [diff] [blame] | 634 | goto out_unlock; |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 635 | if (nonblock) |
| 636 | goto out_sched; |
| 637 | set_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags); |
Steven Whitehouse | 265d529c | 2008-07-07 10:02:36 +0100 | [diff] [blame] | 638 | GLOCK_BUG_ON(gl, gl->gl_demote_state == LM_ST_EXCLUSIVE); |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 639 | gl->gl_target = gl->gl_demote_state; |
| 640 | } else { |
| 641 | if (test_bit(GLF_DEMOTE, &gl->gl_flags)) |
| 642 | gfs2_demote_wake(gl); |
Steven Whitehouse | 813e0c4 | 2008-11-18 13:38:48 +0000 | [diff] [blame] | 643 | ret = do_promote(gl); |
| 644 | if (ret == 0) |
Steven Whitehouse | d8348de | 2009-02-05 10:12:38 +0000 | [diff] [blame] | 645 | goto out_unlock; |
Steven Whitehouse | 813e0c4 | 2008-11-18 13:38:48 +0000 | [diff] [blame] | 646 | if (ret == 2) |
Steven Whitehouse | a228df6 | 2009-04-07 14:01:34 +0100 | [diff] [blame] | 647 | goto out; |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 648 | gh = find_first_waiter(gl); |
| 649 | gl->gl_target = gh->gh_state; |
| 650 | if (!(gh->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB))) |
| 651 | do_error(gl, 0); /* Fail queued try locks */ |
| 652 | } |
| 653 | do_xmote(gl, gh, gl->gl_target); |
Steven Whitehouse | a228df6 | 2009-04-07 14:01:34 +0100 | [diff] [blame] | 654 | out: |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 655 | return; |
| 656 | |
| 657 | out_sched: |
Steven Whitehouse | 7e71c55 | 2009-09-22 10:56:16 +0100 | [diff] [blame] | 658 | clear_bit(GLF_LOCK, &gl->gl_flags); |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 659 | smp_mb__after_atomic(); |
Steven Whitehouse | e66cf16 | 2013-10-15 15:18:08 +0100 | [diff] [blame] | 660 | gl->gl_lockref.count++; |
Andreas Gruenbacher | 6b0c744 | 2017-06-30 08:10:01 -0500 | [diff] [blame] | 661 | __gfs2_glock_queue_work(gl, 0); |
Steven Whitehouse | 7e71c55 | 2009-09-22 10:56:16 +0100 | [diff] [blame] | 662 | return; |
| 663 | |
Steven Whitehouse | d8348de | 2009-02-05 10:12:38 +0000 | [diff] [blame] | 664 | out_unlock: |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 665 | clear_bit(GLF_LOCK, &gl->gl_flags); |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 666 | smp_mb__after_atomic(); |
Steven Whitehouse | 7e71c55 | 2009-09-22 10:56:16 +0100 | [diff] [blame] | 667 | return; |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 668 | } |
| 669 | |
Benjamin Marzinski | b94a170 | 2009-07-23 18:52:34 -0500 | [diff] [blame] | 670 | static void delete_work_func(struct work_struct *work) |
| 671 | { |
| 672 | struct gfs2_glock *gl = container_of(work, struct gfs2_glock, gl_delete); |
Bob Peterson | 15562c4 | 2015-03-16 11:52:05 -0500 | [diff] [blame] | 673 | struct gfs2_sbd *sdp = gl->gl_name.ln_sbd; |
Andreas Gruenbacher | ec5ec66 | 2016-06-14 12:23:59 -0500 | [diff] [blame] | 674 | struct inode *inode; |
Steven Whitehouse | 044b941 | 2010-11-03 20:01:07 +0000 | [diff] [blame] | 675 | u64 no_addr = gl->gl_name.ln_number; |
Benjamin Marzinski | b94a170 | 2009-07-23 18:52:34 -0500 | [diff] [blame] | 676 | |
Bob Peterson | a492386 | 2015-12-07 16:24:27 -0600 | [diff] [blame] | 677 | /* If someone's using this glock to create a new dinode, the block must |
| 678 | have been freed by another node, then re-used, in which case our |
| 679 | iopen callback is too late after the fact. Ignore it. */ |
| 680 | if (test_bit(GLF_INODE_CREATING, &gl->gl_flags)) |
| 681 | goto out; |
| 682 | |
Andreas Gruenbacher | ec5ec66 | 2016-06-14 12:23:59 -0500 | [diff] [blame] | 683 | inode = gfs2_lookup_by_inum(sdp, no_addr, NULL, GFS2_BLKST_UNLINKED); |
Steven Whitehouse | 044b941 | 2010-11-03 20:01:07 +0000 | [diff] [blame] | 684 | if (inode && !IS_ERR(inode)) { |
| 685 | d_prune_aliases(inode); |
| 686 | iput(inode); |
Benjamin Marzinski | b94a170 | 2009-07-23 18:52:34 -0500 | [diff] [blame] | 687 | } |
Bob Peterson | a492386 | 2015-12-07 16:24:27 -0600 | [diff] [blame] | 688 | out: |
Benjamin Marzinski | b94a170 | 2009-07-23 18:52:34 -0500 | [diff] [blame] | 689 | gfs2_glock_put(gl); |
| 690 | } |
| 691 | |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 692 | static void glock_work_func(struct work_struct *work) |
| 693 | { |
| 694 | unsigned long delay = 0; |
| 695 | struct gfs2_glock *gl = container_of(work, struct gfs2_glock, gl_work.work); |
Andreas Gruenbacher | 6b0c744 | 2017-06-30 08:10:01 -0500 | [diff] [blame] | 696 | unsigned int drop_refs = 1; |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 697 | |
Steven Whitehouse | 26bb750 | 2009-11-27 10:31:11 +0000 | [diff] [blame] | 698 | if (test_and_clear_bit(GLF_REPLY_PENDING, &gl->gl_flags)) { |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 699 | finish_xmote(gl, gl->gl_reply); |
Andreas Gruenbacher | 6b0c744 | 2017-06-30 08:10:01 -0500 | [diff] [blame] | 700 | drop_refs++; |
Steven Whitehouse | 26bb750 | 2009-11-27 10:31:11 +0000 | [diff] [blame] | 701 | } |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 702 | spin_lock(&gl->gl_lockref.lock); |
Bob Peterson | f90e5b5 | 2011-05-24 10:44:42 -0400 | [diff] [blame] | 703 | if (test_bit(GLF_PENDING_DEMOTE, &gl->gl_flags) && |
Steven Whitehouse | 265d529c | 2008-07-07 10:02:36 +0100 | [diff] [blame] | 704 | gl->gl_state != LM_ST_UNLOCKED && |
| 705 | gl->gl_demote_state != LM_ST_EXCLUSIVE) { |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 706 | unsigned long holdtime, now = jiffies; |
Bob Peterson | f90e5b5 | 2011-05-24 10:44:42 -0400 | [diff] [blame] | 707 | |
Bob Peterson | 7cf8dcd | 2011-06-15 11:41:48 -0400 | [diff] [blame] | 708 | holdtime = gl->gl_tchange + gl->gl_hold_time; |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 709 | if (time_before(now, holdtime)) |
| 710 | delay = holdtime - now; |
Bob Peterson | f90e5b5 | 2011-05-24 10:44:42 -0400 | [diff] [blame] | 711 | |
| 712 | if (!delay) { |
| 713 | clear_bit(GLF_PENDING_DEMOTE, &gl->gl_flags); |
| 714 | set_bit(GLF_DEMOTE, &gl->gl_flags); |
| 715 | } |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 716 | } |
| 717 | run_queue(gl, 0); |
Andreas Gruenbacher | 6b0c744 | 2017-06-30 08:10:01 -0500 | [diff] [blame] | 718 | if (delay) { |
| 719 | /* Keep one glock reference for the work we requeue. */ |
| 720 | drop_refs--; |
Bob Peterson | 7cf8dcd | 2011-06-15 11:41:48 -0400 | [diff] [blame] | 721 | if (gl->gl_name.ln_type != LM_TYPE_INODE) |
| 722 | delay = 0; |
Andreas Gruenbacher | 6b0c744 | 2017-06-30 08:10:01 -0500 | [diff] [blame] | 723 | __gfs2_glock_queue_work(gl, delay); |
Bob Peterson | 7cf8dcd | 2011-06-15 11:41:48 -0400 | [diff] [blame] | 724 | } |
Andreas Gruenbacher | 6b0c744 | 2017-06-30 08:10:01 -0500 | [diff] [blame] | 725 | |
| 726 | /* |
| 727 | * Drop the remaining glock references manually here. (Mind that |
| 728 | * __gfs2_glock_queue_work depends on the lockref spinlock begin held |
| 729 | * here as well.) |
| 730 | */ |
| 731 | gl->gl_lockref.count -= drop_refs; |
| 732 | if (!gl->gl_lockref.count) { |
| 733 | __gfs2_glock_put(gl); |
| 734 | return; |
| 735 | } |
| 736 | spin_unlock(&gl->gl_lockref.lock); |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 737 | } |
| 738 | |
Andreas Gruenbacher | 0515480 | 2017-08-01 11:18:26 -0500 | [diff] [blame] | 739 | static struct gfs2_glock *find_insert_glock(struct lm_lockname *name, |
| 740 | struct gfs2_glock *new) |
| 741 | { |
| 742 | struct wait_glock_queue wait; |
Andreas Gruenbacher | a91323e | 2017-08-04 07:40:45 -0500 | [diff] [blame] | 743 | wait_queue_head_t *wq = glock_waitqueue(name); |
Andreas Gruenbacher | 0515480 | 2017-08-01 11:18:26 -0500 | [diff] [blame] | 744 | struct gfs2_glock *gl; |
| 745 | |
Andreas Gruenbacher | a91323e | 2017-08-04 07:40:45 -0500 | [diff] [blame] | 746 | wait.name = name; |
| 747 | init_wait(&wait.wait); |
| 748 | wait.wait.func = glock_wake_function; |
| 749 | |
Andreas Gruenbacher | 0515480 | 2017-08-01 11:18:26 -0500 | [diff] [blame] | 750 | again: |
Andreas Gruenbacher | a91323e | 2017-08-04 07:40:45 -0500 | [diff] [blame] | 751 | prepare_to_wait(wq, &wait.wait, TASK_UNINTERRUPTIBLE); |
Andreas Gruenbacher | 0515480 | 2017-08-01 11:18:26 -0500 | [diff] [blame] | 752 | rcu_read_lock(); |
| 753 | if (new) { |
| 754 | gl = rhashtable_lookup_get_insert_fast(&gl_hash_table, |
| 755 | &new->gl_node, ht_parms); |
| 756 | if (IS_ERR(gl)) |
| 757 | goto out; |
| 758 | } else { |
| 759 | gl = rhashtable_lookup_fast(&gl_hash_table, |
| 760 | name, ht_parms); |
| 761 | } |
| 762 | if (gl && !lockref_get_not_dead(&gl->gl_lockref)) { |
| 763 | rcu_read_unlock(); |
| 764 | schedule(); |
| 765 | goto again; |
| 766 | } |
| 767 | out: |
| 768 | rcu_read_unlock(); |
Andreas Gruenbacher | a91323e | 2017-08-04 07:40:45 -0500 | [diff] [blame] | 769 | finish_wait(wq, &wait.wait); |
Andreas Gruenbacher | 0515480 | 2017-08-01 11:18:26 -0500 | [diff] [blame] | 770 | return gl; |
| 771 | } |
| 772 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 773 | /** |
| 774 | * gfs2_glock_get() - Get a glock, or create one if one doesn't exist |
| 775 | * @sdp: The GFS2 superblock |
| 776 | * @number: the lock number |
| 777 | * @glops: The glock_operations to use |
| 778 | * @create: If 0, don't create the glock if it doesn't exist |
| 779 | * @glp: the glock is returned here |
| 780 | * |
| 781 | * This does not lock a glock, just finds/creates structures for one. |
| 782 | * |
| 783 | * Returns: errno |
| 784 | */ |
| 785 | |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 786 | int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number, |
Steven Whitehouse | 8fb4b53 | 2006-08-30 09:30:00 -0400 | [diff] [blame] | 787 | const struct gfs2_glock_operations *glops, int create, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 788 | struct gfs2_glock **glp) |
| 789 | { |
Steven Whitehouse | 009d851 | 2009-12-08 12:12:13 +0000 | [diff] [blame] | 790 | struct super_block *s = sdp->sd_vfs; |
Bob Peterson | 15562c4 | 2015-03-16 11:52:05 -0500 | [diff] [blame] | 791 | struct lm_lockname name = { .ln_number = number, |
| 792 | .ln_type = glops->go_type, |
| 793 | .ln_sbd = sdp }; |
Andreas Gruenbacher | 0a52aba | 2017-02-21 23:19:10 +0100 | [diff] [blame] | 794 | struct gfs2_glock *gl, *tmp; |
Steven Whitehouse | 009d851 | 2009-12-08 12:12:13 +0000 | [diff] [blame] | 795 | struct address_space *mapping; |
Steven Whitehouse | bc015cb | 2011-01-19 09:30:01 +0000 | [diff] [blame] | 796 | struct kmem_cache *cachep; |
Andreas Gruenbacher | 0a52aba | 2017-02-21 23:19:10 +0100 | [diff] [blame] | 797 | int ret = 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 798 | |
Andreas Gruenbacher | 0515480 | 2017-08-01 11:18:26 -0500 | [diff] [blame] | 799 | gl = find_insert_glock(&name, NULL); |
| 800 | if (gl) { |
| 801 | *glp = gl; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 802 | return 0; |
Andreas Gruenbacher | 0515480 | 2017-08-01 11:18:26 -0500 | [diff] [blame] | 803 | } |
Steven Whitehouse | 64d576b | 2009-02-12 13:31:58 +0000 | [diff] [blame] | 804 | if (!create) |
| 805 | return -ENOENT; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 806 | |
Steven Whitehouse | 009d851 | 2009-12-08 12:12:13 +0000 | [diff] [blame] | 807 | if (glops->go_flags & GLOF_ASPACE) |
Steven Whitehouse | bc015cb | 2011-01-19 09:30:01 +0000 | [diff] [blame] | 808 | cachep = gfs2_glock_aspace_cachep; |
Steven Whitehouse | 009d851 | 2009-12-08 12:12:13 +0000 | [diff] [blame] | 809 | else |
Steven Whitehouse | bc015cb | 2011-01-19 09:30:01 +0000 | [diff] [blame] | 810 | cachep = gfs2_glock_cachep; |
Steven Whitehouse | fe0bbd2 | 2014-06-23 14:50:20 +0100 | [diff] [blame] | 811 | gl = kmem_cache_alloc(cachep, GFP_NOFS); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 812 | if (!gl) |
| 813 | return -ENOMEM; |
| 814 | |
David Teigland | dba2d70 | 2012-11-14 13:46:53 -0500 | [diff] [blame] | 815 | memset(&gl->gl_lksb, 0, sizeof(struct dlm_lksb)); |
David Teigland | dba2d70 | 2012-11-14 13:46:53 -0500 | [diff] [blame] | 816 | |
| 817 | if (glops->go_flags & GLOF_LVB) { |
Steven Whitehouse | fe0bbd2 | 2014-06-23 14:50:20 +0100 | [diff] [blame] | 818 | gl->gl_lksb.sb_lvbptr = kzalloc(GFS2_MIN_LVB_SIZE, GFP_NOFS); |
David Teigland | 4e2f884 | 2012-11-14 13:47:37 -0500 | [diff] [blame] | 819 | if (!gl->gl_lksb.sb_lvbptr) { |
David Teigland | dba2d70 | 2012-11-14 13:46:53 -0500 | [diff] [blame] | 820 | kmem_cache_free(cachep, gl); |
| 821 | return -ENOMEM; |
| 822 | } |
David Teigland | dba2d70 | 2012-11-14 13:46:53 -0500 | [diff] [blame] | 823 | } |
| 824 | |
Steven Whitehouse | 8f05228 | 2010-01-29 15:21:27 +0000 | [diff] [blame] | 825 | atomic_inc(&sdp->sd_glock_disposal); |
Bob Peterson | 88ffbf3 | 2015-03-16 11:02:46 -0500 | [diff] [blame] | 826 | gl->gl_node.next = NULL; |
Steven Whitehouse | ec45d9f | 2006-08-30 10:36:52 -0400 | [diff] [blame] | 827 | gl->gl_flags = 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 828 | gl->gl_name = name; |
Steven Whitehouse | e66cf16 | 2013-10-15 15:18:08 +0100 | [diff] [blame] | 829 | gl->gl_lockref.count = 1; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 830 | gl->gl_state = LM_ST_UNLOCKED; |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 831 | gl->gl_target = LM_ST_UNLOCKED; |
Benjamin Marzinski | c4f68a1 | 2007-08-23 13:19:05 -0500 | [diff] [blame] | 832 | gl->gl_demote_state = LM_ST_EXCLUSIVE; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 833 | gl->gl_ops = glops; |
Thomas Gleixner | 8b0e195 | 2016-12-25 12:30:41 +0100 | [diff] [blame] | 834 | gl->gl_dstamp = 0; |
Steven Whitehouse | a245769 | 2012-01-20 10:38:36 +0000 | [diff] [blame] | 835 | preempt_disable(); |
| 836 | /* We use the global stats to estimate the initial per-glock stats */ |
| 837 | gl->gl_stats = this_cpu_ptr(sdp->sd_lkstats)->lkstats[glops->go_type]; |
| 838 | preempt_enable(); |
| 839 | gl->gl_stats.stats[GFS2_LKS_DCOUNT] = 0; |
| 840 | gl->gl_stats.stats[GFS2_LKS_QCOUNT] = 0; |
Benjamin Marzinski | c4f68a1 | 2007-08-23 13:19:05 -0500 | [diff] [blame] | 841 | gl->gl_tchange = jiffies; |
Steven Whitehouse | ec45d9f | 2006-08-30 10:36:52 -0400 | [diff] [blame] | 842 | gl->gl_object = NULL; |
Bob Peterson | 7cf8dcd | 2011-06-15 11:41:48 -0400 | [diff] [blame] | 843 | gl->gl_hold_time = GL_GLOCK_DFT_HOLD; |
Benjamin Marzinski | c4f68a1 | 2007-08-23 13:19:05 -0500 | [diff] [blame] | 844 | INIT_DELAYED_WORK(&gl->gl_work, glock_work_func); |
Benjamin Marzinski | b94a170 | 2009-07-23 18:52:34 -0500 | [diff] [blame] | 845 | INIT_WORK(&gl->gl_delete, delete_work_func); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 846 | |
Steven Whitehouse | 009d851 | 2009-12-08 12:12:13 +0000 | [diff] [blame] | 847 | mapping = gfs2_glock2aspace(gl); |
| 848 | if (mapping) { |
| 849 | mapping->a_ops = &gfs2_meta_aops; |
| 850 | mapping->host = s->s_bdev->bd_inode; |
| 851 | mapping->flags = 0; |
| 852 | mapping_set_gfp_mask(mapping, GFP_NOFS); |
Rafael Aquini | 252aa6f | 2012-12-11 16:02:35 -0800 | [diff] [blame] | 853 | mapping->private_data = NULL; |
Steven Whitehouse | 009d851 | 2009-12-08 12:12:13 +0000 | [diff] [blame] | 854 | mapping->writeback_index = 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 855 | } |
| 856 | |
Andreas Gruenbacher | 0515480 | 2017-08-01 11:18:26 -0500 | [diff] [blame] | 857 | tmp = find_insert_glock(&name, gl); |
Andreas Gruenbacher | 0a52aba | 2017-02-21 23:19:10 +0100 | [diff] [blame] | 858 | if (!tmp) { |
Bob Peterson | 88ffbf3 | 2015-03-16 11:02:46 -0500 | [diff] [blame] | 859 | *glp = gl; |
Andreas Gruenbacher | 0a52aba | 2017-02-21 23:19:10 +0100 | [diff] [blame] | 860 | goto out; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 861 | } |
Andreas Gruenbacher | 0a52aba | 2017-02-21 23:19:10 +0100 | [diff] [blame] | 862 | if (IS_ERR(tmp)) { |
| 863 | ret = PTR_ERR(tmp); |
| 864 | goto out_free; |
| 865 | } |
Andreas Gruenbacher | 0515480 | 2017-08-01 11:18:26 -0500 | [diff] [blame] | 866 | *glp = tmp; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 867 | |
Andreas Gruenbacher | 0a52aba | 2017-02-21 23:19:10 +0100 | [diff] [blame] | 868 | out_free: |
Bob Peterson | 88ffbf3 | 2015-03-16 11:02:46 -0500 | [diff] [blame] | 869 | kfree(gl->gl_lksb.sb_lvbptr); |
| 870 | kmem_cache_free(cachep, gl); |
| 871 | atomic_dec(&sdp->sd_glock_disposal); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 872 | |
Andreas Gruenbacher | 0a52aba | 2017-02-21 23:19:10 +0100 | [diff] [blame] | 873 | out: |
Bob Peterson | 88ffbf3 | 2015-03-16 11:02:46 -0500 | [diff] [blame] | 874 | return ret; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | /** |
| 878 | * gfs2_holder_init - initialize a struct gfs2_holder in the default way |
| 879 | * @gl: the glock |
| 880 | * @state: the state we're requesting |
| 881 | * @flags: the modifier flags |
| 882 | * @gh: the holder structure |
| 883 | * |
| 884 | */ |
| 885 | |
Bob Peterson | b58bf40 | 2015-07-24 09:45:43 -0500 | [diff] [blame] | 886 | void gfs2_holder_init(struct gfs2_glock *gl, unsigned int state, u16 flags, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 887 | struct gfs2_holder *gh) |
| 888 | { |
| 889 | INIT_LIST_HEAD(&gh->gh_list); |
| 890 | gh->gh_gl = gl; |
Fabian Frederick | d29c0af | 2014-10-03 20:15:36 +0200 | [diff] [blame] | 891 | gh->gh_ip = _RET_IP_; |
Pavel Emelyanov | b1e058d | 2008-02-07 00:13:19 -0800 | [diff] [blame] | 892 | gh->gh_owner_pid = get_pid(task_pid(current)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 893 | gh->gh_state = state; |
| 894 | gh->gh_flags = flags; |
| 895 | gh->gh_error = 0; |
| 896 | gh->gh_iflags = 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 897 | gfs2_glock_hold(gl); |
| 898 | } |
| 899 | |
| 900 | /** |
| 901 | * gfs2_holder_reinit - reinitialize a struct gfs2_holder so we can requeue it |
| 902 | * @state: the state we're requesting |
| 903 | * @flags: the modifier flags |
| 904 | * @gh: the holder structure |
| 905 | * |
| 906 | * Don't mess with the glock. |
| 907 | * |
| 908 | */ |
| 909 | |
Bob Peterson | b58bf40 | 2015-07-24 09:45:43 -0500 | [diff] [blame] | 910 | void gfs2_holder_reinit(unsigned int state, u16 flags, struct gfs2_holder *gh) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 911 | { |
| 912 | gh->gh_state = state; |
Steven Whitehouse | 579b78a | 2006-04-26 14:58:26 -0400 | [diff] [blame] | 913 | gh->gh_flags = flags; |
Steven Whitehouse | 3b8249f | 2007-03-16 09:40:31 +0000 | [diff] [blame] | 914 | gh->gh_iflags = 0; |
Fabian Frederick | d29c0af | 2014-10-03 20:15:36 +0200 | [diff] [blame] | 915 | gh->gh_ip = _RET_IP_; |
Markus Elfring | 30badc9 | 2014-11-18 11:31:23 +0100 | [diff] [blame] | 916 | put_pid(gh->gh_owner_pid); |
Bob Peterson | 1a0eae8 | 2010-04-14 11:58:16 -0400 | [diff] [blame] | 917 | gh->gh_owner_pid = get_pid(task_pid(current)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | /** |
| 921 | * gfs2_holder_uninit - uninitialize a holder structure (drop glock reference) |
| 922 | * @gh: the holder structure |
| 923 | * |
| 924 | */ |
| 925 | |
| 926 | void gfs2_holder_uninit(struct gfs2_holder *gh) |
| 927 | { |
Pavel Emelyanov | b1e058d | 2008-02-07 00:13:19 -0800 | [diff] [blame] | 928 | put_pid(gh->gh_owner_pid); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 929 | gfs2_glock_put(gh->gh_gl); |
Andreas Gruenbacher | 6df9f9a | 2016-06-17 07:31:27 -0500 | [diff] [blame] | 930 | gfs2_holder_mark_uninitialized(gh); |
Steven Whitehouse | d0dc80d | 2006-03-29 14:36:49 -0500 | [diff] [blame] | 931 | gh->gh_ip = 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 932 | } |
| 933 | |
Steven Whitehouse | fe64d51 | 2009-05-19 10:01:18 +0100 | [diff] [blame] | 934 | /** |
Bob Peterson | 07a7904 | 2012-08-09 12:48:44 -0500 | [diff] [blame] | 935 | * gfs2_glock_wait - wait on a glock acquisition |
| 936 | * @gh: the glock holder |
| 937 | * |
| 938 | * Returns: 0 on success |
| 939 | */ |
| 940 | |
| 941 | int gfs2_glock_wait(struct gfs2_holder *gh) |
Steven Whitehouse | fee852e | 2007-01-17 15:33:23 +0000 | [diff] [blame] | 942 | { |
Bob Peterson | 7cf8dcd | 2011-06-15 11:41:48 -0400 | [diff] [blame] | 943 | unsigned long time1 = jiffies; |
| 944 | |
Steven Whitehouse | fee852e | 2007-01-17 15:33:23 +0000 | [diff] [blame] | 945 | might_sleep(); |
NeilBrown | 7431620 | 2014-07-07 15:16:04 +1000 | [diff] [blame] | 946 | wait_on_bit(&gh->gh_iflags, HIF_WAIT, TASK_UNINTERRUPTIBLE); |
Bob Peterson | 7cf8dcd | 2011-06-15 11:41:48 -0400 | [diff] [blame] | 947 | if (time_after(jiffies, time1 + HZ)) /* have we waited > a second? */ |
| 948 | /* Lengthen the minimum hold time. */ |
| 949 | gh->gh_gl->gl_hold_time = min(gh->gh_gl->gl_hold_time + |
| 950 | GL_GLOCK_HOLD_INCR, |
| 951 | GL_GLOCK_MAX_HOLD); |
Bob Peterson | 07a7904 | 2012-08-09 12:48:44 -0500 | [diff] [blame] | 952 | return gh->gh_error; |
Abhijith Das | d93cfa9 | 2007-06-11 08:22:32 +0100 | [diff] [blame] | 953 | } |
| 954 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 955 | /** |
Steven Whitehouse | 3b8249f | 2007-03-16 09:40:31 +0000 | [diff] [blame] | 956 | * handle_callback - process a demote request |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 957 | * @gl: the glock |
| 958 | * @state: the state the caller wants us to change to |
| 959 | * |
Steven Whitehouse | 3b8249f | 2007-03-16 09:40:31 +0000 | [diff] [blame] | 960 | * There are only two requests that we are going to see in actual |
| 961 | * practise: LM_ST_SHARED and LM_ST_UNLOCKED |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 962 | */ |
| 963 | |
Benjamin Marzinski | c4f68a1 | 2007-08-23 13:19:05 -0500 | [diff] [blame] | 964 | static void handle_callback(struct gfs2_glock *gl, unsigned int state, |
Steven Whitehouse | 81ffbf6 | 2013-04-10 10:26:55 +0100 | [diff] [blame] | 965 | unsigned long delay, bool remote) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 966 | { |
Benjamin Marzinski | c4f68a1 | 2007-08-23 13:19:05 -0500 | [diff] [blame] | 967 | int bit = delay ? GLF_PENDING_DEMOTE : GLF_DEMOTE; |
| 968 | |
Benjamin Marzinski | c4f68a1 | 2007-08-23 13:19:05 -0500 | [diff] [blame] | 969 | set_bit(bit, &gl->gl_flags); |
| 970 | if (gl->gl_demote_state == LM_ST_EXCLUSIVE) { |
Steven Whitehouse | 3b8249f | 2007-03-16 09:40:31 +0000 | [diff] [blame] | 971 | gl->gl_demote_state = state; |
| 972 | gl->gl_demote_time = jiffies; |
Josef Whiter | 26caee5 | 2007-07-23 10:02:40 +0100 | [diff] [blame] | 973 | } else if (gl->gl_demote_state != LM_ST_UNLOCKED && |
| 974 | gl->gl_demote_state != state) { |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 975 | gl->gl_demote_state = LM_ST_UNLOCKED; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 976 | } |
Benjamin Marzinski | b94a170 | 2009-07-23 18:52:34 -0500 | [diff] [blame] | 977 | if (gl->gl_ops->go_callback) |
Steven Whitehouse | 81ffbf6 | 2013-04-10 10:26:55 +0100 | [diff] [blame] | 978 | gl->gl_ops->go_callback(gl, remote); |
Steven Whitehouse | 7bd8b2e | 2013-04-10 10:32:05 +0100 | [diff] [blame] | 979 | trace_gfs2_demote_rq(gl, remote); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 980 | } |
| 981 | |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 982 | void gfs2_print_dbg(struct seq_file *seq, const char *fmt, ...) |
Robert Peterson | 7c52b16 | 2007-03-16 10:26:37 +0000 | [diff] [blame] | 983 | { |
Joe Perches | 5e69069 | 2010-11-09 16:35:20 -0800 | [diff] [blame] | 984 | struct va_format vaf; |
Robert Peterson | 7c52b16 | 2007-03-16 10:26:37 +0000 | [diff] [blame] | 985 | va_list args; |
| 986 | |
| 987 | va_start(args, fmt); |
Joe Perches | 5e69069 | 2010-11-09 16:35:20 -0800 | [diff] [blame] | 988 | |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 989 | if (seq) { |
Steven Whitehouse | 1bb4930 | 2012-06-11 13:26:50 +0100 | [diff] [blame] | 990 | seq_vprintf(seq, fmt, args); |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 991 | } else { |
Joe Perches | 5e69069 | 2010-11-09 16:35:20 -0800 | [diff] [blame] | 992 | vaf.fmt = fmt; |
| 993 | vaf.va = &args; |
| 994 | |
Joe Perches | d77d1b5 | 2014-03-06 12:10:45 -0800 | [diff] [blame] | 995 | pr_err("%pV", &vaf); |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 996 | } |
Joe Perches | 5e69069 | 2010-11-09 16:35:20 -0800 | [diff] [blame] | 997 | |
Robert Peterson | 7c52b16 | 2007-03-16 10:26:37 +0000 | [diff] [blame] | 998 | va_end(args); |
| 999 | } |
| 1000 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1001 | /** |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1002 | * add_to_queue - Add a holder to the wait queue (but look for recursion) |
| 1003 | * @gh: the holder structure to add |
| 1004 | * |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1005 | * Eventually we should move the recursive locking trap to a |
| 1006 | * debugging option or something like that. This is the fast |
| 1007 | * path and needs to have the minimum number of distractions. |
| 1008 | * |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1009 | */ |
| 1010 | |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1011 | static inline void add_to_queue(struct gfs2_holder *gh) |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 1012 | __releases(&gl->gl_lockref.lock) |
| 1013 | __acquires(&gl->gl_lockref.lock) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1014 | { |
| 1015 | struct gfs2_glock *gl = gh->gh_gl; |
Bob Peterson | 15562c4 | 2015-03-16 11:52:05 -0500 | [diff] [blame] | 1016 | struct gfs2_sbd *sdp = gl->gl_name.ln_sbd; |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1017 | struct list_head *insert_pt = NULL; |
| 1018 | struct gfs2_holder *gh2; |
Bob Peterson | e5dc76b | 2012-08-09 12:48:46 -0500 | [diff] [blame] | 1019 | int try_futile = 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1020 | |
Pavel Emelyanov | b1e058d | 2008-02-07 00:13:19 -0800 | [diff] [blame] | 1021 | BUG_ON(gh->gh_owner_pid == NULL); |
Steven Whitehouse | fee852e | 2007-01-17 15:33:23 +0000 | [diff] [blame] | 1022 | if (test_and_set_bit(HIF_WAIT, &gh->gh_iflags)) |
| 1023 | BUG(); |
Steven Whitehouse | 190562b | 2006-04-20 16:57:23 -0400 | [diff] [blame] | 1024 | |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1025 | if (gh->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB)) { |
| 1026 | if (test_bit(GLF_LOCK, &gl->gl_flags)) |
Bob Peterson | e5dc76b | 2012-08-09 12:48:46 -0500 | [diff] [blame] | 1027 | try_futile = !may_grant(gl, gh); |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1028 | if (test_bit(GLF_INVALIDATE_IN_PROGRESS, &gl->gl_flags)) |
| 1029 | goto fail; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1030 | } |
| 1031 | |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1032 | list_for_each_entry(gh2, &gl->gl_holders, gh_list) { |
| 1033 | if (unlikely(gh2->gh_owner_pid == gh->gh_owner_pid && |
| 1034 | (gh->gh_gl->gl_ops->go_type != LM_TYPE_FLOCK))) |
| 1035 | goto trap_recursive; |
Bob Peterson | e5dc76b | 2012-08-09 12:48:46 -0500 | [diff] [blame] | 1036 | if (try_futile && |
| 1037 | !(gh2->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB))) { |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1038 | fail: |
| 1039 | gh->gh_error = GLR_TRYFAILED; |
| 1040 | gfs2_holder_wake(gh); |
| 1041 | return; |
| 1042 | } |
| 1043 | if (test_bit(HIF_HOLDER, &gh2->gh_iflags)) |
| 1044 | continue; |
| 1045 | if (unlikely((gh->gh_flags & LM_FLAG_PRIORITY) && !insert_pt)) |
| 1046 | insert_pt = &gh2->gh_list; |
| 1047 | } |
Steven Whitehouse | 7b5e3d5 | 2010-09-03 09:39:20 +0100 | [diff] [blame] | 1048 | set_bit(GLF_QUEUED, &gl->gl_flags); |
Steven Whitehouse | edae38a | 2011-01-31 09:38:12 +0000 | [diff] [blame] | 1049 | trace_gfs2_glock_queue(gh, 1); |
Steven Whitehouse | a245769 | 2012-01-20 10:38:36 +0000 | [diff] [blame] | 1050 | gfs2_glstats_inc(gl, GFS2_LKS_QCOUNT); |
| 1051 | gfs2_sbstats_inc(gl, GFS2_LKS_QCOUNT); |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1052 | if (likely(insert_pt == NULL)) { |
| 1053 | list_add_tail(&gh->gh_list, &gl->gl_holders); |
| 1054 | if (unlikely(gh->gh_flags & LM_FLAG_PRIORITY)) |
| 1055 | goto do_cancel; |
| 1056 | return; |
| 1057 | } |
| 1058 | list_add_tail(&gh->gh_list, insert_pt); |
| 1059 | do_cancel: |
| 1060 | gh = list_entry(gl->gl_holders.next, struct gfs2_holder, gh_list); |
| 1061 | if (!(gh->gh_flags & LM_FLAG_PRIORITY)) { |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 1062 | spin_unlock(&gl->gl_lockref.lock); |
Steven Whitehouse | 048bca2 | 2008-05-23 14:46:04 +0100 | [diff] [blame] | 1063 | if (sdp->sd_lockstruct.ls_ops->lm_cancel) |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 1064 | sdp->sd_lockstruct.ls_ops->lm_cancel(gl); |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 1065 | spin_lock(&gl->gl_lockref.lock); |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1066 | } |
| 1067 | return; |
| 1068 | |
| 1069 | trap_recursive: |
Bob Peterson | e54c78a | 2018-10-03 08:47:36 -0500 | [diff] [blame] | 1070 | fs_err(sdp, "original: %pSR\n", (void *)gh2->gh_ip); |
| 1071 | fs_err(sdp, "pid: %d\n", pid_nr(gh2->gh_owner_pid)); |
| 1072 | fs_err(sdp, "lock type: %d req lock state : %d\n", |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1073 | gh2->gh_gl->gl_name.ln_type, gh2->gh_state); |
Bob Peterson | e54c78a | 2018-10-03 08:47:36 -0500 | [diff] [blame] | 1074 | fs_err(sdp, "new: %pSR\n", (void *)gh->gh_ip); |
| 1075 | fs_err(sdp, "pid: %d\n", pid_nr(gh->gh_owner_pid)); |
| 1076 | fs_err(sdp, "lock type: %d req lock state : %d\n", |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1077 | gh->gh_gl->gl_name.ln_type, gh->gh_state); |
Steven Whitehouse | 8eae1ca0 | 2012-10-15 10:57:02 +0100 | [diff] [blame] | 1078 | gfs2_dump_glock(NULL, gl); |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1079 | BUG(); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1080 | } |
| 1081 | |
| 1082 | /** |
| 1083 | * gfs2_glock_nq - enqueue a struct gfs2_holder onto a glock (acquire a glock) |
| 1084 | * @gh: the holder structure |
| 1085 | * |
| 1086 | * if (gh->gh_flags & GL_ASYNC), this never returns an error |
| 1087 | * |
| 1088 | * Returns: 0, GLR_TRYFAILED, or errno on failure |
| 1089 | */ |
| 1090 | |
| 1091 | int gfs2_glock_nq(struct gfs2_holder *gh) |
| 1092 | { |
| 1093 | struct gfs2_glock *gl = gh->gh_gl; |
Bob Peterson | 15562c4 | 2015-03-16 11:52:05 -0500 | [diff] [blame] | 1094 | struct gfs2_sbd *sdp = gl->gl_name.ln_sbd; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1095 | int error = 0; |
| 1096 | |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1097 | if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1098 | return -EIO; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1099 | |
Steven Whitehouse | f42ab08 | 2011-04-14 16:50:31 +0100 | [diff] [blame] | 1100 | if (test_bit(GLF_LRU, &gl->gl_flags)) |
| 1101 | gfs2_glock_remove_from_lru(gl); |
| 1102 | |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 1103 | spin_lock(&gl->gl_lockref.lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1104 | add_to_queue(gh); |
Bob Peterson | 01b172b | 2014-03-12 10:32:20 -0400 | [diff] [blame] | 1105 | if (unlikely((LM_FLAG_NOEXP & gh->gh_flags) && |
| 1106 | test_and_clear_bit(GLF_FROZEN, &gl->gl_flags))) { |
Steven Whitehouse | 0809f6e | 2010-08-02 10:15:17 +0100 | [diff] [blame] | 1107 | set_bit(GLF_REPLY_PENDING, &gl->gl_flags); |
Bob Peterson | 01b172b | 2014-03-12 10:32:20 -0400 | [diff] [blame] | 1108 | gl->gl_lockref.count++; |
Andreas Gruenbacher | 6b0c744 | 2017-06-30 08:10:01 -0500 | [diff] [blame] | 1109 | __gfs2_glock_queue_work(gl, 0); |
Bob Peterson | 01b172b | 2014-03-12 10:32:20 -0400 | [diff] [blame] | 1110 | } |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1111 | run_queue(gl, 1); |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 1112 | spin_unlock(&gl->gl_lockref.lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1113 | |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1114 | if (!(gh->gh_flags & GL_ASYNC)) |
| 1115 | error = gfs2_glock_wait(gh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1116 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1117 | return error; |
| 1118 | } |
| 1119 | |
| 1120 | /** |
| 1121 | * gfs2_glock_poll - poll to see if an async request has been completed |
| 1122 | * @gh: the holder |
| 1123 | * |
| 1124 | * Returns: 1 if the request is ready to be gfs2_glock_wait()ed on |
| 1125 | */ |
| 1126 | |
| 1127 | int gfs2_glock_poll(struct gfs2_holder *gh) |
| 1128 | { |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1129 | return test_bit(HIF_WAIT, &gh->gh_iflags) ? 0 : 1; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | /** |
| 1133 | * gfs2_glock_dq - dequeue a struct gfs2_holder from a glock (release a glock) |
| 1134 | * @gh: the glock holder |
| 1135 | * |
| 1136 | */ |
| 1137 | |
| 1138 | void gfs2_glock_dq(struct gfs2_holder *gh) |
| 1139 | { |
| 1140 | struct gfs2_glock *gl = gh->gh_gl; |
Steven Whitehouse | 8fb4b53 | 2006-08-30 09:30:00 -0400 | [diff] [blame] | 1141 | const struct gfs2_glock_operations *glops = gl->gl_ops; |
Benjamin Marzinski | c4f68a1 | 2007-08-23 13:19:05 -0500 | [diff] [blame] | 1142 | unsigned delay = 0; |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1143 | int fast_path = 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1144 | |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 1145 | spin_lock(&gl->gl_lockref.lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1146 | if (gh->gh_flags & GL_NOCACHE) |
Steven Whitehouse | 81ffbf6 | 2013-04-10 10:26:55 +0100 | [diff] [blame] | 1147 | handle_callback(gl, LM_ST_UNLOCKED, 0, false); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1148 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1149 | list_del_init(&gh->gh_list); |
Bob Peterson | 7508abc | 2015-12-18 11:54:55 -0600 | [diff] [blame] | 1150 | clear_bit(HIF_HOLDER, &gh->gh_iflags); |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1151 | if (find_first_holder(gl) == NULL) { |
Steven Whitehouse | 3042a2cc | 2007-11-02 08:39:34 +0000 | [diff] [blame] | 1152 | if (glops->go_unlock) { |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1153 | GLOCK_BUG_ON(gl, test_and_set_bit(GLF_LOCK, &gl->gl_flags)); |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 1154 | spin_unlock(&gl->gl_lockref.lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1155 | glops->go_unlock(gh); |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 1156 | spin_lock(&gl->gl_lockref.lock); |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1157 | clear_bit(GLF_LOCK, &gl->gl_flags); |
Steven Whitehouse | 3042a2cc | 2007-11-02 08:39:34 +0000 | [diff] [blame] | 1158 | } |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1159 | if (list_empty(&gl->gl_holders) && |
| 1160 | !test_bit(GLF_PENDING_DEMOTE, &gl->gl_flags) && |
| 1161 | !test_bit(GLF_DEMOTE, &gl->gl_flags)) |
| 1162 | fast_path = 1; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1163 | } |
Ross Lagerwall | 7881ef3 | 2019-03-27 17:09:17 +0000 | [diff] [blame] | 1164 | if (!test_bit(GLF_LFLUSH, &gl->gl_flags) && demote_ok(gl)) |
Bob Peterson | 4abb6ad9 | 2012-08-09 12:48:43 -0500 | [diff] [blame] | 1165 | gfs2_glock_add_to_lru(gl); |
| 1166 | |
Steven Whitehouse | 6399777 | 2009-06-12 08:49:20 +0100 | [diff] [blame] | 1167 | trace_gfs2_glock_queue(gh, 0); |
Andreas Gruenbacher | 6b0c744 | 2017-06-30 08:10:01 -0500 | [diff] [blame] | 1168 | if (unlikely(!fast_path)) { |
| 1169 | gl->gl_lockref.count++; |
| 1170 | if (test_bit(GLF_PENDING_DEMOTE, &gl->gl_flags) && |
| 1171 | !test_bit(GLF_DEMOTE, &gl->gl_flags) && |
| 1172 | gl->gl_name.ln_type == LM_TYPE_INODE) |
| 1173 | delay = gl->gl_hold_time; |
| 1174 | __gfs2_glock_queue_work(gl, delay); |
| 1175 | } |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 1176 | spin_unlock(&gl->gl_lockref.lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1177 | } |
| 1178 | |
Abhijith Das | d93cfa9 | 2007-06-11 08:22:32 +0100 | [diff] [blame] | 1179 | void gfs2_glock_dq_wait(struct gfs2_holder *gh) |
| 1180 | { |
| 1181 | struct gfs2_glock *gl = gh->gh_gl; |
| 1182 | gfs2_glock_dq(gh); |
Bob Peterson | 81e1d45 | 2012-08-09 12:48:45 -0500 | [diff] [blame] | 1183 | might_sleep(); |
NeilBrown | 7431620 | 2014-07-07 15:16:04 +1000 | [diff] [blame] | 1184 | wait_on_bit(&gl->gl_flags, GLF_DEMOTE, TASK_UNINTERRUPTIBLE); |
Abhijith Das | d93cfa9 | 2007-06-11 08:22:32 +0100 | [diff] [blame] | 1185 | } |
| 1186 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1187 | /** |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1188 | * gfs2_glock_dq_uninit - dequeue a holder from a glock and initialize it |
| 1189 | * @gh: the holder structure |
| 1190 | * |
| 1191 | */ |
| 1192 | |
| 1193 | void gfs2_glock_dq_uninit(struct gfs2_holder *gh) |
| 1194 | { |
| 1195 | gfs2_glock_dq(gh); |
| 1196 | gfs2_holder_uninit(gh); |
| 1197 | } |
| 1198 | |
| 1199 | /** |
| 1200 | * gfs2_glock_nq_num - acquire a glock based on lock number |
| 1201 | * @sdp: the filesystem |
| 1202 | * @number: the lock number |
| 1203 | * @glops: the glock operations for the type of glock |
| 1204 | * @state: the state to acquire the glock in |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1205 | * @flags: modifier flags for the acquisition |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1206 | * @gh: the struct gfs2_holder |
| 1207 | * |
| 1208 | * Returns: errno |
| 1209 | */ |
| 1210 | |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 1211 | int gfs2_glock_nq_num(struct gfs2_sbd *sdp, u64 number, |
Steven Whitehouse | 8fb4b53 | 2006-08-30 09:30:00 -0400 | [diff] [blame] | 1212 | const struct gfs2_glock_operations *glops, |
Bob Peterson | b58bf40 | 2015-07-24 09:45:43 -0500 | [diff] [blame] | 1213 | unsigned int state, u16 flags, struct gfs2_holder *gh) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1214 | { |
| 1215 | struct gfs2_glock *gl; |
| 1216 | int error; |
| 1217 | |
| 1218 | error = gfs2_glock_get(sdp, number, glops, CREATE, &gl); |
| 1219 | if (!error) { |
| 1220 | error = gfs2_glock_nq_init(gl, state, flags, gh); |
| 1221 | gfs2_glock_put(gl); |
| 1222 | } |
| 1223 | |
| 1224 | return error; |
| 1225 | } |
| 1226 | |
| 1227 | /** |
| 1228 | * glock_compare - Compare two struct gfs2_glock structures for sorting |
| 1229 | * @arg_a: the first structure |
| 1230 | * @arg_b: the second structure |
| 1231 | * |
| 1232 | */ |
| 1233 | |
| 1234 | static int glock_compare(const void *arg_a, const void *arg_b) |
| 1235 | { |
Steven Whitehouse | a5e08a9e | 2006-09-09 17:07:05 -0400 | [diff] [blame] | 1236 | const struct gfs2_holder *gh_a = *(const struct gfs2_holder **)arg_a; |
| 1237 | const struct gfs2_holder *gh_b = *(const struct gfs2_holder **)arg_b; |
| 1238 | const struct lm_lockname *a = &gh_a->gh_gl->gl_name; |
| 1239 | const struct lm_lockname *b = &gh_b->gh_gl->gl_name; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1240 | |
| 1241 | if (a->ln_number > b->ln_number) |
Steven Whitehouse | a5e08a9e | 2006-09-09 17:07:05 -0400 | [diff] [blame] | 1242 | return 1; |
| 1243 | if (a->ln_number < b->ln_number) |
| 1244 | return -1; |
Steven Whitehouse | 1c0f487 | 2007-01-22 12:10:39 -0500 | [diff] [blame] | 1245 | BUG_ON(gh_a->gh_gl->gl_ops->go_type == gh_b->gh_gl->gl_ops->go_type); |
Steven Whitehouse | a5e08a9e | 2006-09-09 17:07:05 -0400 | [diff] [blame] | 1246 | return 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1247 | } |
| 1248 | |
| 1249 | /** |
| 1250 | * nq_m_sync - synchonously acquire more than one glock in deadlock free order |
| 1251 | * @num_gh: the number of structures |
| 1252 | * @ghs: an array of struct gfs2_holder structures |
| 1253 | * |
| 1254 | * Returns: 0 on success (all glocks acquired), |
| 1255 | * errno on failure (no glocks acquired) |
| 1256 | */ |
| 1257 | |
| 1258 | static int nq_m_sync(unsigned int num_gh, struct gfs2_holder *ghs, |
| 1259 | struct gfs2_holder **p) |
| 1260 | { |
| 1261 | unsigned int x; |
| 1262 | int error = 0; |
| 1263 | |
| 1264 | for (x = 0; x < num_gh; x++) |
| 1265 | p[x] = &ghs[x]; |
| 1266 | |
| 1267 | sort(p, num_gh, sizeof(struct gfs2_holder *), glock_compare, NULL); |
| 1268 | |
| 1269 | for (x = 0; x < num_gh; x++) { |
| 1270 | p[x]->gh_flags &= ~(LM_FLAG_TRY | GL_ASYNC); |
| 1271 | |
| 1272 | error = gfs2_glock_nq(p[x]); |
| 1273 | if (error) { |
| 1274 | while (x--) |
| 1275 | gfs2_glock_dq(p[x]); |
| 1276 | break; |
| 1277 | } |
| 1278 | } |
| 1279 | |
| 1280 | return error; |
| 1281 | } |
| 1282 | |
| 1283 | /** |
| 1284 | * gfs2_glock_nq_m - acquire multiple glocks |
| 1285 | * @num_gh: the number of structures |
| 1286 | * @ghs: an array of struct gfs2_holder structures |
| 1287 | * |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1288 | * |
| 1289 | * Returns: 0 on success (all glocks acquired), |
| 1290 | * errno on failure (no glocks acquired) |
| 1291 | */ |
| 1292 | |
| 1293 | int gfs2_glock_nq_m(unsigned int num_gh, struct gfs2_holder *ghs) |
| 1294 | { |
Steven Whitehouse | eaf5bd3 | 2007-06-19 15:38:17 +0100 | [diff] [blame] | 1295 | struct gfs2_holder *tmp[4]; |
| 1296 | struct gfs2_holder **pph = tmp; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1297 | int error = 0; |
| 1298 | |
Steven Whitehouse | eaf5bd3 | 2007-06-19 15:38:17 +0100 | [diff] [blame] | 1299 | switch(num_gh) { |
| 1300 | case 0: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1301 | return 0; |
Steven Whitehouse | eaf5bd3 | 2007-06-19 15:38:17 +0100 | [diff] [blame] | 1302 | case 1: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1303 | ghs->gh_flags &= ~(LM_FLAG_TRY | GL_ASYNC); |
| 1304 | return gfs2_glock_nq(ghs); |
Steven Whitehouse | eaf5bd3 | 2007-06-19 15:38:17 +0100 | [diff] [blame] | 1305 | default: |
| 1306 | if (num_gh <= 4) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1307 | break; |
Kees Cook | 6da2ec5 | 2018-06-12 13:55:00 -0700 | [diff] [blame] | 1308 | pph = kmalloc_array(num_gh, sizeof(struct gfs2_holder *), |
| 1309 | GFP_NOFS); |
Steven Whitehouse | eaf5bd3 | 2007-06-19 15:38:17 +0100 | [diff] [blame] | 1310 | if (!pph) |
| 1311 | return -ENOMEM; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1312 | } |
| 1313 | |
Steven Whitehouse | eaf5bd3 | 2007-06-19 15:38:17 +0100 | [diff] [blame] | 1314 | error = nq_m_sync(num_gh, ghs, pph); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1315 | |
Steven Whitehouse | eaf5bd3 | 2007-06-19 15:38:17 +0100 | [diff] [blame] | 1316 | if (pph != tmp) |
| 1317 | kfree(pph); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1318 | |
| 1319 | return error; |
| 1320 | } |
| 1321 | |
| 1322 | /** |
| 1323 | * gfs2_glock_dq_m - release multiple glocks |
| 1324 | * @num_gh: the number of structures |
| 1325 | * @ghs: an array of struct gfs2_holder structures |
| 1326 | * |
| 1327 | */ |
| 1328 | |
| 1329 | void gfs2_glock_dq_m(unsigned int num_gh, struct gfs2_holder *ghs) |
| 1330 | { |
Bob Peterson | fa1bbde | 2011-03-10 11:41:57 -0500 | [diff] [blame] | 1331 | while (num_gh--) |
| 1332 | gfs2_glock_dq(&ghs[num_gh]); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1333 | } |
| 1334 | |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 1335 | void gfs2_glock_cb(struct gfs2_glock *gl, unsigned int state) |
Steven Whitehouse | da755fd | 2008-01-30 15:34:04 +0000 | [diff] [blame] | 1336 | { |
Benjamin Marzinski | c4f68a1 | 2007-08-23 13:19:05 -0500 | [diff] [blame] | 1337 | unsigned long delay = 0; |
| 1338 | unsigned long holdtime; |
| 1339 | unsigned long now = jiffies; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1340 | |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 1341 | gfs2_glock_hold(gl); |
Bob Peterson | 7cf8dcd | 2011-06-15 11:41:48 -0400 | [diff] [blame] | 1342 | holdtime = gl->gl_tchange + gl->gl_hold_time; |
| 1343 | if (test_bit(GLF_QUEUED, &gl->gl_flags) && |
| 1344 | gl->gl_name.ln_type == LM_TYPE_INODE) { |
Steven Whitehouse | 7b5e3d5 | 2010-09-03 09:39:20 +0100 | [diff] [blame] | 1345 | if (time_before(now, holdtime)) |
| 1346 | delay = holdtime - now; |
| 1347 | if (test_bit(GLF_REPLY_PENDING, &gl->gl_flags)) |
Bob Peterson | 7cf8dcd | 2011-06-15 11:41:48 -0400 | [diff] [blame] | 1348 | delay = gl->gl_hold_time; |
Steven Whitehouse | 7b5e3d5 | 2010-09-03 09:39:20 +0100 | [diff] [blame] | 1349 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1350 | |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 1351 | spin_lock(&gl->gl_lockref.lock); |
Steven Whitehouse | 81ffbf6 | 2013-04-10 10:26:55 +0100 | [diff] [blame] | 1352 | handle_callback(gl, state, delay, true); |
Andreas Gruenbacher | 6b0c744 | 2017-06-30 08:10:01 -0500 | [diff] [blame] | 1353 | __gfs2_glock_queue_work(gl, delay); |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 1354 | spin_unlock(&gl->gl_lockref.lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1355 | } |
| 1356 | |
| 1357 | /** |
Steven Whitehouse | 0809f6e | 2010-08-02 10:15:17 +0100 | [diff] [blame] | 1358 | * gfs2_should_freeze - Figure out if glock should be frozen |
| 1359 | * @gl: The glock in question |
| 1360 | * |
| 1361 | * Glocks are not frozen if (a) the result of the dlm operation is |
| 1362 | * an error, (b) the locking operation was an unlock operation or |
| 1363 | * (c) if there is a "noexp" flagged request anywhere in the queue |
| 1364 | * |
| 1365 | * Returns: 1 if freezing should occur, 0 otherwise |
| 1366 | */ |
| 1367 | |
| 1368 | static int gfs2_should_freeze(const struct gfs2_glock *gl) |
| 1369 | { |
| 1370 | const struct gfs2_holder *gh; |
| 1371 | |
| 1372 | if (gl->gl_reply & ~LM_OUT_ST_MASK) |
| 1373 | return 0; |
| 1374 | if (gl->gl_target == LM_ST_UNLOCKED) |
| 1375 | return 0; |
| 1376 | |
| 1377 | list_for_each_entry(gh, &gl->gl_holders, gh_list) { |
| 1378 | if (test_bit(HIF_HOLDER, &gh->gh_iflags)) |
| 1379 | continue; |
| 1380 | if (LM_FLAG_NOEXP & gh->gh_flags) |
| 1381 | return 0; |
| 1382 | } |
| 1383 | |
| 1384 | return 1; |
| 1385 | } |
| 1386 | |
| 1387 | /** |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 1388 | * gfs2_glock_complete - Callback used by locking |
| 1389 | * @gl: Pointer to the glock |
| 1390 | * @ret: The return value from the dlm |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1391 | * |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 1392 | * The gl_reply field is under the gl_lockref.lock lock so that it is ok |
Steven Whitehouse | 47a2538 | 2010-11-30 15:49:31 +0000 | [diff] [blame] | 1393 | * to use a bitfield shared with other glock state fields. |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1394 | */ |
| 1395 | |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 1396 | void gfs2_glock_complete(struct gfs2_glock *gl, int ret) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1397 | { |
Bob Peterson | 15562c4 | 2015-03-16 11:52:05 -0500 | [diff] [blame] | 1398 | struct lm_lockstruct *ls = &gl->gl_name.ln_sbd->sd_lockstruct; |
Steven Whitehouse | 0809f6e | 2010-08-02 10:15:17 +0100 | [diff] [blame] | 1399 | |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 1400 | spin_lock(&gl->gl_lockref.lock); |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 1401 | gl->gl_reply = ret; |
Steven Whitehouse | 0809f6e | 2010-08-02 10:15:17 +0100 | [diff] [blame] | 1402 | |
David Teigland | e0c2a9a | 2012-01-09 17:18:05 -0500 | [diff] [blame] | 1403 | if (unlikely(test_bit(DFL_BLOCK_LOCKS, &ls->ls_recover_flags))) { |
Steven Whitehouse | 0809f6e | 2010-08-02 10:15:17 +0100 | [diff] [blame] | 1404 | if (gfs2_should_freeze(gl)) { |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 1405 | set_bit(GLF_FROZEN, &gl->gl_flags); |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 1406 | spin_unlock(&gl->gl_lockref.lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1407 | return; |
Steven Whitehouse | 0809f6e | 2010-08-02 10:15:17 +0100 | [diff] [blame] | 1408 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1409 | } |
Steven Whitehouse | 47a2538 | 2010-11-30 15:49:31 +0000 | [diff] [blame] | 1410 | |
Steven Whitehouse | e66cf16 | 2013-10-15 15:18:08 +0100 | [diff] [blame] | 1411 | gl->gl_lockref.count++; |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 1412 | set_bit(GLF_REPLY_PENDING, &gl->gl_flags); |
Andreas Gruenbacher | 6b0c744 | 2017-06-30 08:10:01 -0500 | [diff] [blame] | 1413 | __gfs2_glock_queue_work(gl, 0); |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 1414 | spin_unlock(&gl->gl_lockref.lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1415 | } |
| 1416 | |
Steven Whitehouse | 4506a519 | 2013-02-01 20:36:03 +0000 | [diff] [blame] | 1417 | static int glock_cmp(void *priv, struct list_head *a, struct list_head *b) |
| 1418 | { |
| 1419 | struct gfs2_glock *gla, *glb; |
| 1420 | |
| 1421 | gla = list_entry(a, struct gfs2_glock, gl_lru); |
| 1422 | glb = list_entry(b, struct gfs2_glock, gl_lru); |
| 1423 | |
| 1424 | if (gla->gl_name.ln_number > glb->gl_name.ln_number) |
| 1425 | return 1; |
| 1426 | if (gla->gl_name.ln_number < glb->gl_name.ln_number) |
| 1427 | return -1; |
| 1428 | |
| 1429 | return 0; |
| 1430 | } |
| 1431 | |
| 1432 | /** |
| 1433 | * gfs2_dispose_glock_lru - Demote a list of glocks |
| 1434 | * @list: The list to dispose of |
| 1435 | * |
| 1436 | * Disposing of glocks may involve disk accesses, so that here we sort |
| 1437 | * the glocks by number (i.e. disk location of the inodes) so that if |
| 1438 | * there are any such accesses, they'll be sent in order (mostly). |
| 1439 | * |
| 1440 | * Must be called under the lru_lock, but may drop and retake this |
| 1441 | * lock. While the lru_lock is dropped, entries may vanish from the |
| 1442 | * list, but no new entries will appear on the list (since it is |
| 1443 | * private) |
| 1444 | */ |
| 1445 | |
| 1446 | static void gfs2_dispose_glock_lru(struct list_head *list) |
| 1447 | __releases(&lru_lock) |
| 1448 | __acquires(&lru_lock) |
| 1449 | { |
| 1450 | struct gfs2_glock *gl; |
| 1451 | |
| 1452 | list_sort(NULL, list, glock_cmp); |
| 1453 | |
| 1454 | while(!list_empty(list)) { |
| 1455 | gl = list_entry(list->next, struct gfs2_glock, gl_lru); |
| 1456 | list_del_init(&gl->gl_lru); |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 1457 | if (!spin_trylock(&gl->gl_lockref.lock)) { |
Steven Whitehouse | 94a09a3 | 2014-06-23 14:43:32 +0100 | [diff] [blame] | 1458 | add_back_to_lru: |
Steven Whitehouse | e66cf16 | 2013-10-15 15:18:08 +0100 | [diff] [blame] | 1459 | list_add(&gl->gl_lru, &lru_list); |
Ross Lagerwall | 7881ef3 | 2019-03-27 17:09:17 +0000 | [diff] [blame] | 1460 | set_bit(GLF_LRU, &gl->gl_flags); |
Steven Whitehouse | e66cf16 | 2013-10-15 15:18:08 +0100 | [diff] [blame] | 1461 | atomic_inc(&lru_count); |
| 1462 | continue; |
| 1463 | } |
Steven Whitehouse | 94a09a3 | 2014-06-23 14:43:32 +0100 | [diff] [blame] | 1464 | if (test_and_set_bit(GLF_LOCK, &gl->gl_flags)) { |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 1465 | spin_unlock(&gl->gl_lockref.lock); |
Steven Whitehouse | 94a09a3 | 2014-06-23 14:43:32 +0100 | [diff] [blame] | 1466 | goto add_back_to_lru; |
| 1467 | } |
Steven Whitehouse | e66cf16 | 2013-10-15 15:18:08 +0100 | [diff] [blame] | 1468 | gl->gl_lockref.count++; |
Steven Whitehouse | 4506a519 | 2013-02-01 20:36:03 +0000 | [diff] [blame] | 1469 | if (demote_ok(gl)) |
Steven Whitehouse | 81ffbf6 | 2013-04-10 10:26:55 +0100 | [diff] [blame] | 1470 | handle_callback(gl, LM_ST_UNLOCKED, 0, false); |
Steven Whitehouse | 4506a519 | 2013-02-01 20:36:03 +0000 | [diff] [blame] | 1471 | WARN_ON(!test_and_clear_bit(GLF_LOCK, &gl->gl_flags)); |
Andreas Gruenbacher | 6b0c744 | 2017-06-30 08:10:01 -0500 | [diff] [blame] | 1472 | __gfs2_glock_queue_work(gl, 0); |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 1473 | spin_unlock(&gl->gl_lockref.lock); |
Steven Whitehouse | 94a09a3 | 2014-06-23 14:43:32 +0100 | [diff] [blame] | 1474 | cond_resched_lock(&lru_lock); |
Steven Whitehouse | 4506a519 | 2013-02-01 20:36:03 +0000 | [diff] [blame] | 1475 | } |
| 1476 | } |
| 1477 | |
Steven Whitehouse | 2a00585 | 2012-12-14 12:28:30 +0000 | [diff] [blame] | 1478 | /** |
| 1479 | * gfs2_scan_glock_lru - Scan the LRU looking for locks to demote |
| 1480 | * @nr: The number of entries to scan |
| 1481 | * |
Steven Whitehouse | 4506a519 | 2013-02-01 20:36:03 +0000 | [diff] [blame] | 1482 | * This function selects the entries on the LRU which are able to |
| 1483 | * be demoted, and then kicks off the process by calling |
| 1484 | * gfs2_dispose_glock_lru() above. |
Steven Whitehouse | 2a00585 | 2012-12-14 12:28:30 +0000 | [diff] [blame] | 1485 | */ |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1486 | |
Dave Chinner | 1ab6c49 | 2013-08-28 10:18:09 +1000 | [diff] [blame] | 1487 | static long gfs2_scan_glock_lru(int nr) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1488 | { |
| 1489 | struct gfs2_glock *gl; |
Steven Whitehouse | 97cc1025 | 2008-11-20 13:39:47 +0000 | [diff] [blame] | 1490 | LIST_HEAD(skipped); |
Steven Whitehouse | 4506a519 | 2013-02-01 20:36:03 +0000 | [diff] [blame] | 1491 | LIST_HEAD(dispose); |
Dave Chinner | 1ab6c49 | 2013-08-28 10:18:09 +1000 | [diff] [blame] | 1492 | long freed = 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1493 | |
Steven Whitehouse | 97cc1025 | 2008-11-20 13:39:47 +0000 | [diff] [blame] | 1494 | spin_lock(&lru_lock); |
Dave Chinner | 1ab6c49 | 2013-08-28 10:18:09 +1000 | [diff] [blame] | 1495 | while ((nr-- >= 0) && !list_empty(&lru_list)) { |
Steven Whitehouse | 97cc1025 | 2008-11-20 13:39:47 +0000 | [diff] [blame] | 1496 | gl = list_entry(lru_list.next, struct gfs2_glock, gl_lru); |
Steven Whitehouse | 97cc1025 | 2008-11-20 13:39:47 +0000 | [diff] [blame] | 1497 | |
| 1498 | /* Test for being demotable */ |
Steven Whitehouse | 94a09a3 | 2014-06-23 14:43:32 +0100 | [diff] [blame] | 1499 | if (!test_bit(GLF_LOCK, &gl->gl_flags)) { |
Steven Whitehouse | 4506a519 | 2013-02-01 20:36:03 +0000 | [diff] [blame] | 1500 | list_move(&gl->gl_lru, &dispose); |
| 1501 | atomic_dec(&lru_count); |
Ross Lagerwall | 7881ef3 | 2019-03-27 17:09:17 +0000 | [diff] [blame] | 1502 | clear_bit(GLF_LRU, &gl->gl_flags); |
Dave Chinner | 1ab6c49 | 2013-08-28 10:18:09 +1000 | [diff] [blame] | 1503 | freed++; |
Steven Whitehouse | 2163b1e | 2009-06-25 16:30:26 +0100 | [diff] [blame] | 1504 | continue; |
Steven Whitehouse | 97cc1025 | 2008-11-20 13:39:47 +0000 | [diff] [blame] | 1505 | } |
Steven Whitehouse | 4506a519 | 2013-02-01 20:36:03 +0000 | [diff] [blame] | 1506 | |
| 1507 | list_move(&gl->gl_lru, &skipped); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1508 | } |
Steven Whitehouse | 97cc1025 | 2008-11-20 13:39:47 +0000 | [diff] [blame] | 1509 | list_splice(&skipped, &lru_list); |
Steven Whitehouse | 4506a519 | 2013-02-01 20:36:03 +0000 | [diff] [blame] | 1510 | if (!list_empty(&dispose)) |
| 1511 | gfs2_dispose_glock_lru(&dispose); |
Steven Whitehouse | 97cc1025 | 2008-11-20 13:39:47 +0000 | [diff] [blame] | 1512 | spin_unlock(&lru_lock); |
Dave Chinner | 1ab6c49 | 2013-08-28 10:18:09 +1000 | [diff] [blame] | 1513 | |
| 1514 | return freed; |
Steven Whitehouse | 2a00585 | 2012-12-14 12:28:30 +0000 | [diff] [blame] | 1515 | } |
| 1516 | |
Dave Chinner | 1ab6c49 | 2013-08-28 10:18:09 +1000 | [diff] [blame] | 1517 | static unsigned long gfs2_glock_shrink_scan(struct shrinker *shrink, |
| 1518 | struct shrink_control *sc) |
Steven Whitehouse | 2a00585 | 2012-12-14 12:28:30 +0000 | [diff] [blame] | 1519 | { |
Dave Chinner | 1ab6c49 | 2013-08-28 10:18:09 +1000 | [diff] [blame] | 1520 | if (!(sc->gfp_mask & __GFP_FS)) |
| 1521 | return SHRINK_STOP; |
| 1522 | return gfs2_scan_glock_lru(sc->nr_to_scan); |
| 1523 | } |
Steven Whitehouse | 2a00585 | 2012-12-14 12:28:30 +0000 | [diff] [blame] | 1524 | |
Dave Chinner | 1ab6c49 | 2013-08-28 10:18:09 +1000 | [diff] [blame] | 1525 | static unsigned long gfs2_glock_shrink_count(struct shrinker *shrink, |
| 1526 | struct shrink_control *sc) |
| 1527 | { |
Glauber Costa | 55f841c | 2013-08-28 10:17:53 +1000 | [diff] [blame] | 1528 | return vfs_pressure_ratio(atomic_read(&lru_count)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1529 | } |
| 1530 | |
Steven Whitehouse | 97cc1025 | 2008-11-20 13:39:47 +0000 | [diff] [blame] | 1531 | static struct shrinker glock_shrinker = { |
Steven Whitehouse | 97cc1025 | 2008-11-20 13:39:47 +0000 | [diff] [blame] | 1532 | .seeks = DEFAULT_SEEKS, |
Dave Chinner | 1ab6c49 | 2013-08-28 10:18:09 +1000 | [diff] [blame] | 1533 | .count_objects = gfs2_glock_shrink_count, |
| 1534 | .scan_objects = gfs2_glock_shrink_scan, |
Steven Whitehouse | 97cc1025 | 2008-11-20 13:39:47 +0000 | [diff] [blame] | 1535 | }; |
| 1536 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1537 | /** |
| 1538 | * examine_bucket - Call a function for glock in a hash bucket |
| 1539 | * @examiner: the function |
| 1540 | * @sdp: the filesystem |
| 1541 | * @bucket: the bucket |
| 1542 | * |
Herbert Xu | 98687f4 | 2017-02-11 19:26:45 +0800 | [diff] [blame] | 1543 | * Note that the function can be called multiple times on the same |
| 1544 | * object. So the user must ensure that the function can cope with |
| 1545 | * that. |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1546 | */ |
| 1547 | |
Bob Peterson | 88ffbf3 | 2015-03-16 11:02:46 -0500 | [diff] [blame] | 1548 | static void glock_hash_walk(glock_examiner examiner, const struct gfs2_sbd *sdp) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1549 | { |
Steven Whitehouse | bc015cb | 2011-01-19 09:30:01 +0000 | [diff] [blame] | 1550 | struct gfs2_glock *gl; |
Herbert Xu | 98687f4 | 2017-02-11 19:26:45 +0800 | [diff] [blame] | 1551 | struct rhashtable_iter iter; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1552 | |
Herbert Xu | 98687f4 | 2017-02-11 19:26:45 +0800 | [diff] [blame] | 1553 | rhashtable_walk_enter(&gl_hash_table, &iter); |
| 1554 | |
| 1555 | do { |
Tom Herbert | 97a6ec4 | 2017-12-04 10:31:41 -0800 | [diff] [blame] | 1556 | rhashtable_walk_start(&iter); |
Herbert Xu | 98687f4 | 2017-02-11 19:26:45 +0800 | [diff] [blame] | 1557 | |
| 1558 | while ((gl = rhashtable_walk_next(&iter)) && !IS_ERR(gl)) |
Bob Peterson | 27c3b41 | 2017-08-18 09:15:13 -0500 | [diff] [blame] | 1559 | if (gl->gl_name.ln_sbd == sdp && |
Bob Peterson | 88ffbf3 | 2015-03-16 11:02:46 -0500 | [diff] [blame] | 1560 | lockref_get_not_dead(&gl->gl_lockref)) |
| 1561 | examiner(gl); |
Herbert Xu | 98687f4 | 2017-02-11 19:26:45 +0800 | [diff] [blame] | 1562 | |
| 1563 | rhashtable_walk_stop(&iter); |
| 1564 | } while (cond_resched(), gl == ERR_PTR(-EAGAIN)); |
| 1565 | |
| 1566 | rhashtable_walk_exit(&iter); |
Steven Whitehouse | bc015cb | 2011-01-19 09:30:01 +0000 | [diff] [blame] | 1567 | } |
| 1568 | |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 1569 | /** |
| 1570 | * thaw_glock - thaw out a glock which has an unprocessed reply waiting |
| 1571 | * @gl: The glock to thaw |
| 1572 | * |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 1573 | */ |
| 1574 | |
| 1575 | static void thaw_glock(struct gfs2_glock *gl) |
| 1576 | { |
Andreas Gruenbacher | 6b0c744 | 2017-06-30 08:10:01 -0500 | [diff] [blame] | 1577 | if (!test_and_clear_bit(GLF_FROZEN, &gl->gl_flags)) { |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 1578 | gfs2_glock_put(gl); |
Andreas Gruenbacher | 6b0c744 | 2017-06-30 08:10:01 -0500 | [diff] [blame] | 1579 | return; |
Steven Whitehouse | 7286b31 | 2013-08-20 09:35:09 +0100 | [diff] [blame] | 1580 | } |
Andreas Gruenbacher | 6b0c744 | 2017-06-30 08:10:01 -0500 | [diff] [blame] | 1581 | set_bit(GLF_REPLY_PENDING, &gl->gl_flags); |
| 1582 | gfs2_glock_queue_work(gl, 0); |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 1583 | } |
| 1584 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1585 | /** |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1586 | * clear_glock - look at a glock and see if we can free it from glock cache |
| 1587 | * @gl: the glock to look at |
| 1588 | * |
| 1589 | */ |
| 1590 | |
| 1591 | static void clear_glock(struct gfs2_glock *gl) |
| 1592 | { |
Steven Whitehouse | f42ab08 | 2011-04-14 16:50:31 +0100 | [diff] [blame] | 1593 | gfs2_glock_remove_from_lru(gl); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1594 | |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 1595 | spin_lock(&gl->gl_lockref.lock); |
Steven Whitehouse | c741c45 | 2010-09-29 14:20:52 +0100 | [diff] [blame] | 1596 | if (gl->gl_state != LM_ST_UNLOCKED) |
Steven Whitehouse | 81ffbf6 | 2013-04-10 10:26:55 +0100 | [diff] [blame] | 1597 | handle_callback(gl, LM_ST_UNLOCKED, 0, false); |
Andreas Gruenbacher | 6b0c744 | 2017-06-30 08:10:01 -0500 | [diff] [blame] | 1598 | __gfs2_glock_queue_work(gl, 0); |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 1599 | spin_unlock(&gl->gl_lockref.lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1600 | } |
| 1601 | |
| 1602 | /** |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 1603 | * gfs2_glock_thaw - Thaw any frozen glocks |
| 1604 | * @sdp: The super block |
| 1605 | * |
| 1606 | */ |
| 1607 | |
| 1608 | void gfs2_glock_thaw(struct gfs2_sbd *sdp) |
| 1609 | { |
Steven Whitehouse | bc015cb | 2011-01-19 09:30:01 +0000 | [diff] [blame] | 1610 | glock_hash_walk(thaw_glock, sdp); |
| 1611 | } |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 1612 | |
Steven Whitehouse | ac3beb6 | 2014-01-16 10:31:13 +0000 | [diff] [blame] | 1613 | static void dump_glock(struct seq_file *seq, struct gfs2_glock *gl) |
Steven Whitehouse | bc015cb | 2011-01-19 09:30:01 +0000 | [diff] [blame] | 1614 | { |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 1615 | spin_lock(&gl->gl_lockref.lock); |
Steven Whitehouse | ac3beb6 | 2014-01-16 10:31:13 +0000 | [diff] [blame] | 1616 | gfs2_dump_glock(seq, gl); |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 1617 | spin_unlock(&gl->gl_lockref.lock); |
Steven Whitehouse | bc015cb | 2011-01-19 09:30:01 +0000 | [diff] [blame] | 1618 | } |
| 1619 | |
| 1620 | static void dump_glock_func(struct gfs2_glock *gl) |
| 1621 | { |
| 1622 | dump_glock(NULL, gl); |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 1623 | } |
| 1624 | |
| 1625 | /** |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1626 | * gfs2_gl_hash_clear - Empty out the glock hash table |
| 1627 | * @sdp: the filesystem |
| 1628 | * @wait: wait until it's all gone |
| 1629 | * |
Steven Whitehouse | 1bdad60 | 2008-06-03 14:09:53 +0100 | [diff] [blame] | 1630 | * Called when unmounting the filesystem. |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1631 | */ |
| 1632 | |
Steven Whitehouse | fefc03b | 2008-12-19 15:32:06 +0000 | [diff] [blame] | 1633 | void gfs2_gl_hash_clear(struct gfs2_sbd *sdp) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1634 | { |
David Teigland | fb6791d | 2012-11-13 10:58:56 -0500 | [diff] [blame] | 1635 | set_bit(SDF_SKIP_DLM_UNLOCK, &sdp->sd_flags); |
Bob Peterson | 222cb53 | 2013-04-25 12:49:17 -0400 | [diff] [blame] | 1636 | flush_workqueue(glock_workqueue); |
Steven Whitehouse | bc015cb | 2011-01-19 09:30:01 +0000 | [diff] [blame] | 1637 | glock_hash_walk(clear_glock, sdp); |
Steven Whitehouse | 8f05228 | 2010-01-29 15:21:27 +0000 | [diff] [blame] | 1638 | flush_workqueue(glock_workqueue); |
Bob Peterson | 2aba1b5 | 2015-05-19 09:11:23 -0500 | [diff] [blame] | 1639 | wait_event_timeout(sdp->sd_glock_wait, |
| 1640 | atomic_read(&sdp->sd_glock_disposal) == 0, |
| 1641 | HZ * 600); |
Steven Whitehouse | bc015cb | 2011-01-19 09:30:01 +0000 | [diff] [blame] | 1642 | glock_hash_walk(dump_glock_func, sdp); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1643 | } |
| 1644 | |
Steven Whitehouse | 813e0c4 | 2008-11-18 13:38:48 +0000 | [diff] [blame] | 1645 | void gfs2_glock_finish_truncate(struct gfs2_inode *ip) |
| 1646 | { |
| 1647 | struct gfs2_glock *gl = ip->i_gl; |
| 1648 | int ret; |
| 1649 | |
| 1650 | ret = gfs2_truncatei_resume(ip); |
Bob Peterson | 15562c4 | 2015-03-16 11:52:05 -0500 | [diff] [blame] | 1651 | gfs2_assert_withdraw(gl->gl_name.ln_sbd, ret == 0); |
Steven Whitehouse | 813e0c4 | 2008-11-18 13:38:48 +0000 | [diff] [blame] | 1652 | |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 1653 | spin_lock(&gl->gl_lockref.lock); |
Steven Whitehouse | 813e0c4 | 2008-11-18 13:38:48 +0000 | [diff] [blame] | 1654 | clear_bit(GLF_LOCK, &gl->gl_flags); |
| 1655 | run_queue(gl, 1); |
Andreas Gruenbacher | f3dd164 | 2015-10-29 10:58:09 -0500 | [diff] [blame] | 1656 | spin_unlock(&gl->gl_lockref.lock); |
Steven Whitehouse | 813e0c4 | 2008-11-18 13:38:48 +0000 | [diff] [blame] | 1657 | } |
| 1658 | |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1659 | static const char *state2str(unsigned state) |
Robert Peterson | 04b933f | 2007-03-23 17:05:15 -0500 | [diff] [blame] | 1660 | { |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1661 | switch(state) { |
| 1662 | case LM_ST_UNLOCKED: |
| 1663 | return "UN"; |
| 1664 | case LM_ST_SHARED: |
| 1665 | return "SH"; |
| 1666 | case LM_ST_DEFERRED: |
| 1667 | return "DF"; |
| 1668 | case LM_ST_EXCLUSIVE: |
| 1669 | return "EX"; |
| 1670 | } |
| 1671 | return "??"; |
| 1672 | } |
Robert Peterson | 04b933f | 2007-03-23 17:05:15 -0500 | [diff] [blame] | 1673 | |
Bob Peterson | b58bf40 | 2015-07-24 09:45:43 -0500 | [diff] [blame] | 1674 | static const char *hflags2str(char *buf, u16 flags, unsigned long iflags) |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1675 | { |
| 1676 | char *p = buf; |
| 1677 | if (flags & LM_FLAG_TRY) |
| 1678 | *p++ = 't'; |
| 1679 | if (flags & LM_FLAG_TRY_1CB) |
| 1680 | *p++ = 'T'; |
| 1681 | if (flags & LM_FLAG_NOEXP) |
| 1682 | *p++ = 'e'; |
| 1683 | if (flags & LM_FLAG_ANY) |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 1684 | *p++ = 'A'; |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1685 | if (flags & LM_FLAG_PRIORITY) |
| 1686 | *p++ = 'p'; |
| 1687 | if (flags & GL_ASYNC) |
| 1688 | *p++ = 'a'; |
| 1689 | if (flags & GL_EXACT) |
| 1690 | *p++ = 'E'; |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1691 | if (flags & GL_NOCACHE) |
| 1692 | *p++ = 'c'; |
| 1693 | if (test_bit(HIF_HOLDER, &iflags)) |
| 1694 | *p++ = 'H'; |
| 1695 | if (test_bit(HIF_WAIT, &iflags)) |
| 1696 | *p++ = 'W'; |
| 1697 | if (test_bit(HIF_FIRST, &iflags)) |
| 1698 | *p++ = 'F'; |
| 1699 | *p = 0; |
| 1700 | return buf; |
Robert Peterson | 04b933f | 2007-03-23 17:05:15 -0500 | [diff] [blame] | 1701 | } |
| 1702 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1703 | /** |
| 1704 | * dump_holder - print information about a glock holder |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1705 | * @seq: the seq_file struct |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1706 | * @gh: the glock holder |
| 1707 | * |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1708 | */ |
| 1709 | |
Steven Whitehouse | ac3beb6 | 2014-01-16 10:31:13 +0000 | [diff] [blame] | 1710 | static void dump_holder(struct seq_file *seq, const struct gfs2_holder *gh) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1711 | { |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1712 | struct task_struct *gh_owner = NULL; |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1713 | char flags_buf[32]; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1714 | |
Tetsuo Handa | 0b3a2c9 | 2014-01-02 19:52:20 +0900 | [diff] [blame] | 1715 | rcu_read_lock(); |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1716 | if (gh->gh_owner_pid) |
Pavel Emelyanov | b1e058d | 2008-02-07 00:13:19 -0800 | [diff] [blame] | 1717 | gh_owner = pid_task(gh->gh_owner_pid, PIDTYPE_PID); |
Joe Perches | cc18152 | 2010-11-05 16:12:36 -0700 | [diff] [blame] | 1718 | gfs2_print_dbg(seq, " H: s:%s f:%s e:%d p:%ld [%s] %pS\n", |
| 1719 | state2str(gh->gh_state), |
| 1720 | hflags2str(flags_buf, gh->gh_flags, gh->gh_iflags), |
| 1721 | gh->gh_error, |
| 1722 | gh->gh_owner_pid ? (long)pid_nr(gh->gh_owner_pid) : -1, |
| 1723 | gh_owner ? gh_owner->comm : "(ended)", |
| 1724 | (void *)gh->gh_ip); |
Tetsuo Handa | 0b3a2c9 | 2014-01-02 19:52:20 +0900 | [diff] [blame] | 1725 | rcu_read_unlock(); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1726 | } |
| 1727 | |
Steven Whitehouse | 627c10b | 2011-04-14 14:09:52 +0100 | [diff] [blame] | 1728 | static const char *gflags2str(char *buf, const struct gfs2_glock *gl) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1729 | { |
Steven Whitehouse | 627c10b | 2011-04-14 14:09:52 +0100 | [diff] [blame] | 1730 | const unsigned long *gflags = &gl->gl_flags; |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1731 | char *p = buf; |
Steven Whitehouse | 627c10b | 2011-04-14 14:09:52 +0100 | [diff] [blame] | 1732 | |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1733 | if (test_bit(GLF_LOCK, gflags)) |
| 1734 | *p++ = 'l'; |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1735 | if (test_bit(GLF_DEMOTE, gflags)) |
| 1736 | *p++ = 'D'; |
| 1737 | if (test_bit(GLF_PENDING_DEMOTE, gflags)) |
| 1738 | *p++ = 'd'; |
| 1739 | if (test_bit(GLF_DEMOTE_IN_PROGRESS, gflags)) |
| 1740 | *p++ = 'p'; |
| 1741 | if (test_bit(GLF_DIRTY, gflags)) |
| 1742 | *p++ = 'y'; |
| 1743 | if (test_bit(GLF_LFLUSH, gflags)) |
| 1744 | *p++ = 'f'; |
| 1745 | if (test_bit(GLF_INVALIDATE_IN_PROGRESS, gflags)) |
| 1746 | *p++ = 'i'; |
| 1747 | if (test_bit(GLF_REPLY_PENDING, gflags)) |
| 1748 | *p++ = 'r'; |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 1749 | if (test_bit(GLF_INITIAL, gflags)) |
Steven Whitehouse | d8348de | 2009-02-05 10:12:38 +0000 | [diff] [blame] | 1750 | *p++ = 'I'; |
Steven Whitehouse | f057f6c | 2009-01-12 10:43:39 +0000 | [diff] [blame] | 1751 | if (test_bit(GLF_FROZEN, gflags)) |
| 1752 | *p++ = 'F'; |
Steven Whitehouse | 7b5e3d5 | 2010-09-03 09:39:20 +0100 | [diff] [blame] | 1753 | if (test_bit(GLF_QUEUED, gflags)) |
| 1754 | *p++ = 'q'; |
Steven Whitehouse | 627c10b | 2011-04-14 14:09:52 +0100 | [diff] [blame] | 1755 | if (test_bit(GLF_LRU, gflags)) |
| 1756 | *p++ = 'L'; |
| 1757 | if (gl->gl_object) |
| 1758 | *p++ = 'o'; |
Steven Whitehouse | a245769 | 2012-01-20 10:38:36 +0000 | [diff] [blame] | 1759 | if (test_bit(GLF_BLOCKING, gflags)) |
| 1760 | *p++ = 'b'; |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1761 | *p = 0; |
| 1762 | return buf; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1763 | } |
| 1764 | |
| 1765 | /** |
Steven Whitehouse | 8eae1ca0 | 2012-10-15 10:57:02 +0100 | [diff] [blame] | 1766 | * gfs2_dump_glock - print information about a glock |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1767 | * @seq: The seq_file struct |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1768 | * @gl: the glock |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1769 | * |
| 1770 | * The file format is as follows: |
| 1771 | * One line per object, capital letters are used to indicate objects |
| 1772 | * G = glock, I = Inode, R = rgrp, H = holder. Glocks are not indented, |
| 1773 | * other objects are indented by a single space and follow the glock to |
| 1774 | * which they are related. Fields are indicated by lower case letters |
| 1775 | * followed by a colon and the field value, except for strings which are in |
| 1776 | * [] so that its possible to see if they are composed of spaces for |
| 1777 | * example. The field's are n = number (id of the object), f = flags, |
| 1778 | * t = type, s = state, r = refcount, e = error, p = pid. |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1779 | * |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1780 | */ |
| 1781 | |
Bob Peterson | 27a2660f | 2018-04-18 12:05:01 -0700 | [diff] [blame] | 1782 | void gfs2_dump_glock(struct seq_file *seq, struct gfs2_glock *gl) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1783 | { |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1784 | const struct gfs2_glock_operations *glops = gl->gl_ops; |
| 1785 | unsigned long long dtime; |
| 1786 | const struct gfs2_holder *gh; |
| 1787 | char gflags_buf[32]; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1788 | |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1789 | dtime = jiffies - gl->gl_demote_time; |
| 1790 | dtime *= 1000000/HZ; /* demote time in uSec */ |
| 1791 | if (!test_bit(GLF_DEMOTE, &gl->gl_flags)) |
| 1792 | dtime = 0; |
Bob Peterson | 7cf8dcd | 2011-06-15 11:41:48 -0400 | [diff] [blame] | 1793 | gfs2_print_dbg(seq, "G: s:%s n:%u/%llx f:%s t:%s d:%s/%llu a:%d v:%d r:%d m:%ld\n", |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1794 | state2str(gl->gl_state), |
| 1795 | gl->gl_name.ln_type, |
| 1796 | (unsigned long long)gl->gl_name.ln_number, |
Steven Whitehouse | 627c10b | 2011-04-14 14:09:52 +0100 | [diff] [blame] | 1797 | gflags2str(gflags_buf, gl), |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1798 | state2str(gl->gl_target), |
| 1799 | state2str(gl->gl_demote_state), dtime, |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1800 | atomic_read(&gl->gl_ail_count), |
Bob Peterson | 73118ca | 2019-04-05 04:41:38 +0100 | [diff] [blame] | 1801 | test_bit(GLF_REVOKES, &gl->gl_flags) ? 1 : 0, |
Steven Whitehouse | e66cf16 | 2013-10-15 15:18:08 +0100 | [diff] [blame] | 1802 | (int)gl->gl_lockref.count, gl->gl_hold_time); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1803 | |
Steven Whitehouse | ac3beb6 | 2014-01-16 10:31:13 +0000 | [diff] [blame] | 1804 | list_for_each_entry(gh, &gl->gl_holders, gh_list) |
| 1805 | dump_holder(seq, gh); |
| 1806 | |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1807 | if (gl->gl_state != LM_ST_UNLOCKED && glops->go_dump) |
Steven Whitehouse | ac3beb6 | 2014-01-16 10:31:13 +0000 | [diff] [blame] | 1808 | glops->go_dump(seq, gl); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1809 | } |
| 1810 | |
Steven Whitehouse | a245769 | 2012-01-20 10:38:36 +0000 | [diff] [blame] | 1811 | static int gfs2_glstats_seq_show(struct seq_file *seq, void *iter_ptr) |
| 1812 | { |
| 1813 | struct gfs2_glock *gl = iter_ptr; |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1814 | |
Ben Hutchings | 4d20713 | 2015-08-27 12:51:45 -0500 | [diff] [blame] | 1815 | seq_printf(seq, "G: n:%u/%llx rtt:%llu/%llu rttb:%llu/%llu irt:%llu/%llu dcnt: %llu qcnt: %llu\n", |
Steven Whitehouse | a245769 | 2012-01-20 10:38:36 +0000 | [diff] [blame] | 1816 | gl->gl_name.ln_type, |
| 1817 | (unsigned long long)gl->gl_name.ln_number, |
Ben Hutchings | 4d20713 | 2015-08-27 12:51:45 -0500 | [diff] [blame] | 1818 | (unsigned long long)gl->gl_stats.stats[GFS2_LKS_SRTT], |
| 1819 | (unsigned long long)gl->gl_stats.stats[GFS2_LKS_SRTTVAR], |
| 1820 | (unsigned long long)gl->gl_stats.stats[GFS2_LKS_SRTTB], |
| 1821 | (unsigned long long)gl->gl_stats.stats[GFS2_LKS_SRTTVARB], |
| 1822 | (unsigned long long)gl->gl_stats.stats[GFS2_LKS_SIRT], |
| 1823 | (unsigned long long)gl->gl_stats.stats[GFS2_LKS_SIRTVAR], |
| 1824 | (unsigned long long)gl->gl_stats.stats[GFS2_LKS_DCOUNT], |
| 1825 | (unsigned long long)gl->gl_stats.stats[GFS2_LKS_QCOUNT]); |
Steven Whitehouse | a245769 | 2012-01-20 10:38:36 +0000 | [diff] [blame] | 1826 | return 0; |
| 1827 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1828 | |
Steven Whitehouse | a245769 | 2012-01-20 10:38:36 +0000 | [diff] [blame] | 1829 | static const char *gfs2_gltype[] = { |
| 1830 | "type", |
| 1831 | "reserved", |
| 1832 | "nondisk", |
| 1833 | "inode", |
| 1834 | "rgrp", |
| 1835 | "meta", |
| 1836 | "iopen", |
| 1837 | "flock", |
| 1838 | "plock", |
| 1839 | "quota", |
| 1840 | "journal", |
| 1841 | }; |
| 1842 | |
| 1843 | static const char *gfs2_stype[] = { |
| 1844 | [GFS2_LKS_SRTT] = "srtt", |
| 1845 | [GFS2_LKS_SRTTVAR] = "srttvar", |
| 1846 | [GFS2_LKS_SRTTB] = "srttb", |
| 1847 | [GFS2_LKS_SRTTVARB] = "srttvarb", |
| 1848 | [GFS2_LKS_SIRT] = "sirt", |
| 1849 | [GFS2_LKS_SIRTVAR] = "sirtvar", |
| 1850 | [GFS2_LKS_DCOUNT] = "dlm", |
| 1851 | [GFS2_LKS_QCOUNT] = "queue", |
| 1852 | }; |
| 1853 | |
| 1854 | #define GFS2_NR_SBSTATS (ARRAY_SIZE(gfs2_gltype) * ARRAY_SIZE(gfs2_stype)) |
| 1855 | |
| 1856 | static int gfs2_sbstats_seq_show(struct seq_file *seq, void *iter_ptr) |
| 1857 | { |
Andreas Gruenbacher | 81648d0 | 2015-08-27 11:43:00 -0500 | [diff] [blame] | 1858 | struct gfs2_sbd *sdp = seq->private; |
| 1859 | loff_t pos = *(loff_t *)iter_ptr; |
| 1860 | unsigned index = pos >> 3; |
| 1861 | unsigned subindex = pos & 0x07; |
Steven Whitehouse | a245769 | 2012-01-20 10:38:36 +0000 | [diff] [blame] | 1862 | int i; |
| 1863 | |
| 1864 | if (index == 0 && subindex != 0) |
| 1865 | return 0; |
| 1866 | |
| 1867 | seq_printf(seq, "%-10s %8s:", gfs2_gltype[index], |
| 1868 | (index == 0) ? "cpu": gfs2_stype[subindex]); |
| 1869 | |
| 1870 | for_each_possible_cpu(i) { |
| 1871 | const struct gfs2_pcpu_lkstats *lkstats = per_cpu_ptr(sdp->sd_lkstats, i); |
Andreas Gruenbacher | 8f7e0a8 | 2015-08-27 13:02:54 -0500 | [diff] [blame] | 1872 | |
| 1873 | if (index == 0) |
| 1874 | seq_printf(seq, " %15u", i); |
| 1875 | else |
| 1876 | seq_printf(seq, " %15llu", (unsigned long long)lkstats-> |
| 1877 | lkstats[index - 1].stats[subindex]); |
Steven Whitehouse | a245769 | 2012-01-20 10:38:36 +0000 | [diff] [blame] | 1878 | } |
| 1879 | seq_putc(seq, '\n'); |
| 1880 | return 0; |
| 1881 | } |
Steven Whitehouse | 8fbbfd2 | 2007-08-01 13:57:10 +0100 | [diff] [blame] | 1882 | |
Steven Whitehouse | 85d1da6 | 2006-09-07 14:40:21 -0400 | [diff] [blame] | 1883 | int __init gfs2_glock_init(void) |
| 1884 | { |
Andreas Gruenbacher | 0515480 | 2017-08-01 11:18:26 -0500 | [diff] [blame] | 1885 | int i, ret; |
Bob Peterson | 88ffbf3 | 2015-03-16 11:02:46 -0500 | [diff] [blame] | 1886 | |
| 1887 | ret = rhashtable_init(&gl_hash_table, &ht_parms); |
| 1888 | if (ret < 0) |
| 1889 | return ret; |
Steven Whitehouse | 8fbbfd2 | 2007-08-01 13:57:10 +0100 | [diff] [blame] | 1890 | |
Steven Whitehouse | d211577 | 2010-11-03 19:58:53 +0000 | [diff] [blame] | 1891 | glock_workqueue = alloc_workqueue("glock_workqueue", WQ_MEM_RECLAIM | |
Tejun Heo | 58a69cb | 2011-02-16 09:25:31 +0100 | [diff] [blame] | 1892 | WQ_HIGHPRI | WQ_FREEZABLE, 0); |
Bob Peterson | 88ffbf3 | 2015-03-16 11:02:46 -0500 | [diff] [blame] | 1893 | if (!glock_workqueue) { |
| 1894 | rhashtable_destroy(&gl_hash_table); |
Dan Carpenter | dfc4616 | 2013-08-15 10:54:43 +0300 | [diff] [blame] | 1895 | return -ENOMEM; |
Bob Peterson | 88ffbf3 | 2015-03-16 11:02:46 -0500 | [diff] [blame] | 1896 | } |
Steven Whitehouse | d211577 | 2010-11-03 19:58:53 +0000 | [diff] [blame] | 1897 | gfs2_delete_workqueue = alloc_workqueue("delete_workqueue", |
Tejun Heo | 58a69cb | 2011-02-16 09:25:31 +0100 | [diff] [blame] | 1898 | WQ_MEM_RECLAIM | WQ_FREEZABLE, |
Steven Whitehouse | d211577 | 2010-11-03 19:58:53 +0000 | [diff] [blame] | 1899 | 0); |
Dan Carpenter | dfc4616 | 2013-08-15 10:54:43 +0300 | [diff] [blame] | 1900 | if (!gfs2_delete_workqueue) { |
Benjamin Marzinski | b94a170 | 2009-07-23 18:52:34 -0500 | [diff] [blame] | 1901 | destroy_workqueue(glock_workqueue); |
Bob Peterson | 88ffbf3 | 2015-03-16 11:02:46 -0500 | [diff] [blame] | 1902 | rhashtable_destroy(&gl_hash_table); |
Dan Carpenter | dfc4616 | 2013-08-15 10:54:43 +0300 | [diff] [blame] | 1903 | return -ENOMEM; |
Benjamin Marzinski | b94a170 | 2009-07-23 18:52:34 -0500 | [diff] [blame] | 1904 | } |
Steven Whitehouse | 97cc1025 | 2008-11-20 13:39:47 +0000 | [diff] [blame] | 1905 | |
Chao Yu | e0d735c | 2016-09-21 12:09:40 -0500 | [diff] [blame] | 1906 | ret = register_shrinker(&glock_shrinker); |
| 1907 | if (ret) { |
| 1908 | destroy_workqueue(gfs2_delete_workqueue); |
| 1909 | destroy_workqueue(glock_workqueue); |
| 1910 | rhashtable_destroy(&gl_hash_table); |
| 1911 | return ret; |
| 1912 | } |
Benjamin Marzinski | c4f68a1 | 2007-08-23 13:19:05 -0500 | [diff] [blame] | 1913 | |
Andreas Gruenbacher | 0515480 | 2017-08-01 11:18:26 -0500 | [diff] [blame] | 1914 | for (i = 0; i < GLOCK_WAIT_TABLE_SIZE; i++) |
| 1915 | init_waitqueue_head(glock_wait_table + i); |
| 1916 | |
Steven Whitehouse | 85d1da6 | 2006-09-07 14:40:21 -0400 | [diff] [blame] | 1917 | return 0; |
| 1918 | } |
| 1919 | |
Steven Whitehouse | 8fbbfd2 | 2007-08-01 13:57:10 +0100 | [diff] [blame] | 1920 | void gfs2_glock_exit(void) |
| 1921 | { |
Steven Whitehouse | 97cc1025 | 2008-11-20 13:39:47 +0000 | [diff] [blame] | 1922 | unregister_shrinker(&glock_shrinker); |
Bob Peterson | 88ffbf3 | 2015-03-16 11:02:46 -0500 | [diff] [blame] | 1923 | rhashtable_destroy(&gl_hash_table); |
Benjamin Marzinski | c4f68a1 | 2007-08-23 13:19:05 -0500 | [diff] [blame] | 1924 | destroy_workqueue(glock_workqueue); |
Benjamin Marzinski | b94a170 | 2009-07-23 18:52:34 -0500 | [diff] [blame] | 1925 | destroy_workqueue(gfs2_delete_workqueue); |
Steven Whitehouse | 8fbbfd2 | 2007-08-01 13:57:10 +0100 | [diff] [blame] | 1926 | } |
| 1927 | |
Andreas Gruenbacher | 7ac07fd | 2018-01-08 22:35:43 +0100 | [diff] [blame] | 1928 | static void gfs2_glock_iter_next(struct gfs2_glock_iter *gi, loff_t n) |
Steven Whitehouse | bc015cb | 2011-01-19 09:30:01 +0000 | [diff] [blame] | 1929 | { |
Andreas Gruenbacher | 3fd5d3a | 2018-03-28 12:05:35 +0200 | [diff] [blame] | 1930 | struct gfs2_glock *gl = gi->gl; |
| 1931 | |
| 1932 | if (gl) { |
| 1933 | if (n == 0) |
| 1934 | return; |
| 1935 | if (!lockref_put_not_zero(&gl->gl_lockref)) |
| 1936 | gfs2_glock_queue_put(gl); |
Andreas Gruenbacher | 7ac07fd | 2018-01-08 22:35:43 +0100 | [diff] [blame] | 1937 | } |
| 1938 | for (;;) { |
Andreas Gruenbacher | 3fd5d3a | 2018-03-28 12:05:35 +0200 | [diff] [blame] | 1939 | gl = rhashtable_walk_next(&gi->hti); |
| 1940 | if (IS_ERR_OR_NULL(gl)) { |
| 1941 | if (gl == ERR_PTR(-EAGAIN)) { |
| 1942 | n = 1; |
| 1943 | continue; |
Andreas Gruenbacher | 7ac07fd | 2018-01-08 22:35:43 +0100 | [diff] [blame] | 1944 | } |
Andreas Gruenbacher | 3fd5d3a | 2018-03-28 12:05:35 +0200 | [diff] [blame] | 1945 | gl = NULL; |
| 1946 | break; |
Steven Whitehouse | bc015cb | 2011-01-19 09:30:01 +0000 | [diff] [blame] | 1947 | } |
Andreas Gruenbacher | 3fd5d3a | 2018-03-28 12:05:35 +0200 | [diff] [blame] | 1948 | if (gl->gl_name.ln_sbd != gi->sdp) |
| 1949 | continue; |
| 1950 | if (n <= 1) { |
| 1951 | if (!lockref_get_not_dead(&gl->gl_lockref)) |
| 1952 | continue; |
| 1953 | break; |
| 1954 | } else { |
| 1955 | if (__lockref_is_dead(&gl->gl_lockref)) |
| 1956 | continue; |
| 1957 | n--; |
| 1958 | } |
Dan Carpenter | 14d3756 | 2016-12-14 08:02:03 -0600 | [diff] [blame] | 1959 | } |
Andreas Gruenbacher | 3fd5d3a | 2018-03-28 12:05:35 +0200 | [diff] [blame] | 1960 | gi->gl = gl; |
Robert Peterson | 7c52b16 | 2007-03-16 10:26:37 +0000 | [diff] [blame] | 1961 | } |
| 1962 | |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1963 | static void *gfs2_glock_seq_start(struct seq_file *seq, loff_t *pos) |
Bob Peterson | 27c3b41 | 2017-08-18 09:15:13 -0500 | [diff] [blame] | 1964 | __acquires(RCU) |
Robert Peterson | 7c52b16 | 2007-03-16 10:26:37 +0000 | [diff] [blame] | 1965 | { |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1966 | struct gfs2_glock_iter *gi = seq->private; |
Andreas Gruenbacher | 7ac07fd | 2018-01-08 22:35:43 +0100 | [diff] [blame] | 1967 | loff_t n; |
Robert Peterson | 7c52b16 | 2007-03-16 10:26:37 +0000 | [diff] [blame] | 1968 | |
Andreas Gruenbacher | 7ac07fd | 2018-01-08 22:35:43 +0100 | [diff] [blame] | 1969 | /* |
| 1970 | * We can either stay where we are, skip to the next hash table |
| 1971 | * entry, or start from the beginning. |
| 1972 | */ |
| 1973 | if (*pos < gi->last_pos) { |
| 1974 | rhashtable_walk_exit(&gi->hti); |
| 1975 | rhashtable_walk_enter(&gl_hash_table, &gi->hti); |
| 1976 | n = *pos + 1; |
| 1977 | } else { |
| 1978 | n = *pos - gi->last_pos; |
| 1979 | } |
Robert Peterson | 7c52b16 | 2007-03-16 10:26:37 +0000 | [diff] [blame] | 1980 | |
Andreas Gruenbacher | 7ac07fd | 2018-01-08 22:35:43 +0100 | [diff] [blame] | 1981 | rhashtable_walk_start(&gi->hti); |
Robert Peterson | 7c52b16 | 2007-03-16 10:26:37 +0000 | [diff] [blame] | 1982 | |
Andreas Gruenbacher | 7ac07fd | 2018-01-08 22:35:43 +0100 | [diff] [blame] | 1983 | gfs2_glock_iter_next(gi, n); |
Steven Whitehouse | ba1ddcb | 2012-06-08 11:16:22 +0100 | [diff] [blame] | 1984 | gi->last_pos = *pos; |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1985 | return gi->gl; |
Robert Peterson | 7c52b16 | 2007-03-16 10:26:37 +0000 | [diff] [blame] | 1986 | } |
| 1987 | |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1988 | static void *gfs2_glock_seq_next(struct seq_file *seq, void *iter_ptr, |
Robert Peterson | 7c52b16 | 2007-03-16 10:26:37 +0000 | [diff] [blame] | 1989 | loff_t *pos) |
| 1990 | { |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1991 | struct gfs2_glock_iter *gi = seq->private; |
Robert Peterson | 7c52b16 | 2007-03-16 10:26:37 +0000 | [diff] [blame] | 1992 | |
| 1993 | (*pos)++; |
Steven Whitehouse | ba1ddcb | 2012-06-08 11:16:22 +0100 | [diff] [blame] | 1994 | gi->last_pos = *pos; |
Andreas Gruenbacher | 7ac07fd | 2018-01-08 22:35:43 +0100 | [diff] [blame] | 1995 | gfs2_glock_iter_next(gi, 1); |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1996 | return gi->gl; |
Robert Peterson | 7c52b16 | 2007-03-16 10:26:37 +0000 | [diff] [blame] | 1997 | } |
| 1998 | |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 1999 | static void gfs2_glock_seq_stop(struct seq_file *seq, void *iter_ptr) |
Bob Peterson | 27c3b41 | 2017-08-18 09:15:13 -0500 | [diff] [blame] | 2000 | __releases(RCU) |
Robert Peterson | 7c52b16 | 2007-03-16 10:26:37 +0000 | [diff] [blame] | 2001 | { |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 2002 | struct gfs2_glock_iter *gi = seq->private; |
Steven Whitehouse | bc015cb | 2011-01-19 09:30:01 +0000 | [diff] [blame] | 2003 | |
Bob Peterson | 88ffbf3 | 2015-03-16 11:02:46 -0500 | [diff] [blame] | 2004 | rhashtable_walk_stop(&gi->hti); |
Robert Peterson | 7c52b16 | 2007-03-16 10:26:37 +0000 | [diff] [blame] | 2005 | } |
| 2006 | |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 2007 | static int gfs2_glock_seq_show(struct seq_file *seq, void *iter_ptr) |
Robert Peterson | 7c52b16 | 2007-03-16 10:26:37 +0000 | [diff] [blame] | 2008 | { |
Steven Whitehouse | ac3beb6 | 2014-01-16 10:31:13 +0000 | [diff] [blame] | 2009 | dump_glock(seq, iter_ptr); |
| 2010 | return 0; |
Robert Peterson | 7c52b16 | 2007-03-16 10:26:37 +0000 | [diff] [blame] | 2011 | } |
| 2012 | |
Steven Whitehouse | a245769 | 2012-01-20 10:38:36 +0000 | [diff] [blame] | 2013 | static void *gfs2_sbstats_seq_start(struct seq_file *seq, loff_t *pos) |
| 2014 | { |
Andreas Gruenbacher | 81648d0 | 2015-08-27 11:43:00 -0500 | [diff] [blame] | 2015 | preempt_disable(); |
Steven Whitehouse | a245769 | 2012-01-20 10:38:36 +0000 | [diff] [blame] | 2016 | if (*pos >= GFS2_NR_SBSTATS) |
| 2017 | return NULL; |
Andreas Gruenbacher | 81648d0 | 2015-08-27 11:43:00 -0500 | [diff] [blame] | 2018 | return pos; |
Steven Whitehouse | a245769 | 2012-01-20 10:38:36 +0000 | [diff] [blame] | 2019 | } |
| 2020 | |
| 2021 | static void *gfs2_sbstats_seq_next(struct seq_file *seq, void *iter_ptr, |
| 2022 | loff_t *pos) |
| 2023 | { |
Steven Whitehouse | a245769 | 2012-01-20 10:38:36 +0000 | [diff] [blame] | 2024 | (*pos)++; |
Andreas Gruenbacher | 81648d0 | 2015-08-27 11:43:00 -0500 | [diff] [blame] | 2025 | if (*pos >= GFS2_NR_SBSTATS) |
Steven Whitehouse | a245769 | 2012-01-20 10:38:36 +0000 | [diff] [blame] | 2026 | return NULL; |
Andreas Gruenbacher | 81648d0 | 2015-08-27 11:43:00 -0500 | [diff] [blame] | 2027 | return pos; |
Steven Whitehouse | a245769 | 2012-01-20 10:38:36 +0000 | [diff] [blame] | 2028 | } |
| 2029 | |
| 2030 | static void gfs2_sbstats_seq_stop(struct seq_file *seq, void *iter_ptr) |
| 2031 | { |
| 2032 | preempt_enable(); |
| 2033 | } |
| 2034 | |
Denis Cheng | 4ef2900 | 2007-07-31 18:31:11 +0800 | [diff] [blame] | 2035 | static const struct seq_operations gfs2_glock_seq_ops = { |
Robert Peterson | 7c52b16 | 2007-03-16 10:26:37 +0000 | [diff] [blame] | 2036 | .start = gfs2_glock_seq_start, |
| 2037 | .next = gfs2_glock_seq_next, |
| 2038 | .stop = gfs2_glock_seq_stop, |
| 2039 | .show = gfs2_glock_seq_show, |
| 2040 | }; |
| 2041 | |
Steven Whitehouse | a245769 | 2012-01-20 10:38:36 +0000 | [diff] [blame] | 2042 | static const struct seq_operations gfs2_glstats_seq_ops = { |
| 2043 | .start = gfs2_glock_seq_start, |
| 2044 | .next = gfs2_glock_seq_next, |
| 2045 | .stop = gfs2_glock_seq_stop, |
| 2046 | .show = gfs2_glstats_seq_show, |
| 2047 | }; |
| 2048 | |
| 2049 | static const struct seq_operations gfs2_sbstats_seq_ops = { |
| 2050 | .start = gfs2_sbstats_seq_start, |
| 2051 | .next = gfs2_sbstats_seq_next, |
| 2052 | .stop = gfs2_sbstats_seq_stop, |
| 2053 | .show = gfs2_sbstats_seq_show, |
| 2054 | }; |
| 2055 | |
Steven Whitehouse | 0fe2f1e | 2012-06-11 13:49:47 +0100 | [diff] [blame] | 2056 | #define GFS2_SEQ_GOODSIZE min(PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER, 65536UL) |
| 2057 | |
Andreas Gruenbacher | 92ecd73 | 2017-03-09 09:48:05 -0500 | [diff] [blame] | 2058 | static int __gfs2_glocks_open(struct inode *inode, struct file *file, |
| 2059 | const struct seq_operations *ops) |
Robert Peterson | 7c52b16 | 2007-03-16 10:26:37 +0000 | [diff] [blame] | 2060 | { |
Andreas Gruenbacher | 92ecd73 | 2017-03-09 09:48:05 -0500 | [diff] [blame] | 2061 | int ret = seq_open_private(file, ops, sizeof(struct gfs2_glock_iter)); |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 2062 | if (ret == 0) { |
| 2063 | struct seq_file *seq = file->private_data; |
| 2064 | struct gfs2_glock_iter *gi = seq->private; |
Bob Peterson | 88ffbf3 | 2015-03-16 11:02:46 -0500 | [diff] [blame] | 2065 | |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 2066 | gi->sdp = inode->i_private; |
Steven Whitehouse | 0fe2f1e | 2012-06-11 13:49:47 +0100 | [diff] [blame] | 2067 | seq->buf = kmalloc(GFS2_SEQ_GOODSIZE, GFP_KERNEL | __GFP_NOWARN); |
Steven Whitehouse | df5d2f5 | 2012-06-07 13:30:16 +0100 | [diff] [blame] | 2068 | if (seq->buf) |
Steven Whitehouse | 0fe2f1e | 2012-06-11 13:49:47 +0100 | [diff] [blame] | 2069 | seq->size = GFS2_SEQ_GOODSIZE; |
Andreas Gruenbacher | 7ac07fd | 2018-01-08 22:35:43 +0100 | [diff] [blame] | 2070 | /* |
| 2071 | * Initially, we are "before" the first hash table entry; the |
| 2072 | * first call to rhashtable_walk_next gets us the first entry. |
| 2073 | */ |
| 2074 | gi->last_pos = -1; |
Bob Peterson | 88ffbf3 | 2015-03-16 11:02:46 -0500 | [diff] [blame] | 2075 | gi->gl = NULL; |
Andreas Gruenbacher | 7ac07fd | 2018-01-08 22:35:43 +0100 | [diff] [blame] | 2076 | rhashtable_walk_enter(&gl_hash_table, &gi->hti); |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 2077 | } |
| 2078 | return ret; |
Robert Peterson | 7c52b16 | 2007-03-16 10:26:37 +0000 | [diff] [blame] | 2079 | } |
| 2080 | |
Andreas Gruenbacher | 92ecd73 | 2017-03-09 09:48:05 -0500 | [diff] [blame] | 2081 | static int gfs2_glocks_open(struct inode *inode, struct file *file) |
| 2082 | { |
| 2083 | return __gfs2_glocks_open(inode, file, &gfs2_glock_seq_ops); |
| 2084 | } |
| 2085 | |
Bob Peterson | 88ffbf3 | 2015-03-16 11:02:46 -0500 | [diff] [blame] | 2086 | static int gfs2_glocks_release(struct inode *inode, struct file *file) |
| 2087 | { |
| 2088 | struct seq_file *seq = file->private_data; |
| 2089 | struct gfs2_glock_iter *gi = seq->private; |
| 2090 | |
Andreas Gruenbacher | 3fd5d3a | 2018-03-28 12:05:35 +0200 | [diff] [blame] | 2091 | if (gi->gl) |
| 2092 | gfs2_glock_put(gi->gl); |
Andreas Gruenbacher | 7ac07fd | 2018-01-08 22:35:43 +0100 | [diff] [blame] | 2093 | rhashtable_walk_exit(&gi->hti); |
Bob Peterson | 88ffbf3 | 2015-03-16 11:02:46 -0500 | [diff] [blame] | 2094 | return seq_release_private(inode, file); |
| 2095 | } |
| 2096 | |
Steven Whitehouse | a245769 | 2012-01-20 10:38:36 +0000 | [diff] [blame] | 2097 | static int gfs2_glstats_open(struct inode *inode, struct file *file) |
| 2098 | { |
Andreas Gruenbacher | 92ecd73 | 2017-03-09 09:48:05 -0500 | [diff] [blame] | 2099 | return __gfs2_glocks_open(inode, file, &gfs2_glstats_seq_ops); |
Steven Whitehouse | a245769 | 2012-01-20 10:38:36 +0000 | [diff] [blame] | 2100 | } |
| 2101 | |
| 2102 | static int gfs2_sbstats_open(struct inode *inode, struct file *file) |
| 2103 | { |
Andreas Gruenbacher | 81648d0 | 2015-08-27 11:43:00 -0500 | [diff] [blame] | 2104 | int ret = seq_open(file, &gfs2_sbstats_seq_ops); |
Steven Whitehouse | a245769 | 2012-01-20 10:38:36 +0000 | [diff] [blame] | 2105 | if (ret == 0) { |
| 2106 | struct seq_file *seq = file->private_data; |
Andreas Gruenbacher | 81648d0 | 2015-08-27 11:43:00 -0500 | [diff] [blame] | 2107 | seq->private = inode->i_private; /* sdp */ |
Steven Whitehouse | a245769 | 2012-01-20 10:38:36 +0000 | [diff] [blame] | 2108 | } |
| 2109 | return ret; |
| 2110 | } |
| 2111 | |
| 2112 | static const struct file_operations gfs2_glocks_fops = { |
Robert Peterson | 7c52b16 | 2007-03-16 10:26:37 +0000 | [diff] [blame] | 2113 | .owner = THIS_MODULE, |
Steven Whitehouse | a245769 | 2012-01-20 10:38:36 +0000 | [diff] [blame] | 2114 | .open = gfs2_glocks_open, |
| 2115 | .read = seq_read, |
| 2116 | .llseek = seq_lseek, |
Bob Peterson | 88ffbf3 | 2015-03-16 11:02:46 -0500 | [diff] [blame] | 2117 | .release = gfs2_glocks_release, |
Steven Whitehouse | a245769 | 2012-01-20 10:38:36 +0000 | [diff] [blame] | 2118 | }; |
| 2119 | |
| 2120 | static const struct file_operations gfs2_glstats_fops = { |
| 2121 | .owner = THIS_MODULE, |
| 2122 | .open = gfs2_glstats_open, |
| 2123 | .read = seq_read, |
| 2124 | .llseek = seq_lseek, |
Bob Peterson | 88ffbf3 | 2015-03-16 11:02:46 -0500 | [diff] [blame] | 2125 | .release = gfs2_glocks_release, |
Steven Whitehouse | a245769 | 2012-01-20 10:38:36 +0000 | [diff] [blame] | 2126 | }; |
| 2127 | |
| 2128 | static const struct file_operations gfs2_sbstats_fops = { |
| 2129 | .owner = THIS_MODULE, |
| 2130 | .open = gfs2_sbstats_open, |
Robert Peterson | 7c52b16 | 2007-03-16 10:26:37 +0000 | [diff] [blame] | 2131 | .read = seq_read, |
| 2132 | .llseek = seq_lseek, |
Andreas Gruenbacher | 81648d0 | 2015-08-27 11:43:00 -0500 | [diff] [blame] | 2133 | .release = seq_release, |
Robert Peterson | 7c52b16 | 2007-03-16 10:26:37 +0000 | [diff] [blame] | 2134 | }; |
| 2135 | |
Greg Kroah-Hartman | 2abbf9a | 2019-01-22 16:21:51 +0100 | [diff] [blame] | 2136 | void gfs2_create_debugfs_file(struct gfs2_sbd *sdp) |
Robert Peterson | 7c52b16 | 2007-03-16 10:26:37 +0000 | [diff] [blame] | 2137 | { |
Greg Kroah-Hartman | 2abbf9a | 2019-01-22 16:21:51 +0100 | [diff] [blame] | 2138 | sdp->debugfs_dir = debugfs_create_dir(sdp->sd_table_name, gfs2_root); |
Steven Whitehouse | a245769 | 2012-01-20 10:38:36 +0000 | [diff] [blame] | 2139 | |
Greg Kroah-Hartman | 2abbf9a | 2019-01-22 16:21:51 +0100 | [diff] [blame] | 2140 | debugfs_create_file("glocks", S_IFREG | S_IRUGO, sdp->debugfs_dir, sdp, |
| 2141 | &gfs2_glocks_fops); |
Steven Whitehouse | a245769 | 2012-01-20 10:38:36 +0000 | [diff] [blame] | 2142 | |
Greg Kroah-Hartman | 2abbf9a | 2019-01-22 16:21:51 +0100 | [diff] [blame] | 2143 | debugfs_create_file("glstats", S_IFREG | S_IRUGO, sdp->debugfs_dir, sdp, |
| 2144 | &gfs2_glstats_fops); |
Chengyu Song | 7b4ddfa | 2015-03-24 09:37:53 -0500 | [diff] [blame] | 2145 | |
Greg Kroah-Hartman | 2abbf9a | 2019-01-22 16:21:51 +0100 | [diff] [blame] | 2146 | debugfs_create_file("sbstats", S_IFREG | S_IRUGO, sdp->debugfs_dir, sdp, |
| 2147 | &gfs2_sbstats_fops); |
Robert Peterson | 7c52b16 | 2007-03-16 10:26:37 +0000 | [diff] [blame] | 2148 | } |
| 2149 | |
| 2150 | void gfs2_delete_debugfs_file(struct gfs2_sbd *sdp) |
| 2151 | { |
Greg Kroah-Hartman | 2abbf9a | 2019-01-22 16:21:51 +0100 | [diff] [blame] | 2152 | debugfs_remove_recursive(sdp->debugfs_dir); |
| 2153 | sdp->debugfs_dir = NULL; |
Robert Peterson | 7c52b16 | 2007-03-16 10:26:37 +0000 | [diff] [blame] | 2154 | } |
| 2155 | |
Greg Kroah-Hartman | 2abbf9a | 2019-01-22 16:21:51 +0100 | [diff] [blame] | 2156 | void gfs2_register_debugfs(void) |
Robert Peterson | 7c52b16 | 2007-03-16 10:26:37 +0000 | [diff] [blame] | 2157 | { |
| 2158 | gfs2_root = debugfs_create_dir("gfs2", NULL); |
Robert Peterson | 7c52b16 | 2007-03-16 10:26:37 +0000 | [diff] [blame] | 2159 | } |
| 2160 | |
| 2161 | void gfs2_unregister_debugfs(void) |
| 2162 | { |
| 2163 | debugfs_remove(gfs2_root); |
Robert Peterson | 5f88209 | 2007-04-18 11:41:11 -0500 | [diff] [blame] | 2164 | gfs2_root = NULL; |
Robert Peterson | 7c52b16 | 2007-03-16 10:26:37 +0000 | [diff] [blame] | 2165 | } |