Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'gfs2-v6.10-rc1-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2

Pull gfs2 updates from Andreas Gruenbacher:
"Fixes and cleanups:

- Revise the glock reference counting model and LRU list handling to
be more sensible

- Several quota related fixes: clean up the quota code, add some
missing locking, and work around the on-disk corruption that the
reverted patch "gfs2: ignore negated quota changes" causes

- Clean up the glock demote logic in glock_work_func()"

* tag 'gfs2-v6.10-rc1-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2: (29 commits)
gfs2: Clean up glock demote logic
gfs2: Revert "check for no eligible quota changes"
gfs2: Be more careful with the quota sync generation
gfs2: Get rid of some unnecessary quota locking
gfs2: Add some missing quota locking
gfs2: Fold qd_fish into gfs2_quota_sync
gfs2: quota need_sync cleanup
gfs2: Fix and clean up function do_qc
gfs2: Revert "Add quota_change type"
gfs2: Revert "ignore negated quota changes"
gfs2: qd_check_sync cleanups
gfs2: Revert "introduce qd_bh_get_or_undo"
gfs2: Check quota consistency on mount
gfs2: Minor gfs2_quota_init error path cleanup
gfs2: Get rid of demote_ok checks
Revert "GFS2: Don't add all glocks to the lru"
gfs2: Revise glock reference counting model
gfs2: Switch to a per-filesystem glock workqueue
gfs2: Report when glocks cannot be freed for a long time
gfs2: gfs2_glock_get cleanup
...

