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/kthread.h>
31 #include <linux/pagemap.h>
32 #include <linux/debugfs.h>
33 #include <linux/seq_file.h>
34 #include <linux/time.h>
35 #include <linux/quotaops.h>
37 #define MLOG_MASK_PREFIX ML_DLM_GLUE
38 #include <cluster/masklog.h>
41 #include "ocfs2_lockingver.h"
46 #include "extent_map.h"
48 #include "heartbeat.h"
51 #include "stackglue.h"
56 #include "refcounttree.h"
58 #include "buffer_head_io.h"
60 struct ocfs2_mask_waiter
{
61 struct list_head mw_item
;
63 struct completion mw_complete
;
64 unsigned long mw_mask
;
65 unsigned long mw_goal
;
66 #ifdef CONFIG_OCFS2_FS_STATS
67 unsigned long long mw_lock_start
;
71 static struct ocfs2_super
*ocfs2_get_dentry_osb(struct ocfs2_lock_res
*lockres
);
72 static struct ocfs2_super
*ocfs2_get_inode_osb(struct ocfs2_lock_res
*lockres
);
73 static struct ocfs2_super
*ocfs2_get_file_osb(struct ocfs2_lock_res
*lockres
);
74 static struct ocfs2_super
*ocfs2_get_qinfo_osb(struct ocfs2_lock_res
*lockres
);
77 * Return value from ->downconvert_worker functions.
79 * These control the precise actions of ocfs2_unblock_lock()
80 * and ocfs2_process_blocked_lock()
83 enum ocfs2_unblock_action
{
84 UNBLOCK_CONTINUE
= 0, /* Continue downconvert */
85 UNBLOCK_CONTINUE_POST
= 1, /* Continue downconvert, fire
86 * ->post_unlock callback */
87 UNBLOCK_STOP_POST
= 2, /* Do not downconvert, fire
88 * ->post_unlock() callback. */
91 struct ocfs2_unblock_ctl
{
93 enum ocfs2_unblock_action unblock_action
;
96 /* Lockdep class keys */
97 struct lock_class_key lockdep_keys
[OCFS2_NUM_LOCK_TYPES
];
99 static int ocfs2_check_meta_downconvert(struct ocfs2_lock_res
*lockres
,
101 static void ocfs2_set_meta_lvb(struct ocfs2_lock_res
*lockres
);
103 static int ocfs2_data_convert_worker(struct ocfs2_lock_res
*lockres
,
106 static int ocfs2_dentry_convert_worker(struct ocfs2_lock_res
*lockres
,
109 static void ocfs2_dentry_post_unlock(struct ocfs2_super
*osb
,
110 struct ocfs2_lock_res
*lockres
);
112 static void ocfs2_set_qinfo_lvb(struct ocfs2_lock_res
*lockres
);
114 static int ocfs2_check_refcount_downconvert(struct ocfs2_lock_res
*lockres
,
116 static int ocfs2_refcount_convert_worker(struct ocfs2_lock_res
*lockres
,
119 #define mlog_meta_lvb(__level, __lockres) ocfs2_dump_meta_lvb_info(__level, __PRETTY_FUNCTION__, __LINE__, __lockres)
121 /* This aids in debugging situations where a bad LVB might be involved. */
122 static void ocfs2_dump_meta_lvb_info(u64 level
,
123 const char *function
,
125 struct ocfs2_lock_res
*lockres
)
127 struct ocfs2_meta_lvb
*lvb
= ocfs2_dlm_lvb(&lockres
->l_lksb
);
129 mlog(level
, "LVB information for %s (called from %s:%u):\n",
130 lockres
->l_name
, function
, line
);
131 mlog(level
, "version: %u, clusters: %u, generation: 0x%x\n",
132 lvb
->lvb_version
, be32_to_cpu(lvb
->lvb_iclusters
),
133 be32_to_cpu(lvb
->lvb_igeneration
));
134 mlog(level
, "size: %llu, uid %u, gid %u, mode 0x%x\n",
135 (unsigned long long)be64_to_cpu(lvb
->lvb_isize
),
136 be32_to_cpu(lvb
->lvb_iuid
), be32_to_cpu(lvb
->lvb_igid
),
137 be16_to_cpu(lvb
->lvb_imode
));
138 mlog(level
, "nlink %u, atime_packed 0x%llx, ctime_packed 0x%llx, "
139 "mtime_packed 0x%llx iattr 0x%x\n", be16_to_cpu(lvb
->lvb_inlink
),
140 (long long)be64_to_cpu(lvb
->lvb_iatime_packed
),
141 (long long)be64_to_cpu(lvb
->lvb_ictime_packed
),
142 (long long)be64_to_cpu(lvb
->lvb_imtime_packed
),
143 be32_to_cpu(lvb
->lvb_iattr
));
148 * OCFS2 Lock Resource Operations
150 * These fine tune the behavior of the generic dlmglue locking infrastructure.
152 * The most basic of lock types can point ->l_priv to their respective
153 * struct ocfs2_super and allow the default actions to manage things.
155 * Right now, each lock type also needs to implement an init function,
156 * and trivial lock/unlock wrappers. ocfs2_simple_drop_lockres()
157 * should be called when the lock is no longer needed (i.e., object
160 struct ocfs2_lock_res_ops
{
162 * Translate an ocfs2_lock_res * into an ocfs2_super *. Define
163 * this callback if ->l_priv is not an ocfs2_super pointer
165 struct ocfs2_super
* (*get_osb
)(struct ocfs2_lock_res
*);
168 * Optionally called in the downconvert thread after a
169 * successful downconvert. The lockres will not be referenced
170 * after this callback is called, so it is safe to free
173 * The exact semantics of when this is called are controlled
174 * by ->downconvert_worker()
176 void (*post_unlock
)(struct ocfs2_super
*, struct ocfs2_lock_res
*);
179 * Allow a lock type to add checks to determine whether it is
180 * safe to downconvert a lock. Return 0 to re-queue the
181 * downconvert at a later time, nonzero to continue.
183 * For most locks, the default checks that there are no
184 * incompatible holders are sufficient.
186 * Called with the lockres spinlock held.
188 int (*check_downconvert
)(struct ocfs2_lock_res
*, int);
191 * Allows a lock type to populate the lock value block. This
192 * is called on downconvert, and when we drop a lock.
194 * Locks that want to use this should set LOCK_TYPE_USES_LVB
195 * in the flags field.
197 * Called with the lockres spinlock held.
199 void (*set_lvb
)(struct ocfs2_lock_res
*);
202 * Called from the downconvert thread when it is determined
203 * that a lock will be downconverted. This is called without
204 * any locks held so the function can do work that might
205 * schedule (syncing out data, etc).
207 * This should return any one of the ocfs2_unblock_action
208 * values, depending on what it wants the thread to do.
210 int (*downconvert_worker
)(struct ocfs2_lock_res
*, int);
213 * LOCK_TYPE_* flags which describe the specific requirements
214 * of a lock type. Descriptions of each individual flag follow.
220 * Some locks want to "refresh" potentially stale data when a
221 * meaningful (PRMODE or EXMODE) lock level is first obtained. If this
222 * flag is set, the OCFS2_LOCK_NEEDS_REFRESH flag will be set on the
223 * individual lockres l_flags member from the ast function. It is
224 * expected that the locking wrapper will clear the
225 * OCFS2_LOCK_NEEDS_REFRESH flag when done.
227 #define LOCK_TYPE_REQUIRES_REFRESH 0x1
230 * Indicate that a lock type makes use of the lock value block. The
231 * ->set_lvb lock type callback must be defined.
233 #define LOCK_TYPE_USES_LVB 0x2
235 static struct ocfs2_lock_res_ops ocfs2_inode_rw_lops
= {
236 .get_osb
= ocfs2_get_inode_osb
,
240 static struct ocfs2_lock_res_ops ocfs2_inode_inode_lops
= {
241 .get_osb
= ocfs2_get_inode_osb
,
242 .check_downconvert
= ocfs2_check_meta_downconvert
,
243 .set_lvb
= ocfs2_set_meta_lvb
,
244 .downconvert_worker
= ocfs2_data_convert_worker
,
245 .flags
= LOCK_TYPE_REQUIRES_REFRESH
|LOCK_TYPE_USES_LVB
,
248 static struct ocfs2_lock_res_ops ocfs2_super_lops
= {
249 .flags
= LOCK_TYPE_REQUIRES_REFRESH
,
252 static struct ocfs2_lock_res_ops ocfs2_rename_lops
= {
256 static struct ocfs2_lock_res_ops ocfs2_nfs_sync_lops
= {
260 static struct ocfs2_lock_res_ops ocfs2_orphan_scan_lops
= {
261 .flags
= LOCK_TYPE_REQUIRES_REFRESH
|LOCK_TYPE_USES_LVB
,
264 static struct ocfs2_lock_res_ops ocfs2_dentry_lops
= {
265 .get_osb
= ocfs2_get_dentry_osb
,
266 .post_unlock
= ocfs2_dentry_post_unlock
,
267 .downconvert_worker
= ocfs2_dentry_convert_worker
,
271 static struct ocfs2_lock_res_ops ocfs2_inode_open_lops
= {
272 .get_osb
= ocfs2_get_inode_osb
,
276 static struct ocfs2_lock_res_ops ocfs2_flock_lops
= {
277 .get_osb
= ocfs2_get_file_osb
,
281 static struct ocfs2_lock_res_ops ocfs2_qinfo_lops
= {
282 .set_lvb
= ocfs2_set_qinfo_lvb
,
283 .get_osb
= ocfs2_get_qinfo_osb
,
284 .flags
= LOCK_TYPE_REQUIRES_REFRESH
| LOCK_TYPE_USES_LVB
,
287 static struct ocfs2_lock_res_ops ocfs2_refcount_block_lops
= {
288 .check_downconvert
= ocfs2_check_refcount_downconvert
,
289 .downconvert_worker
= ocfs2_refcount_convert_worker
,
293 static inline int ocfs2_is_inode_lock(struct ocfs2_lock_res
*lockres
)
295 return lockres
->l_type
== OCFS2_LOCK_TYPE_META
||
296 lockres
->l_type
== OCFS2_LOCK_TYPE_RW
||
297 lockres
->l_type
== OCFS2_LOCK_TYPE_OPEN
;
300 static inline struct ocfs2_lock_res
*ocfs2_lksb_to_lock_res(struct ocfs2_dlm_lksb
*lksb
)
302 return container_of(lksb
, struct ocfs2_lock_res
, l_lksb
);
305 static inline struct inode
*ocfs2_lock_res_inode(struct ocfs2_lock_res
*lockres
)
307 BUG_ON(!ocfs2_is_inode_lock(lockres
));
309 return (struct inode
*) lockres
->l_priv
;
312 static inline struct ocfs2_dentry_lock
*ocfs2_lock_res_dl(struct ocfs2_lock_res
*lockres
)
314 BUG_ON(lockres
->l_type
!= OCFS2_LOCK_TYPE_DENTRY
);
316 return (struct ocfs2_dentry_lock
*)lockres
->l_priv
;
319 static inline struct ocfs2_mem_dqinfo
*ocfs2_lock_res_qinfo(struct ocfs2_lock_res
*lockres
)
321 BUG_ON(lockres
->l_type
!= OCFS2_LOCK_TYPE_QINFO
);
323 return (struct ocfs2_mem_dqinfo
*)lockres
->l_priv
;
326 static inline struct ocfs2_refcount_tree
*
327 ocfs2_lock_res_refcount_tree(struct ocfs2_lock_res
*res
)
329 return container_of(res
, struct ocfs2_refcount_tree
, rf_lockres
);
332 static inline struct ocfs2_super
*ocfs2_get_lockres_osb(struct ocfs2_lock_res
*lockres
)
334 if (lockres
->l_ops
->get_osb
)
335 return lockres
->l_ops
->get_osb(lockres
);
337 return (struct ocfs2_super
*)lockres
->l_priv
;
340 static int ocfs2_lock_create(struct ocfs2_super
*osb
,
341 struct ocfs2_lock_res
*lockres
,
344 static inline int ocfs2_may_continue_on_blocked_lock(struct ocfs2_lock_res
*lockres
,
346 static void __ocfs2_cluster_unlock(struct ocfs2_super
*osb
,
347 struct ocfs2_lock_res
*lockres
,
348 int level
, unsigned long caller_ip
);
349 static inline void ocfs2_cluster_unlock(struct ocfs2_super
*osb
,
350 struct ocfs2_lock_res
*lockres
,
353 __ocfs2_cluster_unlock(osb
, lockres
, level
, _RET_IP_
);
356 static inline void ocfs2_generic_handle_downconvert_action(struct ocfs2_lock_res
*lockres
);
357 static inline void ocfs2_generic_handle_convert_action(struct ocfs2_lock_res
*lockres
);
358 static inline void ocfs2_generic_handle_attach_action(struct ocfs2_lock_res
*lockres
);
359 static int ocfs2_generic_handle_bast(struct ocfs2_lock_res
*lockres
, int level
);
360 static void ocfs2_schedule_blocked_lock(struct ocfs2_super
*osb
,
361 struct ocfs2_lock_res
*lockres
);
362 static inline void ocfs2_recover_from_dlm_error(struct ocfs2_lock_res
*lockres
,
364 #define ocfs2_log_dlm_error(_func, _err, _lockres) do { \
365 if ((_lockres)->l_type != OCFS2_LOCK_TYPE_DENTRY) \
366 mlog(ML_ERROR, "DLM error %d while calling %s on resource %s\n", \
367 _err, _func, _lockres->l_name); \
369 mlog(ML_ERROR, "DLM error %d while calling %s on resource %.*s%08x\n", \
370 _err, _func, OCFS2_DENTRY_LOCK_INO_START - 1, (_lockres)->l_name, \
371 (unsigned int)ocfs2_get_dentry_lock_ino(_lockres)); \
373 static int ocfs2_downconvert_thread(void *arg
);
374 static void ocfs2_downconvert_on_unlock(struct ocfs2_super
*osb
,
375 struct ocfs2_lock_res
*lockres
);
376 static int ocfs2_inode_lock_update(struct inode
*inode
,
377 struct buffer_head
**bh
);
378 static void ocfs2_drop_osb_locks(struct ocfs2_super
*osb
);
379 static inline int ocfs2_highest_compat_lock_level(int level
);
380 static unsigned int ocfs2_prepare_downconvert(struct ocfs2_lock_res
*lockres
,
382 static int ocfs2_downconvert_lock(struct ocfs2_super
*osb
,
383 struct ocfs2_lock_res
*lockres
,
386 unsigned int generation
);
387 static int ocfs2_prepare_cancel_convert(struct ocfs2_super
*osb
,
388 struct ocfs2_lock_res
*lockres
);
389 static int ocfs2_cancel_convert(struct ocfs2_super
*osb
,
390 struct ocfs2_lock_res
*lockres
);
393 static void ocfs2_build_lock_name(enum ocfs2_lock_type type
,
400 BUG_ON(type
>= OCFS2_NUM_LOCK_TYPES
);
402 len
= snprintf(name
, OCFS2_LOCK_ID_MAX_LEN
, "%c%s%016llx%08x",
403 ocfs2_lock_type_char(type
), OCFS2_LOCK_ID_PAD
,
404 (long long)blkno
, generation
);
406 BUG_ON(len
!= (OCFS2_LOCK_ID_MAX_LEN
- 1));
408 mlog(0, "built lock resource with name: %s\n", name
);
411 static DEFINE_SPINLOCK(ocfs2_dlm_tracking_lock
);
413 static void ocfs2_add_lockres_tracking(struct ocfs2_lock_res
*res
,
414 struct ocfs2_dlm_debug
*dlm_debug
)
416 mlog(0, "Add tracking for lockres %s\n", res
->l_name
);
418 spin_lock(&ocfs2_dlm_tracking_lock
);
419 list_add(&res
->l_debug_list
, &dlm_debug
->d_lockres_tracking
);
420 spin_unlock(&ocfs2_dlm_tracking_lock
);
423 static void ocfs2_remove_lockres_tracking(struct ocfs2_lock_res
*res
)
425 spin_lock(&ocfs2_dlm_tracking_lock
);
426 if (!list_empty(&res
->l_debug_list
))
427 list_del_init(&res
->l_debug_list
);
428 spin_unlock(&ocfs2_dlm_tracking_lock
);
431 #ifdef CONFIG_OCFS2_FS_STATS
432 static void ocfs2_init_lock_stats(struct ocfs2_lock_res
*res
)
434 res
->l_lock_num_prmode
= 0;
435 res
->l_lock_num_prmode_failed
= 0;
436 res
->l_lock_total_prmode
= 0;
437 res
->l_lock_max_prmode
= 0;
438 res
->l_lock_num_exmode
= 0;
439 res
->l_lock_num_exmode_failed
= 0;
440 res
->l_lock_total_exmode
= 0;
441 res
->l_lock_max_exmode
= 0;
442 res
->l_lock_refresh
= 0;
445 static void ocfs2_update_lock_stats(struct ocfs2_lock_res
*res
, int level
,
446 struct ocfs2_mask_waiter
*mw
, int ret
)
448 unsigned long long *num
, *sum
;
449 unsigned int *max
, *failed
;
450 struct timespec ts
= current_kernel_time();
451 unsigned long long time
= timespec_to_ns(&ts
) - mw
->mw_lock_start
;
453 if (level
== LKM_PRMODE
) {
454 num
= &res
->l_lock_num_prmode
;
455 sum
= &res
->l_lock_total_prmode
;
456 max
= &res
->l_lock_max_prmode
;
457 failed
= &res
->l_lock_num_prmode_failed
;
458 } else if (level
== LKM_EXMODE
) {
459 num
= &res
->l_lock_num_exmode
;
460 sum
= &res
->l_lock_total_exmode
;
461 max
= &res
->l_lock_max_exmode
;
462 failed
= &res
->l_lock_num_exmode_failed
;
474 static inline void ocfs2_track_lock_refresh(struct ocfs2_lock_res
*lockres
)
476 lockres
->l_lock_refresh
++;
479 static inline void ocfs2_init_start_time(struct ocfs2_mask_waiter
*mw
)
481 struct timespec ts
= current_kernel_time();
482 mw
->mw_lock_start
= timespec_to_ns(&ts
);
485 static inline void ocfs2_init_lock_stats(struct ocfs2_lock_res
*res
)
488 static inline void ocfs2_update_lock_stats(struct ocfs2_lock_res
*res
,
489 int level
, struct ocfs2_mask_waiter
*mw
, int ret
)
492 static inline void ocfs2_track_lock_refresh(struct ocfs2_lock_res
*lockres
)
495 static inline void ocfs2_init_start_time(struct ocfs2_mask_waiter
*mw
)
500 static void ocfs2_lock_res_init_common(struct ocfs2_super
*osb
,
501 struct ocfs2_lock_res
*res
,
502 enum ocfs2_lock_type type
,
503 struct ocfs2_lock_res_ops
*ops
,
510 res
->l_level
= DLM_LOCK_IV
;
511 res
->l_requested
= DLM_LOCK_IV
;
512 res
->l_blocking
= DLM_LOCK_IV
;
513 res
->l_action
= OCFS2_AST_INVALID
;
514 res
->l_unlock_action
= OCFS2_UNLOCK_INVALID
;
516 res
->l_flags
= OCFS2_LOCK_INITIALIZED
;
518 ocfs2_add_lockres_tracking(res
, osb
->osb_dlm_debug
);
520 ocfs2_init_lock_stats(res
);
521 #ifdef CONFIG_DEBUG_LOCK_ALLOC
522 if (type
!= OCFS2_LOCK_TYPE_OPEN
)
523 lockdep_init_map(&res
->l_lockdep_map
, ocfs2_lock_type_strings
[type
],
524 &lockdep_keys
[type
], 0);
526 res
->l_lockdep_map
.key
= NULL
;
530 void ocfs2_lock_res_init_once(struct ocfs2_lock_res
*res
)
532 /* This also clears out the lock status block */
533 memset(res
, 0, sizeof(struct ocfs2_lock_res
));
534 spin_lock_init(&res
->l_lock
);
535 init_waitqueue_head(&res
->l_event
);
536 INIT_LIST_HEAD(&res
->l_blocked_list
);
537 INIT_LIST_HEAD(&res
->l_mask_waiters
);
540 void ocfs2_inode_lock_res_init(struct ocfs2_lock_res
*res
,
541 enum ocfs2_lock_type type
,
542 unsigned int generation
,
545 struct ocfs2_lock_res_ops
*ops
;
548 case OCFS2_LOCK_TYPE_RW
:
549 ops
= &ocfs2_inode_rw_lops
;
551 case OCFS2_LOCK_TYPE_META
:
552 ops
= &ocfs2_inode_inode_lops
;
554 case OCFS2_LOCK_TYPE_OPEN
:
555 ops
= &ocfs2_inode_open_lops
;
558 mlog_bug_on_msg(1, "type: %d\n", type
);
559 ops
= NULL
; /* thanks, gcc */
563 ocfs2_build_lock_name(type
, OCFS2_I(inode
)->ip_blkno
,
564 generation
, res
->l_name
);
565 ocfs2_lock_res_init_common(OCFS2_SB(inode
->i_sb
), res
, type
, ops
, inode
);
568 static struct ocfs2_super
*ocfs2_get_inode_osb(struct ocfs2_lock_res
*lockres
)
570 struct inode
*inode
= ocfs2_lock_res_inode(lockres
);
572 return OCFS2_SB(inode
->i_sb
);
575 static struct ocfs2_super
*ocfs2_get_qinfo_osb(struct ocfs2_lock_res
*lockres
)
577 struct ocfs2_mem_dqinfo
*info
= lockres
->l_priv
;
579 return OCFS2_SB(info
->dqi_gi
.dqi_sb
);
582 static struct ocfs2_super
*ocfs2_get_file_osb(struct ocfs2_lock_res
*lockres
)
584 struct ocfs2_file_private
*fp
= lockres
->l_priv
;
586 return OCFS2_SB(fp
->fp_file
->f_mapping
->host
->i_sb
);
589 static __u64
ocfs2_get_dentry_lock_ino(struct ocfs2_lock_res
*lockres
)
591 __be64 inode_blkno_be
;
593 memcpy(&inode_blkno_be
, &lockres
->l_name
[OCFS2_DENTRY_LOCK_INO_START
],
596 return be64_to_cpu(inode_blkno_be
);
599 static struct ocfs2_super
*ocfs2_get_dentry_osb(struct ocfs2_lock_res
*lockres
)
601 struct ocfs2_dentry_lock
*dl
= lockres
->l_priv
;
603 return OCFS2_SB(dl
->dl_inode
->i_sb
);
606 void ocfs2_dentry_lock_res_init(struct ocfs2_dentry_lock
*dl
,
607 u64 parent
, struct inode
*inode
)
610 u64 inode_blkno
= OCFS2_I(inode
)->ip_blkno
;
611 __be64 inode_blkno_be
= cpu_to_be64(inode_blkno
);
612 struct ocfs2_lock_res
*lockres
= &dl
->dl_lockres
;
614 ocfs2_lock_res_init_once(lockres
);
617 * Unfortunately, the standard lock naming scheme won't work
618 * here because we have two 16 byte values to use. Instead,
619 * we'll stuff the inode number as a binary value. We still
620 * want error prints to show something without garbling the
621 * display, so drop a null byte in there before the inode
622 * number. A future version of OCFS2 will likely use all
623 * binary lock names. The stringified names have been a
624 * tremendous aid in debugging, but now that the debugfs
625 * interface exists, we can mangle things there if need be.
627 * NOTE: We also drop the standard "pad" value (the total lock
628 * name size stays the same though - the last part is all
629 * zeros due to the memset in ocfs2_lock_res_init_once()
631 len
= snprintf(lockres
->l_name
, OCFS2_DENTRY_LOCK_INO_START
,
633 ocfs2_lock_type_char(OCFS2_LOCK_TYPE_DENTRY
),
636 BUG_ON(len
!= (OCFS2_DENTRY_LOCK_INO_START
- 1));
638 memcpy(&lockres
->l_name
[OCFS2_DENTRY_LOCK_INO_START
], &inode_blkno_be
,
641 ocfs2_lock_res_init_common(OCFS2_SB(inode
->i_sb
), lockres
,
642 OCFS2_LOCK_TYPE_DENTRY
, &ocfs2_dentry_lops
,
646 static void ocfs2_super_lock_res_init(struct ocfs2_lock_res
*res
,
647 struct ocfs2_super
*osb
)
649 /* Superblock lockres doesn't come from a slab so we call init
650 * once on it manually. */
651 ocfs2_lock_res_init_once(res
);
652 ocfs2_build_lock_name(OCFS2_LOCK_TYPE_SUPER
, OCFS2_SUPER_BLOCK_BLKNO
,
654 ocfs2_lock_res_init_common(osb
, res
, OCFS2_LOCK_TYPE_SUPER
,
655 &ocfs2_super_lops
, osb
);
658 static void ocfs2_rename_lock_res_init(struct ocfs2_lock_res
*res
,
659 struct ocfs2_super
*osb
)
661 /* Rename lockres doesn't come from a slab so we call init
662 * once on it manually. */
663 ocfs2_lock_res_init_once(res
);
664 ocfs2_build_lock_name(OCFS2_LOCK_TYPE_RENAME
, 0, 0, res
->l_name
);
665 ocfs2_lock_res_init_common(osb
, res
, OCFS2_LOCK_TYPE_RENAME
,
666 &ocfs2_rename_lops
, osb
);
669 static void ocfs2_nfs_sync_lock_res_init(struct ocfs2_lock_res
*res
,
670 struct ocfs2_super
*osb
)
672 /* nfs_sync lockres doesn't come from a slab so we call init
673 * once on it manually. */
674 ocfs2_lock_res_init_once(res
);
675 ocfs2_build_lock_name(OCFS2_LOCK_TYPE_NFS_SYNC
, 0, 0, res
->l_name
);
676 ocfs2_lock_res_init_common(osb
, res
, OCFS2_LOCK_TYPE_NFS_SYNC
,
677 &ocfs2_nfs_sync_lops
, osb
);
680 static void ocfs2_orphan_scan_lock_res_init(struct ocfs2_lock_res
*res
,
681 struct ocfs2_super
*osb
)
683 ocfs2_lock_res_init_once(res
);
684 ocfs2_build_lock_name(OCFS2_LOCK_TYPE_ORPHAN_SCAN
, 0, 0, res
->l_name
);
685 ocfs2_lock_res_init_common(osb
, res
, OCFS2_LOCK_TYPE_ORPHAN_SCAN
,
686 &ocfs2_orphan_scan_lops
, osb
);
689 void ocfs2_file_lock_res_init(struct ocfs2_lock_res
*lockres
,
690 struct ocfs2_file_private
*fp
)
692 struct inode
*inode
= fp
->fp_file
->f_mapping
->host
;
693 struct ocfs2_inode_info
*oi
= OCFS2_I(inode
);
695 ocfs2_lock_res_init_once(lockres
);
696 ocfs2_build_lock_name(OCFS2_LOCK_TYPE_FLOCK
, oi
->ip_blkno
,
697 inode
->i_generation
, lockres
->l_name
);
698 ocfs2_lock_res_init_common(OCFS2_SB(inode
->i_sb
), lockres
,
699 OCFS2_LOCK_TYPE_FLOCK
, &ocfs2_flock_lops
,
701 lockres
->l_flags
|= OCFS2_LOCK_NOCACHE
;
704 void ocfs2_qinfo_lock_res_init(struct ocfs2_lock_res
*lockres
,
705 struct ocfs2_mem_dqinfo
*info
)
707 ocfs2_lock_res_init_once(lockres
);
708 ocfs2_build_lock_name(OCFS2_LOCK_TYPE_QINFO
, info
->dqi_gi
.dqi_type
,
710 ocfs2_lock_res_init_common(OCFS2_SB(info
->dqi_gi
.dqi_sb
), lockres
,
711 OCFS2_LOCK_TYPE_QINFO
, &ocfs2_qinfo_lops
,
715 void ocfs2_refcount_lock_res_init(struct ocfs2_lock_res
*lockres
,
716 struct ocfs2_super
*osb
, u64 ref_blkno
,
717 unsigned int generation
)
719 ocfs2_lock_res_init_once(lockres
);
720 ocfs2_build_lock_name(OCFS2_LOCK_TYPE_REFCOUNT
, ref_blkno
,
721 generation
, lockres
->l_name
);
722 ocfs2_lock_res_init_common(osb
, lockres
, OCFS2_LOCK_TYPE_REFCOUNT
,
723 &ocfs2_refcount_block_lops
, osb
);
726 void ocfs2_lock_res_free(struct ocfs2_lock_res
*res
)
728 if (!(res
->l_flags
& OCFS2_LOCK_INITIALIZED
))
731 ocfs2_remove_lockres_tracking(res
);
733 mlog_bug_on_msg(!list_empty(&res
->l_blocked_list
),
734 "Lockres %s is on the blocked list\n",
736 mlog_bug_on_msg(!list_empty(&res
->l_mask_waiters
),
737 "Lockres %s has mask waiters pending\n",
739 mlog_bug_on_msg(spin_is_locked(&res
->l_lock
),
740 "Lockres %s is locked\n",
742 mlog_bug_on_msg(res
->l_ro_holders
,
743 "Lockres %s has %u ro holders\n",
744 res
->l_name
, res
->l_ro_holders
);
745 mlog_bug_on_msg(res
->l_ex_holders
,
746 "Lockres %s has %u ex holders\n",
747 res
->l_name
, res
->l_ex_holders
);
749 /* Need to clear out the lock status block for the dlm */
750 memset(&res
->l_lksb
, 0, sizeof(res
->l_lksb
));
755 static inline void ocfs2_inc_holders(struct ocfs2_lock_res
*lockres
,
762 lockres
->l_ex_holders
++;
765 lockres
->l_ro_holders
++;
772 static inline void ocfs2_dec_holders(struct ocfs2_lock_res
*lockres
,
779 BUG_ON(!lockres
->l_ex_holders
);
780 lockres
->l_ex_holders
--;
783 BUG_ON(!lockres
->l_ro_holders
);
784 lockres
->l_ro_holders
--;
791 /* WARNING: This function lives in a world where the only three lock
792 * levels are EX, PR, and NL. It *will* have to be adjusted when more
793 * lock types are added. */
794 static inline int ocfs2_highest_compat_lock_level(int level
)
796 int new_level
= DLM_LOCK_EX
;
798 if (level
== DLM_LOCK_EX
)
799 new_level
= DLM_LOCK_NL
;
800 else if (level
== DLM_LOCK_PR
)
801 new_level
= DLM_LOCK_PR
;
805 static void lockres_set_flags(struct ocfs2_lock_res
*lockres
,
806 unsigned long newflags
)
808 struct ocfs2_mask_waiter
*mw
, *tmp
;
810 assert_spin_locked(&lockres
->l_lock
);
812 lockres
->l_flags
= newflags
;
814 list_for_each_entry_safe(mw
, tmp
, &lockres
->l_mask_waiters
, mw_item
) {
815 if ((lockres
->l_flags
& mw
->mw_mask
) != mw
->mw_goal
)
818 list_del_init(&mw
->mw_item
);
820 complete(&mw
->mw_complete
);
823 static void lockres_or_flags(struct ocfs2_lock_res
*lockres
, unsigned long or)
825 lockres_set_flags(lockres
, lockres
->l_flags
| or);
827 static void lockres_clear_flags(struct ocfs2_lock_res
*lockres
,
830 lockres_set_flags(lockres
, lockres
->l_flags
& ~clear
);
833 static inline void ocfs2_generic_handle_downconvert_action(struct ocfs2_lock_res
*lockres
)
835 BUG_ON(!(lockres
->l_flags
& OCFS2_LOCK_BUSY
));
836 BUG_ON(!(lockres
->l_flags
& OCFS2_LOCK_ATTACHED
));
837 BUG_ON(!(lockres
->l_flags
& OCFS2_LOCK_BLOCKED
));
838 BUG_ON(lockres
->l_blocking
<= DLM_LOCK_NL
);
840 lockres
->l_level
= lockres
->l_requested
;
841 if (lockres
->l_level
<=
842 ocfs2_highest_compat_lock_level(lockres
->l_blocking
)) {
843 lockres
->l_blocking
= DLM_LOCK_NL
;
844 lockres_clear_flags(lockres
, OCFS2_LOCK_BLOCKED
);
846 lockres_clear_flags(lockres
, OCFS2_LOCK_BUSY
);
849 static inline void ocfs2_generic_handle_convert_action(struct ocfs2_lock_res
*lockres
)
851 BUG_ON(!(lockres
->l_flags
& OCFS2_LOCK_BUSY
));
852 BUG_ON(!(lockres
->l_flags
& OCFS2_LOCK_ATTACHED
));
854 /* Convert from RO to EX doesn't really need anything as our
855 * information is already up to data. Convert from NL to
856 * *anything* however should mark ourselves as needing an
858 if (lockres
->l_level
== DLM_LOCK_NL
&&
859 lockres
->l_ops
->flags
& LOCK_TYPE_REQUIRES_REFRESH
)
860 lockres_or_flags(lockres
, OCFS2_LOCK_NEEDS_REFRESH
);
862 lockres
->l_level
= lockres
->l_requested
;
865 * We set the OCFS2_LOCK_UPCONVERT_FINISHING flag before clearing
866 * the OCFS2_LOCK_BUSY flag to prevent the dc thread from
867 * downconverting the lock before the upconvert has fully completed.
869 lockres_or_flags(lockres
, OCFS2_LOCK_UPCONVERT_FINISHING
);
871 lockres_clear_flags(lockres
, OCFS2_LOCK_BUSY
);
874 static inline void ocfs2_generic_handle_attach_action(struct ocfs2_lock_res
*lockres
)
876 BUG_ON((!(lockres
->l_flags
& OCFS2_LOCK_BUSY
)));
877 BUG_ON(lockres
->l_flags
& OCFS2_LOCK_ATTACHED
);
879 if (lockres
->l_requested
> DLM_LOCK_NL
&&
880 !(lockres
->l_flags
& OCFS2_LOCK_LOCAL
) &&
881 lockres
->l_ops
->flags
& LOCK_TYPE_REQUIRES_REFRESH
)
882 lockres_or_flags(lockres
, OCFS2_LOCK_NEEDS_REFRESH
);
884 lockres
->l_level
= lockres
->l_requested
;
885 lockres_or_flags(lockres
, OCFS2_LOCK_ATTACHED
);
886 lockres_clear_flags(lockres
, OCFS2_LOCK_BUSY
);
889 static int ocfs2_generic_handle_bast(struct ocfs2_lock_res
*lockres
,
892 int needs_downconvert
= 0;
894 assert_spin_locked(&lockres
->l_lock
);
896 if (level
> lockres
->l_blocking
) {
897 /* only schedule a downconvert if we haven't already scheduled
898 * one that goes low enough to satisfy the level we're
899 * blocking. this also catches the case where we get
901 if (ocfs2_highest_compat_lock_level(level
) <
902 ocfs2_highest_compat_lock_level(lockres
->l_blocking
))
903 needs_downconvert
= 1;
905 lockres
->l_blocking
= level
;
908 mlog(ML_BASTS
, "lockres %s, block %d, level %d, l_block %d, dwn %d\n",
909 lockres
->l_name
, level
, lockres
->l_level
, lockres
->l_blocking
,
912 if (needs_downconvert
)
913 lockres_or_flags(lockres
, OCFS2_LOCK_BLOCKED
);
914 mlog(0, "needs_downconvert = %d\n", needs_downconvert
);
915 return needs_downconvert
;
919 * OCFS2_LOCK_PENDING and l_pending_gen.
921 * Why does OCFS2_LOCK_PENDING exist? To close a race between setting
922 * OCFS2_LOCK_BUSY and calling ocfs2_dlm_lock(). See ocfs2_unblock_lock()
923 * for more details on the race.
925 * OCFS2_LOCK_PENDING closes the race quite nicely. However, it introduces
926 * a race on itself. In o2dlm, we can get the ast before ocfs2_dlm_lock()
927 * returns. The ast clears OCFS2_LOCK_BUSY, and must therefore clear
928 * OCFS2_LOCK_PENDING at the same time. When ocfs2_dlm_lock() returns,
929 * the caller is going to try to clear PENDING again. If nothing else is
930 * happening, __lockres_clear_pending() sees PENDING is unset and does
933 * But what if another path (eg downconvert thread) has just started a
934 * new locking action? The other path has re-set PENDING. Our path
935 * cannot clear PENDING, because that will re-open the original race
941 * ocfs2_cluster_lock()
946 * ocfs2_locking_ast() ocfs2_downconvert_thread()
947 * clear PENDING ocfs2_unblock_lock()
950 * ocfs2_prepare_downconvert()
960 * So as you can see, we now have a window where l_lock is not held,
961 * PENDING is not set, and ocfs2_dlm_lock() has not been called.
963 * The core problem is that ocfs2_cluster_lock() has cleared the PENDING
964 * set by ocfs2_prepare_downconvert(). That wasn't nice.
966 * To solve this we introduce l_pending_gen. A call to
967 * lockres_clear_pending() will only do so when it is passed a generation
968 * number that matches the lockres. lockres_set_pending() will return the
969 * current generation number. When ocfs2_cluster_lock() goes to clear
970 * PENDING, it passes the generation it got from set_pending(). In our
971 * example above, the generation numbers will *not* match. Thus,
972 * ocfs2_cluster_lock() will not clear the PENDING set by
973 * ocfs2_prepare_downconvert().
976 /* Unlocked version for ocfs2_locking_ast() */
977 static void __lockres_clear_pending(struct ocfs2_lock_res
*lockres
,
978 unsigned int generation
,
979 struct ocfs2_super
*osb
)
981 assert_spin_locked(&lockres
->l_lock
);
984 * The ast and locking functions can race us here. The winner
985 * will clear pending, the loser will not.
987 if (!(lockres
->l_flags
& OCFS2_LOCK_PENDING
) ||
988 (lockres
->l_pending_gen
!= generation
))
991 lockres_clear_flags(lockres
, OCFS2_LOCK_PENDING
);
992 lockres
->l_pending_gen
++;
995 * The downconvert thread may have skipped us because we
996 * were PENDING. Wake it up.
998 if (lockres
->l_flags
& OCFS2_LOCK_BLOCKED
)
999 ocfs2_wake_downconvert_thread(osb
);
1002 /* Locked version for callers of ocfs2_dlm_lock() */
1003 static void lockres_clear_pending(struct ocfs2_lock_res
*lockres
,
1004 unsigned int generation
,
1005 struct ocfs2_super
*osb
)
1007 unsigned long flags
;
1009 spin_lock_irqsave(&lockres
->l_lock
, flags
);
1010 __lockres_clear_pending(lockres
, generation
, osb
);
1011 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
1014 static unsigned int lockres_set_pending(struct ocfs2_lock_res
*lockres
)
1016 assert_spin_locked(&lockres
->l_lock
);
1017 BUG_ON(!(lockres
->l_flags
& OCFS2_LOCK_BUSY
));
1019 lockres_or_flags(lockres
, OCFS2_LOCK_PENDING
);
1021 return lockres
->l_pending_gen
;
1024 static void ocfs2_blocking_ast(struct ocfs2_dlm_lksb
*lksb
, int level
)
1026 struct ocfs2_lock_res
*lockres
= ocfs2_lksb_to_lock_res(lksb
);
1027 struct ocfs2_super
*osb
= ocfs2_get_lockres_osb(lockres
);
1028 int needs_downconvert
;
1029 unsigned long flags
;
1031 BUG_ON(level
<= DLM_LOCK_NL
);
1033 mlog(ML_BASTS
, "BAST fired for lockres %s, blocking %d, level %d, "
1034 "type %s\n", lockres
->l_name
, level
, lockres
->l_level
,
1035 ocfs2_lock_type_string(lockres
->l_type
));
1038 * We can skip the bast for locks which don't enable caching -
1039 * they'll be dropped at the earliest possible time anyway.
1041 if (lockres
->l_flags
& OCFS2_LOCK_NOCACHE
)
1044 spin_lock_irqsave(&lockres
->l_lock
, flags
);
1045 needs_downconvert
= ocfs2_generic_handle_bast(lockres
, level
);
1046 if (needs_downconvert
)
1047 ocfs2_schedule_blocked_lock(osb
, lockres
);
1048 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
1050 wake_up(&lockres
->l_event
);
1052 ocfs2_wake_downconvert_thread(osb
);
1055 static void ocfs2_locking_ast(struct ocfs2_dlm_lksb
*lksb
)
1057 struct ocfs2_lock_res
*lockres
= ocfs2_lksb_to_lock_res(lksb
);
1058 struct ocfs2_super
*osb
= ocfs2_get_lockres_osb(lockres
);
1059 unsigned long flags
;
1062 spin_lock_irqsave(&lockres
->l_lock
, flags
);
1064 status
= ocfs2_dlm_lock_status(&lockres
->l_lksb
);
1066 if (status
== -EAGAIN
) {
1067 lockres_clear_flags(lockres
, OCFS2_LOCK_BUSY
);
1072 mlog(ML_ERROR
, "lockres %s: lksb status value of %d!\n",
1073 lockres
->l_name
, status
);
1074 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
1078 mlog(ML_BASTS
, "AST fired for lockres %s, action %d, unlock %d, "
1079 "level %d => %d\n", lockres
->l_name
, lockres
->l_action
,
1080 lockres
->l_unlock_action
, lockres
->l_level
, lockres
->l_requested
);
1082 switch(lockres
->l_action
) {
1083 case OCFS2_AST_ATTACH
:
1084 ocfs2_generic_handle_attach_action(lockres
);
1085 lockres_clear_flags(lockres
, OCFS2_LOCK_LOCAL
);
1087 case OCFS2_AST_CONVERT
:
1088 ocfs2_generic_handle_convert_action(lockres
);
1090 case OCFS2_AST_DOWNCONVERT
:
1091 ocfs2_generic_handle_downconvert_action(lockres
);
1094 mlog(ML_ERROR
, "lockres %s: AST fired with invalid action: %u, "
1095 "flags 0x%lx, unlock: %u\n",
1096 lockres
->l_name
, lockres
->l_action
, lockres
->l_flags
,
1097 lockres
->l_unlock_action
);
1101 /* set it to something invalid so if we get called again we
1103 lockres
->l_action
= OCFS2_AST_INVALID
;
1105 /* Did we try to cancel this lock? Clear that state */
1106 if (lockres
->l_unlock_action
== OCFS2_UNLOCK_CANCEL_CONVERT
)
1107 lockres
->l_unlock_action
= OCFS2_UNLOCK_INVALID
;
1110 * We may have beaten the locking functions here. We certainly
1111 * know that dlm_lock() has been called :-)
1112 * Because we can't have two lock calls in flight at once, we
1113 * can use lockres->l_pending_gen.
1115 __lockres_clear_pending(lockres
, lockres
->l_pending_gen
, osb
);
1117 wake_up(&lockres
->l_event
);
1118 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
1121 static void ocfs2_unlock_ast(struct ocfs2_dlm_lksb
*lksb
, int error
)
1123 struct ocfs2_lock_res
*lockres
= ocfs2_lksb_to_lock_res(lksb
);
1124 unsigned long flags
;
1126 mlog(ML_BASTS
, "UNLOCK AST fired for lockres %s, action = %d\n",
1127 lockres
->l_name
, lockres
->l_unlock_action
);
1129 spin_lock_irqsave(&lockres
->l_lock
, flags
);
1131 mlog(ML_ERROR
, "Dlm passes error %d for lock %s, "
1132 "unlock_action %d\n", error
, lockres
->l_name
,
1133 lockres
->l_unlock_action
);
1134 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
1138 switch(lockres
->l_unlock_action
) {
1139 case OCFS2_UNLOCK_CANCEL_CONVERT
:
1140 mlog(0, "Cancel convert success for %s\n", lockres
->l_name
);
1141 lockres
->l_action
= OCFS2_AST_INVALID
;
1142 /* Downconvert thread may have requeued this lock, we
1143 * need to wake it. */
1144 if (lockres
->l_flags
& OCFS2_LOCK_BLOCKED
)
1145 ocfs2_wake_downconvert_thread(ocfs2_get_lockres_osb(lockres
));
1147 case OCFS2_UNLOCK_DROP_LOCK
:
1148 lockres
->l_level
= DLM_LOCK_IV
;
1154 lockres_clear_flags(lockres
, OCFS2_LOCK_BUSY
);
1155 lockres
->l_unlock_action
= OCFS2_UNLOCK_INVALID
;
1156 wake_up(&lockres
->l_event
);
1157 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
1161 * This is the filesystem locking protocol. It provides the lock handling
1162 * hooks for the underlying DLM. It has a maximum version number.
1163 * The version number allows interoperability with systems running at
1164 * the same major number and an equal or smaller minor number.
1166 * Whenever the filesystem does new things with locks (adds or removes a
1167 * lock, orders them differently, does different things underneath a lock),
1168 * the version must be changed. The protocol is negotiated when joining
1169 * the dlm domain. A node may join the domain if its major version is
1170 * identical to all other nodes and its minor version is greater than
1171 * or equal to all other nodes. When its minor version is greater than
1172 * the other nodes, it will run at the minor version specified by the
1175 * If a locking change is made that will not be compatible with older
1176 * versions, the major number must be increased and the minor version set
1177 * to zero. If a change merely adds a behavior that can be disabled when
1178 * speaking to older versions, the minor version must be increased. If a
1179 * change adds a fully backwards compatible change (eg, LVB changes that
1180 * are just ignored by older versions), the version does not need to be
1183 static struct ocfs2_locking_protocol lproto
= {
1185 .pv_major
= OCFS2_LOCKING_PROTOCOL_MAJOR
,
1186 .pv_minor
= OCFS2_LOCKING_PROTOCOL_MINOR
,
1188 .lp_lock_ast
= ocfs2_locking_ast
,
1189 .lp_blocking_ast
= ocfs2_blocking_ast
,
1190 .lp_unlock_ast
= ocfs2_unlock_ast
,
1193 void ocfs2_set_locking_protocol(void)
1195 ocfs2_stack_glue_set_max_proto_version(&lproto
.lp_max_version
);
1198 static inline void ocfs2_recover_from_dlm_error(struct ocfs2_lock_res
*lockres
,
1201 unsigned long flags
;
1203 spin_lock_irqsave(&lockres
->l_lock
, flags
);
1204 lockres_clear_flags(lockres
, OCFS2_LOCK_BUSY
);
1205 lockres_clear_flags(lockres
, OCFS2_LOCK_UPCONVERT_FINISHING
);
1207 lockres
->l_action
= OCFS2_AST_INVALID
;
1209 lockres
->l_unlock_action
= OCFS2_UNLOCK_INVALID
;
1210 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
1212 wake_up(&lockres
->l_event
);
1215 /* Note: If we detect another process working on the lock (i.e.,
1216 * OCFS2_LOCK_BUSY), we'll bail out returning 0. It's up to the caller
1217 * to do the right thing in that case.
1219 static int ocfs2_lock_create(struct ocfs2_super
*osb
,
1220 struct ocfs2_lock_res
*lockres
,
1225 unsigned long flags
;
1228 mlog(0, "lock %s, level = %d, flags = %u\n", lockres
->l_name
, level
,
1231 spin_lock_irqsave(&lockres
->l_lock
, flags
);
1232 if ((lockres
->l_flags
& OCFS2_LOCK_ATTACHED
) ||
1233 (lockres
->l_flags
& OCFS2_LOCK_BUSY
)) {
1234 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
1238 lockres
->l_action
= OCFS2_AST_ATTACH
;
1239 lockres
->l_requested
= level
;
1240 lockres_or_flags(lockres
, OCFS2_LOCK_BUSY
);
1241 gen
= lockres_set_pending(lockres
);
1242 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
1244 ret
= ocfs2_dlm_lock(osb
->cconn
,
1249 OCFS2_LOCK_ID_MAX_LEN
- 1);
1250 lockres_clear_pending(lockres
, gen
, osb
);
1252 ocfs2_log_dlm_error("ocfs2_dlm_lock", ret
, lockres
);
1253 ocfs2_recover_from_dlm_error(lockres
, 1);
1256 mlog(0, "lock %s, return from ocfs2_dlm_lock\n", lockres
->l_name
);
1262 static inline int ocfs2_check_wait_flag(struct ocfs2_lock_res
*lockres
,
1265 unsigned long flags
;
1268 spin_lock_irqsave(&lockres
->l_lock
, flags
);
1269 ret
= lockres
->l_flags
& flag
;
1270 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
1275 static inline void ocfs2_wait_on_busy_lock(struct ocfs2_lock_res
*lockres
)
1278 wait_event(lockres
->l_event
,
1279 !ocfs2_check_wait_flag(lockres
, OCFS2_LOCK_BUSY
));
1282 static inline void ocfs2_wait_on_refreshing_lock(struct ocfs2_lock_res
*lockres
)
1285 wait_event(lockres
->l_event
,
1286 !ocfs2_check_wait_flag(lockres
, OCFS2_LOCK_REFRESHING
));
1289 /* predict what lock level we'll be dropping down to on behalf
1290 * of another node, and return true if the currently wanted
1291 * level will be compatible with it. */
1292 static inline int ocfs2_may_continue_on_blocked_lock(struct ocfs2_lock_res
*lockres
,
1295 BUG_ON(!(lockres
->l_flags
& OCFS2_LOCK_BLOCKED
));
1297 return wanted
<= ocfs2_highest_compat_lock_level(lockres
->l_blocking
);
1300 static void ocfs2_init_mask_waiter(struct ocfs2_mask_waiter
*mw
)
1302 INIT_LIST_HEAD(&mw
->mw_item
);
1303 init_completion(&mw
->mw_complete
);
1304 ocfs2_init_start_time(mw
);
1307 static int ocfs2_wait_for_mask(struct ocfs2_mask_waiter
*mw
)
1309 wait_for_completion(&mw
->mw_complete
);
1310 /* Re-arm the completion in case we want to wait on it again */
1311 INIT_COMPLETION(mw
->mw_complete
);
1312 return mw
->mw_status
;
1315 static void lockres_add_mask_waiter(struct ocfs2_lock_res
*lockres
,
1316 struct ocfs2_mask_waiter
*mw
,
1320 BUG_ON(!list_empty(&mw
->mw_item
));
1322 assert_spin_locked(&lockres
->l_lock
);
1324 list_add_tail(&mw
->mw_item
, &lockres
->l_mask_waiters
);
1329 /* returns 0 if the mw that was removed was already satisfied, -EBUSY
1330 * if the mask still hadn't reached its goal */
1331 static int lockres_remove_mask_waiter(struct ocfs2_lock_res
*lockres
,
1332 struct ocfs2_mask_waiter
*mw
)
1334 unsigned long flags
;
1337 spin_lock_irqsave(&lockres
->l_lock
, flags
);
1338 if (!list_empty(&mw
->mw_item
)) {
1339 if ((lockres
->l_flags
& mw
->mw_mask
) != mw
->mw_goal
)
1342 list_del_init(&mw
->mw_item
);
1343 init_completion(&mw
->mw_complete
);
1345 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
1351 static int ocfs2_wait_for_mask_interruptible(struct ocfs2_mask_waiter
*mw
,
1352 struct ocfs2_lock_res
*lockres
)
1356 ret
= wait_for_completion_interruptible(&mw
->mw_complete
);
1358 lockres_remove_mask_waiter(lockres
, mw
);
1360 ret
= mw
->mw_status
;
1361 /* Re-arm the completion in case we want to wait on it again */
1362 INIT_COMPLETION(mw
->mw_complete
);
1366 static int __ocfs2_cluster_lock(struct ocfs2_super
*osb
,
1367 struct ocfs2_lock_res
*lockres
,
1372 unsigned long caller_ip
)
1374 struct ocfs2_mask_waiter mw
;
1375 int wait
, catch_signals
= !(osb
->s_mount_opt
& OCFS2_MOUNT_NOINTR
);
1376 int ret
= 0; /* gcc doesn't realize wait = 1 guarantees ret is set */
1377 unsigned long flags
;
1379 int noqueue_attempted
= 0;
1381 ocfs2_init_mask_waiter(&mw
);
1383 if (lockres
->l_ops
->flags
& LOCK_TYPE_USES_LVB
)
1384 lkm_flags
|= DLM_LKF_VALBLK
;
1389 spin_lock_irqsave(&lockres
->l_lock
, flags
);
1391 if (catch_signals
&& signal_pending(current
)) {
1396 mlog_bug_on_msg(lockres
->l_flags
& OCFS2_LOCK_FREEING
,
1397 "Cluster lock called on freeing lockres %s! flags "
1398 "0x%lx\n", lockres
->l_name
, lockres
->l_flags
);
1400 /* We only compare against the currently granted level
1401 * here. If the lock is blocked waiting on a downconvert,
1402 * we'll get caught below. */
1403 if (lockres
->l_flags
& OCFS2_LOCK_BUSY
&&
1404 level
> lockres
->l_level
) {
1405 /* is someone sitting in dlm_lock? If so, wait on
1407 lockres_add_mask_waiter(lockres
, &mw
, OCFS2_LOCK_BUSY
, 0);
1412 if (lockres
->l_flags
& OCFS2_LOCK_UPCONVERT_FINISHING
) {
1414 * We've upconverted. If the lock now has a level we can
1415 * work with, we take it. If, however, the lock is not at the
1416 * required level, we go thru the full cycle. One way this could
1417 * happen is if a process requesting an upconvert to PR is
1418 * closely followed by another requesting upconvert to an EX.
1419 * If the process requesting EX lands here, we want it to
1420 * continue attempting to upconvert and let the process
1421 * requesting PR take the lock.
1422 * If multiple processes request upconvert to PR, the first one
1423 * here will take the lock. The others will have to go thru the
1424 * OCFS2_LOCK_BLOCKED check to ensure that there is no pending
1425 * downconvert request.
1427 if (level
<= lockres
->l_level
)
1428 goto update_holders
;
1431 if (lockres
->l_flags
& OCFS2_LOCK_BLOCKED
&&
1432 !ocfs2_may_continue_on_blocked_lock(lockres
, level
)) {
1433 /* is the lock is currently blocked on behalf of
1435 lockres_add_mask_waiter(lockres
, &mw
, OCFS2_LOCK_BLOCKED
, 0);
1440 if (level
> lockres
->l_level
) {
1441 if (noqueue_attempted
> 0) {
1445 if (lkm_flags
& DLM_LKF_NOQUEUE
)
1446 noqueue_attempted
= 1;
1448 if (lockres
->l_action
!= OCFS2_AST_INVALID
)
1449 mlog(ML_ERROR
, "lockres %s has action %u pending\n",
1450 lockres
->l_name
, lockres
->l_action
);
1452 if (!(lockres
->l_flags
& OCFS2_LOCK_ATTACHED
)) {
1453 lockres
->l_action
= OCFS2_AST_ATTACH
;
1454 lkm_flags
&= ~DLM_LKF_CONVERT
;
1456 lockres
->l_action
= OCFS2_AST_CONVERT
;
1457 lkm_flags
|= DLM_LKF_CONVERT
;
1460 lockres
->l_requested
= level
;
1461 lockres_or_flags(lockres
, OCFS2_LOCK_BUSY
);
1462 gen
= lockres_set_pending(lockres
);
1463 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
1465 BUG_ON(level
== DLM_LOCK_IV
);
1466 BUG_ON(level
== DLM_LOCK_NL
);
1468 mlog(ML_BASTS
, "lockres %s, convert from %d to %d\n",
1469 lockres
->l_name
, lockres
->l_level
, level
);
1471 /* call dlm_lock to upgrade lock now */
1472 ret
= ocfs2_dlm_lock(osb
->cconn
,
1477 OCFS2_LOCK_ID_MAX_LEN
- 1);
1478 lockres_clear_pending(lockres
, gen
, osb
);
1480 if (!(lkm_flags
& DLM_LKF_NOQUEUE
) ||
1482 ocfs2_log_dlm_error("ocfs2_dlm_lock",
1485 ocfs2_recover_from_dlm_error(lockres
, 1);
1489 mlog(0, "lock %s, successful return from ocfs2_dlm_lock\n",
1492 /* At this point we've gone inside the dlm and need to
1493 * complete our work regardless. */
1496 /* wait for busy to clear and carry on */
1501 /* Ok, if we get here then we're good to go. */
1502 ocfs2_inc_holders(lockres
, level
);
1506 lockres_clear_flags(lockres
, OCFS2_LOCK_UPCONVERT_FINISHING
);
1508 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
1511 * This is helping work around a lock inversion between the page lock
1512 * and dlm locks. One path holds the page lock while calling aops
1513 * which block acquiring dlm locks. The voting thread holds dlm
1514 * locks while acquiring page locks while down converting data locks.
1515 * This block is helping an aop path notice the inversion and back
1516 * off to unlock its page lock before trying the dlm lock again.
1518 if (wait
&& arg_flags
& OCFS2_LOCK_NONBLOCK
&&
1519 mw
.mw_mask
& (OCFS2_LOCK_BUSY
|OCFS2_LOCK_BLOCKED
)) {
1521 if (lockres_remove_mask_waiter(lockres
, &mw
))
1527 ret
= ocfs2_wait_for_mask(&mw
);
1532 ocfs2_update_lock_stats(lockres
, level
, &mw
, ret
);
1534 #ifdef CONFIG_DEBUG_LOCK_ALLOC
1535 if (!ret
&& lockres
->l_lockdep_map
.key
!= NULL
) {
1536 if (level
== DLM_LOCK_PR
)
1537 rwsem_acquire_read(&lockres
->l_lockdep_map
, l_subclass
,
1538 !!(arg_flags
& OCFS2_META_LOCK_NOQUEUE
),
1541 rwsem_acquire(&lockres
->l_lockdep_map
, l_subclass
,
1542 !!(arg_flags
& OCFS2_META_LOCK_NOQUEUE
),
1549 static inline int ocfs2_cluster_lock(struct ocfs2_super
*osb
,
1550 struct ocfs2_lock_res
*lockres
,
1555 return __ocfs2_cluster_lock(osb
, lockres
, level
, lkm_flags
, arg_flags
,
1560 static void __ocfs2_cluster_unlock(struct ocfs2_super
*osb
,
1561 struct ocfs2_lock_res
*lockres
,
1563 unsigned long caller_ip
)
1565 unsigned long flags
;
1567 spin_lock_irqsave(&lockres
->l_lock
, flags
);
1568 ocfs2_dec_holders(lockres
, level
);
1569 ocfs2_downconvert_on_unlock(osb
, lockres
);
1570 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
1571 #ifdef CONFIG_DEBUG_LOCK_ALLOC
1572 if (lockres
->l_lockdep_map
.key
!= NULL
)
1573 rwsem_release(&lockres
->l_lockdep_map
, 1, caller_ip
);
1577 static int ocfs2_create_new_lock(struct ocfs2_super
*osb
,
1578 struct ocfs2_lock_res
*lockres
,
1582 int level
= ex
? DLM_LOCK_EX
: DLM_LOCK_PR
;
1583 unsigned long flags
;
1584 u32 lkm_flags
= local
? DLM_LKF_LOCAL
: 0;
1586 spin_lock_irqsave(&lockres
->l_lock
, flags
);
1587 BUG_ON(lockres
->l_flags
& OCFS2_LOCK_ATTACHED
);
1588 lockres_or_flags(lockres
, OCFS2_LOCK_LOCAL
);
1589 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
1591 return ocfs2_lock_create(osb
, lockres
, level
, lkm_flags
);
1594 /* Grants us an EX lock on the data and metadata resources, skipping
1595 * the normal cluster directory lookup. Use this ONLY on newly created
1596 * inodes which other nodes can't possibly see, and which haven't been
1597 * hashed in the inode hash yet. This can give us a good performance
1598 * increase as it'll skip the network broadcast normally associated
1599 * with creating a new lock resource. */
1600 int ocfs2_create_new_inode_locks(struct inode
*inode
)
1603 struct ocfs2_super
*osb
= OCFS2_SB(inode
->i_sb
);
1606 BUG_ON(!ocfs2_inode_is_new(inode
));
1608 mlog(0, "Inode %llu\n", (unsigned long long)OCFS2_I(inode
)->ip_blkno
);
1610 /* NOTE: That we don't increment any of the holder counts, nor
1611 * do we add anything to a journal handle. Since this is
1612 * supposed to be a new inode which the cluster doesn't know
1613 * about yet, there is no need to. As far as the LVB handling
1614 * is concerned, this is basically like acquiring an EX lock
1615 * on a resource which has an invalid one -- we'll set it
1616 * valid when we release the EX. */
1618 ret
= ocfs2_create_new_lock(osb
, &OCFS2_I(inode
)->ip_rw_lockres
, 1, 1);
1625 * We don't want to use DLM_LKF_LOCAL on a meta data lock as they
1626 * don't use a generation in their lock names.
1628 ret
= ocfs2_create_new_lock(osb
, &OCFS2_I(inode
)->ip_inode_lockres
, 1, 0);
1634 ret
= ocfs2_create_new_lock(osb
, &OCFS2_I(inode
)->ip_open_lockres
, 0, 0);
1644 int ocfs2_rw_lock(struct inode
*inode
, int write
)
1647 struct ocfs2_lock_res
*lockres
;
1648 struct ocfs2_super
*osb
= OCFS2_SB(inode
->i_sb
);
1652 mlog(0, "inode %llu take %s RW lock\n",
1653 (unsigned long long)OCFS2_I(inode
)->ip_blkno
,
1654 write
? "EXMODE" : "PRMODE");
1656 if (ocfs2_mount_local(osb
))
1659 lockres
= &OCFS2_I(inode
)->ip_rw_lockres
;
1661 level
= write
? DLM_LOCK_EX
: DLM_LOCK_PR
;
1663 status
= ocfs2_cluster_lock(OCFS2_SB(inode
->i_sb
), lockres
, level
, 0,
1671 void ocfs2_rw_unlock(struct inode
*inode
, int write
)
1673 int level
= write
? DLM_LOCK_EX
: DLM_LOCK_PR
;
1674 struct ocfs2_lock_res
*lockres
= &OCFS2_I(inode
)->ip_rw_lockres
;
1675 struct ocfs2_super
*osb
= OCFS2_SB(inode
->i_sb
);
1677 mlog(0, "inode %llu drop %s RW lock\n",
1678 (unsigned long long)OCFS2_I(inode
)->ip_blkno
,
1679 write
? "EXMODE" : "PRMODE");
1681 if (!ocfs2_mount_local(osb
))
1682 ocfs2_cluster_unlock(OCFS2_SB(inode
->i_sb
), lockres
, level
);
1686 * ocfs2_open_lock always get PR mode lock.
1688 int ocfs2_open_lock(struct inode
*inode
)
1691 struct ocfs2_lock_res
*lockres
;
1692 struct ocfs2_super
*osb
= OCFS2_SB(inode
->i_sb
);
1696 mlog(0, "inode %llu take PRMODE open lock\n",
1697 (unsigned long long)OCFS2_I(inode
)->ip_blkno
);
1699 if (ocfs2_mount_local(osb
))
1702 lockres
= &OCFS2_I(inode
)->ip_open_lockres
;
1704 status
= ocfs2_cluster_lock(OCFS2_SB(inode
->i_sb
), lockres
,
1713 int ocfs2_try_open_lock(struct inode
*inode
, int write
)
1715 int status
= 0, level
;
1716 struct ocfs2_lock_res
*lockres
;
1717 struct ocfs2_super
*osb
= OCFS2_SB(inode
->i_sb
);
1721 mlog(0, "inode %llu try to take %s open lock\n",
1722 (unsigned long long)OCFS2_I(inode
)->ip_blkno
,
1723 write
? "EXMODE" : "PRMODE");
1725 if (ocfs2_mount_local(osb
))
1728 lockres
= &OCFS2_I(inode
)->ip_open_lockres
;
1730 level
= write
? DLM_LOCK_EX
: DLM_LOCK_PR
;
1733 * The file system may already holding a PRMODE/EXMODE open lock.
1734 * Since we pass DLM_LKF_NOQUEUE, the request won't block waiting on
1735 * other nodes and the -EAGAIN will indicate to the caller that
1736 * this inode is still in use.
1738 status
= ocfs2_cluster_lock(OCFS2_SB(inode
->i_sb
), lockres
,
1739 level
, DLM_LKF_NOQUEUE
, 0);
1746 * ocfs2_open_unlock unlock PR and EX mode open locks.
1748 void ocfs2_open_unlock(struct inode
*inode
)
1750 struct ocfs2_lock_res
*lockres
= &OCFS2_I(inode
)->ip_open_lockres
;
1751 struct ocfs2_super
*osb
= OCFS2_SB(inode
->i_sb
);
1753 mlog(0, "inode %llu drop open lock\n",
1754 (unsigned long long)OCFS2_I(inode
)->ip_blkno
);
1756 if (ocfs2_mount_local(osb
))
1759 if(lockres
->l_ro_holders
)
1760 ocfs2_cluster_unlock(OCFS2_SB(inode
->i_sb
), lockres
,
1762 if(lockres
->l_ex_holders
)
1763 ocfs2_cluster_unlock(OCFS2_SB(inode
->i_sb
), lockres
,
1770 static int ocfs2_flock_handle_signal(struct ocfs2_lock_res
*lockres
,
1774 struct ocfs2_super
*osb
= ocfs2_get_lockres_osb(lockres
);
1775 unsigned long flags
;
1776 struct ocfs2_mask_waiter mw
;
1778 ocfs2_init_mask_waiter(&mw
);
1781 spin_lock_irqsave(&lockres
->l_lock
, flags
);
1782 if (lockres
->l_flags
& OCFS2_LOCK_BUSY
) {
1783 ret
= ocfs2_prepare_cancel_convert(osb
, lockres
);
1785 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
1786 ret
= ocfs2_cancel_convert(osb
, lockres
);
1793 lockres_add_mask_waiter(lockres
, &mw
, OCFS2_LOCK_BUSY
, 0);
1794 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
1796 ocfs2_wait_for_mask(&mw
);
1802 * We may still have gotten the lock, in which case there's no
1803 * point to restarting the syscall.
1805 if (lockres
->l_level
== level
)
1808 mlog(0, "Cancel returning %d. flags: 0x%lx, level: %d, act: %d\n", ret
,
1809 lockres
->l_flags
, lockres
->l_level
, lockres
->l_action
);
1811 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
1818 * ocfs2_file_lock() and ocfs2_file_unlock() map to a single pair of
1819 * flock() calls. The locking approach this requires is sufficiently
1820 * different from all other cluster lock types that we implement a
1821 * separate path to the "low-level" dlm calls. In particular:
1823 * - No optimization of lock levels is done - we take at exactly
1824 * what's been requested.
1826 * - No lock caching is employed. We immediately downconvert to
1827 * no-lock at unlock time. This also means flock locks never go on
1828 * the blocking list).
1830 * - Since userspace can trivially deadlock itself with flock, we make
1831 * sure to allow cancellation of a misbehaving applications flock()
1834 * - Access to any flock lockres doesn't require concurrency, so we
1835 * can simplify the code by requiring the caller to guarantee
1836 * serialization of dlmglue flock calls.
1838 int ocfs2_file_lock(struct file
*file
, int ex
, int trylock
)
1840 int ret
, level
= ex
? DLM_LOCK_EX
: DLM_LOCK_PR
;
1841 unsigned int lkm_flags
= trylock
? DLM_LKF_NOQUEUE
: 0;
1842 unsigned long flags
;
1843 struct ocfs2_file_private
*fp
= file
->private_data
;
1844 struct ocfs2_lock_res
*lockres
= &fp
->fp_flock
;
1845 struct ocfs2_super
*osb
= OCFS2_SB(file
->f_mapping
->host
->i_sb
);
1846 struct ocfs2_mask_waiter mw
;
1848 ocfs2_init_mask_waiter(&mw
);
1850 if ((lockres
->l_flags
& OCFS2_LOCK_BUSY
) ||
1851 (lockres
->l_level
> DLM_LOCK_NL
)) {
1853 "File lock \"%s\" has busy or locked state: flags: 0x%lx, "
1854 "level: %u\n", lockres
->l_name
, lockres
->l_flags
,
1859 spin_lock_irqsave(&lockres
->l_lock
, flags
);
1860 if (!(lockres
->l_flags
& OCFS2_LOCK_ATTACHED
)) {
1861 lockres_add_mask_waiter(lockres
, &mw
, OCFS2_LOCK_BUSY
, 0);
1862 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
1865 * Get the lock at NLMODE to start - that way we
1866 * can cancel the upconvert request if need be.
1868 ret
= ocfs2_lock_create(osb
, lockres
, DLM_LOCK_NL
, 0);
1874 ret
= ocfs2_wait_for_mask(&mw
);
1879 spin_lock_irqsave(&lockres
->l_lock
, flags
);
1882 lockres
->l_action
= OCFS2_AST_CONVERT
;
1883 lkm_flags
|= DLM_LKF_CONVERT
;
1884 lockres
->l_requested
= level
;
1885 lockres_or_flags(lockres
, OCFS2_LOCK_BUSY
);
1887 lockres_add_mask_waiter(lockres
, &mw
, OCFS2_LOCK_BUSY
, 0);
1888 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
1890 ret
= ocfs2_dlm_lock(osb
->cconn
, level
, &lockres
->l_lksb
, lkm_flags
,
1891 lockres
->l_name
, OCFS2_LOCK_ID_MAX_LEN
- 1);
1893 if (!trylock
|| (ret
!= -EAGAIN
)) {
1894 ocfs2_log_dlm_error("ocfs2_dlm_lock", ret
, lockres
);
1898 ocfs2_recover_from_dlm_error(lockres
, 1);
1899 lockres_remove_mask_waiter(lockres
, &mw
);
1903 ret
= ocfs2_wait_for_mask_interruptible(&mw
, lockres
);
1904 if (ret
== -ERESTARTSYS
) {
1906 * Userspace can cause deadlock itself with
1907 * flock(). Current behavior locally is to allow the
1908 * deadlock, but abort the system call if a signal is
1909 * received. We follow this example, otherwise a
1910 * poorly written program could sit in kernel until
1913 * Handling this is a bit more complicated for Ocfs2
1914 * though. We can't exit this function with an
1915 * outstanding lock request, so a cancel convert is
1916 * required. We intentionally overwrite 'ret' - if the
1917 * cancel fails and the lock was granted, it's easier
1918 * to just bubble success back up to the user.
1920 ret
= ocfs2_flock_handle_signal(lockres
, level
);
1921 } else if (!ret
&& (level
> lockres
->l_level
)) {
1922 /* Trylock failed asynchronously */
1929 mlog(0, "Lock: \"%s\" ex: %d, trylock: %d, returns: %d\n",
1930 lockres
->l_name
, ex
, trylock
, ret
);
1934 void ocfs2_file_unlock(struct file
*file
)
1938 unsigned long flags
;
1939 struct ocfs2_file_private
*fp
= file
->private_data
;
1940 struct ocfs2_lock_res
*lockres
= &fp
->fp_flock
;
1941 struct ocfs2_super
*osb
= OCFS2_SB(file
->f_mapping
->host
->i_sb
);
1942 struct ocfs2_mask_waiter mw
;
1944 ocfs2_init_mask_waiter(&mw
);
1946 if (!(lockres
->l_flags
& OCFS2_LOCK_ATTACHED
))
1949 if (lockres
->l_level
== DLM_LOCK_NL
)
1952 mlog(0, "Unlock: \"%s\" flags: 0x%lx, level: %d, act: %d\n",
1953 lockres
->l_name
, lockres
->l_flags
, lockres
->l_level
,
1956 spin_lock_irqsave(&lockres
->l_lock
, flags
);
1958 * Fake a blocking ast for the downconvert code.
1960 lockres_or_flags(lockres
, OCFS2_LOCK_BLOCKED
);
1961 lockres
->l_blocking
= DLM_LOCK_EX
;
1963 gen
= ocfs2_prepare_downconvert(lockres
, DLM_LOCK_NL
);
1964 lockres_add_mask_waiter(lockres
, &mw
, OCFS2_LOCK_BUSY
, 0);
1965 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
1967 ret
= ocfs2_downconvert_lock(osb
, lockres
, DLM_LOCK_NL
, 0, gen
);
1973 ret
= ocfs2_wait_for_mask(&mw
);
1978 static void ocfs2_downconvert_on_unlock(struct ocfs2_super
*osb
,
1979 struct ocfs2_lock_res
*lockres
)
1983 /* If we know that another node is waiting on our lock, kick
1984 * the downconvert thread * pre-emptively when we reach a release
1986 if (lockres
->l_flags
& OCFS2_LOCK_BLOCKED
) {
1987 switch(lockres
->l_blocking
) {
1989 if (!lockres
->l_ex_holders
&& !lockres
->l_ro_holders
)
1993 if (!lockres
->l_ex_holders
)
2002 ocfs2_wake_downconvert_thread(osb
);
2005 #define OCFS2_SEC_BITS 34
2006 #define OCFS2_SEC_SHIFT (64 - 34)
2007 #define OCFS2_NSEC_MASK ((1ULL << OCFS2_SEC_SHIFT) - 1)
2009 /* LVB only has room for 64 bits of time here so we pack it for
2011 static u64
ocfs2_pack_timespec(struct timespec
*spec
)
2014 u64 sec
= spec
->tv_sec
;
2015 u32 nsec
= spec
->tv_nsec
;
2017 res
= (sec
<< OCFS2_SEC_SHIFT
) | (nsec
& OCFS2_NSEC_MASK
);
2022 /* Call this with the lockres locked. I am reasonably sure we don't
2023 * need ip_lock in this function as anyone who would be changing those
2024 * values is supposed to be blocked in ocfs2_inode_lock right now. */
2025 static void __ocfs2_stuff_meta_lvb(struct inode
*inode
)
2027 struct ocfs2_inode_info
*oi
= OCFS2_I(inode
);
2028 struct ocfs2_lock_res
*lockres
= &oi
->ip_inode_lockres
;
2029 struct ocfs2_meta_lvb
*lvb
;
2031 lvb
= ocfs2_dlm_lvb(&lockres
->l_lksb
);
2034 * Invalidate the LVB of a deleted inode - this way other
2035 * nodes are forced to go to disk and discover the new inode
2038 if (oi
->ip_flags
& OCFS2_INODE_DELETED
) {
2039 lvb
->lvb_version
= 0;
2043 lvb
->lvb_version
= OCFS2_LVB_VERSION
;
2044 lvb
->lvb_isize
= cpu_to_be64(i_size_read(inode
));
2045 lvb
->lvb_iclusters
= cpu_to_be32(oi
->ip_clusters
);
2046 lvb
->lvb_iuid
= cpu_to_be32(inode
->i_uid
);
2047 lvb
->lvb_igid
= cpu_to_be32(inode
->i_gid
);
2048 lvb
->lvb_imode
= cpu_to_be16(inode
->i_mode
);
2049 lvb
->lvb_inlink
= cpu_to_be16(inode
->i_nlink
);
2050 lvb
->lvb_iatime_packed
=
2051 cpu_to_be64(ocfs2_pack_timespec(&inode
->i_atime
));
2052 lvb
->lvb_ictime_packed
=
2053 cpu_to_be64(ocfs2_pack_timespec(&inode
->i_ctime
));
2054 lvb
->lvb_imtime_packed
=
2055 cpu_to_be64(ocfs2_pack_timespec(&inode
->i_mtime
));
2056 lvb
->lvb_iattr
= cpu_to_be32(oi
->ip_attr
);
2057 lvb
->lvb_idynfeatures
= cpu_to_be16(oi
->ip_dyn_features
);
2058 lvb
->lvb_igeneration
= cpu_to_be32(inode
->i_generation
);
2061 mlog_meta_lvb(0, lockres
);
2064 static void ocfs2_unpack_timespec(struct timespec
*spec
,
2067 spec
->tv_sec
= packed_time
>> OCFS2_SEC_SHIFT
;
2068 spec
->tv_nsec
= packed_time
& OCFS2_NSEC_MASK
;
2071 static void ocfs2_refresh_inode_from_lvb(struct inode
*inode
)
2073 struct ocfs2_inode_info
*oi
= OCFS2_I(inode
);
2074 struct ocfs2_lock_res
*lockres
= &oi
->ip_inode_lockres
;
2075 struct ocfs2_meta_lvb
*lvb
;
2077 mlog_meta_lvb(0, lockres
);
2079 lvb
= ocfs2_dlm_lvb(&lockres
->l_lksb
);
2081 /* We're safe here without the lockres lock... */
2082 spin_lock(&oi
->ip_lock
);
2083 oi
->ip_clusters
= be32_to_cpu(lvb
->lvb_iclusters
);
2084 i_size_write(inode
, be64_to_cpu(lvb
->lvb_isize
));
2086 oi
->ip_attr
= be32_to_cpu(lvb
->lvb_iattr
);
2087 oi
->ip_dyn_features
= be16_to_cpu(lvb
->lvb_idynfeatures
);
2088 ocfs2_set_inode_flags(inode
);
2090 /* fast-symlinks are a special case */
2091 if (S_ISLNK(inode
->i_mode
) && !oi
->ip_clusters
)
2092 inode
->i_blocks
= 0;
2094 inode
->i_blocks
= ocfs2_inode_sector_count(inode
);
2096 inode
->i_uid
= be32_to_cpu(lvb
->lvb_iuid
);
2097 inode
->i_gid
= be32_to_cpu(lvb
->lvb_igid
);
2098 inode
->i_mode
= be16_to_cpu(lvb
->lvb_imode
);
2099 inode
->i_nlink
= be16_to_cpu(lvb
->lvb_inlink
);
2100 ocfs2_unpack_timespec(&inode
->i_atime
,
2101 be64_to_cpu(lvb
->lvb_iatime_packed
));
2102 ocfs2_unpack_timespec(&inode
->i_mtime
,
2103 be64_to_cpu(lvb
->lvb_imtime_packed
));
2104 ocfs2_unpack_timespec(&inode
->i_ctime
,
2105 be64_to_cpu(lvb
->lvb_ictime_packed
));
2106 spin_unlock(&oi
->ip_lock
);
2109 static inline int ocfs2_meta_lvb_is_trustable(struct inode
*inode
,
2110 struct ocfs2_lock_res
*lockres
)
2112 struct ocfs2_meta_lvb
*lvb
= ocfs2_dlm_lvb(&lockres
->l_lksb
);
2114 if (ocfs2_dlm_lvb_valid(&lockres
->l_lksb
)
2115 && lvb
->lvb_version
== OCFS2_LVB_VERSION
2116 && be32_to_cpu(lvb
->lvb_igeneration
) == inode
->i_generation
)
2121 /* Determine whether a lock resource needs to be refreshed, and
2122 * arbitrate who gets to refresh it.
2124 * 0 means no refresh needed.
2126 * > 0 means you need to refresh this and you MUST call
2127 * ocfs2_complete_lock_res_refresh afterwards. */
2128 static int ocfs2_should_refresh_lock_res(struct ocfs2_lock_res
*lockres
)
2130 unsigned long flags
;
2134 spin_lock_irqsave(&lockres
->l_lock
, flags
);
2135 if (!(lockres
->l_flags
& OCFS2_LOCK_NEEDS_REFRESH
)) {
2136 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
2140 if (lockres
->l_flags
& OCFS2_LOCK_REFRESHING
) {
2141 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
2143 ocfs2_wait_on_refreshing_lock(lockres
);
2147 /* Ok, I'll be the one to refresh this lock. */
2148 lockres_or_flags(lockres
, OCFS2_LOCK_REFRESHING
);
2149 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
2153 mlog(0, "status %d\n", status
);
2157 /* If status is non zero, I'll mark it as not being in refresh
2158 * anymroe, but i won't clear the needs refresh flag. */
2159 static inline void ocfs2_complete_lock_res_refresh(struct ocfs2_lock_res
*lockres
,
2162 unsigned long flags
;
2164 spin_lock_irqsave(&lockres
->l_lock
, flags
);
2165 lockres_clear_flags(lockres
, OCFS2_LOCK_REFRESHING
);
2167 lockres_clear_flags(lockres
, OCFS2_LOCK_NEEDS_REFRESH
);
2168 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
2170 wake_up(&lockres
->l_event
);
2173 /* may or may not return a bh if it went to disk. */
2174 static int ocfs2_inode_lock_update(struct inode
*inode
,
2175 struct buffer_head
**bh
)
2178 struct ocfs2_inode_info
*oi
= OCFS2_I(inode
);
2179 struct ocfs2_lock_res
*lockres
= &oi
->ip_inode_lockres
;
2180 struct ocfs2_dinode
*fe
;
2181 struct ocfs2_super
*osb
= OCFS2_SB(inode
->i_sb
);
2183 if (ocfs2_mount_local(osb
))
2186 spin_lock(&oi
->ip_lock
);
2187 if (oi
->ip_flags
& OCFS2_INODE_DELETED
) {
2188 mlog(0, "Orphaned inode %llu was deleted while we "
2189 "were waiting on a lock. ip_flags = 0x%x\n",
2190 (unsigned long long)oi
->ip_blkno
, oi
->ip_flags
);
2191 spin_unlock(&oi
->ip_lock
);
2195 spin_unlock(&oi
->ip_lock
);
2197 if (!ocfs2_should_refresh_lock_res(lockres
))
2200 /* This will discard any caching information we might have had
2201 * for the inode metadata. */
2202 ocfs2_metadata_cache_purge(INODE_CACHE(inode
));
2204 ocfs2_extent_map_trunc(inode
, 0);
2206 if (ocfs2_meta_lvb_is_trustable(inode
, lockres
)) {
2207 mlog(0, "Trusting LVB on inode %llu\n",
2208 (unsigned long long)oi
->ip_blkno
);
2209 ocfs2_refresh_inode_from_lvb(inode
);
2211 /* Boo, we have to go to disk. */
2212 /* read bh, cast, ocfs2_refresh_inode */
2213 status
= ocfs2_read_inode_block(inode
, bh
);
2218 fe
= (struct ocfs2_dinode
*) (*bh
)->b_data
;
2220 /* This is a good chance to make sure we're not
2221 * locking an invalid object. ocfs2_read_inode_block()
2222 * already checked that the inode block is sane.
2224 * We bug on a stale inode here because we checked
2225 * above whether it was wiped from disk. The wiping
2226 * node provides a guarantee that we receive that
2227 * message and can mark the inode before dropping any
2228 * locks associated with it. */
2229 mlog_bug_on_msg(inode
->i_generation
!=
2230 le32_to_cpu(fe
->i_generation
),
2231 "Invalid dinode %llu disk generation: %u "
2232 "inode->i_generation: %u\n",
2233 (unsigned long long)oi
->ip_blkno
,
2234 le32_to_cpu(fe
->i_generation
),
2235 inode
->i_generation
);
2236 mlog_bug_on_msg(le64_to_cpu(fe
->i_dtime
) ||
2237 !(fe
->i_flags
& cpu_to_le32(OCFS2_VALID_FL
)),
2238 "Stale dinode %llu dtime: %llu flags: 0x%x\n",
2239 (unsigned long long)oi
->ip_blkno
,
2240 (unsigned long long)le64_to_cpu(fe
->i_dtime
),
2241 le32_to_cpu(fe
->i_flags
));
2243 ocfs2_refresh_inode(inode
, fe
);
2244 ocfs2_track_lock_refresh(lockres
);
2249 ocfs2_complete_lock_res_refresh(lockres
, status
);
2254 static int ocfs2_assign_bh(struct inode
*inode
,
2255 struct buffer_head
**ret_bh
,
2256 struct buffer_head
*passed_bh
)
2261 /* Ok, the update went to disk for us, use the
2263 *ret_bh
= passed_bh
;
2269 status
= ocfs2_read_inode_block(inode
, ret_bh
);
2277 * returns < 0 error if the callback will never be called, otherwise
2278 * the result of the lock will be communicated via the callback.
2280 int ocfs2_inode_lock_full_nested(struct inode
*inode
,
2281 struct buffer_head
**ret_bh
,
2286 int status
, level
, acquired
;
2288 struct ocfs2_lock_res
*lockres
= NULL
;
2289 struct ocfs2_super
*osb
= OCFS2_SB(inode
->i_sb
);
2290 struct buffer_head
*local_bh
= NULL
;
2294 mlog(0, "inode %llu, take %s META lock\n",
2295 (unsigned long long)OCFS2_I(inode
)->ip_blkno
,
2296 ex
? "EXMODE" : "PRMODE");
2300 /* We'll allow faking a readonly metadata lock for
2302 if (ocfs2_is_hard_readonly(osb
)) {
2308 if (ocfs2_mount_local(osb
))
2311 if (!(arg_flags
& OCFS2_META_LOCK_RECOVERY
))
2312 ocfs2_wait_for_recovery(osb
);
2314 lockres
= &OCFS2_I(inode
)->ip_inode_lockres
;
2315 level
= ex
? DLM_LOCK_EX
: DLM_LOCK_PR
;
2317 if (arg_flags
& OCFS2_META_LOCK_NOQUEUE
)
2318 dlm_flags
|= DLM_LKF_NOQUEUE
;
2320 status
= __ocfs2_cluster_lock(osb
, lockres
, level
, dlm_flags
,
2321 arg_flags
, subclass
, _RET_IP_
);
2323 if (status
!= -EAGAIN
&& status
!= -EIOCBRETRY
)
2328 /* Notify the error cleanup path to drop the cluster lock. */
2331 /* We wait twice because a node may have died while we were in
2332 * the lower dlm layers. The second time though, we've
2333 * committed to owning this lock so we don't allow signals to
2334 * abort the operation. */
2335 if (!(arg_flags
& OCFS2_META_LOCK_RECOVERY
))
2336 ocfs2_wait_for_recovery(osb
);
2340 * We only see this flag if we're being called from
2341 * ocfs2_read_locked_inode(). It means we're locking an inode
2342 * which hasn't been populated yet, so clear the refresh flag
2343 * and let the caller handle it.
2345 if (inode
->i_state
& I_NEW
) {
2348 ocfs2_complete_lock_res_refresh(lockres
, 0);
2352 /* This is fun. The caller may want a bh back, or it may
2353 * not. ocfs2_inode_lock_update definitely wants one in, but
2354 * may or may not read one, depending on what's in the
2355 * LVB. The result of all of this is that we've *only* gone to
2356 * disk if we have to, so the complexity is worthwhile. */
2357 status
= ocfs2_inode_lock_update(inode
, &local_bh
);
2359 if (status
!= -ENOENT
)
2365 status
= ocfs2_assign_bh(inode
, ret_bh
, local_bh
);
2374 if (ret_bh
&& (*ret_bh
)) {
2379 ocfs2_inode_unlock(inode
, ex
);
2389 * This is working around a lock inversion between tasks acquiring DLM
2390 * locks while holding a page lock and the downconvert thread which
2391 * blocks dlm lock acquiry while acquiring page locks.
2393 * ** These _with_page variantes are only intended to be called from aop
2394 * methods that hold page locks and return a very specific *positive* error
2395 * code that aop methods pass up to the VFS -- test for errors with != 0. **
2397 * The DLM is called such that it returns -EAGAIN if it would have
2398 * blocked waiting for the downconvert thread. In that case we unlock
2399 * our page so the downconvert thread can make progress. Once we've
2400 * done this we have to return AOP_TRUNCATED_PAGE so the aop method
2401 * that called us can bubble that back up into the VFS who will then
2402 * immediately retry the aop call.
2404 * We do a blocking lock and immediate unlock before returning, though, so that
2405 * the lock has a great chance of being cached on this node by the time the VFS
2406 * calls back to retry the aop. This has a potential to livelock as nodes
2407 * ping locks back and forth, but that's a risk we're willing to take to avoid
2408 * the lock inversion simply.
2410 int ocfs2_inode_lock_with_page(struct inode
*inode
,
2411 struct buffer_head
**ret_bh
,
2417 ret
= ocfs2_inode_lock_full(inode
, ret_bh
, ex
, OCFS2_LOCK_NONBLOCK
);
2418 if (ret
== -EAGAIN
) {
2420 if (ocfs2_inode_lock(inode
, ret_bh
, ex
) == 0)
2421 ocfs2_inode_unlock(inode
, ex
);
2422 ret
= AOP_TRUNCATED_PAGE
;
2428 int ocfs2_inode_lock_atime(struct inode
*inode
,
2429 struct vfsmount
*vfsmnt
,
2434 ret
= ocfs2_inode_lock(inode
, NULL
, 0);
2441 * If we should update atime, we will get EX lock,
2442 * otherwise we just get PR lock.
2444 if (ocfs2_should_update_atime(inode
, vfsmnt
)) {
2445 struct buffer_head
*bh
= NULL
;
2447 ocfs2_inode_unlock(inode
, 0);
2448 ret
= ocfs2_inode_lock(inode
, &bh
, 1);
2454 if (ocfs2_should_update_atime(inode
, vfsmnt
))
2455 ocfs2_update_inode_atime(inode
, bh
);
2464 void ocfs2_inode_unlock(struct inode
*inode
,
2467 int level
= ex
? DLM_LOCK_EX
: DLM_LOCK_PR
;
2468 struct ocfs2_lock_res
*lockres
= &OCFS2_I(inode
)->ip_inode_lockres
;
2469 struct ocfs2_super
*osb
= OCFS2_SB(inode
->i_sb
);
2471 mlog(0, "inode %llu drop %s META lock\n",
2472 (unsigned long long)OCFS2_I(inode
)->ip_blkno
,
2473 ex
? "EXMODE" : "PRMODE");
2475 if (!ocfs2_is_hard_readonly(OCFS2_SB(inode
->i_sb
)) &&
2476 !ocfs2_mount_local(osb
))
2477 ocfs2_cluster_unlock(OCFS2_SB(inode
->i_sb
), lockres
, level
);
2480 int ocfs2_orphan_scan_lock(struct ocfs2_super
*osb
, u32
*seqno
)
2482 struct ocfs2_lock_res
*lockres
;
2483 struct ocfs2_orphan_scan_lvb
*lvb
;
2486 if (ocfs2_is_hard_readonly(osb
))
2489 if (ocfs2_mount_local(osb
))
2492 lockres
= &osb
->osb_orphan_scan
.os_lockres
;
2493 status
= ocfs2_cluster_lock(osb
, lockres
, DLM_LOCK_EX
, 0, 0);
2497 lvb
= ocfs2_dlm_lvb(&lockres
->l_lksb
);
2498 if (ocfs2_dlm_lvb_valid(&lockres
->l_lksb
) &&
2499 lvb
->lvb_version
== OCFS2_ORPHAN_LVB_VERSION
)
2500 *seqno
= be32_to_cpu(lvb
->lvb_os_seqno
);
2502 *seqno
= osb
->osb_orphan_scan
.os_seqno
+ 1;
2507 void ocfs2_orphan_scan_unlock(struct ocfs2_super
*osb
, u32 seqno
)
2509 struct ocfs2_lock_res
*lockres
;
2510 struct ocfs2_orphan_scan_lvb
*lvb
;
2512 if (!ocfs2_is_hard_readonly(osb
) && !ocfs2_mount_local(osb
)) {
2513 lockres
= &osb
->osb_orphan_scan
.os_lockres
;
2514 lvb
= ocfs2_dlm_lvb(&lockres
->l_lksb
);
2515 lvb
->lvb_version
= OCFS2_ORPHAN_LVB_VERSION
;
2516 lvb
->lvb_os_seqno
= cpu_to_be32(seqno
);
2517 ocfs2_cluster_unlock(osb
, lockres
, DLM_LOCK_EX
);
2521 int ocfs2_super_lock(struct ocfs2_super
*osb
,
2525 int level
= ex
? DLM_LOCK_EX
: DLM_LOCK_PR
;
2526 struct ocfs2_lock_res
*lockres
= &osb
->osb_super_lockres
;
2528 if (ocfs2_is_hard_readonly(osb
))
2531 if (ocfs2_mount_local(osb
))
2534 status
= ocfs2_cluster_lock(osb
, lockres
, level
, 0, 0);
2540 /* The super block lock path is really in the best position to
2541 * know when resources covered by the lock need to be
2542 * refreshed, so we do it here. Of course, making sense of
2543 * everything is up to the caller :) */
2544 status
= ocfs2_should_refresh_lock_res(lockres
);
2550 status
= ocfs2_refresh_slot_info(osb
);
2552 ocfs2_complete_lock_res_refresh(lockres
, status
);
2556 ocfs2_track_lock_refresh(lockres
);
2562 void ocfs2_super_unlock(struct ocfs2_super
*osb
,
2565 int level
= ex
? DLM_LOCK_EX
: DLM_LOCK_PR
;
2566 struct ocfs2_lock_res
*lockres
= &osb
->osb_super_lockres
;
2568 if (!ocfs2_mount_local(osb
))
2569 ocfs2_cluster_unlock(osb
, lockres
, level
);
2572 int ocfs2_rename_lock(struct ocfs2_super
*osb
)
2575 struct ocfs2_lock_res
*lockres
= &osb
->osb_rename_lockres
;
2577 if (ocfs2_is_hard_readonly(osb
))
2580 if (ocfs2_mount_local(osb
))
2583 status
= ocfs2_cluster_lock(osb
, lockres
, DLM_LOCK_EX
, 0, 0);
2590 void ocfs2_rename_unlock(struct ocfs2_super
*osb
)
2592 struct ocfs2_lock_res
*lockres
= &osb
->osb_rename_lockres
;
2594 if (!ocfs2_mount_local(osb
))
2595 ocfs2_cluster_unlock(osb
, lockres
, DLM_LOCK_EX
);
2598 int ocfs2_nfs_sync_lock(struct ocfs2_super
*osb
, int ex
)
2601 struct ocfs2_lock_res
*lockres
= &osb
->osb_nfs_sync_lockres
;
2603 if (ocfs2_is_hard_readonly(osb
))
2606 if (ocfs2_mount_local(osb
))
2609 status
= ocfs2_cluster_lock(osb
, lockres
, ex
? LKM_EXMODE
: LKM_PRMODE
,
2612 mlog(ML_ERROR
, "lock on nfs sync lock failed %d\n", status
);
2617 void ocfs2_nfs_sync_unlock(struct ocfs2_super
*osb
, int ex
)
2619 struct ocfs2_lock_res
*lockres
= &osb
->osb_nfs_sync_lockres
;
2621 if (!ocfs2_mount_local(osb
))
2622 ocfs2_cluster_unlock(osb
, lockres
,
2623 ex
? LKM_EXMODE
: LKM_PRMODE
);
2626 int ocfs2_dentry_lock(struct dentry
*dentry
, int ex
)
2629 int level
= ex
? DLM_LOCK_EX
: DLM_LOCK_PR
;
2630 struct ocfs2_dentry_lock
*dl
= dentry
->d_fsdata
;
2631 struct ocfs2_super
*osb
= OCFS2_SB(dentry
->d_sb
);
2635 if (ocfs2_is_hard_readonly(osb
))
2638 if (ocfs2_mount_local(osb
))
2641 ret
= ocfs2_cluster_lock(osb
, &dl
->dl_lockres
, level
, 0, 0);
2648 void ocfs2_dentry_unlock(struct dentry
*dentry
, int ex
)
2650 int level
= ex
? DLM_LOCK_EX
: DLM_LOCK_PR
;
2651 struct ocfs2_dentry_lock
*dl
= dentry
->d_fsdata
;
2652 struct ocfs2_super
*osb
= OCFS2_SB(dentry
->d_sb
);
2654 if (!ocfs2_mount_local(osb
))
2655 ocfs2_cluster_unlock(osb
, &dl
->dl_lockres
, level
);
2658 /* Reference counting of the dlm debug structure. We want this because
2659 * open references on the debug inodes can live on after a mount, so
2660 * we can't rely on the ocfs2_super to always exist. */
2661 static void ocfs2_dlm_debug_free(struct kref
*kref
)
2663 struct ocfs2_dlm_debug
*dlm_debug
;
2665 dlm_debug
= container_of(kref
, struct ocfs2_dlm_debug
, d_refcnt
);
2670 void ocfs2_put_dlm_debug(struct ocfs2_dlm_debug
*dlm_debug
)
2673 kref_put(&dlm_debug
->d_refcnt
, ocfs2_dlm_debug_free
);
2676 static void ocfs2_get_dlm_debug(struct ocfs2_dlm_debug
*debug
)
2678 kref_get(&debug
->d_refcnt
);
2681 struct ocfs2_dlm_debug
*ocfs2_new_dlm_debug(void)
2683 struct ocfs2_dlm_debug
*dlm_debug
;
2685 dlm_debug
= kmalloc(sizeof(struct ocfs2_dlm_debug
), GFP_KERNEL
);
2687 mlog_errno(-ENOMEM
);
2691 kref_init(&dlm_debug
->d_refcnt
);
2692 INIT_LIST_HEAD(&dlm_debug
->d_lockres_tracking
);
2693 dlm_debug
->d_locking_state
= NULL
;
2698 /* Access to this is arbitrated for us via seq_file->sem. */
2699 struct ocfs2_dlm_seq_priv
{
2700 struct ocfs2_dlm_debug
*p_dlm_debug
;
2701 struct ocfs2_lock_res p_iter_res
;
2702 struct ocfs2_lock_res p_tmp_res
;
2705 static struct ocfs2_lock_res
*ocfs2_dlm_next_res(struct ocfs2_lock_res
*start
,
2706 struct ocfs2_dlm_seq_priv
*priv
)
2708 struct ocfs2_lock_res
*iter
, *ret
= NULL
;
2709 struct ocfs2_dlm_debug
*dlm_debug
= priv
->p_dlm_debug
;
2711 assert_spin_locked(&ocfs2_dlm_tracking_lock
);
2713 list_for_each_entry(iter
, &start
->l_debug_list
, l_debug_list
) {
2714 /* discover the head of the list */
2715 if (&iter
->l_debug_list
== &dlm_debug
->d_lockres_tracking
) {
2716 mlog(0, "End of list found, %p\n", ret
);
2720 /* We track our "dummy" iteration lockres' by a NULL
2722 if (iter
->l_ops
!= NULL
) {
2731 static void *ocfs2_dlm_seq_start(struct seq_file
*m
, loff_t
*pos
)
2733 struct ocfs2_dlm_seq_priv
*priv
= m
->private;
2734 struct ocfs2_lock_res
*iter
;
2736 spin_lock(&ocfs2_dlm_tracking_lock
);
2737 iter
= ocfs2_dlm_next_res(&priv
->p_iter_res
, priv
);
2739 /* Since lockres' have the lifetime of their container
2740 * (which can be inodes, ocfs2_supers, etc) we want to
2741 * copy this out to a temporary lockres while still
2742 * under the spinlock. Obviously after this we can't
2743 * trust any pointers on the copy returned, but that's
2744 * ok as the information we want isn't typically held
2746 priv
->p_tmp_res
= *iter
;
2747 iter
= &priv
->p_tmp_res
;
2749 spin_unlock(&ocfs2_dlm_tracking_lock
);
2754 static void ocfs2_dlm_seq_stop(struct seq_file
*m
, void *v
)
2758 static void *ocfs2_dlm_seq_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
2760 struct ocfs2_dlm_seq_priv
*priv
= m
->private;
2761 struct ocfs2_lock_res
*iter
= v
;
2762 struct ocfs2_lock_res
*dummy
= &priv
->p_iter_res
;
2764 spin_lock(&ocfs2_dlm_tracking_lock
);
2765 iter
= ocfs2_dlm_next_res(iter
, priv
);
2766 list_del_init(&dummy
->l_debug_list
);
2768 list_add(&dummy
->l_debug_list
, &iter
->l_debug_list
);
2769 priv
->p_tmp_res
= *iter
;
2770 iter
= &priv
->p_tmp_res
;
2772 spin_unlock(&ocfs2_dlm_tracking_lock
);
2777 /* So that debugfs.ocfs2 can determine which format is being used */
2778 #define OCFS2_DLM_DEBUG_STR_VERSION 2
2779 static int ocfs2_dlm_seq_show(struct seq_file
*m
, void *v
)
2783 struct ocfs2_lock_res
*lockres
= v
;
2788 seq_printf(m
, "0x%x\t", OCFS2_DLM_DEBUG_STR_VERSION
);
2790 if (lockres
->l_type
== OCFS2_LOCK_TYPE_DENTRY
)
2791 seq_printf(m
, "%.*s%08x\t", OCFS2_DENTRY_LOCK_INO_START
- 1,
2793 (unsigned int)ocfs2_get_dentry_lock_ino(lockres
));
2795 seq_printf(m
, "%.*s\t", OCFS2_LOCK_ID_MAX_LEN
, lockres
->l_name
);
2797 seq_printf(m
, "%d\t"
2808 lockres
->l_unlock_action
,
2809 lockres
->l_ro_holders
,
2810 lockres
->l_ex_holders
,
2811 lockres
->l_requested
,
2812 lockres
->l_blocking
);
2814 /* Dump the raw LVB */
2815 lvb
= ocfs2_dlm_lvb(&lockres
->l_lksb
);
2816 for(i
= 0; i
< DLM_LVB_LEN
; i
++)
2817 seq_printf(m
, "0x%x\t", lvb
[i
]);
2819 #ifdef CONFIG_OCFS2_FS_STATS
2820 # define lock_num_prmode(_l) (_l)->l_lock_num_prmode
2821 # define lock_num_exmode(_l) (_l)->l_lock_num_exmode
2822 # define lock_num_prmode_failed(_l) (_l)->l_lock_num_prmode_failed
2823 # define lock_num_exmode_failed(_l) (_l)->l_lock_num_exmode_failed
2824 # define lock_total_prmode(_l) (_l)->l_lock_total_prmode
2825 # define lock_total_exmode(_l) (_l)->l_lock_total_exmode
2826 # define lock_max_prmode(_l) (_l)->l_lock_max_prmode
2827 # define lock_max_exmode(_l) (_l)->l_lock_max_exmode
2828 # define lock_refresh(_l) (_l)->l_lock_refresh
2830 # define lock_num_prmode(_l) (0ULL)
2831 # define lock_num_exmode(_l) (0ULL)
2832 # define lock_num_prmode_failed(_l) (0)
2833 # define lock_num_exmode_failed(_l) (0)
2834 # define lock_total_prmode(_l) (0ULL)
2835 # define lock_total_exmode(_l) (0ULL)
2836 # define lock_max_prmode(_l) (0)
2837 # define lock_max_exmode(_l) (0)
2838 # define lock_refresh(_l) (0)
2840 /* The following seq_print was added in version 2 of this output */
2841 seq_printf(m
, "%llu\t"
2850 lock_num_prmode(lockres
),
2851 lock_num_exmode(lockres
),
2852 lock_num_prmode_failed(lockres
),
2853 lock_num_exmode_failed(lockres
),
2854 lock_total_prmode(lockres
),
2855 lock_total_exmode(lockres
),
2856 lock_max_prmode(lockres
),
2857 lock_max_exmode(lockres
),
2858 lock_refresh(lockres
));
2861 seq_printf(m
, "\n");
2865 static const struct seq_operations ocfs2_dlm_seq_ops
= {
2866 .start
= ocfs2_dlm_seq_start
,
2867 .stop
= ocfs2_dlm_seq_stop
,
2868 .next
= ocfs2_dlm_seq_next
,
2869 .show
= ocfs2_dlm_seq_show
,
2872 static int ocfs2_dlm_debug_release(struct inode
*inode
, struct file
*file
)
2874 struct seq_file
*seq
= file
->private_data
;
2875 struct ocfs2_dlm_seq_priv
*priv
= seq
->private;
2876 struct ocfs2_lock_res
*res
= &priv
->p_iter_res
;
2878 ocfs2_remove_lockres_tracking(res
);
2879 ocfs2_put_dlm_debug(priv
->p_dlm_debug
);
2880 return seq_release_private(inode
, file
);
2883 static int ocfs2_dlm_debug_open(struct inode
*inode
, struct file
*file
)
2886 struct ocfs2_dlm_seq_priv
*priv
;
2887 struct seq_file
*seq
;
2888 struct ocfs2_super
*osb
;
2890 priv
= kzalloc(sizeof(struct ocfs2_dlm_seq_priv
), GFP_KERNEL
);
2896 osb
= inode
->i_private
;
2897 ocfs2_get_dlm_debug(osb
->osb_dlm_debug
);
2898 priv
->p_dlm_debug
= osb
->osb_dlm_debug
;
2899 INIT_LIST_HEAD(&priv
->p_iter_res
.l_debug_list
);
2901 ret
= seq_open(file
, &ocfs2_dlm_seq_ops
);
2908 seq
= file
->private_data
;
2909 seq
->private = priv
;
2911 ocfs2_add_lockres_tracking(&priv
->p_iter_res
,
2918 static const struct file_operations ocfs2_dlm_debug_fops
= {
2919 .open
= ocfs2_dlm_debug_open
,
2920 .release
= ocfs2_dlm_debug_release
,
2922 .llseek
= seq_lseek
,
2925 static int ocfs2_dlm_init_debug(struct ocfs2_super
*osb
)
2928 struct ocfs2_dlm_debug
*dlm_debug
= osb
->osb_dlm_debug
;
2930 dlm_debug
->d_locking_state
= debugfs_create_file("locking_state",
2932 osb
->osb_debug_root
,
2934 &ocfs2_dlm_debug_fops
);
2935 if (!dlm_debug
->d_locking_state
) {
2938 "Unable to create locking state debugfs file.\n");
2942 ocfs2_get_dlm_debug(dlm_debug
);
2947 static void ocfs2_dlm_shutdown_debug(struct ocfs2_super
*osb
)
2949 struct ocfs2_dlm_debug
*dlm_debug
= osb
->osb_dlm_debug
;
2952 debugfs_remove(dlm_debug
->d_locking_state
);
2953 ocfs2_put_dlm_debug(dlm_debug
);
2957 int ocfs2_dlm_init(struct ocfs2_super
*osb
)
2960 struct ocfs2_cluster_connection
*conn
= NULL
;
2962 if (ocfs2_mount_local(osb
)) {
2967 status
= ocfs2_dlm_init_debug(osb
);
2973 /* launch downconvert thread */
2974 osb
->dc_task
= kthread_run(ocfs2_downconvert_thread
, osb
, "ocfs2dc");
2975 if (IS_ERR(osb
->dc_task
)) {
2976 status
= PTR_ERR(osb
->dc_task
);
2977 osb
->dc_task
= NULL
;
2982 /* for now, uuid == domain */
2983 status
= ocfs2_cluster_connect(osb
->osb_cluster_stack
,
2985 strlen(osb
->uuid_str
),
2986 &lproto
, ocfs2_do_node_down
, osb
,
2993 status
= ocfs2_cluster_this_node(&osb
->node_num
);
2997 "could not find this host's node number\n");
2998 ocfs2_cluster_disconnect(conn
, 0);
3003 ocfs2_super_lock_res_init(&osb
->osb_super_lockres
, osb
);
3004 ocfs2_rename_lock_res_init(&osb
->osb_rename_lockres
, osb
);
3005 ocfs2_nfs_sync_lock_res_init(&osb
->osb_nfs_sync_lockres
, osb
);
3006 ocfs2_orphan_scan_lock_res_init(&osb
->osb_orphan_scan
.os_lockres
, osb
);
3013 ocfs2_dlm_shutdown_debug(osb
);
3015 kthread_stop(osb
->dc_task
);
3021 void ocfs2_dlm_shutdown(struct ocfs2_super
*osb
,
3024 ocfs2_drop_osb_locks(osb
);
3027 * Now that we have dropped all locks and ocfs2_dismount_volume()
3028 * has disabled recovery, the DLM won't be talking to us. It's
3029 * safe to tear things down before disconnecting the cluster.
3033 kthread_stop(osb
->dc_task
);
3034 osb
->dc_task
= NULL
;
3037 ocfs2_lock_res_free(&osb
->osb_super_lockres
);
3038 ocfs2_lock_res_free(&osb
->osb_rename_lockres
);
3039 ocfs2_lock_res_free(&osb
->osb_nfs_sync_lockres
);
3040 ocfs2_lock_res_free(&osb
->osb_orphan_scan
.os_lockres
);
3042 ocfs2_cluster_disconnect(osb
->cconn
, hangup_pending
);
3045 ocfs2_dlm_shutdown_debug(osb
);
3048 static int ocfs2_drop_lock(struct ocfs2_super
*osb
,
3049 struct ocfs2_lock_res
*lockres
)
3052 unsigned long flags
;
3055 /* We didn't get anywhere near actually using this lockres. */
3056 if (!(lockres
->l_flags
& OCFS2_LOCK_INITIALIZED
))
3059 if (lockres
->l_ops
->flags
& LOCK_TYPE_USES_LVB
)
3060 lkm_flags
|= DLM_LKF_VALBLK
;
3062 spin_lock_irqsave(&lockres
->l_lock
, flags
);
3064 mlog_bug_on_msg(!(lockres
->l_flags
& OCFS2_LOCK_FREEING
),
3065 "lockres %s, flags 0x%lx\n",
3066 lockres
->l_name
, lockres
->l_flags
);
3068 while (lockres
->l_flags
& OCFS2_LOCK_BUSY
) {
3069 mlog(0, "waiting on busy lock \"%s\": flags = %lx, action = "
3070 "%u, unlock_action = %u\n",
3071 lockres
->l_name
, lockres
->l_flags
, lockres
->l_action
,
3072 lockres
->l_unlock_action
);
3074 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
3076 /* XXX: Today we just wait on any busy
3077 * locks... Perhaps we need to cancel converts in the
3079 ocfs2_wait_on_busy_lock(lockres
);
3081 spin_lock_irqsave(&lockres
->l_lock
, flags
);
3084 if (lockres
->l_ops
->flags
& LOCK_TYPE_USES_LVB
) {
3085 if (lockres
->l_flags
& OCFS2_LOCK_ATTACHED
&&
3086 lockres
->l_level
== DLM_LOCK_EX
&&
3087 !(lockres
->l_flags
& OCFS2_LOCK_NEEDS_REFRESH
))
3088 lockres
->l_ops
->set_lvb(lockres
);
3091 if (lockres
->l_flags
& OCFS2_LOCK_BUSY
)
3092 mlog(ML_ERROR
, "destroying busy lock: \"%s\"\n",
3094 if (lockres
->l_flags
& OCFS2_LOCK_BLOCKED
)
3095 mlog(0, "destroying blocked lock: \"%s\"\n", lockres
->l_name
);
3097 if (!(lockres
->l_flags
& OCFS2_LOCK_ATTACHED
)) {
3098 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
3102 lockres_clear_flags(lockres
, OCFS2_LOCK_ATTACHED
);
3104 /* make sure we never get here while waiting for an ast to
3106 BUG_ON(lockres
->l_action
!= OCFS2_AST_INVALID
);
3108 /* is this necessary? */
3109 lockres_or_flags(lockres
, OCFS2_LOCK_BUSY
);
3110 lockres
->l_unlock_action
= OCFS2_UNLOCK_DROP_LOCK
;
3111 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
3113 mlog(0, "lock %s\n", lockres
->l_name
);
3115 ret
= ocfs2_dlm_unlock(osb
->cconn
, &lockres
->l_lksb
, lkm_flags
);
3117 ocfs2_log_dlm_error("ocfs2_dlm_unlock", ret
, lockres
);
3118 mlog(ML_ERROR
, "lockres flags: %lu\n", lockres
->l_flags
);
3119 ocfs2_dlm_dump_lksb(&lockres
->l_lksb
);
3122 mlog(0, "lock %s, successful return from ocfs2_dlm_unlock\n",
3125 ocfs2_wait_on_busy_lock(lockres
);
3130 /* Mark the lockres as being dropped. It will no longer be
3131 * queued if blocking, but we still may have to wait on it
3132 * being dequeued from the downconvert thread before we can consider
3135 * You can *not* attempt to call cluster_lock on this lockres anymore. */
3136 void ocfs2_mark_lockres_freeing(struct ocfs2_lock_res
*lockres
)
3139 struct ocfs2_mask_waiter mw
;
3140 unsigned long flags
;
3142 ocfs2_init_mask_waiter(&mw
);
3144 spin_lock_irqsave(&lockres
->l_lock
, flags
);
3145 lockres
->l_flags
|= OCFS2_LOCK_FREEING
;
3146 while (lockres
->l_flags
& OCFS2_LOCK_QUEUED
) {
3147 lockres_add_mask_waiter(lockres
, &mw
, OCFS2_LOCK_QUEUED
, 0);
3148 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
3150 mlog(0, "Waiting on lockres %s\n", lockres
->l_name
);
3152 status
= ocfs2_wait_for_mask(&mw
);
3156 spin_lock_irqsave(&lockres
->l_lock
, flags
);
3158 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
3161 void ocfs2_simple_drop_lockres(struct ocfs2_super
*osb
,
3162 struct ocfs2_lock_res
*lockres
)
3166 ocfs2_mark_lockres_freeing(lockres
);
3167 ret
= ocfs2_drop_lock(osb
, lockres
);
3172 static void ocfs2_drop_osb_locks(struct ocfs2_super
*osb
)
3174 ocfs2_simple_drop_lockres(osb
, &osb
->osb_super_lockres
);
3175 ocfs2_simple_drop_lockres(osb
, &osb
->osb_rename_lockres
);
3176 ocfs2_simple_drop_lockres(osb
, &osb
->osb_nfs_sync_lockres
);
3177 ocfs2_simple_drop_lockres(osb
, &osb
->osb_orphan_scan
.os_lockres
);
3180 int ocfs2_drop_inode_locks(struct inode
*inode
)
3184 /* No need to call ocfs2_mark_lockres_freeing here -
3185 * ocfs2_clear_inode has done it for us. */
3187 err
= ocfs2_drop_lock(OCFS2_SB(inode
->i_sb
),
3188 &OCFS2_I(inode
)->ip_open_lockres
);
3194 err
= ocfs2_drop_lock(OCFS2_SB(inode
->i_sb
),
3195 &OCFS2_I(inode
)->ip_inode_lockres
);
3198 if (err
< 0 && !status
)
3201 err
= ocfs2_drop_lock(OCFS2_SB(inode
->i_sb
),
3202 &OCFS2_I(inode
)->ip_rw_lockres
);
3205 if (err
< 0 && !status
)
3211 static unsigned int ocfs2_prepare_downconvert(struct ocfs2_lock_res
*lockres
,
3214 assert_spin_locked(&lockres
->l_lock
);
3216 BUG_ON(lockres
->l_blocking
<= DLM_LOCK_NL
);
3218 if (lockres
->l_level
<= new_level
) {
3219 mlog(ML_ERROR
, "lockres %s, lvl %d <= %d, blcklst %d, mask %d, "
3220 "type %d, flags 0x%lx, hold %d %d, act %d %d, req %d, "
3221 "block %d, pgen %d\n", lockres
->l_name
, lockres
->l_level
,
3222 new_level
, list_empty(&lockres
->l_blocked_list
),
3223 list_empty(&lockres
->l_mask_waiters
), lockres
->l_type
,
3224 lockres
->l_flags
, lockres
->l_ro_holders
,
3225 lockres
->l_ex_holders
, lockres
->l_action
,
3226 lockres
->l_unlock_action
, lockres
->l_requested
,
3227 lockres
->l_blocking
, lockres
->l_pending_gen
);
3231 mlog(ML_BASTS
, "lockres %s, level %d => %d, blocking %d\n",
3232 lockres
->l_name
, lockres
->l_level
, new_level
, lockres
->l_blocking
);
3234 lockres
->l_action
= OCFS2_AST_DOWNCONVERT
;
3235 lockres
->l_requested
= new_level
;
3236 lockres_or_flags(lockres
, OCFS2_LOCK_BUSY
);
3237 return lockres_set_pending(lockres
);
3240 static int ocfs2_downconvert_lock(struct ocfs2_super
*osb
,
3241 struct ocfs2_lock_res
*lockres
,
3244 unsigned int generation
)
3247 u32 dlm_flags
= DLM_LKF_CONVERT
;
3249 mlog(ML_BASTS
, "lockres %s, level %d => %d\n", lockres
->l_name
,
3250 lockres
->l_level
, new_level
);
3253 dlm_flags
|= DLM_LKF_VALBLK
;
3255 ret
= ocfs2_dlm_lock(osb
->cconn
,
3260 OCFS2_LOCK_ID_MAX_LEN
- 1);
3261 lockres_clear_pending(lockres
, generation
, osb
);
3263 ocfs2_log_dlm_error("ocfs2_dlm_lock", ret
, lockres
);
3264 ocfs2_recover_from_dlm_error(lockres
, 1);
3273 /* returns 1 when the caller should unlock and call ocfs2_dlm_unlock */
3274 static int ocfs2_prepare_cancel_convert(struct ocfs2_super
*osb
,
3275 struct ocfs2_lock_res
*lockres
)
3277 assert_spin_locked(&lockres
->l_lock
);
3279 if (lockres
->l_unlock_action
== OCFS2_UNLOCK_CANCEL_CONVERT
) {
3280 /* If we're already trying to cancel a lock conversion
3281 * then just drop the spinlock and allow the caller to
3282 * requeue this lock. */
3283 mlog(ML_BASTS
, "lockres %s, skip convert\n", lockres
->l_name
);
3287 /* were we in a convert when we got the bast fire? */
3288 BUG_ON(lockres
->l_action
!= OCFS2_AST_CONVERT
&&
3289 lockres
->l_action
!= OCFS2_AST_DOWNCONVERT
);
3290 /* set things up for the unlockast to know to just
3291 * clear out the ast_action and unset busy, etc. */
3292 lockres
->l_unlock_action
= OCFS2_UNLOCK_CANCEL_CONVERT
;
3294 mlog_bug_on_msg(!(lockres
->l_flags
& OCFS2_LOCK_BUSY
),
3295 "lock %s, invalid flags: 0x%lx\n",
3296 lockres
->l_name
, lockres
->l_flags
);
3298 mlog(ML_BASTS
, "lockres %s\n", lockres
->l_name
);
3303 static int ocfs2_cancel_convert(struct ocfs2_super
*osb
,
3304 struct ocfs2_lock_res
*lockres
)
3308 ret
= ocfs2_dlm_unlock(osb
->cconn
, &lockres
->l_lksb
,
3311 ocfs2_log_dlm_error("ocfs2_dlm_unlock", ret
, lockres
);
3312 ocfs2_recover_from_dlm_error(lockres
, 0);
3315 mlog(ML_BASTS
, "lockres %s\n", lockres
->l_name
);
3320 static int ocfs2_unblock_lock(struct ocfs2_super
*osb
,
3321 struct ocfs2_lock_res
*lockres
,
3322 struct ocfs2_unblock_ctl
*ctl
)
3324 unsigned long flags
;
3332 spin_lock_irqsave(&lockres
->l_lock
, flags
);
3336 * Is it still blocking? If not, we have no more work to do.
3338 if (!(lockres
->l_flags
& OCFS2_LOCK_BLOCKED
)) {
3339 BUG_ON(lockres
->l_blocking
!= DLM_LOCK_NL
);
3340 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
3345 if (lockres
->l_flags
& OCFS2_LOCK_BUSY
) {
3347 * This is a *big* race. The OCFS2_LOCK_PENDING flag
3348 * exists entirely for one reason - another thread has set
3349 * OCFS2_LOCK_BUSY, but has *NOT* yet called dlm_lock().
3351 * If we do ocfs2_cancel_convert() before the other thread
3352 * calls dlm_lock(), our cancel will do nothing. We will
3353 * get no ast, and we will have no way of knowing the
3354 * cancel failed. Meanwhile, the other thread will call
3355 * into dlm_lock() and wait...forever.
3357 * Why forever? Because another node has asked for the
3358 * lock first; that's why we're here in unblock_lock().
3360 * The solution is OCFS2_LOCK_PENDING. When PENDING is
3361 * set, we just requeue the unblock. Only when the other
3362 * thread has called dlm_lock() and cleared PENDING will
3363 * we then cancel their request.
3365 * All callers of dlm_lock() must set OCFS2_DLM_PENDING
3366 * at the same time they set OCFS2_DLM_BUSY. They must
3367 * clear OCFS2_DLM_PENDING after dlm_lock() returns.
3369 if (lockres
->l_flags
& OCFS2_LOCK_PENDING
) {
3370 mlog(ML_BASTS
, "lockres %s, ReQ: Pending\n",
3376 ret
= ocfs2_prepare_cancel_convert(osb
, lockres
);
3377 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
3379 ret
= ocfs2_cancel_convert(osb
, lockres
);
3387 * This prevents livelocks. OCFS2_LOCK_UPCONVERT_FINISHING flag is
3388 * set when the ast is received for an upconvert just before the
3389 * OCFS2_LOCK_BUSY flag is cleared. Now if the fs received a bast
3390 * on the heels of the ast, we want to delay the downconvert just
3391 * enough to allow the up requestor to do its task. Because this
3392 * lock is in the blocked queue, the lock will be downconverted
3393 * as soon as the requestor is done with the lock.
3395 if (lockres
->l_flags
& OCFS2_LOCK_UPCONVERT_FINISHING
)
3399 * How can we block and yet be at NL? We were trying to upconvert
3400 * from NL and got canceled. The code comes back here, and now
3401 * we notice and clear BLOCKING.
3403 if (lockres
->l_level
== DLM_LOCK_NL
) {
3404 BUG_ON(lockres
->l_ex_holders
|| lockres
->l_ro_holders
);
3405 mlog(ML_BASTS
, "lockres %s, Aborting dc\n", lockres
->l_name
);
3406 lockres
->l_blocking
= DLM_LOCK_NL
;
3407 lockres_clear_flags(lockres
, OCFS2_LOCK_BLOCKED
);
3408 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
3412 /* if we're blocking an exclusive and we have *any* holders,
3414 if ((lockres
->l_blocking
== DLM_LOCK_EX
)
3415 && (lockres
->l_ex_holders
|| lockres
->l_ro_holders
)) {
3416 mlog(ML_BASTS
, "lockres %s, ReQ: EX/PR Holders %u,%u\n",
3417 lockres
->l_name
, lockres
->l_ex_holders
,
3418 lockres
->l_ro_holders
);
3422 /* If it's a PR we're blocking, then only
3423 * requeue if we've got any EX holders */
3424 if (lockres
->l_blocking
== DLM_LOCK_PR
&&
3425 lockres
->l_ex_holders
) {
3426 mlog(ML_BASTS
, "lockres %s, ReQ: EX Holders %u\n",
3427 lockres
->l_name
, lockres
->l_ex_holders
);
3432 * Can we get a lock in this state if the holder counts are
3433 * zero? The meta data unblock code used to check this.
3435 if ((lockres
->l_ops
->flags
& LOCK_TYPE_REQUIRES_REFRESH
)
3436 && (lockres
->l_flags
& OCFS2_LOCK_REFRESHING
)) {
3437 mlog(ML_BASTS
, "lockres %s, ReQ: Lock Refreshing\n",
3442 new_level
= ocfs2_highest_compat_lock_level(lockres
->l_blocking
);
3444 if (lockres
->l_ops
->check_downconvert
3445 && !lockres
->l_ops
->check_downconvert(lockres
, new_level
)) {
3446 mlog(ML_BASTS
, "lockres %s, ReQ: Checkpointing\n",
3451 /* If we get here, then we know that there are no more
3452 * incompatible holders (and anyone asking for an incompatible
3453 * lock is blocked). We can now downconvert the lock */
3454 if (!lockres
->l_ops
->downconvert_worker
)
3457 /* Some lockres types want to do a bit of work before
3458 * downconverting a lock. Allow that here. The worker function
3459 * may sleep, so we save off a copy of what we're blocking as
3460 * it may change while we're not holding the spin lock. */
3461 blocking
= lockres
->l_blocking
;
3462 level
= lockres
->l_level
;
3463 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
3465 ctl
->unblock_action
= lockres
->l_ops
->downconvert_worker(lockres
, blocking
);
3467 if (ctl
->unblock_action
== UNBLOCK_STOP_POST
) {
3468 mlog(ML_BASTS
, "lockres %s, UNBLOCK_STOP_POST\n",
3473 spin_lock_irqsave(&lockres
->l_lock
, flags
);
3474 if ((blocking
!= lockres
->l_blocking
) || (level
!= lockres
->l_level
)) {
3475 /* If this changed underneath us, then we can't drop
3477 mlog(ML_BASTS
, "lockres %s, block=%d:%d, level=%d:%d, "
3478 "Recheck\n", lockres
->l_name
, blocking
,
3479 lockres
->l_blocking
, level
, lockres
->l_level
);
3486 if (lockres
->l_ops
->flags
& LOCK_TYPE_USES_LVB
) {
3487 if (lockres
->l_level
== DLM_LOCK_EX
)
3491 * We only set the lvb if the lock has been fully
3492 * refreshed - otherwise we risk setting stale
3493 * data. Otherwise, there's no need to actually clear
3494 * out the lvb here as it's value is still valid.
3496 if (set_lvb
&& !(lockres
->l_flags
& OCFS2_LOCK_NEEDS_REFRESH
))
3497 lockres
->l_ops
->set_lvb(lockres
);
3500 gen
= ocfs2_prepare_downconvert(lockres
, new_level
);
3501 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
3502 ret
= ocfs2_downconvert_lock(osb
, lockres
, new_level
, set_lvb
,
3511 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
3517 static int ocfs2_data_convert_worker(struct ocfs2_lock_res
*lockres
,
3520 struct inode
*inode
;
3521 struct address_space
*mapping
;
3522 struct ocfs2_inode_info
*oi
;
3524 inode
= ocfs2_lock_res_inode(lockres
);
3525 mapping
= inode
->i_mapping
;
3527 if (S_ISDIR(inode
->i_mode
)) {
3528 oi
= OCFS2_I(inode
);
3529 oi
->ip_dir_lock_gen
++;
3530 mlog(0, "generation: %u\n", oi
->ip_dir_lock_gen
);
3534 if (!S_ISREG(inode
->i_mode
))
3538 * We need this before the filemap_fdatawrite() so that it can
3539 * transfer the dirty bit from the PTE to the
3540 * page. Unfortunately this means that even for EX->PR
3541 * downconverts, we'll lose our mappings and have to build
3544 unmap_mapping_range(mapping
, 0, 0, 0);
3546 if (filemap_fdatawrite(mapping
)) {
3547 mlog(ML_ERROR
, "Could not sync inode %llu for downconvert!",
3548 (unsigned long long)OCFS2_I(inode
)->ip_blkno
);
3550 sync_mapping_buffers(mapping
);
3551 if (blocking
== DLM_LOCK_EX
) {
3552 truncate_inode_pages(mapping
, 0);
3554 /* We only need to wait on the I/O if we're not also
3555 * truncating pages because truncate_inode_pages waits
3556 * for us above. We don't truncate pages if we're
3557 * blocking anything < EXMODE because we want to keep
3558 * them around in that case. */
3559 filemap_fdatawait(mapping
);
3563 return UNBLOCK_CONTINUE
;
3566 static int ocfs2_ci_checkpointed(struct ocfs2_caching_info
*ci
,
3567 struct ocfs2_lock_res
*lockres
,
3570 int checkpointed
= ocfs2_ci_fully_checkpointed(ci
);
3572 BUG_ON(new_level
!= DLM_LOCK_NL
&& new_level
!= DLM_LOCK_PR
);
3573 BUG_ON(lockres
->l_level
!= DLM_LOCK_EX
&& !checkpointed
);
3578 ocfs2_start_checkpoint(OCFS2_SB(ocfs2_metadata_cache_get_super(ci
)));
3582 static int ocfs2_check_meta_downconvert(struct ocfs2_lock_res
*lockres
,
3585 struct inode
*inode
= ocfs2_lock_res_inode(lockres
);
3587 return ocfs2_ci_checkpointed(INODE_CACHE(inode
), lockres
, new_level
);
3590 static void ocfs2_set_meta_lvb(struct ocfs2_lock_res
*lockres
)
3592 struct inode
*inode
= ocfs2_lock_res_inode(lockres
);
3594 __ocfs2_stuff_meta_lvb(inode
);
3598 * Does the final reference drop on our dentry lock. Right now this
3599 * happens in the downconvert thread, but we could choose to simplify the
3600 * dlmglue API and push these off to the ocfs2_wq in the future.
3602 static void ocfs2_dentry_post_unlock(struct ocfs2_super
*osb
,
3603 struct ocfs2_lock_res
*lockres
)
3605 struct ocfs2_dentry_lock
*dl
= ocfs2_lock_res_dl(lockres
);
3606 ocfs2_dentry_lock_put(osb
, dl
);
3610 * d_delete() matching dentries before the lock downconvert.
3612 * At this point, any process waiting to destroy the
3613 * dentry_lock due to last ref count is stopped by the
3614 * OCFS2_LOCK_QUEUED flag.
3616 * We have two potential problems
3618 * 1) If we do the last reference drop on our dentry_lock (via dput)
3619 * we'll wind up in ocfs2_release_dentry_lock(), waiting on
3620 * the downconvert to finish. Instead we take an elevated
3621 * reference and push the drop until after we've completed our
3622 * unblock processing.
3624 * 2) There might be another process with a final reference,
3625 * waiting on us to finish processing. If this is the case, we
3626 * detect it and exit out - there's no more dentries anyway.
3628 static int ocfs2_dentry_convert_worker(struct ocfs2_lock_res
*lockres
,
3631 struct ocfs2_dentry_lock
*dl
= ocfs2_lock_res_dl(lockres
);
3632 struct ocfs2_inode_info
*oi
= OCFS2_I(dl
->dl_inode
);
3633 struct dentry
*dentry
;
3634 unsigned long flags
;
3638 * This node is blocking another node from getting a read
3639 * lock. This happens when we've renamed within a
3640 * directory. We've forced the other nodes to d_delete(), but
3641 * we never actually dropped our lock because it's still
3642 * valid. The downconvert code will retain a PR for this node,
3643 * so there's no further work to do.
3645 if (blocking
== DLM_LOCK_PR
)
3646 return UNBLOCK_CONTINUE
;
3649 * Mark this inode as potentially orphaned. The code in
3650 * ocfs2_delete_inode() will figure out whether it actually
3651 * needs to be freed or not.
3653 spin_lock(&oi
->ip_lock
);
3654 oi
->ip_flags
|= OCFS2_INODE_MAYBE_ORPHANED
;
3655 spin_unlock(&oi
->ip_lock
);
3658 * Yuck. We need to make sure however that the check of
3659 * OCFS2_LOCK_FREEING and the extra reference are atomic with
3660 * respect to a reference decrement or the setting of that
3663 spin_lock_irqsave(&lockres
->l_lock
, flags
);
3664 spin_lock(&dentry_attach_lock
);
3665 if (!(lockres
->l_flags
& OCFS2_LOCK_FREEING
)
3670 spin_unlock(&dentry_attach_lock
);
3671 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
3673 mlog(0, "extra_ref = %d\n", extra_ref
);
3676 * We have a process waiting on us in ocfs2_dentry_iput(),
3677 * which means we can't have any more outstanding
3678 * aliases. There's no need to do any more work.
3681 return UNBLOCK_CONTINUE
;
3683 spin_lock(&dentry_attach_lock
);
3685 dentry
= ocfs2_find_local_alias(dl
->dl_inode
,
3686 dl
->dl_parent_blkno
, 1);
3689 spin_unlock(&dentry_attach_lock
);
3691 mlog(0, "d_delete(%.*s);\n", dentry
->d_name
.len
,
3692 dentry
->d_name
.name
);
3695 * The following dcache calls may do an
3696 * iput(). Normally we don't want that from the
3697 * downconverting thread, but in this case it's ok
3698 * because the requesting node already has an
3699 * exclusive lock on the inode, so it can't be queued
3700 * for a downconvert.
3705 spin_lock(&dentry_attach_lock
);
3707 spin_unlock(&dentry_attach_lock
);
3710 * If we are the last holder of this dentry lock, there is no
3711 * reason to downconvert so skip straight to the unlock.
3713 if (dl
->dl_count
== 1)
3714 return UNBLOCK_STOP_POST
;
3716 return UNBLOCK_CONTINUE_POST
;
3719 static int ocfs2_check_refcount_downconvert(struct ocfs2_lock_res
*lockres
,
3722 struct ocfs2_refcount_tree
*tree
=
3723 ocfs2_lock_res_refcount_tree(lockres
);
3725 return ocfs2_ci_checkpointed(&tree
->rf_ci
, lockres
, new_level
);
3728 static int ocfs2_refcount_convert_worker(struct ocfs2_lock_res
*lockres
,
3731 struct ocfs2_refcount_tree
*tree
=
3732 ocfs2_lock_res_refcount_tree(lockres
);
3734 ocfs2_metadata_cache_purge(&tree
->rf_ci
);
3736 return UNBLOCK_CONTINUE
;
3739 static void ocfs2_set_qinfo_lvb(struct ocfs2_lock_res
*lockres
)
3741 struct ocfs2_qinfo_lvb
*lvb
;
3742 struct ocfs2_mem_dqinfo
*oinfo
= ocfs2_lock_res_qinfo(lockres
);
3743 struct mem_dqinfo
*info
= sb_dqinfo(oinfo
->dqi_gi
.dqi_sb
,
3744 oinfo
->dqi_gi
.dqi_type
);
3746 lvb
= ocfs2_dlm_lvb(&lockres
->l_lksb
);
3747 lvb
->lvb_version
= OCFS2_QINFO_LVB_VERSION
;
3748 lvb
->lvb_bgrace
= cpu_to_be32(info
->dqi_bgrace
);
3749 lvb
->lvb_igrace
= cpu_to_be32(info
->dqi_igrace
);
3750 lvb
->lvb_syncms
= cpu_to_be32(oinfo
->dqi_syncms
);
3751 lvb
->lvb_blocks
= cpu_to_be32(oinfo
->dqi_gi
.dqi_blocks
);
3752 lvb
->lvb_free_blk
= cpu_to_be32(oinfo
->dqi_gi
.dqi_free_blk
);
3753 lvb
->lvb_free_entry
= cpu_to_be32(oinfo
->dqi_gi
.dqi_free_entry
);
3756 void ocfs2_qinfo_unlock(struct ocfs2_mem_dqinfo
*oinfo
, int ex
)
3758 struct ocfs2_lock_res
*lockres
= &oinfo
->dqi_gqlock
;
3759 struct ocfs2_super
*osb
= OCFS2_SB(oinfo
->dqi_gi
.dqi_sb
);
3760 int level
= ex
? DLM_LOCK_EX
: DLM_LOCK_PR
;
3762 if (!ocfs2_is_hard_readonly(osb
) && !ocfs2_mount_local(osb
))
3763 ocfs2_cluster_unlock(osb
, lockres
, level
);
3766 static int ocfs2_refresh_qinfo(struct ocfs2_mem_dqinfo
*oinfo
)
3768 struct mem_dqinfo
*info
= sb_dqinfo(oinfo
->dqi_gi
.dqi_sb
,
3769 oinfo
->dqi_gi
.dqi_type
);
3770 struct ocfs2_lock_res
*lockres
= &oinfo
->dqi_gqlock
;
3771 struct ocfs2_qinfo_lvb
*lvb
= ocfs2_dlm_lvb(&lockres
->l_lksb
);
3772 struct buffer_head
*bh
= NULL
;
3773 struct ocfs2_global_disk_dqinfo
*gdinfo
;
3776 if (ocfs2_dlm_lvb_valid(&lockres
->l_lksb
) &&
3777 lvb
->lvb_version
== OCFS2_QINFO_LVB_VERSION
) {
3778 info
->dqi_bgrace
= be32_to_cpu(lvb
->lvb_bgrace
);
3779 info
->dqi_igrace
= be32_to_cpu(lvb
->lvb_igrace
);
3780 oinfo
->dqi_syncms
= be32_to_cpu(lvb
->lvb_syncms
);
3781 oinfo
->dqi_gi
.dqi_blocks
= be32_to_cpu(lvb
->lvb_blocks
);
3782 oinfo
->dqi_gi
.dqi_free_blk
= be32_to_cpu(lvb
->lvb_free_blk
);
3783 oinfo
->dqi_gi
.dqi_free_entry
=
3784 be32_to_cpu(lvb
->lvb_free_entry
);
3786 status
= ocfs2_read_quota_phys_block(oinfo
->dqi_gqinode
,
3787 oinfo
->dqi_giblk
, &bh
);
3792 gdinfo
= (struct ocfs2_global_disk_dqinfo
*)
3793 (bh
->b_data
+ OCFS2_GLOBAL_INFO_OFF
);
3794 info
->dqi_bgrace
= le32_to_cpu(gdinfo
->dqi_bgrace
);
3795 info
->dqi_igrace
= le32_to_cpu(gdinfo
->dqi_igrace
);
3796 oinfo
->dqi_syncms
= le32_to_cpu(gdinfo
->dqi_syncms
);
3797 oinfo
->dqi_gi
.dqi_blocks
= le32_to_cpu(gdinfo
->dqi_blocks
);
3798 oinfo
->dqi_gi
.dqi_free_blk
= le32_to_cpu(gdinfo
->dqi_free_blk
);
3799 oinfo
->dqi_gi
.dqi_free_entry
=
3800 le32_to_cpu(gdinfo
->dqi_free_entry
);
3802 ocfs2_track_lock_refresh(lockres
);
3809 /* Lock quota info, this function expects at least shared lock on the quota file
3810 * so that we can safely refresh quota info from disk. */
3811 int ocfs2_qinfo_lock(struct ocfs2_mem_dqinfo
*oinfo
, int ex
)
3813 struct ocfs2_lock_res
*lockres
= &oinfo
->dqi_gqlock
;
3814 struct ocfs2_super
*osb
= OCFS2_SB(oinfo
->dqi_gi
.dqi_sb
);
3815 int level
= ex
? DLM_LOCK_EX
: DLM_LOCK_PR
;
3818 /* On RO devices, locking really isn't needed... */
3819 if (ocfs2_is_hard_readonly(osb
)) {
3824 if (ocfs2_mount_local(osb
))
3827 status
= ocfs2_cluster_lock(osb
, lockres
, level
, 0, 0);
3832 if (!ocfs2_should_refresh_lock_res(lockres
))
3834 /* OK, we have the lock but we need to refresh the quota info */
3835 status
= ocfs2_refresh_qinfo(oinfo
);
3837 ocfs2_qinfo_unlock(oinfo
, ex
);
3838 ocfs2_complete_lock_res_refresh(lockres
, status
);
3843 int ocfs2_refcount_lock(struct ocfs2_refcount_tree
*ref_tree
, int ex
)
3846 int level
= ex
? DLM_LOCK_EX
: DLM_LOCK_PR
;
3847 struct ocfs2_lock_res
*lockres
= &ref_tree
->rf_lockres
;
3848 struct ocfs2_super
*osb
= lockres
->l_priv
;
3851 if (ocfs2_is_hard_readonly(osb
))
3854 if (ocfs2_mount_local(osb
))
3857 status
= ocfs2_cluster_lock(osb
, lockres
, level
, 0, 0);
3864 void ocfs2_refcount_unlock(struct ocfs2_refcount_tree
*ref_tree
, int ex
)
3866 int level
= ex
? DLM_LOCK_EX
: DLM_LOCK_PR
;
3867 struct ocfs2_lock_res
*lockres
= &ref_tree
->rf_lockres
;
3868 struct ocfs2_super
*osb
= lockres
->l_priv
;
3870 if (!ocfs2_mount_local(osb
))
3871 ocfs2_cluster_unlock(osb
, lockres
, level
);
3874 static void ocfs2_process_blocked_lock(struct ocfs2_super
*osb
,
3875 struct ocfs2_lock_res
*lockres
)
3878 struct ocfs2_unblock_ctl ctl
= {0, 0,};
3879 unsigned long flags
;
3881 /* Our reference to the lockres in this function can be
3882 * considered valid until we remove the OCFS2_LOCK_QUEUED
3886 BUG_ON(!lockres
->l_ops
);
3888 mlog(ML_BASTS
, "lockres %s blocked\n", lockres
->l_name
);
3890 /* Detect whether a lock has been marked as going away while
3891 * the downconvert thread was processing other things. A lock can
3892 * still be marked with OCFS2_LOCK_FREEING after this check,
3893 * but short circuiting here will still save us some
3895 spin_lock_irqsave(&lockres
->l_lock
, flags
);
3896 if (lockres
->l_flags
& OCFS2_LOCK_FREEING
)
3898 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
3900 status
= ocfs2_unblock_lock(osb
, lockres
, &ctl
);
3904 spin_lock_irqsave(&lockres
->l_lock
, flags
);
3906 if (lockres
->l_flags
& OCFS2_LOCK_FREEING
|| !ctl
.requeue
) {
3907 lockres_clear_flags(lockres
, OCFS2_LOCK_QUEUED
);
3909 ocfs2_schedule_blocked_lock(osb
, lockres
);
3911 mlog(ML_BASTS
, "lockres %s, requeue = %s.\n", lockres
->l_name
,
3912 ctl
.requeue
? "yes" : "no");
3913 spin_unlock_irqrestore(&lockres
->l_lock
, flags
);
3915 if (ctl
.unblock_action
!= UNBLOCK_CONTINUE
3916 && lockres
->l_ops
->post_unlock
)
3917 lockres
->l_ops
->post_unlock(osb
, lockres
);
3920 static void ocfs2_schedule_blocked_lock(struct ocfs2_super
*osb
,
3921 struct ocfs2_lock_res
*lockres
)
3923 assert_spin_locked(&lockres
->l_lock
);
3925 if (lockres
->l_flags
& OCFS2_LOCK_FREEING
) {
3926 /* Do not schedule a lock for downconvert when it's on
3927 * the way to destruction - any nodes wanting access
3928 * to the resource will get it soon. */
3929 mlog(ML_BASTS
, "lockres %s won't be scheduled: flags 0x%lx\n",
3930 lockres
->l_name
, lockres
->l_flags
);
3934 lockres_or_flags(lockres
, OCFS2_LOCK_QUEUED
);
3936 spin_lock(&osb
->dc_task_lock
);
3937 if (list_empty(&lockres
->l_blocked_list
)) {
3938 list_add_tail(&lockres
->l_blocked_list
,
3939 &osb
->blocked_lock_list
);
3940 osb
->blocked_lock_count
++;
3942 spin_unlock(&osb
->dc_task_lock
);
3945 static void ocfs2_downconvert_thread_do_work(struct ocfs2_super
*osb
)
3947 unsigned long processed
;
3948 struct ocfs2_lock_res
*lockres
;
3950 spin_lock(&osb
->dc_task_lock
);
3951 /* grab this early so we know to try again if a state change and
3952 * wake happens part-way through our work */
3953 osb
->dc_work_sequence
= osb
->dc_wake_sequence
;
3955 processed
= osb
->blocked_lock_count
;
3957 BUG_ON(list_empty(&osb
->blocked_lock_list
));
3959 lockres
= list_entry(osb
->blocked_lock_list
.next
,
3960 struct ocfs2_lock_res
, l_blocked_list
);
3961 list_del_init(&lockres
->l_blocked_list
);
3962 osb
->blocked_lock_count
--;
3963 spin_unlock(&osb
->dc_task_lock
);
3968 ocfs2_process_blocked_lock(osb
, lockres
);
3970 spin_lock(&osb
->dc_task_lock
);
3972 spin_unlock(&osb
->dc_task_lock
);
3975 static int ocfs2_downconvert_thread_lists_empty(struct ocfs2_super
*osb
)
3979 spin_lock(&osb
->dc_task_lock
);
3980 if (list_empty(&osb
->blocked_lock_list
))
3983 spin_unlock(&osb
->dc_task_lock
);
3987 static int ocfs2_downconvert_thread_should_wake(struct ocfs2_super
*osb
)
3989 int should_wake
= 0;
3991 spin_lock(&osb
->dc_task_lock
);
3992 if (osb
->dc_work_sequence
!= osb
->dc_wake_sequence
)
3994 spin_unlock(&osb
->dc_task_lock
);
3999 static int ocfs2_downconvert_thread(void *arg
)
4002 struct ocfs2_super
*osb
= arg
;
4004 /* only quit once we've been asked to stop and there is no more
4006 while (!(kthread_should_stop() &&
4007 ocfs2_downconvert_thread_lists_empty(osb
))) {
4009 wait_event_interruptible(osb
->dc_event
,
4010 ocfs2_downconvert_thread_should_wake(osb
) ||
4011 kthread_should_stop());
4013 mlog(0, "downconvert_thread: awoken\n");
4015 ocfs2_downconvert_thread_do_work(osb
);
4018 osb
->dc_task
= NULL
;
4022 void ocfs2_wake_downconvert_thread(struct ocfs2_super
*osb
)
4024 spin_lock(&osb
->dc_task_lock
);
4025 /* make sure the voting thread gets a swipe at whatever changes
4026 * the caller may have made to the voting state */
4027 osb
->dc_wake_sequence
++;
4028 spin_unlock(&osb
->dc_task_lock
);
4029 wake_up(&osb
->dc_event
);