aboutsummaryrefslogtreecommitdiffstats
path: root/fs/gfs2/glock.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/gfs2/glock.c')
-rw-r--r--fs/gfs2/glock.c249
1 files changed, 75 insertions, 174 deletions
diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c
index 6b983aef785d..cd200a564c79 100644
--- a/fs/gfs2/glock.c
+++ b/fs/gfs2/glock.c
@@ -10,7 +10,6 @@
10#include <linux/sched.h> 10#include <linux/sched.h>
11#include <linux/slab.h> 11#include <linux/slab.h>
12#include <linux/spinlock.h> 12#include <linux/spinlock.h>
13#include <linux/completion.h>
14#include <linux/buffer_head.h> 13#include <linux/buffer_head.h>
15#include <linux/delay.h> 14#include <linux/delay.h>
16#include <linux/sort.h> 15#include <linux/sort.h>
@@ -18,7 +17,6 @@
18#include <linux/kallsyms.h> 17#include <linux/kallsyms.h>
19#include <linux/gfs2_ondisk.h> 18#include <linux/gfs2_ondisk.h>
20#include <linux/list.h> 19#include <linux/list.h>
21#include <linux/lm_interface.h>
22#include <linux/wait.h> 20#include <linux/wait.h>
23#include <linux/module.h> 21#include <linux/module.h>
24#include <linux/rwsem.h> 22#include <linux/rwsem.h>
@@ -155,13 +153,10 @@ static void glock_free(struct gfs2_glock *gl)
155 struct gfs2_sbd *sdp = gl->gl_sbd; 153 struct gfs2_sbd *sdp = gl->gl_sbd;
156 struct inode *aspace = gl->gl_aspace; 154 struct inode *aspace = gl->gl_aspace;
157 155
158 if (sdp->sd_lockstruct.ls_ops->lm_put_lock)
159 sdp->sd_lockstruct.ls_ops->lm_put_lock(gl->gl_lock);
160
161 if (aspace) 156 if (aspace)
162 gfs2_aspace_put(aspace); 157 gfs2_aspace_put(aspace);
163 158
164 kmem_cache_free(gfs2_glock_cachep, gl); 159 sdp->sd_lockstruct.ls_ops->lm_put_lock(gfs2_glock_cachep, gl);
165} 160}
166 161
167/** 162/**
@@ -211,7 +206,6 @@ int gfs2_glock_put(struct gfs2_glock *gl)
211 atomic_dec(&lru_count); 206 atomic_dec(&lru_count);
212 } 207 }
213 spin_unlock(&lru_lock); 208 spin_unlock(&lru_lock);
214 GLOCK_BUG_ON(gl, gl->gl_state != LM_ST_UNLOCKED);
215 GLOCK_BUG_ON(gl, !list_empty(&gl->gl_lru)); 209 GLOCK_BUG_ON(gl, !list_empty(&gl->gl_lru));
216 GLOCK_BUG_ON(gl, !list_empty(&gl->gl_holders)); 210 GLOCK_BUG_ON(gl, !list_empty(&gl->gl_holders));
217 glock_free(gl); 211 glock_free(gl);
@@ -256,27 +250,6 @@ static struct gfs2_glock *search_bucket(unsigned int hash,
256} 250}
257 251
258/** 252/**
259 * gfs2_glock_find() - Find glock by lock number
260 * @sdp: The GFS2 superblock
261 * @name: The lock name
262 *
263 * Returns: NULL, or the struct gfs2_glock with the requested number
264 */
265
266static struct gfs2_glock *gfs2_glock_find(const struct gfs2_sbd *sdp,
267 const struct lm_lockname *name)
268{
269 unsigned int hash = gl_hash(sdp, name);
270 struct gfs2_glock *gl;
271
272 read_lock(gl_lock_addr(hash));
273 gl = search_bucket(hash, sdp, name);
274 read_unlock(gl_lock_addr(hash));
275
276 return gl;
277}
278
279/**
280 * may_grant - check if its ok to grant a new lock 253 * may_grant - check if its ok to grant a new lock
281 * @gl: The glock 254 * @gl: The glock
282 * @gh: The lock request which we wish to grant 255 * @gh: The lock request which we wish to grant
@@ -523,7 +496,7 @@ out_locked:
523} 496}
524 497
525static unsigned int gfs2_lm_lock(struct gfs2_sbd *sdp, void *lock, 498static unsigned int gfs2_lm_lock(struct gfs2_sbd *sdp, void *lock,
526 unsigned int cur_state, unsigned int req_state, 499 unsigned int req_state,
527 unsigned int flags) 500 unsigned int flags)
528{ 501{
529 int ret = LM_OUT_ERROR; 502 int ret = LM_OUT_ERROR;
@@ -532,7 +505,7 @@ static unsigned int gfs2_lm_lock(struct gfs2_sbd *sdp, void *lock,
532 return req_state == LM_ST_UNLOCKED ? 0 : req_state; 505 return req_state == LM_ST_UNLOCKED ? 0 : req_state;
533 506
534 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) 507 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
535 ret = sdp->sd_lockstruct.ls_ops->lm_lock(lock, cur_state, 508 ret = sdp->sd_lockstruct.ls_ops->lm_lock(lock,
536 req_state, flags); 509 req_state, flags);
537 return ret; 510 return ret;
538} 511}
@@ -575,7 +548,7 @@ __acquires(&gl->gl_spin)
575 gl->gl_state == LM_ST_DEFERRED) && 548 gl->gl_state == LM_ST_DEFERRED) &&
576 !(lck_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB))) 549 !(lck_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB)))
577 lck_flags |= LM_FLAG_TRY_1CB; 550 lck_flags |= LM_FLAG_TRY_1CB;
578 ret = gfs2_lm_lock(sdp, gl->gl_lock, gl->gl_state, target, lck_flags); 551 ret = gfs2_lm_lock(sdp, gl, target, lck_flags);
579 552
580 if (!(ret & LM_OUT_ASYNC)) { 553 if (!(ret & LM_OUT_ASYNC)) {
581 finish_xmote(gl, ret); 554 finish_xmote(gl, ret);
@@ -681,18 +654,6 @@ static void glock_work_func(struct work_struct *work)
681 gfs2_glock_put(gl); 654 gfs2_glock_put(gl);
682} 655}
683 656
684static int gfs2_lm_get_lock(struct gfs2_sbd *sdp, struct lm_lockname *name,
685 void **lockp)
686{
687 int error = -EIO;
688 if (!sdp->sd_lockstruct.ls_ops->lm_get_lock)
689 return 0;
690 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
691 error = sdp->sd_lockstruct.ls_ops->lm_get_lock(
692 sdp->sd_lockstruct.ls_lockspace, name, lockp);
693 return error;
694}
695
696/** 657/**
697 * gfs2_glock_get() - Get a glock, or create one if one doesn't exist 658 * gfs2_glock_get() - Get a glock, or create one if one doesn't exist
698 * @sdp: The GFS2 superblock 659 * @sdp: The GFS2 superblock
@@ -736,6 +697,9 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
736 gl->gl_demote_state = LM_ST_EXCLUSIVE; 697 gl->gl_demote_state = LM_ST_EXCLUSIVE;
737 gl->gl_hash = hash; 698 gl->gl_hash = hash;
738 gl->gl_ops = glops; 699 gl->gl_ops = glops;
700 snprintf(gl->gl_strname, GDLM_STRNAME_BYTES, "%8x%16llx", name.ln_type, (unsigned long long)number);
701 memset(&gl->gl_lksb, 0, sizeof(struct dlm_lksb));
702 gl->gl_lksb.sb_lvbptr = gl->gl_lvb;
739 gl->gl_stamp = jiffies; 703 gl->gl_stamp = jiffies;
740 gl->gl_tchange = jiffies; 704 gl->gl_tchange = jiffies;
741 gl->gl_object = NULL; 705 gl->gl_object = NULL;
@@ -753,10 +717,6 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
753 } 717 }
754 } 718 }
755 719
756 error = gfs2_lm_get_lock(sdp, &name, &gl->gl_lock);
757 if (error)
758 goto fail_aspace;
759
760 write_lock(gl_lock_addr(hash)); 720 write_lock(gl_lock_addr(hash));
761 tmp = search_bucket(hash, sdp, &name); 721 tmp = search_bucket(hash, sdp, &name);
762 if (tmp) { 722 if (tmp) {
@@ -772,9 +732,6 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
772 732
773 return 0; 733 return 0;
774 734
775fail_aspace:
776 if (gl->gl_aspace)
777 gfs2_aspace_put(gl->gl_aspace);
778fail: 735fail:
779 kmem_cache_free(gfs2_glock_cachep, gl); 736 kmem_cache_free(gfs2_glock_cachep, gl);
780 return error; 737 return error;
@@ -966,7 +923,7 @@ do_cancel:
966 if (!(gh->gh_flags & LM_FLAG_PRIORITY)) { 923 if (!(gh->gh_flags & LM_FLAG_PRIORITY)) {
967 spin_unlock(&gl->gl_spin); 924 spin_unlock(&gl->gl_spin);
968 if (sdp->sd_lockstruct.ls_ops->lm_cancel) 925 if (sdp->sd_lockstruct.ls_ops->lm_cancel)
969 sdp->sd_lockstruct.ls_ops->lm_cancel(gl->gl_lock); 926 sdp->sd_lockstruct.ls_ops->lm_cancel(gl);
970 spin_lock(&gl->gl_spin); 927 spin_lock(&gl->gl_spin);
971 } 928 }
972 return; 929 return;
@@ -1240,70 +1197,13 @@ void gfs2_glock_dq_uninit_m(unsigned int num_gh, struct gfs2_holder *ghs)
1240 gfs2_glock_dq_uninit(&ghs[x]); 1197 gfs2_glock_dq_uninit(&ghs[x]);
1241} 1198}
1242 1199
1243static int gfs2_lm_hold_lvb(struct gfs2_sbd *sdp, void *lock, char **lvbp) 1200void gfs2_glock_cb(struct gfs2_glock *gl, unsigned int state)
1244{ 1201{
1245 int error = -EIO;
1246 if (!sdp->sd_lockstruct.ls_ops->lm_hold_lvb)
1247 return 0;
1248 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
1249 error = sdp->sd_lockstruct.ls_ops->lm_hold_lvb(lock, lvbp);
1250 return error;
1251}
1252
1253/**
1254 * gfs2_lvb_hold - attach a LVB from a glock
1255 * @gl: The glock in question
1256 *
1257 */
1258
1259int gfs2_lvb_hold(struct gfs2_glock *gl)
1260{
1261 int error;
1262
1263 if (!atomic_read(&gl->gl_lvb_count)) {
1264 error = gfs2_lm_hold_lvb(gl->gl_sbd, gl->gl_lock, &gl->gl_lvb);
1265 if (error)
1266 return error;
1267 gfs2_glock_hold(gl);
1268 }
1269 atomic_inc(&gl->gl_lvb_count);
1270
1271 return 0;
1272}
1273
1274/**
1275 * gfs2_lvb_unhold - detach a LVB from a glock
1276 * @gl: The glock in question
1277 *
1278 */
1279
1280void gfs2_lvb_unhold(struct gfs2_glock *gl)
1281{
1282 struct gfs2_sbd *sdp = gl->gl_sbd;
1283
1284 gfs2_glock_hold(gl);
1285 gfs2_assert(gl->gl_sbd, atomic_read(&gl->gl_lvb_count) > 0);
1286 if (atomic_dec_and_test(&gl->gl_lvb_count)) {
1287 if (sdp->sd_lockstruct.ls_ops->lm_unhold_lvb)
1288 sdp->sd_lockstruct.ls_ops->lm_unhold_lvb(gl->gl_lock, gl->gl_lvb);
1289 gl->gl_lvb = NULL;
1290 gfs2_glock_put(gl);
1291 }
1292 gfs2_glock_put(gl);
1293}
1294
1295static void blocking_cb(struct gfs2_sbd *sdp, struct lm_lockname *name,
1296 unsigned int state)
1297{
1298 struct gfs2_glock *gl;
1299 unsigned long delay = 0; 1202 unsigned long delay = 0;
1300 unsigned long holdtime; 1203 unsigned long holdtime;
1301 unsigned long now = jiffies; 1204 unsigned long now = jiffies;
1302 1205
1303 gl = gfs2_glock_find(sdp, name); 1206 gfs2_glock_hold(gl);
1304 if (!gl)
1305 return;
1306
1307 holdtime = gl->gl_tchange + gl->gl_ops->go_min_hold_time; 1207 holdtime = gl->gl_tchange + gl->gl_ops->go_min_hold_time;
1308 if (time_before(now, holdtime)) 1208 if (time_before(now, holdtime))
1309 delay = holdtime - now; 1209 delay = holdtime - now;
@@ -1317,74 +1217,37 @@ static void blocking_cb(struct gfs2_sbd *sdp, struct lm_lockname *name,
1317 gfs2_glock_put(gl); 1217 gfs2_glock_put(gl);
1318} 1218}
1319 1219
1320static void gfs2_jdesc_make_dirty(struct gfs2_sbd *sdp, unsigned int jid)
1321{
1322 struct gfs2_jdesc *jd;
1323
1324 spin_lock(&sdp->sd_jindex_spin);
1325 list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) {
1326 if (jd->jd_jid != jid)
1327 continue;
1328 jd->jd_dirty = 1;
1329 break;
1330 }
1331 spin_unlock(&sdp->sd_jindex_spin);
1332}
1333
1334/** 1220/**
1335 * gfs2_glock_cb - Callback used by locking module 1221 * gfs2_glock_complete - Callback used by locking
1336 * @sdp: Pointer to the superblock 1222 * @gl: Pointer to the glock
1337 * @type: Type of callback 1223 * @ret: The return value from the dlm
1338 * @data: Type dependent data pointer
1339 * 1224 *
1340 * Called by the locking module when it wants to tell us something.
1341 * Either we need to drop a lock, one of our ASYNC requests completed, or
1342 * a journal from another client needs to be recovered.
1343 */ 1225 */
1344 1226
1345void gfs2_glock_cb(void *cb_data, unsigned int type, void *data) 1227void gfs2_glock_complete(struct gfs2_glock *gl, int ret)
1346{ 1228{
1347 struct gfs2_sbd *sdp = cb_data; 1229 struct lm_lockstruct *ls = &gl->gl_sbd->sd_lockstruct;
1348 1230 down_read(&gfs2_umount_flush_sem);
1349 switch (type) { 1231 gl->gl_reply = ret;
1350 case LM_CB_NEED_E: 1232 if (unlikely(test_bit(DFL_BLOCK_LOCKS, &ls->ls_flags))) {
1351 blocking_cb(sdp, data, LM_ST_UNLOCKED); 1233 struct gfs2_holder *gh;
1352 return; 1234 spin_lock(&gl->gl_spin);
1353 1235 gh = find_first_waiter(gl);
1354 case LM_CB_NEED_D: 1236 if ((!(gh && (gh->gh_flags & LM_FLAG_NOEXP)) &&
1355 blocking_cb(sdp, data, LM_ST_DEFERRED); 1237 (gl->gl_target != LM_ST_UNLOCKED)) ||
1356 return; 1238 ((ret & ~LM_OUT_ST_MASK) != 0))
1357 1239 set_bit(GLF_FROZEN, &gl->gl_flags);
1358 case LM_CB_NEED_S: 1240 spin_unlock(&gl->gl_spin);
1359 blocking_cb(sdp, data, LM_ST_SHARED); 1241 if (test_bit(GLF_FROZEN, &gl->gl_flags)) {
1360 return; 1242 up_read(&gfs2_umount_flush_sem);
1361
1362 case LM_CB_ASYNC: {
1363 struct lm_async_cb *async = data;
1364 struct gfs2_glock *gl;
1365
1366 down_read(&gfs2_umount_flush_sem);
1367 gl = gfs2_glock_find(sdp, &async->lc_name);
1368 if (gfs2_assert_warn(sdp, gl))
1369 return; 1243 return;
1370 gl->gl_reply = async->lc_ret; 1244 }
1371 set_bit(GLF_REPLY_PENDING, &gl->gl_flags);
1372 if (queue_delayed_work(glock_workqueue, &gl->gl_work, 0) == 0)
1373 gfs2_glock_put(gl);
1374 up_read(&gfs2_umount_flush_sem);
1375 return;
1376 }
1377
1378 case LM_CB_NEED_RECOVERY:
1379 gfs2_jdesc_make_dirty(sdp, *(unsigned int *)data);
1380 if (sdp->sd_recoverd_process)
1381 wake_up_process(sdp->sd_recoverd_process);
1382 return;
1383
1384 default:
1385 gfs2_assert_warn(sdp, 0);
1386 return;
1387 } 1245 }
1246 set_bit(GLF_REPLY_PENDING, &gl->gl_flags);
1247 gfs2_glock_hold(gl);
1248 if (queue_delayed_work(glock_workqueue, &gl->gl_work, 0) == 0)
1249 gfs2_glock_put(gl);
1250 up_read(&gfs2_umount_flush_sem);
1388} 1251}
1389 1252
1390/** 1253/**
@@ -1515,6 +1378,27 @@ out:
1515 return has_entries; 1378 return has_entries;
1516} 1379}
1517 1380
1381
1382/**
1383 * thaw_glock - thaw out a glock which has an unprocessed reply waiting
1384 * @gl: The glock to thaw
1385 *
1386 * N.B. When we freeze a glock, we leave a ref to the glock outstanding,
1387 * so this has to result in the ref count being dropped by one.
1388 */
1389
1390static void thaw_glock(struct gfs2_glock *gl)
1391{
1392 if (!test_and_clear_bit(GLF_FROZEN, &gl->gl_flags))
1393 return;
1394 down_read(&gfs2_umount_flush_sem);
1395 set_bit(GLF_REPLY_PENDING, &gl->gl_flags);
1396 gfs2_glock_hold(gl);
1397 if (queue_delayed_work(glock_workqueue, &gl->gl_work, 0) == 0)
1398 gfs2_glock_put(gl);
1399 up_read(&gfs2_umount_flush_sem);
1400}
1401
1518/** 1402/**
1519 * clear_glock - look at a glock and see if we can free it from glock cache 1403 * clear_glock - look at a glock and see if we can free it from glock cache
1520 * @gl: the glock to look at 1404 * @gl: the glock to look at
@@ -1540,6 +1424,20 @@ static void clear_glock(struct gfs2_glock *gl)
1540} 1424}
1541 1425
1542/** 1426/**
1427 * gfs2_glock_thaw - Thaw any frozen glocks
1428 * @sdp: The super block
1429 *
1430 */
1431
1432void gfs2_glock_thaw(struct gfs2_sbd *sdp)
1433{
1434 unsigned x;
1435
1436 for (x = 0; x < GFS2_GL_HASH_SIZE; x++)
1437 examine_bucket(thaw_glock, sdp, x);
1438}
1439
1440/**
1543 * gfs2_gl_hash_clear - Empty out the glock hash table 1441 * gfs2_gl_hash_clear - Empty out the glock hash table
1544 * @sdp: the filesystem 1442 * @sdp: the filesystem
1545 * @wait: wait until it's all gone 1443 * @wait: wait until it's all gone
@@ -1619,7 +1517,7 @@ static const char *hflags2str(char *buf, unsigned flags, unsigned long iflags)
1619 if (flags & LM_FLAG_NOEXP) 1517 if (flags & LM_FLAG_NOEXP)
1620 *p++ = 'e'; 1518 *p++ = 'e';
1621 if (flags & LM_FLAG_ANY) 1519 if (flags & LM_FLAG_ANY)
1622 *p++ = 'a'; 1520 *p++ = 'A';
1623 if (flags & LM_FLAG_PRIORITY) 1521 if (flags & LM_FLAG_PRIORITY)
1624 *p++ = 'p'; 1522 *p++ = 'p';
1625 if (flags & GL_ASYNC) 1523 if (flags & GL_ASYNC)
@@ -1683,6 +1581,10 @@ static const char *gflags2str(char *buf, const unsigned long *gflags)
1683 *p++ = 'i'; 1581 *p++ = 'i';
1684 if (test_bit(GLF_REPLY_PENDING, gflags)) 1582 if (test_bit(GLF_REPLY_PENDING, gflags))
1685 *p++ = 'r'; 1583 *p++ = 'r';
1584 if (test_bit(GLF_INITIAL, gflags))
1585 *p++ = 'i';
1586 if (test_bit(GLF_FROZEN, gflags))
1587 *p++ = 'F';
1686 *p = 0; 1588 *p = 0;
1687 return buf; 1589 return buf;
1688} 1590}
@@ -1717,14 +1619,13 @@ static int __dump_glock(struct seq_file *seq, const struct gfs2_glock *gl)
1717 dtime *= 1000000/HZ; /* demote time in uSec */ 1619 dtime *= 1000000/HZ; /* demote time in uSec */
1718 if (!test_bit(GLF_DEMOTE, &gl->gl_flags)) 1620 if (!test_bit(GLF_DEMOTE, &gl->gl_flags))
1719 dtime = 0; 1621 dtime = 0;
1720 gfs2_print_dbg(seq, "G: s:%s n:%u/%llu f:%s t:%s d:%s/%llu l:%d a:%d r:%d\n", 1622 gfs2_print_dbg(seq, "G: s:%s n:%u/%llu f:%s t:%s d:%s/%llu a:%d r:%d\n",
1721 state2str(gl->gl_state), 1623 state2str(gl->gl_state),
1722 gl->gl_name.ln_type, 1624 gl->gl_name.ln_type,
1723 (unsigned long long)gl->gl_name.ln_number, 1625 (unsigned long long)gl->gl_name.ln_number,
1724 gflags2str(gflags_buf, &gl->gl_flags), 1626 gflags2str(gflags_buf, &gl->gl_flags),
1725 state2str(gl->gl_target), 1627 state2str(gl->gl_target),
1726 state2str(gl->gl_demote_state), dtime, 1628 state2str(gl->gl_demote_state), dtime,
1727 atomic_read(&gl->gl_lvb_count),
1728 atomic_read(&gl->gl_ail_count), 1629 atomic_read(&gl->gl_ail_count),
1729 atomic_read(&gl->gl_ref)); 1630 atomic_read(&gl->gl_ref));
1730 1631