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);
1431 mlog_meta_lvb(0, lockres);
1436 static void ocfs2_unpack_timespec(struct timespec *spec,
1439 spec->tv_sec = packed_time >> OCFS2_SEC_SHIFT;
1440 spec->tv_nsec = packed_time & OCFS2_NSEC_MASK;
1443 static void ocfs2_refresh_inode_from_lvb(struct inode *inode)
1445 struct ocfs2_inode_info *oi = OCFS2_I(inode);
1446 struct ocfs2_lock_res *lockres = &oi->ip_meta_lockres;
1447 struct ocfs2_meta_lvb *lvb;
1451 mlog_meta_lvb(0, lockres);
1453 lvb = (struct ocfs2_meta_lvb *) lockres->l_lksb.lvb;
1455 /* We're safe here without the lockres lock... */
1456 spin_lock(&oi->ip_lock);
1457 oi->ip_clusters = be32_to_cpu(lvb->lvb_iclusters);
1458 i_size_write(inode, be64_to_cpu(lvb->lvb_isize));
1460 oi->ip_attr = be32_to_cpu(lvb->lvb_iattr);
1461 ocfs2_set_inode_flags(inode);
1463 /* fast-symlinks are a special case */
1464 if (S_ISLNK(inode->i_mode) && !oi->ip_clusters)
1465 inode->i_blocks = 0;
1468 ocfs2_align_bytes_to_sectors(i_size_read(inode));
1470 inode->i_uid = be32_to_cpu(lvb->lvb_iuid);
1471 inode->i_gid = be32_to_cpu(lvb->lvb_igid);
1472 inode->i_mode = be16_to_cpu(lvb->lvb_imode);
1473 inode->i_nlink = be16_to_cpu(lvb->lvb_inlink);
1474 ocfs2_unpack_timespec(&inode->i_atime,
1475 be64_to_cpu(lvb->lvb_iatime_packed));
1476 ocfs2_unpack_timespec(&inode->i_mtime,
1477 be64_to_cpu(lvb->lvb_imtime_packed));
1478 ocfs2_unpack_timespec(&inode->i_ctime,
1479 be64_to_cpu(lvb->lvb_ictime_packed));
1480 spin_unlock(&oi->ip_lock);
1485 static inline int ocfs2_meta_lvb_is_trustable(struct ocfs2_lock_res *lockres)
1487 struct ocfs2_meta_lvb *lvb = (struct ocfs2_meta_lvb *) lockres->l_lksb.lvb;
1489 if (lvb->lvb_version == OCFS2_LVB_VERSION)
1494 /* Determine whether a lock resource needs to be refreshed, and
1495 * arbitrate who gets to refresh it.
1497 * 0 means no refresh needed.
1499 * > 0 means you need to refresh this and you MUST call
1500 * ocfs2_complete_lock_res_refresh afterwards. */
1501 static int ocfs2_should_refresh_lock_res(struct ocfs2_lock_res *lockres)
1503 unsigned long flags;
1509 spin_lock_irqsave(&lockres->l_lock, flags);
1510 if (!(lockres->l_flags & OCFS2_LOCK_NEEDS_REFRESH)) {
1511 spin_unlock_irqrestore(&lockres->l_lock, flags);
1515 if (lockres->l_flags & OCFS2_LOCK_REFRESHING) {
1516 spin_unlock_irqrestore(&lockres->l_lock, flags);
1518 ocfs2_wait_on_refreshing_lock(lockres);
1522 /* Ok, I'll be the one to refresh this lock. */
1523 lockres_or_flags(lockres, OCFS2_LOCK_REFRESHING);
1524 spin_unlock_irqrestore(&lockres->l_lock, flags);
1532 /* If status is non zero, I'll mark it as not being in refresh
1533 * anymroe, but i won't clear the needs refresh flag. */
1534 static inline void ocfs2_complete_lock_res_refresh(struct ocfs2_lock_res *lockres,
1537 unsigned long flags;
1540 spin_lock_irqsave(&lockres->l_lock, flags);
1541 lockres_clear_flags(lockres, OCFS2_LOCK_REFRESHING);
1543 lockres_clear_flags(lockres, OCFS2_LOCK_NEEDS_REFRESH);
1544 spin_unlock_irqrestore(&lockres->l_lock, flags);
1546 wake_up(&lockres->l_event);
1551 /* may or may not return a bh if it went to disk. */
1552 static int ocfs2_meta_lock_update(struct inode *inode,
1553 struct buffer_head **bh)
1556 struct ocfs2_inode_info *oi = OCFS2_I(inode);
1557 struct ocfs2_lock_res *lockres;
1558 struct ocfs2_dinode *fe;
1562 spin_lock(&oi->ip_lock);
1563 if (oi->ip_flags & OCFS2_INODE_DELETED) {
1564 mlog(0, "Orphaned inode %llu was deleted while we "
1565 "were waiting on a lock. ip_flags = 0x%x\n",
1566 (unsigned long long)oi->ip_blkno, oi->ip_flags);
1567 spin_unlock(&oi->ip_lock);
1571 spin_unlock(&oi->ip_lock);
1573 lockres = &oi->ip_meta_lockres;
1575 if (!ocfs2_should_refresh_lock_res(lockres))
1578 /* This will discard any caching information we might have had
1579 * for the inode metadata. */
1580 ocfs2_metadata_cache_purge(inode);
1582 /* will do nothing for inode types that don't use the extent
1583 * map (directories, bitmap files, etc) */
1584 ocfs2_extent_map_trunc(inode, 0);
1586 if (ocfs2_meta_lvb_is_trustable(lockres)) {
1587 mlog(0, "Trusting LVB on inode %llu\n",
1588 (unsigned long long)oi->ip_blkno);
1589 ocfs2_refresh_inode_from_lvb(inode);
1591 /* Boo, we have to go to disk. */
1592 /* read bh, cast, ocfs2_refresh_inode */
1593 status = ocfs2_read_block(OCFS2_SB(inode->i_sb), oi->ip_blkno,
1594 bh, OCFS2_BH_CACHED, inode);
1599 fe = (struct ocfs2_dinode *) (*bh)->b_data;
1601 /* This is a good chance to make sure we're not
1602 * locking an invalid object.
1604 * We bug on a stale inode here because we checked
1605 * above whether it was wiped from disk. The wiping
1606 * node provides a guarantee that we receive that
1607 * message and can mark the inode before dropping any
1608 * locks associated with it. */
1609 if (!OCFS2_IS_VALID_DINODE(fe)) {
1610 OCFS2_RO_ON_INVALID_DINODE(inode->i_sb, fe);
1614 mlog_bug_on_msg(inode->i_generation !=
1615 le32_to_cpu(fe->i_generation),
1616 "Invalid dinode %llu disk generation: %u "
1617 "inode->i_generation: %u\n",
1618 (unsigned long long)oi->ip_blkno,
1619 le32_to_cpu(fe->i_generation),
1620 inode->i_generation);
1621 mlog_bug_on_msg(le64_to_cpu(fe->i_dtime) ||
1622 !(fe->i_flags & cpu_to_le32(OCFS2_VALID_FL)),
1623 "Stale dinode %llu dtime: %llu flags: 0x%x\n",
1624 (unsigned long long)oi->ip_blkno,
1625 (unsigned long long)le64_to_cpu(fe->i_dtime),
1626 le32_to_cpu(fe->i_flags));
1628 ocfs2_refresh_inode(inode, fe);
1633 ocfs2_complete_lock_res_refresh(lockres, status);
1639 static int ocfs2_assign_bh(struct inode *inode,
1640 struct buffer_head **ret_bh,
1641 struct buffer_head *passed_bh)
1646 /* Ok, the update went to disk for us, use the
1648 *ret_bh = passed_bh;
1654 status = ocfs2_read_block(OCFS2_SB(inode->i_sb),
1655 OCFS2_I(inode)->ip_blkno,
1666 * returns < 0 error if the callback will never be called, otherwise
1667 * the result of the lock will be communicated via the callback.
1669 int ocfs2_meta_lock_full(struct inode *inode,
1670 struct ocfs2_journal_handle *handle,
1671 struct buffer_head **ret_bh,
1675 int status, level, dlm_flags, acquired;
1676 struct ocfs2_lock_res *lockres;
1677 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1678 struct buffer_head *local_bh = NULL;
1684 mlog(0, "inode %llu, take %s META lock\n",
1685 (unsigned long long)OCFS2_I(inode)->ip_blkno,
1686 ex ? "EXMODE" : "PRMODE");
1690 /* We'll allow faking a readonly metadata lock for
1692 if (ocfs2_is_hard_readonly(osb)) {
1698 if (!(arg_flags & OCFS2_META_LOCK_RECOVERY))
1699 wait_event(osb->recovery_event,
1700 ocfs2_node_map_is_empty(osb, &osb->recovery_map));
1703 lockres = &OCFS2_I(inode)->ip_meta_lockres;
1704 level = ex ? LKM_EXMODE : LKM_PRMODE;
1706 if (arg_flags & OCFS2_META_LOCK_NOQUEUE)
1707 dlm_flags |= LKM_NOQUEUE;
1709 status = ocfs2_cluster_lock(osb, lockres, level, dlm_flags, arg_flags);
1711 if (status != -EAGAIN && status != -EIOCBRETRY)
1716 /* Notify the error cleanup path to drop the cluster lock. */
1719 /* We wait twice because a node may have died while we were in
1720 * the lower dlm layers. The second time though, we've
1721 * committed to owning this lock so we don't allow signals to
1722 * abort the operation. */
1723 if (!(arg_flags & OCFS2_META_LOCK_RECOVERY))
1724 wait_event(osb->recovery_event,
1725 ocfs2_node_map_is_empty(osb, &osb->recovery_map));
1727 /* This is fun. The caller may want a bh back, or it may
1728 * not. ocfs2_meta_lock_update definitely wants one in, but
1729 * may or may not read one, depending on what's in the
1730 * LVB. The result of all of this is that we've *only* gone to
1731 * disk if we have to, so the complexity is worthwhile. */
1732 status = ocfs2_meta_lock_update(inode, &local_bh);
1734 if (status != -ENOENT)
1740 status = ocfs2_assign_bh(inode, ret_bh, local_bh);
1748 status = ocfs2_handle_add_lock(handle, inode);
1755 if (ret_bh && (*ret_bh)) {
1760 ocfs2_meta_unlock(inode, ex);
1771 * This is working around a lock inversion between tasks acquiring DLM locks
1772 * while holding a page lock and the vote thread which blocks dlm lock acquiry
1773 * while acquiring page locks.
1775 * ** These _with_page variantes are only intended to be called from aop
1776 * methods that hold page locks and return a very specific *positive* error
1777 * code that aop methods pass up to the VFS -- test for errors with != 0. **
1779 * The DLM is called such that it returns -EAGAIN if it would have blocked
1780 * waiting for the vote thread. In that case we unlock our page so the vote
1781 * thread can make progress. Once we've done this we have to return
1782 * AOP_TRUNCATED_PAGE so the aop method that called us can bubble that back up
1783 * into the VFS who will then immediately retry the aop call.
1785 * We do a blocking lock and immediate unlock before returning, though, so that
1786 * the lock has a great chance of being cached on this node by the time the VFS
1787 * calls back to retry the aop. This has a potential to livelock as nodes
1788 * ping locks back and forth, but that's a risk we're willing to take to avoid
1789 * the lock inversion simply.
1791 int ocfs2_meta_lock_with_page(struct inode *inode,
1792 struct ocfs2_journal_handle *handle,
1793 struct buffer_head **ret_bh,
1799 ret = ocfs2_meta_lock_full(inode, handle, ret_bh, ex,
1800 OCFS2_LOCK_NONBLOCK);
1801 if (ret == -EAGAIN) {
1803 if (ocfs2_meta_lock(inode, handle, ret_bh, ex) == 0)
1804 ocfs2_meta_unlock(inode, ex);
1805 ret = AOP_TRUNCATED_PAGE;
1811 void ocfs2_meta_unlock(struct inode *inode,
1814 int level = ex ? LKM_EXMODE : LKM_PRMODE;
1815 struct ocfs2_lock_res *lockres = &OCFS2_I(inode)->ip_meta_lockres;
1819 mlog(0, "inode %llu drop %s META lock\n",
1820 (unsigned long long)OCFS2_I(inode)->ip_blkno,
1821 ex ? "EXMODE" : "PRMODE");
1823 if (!ocfs2_is_hard_readonly(OCFS2_SB(inode->i_sb)))
1824 ocfs2_cluster_unlock(OCFS2_SB(inode->i_sb), lockres, level);
1829 int ocfs2_super_lock(struct ocfs2_super *osb,
1833 int level = ex ? LKM_EXMODE : LKM_PRMODE;
1834 struct ocfs2_lock_res *lockres = &osb->osb_super_lockres;
1835 struct buffer_head *bh;
1836 struct ocfs2_slot_info *si = osb->slot_info;
1840 if (ocfs2_is_hard_readonly(osb))
1843 status = ocfs2_cluster_lock(osb, lockres, level, 0, 0);
1849 /* The super block lock path is really in the best position to
1850 * know when resources covered by the lock need to be
1851 * refreshed, so we do it here. Of course, making sense of
1852 * everything is up to the caller :) */
1853 status = ocfs2_should_refresh_lock_res(lockres);
1860 status = ocfs2_read_block(osb, bh->b_blocknr, &bh, 0,
1863 ocfs2_update_slot_info(si);
1865 ocfs2_complete_lock_res_refresh(lockres, status);
1875 void ocfs2_super_unlock(struct ocfs2_super *osb,
1878 int level = ex ? LKM_EXMODE : LKM_PRMODE;
1879 struct ocfs2_lock_res *lockres = &osb->osb_super_lockres;
1881 ocfs2_cluster_unlock(osb, lockres, level);
1884 int ocfs2_rename_lock(struct ocfs2_super *osb)
1887 struct ocfs2_lock_res *lockres = &osb->osb_rename_lockres;
1889 if (ocfs2_is_hard_readonly(osb))
1892 status = ocfs2_cluster_lock(osb, lockres, LKM_EXMODE, 0, 0);
1899 void ocfs2_rename_unlock(struct ocfs2_super *osb)
1901 struct ocfs2_lock_res *lockres = &osb->osb_rename_lockres;
1903 ocfs2_cluster_unlock(osb, lockres, LKM_EXMODE);
1906 int ocfs2_dentry_lock(struct dentry *dentry, int ex)
1909 int level = ex ? LKM_EXMODE : LKM_PRMODE;
1910 struct ocfs2_dentry_lock *dl = dentry->d_fsdata;
1911 struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb);
1915 if (ocfs2_is_hard_readonly(osb))
1918 ret = ocfs2_cluster_lock(osb, &dl->dl_lockres, level, 0, 0);
1925 void ocfs2_dentry_unlock(struct dentry *dentry, int ex)
1927 int level = ex ? LKM_EXMODE : LKM_PRMODE;
1928 struct ocfs2_dentry_lock *dl = dentry->d_fsdata;
1929 struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb);
1931 ocfs2_cluster_unlock(osb, &dl->dl_lockres, level);
1934 /* Reference counting of the dlm debug structure. We want this because
1935 * open references on the debug inodes can live on after a mount, so
1936 * we can't rely on the ocfs2_super to always exist. */
1937 static void ocfs2_dlm_debug_free(struct kref *kref)
1939 struct ocfs2_dlm_debug *dlm_debug;
1941 dlm_debug = container_of(kref, struct ocfs2_dlm_debug, d_refcnt);
1946 void ocfs2_put_dlm_debug(struct ocfs2_dlm_debug *dlm_debug)
1949 kref_put(&dlm_debug->d_refcnt, ocfs2_dlm_debug_free);
1952 static void ocfs2_get_dlm_debug(struct ocfs2_dlm_debug *debug)
1954 kref_get(&debug->d_refcnt);
1957 struct ocfs2_dlm_debug *ocfs2_new_dlm_debug(void)
1959 struct ocfs2_dlm_debug *dlm_debug;
1961 dlm_debug = kmalloc(sizeof(struct ocfs2_dlm_debug), GFP_KERNEL);
1963 mlog_errno(-ENOMEM);
1967 kref_init(&dlm_debug->d_refcnt);
1968 INIT_LIST_HEAD(&dlm_debug->d_lockres_tracking);
1969 dlm_debug->d_locking_state = NULL;
1974 /* Access to this is arbitrated for us via seq_file->sem. */
1975 struct ocfs2_dlm_seq_priv {
1976 struct ocfs2_dlm_debug *p_dlm_debug;
1977 struct ocfs2_lock_res p_iter_res;
1978 struct ocfs2_lock_res p_tmp_res;
1981 static struct ocfs2_lock_res *ocfs2_dlm_next_res(struct ocfs2_lock_res *start,
1982 struct ocfs2_dlm_seq_priv *priv)
1984 struct ocfs2_lock_res *iter, *ret = NULL;
1985 struct ocfs2_dlm_debug *dlm_debug = priv->p_dlm_debug;
1987 assert_spin_locked(&ocfs2_dlm_tracking_lock);
1989 list_for_each_entry(iter, &start->l_debug_list, l_debug_list) {
1990 /* discover the head of the list */
1991 if (&iter->l_debug_list == &dlm_debug->d_lockres_tracking) {
1992 mlog(0, "End of list found, %p\n", ret);
1996 /* We track our "dummy" iteration lockres' by a NULL
1998 if (iter->l_ops != NULL) {
2007 static void *ocfs2_dlm_seq_start(struct seq_file *m, loff_t *pos)
2009 struct ocfs2_dlm_seq_priv *priv = m->private;
2010 struct ocfs2_lock_res *iter;
2012 spin_lock(&ocfs2_dlm_tracking_lock);
2013 iter = ocfs2_dlm_next_res(&priv->p_iter_res, priv);
2015 /* Since lockres' have the lifetime of their container
2016 * (which can be inodes, ocfs2_supers, etc) we want to
2017 * copy this out to a temporary lockres while still
2018 * under the spinlock. Obviously after this we can't
2019 * trust any pointers on the copy returned, but that's
2020 * ok as the information we want isn't typically held
2022 priv->p_tmp_res = *iter;
2023 iter = &priv->p_tmp_res;
2025 spin_unlock(&ocfs2_dlm_tracking_lock);
2030 static void ocfs2_dlm_seq_stop(struct seq_file *m, void *v)
2034 static void *ocfs2_dlm_seq_next(struct seq_file *m, void *v, loff_t *pos)
2036 struct ocfs2_dlm_seq_priv *priv = m->private;
2037 struct ocfs2_lock_res *iter = v;
2038 struct ocfs2_lock_res *dummy = &priv->p_iter_res;
2040 spin_lock(&ocfs2_dlm_tracking_lock);
2041 iter = ocfs2_dlm_next_res(iter, priv);
2042 list_del_init(&dummy->l_debug_list);
2044 list_add(&dummy->l_debug_list, &iter->l_debug_list);
2045 priv->p_tmp_res = *iter;
2046 iter = &priv->p_tmp_res;
2048 spin_unlock(&ocfs2_dlm_tracking_lock);
2053 /* So that debugfs.ocfs2 can determine which format is being used */
2054 #define OCFS2_DLM_DEBUG_STR_VERSION 1
2055 static int ocfs2_dlm_seq_show(struct seq_file *m, void *v)
2059 struct ocfs2_lock_res *lockres = v;
2064 seq_printf(m, "0x%x\t", OCFS2_DLM_DEBUG_STR_VERSION);
2066 if (lockres->l_type == OCFS2_LOCK_TYPE_DENTRY)
2067 seq_printf(m, "%.*s%08x\t", OCFS2_DENTRY_LOCK_INO_START - 1,
2069 (unsigned int)ocfs2_get_dentry_lock_ino(lockres));
2071 seq_printf(m, "%.*s\t", OCFS2_LOCK_ID_MAX_LEN, lockres->l_name);
2073 seq_printf(m, "%d\t"
2084 lockres->l_unlock_action,
2085 lockres->l_ro_holders,
2086 lockres->l_ex_holders,
2087 lockres->l_requested,
2088 lockres->l_blocking);
2090 /* Dump the raw LVB */
2091 lvb = lockres->l_lksb.lvb;
2092 for(i = 0; i < DLM_LVB_LEN; i++)
2093 seq_printf(m, "0x%x\t", lvb[i]);
2096 seq_printf(m, "\n");
2100 static struct seq_operations ocfs2_dlm_seq_ops = {
2101 .start = ocfs2_dlm_seq_start,
2102 .stop = ocfs2_dlm_seq_stop,
2103 .next = ocfs2_dlm_seq_next,
2104 .show = ocfs2_dlm_seq_show,
2107 static int ocfs2_dlm_debug_release(struct inode *inode, struct file *file)
2109 struct seq_file *seq = (struct seq_file *) file->private_data;
2110 struct ocfs2_dlm_seq_priv *priv = seq->private;
2111 struct ocfs2_lock_res *res = &priv->p_iter_res;
2113 ocfs2_remove_lockres_tracking(res);
2114 ocfs2_put_dlm_debug(priv->p_dlm_debug);
2115 return seq_release_private(inode, file);
2118 static int ocfs2_dlm_debug_open(struct inode *inode, struct file *file)
2121 struct ocfs2_dlm_seq_priv *priv;
2122 struct seq_file *seq;
2123 struct ocfs2_super *osb;
2125 priv = kzalloc(sizeof(struct ocfs2_dlm_seq_priv), GFP_KERNEL);
2131 osb = (struct ocfs2_super *) inode->u.generic_ip;
2132 ocfs2_get_dlm_debug(osb->osb_dlm_debug);
2133 priv->p_dlm_debug = osb->osb_dlm_debug;
2134 INIT_LIST_HEAD(&priv->p_iter_res.l_debug_list);
2136 ret = seq_open(file, &ocfs2_dlm_seq_ops);
2143 seq = (struct seq_file *) file->private_data;
2144 seq->private = priv;
2146 ocfs2_add_lockres_tracking(&priv->p_iter_res,
2153 static const struct file_operations ocfs2_dlm_debug_fops = {
2154 .open = ocfs2_dlm_debug_open,
2155 .release = ocfs2_dlm_debug_release,
2157 .llseek = seq_lseek,
2160 static int ocfs2_dlm_init_debug(struct ocfs2_super *osb)
2163 struct ocfs2_dlm_debug *dlm_debug = osb->osb_dlm_debug;
2165 dlm_debug->d_locking_state = debugfs_create_file("locking_state",
2167 osb->osb_debug_root,
2169 &ocfs2_dlm_debug_fops);
2170 if (!dlm_debug->d_locking_state) {
2173 "Unable to create locking state debugfs file.\n");
2177 ocfs2_get_dlm_debug(dlm_debug);
2182 static void ocfs2_dlm_shutdown_debug(struct ocfs2_super *osb)
2184 struct ocfs2_dlm_debug *dlm_debug = osb->osb_dlm_debug;
2187 debugfs_remove(dlm_debug->d_locking_state);
2188 ocfs2_put_dlm_debug(dlm_debug);
2192 int ocfs2_dlm_init(struct ocfs2_super *osb)
2196 struct dlm_ctxt *dlm;
2200 status = ocfs2_dlm_init_debug(osb);
2206 /* launch vote thread */
2207 osb->vote_task = kthread_run(ocfs2_vote_thread, osb, "ocfs2vote");
2208 if (IS_ERR(osb->vote_task)) {
2209 status = PTR_ERR(osb->vote_task);
2210 osb->vote_task = NULL;
2215 /* used by the dlm code to make message headers unique, each
2216 * node in this domain must agree on this. */
2217 dlm_key = crc32_le(0, osb->uuid_str, strlen(osb->uuid_str));
2219 /* for now, uuid == domain */
2220 dlm = dlm_register_domain(osb->uuid_str, dlm_key);
2222 status = PTR_ERR(dlm);
2227 ocfs2_super_lock_res_init(&osb->osb_super_lockres, osb);
2228 ocfs2_rename_lock_res_init(&osb->osb_rename_lockres, osb);
2230 dlm_register_eviction_cb(dlm, &osb->osb_eviction_cb);
2237 ocfs2_dlm_shutdown_debug(osb);
2239 kthread_stop(osb->vote_task);
2246 void ocfs2_dlm_shutdown(struct ocfs2_super *osb)
2250 dlm_unregister_eviction_cb(&osb->osb_eviction_cb);
2252 ocfs2_drop_osb_locks(osb);
2254 if (osb->vote_task) {
2255 kthread_stop(osb->vote_task);
2256 osb->vote_task = NULL;
2259 ocfs2_lock_res_free(&osb->osb_super_lockres);
2260 ocfs2_lock_res_free(&osb->osb_rename_lockres);
2262 dlm_unregister_domain(osb->dlm);
2265 ocfs2_dlm_shutdown_debug(osb);
2270 static void ocfs2_unlock_ast_func(void *opaque, enum dlm_status status)
2272 struct ocfs2_lock_res *lockres = opaque;
2273 unsigned long flags;
2277 mlog(0, "UNLOCK AST called on lock %s, action = %d\n", lockres->l_name,
2278 lockres->l_unlock_action);
2280 spin_lock_irqsave(&lockres->l_lock, flags);
2281 /* We tried to cancel a convert request, but it was already
2282 * granted. All we want to do here is clear our unlock
2283 * state. The wake_up call done at the bottom is redundant
2284 * (ocfs2_prepare_cancel_convert doesn't sleep on this) but doesn't
2285 * hurt anything anyway */
2286 if (status == DLM_CANCELGRANT &&
2287 lockres->l_unlock_action == OCFS2_UNLOCK_CANCEL_CONVERT) {
2288 mlog(0, "Got cancelgrant for %s\n", lockres->l_name);
2290 /* We don't clear the busy flag in this case as it
2291 * should have been cleared by the ast which the dlm
2293 goto complete_unlock;
2296 if (status != DLM_NORMAL) {
2297 mlog(ML_ERROR, "Dlm passes status %d for lock %s, "
2298 "unlock_action %d\n", status, lockres->l_name,
2299 lockres->l_unlock_action);
2300 spin_unlock_irqrestore(&lockres->l_lock, flags);
2304 switch(lockres->l_unlock_action) {
2305 case OCFS2_UNLOCK_CANCEL_CONVERT:
2306 mlog(0, "Cancel convert success for %s\n", lockres->l_name);
2307 lockres->l_action = OCFS2_AST_INVALID;
2309 case OCFS2_UNLOCK_DROP_LOCK:
2310 lockres->l_level = LKM_IVMODE;
2316 lockres_clear_flags(lockres, OCFS2_LOCK_BUSY);
2318 lockres->l_unlock_action = OCFS2_UNLOCK_INVALID;
2319 spin_unlock_irqrestore(&lockres->l_lock, flags);
2321 wake_up(&lockres->l_event);
2326 typedef void (ocfs2_pre_drop_cb_t)(struct ocfs2_lock_res *, void *);
2328 struct drop_lock_cb {
2329 ocfs2_pre_drop_cb_t *drop_func;
2333 static int ocfs2_drop_lock(struct ocfs2_super *osb,
2334 struct ocfs2_lock_res *lockres,
2335 struct drop_lock_cb *dcb)
2337 enum dlm_status status;
2338 unsigned long flags;
2340 /* We didn't get anywhere near actually using this lockres. */
2341 if (!(lockres->l_flags & OCFS2_LOCK_INITIALIZED))
2344 spin_lock_irqsave(&lockres->l_lock, flags);
2346 mlog_bug_on_msg(!(lockres->l_flags & OCFS2_LOCK_FREEING),
2347 "lockres %s, flags 0x%lx\n",
2348 lockres->l_name, lockres->l_flags);
2350 while (lockres->l_flags & OCFS2_LOCK_BUSY) {
2351 mlog(0, "waiting on busy lock \"%s\": flags = %lx, action = "
2352 "%u, unlock_action = %u\n",
2353 lockres->l_name, lockres->l_flags, lockres->l_action,
2354 lockres->l_unlock_action);
2356 spin_unlock_irqrestore(&lockres->l_lock, flags);
2358 /* XXX: Today we just wait on any busy
2359 * locks... Perhaps we need to cancel converts in the
2361 ocfs2_wait_on_busy_lock(lockres);
2363 spin_lock_irqsave(&lockres->l_lock, flags);
2367 dcb->drop_func(lockres, dcb->drop_data);
2369 if (lockres->l_flags & OCFS2_LOCK_BUSY)
2370 mlog(ML_ERROR, "destroying busy lock: \"%s\"\n",
2372 if (lockres->l_flags & OCFS2_LOCK_BLOCKED)
2373 mlog(0, "destroying blocked lock: \"%s\"\n", lockres->l_name);
2375 if (!(lockres->l_flags & OCFS2_LOCK_ATTACHED)) {
2376 spin_unlock_irqrestore(&lockres->l_lock, flags);
2380 lockres_clear_flags(lockres, OCFS2_LOCK_ATTACHED);
2382 /* make sure we never get here while waiting for an ast to
2384 BUG_ON(lockres->l_action != OCFS2_AST_INVALID);
2386 /* is this necessary? */
2387 lockres_or_flags(lockres, OCFS2_LOCK_BUSY);
2388 lockres->l_unlock_action = OCFS2_UNLOCK_DROP_LOCK;
2389 spin_unlock_irqrestore(&lockres->l_lock, flags);
2391 mlog(0, "lock %s\n", lockres->l_name);
2393 status = dlmunlock(osb->dlm, &lockres->l_lksb, LKM_VALBLK,
2394 lockres->l_ops->unlock_ast, lockres);
2395 if (status != DLM_NORMAL) {
2396 ocfs2_log_dlm_error("dlmunlock", status, lockres);
2397 mlog(ML_ERROR, "lockres flags: %lu\n", lockres->l_flags);
2398 dlm_print_one_lock(lockres->l_lksb.lockid);
2401 mlog(0, "lock %s, successfull return from dlmunlock\n",
2404 ocfs2_wait_on_busy_lock(lockres);
2410 /* Mark the lockres as being dropped. It will no longer be
2411 * queued if blocking, but we still may have to wait on it
2412 * being dequeued from the vote thread before we can consider
2415 * You can *not* attempt to call cluster_lock on this lockres anymore. */
2416 void ocfs2_mark_lockres_freeing(struct ocfs2_lock_res *lockres)
2419 struct ocfs2_mask_waiter mw;
2420 unsigned long flags;
2422 ocfs2_init_mask_waiter(&mw);
2424 spin_lock_irqsave(&lockres->l_lock, flags);
2425 lockres->l_flags |= OCFS2_LOCK_FREEING;
2426 while (lockres->l_flags & OCFS2_LOCK_QUEUED) {
2427 lockres_add_mask_waiter(lockres, &mw, OCFS2_LOCK_QUEUED, 0);
2428 spin_unlock_irqrestore(&lockres->l_lock, flags);
2430 mlog(0, "Waiting on lockres %s\n", lockres->l_name);
2432 status = ocfs2_wait_for_mask(&mw);
2436 spin_lock_irqsave(&lockres->l_lock, flags);
2438 spin_unlock_irqrestore(&lockres->l_lock, flags);
2441 void ocfs2_simple_drop_lockres(struct ocfs2_super *osb,
2442 struct ocfs2_lock_res *lockres)
2446 ocfs2_mark_lockres_freeing(lockres);
2447 ret = ocfs2_drop_lock(osb, lockres, NULL);
2452 static void ocfs2_drop_osb_locks(struct ocfs2_super *osb)
2454 ocfs2_simple_drop_lockres(osb, &osb->osb_super_lockres);
2455 ocfs2_simple_drop_lockres(osb, &osb->osb_rename_lockres);
2458 static void ocfs2_meta_pre_drop(struct ocfs2_lock_res *lockres, void *data)
2460 struct inode *inode = data;
2462 /* the metadata lock requires a bit more work as we have an
2463 * LVB to worry about. */
2464 if (lockres->l_flags & OCFS2_LOCK_ATTACHED &&
2465 lockres->l_level == LKM_EXMODE &&
2466 !(lockres->l_flags & OCFS2_LOCK_NEEDS_REFRESH))
2467 __ocfs2_stuff_meta_lvb(inode);
2470 int ocfs2_drop_inode_locks(struct inode *inode)
2473 struct drop_lock_cb meta_dcb = { ocfs2_meta_pre_drop, inode, };
2477 /* No need to call ocfs2_mark_lockres_freeing here -
2478 * ocfs2_clear_inode has done it for us. */
2480 err = ocfs2_drop_lock(OCFS2_SB(inode->i_sb),
2481 &OCFS2_I(inode)->ip_data_lockres,
2488 err = ocfs2_drop_lock(OCFS2_SB(inode->i_sb),
2489 &OCFS2_I(inode)->ip_meta_lockres,
2493 if (err < 0 && !status)
2496 err = ocfs2_drop_lock(OCFS2_SB(inode->i_sb),
2497 &OCFS2_I(inode)->ip_rw_lockres,
2501 if (err < 0 && !status)
2508 static void ocfs2_prepare_downconvert(struct ocfs2_lock_res *lockres,
2511 assert_spin_locked(&lockres->l_lock);
2513 BUG_ON(lockres->l_blocking <= LKM_NLMODE);
2515 if (lockres->l_level <= new_level) {
2516 mlog(ML_ERROR, "lockres->l_level (%u) <= new_level (%u)\n",
2517 lockres->l_level, new_level);
2521 mlog(0, "lock %s, new_level = %d, l_blocking = %d\n",
2522 lockres->l_name, new_level, lockres->l_blocking);
2524 lockres->l_action = OCFS2_AST_DOWNCONVERT;
2525 lockres->l_requested = new_level;
2526 lockres_or_flags(lockres, OCFS2_LOCK_BUSY);
2529 static int ocfs2_downconvert_lock(struct ocfs2_super *osb,
2530 struct ocfs2_lock_res *lockres,
2534 int ret, dlm_flags = LKM_CONVERT;
2535 enum dlm_status status;
2540 dlm_flags |= LKM_VALBLK;
2542 status = dlmlock(osb->dlm,
2547 OCFS2_LOCK_ID_MAX_LEN - 1,
2548 lockres->l_ops->ast,
2550 lockres->l_ops->bast);
2551 if (status != DLM_NORMAL) {
2552 ocfs2_log_dlm_error("dlmlock", status, lockres);
2554 ocfs2_recover_from_dlm_error(lockres, 1);
2564 /* returns 1 when the caller should unlock and call dlmunlock */
2565 static int ocfs2_prepare_cancel_convert(struct ocfs2_super *osb,
2566 struct ocfs2_lock_res *lockres)
2568 assert_spin_locked(&lockres->l_lock);
2571 mlog(0, "lock %s\n", lockres->l_name);
2573 if (lockres->l_unlock_action == OCFS2_UNLOCK_CANCEL_CONVERT) {
2574 /* If we're already trying to cancel a lock conversion
2575 * then just drop the spinlock and allow the caller to
2576 * requeue this lock. */
2578 mlog(0, "Lockres %s, skip convert\n", lockres->l_name);
2582 /* were we in a convert when we got the bast fire? */
2583 BUG_ON(lockres->l_action != OCFS2_AST_CONVERT &&
2584 lockres->l_action != OCFS2_AST_DOWNCONVERT);
2585 /* set things up for the unlockast to know to just
2586 * clear out the ast_action and unset busy, etc. */
2587 lockres->l_unlock_action = OCFS2_UNLOCK_CANCEL_CONVERT;
2589 mlog_bug_on_msg(!(lockres->l_flags & OCFS2_LOCK_BUSY),
2590 "lock %s, invalid flags: 0x%lx\n",
2591 lockres->l_name, lockres->l_flags);
2596 static int ocfs2_cancel_convert(struct ocfs2_super *osb,
2597 struct ocfs2_lock_res *lockres)
2600 enum dlm_status status;
2603 mlog(0, "lock %s\n", lockres->l_name);
2606 status = dlmunlock(osb->dlm,
2609 lockres->l_ops->unlock_ast,
2611 if (status != DLM_NORMAL) {
2612 ocfs2_log_dlm_error("dlmunlock", status, lockres);
2614 ocfs2_recover_from_dlm_error(lockres, 0);
2617 mlog(0, "lock %s return from dlmunlock\n", lockres->l_name);
2623 static inline int ocfs2_can_downconvert_meta_lock(struct inode *inode,
2624 struct ocfs2_lock_res *lockres,
2631 BUG_ON(new_level != LKM_NLMODE && new_level != LKM_PRMODE);
2633 if (lockres->l_flags & OCFS2_LOCK_REFRESHING) {
2635 mlog(0, "lockres %s currently being refreshed -- backing "
2636 "off!\n", lockres->l_name);
2637 } else if (new_level == LKM_PRMODE)
2638 ret = !lockres->l_ex_holders &&
2639 ocfs2_inode_fully_checkpointed(inode);
2640 else /* Must be NLMODE we're converting to. */
2641 ret = !lockres->l_ro_holders && !lockres->l_ex_holders &&
2642 ocfs2_inode_fully_checkpointed(inode);
2648 static int ocfs2_do_unblock_meta(struct inode *inode,
2654 struct ocfs2_lock_res *lockres = &OCFS2_I(inode)->ip_meta_lockres;
2655 unsigned long flags;
2657 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
2661 spin_lock_irqsave(&lockres->l_lock, flags);
2663 BUG_ON(!(lockres->l_flags & OCFS2_LOCK_BLOCKED));
2665 mlog(0, "l_level=%d, l_blocking=%d\n", lockres->l_level,
2666 lockres->l_blocking);
2668 BUG_ON(lockres->l_level != LKM_EXMODE &&
2669 lockres->l_level != LKM_PRMODE);
2671 if (lockres->l_flags & OCFS2_LOCK_BUSY) {
2673 ret = ocfs2_prepare_cancel_convert(osb, lockres);
2674 spin_unlock_irqrestore(&lockres->l_lock, flags);
2676 ret = ocfs2_cancel_convert(osb, lockres);
2683 new_level = ocfs2_highest_compat_lock_level(lockres->l_blocking);
2685 mlog(0, "l_level=%d, l_blocking=%d, new_level=%d\n",
2686 lockres->l_level, lockres->l_blocking, new_level);
2688 if (ocfs2_can_downconvert_meta_lock(inode, lockres, new_level)) {
2689 if (lockres->l_level == LKM_EXMODE)
2692 /* If the lock hasn't been refreshed yet (rare), then
2693 * our memory inode values are old and we skip
2694 * stuffing the lvb. There's no need to actually clear
2695 * out the lvb here as it's value is still valid. */
2696 if (!(lockres->l_flags & OCFS2_LOCK_NEEDS_REFRESH)) {
2698 __ocfs2_stuff_meta_lvb(inode);
2700 mlog(0, "lockres %s: downconverting stale lock!\n",
2703 mlog(0, "calling ocfs2_downconvert_lock with l_level=%d, "
2704 "l_blocking=%d, new_level=%d\n",
2705 lockres->l_level, lockres->l_blocking, new_level);
2707 ocfs2_prepare_downconvert(lockres, new_level);
2708 spin_unlock_irqrestore(&lockres->l_lock, flags);
2709 ret = ocfs2_downconvert_lock(osb, lockres, new_level, set_lvb);
2712 if (!ocfs2_inode_fully_checkpointed(inode))
2713 ocfs2_start_checkpoint(osb);
2716 spin_unlock_irqrestore(&lockres->l_lock, flags);
2723 static int ocfs2_generic_unblock_lock(struct ocfs2_super *osb,
2724 struct ocfs2_lock_res *lockres,
2725 struct ocfs2_unblock_ctl *ctl,
2726 ocfs2_convert_worker_t *worker)
2728 unsigned long flags;
2735 spin_lock_irqsave(&lockres->l_lock, flags);
2737 BUG_ON(!(lockres->l_flags & OCFS2_LOCK_BLOCKED));
2740 if (lockres->l_flags & OCFS2_LOCK_BUSY) {
2742 ret = ocfs2_prepare_cancel_convert(osb, lockres);
2743 spin_unlock_irqrestore(&lockres->l_lock, flags);
2745 ret = ocfs2_cancel_convert(osb, lockres);
2752 /* if we're blocking an exclusive and we have *any* holders,
2754 if ((lockres->l_blocking == LKM_EXMODE)
2755 && (lockres->l_ex_holders || lockres->l_ro_holders)) {
2756 spin_unlock_irqrestore(&lockres->l_lock, flags);
2762 /* If it's a PR we're blocking, then only
2763 * requeue if we've got any EX holders */
2764 if (lockres->l_blocking == LKM_PRMODE &&
2765 lockres->l_ex_holders) {
2766 spin_unlock_irqrestore(&lockres->l_lock, flags);
2772 /* If we get here, then we know that there are no more
2773 * incompatible holders (and anyone asking for an incompatible
2774 * lock is blocked). We can now downconvert the lock */
2778 /* Some lockres types want to do a bit of work before
2779 * downconverting a lock. Allow that here. The worker function
2780 * may sleep, so we save off a copy of what we're blocking as
2781 * it may change while we're not holding the spin lock. */
2782 blocking = lockres->l_blocking;
2783 spin_unlock_irqrestore(&lockres->l_lock, flags);
2785 ctl->unblock_action = worker(lockres, blocking);
2787 if (ctl->unblock_action == UNBLOCK_STOP_POST)
2790 spin_lock_irqsave(&lockres->l_lock, flags);
2791 if (blocking != lockres->l_blocking) {
2792 /* If this changed underneath us, then we can't drop
2799 new_level = ocfs2_highest_compat_lock_level(lockres->l_blocking);
2801 ocfs2_prepare_downconvert(lockres, new_level);
2802 spin_unlock_irqrestore(&lockres->l_lock, flags);
2803 ret = ocfs2_downconvert_lock(osb, lockres, new_level, 0);
2809 static int ocfs2_data_convert_worker(struct ocfs2_lock_res *lockres,
2812 struct inode *inode;
2813 struct address_space *mapping;
2815 inode = ocfs2_lock_res_inode(lockres);
2816 mapping = inode->i_mapping;
2818 if (filemap_fdatawrite(mapping)) {
2819 mlog(ML_ERROR, "Could not sync inode %llu for downconvert!",
2820 (unsigned long long)OCFS2_I(inode)->ip_blkno);
2822 sync_mapping_buffers(mapping);
2823 if (blocking == LKM_EXMODE) {
2824 truncate_inode_pages(mapping, 0);
2825 unmap_mapping_range(mapping, 0, 0, 0);
2827 /* We only need to wait on the I/O if we're not also
2828 * truncating pages because truncate_inode_pages waits
2829 * for us above. We don't truncate pages if we're
2830 * blocking anything < EXMODE because we want to keep
2831 * them around in that case. */
2832 filemap_fdatawait(mapping);
2835 return UNBLOCK_CONTINUE;
2838 int ocfs2_unblock_data(struct ocfs2_lock_res *lockres,
2839 struct ocfs2_unblock_ctl *ctl)
2842 struct inode *inode;
2843 struct ocfs2_super *osb;
2847 inode = ocfs2_lock_res_inode(lockres);
2848 osb = OCFS2_SB(inode->i_sb);
2850 mlog(0, "unblock inode %llu\n",
2851 (unsigned long long)OCFS2_I(inode)->ip_blkno);
2853 status = ocfs2_generic_unblock_lock(osb, lockres, ctl,
2854 ocfs2_data_convert_worker);
2858 mlog(0, "inode %llu, requeue = %d\n",
2859 (unsigned long long)OCFS2_I(inode)->ip_blkno, ctl->requeue);
2865 static int ocfs2_unblock_inode_lock(struct ocfs2_lock_res *lockres,
2866 struct ocfs2_unblock_ctl *ctl)
2869 struct inode *inode;
2873 mlog(0, "Unblock lockres %s\n", lockres->l_name);
2875 inode = ocfs2_lock_res_inode(lockres);
2877 status = ocfs2_generic_unblock_lock(OCFS2_SB(inode->i_sb),
2878 lockres, ctl, NULL);
2886 static int ocfs2_unblock_meta(struct ocfs2_lock_res *lockres,
2887 struct ocfs2_unblock_ctl *ctl)
2890 struct inode *inode;
2894 inode = ocfs2_lock_res_inode(lockres);
2896 mlog(0, "unblock inode %llu\n",
2897 (unsigned long long)OCFS2_I(inode)->ip_blkno);
2899 status = ocfs2_do_unblock_meta(inode, &ctl->requeue);
2903 mlog(0, "inode %llu, requeue = %d\n",
2904 (unsigned long long)OCFS2_I(inode)->ip_blkno, ctl->requeue);
2911 * Does the final reference drop on our dentry lock. Right now this
2912 * happens in the vote thread, but we could choose to simplify the
2913 * dlmglue API and push these off to the ocfs2_wq in the future.
2915 static void ocfs2_dentry_post_unlock(struct ocfs2_super *osb,
2916 struct ocfs2_lock_res *lockres)
2918 struct ocfs2_dentry_lock *dl = ocfs2_lock_res_dl(lockres);
2919 ocfs2_dentry_lock_put(osb, dl);
2923 * d_delete() matching dentries before the lock downconvert.
2925 * At this point, any process waiting to destroy the
2926 * dentry_lock due to last ref count is stopped by the
2927 * OCFS2_LOCK_QUEUED flag.
2929 * We have two potential problems
2931 * 1) If we do the last reference drop on our dentry_lock (via dput)
2932 * we'll wind up in ocfs2_release_dentry_lock(), waiting on
2933 * the downconvert to finish. Instead we take an elevated
2934 * reference and push the drop until after we've completed our
2935 * unblock processing.
2937 * 2) There might be another process with a final reference,
2938 * waiting on us to finish processing. If this is the case, we
2939 * detect it and exit out - there's no more dentries anyway.
2941 static int ocfs2_dentry_convert_worker(struct ocfs2_lock_res *lockres,
2944 struct ocfs2_dentry_lock *dl = ocfs2_lock_res_dl(lockres);
2945 struct ocfs2_inode_info *oi = OCFS2_I(dl->dl_inode);
2946 struct dentry *dentry;
2947 unsigned long flags;
2951 * This node is blocking another node from getting a read
2952 * lock. This happens when we've renamed within a
2953 * directory. We've forced the other nodes to d_delete(), but
2954 * we never actually dropped our lock because it's still
2955 * valid. The downconvert code will retain a PR for this node,
2956 * so there's no further work to do.
2958 if (blocking == LKM_PRMODE)
2959 return UNBLOCK_CONTINUE;
2962 * Mark this inode as potentially orphaned. The code in
2963 * ocfs2_delete_inode() will figure out whether it actually
2964 * needs to be freed or not.
2966 spin_lock(&oi->ip_lock);
2967 oi->ip_flags |= OCFS2_INODE_MAYBE_ORPHANED;
2968 spin_unlock(&oi->ip_lock);
2971 * Yuck. We need to make sure however that the check of
2972 * OCFS2_LOCK_FREEING and the extra reference are atomic with
2973 * respect to a reference decrement or the setting of that
2976 spin_lock_irqsave(&lockres->l_lock, flags);
2977 spin_lock(&dentry_attach_lock);
2978 if (!(lockres->l_flags & OCFS2_LOCK_FREEING)
2983 spin_unlock(&dentry_attach_lock);
2984 spin_unlock_irqrestore(&lockres->l_lock, flags);
2986 mlog(0, "extra_ref = %d\n", extra_ref);
2989 * We have a process waiting on us in ocfs2_dentry_iput(),
2990 * which means we can't have any more outstanding
2991 * aliases. There's no need to do any more work.
2994 return UNBLOCK_CONTINUE;
2996 spin_lock(&dentry_attach_lock);
2998 dentry = ocfs2_find_local_alias(dl->dl_inode,
2999 dl->dl_parent_blkno, 1);
3002 spin_unlock(&dentry_attach_lock);
3004 mlog(0, "d_delete(%.*s);\n", dentry->d_name.len,
3005 dentry->d_name.name);
3008 * The following dcache calls may do an
3009 * iput(). Normally we don't want that from the
3010 * downconverting thread, but in this case it's ok
3011 * because the requesting node already has an
3012 * exclusive lock on the inode, so it can't be queued
3013 * for a downconvert.
3018 spin_lock(&dentry_attach_lock);
3020 spin_unlock(&dentry_attach_lock);
3023 * If we are the last holder of this dentry lock, there is no
3024 * reason to downconvert so skip straight to the unlock.
3026 if (dl->dl_count == 1)
3027 return UNBLOCK_STOP_POST;
3029 return UNBLOCK_CONTINUE_POST;
3032 static int ocfs2_unblock_dentry_lock(struct ocfs2_lock_res *lockres,
3033 struct ocfs2_unblock_ctl *ctl)
3036 struct ocfs2_dentry_lock *dl = ocfs2_lock_res_dl(lockres);
3037 struct ocfs2_super *osb = OCFS2_SB(dl->dl_inode->i_sb);
3039 mlog(0, "unblock dentry lock: %llu\n",
3040 (unsigned long long)OCFS2_I(dl->dl_inode)->ip_blkno);
3042 ret = ocfs2_generic_unblock_lock(osb,
3045 ocfs2_dentry_convert_worker);
3049 mlog(0, "requeue = %d, post = %d\n", ctl->requeue, ctl->unblock_action);
3054 /* Generic unblock function for any lockres whose private data is an
3055 * ocfs2_super pointer. */
3056 static int ocfs2_unblock_osb_lock(struct ocfs2_lock_res *lockres,
3057 struct ocfs2_unblock_ctl *ctl)
3060 struct ocfs2_super *osb;
3064 mlog(0, "Unblock lockres %s\n", lockres->l_name);
3066 osb = ocfs2_lock_res_super(lockres);
3068 status = ocfs2_generic_unblock_lock(osb,
3079 void ocfs2_process_blocked_lock(struct ocfs2_super *osb,
3080 struct ocfs2_lock_res *lockres)
3083 struct ocfs2_unblock_ctl ctl = {0, 0,};
3084 unsigned long flags;
3086 /* Our reference to the lockres in this function can be
3087 * considered valid until we remove the OCFS2_LOCK_QUEUED
3093 BUG_ON(!lockres->l_ops);
3094 BUG_ON(!lockres->l_ops->unblock);
3096 mlog(0, "lockres %s blocked.\n", lockres->l_name);
3098 /* Detect whether a lock has been marked as going away while
3099 * the vote thread was processing other things. A lock can
3100 * still be marked with OCFS2_LOCK_FREEING after this check,
3101 * but short circuiting here will still save us some
3103 spin_lock_irqsave(&lockres->l_lock, flags);
3104 if (lockres->l_flags & OCFS2_LOCK_FREEING)
3106 spin_unlock_irqrestore(&lockres->l_lock, flags);
3108 status = lockres->l_ops->unblock(lockres, &ctl);
3112 spin_lock_irqsave(&lockres->l_lock, flags);
3114 if (lockres->l_flags & OCFS2_LOCK_FREEING || !ctl.requeue) {
3115 lockres_clear_flags(lockres, OCFS2_LOCK_QUEUED);
3117 ocfs2_schedule_blocked_lock(osb, lockres);
3119 mlog(0, "lockres %s, requeue = %s.\n", lockres->l_name,
3120 ctl.requeue ? "yes" : "no");
3121 spin_unlock_irqrestore(&lockres->l_lock, flags);
3123 if (ctl.unblock_action != UNBLOCK_CONTINUE
3124 && lockres->l_ops->post_unlock)
3125 lockres->l_ops->post_unlock(osb, lockres);
3130 static void ocfs2_schedule_blocked_lock(struct ocfs2_super *osb,
3131 struct ocfs2_lock_res *lockres)
3135 assert_spin_locked(&lockres->l_lock);
3137 if (lockres->l_flags & OCFS2_LOCK_FREEING) {
3138 /* Do not schedule a lock for downconvert when it's on
3139 * the way to destruction - any nodes wanting access
3140 * to the resource will get it soon. */
3141 mlog(0, "Lockres %s won't be scheduled: flags 0x%lx\n",
3142 lockres->l_name, lockres->l_flags);
3146 lockres_or_flags(lockres, OCFS2_LOCK_QUEUED);
3148 spin_lock(&osb->vote_task_lock);
3149 if (list_empty(&lockres->l_blocked_list)) {
3150 list_add_tail(&lockres->l_blocked_list,
3151 &osb->blocked_lock_list);
3152 osb->blocked_lock_count++;
3154 spin_unlock(&osb->vote_task_lock);
3159 /* This aids in debugging situations where a bad LVB might be involved. */
3160 void ocfs2_dump_meta_lvb_info(u64 level,
3161 const char *function,
3163 struct ocfs2_lock_res *lockres)
3165 struct ocfs2_meta_lvb *lvb = (struct ocfs2_meta_lvb *) lockres->l_lksb.lvb;
3167 mlog(level, "LVB information for %s (called from %s:%u):\n",
3168 lockres->l_name, function, line);
3169 mlog(level, "version: %u, clusters: %u\n",
3170 lvb->lvb_version, be32_to_cpu(lvb->lvb_iclusters));
3171 mlog(level, "size: %llu, uid %u, gid %u, mode 0x%x\n",
3172 (unsigned long long)be64_to_cpu(lvb->lvb_isize),
3173 be32_to_cpu(lvb->lvb_iuid), be32_to_cpu(lvb->lvb_igid),
3174 be16_to_cpu(lvb->lvb_imode));
3175 mlog(level, "nlink %u, atime_packed 0x%llx, ctime_packed 0x%llx, "
3176 "mtime_packed 0x%llx iattr 0x%x\n", be16_to_cpu(lvb->lvb_inlink),
3177 (long long)be64_to_cpu(lvb->lvb_iatime_packed),
3178 (long long)be64_to_cpu(lvb->lvb_ictime_packed),
3179 (long long)be64_to_cpu(lvb->lvb_imtime_packed),
3180 be32_to_cpu(lvb->lvb_iattr));