+380 -405
+26 -29
Documentation/filesystems/gfs2-glocks.rst
··· 40 40 operations. The glocks are basically a lock plus some routines which deal 41 41 with cache management. The following rules apply for the cache: 42 42 43 - ========== ========== ============== ========== ============== 44 - Glock mode Cache data Cache Metadata Dirty Data Dirty Metadata 45 - ========== ========== ============== ========== ============== 46 - UN No No No No 47 - SH Yes Yes No No 48 - DF No Yes No No 49 - EX Yes Yes Yes Yes 50 - ========== ========== ============== ========== ============== 43 + ========== ============== ========== ========== ============== 44 + Glock mode Cache Metadata Cache data Dirty Data Dirty Metadata 45 + ========== ============== ========== ========== ============== 46 + UN No No No No 47 + DF Yes No No No 48 + SH Yes Yes No No 49 + EX Yes Yes Yes Yes 50 + ========== ============== ========== ========== ============== 51 51 52 52 These rules are implemented using the various glock operations which 53 53 are defined for each type of glock. Not all types of glocks use ··· 55 55 56 56 Table of glock operations and per type constants: 57 57 58 - ============= ============================================================= 58 + ============== ============================================================= 59 59 Field Purpose 60 - ============= ============================================================= 61 - go_xmote_th Called before remote state change (e.g. to sync dirty data) 60 + ============== ============================================================= 61 + go_sync Called before remote state change (e.g. to sync dirty data) 62 62 go_xmote_bh Called after remote state change (e.g. to refill cache) 63 63 go_inval Called if remote state change requires invalidating the cache 64 - go_demote_ok Returns boolean value of whether its ok to demote a glock 65 - (e.g. checks timeout, and that there is no cached data) 66 - go_lock Called for the first local holder of a lock 67 - go_unlock Called on the final local unlock of a lock 64 + go_instantiate Called when a glock has been acquired 65 + go_held Called every time a glock holder is acquired 68 66 go_dump Called to print content of object for debugfs file, or on 69 67 error to dump glock to the log. 70 - go_type The type of the glock, ``LM_TYPE_*`` 71 68 go_callback Called if the DLM sends a callback to drop this lock 69 + go_unlocked Called when a glock is unlocked (dlm_unlock()) 70 + go_type The type of the glock, ``LM_TYPE_*`` 72 71 go_flags GLOF_ASPACE is set, if the glock has an address space 73 72 associated with it 74 - ============= ============================================================= 73 + ============== ============================================================= 75 74 76 75 The minimum hold time for each lock is the time after a remote lock 77 76 grant for which we ignore remote demote requests. This is in order to ··· 81 82 remote callback, that gives the userspace program time to make 82 83 some progress before the pages are unmapped. 83 84 84 - There is a plan to try and remove the go_lock and go_unlock callbacks 85 - if possible, in order to try and speed up the fast path though the locking. 86 - Also, eventually we hope to make the glock "EX" mode locally shared 87 - such that any local locking will be done with the i_mutex as required 88 - rather than via the glock. 85 + Eventually, we hope to make the glock "EX" mode locally shared such that any 86 + local locking will be done with the i_mutex as required rather than via the 87 + glock. 89 88 90 89 Locking rules for glock operations: 91 90 92 - ============= ====================== ============================= 91 + ============== ====================== ============================= 93 92 Operation GLF_LOCK bit lock held gl_lockref.lock spinlock held 94 - ============= ====================== ============================= 95 - go_xmote_th Yes No 93 + ============== ====================== ============================= 94 + go_sync Yes No 96 95 go_xmote_bh Yes No 97 96 go_inval Yes No 98 - go_demote_ok Sometimes Yes 99 - go_lock Yes No 100 - go_unlock Yes No 97 + go_instantiate No No 98 + go_held No No 101 99 go_dump Sometimes Yes 102 100 go_callback Sometimes (N/A) Yes 103 - ============= ====================== ============================= 101 + go_unlocked Yes No 102 + ============== ====================== ============================= 104 103 105 104 .. Note:: 106 105
+99 -128
fs/gfs2/glock.c
··· 61 61 typedef void (*glock_examiner) (struct gfs2_glock * gl); 62 62 63 63 static void do_xmote(struct gfs2_glock *gl, struct gfs2_holder *gh, unsigned int target); 64 - static void __gfs2_glock_dq(struct gfs2_holder *gh); 65 - static void handle_callback(struct gfs2_glock *gl, unsigned int state, 66 - unsigned long delay, bool remote); 64 + static void request_demote(struct gfs2_glock *gl, unsigned int state, 65 + unsigned long delay, bool remote); 67 66 68 67 static struct dentry *gfs2_root; 69 - static struct workqueue_struct *glock_workqueue; 70 68 static LIST_HEAD(lru_list); 71 69 static atomic_t lru_count = ATOMIC_INIT(0); 72 70 static DEFINE_SPINLOCK(lru_lock); ··· 216 218 return gl; 217 219 } 218 220 219 - /** 220 - * demote_ok - Check to see if it's ok to unlock a glock 221 - * @gl: the glock 222 - * 223 - * Returns: 1 if it's ok 224 - */ 225 - 226 - static int demote_ok(const struct gfs2_glock *gl) 221 + static void gfs2_glock_add_to_lru(struct gfs2_glock *gl) 227 222 { 228 - const struct gfs2_glock_operations *glops = gl->gl_ops; 229 - 230 - if (gl->gl_state == LM_ST_UNLOCKED) 231 - return 0; 232 - if (!list_empty(&gl->gl_holders)) 233 - return 0; 234 - if (glops->go_demote_ok) 235 - return glops->go_demote_ok(gl); 236 - return 1; 237 - } 238 - 239 - 240 - void gfs2_glock_add_to_lru(struct gfs2_glock *gl) 241 - { 242 - if (!(gl->gl_ops->go_flags & GLOF_LRU)) 243 - return; 244 - 245 223 spin_lock(&lru_lock); 246 - 247 224 list_move_tail(&gl->gl_lru, &lru_list); 248 225 249 226 if (!test_bit(GLF_LRU, &gl->gl_flags)) { ··· 231 258 232 259 static void gfs2_glock_remove_from_lru(struct gfs2_glock *gl) 233 260 { 234 - if (!(gl->gl_ops->go_flags & GLOF_LRU)) 235 - return; 236 - 237 261 spin_lock(&lru_lock); 238 262 if (test_bit(GLF_LRU, &gl->gl_flags)) { 239 263 list_del_init(&gl->gl_lru); ··· 245 275 * work queue. 246 276 */ 247 277 static void gfs2_glock_queue_work(struct gfs2_glock *gl, unsigned long delay) { 248 - if (!queue_delayed_work(glock_workqueue, &gl->gl_work, delay)) { 278 + struct gfs2_sbd *sdp = gl->gl_name.ln_sbd; 279 + 280 + if (!queue_delayed_work(sdp->sd_glock_wq, &gl->gl_work, delay)) { 249 281 /* 250 282 * We are holding the lockref spinlock, and the work was still 251 283 * queued above. The queued work (glock_work_func) takes that ··· 277 305 sdp->sd_lockstruct.ls_ops->lm_put_lock(gl); 278 306 } 279 307 308 + static bool __gfs2_glock_put_or_lock(struct gfs2_glock *gl) 309 + { 310 + if (lockref_put_or_lock(&gl->gl_lockref)) 311 + return true; 312 + GLOCK_BUG_ON(gl, gl->gl_lockref.count != 1); 313 + if (gl->gl_state != LM_ST_UNLOCKED) { 314 + gl->gl_lockref.count--; 315 + gfs2_glock_add_to_lru(gl); 316 + spin_unlock(&gl->gl_lockref.lock); 317 + return true; 318 + } 319 + return false; 320 + } 321 + 280 322 /** 281 323 * gfs2_glock_put() - Decrement reference count on glock 282 324 * @gl: The glock to put ··· 299 313 300 314 void gfs2_glock_put(struct gfs2_glock *gl) 301 315 { 302 - if (lockref_put_or_lock(&gl->gl_lockref)) 316 + if (__gfs2_glock_put_or_lock(gl)) 303 317 return; 304 318 305 319 __gfs2_glock_put(gl); ··· 314 328 */ 315 329 void gfs2_glock_put_async(struct gfs2_glock *gl) 316 330 { 317 - if (lockref_put_or_lock(&gl->gl_lockref)) 331 + if (__gfs2_glock_put_or_lock(gl)) 318 332 return; 319 333 320 - GLOCK_BUG_ON(gl, gl->gl_lockref.count != 1); 321 334 gfs2_glock_queue_work(gl, 0); 322 335 spin_unlock(&gl->gl_lockref.lock); 323 336 } ··· 555 570 556 571 static void state_change(struct gfs2_glock *gl, unsigned int new_state) 557 572 { 558 - int held1, held2; 559 - 560 - held1 = (gl->gl_state != LM_ST_UNLOCKED); 561 - held2 = (new_state != LM_ST_UNLOCKED); 562 - 563 - if (held1 != held2) { 564 - GLOCK_BUG_ON(gl, __lockref_is_dead(&gl->gl_lockref)); 565 - if (held2) 566 - gl->gl_lockref.count++; 567 - else 568 - gl->gl_lockref.count--; 569 - } 570 573 if (new_state != gl->gl_target) 571 574 /* shorten our minimum hold time */ 572 575 gl->gl_hold_time = max(gl->gl_hold_time - GL_GLOCK_HOLD_DECR, ··· 785 812 (target != LM_ST_UNLOCKED || 786 813 test_bit(SDF_WITHDRAW_RECOVERY, &sdp->sd_flags))) { 787 814 if (!is_system_glock(gl)) { 788 - handle_callback(gl, LM_ST_UNLOCKED, 0, false); /* sets demote */ 815 + request_demote(gl, LM_ST_UNLOCKED, 0, false); 789 816 /* 790 817 * Ordinarily, we would call dlm and its callback would call 791 818 * finish_xmote, which would call state_change() to the new state. ··· 883 910 out_unlock: 884 911 clear_bit(GLF_LOCK, &gl->gl_flags); 885 912 smp_mb__after_atomic(); 886 - return; 887 913 } 888 914 889 915 /** ··· 1083 1111 unsigned int drop_refs = 1; 1084 1112 1085 1113 spin_lock(&gl->gl_lockref.lock); 1086 - if (test_bit(GLF_REPLY_PENDING, &gl->gl_flags)) { 1087 - clear_bit(GLF_REPLY_PENDING, &gl->gl_flags); 1114 + if (test_bit(GLF_HAVE_REPLY, &gl->gl_flags)) { 1115 + clear_bit(GLF_HAVE_REPLY, &gl->gl_flags); 1088 1116 finish_xmote(gl, gl->gl_reply); 1089 1117 drop_refs++; 1090 1118 } 1091 1119 if (test_bit(GLF_PENDING_DEMOTE, &gl->gl_flags) && 1092 1120 gl->gl_state != LM_ST_UNLOCKED && 1093 1121 gl->gl_demote_state != LM_ST_EXCLUSIVE) { 1094 - unsigned long holdtime, now = jiffies; 1122 + if (gl->gl_name.ln_type == LM_TYPE_INODE) { 1123 + unsigned long holdtime, now = jiffies; 1095 1124 1096 - holdtime = gl->gl_tchange + gl->gl_hold_time; 1097 - if (time_before(now, holdtime)) 1098 - delay = holdtime - now; 1125 + holdtime = gl->gl_tchange + gl->gl_hold_time; 1126 + if (time_before(now, holdtime)) 1127 + delay = holdtime - now; 1128 + } 1099 1129 1100 1130 if (!delay) { 1101 1131 clear_bit(GLF_PENDING_DEMOTE, &gl->gl_flags); ··· 1108 1134 if (delay) { 1109 1135 /* Keep one glock reference for the work we requeue. */ 1110 1136 drop_refs--; 1111 - if (gl->gl_name.ln_type != LM_TYPE_INODE) 1112 - delay = 0; 1113 1137 gfs2_glock_queue_work(gl, delay); 1114 1138 } 1115 1139 1116 - /* 1117 - * Drop the remaining glock references manually here. (Mind that 1118 - * gfs2_glock_queue_work depends on the lockref spinlock begin held 1119 - * here as well.) 1120 - */ 1140 + /* Drop the remaining glock references manually. */ 1141 + GLOCK_BUG_ON(gl, gl->gl_lockref.count < drop_refs); 1121 1142 gl->gl_lockref.count -= drop_refs; 1122 1143 if (!gl->gl_lockref.count) { 1123 - __gfs2_glock_put(gl); 1124 - return; 1144 + if (gl->gl_state == LM_ST_UNLOCKED) { 1145 + __gfs2_glock_put(gl); 1146 + return; 1147 + } 1148 + gfs2_glock_add_to_lru(gl); 1125 1149 } 1126 1150 spin_unlock(&gl->gl_lockref.lock); 1127 1151 } ··· 1155 1183 out: 1156 1184 rcu_read_unlock(); 1157 1185 finish_wait(wq, &wait.wait); 1186 + if (gl) 1187 + gfs2_glock_remove_from_lru(gl); 1158 1188 return gl; 1159 1189 } 1160 1190 ··· 1183 1209 .ln_sbd = sdp }; 1184 1210 struct gfs2_glock *gl, *tmp; 1185 1211 struct address_space *mapping; 1186 - int ret = 0; 1187 1212 1188 1213 gl = find_insert_glock(&name, NULL); 1189 - if (gl) { 1190 - *glp = gl; 1191 - return 0; 1192 - } 1214 + if (gl) 1215 + goto found; 1193 1216 if (!create) 1194 1217 return -ENOENT; 1195 1218 ··· 1214 1243 1215 1244 atomic_inc(&sdp->sd_glock_disposal); 1216 1245 gl->gl_node.next = NULL; 1217 - gl->gl_flags = glops->go_instantiate ? BIT(GLF_INSTANTIATE_NEEDED) : 0; 1246 + gl->gl_flags = BIT(GLF_INITIAL); 1247 + if (glops->go_instantiate) 1248 + gl->gl_flags |= BIT(GLF_INSTANTIATE_NEEDED); 1218 1249 gl->gl_name = name; 1219 1250 lockdep_set_subclass(&gl->gl_lockref.lock, glops->go_subclass); 1220 1251 gl->gl_lockref.count = 1; ··· 1248 1275 } 1249 1276 1250 1277 tmp = find_insert_glock(&name, gl); 1251 - if (!tmp) { 1252 - *glp = gl; 1253 - goto out; 1254 - } 1255 - if (IS_ERR(tmp)) { 1256 - ret = PTR_ERR(tmp); 1257 - goto out_free; 1258 - } 1259 - *glp = tmp; 1278 + if (tmp) { 1279 + gfs2_glock_dealloc(&gl->gl_rcu); 1280 + if (atomic_dec_and_test(&sdp->sd_glock_disposal)) 1281 + wake_up(&sdp->sd_kill_wait); 1260 1282 1261 - out_free: 1262 - gfs2_glock_dealloc(&gl->gl_rcu); 1263 - if (atomic_dec_and_test(&sdp->sd_glock_disposal)) 1264 - wake_up(&sdp->sd_kill_wait); 1283 + if (IS_ERR(tmp)) 1284 + return PTR_ERR(tmp); 1285 + gl = tmp; 1286 + } 1265 1287 1266 - out: 1267 - return ret; 1288 + found: 1289 + *glp = gl; 1290 + return 0; 1268 1291 } 1269 1292 1270 1293 /** ··· 1430 1461 } 1431 1462 1432 1463 /** 1433 - * handle_callback - process a demote request 1464 + * request_demote - process a demote request 1434 1465 * @gl: the glock 1435 1466 * @state: the state the caller wants us to change to 1436 1467 * @delay: zero to demote immediately; otherwise pending demote ··· 1440 1471 * practise: LM_ST_SHARED and LM_ST_UNLOCKED 1441 1472 */ 1442 1473 1443 - static void handle_callback(struct gfs2_glock *gl, unsigned int state, 1444 - unsigned long delay, bool remote) 1474 + static void request_demote(struct gfs2_glock *gl, unsigned int state, 1475 + unsigned long delay, bool remote) 1445 1476 { 1446 1477 if (delay) 1447 1478 set_bit(GLF_PENDING_DEMOTE, &gl->gl_flags); ··· 1605 1636 return error; 1606 1637 } 1607 1638 1608 - if (test_bit(GLF_LRU, &gl->gl_flags)) 1609 - gfs2_glock_remove_from_lru(gl); 1610 - 1611 1639 gh->gh_error = 0; 1612 1640 spin_lock(&gl->gl_lockref.lock); 1613 1641 add_to_queue(gh); 1614 1642 if (unlikely((LM_FLAG_NOEXP & gh->gh_flags) && 1615 - test_and_clear_bit(GLF_FROZEN, &gl->gl_flags))) { 1616 - set_bit(GLF_REPLY_PENDING, &gl->gl_flags); 1643 + test_and_clear_bit(GLF_HAVE_FROZEN_REPLY, &gl->gl_flags))) { 1644 + set_bit(GLF_HAVE_REPLY, &gl->gl_flags); 1617 1645 gl->gl_lockref.count++; 1618 1646 gfs2_glock_queue_work(gl, 0); 1619 1647 } ··· 1654 1688 * below. 1655 1689 */ 1656 1690 if (gh->gh_flags & GL_NOCACHE) 1657 - handle_callback(gl, LM_ST_UNLOCKED, 0, false); 1691 + request_demote(gl, LM_ST_UNLOCKED, 0, false); 1658 1692 1659 1693 list_del_init(&gh->gh_list); 1660 1694 clear_bit(HIF_HOLDER, &gh->gh_iflags); ··· 1668 1702 if (list_empty(&gl->gl_holders)) 1669 1703 fast_path = 1; 1670 1704 } 1671 - 1672 - if (!test_bit(GLF_LFLUSH, &gl->gl_flags) && demote_ok(gl)) 1673 - gfs2_glock_add_to_lru(gl); 1674 1705 1675 1706 if (unlikely(!fast_path)) { 1676 1707 gl->gl_lockref.count++; ··· 1895 1932 gl->gl_name.ln_type == LM_TYPE_INODE) { 1896 1933 if (time_before(now, holdtime)) 1897 1934 delay = holdtime - now; 1898 - if (test_bit(GLF_REPLY_PENDING, &gl->gl_flags)) 1935 + if (test_bit(GLF_HAVE_REPLY, &gl->gl_flags)) 1899 1936 delay = gl->gl_hold_time; 1900 1937 } 1901 - handle_callback(gl, state, delay, true); 1938 + request_demote(gl, state, delay, true); 1902 1939 gfs2_glock_queue_work(gl, delay); 1903 1940 spin_unlock(&gl->gl_lockref.lock); 1904 1941 } ··· 1951 1988 1952 1989 if (unlikely(test_bit(DFL_BLOCK_LOCKS, &ls->ls_recover_flags))) { 1953 1990 if (gfs2_should_freeze(gl)) { 1954 - set_bit(GLF_FROZEN, &gl->gl_flags); 1991 + set_bit(GLF_HAVE_FROZEN_REPLY, &gl->gl_flags); 1955 1992 spin_unlock(&gl->gl_lockref.lock); 1956 1993 return; 1957 1994 } 1958 1995 } 1959 1996 1960 1997 gl->gl_lockref.count++; 1961 - set_bit(GLF_REPLY_PENDING, &gl->gl_flags); 1998 + set_bit(GLF_HAVE_REPLY, &gl->gl_flags); 1962 1999 gfs2_glock_queue_work(gl, 0); 1963 2000 spin_unlock(&gl->gl_lockref.lock); 1964 2001 } ··· 1981 2018 1982 2019 static bool can_free_glock(struct gfs2_glock *gl) 1983 2020 { 1984 - bool held = gl->gl_state != LM_ST_UNLOCKED; 2021 + struct gfs2_sbd *sdp = gl->gl_name.ln_sbd; 1985 2022 1986 2023 return !test_bit(GLF_LOCK, &gl->gl_flags) && 1987 - gl->gl_lockref.count == held; 2024 + !gl->gl_lockref.count && 2025 + (!test_bit(GLF_LFLUSH, &gl->gl_flags) || 2026 + test_bit(SDF_KILL, &sdp->sd_flags)); 1988 2027 } 1989 2028 1990 2029 /** ··· 2028 2063 clear_bit(GLF_LRU, &gl->gl_flags); 2029 2064 freed++; 2030 2065 gl->gl_lockref.count++; 2031 - if (demote_ok(gl)) 2032 - handle_callback(gl, LM_ST_UNLOCKED, 0, false); 2066 + if (gl->gl_state != LM_ST_UNLOCKED) 2067 + request_demote(gl, LM_ST_UNLOCKED, 0, false); 2033 2068 gfs2_glock_queue_work(gl, 0); 2034 2069 spin_unlock(&gl->gl_lockref.lock); 2035 2070 cond_resched_lock(&lru_lock); ··· 2147 2182 2148 2183 static void thaw_glock(struct gfs2_glock *gl) 2149 2184 { 2150 - if (!test_and_clear_bit(GLF_FROZEN, &gl->gl_flags)) 2185 + if (!test_and_clear_bit(GLF_HAVE_FROZEN_REPLY, &gl->gl_flags)) 2151 2186 return; 2152 2187 if (!lockref_get_not_dead(&gl->gl_lockref)) 2153 2188 return; 2154 2189 2190 + gfs2_glock_remove_from_lru(gl); 2155 2191 spin_lock(&gl->gl_lockref.lock); 2156 - set_bit(GLF_REPLY_PENDING, &gl->gl_flags); 2192 + set_bit(GLF_HAVE_REPLY, &gl->gl_flags); 2157 2193 gfs2_glock_queue_work(gl, 0); 2158 2194 spin_unlock(&gl->gl_lockref.lock); 2159 2195 } ··· 2173 2207 if (!__lockref_is_dead(&gl->gl_lockref)) { 2174 2208 gl->gl_lockref.count++; 2175 2209 if (gl->gl_state != LM_ST_UNLOCKED) 2176 - handle_callback(gl, LM_ST_UNLOCKED, 0, false); 2210 + request_demote(gl, LM_ST_UNLOCKED, 0, false); 2177 2211 gfs2_glock_queue_work(gl, 0); 2178 2212 } 2179 2213 spin_unlock(&gl->gl_lockref.lock); ··· 2225 2259 2226 2260 void gfs2_gl_hash_clear(struct gfs2_sbd *sdp) 2227 2261 { 2262 + unsigned long start = jiffies; 2263 + bool timed_out = false; 2264 + 2228 2265 set_bit(SDF_SKIP_DLM_UNLOCK, &sdp->sd_flags); 2229 - flush_workqueue(glock_workqueue); 2266 + flush_workqueue(sdp->sd_glock_wq); 2230 2267 glock_hash_walk(clear_glock, sdp); 2231 - flush_workqueue(glock_workqueue); 2232 - wait_event_timeout(sdp->sd_kill_wait, 2233 - atomic_read(&sdp->sd_glock_disposal) == 0, 2234 - HZ * 600); 2268 + flush_workqueue(sdp->sd_glock_wq); 2269 + 2270 + while (!timed_out) { 2271 + wait_event_timeout(sdp->sd_kill_wait, 2272 + !atomic_read(&sdp->sd_glock_disposal), 2273 + HZ * 60); 2274 + if (!atomic_read(&sdp->sd_glock_disposal)) 2275 + break; 2276 + timed_out = time_after(jiffies, start + (HZ * 600)); 2277 + fs_warn(sdp, "%u glocks left after %u seconds%s\n", 2278 + atomic_read(&sdp->sd_glock_disposal), 2279 + jiffies_to_msecs(jiffies - start) / 1000, 2280 + timed_out ? ":" : "; still waiting"); 2281 + } 2235 2282 gfs2_lm_unmount(sdp); 2236 2283 gfs2_free_dead_glocks(sdp); 2237 2284 glock_hash_walk(dump_glock_func, sdp); 2285 + destroy_workqueue(sdp->sd_glock_wq); 2238 2286 } 2239 2287 2240 2288 static const char *state2str(unsigned state) ··· 2346 2366 *p++ = 'f'; 2347 2367 if (test_bit(GLF_INVALIDATE_IN_PROGRESS, gflags)) 2348 2368 *p++ = 'i'; 2349 - if (test_bit(GLF_REPLY_PENDING, gflags)) 2369 + if (test_bit(GLF_HAVE_REPLY, gflags)) 2350 2370 *p++ = 'r'; 2351 2371 if (test_bit(GLF_INITIAL, gflags)) 2352 - *p++ = 'I'; 2353 - if (test_bit(GLF_FROZEN, gflags)) 2372 + *p++ = 'a'; 2373 + if (test_bit(GLF_HAVE_FROZEN_REPLY, gflags)) 2354 2374 *p++ = 'F'; 2355 2375 if (!list_empty(&gl->gl_holders)) 2356 2376 *p++ = 'q'; ··· 2360 2380 *p++ = 'o'; 2361 2381 if (test_bit(GLF_BLOCKING, gflags)) 2362 2382 *p++ = 'b'; 2363 - if (test_bit(GLF_FREEING, gflags)) 2383 + if (test_bit(GLF_UNLOCKED, gflags)) 2364 2384 *p++ = 'x'; 2365 2385 if (test_bit(GLF_INSTANTIATE_NEEDED, gflags)) 2366 2386 *p++ = 'n'; ··· 2513 2533 if (ret < 0) 2514 2534 return ret; 2515 2535 2516 - glock_workqueue = alloc_workqueue("glock_workqueue", WQ_MEM_RECLAIM | 2517 - WQ_HIGHPRI | WQ_FREEZABLE, 0); 2518 - if (!glock_workqueue) { 2519 - rhashtable_destroy(&gl_hash_table); 2520 - return -ENOMEM; 2521 - } 2522 - 2523 2536 glock_shrinker = shrinker_alloc(0, "gfs2-glock"); 2524 2537 if (!glock_shrinker) { 2525 - destroy_workqueue(glock_workqueue); 2526 2538 rhashtable_destroy(&gl_hash_table); 2527 2539 return -ENOMEM; 2528 2540 } ··· 2534 2562 { 2535 2563 shrinker_free(glock_shrinker); 2536 2564 rhashtable_destroy(&gl_hash_table); 2537 - destroy_workqueue(glock_workqueue); 2538 2565 } 2539 2566 2540 2567 static void gfs2_glock_iter_next(struct gfs2_glock_iter *gi, loff_t n)
-1
fs/gfs2/glock.h
··· 250 250 void gfs2_gl_hash_clear(struct gfs2_sbd *sdp); 251 251 void gfs2_gl_dq_holders(struct gfs2_sbd *sdp); 252 252 void gfs2_glock_thaw(struct gfs2_sbd *sdp); 253 - void gfs2_glock_add_to_lru(struct gfs2_glock *gl); 254 253 void gfs2_glock_free(struct gfs2_glock *gl); 255 254 void gfs2_glock_free_later(struct gfs2_glock *gl); 256 255
+12 -30
fs/gfs2/glops.c
··· 385 385 gfs2_clear_glop_pending(ip); 386 386 } 387 387 388 - /** 389 - * inode_go_demote_ok - Check to see if it's ok to unlock an inode glock 390 - * @gl: the glock 391 - * 392 - * Returns: 1 if it's ok 393 - */ 394 - 395 - static int inode_go_demote_ok(const struct gfs2_glock *gl) 396 - { 397 - struct gfs2_sbd *sdp = gl->gl_name.ln_sbd; 398 - 399 - if (sdp->sd_jindex == gl->gl_object || sdp->sd_rindex == gl->gl_object) 400 - return 0; 401 - 402 - return 1; 403 - } 404 - 405 388 static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf) 406 389 { 407 390 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); ··· 631 648 } 632 649 633 650 /** 634 - * inode_go_free - wake up anyone waiting for dlm's unlock ast to free it 635 - * @gl: glock being freed 651 + * inode_go_unlocked - wake up anyone waiting for dlm's unlock ast 652 + * @gl: glock being unlocked 636 653 * 637 654 * For now, this is only used for the journal inode glock. In withdraw 638 - * situations, we need to wait for the glock to be freed so that we know 655 + * situations, we need to wait for the glock to be unlocked so that we know 639 656 * other nodes may proceed with recovery / journal replay. 640 657 */ 641 - static void inode_go_free(struct gfs2_glock *gl) 658 + static void inode_go_unlocked(struct gfs2_glock *gl) 642 659 { 643 660 /* Note that we cannot reference gl_object because it's already set 644 661 * to NULL by this point in its lifecycle. */ 645 - if (!test_bit(GLF_FREEING, &gl->gl_flags)) 662 + if (!test_bit(GLF_UNLOCKED, &gl->gl_flags)) 646 663 return; 647 - clear_bit_unlock(GLF_FREEING, &gl->gl_flags); 648 - wake_up_bit(&gl->gl_flags, GLF_FREEING); 664 + clear_bit_unlock(GLF_UNLOCKED, &gl->gl_flags); 665 + wake_up_bit(&gl->gl_flags, GLF_UNLOCKED); 649 666 } 650 667 651 668 /** ··· 705 722 const struct gfs2_glock_operations gfs2_inode_glops = { 706 723 .go_sync = inode_go_sync, 707 724 .go_inval = inode_go_inval, 708 - .go_demote_ok = inode_go_demote_ok, 709 725 .go_instantiate = inode_go_instantiate, 710 726 .go_held = inode_go_held, 711 727 .go_dump = inode_go_dump, 712 728 .go_type = LM_TYPE_INODE, 713 - .go_flags = GLOF_ASPACE | GLOF_LRU | GLOF_LVB, 714 - .go_free = inode_go_free, 729 + .go_flags = GLOF_ASPACE | GLOF_LVB, 730 + .go_unlocked = inode_go_unlocked, 715 731 }; 716 732 717 733 const struct gfs2_glock_operations gfs2_rgrp_glops = { ··· 733 751 .go_type = LM_TYPE_IOPEN, 734 752 .go_callback = iopen_go_callback, 735 753 .go_dump = inode_go_dump, 736 - .go_flags = GLOF_LRU | GLOF_NONDISK, 754 + .go_flags = GLOF_NONDISK, 737 755 .go_subclass = 1, 738 756 }; 739 757 740 758 const struct gfs2_glock_operations gfs2_flock_glops = { 741 759 .go_type = LM_TYPE_FLOCK, 742 - .go_flags = GLOF_LRU | GLOF_NONDISK, 760 + .go_flags = GLOF_NONDISK, 743 761 }; 744 762 745 763 const struct gfs2_glock_operations gfs2_nondisk_glops = { ··· 750 768 751 769 const struct gfs2_glock_operations gfs2_quota_glops = { 752 770 .go_type = LM_TYPE_QUOTA, 753 - .go_flags = GLOF_LVB | GLOF_LRU | GLOF_NONDISK, 771 + .go_flags = GLOF_LVB | GLOF_NONDISK, 754 772 }; 755 773 756 774 const struct gfs2_glock_operations gfs2_journal_glops = {
+5 -7
fs/gfs2/incore.h
··· 218 218 int (*go_sync) (struct gfs2_glock *gl); 219 219 int (*go_xmote_bh)(struct gfs2_glock *gl); 220 220 void (*go_inval) (struct gfs2_glock *gl, int flags); 221 - int (*go_demote_ok) (const struct gfs2_glock *gl); 222 221 int (*go_instantiate) (struct gfs2_glock *gl); 223 222 int (*go_held)(struct gfs2_holder *gh); 224 223 void (*go_dump)(struct seq_file *seq, const struct gfs2_glock *gl, 225 224 const char *fs_id_buf); 226 225 void (*go_callback)(struct gfs2_glock *gl, bool remote); 227 - void (*go_free)(struct gfs2_glock *gl); 226 + void (*go_unlocked)(struct gfs2_glock *gl); 228 227 const int go_subclass; 229 228 const int go_type; 230 229 const unsigned long go_flags; 231 230 #define GLOF_ASPACE 1 /* address space attached */ 232 231 #define GLOF_LVB 2 /* Lock Value Block attached */ 233 - #define GLOF_LRU 4 /* LRU managed */ 234 232 #define GLOF_NONDISK 8 /* not I/O related */ 235 233 }; 236 234 ··· 320 322 GLF_DIRTY = 6, 321 323 GLF_LFLUSH = 7, 322 324 GLF_INVALIDATE_IN_PROGRESS = 8, 323 - GLF_REPLY_PENDING = 9, 325 + GLF_HAVE_REPLY = 9, 324 326 GLF_INITIAL = 10, 325 - GLF_FROZEN = 11, 327 + GLF_HAVE_FROZEN_REPLY = 11, 326 328 GLF_INSTANTIATE_IN_PROG = 12, /* instantiate happening now */ 327 329 GLF_LRU = 13, 328 330 GLF_OBJECT = 14, /* Used only for tracing */ 329 331 GLF_BLOCKING = 15, 330 - GLF_FREEING = 16, /* Wait for glock to be freed */ 332 + GLF_UNLOCKED = 16, /* Wait for glock to be unlocked */ 331 333 GLF_TRY_TO_EVICT = 17, /* iopen glocks only */ 332 334 GLF_VERIFY_EVICT = 18, /* iopen glocks only */ 333 335 }; ··· 770 772 771 773 /* Workqueue stuff */ 772 774 775 + struct workqueue_struct *sd_glock_wq; 773 776 struct workqueue_struct *sd_delete_wq; 774 777 775 778 /* Daemon stuff */ ··· 782 783 783 784 struct list_head sd_quota_list; 784 785 atomic_t sd_quota_count; 785 - struct mutex sd_quota_mutex; 786 786 struct mutex sd_quota_sync_mutex; 787 787 wait_queue_head_t sd_quota_wait; 788 788
+19 -9
fs/gfs2/lock_dlm.c
··· 134 134 135 135 switch (gl->gl_lksb.sb_status) { 136 136 case -DLM_EUNLOCK: /* Unlocked, so glock can be freed */ 137 - if (gl->gl_ops->go_free) 138 - gl->gl_ops->go_free(gl); 137 + if (gl->gl_ops->go_unlocked) 138 + gl->gl_ops->go_unlocked(gl); 139 139 gfs2_glock_free(gl); 140 140 return; 141 141 case -DLM_ECANCEL: /* Cancel while getting lock */ ··· 163 163 BUG(); 164 164 } 165 165 166 - set_bit(GLF_INITIAL, &gl->gl_flags); 166 + /* 167 + * The GLF_INITIAL flag is initially set for new glocks. Upon the 168 + * first successful new (non-conversion) request, we clear this flag to 169 + * indicate that a DLM lock exists and that gl->gl_lksb.sb_lkid is the 170 + * identifier to use for identifying it. 171 + * 172 + * Any failed initial requests do not create a DLM lock, so we ignore 173 + * the gl->gl_lksb.sb_lkid values that come with such requests. 174 + */ 175 + 176 + clear_bit(GLF_INITIAL, &gl->gl_flags); 167 177 gfs2_glock_complete(gl, ret); 168 178 return; 169 179 out: 170 - if (!test_bit(GLF_INITIAL, &gl->gl_flags)) 180 + if (test_bit(GLF_INITIAL, &gl->gl_flags)) 171 181 gl->gl_lksb.sb_lkid = 0; 172 182 gfs2_glock_complete(gl, ret); 173 183 } ··· 249 239 BUG(); 250 240 } 251 241 252 - if (gl->gl_lksb.sb_lkid != 0) { 242 + if (!test_bit(GLF_INITIAL, &gl->gl_flags)) { 253 243 lkf |= DLM_LKF_CONVERT; 254 244 if (test_bit(GLF_BLOCKING, &gl->gl_flags)) 255 245 lkf |= DLM_LKF_QUECVT; ··· 280 270 lkf = make_flags(gl, flags, req); 281 271 gfs2_glstats_inc(gl, GFS2_LKS_DCOUNT); 282 272 gfs2_sbstats_inc(gl, GFS2_LKS_DCOUNT); 283 - if (gl->gl_lksb.sb_lkid) { 284 - gfs2_update_request_times(gl); 285 - } else { 273 + if (test_bit(GLF_INITIAL, &gl->gl_flags)) { 286 274 memset(strname, ' ', GDLM_STRNAME_BYTES - 1); 287 275 strname[GDLM_STRNAME_BYTES - 1] = '\0'; 288 276 gfs2_reverse_hex(strname + 7, gl->gl_name.ln_type); 289 277 gfs2_reverse_hex(strname + 23, gl->gl_name.ln_number); 290 278 gl->gl_dstamp = ktime_get_real(); 279 + } else { 280 + gfs2_update_request_times(gl); 291 281 } 292 282 /* 293 283 * Submit the actual lock request. ··· 311 301 312 302 BUG_ON(!__lockref_is_dead(&gl->gl_lockref)); 313 303 314 - if (gl->gl_lksb.sb_lkid == 0) { 304 + if (test_bit(GLF_INITIAL, &gl->gl_flags)) { 315 305 gfs2_glock_free(gl); 316 306 return; 317 307 }
+10 -3
fs/gfs2/ops_fstype.c
··· 103 103 init_completion(&sdp->sd_journal_ready); 104 104 105 105 INIT_LIST_HEAD(&sdp->sd_quota_list); 106 - mutex_init(&sdp->sd_quota_mutex); 107 106 mutex_init(&sdp->sd_quota_sync_mutex); 108 107 init_waitqueue_head(&sdp->sd_quota_wait); 109 108 spin_lock_init(&sdp->sd_bitmap_lock); ··· 1187 1188 1188 1189 snprintf(sdp->sd_fsname, sizeof(sdp->sd_fsname), "%s", sdp->sd_table_name); 1189 1190 1191 + error = -ENOMEM; 1192 + sdp->sd_glock_wq = alloc_workqueue("gfs2-glock/%s", 1193 + WQ_MEM_RECLAIM | WQ_HIGHPRI | WQ_FREEZABLE, 0, 1194 + sdp->sd_fsname); 1195 + if (!sdp->sd_glock_wq) 1196 + goto fail_free; 1197 + 1190 1198 sdp->sd_delete_wq = alloc_workqueue("gfs2-delete/%s", 1191 1199 WQ_MEM_RECLAIM | WQ_FREEZABLE, 0, sdp->sd_fsname); 1192 - error = -ENOMEM; 1193 1200 if (!sdp->sd_delete_wq) 1194 - goto fail_free; 1201 + goto fail_glock_wq; 1195 1202 1196 1203 error = gfs2_sys_fs_add(sdp); 1197 1204 if (error) ··· 1306 1301 gfs2_sys_fs_del(sdp); 1307 1302 fail_delete_wq: 1308 1303 destroy_workqueue(sdp->sd_delete_wq); 1304 + fail_glock_wq: 1305 + destroy_workqueue(sdp->sd_glock_wq); 1309 1306 fail_free: 1310 1307 free_sbd(sdp); 1311 1308 sb->s_fs_info = NULL;
+200 -188
fs/gfs2/quota.c
··· 75 75 #define GFS2_QD_HASH_SIZE BIT(GFS2_QD_HASH_SHIFT) 76 76 #define GFS2_QD_HASH_MASK (GFS2_QD_HASH_SIZE - 1) 77 77 78 - #define QC_CHANGE 0 79 - #define QC_SYNC 1 80 - 81 78 /* Lock order: qd_lock -> bucket lock -> qd->lockref.lock -> lru lock */ 82 79 /* -> sd_bitmap_lock */ 83 80 static DEFINE_SPINLOCK(qd_lock); ··· 316 319 } 317 320 318 321 319 - static void qd_hold(struct gfs2_quota_data *qd) 322 + static void __qd_hold(struct gfs2_quota_data *qd) 320 323 { 321 324 struct gfs2_sbd *sdp = qd->qd_sbd; 322 - gfs2_assert(sdp, !__lockref_is_dead(&qd->qd_lockref)); 323 - lockref_get(&qd->qd_lockref); 325 + gfs2_assert(sdp, qd->qd_lockref.count > 0); 326 + qd->qd_lockref.count++; 324 327 } 325 328 326 329 static void qd_put(struct gfs2_quota_data *qd) ··· 397 400 struct inode *inode = sdp->sd_qc_inode; 398 401 struct gfs2_inode *ip = GFS2_I(inode); 399 402 unsigned int block, offset; 400 - struct buffer_head *bh; 403 + struct buffer_head *bh = NULL; 401 404 struct iomap iomap = { }; 402 405 int error; 403 406 404 - mutex_lock(&sdp->sd_quota_mutex); 405 - 406 - if (qd->qd_bh_count++) { 407 - mutex_unlock(&sdp->sd_quota_mutex); 407 + spin_lock(&qd->qd_lockref.lock); 408 + if (qd->qd_bh_count) { 409 + qd->qd_bh_count++; 410 + spin_unlock(&qd->qd_lockref.lock); 408 411 return 0; 409 412 } 413 + spin_unlock(&qd->qd_lockref.lock); 410 414 411 415 block = qd->qd_slot / sdp->sd_qc_per_block; 412 416 offset = qd->qd_slot % sdp->sd_qc_per_block; ··· 416 418 (loff_t)block << inode->i_blkbits, 417 419 i_blocksize(inode), &iomap); 418 420 if (error) 419 - goto fail; 421 + return error; 420 422 error = -ENOENT; 421 423 if (iomap.type != IOMAP_MAPPED) 422 - goto fail; 424 + return error; 423 425 424 426 error = gfs2_meta_read(ip->i_gl, iomap.addr >> inode->i_blkbits, 425 427 DIO_WAIT, 0, &bh); 426 428 if (error) 427 - goto fail; 429 + return error; 428 430 error = -EIO; 429 431 if (gfs2_metatype_check(sdp, bh, GFS2_METATYPE_QC)) 430 - goto fail_brelse; 432 + goto out; 431 433 432 - qd->qd_bh = bh; 433 - qd->qd_bh_qc = (struct gfs2_quota_change *) 434 - (bh->b_data + sizeof(struct gfs2_meta_header) + 435 - offset * sizeof(struct gfs2_quota_change)); 434 + spin_lock(&qd->qd_lockref.lock); 435 + if (qd->qd_bh == NULL) { 436 + qd->qd_bh = bh; 437 + qd->qd_bh_qc = (struct gfs2_quota_change *) 438 + (bh->b_data + sizeof(struct gfs2_meta_header) + 439 + offset * sizeof(struct gfs2_quota_change)); 440 + bh = NULL; 441 + } 442 + qd->qd_bh_count++; 443 + spin_unlock(&qd->qd_lockref.lock); 444 + error = 0; 436 445 437 - mutex_unlock(&sdp->sd_quota_mutex); 438 - 439 - return 0; 440 - 441 - fail_brelse: 446 + out: 442 447 brelse(bh); 443 - fail: 444 - qd->qd_bh_count--; 445 - mutex_unlock(&sdp->sd_quota_mutex); 446 448 return error; 447 449 } 448 450 449 451 static void bh_put(struct gfs2_quota_data *qd) 450 452 { 451 453 struct gfs2_sbd *sdp = qd->qd_sbd; 454 + struct buffer_head *bh = NULL; 452 455 453 - mutex_lock(&sdp->sd_quota_mutex); 456 + spin_lock(&qd->qd_lockref.lock); 454 457 gfs2_assert(sdp, qd->qd_bh_count); 455 458 if (!--qd->qd_bh_count) { 456 - brelse(qd->qd_bh); 459 + bh = qd->qd_bh; 457 460 qd->qd_bh = NULL; 458 461 qd->qd_bh_qc = NULL; 459 462 } 460 - mutex_unlock(&sdp->sd_quota_mutex); 463 + spin_unlock(&qd->qd_lockref.lock); 464 + brelse(bh); 461 465 } 462 466 463 - static int qd_check_sync(struct gfs2_sbd *sdp, struct gfs2_quota_data *qd, 464 - u64 *sync_gen) 467 + static bool qd_grab_sync(struct gfs2_sbd *sdp, struct gfs2_quota_data *qd, 468 + u64 sync_gen) 465 469 { 470 + bool ret = false; 471 + 472 + spin_lock(&qd->qd_lockref.lock); 466 473 if (test_bit(QDF_LOCKED, &qd->qd_flags) || 467 474 !test_bit(QDF_CHANGE, &qd->qd_flags) || 468 - (sync_gen && (qd->qd_sync_gen >= *sync_gen))) 469 - return 0; 475 + qd->qd_sync_gen >= sync_gen) 476 + goto out; 470 477 471 - /* 472 - * If qd_change is 0 it means a pending quota change was negated. 473 - * We should not sync it, but we still have a qd reference and slot 474 - * reference taken by gfs2_quota_change -> do_qc that need to be put. 475 - */ 476 - if (!qd->qd_change && test_and_clear_bit(QDF_CHANGE, &qd->qd_flags)) { 477 - slot_put(qd); 478 - qd_put(qd); 479 - return 0; 480 - } 481 - 482 - if (!lockref_get_not_dead(&qd->qd_lockref)) 483 - return 0; 478 + if (__lockref_is_dead(&qd->qd_lockref)) 479 + goto out; 480 + qd->qd_lockref.count++; 484 481 485 482 list_move_tail(&qd->qd_list, &sdp->sd_quota_list); 486 483 set_bit(QDF_LOCKED, &qd->qd_flags); 487 484 qd->qd_change_sync = qd->qd_change; 488 485 slot_hold(qd); 489 - return 1; 486 + ret = true; 487 + 488 + out: 489 + spin_unlock(&qd->qd_lockref.lock); 490 + return ret; 490 491 } 491 492 492 - static int qd_bh_get_or_undo(struct gfs2_sbd *sdp, struct gfs2_quota_data *qd) 493 + static void qd_ungrab_sync(struct gfs2_quota_data *qd) 493 494 { 494 - int error; 495 - 496 - error = bh_get(qd); 497 - if (!error) 498 - return 0; 499 - 500 495 clear_bit(QDF_LOCKED, &qd->qd_flags); 501 496 slot_put(qd); 502 497 qd_put(qd); 503 - return error; 504 - } 505 - 506 - static int qd_fish(struct gfs2_sbd *sdp, struct gfs2_quota_data **qdp) 507 - { 508 - struct gfs2_quota_data *qd = NULL, *iter; 509 - int error; 510 - 511 - *qdp = NULL; 512 - 513 - if (sb_rdonly(sdp->sd_vfs)) 514 - return 0; 515 - 516 - spin_lock(&qd_lock); 517 - 518 - list_for_each_entry(iter, &sdp->sd_quota_list, qd_list) { 519 - if (qd_check_sync(sdp, iter, &sdp->sd_quota_sync_gen)) { 520 - qd = iter; 521 - break; 522 - } 523 - } 524 - 525 - spin_unlock(&qd_lock); 526 - 527 - if (qd) { 528 - error = qd_bh_get_or_undo(sdp, qd); 529 - if (error) 530 - return error; 531 - *qdp = qd; 532 - } 533 - 534 - return 0; 535 498 } 536 499 537 500 static void qdsb_put(struct gfs2_quota_data *qd) ··· 504 545 505 546 static void qd_unlock(struct gfs2_quota_data *qd) 506 547 { 548 + spin_lock(&qd->qd_lockref.lock); 507 549 gfs2_assert_warn(qd->qd_sbd, test_bit(QDF_LOCKED, &qd->qd_flags)); 508 550 clear_bit(QDF_LOCKED, &qd->qd_flags); 551 + spin_unlock(&qd->qd_lockref.lock); 509 552 qdsb_put(qd); 510 553 } 511 554 ··· 671 710 return 0; 672 711 } 673 712 674 - static void do_qc(struct gfs2_quota_data *qd, s64 change, int qc_type) 713 + static void do_qc(struct gfs2_quota_data *qd, s64 change) 675 714 { 676 715 struct gfs2_sbd *sdp = qd->qd_sbd; 677 716 struct gfs2_inode *ip = GFS2_I(sdp->sd_qc_inode); 678 717 struct gfs2_quota_change *qc = qd->qd_bh_qc; 718 + bool needs_put = false; 679 719 s64 x; 680 720 681 - mutex_lock(&sdp->sd_quota_mutex); 682 721 gfs2_trans_add_meta(ip->i_gl, qd->qd_bh); 683 722 684 - if (!test_bit(QDF_CHANGE, &qd->qd_flags)) { 685 - qc->qc_change = 0; 723 + /* 724 + * The QDF_CHANGE flag indicates that the slot in the quota change file 725 + * is used. Here, we use the value of qc->qc_change when the slot is 726 + * used, and we assume a value of 0 otherwise. 727 + */ 728 + 729 + spin_lock(&qd->qd_lockref.lock); 730 + 731 + x = 0; 732 + if (test_bit(QDF_CHANGE, &qd->qd_flags)) 733 + x = be64_to_cpu(qc->qc_change); 734 + x += change; 735 + qd->qd_change += change; 736 + 737 + if (!x && test_bit(QDF_CHANGE, &qd->qd_flags)) { 738 + /* The slot in the quota change file becomes unused. */ 739 + clear_bit(QDF_CHANGE, &qd->qd_flags); 740 + qc->qc_flags = 0; 741 + qc->qc_id = 0; 742 + needs_put = true; 743 + } else if (x && !test_bit(QDF_CHANGE, &qd->qd_flags)) { 744 + /* The slot in the quota change file becomes used. */ 745 + set_bit(QDF_CHANGE, &qd->qd_flags); 746 + __qd_hold(qd); 747 + slot_hold(qd); 748 + 686 749 qc->qc_flags = 0; 687 750 if (qd->qd_id.type == USRQUOTA) 688 751 qc->qc_flags = cpu_to_be32(GFS2_QCF_USER); 689 752 qc->qc_id = cpu_to_be32(from_kqid(&init_user_ns, qd->qd_id)); 690 753 } 691 - 692 - x = be64_to_cpu(qc->qc_change) + change; 693 754 qc->qc_change = cpu_to_be64(x); 694 755 695 - spin_lock(&qd_lock); 696 - qd->qd_change = x; 697 - spin_unlock(&qd_lock); 756 + spin_unlock(&qd->qd_lockref.lock); 698 757 699 - if (qc_type == QC_CHANGE) { 700 - if (!test_and_set_bit(QDF_CHANGE, &qd->qd_flags)) { 701 - qd_hold(qd); 702 - slot_hold(qd); 703 - } 704 - } else { 705 - gfs2_assert_warn(sdp, test_bit(QDF_CHANGE, &qd->qd_flags)); 706 - clear_bit(QDF_CHANGE, &qd->qd_flags); 707 - qc->qc_flags = 0; 708 - qc->qc_id = 0; 758 + if (needs_put) { 709 759 slot_put(qd); 710 760 qd_put(qd); 711 761 } 712 - 713 762 if (change < 0) /* Reset quiet flag if we freed some blocks */ 714 763 clear_bit(QDF_QMSG_QUIET, &qd->qd_flags); 715 - mutex_unlock(&sdp->sd_quota_mutex); 716 764 } 717 765 718 766 static int gfs2_write_buf_to_page(struct gfs2_sbd *sdp, unsigned long index, ··· 860 890 be64_add_cpu(&q.qu_value, change); 861 891 if (((s64)be64_to_cpu(q.qu_value)) < 0) 862 892 q.qu_value = 0; /* Never go negative on quota usage */ 893 + spin_lock(&qd->qd_lockref.lock); 863 894 qd->qd_qb.qb_value = q.qu_value; 864 895 if (fdq) { 865 896 if (fdq->d_fieldmask & QC_SPC_SOFT) { ··· 876 905 qd->qd_qb.qb_value = q.qu_value; 877 906 } 878 907 } 908 + spin_unlock(&qd->qd_lockref.lock); 879 909 880 910 err = gfs2_write_disk_quota(sdp, &q, loc); 881 911 if (!err) { ··· 891 919 return err; 892 920 } 893 921 894 - static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda) 922 + static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda, 923 + u64 sync_gen) 895 924 { 896 925 struct gfs2_sbd *sdp = (*qda)->qd_sbd; 897 926 struct gfs2_inode *ip = GFS2_I(sdp->sd_quota_inode); ··· 965 992 if (error) 966 993 goto out_end_trans; 967 994 968 - do_qc(qd, -qd->qd_change_sync, QC_SYNC); 995 + do_qc(qd, -qd->qd_change_sync); 969 996 set_bit(QDF_REFRESH, &qd->qd_flags); 970 997 } 971 998 ··· 983 1010 gfs2_log_flush(ip->i_gl->gl_name.ln_sbd, ip->i_gl, 984 1011 GFS2_LOG_HEAD_FLUSH_NORMAL | GFS2_LFC_DO_SYNC); 985 1012 if (!error) { 986 - for (x = 0; x < num_qd; x++) 987 - qda[x]->qd_sync_gen = sdp->sd_quota_sync_gen; 1013 + for (x = 0; x < num_qd; x++) { 1014 + qd = qda[x]; 1015 + spin_lock(&qd->qd_lockref.lock); 1016 + if (qd->qd_sync_gen < sync_gen) 1017 + qd->qd_sync_gen = sync_gen; 1018 + spin_unlock(&qd->qd_lockref.lock); 1019 + } 988 1020 } 989 1021 return error; 990 1022 } ··· 1014 1036 qlvb->qb_limit = q.qu_limit; 1015 1037 qlvb->qb_warn = q.qu_warn; 1016 1038 qlvb->qb_value = q.qu_value; 1039 + spin_lock(&qd->qd_lockref.lock); 1017 1040 qd->qd_qb = *qlvb; 1041 + spin_unlock(&qd->qd_lockref.lock); 1018 1042 1019 1043 return 0; 1020 1044 } ··· 1038 1058 if (test_and_clear_bit(QDF_REFRESH, &qd->qd_flags)) 1039 1059 force_refresh = FORCE; 1040 1060 1061 + spin_lock(&qd->qd_lockref.lock); 1041 1062 qd->qd_qb = *(struct gfs2_quota_lvb *)qd->qd_gl->gl_lksb.sb_lvbptr; 1063 + spin_unlock(&qd->qd_lockref.lock); 1042 1064 1043 1065 if (force_refresh || qd->qd_qb.qb_magic != cpu_to_be32(GFS2_MAGIC)) { 1044 1066 gfs2_glock_dq_uninit(q_gh); ··· 1111 1129 { 1112 1130 struct gfs2_sbd *sdp = qd->qd_sbd; 1113 1131 struct gfs2_tune *gt = &sdp->sd_tune; 1114 - s64 value; 1132 + s64 value, change, limit; 1115 1133 unsigned int num, den; 1134 + int ret = false; 1116 1135 1136 + spin_lock(&qd->qd_lockref.lock); 1117 1137 if (!qd->qd_qb.qb_limit) 1118 - return false; 1138 + goto out; 1119 1139 1120 - spin_lock(&qd_lock); 1121 - value = qd->qd_change; 1122 - spin_unlock(&qd_lock); 1140 + change = qd->qd_change; 1141 + if (change <= 0) 1142 + goto out; 1143 + value = (s64)be64_to_cpu(qd->qd_qb.qb_value); 1144 + limit = (s64)be64_to_cpu(qd->qd_qb.qb_limit); 1145 + if (value >= limit) 1146 + goto out; 1123 1147 1124 1148 spin_lock(&gt->gt_spin); 1125 1149 num = gt->gt_quota_scale_num; 1126 1150 den = gt->gt_quota_scale_den; 1127 1151 spin_unlock(&gt->gt_spin); 1128 1152 1129 - if (value <= 0) 1130 - return false; 1131 - else if ((s64)be64_to_cpu(qd->qd_qb.qb_value) >= 1132 - (s64)be64_to_cpu(qd->qd_qb.qb_limit)) 1133 - return false; 1134 - else { 1135 - value *= gfs2_jindex_size(sdp) * num; 1136 - value = div_s64(value, den); 1137 - value += (s64)be64_to_cpu(qd->qd_qb.qb_value); 1138 - if (value < (s64)be64_to_cpu(qd->qd_qb.qb_limit)) 1139 - return false; 1140 - } 1153 + change *= gfs2_jindex_size(sdp) * num; 1154 + change = div_s64(change, den); 1155 + if (value + change < limit) 1156 + goto out; 1141 1157 1142 - return true; 1158 + ret = true; 1159 + out: 1160 + spin_unlock(&qd->qd_lockref.lock); 1161 + return ret; 1143 1162 } 1144 1163 1145 1164 void gfs2_quota_unlock(struct gfs2_inode *ip) ··· 1149 1166 struct gfs2_quota_data *qda[2 * GFS2_MAXQUOTAS]; 1150 1167 unsigned int count = 0; 1151 1168 u32 x; 1152 - int found; 1153 1169 1154 1170 if (!test_and_clear_bit(GIF_QD_LOCKED, &ip->i_flags)) 1155 1171 return; ··· 1156 1174 for (x = 0; x < ip->i_qadata->qa_qd_num; x++) { 1157 1175 struct gfs2_quota_data *qd; 1158 1176 bool sync; 1177 + int error; 1159 1178 1160 1179 qd = ip->i_qadata->qa_qd[x]; 1161 1180 sync = need_sync(qd); ··· 1166 1183 continue; 1167 1184 1168 1185 spin_lock(&qd_lock); 1169 - found = qd_check_sync(sdp, qd, NULL); 1186 + sync = qd_grab_sync(sdp, qd, U64_MAX); 1170 1187 spin_unlock(&qd_lock); 1171 1188 1172 - if (!found) 1189 + if (!sync) 1173 1190 continue; 1174 1191 1175 - if (!qd_bh_get_or_undo(sdp, qd)) 1176 - qda[count++] = qd; 1192 + gfs2_assert_warn(sdp, qd->qd_change_sync); 1193 + error = bh_get(qd); 1194 + if (error) { 1195 + qd_ungrab_sync(qd); 1196 + continue; 1197 + } 1198 + 1199 + qda[count++] = qd; 1177 1200 } 1178 1201 1179 1202 if (count) { 1180 - do_sync(count, qda); 1203 + u64 sync_gen = READ_ONCE(sdp->sd_quota_sync_gen); 1204 + 1205 + do_sync(count, qda, sync_gen); 1181 1206 for (x = 0; x < count; x++) 1182 1207 qd_unlock(qda[x]); 1183 1208 } ··· 1244 1253 qid_eq(qd->qd_id, make_kqid_gid(gid)))) 1245 1254 continue; 1246 1255 1256 + spin_lock(&qd->qd_lockref.lock); 1247 1257 warn = (s64)be64_to_cpu(qd->qd_qb.qb_warn); 1248 1258 limit = (s64)be64_to_cpu(qd->qd_qb.qb_limit); 1249 1259 value = (s64)be64_to_cpu(qd->qd_qb.qb_value); 1250 - spin_lock(&qd_lock); 1251 1260 value += qd->qd_change; 1252 - spin_unlock(&qd_lock); 1261 + spin_unlock(&qd->qd_lockref.lock); 1253 1262 1254 1263 if (limit > 0 && (limit - value) < ap->allowed) 1255 1264 ap->allowed = limit - value; ··· 1303 1312 1304 1313 if (qid_eq(qd->qd_id, make_kqid_uid(uid)) || 1305 1314 qid_eq(qd->qd_id, make_kqid_gid(gid))) { 1306 - do_qc(qd, change, QC_CHANGE); 1315 + do_qc(qd, change); 1307 1316 } 1308 1317 } 1309 - } 1310 - 1311 - static bool qd_changed(struct gfs2_sbd *sdp) 1312 - { 1313 - struct gfs2_quota_data *qd; 1314 - bool changed = false; 1315 - 1316 - spin_lock(&qd_lock); 1317 - list_for_each_entry(qd, &sdp->sd_quota_list, qd_list) { 1318 - if (test_bit(QDF_LOCKED, &qd->qd_flags) || 1319 - !test_bit(QDF_CHANGE, &qd->qd_flags)) 1320 - continue; 1321 - 1322 - changed = true; 1323 - break; 1324 - } 1325 - spin_unlock(&qd_lock); 1326 - return changed; 1327 1318 } 1328 1319 1329 1320 int gfs2_quota_sync(struct super_block *sb, int type) ··· 1313 1340 struct gfs2_sbd *sdp = sb->s_fs_info; 1314 1341 struct gfs2_quota_data **qda; 1315 1342 unsigned int max_qd = PAGE_SIZE / sizeof(struct gfs2_holder); 1316 - unsigned int num_qd; 1317 - unsigned int x; 1343 + u64 sync_gen; 1318 1344 int error = 0; 1319 1345 1320 - if (!qd_changed(sdp)) 1346 + if (sb_rdonly(sdp->sd_vfs)) 1321 1347 return 0; 1322 1348 1323 1349 qda = kcalloc(max_qd, sizeof(struct gfs2_quota_data *), GFP_KERNEL); ··· 1324 1352 return -ENOMEM; 1325 1353 1326 1354 mutex_lock(&sdp->sd_quota_sync_mutex); 1327 - sdp->sd_quota_sync_gen++; 1355 + sync_gen = sdp->sd_quota_sync_gen + 1; 1328 1356 1329 1357 do { 1330 - num_qd = 0; 1358 + struct gfs2_quota_data *iter; 1359 + unsigned int num_qd = 0; 1360 + unsigned int x; 1331 1361 1332 - for (;;) { 1333 - error = qd_fish(sdp, qda + num_qd); 1334 - if (error || !qda[num_qd]) 1335 - break; 1336 - if (++num_qd == max_qd) 1337 - break; 1362 + spin_lock(&qd_lock); 1363 + list_for_each_entry(iter, &sdp->sd_quota_list, qd_list) { 1364 + if (qd_grab_sync(sdp, iter, sync_gen)) { 1365 + qda[num_qd++] = iter; 1366 + if (num_qd == max_qd) 1367 + break; 1368 + } 1338 1369 } 1370 + spin_unlock(&qd_lock); 1339 1371 1340 - if (num_qd) { 1372 + if (!num_qd) 1373 + break; 1374 + 1375 + for (x = 0; x < num_qd; x++) { 1376 + error = bh_get(qda[x]); 1341 1377 if (!error) 1342 - error = do_sync(num_qd, qda); 1378 + continue; 1343 1379 1344 - for (x = 0; x < num_qd; x++) 1345 - qd_unlock(qda[x]); 1380 + while (x < num_qd) 1381 + qd_ungrab_sync(qda[--num_qd]); 1382 + break; 1346 1383 } 1347 - } while (!error && num_qd == max_qd); 1384 + 1385 + if (!error) { 1386 + WRITE_ONCE(sdp->sd_quota_sync_gen, sync_gen); 1387 + error = do_sync(num_qd, qda, sync_gen); 1388 + } 1389 + 1390 + for (x = 0; x < num_qd; x++) 1391 + qd_unlock(qda[x]); 1392 + } while (!error); 1348 1393 1349 1394 mutex_unlock(&sdp->sd_quota_sync_mutex); 1350 1395 kfree(qda); ··· 1396 1407 unsigned int found = 0; 1397 1408 unsigned int hash; 1398 1409 unsigned int bm_size; 1410 + struct buffer_head *bh; 1399 1411 u64 dblock; 1400 1412 u32 extlen = 0; 1401 1413 int error; ··· 1416 1426 return error; 1417 1427 1418 1428 for (x = 0; x < blocks; x++) { 1419 - struct buffer_head *bh; 1420 - const struct gfs2_quota_change *qc; 1429 + struct gfs2_quota_change *qc; 1421 1430 unsigned int y; 1422 1431 1423 1432 if (!extlen) { ··· 1429 1440 bh = gfs2_meta_ra(ip->i_gl, dblock, extlen); 1430 1441 if (!bh) 1431 1442 goto fail; 1432 - if (gfs2_metatype_check(sdp, bh, GFS2_METATYPE_QC)) { 1433 - brelse(bh); 1434 - goto fail; 1435 - } 1443 + if (gfs2_metatype_check(sdp, bh, GFS2_METATYPE_QC)) 1444 + goto fail_brelse; 1436 1445 1437 - qc = (const struct gfs2_quota_change *)(bh->b_data + sizeof(struct gfs2_meta_header)); 1446 + qc = (struct gfs2_quota_change *)(bh->b_data + sizeof(struct gfs2_meta_header)); 1438 1447 for (y = 0; y < sdp->sd_qc_per_block && slot < sdp->sd_quota_slots; 1439 1448 y++, slot++) { 1440 - struct gfs2_quota_data *qd; 1449 + struct gfs2_quota_data *old_qd, *qd; 1441 1450 s64 qc_change = be64_to_cpu(qc->qc_change); 1442 1451 u32 qc_flags = be32_to_cpu(qc->qc_flags); 1443 1452 enum quota_type qtype = (qc_flags & GFS2_QCF_USER) ? ··· 1448 1461 1449 1462 hash = gfs2_qd_hash(sdp, qc_id); 1450 1463 qd = qd_alloc(hash, sdp, qc_id); 1451 - if (qd == NULL) { 1452 - brelse(bh); 1453 - goto fail; 1454 - } 1464 + if (qd == NULL) 1465 + goto fail_brelse; 1455 1466 1456 1467 set_bit(QDF_CHANGE, &qd->qd_flags); 1457 1468 qd->qd_change = qc_change; ··· 1457 1472 qd->qd_slot_ref = 1; 1458 1473 1459 1474 spin_lock(&qd_lock); 1475 + spin_lock_bucket(hash); 1476 + old_qd = gfs2_qd_search_bucket(hash, sdp, qc_id); 1477 + if (old_qd) { 1478 + fs_err(sdp, "Corruption found in quota_change%u" 1479 + "file: duplicate identifier in " 1480 + "slot %u\n", 1481 + sdp->sd_jdesc->jd_jid, slot); 1482 + 1483 + spin_unlock_bucket(hash); 1484 + spin_unlock(&qd_lock); 1485 + qd_put(old_qd); 1486 + 1487 + gfs2_glock_put(qd->qd_gl); 1488 + kmem_cache_free(gfs2_quotad_cachep, qd); 1489 + 1490 + /* zero out the duplicate slot */ 1491 + lock_buffer(bh); 1492 + memset(qc, 0, sizeof(*qc)); 1493 + mark_buffer_dirty(bh); 1494 + unlock_buffer(bh); 1495 + 1496 + continue; 1497 + } 1460 1498 BUG_ON(test_and_set_bit(slot, sdp->sd_quota_bitmap)); 1461 1499 list_add(&qd->qd_list, &sdp->sd_quota_list); 1462 1500 atomic_inc(&sdp->sd_quota_count); 1463 - spin_unlock(&qd_lock); 1464 - 1465 - spin_lock_bucket(hash); 1466 1501 hlist_bl_add_head_rcu(&qd->qd_hlist, &qd_hash_table[hash]); 1467 1502 spin_unlock_bucket(hash); 1503 + spin_unlock(&qd_lock); 1468 1504 1469 1505 found++; 1470 1506 } 1471 1507 1508 + if (buffer_dirty(bh)) 1509 + sync_dirty_buffer(bh); 1472 1510 brelse(bh); 1473 1511 dblock++; 1474 1512 extlen--; ··· 1502 1494 1503 1495 return 0; 1504 1496 1497 + fail_brelse: 1498 + if (buffer_dirty(bh)) 1499 + sync_dirty_buffer(bh); 1500 + brelse(bh); 1505 1501 fail: 1506 1502 gfs2_quota_cleanup(sdp); 1507 1503 return error;
-1
fs/gfs2/super.c
··· 1524 1524 if (ip->i_gl) { 1525 1525 glock_clear_object(ip->i_gl, ip); 1526 1526 wait_on_bit_io(&ip->i_flags, GIF_GLOP_PENDING, TASK_UNINTERRUPTIBLE); 1527 - gfs2_glock_add_to_lru(ip->i_gl); 1528 1527 gfs2_glock_put_eventually(ip->i_gl); 1529 1528 rcu_assign_pointer(ip->i_gl, NULL); 1530 1529 }
+3 -3
fs/gfs2/trace_gfs2.h
··· 53 53 {(1UL << GLF_DIRTY), "y" }, \ 54 54 {(1UL << GLF_LFLUSH), "f" }, \ 55 55 {(1UL << GLF_INVALIDATE_IN_PROGRESS), "i" }, \ 56 - {(1UL << GLF_REPLY_PENDING), "r" }, \ 57 - {(1UL << GLF_INITIAL), "I" }, \ 58 - {(1UL << GLF_FROZEN), "F" }, \ 56 + {(1UL << GLF_HAVE_REPLY), "r" }, \ 57 + {(1UL << GLF_INITIAL), "a" }, \ 58 + {(1UL << GLF_HAVE_FROZEN_REPLY), "F" }, \ 59 59 {(1UL << GLF_LRU), "L" }, \ 60 60 {(1UL << GLF_OBJECT), "o" }, \ 61 61 {(1UL << GLF_BLOCKING), "b" })
+6 -6
fs/gfs2/util.c
··· 99 99 */ 100 100 int gfs2_freeze_lock_shared(struct gfs2_sbd *sdp) 101 101 { 102 + int flags = LM_FLAG_NOEXP | GL_EXACT; 102 103 int error; 103 104 104 - error = gfs2_glock_nq_init(sdp->sd_freeze_gl, LM_ST_SHARED, 105 - LM_FLAG_NOEXP | GL_EXACT, 105 + error = gfs2_glock_nq_init(sdp->sd_freeze_gl, LM_ST_SHARED, flags, 106 106 &sdp->sd_freeze_gh); 107 - if (error) 107 + if (error && error != GLR_TRYFAILED) 108 108 fs_err(sdp, "can't lock the freeze glock: %d\n", error); 109 109 return error; 110 110 } ··· 206 206 * on other nodes to be successful, otherwise we remain the owner of 207 207 * the glock as far as dlm is concerned. 208 208 */ 209 - if (i_gl->gl_ops->go_free) { 210 - set_bit(GLF_FREEING, &i_gl->gl_flags); 211 - wait_on_bit(&i_gl->gl_flags, GLF_FREEING, TASK_UNINTERRUPTIBLE); 209 + if (i_gl->gl_ops->go_unlocked) { 210 + set_bit(GLF_UNLOCKED, &i_gl->gl_flags); 211 + wait_on_bit(&i_gl->gl_flags, GLF_UNLOCKED, TASK_UNINTERRUPTIBLE); 212 212 } 213 213 214 214 /*