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/crc32.h>
31 #include <linux/kthread.h>
32 #include <linux/pagemap.h>
33 #include <linux/debugfs.h>
34 #include <linux/seq_file.h>
36 #include <cluster/heartbeat.h>
37 #include <cluster/nodemanager.h>
38 #include <cluster/tcp.h>
40 #include <dlm/dlmapi.h>
42 #define MLOG_MASK_PREFIX ML_DLM_GLUE
43 #include <cluster/masklog.h>
50 #include "extent_map.h"
52 #include "heartbeat.h"
59 #include "buffer_head_io.h"
61 struct ocfs2_mask_waiter {
62 struct list_head mw_item;
64 struct completion mw_complete;
65 unsigned long mw_mask;
66 unsigned long mw_goal;
69 static struct ocfs2_super *ocfs2_get_dentry_osb(struct ocfs2_lock_res *lockres);
70 static struct ocfs2_super *ocfs2_get_inode_osb(struct ocfs2_lock_res *lockres);
73 * Return value from ->downconvert_worker functions.
75 * These control the precise actions of ocfs2_unblock_lock()
76 * and ocfs2_process_blocked_lock()
79 enum ocfs2_unblock_action {
80 UNBLOCK_CONTINUE = 0, /* Continue downconvert */
81 UNBLOCK_CONTINUE_POST = 1, /* Continue downconvert, fire
82 * ->post_unlock callback */
83 UNBLOCK_STOP_POST = 2, /* Do not downconvert, fire
84 * ->post_unlock() callback. */
87 struct ocfs2_unblock_ctl {
89 enum ocfs2_unblock_action unblock_action;
92 static int ocfs2_check_meta_downconvert(struct ocfs2_lock_res *lockres,
94 static void ocfs2_set_meta_lvb(struct ocfs2_lock_res *lockres);
96 static int ocfs2_data_convert_worker(struct ocfs2_lock_res *lockres,
99 static int ocfs2_dentry_convert_worker(struct ocfs2_lock_res *lockres,
102 static void ocfs2_dentry_post_unlock(struct ocfs2_super *osb,
103 struct ocfs2_lock_res *lockres);
106 #define mlog_meta_lvb(__level, __lockres) ocfs2_dump_meta_lvb_info(__level, __PRETTY_FUNCTION__, __LINE__, __lockres)
108 /* This aids in debugging situations where a bad LVB might be involved. */
109 static void ocfs2_dump_meta_lvb_info(u64 level,
110 const char *function,
112 struct ocfs2_lock_res *lockres)
114 struct ocfs2_meta_lvb *lvb = (struct ocfs2_meta_lvb *) lockres->l_lksb.lvb;
116 mlog(level, "LVB information for %s (called from %s:%u):\n",
117 lockres->l_name, function, line);
118 mlog(level, "version: %u, clusters: %u, generation: 0x%x\n",
119 lvb->lvb_version, be32_to_cpu(lvb->lvb_iclusters),
120 be32_to_cpu(lvb->lvb_igeneration));
121 mlog(level, "size: %llu, uid %u, gid %u, mode 0x%x\n",
122 (unsigned long long)be64_to_cpu(lvb->lvb_isize),
123 be32_to_cpu(lvb->lvb_iuid), be32_to_cpu(lvb->lvb_igid),
124 be16_to_cpu(lvb->lvb_imode));
125 mlog(level, "nlink %u, atime_packed 0x%llx, ctime_packed 0x%llx, "
126 "mtime_packed 0x%llx iattr 0x%x\n", be16_to_cpu(lvb->lvb_inlink),
127 (long long)be64_to_cpu(lvb->lvb_iatime_packed),
128 (long long)be64_to_cpu(lvb->lvb_ictime_packed),
129 (long long)be64_to_cpu(lvb->lvb_imtime_packed),
130 be32_to_cpu(lvb->lvb_iattr));
135 * OCFS2 Lock Resource Operations
137 * These fine tune the behavior of the generic dlmglue locking infrastructure.
139 * The most basic of lock types can point ->l_priv to their respective
140 * struct ocfs2_super and allow the default actions to manage things.
142 * Right now, each lock type also needs to implement an init function,
143 * and trivial lock/unlock wrappers. ocfs2_simple_drop_lockres()
144 * should be called when the lock is no longer needed (i.e., object
147 struct ocfs2_lock_res_ops {
149 * Translate an ocfs2_lock_res * into an ocfs2_super *. Define
150 * this callback if ->l_priv is not an ocfs2_super pointer
152 struct ocfs2_super * (*get_osb)(struct ocfs2_lock_res *);
155 * Optionally called in the downconvert thread after a
156 * successful downconvert. The lockres will not be referenced
157 * after this callback is called, so it is safe to free
160 * The exact semantics of when this is called are controlled
161 * by ->downconvert_worker()
163 void (*post_unlock)(struct ocfs2_super *, struct ocfs2_lock_res *);
166 * Allow a lock type to add checks to determine whether it is
167 * safe to downconvert a lock. Return 0 to re-queue the
168 * downconvert at a later time, nonzero to continue.
170 * For most locks, the default checks that there are no
171 * incompatible holders are sufficient.
173 * Called with the lockres spinlock held.
175 int (*check_downconvert)(struct ocfs2_lock_res *, int);
178 * Allows a lock type to populate the lock value block. This
179 * is called on downconvert, and when we drop a lock.
181 * Locks that want to use this should set LOCK_TYPE_USES_LVB
182 * in the flags field.
184 * Called with the lockres spinlock held.
186 void (*set_lvb)(struct ocfs2_lock_res *);
189 * Called from the downconvert thread when it is determined
190 * that a lock will be downconverted. This is called without
191 * any locks held so the function can do work that might
192 * schedule (syncing out data, etc).
194 * This should return any one of the ocfs2_unblock_action
195 * values, depending on what it wants the thread to do.
197 int (*downconvert_worker)(struct ocfs2_lock_res *, int);
200 * LOCK_TYPE_* flags which describe the specific requirements
201 * of a lock type. Descriptions of each individual flag follow.
207 * Some locks want to "refresh" potentially stale data when a
208 * meaningful (PRMODE or EXMODE) lock level is first obtained. If this
209 * flag is set, the OCFS2_LOCK_NEEDS_REFRESH flag will be set on the
210 * individual lockres l_flags member from the ast function. It is
211 * expected that the locking wrapper will clear the
212 * OCFS2_LOCK_NEEDS_REFRESH flag when done.
214 #define LOCK_TYPE_REQUIRES_REFRESH 0x1
217 * Indicate that a lock type makes use of the lock value block. The
218 * ->set_lvb lock type callback must be defined.
220 #define LOCK_TYPE_USES_LVB 0x2
222 static struct ocfs2_lock_res_ops ocfs2_inode_rw_lops = {
223 .get_osb = ocfs2_get_inode_osb,
227 static struct ocfs2_lock_res_ops ocfs2_inode_meta_lops = {
228 .get_osb = ocfs2_get_inode_osb,
229 .check_downconvert = ocfs2_check_meta_downconvert,
230 .set_lvb = ocfs2_set_meta_lvb,
231 .downconvert_worker = ocfs2_data_convert_worker,
232 .flags = LOCK_TYPE_REQUIRES_REFRESH|LOCK_TYPE_USES_LVB,
235 static struct ocfs2_lock_res_ops ocfs2_inode_data_lops = {
236 .get_osb = ocfs2_get_inode_osb,
237 .downconvert_worker = ocfs2_data_convert_worker,
241 static struct ocfs2_lock_res_ops ocfs2_super_lops = {
242 .flags = LOCK_TYPE_REQUIRES_REFRESH,
245 static struct ocfs2_lock_res_ops ocfs2_rename_lops = {
249 static struct ocfs2_lock_res_ops ocfs2_dentry_lops = {
250 .get_osb = ocfs2_get_dentry_osb,
251 .post_unlock = ocfs2_dentry_post_unlock,
252 .downconvert_worker = ocfs2_dentry_convert_worker,
256 static struct ocfs2_lock_res_ops ocfs2_inode_open_lops = {
257 .get_osb = ocfs2_get_inode_osb,
261 static inline int ocfs2_is_inode_lock(struct ocfs2_lock_res *lockres)
263 return lockres->l_type == OCFS2_LOCK_TYPE_META ||
264 lockres->l_type == OCFS2_LOCK_TYPE_DATA ||
265 lockres->l_type == OCFS2_LOCK_TYPE_RW ||
266 lockres->l_type == OCFS2_LOCK_TYPE_OPEN;
269 static inline struct inode *ocfs2_lock_res_inode(struct ocfs2_lock_res *lockres)
271 BUG_ON(!ocfs2_is_inode_lock(lockres));
273 return (struct inode *) lockres->l_priv;
276 static inline struct ocfs2_dentry_lock *ocfs2_lock_res_dl(struct ocfs2_lock_res *lockres)
278 BUG_ON(lockres->l_type != OCFS2_LOCK_TYPE_DENTRY);
280 return (struct ocfs2_dentry_lock *)lockres->l_priv;
283 static inline struct ocfs2_super *ocfs2_get_lockres_osb(struct ocfs2_lock_res *lockres)
285 if (lockres->l_ops->get_osb)
286 return lockres->l_ops->get_osb(lockres);
288 return (struct ocfs2_super *)lockres->l_priv;
291 static int ocfs2_lock_create(struct ocfs2_super *osb,
292 struct ocfs2_lock_res *lockres,
295 static inline int ocfs2_may_continue_on_blocked_lock(struct ocfs2_lock_res *lockres,
297 static void ocfs2_cluster_unlock(struct ocfs2_super *osb,
298 struct ocfs2_lock_res *lockres,
300 static inline void ocfs2_generic_handle_downconvert_action(struct ocfs2_lock_res *lockres);
301 static inline void ocfs2_generic_handle_convert_action(struct ocfs2_lock_res *lockres);
302 static inline void ocfs2_generic_handle_attach_action(struct ocfs2_lock_res *lockres);
303 static int ocfs2_generic_handle_bast(struct ocfs2_lock_res *lockres, int level);
304 static void ocfs2_schedule_blocked_lock(struct ocfs2_super *osb,
305 struct ocfs2_lock_res *lockres);
306 static inline void ocfs2_recover_from_dlm_error(struct ocfs2_lock_res *lockres,
308 #define ocfs2_log_dlm_error(_func, _stat, _lockres) do { \
309 mlog(ML_ERROR, "Dlm error \"%s\" while calling %s on " \
310 "resource %s: %s\n", dlm_errname(_stat), _func, \
311 _lockres->l_name, dlm_errmsg(_stat)); \
313 static int ocfs2_downconvert_thread(void *arg);
314 static void ocfs2_downconvert_on_unlock(struct ocfs2_super *osb,
315 struct ocfs2_lock_res *lockres);
316 static int ocfs2_meta_lock_update(struct inode *inode,
317 struct buffer_head **bh);
318 static void ocfs2_drop_osb_locks(struct ocfs2_super *osb);
319 static inline int ocfs2_highest_compat_lock_level(int level);
321 static void ocfs2_build_lock_name(enum ocfs2_lock_type type,
330 BUG_ON(type >= OCFS2_NUM_LOCK_TYPES);
332 len = snprintf(name, OCFS2_LOCK_ID_MAX_LEN, "%c%s%016llx%08x",
333 ocfs2_lock_type_char(type), OCFS2_LOCK_ID_PAD,
334 (long long)blkno, generation);
336 BUG_ON(len != (OCFS2_LOCK_ID_MAX_LEN - 1));
338 mlog(0, "built lock resource with name: %s\n", name);
343 static DEFINE_SPINLOCK(ocfs2_dlm_tracking_lock);
345 static void ocfs2_add_lockres_tracking(struct ocfs2_lock_res *res,
346 struct ocfs2_dlm_debug *dlm_debug)
348 mlog(0, "Add tracking for lockres %s\n", res->l_name);
350 spin_lock(&ocfs2_dlm_tracking_lock);
351 list_add(&res->l_debug_list, &dlm_debug->d_lockres_tracking);
352 spin_unlock(&ocfs2_dlm_tracking_lock);
355 static void ocfs2_remove_lockres_tracking(struct ocfs2_lock_res *res)
357 spin_lock(&ocfs2_dlm_tracking_lock);
358 if (!list_empty(&res->l_debug_list))
359 list_del_init(&res->l_debug_list);
360 spin_unlock(&ocfs2_dlm_tracking_lock);
363 static void ocfs2_lock_res_init_common(struct ocfs2_super *osb,
364 struct ocfs2_lock_res *res,
365 enum ocfs2_lock_type type,
366 struct ocfs2_lock_res_ops *ops,
373 res->l_level = LKM_IVMODE;
374 res->l_requested = LKM_IVMODE;
375 res->l_blocking = LKM_IVMODE;
376 res->l_action = OCFS2_AST_INVALID;
377 res->l_unlock_action = OCFS2_UNLOCK_INVALID;
379 res->l_flags = OCFS2_LOCK_INITIALIZED;
381 ocfs2_add_lockres_tracking(res, osb->osb_dlm_debug);
384 void ocfs2_lock_res_init_once(struct ocfs2_lock_res *res)
386 /* This also clears out the lock status block */
387 memset(res, 0, sizeof(struct ocfs2_lock_res));
388 spin_lock_init(&res->l_lock);
389 init_waitqueue_head(&res->l_event);
390 INIT_LIST_HEAD(&res->l_blocked_list);
391 INIT_LIST_HEAD(&res->l_mask_waiters);
394 void ocfs2_inode_lock_res_init(struct ocfs2_lock_res *res,
395 enum ocfs2_lock_type type,
396 unsigned int generation,
399 struct ocfs2_lock_res_ops *ops;
402 case OCFS2_LOCK_TYPE_RW:
403 ops = &ocfs2_inode_rw_lops;
405 case OCFS2_LOCK_TYPE_META:
406 ops = &ocfs2_inode_meta_lops;
408 case OCFS2_LOCK_TYPE_DATA:
409 ops = &ocfs2_inode_data_lops;
411 case OCFS2_LOCK_TYPE_OPEN:
412 ops = &ocfs2_inode_open_lops;
415 mlog_bug_on_msg(1, "type: %d\n", type);
416 ops = NULL; /* thanks, gcc */
420 ocfs2_build_lock_name(type, OCFS2_I(inode)->ip_blkno,
421 generation, res->l_name);
422 ocfs2_lock_res_init_common(OCFS2_SB(inode->i_sb), res, type, ops, inode);
425 static struct ocfs2_super *ocfs2_get_inode_osb(struct ocfs2_lock_res *lockres)
427 struct inode *inode = ocfs2_lock_res_inode(lockres);
429 return OCFS2_SB(inode->i_sb);
432 static __u64 ocfs2_get_dentry_lock_ino(struct ocfs2_lock_res *lockres)
434 __be64 inode_blkno_be;
436 memcpy(&inode_blkno_be, &lockres->l_name[OCFS2_DENTRY_LOCK_INO_START],
439 return be64_to_cpu(inode_blkno_be);
442 static struct ocfs2_super *ocfs2_get_dentry_osb(struct ocfs2_lock_res *lockres)
444 struct ocfs2_dentry_lock *dl = lockres->l_priv;
446 return OCFS2_SB(dl->dl_inode->i_sb);
449 void ocfs2_dentry_lock_res_init(struct ocfs2_dentry_lock *dl,
450 u64 parent, struct inode *inode)
453 u64 inode_blkno = OCFS2_I(inode)->ip_blkno;
454 __be64 inode_blkno_be = cpu_to_be64(inode_blkno);
455 struct ocfs2_lock_res *lockres = &dl->dl_lockres;
457 ocfs2_lock_res_init_once(lockres);
460 * Unfortunately, the standard lock naming scheme won't work
461 * here because we have two 16 byte values to use. Instead,
462 * we'll stuff the inode number as a binary value. We still
463 * want error prints to show something without garbling the
464 * display, so drop a null byte in there before the inode
465 * number. A future version of OCFS2 will likely use all
466 * binary lock names. The stringified names have been a
467 * tremendous aid in debugging, but now that the debugfs
468 * interface exists, we can mangle things there if need be.
470 * NOTE: We also drop the standard "pad" value (the total lock
471 * name size stays the same though - the last part is all
472 * zeros due to the memset in ocfs2_lock_res_init_once()
474 len = snprintf(lockres->l_name, OCFS2_DENTRY_LOCK_INO_START,
476 ocfs2_lock_type_char(OCFS2_LOCK_TYPE_DENTRY),
479 BUG_ON(len != (OCFS2_DENTRY_LOCK_INO_START - 1));
481 memcpy(&lockres->l_name[OCFS2_DENTRY_LOCK_INO_START], &inode_blkno_be,
484 ocfs2_lock_res_init_common(OCFS2_SB(inode->i_sb), lockres,
485 OCFS2_LOCK_TYPE_DENTRY, &ocfs2_dentry_lops,
489 static void ocfs2_super_lock_res_init(struct ocfs2_lock_res *res,
490 struct ocfs2_super *osb)
492 /* Superblock lockres doesn't come from a slab so we call init
493 * once on it manually. */
494 ocfs2_lock_res_init_once(res);
495 ocfs2_build_lock_name(OCFS2_LOCK_TYPE_SUPER, OCFS2_SUPER_BLOCK_BLKNO,
497 ocfs2_lock_res_init_common(osb, res, OCFS2_LOCK_TYPE_SUPER,
498 &ocfs2_super_lops, osb);
501 static void ocfs2_rename_lock_res_init(struct ocfs2_lock_res *res,
502 struct ocfs2_super *osb)
504 /* Rename lockres doesn't come from a slab so we call init
505 * once on it manually. */
506 ocfs2_lock_res_init_once(res);
507 ocfs2_build_lock_name(OCFS2_LOCK_TYPE_RENAME, 0, 0, res->l_name);
508 ocfs2_lock_res_init_common(osb, res, OCFS2_LOCK_TYPE_RENAME,
509 &ocfs2_rename_lops, osb);
512 void ocfs2_lock_res_free(struct ocfs2_lock_res *res)
516 if (!(res->l_flags & OCFS2_LOCK_INITIALIZED))
519 ocfs2_remove_lockres_tracking(res);
521 mlog_bug_on_msg(!list_empty(&res->l_blocked_list),
522 "Lockres %s is on the blocked list\n",
524 mlog_bug_on_msg(!list_empty(&res->l_mask_waiters),
525 "Lockres %s has mask waiters pending\n",
527 mlog_bug_on_msg(spin_is_locked(&res->l_lock),
528 "Lockres %s is locked\n",
530 mlog_bug_on_msg(res->l_ro_holders,
531 "Lockres %s has %u ro holders\n",
532 res->l_name, res->l_ro_holders);
533 mlog_bug_on_msg(res->l_ex_holders,
534 "Lockres %s has %u ex holders\n",
535 res->l_name, res->l_ex_holders);
537 /* Need to clear out the lock status block for the dlm */
538 memset(&res->l_lksb, 0, sizeof(res->l_lksb));
544 static inline void ocfs2_inc_holders(struct ocfs2_lock_res *lockres,
553 lockres->l_ex_holders++;
556 lockres->l_ro_holders++;
565 static inline void ocfs2_dec_holders(struct ocfs2_lock_res *lockres,
574 BUG_ON(!lockres->l_ex_holders);
575 lockres->l_ex_holders--;
578 BUG_ON(!lockres->l_ro_holders);
579 lockres->l_ro_holders--;
587 /* WARNING: This function lives in a world where the only three lock
588 * levels are EX, PR, and NL. It *will* have to be adjusted when more
589 * lock types are added. */
590 static inline int ocfs2_highest_compat_lock_level(int level)
592 int new_level = LKM_EXMODE;
594 if (level == LKM_EXMODE)
595 new_level = LKM_NLMODE;
596 else if (level == LKM_PRMODE)
597 new_level = LKM_PRMODE;
601 static void lockres_set_flags(struct ocfs2_lock_res *lockres,
602 unsigned long newflags)
604 struct ocfs2_mask_waiter *mw, *tmp;
606 assert_spin_locked(&lockres->l_lock);
608 lockres->l_flags = newflags;
610 list_for_each_entry_safe(mw, tmp, &lockres->l_mask_waiters, mw_item) {
611 if ((lockres->l_flags & mw->mw_mask) != mw->mw_goal)
614 list_del_init(&mw->mw_item);
616 complete(&mw->mw_complete);
619 static void lockres_or_flags(struct ocfs2_lock_res *lockres, unsigned long or)
621 lockres_set_flags(lockres, lockres->l_flags | or);
623 static void lockres_clear_flags(struct ocfs2_lock_res *lockres,
626 lockres_set_flags(lockres, lockres->l_flags & ~clear);
629 static inline void ocfs2_generic_handle_downconvert_action(struct ocfs2_lock_res *lockres)
633 BUG_ON(!(lockres->l_flags & OCFS2_LOCK_BUSY));
634 BUG_ON(!(lockres->l_flags & OCFS2_LOCK_ATTACHED));
635 BUG_ON(!(lockres->l_flags & OCFS2_LOCK_BLOCKED));
636 BUG_ON(lockres->l_blocking <= LKM_NLMODE);
638 lockres->l_level = lockres->l_requested;
639 if (lockres->l_level <=
640 ocfs2_highest_compat_lock_level(lockres->l_blocking)) {
641 lockres->l_blocking = LKM_NLMODE;
642 lockres_clear_flags(lockres, OCFS2_LOCK_BLOCKED);
644 lockres_clear_flags(lockres, OCFS2_LOCK_BUSY);
649 static inline void ocfs2_generic_handle_convert_action(struct ocfs2_lock_res *lockres)
653 BUG_ON(!(lockres->l_flags & OCFS2_LOCK_BUSY));
654 BUG_ON(!(lockres->l_flags & OCFS2_LOCK_ATTACHED));
656 /* Convert from RO to EX doesn't really need anything as our
657 * information is already up to data. Convert from NL to
658 * *anything* however should mark ourselves as needing an
660 if (lockres->l_level == LKM_NLMODE &&
661 lockres->l_ops->flags & LOCK_TYPE_REQUIRES_REFRESH)
662 lockres_or_flags(lockres, OCFS2_LOCK_NEEDS_REFRESH);
664 lockres->l_level = lockres->l_requested;
665 lockres_clear_flags(lockres, OCFS2_LOCK_BUSY);
670 static inline void ocfs2_generic_handle_attach_action(struct ocfs2_lock_res *lockres)
674 BUG_ON((!(lockres->l_flags & OCFS2_LOCK_BUSY)));
675 BUG_ON(lockres->l_flags & OCFS2_LOCK_ATTACHED);
677 if (lockres->l_requested > LKM_NLMODE &&
678 !(lockres->l_flags & OCFS2_LOCK_LOCAL) &&
679 lockres->l_ops->flags & LOCK_TYPE_REQUIRES_REFRESH)
680 lockres_or_flags(lockres, OCFS2_LOCK_NEEDS_REFRESH);
682 lockres->l_level = lockres->l_requested;
683 lockres_or_flags(lockres, OCFS2_LOCK_ATTACHED);
684 lockres_clear_flags(lockres, OCFS2_LOCK_BUSY);
689 static int ocfs2_generic_handle_bast(struct ocfs2_lock_res *lockres,
692 int needs_downconvert = 0;
695 assert_spin_locked(&lockres->l_lock);
697 lockres_or_flags(lockres, OCFS2_LOCK_BLOCKED);
699 if (level > lockres->l_blocking) {
700 /* only schedule a downconvert if we haven't already scheduled
701 * one that goes low enough to satisfy the level we're
702 * blocking. this also catches the case where we get
704 if (ocfs2_highest_compat_lock_level(level) <
705 ocfs2_highest_compat_lock_level(lockres->l_blocking))
706 needs_downconvert = 1;
708 lockres->l_blocking = level;
711 mlog_exit(needs_downconvert);
712 return needs_downconvert;
715 static void ocfs2_blocking_ast(void *opaque, int level)
717 struct ocfs2_lock_res *lockres = opaque;
718 struct ocfs2_super *osb = ocfs2_get_lockres_osb(lockres);
719 int needs_downconvert;
722 BUG_ON(level <= LKM_NLMODE);
724 mlog(0, "BAST fired for lockres %s, blocking %d, level %d type %s\n",
725 lockres->l_name, level, lockres->l_level,
726 ocfs2_lock_type_string(lockres->l_type));
728 spin_lock_irqsave(&lockres->l_lock, flags);
729 needs_downconvert = ocfs2_generic_handle_bast(lockres, level);
730 if (needs_downconvert)
731 ocfs2_schedule_blocked_lock(osb, lockres);
732 spin_unlock_irqrestore(&lockres->l_lock, flags);
734 wake_up(&lockres->l_event);
736 ocfs2_wake_downconvert_thread(osb);
739 static void ocfs2_locking_ast(void *opaque)
741 struct ocfs2_lock_res *lockres = opaque;
742 struct dlm_lockstatus *lksb = &lockres->l_lksb;
745 spin_lock_irqsave(&lockres->l_lock, flags);
747 if (lksb->status != DLM_NORMAL) {
748 mlog(ML_ERROR, "lockres %s: lksb status value of %u!\n",
749 lockres->l_name, lksb->status);
750 spin_unlock_irqrestore(&lockres->l_lock, flags);
754 switch(lockres->l_action) {
755 case OCFS2_AST_ATTACH:
756 ocfs2_generic_handle_attach_action(lockres);
757 lockres_clear_flags(lockres, OCFS2_LOCK_LOCAL);
759 case OCFS2_AST_CONVERT:
760 ocfs2_generic_handle_convert_action(lockres);
762 case OCFS2_AST_DOWNCONVERT:
763 ocfs2_generic_handle_downconvert_action(lockres);
766 mlog(ML_ERROR, "lockres %s: ast fired with invalid action: %u "
767 "lockres flags = 0x%lx, unlock action: %u\n",
768 lockres->l_name, lockres->l_action, lockres->l_flags,
769 lockres->l_unlock_action);
773 /* set it to something invalid so if we get called again we
775 lockres->l_action = OCFS2_AST_INVALID;
777 wake_up(&lockres->l_event);
778 spin_unlock_irqrestore(&lockres->l_lock, flags);
781 static inline void ocfs2_recover_from_dlm_error(struct ocfs2_lock_res *lockres,
787 spin_lock_irqsave(&lockres->l_lock, flags);
788 lockres_clear_flags(lockres, OCFS2_LOCK_BUSY);
790 lockres->l_action = OCFS2_AST_INVALID;
792 lockres->l_unlock_action = OCFS2_UNLOCK_INVALID;
793 spin_unlock_irqrestore(&lockres->l_lock, flags);
795 wake_up(&lockres->l_event);
799 /* Note: If we detect another process working on the lock (i.e.,
800 * OCFS2_LOCK_BUSY), we'll bail out returning 0. It's up to the caller
801 * to do the right thing in that case.
803 static int ocfs2_lock_create(struct ocfs2_super *osb,
804 struct ocfs2_lock_res *lockres,
809 enum dlm_status status = DLM_NORMAL;
814 mlog(0, "lock %s, level = %d, flags = %d\n", lockres->l_name, level,
817 spin_lock_irqsave(&lockres->l_lock, flags);
818 if ((lockres->l_flags & OCFS2_LOCK_ATTACHED) ||
819 (lockres->l_flags & OCFS2_LOCK_BUSY)) {
820 spin_unlock_irqrestore(&lockres->l_lock, flags);
824 lockres->l_action = OCFS2_AST_ATTACH;
825 lockres->l_requested = level;
826 lockres_or_flags(lockres, OCFS2_LOCK_BUSY);
827 spin_unlock_irqrestore(&lockres->l_lock, flags);
829 status = dlmlock(osb->dlm,
834 OCFS2_LOCK_ID_MAX_LEN - 1,
838 if (status != DLM_NORMAL) {
839 ocfs2_log_dlm_error("dlmlock", status, lockres);
841 ocfs2_recover_from_dlm_error(lockres, 1);
844 mlog(0, "lock %s, successfull return from dlmlock\n", lockres->l_name);
851 static inline int ocfs2_check_wait_flag(struct ocfs2_lock_res *lockres,
857 spin_lock_irqsave(&lockres->l_lock, flags);
858 ret = lockres->l_flags & flag;
859 spin_unlock_irqrestore(&lockres->l_lock, flags);
864 static inline void ocfs2_wait_on_busy_lock(struct ocfs2_lock_res *lockres)
867 wait_event(lockres->l_event,
868 !ocfs2_check_wait_flag(lockres, OCFS2_LOCK_BUSY));
871 static inline void ocfs2_wait_on_refreshing_lock(struct ocfs2_lock_res *lockres)
874 wait_event(lockres->l_event,
875 !ocfs2_check_wait_flag(lockres, OCFS2_LOCK_REFRESHING));
878 /* predict what lock level we'll be dropping down to on behalf
879 * of another node, and return true if the currently wanted
880 * level will be compatible with it. */
881 static inline int ocfs2_may_continue_on_blocked_lock(struct ocfs2_lock_res *lockres,
884 BUG_ON(!(lockres->l_flags & OCFS2_LOCK_BLOCKED));
886 return wanted <= ocfs2_highest_compat_lock_level(lockres->l_blocking);
889 static void ocfs2_init_mask_waiter(struct ocfs2_mask_waiter *mw)
891 INIT_LIST_HEAD(&mw->mw_item);
892 init_completion(&mw->mw_complete);
895 static int ocfs2_wait_for_mask(struct ocfs2_mask_waiter *mw)
897 wait_for_completion(&mw->mw_complete);
898 /* Re-arm the completion in case we want to wait on it again */
899 INIT_COMPLETION(mw->mw_complete);
900 return mw->mw_status;
903 static void lockres_add_mask_waiter(struct ocfs2_lock_res *lockres,
904 struct ocfs2_mask_waiter *mw,
908 BUG_ON(!list_empty(&mw->mw_item));
910 assert_spin_locked(&lockres->l_lock);
912 list_add_tail(&mw->mw_item, &lockres->l_mask_waiters);
917 /* returns 0 if the mw that was removed was already satisfied, -EBUSY
918 * if the mask still hadn't reached its goal */
919 static int lockres_remove_mask_waiter(struct ocfs2_lock_res *lockres,
920 struct ocfs2_mask_waiter *mw)
925 spin_lock_irqsave(&lockres->l_lock, flags);
926 if (!list_empty(&mw->mw_item)) {
927 if ((lockres->l_flags & mw->mw_mask) != mw->mw_goal)
930 list_del_init(&mw->mw_item);
931 init_completion(&mw->mw_complete);
933 spin_unlock_irqrestore(&lockres->l_lock, flags);
939 static int ocfs2_cluster_lock(struct ocfs2_super *osb,
940 struct ocfs2_lock_res *lockres,
945 struct ocfs2_mask_waiter mw;
946 enum dlm_status status;
947 int wait, catch_signals = !(osb->s_mount_opt & OCFS2_MOUNT_NOINTR);
948 int ret = 0; /* gcc doesn't realize wait = 1 guarantees ret is set */
953 ocfs2_init_mask_waiter(&mw);
955 if (lockres->l_ops->flags & LOCK_TYPE_USES_LVB)
956 lkm_flags |= LKM_VALBLK;
961 if (catch_signals && signal_pending(current)) {
966 spin_lock_irqsave(&lockres->l_lock, flags);
968 mlog_bug_on_msg(lockres->l_flags & OCFS2_LOCK_FREEING,
969 "Cluster lock called on freeing lockres %s! flags "
970 "0x%lx\n", lockres->l_name, lockres->l_flags);
972 /* We only compare against the currently granted level
973 * here. If the lock is blocked waiting on a downconvert,
974 * we'll get caught below. */
975 if (lockres->l_flags & OCFS2_LOCK_BUSY &&
976 level > lockres->l_level) {
977 /* is someone sitting in dlm_lock? If so, wait on
979 lockres_add_mask_waiter(lockres, &mw, OCFS2_LOCK_BUSY, 0);
984 if (lockres->l_flags & OCFS2_LOCK_BLOCKED &&
985 !ocfs2_may_continue_on_blocked_lock(lockres, level)) {
986 /* is the lock is currently blocked on behalf of
988 lockres_add_mask_waiter(lockres, &mw, OCFS2_LOCK_BLOCKED, 0);
993 if (level > lockres->l_level) {
994 if (lockres->l_action != OCFS2_AST_INVALID)
995 mlog(ML_ERROR, "lockres %s has action %u pending\n",
996 lockres->l_name, lockres->l_action);
998 if (!(lockres->l_flags & OCFS2_LOCK_ATTACHED)) {
999 lockres->l_action = OCFS2_AST_ATTACH;
1000 lkm_flags &= ~LKM_CONVERT;
1002 lockres->l_action = OCFS2_AST_CONVERT;
1003 lkm_flags |= LKM_CONVERT;
1006 lockres->l_requested = level;
1007 lockres_or_flags(lockres, OCFS2_LOCK_BUSY);
1008 spin_unlock_irqrestore(&lockres->l_lock, flags);
1010 BUG_ON(level == LKM_IVMODE);
1011 BUG_ON(level == LKM_NLMODE);
1013 mlog(0, "lock %s, convert from %d to level = %d\n",
1014 lockres->l_name, lockres->l_level, level);
1016 /* call dlm_lock to upgrade lock now */
1017 status = dlmlock(osb->dlm,
1022 OCFS2_LOCK_ID_MAX_LEN - 1,
1025 ocfs2_blocking_ast);
1026 if (status != DLM_NORMAL) {
1027 if ((lkm_flags & LKM_NOQUEUE) &&
1028 (status == DLM_NOTQUEUED))
1031 ocfs2_log_dlm_error("dlmlock", status,
1035 ocfs2_recover_from_dlm_error(lockres, 1);
1039 mlog(0, "lock %s, successfull return from dlmlock\n",
1042 /* At this point we've gone inside the dlm and need to
1043 * complete our work regardless. */
1046 /* wait for busy to clear and carry on */
1050 /* Ok, if we get here then we're good to go. */
1051 ocfs2_inc_holders(lockres, level);
1055 spin_unlock_irqrestore(&lockres->l_lock, flags);
1058 * This is helping work around a lock inversion between the page lock
1059 * and dlm locks. One path holds the page lock while calling aops
1060 * which block acquiring dlm locks. The voting thread holds dlm
1061 * locks while acquiring page locks while down converting data locks.
1062 * This block is helping an aop path notice the inversion and back
1063 * off to unlock its page lock before trying the dlm lock again.
1065 if (wait && arg_flags & OCFS2_LOCK_NONBLOCK &&
1066 mw.mw_mask & (OCFS2_LOCK_BUSY|OCFS2_LOCK_BLOCKED)) {
1068 if (lockres_remove_mask_waiter(lockres, &mw))
1074 ret = ocfs2_wait_for_mask(&mw);
1084 static void ocfs2_cluster_unlock(struct ocfs2_super *osb,
1085 struct ocfs2_lock_res *lockres,
1088 unsigned long flags;
1091 spin_lock_irqsave(&lockres->l_lock, flags);
1092 ocfs2_dec_holders(lockres, level);
1093 ocfs2_downconvert_on_unlock(osb, lockres);
1094 spin_unlock_irqrestore(&lockres->l_lock, flags);
1098 static int ocfs2_create_new_lock(struct ocfs2_super *osb,
1099 struct ocfs2_lock_res *lockres,
1103 int level = ex ? LKM_EXMODE : LKM_PRMODE;
1104 unsigned long flags;
1105 int lkm_flags = local ? LKM_LOCAL : 0;
1107 spin_lock_irqsave(&lockres->l_lock, flags);
1108 BUG_ON(lockres->l_flags & OCFS2_LOCK_ATTACHED);
1109 lockres_or_flags(lockres, OCFS2_LOCK_LOCAL);
1110 spin_unlock_irqrestore(&lockres->l_lock, flags);
1112 return ocfs2_lock_create(osb, lockres, level, lkm_flags);
1115 /* Grants us an EX lock on the data and metadata resources, skipping
1116 * the normal cluster directory lookup. Use this ONLY on newly created
1117 * inodes which other nodes can't possibly see, and which haven't been
1118 * hashed in the inode hash yet. This can give us a good performance
1119 * increase as it'll skip the network broadcast normally associated
1120 * with creating a new lock resource. */
1121 int ocfs2_create_new_inode_locks(struct inode *inode)
1124 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1127 BUG_ON(!ocfs2_inode_is_new(inode));
1131 mlog(0, "Inode %llu\n", (unsigned long long)OCFS2_I(inode)->ip_blkno);
1133 /* NOTE: That we don't increment any of the holder counts, nor
1134 * do we add anything to a journal handle. Since this is
1135 * supposed to be a new inode which the cluster doesn't know
1136 * about yet, there is no need to. As far as the LVB handling
1137 * is concerned, this is basically like acquiring an EX lock
1138 * on a resource which has an invalid one -- we'll set it
1139 * valid when we release the EX. */
1141 ret = ocfs2_create_new_lock(osb, &OCFS2_I(inode)->ip_rw_lockres, 1, 1);
1148 * We don't want to use LKM_LOCAL on a meta data lock as they
1149 * don't use a generation in their lock names.
1151 ret = ocfs2_create_new_lock(osb, &OCFS2_I(inode)->ip_meta_lockres, 1, 0);
1157 ret = ocfs2_create_new_lock(osb, &OCFS2_I(inode)->ip_data_lockres, 1, 1);
1163 ret = ocfs2_create_new_lock(osb, &OCFS2_I(inode)->ip_open_lockres, 0, 0);
1174 int ocfs2_rw_lock(struct inode *inode, int write)
1177 struct ocfs2_lock_res *lockres;
1178 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1184 mlog(0, "inode %llu take %s RW lock\n",
1185 (unsigned long long)OCFS2_I(inode)->ip_blkno,
1186 write ? "EXMODE" : "PRMODE");
1188 if (ocfs2_mount_local(osb))
1191 lockres = &OCFS2_I(inode)->ip_rw_lockres;
1193 level = write ? LKM_EXMODE : LKM_PRMODE;
1195 status = ocfs2_cluster_lock(OCFS2_SB(inode->i_sb), lockres, level, 0,
1204 void ocfs2_rw_unlock(struct inode *inode, int write)
1206 int level = write ? LKM_EXMODE : LKM_PRMODE;
1207 struct ocfs2_lock_res *lockres = &OCFS2_I(inode)->ip_rw_lockres;
1208 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1212 mlog(0, "inode %llu drop %s RW lock\n",
1213 (unsigned long long)OCFS2_I(inode)->ip_blkno,
1214 write ? "EXMODE" : "PRMODE");
1216 if (!ocfs2_mount_local(osb))
1217 ocfs2_cluster_unlock(OCFS2_SB(inode->i_sb), lockres, level);
1223 * ocfs2_open_lock always get PR mode lock.
1225 int ocfs2_open_lock(struct inode *inode)
1228 struct ocfs2_lock_res *lockres;
1229 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1235 mlog(0, "inode %llu take PRMODE open lock\n",
1236 (unsigned long long)OCFS2_I(inode)->ip_blkno);
1238 if (ocfs2_mount_local(osb))
1241 lockres = &OCFS2_I(inode)->ip_open_lockres;
1243 status = ocfs2_cluster_lock(OCFS2_SB(inode->i_sb), lockres,
1253 int ocfs2_try_open_lock(struct inode *inode, int write)
1255 int status = 0, level;
1256 struct ocfs2_lock_res *lockres;
1257 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1263 mlog(0, "inode %llu try to take %s open lock\n",
1264 (unsigned long long)OCFS2_I(inode)->ip_blkno,
1265 write ? "EXMODE" : "PRMODE");
1267 if (ocfs2_mount_local(osb))
1270 lockres = &OCFS2_I(inode)->ip_open_lockres;
1272 level = write ? LKM_EXMODE : LKM_PRMODE;
1275 * The file system may already holding a PRMODE/EXMODE open lock.
1276 * Since we pass LKM_NOQUEUE, the request won't block waiting on
1277 * other nodes and the -EAGAIN will indicate to the caller that
1278 * this inode is still in use.
1280 status = ocfs2_cluster_lock(OCFS2_SB(inode->i_sb), lockres,
1281 level, LKM_NOQUEUE, 0);
1289 * ocfs2_open_unlock unlock PR and EX mode open locks.
1291 void ocfs2_open_unlock(struct inode *inode)
1293 struct ocfs2_lock_res *lockres = &OCFS2_I(inode)->ip_open_lockres;
1294 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1298 mlog(0, "inode %llu drop open lock\n",
1299 (unsigned long long)OCFS2_I(inode)->ip_blkno);
1301 if (ocfs2_mount_local(osb))
1304 if(lockres->l_ro_holders)
1305 ocfs2_cluster_unlock(OCFS2_SB(inode->i_sb), lockres,
1307 if(lockres->l_ex_holders)
1308 ocfs2_cluster_unlock(OCFS2_SB(inode->i_sb), lockres,
1315 int ocfs2_data_lock_full(struct inode *inode,
1319 int status = 0, level;
1320 struct ocfs2_lock_res *lockres;
1321 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1327 mlog(0, "inode %llu take %s DATA lock\n",
1328 (unsigned long long)OCFS2_I(inode)->ip_blkno,
1329 write ? "EXMODE" : "PRMODE");
1331 /* We'll allow faking a readonly data lock for
1333 if (ocfs2_is_hard_readonly(OCFS2_SB(inode->i_sb))) {
1341 if (ocfs2_mount_local(osb))
1344 lockres = &OCFS2_I(inode)->ip_data_lockres;
1346 level = write ? LKM_EXMODE : LKM_PRMODE;
1348 status = ocfs2_cluster_lock(OCFS2_SB(inode->i_sb), lockres, level,
1350 if (status < 0 && status != -EAGAIN)
1358 /* see ocfs2_meta_lock_with_page() */
1359 int ocfs2_data_lock_with_page(struct inode *inode,
1365 ret = ocfs2_data_lock_full(inode, write, OCFS2_LOCK_NONBLOCK);
1366 if (ret == -EAGAIN) {
1368 if (ocfs2_data_lock(inode, write) == 0)
1369 ocfs2_data_unlock(inode, write);
1370 ret = AOP_TRUNCATED_PAGE;
1376 static void ocfs2_downconvert_on_unlock(struct ocfs2_super *osb,
1377 struct ocfs2_lock_res *lockres)
1383 /* If we know that another node is waiting on our lock, kick
1384 * the downconvert thread * pre-emptively when we reach a release
1386 if (lockres->l_flags & OCFS2_LOCK_BLOCKED) {
1387 switch(lockres->l_blocking) {
1389 if (!lockres->l_ex_holders && !lockres->l_ro_holders)
1393 if (!lockres->l_ex_holders)
1402 ocfs2_wake_downconvert_thread(osb);
1407 void ocfs2_data_unlock(struct inode *inode,
1410 int level = write ? LKM_EXMODE : LKM_PRMODE;
1411 struct ocfs2_lock_res *lockres = &OCFS2_I(inode)->ip_data_lockres;
1412 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1416 mlog(0, "inode %llu drop %s DATA lock\n",
1417 (unsigned long long)OCFS2_I(inode)->ip_blkno,
1418 write ? "EXMODE" : "PRMODE");
1420 if (!ocfs2_is_hard_readonly(OCFS2_SB(inode->i_sb)) &&
1421 !ocfs2_mount_local(osb))
1422 ocfs2_cluster_unlock(OCFS2_SB(inode->i_sb), lockres, level);
1427 #define OCFS2_SEC_BITS 34
1428 #define OCFS2_SEC_SHIFT (64 - 34)
1429 #define OCFS2_NSEC_MASK ((1ULL << OCFS2_SEC_SHIFT) - 1)
1431 /* LVB only has room for 64 bits of time here so we pack it for
1433 static u64 ocfs2_pack_timespec(struct timespec *spec)
1436 u64 sec = spec->tv_sec;
1437 u32 nsec = spec->tv_nsec;
1439 res = (sec << OCFS2_SEC_SHIFT) | (nsec & OCFS2_NSEC_MASK);
1444 /* Call this with the lockres locked. I am reasonably sure we don't
1445 * need ip_lock in this function as anyone who would be changing those
1446 * values is supposed to be blocked in ocfs2_meta_lock right now. */
1447 static void __ocfs2_stuff_meta_lvb(struct inode *inode)
1449 struct ocfs2_inode_info *oi = OCFS2_I(inode);
1450 struct ocfs2_lock_res *lockres = &oi->ip_meta_lockres;
1451 struct ocfs2_meta_lvb *lvb;
1455 lvb = (struct ocfs2_meta_lvb *) lockres->l_lksb.lvb;
1458 * Invalidate the LVB of a deleted inode - this way other
1459 * nodes are forced to go to disk and discover the new inode
1462 if (oi->ip_flags & OCFS2_INODE_DELETED) {
1463 lvb->lvb_version = 0;
1467 lvb->lvb_version = OCFS2_LVB_VERSION;
1468 lvb->lvb_isize = cpu_to_be64(i_size_read(inode));
1469 lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
1470 lvb->lvb_iuid = cpu_to_be32(inode->i_uid);
1471 lvb->lvb_igid = cpu_to_be32(inode->i_gid);
1472 lvb->lvb_imode = cpu_to_be16(inode->i_mode);
1473 lvb->lvb_inlink = cpu_to_be16(inode->i_nlink);
1474 lvb->lvb_iatime_packed =
1475 cpu_to_be64(ocfs2_pack_timespec(&inode->i_atime));
1476 lvb->lvb_ictime_packed =
1477 cpu_to_be64(ocfs2_pack_timespec(&inode->i_ctime));
1478 lvb->lvb_imtime_packed =
1479 cpu_to_be64(ocfs2_pack_timespec(&inode->i_mtime));
1480 lvb->lvb_iattr = cpu_to_be32(oi->ip_attr);
1481 lvb->lvb_idynfeatures = cpu_to_be16(oi->ip_dyn_features);
1482 lvb->lvb_igeneration = cpu_to_be32(inode->i_generation);
1485 mlog_meta_lvb(0, lockres);
1490 static void ocfs2_unpack_timespec(struct timespec *spec,
1493 spec->tv_sec = packed_time >> OCFS2_SEC_SHIFT;
1494 spec->tv_nsec = packed_time & OCFS2_NSEC_MASK;
1497 static void ocfs2_refresh_inode_from_lvb(struct inode *inode)
1499 struct ocfs2_inode_info *oi = OCFS2_I(inode);
1500 struct ocfs2_lock_res *lockres = &oi->ip_meta_lockres;
1501 struct ocfs2_meta_lvb *lvb;
1505 mlog_meta_lvb(0, lockres);
1507 lvb = (struct ocfs2_meta_lvb *) lockres->l_lksb.lvb;
1509 /* We're safe here without the lockres lock... */
1510 spin_lock(&oi->ip_lock);
1511 oi->ip_clusters = be32_to_cpu(lvb->lvb_iclusters);
1512 i_size_write(inode, be64_to_cpu(lvb->lvb_isize));
1514 oi->ip_attr = be32_to_cpu(lvb->lvb_iattr);
1515 oi->ip_dyn_features = be16_to_cpu(lvb->lvb_idynfeatures);
1516 ocfs2_set_inode_flags(inode);
1518 /* fast-symlinks are a special case */
1519 if (S_ISLNK(inode->i_mode) && !oi->ip_clusters)
1520 inode->i_blocks = 0;
1522 inode->i_blocks = ocfs2_inode_sector_count(inode);
1524 inode->i_uid = be32_to_cpu(lvb->lvb_iuid);
1525 inode->i_gid = be32_to_cpu(lvb->lvb_igid);
1526 inode->i_mode = be16_to_cpu(lvb->lvb_imode);
1527 inode->i_nlink = be16_to_cpu(lvb->lvb_inlink);
1528 ocfs2_unpack_timespec(&inode->i_atime,
1529 be64_to_cpu(lvb->lvb_iatime_packed));
1530 ocfs2_unpack_timespec(&inode->i_mtime,
1531 be64_to_cpu(lvb->lvb_imtime_packed));
1532 ocfs2_unpack_timespec(&inode->i_ctime,
1533 be64_to_cpu(lvb->lvb_ictime_packed));
1534 spin_unlock(&oi->ip_lock);
1539 static inline int ocfs2_meta_lvb_is_trustable(struct inode *inode,
1540 struct ocfs2_lock_res *lockres)
1542 struct ocfs2_meta_lvb *lvb = (struct ocfs2_meta_lvb *) lockres->l_lksb.lvb;
1544 if (lvb->lvb_version == OCFS2_LVB_VERSION
1545 && be32_to_cpu(lvb->lvb_igeneration) == inode->i_generation)
1550 /* Determine whether a lock resource needs to be refreshed, and
1551 * arbitrate who gets to refresh it.
1553 * 0 means no refresh needed.
1555 * > 0 means you need to refresh this and you MUST call
1556 * ocfs2_complete_lock_res_refresh afterwards. */
1557 static int ocfs2_should_refresh_lock_res(struct ocfs2_lock_res *lockres)
1559 unsigned long flags;
1565 spin_lock_irqsave(&lockres->l_lock, flags);
1566 if (!(lockres->l_flags & OCFS2_LOCK_NEEDS_REFRESH)) {
1567 spin_unlock_irqrestore(&lockres->l_lock, flags);
1571 if (lockres->l_flags & OCFS2_LOCK_REFRESHING) {
1572 spin_unlock_irqrestore(&lockres->l_lock, flags);
1574 ocfs2_wait_on_refreshing_lock(lockres);
1578 /* Ok, I'll be the one to refresh this lock. */
1579 lockres_or_flags(lockres, OCFS2_LOCK_REFRESHING);
1580 spin_unlock_irqrestore(&lockres->l_lock, flags);
1588 /* If status is non zero, I'll mark it as not being in refresh
1589 * anymroe, but i won't clear the needs refresh flag. */
1590 static inline void ocfs2_complete_lock_res_refresh(struct ocfs2_lock_res *lockres,
1593 unsigned long flags;
1596 spin_lock_irqsave(&lockres->l_lock, flags);
1597 lockres_clear_flags(lockres, OCFS2_LOCK_REFRESHING);
1599 lockres_clear_flags(lockres, OCFS2_LOCK_NEEDS_REFRESH);
1600 spin_unlock_irqrestore(&lockres->l_lock, flags);
1602 wake_up(&lockres->l_event);
1607 /* may or may not return a bh if it went to disk. */
1608 static int ocfs2_meta_lock_update(struct inode *inode,
1609 struct buffer_head **bh)
1612 struct ocfs2_inode_info *oi = OCFS2_I(inode);
1613 struct ocfs2_lock_res *lockres = &oi->ip_meta_lockres;
1614 struct ocfs2_dinode *fe;
1615 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1619 if (ocfs2_mount_local(osb))
1622 spin_lock(&oi->ip_lock);
1623 if (oi->ip_flags & OCFS2_INODE_DELETED) {
1624 mlog(0, "Orphaned inode %llu was deleted while we "
1625 "were waiting on a lock. ip_flags = 0x%x\n",
1626 (unsigned long long)oi->ip_blkno, oi->ip_flags);
1627 spin_unlock(&oi->ip_lock);
1631 spin_unlock(&oi->ip_lock);
1633 if (!ocfs2_should_refresh_lock_res(lockres))
1636 /* This will discard any caching information we might have had
1637 * for the inode metadata. */
1638 ocfs2_metadata_cache_purge(inode);
1640 ocfs2_extent_map_trunc(inode, 0);
1642 if (ocfs2_meta_lvb_is_trustable(inode, lockres)) {
1643 mlog(0, "Trusting LVB on inode %llu\n",
1644 (unsigned long long)oi->ip_blkno);
1645 ocfs2_refresh_inode_from_lvb(inode);
1647 /* Boo, we have to go to disk. */
1648 /* read bh, cast, ocfs2_refresh_inode */
1649 status = ocfs2_read_block(OCFS2_SB(inode->i_sb), oi->ip_blkno,
1650 bh, OCFS2_BH_CACHED, inode);
1655 fe = (struct ocfs2_dinode *) (*bh)->b_data;
1657 /* This is a good chance to make sure we're not
1658 * locking an invalid object.
1660 * We bug on a stale inode here because we checked
1661 * above whether it was wiped from disk. The wiping
1662 * node provides a guarantee that we receive that
1663 * message and can mark the inode before dropping any
1664 * locks associated with it. */
1665 if (!OCFS2_IS_VALID_DINODE(fe)) {
1666 OCFS2_RO_ON_INVALID_DINODE(inode->i_sb, fe);
1670 mlog_bug_on_msg(inode->i_generation !=
1671 le32_to_cpu(fe->i_generation),
1672 "Invalid dinode %llu disk generation: %u "
1673 "inode->i_generation: %u\n",
1674 (unsigned long long)oi->ip_blkno,
1675 le32_to_cpu(fe->i_generation),
1676 inode->i_generation);
1677 mlog_bug_on_msg(le64_to_cpu(fe->i_dtime) ||
1678 !(fe->i_flags & cpu_to_le32(OCFS2_VALID_FL)),
1679 "Stale dinode %llu dtime: %llu flags: 0x%x\n",
1680 (unsigned long long)oi->ip_blkno,
1681 (unsigned long long)le64_to_cpu(fe->i_dtime),
1682 le32_to_cpu(fe->i_flags));
1684 ocfs2_refresh_inode(inode, fe);
1689 ocfs2_complete_lock_res_refresh(lockres, status);
1695 static int ocfs2_assign_bh(struct inode *inode,
1696 struct buffer_head **ret_bh,
1697 struct buffer_head *passed_bh)
1702 /* Ok, the update went to disk for us, use the
1704 *ret_bh = passed_bh;
1710 status = ocfs2_read_block(OCFS2_SB(inode->i_sb),
1711 OCFS2_I(inode)->ip_blkno,
1722 * returns < 0 error if the callback will never be called, otherwise
1723 * the result of the lock will be communicated via the callback.
1725 int ocfs2_meta_lock_full(struct inode *inode,
1726 struct buffer_head **ret_bh,
1730 int status, level, dlm_flags, acquired;
1731 struct ocfs2_lock_res *lockres = NULL;
1732 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1733 struct buffer_head *local_bh = NULL;
1739 mlog(0, "inode %llu, take %s META lock\n",
1740 (unsigned long long)OCFS2_I(inode)->ip_blkno,
1741 ex ? "EXMODE" : "PRMODE");
1745 /* We'll allow faking a readonly metadata lock for
1747 if (ocfs2_is_hard_readonly(osb)) {
1753 if (ocfs2_mount_local(osb))
1756 if (!(arg_flags & OCFS2_META_LOCK_RECOVERY))
1757 wait_event(osb->recovery_event,
1758 ocfs2_node_map_is_empty(osb, &osb->recovery_map));
1760 lockres = &OCFS2_I(inode)->ip_meta_lockres;
1761 level = ex ? LKM_EXMODE : LKM_PRMODE;
1763 if (arg_flags & OCFS2_META_LOCK_NOQUEUE)
1764 dlm_flags |= LKM_NOQUEUE;
1766 status = ocfs2_cluster_lock(osb, lockres, level, dlm_flags, arg_flags);
1768 if (status != -EAGAIN && status != -EIOCBRETRY)
1773 /* Notify the error cleanup path to drop the cluster lock. */
1776 /* We wait twice because a node may have died while we were in
1777 * the lower dlm layers. The second time though, we've
1778 * committed to owning this lock so we don't allow signals to
1779 * abort the operation. */
1780 if (!(arg_flags & OCFS2_META_LOCK_RECOVERY))
1781 wait_event(osb->recovery_event,
1782 ocfs2_node_map_is_empty(osb, &osb->recovery_map));
1786 * We only see this flag if we're being called from
1787 * ocfs2_read_locked_inode(). It means we're locking an inode
1788 * which hasn't been populated yet, so clear the refresh flag
1789 * and let the caller handle it.
1791 if (inode->i_state & I_NEW) {
1794 ocfs2_complete_lock_res_refresh(lockres, 0);
1798 /* This is fun. The caller may want a bh back, or it may
1799 * not. ocfs2_meta_lock_update definitely wants one in, but
1800 * may or may not read one, depending on what's in the
1801 * LVB. The result of all of this is that we've *only* gone to
1802 * disk if we have to, so the complexity is worthwhile. */
1803 status = ocfs2_meta_lock_update(inode, &local_bh);
1805 if (status != -ENOENT)
1811 status = ocfs2_assign_bh(inode, ret_bh, local_bh);
1820 if (ret_bh && (*ret_bh)) {
1825 ocfs2_meta_unlock(inode, ex);
1836 * This is working around a lock inversion between tasks acquiring DLM
1837 * locks while holding a page lock and the downconvert thread which
1838 * blocks dlm lock acquiry while acquiring page locks.
1840 * ** These _with_page variantes are only intended to be called from aop
1841 * methods that hold page locks and return a very specific *positive* error
1842 * code that aop methods pass up to the VFS -- test for errors with != 0. **
1844 * The DLM is called such that it returns -EAGAIN if it would have
1845 * blocked waiting for the downconvert thread. In that case we unlock
1846 * our page so the downconvert thread can make progress. Once we've
1847 * done this we have to return AOP_TRUNCATED_PAGE so the aop method
1848 * that called us can bubble that back up into the VFS who will then
1849 * immediately retry the aop call.
1851 * We do a blocking lock and immediate unlock before returning, though, so that
1852 * the lock has a great chance of being cached on this node by the time the VFS
1853 * calls back to retry the aop. This has a potential to livelock as nodes
1854 * ping locks back and forth, but that's a risk we're willing to take to avoid
1855 * the lock inversion simply.
1857 int ocfs2_meta_lock_with_page(struct inode *inode,
1858 struct buffer_head **ret_bh,
1864 ret = ocfs2_meta_lock_full(inode, ret_bh, ex, OCFS2_LOCK_NONBLOCK);
1865 if (ret == -EAGAIN) {
1867 if (ocfs2_meta_lock(inode, ret_bh, ex) == 0)
1868 ocfs2_meta_unlock(inode, ex);
1869 ret = AOP_TRUNCATED_PAGE;
1875 int ocfs2_meta_lock_atime(struct inode *inode,
1876 struct vfsmount *vfsmnt,
1882 ret = ocfs2_meta_lock(inode, NULL, 0);
1889 * If we should update atime, we will get EX lock,
1890 * otherwise we just get PR lock.
1892 if (ocfs2_should_update_atime(inode, vfsmnt)) {
1893 struct buffer_head *bh = NULL;
1895 ocfs2_meta_unlock(inode, 0);
1896 ret = ocfs2_meta_lock(inode, &bh, 1);
1902 if (ocfs2_should_update_atime(inode, vfsmnt))
1903 ocfs2_update_inode_atime(inode, bh);
1913 void ocfs2_meta_unlock(struct inode *inode,
1916 int level = ex ? LKM_EXMODE : LKM_PRMODE;
1917 struct ocfs2_lock_res *lockres = &OCFS2_I(inode)->ip_meta_lockres;
1918 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1922 mlog(0, "inode %llu drop %s META lock\n",
1923 (unsigned long long)OCFS2_I(inode)->ip_blkno,
1924 ex ? "EXMODE" : "PRMODE");
1926 if (!ocfs2_is_hard_readonly(OCFS2_SB(inode->i_sb)) &&
1927 !ocfs2_mount_local(osb))
1928 ocfs2_cluster_unlock(OCFS2_SB(inode->i_sb), lockres, level);
1933 int ocfs2_super_lock(struct ocfs2_super *osb,
1937 int level = ex ? LKM_EXMODE : LKM_PRMODE;
1938 struct ocfs2_lock_res *lockres = &osb->osb_super_lockres;
1939 struct buffer_head *bh;
1940 struct ocfs2_slot_info *si = osb->slot_info;
1944 if (ocfs2_is_hard_readonly(osb))
1947 if (ocfs2_mount_local(osb))
1950 status = ocfs2_cluster_lock(osb, lockres, level, 0, 0);
1956 /* The super block lock path is really in the best position to
1957 * know when resources covered by the lock need to be
1958 * refreshed, so we do it here. Of course, making sense of
1959 * everything is up to the caller :) */
1960 status = ocfs2_should_refresh_lock_res(lockres);
1967 status = ocfs2_read_block(osb, bh->b_blocknr, &bh, 0,
1970 ocfs2_update_slot_info(si);
1972 ocfs2_complete_lock_res_refresh(lockres, status);
1982 void ocfs2_super_unlock(struct ocfs2_super *osb,
1985 int level = ex ? LKM_EXMODE : LKM_PRMODE;
1986 struct ocfs2_lock_res *lockres = &osb->osb_super_lockres;
1988 if (!ocfs2_mount_local(osb))
1989 ocfs2_cluster_unlock(osb, lockres, level);
1992 int ocfs2_rename_lock(struct ocfs2_super *osb)
1995 struct ocfs2_lock_res *lockres = &osb->osb_rename_lockres;
1997 if (ocfs2_is_hard_readonly(osb))
2000 if (ocfs2_mount_local(osb))
2003 status = ocfs2_cluster_lock(osb, lockres, LKM_EXMODE, 0, 0);
2010 void ocfs2_rename_unlock(struct ocfs2_super *osb)
2012 struct ocfs2_lock_res *lockres = &osb->osb_rename_lockres;
2014 if (!ocfs2_mount_local(osb))
2015 ocfs2_cluster_unlock(osb, lockres, LKM_EXMODE);
2018 int ocfs2_dentry_lock(struct dentry *dentry, int ex)
2021 int level = ex ? LKM_EXMODE : LKM_PRMODE;
2022 struct ocfs2_dentry_lock *dl = dentry->d_fsdata;
2023 struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb);
2027 if (ocfs2_is_hard_readonly(osb))
2030 if (ocfs2_mount_local(osb))
2033 ret = ocfs2_cluster_lock(osb, &dl->dl_lockres, level, 0, 0);
2040 void ocfs2_dentry_unlock(struct dentry *dentry, int ex)
2042 int level = ex ? LKM_EXMODE : LKM_PRMODE;
2043 struct ocfs2_dentry_lock *dl = dentry->d_fsdata;
2044 struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb);
2046 if (!ocfs2_mount_local(osb))
2047 ocfs2_cluster_unlock(osb, &dl->dl_lockres, level);
2050 /* Reference counting of the dlm debug structure. We want this because
2051 * open references on the debug inodes can live on after a mount, so
2052 * we can't rely on the ocfs2_super to always exist. */
2053 static void ocfs2_dlm_debug_free(struct kref *kref)
2055 struct ocfs2_dlm_debug *dlm_debug;
2057 dlm_debug = container_of(kref, struct ocfs2_dlm_debug, d_refcnt);
2062 void ocfs2_put_dlm_debug(struct ocfs2_dlm_debug *dlm_debug)
2065 kref_put(&dlm_debug->d_refcnt, ocfs2_dlm_debug_free);
2068 static void ocfs2_get_dlm_debug(struct ocfs2_dlm_debug *debug)
2070 kref_get(&debug->d_refcnt);
2073 struct ocfs2_dlm_debug *ocfs2_new_dlm_debug(void)
2075 struct ocfs2_dlm_debug *dlm_debug;
2077 dlm_debug = kmalloc(sizeof(struct ocfs2_dlm_debug), GFP_KERNEL);
2079 mlog_errno(-ENOMEM);
2083 kref_init(&dlm_debug->d_refcnt);
2084 INIT_LIST_HEAD(&dlm_debug->d_lockres_tracking);
2085 dlm_debug->d_locking_state = NULL;
2090 /* Access to this is arbitrated for us via seq_file->sem. */
2091 struct ocfs2_dlm_seq_priv {
2092 struct ocfs2_dlm_debug *p_dlm_debug;
2093 struct ocfs2_lock_res p_iter_res;
2094 struct ocfs2_lock_res p_tmp_res;
2097 static struct ocfs2_lock_res *ocfs2_dlm_next_res(struct ocfs2_lock_res *start,
2098 struct ocfs2_dlm_seq_priv *priv)
2100 struct ocfs2_lock_res *iter, *ret = NULL;
2101 struct ocfs2_dlm_debug *dlm_debug = priv->p_dlm_debug;
2103 assert_spin_locked(&ocfs2_dlm_tracking_lock);
2105 list_for_each_entry(iter, &start->l_debug_list, l_debug_list) {
2106 /* discover the head of the list */
2107 if (&iter->l_debug_list == &dlm_debug->d_lockres_tracking) {
2108 mlog(0, "End of list found, %p\n", ret);
2112 /* We track our "dummy" iteration lockres' by a NULL
2114 if (iter->l_ops != NULL) {
2123 static void *ocfs2_dlm_seq_start(struct seq_file *m, loff_t *pos)
2125 struct ocfs2_dlm_seq_priv *priv = m->private;
2126 struct ocfs2_lock_res *iter;
2128 spin_lock(&ocfs2_dlm_tracking_lock);
2129 iter = ocfs2_dlm_next_res(&priv->p_iter_res, priv);
2131 /* Since lockres' have the lifetime of their container
2132 * (which can be inodes, ocfs2_supers, etc) we want to
2133 * copy this out to a temporary lockres while still
2134 * under the spinlock. Obviously after this we can't
2135 * trust any pointers on the copy returned, but that's
2136 * ok as the information we want isn't typically held
2138 priv->p_tmp_res = *iter;
2139 iter = &priv->p_tmp_res;
2141 spin_unlock(&ocfs2_dlm_tracking_lock);
2146 static void ocfs2_dlm_seq_stop(struct seq_file *m, void *v)
2150 static void *ocfs2_dlm_seq_next(struct seq_file *m, void *v, loff_t *pos)
2152 struct ocfs2_dlm_seq_priv *priv = m->private;
2153 struct ocfs2_lock_res *iter = v;
2154 struct ocfs2_lock_res *dummy = &priv->p_iter_res;
2156 spin_lock(&ocfs2_dlm_tracking_lock);
2157 iter = ocfs2_dlm_next_res(iter, priv);
2158 list_del_init(&dummy->l_debug_list);
2160 list_add(&dummy->l_debug_list, &iter->l_debug_list);
2161 priv->p_tmp_res = *iter;
2162 iter = &priv->p_tmp_res;
2164 spin_unlock(&ocfs2_dlm_tracking_lock);
2169 /* So that debugfs.ocfs2 can determine which format is being used */
2170 #define OCFS2_DLM_DEBUG_STR_VERSION 1
2171 static int ocfs2_dlm_seq_show(struct seq_file *m, void *v)
2175 struct ocfs2_lock_res *lockres = v;
2180 seq_printf(m, "0x%x\t", OCFS2_DLM_DEBUG_STR_VERSION);
2182 if (lockres->l_type == OCFS2_LOCK_TYPE_DENTRY)
2183 seq_printf(m, "%.*s%08x\t", OCFS2_DENTRY_LOCK_INO_START - 1,
2185 (unsigned int)ocfs2_get_dentry_lock_ino(lockres));
2187 seq_printf(m, "%.*s\t", OCFS2_LOCK_ID_MAX_LEN, lockres->l_name);
2189 seq_printf(m, "%d\t"
2200 lockres->l_unlock_action,
2201 lockres->l_ro_holders,
2202 lockres->l_ex_holders,
2203 lockres->l_requested,
2204 lockres->l_blocking);
2206 /* Dump the raw LVB */
2207 lvb = lockres->l_lksb.lvb;
2208 for(i = 0; i < DLM_LVB_LEN; i++)
2209 seq_printf(m, "0x%x\t", lvb[i]);
2212 seq_printf(m, "\n");
2216 static struct seq_operations ocfs2_dlm_seq_ops = {
2217 .start = ocfs2_dlm_seq_start,
2218 .stop = ocfs2_dlm_seq_stop,
2219 .next = ocfs2_dlm_seq_next,
2220 .show = ocfs2_dlm_seq_show,
2223 static int ocfs2_dlm_debug_release(struct inode *inode, struct file *file)
2225 struct seq_file *seq = (struct seq_file *) file->private_data;
2226 struct ocfs2_dlm_seq_priv *priv = seq->private;
2227 struct ocfs2_lock_res *res = &priv->p_iter_res;
2229 ocfs2_remove_lockres_tracking(res);
2230 ocfs2_put_dlm_debug(priv->p_dlm_debug);
2231 return seq_release_private(inode, file);
2234 static int ocfs2_dlm_debug_open(struct inode *inode, struct file *file)
2237 struct ocfs2_dlm_seq_priv *priv;
2238 struct seq_file *seq;
2239 struct ocfs2_super *osb;
2241 priv = kzalloc(sizeof(struct ocfs2_dlm_seq_priv), GFP_KERNEL);
2247 osb = inode->i_private;
2248 ocfs2_get_dlm_debug(osb->osb_dlm_debug);
2249 priv->p_dlm_debug = osb->osb_dlm_debug;
2250 INIT_LIST_HEAD(&priv->p_iter_res.l_debug_list);
2252 ret = seq_open(file, &ocfs2_dlm_seq_ops);
2259 seq = (struct seq_file *) file->private_data;
2260 seq->private = priv;
2262 ocfs2_add_lockres_tracking(&priv->p_iter_res,
2269 static const struct file_operations ocfs2_dlm_debug_fops = {
2270 .open = ocfs2_dlm_debug_open,
2271 .release = ocfs2_dlm_debug_release,
2273 .llseek = seq_lseek,
2276 static int ocfs2_dlm_init_debug(struct ocfs2_super *osb)
2279 struct ocfs2_dlm_debug *dlm_debug = osb->osb_dlm_debug;
2281 dlm_debug->d_locking_state = debugfs_create_file("locking_state",
2283 osb->osb_debug_root,
2285 &ocfs2_dlm_debug_fops);
2286 if (!dlm_debug->d_locking_state) {
2289 "Unable to create locking state debugfs file.\n");
2293 ocfs2_get_dlm_debug(dlm_debug);
2298 static void ocfs2_dlm_shutdown_debug(struct ocfs2_super *osb)
2300 struct ocfs2_dlm_debug *dlm_debug = osb->osb_dlm_debug;
2303 debugfs_remove(dlm_debug->d_locking_state);
2304 ocfs2_put_dlm_debug(dlm_debug);
2308 int ocfs2_dlm_init(struct ocfs2_super *osb)
2312 struct dlm_ctxt *dlm = NULL;
2316 if (ocfs2_mount_local(osb))
2319 status = ocfs2_dlm_init_debug(osb);
2325 /* launch downconvert thread */
2326 osb->dc_task = kthread_run(ocfs2_downconvert_thread, osb, "ocfs2dc");
2327 if (IS_ERR(osb->dc_task)) {
2328 status = PTR_ERR(osb->dc_task);
2329 osb->dc_task = NULL;
2334 /* used by the dlm code to make message headers unique, each
2335 * node in this domain must agree on this. */
2336 dlm_key = crc32_le(0, osb->uuid_str, strlen(osb->uuid_str));
2338 /* for now, uuid == domain */
2339 dlm = dlm_register_domain(osb->uuid_str, dlm_key);
2341 status = PTR_ERR(dlm);
2346 dlm_register_eviction_cb(dlm, &osb->osb_eviction_cb);
2349 ocfs2_super_lock_res_init(&osb->osb_super_lockres, osb);
2350 ocfs2_rename_lock_res_init(&osb->osb_rename_lockres, osb);
2357 ocfs2_dlm_shutdown_debug(osb);
2359 kthread_stop(osb->dc_task);
2366 void ocfs2_dlm_shutdown(struct ocfs2_super *osb)
2370 dlm_unregister_eviction_cb(&osb->osb_eviction_cb);
2372 ocfs2_drop_osb_locks(osb);
2375 kthread_stop(osb->dc_task);
2376 osb->dc_task = NULL;
2379 ocfs2_lock_res_free(&osb->osb_super_lockres);
2380 ocfs2_lock_res_free(&osb->osb_rename_lockres);
2382 dlm_unregister_domain(osb->dlm);
2385 ocfs2_dlm_shutdown_debug(osb);
2390 static void ocfs2_unlock_ast(void *opaque, enum dlm_status status)
2392 struct ocfs2_lock_res *lockres = opaque;
2393 unsigned long flags;
2397 mlog(0, "UNLOCK AST called on lock %s, action = %d\n", lockres->l_name,
2398 lockres->l_unlock_action);
2400 spin_lock_irqsave(&lockres->l_lock, flags);
2401 /* We tried to cancel a convert request, but it was already
2402 * granted. All we want to do here is clear our unlock
2403 * state. The wake_up call done at the bottom is redundant
2404 * (ocfs2_prepare_cancel_convert doesn't sleep on this) but doesn't
2405 * hurt anything anyway */
2406 if (status == DLM_CANCELGRANT &&
2407 lockres->l_unlock_action == OCFS2_UNLOCK_CANCEL_CONVERT) {
2408 mlog(0, "Got cancelgrant for %s\n", lockres->l_name);
2410 /* We don't clear the busy flag in this case as it
2411 * should have been cleared by the ast which the dlm
2413 goto complete_unlock;
2416 if (status != DLM_NORMAL) {
2417 mlog(ML_ERROR, "Dlm passes status %d for lock %s, "
2418 "unlock_action %d\n", status, lockres->l_name,
2419 lockres->l_unlock_action);
2420 spin_unlock_irqrestore(&lockres->l_lock, flags);
2424 switch(lockres->l_unlock_action) {
2425 case OCFS2_UNLOCK_CANCEL_CONVERT:
2426 mlog(0, "Cancel convert success for %s\n", lockres->l_name);
2427 lockres->l_action = OCFS2_AST_INVALID;
2429 case OCFS2_UNLOCK_DROP_LOCK:
2430 lockres->l_level = LKM_IVMODE;
2436 lockres_clear_flags(lockres, OCFS2_LOCK_BUSY);
2438 lockres->l_unlock_action = OCFS2_UNLOCK_INVALID;
2439 spin_unlock_irqrestore(&lockres->l_lock, flags);
2441 wake_up(&lockres->l_event);
2446 static int ocfs2_drop_lock(struct ocfs2_super *osb,
2447 struct ocfs2_lock_res *lockres)
2449 enum dlm_status status;
2450 unsigned long flags;
2453 /* We didn't get anywhere near actually using this lockres. */
2454 if (!(lockres->l_flags & OCFS2_LOCK_INITIALIZED))
2457 if (lockres->l_ops->flags & LOCK_TYPE_USES_LVB)
2458 lkm_flags |= LKM_VALBLK;
2460 spin_lock_irqsave(&lockres->l_lock, flags);
2462 mlog_bug_on_msg(!(lockres->l_flags & OCFS2_LOCK_FREEING),
2463 "lockres %s, flags 0x%lx\n",
2464 lockres->l_name, lockres->l_flags);
2466 while (lockres->l_flags & OCFS2_LOCK_BUSY) {
2467 mlog(0, "waiting on busy lock \"%s\": flags = %lx, action = "
2468 "%u, unlock_action = %u\n",
2469 lockres->l_name, lockres->l_flags, lockres->l_action,
2470 lockres->l_unlock_action);
2472 spin_unlock_irqrestore(&lockres->l_lock, flags);
2474 /* XXX: Today we just wait on any busy
2475 * locks... Perhaps we need to cancel converts in the
2477 ocfs2_wait_on_busy_lock(lockres);
2479 spin_lock_irqsave(&lockres->l_lock, flags);
2482 if (lockres->l_ops->flags & LOCK_TYPE_USES_LVB) {
2483 if (lockres->l_flags & OCFS2_LOCK_ATTACHED &&
2484 lockres->l_level == LKM_EXMODE &&
2485 !(lockres->l_flags & OCFS2_LOCK_NEEDS_REFRESH))
2486 lockres->l_ops->set_lvb(lockres);
2489 if (lockres->l_flags & OCFS2_LOCK_BUSY)
2490 mlog(ML_ERROR, "destroying busy lock: \"%s\"\n",
2492 if (lockres->l_flags & OCFS2_LOCK_BLOCKED)
2493 mlog(0, "destroying blocked lock: \"%s\"\n", lockres->l_name);
2495 if (!(lockres->l_flags & OCFS2_LOCK_ATTACHED)) {
2496 spin_unlock_irqrestore(&lockres->l_lock, flags);
2500 lockres_clear_flags(lockres, OCFS2_LOCK_ATTACHED);
2502 /* make sure we never get here while waiting for an ast to
2504 BUG_ON(lockres->l_action != OCFS2_AST_INVALID);
2506 /* is this necessary? */
2507 lockres_or_flags(lockres, OCFS2_LOCK_BUSY);
2508 lockres->l_unlock_action = OCFS2_UNLOCK_DROP_LOCK;
2509 spin_unlock_irqrestore(&lockres->l_lock, flags);
2511 mlog(0, "lock %s\n", lockres->l_name);
2513 status = dlmunlock(osb->dlm, &lockres->l_lksb, lkm_flags,
2514 ocfs2_unlock_ast, lockres);
2515 if (status != DLM_NORMAL) {
2516 ocfs2_log_dlm_error("dlmunlock", status, lockres);
2517 mlog(ML_ERROR, "lockres flags: %lu\n", lockres->l_flags);
2518 dlm_print_one_lock(lockres->l_lksb.lockid);
2521 mlog(0, "lock %s, successfull return from dlmunlock\n",
2524 ocfs2_wait_on_busy_lock(lockres);
2530 /* Mark the lockres as being dropped. It will no longer be
2531 * queued if blocking, but we still may have to wait on it
2532 * being dequeued from the downconvert thread before we can consider
2535 * You can *not* attempt to call cluster_lock on this lockres anymore. */
2536 void ocfs2_mark_lockres_freeing(struct ocfs2_lock_res *lockres)
2539 struct ocfs2_mask_waiter mw;
2540 unsigned long flags;
2542 ocfs2_init_mask_waiter(&mw);
2544 spin_lock_irqsave(&lockres->l_lock, flags);
2545 lockres->l_flags |= OCFS2_LOCK_FREEING;
2546 while (lockres->l_flags & OCFS2_LOCK_QUEUED) {
2547 lockres_add_mask_waiter(lockres, &mw, OCFS2_LOCK_QUEUED, 0);
2548 spin_unlock_irqrestore(&lockres->l_lock, flags);
2550 mlog(0, "Waiting on lockres %s\n", lockres->l_name);
2552 status = ocfs2_wait_for_mask(&mw);
2556 spin_lock_irqsave(&lockres->l_lock, flags);
2558 spin_unlock_irqrestore(&lockres->l_lock, flags);
2561 void ocfs2_simple_drop_lockres(struct ocfs2_super *osb,
2562 struct ocfs2_lock_res *lockres)
2566 ocfs2_mark_lockres_freeing(lockres);
2567 ret = ocfs2_drop_lock(osb, lockres);
2572 static void ocfs2_drop_osb_locks(struct ocfs2_super *osb)
2574 ocfs2_simple_drop_lockres(osb, &osb->osb_super_lockres);
2575 ocfs2_simple_drop_lockres(osb, &osb->osb_rename_lockres);
2578 int ocfs2_drop_inode_locks(struct inode *inode)
2584 /* No need to call ocfs2_mark_lockres_freeing here -
2585 * ocfs2_clear_inode has done it for us. */
2587 err = ocfs2_drop_lock(OCFS2_SB(inode->i_sb),
2588 &OCFS2_I(inode)->ip_open_lockres);
2594 err = ocfs2_drop_lock(OCFS2_SB(inode->i_sb),
2595 &OCFS2_I(inode)->ip_data_lockres);
2598 if (err < 0 && !status)
2601 err = ocfs2_drop_lock(OCFS2_SB(inode->i_sb),
2602 &OCFS2_I(inode)->ip_meta_lockres);
2605 if (err < 0 && !status)
2608 err = ocfs2_drop_lock(OCFS2_SB(inode->i_sb),
2609 &OCFS2_I(inode)->ip_rw_lockres);
2612 if (err < 0 && !status)
2619 static void ocfs2_prepare_downconvert(struct ocfs2_lock_res *lockres,
2622 assert_spin_locked(&lockres->l_lock);
2624 BUG_ON(lockres->l_blocking <= LKM_NLMODE);
2626 if (lockres->l_level <= new_level) {
2627 mlog(ML_ERROR, "lockres->l_level (%u) <= new_level (%u)\n",
2628 lockres->l_level, new_level);
2632 mlog(0, "lock %s, new_level = %d, l_blocking = %d\n",
2633 lockres->l_name, new_level, lockres->l_blocking);
2635 lockres->l_action = OCFS2_AST_DOWNCONVERT;
2636 lockres->l_requested = new_level;
2637 lockres_or_flags(lockres, OCFS2_LOCK_BUSY);
2640 static int ocfs2_downconvert_lock(struct ocfs2_super *osb,
2641 struct ocfs2_lock_res *lockres,
2645 int ret, dlm_flags = LKM_CONVERT;
2646 enum dlm_status status;
2651 dlm_flags |= LKM_VALBLK;
2653 status = dlmlock(osb->dlm,
2658 OCFS2_LOCK_ID_MAX_LEN - 1,
2661 ocfs2_blocking_ast);
2662 if (status != DLM_NORMAL) {
2663 ocfs2_log_dlm_error("dlmlock", status, lockres);
2665 ocfs2_recover_from_dlm_error(lockres, 1);
2675 /* returns 1 when the caller should unlock and call dlmunlock */
2676 static int ocfs2_prepare_cancel_convert(struct ocfs2_super *osb,
2677 struct ocfs2_lock_res *lockres)
2679 assert_spin_locked(&lockres->l_lock);
2682 mlog(0, "lock %s\n", lockres->l_name);
2684 if (lockres->l_unlock_action == OCFS2_UNLOCK_CANCEL_CONVERT) {
2685 /* If we're already trying to cancel a lock conversion
2686 * then just drop the spinlock and allow the caller to
2687 * requeue this lock. */
2689 mlog(0, "Lockres %s, skip convert\n", lockres->l_name);
2693 /* were we in a convert when we got the bast fire? */
2694 BUG_ON(lockres->l_action != OCFS2_AST_CONVERT &&
2695 lockres->l_action != OCFS2_AST_DOWNCONVERT);
2696 /* set things up for the unlockast to know to just
2697 * clear out the ast_action and unset busy, etc. */
2698 lockres->l_unlock_action = OCFS2_UNLOCK_CANCEL_CONVERT;
2700 mlog_bug_on_msg(!(lockres->l_flags & OCFS2_LOCK_BUSY),
2701 "lock %s, invalid flags: 0x%lx\n",
2702 lockres->l_name, lockres->l_flags);
2707 static int ocfs2_cancel_convert(struct ocfs2_super *osb,
2708 struct ocfs2_lock_res *lockres)
2711 enum dlm_status status;
2714 mlog(0, "lock %s\n", lockres->l_name);
2717 status = dlmunlock(osb->dlm,
2722 if (status != DLM_NORMAL) {
2723 ocfs2_log_dlm_error("dlmunlock", status, lockres);
2725 ocfs2_recover_from_dlm_error(lockres, 0);
2728 mlog(0, "lock %s return from dlmunlock\n", lockres->l_name);
2734 static int ocfs2_unblock_lock(struct ocfs2_super *osb,
2735 struct ocfs2_lock_res *lockres,
2736 struct ocfs2_unblock_ctl *ctl)
2738 unsigned long flags;
2746 spin_lock_irqsave(&lockres->l_lock, flags);
2748 BUG_ON(!(lockres->l_flags & OCFS2_LOCK_BLOCKED));
2751 if (lockres->l_flags & OCFS2_LOCK_BUSY) {
2753 ret = ocfs2_prepare_cancel_convert(osb, lockres);
2754 spin_unlock_irqrestore(&lockres->l_lock, flags);
2756 ret = ocfs2_cancel_convert(osb, lockres);
2763 /* if we're blocking an exclusive and we have *any* holders,
2765 if ((lockres->l_blocking == LKM_EXMODE)
2766 && (lockres->l_ex_holders || lockres->l_ro_holders))
2769 /* If it's a PR we're blocking, then only
2770 * requeue if we've got any EX holders */
2771 if (lockres->l_blocking == LKM_PRMODE &&
2772 lockres->l_ex_holders)
2776 * Can we get a lock in this state if the holder counts are
2777 * zero? The meta data unblock code used to check this.
2779 if ((lockres->l_ops->flags & LOCK_TYPE_REQUIRES_REFRESH)
2780 && (lockres->l_flags & OCFS2_LOCK_REFRESHING))
2783 new_level = ocfs2_highest_compat_lock_level(lockres->l_blocking);
2785 if (lockres->l_ops->check_downconvert
2786 && !lockres->l_ops->check_downconvert(lockres, new_level))
2789 /* If we get here, then we know that there are no more
2790 * incompatible holders (and anyone asking for an incompatible
2791 * lock is blocked). We can now downconvert the lock */
2792 if (!lockres->l_ops->downconvert_worker)
2795 /* Some lockres types want to do a bit of work before
2796 * downconverting a lock. Allow that here. The worker function
2797 * may sleep, so we save off a copy of what we're blocking as
2798 * it may change while we're not holding the spin lock. */
2799 blocking = lockres->l_blocking;
2800 spin_unlock_irqrestore(&lockres->l_lock, flags);
2802 ctl->unblock_action = lockres->l_ops->downconvert_worker(lockres, blocking);
2804 if (ctl->unblock_action == UNBLOCK_STOP_POST)
2807 spin_lock_irqsave(&lockres->l_lock, flags);
2808 if (blocking != lockres->l_blocking) {
2809 /* If this changed underneath us, then we can't drop
2817 if (lockres->l_ops->flags & LOCK_TYPE_USES_LVB) {
2818 if (lockres->l_level == LKM_EXMODE)
2822 * We only set the lvb if the lock has been fully
2823 * refreshed - otherwise we risk setting stale
2824 * data. Otherwise, there's no need to actually clear
2825 * out the lvb here as it's value is still valid.
2827 if (set_lvb && !(lockres->l_flags & OCFS2_LOCK_NEEDS_REFRESH))
2828 lockres->l_ops->set_lvb(lockres);
2831 ocfs2_prepare_downconvert(lockres, new_level);
2832 spin_unlock_irqrestore(&lockres->l_lock, flags);
2833 ret = ocfs2_downconvert_lock(osb, lockres, new_level, set_lvb);
2839 spin_unlock_irqrestore(&lockres->l_lock, flags);
2846 static int ocfs2_data_convert_worker(struct ocfs2_lock_res *lockres,
2849 struct inode *inode;
2850 struct address_space *mapping;
2852 inode = ocfs2_lock_res_inode(lockres);
2853 mapping = inode->i_mapping;
2855 if (S_ISREG(inode->i_mode))
2859 * We need this before the filemap_fdatawrite() so that it can
2860 * transfer the dirty bit from the PTE to the
2861 * page. Unfortunately this means that even for EX->PR
2862 * downconverts, we'll lose our mappings and have to build
2865 unmap_mapping_range(mapping, 0, 0, 0);
2867 if (filemap_fdatawrite(mapping)) {
2868 mlog(ML_ERROR, "Could not sync inode %llu for downconvert!",
2869 (unsigned long long)OCFS2_I(inode)->ip_blkno);
2871 sync_mapping_buffers(mapping);
2872 if (blocking == LKM_EXMODE) {
2873 truncate_inode_pages(mapping, 0);
2875 /* We only need to wait on the I/O if we're not also
2876 * truncating pages because truncate_inode_pages waits
2877 * for us above. We don't truncate pages if we're
2878 * blocking anything < EXMODE because we want to keep
2879 * them around in that case. */
2880 filemap_fdatawait(mapping);
2884 return UNBLOCK_CONTINUE;
2887 static int ocfs2_check_meta_downconvert(struct ocfs2_lock_res *lockres,
2890 struct inode *inode = ocfs2_lock_res_inode(lockres);
2891 int checkpointed = ocfs2_inode_fully_checkpointed(inode);
2893 BUG_ON(new_level != LKM_NLMODE && new_level != LKM_PRMODE);
2894 BUG_ON(lockres->l_level != LKM_EXMODE && !checkpointed);
2899 ocfs2_start_checkpoint(OCFS2_SB(inode->i_sb));
2903 static void ocfs2_set_meta_lvb(struct ocfs2_lock_res *lockres)
2905 struct inode *inode = ocfs2_lock_res_inode(lockres);
2907 __ocfs2_stuff_meta_lvb(inode);
2911 * Does the final reference drop on our dentry lock. Right now this
2912 * happens in the downconvert 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 void ocfs2_process_blocked_lock(struct ocfs2_super *osb,
3033 struct ocfs2_lock_res *lockres)
3036 struct ocfs2_unblock_ctl ctl = {0, 0,};
3037 unsigned long flags;
3039 /* Our reference to the lockres in this function can be
3040 * considered valid until we remove the OCFS2_LOCK_QUEUED
3046 BUG_ON(!lockres->l_ops);
3048 mlog(0, "lockres %s blocked.\n", lockres->l_name);
3050 /* Detect whether a lock has been marked as going away while
3051 * the downconvert thread was processing other things. A lock can
3052 * still be marked with OCFS2_LOCK_FREEING after this check,
3053 * but short circuiting here will still save us some
3055 spin_lock_irqsave(&lockres->l_lock, flags);
3056 if (lockres->l_flags & OCFS2_LOCK_FREEING)
3058 spin_unlock_irqrestore(&lockres->l_lock, flags);
3060 status = ocfs2_unblock_lock(osb, lockres, &ctl);
3064 spin_lock_irqsave(&lockres->l_lock, flags);
3066 if (lockres->l_flags & OCFS2_LOCK_FREEING || !ctl.requeue) {
3067 lockres_clear_flags(lockres, OCFS2_LOCK_QUEUED);
3069 ocfs2_schedule_blocked_lock(osb, lockres);
3071 mlog(0, "lockres %s, requeue = %s.\n", lockres->l_name,
3072 ctl.requeue ? "yes" : "no");
3073 spin_unlock_irqrestore(&lockres->l_lock, flags);
3075 if (ctl.unblock_action != UNBLOCK_CONTINUE
3076 && lockres->l_ops->post_unlock)
3077 lockres->l_ops->post_unlock(osb, lockres);
3082 static void ocfs2_schedule_blocked_lock(struct ocfs2_super *osb,
3083 struct ocfs2_lock_res *lockres)
3087 assert_spin_locked(&lockres->l_lock);
3089 if (lockres->l_flags & OCFS2_LOCK_FREEING) {
3090 /* Do not schedule a lock for downconvert when it's on
3091 * the way to destruction - any nodes wanting access
3092 * to the resource will get it soon. */
3093 mlog(0, "Lockres %s won't be scheduled: flags 0x%lx\n",
3094 lockres->l_name, lockres->l_flags);
3098 lockres_or_flags(lockres, OCFS2_LOCK_QUEUED);
3100 spin_lock(&osb->dc_task_lock);
3101 if (list_empty(&lockres->l_blocked_list)) {
3102 list_add_tail(&lockres->l_blocked_list,
3103 &osb->blocked_lock_list);
3104 osb->blocked_lock_count++;
3106 spin_unlock(&osb->dc_task_lock);
3111 static void ocfs2_downconvert_thread_do_work(struct ocfs2_super *osb)
3113 unsigned long processed;
3114 struct ocfs2_lock_res *lockres;
3118 spin_lock(&osb->dc_task_lock);
3119 /* grab this early so we know to try again if a state change and
3120 * wake happens part-way through our work */
3121 osb->dc_work_sequence = osb->dc_wake_sequence;
3123 processed = osb->blocked_lock_count;
3125 BUG_ON(list_empty(&osb->blocked_lock_list));
3127 lockres = list_entry(osb->blocked_lock_list.next,
3128 struct ocfs2_lock_res, l_blocked_list);
3129 list_del_init(&lockres->l_blocked_list);
3130 osb->blocked_lock_count--;
3131 spin_unlock(&osb->dc_task_lock);
3136 ocfs2_process_blocked_lock(osb, lockres);
3138 spin_lock(&osb->dc_task_lock);
3140 spin_unlock(&osb->dc_task_lock);
3145 static int ocfs2_downconvert_thread_lists_empty(struct ocfs2_super *osb)
3149 spin_lock(&osb->dc_task_lock);
3150 if (list_empty(&osb->blocked_lock_list))
3153 spin_unlock(&osb->dc_task_lock);
3157 static int ocfs2_downconvert_thread_should_wake(struct ocfs2_super *osb)
3159 int should_wake = 0;
3161 spin_lock(&osb->dc_task_lock);
3162 if (osb->dc_work_sequence != osb->dc_wake_sequence)
3164 spin_unlock(&osb->dc_task_lock);
3169 int ocfs2_downconvert_thread(void *arg)
3172 struct ocfs2_super *osb = arg;
3174 /* only quit once we've been asked to stop and there is no more
3176 while (!(kthread_should_stop() &&
3177 ocfs2_downconvert_thread_lists_empty(osb))) {
3179 wait_event_interruptible(osb->dc_event,
3180 ocfs2_downconvert_thread_should_wake(osb) ||
3181 kthread_should_stop());
3183 mlog(0, "downconvert_thread: awoken\n");
3185 ocfs2_downconvert_thread_do_work(osb);
3188 osb->dc_task = NULL;
3192 void ocfs2_wake_downconvert_thread(struct ocfs2_super *osb)
3194 spin_lock(&osb->dc_task_lock);
3195 /* make sure the voting thread gets a swipe at whatever changes
3196 * the caller may have made to the voting state */
3197 osb->dc_wake_sequence++;
3198 spin_unlock(&osb->dc_task_lock);
3199 wake_up(&osb->dc_event);