1 /* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
6 * Code which implements an OCFS2 specific interface to our DLM.
8 * Copyright (C) 2003, 2004 Oracle. All rights reserved.
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public
21 * License along with this program; if not, write to the
22 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 * Boston, MA 021110-1307, USA.
26 #include <linux/types.h>
27 #include <linux/slab.h>
28 #include <linux/highmem.h>
30 #include <linux/smp_lock.h>
31 #include <linux/crc32.h>
32 #include <linux/kthread.h>
33 #include <linux/pagemap.h>
34 #include <linux/debugfs.h>
35 #include <linux/seq_file.h>
37 #include <cluster/heartbeat.h>
38 #include <cluster/nodemanager.h>
39 #include <cluster/tcp.h>
41 #include <dlm/dlmapi.h>
43 #define MLOG_MASK_PREFIX ML_DLM_GLUE
44 #include <cluster/masklog.h>
51 #include "extent_map.h"
52 #include "heartbeat.h"
60 #include "buffer_head_io.h"
62 struct ocfs2_mask_waiter {
63 struct list_head mw_item;
65 struct completion mw_complete;
66 unsigned long mw_mask;
67 unsigned long mw_goal;
70 static void ocfs2_inode_ast_func(void *opaque);
71 static void ocfs2_inode_bast_func(void *opaque,
73 static void ocfs2_dentry_ast_func(void *opaque);
74 static void ocfs2_dentry_bast_func(void *opaque,
76 static void ocfs2_super_ast_func(void *opaque);
77 static void ocfs2_super_bast_func(void *opaque,
79 static void ocfs2_rename_ast_func(void *opaque);
80 static void ocfs2_rename_bast_func(void *opaque,
84 * Return value from ocfs2_convert_worker_t functions.
86 * These control the precise actions of ocfs2_generic_unblock_lock()
87 * and ocfs2_process_blocked_lock()
90 enum ocfs2_unblock_action {
91 UNBLOCK_CONTINUE = 0, /* Continue downconvert */
92 UNBLOCK_CONTINUE_POST = 1, /* Continue downconvert, fire
93 * ->post_unlock callback */
94 UNBLOCK_STOP_POST = 2, /* Do not downconvert, fire
95 * ->post_unlock() callback. */
98 struct ocfs2_unblock_ctl {
100 enum ocfs2_unblock_action unblock_action;
103 /* so far, all locks have gotten along with the same unlock ast */
104 static void ocfs2_unlock_ast_func(void *opaque,
105 enum dlm_status status);
106 static int ocfs2_unblock_meta(struct ocfs2_lock_res *lockres,
107 struct ocfs2_unblock_ctl *ctl);
108 static int ocfs2_unblock_data(struct ocfs2_lock_res *lockres,
109 struct ocfs2_unblock_ctl *ctl);
110 static int ocfs2_unblock_inode_lock(struct ocfs2_lock_res *lockres,
111 struct ocfs2_unblock_ctl *ctl);
112 static int ocfs2_unblock_dentry_lock(struct ocfs2_lock_res *lockres,
113 struct ocfs2_unblock_ctl *ctl);
114 static int ocfs2_unblock_osb_lock(struct ocfs2_lock_res *lockres,
115 struct ocfs2_unblock_ctl *ctl);
117 static void ocfs2_dentry_post_unlock(struct ocfs2_super *osb,
118 struct ocfs2_lock_res *lockres);
120 struct ocfs2_lock_res_ops {
122 void (*bast)(void *, int);
123 void (*unlock_ast)(void *, enum dlm_status);
124 int (*unblock)(struct ocfs2_lock_res *, struct ocfs2_unblock_ctl *);
125 void (*post_unlock)(struct ocfs2_super *, struct ocfs2_lock_res *);
128 typedef int (ocfs2_convert_worker_t)(struct ocfs2_lock_res *, int);
129 static int ocfs2_generic_unblock_lock(struct ocfs2_super *osb,
130 struct ocfs2_lock_res *lockres,
131 struct ocfs2_unblock_ctl *ctl,
132 ocfs2_convert_worker_t *worker);
134 static struct ocfs2_lock_res_ops ocfs2_inode_rw_lops = {
135 .ast = ocfs2_inode_ast_func,
136 .bast = ocfs2_inode_bast_func,
137 .unlock_ast = ocfs2_unlock_ast_func,
138 .unblock = ocfs2_unblock_inode_lock,
141 static struct ocfs2_lock_res_ops ocfs2_inode_meta_lops = {
142 .ast = ocfs2_inode_ast_func,
143 .bast = ocfs2_inode_bast_func,
144 .unlock_ast = ocfs2_unlock_ast_func,
145 .unblock = ocfs2_unblock_meta,
148 static struct ocfs2_lock_res_ops ocfs2_inode_data_lops = {
149 .ast = ocfs2_inode_ast_func,
150 .bast = ocfs2_inode_bast_func,
151 .unlock_ast = ocfs2_unlock_ast_func,
152 .unblock = ocfs2_unblock_data,
155 static struct ocfs2_lock_res_ops ocfs2_super_lops = {
156 .ast = ocfs2_super_ast_func,
157 .bast = ocfs2_super_bast_func,
158 .unlock_ast = ocfs2_unlock_ast_func,
159 .unblock = ocfs2_unblock_osb_lock,
162 static struct ocfs2_lock_res_ops ocfs2_rename_lops = {
163 .ast = ocfs2_rename_ast_func,
164 .bast = ocfs2_rename_bast_func,
165 .unlock_ast = ocfs2_unlock_ast_func,
166 .unblock = ocfs2_unblock_osb_lock,
169 static struct ocfs2_lock_res_ops ocfs2_dentry_lops = {
170 .ast = ocfs2_dentry_ast_func,
171 .bast = ocfs2_dentry_bast_func,
172 .unlock_ast = ocfs2_unlock_ast_func,
173 .unblock = ocfs2_unblock_dentry_lock,
174 .post_unlock = ocfs2_dentry_post_unlock,
177 static inline int ocfs2_is_inode_lock(struct ocfs2_lock_res *lockres)
179 return lockres->l_type == OCFS2_LOCK_TYPE_META ||
180 lockres->l_type == OCFS2_LOCK_TYPE_DATA ||
181 lockres->l_type == OCFS2_LOCK_TYPE_RW;
184 static inline int ocfs2_is_super_lock(struct ocfs2_lock_res *lockres)
186 return lockres->l_type == OCFS2_LOCK_TYPE_SUPER;
189 static inline int ocfs2_is_rename_lock(struct ocfs2_lock_res *lockres)
191 return lockres->l_type == OCFS2_LOCK_TYPE_RENAME;
194 static inline struct ocfs2_super *ocfs2_lock_res_super(struct ocfs2_lock_res *lockres)
196 BUG_ON(!ocfs2_is_super_lock(lockres)
197 && !ocfs2_is_rename_lock(lockres));
199 return (struct ocfs2_super *) lockres->l_priv;
202 static inline struct inode *ocfs2_lock_res_inode(struct ocfs2_lock_res *lockres)
204 BUG_ON(!ocfs2_is_inode_lock(lockres));
206 return (struct inode *) lockres->l_priv;
209 static inline struct ocfs2_dentry_lock *ocfs2_lock_res_dl(struct ocfs2_lock_res *lockres)
211 BUG_ON(lockres->l_type != OCFS2_LOCK_TYPE_DENTRY);
213 return (struct ocfs2_dentry_lock *)lockres->l_priv;
216 static int ocfs2_lock_create(struct ocfs2_super *osb,
217 struct ocfs2_lock_res *lockres,
220 static inline int ocfs2_may_continue_on_blocked_lock(struct ocfs2_lock_res *lockres,
222 static void ocfs2_cluster_unlock(struct ocfs2_super *osb,
223 struct ocfs2_lock_res *lockres,
225 static inline void ocfs2_generic_handle_downconvert_action(struct ocfs2_lock_res *lockres);
226 static inline void ocfs2_generic_handle_convert_action(struct ocfs2_lock_res *lockres);
227 static inline void ocfs2_generic_handle_attach_action(struct ocfs2_lock_res *lockres);
228 static int ocfs2_generic_handle_bast(struct ocfs2_lock_res *lockres, int level);
229 static void ocfs2_schedule_blocked_lock(struct ocfs2_super *osb,
230 struct ocfs2_lock_res *lockres);
231 static inline void ocfs2_recover_from_dlm_error(struct ocfs2_lock_res *lockres,
233 #define ocfs2_log_dlm_error(_func, _stat, _lockres) do { \
234 mlog(ML_ERROR, "Dlm error \"%s\" while calling %s on " \
235 "resource %s: %s\n", dlm_errname(_stat), _func, \
236 _lockres->l_name, dlm_errmsg(_stat)); \
238 static void ocfs2_vote_on_unlock(struct ocfs2_super *osb,
239 struct ocfs2_lock_res *lockres);
240 static int ocfs2_meta_lock_update(struct inode *inode,
241 struct buffer_head **bh);
242 static void ocfs2_drop_osb_locks(struct ocfs2_super *osb);
243 static inline int ocfs2_highest_compat_lock_level(int level);
244 static inline int ocfs2_can_downconvert_meta_lock(struct inode *inode,
245 struct ocfs2_lock_res *lockres,
248 static void ocfs2_build_lock_name(enum ocfs2_lock_type type,
257 BUG_ON(type >= OCFS2_NUM_LOCK_TYPES);
259 len = snprintf(name, OCFS2_LOCK_ID_MAX_LEN, "%c%s%016llx%08x",
260 ocfs2_lock_type_char(type), OCFS2_LOCK_ID_PAD,
261 (long long)blkno, generation);
263 BUG_ON(len != (OCFS2_LOCK_ID_MAX_LEN - 1));
265 mlog(0, "built lock resource with name: %s\n", name);
270 static DEFINE_SPINLOCK(ocfs2_dlm_tracking_lock);
272 static void ocfs2_add_lockres_tracking(struct ocfs2_lock_res *res,
273 struct ocfs2_dlm_debug *dlm_debug)
275 mlog(0, "Add tracking for lockres %s\n", res->l_name);
277 spin_lock(&ocfs2_dlm_tracking_lock);
278 list_add(&res->l_debug_list, &dlm_debug->d_lockres_tracking);
279 spin_unlock(&ocfs2_dlm_tracking_lock);
282 static void ocfs2_remove_lockres_tracking(struct ocfs2_lock_res *res)
284 spin_lock(&ocfs2_dlm_tracking_lock);
285 if (!list_empty(&res->l_debug_list))
286 list_del_init(&res->l_debug_list);
287 spin_unlock(&ocfs2_dlm_tracking_lock);
290 static void ocfs2_lock_res_init_common(struct ocfs2_super *osb,
291 struct ocfs2_lock_res *res,
292 enum ocfs2_lock_type type,
293 struct ocfs2_lock_res_ops *ops,
300 res->l_level = LKM_IVMODE;
301 res->l_requested = LKM_IVMODE;
302 res->l_blocking = LKM_IVMODE;
303 res->l_action = OCFS2_AST_INVALID;
304 res->l_unlock_action = OCFS2_UNLOCK_INVALID;
306 res->l_flags = OCFS2_LOCK_INITIALIZED;
308 ocfs2_add_lockres_tracking(res, osb->osb_dlm_debug);
311 void ocfs2_lock_res_init_once(struct ocfs2_lock_res *res)
313 /* This also clears out the lock status block */
314 memset(res, 0, sizeof(struct ocfs2_lock_res));
315 spin_lock_init(&res->l_lock);
316 init_waitqueue_head(&res->l_event);
317 INIT_LIST_HEAD(&res->l_blocked_list);
318 INIT_LIST_HEAD(&res->l_mask_waiters);
321 void ocfs2_inode_lock_res_init(struct ocfs2_lock_res *res,
322 enum ocfs2_lock_type type,
323 unsigned int generation,
326 struct ocfs2_lock_res_ops *ops;
329 case OCFS2_LOCK_TYPE_RW:
330 ops = &ocfs2_inode_rw_lops;
332 case OCFS2_LOCK_TYPE_META:
333 ops = &ocfs2_inode_meta_lops;
335 case OCFS2_LOCK_TYPE_DATA:
336 ops = &ocfs2_inode_data_lops;
339 mlog_bug_on_msg(1, "type: %d\n", type);
340 ops = NULL; /* thanks, gcc */
344 ocfs2_build_lock_name(type, OCFS2_I(inode)->ip_blkno,
345 generation, res->l_name);
346 ocfs2_lock_res_init_common(OCFS2_SB(inode->i_sb), res, type, ops, inode);
349 static __u64 ocfs2_get_dentry_lock_ino(struct ocfs2_lock_res *lockres)
351 __be64 inode_blkno_be;
353 memcpy(&inode_blkno_be, &lockres->l_name[OCFS2_DENTRY_LOCK_INO_START],
356 return be64_to_cpu(inode_blkno_be);
359 void ocfs2_dentry_lock_res_init(struct ocfs2_dentry_lock *dl,
360 u64 parent, struct inode *inode)
363 u64 inode_blkno = OCFS2_I(inode)->ip_blkno;
364 __be64 inode_blkno_be = cpu_to_be64(inode_blkno);
365 struct ocfs2_lock_res *lockres = &dl->dl_lockres;
367 ocfs2_lock_res_init_once(lockres);
370 * Unfortunately, the standard lock naming scheme won't work
371 * here because we have two 16 byte values to use. Instead,
372 * we'll stuff the inode number as a binary value. We still
373 * want error prints to show something without garbling the
374 * display, so drop a null byte in there before the inode
375 * number. A future version of OCFS2 will likely use all
376 * binary lock names. The stringified names have been a
377 * tremendous aid in debugging, but now that the debugfs
378 * interface exists, we can mangle things there if need be.
380 * NOTE: We also drop the standard "pad" value (the total lock
381 * name size stays the same though - the last part is all
382 * zeros due to the memset in ocfs2_lock_res_init_once()
384 len = snprintf(lockres->l_name, OCFS2_DENTRY_LOCK_INO_START,
386 ocfs2_lock_type_char(OCFS2_LOCK_TYPE_DENTRY),
389 BUG_ON(len != (OCFS2_DENTRY_LOCK_INO_START - 1));
391 memcpy(&lockres->l_name[OCFS2_DENTRY_LOCK_INO_START], &inode_blkno_be,
394 ocfs2_lock_res_init_common(OCFS2_SB(inode->i_sb), lockres,
395 OCFS2_LOCK_TYPE_DENTRY, &ocfs2_dentry_lops,
399 static void ocfs2_super_lock_res_init(struct ocfs2_lock_res *res,
400 struct ocfs2_super *osb)
402 /* Superblock lockres doesn't come from a slab so we call init
403 * once on it manually. */
404 ocfs2_lock_res_init_once(res);
405 ocfs2_build_lock_name(OCFS2_LOCK_TYPE_SUPER, OCFS2_SUPER_BLOCK_BLKNO,
407 ocfs2_lock_res_init_common(osb, res, OCFS2_LOCK_TYPE_SUPER,
408 &ocfs2_super_lops, osb);
411 static void ocfs2_rename_lock_res_init(struct ocfs2_lock_res *res,
412 struct ocfs2_super *osb)
414 /* Rename lockres doesn't come from a slab so we call init
415 * once on it manually. */
416 ocfs2_lock_res_init_once(res);
417 ocfs2_build_lock_name(OCFS2_LOCK_TYPE_RENAME, 0, 0, res->l_name);
418 ocfs2_lock_res_init_common(osb, res, OCFS2_LOCK_TYPE_RENAME,
419 &ocfs2_rename_lops, osb);
422 void ocfs2_lock_res_free(struct ocfs2_lock_res *res)
426 if (!(res->l_flags & OCFS2_LOCK_INITIALIZED))
429 ocfs2_remove_lockres_tracking(res);
431 mlog_bug_on_msg(!list_empty(&res->l_blocked_list),
432 "Lockres %s is on the blocked list\n",
434 mlog_bug_on_msg(!list_empty(&res->l_mask_waiters),
435 "Lockres %s has mask waiters pending\n",
437 mlog_bug_on_msg(spin_is_locked(&res->l_lock),
438 "Lockres %s is locked\n",
440 mlog_bug_on_msg(res->l_ro_holders,
441 "Lockres %s has %u ro holders\n",
442 res->l_name, res->l_ro_holders);
443 mlog_bug_on_msg(res->l_ex_holders,
444 "Lockres %s has %u ex holders\n",
445 res->l_name, res->l_ex_holders);
447 /* Need to clear out the lock status block for the dlm */
448 memset(&res->l_lksb, 0, sizeof(res->l_lksb));
454 static inline void ocfs2_inc_holders(struct ocfs2_lock_res *lockres,
463 lockres->l_ex_holders++;
466 lockres->l_ro_holders++;
475 static inline void ocfs2_dec_holders(struct ocfs2_lock_res *lockres,
484 BUG_ON(!lockres->l_ex_holders);
485 lockres->l_ex_holders--;
488 BUG_ON(!lockres->l_ro_holders);
489 lockres->l_ro_holders--;
497 /* WARNING: This function lives in a world where the only three lock
498 * levels are EX, PR, and NL. It *will* have to be adjusted when more
499 * lock types are added. */
500 static inline int ocfs2_highest_compat_lock_level(int level)
502 int new_level = LKM_EXMODE;
504 if (level == LKM_EXMODE)
505 new_level = LKM_NLMODE;
506 else if (level == LKM_PRMODE)
507 new_level = LKM_PRMODE;
511 static void lockres_set_flags(struct ocfs2_lock_res *lockres,
512 unsigned long newflags)
514 struct list_head *pos, *tmp;
515 struct ocfs2_mask_waiter *mw;
517 assert_spin_locked(&lockres->l_lock);
519 lockres->l_flags = newflags;
521 list_for_each_safe(pos, tmp, &lockres->l_mask_waiters) {
522 mw = list_entry(pos, struct ocfs2_mask_waiter, mw_item);
523 if ((lockres->l_flags & mw->mw_mask) != mw->mw_goal)
526 list_del_init(&mw->mw_item);
528 complete(&mw->mw_complete);
531 static void lockres_or_flags(struct ocfs2_lock_res *lockres, unsigned long or)
533 lockres_set_flags(lockres, lockres->l_flags | or);
535 static void lockres_clear_flags(struct ocfs2_lock_res *lockres,
538 lockres_set_flags(lockres, lockres->l_flags & ~clear);
541 static inline void ocfs2_generic_handle_downconvert_action(struct ocfs2_lock_res *lockres)
545 BUG_ON(!(lockres->l_flags & OCFS2_LOCK_BUSY));
546 BUG_ON(!(lockres->l_flags & OCFS2_LOCK_ATTACHED));
547 BUG_ON(!(lockres->l_flags & OCFS2_LOCK_BLOCKED));
548 BUG_ON(lockres->l_blocking <= LKM_NLMODE);
550 lockres->l_level = lockres->l_requested;
551 if (lockres->l_level <=
552 ocfs2_highest_compat_lock_level(lockres->l_blocking)) {
553 lockres->l_blocking = LKM_NLMODE;
554 lockres_clear_flags(lockres, OCFS2_LOCK_BLOCKED);
556 lockres_clear_flags(lockres, OCFS2_LOCK_BUSY);
561 static inline void ocfs2_generic_handle_convert_action(struct ocfs2_lock_res *lockres)
565 BUG_ON(!(lockres->l_flags & OCFS2_LOCK_BUSY));
566 BUG_ON(!(lockres->l_flags & OCFS2_LOCK_ATTACHED));
568 /* Convert from RO to EX doesn't really need anything as our
569 * information is already up to data. Convert from NL to
570 * *anything* however should mark ourselves as needing an
572 if (lockres->l_level == LKM_NLMODE)
573 lockres_or_flags(lockres, OCFS2_LOCK_NEEDS_REFRESH);
575 lockres->l_level = lockres->l_requested;
576 lockres_clear_flags(lockres, OCFS2_LOCK_BUSY);
581 static inline void ocfs2_generic_handle_attach_action(struct ocfs2_lock_res *lockres)
585 BUG_ON((!lockres->l_flags & OCFS2_LOCK_BUSY));
586 BUG_ON(lockres->l_flags & OCFS2_LOCK_ATTACHED);
588 if (lockres->l_requested > LKM_NLMODE &&
589 !(lockres->l_flags & OCFS2_LOCK_LOCAL))
590 lockres_or_flags(lockres, OCFS2_LOCK_NEEDS_REFRESH);
592 lockres->l_level = lockres->l_requested;
593 lockres_or_flags(lockres, OCFS2_LOCK_ATTACHED);
594 lockres_clear_flags(lockres, OCFS2_LOCK_BUSY);
599 static void ocfs2_inode_ast_func(void *opaque)
601 struct ocfs2_lock_res *lockres = opaque;
603 struct dlm_lockstatus *lksb;
608 inode = ocfs2_lock_res_inode(lockres);
610 mlog(0, "AST fired for inode %llu, l_action = %u, type = %s\n",
611 (unsigned long long)OCFS2_I(inode)->ip_blkno, lockres->l_action,
612 ocfs2_lock_type_string(lockres->l_type));
614 BUG_ON(!ocfs2_is_inode_lock(lockres));
616 spin_lock_irqsave(&lockres->l_lock, flags);
618 lksb = &(lockres->l_lksb);
619 if (lksb->status != DLM_NORMAL) {
620 mlog(ML_ERROR, "ocfs2_inode_ast_func: lksb status value of %u "
621 "on inode %llu\n", lksb->status,
622 (unsigned long long)OCFS2_I(inode)->ip_blkno);
623 spin_unlock_irqrestore(&lockres->l_lock, flags);
628 switch(lockres->l_action) {
629 case OCFS2_AST_ATTACH:
630 ocfs2_generic_handle_attach_action(lockres);
631 lockres_clear_flags(lockres, OCFS2_LOCK_LOCAL);
633 case OCFS2_AST_CONVERT:
634 ocfs2_generic_handle_convert_action(lockres);
636 case OCFS2_AST_DOWNCONVERT:
637 ocfs2_generic_handle_downconvert_action(lockres);
640 mlog(ML_ERROR, "lockres %s: ast fired with invalid action: %u "
641 "lockres flags = 0x%lx, unlock action: %u\n",
642 lockres->l_name, lockres->l_action, lockres->l_flags,
643 lockres->l_unlock_action);
648 /* data and rw locking ignores refresh flag for now. */
649 if (lockres->l_type != OCFS2_LOCK_TYPE_META)
650 lockres_clear_flags(lockres, OCFS2_LOCK_NEEDS_REFRESH);
652 /* set it to something invalid so if we get called again we
654 lockres->l_action = OCFS2_AST_INVALID;
655 spin_unlock_irqrestore(&lockres->l_lock, flags);
656 wake_up(&lockres->l_event);
661 static int ocfs2_generic_handle_bast(struct ocfs2_lock_res *lockres,
664 int needs_downconvert = 0;
667 assert_spin_locked(&lockres->l_lock);
669 lockres_or_flags(lockres, OCFS2_LOCK_BLOCKED);
671 if (level > lockres->l_blocking) {
672 /* only schedule a downconvert if we haven't already scheduled
673 * one that goes low enough to satisfy the level we're
674 * blocking. this also catches the case where we get
676 if (ocfs2_highest_compat_lock_level(level) <
677 ocfs2_highest_compat_lock_level(lockres->l_blocking))
678 needs_downconvert = 1;
680 lockres->l_blocking = level;
683 mlog_exit(needs_downconvert);
684 return needs_downconvert;
687 static void ocfs2_generic_bast_func(struct ocfs2_super *osb,
688 struct ocfs2_lock_res *lockres,
691 int needs_downconvert;
696 BUG_ON(level <= LKM_NLMODE);
698 spin_lock_irqsave(&lockres->l_lock, flags);
699 needs_downconvert = ocfs2_generic_handle_bast(lockres, level);
700 if (needs_downconvert)
701 ocfs2_schedule_blocked_lock(osb, lockres);
702 spin_unlock_irqrestore(&lockres->l_lock, flags);
704 wake_up(&lockres->l_event);
706 ocfs2_kick_vote_thread(osb);
711 static void ocfs2_inode_bast_func(void *opaque, int level)
713 struct ocfs2_lock_res *lockres = opaque;
715 struct ocfs2_super *osb;
719 BUG_ON(!ocfs2_is_inode_lock(lockres));
721 inode = ocfs2_lock_res_inode(lockres);
722 osb = OCFS2_SB(inode->i_sb);
724 mlog(0, "BAST fired for inode %llu, blocking %d, level %d type %s\n",
725 (unsigned long long)OCFS2_I(inode)->ip_blkno, level,
726 lockres->l_level, ocfs2_lock_type_string(lockres->l_type));
728 ocfs2_generic_bast_func(osb, lockres, level);
733 static void ocfs2_generic_ast_func(struct ocfs2_lock_res *lockres,
736 struct dlm_lockstatus *lksb = &lockres->l_lksb;
739 spin_lock_irqsave(&lockres->l_lock, flags);
741 if (lksb->status != DLM_NORMAL) {
742 mlog(ML_ERROR, "lockres %s: lksb status value of %u!\n",
743 lockres->l_name, lksb->status);
744 spin_unlock_irqrestore(&lockres->l_lock, flags);
748 switch(lockres->l_action) {
749 case OCFS2_AST_ATTACH:
750 ocfs2_generic_handle_attach_action(lockres);
752 case OCFS2_AST_CONVERT:
753 ocfs2_generic_handle_convert_action(lockres);
755 case OCFS2_AST_DOWNCONVERT:
756 ocfs2_generic_handle_downconvert_action(lockres);
763 lockres_clear_flags(lockres, OCFS2_LOCK_NEEDS_REFRESH);
765 /* set it to something invalid so if we get called again we
767 lockres->l_action = OCFS2_AST_INVALID;
769 wake_up(&lockres->l_event);
770 spin_unlock_irqrestore(&lockres->l_lock, flags);
773 static void ocfs2_super_ast_func(void *opaque)
775 struct ocfs2_lock_res *lockres = opaque;
778 mlog(0, "Superblock AST fired\n");
780 BUG_ON(!ocfs2_is_super_lock(lockres));
781 ocfs2_generic_ast_func(lockres, 0);
786 static void ocfs2_super_bast_func(void *opaque,
789 struct ocfs2_lock_res *lockres = opaque;
790 struct ocfs2_super *osb;
793 mlog(0, "Superblock BAST fired\n");
795 BUG_ON(!ocfs2_is_super_lock(lockres));
796 osb = ocfs2_lock_res_super(lockres);
797 ocfs2_generic_bast_func(osb, lockres, level);
802 static void ocfs2_rename_ast_func(void *opaque)
804 struct ocfs2_lock_res *lockres = opaque;
808 mlog(0, "Rename AST fired\n");
810 BUG_ON(!ocfs2_is_rename_lock(lockres));
812 ocfs2_generic_ast_func(lockres, 1);
817 static void ocfs2_rename_bast_func(void *opaque,
820 struct ocfs2_lock_res *lockres = opaque;
821 struct ocfs2_super *osb;
825 mlog(0, "Rename BAST fired\n");
827 BUG_ON(!ocfs2_is_rename_lock(lockres));
829 osb = ocfs2_lock_res_super(lockres);
830 ocfs2_generic_bast_func(osb, lockres, level);
835 static void ocfs2_dentry_ast_func(void *opaque)
837 struct ocfs2_lock_res *lockres = opaque;
841 ocfs2_generic_ast_func(lockres, 1);
844 static void ocfs2_dentry_bast_func(void *opaque, int level)
846 struct ocfs2_lock_res *lockres = opaque;
847 struct ocfs2_dentry_lock *dl = lockres->l_priv;
848 struct ocfs2_super *osb = OCFS2_SB(dl->dl_inode->i_sb);
850 mlog(0, "Dentry bast: level: %d, name: %s\n", level,
853 ocfs2_generic_bast_func(osb, lockres, level);
856 static inline void ocfs2_recover_from_dlm_error(struct ocfs2_lock_res *lockres,
862 spin_lock_irqsave(&lockres->l_lock, flags);
863 lockres_clear_flags(lockres, OCFS2_LOCK_BUSY);
865 lockres->l_action = OCFS2_AST_INVALID;
867 lockres->l_unlock_action = OCFS2_UNLOCK_INVALID;
868 spin_unlock_irqrestore(&lockres->l_lock, flags);
870 wake_up(&lockres->l_event);
874 /* Note: If we detect another process working on the lock (i.e.,
875 * OCFS2_LOCK_BUSY), we'll bail out returning 0. It's up to the caller
876 * to do the right thing in that case.
878 static int ocfs2_lock_create(struct ocfs2_super *osb,
879 struct ocfs2_lock_res *lockres,
884 enum dlm_status status;
889 mlog(0, "lock %s, level = %d, flags = %d\n", lockres->l_name, level,
892 spin_lock_irqsave(&lockres->l_lock, flags);
893 if ((lockres->l_flags & OCFS2_LOCK_ATTACHED) ||
894 (lockres->l_flags & OCFS2_LOCK_BUSY)) {
895 spin_unlock_irqrestore(&lockres->l_lock, flags);
899 lockres->l_action = OCFS2_AST_ATTACH;
900 lockres->l_requested = level;
901 lockres_or_flags(lockres, OCFS2_LOCK_BUSY);
902 spin_unlock_irqrestore(&lockres->l_lock, flags);
904 status = dlmlock(osb->dlm,
909 OCFS2_LOCK_ID_MAX_LEN - 1,
912 lockres->l_ops->bast);
913 if (status != DLM_NORMAL) {
914 ocfs2_log_dlm_error("dlmlock", status, lockres);
916 ocfs2_recover_from_dlm_error(lockres, 1);
919 mlog(0, "lock %s, successfull return from dlmlock\n", lockres->l_name);
926 static inline int ocfs2_check_wait_flag(struct ocfs2_lock_res *lockres,
932 spin_lock_irqsave(&lockres->l_lock, flags);
933 ret = lockres->l_flags & flag;
934 spin_unlock_irqrestore(&lockres->l_lock, flags);
939 static inline void ocfs2_wait_on_busy_lock(struct ocfs2_lock_res *lockres)
942 wait_event(lockres->l_event,
943 !ocfs2_check_wait_flag(lockres, OCFS2_LOCK_BUSY));
946 static inline void ocfs2_wait_on_refreshing_lock(struct ocfs2_lock_res *lockres)
949 wait_event(lockres->l_event,
950 !ocfs2_check_wait_flag(lockres, OCFS2_LOCK_REFRESHING));
953 /* predict what lock level we'll be dropping down to on behalf
954 * of another node, and return true if the currently wanted
955 * level will be compatible with it. */
956 static inline int ocfs2_may_continue_on_blocked_lock(struct ocfs2_lock_res *lockres,
959 BUG_ON(!(lockres->l_flags & OCFS2_LOCK_BLOCKED));
961 return wanted <= ocfs2_highest_compat_lock_level(lockres->l_blocking);
964 static void ocfs2_init_mask_waiter(struct ocfs2_mask_waiter *mw)
966 INIT_LIST_HEAD(&mw->mw_item);
967 init_completion(&mw->mw_complete);
970 static int ocfs2_wait_for_mask(struct ocfs2_mask_waiter *mw)
972 wait_for_completion(&mw->mw_complete);
973 /* Re-arm the completion in case we want to wait on it again */
974 INIT_COMPLETION(mw->mw_complete);
975 return mw->mw_status;
978 static void lockres_add_mask_waiter(struct ocfs2_lock_res *lockres,
979 struct ocfs2_mask_waiter *mw,
983 BUG_ON(!list_empty(&mw->mw_item));
985 assert_spin_locked(&lockres->l_lock);
987 list_add_tail(&mw->mw_item, &lockres->l_mask_waiters);
992 /* returns 0 if the mw that was removed was already satisfied, -EBUSY
993 * if the mask still hadn't reached its goal */
994 static int lockres_remove_mask_waiter(struct ocfs2_lock_res *lockres,
995 struct ocfs2_mask_waiter *mw)
1000 spin_lock_irqsave(&lockres->l_lock, flags);
1001 if (!list_empty(&mw->mw_item)) {
1002 if ((lockres->l_flags & mw->mw_mask) != mw->mw_goal)
1005 list_del_init(&mw->mw_item);
1006 init_completion(&mw->mw_complete);
1008 spin_unlock_irqrestore(&lockres->l_lock, flags);
1014 static int ocfs2_cluster_lock(struct ocfs2_super *osb,
1015 struct ocfs2_lock_res *lockres,
1020 struct ocfs2_mask_waiter mw;
1021 enum dlm_status status;
1022 int wait, catch_signals = !(osb->s_mount_opt & OCFS2_MOUNT_NOINTR);
1023 int ret = 0; /* gcc doesn't realize wait = 1 guarantees ret is set */
1024 unsigned long flags;
1028 ocfs2_init_mask_waiter(&mw);
1033 if (catch_signals && signal_pending(current)) {
1038 spin_lock_irqsave(&lockres->l_lock, flags);
1040 mlog_bug_on_msg(lockres->l_flags & OCFS2_LOCK_FREEING,
1041 "Cluster lock called on freeing lockres %s! flags "
1042 "0x%lx\n", lockres->l_name, lockres->l_flags);
1044 /* We only compare against the currently granted level
1045 * here. If the lock is blocked waiting on a downconvert,
1046 * we'll get caught below. */
1047 if (lockres->l_flags & OCFS2_LOCK_BUSY &&
1048 level > lockres->l_level) {
1049 /* is someone sitting in dlm_lock? If so, wait on
1051 lockres_add_mask_waiter(lockres, &mw, OCFS2_LOCK_BUSY, 0);
1056 if (!(lockres->l_flags & OCFS2_LOCK_ATTACHED)) {
1057 /* lock has not been created yet. */
1058 spin_unlock_irqrestore(&lockres->l_lock, flags);
1060 ret = ocfs2_lock_create(osb, lockres, LKM_NLMODE, 0);
1068 if (lockres->l_flags & OCFS2_LOCK_BLOCKED &&
1069 !ocfs2_may_continue_on_blocked_lock(lockres, level)) {
1070 /* is the lock is currently blocked on behalf of
1072 lockres_add_mask_waiter(lockres, &mw, OCFS2_LOCK_BLOCKED, 0);
1077 if (level > lockres->l_level) {
1078 if (lockres->l_action != OCFS2_AST_INVALID)
1079 mlog(ML_ERROR, "lockres %s has action %u pending\n",
1080 lockres->l_name, lockres->l_action);
1082 lockres->l_action = OCFS2_AST_CONVERT;
1083 lockres->l_requested = level;
1084 lockres_or_flags(lockres, OCFS2_LOCK_BUSY);
1085 spin_unlock_irqrestore(&lockres->l_lock, flags);
1087 BUG_ON(level == LKM_IVMODE);
1088 BUG_ON(level == LKM_NLMODE);
1090 mlog(0, "lock %s, convert from %d to level = %d\n",
1091 lockres->l_name, lockres->l_level, level);
1093 /* call dlm_lock to upgrade lock now */
1094 status = dlmlock(osb->dlm,
1097 lkm_flags|LKM_CONVERT|LKM_VALBLK,
1099 OCFS2_LOCK_ID_MAX_LEN - 1,
1100 lockres->l_ops->ast,
1102 lockres->l_ops->bast);
1103 if (status != DLM_NORMAL) {
1104 if ((lkm_flags & LKM_NOQUEUE) &&
1105 (status == DLM_NOTQUEUED))
1108 ocfs2_log_dlm_error("dlmlock", status,
1112 ocfs2_recover_from_dlm_error(lockres, 1);
1116 mlog(0, "lock %s, successfull return from dlmlock\n",
1119 /* At this point we've gone inside the dlm and need to
1120 * complete our work regardless. */
1123 /* wait for busy to clear and carry on */
1127 /* Ok, if we get here then we're good to go. */
1128 ocfs2_inc_holders(lockres, level);
1132 spin_unlock_irqrestore(&lockres->l_lock, flags);
1135 * This is helping work around a lock inversion between the page lock
1136 * and dlm locks. One path holds the page lock while calling aops
1137 * which block acquiring dlm locks. The voting thread holds dlm
1138 * locks while acquiring page locks while down converting data locks.
1139 * This block is helping an aop path notice the inversion and back
1140 * off to unlock its page lock before trying the dlm lock again.
1142 if (wait && arg_flags & OCFS2_LOCK_NONBLOCK &&
1143 mw.mw_mask & (OCFS2_LOCK_BUSY|OCFS2_LOCK_BLOCKED)) {
1145 if (lockres_remove_mask_waiter(lockres, &mw))
1151 ret = ocfs2_wait_for_mask(&mw);
1161 static void ocfs2_cluster_unlock(struct ocfs2_super *osb,
1162 struct ocfs2_lock_res *lockres,
1165 unsigned long flags;
1168 spin_lock_irqsave(&lockres->l_lock, flags);
1169 ocfs2_dec_holders(lockres, level);
1170 ocfs2_vote_on_unlock(osb, lockres);
1171 spin_unlock_irqrestore(&lockres->l_lock, flags);
1175 int ocfs2_create_new_lock(struct ocfs2_super *osb,
1176 struct ocfs2_lock_res *lockres,
1180 int level = ex ? LKM_EXMODE : LKM_PRMODE;
1181 unsigned long flags;
1182 int lkm_flags = local ? LKM_LOCAL : 0;
1184 spin_lock_irqsave(&lockres->l_lock, flags);
1185 BUG_ON(lockres->l_flags & OCFS2_LOCK_ATTACHED);
1186 lockres_or_flags(lockres, OCFS2_LOCK_LOCAL);
1187 spin_unlock_irqrestore(&lockres->l_lock, flags);
1189 return ocfs2_lock_create(osb, lockres, level, lkm_flags);
1192 /* Grants us an EX lock on the data and metadata resources, skipping
1193 * the normal cluster directory lookup. Use this ONLY on newly created
1194 * inodes which other nodes can't possibly see, and which haven't been
1195 * hashed in the inode hash yet. This can give us a good performance
1196 * increase as it'll skip the network broadcast normally associated
1197 * with creating a new lock resource. */
1198 int ocfs2_create_new_inode_locks(struct inode *inode)
1201 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1204 BUG_ON(!ocfs2_inode_is_new(inode));
1208 mlog(0, "Inode %llu\n", (unsigned long long)OCFS2_I(inode)->ip_blkno);
1210 /* NOTE: That we don't increment any of the holder counts, nor
1211 * do we add anything to a journal handle. Since this is
1212 * supposed to be a new inode which the cluster doesn't know
1213 * about yet, there is no need to. As far as the LVB handling
1214 * is concerned, this is basically like acquiring an EX lock
1215 * on a resource which has an invalid one -- we'll set it
1216 * valid when we release the EX. */
1218 ret = ocfs2_create_new_lock(osb, &OCFS2_I(inode)->ip_rw_lockres, 1, 1);
1225 * We don't want to use LKM_LOCAL on a meta data lock as they
1226 * don't use a generation in their lock names.
1228 ret = ocfs2_create_new_lock(osb, &OCFS2_I(inode)->ip_meta_lockres, 1, 0);
1234 ret = ocfs2_create_new_lock(osb, &OCFS2_I(inode)->ip_data_lockres, 1, 1);
1245 int ocfs2_rw_lock(struct inode *inode, int write)
1248 struct ocfs2_lock_res *lockres;
1254 mlog(0, "inode %llu take %s RW lock\n",
1255 (unsigned long long)OCFS2_I(inode)->ip_blkno,
1256 write ? "EXMODE" : "PRMODE");
1258 lockres = &OCFS2_I(inode)->ip_rw_lockres;
1260 level = write ? LKM_EXMODE : LKM_PRMODE;
1262 status = ocfs2_cluster_lock(OCFS2_SB(inode->i_sb), lockres, level, 0,
1271 void ocfs2_rw_unlock(struct inode *inode, int write)
1273 int level = write ? LKM_EXMODE : LKM_PRMODE;
1274 struct ocfs2_lock_res *lockres = &OCFS2_I(inode)->ip_rw_lockres;
1278 mlog(0, "inode %llu drop %s RW lock\n",
1279 (unsigned long long)OCFS2_I(inode)->ip_blkno,
1280 write ? "EXMODE" : "PRMODE");
1282 ocfs2_cluster_unlock(OCFS2_SB(inode->i_sb), lockres, level);
1287 int ocfs2_data_lock_full(struct inode *inode,
1291 int status = 0, level;
1292 struct ocfs2_lock_res *lockres;
1298 mlog(0, "inode %llu take %s DATA lock\n",
1299 (unsigned long long)OCFS2_I(inode)->ip_blkno,
1300 write ? "EXMODE" : "PRMODE");
1302 /* We'll allow faking a readonly data lock for
1304 if (ocfs2_is_hard_readonly(OCFS2_SB(inode->i_sb))) {
1312 lockres = &OCFS2_I(inode)->ip_data_lockres;
1314 level = write ? LKM_EXMODE : LKM_PRMODE;
1316 status = ocfs2_cluster_lock(OCFS2_SB(inode->i_sb), lockres, level,
1318 if (status < 0 && status != -EAGAIN)
1326 /* see ocfs2_meta_lock_with_page() */
1327 int ocfs2_data_lock_with_page(struct inode *inode,
1333 ret = ocfs2_data_lock_full(inode, write, OCFS2_LOCK_NONBLOCK);
1334 if (ret == -EAGAIN) {
1336 if (ocfs2_data_lock(inode, write) == 0)
1337 ocfs2_data_unlock(inode, write);
1338 ret = AOP_TRUNCATED_PAGE;
1344 static void ocfs2_vote_on_unlock(struct ocfs2_super *osb,
1345 struct ocfs2_lock_res *lockres)
1351 /* If we know that another node is waiting on our lock, kick
1352 * the vote thread * pre-emptively when we reach a release
1354 if (lockres->l_flags & OCFS2_LOCK_BLOCKED) {
1355 switch(lockres->l_blocking) {
1357 if (!lockres->l_ex_holders && !lockres->l_ro_holders)
1361 if (!lockres->l_ex_holders)
1370 ocfs2_kick_vote_thread(osb);
1375 void ocfs2_data_unlock(struct inode *inode,
1378 int level = write ? LKM_EXMODE : LKM_PRMODE;
1379 struct ocfs2_lock_res *lockres = &OCFS2_I(inode)->ip_data_lockres;
1383 mlog(0, "inode %llu drop %s DATA lock\n",
1384 (unsigned long long)OCFS2_I(inode)->ip_blkno,
1385 write ? "EXMODE" : "PRMODE");
1387 if (!ocfs2_is_hard_readonly(OCFS2_SB(inode->i_sb)))
1388 ocfs2_cluster_unlock(OCFS2_SB(inode->i_sb), lockres, level);
1393 #define OCFS2_SEC_BITS 34
1394 #define OCFS2_SEC_SHIFT (64 - 34)
1395 #define OCFS2_NSEC_MASK ((1ULL << OCFS2_SEC_SHIFT) - 1)
1397 /* LVB only has room for 64 bits of time here so we pack it for
1399 static u64 ocfs2_pack_timespec(struct timespec *spec)
1402 u64 sec = spec->tv_sec;
1403 u32 nsec = spec->tv_nsec;
1405 res = (sec << OCFS2_SEC_SHIFT) | (nsec & OCFS2_NSEC_MASK);
1410 /* Call this with the lockres locked. I am reasonably sure we don't
1411 * need ip_lock in this function as anyone who would be changing those
1412 * values is supposed to be blocked in ocfs2_meta_lock right now. */
1413 static void __ocfs2_stuff_meta_lvb(struct inode *inode)
1415 struct ocfs2_inode_info *oi = OCFS2_I(inode);
1416 struct ocfs2_lock_res *lockres = &oi->ip_meta_lockres;
1417 struct ocfs2_meta_lvb *lvb;
1421 lvb = (struct ocfs2_meta_lvb *) lockres->l_lksb.lvb;
1424 * Invalidate the LVB of a deleted inode - this way other
1425 * nodes are forced to go to disk and discover the new inode
1428 if (oi->ip_flags & OCFS2_INODE_DELETED) {
1429 lvb->lvb_version = 0;
1433 lvb->lvb_version = OCFS2_LVB_VERSION;
1434 lvb->lvb_isize = cpu_to_be64(i_size_read(inode));
1435 lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
1436 lvb->lvb_iuid = cpu_to_be32(inode->i_uid);
1437 lvb->lvb_igid = cpu_to_be32(inode->i_gid);
1438 lvb->lvb_imode = cpu_to_be16(inode->i_mode);
1439 lvb->lvb_inlink = cpu_to_be16(inode->i_nlink);
1440 lvb->lvb_iatime_packed =
1441 cpu_to_be64(ocfs2_pack_timespec(&inode->i_atime));
1442 lvb->lvb_ictime_packed =
1443 cpu_to_be64(ocfs2_pack_timespec(&inode->i_ctime));
1444 lvb->lvb_imtime_packed =
1445 cpu_to_be64(ocfs2_pack_timespec(&inode->i_mtime));
1446 lvb->lvb_iattr = cpu_to_be32(oi->ip_attr);
1447 lvb->lvb_igeneration = cpu_to_be32(inode->i_generation);
1450 mlog_meta_lvb(0, lockres);
1455 static void ocfs2_unpack_timespec(struct timespec *spec,
1458 spec->tv_sec = packed_time >> OCFS2_SEC_SHIFT;
1459 spec->tv_nsec = packed_time & OCFS2_NSEC_MASK;
1462 static void ocfs2_refresh_inode_from_lvb(struct inode *inode)
1464 struct ocfs2_inode_info *oi = OCFS2_I(inode);
1465 struct ocfs2_lock_res *lockres = &oi->ip_meta_lockres;
1466 struct ocfs2_meta_lvb *lvb;
1470 mlog_meta_lvb(0, lockres);
1472 lvb = (struct ocfs2_meta_lvb *) lockres->l_lksb.lvb;
1474 /* We're safe here without the lockres lock... */
1475 spin_lock(&oi->ip_lock);
1476 oi->ip_clusters = be32_to_cpu(lvb->lvb_iclusters);
1477 i_size_write(inode, be64_to_cpu(lvb->lvb_isize));
1479 oi->ip_attr = be32_to_cpu(lvb->lvb_iattr);
1480 ocfs2_set_inode_flags(inode);
1482 /* fast-symlinks are a special case */
1483 if (S_ISLNK(inode->i_mode) && !oi->ip_clusters)
1484 inode->i_blocks = 0;
1487 ocfs2_align_bytes_to_sectors(i_size_read(inode));
1489 inode->i_uid = be32_to_cpu(lvb->lvb_iuid);
1490 inode->i_gid = be32_to_cpu(lvb->lvb_igid);
1491 inode->i_mode = be16_to_cpu(lvb->lvb_imode);
1492 inode->i_nlink = be16_to_cpu(lvb->lvb_inlink);
1493 ocfs2_unpack_timespec(&inode->i_atime,
1494 be64_to_cpu(lvb->lvb_iatime_packed));
1495 ocfs2_unpack_timespec(&inode->i_mtime,
1496 be64_to_cpu(lvb->lvb_imtime_packed));
1497 ocfs2_unpack_timespec(&inode->i_ctime,
1498 be64_to_cpu(lvb->lvb_ictime_packed));
1499 spin_unlock(&oi->ip_lock);
1504 static inline int ocfs2_meta_lvb_is_trustable(struct inode *inode,
1505 struct ocfs2_lock_res *lockres)
1507 struct ocfs2_meta_lvb *lvb = (struct ocfs2_meta_lvb *) lockres->l_lksb.lvb;
1509 if (lvb->lvb_version == OCFS2_LVB_VERSION
1510 && be32_to_cpu(lvb->lvb_igeneration) == inode->i_generation)
1515 /* Determine whether a lock resource needs to be refreshed, and
1516 * arbitrate who gets to refresh it.
1518 * 0 means no refresh needed.
1520 * > 0 means you need to refresh this and you MUST call
1521 * ocfs2_complete_lock_res_refresh afterwards. */
1522 static int ocfs2_should_refresh_lock_res(struct ocfs2_lock_res *lockres)
1524 unsigned long flags;
1530 spin_lock_irqsave(&lockres->l_lock, flags);
1531 if (!(lockres->l_flags & OCFS2_LOCK_NEEDS_REFRESH)) {
1532 spin_unlock_irqrestore(&lockres->l_lock, flags);
1536 if (lockres->l_flags & OCFS2_LOCK_REFRESHING) {
1537 spin_unlock_irqrestore(&lockres->l_lock, flags);
1539 ocfs2_wait_on_refreshing_lock(lockres);
1543 /* Ok, I'll be the one to refresh this lock. */
1544 lockres_or_flags(lockres, OCFS2_LOCK_REFRESHING);
1545 spin_unlock_irqrestore(&lockres->l_lock, flags);
1553 /* If status is non zero, I'll mark it as not being in refresh
1554 * anymroe, but i won't clear the needs refresh flag. */
1555 static inline void ocfs2_complete_lock_res_refresh(struct ocfs2_lock_res *lockres,
1558 unsigned long flags;
1561 spin_lock_irqsave(&lockres->l_lock, flags);
1562 lockres_clear_flags(lockres, OCFS2_LOCK_REFRESHING);
1564 lockres_clear_flags(lockres, OCFS2_LOCK_NEEDS_REFRESH);
1565 spin_unlock_irqrestore(&lockres->l_lock, flags);
1567 wake_up(&lockres->l_event);
1572 /* may or may not return a bh if it went to disk. */
1573 static int ocfs2_meta_lock_update(struct inode *inode,
1574 struct buffer_head **bh)
1577 struct ocfs2_inode_info *oi = OCFS2_I(inode);
1578 struct ocfs2_lock_res *lockres;
1579 struct ocfs2_dinode *fe;
1583 spin_lock(&oi->ip_lock);
1584 if (oi->ip_flags & OCFS2_INODE_DELETED) {
1585 mlog(0, "Orphaned inode %llu was deleted while we "
1586 "were waiting on a lock. ip_flags = 0x%x\n",
1587 (unsigned long long)oi->ip_blkno, oi->ip_flags);
1588 spin_unlock(&oi->ip_lock);
1592 spin_unlock(&oi->ip_lock);
1594 lockres = &oi->ip_meta_lockres;
1596 if (!ocfs2_should_refresh_lock_res(lockres))
1599 /* This will discard any caching information we might have had
1600 * for the inode metadata. */
1601 ocfs2_metadata_cache_purge(inode);
1603 /* will do nothing for inode types that don't use the extent
1604 * map (directories, bitmap files, etc) */
1605 ocfs2_extent_map_trunc(inode, 0);
1607 if (ocfs2_meta_lvb_is_trustable(inode, lockres)) {
1608 mlog(0, "Trusting LVB on inode %llu\n",
1609 (unsigned long long)oi->ip_blkno);
1610 ocfs2_refresh_inode_from_lvb(inode);
1612 /* Boo, we have to go to disk. */
1613 /* read bh, cast, ocfs2_refresh_inode */
1614 status = ocfs2_read_block(OCFS2_SB(inode->i_sb), oi->ip_blkno,
1615 bh, OCFS2_BH_CACHED, inode);
1620 fe = (struct ocfs2_dinode *) (*bh)->b_data;
1622 /* This is a good chance to make sure we're not
1623 * locking an invalid object.
1625 * We bug on a stale inode here because we checked
1626 * above whether it was wiped from disk. The wiping
1627 * node provides a guarantee that we receive that
1628 * message and can mark the inode before dropping any
1629 * locks associated with it. */
1630 if (!OCFS2_IS_VALID_DINODE(fe)) {
1631 OCFS2_RO_ON_INVALID_DINODE(inode->i_sb, fe);
1635 mlog_bug_on_msg(inode->i_generation !=
1636 le32_to_cpu(fe->i_generation),
1637 "Invalid dinode %llu disk generation: %u "
1638 "inode->i_generation: %u\n",
1639 (unsigned long long)oi->ip_blkno,
1640 le32_to_cpu(fe->i_generation),
1641 inode->i_generation);
1642 mlog_bug_on_msg(le64_to_cpu(fe->i_dtime) ||
1643 !(fe->i_flags & cpu_to_le32(OCFS2_VALID_FL)),
1644 "Stale dinode %llu dtime: %llu flags: 0x%x\n",
1645 (unsigned long long)oi->ip_blkno,
1646 (unsigned long long)le64_to_cpu(fe->i_dtime),
1647 le32_to_cpu(fe->i_flags));
1649 ocfs2_refresh_inode(inode, fe);
1654 ocfs2_complete_lock_res_refresh(lockres, status);
1660 static int ocfs2_assign_bh(struct inode *inode,
1661 struct buffer_head **ret_bh,
1662 struct buffer_head *passed_bh)
1667 /* Ok, the update went to disk for us, use the
1669 *ret_bh = passed_bh;
1675 status = ocfs2_read_block(OCFS2_SB(inode->i_sb),
1676 OCFS2_I(inode)->ip_blkno,
1687 * returns < 0 error if the callback will never be called, otherwise
1688 * the result of the lock will be communicated via the callback.
1690 int ocfs2_meta_lock_full(struct inode *inode,
1691 struct ocfs2_journal_handle *handle,
1692 struct buffer_head **ret_bh,
1696 int status, level, dlm_flags, acquired;
1697 struct ocfs2_lock_res *lockres;
1698 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1699 struct buffer_head *local_bh = NULL;
1705 mlog(0, "inode %llu, take %s META lock\n",
1706 (unsigned long long)OCFS2_I(inode)->ip_blkno,
1707 ex ? "EXMODE" : "PRMODE");
1711 /* We'll allow faking a readonly metadata lock for
1713 if (ocfs2_is_hard_readonly(osb)) {
1719 if (!(arg_flags & OCFS2_META_LOCK_RECOVERY))
1720 wait_event(osb->recovery_event,
1721 ocfs2_node_map_is_empty(osb, &osb->recovery_map));
1724 lockres = &OCFS2_I(inode)->ip_meta_lockres;
1725 level = ex ? LKM_EXMODE : LKM_PRMODE;
1727 if (arg_flags & OCFS2_META_LOCK_NOQUEUE)
1728 dlm_flags |= LKM_NOQUEUE;
1730 status = ocfs2_cluster_lock(osb, lockres, level, dlm_flags, arg_flags);
1732 if (status != -EAGAIN && status != -EIOCBRETRY)
1737 /* Notify the error cleanup path to drop the cluster lock. */
1740 /* We wait twice because a node may have died while we were in
1741 * the lower dlm layers. The second time though, we've
1742 * committed to owning this lock so we don't allow signals to
1743 * abort the operation. */
1744 if (!(arg_flags & OCFS2_META_LOCK_RECOVERY))
1745 wait_event(osb->recovery_event,
1746 ocfs2_node_map_is_empty(osb, &osb->recovery_map));
1749 * We only see this flag if we're being called from
1750 * ocfs2_read_locked_inode(). It means we're locking an inode
1751 * which hasn't been populated yet, so clear the refresh flag
1752 * and let the caller handle it.
1754 if (inode->i_state & I_NEW) {
1756 ocfs2_complete_lock_res_refresh(lockres, 0);
1760 /* This is fun. The caller may want a bh back, or it may
1761 * not. ocfs2_meta_lock_update definitely wants one in, but
1762 * may or may not read one, depending on what's in the
1763 * LVB. The result of all of this is that we've *only* gone to
1764 * disk if we have to, so the complexity is worthwhile. */
1765 status = ocfs2_meta_lock_update(inode, &local_bh);
1767 if (status != -ENOENT)
1773 status = ocfs2_assign_bh(inode, ret_bh, local_bh);
1781 status = ocfs2_handle_add_lock(handle, inode);
1788 if (ret_bh && (*ret_bh)) {
1793 ocfs2_meta_unlock(inode, ex);
1804 * This is working around a lock inversion between tasks acquiring DLM locks
1805 * while holding a page lock and the vote thread which blocks dlm lock acquiry
1806 * while acquiring page locks.
1808 * ** These _with_page variantes are only intended to be called from aop
1809 * methods that hold page locks and return a very specific *positive* error
1810 * code that aop methods pass up to the VFS -- test for errors with != 0. **
1812 * The DLM is called such that it returns -EAGAIN if it would have blocked
1813 * waiting for the vote thread. In that case we unlock our page so the vote
1814 * thread can make progress. Once we've done this we have to return
1815 * AOP_TRUNCATED_PAGE so the aop method that called us can bubble that back up
1816 * into the VFS who will then immediately retry the aop call.
1818 * We do a blocking lock and immediate unlock before returning, though, so that
1819 * the lock has a great chance of being cached on this node by the time the VFS
1820 * calls back to retry the aop. This has a potential to livelock as nodes
1821 * ping locks back and forth, but that's a risk we're willing to take to avoid
1822 * the lock inversion simply.
1824 int ocfs2_meta_lock_with_page(struct inode *inode,
1825 struct ocfs2_journal_handle *handle,
1826 struct buffer_head **ret_bh,
1832 ret = ocfs2_meta_lock_full(inode, handle, ret_bh, ex,
1833 OCFS2_LOCK_NONBLOCK);
1834 if (ret == -EAGAIN) {
1836 if (ocfs2_meta_lock(inode, handle, ret_bh, ex) == 0)
1837 ocfs2_meta_unlock(inode, ex);
1838 ret = AOP_TRUNCATED_PAGE;
1844 void ocfs2_meta_unlock(struct inode *inode,
1847 int level = ex ? LKM_EXMODE : LKM_PRMODE;
1848 struct ocfs2_lock_res *lockres = &OCFS2_I(inode)->ip_meta_lockres;
1852 mlog(0, "inode %llu drop %s META lock\n",
1853 (unsigned long long)OCFS2_I(inode)->ip_blkno,
1854 ex ? "EXMODE" : "PRMODE");
1856 if (!ocfs2_is_hard_readonly(OCFS2_SB(inode->i_sb)))
1857 ocfs2_cluster_unlock(OCFS2_SB(inode->i_sb), lockres, level);
1862 int ocfs2_super_lock(struct ocfs2_super *osb,
1866 int level = ex ? LKM_EXMODE : LKM_PRMODE;
1867 struct ocfs2_lock_res *lockres = &osb->osb_super_lockres;
1868 struct buffer_head *bh;
1869 struct ocfs2_slot_info *si = osb->slot_info;
1873 if (ocfs2_is_hard_readonly(osb))
1876 status = ocfs2_cluster_lock(osb, lockres, level, 0, 0);
1882 /* The super block lock path is really in the best position to
1883 * know when resources covered by the lock need to be
1884 * refreshed, so we do it here. Of course, making sense of
1885 * everything is up to the caller :) */
1886 status = ocfs2_should_refresh_lock_res(lockres);
1893 status = ocfs2_read_block(osb, bh->b_blocknr, &bh, 0,
1896 ocfs2_update_slot_info(si);
1898 ocfs2_complete_lock_res_refresh(lockres, status);
1908 void ocfs2_super_unlock(struct ocfs2_super *osb,
1911 int level = ex ? LKM_EXMODE : LKM_PRMODE;
1912 struct ocfs2_lock_res *lockres = &osb->osb_super_lockres;
1914 ocfs2_cluster_unlock(osb, lockres, level);
1917 int ocfs2_rename_lock(struct ocfs2_super *osb)
1920 struct ocfs2_lock_res *lockres = &osb->osb_rename_lockres;
1922 if (ocfs2_is_hard_readonly(osb))
1925 status = ocfs2_cluster_lock(osb, lockres, LKM_EXMODE, 0, 0);
1932 void ocfs2_rename_unlock(struct ocfs2_super *osb)
1934 struct ocfs2_lock_res *lockres = &osb->osb_rename_lockres;
1936 ocfs2_cluster_unlock(osb, lockres, LKM_EXMODE);
1939 int ocfs2_dentry_lock(struct dentry *dentry, int ex)
1942 int level = ex ? LKM_EXMODE : LKM_PRMODE;
1943 struct ocfs2_dentry_lock *dl = dentry->d_fsdata;
1944 struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb);
1948 if (ocfs2_is_hard_readonly(osb))
1951 ret = ocfs2_cluster_lock(osb, &dl->dl_lockres, level, 0, 0);
1958 void ocfs2_dentry_unlock(struct dentry *dentry, int ex)
1960 int level = ex ? LKM_EXMODE : LKM_PRMODE;
1961 struct ocfs2_dentry_lock *dl = dentry->d_fsdata;
1962 struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb);
1964 ocfs2_cluster_unlock(osb, &dl->dl_lockres, level);
1967 /* Reference counting of the dlm debug structure. We want this because
1968 * open references on the debug inodes can live on after a mount, so
1969 * we can't rely on the ocfs2_super to always exist. */
1970 static void ocfs2_dlm_debug_free(struct kref *kref)
1972 struct ocfs2_dlm_debug *dlm_debug;
1974 dlm_debug = container_of(kref, struct ocfs2_dlm_debug, d_refcnt);
1979 void ocfs2_put_dlm_debug(struct ocfs2_dlm_debug *dlm_debug)
1982 kref_put(&dlm_debug->d_refcnt, ocfs2_dlm_debug_free);
1985 static void ocfs2_get_dlm_debug(struct ocfs2_dlm_debug *debug)
1987 kref_get(&debug->d_refcnt);
1990 struct ocfs2_dlm_debug *ocfs2_new_dlm_debug(void)
1992 struct ocfs2_dlm_debug *dlm_debug;
1994 dlm_debug = kmalloc(sizeof(struct ocfs2_dlm_debug), GFP_KERNEL);
1996 mlog_errno(-ENOMEM);
2000 kref_init(&dlm_debug->d_refcnt);
2001 INIT_LIST_HEAD(&dlm_debug->d_lockres_tracking);
2002 dlm_debug->d_locking_state = NULL;
2007 /* Access to this is arbitrated for us via seq_file->sem. */
2008 struct ocfs2_dlm_seq_priv {
2009 struct ocfs2_dlm_debug *p_dlm_debug;
2010 struct ocfs2_lock_res p_iter_res;
2011 struct ocfs2_lock_res p_tmp_res;
2014 static struct ocfs2_lock_res *ocfs2_dlm_next_res(struct ocfs2_lock_res *start,
2015 struct ocfs2_dlm_seq_priv *priv)
2017 struct ocfs2_lock_res *iter, *ret = NULL;
2018 struct ocfs2_dlm_debug *dlm_debug = priv->p_dlm_debug;
2020 assert_spin_locked(&ocfs2_dlm_tracking_lock);
2022 list_for_each_entry(iter, &start->l_debug_list, l_debug_list) {
2023 /* discover the head of the list */
2024 if (&iter->l_debug_list == &dlm_debug->d_lockres_tracking) {
2025 mlog(0, "End of list found, %p\n", ret);
2029 /* We track our "dummy" iteration lockres' by a NULL
2031 if (iter->l_ops != NULL) {
2040 static void *ocfs2_dlm_seq_start(struct seq_file *m, loff_t *pos)
2042 struct ocfs2_dlm_seq_priv *priv = m->private;
2043 struct ocfs2_lock_res *iter;
2045 spin_lock(&ocfs2_dlm_tracking_lock);
2046 iter = ocfs2_dlm_next_res(&priv->p_iter_res, priv);
2048 /* Since lockres' have the lifetime of their container
2049 * (which can be inodes, ocfs2_supers, etc) we want to
2050 * copy this out to a temporary lockres while still
2051 * under the spinlock. Obviously after this we can't
2052 * trust any pointers on the copy returned, but that's
2053 * ok as the information we want isn't typically held
2055 priv->p_tmp_res = *iter;
2056 iter = &priv->p_tmp_res;
2058 spin_unlock(&ocfs2_dlm_tracking_lock);
2063 static void ocfs2_dlm_seq_stop(struct seq_file *m, void *v)
2067 static void *ocfs2_dlm_seq_next(struct seq_file *m, void *v, loff_t *pos)
2069 struct ocfs2_dlm_seq_priv *priv = m->private;
2070 struct ocfs2_lock_res *iter = v;
2071 struct ocfs2_lock_res *dummy = &priv->p_iter_res;
2073 spin_lock(&ocfs2_dlm_tracking_lock);
2074 iter = ocfs2_dlm_next_res(iter, priv);
2075 list_del_init(&dummy->l_debug_list);
2077 list_add(&dummy->l_debug_list, &iter->l_debug_list);
2078 priv->p_tmp_res = *iter;
2079 iter = &priv->p_tmp_res;
2081 spin_unlock(&ocfs2_dlm_tracking_lock);
2086 /* So that debugfs.ocfs2 can determine which format is being used */
2087 #define OCFS2_DLM_DEBUG_STR_VERSION 1
2088 static int ocfs2_dlm_seq_show(struct seq_file *m, void *v)
2092 struct ocfs2_lock_res *lockres = v;
2097 seq_printf(m, "0x%x\t", OCFS2_DLM_DEBUG_STR_VERSION);
2099 if (lockres->l_type == OCFS2_LOCK_TYPE_DENTRY)
2100 seq_printf(m, "%.*s%08x\t", OCFS2_DENTRY_LOCK_INO_START - 1,
2102 (unsigned int)ocfs2_get_dentry_lock_ino(lockres));
2104 seq_printf(m, "%.*s\t", OCFS2_LOCK_ID_MAX_LEN, lockres->l_name);
2106 seq_printf(m, "%d\t"
2117 lockres->l_unlock_action,
2118 lockres->l_ro_holders,
2119 lockres->l_ex_holders,
2120 lockres->l_requested,
2121 lockres->l_blocking);
2123 /* Dump the raw LVB */
2124 lvb = lockres->l_lksb.lvb;
2125 for(i = 0; i < DLM_LVB_LEN; i++)
2126 seq_printf(m, "0x%x\t", lvb[i]);
2129 seq_printf(m, "\n");
2133 static struct seq_operations ocfs2_dlm_seq_ops = {
2134 .start = ocfs2_dlm_seq_start,
2135 .stop = ocfs2_dlm_seq_stop,
2136 .next = ocfs2_dlm_seq_next,
2137 .show = ocfs2_dlm_seq_show,
2140 static int ocfs2_dlm_debug_release(struct inode *inode, struct file *file)
2142 struct seq_file *seq = (struct seq_file *) file->private_data;
2143 struct ocfs2_dlm_seq_priv *priv = seq->private;
2144 struct ocfs2_lock_res *res = &priv->p_iter_res;
2146 ocfs2_remove_lockres_tracking(res);
2147 ocfs2_put_dlm_debug(priv->p_dlm_debug);
2148 return seq_release_private(inode, file);
2151 static int ocfs2_dlm_debug_open(struct inode *inode, struct file *file)
2154 struct ocfs2_dlm_seq_priv *priv;
2155 struct seq_file *seq;
2156 struct ocfs2_super *osb;
2158 priv = kzalloc(sizeof(struct ocfs2_dlm_seq_priv), GFP_KERNEL);
2164 osb = (struct ocfs2_super *) inode->u.generic_ip;
2165 ocfs2_get_dlm_debug(osb->osb_dlm_debug);
2166 priv->p_dlm_debug = osb->osb_dlm_debug;
2167 INIT_LIST_HEAD(&priv->p_iter_res.l_debug_list);
2169 ret = seq_open(file, &ocfs2_dlm_seq_ops);
2176 seq = (struct seq_file *) file->private_data;
2177 seq->private = priv;
2179 ocfs2_add_lockres_tracking(&priv->p_iter_res,
2186 static const struct file_operations ocfs2_dlm_debug_fops = {
2187 .open = ocfs2_dlm_debug_open,
2188 .release = ocfs2_dlm_debug_release,
2190 .llseek = seq_lseek,
2193 static int ocfs2_dlm_init_debug(struct ocfs2_super *osb)
2196 struct ocfs2_dlm_debug *dlm_debug = osb->osb_dlm_debug;
2198 dlm_debug->d_locking_state = debugfs_create_file("locking_state",
2200 osb->osb_debug_root,
2202 &ocfs2_dlm_debug_fops);
2203 if (!dlm_debug->d_locking_state) {
2206 "Unable to create locking state debugfs file.\n");
2210 ocfs2_get_dlm_debug(dlm_debug);
2215 static void ocfs2_dlm_shutdown_debug(struct ocfs2_super *osb)
2217 struct ocfs2_dlm_debug *dlm_debug = osb->osb_dlm_debug;
2220 debugfs_remove(dlm_debug->d_locking_state);
2221 ocfs2_put_dlm_debug(dlm_debug);
2225 int ocfs2_dlm_init(struct ocfs2_super *osb)
2229 struct dlm_ctxt *dlm;
2233 status = ocfs2_dlm_init_debug(osb);
2239 /* launch vote thread */
2240 osb->vote_task = kthread_run(ocfs2_vote_thread, osb, "ocfs2vote");
2241 if (IS_ERR(osb->vote_task)) {
2242 status = PTR_ERR(osb->vote_task);
2243 osb->vote_task = NULL;
2248 /* used by the dlm code to make message headers unique, each
2249 * node in this domain must agree on this. */
2250 dlm_key = crc32_le(0, osb->uuid_str, strlen(osb->uuid_str));
2252 /* for now, uuid == domain */
2253 dlm = dlm_register_domain(osb->uuid_str, dlm_key);
2255 status = PTR_ERR(dlm);
2260 ocfs2_super_lock_res_init(&osb->osb_super_lockres, osb);
2261 ocfs2_rename_lock_res_init(&osb->osb_rename_lockres, osb);
2263 dlm_register_eviction_cb(dlm, &osb->osb_eviction_cb);
2270 ocfs2_dlm_shutdown_debug(osb);
2272 kthread_stop(osb->vote_task);
2279 void ocfs2_dlm_shutdown(struct ocfs2_super *osb)
2283 dlm_unregister_eviction_cb(&osb->osb_eviction_cb);
2285 ocfs2_drop_osb_locks(osb);
2287 if (osb->vote_task) {
2288 kthread_stop(osb->vote_task);
2289 osb->vote_task = NULL;
2292 ocfs2_lock_res_free(&osb->osb_super_lockres);
2293 ocfs2_lock_res_free(&osb->osb_rename_lockres);
2295 dlm_unregister_domain(osb->dlm);
2298 ocfs2_dlm_shutdown_debug(osb);
2303 static void ocfs2_unlock_ast_func(void *opaque, enum dlm_status status)
2305 struct ocfs2_lock_res *lockres = opaque;
2306 unsigned long flags;
2310 mlog(0, "UNLOCK AST called on lock %s, action = %d\n", lockres->l_name,
2311 lockres->l_unlock_action);
2313 spin_lock_irqsave(&lockres->l_lock, flags);
2314 /* We tried to cancel a convert request, but it was already
2315 * granted. All we want to do here is clear our unlock
2316 * state. The wake_up call done at the bottom is redundant
2317 * (ocfs2_prepare_cancel_convert doesn't sleep on this) but doesn't
2318 * hurt anything anyway */
2319 if (status == DLM_CANCELGRANT &&
2320 lockres->l_unlock_action == OCFS2_UNLOCK_CANCEL_CONVERT) {
2321 mlog(0, "Got cancelgrant for %s\n", lockres->l_name);
2323 /* We don't clear the busy flag in this case as it
2324 * should have been cleared by the ast which the dlm
2326 goto complete_unlock;
2329 if (status != DLM_NORMAL) {
2330 mlog(ML_ERROR, "Dlm passes status %d for lock %s, "
2331 "unlock_action %d\n", status, lockres->l_name,
2332 lockres->l_unlock_action);
2333 spin_unlock_irqrestore(&lockres->l_lock, flags);
2337 switch(lockres->l_unlock_action) {
2338 case OCFS2_UNLOCK_CANCEL_CONVERT:
2339 mlog(0, "Cancel convert success for %s\n", lockres->l_name);
2340 lockres->l_action = OCFS2_AST_INVALID;
2342 case OCFS2_UNLOCK_DROP_LOCK:
2343 lockres->l_level = LKM_IVMODE;
2349 lockres_clear_flags(lockres, OCFS2_LOCK_BUSY);
2351 lockres->l_unlock_action = OCFS2_UNLOCK_INVALID;
2352 spin_unlock_irqrestore(&lockres->l_lock, flags);
2354 wake_up(&lockres->l_event);
2359 typedef void (ocfs2_pre_drop_cb_t)(struct ocfs2_lock_res *, void *);
2361 struct drop_lock_cb {
2362 ocfs2_pre_drop_cb_t *drop_func;
2366 static int ocfs2_drop_lock(struct ocfs2_super *osb,
2367 struct ocfs2_lock_res *lockres,
2368 struct drop_lock_cb *dcb)
2370 enum dlm_status status;
2371 unsigned long flags;
2373 /* We didn't get anywhere near actually using this lockres. */
2374 if (!(lockres->l_flags & OCFS2_LOCK_INITIALIZED))
2377 spin_lock_irqsave(&lockres->l_lock, flags);
2379 mlog_bug_on_msg(!(lockres->l_flags & OCFS2_LOCK_FREEING),
2380 "lockres %s, flags 0x%lx\n",
2381 lockres->l_name, lockres->l_flags);
2383 while (lockres->l_flags & OCFS2_LOCK_BUSY) {
2384 mlog(0, "waiting on busy lock \"%s\": flags = %lx, action = "
2385 "%u, unlock_action = %u\n",
2386 lockres->l_name, lockres->l_flags, lockres->l_action,
2387 lockres->l_unlock_action);
2389 spin_unlock_irqrestore(&lockres->l_lock, flags);
2391 /* XXX: Today we just wait on any busy
2392 * locks... Perhaps we need to cancel converts in the
2394 ocfs2_wait_on_busy_lock(lockres);
2396 spin_lock_irqsave(&lockres->l_lock, flags);
2400 dcb->drop_func(lockres, dcb->drop_data);
2402 if (lockres->l_flags & OCFS2_LOCK_BUSY)
2403 mlog(ML_ERROR, "destroying busy lock: \"%s\"\n",
2405 if (lockres->l_flags & OCFS2_LOCK_BLOCKED)
2406 mlog(0, "destroying blocked lock: \"%s\"\n", lockres->l_name);
2408 if (!(lockres->l_flags & OCFS2_LOCK_ATTACHED)) {
2409 spin_unlock_irqrestore(&lockres->l_lock, flags);
2413 lockres_clear_flags(lockres, OCFS2_LOCK_ATTACHED);
2415 /* make sure we never get here while waiting for an ast to
2417 BUG_ON(lockres->l_action != OCFS2_AST_INVALID);
2419 /* is this necessary? */
2420 lockres_or_flags(lockres, OCFS2_LOCK_BUSY);
2421 lockres->l_unlock_action = OCFS2_UNLOCK_DROP_LOCK;
2422 spin_unlock_irqrestore(&lockres->l_lock, flags);
2424 mlog(0, "lock %s\n", lockres->l_name);
2426 status = dlmunlock(osb->dlm, &lockres->l_lksb, LKM_VALBLK,
2427 lockres->l_ops->unlock_ast, lockres);
2428 if (status != DLM_NORMAL) {
2429 ocfs2_log_dlm_error("dlmunlock", status, lockres);
2430 mlog(ML_ERROR, "lockres flags: %lu\n", lockres->l_flags);
2431 dlm_print_one_lock(lockres->l_lksb.lockid);
2434 mlog(0, "lock %s, successfull return from dlmunlock\n",
2437 ocfs2_wait_on_busy_lock(lockres);
2443 /* Mark the lockres as being dropped. It will no longer be
2444 * queued if blocking, but we still may have to wait on it
2445 * being dequeued from the vote thread before we can consider
2448 * You can *not* attempt to call cluster_lock on this lockres anymore. */
2449 void ocfs2_mark_lockres_freeing(struct ocfs2_lock_res *lockres)
2452 struct ocfs2_mask_waiter mw;
2453 unsigned long flags;
2455 ocfs2_init_mask_waiter(&mw);
2457 spin_lock_irqsave(&lockres->l_lock, flags);
2458 lockres->l_flags |= OCFS2_LOCK_FREEING;
2459 while (lockres->l_flags & OCFS2_LOCK_QUEUED) {
2460 lockres_add_mask_waiter(lockres, &mw, OCFS2_LOCK_QUEUED, 0);
2461 spin_unlock_irqrestore(&lockres->l_lock, flags);
2463 mlog(0, "Waiting on lockres %s\n", lockres->l_name);
2465 status = ocfs2_wait_for_mask(&mw);
2469 spin_lock_irqsave(&lockres->l_lock, flags);
2471 spin_unlock_irqrestore(&lockres->l_lock, flags);
2474 void ocfs2_simple_drop_lockres(struct ocfs2_super *osb,
2475 struct ocfs2_lock_res *lockres)
2479 ocfs2_mark_lockres_freeing(lockres);
2480 ret = ocfs2_drop_lock(osb, lockres, NULL);
2485 static void ocfs2_drop_osb_locks(struct ocfs2_super *osb)
2487 ocfs2_simple_drop_lockres(osb, &osb->osb_super_lockres);
2488 ocfs2_simple_drop_lockres(osb, &osb->osb_rename_lockres);
2491 static void ocfs2_meta_pre_drop(struct ocfs2_lock_res *lockres, void *data)
2493 struct inode *inode = data;
2495 /* the metadata lock requires a bit more work as we have an
2496 * LVB to worry about. */
2497 if (lockres->l_flags & OCFS2_LOCK_ATTACHED &&
2498 lockres->l_level == LKM_EXMODE &&
2499 !(lockres->l_flags & OCFS2_LOCK_NEEDS_REFRESH))
2500 __ocfs2_stuff_meta_lvb(inode);
2503 int ocfs2_drop_inode_locks(struct inode *inode)
2506 struct drop_lock_cb meta_dcb = { ocfs2_meta_pre_drop, inode, };
2510 /* No need to call ocfs2_mark_lockres_freeing here -
2511 * ocfs2_clear_inode has done it for us. */
2513 err = ocfs2_drop_lock(OCFS2_SB(inode->i_sb),
2514 &OCFS2_I(inode)->ip_data_lockres,
2521 err = ocfs2_drop_lock(OCFS2_SB(inode->i_sb),
2522 &OCFS2_I(inode)->ip_meta_lockres,
2526 if (err < 0 && !status)
2529 err = ocfs2_drop_lock(OCFS2_SB(inode->i_sb),
2530 &OCFS2_I(inode)->ip_rw_lockres,
2534 if (err < 0 && !status)
2541 static void ocfs2_prepare_downconvert(struct ocfs2_lock_res *lockres,
2544 assert_spin_locked(&lockres->l_lock);
2546 BUG_ON(lockres->l_blocking <= LKM_NLMODE);
2548 if (lockres->l_level <= new_level) {
2549 mlog(ML_ERROR, "lockres->l_level (%u) <= new_level (%u)\n",
2550 lockres->l_level, new_level);
2554 mlog(0, "lock %s, new_level = %d, l_blocking = %d\n",
2555 lockres->l_name, new_level, lockres->l_blocking);
2557 lockres->l_action = OCFS2_AST_DOWNCONVERT;
2558 lockres->l_requested = new_level;
2559 lockres_or_flags(lockres, OCFS2_LOCK_BUSY);
2562 static int ocfs2_downconvert_lock(struct ocfs2_super *osb,
2563 struct ocfs2_lock_res *lockres,
2567 int ret, dlm_flags = LKM_CONVERT;
2568 enum dlm_status status;
2573 dlm_flags |= LKM_VALBLK;
2575 status = dlmlock(osb->dlm,
2580 OCFS2_LOCK_ID_MAX_LEN - 1,
2581 lockres->l_ops->ast,
2583 lockres->l_ops->bast);
2584 if (status != DLM_NORMAL) {
2585 ocfs2_log_dlm_error("dlmlock", status, lockres);
2587 ocfs2_recover_from_dlm_error(lockres, 1);
2597 /* returns 1 when the caller should unlock and call dlmunlock */
2598 static int ocfs2_prepare_cancel_convert(struct ocfs2_super *osb,
2599 struct ocfs2_lock_res *lockres)
2601 assert_spin_locked(&lockres->l_lock);
2604 mlog(0, "lock %s\n", lockres->l_name);
2606 if (lockres->l_unlock_action == OCFS2_UNLOCK_CANCEL_CONVERT) {
2607 /* If we're already trying to cancel a lock conversion
2608 * then just drop the spinlock and allow the caller to
2609 * requeue this lock. */
2611 mlog(0, "Lockres %s, skip convert\n", lockres->l_name);
2615 /* were we in a convert when we got the bast fire? */
2616 BUG_ON(lockres->l_action != OCFS2_AST_CONVERT &&
2617 lockres->l_action != OCFS2_AST_DOWNCONVERT);
2618 /* set things up for the unlockast to know to just
2619 * clear out the ast_action and unset busy, etc. */
2620 lockres->l_unlock_action = OCFS2_UNLOCK_CANCEL_CONVERT;
2622 mlog_bug_on_msg(!(lockres->l_flags & OCFS2_LOCK_BUSY),
2623 "lock %s, invalid flags: 0x%lx\n",
2624 lockres->l_name, lockres->l_flags);
2629 static int ocfs2_cancel_convert(struct ocfs2_super *osb,
2630 struct ocfs2_lock_res *lockres)
2633 enum dlm_status status;
2636 mlog(0, "lock %s\n", lockres->l_name);
2639 status = dlmunlock(osb->dlm,
2642 lockres->l_ops->unlock_ast,
2644 if (status != DLM_NORMAL) {
2645 ocfs2_log_dlm_error("dlmunlock", status, lockres);
2647 ocfs2_recover_from_dlm_error(lockres, 0);
2650 mlog(0, "lock %s return from dlmunlock\n", lockres->l_name);
2656 static inline int ocfs2_can_downconvert_meta_lock(struct inode *inode,
2657 struct ocfs2_lock_res *lockres,
2664 BUG_ON(new_level != LKM_NLMODE && new_level != LKM_PRMODE);
2666 if (lockres->l_flags & OCFS2_LOCK_REFRESHING) {
2668 mlog(0, "lockres %s currently being refreshed -- backing "
2669 "off!\n", lockres->l_name);
2670 } else if (new_level == LKM_PRMODE)
2671 ret = !lockres->l_ex_holders &&
2672 ocfs2_inode_fully_checkpointed(inode);
2673 else /* Must be NLMODE we're converting to. */
2674 ret = !lockres->l_ro_holders && !lockres->l_ex_holders &&
2675 ocfs2_inode_fully_checkpointed(inode);
2681 static int ocfs2_do_unblock_meta(struct inode *inode,
2687 struct ocfs2_lock_res *lockres = &OCFS2_I(inode)->ip_meta_lockres;
2688 unsigned long flags;
2690 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
2694 spin_lock_irqsave(&lockres->l_lock, flags);
2696 BUG_ON(!(lockres->l_flags & OCFS2_LOCK_BLOCKED));
2698 mlog(0, "l_level=%d, l_blocking=%d\n", lockres->l_level,
2699 lockres->l_blocking);
2701 BUG_ON(lockres->l_level != LKM_EXMODE &&
2702 lockres->l_level != LKM_PRMODE);
2704 if (lockres->l_flags & OCFS2_LOCK_BUSY) {
2706 ret = ocfs2_prepare_cancel_convert(osb, lockres);
2707 spin_unlock_irqrestore(&lockres->l_lock, flags);
2709 ret = ocfs2_cancel_convert(osb, lockres);
2716 new_level = ocfs2_highest_compat_lock_level(lockres->l_blocking);
2718 mlog(0, "l_level=%d, l_blocking=%d, new_level=%d\n",
2719 lockres->l_level, lockres->l_blocking, new_level);
2721 if (ocfs2_can_downconvert_meta_lock(inode, lockres, new_level)) {
2722 if (lockres->l_level == LKM_EXMODE)
2725 /* If the lock hasn't been refreshed yet (rare), then
2726 * our memory inode values are old and we skip
2727 * stuffing the lvb. There's no need to actually clear
2728 * out the lvb here as it's value is still valid. */
2729 if (!(lockres->l_flags & OCFS2_LOCK_NEEDS_REFRESH)) {
2731 __ocfs2_stuff_meta_lvb(inode);
2733 mlog(0, "lockres %s: downconverting stale lock!\n",
2736 mlog(0, "calling ocfs2_downconvert_lock with l_level=%d, "
2737 "l_blocking=%d, new_level=%d\n",
2738 lockres->l_level, lockres->l_blocking, new_level);
2740 ocfs2_prepare_downconvert(lockres, new_level);
2741 spin_unlock_irqrestore(&lockres->l_lock, flags);
2742 ret = ocfs2_downconvert_lock(osb, lockres, new_level, set_lvb);
2745 if (!ocfs2_inode_fully_checkpointed(inode))
2746 ocfs2_start_checkpoint(osb);
2749 spin_unlock_irqrestore(&lockres->l_lock, flags);
2756 static int ocfs2_generic_unblock_lock(struct ocfs2_super *osb,
2757 struct ocfs2_lock_res *lockres,
2758 struct ocfs2_unblock_ctl *ctl,
2759 ocfs2_convert_worker_t *worker)
2761 unsigned long flags;
2768 spin_lock_irqsave(&lockres->l_lock, flags);
2770 BUG_ON(!(lockres->l_flags & OCFS2_LOCK_BLOCKED));
2773 if (lockres->l_flags & OCFS2_LOCK_BUSY) {
2775 ret = ocfs2_prepare_cancel_convert(osb, lockres);
2776 spin_unlock_irqrestore(&lockres->l_lock, flags);
2778 ret = ocfs2_cancel_convert(osb, lockres);
2785 /* if we're blocking an exclusive and we have *any* holders,
2787 if ((lockres->l_blocking == LKM_EXMODE)
2788 && (lockres->l_ex_holders || lockres->l_ro_holders)) {
2789 spin_unlock_irqrestore(&lockres->l_lock, flags);
2795 /* If it's a PR we're blocking, then only
2796 * requeue if we've got any EX holders */
2797 if (lockres->l_blocking == LKM_PRMODE &&
2798 lockres->l_ex_holders) {
2799 spin_unlock_irqrestore(&lockres->l_lock, flags);
2805 /* If we get here, then we know that there are no more
2806 * incompatible holders (and anyone asking for an incompatible
2807 * lock is blocked). We can now downconvert the lock */
2811 /* Some lockres types want to do a bit of work before
2812 * downconverting a lock. Allow that here. The worker function
2813 * may sleep, so we save off a copy of what we're blocking as
2814 * it may change while we're not holding the spin lock. */
2815 blocking = lockres->l_blocking;
2816 spin_unlock_irqrestore(&lockres->l_lock, flags);
2818 ctl->unblock_action = worker(lockres, blocking);
2820 if (ctl->unblock_action == UNBLOCK_STOP_POST)
2823 spin_lock_irqsave(&lockres->l_lock, flags);
2824 if (blocking != lockres->l_blocking) {
2825 /* If this changed underneath us, then we can't drop
2832 new_level = ocfs2_highest_compat_lock_level(lockres->l_blocking);
2834 ocfs2_prepare_downconvert(lockres, new_level);
2835 spin_unlock_irqrestore(&lockres->l_lock, flags);
2836 ret = ocfs2_downconvert_lock(osb, lockres, new_level, 0);
2842 static int ocfs2_data_convert_worker(struct ocfs2_lock_res *lockres,
2845 struct inode *inode;
2846 struct address_space *mapping;
2848 inode = ocfs2_lock_res_inode(lockres);
2849 mapping = inode->i_mapping;
2851 if (filemap_fdatawrite(mapping)) {
2852 mlog(ML_ERROR, "Could not sync inode %llu for downconvert!",
2853 (unsigned long long)OCFS2_I(inode)->ip_blkno);
2855 sync_mapping_buffers(mapping);
2856 if (blocking == LKM_EXMODE) {
2857 truncate_inode_pages(mapping, 0);
2858 unmap_mapping_range(mapping, 0, 0, 0);
2860 /* We only need to wait on the I/O if we're not also
2861 * truncating pages because truncate_inode_pages waits
2862 * for us above. We don't truncate pages if we're
2863 * blocking anything < EXMODE because we want to keep
2864 * them around in that case. */
2865 filemap_fdatawait(mapping);
2868 return UNBLOCK_CONTINUE;
2871 int ocfs2_unblock_data(struct ocfs2_lock_res *lockres,
2872 struct ocfs2_unblock_ctl *ctl)
2875 struct inode *inode;
2876 struct ocfs2_super *osb;
2880 inode = ocfs2_lock_res_inode(lockres);
2881 osb = OCFS2_SB(inode->i_sb);
2883 mlog(0, "unblock inode %llu\n",
2884 (unsigned long long)OCFS2_I(inode)->ip_blkno);
2886 status = ocfs2_generic_unblock_lock(osb, lockres, ctl,
2887 ocfs2_data_convert_worker);
2891 mlog(0, "inode %llu, requeue = %d\n",
2892 (unsigned long long)OCFS2_I(inode)->ip_blkno, ctl->requeue);
2898 static int ocfs2_unblock_inode_lock(struct ocfs2_lock_res *lockres,
2899 struct ocfs2_unblock_ctl *ctl)
2902 struct inode *inode;
2906 mlog(0, "Unblock lockres %s\n", lockres->l_name);
2908 inode = ocfs2_lock_res_inode(lockres);
2910 status = ocfs2_generic_unblock_lock(OCFS2_SB(inode->i_sb),
2911 lockres, ctl, NULL);
2919 static int ocfs2_unblock_meta(struct ocfs2_lock_res *lockres,
2920 struct ocfs2_unblock_ctl *ctl)
2923 struct inode *inode;
2927 inode = ocfs2_lock_res_inode(lockres);
2929 mlog(0, "unblock inode %llu\n",
2930 (unsigned long long)OCFS2_I(inode)->ip_blkno);
2932 status = ocfs2_do_unblock_meta(inode, &ctl->requeue);
2936 mlog(0, "inode %llu, requeue = %d\n",
2937 (unsigned long long)OCFS2_I(inode)->ip_blkno, ctl->requeue);
2944 * Does the final reference drop on our dentry lock. Right now this
2945 * happens in the vote thread, but we could choose to simplify the
2946 * dlmglue API and push these off to the ocfs2_wq in the future.
2948 static void ocfs2_dentry_post_unlock(struct ocfs2_super *osb,
2949 struct ocfs2_lock_res *lockres)
2951 struct ocfs2_dentry_lock *dl = ocfs2_lock_res_dl(lockres);
2952 ocfs2_dentry_lock_put(osb, dl);
2956 * d_delete() matching dentries before the lock downconvert.
2958 * At this point, any process waiting to destroy the
2959 * dentry_lock due to last ref count is stopped by the
2960 * OCFS2_LOCK_QUEUED flag.
2962 * We have two potential problems
2964 * 1) If we do the last reference drop on our dentry_lock (via dput)
2965 * we'll wind up in ocfs2_release_dentry_lock(), waiting on
2966 * the downconvert to finish. Instead we take an elevated
2967 * reference and push the drop until after we've completed our
2968 * unblock processing.
2970 * 2) There might be another process with a final reference,
2971 * waiting on us to finish processing. If this is the case, we
2972 * detect it and exit out - there's no more dentries anyway.
2974 static int ocfs2_dentry_convert_worker(struct ocfs2_lock_res *lockres,
2977 struct ocfs2_dentry_lock *dl = ocfs2_lock_res_dl(lockres);
2978 struct ocfs2_inode_info *oi = OCFS2_I(dl->dl_inode);
2979 struct dentry *dentry;
2980 unsigned long flags;
2984 * This node is blocking another node from getting a read
2985 * lock. This happens when we've renamed within a
2986 * directory. We've forced the other nodes to d_delete(), but
2987 * we never actually dropped our lock because it's still
2988 * valid. The downconvert code will retain a PR for this node,
2989 * so there's no further work to do.
2991 if (blocking == LKM_PRMODE)
2992 return UNBLOCK_CONTINUE;
2995 * Mark this inode as potentially orphaned. The code in
2996 * ocfs2_delete_inode() will figure out whether it actually
2997 * needs to be freed or not.
2999 spin_lock(&oi->ip_lock);
3000 oi->ip_flags |= OCFS2_INODE_MAYBE_ORPHANED;
3001 spin_unlock(&oi->ip_lock);
3004 * Yuck. We need to make sure however that the check of
3005 * OCFS2_LOCK_FREEING and the extra reference are atomic with
3006 * respect to a reference decrement or the setting of that
3009 spin_lock_irqsave(&lockres->l_lock, flags);
3010 spin_lock(&dentry_attach_lock);
3011 if (!(lockres->l_flags & OCFS2_LOCK_FREEING)
3016 spin_unlock(&dentry_attach_lock);
3017 spin_unlock_irqrestore(&lockres->l_lock, flags);
3019 mlog(0, "extra_ref = %d\n", extra_ref);
3022 * We have a process waiting on us in ocfs2_dentry_iput(),
3023 * which means we can't have any more outstanding
3024 * aliases. There's no need to do any more work.
3027 return UNBLOCK_CONTINUE;
3029 spin_lock(&dentry_attach_lock);
3031 dentry = ocfs2_find_local_alias(dl->dl_inode,
3032 dl->dl_parent_blkno, 1);
3035 spin_unlock(&dentry_attach_lock);
3037 mlog(0, "d_delete(%.*s);\n", dentry->d_name.len,
3038 dentry->d_name.name);
3041 * The following dcache calls may do an
3042 * iput(). Normally we don't want that from the
3043 * downconverting thread, but in this case it's ok
3044 * because the requesting node already has an
3045 * exclusive lock on the inode, so it can't be queued
3046 * for a downconvert.
3051 spin_lock(&dentry_attach_lock);
3053 spin_unlock(&dentry_attach_lock);
3056 * If we are the last holder of this dentry lock, there is no
3057 * reason to downconvert so skip straight to the unlock.
3059 if (dl->dl_count == 1)
3060 return UNBLOCK_STOP_POST;
3062 return UNBLOCK_CONTINUE_POST;
3065 static int ocfs2_unblock_dentry_lock(struct ocfs2_lock_res *lockres,
3066 struct ocfs2_unblock_ctl *ctl)
3069 struct ocfs2_dentry_lock *dl = ocfs2_lock_res_dl(lockres);
3070 struct ocfs2_super *osb = OCFS2_SB(dl->dl_inode->i_sb);
3072 mlog(0, "unblock dentry lock: %llu\n",
3073 (unsigned long long)OCFS2_I(dl->dl_inode)->ip_blkno);
3075 ret = ocfs2_generic_unblock_lock(osb,
3078 ocfs2_dentry_convert_worker);
3082 mlog(0, "requeue = %d, post = %d\n", ctl->requeue, ctl->unblock_action);
3087 /* Generic unblock function for any lockres whose private data is an
3088 * ocfs2_super pointer. */
3089 static int ocfs2_unblock_osb_lock(struct ocfs2_lock_res *lockres,
3090 struct ocfs2_unblock_ctl *ctl)
3093 struct ocfs2_super *osb;
3097 mlog(0, "Unblock lockres %s\n", lockres->l_name);
3099 osb = ocfs2_lock_res_super(lockres);
3101 status = ocfs2_generic_unblock_lock(osb,
3112 void ocfs2_process_blocked_lock(struct ocfs2_super *osb,
3113 struct ocfs2_lock_res *lockres)
3116 struct ocfs2_unblock_ctl ctl = {0, 0,};
3117 unsigned long flags;
3119 /* Our reference to the lockres in this function can be
3120 * considered valid until we remove the OCFS2_LOCK_QUEUED
3126 BUG_ON(!lockres->l_ops);
3127 BUG_ON(!lockres->l_ops->unblock);
3129 mlog(0, "lockres %s blocked.\n", lockres->l_name);
3131 /* Detect whether a lock has been marked as going away while
3132 * the vote thread was processing other things. A lock can
3133 * still be marked with OCFS2_LOCK_FREEING after this check,
3134 * but short circuiting here will still save us some
3136 spin_lock_irqsave(&lockres->l_lock, flags);
3137 if (lockres->l_flags & OCFS2_LOCK_FREEING)
3139 spin_unlock_irqrestore(&lockres->l_lock, flags);
3141 status = lockres->l_ops->unblock(lockres, &ctl);
3145 spin_lock_irqsave(&lockres->l_lock, flags);
3147 if (lockres->l_flags & OCFS2_LOCK_FREEING || !ctl.requeue) {
3148 lockres_clear_flags(lockres, OCFS2_LOCK_QUEUED);
3150 ocfs2_schedule_blocked_lock(osb, lockres);
3152 mlog(0, "lockres %s, requeue = %s.\n", lockres->l_name,
3153 ctl.requeue ? "yes" : "no");
3154 spin_unlock_irqrestore(&lockres->l_lock, flags);
3156 if (ctl.unblock_action != UNBLOCK_CONTINUE
3157 && lockres->l_ops->post_unlock)
3158 lockres->l_ops->post_unlock(osb, lockres);
3163 static void ocfs2_schedule_blocked_lock(struct ocfs2_super *osb,
3164 struct ocfs2_lock_res *lockres)
3168 assert_spin_locked(&lockres->l_lock);
3170 if (lockres->l_flags & OCFS2_LOCK_FREEING) {
3171 /* Do not schedule a lock for downconvert when it's on
3172 * the way to destruction - any nodes wanting access
3173 * to the resource will get it soon. */
3174 mlog(0, "Lockres %s won't be scheduled: flags 0x%lx\n",
3175 lockres->l_name, lockres->l_flags);
3179 lockres_or_flags(lockres, OCFS2_LOCK_QUEUED);
3181 spin_lock(&osb->vote_task_lock);
3182 if (list_empty(&lockres->l_blocked_list)) {
3183 list_add_tail(&lockres->l_blocked_list,
3184 &osb->blocked_lock_list);
3185 osb->blocked_lock_count++;
3187 spin_unlock(&osb->vote_task_lock);
3192 /* This aids in debugging situations where a bad LVB might be involved. */
3193 void ocfs2_dump_meta_lvb_info(u64 level,
3194 const char *function,
3196 struct ocfs2_lock_res *lockres)
3198 struct ocfs2_meta_lvb *lvb = (struct ocfs2_meta_lvb *) lockres->l_lksb.lvb;
3200 mlog(level, "LVB information for %s (called from %s:%u):\n",
3201 lockres->l_name, function, line);
3202 mlog(level, "version: %u, clusters: %u, generation: 0x%x\n",
3203 lvb->lvb_version, be32_to_cpu(lvb->lvb_iclusters),
3204 be32_to_cpu(lvb->lvb_igeneration));
3205 mlog(level, "size: %llu, uid %u, gid %u, mode 0x%x\n",
3206 (unsigned long long)be64_to_cpu(lvb->lvb_isize),
3207 be32_to_cpu(lvb->lvb_iuid), be32_to_cpu(lvb->lvb_igid),
3208 be16_to_cpu(lvb->lvb_imode));
3209 mlog(level, "nlink %u, atime_packed 0x%llx, ctime_packed 0x%llx, "
3210 "mtime_packed 0x%llx iattr 0x%x\n", be16_to_cpu(lvb->lvb_inlink),
3211 (long long)be64_to_cpu(lvb->lvb_iatime_packed),
3212 (long long)be64_to_cpu(lvb->lvb_ictime_packed),
3213 (long long)be64_to_cpu(lvb->lvb_imtime_packed),
3214 be32_to_cpu(lvb->lvb_iattr));