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,
325 struct ocfs2_lock_res_ops *ops;
328 case OCFS2_LOCK_TYPE_RW:
329 ops = &ocfs2_inode_rw_lops;
331 case OCFS2_LOCK_TYPE_META:
332 ops = &ocfs2_inode_meta_lops;
334 case OCFS2_LOCK_TYPE_DATA:
335 ops = &ocfs2_inode_data_lops;
338 mlog_bug_on_msg(1, "type: %d\n", type);
339 ops = NULL; /* thanks, gcc */
343 ocfs2_build_lock_name(type, OCFS2_I(inode)->ip_blkno,
344 inode->i_generation, res->l_name);
345 ocfs2_lock_res_init_common(OCFS2_SB(inode->i_sb), res, type, ops, inode);
348 static __u64 ocfs2_get_dentry_lock_ino(struct ocfs2_lock_res *lockres)
350 __be64 inode_blkno_be;
352 memcpy(&inode_blkno_be, &lockres->l_name[OCFS2_DENTRY_LOCK_INO_START],
355 return be64_to_cpu(inode_blkno_be);
358 void ocfs2_dentry_lock_res_init(struct ocfs2_dentry_lock *dl,
359 u64 parent, struct inode *inode)
362 u64 inode_blkno = OCFS2_I(inode)->ip_blkno;
363 __be64 inode_blkno_be = cpu_to_be64(inode_blkno);
364 struct ocfs2_lock_res *lockres = &dl->dl_lockres;
366 ocfs2_lock_res_init_once(lockres);
369 * Unfortunately, the standard lock naming scheme won't work
370 * here because we have two 16 byte values to use. Instead,
371 * we'll stuff the inode number as a binary value. We still
372 * want error prints to show something without garbling the
373 * display, so drop a null byte in there before the inode
374 * number. A future version of OCFS2 will likely use all
375 * binary lock names. The stringified names have been a
376 * tremendous aid in debugging, but now that the debugfs
377 * interface exists, we can mangle things there if need be.
379 * NOTE: We also drop the standard "pad" value (the total lock
380 * name size stays the same though - the last part is all
381 * zeros due to the memset in ocfs2_lock_res_init_once()
383 len = snprintf(lockres->l_name, OCFS2_DENTRY_LOCK_INO_START,
385 ocfs2_lock_type_char(OCFS2_LOCK_TYPE_DENTRY),
388 BUG_ON(len != (OCFS2_DENTRY_LOCK_INO_START - 1));
390 memcpy(&lockres->l_name[OCFS2_DENTRY_LOCK_INO_START], &inode_blkno_be,
393 ocfs2_lock_res_init_common(OCFS2_SB(inode->i_sb), lockres,
394 OCFS2_LOCK_TYPE_DENTRY, &ocfs2_dentry_lops,
398 static void ocfs2_super_lock_res_init(struct ocfs2_lock_res *res,
399 struct ocfs2_super *osb)
401 /* Superblock lockres doesn't come from a slab so we call init
402 * once on it manually. */
403 ocfs2_lock_res_init_once(res);
404 ocfs2_build_lock_name(OCFS2_LOCK_TYPE_SUPER, OCFS2_SUPER_BLOCK_BLKNO,
406 ocfs2_lock_res_init_common(osb, res, OCFS2_LOCK_TYPE_SUPER,
407 &ocfs2_super_lops, osb);
410 static void ocfs2_rename_lock_res_init(struct ocfs2_lock_res *res,
411 struct ocfs2_super *osb)
413 /* Rename lockres doesn't come from a slab so we call init
414 * once on it manually. */
415 ocfs2_lock_res_init_once(res);
416 ocfs2_build_lock_name(OCFS2_LOCK_TYPE_RENAME, 0, 0, res->l_name);
417 ocfs2_lock_res_init_common(osb, res, OCFS2_LOCK_TYPE_RENAME,
418 &ocfs2_rename_lops, osb);
421 void ocfs2_lock_res_free(struct ocfs2_lock_res *res)
425 if (!(res->l_flags & OCFS2_LOCK_INITIALIZED))
428 ocfs2_remove_lockres_tracking(res);
430 mlog_bug_on_msg(!list_empty(&res->l_blocked_list),
431 "Lockres %s is on the blocked list\n",
433 mlog_bug_on_msg(!list_empty(&res->l_mask_waiters),
434 "Lockres %s has mask waiters pending\n",
436 mlog_bug_on_msg(spin_is_locked(&res->l_lock),
437 "Lockres %s is locked\n",
439 mlog_bug_on_msg(res->l_ro_holders,
440 "Lockres %s has %u ro holders\n",
441 res->l_name, res->l_ro_holders);
442 mlog_bug_on_msg(res->l_ex_holders,
443 "Lockres %s has %u ex holders\n",
444 res->l_name, res->l_ex_holders);
446 /* Need to clear out the lock status block for the dlm */
447 memset(&res->l_lksb, 0, sizeof(res->l_lksb));
453 static inline void ocfs2_inc_holders(struct ocfs2_lock_res *lockres,
462 lockres->l_ex_holders++;
465 lockres->l_ro_holders++;
474 static inline void ocfs2_dec_holders(struct ocfs2_lock_res *lockres,
483 BUG_ON(!lockres->l_ex_holders);
484 lockres->l_ex_holders--;
487 BUG_ON(!lockres->l_ro_holders);
488 lockres->l_ro_holders--;
496 /* WARNING: This function lives in a world where the only three lock
497 * levels are EX, PR, and NL. It *will* have to be adjusted when more
498 * lock types are added. */
499 static inline int ocfs2_highest_compat_lock_level(int level)
501 int new_level = LKM_EXMODE;
503 if (level == LKM_EXMODE)
504 new_level = LKM_NLMODE;
505 else if (level == LKM_PRMODE)
506 new_level = LKM_PRMODE;
510 static void lockres_set_flags(struct ocfs2_lock_res *lockres,
511 unsigned long newflags)
513 struct list_head *pos, *tmp;
514 struct ocfs2_mask_waiter *mw;
516 assert_spin_locked(&lockres->l_lock);
518 lockres->l_flags = newflags;
520 list_for_each_safe(pos, tmp, &lockres->l_mask_waiters) {
521 mw = list_entry(pos, struct ocfs2_mask_waiter, mw_item);
522 if ((lockres->l_flags & mw->mw_mask) != mw->mw_goal)
525 list_del_init(&mw->mw_item);
527 complete(&mw->mw_complete);
530 static void lockres_or_flags(struct ocfs2_lock_res *lockres, unsigned long or)
532 lockres_set_flags(lockres, lockres->l_flags | or);
534 static void lockres_clear_flags(struct ocfs2_lock_res *lockres,
537 lockres_set_flags(lockres, lockres->l_flags & ~clear);
540 static inline void ocfs2_generic_handle_downconvert_action(struct ocfs2_lock_res *lockres)
544 BUG_ON(!(lockres->l_flags & OCFS2_LOCK_BUSY));
545 BUG_ON(!(lockres->l_flags & OCFS2_LOCK_ATTACHED));
546 BUG_ON(!(lockres->l_flags & OCFS2_LOCK_BLOCKED));
547 BUG_ON(lockres->l_blocking <= LKM_NLMODE);
549 lockres->l_level = lockres->l_requested;
550 if (lockres->l_level <=
551 ocfs2_highest_compat_lock_level(lockres->l_blocking)) {
552 lockres->l_blocking = LKM_NLMODE;
553 lockres_clear_flags(lockres, OCFS2_LOCK_BLOCKED);
555 lockres_clear_flags(lockres, OCFS2_LOCK_BUSY);
560 static inline void ocfs2_generic_handle_convert_action(struct ocfs2_lock_res *lockres)
564 BUG_ON(!(lockres->l_flags & OCFS2_LOCK_BUSY));
565 BUG_ON(!(lockres->l_flags & OCFS2_LOCK_ATTACHED));
567 /* Convert from RO to EX doesn't really need anything as our
568 * information is already up to data. Convert from NL to
569 * *anything* however should mark ourselves as needing an
571 if (lockres->l_level == LKM_NLMODE)
572 lockres_or_flags(lockres, OCFS2_LOCK_NEEDS_REFRESH);
574 lockres->l_level = lockres->l_requested;
575 lockres_clear_flags(lockres, OCFS2_LOCK_BUSY);
580 static inline void ocfs2_generic_handle_attach_action(struct ocfs2_lock_res *lockres)
584 BUG_ON((!lockres->l_flags & OCFS2_LOCK_BUSY));
585 BUG_ON(lockres->l_flags & OCFS2_LOCK_ATTACHED);
587 if (lockres->l_requested > LKM_NLMODE &&
588 !(lockres->l_flags & OCFS2_LOCK_LOCAL))
589 lockres_or_flags(lockres, OCFS2_LOCK_NEEDS_REFRESH);
591 lockres->l_level = lockres->l_requested;
592 lockres_or_flags(lockres, OCFS2_LOCK_ATTACHED);
593 lockres_clear_flags(lockres, OCFS2_LOCK_BUSY);
598 static void ocfs2_inode_ast_func(void *opaque)
600 struct ocfs2_lock_res *lockres = opaque;
602 struct dlm_lockstatus *lksb;
607 inode = ocfs2_lock_res_inode(lockres);
609 mlog(0, "AST fired for inode %llu, l_action = %u, type = %s\n",
610 (unsigned long long)OCFS2_I(inode)->ip_blkno, lockres->l_action,
611 ocfs2_lock_type_string(lockres->l_type));
613 BUG_ON(!ocfs2_is_inode_lock(lockres));
615 spin_lock_irqsave(&lockres->l_lock, flags);
617 lksb = &(lockres->l_lksb);
618 if (lksb->status != DLM_NORMAL) {
619 mlog(ML_ERROR, "ocfs2_inode_ast_func: lksb status value of %u "
620 "on inode %llu\n", lksb->status,
621 (unsigned long long)OCFS2_I(inode)->ip_blkno);
622 spin_unlock_irqrestore(&lockres->l_lock, flags);
627 switch(lockres->l_action) {
628 case OCFS2_AST_ATTACH:
629 ocfs2_generic_handle_attach_action(lockres);
630 lockres_clear_flags(lockres, OCFS2_LOCK_LOCAL);
632 case OCFS2_AST_CONVERT:
633 ocfs2_generic_handle_convert_action(lockres);
635 case OCFS2_AST_DOWNCONVERT:
636 ocfs2_generic_handle_downconvert_action(lockres);
639 mlog(ML_ERROR, "lockres %s: ast fired with invalid action: %u "
640 "lockres flags = 0x%lx, unlock action: %u\n",
641 lockres->l_name, lockres->l_action, lockres->l_flags,
642 lockres->l_unlock_action);
647 /* data and rw locking ignores refresh flag for now. */
648 if (lockres->l_type != OCFS2_LOCK_TYPE_META)
649 lockres_clear_flags(lockres, OCFS2_LOCK_NEEDS_REFRESH);
651 /* set it to something invalid so if we get called again we
653 lockres->l_action = OCFS2_AST_INVALID;
654 spin_unlock_irqrestore(&lockres->l_lock, flags);
655 wake_up(&lockres->l_event);
660 static int ocfs2_generic_handle_bast(struct ocfs2_lock_res *lockres,
663 int needs_downconvert = 0;
666 assert_spin_locked(&lockres->l_lock);
668 lockres_or_flags(lockres, OCFS2_LOCK_BLOCKED);
670 if (level > lockres->l_blocking) {
671 /* only schedule a downconvert if we haven't already scheduled
672 * one that goes low enough to satisfy the level we're
673 * blocking. this also catches the case where we get
675 if (ocfs2_highest_compat_lock_level(level) <
676 ocfs2_highest_compat_lock_level(lockres->l_blocking))
677 needs_downconvert = 1;
679 lockres->l_blocking = level;
682 mlog_exit(needs_downconvert);
683 return needs_downconvert;
686 static void ocfs2_generic_bast_func(struct ocfs2_super *osb,
687 struct ocfs2_lock_res *lockres,
690 int needs_downconvert;
695 BUG_ON(level <= LKM_NLMODE);
697 spin_lock_irqsave(&lockres->l_lock, flags);
698 needs_downconvert = ocfs2_generic_handle_bast(lockres, level);
699 if (needs_downconvert)
700 ocfs2_schedule_blocked_lock(osb, lockres);
701 spin_unlock_irqrestore(&lockres->l_lock, flags);
703 wake_up(&lockres->l_event);
705 ocfs2_kick_vote_thread(osb);
710 static void ocfs2_inode_bast_func(void *opaque, int level)
712 struct ocfs2_lock_res *lockres = opaque;
714 struct ocfs2_super *osb;
718 BUG_ON(!ocfs2_is_inode_lock(lockres));
720 inode = ocfs2_lock_res_inode(lockres);
721 osb = OCFS2_SB(inode->i_sb);
723 mlog(0, "BAST fired for inode %llu, blocking %d, level %d type %s\n",
724 (unsigned long long)OCFS2_I(inode)->ip_blkno, level,
725 lockres->l_level, ocfs2_lock_type_string(lockres->l_type));
727 ocfs2_generic_bast_func(osb, lockres, level);
732 static void ocfs2_generic_ast_func(struct ocfs2_lock_res *lockres,
735 struct dlm_lockstatus *lksb = &lockres->l_lksb;
738 spin_lock_irqsave(&lockres->l_lock, flags);
740 if (lksb->status != DLM_NORMAL) {
741 mlog(ML_ERROR, "lockres %s: lksb status value of %u!\n",
742 lockres->l_name, lksb->status);
743 spin_unlock_irqrestore(&lockres->l_lock, flags);
747 switch(lockres->l_action) {
748 case OCFS2_AST_ATTACH:
749 ocfs2_generic_handle_attach_action(lockres);
751 case OCFS2_AST_CONVERT:
752 ocfs2_generic_handle_convert_action(lockres);
754 case OCFS2_AST_DOWNCONVERT:
755 ocfs2_generic_handle_downconvert_action(lockres);
762 lockres_clear_flags(lockres, OCFS2_LOCK_NEEDS_REFRESH);
764 /* set it to something invalid so if we get called again we
766 lockres->l_action = OCFS2_AST_INVALID;
768 wake_up(&lockres->l_event);
769 spin_unlock_irqrestore(&lockres->l_lock, flags);
772 static void ocfs2_super_ast_func(void *opaque)
774 struct ocfs2_lock_res *lockres = opaque;
777 mlog(0, "Superblock AST fired\n");
779 BUG_ON(!ocfs2_is_super_lock(lockres));
780 ocfs2_generic_ast_func(lockres, 0);
785 static void ocfs2_super_bast_func(void *opaque,
788 struct ocfs2_lock_res *lockres = opaque;
789 struct ocfs2_super *osb;
792 mlog(0, "Superblock BAST fired\n");
794 BUG_ON(!ocfs2_is_super_lock(lockres));
795 osb = ocfs2_lock_res_super(lockres);
796 ocfs2_generic_bast_func(osb, lockres, level);
801 static void ocfs2_rename_ast_func(void *opaque)
803 struct ocfs2_lock_res *lockres = opaque;
807 mlog(0, "Rename AST fired\n");
809 BUG_ON(!ocfs2_is_rename_lock(lockres));
811 ocfs2_generic_ast_func(lockres, 1);
816 static void ocfs2_rename_bast_func(void *opaque,
819 struct ocfs2_lock_res *lockres = opaque;
820 struct ocfs2_super *osb;
824 mlog(0, "Rename BAST fired\n");
826 BUG_ON(!ocfs2_is_rename_lock(lockres));
828 osb = ocfs2_lock_res_super(lockres);
829 ocfs2_generic_bast_func(osb, lockres, level);
834 static void ocfs2_dentry_ast_func(void *opaque)
836 struct ocfs2_lock_res *lockres = opaque;
840 ocfs2_generic_ast_func(lockres, 1);
843 static void ocfs2_dentry_bast_func(void *opaque, int level)
845 struct ocfs2_lock_res *lockres = opaque;
846 struct ocfs2_dentry_lock *dl = lockres->l_priv;
847 struct ocfs2_super *osb = OCFS2_SB(dl->dl_inode->i_sb);
849 mlog(0, "Dentry bast: level: %d, name: %s\n", level,
852 ocfs2_generic_bast_func(osb, lockres, level);
855 static inline void ocfs2_recover_from_dlm_error(struct ocfs2_lock_res *lockres,
861 spin_lock_irqsave(&lockres->l_lock, flags);
862 lockres_clear_flags(lockres, OCFS2_LOCK_BUSY);
864 lockres->l_action = OCFS2_AST_INVALID;
866 lockres->l_unlock_action = OCFS2_UNLOCK_INVALID;
867 spin_unlock_irqrestore(&lockres->l_lock, flags);
869 wake_up(&lockres->l_event);
873 /* Note: If we detect another process working on the lock (i.e.,
874 * OCFS2_LOCK_BUSY), we'll bail out returning 0. It's up to the caller
875 * to do the right thing in that case.
877 static int ocfs2_lock_create(struct ocfs2_super *osb,
878 struct ocfs2_lock_res *lockres,
883 enum dlm_status status;
888 mlog(0, "lock %s, level = %d, flags = %d\n", lockres->l_name, level,
891 spin_lock_irqsave(&lockres->l_lock, flags);
892 if ((lockres->l_flags & OCFS2_LOCK_ATTACHED) ||
893 (lockres->l_flags & OCFS2_LOCK_BUSY)) {
894 spin_unlock_irqrestore(&lockres->l_lock, flags);
898 lockres->l_action = OCFS2_AST_ATTACH;
899 lockres->l_requested = level;
900 lockres_or_flags(lockres, OCFS2_LOCK_BUSY);
901 spin_unlock_irqrestore(&lockres->l_lock, flags);
903 status = dlmlock(osb->dlm,
908 OCFS2_LOCK_ID_MAX_LEN - 1,
911 lockres->l_ops->bast);
912 if (status != DLM_NORMAL) {
913 ocfs2_log_dlm_error("dlmlock", status, lockres);
915 ocfs2_recover_from_dlm_error(lockres, 1);
918 mlog(0, "lock %s, successfull return from dlmlock\n", lockres->l_name);
925 static inline int ocfs2_check_wait_flag(struct ocfs2_lock_res *lockres,
931 spin_lock_irqsave(&lockres->l_lock, flags);
932 ret = lockres->l_flags & flag;
933 spin_unlock_irqrestore(&lockres->l_lock, flags);
938 static inline void ocfs2_wait_on_busy_lock(struct ocfs2_lock_res *lockres)
941 wait_event(lockres->l_event,
942 !ocfs2_check_wait_flag(lockres, OCFS2_LOCK_BUSY));
945 static inline void ocfs2_wait_on_refreshing_lock(struct ocfs2_lock_res *lockres)
948 wait_event(lockres->l_event,
949 !ocfs2_check_wait_flag(lockres, OCFS2_LOCK_REFRESHING));
952 /* predict what lock level we'll be dropping down to on behalf
953 * of another node, and return true if the currently wanted
954 * level will be compatible with it. */
955 static inline int ocfs2_may_continue_on_blocked_lock(struct ocfs2_lock_res *lockres,
958 BUG_ON(!(lockres->l_flags & OCFS2_LOCK_BLOCKED));
960 return wanted <= ocfs2_highest_compat_lock_level(lockres->l_blocking);
963 static void ocfs2_init_mask_waiter(struct ocfs2_mask_waiter *mw)
965 INIT_LIST_HEAD(&mw->mw_item);
966 init_completion(&mw->mw_complete);
969 static int ocfs2_wait_for_mask(struct ocfs2_mask_waiter *mw)
971 wait_for_completion(&mw->mw_complete);
972 /* Re-arm the completion in case we want to wait on it again */
973 INIT_COMPLETION(mw->mw_complete);
974 return mw->mw_status;
977 static void lockres_add_mask_waiter(struct ocfs2_lock_res *lockres,
978 struct ocfs2_mask_waiter *mw,
982 BUG_ON(!list_empty(&mw->mw_item));
984 assert_spin_locked(&lockres->l_lock);
986 list_add_tail(&mw->mw_item, &lockres->l_mask_waiters);
991 /* returns 0 if the mw that was removed was already satisfied, -EBUSY
992 * if the mask still hadn't reached its goal */
993 static int lockres_remove_mask_waiter(struct ocfs2_lock_res *lockres,
994 struct ocfs2_mask_waiter *mw)
999 spin_lock_irqsave(&lockres->l_lock, flags);
1000 if (!list_empty(&mw->mw_item)) {
1001 if ((lockres->l_flags & mw->mw_mask) != mw->mw_goal)
1004 list_del_init(&mw->mw_item);
1005 init_completion(&mw->mw_complete);
1007 spin_unlock_irqrestore(&lockres->l_lock, flags);
1013 static int ocfs2_cluster_lock(struct ocfs2_super *osb,
1014 struct ocfs2_lock_res *lockres,
1019 struct ocfs2_mask_waiter mw;
1020 enum dlm_status status;
1021 int wait, catch_signals = !(osb->s_mount_opt & OCFS2_MOUNT_NOINTR);
1022 int ret = 0; /* gcc doesn't realize wait = 1 guarantees ret is set */
1023 unsigned long flags;
1027 ocfs2_init_mask_waiter(&mw);
1032 if (catch_signals && signal_pending(current)) {
1037 spin_lock_irqsave(&lockres->l_lock, flags);
1039 mlog_bug_on_msg(lockres->l_flags & OCFS2_LOCK_FREEING,
1040 "Cluster lock called on freeing lockres %s! flags "
1041 "0x%lx\n", lockres->l_name, lockres->l_flags);
1043 /* We only compare against the currently granted level
1044 * here. If the lock is blocked waiting on a downconvert,
1045 * we'll get caught below. */
1046 if (lockres->l_flags & OCFS2_LOCK_BUSY &&
1047 level > lockres->l_level) {
1048 /* is someone sitting in dlm_lock? If so, wait on
1050 lockres_add_mask_waiter(lockres, &mw, OCFS2_LOCK_BUSY, 0);
1055 if (!(lockres->l_flags & OCFS2_LOCK_ATTACHED)) {
1056 /* lock has not been created yet. */
1057 spin_unlock_irqrestore(&lockres->l_lock, flags);
1059 ret = ocfs2_lock_create(osb, lockres, LKM_NLMODE, 0);
1067 if (lockres->l_flags & OCFS2_LOCK_BLOCKED &&
1068 !ocfs2_may_continue_on_blocked_lock(lockres, level)) {
1069 /* is the lock is currently blocked on behalf of
1071 lockres_add_mask_waiter(lockres, &mw, OCFS2_LOCK_BLOCKED, 0);
1076 if (level > lockres->l_level) {
1077 if (lockres->l_action != OCFS2_AST_INVALID)
1078 mlog(ML_ERROR, "lockres %s has action %u pending\n",
1079 lockres->l_name, lockres->l_action);
1081 lockres->l_action = OCFS2_AST_CONVERT;
1082 lockres->l_requested = level;
1083 lockres_or_flags(lockres, OCFS2_LOCK_BUSY);
1084 spin_unlock_irqrestore(&lockres->l_lock, flags);
1086 BUG_ON(level == LKM_IVMODE);
1087 BUG_ON(level == LKM_NLMODE);
1089 mlog(0, "lock %s, convert from %d to level = %d\n",
1090 lockres->l_name, lockres->l_level, level);
1092 /* call dlm_lock to upgrade lock now */
1093 status = dlmlock(osb->dlm,
1096 lkm_flags|LKM_CONVERT|LKM_VALBLK,
1098 OCFS2_LOCK_ID_MAX_LEN - 1,
1099 lockres->l_ops->ast,
1101 lockres->l_ops->bast);
1102 if (status != DLM_NORMAL) {
1103 if ((lkm_flags & LKM_NOQUEUE) &&
1104 (status == DLM_NOTQUEUED))
1107 ocfs2_log_dlm_error("dlmlock", status,
1111 ocfs2_recover_from_dlm_error(lockres, 1);
1115 mlog(0, "lock %s, successfull return from dlmlock\n",
1118 /* At this point we've gone inside the dlm and need to
1119 * complete our work regardless. */
1122 /* wait for busy to clear and carry on */
1126 /* Ok, if we get here then we're good to go. */
1127 ocfs2_inc_holders(lockres, level);
1131 spin_unlock_irqrestore(&lockres->l_lock, flags);
1134 * This is helping work around a lock inversion between the page lock
1135 * and dlm locks. One path holds the page lock while calling aops
1136 * which block acquiring dlm locks. The voting thread holds dlm
1137 * locks while acquiring page locks while down converting data locks.
1138 * This block is helping an aop path notice the inversion and back
1139 * off to unlock its page lock before trying the dlm lock again.
1141 if (wait && arg_flags & OCFS2_LOCK_NONBLOCK &&
1142 mw.mw_mask & (OCFS2_LOCK_BUSY|OCFS2_LOCK_BLOCKED)) {
1144 if (lockres_remove_mask_waiter(lockres, &mw))
1150 ret = ocfs2_wait_for_mask(&mw);
1160 static void ocfs2_cluster_unlock(struct ocfs2_super *osb,
1161 struct ocfs2_lock_res *lockres,
1164 unsigned long flags;
1167 spin_lock_irqsave(&lockres->l_lock, flags);
1168 ocfs2_dec_holders(lockres, level);
1169 ocfs2_vote_on_unlock(osb, lockres);
1170 spin_unlock_irqrestore(&lockres->l_lock, flags);
1174 int ocfs2_create_new_lock(struct ocfs2_super *osb,
1175 struct ocfs2_lock_res *lockres,
1178 int level = ex ? LKM_EXMODE : LKM_PRMODE;
1179 unsigned long flags;
1181 spin_lock_irqsave(&lockres->l_lock, flags);
1182 BUG_ON(lockres->l_flags & OCFS2_LOCK_ATTACHED);
1183 lockres_or_flags(lockres, OCFS2_LOCK_LOCAL);
1184 spin_unlock_irqrestore(&lockres->l_lock, flags);
1186 return ocfs2_lock_create(osb, lockres, level, LKM_LOCAL);
1189 /* Grants us an EX lock on the data and metadata resources, skipping
1190 * the normal cluster directory lookup. Use this ONLY on newly created
1191 * inodes which other nodes can't possibly see, and which haven't been
1192 * hashed in the inode hash yet. This can give us a good performance
1193 * increase as it'll skip the network broadcast normally associated
1194 * with creating a new lock resource. */
1195 int ocfs2_create_new_inode_locks(struct inode *inode)
1198 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1201 BUG_ON(!ocfs2_inode_is_new(inode));
1205 mlog(0, "Inode %llu\n", (unsigned long long)OCFS2_I(inode)->ip_blkno);
1207 /* NOTE: That we don't increment any of the holder counts, nor
1208 * do we add anything to a journal handle. Since this is
1209 * supposed to be a new inode which the cluster doesn't know
1210 * about yet, there is no need to. As far as the LVB handling
1211 * is concerned, this is basically like acquiring an EX lock
1212 * on a resource which has an invalid one -- we'll set it
1213 * valid when we release the EX. */
1215 ret = ocfs2_create_new_lock(osb, &OCFS2_I(inode)->ip_rw_lockres, 1);
1221 ret = ocfs2_create_new_lock(osb, &OCFS2_I(inode)->ip_meta_lockres, 1);
1227 ret = ocfs2_create_new_lock(osb, &OCFS2_I(inode)->ip_data_lockres, 1);
1238 int ocfs2_rw_lock(struct inode *inode, int write)
1241 struct ocfs2_lock_res *lockres;
1247 mlog(0, "inode %llu take %s RW lock\n",
1248 (unsigned long long)OCFS2_I(inode)->ip_blkno,
1249 write ? "EXMODE" : "PRMODE");
1251 lockres = &OCFS2_I(inode)->ip_rw_lockres;
1253 level = write ? LKM_EXMODE : LKM_PRMODE;
1255 status = ocfs2_cluster_lock(OCFS2_SB(inode->i_sb), lockres, level, 0,
1264 void ocfs2_rw_unlock(struct inode *inode, int write)
1266 int level = write ? LKM_EXMODE : LKM_PRMODE;
1267 struct ocfs2_lock_res *lockres = &OCFS2_I(inode)->ip_rw_lockres;
1271 mlog(0, "inode %llu drop %s RW lock\n",
1272 (unsigned long long)OCFS2_I(inode)->ip_blkno,
1273 write ? "EXMODE" : "PRMODE");
1275 ocfs2_cluster_unlock(OCFS2_SB(inode->i_sb), lockres, level);
1280 int ocfs2_data_lock_full(struct inode *inode,
1284 int status = 0, level;
1285 struct ocfs2_lock_res *lockres;
1291 mlog(0, "inode %llu take %s DATA lock\n",
1292 (unsigned long long)OCFS2_I(inode)->ip_blkno,
1293 write ? "EXMODE" : "PRMODE");
1295 /* We'll allow faking a readonly data lock for
1297 if (ocfs2_is_hard_readonly(OCFS2_SB(inode->i_sb))) {
1305 lockres = &OCFS2_I(inode)->ip_data_lockres;
1307 level = write ? LKM_EXMODE : LKM_PRMODE;
1309 status = ocfs2_cluster_lock(OCFS2_SB(inode->i_sb), lockres, level,
1311 if (status < 0 && status != -EAGAIN)
1319 /* see ocfs2_meta_lock_with_page() */
1320 int ocfs2_data_lock_with_page(struct inode *inode,
1326 ret = ocfs2_data_lock_full(inode, write, OCFS2_LOCK_NONBLOCK);
1327 if (ret == -EAGAIN) {
1329 if (ocfs2_data_lock(inode, write) == 0)
1330 ocfs2_data_unlock(inode, write);
1331 ret = AOP_TRUNCATED_PAGE;
1337 static void ocfs2_vote_on_unlock(struct ocfs2_super *osb,
1338 struct ocfs2_lock_res *lockres)
1344 /* If we know that another node is waiting on our lock, kick
1345 * the vote thread * pre-emptively when we reach a release
1347 if (lockres->l_flags & OCFS2_LOCK_BLOCKED) {
1348 switch(lockres->l_blocking) {
1350 if (!lockres->l_ex_holders && !lockres->l_ro_holders)
1354 if (!lockres->l_ex_holders)
1363 ocfs2_kick_vote_thread(osb);
1368 void ocfs2_data_unlock(struct inode *inode,
1371 int level = write ? LKM_EXMODE : LKM_PRMODE;
1372 struct ocfs2_lock_res *lockres = &OCFS2_I(inode)->ip_data_lockres;
1376 mlog(0, "inode %llu drop %s DATA lock\n",
1377 (unsigned long long)OCFS2_I(inode)->ip_blkno,
1378 write ? "EXMODE" : "PRMODE");
1380 if (!ocfs2_is_hard_readonly(OCFS2_SB(inode->i_sb)))
1381 ocfs2_cluster_unlock(OCFS2_SB(inode->i_sb), lockres, level);
1386 #define OCFS2_SEC_BITS 34
1387 #define OCFS2_SEC_SHIFT (64 - 34)
1388 #define OCFS2_NSEC_MASK ((1ULL << OCFS2_SEC_SHIFT) - 1)
1390 /* LVB only has room for 64 bits of time here so we pack it for
1392 static u64 ocfs2_pack_timespec(struct timespec *spec)
1395 u64 sec = spec->tv_sec;
1396 u32 nsec = spec->tv_nsec;
1398 res = (sec << OCFS2_SEC_SHIFT) | (nsec & OCFS2_NSEC_MASK);
1403 /* Call this with the lockres locked. I am reasonably sure we don't
1404 * need ip_lock in this function as anyone who would be changing those
1405 * values is supposed to be blocked in ocfs2_meta_lock right now. */
1406 static void __ocfs2_stuff_meta_lvb(struct inode *inode)
1408 struct ocfs2_inode_info *oi = OCFS2_I(inode);
1409 struct ocfs2_lock_res *lockres = &oi->ip_meta_lockres;
1410 struct ocfs2_meta_lvb *lvb;
1414 lvb = (struct ocfs2_meta_lvb *) lockres->l_lksb.lvb;
1416 lvb->lvb_version = OCFS2_LVB_VERSION;
1417 lvb->lvb_isize = cpu_to_be64(i_size_read(inode));
1418 lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
1419 lvb->lvb_iuid = cpu_to_be32(inode->i_uid);
1420 lvb->lvb_igid = cpu_to_be32(inode->i_gid);
1421 lvb->lvb_imode = cpu_to_be16(inode->i_mode);
1422 lvb->lvb_inlink = cpu_to_be16(inode->i_nlink);
1423 lvb->lvb_iatime_packed =
1424 cpu_to_be64(ocfs2_pack_timespec(&inode->i_atime));
1425 lvb->lvb_ictime_packed =
1426 cpu_to_be64(ocfs2_pack_timespec(&inode->i_ctime));
1427 lvb->lvb_imtime_packed =
1428 cpu_to_be64(ocfs2_pack_timespec(&inode->i_mtime));
1429 lvb->lvb_iattr = cpu_to_be32(oi->ip_attr);
1430 lvb->lvb_igeneration = cpu_to_be32(inode->i_generation);
1432 mlog_meta_lvb(0, lockres);
1437 static void ocfs2_unpack_timespec(struct timespec *spec,
1440 spec->tv_sec = packed_time >> OCFS2_SEC_SHIFT;
1441 spec->tv_nsec = packed_time & OCFS2_NSEC_MASK;
1444 static void ocfs2_refresh_inode_from_lvb(struct inode *inode)
1446 struct ocfs2_inode_info *oi = OCFS2_I(inode);
1447 struct ocfs2_lock_res *lockres = &oi->ip_meta_lockres;
1448 struct ocfs2_meta_lvb *lvb;
1452 mlog_meta_lvb(0, lockres);
1454 lvb = (struct ocfs2_meta_lvb *) lockres->l_lksb.lvb;
1456 /* We're safe here without the lockres lock... */
1457 spin_lock(&oi->ip_lock);
1458 oi->ip_clusters = be32_to_cpu(lvb->lvb_iclusters);
1459 i_size_write(inode, be64_to_cpu(lvb->lvb_isize));
1461 oi->ip_attr = be32_to_cpu(lvb->lvb_iattr);
1462 ocfs2_set_inode_flags(inode);
1464 /* fast-symlinks are a special case */
1465 if (S_ISLNK(inode->i_mode) && !oi->ip_clusters)
1466 inode->i_blocks = 0;
1469 ocfs2_align_bytes_to_sectors(i_size_read(inode));
1471 inode->i_uid = be32_to_cpu(lvb->lvb_iuid);
1472 inode->i_gid = be32_to_cpu(lvb->lvb_igid);
1473 inode->i_mode = be16_to_cpu(lvb->lvb_imode);
1474 inode->i_nlink = be16_to_cpu(lvb->lvb_inlink);
1475 ocfs2_unpack_timespec(&inode->i_atime,
1476 be64_to_cpu(lvb->lvb_iatime_packed));
1477 ocfs2_unpack_timespec(&inode->i_mtime,
1478 be64_to_cpu(lvb->lvb_imtime_packed));
1479 ocfs2_unpack_timespec(&inode->i_ctime,
1480 be64_to_cpu(lvb->lvb_ictime_packed));
1481 spin_unlock(&oi->ip_lock);
1486 static inline int ocfs2_meta_lvb_is_trustable(struct inode *inode,
1487 struct ocfs2_lock_res *lockres)
1489 struct ocfs2_meta_lvb *lvb = (struct ocfs2_meta_lvb *) lockres->l_lksb.lvb;
1491 if (lvb->lvb_version == OCFS2_LVB_VERSION
1492 && be32_to_cpu(lvb->lvb_igeneration) == inode->i_generation)
1497 /* Determine whether a lock resource needs to be refreshed, and
1498 * arbitrate who gets to refresh it.
1500 * 0 means no refresh needed.
1502 * > 0 means you need to refresh this and you MUST call
1503 * ocfs2_complete_lock_res_refresh afterwards. */
1504 static int ocfs2_should_refresh_lock_res(struct ocfs2_lock_res *lockres)
1506 unsigned long flags;
1512 spin_lock_irqsave(&lockres->l_lock, flags);
1513 if (!(lockres->l_flags & OCFS2_LOCK_NEEDS_REFRESH)) {
1514 spin_unlock_irqrestore(&lockres->l_lock, flags);
1518 if (lockres->l_flags & OCFS2_LOCK_REFRESHING) {
1519 spin_unlock_irqrestore(&lockres->l_lock, flags);
1521 ocfs2_wait_on_refreshing_lock(lockres);
1525 /* Ok, I'll be the one to refresh this lock. */
1526 lockres_or_flags(lockres, OCFS2_LOCK_REFRESHING);
1527 spin_unlock_irqrestore(&lockres->l_lock, flags);
1535 /* If status is non zero, I'll mark it as not being in refresh
1536 * anymroe, but i won't clear the needs refresh flag. */
1537 static inline void ocfs2_complete_lock_res_refresh(struct ocfs2_lock_res *lockres,
1540 unsigned long flags;
1543 spin_lock_irqsave(&lockres->l_lock, flags);
1544 lockres_clear_flags(lockres, OCFS2_LOCK_REFRESHING);
1546 lockres_clear_flags(lockres, OCFS2_LOCK_NEEDS_REFRESH);
1547 spin_unlock_irqrestore(&lockres->l_lock, flags);
1549 wake_up(&lockres->l_event);
1554 /* may or may not return a bh if it went to disk. */
1555 static int ocfs2_meta_lock_update(struct inode *inode,
1556 struct buffer_head **bh)
1559 struct ocfs2_inode_info *oi = OCFS2_I(inode);
1560 struct ocfs2_lock_res *lockres;
1561 struct ocfs2_dinode *fe;
1565 spin_lock(&oi->ip_lock);
1566 if (oi->ip_flags & OCFS2_INODE_DELETED) {
1567 mlog(0, "Orphaned inode %llu was deleted while we "
1568 "were waiting on a lock. ip_flags = 0x%x\n",
1569 (unsigned long long)oi->ip_blkno, oi->ip_flags);
1570 spin_unlock(&oi->ip_lock);
1574 spin_unlock(&oi->ip_lock);
1576 lockres = &oi->ip_meta_lockres;
1578 if (!ocfs2_should_refresh_lock_res(lockres))
1581 /* This will discard any caching information we might have had
1582 * for the inode metadata. */
1583 ocfs2_metadata_cache_purge(inode);
1585 /* will do nothing for inode types that don't use the extent
1586 * map (directories, bitmap files, etc) */
1587 ocfs2_extent_map_trunc(inode, 0);
1589 if (ocfs2_meta_lvb_is_trustable(inode, lockres)) {
1590 mlog(0, "Trusting LVB on inode %llu\n",
1591 (unsigned long long)oi->ip_blkno);
1592 ocfs2_refresh_inode_from_lvb(inode);
1594 /* Boo, we have to go to disk. */
1595 /* read bh, cast, ocfs2_refresh_inode */
1596 status = ocfs2_read_block(OCFS2_SB(inode->i_sb), oi->ip_blkno,
1597 bh, OCFS2_BH_CACHED, inode);
1602 fe = (struct ocfs2_dinode *) (*bh)->b_data;
1604 /* This is a good chance to make sure we're not
1605 * locking an invalid object.
1607 * We bug on a stale inode here because we checked
1608 * above whether it was wiped from disk. The wiping
1609 * node provides a guarantee that we receive that
1610 * message and can mark the inode before dropping any
1611 * locks associated with it. */
1612 if (!OCFS2_IS_VALID_DINODE(fe)) {
1613 OCFS2_RO_ON_INVALID_DINODE(inode->i_sb, fe);
1617 mlog_bug_on_msg(inode->i_generation !=
1618 le32_to_cpu(fe->i_generation),
1619 "Invalid dinode %llu disk generation: %u "
1620 "inode->i_generation: %u\n",
1621 (unsigned long long)oi->ip_blkno,
1622 le32_to_cpu(fe->i_generation),
1623 inode->i_generation);
1624 mlog_bug_on_msg(le64_to_cpu(fe->i_dtime) ||
1625 !(fe->i_flags & cpu_to_le32(OCFS2_VALID_FL)),
1626 "Stale dinode %llu dtime: %llu flags: 0x%x\n",
1627 (unsigned long long)oi->ip_blkno,
1628 (unsigned long long)le64_to_cpu(fe->i_dtime),
1629 le32_to_cpu(fe->i_flags));
1631 ocfs2_refresh_inode(inode, fe);
1636 ocfs2_complete_lock_res_refresh(lockres, status);
1642 static int ocfs2_assign_bh(struct inode *inode,
1643 struct buffer_head **ret_bh,
1644 struct buffer_head *passed_bh)
1649 /* Ok, the update went to disk for us, use the
1651 *ret_bh = passed_bh;
1657 status = ocfs2_read_block(OCFS2_SB(inode->i_sb),
1658 OCFS2_I(inode)->ip_blkno,
1669 * returns < 0 error if the callback will never be called, otherwise
1670 * the result of the lock will be communicated via the callback.
1672 int ocfs2_meta_lock_full(struct inode *inode,
1673 struct ocfs2_journal_handle *handle,
1674 struct buffer_head **ret_bh,
1678 int status, level, dlm_flags, acquired;
1679 struct ocfs2_lock_res *lockres;
1680 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1681 struct buffer_head *local_bh = NULL;
1687 mlog(0, "inode %llu, take %s META lock\n",
1688 (unsigned long long)OCFS2_I(inode)->ip_blkno,
1689 ex ? "EXMODE" : "PRMODE");
1693 /* We'll allow faking a readonly metadata lock for
1695 if (ocfs2_is_hard_readonly(osb)) {
1701 if (!(arg_flags & OCFS2_META_LOCK_RECOVERY))
1702 wait_event(osb->recovery_event,
1703 ocfs2_node_map_is_empty(osb, &osb->recovery_map));
1706 lockres = &OCFS2_I(inode)->ip_meta_lockres;
1707 level = ex ? LKM_EXMODE : LKM_PRMODE;
1709 if (arg_flags & OCFS2_META_LOCK_NOQUEUE)
1710 dlm_flags |= LKM_NOQUEUE;
1712 status = ocfs2_cluster_lock(osb, lockres, level, dlm_flags, arg_flags);
1714 if (status != -EAGAIN && status != -EIOCBRETRY)
1719 /* Notify the error cleanup path to drop the cluster lock. */
1722 /* We wait twice because a node may have died while we were in
1723 * the lower dlm layers. The second time though, we've
1724 * committed to owning this lock so we don't allow signals to
1725 * abort the operation. */
1726 if (!(arg_flags & OCFS2_META_LOCK_RECOVERY))
1727 wait_event(osb->recovery_event,
1728 ocfs2_node_map_is_empty(osb, &osb->recovery_map));
1730 /* This is fun. The caller may want a bh back, or it may
1731 * not. ocfs2_meta_lock_update definitely wants one in, but
1732 * may or may not read one, depending on what's in the
1733 * LVB. The result of all of this is that we've *only* gone to
1734 * disk if we have to, so the complexity is worthwhile. */
1735 status = ocfs2_meta_lock_update(inode, &local_bh);
1737 if (status != -ENOENT)
1743 status = ocfs2_assign_bh(inode, ret_bh, local_bh);
1751 status = ocfs2_handle_add_lock(handle, inode);
1758 if (ret_bh && (*ret_bh)) {
1763 ocfs2_meta_unlock(inode, ex);
1774 * This is working around a lock inversion between tasks acquiring DLM locks
1775 * while holding a page lock and the vote thread which blocks dlm lock acquiry
1776 * while acquiring page locks.
1778 * ** These _with_page variantes are only intended to be called from aop
1779 * methods that hold page locks and return a very specific *positive* error
1780 * code that aop methods pass up to the VFS -- test for errors with != 0. **
1782 * The DLM is called such that it returns -EAGAIN if it would have blocked
1783 * waiting for the vote thread. In that case we unlock our page so the vote
1784 * thread can make progress. Once we've done this we have to return
1785 * AOP_TRUNCATED_PAGE so the aop method that called us can bubble that back up
1786 * into the VFS who will then immediately retry the aop call.
1788 * We do a blocking lock and immediate unlock before returning, though, so that
1789 * the lock has a great chance of being cached on this node by the time the VFS
1790 * calls back to retry the aop. This has a potential to livelock as nodes
1791 * ping locks back and forth, but that's a risk we're willing to take to avoid
1792 * the lock inversion simply.
1794 int ocfs2_meta_lock_with_page(struct inode *inode,
1795 struct ocfs2_journal_handle *handle,
1796 struct buffer_head **ret_bh,
1802 ret = ocfs2_meta_lock_full(inode, handle, ret_bh, ex,
1803 OCFS2_LOCK_NONBLOCK);
1804 if (ret == -EAGAIN) {
1806 if (ocfs2_meta_lock(inode, handle, ret_bh, ex) == 0)
1807 ocfs2_meta_unlock(inode, ex);
1808 ret = AOP_TRUNCATED_PAGE;
1814 void ocfs2_meta_unlock(struct inode *inode,
1817 int level = ex ? LKM_EXMODE : LKM_PRMODE;
1818 struct ocfs2_lock_res *lockres = &OCFS2_I(inode)->ip_meta_lockres;
1822 mlog(0, "inode %llu drop %s META lock\n",
1823 (unsigned long long)OCFS2_I(inode)->ip_blkno,
1824 ex ? "EXMODE" : "PRMODE");
1826 if (!ocfs2_is_hard_readonly(OCFS2_SB(inode->i_sb)))
1827 ocfs2_cluster_unlock(OCFS2_SB(inode->i_sb), lockres, level);
1832 int ocfs2_super_lock(struct ocfs2_super *osb,
1836 int level = ex ? LKM_EXMODE : LKM_PRMODE;
1837 struct ocfs2_lock_res *lockres = &osb->osb_super_lockres;
1838 struct buffer_head *bh;
1839 struct ocfs2_slot_info *si = osb->slot_info;
1843 if (ocfs2_is_hard_readonly(osb))
1846 status = ocfs2_cluster_lock(osb, lockres, level, 0, 0);
1852 /* The super block lock path is really in the best position to
1853 * know when resources covered by the lock need to be
1854 * refreshed, so we do it here. Of course, making sense of
1855 * everything is up to the caller :) */
1856 status = ocfs2_should_refresh_lock_res(lockres);
1863 status = ocfs2_read_block(osb, bh->b_blocknr, &bh, 0,
1866 ocfs2_update_slot_info(si);
1868 ocfs2_complete_lock_res_refresh(lockres, status);
1878 void ocfs2_super_unlock(struct ocfs2_super *osb,
1881 int level = ex ? LKM_EXMODE : LKM_PRMODE;
1882 struct ocfs2_lock_res *lockres = &osb->osb_super_lockres;
1884 ocfs2_cluster_unlock(osb, lockres, level);
1887 int ocfs2_rename_lock(struct ocfs2_super *osb)
1890 struct ocfs2_lock_res *lockres = &osb->osb_rename_lockres;
1892 if (ocfs2_is_hard_readonly(osb))
1895 status = ocfs2_cluster_lock(osb, lockres, LKM_EXMODE, 0, 0);
1902 void ocfs2_rename_unlock(struct ocfs2_super *osb)
1904 struct ocfs2_lock_res *lockres = &osb->osb_rename_lockres;
1906 ocfs2_cluster_unlock(osb, lockres, LKM_EXMODE);
1909 int ocfs2_dentry_lock(struct dentry *dentry, int ex)
1912 int level = ex ? LKM_EXMODE : LKM_PRMODE;
1913 struct ocfs2_dentry_lock *dl = dentry->d_fsdata;
1914 struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb);
1918 if (ocfs2_is_hard_readonly(osb))
1921 ret = ocfs2_cluster_lock(osb, &dl->dl_lockres, level, 0, 0);
1928 void ocfs2_dentry_unlock(struct dentry *dentry, int ex)
1930 int level = ex ? LKM_EXMODE : LKM_PRMODE;
1931 struct ocfs2_dentry_lock *dl = dentry->d_fsdata;
1932 struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb);
1934 ocfs2_cluster_unlock(osb, &dl->dl_lockres, level);
1937 /* Reference counting of the dlm debug structure. We want this because
1938 * open references on the debug inodes can live on after a mount, so
1939 * we can't rely on the ocfs2_super to always exist. */
1940 static void ocfs2_dlm_debug_free(struct kref *kref)
1942 struct ocfs2_dlm_debug *dlm_debug;
1944 dlm_debug = container_of(kref, struct ocfs2_dlm_debug, d_refcnt);
1949 void ocfs2_put_dlm_debug(struct ocfs2_dlm_debug *dlm_debug)
1952 kref_put(&dlm_debug->d_refcnt, ocfs2_dlm_debug_free);
1955 static void ocfs2_get_dlm_debug(struct ocfs2_dlm_debug *debug)
1957 kref_get(&debug->d_refcnt);
1960 struct ocfs2_dlm_debug *ocfs2_new_dlm_debug(void)
1962 struct ocfs2_dlm_debug *dlm_debug;
1964 dlm_debug = kmalloc(sizeof(struct ocfs2_dlm_debug), GFP_KERNEL);
1966 mlog_errno(-ENOMEM);
1970 kref_init(&dlm_debug->d_refcnt);
1971 INIT_LIST_HEAD(&dlm_debug->d_lockres_tracking);
1972 dlm_debug->d_locking_state = NULL;
1977 /* Access to this is arbitrated for us via seq_file->sem. */
1978 struct ocfs2_dlm_seq_priv {
1979 struct ocfs2_dlm_debug *p_dlm_debug;
1980 struct ocfs2_lock_res p_iter_res;
1981 struct ocfs2_lock_res p_tmp_res;
1984 static struct ocfs2_lock_res *ocfs2_dlm_next_res(struct ocfs2_lock_res *start,
1985 struct ocfs2_dlm_seq_priv *priv)
1987 struct ocfs2_lock_res *iter, *ret = NULL;
1988 struct ocfs2_dlm_debug *dlm_debug = priv->p_dlm_debug;
1990 assert_spin_locked(&ocfs2_dlm_tracking_lock);
1992 list_for_each_entry(iter, &start->l_debug_list, l_debug_list) {
1993 /* discover the head of the list */
1994 if (&iter->l_debug_list == &dlm_debug->d_lockres_tracking) {
1995 mlog(0, "End of list found, %p\n", ret);
1999 /* We track our "dummy" iteration lockres' by a NULL
2001 if (iter->l_ops != NULL) {
2010 static void *ocfs2_dlm_seq_start(struct seq_file *m, loff_t *pos)
2012 struct ocfs2_dlm_seq_priv *priv = m->private;
2013 struct ocfs2_lock_res *iter;
2015 spin_lock(&ocfs2_dlm_tracking_lock);
2016 iter = ocfs2_dlm_next_res(&priv->p_iter_res, priv);
2018 /* Since lockres' have the lifetime of their container
2019 * (which can be inodes, ocfs2_supers, etc) we want to
2020 * copy this out to a temporary lockres while still
2021 * under the spinlock. Obviously after this we can't
2022 * trust any pointers on the copy returned, but that's
2023 * ok as the information we want isn't typically held
2025 priv->p_tmp_res = *iter;
2026 iter = &priv->p_tmp_res;
2028 spin_unlock(&ocfs2_dlm_tracking_lock);
2033 static void ocfs2_dlm_seq_stop(struct seq_file *m, void *v)
2037 static void *ocfs2_dlm_seq_next(struct seq_file *m, void *v, loff_t *pos)
2039 struct ocfs2_dlm_seq_priv *priv = m->private;
2040 struct ocfs2_lock_res *iter = v;
2041 struct ocfs2_lock_res *dummy = &priv->p_iter_res;
2043 spin_lock(&ocfs2_dlm_tracking_lock);
2044 iter = ocfs2_dlm_next_res(iter, priv);
2045 list_del_init(&dummy->l_debug_list);
2047 list_add(&dummy->l_debug_list, &iter->l_debug_list);
2048 priv->p_tmp_res = *iter;
2049 iter = &priv->p_tmp_res;
2051 spin_unlock(&ocfs2_dlm_tracking_lock);
2056 /* So that debugfs.ocfs2 can determine which format is being used */
2057 #define OCFS2_DLM_DEBUG_STR_VERSION 1
2058 static int ocfs2_dlm_seq_show(struct seq_file *m, void *v)
2062 struct ocfs2_lock_res *lockres = v;
2067 seq_printf(m, "0x%x\t", OCFS2_DLM_DEBUG_STR_VERSION);
2069 if (lockres->l_type == OCFS2_LOCK_TYPE_DENTRY)
2070 seq_printf(m, "%.*s%08x\t", OCFS2_DENTRY_LOCK_INO_START - 1,
2072 (unsigned int)ocfs2_get_dentry_lock_ino(lockres));
2074 seq_printf(m, "%.*s\t", OCFS2_LOCK_ID_MAX_LEN, lockres->l_name);
2076 seq_printf(m, "%d\t"
2087 lockres->l_unlock_action,
2088 lockres->l_ro_holders,
2089 lockres->l_ex_holders,
2090 lockres->l_requested,
2091 lockres->l_blocking);
2093 /* Dump the raw LVB */
2094 lvb = lockres->l_lksb.lvb;
2095 for(i = 0; i < DLM_LVB_LEN; i++)
2096 seq_printf(m, "0x%x\t", lvb[i]);
2099 seq_printf(m, "\n");
2103 static struct seq_operations ocfs2_dlm_seq_ops = {
2104 .start = ocfs2_dlm_seq_start,
2105 .stop = ocfs2_dlm_seq_stop,
2106 .next = ocfs2_dlm_seq_next,
2107 .show = ocfs2_dlm_seq_show,
2110 static int ocfs2_dlm_debug_release(struct inode *inode, struct file *file)
2112 struct seq_file *seq = (struct seq_file *) file->private_data;
2113 struct ocfs2_dlm_seq_priv *priv = seq->private;
2114 struct ocfs2_lock_res *res = &priv->p_iter_res;
2116 ocfs2_remove_lockres_tracking(res);
2117 ocfs2_put_dlm_debug(priv->p_dlm_debug);
2118 return seq_release_private(inode, file);
2121 static int ocfs2_dlm_debug_open(struct inode *inode, struct file *file)
2124 struct ocfs2_dlm_seq_priv *priv;
2125 struct seq_file *seq;
2126 struct ocfs2_super *osb;
2128 priv = kzalloc(sizeof(struct ocfs2_dlm_seq_priv), GFP_KERNEL);
2134 osb = (struct ocfs2_super *) inode->u.generic_ip;
2135 ocfs2_get_dlm_debug(osb->osb_dlm_debug);
2136 priv->p_dlm_debug = osb->osb_dlm_debug;
2137 INIT_LIST_HEAD(&priv->p_iter_res.l_debug_list);
2139 ret = seq_open(file, &ocfs2_dlm_seq_ops);
2146 seq = (struct seq_file *) file->private_data;
2147 seq->private = priv;
2149 ocfs2_add_lockres_tracking(&priv->p_iter_res,
2156 static const struct file_operations ocfs2_dlm_debug_fops = {
2157 .open = ocfs2_dlm_debug_open,
2158 .release = ocfs2_dlm_debug_release,
2160 .llseek = seq_lseek,
2163 static int ocfs2_dlm_init_debug(struct ocfs2_super *osb)
2166 struct ocfs2_dlm_debug *dlm_debug = osb->osb_dlm_debug;
2168 dlm_debug->d_locking_state = debugfs_create_file("locking_state",
2170 osb->osb_debug_root,
2172 &ocfs2_dlm_debug_fops);
2173 if (!dlm_debug->d_locking_state) {
2176 "Unable to create locking state debugfs file.\n");
2180 ocfs2_get_dlm_debug(dlm_debug);
2185 static void ocfs2_dlm_shutdown_debug(struct ocfs2_super *osb)
2187 struct ocfs2_dlm_debug *dlm_debug = osb->osb_dlm_debug;
2190 debugfs_remove(dlm_debug->d_locking_state);
2191 ocfs2_put_dlm_debug(dlm_debug);
2195 int ocfs2_dlm_init(struct ocfs2_super *osb)
2199 struct dlm_ctxt *dlm;
2203 status = ocfs2_dlm_init_debug(osb);
2209 /* launch vote thread */
2210 osb->vote_task = kthread_run(ocfs2_vote_thread, osb, "ocfs2vote");
2211 if (IS_ERR(osb->vote_task)) {
2212 status = PTR_ERR(osb->vote_task);
2213 osb->vote_task = NULL;
2218 /* used by the dlm code to make message headers unique, each
2219 * node in this domain must agree on this. */
2220 dlm_key = crc32_le(0, osb->uuid_str, strlen(osb->uuid_str));
2222 /* for now, uuid == domain */
2223 dlm = dlm_register_domain(osb->uuid_str, dlm_key);
2225 status = PTR_ERR(dlm);
2230 ocfs2_super_lock_res_init(&osb->osb_super_lockres, osb);
2231 ocfs2_rename_lock_res_init(&osb->osb_rename_lockres, osb);
2233 dlm_register_eviction_cb(dlm, &osb->osb_eviction_cb);
2240 ocfs2_dlm_shutdown_debug(osb);
2242 kthread_stop(osb->vote_task);
2249 void ocfs2_dlm_shutdown(struct ocfs2_super *osb)
2253 dlm_unregister_eviction_cb(&osb->osb_eviction_cb);
2255 ocfs2_drop_osb_locks(osb);
2257 if (osb->vote_task) {
2258 kthread_stop(osb->vote_task);
2259 osb->vote_task = NULL;
2262 ocfs2_lock_res_free(&osb->osb_super_lockres);
2263 ocfs2_lock_res_free(&osb->osb_rename_lockres);
2265 dlm_unregister_domain(osb->dlm);
2268 ocfs2_dlm_shutdown_debug(osb);
2273 static void ocfs2_unlock_ast_func(void *opaque, enum dlm_status status)
2275 struct ocfs2_lock_res *lockres = opaque;
2276 unsigned long flags;
2280 mlog(0, "UNLOCK AST called on lock %s, action = %d\n", lockres->l_name,
2281 lockres->l_unlock_action);
2283 spin_lock_irqsave(&lockres->l_lock, flags);
2284 /* We tried to cancel a convert request, but it was already
2285 * granted. All we want to do here is clear our unlock
2286 * state. The wake_up call done at the bottom is redundant
2287 * (ocfs2_prepare_cancel_convert doesn't sleep on this) but doesn't
2288 * hurt anything anyway */
2289 if (status == DLM_CANCELGRANT &&
2290 lockres->l_unlock_action == OCFS2_UNLOCK_CANCEL_CONVERT) {
2291 mlog(0, "Got cancelgrant for %s\n", lockres->l_name);
2293 /* We don't clear the busy flag in this case as it
2294 * should have been cleared by the ast which the dlm
2296 goto complete_unlock;
2299 if (status != DLM_NORMAL) {
2300 mlog(ML_ERROR, "Dlm passes status %d for lock %s, "
2301 "unlock_action %d\n", status, lockres->l_name,
2302 lockres->l_unlock_action);
2303 spin_unlock_irqrestore(&lockres->l_lock, flags);
2307 switch(lockres->l_unlock_action) {
2308 case OCFS2_UNLOCK_CANCEL_CONVERT:
2309 mlog(0, "Cancel convert success for %s\n", lockres->l_name);
2310 lockres->l_action = OCFS2_AST_INVALID;
2312 case OCFS2_UNLOCK_DROP_LOCK:
2313 lockres->l_level = LKM_IVMODE;
2319 lockres_clear_flags(lockres, OCFS2_LOCK_BUSY);
2321 lockres->l_unlock_action = OCFS2_UNLOCK_INVALID;
2322 spin_unlock_irqrestore(&lockres->l_lock, flags);
2324 wake_up(&lockres->l_event);
2329 typedef void (ocfs2_pre_drop_cb_t)(struct ocfs2_lock_res *, void *);
2331 struct drop_lock_cb {
2332 ocfs2_pre_drop_cb_t *drop_func;
2336 static int ocfs2_drop_lock(struct ocfs2_super *osb,
2337 struct ocfs2_lock_res *lockres,
2338 struct drop_lock_cb *dcb)
2340 enum dlm_status status;
2341 unsigned long flags;
2343 /* We didn't get anywhere near actually using this lockres. */
2344 if (!(lockres->l_flags & OCFS2_LOCK_INITIALIZED))
2347 spin_lock_irqsave(&lockres->l_lock, flags);
2349 mlog_bug_on_msg(!(lockres->l_flags & OCFS2_LOCK_FREEING),
2350 "lockres %s, flags 0x%lx\n",
2351 lockres->l_name, lockres->l_flags);
2353 while (lockres->l_flags & OCFS2_LOCK_BUSY) {
2354 mlog(0, "waiting on busy lock \"%s\": flags = %lx, action = "
2355 "%u, unlock_action = %u\n",
2356 lockres->l_name, lockres->l_flags, lockres->l_action,
2357 lockres->l_unlock_action);
2359 spin_unlock_irqrestore(&lockres->l_lock, flags);
2361 /* XXX: Today we just wait on any busy
2362 * locks... Perhaps we need to cancel converts in the
2364 ocfs2_wait_on_busy_lock(lockres);
2366 spin_lock_irqsave(&lockres->l_lock, flags);
2370 dcb->drop_func(lockres, dcb->drop_data);
2372 if (lockres->l_flags & OCFS2_LOCK_BUSY)
2373 mlog(ML_ERROR, "destroying busy lock: \"%s\"\n",
2375 if (lockres->l_flags & OCFS2_LOCK_BLOCKED)
2376 mlog(0, "destroying blocked lock: \"%s\"\n", lockres->l_name);
2378 if (!(lockres->l_flags & OCFS2_LOCK_ATTACHED)) {
2379 spin_unlock_irqrestore(&lockres->l_lock, flags);
2383 lockres_clear_flags(lockres, OCFS2_LOCK_ATTACHED);
2385 /* make sure we never get here while waiting for an ast to
2387 BUG_ON(lockres->l_action != OCFS2_AST_INVALID);
2389 /* is this necessary? */
2390 lockres_or_flags(lockres, OCFS2_LOCK_BUSY);
2391 lockres->l_unlock_action = OCFS2_UNLOCK_DROP_LOCK;
2392 spin_unlock_irqrestore(&lockres->l_lock, flags);
2394 mlog(0, "lock %s\n", lockres->l_name);
2396 status = dlmunlock(osb->dlm, &lockres->l_lksb, LKM_VALBLK,
2397 lockres->l_ops->unlock_ast, lockres);
2398 if (status != DLM_NORMAL) {
2399 ocfs2_log_dlm_error("dlmunlock", status, lockres);
2400 mlog(ML_ERROR, "lockres flags: %lu\n", lockres->l_flags);
2401 dlm_print_one_lock(lockres->l_lksb.lockid);
2404 mlog(0, "lock %s, successfull return from dlmunlock\n",
2407 ocfs2_wait_on_busy_lock(lockres);
2413 /* Mark the lockres as being dropped. It will no longer be
2414 * queued if blocking, but we still may have to wait on it
2415 * being dequeued from the vote thread before we can consider
2418 * You can *not* attempt to call cluster_lock on this lockres anymore. */
2419 void ocfs2_mark_lockres_freeing(struct ocfs2_lock_res *lockres)
2422 struct ocfs2_mask_waiter mw;
2423 unsigned long flags;
2425 ocfs2_init_mask_waiter(&mw);
2427 spin_lock_irqsave(&lockres->l_lock, flags);
2428 lockres->l_flags |= OCFS2_LOCK_FREEING;
2429 while (lockres->l_flags & OCFS2_LOCK_QUEUED) {
2430 lockres_add_mask_waiter(lockres, &mw, OCFS2_LOCK_QUEUED, 0);
2431 spin_unlock_irqrestore(&lockres->l_lock, flags);
2433 mlog(0, "Waiting on lockres %s\n", lockres->l_name);
2435 status = ocfs2_wait_for_mask(&mw);
2439 spin_lock_irqsave(&lockres->l_lock, flags);
2441 spin_unlock_irqrestore(&lockres->l_lock, flags);
2444 void ocfs2_simple_drop_lockres(struct ocfs2_super *osb,
2445 struct ocfs2_lock_res *lockres)
2449 ocfs2_mark_lockres_freeing(lockres);
2450 ret = ocfs2_drop_lock(osb, lockres, NULL);
2455 static void ocfs2_drop_osb_locks(struct ocfs2_super *osb)
2457 ocfs2_simple_drop_lockres(osb, &osb->osb_super_lockres);
2458 ocfs2_simple_drop_lockres(osb, &osb->osb_rename_lockres);
2461 static void ocfs2_meta_pre_drop(struct ocfs2_lock_res *lockres, void *data)
2463 struct inode *inode = data;
2465 /* the metadata lock requires a bit more work as we have an
2466 * LVB to worry about. */
2467 if (lockres->l_flags & OCFS2_LOCK_ATTACHED &&
2468 lockres->l_level == LKM_EXMODE &&
2469 !(lockres->l_flags & OCFS2_LOCK_NEEDS_REFRESH))
2470 __ocfs2_stuff_meta_lvb(inode);
2473 int ocfs2_drop_inode_locks(struct inode *inode)
2476 struct drop_lock_cb meta_dcb = { ocfs2_meta_pre_drop, inode, };
2480 /* No need to call ocfs2_mark_lockres_freeing here -
2481 * ocfs2_clear_inode has done it for us. */
2483 err = ocfs2_drop_lock(OCFS2_SB(inode->i_sb),
2484 &OCFS2_I(inode)->ip_data_lockres,
2491 err = ocfs2_drop_lock(OCFS2_SB(inode->i_sb),
2492 &OCFS2_I(inode)->ip_meta_lockres,
2496 if (err < 0 && !status)
2499 err = ocfs2_drop_lock(OCFS2_SB(inode->i_sb),
2500 &OCFS2_I(inode)->ip_rw_lockres,
2504 if (err < 0 && !status)
2511 static void ocfs2_prepare_downconvert(struct ocfs2_lock_res *lockres,
2514 assert_spin_locked(&lockres->l_lock);
2516 BUG_ON(lockres->l_blocking <= LKM_NLMODE);
2518 if (lockres->l_level <= new_level) {
2519 mlog(ML_ERROR, "lockres->l_level (%u) <= new_level (%u)\n",
2520 lockres->l_level, new_level);
2524 mlog(0, "lock %s, new_level = %d, l_blocking = %d\n",
2525 lockres->l_name, new_level, lockres->l_blocking);
2527 lockres->l_action = OCFS2_AST_DOWNCONVERT;
2528 lockres->l_requested = new_level;
2529 lockres_or_flags(lockres, OCFS2_LOCK_BUSY);
2532 static int ocfs2_downconvert_lock(struct ocfs2_super *osb,
2533 struct ocfs2_lock_res *lockres,
2537 int ret, dlm_flags = LKM_CONVERT;
2538 enum dlm_status status;
2543 dlm_flags |= LKM_VALBLK;
2545 status = dlmlock(osb->dlm,
2550 OCFS2_LOCK_ID_MAX_LEN - 1,
2551 lockres->l_ops->ast,
2553 lockres->l_ops->bast);
2554 if (status != DLM_NORMAL) {
2555 ocfs2_log_dlm_error("dlmlock", status, lockres);
2557 ocfs2_recover_from_dlm_error(lockres, 1);
2567 /* returns 1 when the caller should unlock and call dlmunlock */
2568 static int ocfs2_prepare_cancel_convert(struct ocfs2_super *osb,
2569 struct ocfs2_lock_res *lockres)
2571 assert_spin_locked(&lockres->l_lock);
2574 mlog(0, "lock %s\n", lockres->l_name);
2576 if (lockres->l_unlock_action == OCFS2_UNLOCK_CANCEL_CONVERT) {
2577 /* If we're already trying to cancel a lock conversion
2578 * then just drop the spinlock and allow the caller to
2579 * requeue this lock. */
2581 mlog(0, "Lockres %s, skip convert\n", lockres->l_name);
2585 /* were we in a convert when we got the bast fire? */
2586 BUG_ON(lockres->l_action != OCFS2_AST_CONVERT &&
2587 lockres->l_action != OCFS2_AST_DOWNCONVERT);
2588 /* set things up for the unlockast to know to just
2589 * clear out the ast_action and unset busy, etc. */
2590 lockres->l_unlock_action = OCFS2_UNLOCK_CANCEL_CONVERT;
2592 mlog_bug_on_msg(!(lockres->l_flags & OCFS2_LOCK_BUSY),
2593 "lock %s, invalid flags: 0x%lx\n",
2594 lockres->l_name, lockres->l_flags);
2599 static int ocfs2_cancel_convert(struct ocfs2_super *osb,
2600 struct ocfs2_lock_res *lockres)
2603 enum dlm_status status;
2606 mlog(0, "lock %s\n", lockres->l_name);
2609 status = dlmunlock(osb->dlm,
2612 lockres->l_ops->unlock_ast,
2614 if (status != DLM_NORMAL) {
2615 ocfs2_log_dlm_error("dlmunlock", status, lockres);
2617 ocfs2_recover_from_dlm_error(lockres, 0);
2620 mlog(0, "lock %s return from dlmunlock\n", lockres->l_name);
2626 static inline int ocfs2_can_downconvert_meta_lock(struct inode *inode,
2627 struct ocfs2_lock_res *lockres,
2634 BUG_ON(new_level != LKM_NLMODE && new_level != LKM_PRMODE);
2636 if (lockres->l_flags & OCFS2_LOCK_REFRESHING) {
2638 mlog(0, "lockres %s currently being refreshed -- backing "
2639 "off!\n", lockres->l_name);
2640 } else if (new_level == LKM_PRMODE)
2641 ret = !lockres->l_ex_holders &&
2642 ocfs2_inode_fully_checkpointed(inode);
2643 else /* Must be NLMODE we're converting to. */
2644 ret = !lockres->l_ro_holders && !lockres->l_ex_holders &&
2645 ocfs2_inode_fully_checkpointed(inode);
2651 static int ocfs2_do_unblock_meta(struct inode *inode,
2657 struct ocfs2_lock_res *lockres = &OCFS2_I(inode)->ip_meta_lockres;
2658 unsigned long flags;
2660 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
2664 spin_lock_irqsave(&lockres->l_lock, flags);
2666 BUG_ON(!(lockres->l_flags & OCFS2_LOCK_BLOCKED));
2668 mlog(0, "l_level=%d, l_blocking=%d\n", lockres->l_level,
2669 lockres->l_blocking);
2671 BUG_ON(lockres->l_level != LKM_EXMODE &&
2672 lockres->l_level != LKM_PRMODE);
2674 if (lockres->l_flags & OCFS2_LOCK_BUSY) {
2676 ret = ocfs2_prepare_cancel_convert(osb, lockres);
2677 spin_unlock_irqrestore(&lockres->l_lock, flags);
2679 ret = ocfs2_cancel_convert(osb, lockres);
2686 new_level = ocfs2_highest_compat_lock_level(lockres->l_blocking);
2688 mlog(0, "l_level=%d, l_blocking=%d, new_level=%d\n",
2689 lockres->l_level, lockres->l_blocking, new_level);
2691 if (ocfs2_can_downconvert_meta_lock(inode, lockres, new_level)) {
2692 if (lockres->l_level == LKM_EXMODE)
2695 /* If the lock hasn't been refreshed yet (rare), then
2696 * our memory inode values are old and we skip
2697 * stuffing the lvb. There's no need to actually clear
2698 * out the lvb here as it's value is still valid. */
2699 if (!(lockres->l_flags & OCFS2_LOCK_NEEDS_REFRESH)) {
2701 __ocfs2_stuff_meta_lvb(inode);
2703 mlog(0, "lockres %s: downconverting stale lock!\n",
2706 mlog(0, "calling ocfs2_downconvert_lock with l_level=%d, "
2707 "l_blocking=%d, new_level=%d\n",
2708 lockres->l_level, lockres->l_blocking, new_level);
2710 ocfs2_prepare_downconvert(lockres, new_level);
2711 spin_unlock_irqrestore(&lockres->l_lock, flags);
2712 ret = ocfs2_downconvert_lock(osb, lockres, new_level, set_lvb);
2715 if (!ocfs2_inode_fully_checkpointed(inode))
2716 ocfs2_start_checkpoint(osb);
2719 spin_unlock_irqrestore(&lockres->l_lock, flags);
2726 static int ocfs2_generic_unblock_lock(struct ocfs2_super *osb,
2727 struct ocfs2_lock_res *lockres,
2728 struct ocfs2_unblock_ctl *ctl,
2729 ocfs2_convert_worker_t *worker)
2731 unsigned long flags;
2738 spin_lock_irqsave(&lockres->l_lock, flags);
2740 BUG_ON(!(lockres->l_flags & OCFS2_LOCK_BLOCKED));
2743 if (lockres->l_flags & OCFS2_LOCK_BUSY) {
2745 ret = ocfs2_prepare_cancel_convert(osb, lockres);
2746 spin_unlock_irqrestore(&lockres->l_lock, flags);
2748 ret = ocfs2_cancel_convert(osb, lockres);
2755 /* if we're blocking an exclusive and we have *any* holders,
2757 if ((lockres->l_blocking == LKM_EXMODE)
2758 && (lockres->l_ex_holders || lockres->l_ro_holders)) {
2759 spin_unlock_irqrestore(&lockres->l_lock, flags);
2765 /* If it's a PR we're blocking, then only
2766 * requeue if we've got any EX holders */
2767 if (lockres->l_blocking == LKM_PRMODE &&
2768 lockres->l_ex_holders) {
2769 spin_unlock_irqrestore(&lockres->l_lock, flags);
2775 /* If we get here, then we know that there are no more
2776 * incompatible holders (and anyone asking for an incompatible
2777 * lock is blocked). We can now downconvert the lock */
2781 /* Some lockres types want to do a bit of work before
2782 * downconverting a lock. Allow that here. The worker function
2783 * may sleep, so we save off a copy of what we're blocking as
2784 * it may change while we're not holding the spin lock. */
2785 blocking = lockres->l_blocking;
2786 spin_unlock_irqrestore(&lockres->l_lock, flags);
2788 ctl->unblock_action = worker(lockres, blocking);
2790 if (ctl->unblock_action == UNBLOCK_STOP_POST)
2793 spin_lock_irqsave(&lockres->l_lock, flags);
2794 if (blocking != lockres->l_blocking) {
2795 /* If this changed underneath us, then we can't drop
2802 new_level = ocfs2_highest_compat_lock_level(lockres->l_blocking);
2804 ocfs2_prepare_downconvert(lockres, new_level);
2805 spin_unlock_irqrestore(&lockres->l_lock, flags);
2806 ret = ocfs2_downconvert_lock(osb, lockres, new_level, 0);
2812 static int ocfs2_data_convert_worker(struct ocfs2_lock_res *lockres,
2815 struct inode *inode;
2816 struct address_space *mapping;
2818 inode = ocfs2_lock_res_inode(lockres);
2819 mapping = inode->i_mapping;
2821 if (filemap_fdatawrite(mapping)) {
2822 mlog(ML_ERROR, "Could not sync inode %llu for downconvert!",
2823 (unsigned long long)OCFS2_I(inode)->ip_blkno);
2825 sync_mapping_buffers(mapping);
2826 if (blocking == LKM_EXMODE) {
2827 truncate_inode_pages(mapping, 0);
2828 unmap_mapping_range(mapping, 0, 0, 0);
2830 /* We only need to wait on the I/O if we're not also
2831 * truncating pages because truncate_inode_pages waits
2832 * for us above. We don't truncate pages if we're
2833 * blocking anything < EXMODE because we want to keep
2834 * them around in that case. */
2835 filemap_fdatawait(mapping);
2838 return UNBLOCK_CONTINUE;
2841 int ocfs2_unblock_data(struct ocfs2_lock_res *lockres,
2842 struct ocfs2_unblock_ctl *ctl)
2845 struct inode *inode;
2846 struct ocfs2_super *osb;
2850 inode = ocfs2_lock_res_inode(lockres);
2851 osb = OCFS2_SB(inode->i_sb);
2853 mlog(0, "unblock inode %llu\n",
2854 (unsigned long long)OCFS2_I(inode)->ip_blkno);
2856 status = ocfs2_generic_unblock_lock(osb, lockres, ctl,
2857 ocfs2_data_convert_worker);
2861 mlog(0, "inode %llu, requeue = %d\n",
2862 (unsigned long long)OCFS2_I(inode)->ip_blkno, ctl->requeue);
2868 static int ocfs2_unblock_inode_lock(struct ocfs2_lock_res *lockres,
2869 struct ocfs2_unblock_ctl *ctl)
2872 struct inode *inode;
2876 mlog(0, "Unblock lockres %s\n", lockres->l_name);
2878 inode = ocfs2_lock_res_inode(lockres);
2880 status = ocfs2_generic_unblock_lock(OCFS2_SB(inode->i_sb),
2881 lockres, ctl, NULL);
2889 static int ocfs2_unblock_meta(struct ocfs2_lock_res *lockres,
2890 struct ocfs2_unblock_ctl *ctl)
2893 struct inode *inode;
2897 inode = ocfs2_lock_res_inode(lockres);
2899 mlog(0, "unblock inode %llu\n",
2900 (unsigned long long)OCFS2_I(inode)->ip_blkno);
2902 status = ocfs2_do_unblock_meta(inode, &ctl->requeue);
2906 mlog(0, "inode %llu, requeue = %d\n",
2907 (unsigned long long)OCFS2_I(inode)->ip_blkno, ctl->requeue);
2914 * Does the final reference drop on our dentry lock. Right now this
2915 * happens in the vote thread, but we could choose to simplify the
2916 * dlmglue API and push these off to the ocfs2_wq in the future.
2918 static void ocfs2_dentry_post_unlock(struct ocfs2_super *osb,
2919 struct ocfs2_lock_res *lockres)
2921 struct ocfs2_dentry_lock *dl = ocfs2_lock_res_dl(lockres);
2922 ocfs2_dentry_lock_put(osb, dl);
2926 * d_delete() matching dentries before the lock downconvert.
2928 * At this point, any process waiting to destroy the
2929 * dentry_lock due to last ref count is stopped by the
2930 * OCFS2_LOCK_QUEUED flag.
2932 * We have two potential problems
2934 * 1) If we do the last reference drop on our dentry_lock (via dput)
2935 * we'll wind up in ocfs2_release_dentry_lock(), waiting on
2936 * the downconvert to finish. Instead we take an elevated
2937 * reference and push the drop until after we've completed our
2938 * unblock processing.
2940 * 2) There might be another process with a final reference,
2941 * waiting on us to finish processing. If this is the case, we
2942 * detect it and exit out - there's no more dentries anyway.
2944 static int ocfs2_dentry_convert_worker(struct ocfs2_lock_res *lockres,
2947 struct ocfs2_dentry_lock *dl = ocfs2_lock_res_dl(lockres);
2948 struct ocfs2_inode_info *oi = OCFS2_I(dl->dl_inode);
2949 struct dentry *dentry;
2950 unsigned long flags;
2954 * This node is blocking another node from getting a read
2955 * lock. This happens when we've renamed within a
2956 * directory. We've forced the other nodes to d_delete(), but
2957 * we never actually dropped our lock because it's still
2958 * valid. The downconvert code will retain a PR for this node,
2959 * so there's no further work to do.
2961 if (blocking == LKM_PRMODE)
2962 return UNBLOCK_CONTINUE;
2965 * Mark this inode as potentially orphaned. The code in
2966 * ocfs2_delete_inode() will figure out whether it actually
2967 * needs to be freed or not.
2969 spin_lock(&oi->ip_lock);
2970 oi->ip_flags |= OCFS2_INODE_MAYBE_ORPHANED;
2971 spin_unlock(&oi->ip_lock);
2974 * Yuck. We need to make sure however that the check of
2975 * OCFS2_LOCK_FREEING and the extra reference are atomic with
2976 * respect to a reference decrement or the setting of that
2979 spin_lock_irqsave(&lockres->l_lock, flags);
2980 spin_lock(&dentry_attach_lock);
2981 if (!(lockres->l_flags & OCFS2_LOCK_FREEING)
2986 spin_unlock(&dentry_attach_lock);
2987 spin_unlock_irqrestore(&lockres->l_lock, flags);
2989 mlog(0, "extra_ref = %d\n", extra_ref);
2992 * We have a process waiting on us in ocfs2_dentry_iput(),
2993 * which means we can't have any more outstanding
2994 * aliases. There's no need to do any more work.
2997 return UNBLOCK_CONTINUE;
2999 spin_lock(&dentry_attach_lock);
3001 dentry = ocfs2_find_local_alias(dl->dl_inode,
3002 dl->dl_parent_blkno, 1);
3005 spin_unlock(&dentry_attach_lock);
3007 mlog(0, "d_delete(%.*s);\n", dentry->d_name.len,
3008 dentry->d_name.name);
3011 * The following dcache calls may do an
3012 * iput(). Normally we don't want that from the
3013 * downconverting thread, but in this case it's ok
3014 * because the requesting node already has an
3015 * exclusive lock on the inode, so it can't be queued
3016 * for a downconvert.
3021 spin_lock(&dentry_attach_lock);
3023 spin_unlock(&dentry_attach_lock);
3026 * If we are the last holder of this dentry lock, there is no
3027 * reason to downconvert so skip straight to the unlock.
3029 if (dl->dl_count == 1)
3030 return UNBLOCK_STOP_POST;
3032 return UNBLOCK_CONTINUE_POST;
3035 static int ocfs2_unblock_dentry_lock(struct ocfs2_lock_res *lockres,
3036 struct ocfs2_unblock_ctl *ctl)
3039 struct ocfs2_dentry_lock *dl = ocfs2_lock_res_dl(lockres);
3040 struct ocfs2_super *osb = OCFS2_SB(dl->dl_inode->i_sb);
3042 mlog(0, "unblock dentry lock: %llu\n",
3043 (unsigned long long)OCFS2_I(dl->dl_inode)->ip_blkno);
3045 ret = ocfs2_generic_unblock_lock(osb,
3048 ocfs2_dentry_convert_worker);
3052 mlog(0, "requeue = %d, post = %d\n", ctl->requeue, ctl->unblock_action);
3057 /* Generic unblock function for any lockres whose private data is an
3058 * ocfs2_super pointer. */
3059 static int ocfs2_unblock_osb_lock(struct ocfs2_lock_res *lockres,
3060 struct ocfs2_unblock_ctl *ctl)
3063 struct ocfs2_super *osb;
3067 mlog(0, "Unblock lockres %s\n", lockres->l_name);
3069 osb = ocfs2_lock_res_super(lockres);
3071 status = ocfs2_generic_unblock_lock(osb,
3082 void ocfs2_process_blocked_lock(struct ocfs2_super *osb,
3083 struct ocfs2_lock_res *lockres)
3086 struct ocfs2_unblock_ctl ctl = {0, 0,};
3087 unsigned long flags;
3089 /* Our reference to the lockres in this function can be
3090 * considered valid until we remove the OCFS2_LOCK_QUEUED
3096 BUG_ON(!lockres->l_ops);
3097 BUG_ON(!lockres->l_ops->unblock);
3099 mlog(0, "lockres %s blocked.\n", lockres->l_name);
3101 /* Detect whether a lock has been marked as going away while
3102 * the vote thread was processing other things. A lock can
3103 * still be marked with OCFS2_LOCK_FREEING after this check,
3104 * but short circuiting here will still save us some
3106 spin_lock_irqsave(&lockres->l_lock, flags);
3107 if (lockres->l_flags & OCFS2_LOCK_FREEING)
3109 spin_unlock_irqrestore(&lockres->l_lock, flags);
3111 status = lockres->l_ops->unblock(lockres, &ctl);
3115 spin_lock_irqsave(&lockres->l_lock, flags);
3117 if (lockres->l_flags & OCFS2_LOCK_FREEING || !ctl.requeue) {
3118 lockres_clear_flags(lockres, OCFS2_LOCK_QUEUED);
3120 ocfs2_schedule_blocked_lock(osb, lockres);
3122 mlog(0, "lockres %s, requeue = %s.\n", lockres->l_name,
3123 ctl.requeue ? "yes" : "no");
3124 spin_unlock_irqrestore(&lockres->l_lock, flags);
3126 if (ctl.unblock_action != UNBLOCK_CONTINUE
3127 && lockres->l_ops->post_unlock)
3128 lockres->l_ops->post_unlock(osb, lockres);
3133 static void ocfs2_schedule_blocked_lock(struct ocfs2_super *osb,
3134 struct ocfs2_lock_res *lockres)
3138 assert_spin_locked(&lockres->l_lock);
3140 if (lockres->l_flags & OCFS2_LOCK_FREEING) {
3141 /* Do not schedule a lock for downconvert when it's on
3142 * the way to destruction - any nodes wanting access
3143 * to the resource will get it soon. */
3144 mlog(0, "Lockres %s won't be scheduled: flags 0x%lx\n",
3145 lockres->l_name, lockres->l_flags);
3149 lockres_or_flags(lockres, OCFS2_LOCK_QUEUED);
3151 spin_lock(&osb->vote_task_lock);
3152 if (list_empty(&lockres->l_blocked_list)) {
3153 list_add_tail(&lockres->l_blocked_list,
3154 &osb->blocked_lock_list);
3155 osb->blocked_lock_count++;
3157 spin_unlock(&osb->vote_task_lock);
3162 /* This aids in debugging situations where a bad LVB might be involved. */
3163 void ocfs2_dump_meta_lvb_info(u64 level,
3164 const char *function,
3166 struct ocfs2_lock_res *lockres)
3168 struct ocfs2_meta_lvb *lvb = (struct ocfs2_meta_lvb *) lockres->l_lksb.lvb;
3170 mlog(level, "LVB information for %s (called from %s:%u):\n",
3171 lockres->l_name, function, line);
3172 mlog(level, "version: %u, clusters: %u, generation: 0x%x\n",
3173 lvb->lvb_version, be32_to_cpu(lvb->lvb_iclusters),
3174 be32_to_cpu(lvb->lvb_igeneration));
3175 mlog(level, "size: %llu, uid %u, gid %u, mode 0x%x\n",
3176 (unsigned long long)be64_to_cpu(lvb->lvb_isize),
3177 be32_to_cpu(lvb->lvb_iuid), be32_to_cpu(lvb->lvb_igid),
3178 be16_to_cpu(lvb->lvb_imode));
3179 mlog(level, "nlink %u, atime_packed 0x%llx, ctime_packed 0x%llx, "
3180 "mtime_packed 0x%llx iattr 0x%x\n", be16_to_cpu(lvb->lvb_inlink),
3181 (long long)be64_to_cpu(lvb->lvb_iatime_packed),
3182 (long long)be64_to_cpu(lvb->lvb_ictime_packed),
3183 (long long)be64_to_cpu(lvb->lvb_imtime_packed),
3184 be32_to_cpu(lvb->lvb_iattr));