Lines Matching refs:lockres
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);
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,
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,
125 struct ocfs2_lock_res *lockres) in ocfs2_dump_meta_lvb_info() argument
127 struct ocfs2_meta_lvb *lvb = ocfs2_dlm_lvb(&lockres->l_lksb); in ocfs2_dump_meta_lvb_info()
130 lockres->l_name, function, line); in ocfs2_dump_meta_lvb_info()
293 static inline int ocfs2_is_inode_lock(struct ocfs2_lock_res *lockres) in ocfs2_is_inode_lock() argument
295 return lockres->l_type == OCFS2_LOCK_TYPE_META || in ocfs2_is_inode_lock()
296 lockres->l_type == OCFS2_LOCK_TYPE_RW || in ocfs2_is_inode_lock()
297 lockres->l_type == OCFS2_LOCK_TYPE_OPEN; in ocfs2_is_inode_lock()
305 static inline struct inode *ocfs2_lock_res_inode(struct ocfs2_lock_res *lockres) in ocfs2_lock_res_inode() argument
307 BUG_ON(!ocfs2_is_inode_lock(lockres)); in ocfs2_lock_res_inode()
309 return (struct inode *) lockres->l_priv; in ocfs2_lock_res_inode()
312 static inline struct ocfs2_dentry_lock *ocfs2_lock_res_dl(struct ocfs2_lock_res *lockres) in ocfs2_lock_res_dl() argument
314 BUG_ON(lockres->l_type != OCFS2_LOCK_TYPE_DENTRY); in ocfs2_lock_res_dl()
316 return (struct ocfs2_dentry_lock *)lockres->l_priv; in ocfs2_lock_res_dl()
319 static inline struct ocfs2_mem_dqinfo *ocfs2_lock_res_qinfo(struct ocfs2_lock_res *lockres) in ocfs2_lock_res_qinfo() argument
321 BUG_ON(lockres->l_type != OCFS2_LOCK_TYPE_QINFO); in ocfs2_lock_res_qinfo()
323 return (struct ocfs2_mem_dqinfo *)lockres->l_priv; in ocfs2_lock_res_qinfo()
332 static inline struct ocfs2_super *ocfs2_get_lockres_osb(struct ocfs2_lock_res *lockres) in ocfs2_get_lockres_osb() argument
334 if (lockres->l_ops->get_osb) in ocfs2_get_lockres_osb()
335 return lockres->l_ops->get_osb(lockres); in ocfs2_get_lockres_osb()
337 return (struct ocfs2_super *)lockres->l_priv; in ocfs2_get_lockres_osb()
341 struct ocfs2_lock_res *lockres,
344 static inline int ocfs2_may_continue_on_blocked_lock(struct ocfs2_lock_res *lockres,
347 struct ocfs2_lock_res *lockres,
350 struct ocfs2_lock_res *lockres, in ocfs2_cluster_unlock() argument
353 __ocfs2_cluster_unlock(osb, lockres, level, _RET_IP_); in ocfs2_cluster_unlock()
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);
361 struct ocfs2_lock_res *lockres);
362 static inline void ocfs2_recover_from_dlm_error(struct ocfs2_lock_res *lockres,
375 struct ocfs2_lock_res *lockres);
380 static unsigned int ocfs2_prepare_downconvert(struct ocfs2_lock_res *lockres,
383 struct ocfs2_lock_res *lockres,
388 struct ocfs2_lock_res *lockres);
390 struct ocfs2_lock_res *lockres);
471 static inline void ocfs2_track_lock_refresh(struct ocfs2_lock_res *lockres) in ocfs2_track_lock_refresh() argument
473 lockres->l_lock_refresh++; in ocfs2_track_lock_refresh()
488 static inline void ocfs2_track_lock_refresh(struct ocfs2_lock_res *lockres) in ocfs2_track_lock_refresh() argument
564 static struct ocfs2_super *ocfs2_get_inode_osb(struct ocfs2_lock_res *lockres) in ocfs2_get_inode_osb() argument
566 struct inode *inode = ocfs2_lock_res_inode(lockres); in ocfs2_get_inode_osb()
571 static struct ocfs2_super *ocfs2_get_qinfo_osb(struct ocfs2_lock_res *lockres) in ocfs2_get_qinfo_osb() argument
573 struct ocfs2_mem_dqinfo *info = lockres->l_priv; in ocfs2_get_qinfo_osb()
578 static struct ocfs2_super *ocfs2_get_file_osb(struct ocfs2_lock_res *lockres) in ocfs2_get_file_osb() argument
580 struct ocfs2_file_private *fp = lockres->l_priv; in ocfs2_get_file_osb()
585 static __u64 ocfs2_get_dentry_lock_ino(struct ocfs2_lock_res *lockres) in ocfs2_get_dentry_lock_ino() argument
589 memcpy(&inode_blkno_be, &lockres->l_name[OCFS2_DENTRY_LOCK_INO_START], in ocfs2_get_dentry_lock_ino()
595 static struct ocfs2_super *ocfs2_get_dentry_osb(struct ocfs2_lock_res *lockres) in ocfs2_get_dentry_osb() argument
597 struct ocfs2_dentry_lock *dl = lockres->l_priv; in ocfs2_get_dentry_osb()
608 struct ocfs2_lock_res *lockres = &dl->dl_lockres; in ocfs2_dentry_lock_res_init() local
610 ocfs2_lock_res_init_once(lockres); in ocfs2_dentry_lock_res_init()
627 len = snprintf(lockres->l_name, OCFS2_DENTRY_LOCK_INO_START, in ocfs2_dentry_lock_res_init()
634 memcpy(&lockres->l_name[OCFS2_DENTRY_LOCK_INO_START], &inode_blkno_be, in ocfs2_dentry_lock_res_init()
637 ocfs2_lock_res_init_common(OCFS2_SB(inode->i_sb), lockres, in ocfs2_dentry_lock_res_init()
685 void ocfs2_file_lock_res_init(struct ocfs2_lock_res *lockres, in ocfs2_file_lock_res_init() argument
691 ocfs2_lock_res_init_once(lockres); in ocfs2_file_lock_res_init()
693 inode->i_generation, lockres->l_name); in ocfs2_file_lock_res_init()
694 ocfs2_lock_res_init_common(OCFS2_SB(inode->i_sb), lockres, in ocfs2_file_lock_res_init()
697 lockres->l_flags |= OCFS2_LOCK_NOCACHE; in ocfs2_file_lock_res_init()
700 void ocfs2_qinfo_lock_res_init(struct ocfs2_lock_res *lockres, in ocfs2_qinfo_lock_res_init() argument
703 ocfs2_lock_res_init_once(lockres); in ocfs2_qinfo_lock_res_init()
705 0, lockres->l_name); in ocfs2_qinfo_lock_res_init()
706 ocfs2_lock_res_init_common(OCFS2_SB(info->dqi_gi.dqi_sb), lockres, in ocfs2_qinfo_lock_res_init()
711 void ocfs2_refcount_lock_res_init(struct ocfs2_lock_res *lockres, in ocfs2_refcount_lock_res_init() argument
715 ocfs2_lock_res_init_once(lockres); in ocfs2_refcount_lock_res_init()
717 generation, lockres->l_name); in ocfs2_refcount_lock_res_init()
718 ocfs2_lock_res_init_common(osb, lockres, OCFS2_LOCK_TYPE_REFCOUNT, in ocfs2_refcount_lock_res_init()
751 static inline void ocfs2_inc_holders(struct ocfs2_lock_res *lockres, in ocfs2_inc_holders() argument
754 BUG_ON(!lockres); in ocfs2_inc_holders()
758 lockres->l_ex_holders++; in ocfs2_inc_holders()
761 lockres->l_ro_holders++; in ocfs2_inc_holders()
768 static inline void ocfs2_dec_holders(struct ocfs2_lock_res *lockres, in ocfs2_dec_holders() argument
771 BUG_ON(!lockres); in ocfs2_dec_holders()
775 BUG_ON(!lockres->l_ex_holders); in ocfs2_dec_holders()
776 lockres->l_ex_holders--; in ocfs2_dec_holders()
779 BUG_ON(!lockres->l_ro_holders); in ocfs2_dec_holders()
780 lockres->l_ro_holders--; in ocfs2_dec_holders()
801 static void lockres_set_flags(struct ocfs2_lock_res *lockres, in lockres_set_flags() argument
806 assert_spin_locked(&lockres->l_lock); in lockres_set_flags()
808 lockres->l_flags = newflags; in lockres_set_flags()
810 list_for_each_entry_safe(mw, tmp, &lockres->l_mask_waiters, mw_item) { in lockres_set_flags()
811 if ((lockres->l_flags & mw->mw_mask) != mw->mw_goal) in lockres_set_flags()
819 static void lockres_or_flags(struct ocfs2_lock_res *lockres, unsigned long or) in lockres_or_flags() argument
821 lockres_set_flags(lockres, lockres->l_flags | or); in lockres_or_flags()
823 static void lockres_clear_flags(struct ocfs2_lock_res *lockres, in lockres_clear_flags() argument
826 lockres_set_flags(lockres, lockres->l_flags & ~clear); in lockres_clear_flags()
829 static inline void ocfs2_generic_handle_downconvert_action(struct ocfs2_lock_res *lockres) in ocfs2_generic_handle_downconvert_action() argument
831 BUG_ON(!(lockres->l_flags & OCFS2_LOCK_BUSY)); in ocfs2_generic_handle_downconvert_action()
832 BUG_ON(!(lockres->l_flags & OCFS2_LOCK_ATTACHED)); in ocfs2_generic_handle_downconvert_action()
833 BUG_ON(!(lockres->l_flags & OCFS2_LOCK_BLOCKED)); in ocfs2_generic_handle_downconvert_action()
834 BUG_ON(lockres->l_blocking <= DLM_LOCK_NL); in ocfs2_generic_handle_downconvert_action()
836 lockres->l_level = lockres->l_requested; in ocfs2_generic_handle_downconvert_action()
837 if (lockres->l_level <= in ocfs2_generic_handle_downconvert_action()
838 ocfs2_highest_compat_lock_level(lockres->l_blocking)) { in ocfs2_generic_handle_downconvert_action()
839 lockres->l_blocking = DLM_LOCK_NL; in ocfs2_generic_handle_downconvert_action()
840 lockres_clear_flags(lockres, OCFS2_LOCK_BLOCKED); in ocfs2_generic_handle_downconvert_action()
842 lockres_clear_flags(lockres, OCFS2_LOCK_BUSY); in ocfs2_generic_handle_downconvert_action()
845 static inline void ocfs2_generic_handle_convert_action(struct ocfs2_lock_res *lockres) in ocfs2_generic_handle_convert_action() argument
847 BUG_ON(!(lockres->l_flags & OCFS2_LOCK_BUSY)); in ocfs2_generic_handle_convert_action()
848 BUG_ON(!(lockres->l_flags & OCFS2_LOCK_ATTACHED)); in ocfs2_generic_handle_convert_action()
854 if (lockres->l_level == DLM_LOCK_NL && in ocfs2_generic_handle_convert_action()
855 lockres->l_ops->flags & LOCK_TYPE_REQUIRES_REFRESH) in ocfs2_generic_handle_convert_action()
856 lockres_or_flags(lockres, OCFS2_LOCK_NEEDS_REFRESH); in ocfs2_generic_handle_convert_action()
858 lockres->l_level = lockres->l_requested; in ocfs2_generic_handle_convert_action()
867 if (!(lockres->l_flags & OCFS2_LOCK_NONBLOCK_FINISHED)) in ocfs2_generic_handle_convert_action()
868 lockres_or_flags(lockres, OCFS2_LOCK_UPCONVERT_FINISHING); in ocfs2_generic_handle_convert_action()
870 lockres_clear_flags(lockres, OCFS2_LOCK_NONBLOCK_FINISHED); in ocfs2_generic_handle_convert_action()
872 lockres_clear_flags(lockres, OCFS2_LOCK_BUSY); in ocfs2_generic_handle_convert_action()
875 static inline void ocfs2_generic_handle_attach_action(struct ocfs2_lock_res *lockres) in ocfs2_generic_handle_attach_action() argument
877 BUG_ON((!(lockres->l_flags & OCFS2_LOCK_BUSY))); in ocfs2_generic_handle_attach_action()
878 BUG_ON(lockres->l_flags & OCFS2_LOCK_ATTACHED); in ocfs2_generic_handle_attach_action()
880 if (lockres->l_requested > DLM_LOCK_NL && in ocfs2_generic_handle_attach_action()
881 !(lockres->l_flags & OCFS2_LOCK_LOCAL) && in ocfs2_generic_handle_attach_action()
882 lockres->l_ops->flags & LOCK_TYPE_REQUIRES_REFRESH) in ocfs2_generic_handle_attach_action()
883 lockres_or_flags(lockres, OCFS2_LOCK_NEEDS_REFRESH); in ocfs2_generic_handle_attach_action()
885 lockres->l_level = lockres->l_requested; in ocfs2_generic_handle_attach_action()
886 lockres_or_flags(lockres, OCFS2_LOCK_ATTACHED); in ocfs2_generic_handle_attach_action()
887 lockres_clear_flags(lockres, OCFS2_LOCK_BUSY); in ocfs2_generic_handle_attach_action()
890 static int ocfs2_generic_handle_bast(struct ocfs2_lock_res *lockres, in ocfs2_generic_handle_bast() argument
895 assert_spin_locked(&lockres->l_lock); in ocfs2_generic_handle_bast()
897 if (level > lockres->l_blocking) { in ocfs2_generic_handle_bast()
903 ocfs2_highest_compat_lock_level(lockres->l_blocking)) in ocfs2_generic_handle_bast()
906 lockres->l_blocking = level; in ocfs2_generic_handle_bast()
910 lockres->l_name, level, lockres->l_level, lockres->l_blocking, in ocfs2_generic_handle_bast()
914 lockres_or_flags(lockres, OCFS2_LOCK_BLOCKED); in ocfs2_generic_handle_bast()
978 static void __lockres_clear_pending(struct ocfs2_lock_res *lockres, in __lockres_clear_pending() argument
982 assert_spin_locked(&lockres->l_lock); in __lockres_clear_pending()
988 if (!(lockres->l_flags & OCFS2_LOCK_PENDING) || in __lockres_clear_pending()
989 (lockres->l_pending_gen != generation)) in __lockres_clear_pending()
992 lockres_clear_flags(lockres, OCFS2_LOCK_PENDING); in __lockres_clear_pending()
993 lockres->l_pending_gen++; in __lockres_clear_pending()
999 if (lockres->l_flags & OCFS2_LOCK_BLOCKED) in __lockres_clear_pending()
1004 static void lockres_clear_pending(struct ocfs2_lock_res *lockres, in lockres_clear_pending() argument
1010 spin_lock_irqsave(&lockres->l_lock, flags); in lockres_clear_pending()
1011 __lockres_clear_pending(lockres, generation, osb); in lockres_clear_pending()
1012 spin_unlock_irqrestore(&lockres->l_lock, flags); in lockres_clear_pending()
1015 static unsigned int lockres_set_pending(struct ocfs2_lock_res *lockres) in lockres_set_pending() argument
1017 assert_spin_locked(&lockres->l_lock); in lockres_set_pending()
1018 BUG_ON(!(lockres->l_flags & OCFS2_LOCK_BUSY)); in lockres_set_pending()
1020 lockres_or_flags(lockres, OCFS2_LOCK_PENDING); in lockres_set_pending()
1022 return lockres->l_pending_gen; in lockres_set_pending()
1027 struct ocfs2_lock_res *lockres = ocfs2_lksb_to_lock_res(lksb); in ocfs2_blocking_ast() local
1028 struct ocfs2_super *osb = ocfs2_get_lockres_osb(lockres); in ocfs2_blocking_ast()
1035 "type %s\n", lockres->l_name, level, lockres->l_level, in ocfs2_blocking_ast()
1036 ocfs2_lock_type_string(lockres->l_type)); in ocfs2_blocking_ast()
1042 if (lockres->l_flags & OCFS2_LOCK_NOCACHE) in ocfs2_blocking_ast()
1045 spin_lock_irqsave(&lockres->l_lock, flags); in ocfs2_blocking_ast()
1046 needs_downconvert = ocfs2_generic_handle_bast(lockres, level); in ocfs2_blocking_ast()
1048 ocfs2_schedule_blocked_lock(osb, lockres); in ocfs2_blocking_ast()
1049 spin_unlock_irqrestore(&lockres->l_lock, flags); in ocfs2_blocking_ast()
1051 wake_up(&lockres->l_event); in ocfs2_blocking_ast()
1058 struct ocfs2_lock_res *lockres = ocfs2_lksb_to_lock_res(lksb); in ocfs2_locking_ast() local
1059 struct ocfs2_super *osb = ocfs2_get_lockres_osb(lockres); in ocfs2_locking_ast()
1063 spin_lock_irqsave(&lockres->l_lock, flags); in ocfs2_locking_ast()
1065 status = ocfs2_dlm_lock_status(&lockres->l_lksb); in ocfs2_locking_ast()
1068 lockres_clear_flags(lockres, OCFS2_LOCK_BUSY); in ocfs2_locking_ast()
1074 lockres->l_name, status); in ocfs2_locking_ast()
1075 spin_unlock_irqrestore(&lockres->l_lock, flags); in ocfs2_locking_ast()
1080 "level %d => %d\n", lockres->l_name, lockres->l_action, in ocfs2_locking_ast()
1081 lockres->l_unlock_action, lockres->l_level, lockres->l_requested); in ocfs2_locking_ast()
1083 switch(lockres->l_action) { in ocfs2_locking_ast()
1085 ocfs2_generic_handle_attach_action(lockres); in ocfs2_locking_ast()
1086 lockres_clear_flags(lockres, OCFS2_LOCK_LOCAL); in ocfs2_locking_ast()
1089 ocfs2_generic_handle_convert_action(lockres); in ocfs2_locking_ast()
1092 ocfs2_generic_handle_downconvert_action(lockres); in ocfs2_locking_ast()
1097 lockres->l_name, lockres->l_action, lockres->l_flags, in ocfs2_locking_ast()
1098 lockres->l_unlock_action); in ocfs2_locking_ast()
1104 lockres->l_action = OCFS2_AST_INVALID; in ocfs2_locking_ast()
1107 if (lockres->l_unlock_action == OCFS2_UNLOCK_CANCEL_CONVERT) in ocfs2_locking_ast()
1108 lockres->l_unlock_action = OCFS2_UNLOCK_INVALID; in ocfs2_locking_ast()
1116 __lockres_clear_pending(lockres, lockres->l_pending_gen, osb); in ocfs2_locking_ast()
1118 wake_up(&lockres->l_event); in ocfs2_locking_ast()
1119 spin_unlock_irqrestore(&lockres->l_lock, flags); in ocfs2_locking_ast()
1124 struct ocfs2_lock_res *lockres = ocfs2_lksb_to_lock_res(lksb); in ocfs2_unlock_ast() local
1128 lockres->l_name, lockres->l_unlock_action); in ocfs2_unlock_ast()
1130 spin_lock_irqsave(&lockres->l_lock, flags); in ocfs2_unlock_ast()
1133 "unlock_action %d\n", error, lockres->l_name, in ocfs2_unlock_ast()
1134 lockres->l_unlock_action); in ocfs2_unlock_ast()
1135 spin_unlock_irqrestore(&lockres->l_lock, flags); in ocfs2_unlock_ast()
1139 switch(lockres->l_unlock_action) { in ocfs2_unlock_ast()
1141 mlog(0, "Cancel convert success for %s\n", lockres->l_name); in ocfs2_unlock_ast()
1142 lockres->l_action = OCFS2_AST_INVALID; in ocfs2_unlock_ast()
1145 if (lockres->l_flags & OCFS2_LOCK_BLOCKED) in ocfs2_unlock_ast()
1146 ocfs2_wake_downconvert_thread(ocfs2_get_lockres_osb(lockres)); in ocfs2_unlock_ast()
1149 lockres->l_level = DLM_LOCK_IV; in ocfs2_unlock_ast()
1155 lockres_clear_flags(lockres, OCFS2_LOCK_BUSY); in ocfs2_unlock_ast()
1156 lockres->l_unlock_action = OCFS2_UNLOCK_INVALID; in ocfs2_unlock_ast()
1157 wake_up(&lockres->l_event); in ocfs2_unlock_ast()
1158 spin_unlock_irqrestore(&lockres->l_lock, flags); in ocfs2_unlock_ast()
1199 static inline void ocfs2_recover_from_dlm_error(struct ocfs2_lock_res *lockres, in ocfs2_recover_from_dlm_error() argument
1204 spin_lock_irqsave(&lockres->l_lock, flags); in ocfs2_recover_from_dlm_error()
1205 lockres_clear_flags(lockres, OCFS2_LOCK_BUSY); in ocfs2_recover_from_dlm_error()
1206 lockres_clear_flags(lockres, OCFS2_LOCK_UPCONVERT_FINISHING); in ocfs2_recover_from_dlm_error()
1208 lockres->l_action = OCFS2_AST_INVALID; in ocfs2_recover_from_dlm_error()
1210 lockres->l_unlock_action = OCFS2_UNLOCK_INVALID; in ocfs2_recover_from_dlm_error()
1211 spin_unlock_irqrestore(&lockres->l_lock, flags); in ocfs2_recover_from_dlm_error()
1213 wake_up(&lockres->l_event); in ocfs2_recover_from_dlm_error()
1221 struct ocfs2_lock_res *lockres, in ocfs2_lock_create() argument
1229 mlog(0, "lock %s, level = %d, flags = %u\n", lockres->l_name, level, in ocfs2_lock_create()
1232 spin_lock_irqsave(&lockres->l_lock, flags); in ocfs2_lock_create()
1233 if ((lockres->l_flags & OCFS2_LOCK_ATTACHED) || in ocfs2_lock_create()
1234 (lockres->l_flags & OCFS2_LOCK_BUSY)) { in ocfs2_lock_create()
1235 spin_unlock_irqrestore(&lockres->l_lock, flags); in ocfs2_lock_create()
1239 lockres->l_action = OCFS2_AST_ATTACH; in ocfs2_lock_create()
1240 lockres->l_requested = level; in ocfs2_lock_create()
1241 lockres_or_flags(lockres, OCFS2_LOCK_BUSY); in ocfs2_lock_create()
1242 gen = lockres_set_pending(lockres); in ocfs2_lock_create()
1243 spin_unlock_irqrestore(&lockres->l_lock, flags); in ocfs2_lock_create()
1247 &lockres->l_lksb, in ocfs2_lock_create()
1249 lockres->l_name, in ocfs2_lock_create()
1251 lockres_clear_pending(lockres, gen, osb); in ocfs2_lock_create()
1253 ocfs2_log_dlm_error("ocfs2_dlm_lock", ret, lockres); in ocfs2_lock_create()
1254 ocfs2_recover_from_dlm_error(lockres, 1); in ocfs2_lock_create()
1257 mlog(0, "lock %s, return from ocfs2_dlm_lock\n", lockres->l_name); in ocfs2_lock_create()
1263 static inline int ocfs2_check_wait_flag(struct ocfs2_lock_res *lockres, in ocfs2_check_wait_flag() argument
1269 spin_lock_irqsave(&lockres->l_lock, flags); in ocfs2_check_wait_flag()
1270 ret = lockres->l_flags & flag; in ocfs2_check_wait_flag()
1271 spin_unlock_irqrestore(&lockres->l_lock, flags); in ocfs2_check_wait_flag()
1276 static inline void ocfs2_wait_on_busy_lock(struct ocfs2_lock_res *lockres) in ocfs2_wait_on_busy_lock() argument
1279 wait_event(lockres->l_event, in ocfs2_wait_on_busy_lock()
1280 !ocfs2_check_wait_flag(lockres, OCFS2_LOCK_BUSY)); in ocfs2_wait_on_busy_lock()
1283 static inline void ocfs2_wait_on_refreshing_lock(struct ocfs2_lock_res *lockres) in ocfs2_wait_on_refreshing_lock() argument
1286 wait_event(lockres->l_event, in ocfs2_wait_on_refreshing_lock()
1287 !ocfs2_check_wait_flag(lockres, OCFS2_LOCK_REFRESHING)); in ocfs2_wait_on_refreshing_lock()
1293 static inline int ocfs2_may_continue_on_blocked_lock(struct ocfs2_lock_res *lockres, in ocfs2_may_continue_on_blocked_lock() argument
1296 BUG_ON(!(lockres->l_flags & OCFS2_LOCK_BLOCKED)); in ocfs2_may_continue_on_blocked_lock()
1298 return wanted <= ocfs2_highest_compat_lock_level(lockres->l_blocking); in ocfs2_may_continue_on_blocked_lock()
1316 static void lockres_add_mask_waiter(struct ocfs2_lock_res *lockres, in lockres_add_mask_waiter() argument
1323 assert_spin_locked(&lockres->l_lock); in lockres_add_mask_waiter()
1325 list_add_tail(&mw->mw_item, &lockres->l_mask_waiters); in lockres_add_mask_waiter()
1332 static int __lockres_remove_mask_waiter(struct ocfs2_lock_res *lockres, in __lockres_remove_mask_waiter() argument
1337 assert_spin_locked(&lockres->l_lock); in __lockres_remove_mask_waiter()
1339 if ((lockres->l_flags & mw->mw_mask) != mw->mw_goal) in __lockres_remove_mask_waiter()
1349 static int lockres_remove_mask_waiter(struct ocfs2_lock_res *lockres, in lockres_remove_mask_waiter() argument
1355 spin_lock_irqsave(&lockres->l_lock, flags); in lockres_remove_mask_waiter()
1356 ret = __lockres_remove_mask_waiter(lockres, mw); in lockres_remove_mask_waiter()
1357 spin_unlock_irqrestore(&lockres->l_lock, flags); in lockres_remove_mask_waiter()
1364 struct ocfs2_lock_res *lockres) in ocfs2_wait_for_mask_interruptible() argument
1370 lockres_remove_mask_waiter(lockres, mw); in ocfs2_wait_for_mask_interruptible()
1379 struct ocfs2_lock_res *lockres, in __ocfs2_cluster_lock() argument
1395 if (!(lockres->l_flags & OCFS2_LOCK_INITIALIZED)) { in __ocfs2_cluster_lock()
1402 if (lockres->l_ops->flags & LOCK_TYPE_USES_LVB) in __ocfs2_cluster_lock()
1408 spin_lock_irqsave(&lockres->l_lock, flags); in __ocfs2_cluster_lock()
1415 mlog_bug_on_msg(lockres->l_flags & OCFS2_LOCK_FREEING, in __ocfs2_cluster_lock()
1417 "0x%lx\n", lockres->l_name, lockres->l_flags); in __ocfs2_cluster_lock()
1422 if (lockres->l_flags & OCFS2_LOCK_BUSY && in __ocfs2_cluster_lock()
1423 level > lockres->l_level) { in __ocfs2_cluster_lock()
1426 lockres_add_mask_waiter(lockres, &mw, OCFS2_LOCK_BUSY, 0); in __ocfs2_cluster_lock()
1431 if (lockres->l_flags & OCFS2_LOCK_UPCONVERT_FINISHING) { in __ocfs2_cluster_lock()
1446 if (level <= lockres->l_level) in __ocfs2_cluster_lock()
1450 if (lockres->l_flags & OCFS2_LOCK_BLOCKED && in __ocfs2_cluster_lock()
1451 !ocfs2_may_continue_on_blocked_lock(lockres, level)) { in __ocfs2_cluster_lock()
1454 lockres_add_mask_waiter(lockres, &mw, OCFS2_LOCK_BLOCKED, 0); in __ocfs2_cluster_lock()
1459 if (level > lockres->l_level) { in __ocfs2_cluster_lock()
1467 if (lockres->l_action != OCFS2_AST_INVALID) in __ocfs2_cluster_lock()
1469 lockres->l_name, lockres->l_action); in __ocfs2_cluster_lock()
1471 if (!(lockres->l_flags & OCFS2_LOCK_ATTACHED)) { in __ocfs2_cluster_lock()
1472 lockres->l_action = OCFS2_AST_ATTACH; in __ocfs2_cluster_lock()
1475 lockres->l_action = OCFS2_AST_CONVERT; in __ocfs2_cluster_lock()
1479 lockres->l_requested = level; in __ocfs2_cluster_lock()
1480 lockres_or_flags(lockres, OCFS2_LOCK_BUSY); in __ocfs2_cluster_lock()
1481 gen = lockres_set_pending(lockres); in __ocfs2_cluster_lock()
1482 spin_unlock_irqrestore(&lockres->l_lock, flags); in __ocfs2_cluster_lock()
1488 lockres->l_name, lockres->l_level, level); in __ocfs2_cluster_lock()
1493 &lockres->l_lksb, in __ocfs2_cluster_lock()
1495 lockres->l_name, in __ocfs2_cluster_lock()
1497 lockres_clear_pending(lockres, gen, osb); in __ocfs2_cluster_lock()
1502 ret, lockres); in __ocfs2_cluster_lock()
1504 ocfs2_recover_from_dlm_error(lockres, 1); in __ocfs2_cluster_lock()
1510 lockres->l_name); in __ocfs2_cluster_lock()
1522 ocfs2_inc_holders(lockres, level); in __ocfs2_cluster_lock()
1526 lockres_clear_flags(lockres, OCFS2_LOCK_UPCONVERT_FINISHING); in __ocfs2_cluster_lock()
1529 kick_dc = (lockres->l_flags & OCFS2_LOCK_BLOCKED); in __ocfs2_cluster_lock()
1531 spin_unlock_irqrestore(&lockres->l_lock, flags); in __ocfs2_cluster_lock()
1546 spin_lock_irqsave(&lockres->l_lock, flags); in __ocfs2_cluster_lock()
1547 if (__lockres_remove_mask_waiter(lockres, &mw)) { in __ocfs2_cluster_lock()
1549 lockres_or_flags(lockres, in __ocfs2_cluster_lock()
1551 spin_unlock_irqrestore(&lockres->l_lock, flags); in __ocfs2_cluster_lock()
1554 spin_unlock_irqrestore(&lockres->l_lock, flags); in __ocfs2_cluster_lock()
1564 ocfs2_update_lock_stats(lockres, level, &mw, ret); in __ocfs2_cluster_lock()
1567 if (!ret && lockres->l_lockdep_map.key != NULL) { in __ocfs2_cluster_lock()
1569 rwsem_acquire_read(&lockres->l_lockdep_map, l_subclass, in __ocfs2_cluster_lock()
1573 rwsem_acquire(&lockres->l_lockdep_map, l_subclass, in __ocfs2_cluster_lock()
1582 struct ocfs2_lock_res *lockres, in ocfs2_cluster_lock() argument
1587 return __ocfs2_cluster_lock(osb, lockres, level, lkm_flags, arg_flags, in ocfs2_cluster_lock()
1593 struct ocfs2_lock_res *lockres, in __ocfs2_cluster_unlock() argument
1599 spin_lock_irqsave(&lockres->l_lock, flags); in __ocfs2_cluster_unlock()
1600 ocfs2_dec_holders(lockres, level); in __ocfs2_cluster_unlock()
1601 ocfs2_downconvert_on_unlock(osb, lockres); in __ocfs2_cluster_unlock()
1602 spin_unlock_irqrestore(&lockres->l_lock, flags); in __ocfs2_cluster_unlock()
1604 if (lockres->l_lockdep_map.key != NULL) in __ocfs2_cluster_unlock()
1605 rwsem_release(&lockres->l_lockdep_map, 1, caller_ip); in __ocfs2_cluster_unlock()
1610 struct ocfs2_lock_res *lockres, in ocfs2_create_new_lock() argument
1618 spin_lock_irqsave(&lockres->l_lock, flags); in ocfs2_create_new_lock()
1619 BUG_ON(lockres->l_flags & OCFS2_LOCK_ATTACHED); in ocfs2_create_new_lock()
1620 lockres_or_flags(lockres, OCFS2_LOCK_LOCAL); in ocfs2_create_new_lock()
1621 spin_unlock_irqrestore(&lockres->l_lock, flags); in ocfs2_create_new_lock()
1623 return ocfs2_lock_create(osb, lockres, level, lkm_flags); in ocfs2_create_new_lock()
1679 struct ocfs2_lock_res *lockres; in ocfs2_rw_lock() local
1691 lockres = &OCFS2_I(inode)->ip_rw_lockres; in ocfs2_rw_lock()
1695 status = ocfs2_cluster_lock(OCFS2_SB(inode->i_sb), lockres, level, 0, in ocfs2_rw_lock()
1706 struct ocfs2_lock_res *lockres = &OCFS2_I(inode)->ip_rw_lockres; in ocfs2_rw_unlock() local
1714 ocfs2_cluster_unlock(OCFS2_SB(inode->i_sb), lockres, level); in ocfs2_rw_unlock()
1723 struct ocfs2_lock_res *lockres; in ocfs2_open_lock() local
1734 lockres = &OCFS2_I(inode)->ip_open_lockres; in ocfs2_open_lock()
1736 status = ocfs2_cluster_lock(OCFS2_SB(inode->i_sb), lockres, in ocfs2_open_lock()
1748 struct ocfs2_lock_res *lockres; in ocfs2_try_open_lock() local
1766 lockres = &OCFS2_I(inode)->ip_open_lockres; in ocfs2_try_open_lock()
1776 status = ocfs2_cluster_lock(OCFS2_SB(inode->i_sb), lockres, in ocfs2_try_open_lock()
1788 struct ocfs2_lock_res *lockres = &OCFS2_I(inode)->ip_open_lockres; in ocfs2_open_unlock() local
1797 if(lockres->l_ro_holders) in ocfs2_open_unlock()
1798 ocfs2_cluster_unlock(OCFS2_SB(inode->i_sb), lockres, in ocfs2_open_unlock()
1800 if(lockres->l_ex_holders) in ocfs2_open_unlock()
1801 ocfs2_cluster_unlock(OCFS2_SB(inode->i_sb), lockres, in ocfs2_open_unlock()
1808 static int ocfs2_flock_handle_signal(struct ocfs2_lock_res *lockres, in ocfs2_flock_handle_signal() argument
1812 struct ocfs2_super *osb = ocfs2_get_lockres_osb(lockres); in ocfs2_flock_handle_signal()
1819 spin_lock_irqsave(&lockres->l_lock, flags); in ocfs2_flock_handle_signal()
1820 if (lockres->l_flags & OCFS2_LOCK_BUSY) { in ocfs2_flock_handle_signal()
1821 ret = ocfs2_prepare_cancel_convert(osb, lockres); in ocfs2_flock_handle_signal()
1823 spin_unlock_irqrestore(&lockres->l_lock, flags); in ocfs2_flock_handle_signal()
1824 ret = ocfs2_cancel_convert(osb, lockres); in ocfs2_flock_handle_signal()
1831 lockres_add_mask_waiter(lockres, &mw, OCFS2_LOCK_BUSY, 0); in ocfs2_flock_handle_signal()
1832 spin_unlock_irqrestore(&lockres->l_lock, flags); in ocfs2_flock_handle_signal()
1843 if (lockres->l_level == level) in ocfs2_flock_handle_signal()
1847 lockres->l_flags, lockres->l_level, lockres->l_action); in ocfs2_flock_handle_signal()
1849 spin_unlock_irqrestore(&lockres->l_lock, flags); in ocfs2_flock_handle_signal()
1882 struct ocfs2_lock_res *lockres = &fp->fp_flock; in ocfs2_file_lock() local
1888 if ((lockres->l_flags & OCFS2_LOCK_BUSY) || in ocfs2_file_lock()
1889 (lockres->l_level > DLM_LOCK_NL)) { in ocfs2_file_lock()
1892 "level: %u\n", lockres->l_name, lockres->l_flags, in ocfs2_file_lock()
1893 lockres->l_level); in ocfs2_file_lock()
1897 spin_lock_irqsave(&lockres->l_lock, flags); in ocfs2_file_lock()
1898 if (!(lockres->l_flags & OCFS2_LOCK_ATTACHED)) { in ocfs2_file_lock()
1899 lockres_add_mask_waiter(lockres, &mw, OCFS2_LOCK_BUSY, 0); in ocfs2_file_lock()
1900 spin_unlock_irqrestore(&lockres->l_lock, flags); in ocfs2_file_lock()
1906 ret = ocfs2_lock_create(osb, lockres, DLM_LOCK_NL, 0); in ocfs2_file_lock()
1917 spin_lock_irqsave(&lockres->l_lock, flags); in ocfs2_file_lock()
1920 lockres->l_action = OCFS2_AST_CONVERT; in ocfs2_file_lock()
1922 lockres->l_requested = level; in ocfs2_file_lock()
1923 lockres_or_flags(lockres, OCFS2_LOCK_BUSY); in ocfs2_file_lock()
1925 lockres_add_mask_waiter(lockres, &mw, OCFS2_LOCK_BUSY, 0); in ocfs2_file_lock()
1926 spin_unlock_irqrestore(&lockres->l_lock, flags); in ocfs2_file_lock()
1928 ret = ocfs2_dlm_lock(osb->cconn, level, &lockres->l_lksb, lkm_flags, in ocfs2_file_lock()
1929 lockres->l_name, OCFS2_LOCK_ID_MAX_LEN - 1); in ocfs2_file_lock()
1932 ocfs2_log_dlm_error("ocfs2_dlm_lock", ret, lockres); in ocfs2_file_lock()
1936 ocfs2_recover_from_dlm_error(lockres, 1); in ocfs2_file_lock()
1937 lockres_remove_mask_waiter(lockres, &mw); in ocfs2_file_lock()
1941 ret = ocfs2_wait_for_mask_interruptible(&mw, lockres); in ocfs2_file_lock()
1958 ret = ocfs2_flock_handle_signal(lockres, level); in ocfs2_file_lock()
1959 } else if (!ret && (level > lockres->l_level)) { in ocfs2_file_lock()
1968 lockres->l_name, ex, trylock, ret); in ocfs2_file_lock()
1978 struct ocfs2_lock_res *lockres = &fp->fp_flock; in ocfs2_file_unlock() local
1984 if (!(lockres->l_flags & OCFS2_LOCK_ATTACHED)) in ocfs2_file_unlock()
1987 if (lockres->l_level == DLM_LOCK_NL) in ocfs2_file_unlock()
1991 lockres->l_name, lockres->l_flags, lockres->l_level, in ocfs2_file_unlock()
1992 lockres->l_action); in ocfs2_file_unlock()
1994 spin_lock_irqsave(&lockres->l_lock, flags); in ocfs2_file_unlock()
1998 lockres_or_flags(lockres, OCFS2_LOCK_BLOCKED); in ocfs2_file_unlock()
1999 lockres->l_blocking = DLM_LOCK_EX; in ocfs2_file_unlock()
2001 gen = ocfs2_prepare_downconvert(lockres, DLM_LOCK_NL); in ocfs2_file_unlock()
2002 lockres_add_mask_waiter(lockres, &mw, OCFS2_LOCK_BUSY, 0); in ocfs2_file_unlock()
2003 spin_unlock_irqrestore(&lockres->l_lock, flags); in ocfs2_file_unlock()
2005 ret = ocfs2_downconvert_lock(osb, lockres, DLM_LOCK_NL, 0, gen); in ocfs2_file_unlock()
2017 struct ocfs2_lock_res *lockres) in ocfs2_downconvert_on_unlock() argument
2024 if (lockres->l_flags & OCFS2_LOCK_BLOCKED) { in ocfs2_downconvert_on_unlock()
2025 switch(lockres->l_blocking) { in ocfs2_downconvert_on_unlock()
2027 if (!lockres->l_ex_holders && !lockres->l_ro_holders) in ocfs2_downconvert_on_unlock()
2031 if (!lockres->l_ex_holders) in ocfs2_downconvert_on_unlock()
2066 struct ocfs2_lock_res *lockres = &oi->ip_inode_lockres; in __ocfs2_stuff_meta_lvb() local
2069 lvb = ocfs2_dlm_lvb(&lockres->l_lksb); in __ocfs2_stuff_meta_lvb()
2099 mlog_meta_lvb(0, lockres); in __ocfs2_stuff_meta_lvb()
2112 struct ocfs2_lock_res *lockres = &oi->ip_inode_lockres; in ocfs2_refresh_inode_from_lvb() local
2115 mlog_meta_lvb(0, lockres); in ocfs2_refresh_inode_from_lvb()
2117 lvb = ocfs2_dlm_lvb(&lockres->l_lksb); in ocfs2_refresh_inode_from_lvb()
2148 struct ocfs2_lock_res *lockres) in ocfs2_meta_lvb_is_trustable() argument
2150 struct ocfs2_meta_lvb *lvb = ocfs2_dlm_lvb(&lockres->l_lksb); in ocfs2_meta_lvb_is_trustable()
2152 if (ocfs2_dlm_lvb_valid(&lockres->l_lksb) in ocfs2_meta_lvb_is_trustable()
2166 static int ocfs2_should_refresh_lock_res(struct ocfs2_lock_res *lockres) in ocfs2_should_refresh_lock_res() argument
2172 spin_lock_irqsave(&lockres->l_lock, flags); in ocfs2_should_refresh_lock_res()
2173 if (!(lockres->l_flags & OCFS2_LOCK_NEEDS_REFRESH)) { in ocfs2_should_refresh_lock_res()
2174 spin_unlock_irqrestore(&lockres->l_lock, flags); in ocfs2_should_refresh_lock_res()
2178 if (lockres->l_flags & OCFS2_LOCK_REFRESHING) { in ocfs2_should_refresh_lock_res()
2179 spin_unlock_irqrestore(&lockres->l_lock, flags); in ocfs2_should_refresh_lock_res()
2181 ocfs2_wait_on_refreshing_lock(lockres); in ocfs2_should_refresh_lock_res()
2186 lockres_or_flags(lockres, OCFS2_LOCK_REFRESHING); in ocfs2_should_refresh_lock_res()
2187 spin_unlock_irqrestore(&lockres->l_lock, flags); in ocfs2_should_refresh_lock_res()
2197 static inline void ocfs2_complete_lock_res_refresh(struct ocfs2_lock_res *lockres, in ocfs2_complete_lock_res_refresh() argument
2202 spin_lock_irqsave(&lockres->l_lock, flags); in ocfs2_complete_lock_res_refresh()
2203 lockres_clear_flags(lockres, OCFS2_LOCK_REFRESHING); in ocfs2_complete_lock_res_refresh()
2205 lockres_clear_flags(lockres, OCFS2_LOCK_NEEDS_REFRESH); in ocfs2_complete_lock_res_refresh()
2206 spin_unlock_irqrestore(&lockres->l_lock, flags); in ocfs2_complete_lock_res_refresh()
2208 wake_up(&lockres->l_event); in ocfs2_complete_lock_res_refresh()
2217 struct ocfs2_lock_res *lockres = &oi->ip_inode_lockres; in ocfs2_inode_lock_update() local
2235 if (!ocfs2_should_refresh_lock_res(lockres)) in ocfs2_inode_lock_update()
2244 if (ocfs2_meta_lvb_is_trustable(inode, lockres)) { in ocfs2_inode_lock_update()
2282 ocfs2_track_lock_refresh(lockres); in ocfs2_inode_lock_update()
2287 ocfs2_complete_lock_res_refresh(lockres, status); in ocfs2_inode_lock_update()
2326 struct ocfs2_lock_res *lockres = NULL; in ocfs2_inode_lock_full_nested() local
2352 lockres = &OCFS2_I(inode)->ip_inode_lockres; in ocfs2_inode_lock_full_nested()
2358 status = __ocfs2_cluster_lock(osb, lockres, level, dlm_flags, in ocfs2_inode_lock_full_nested()
2385 if (lockres) in ocfs2_inode_lock_full_nested()
2386 ocfs2_complete_lock_res_refresh(lockres, 0); in ocfs2_inode_lock_full_nested()
2506 struct ocfs2_lock_res *lockres = &OCFS2_I(inode)->ip_inode_lockres; in ocfs2_inode_unlock() local
2515 ocfs2_cluster_unlock(OCFS2_SB(inode->i_sb), lockres, level); in ocfs2_inode_unlock()
2520 struct ocfs2_lock_res *lockres; in ocfs2_orphan_scan_lock() local
2530 lockres = &osb->osb_orphan_scan.os_lockres; in ocfs2_orphan_scan_lock()
2531 status = ocfs2_cluster_lock(osb, lockres, DLM_LOCK_EX, 0, 0); in ocfs2_orphan_scan_lock()
2535 lvb = ocfs2_dlm_lvb(&lockres->l_lksb); in ocfs2_orphan_scan_lock()
2536 if (ocfs2_dlm_lvb_valid(&lockres->l_lksb) && in ocfs2_orphan_scan_lock()
2547 struct ocfs2_lock_res *lockres; in ocfs2_orphan_scan_unlock() local
2551 lockres = &osb->osb_orphan_scan.os_lockres; in ocfs2_orphan_scan_unlock()
2552 lvb = ocfs2_dlm_lvb(&lockres->l_lksb); in ocfs2_orphan_scan_unlock()
2555 ocfs2_cluster_unlock(osb, lockres, DLM_LOCK_EX); in ocfs2_orphan_scan_unlock()
2564 struct ocfs2_lock_res *lockres = &osb->osb_super_lockres; in ocfs2_super_lock() local
2572 status = ocfs2_cluster_lock(osb, lockres, level, 0, 0); in ocfs2_super_lock()
2582 status = ocfs2_should_refresh_lock_res(lockres); in ocfs2_super_lock()
2586 ocfs2_complete_lock_res_refresh(lockres, status); in ocfs2_super_lock()
2589 ocfs2_cluster_unlock(osb, lockres, level); in ocfs2_super_lock()
2592 ocfs2_track_lock_refresh(lockres); in ocfs2_super_lock()
2602 struct ocfs2_lock_res *lockres = &osb->osb_super_lockres; in ocfs2_super_unlock() local
2605 ocfs2_cluster_unlock(osb, lockres, level); in ocfs2_super_unlock()
2611 struct ocfs2_lock_res *lockres = &osb->osb_rename_lockres; in ocfs2_rename_lock() local
2619 status = ocfs2_cluster_lock(osb, lockres, DLM_LOCK_EX, 0, 0); in ocfs2_rename_lock()
2628 struct ocfs2_lock_res *lockres = &osb->osb_rename_lockres; in ocfs2_rename_unlock() local
2631 ocfs2_cluster_unlock(osb, lockres, DLM_LOCK_EX); in ocfs2_rename_unlock()
2637 struct ocfs2_lock_res *lockres = &osb->osb_nfs_sync_lockres; in ocfs2_nfs_sync_lock() local
2645 status = ocfs2_cluster_lock(osb, lockres, ex ? LKM_EXMODE : LKM_PRMODE, in ocfs2_nfs_sync_lock()
2655 struct ocfs2_lock_res *lockres = &osb->osb_nfs_sync_lockres; in ocfs2_nfs_sync_unlock() local
2658 ocfs2_cluster_unlock(osb, lockres, in ocfs2_nfs_sync_unlock()
2829 struct ocfs2_lock_res *lockres = v; in ocfs2_dlm_seq_show() local
2831 if (!lockres) in ocfs2_dlm_seq_show()
2836 if (lockres->l_type == OCFS2_LOCK_TYPE_DENTRY) in ocfs2_dlm_seq_show()
2838 lockres->l_name, in ocfs2_dlm_seq_show()
2839 (unsigned int)ocfs2_get_dentry_lock_ino(lockres)); in ocfs2_dlm_seq_show()
2841 seq_printf(m, "%.*s\t", OCFS2_LOCK_ID_MAX_LEN, lockres->l_name); in ocfs2_dlm_seq_show()
2851 lockres->l_level, in ocfs2_dlm_seq_show()
2852 lockres->l_flags, in ocfs2_dlm_seq_show()
2853 lockres->l_action, in ocfs2_dlm_seq_show()
2854 lockres->l_unlock_action, in ocfs2_dlm_seq_show()
2855 lockres->l_ro_holders, in ocfs2_dlm_seq_show()
2856 lockres->l_ex_holders, in ocfs2_dlm_seq_show()
2857 lockres->l_requested, in ocfs2_dlm_seq_show()
2858 lockres->l_blocking); in ocfs2_dlm_seq_show()
2861 lvb = ocfs2_dlm_lvb(&lockres->l_lksb); in ocfs2_dlm_seq_show()
2896 lock_num_prmode(lockres), in ocfs2_dlm_seq_show()
2897 lock_num_exmode(lockres), in ocfs2_dlm_seq_show()
2898 lock_num_prmode_failed(lockres), in ocfs2_dlm_seq_show()
2899 lock_num_exmode_failed(lockres), in ocfs2_dlm_seq_show()
2900 lock_total_prmode(lockres), in ocfs2_dlm_seq_show()
2901 lock_total_exmode(lockres), in ocfs2_dlm_seq_show()
2902 lock_max_prmode(lockres), in ocfs2_dlm_seq_show()
2903 lock_max_exmode(lockres), in ocfs2_dlm_seq_show()
2904 lock_refresh(lockres)); in ocfs2_dlm_seq_show()
3083 struct ocfs2_lock_res *lockres) in ocfs2_drop_lock() argument
3090 if (!(lockres->l_flags & OCFS2_LOCK_INITIALIZED)) in ocfs2_drop_lock()
3093 if (lockres->l_ops->flags & LOCK_TYPE_USES_LVB) in ocfs2_drop_lock()
3096 spin_lock_irqsave(&lockres->l_lock, flags); in ocfs2_drop_lock()
3098 mlog_bug_on_msg(!(lockres->l_flags & OCFS2_LOCK_FREEING), in ocfs2_drop_lock()
3100 lockres->l_name, lockres->l_flags); in ocfs2_drop_lock()
3102 while (lockres->l_flags & OCFS2_LOCK_BUSY) { in ocfs2_drop_lock()
3105 lockres->l_name, lockres->l_flags, lockres->l_action, in ocfs2_drop_lock()
3106 lockres->l_unlock_action); in ocfs2_drop_lock()
3108 spin_unlock_irqrestore(&lockres->l_lock, flags); in ocfs2_drop_lock()
3113 ocfs2_wait_on_busy_lock(lockres); in ocfs2_drop_lock()
3115 spin_lock_irqsave(&lockres->l_lock, flags); in ocfs2_drop_lock()
3118 if (lockres->l_ops->flags & LOCK_TYPE_USES_LVB) { in ocfs2_drop_lock()
3119 if (lockres->l_flags & OCFS2_LOCK_ATTACHED && in ocfs2_drop_lock()
3120 lockres->l_level == DLM_LOCK_EX && in ocfs2_drop_lock()
3121 !(lockres->l_flags & OCFS2_LOCK_NEEDS_REFRESH)) in ocfs2_drop_lock()
3122 lockres->l_ops->set_lvb(lockres); in ocfs2_drop_lock()
3125 if (lockres->l_flags & OCFS2_LOCK_BUSY) in ocfs2_drop_lock()
3127 lockres->l_name); in ocfs2_drop_lock()
3128 if (lockres->l_flags & OCFS2_LOCK_BLOCKED) in ocfs2_drop_lock()
3129 mlog(0, "destroying blocked lock: \"%s\"\n", lockres->l_name); in ocfs2_drop_lock()
3131 if (!(lockres->l_flags & OCFS2_LOCK_ATTACHED)) { in ocfs2_drop_lock()
3132 spin_unlock_irqrestore(&lockres->l_lock, flags); in ocfs2_drop_lock()
3136 lockres_clear_flags(lockres, OCFS2_LOCK_ATTACHED); in ocfs2_drop_lock()
3140 BUG_ON(lockres->l_action != OCFS2_AST_INVALID); in ocfs2_drop_lock()
3143 lockres_or_flags(lockres, OCFS2_LOCK_BUSY); in ocfs2_drop_lock()
3144 lockres->l_unlock_action = OCFS2_UNLOCK_DROP_LOCK; in ocfs2_drop_lock()
3145 spin_unlock_irqrestore(&lockres->l_lock, flags); in ocfs2_drop_lock()
3147 mlog(0, "lock %s\n", lockres->l_name); in ocfs2_drop_lock()
3149 ret = ocfs2_dlm_unlock(osb->cconn, &lockres->l_lksb, lkm_flags); in ocfs2_drop_lock()
3151 ocfs2_log_dlm_error("ocfs2_dlm_unlock", ret, lockres); in ocfs2_drop_lock()
3152 mlog(ML_ERROR, "lockres flags: %lu\n", lockres->l_flags); in ocfs2_drop_lock()
3153 ocfs2_dlm_dump_lksb(&lockres->l_lksb); in ocfs2_drop_lock()
3157 lockres->l_name); in ocfs2_drop_lock()
3159 ocfs2_wait_on_busy_lock(lockres); in ocfs2_drop_lock()
3165 struct ocfs2_lock_res *lockres);
3174 struct ocfs2_lock_res *lockres) in ocfs2_mark_lockres_freeing() argument
3182 spin_lock_irqsave(&lockres->l_lock, flags); in ocfs2_mark_lockres_freeing()
3183 lockres->l_flags |= OCFS2_LOCK_FREEING; in ocfs2_mark_lockres_freeing()
3184 if (lockres->l_flags & OCFS2_LOCK_QUEUED && current == osb->dc_task) { in ocfs2_mark_lockres_freeing()
3202 spin_unlock_irqrestore(&lockres->l_lock, flags); in ocfs2_mark_lockres_freeing()
3204 list_del_init(&lockres->l_blocked_list); in ocfs2_mark_lockres_freeing()
3213 WARN_ON_ONCE(lockres->l_ops->post_unlock); in ocfs2_mark_lockres_freeing()
3215 ocfs2_process_blocked_lock(osb, lockres); in ocfs2_mark_lockres_freeing()
3218 while (lockres->l_flags & OCFS2_LOCK_QUEUED) { in ocfs2_mark_lockres_freeing()
3219 lockres_add_mask_waiter(lockres, &mw, OCFS2_LOCK_QUEUED, 0); in ocfs2_mark_lockres_freeing()
3220 spin_unlock_irqrestore(&lockres->l_lock, flags); in ocfs2_mark_lockres_freeing()
3222 mlog(0, "Waiting on lockres %s\n", lockres->l_name); in ocfs2_mark_lockres_freeing()
3228 spin_lock_irqsave(&lockres->l_lock, flags); in ocfs2_mark_lockres_freeing()
3230 spin_unlock_irqrestore(&lockres->l_lock, flags); in ocfs2_mark_lockres_freeing()
3234 struct ocfs2_lock_res *lockres) in ocfs2_simple_drop_lockres() argument
3238 ocfs2_mark_lockres_freeing(osb, lockres); in ocfs2_simple_drop_lockres()
3239 ret = ocfs2_drop_lock(osb, lockres); in ocfs2_simple_drop_lockres()
3283 static unsigned int ocfs2_prepare_downconvert(struct ocfs2_lock_res *lockres, in ocfs2_prepare_downconvert() argument
3286 assert_spin_locked(&lockres->l_lock); in ocfs2_prepare_downconvert()
3288 BUG_ON(lockres->l_blocking <= DLM_LOCK_NL); in ocfs2_prepare_downconvert()
3290 if (lockres->l_level <= new_level) { in ocfs2_prepare_downconvert()
3293 "block %d, pgen %d\n", lockres->l_name, lockres->l_level, in ocfs2_prepare_downconvert()
3294 new_level, list_empty(&lockres->l_blocked_list), in ocfs2_prepare_downconvert()
3295 list_empty(&lockres->l_mask_waiters), lockres->l_type, in ocfs2_prepare_downconvert()
3296 lockres->l_flags, lockres->l_ro_holders, in ocfs2_prepare_downconvert()
3297 lockres->l_ex_holders, lockres->l_action, in ocfs2_prepare_downconvert()
3298 lockres->l_unlock_action, lockres->l_requested, in ocfs2_prepare_downconvert()
3299 lockres->l_blocking, lockres->l_pending_gen); in ocfs2_prepare_downconvert()
3304 lockres->l_name, lockres->l_level, new_level, lockres->l_blocking); in ocfs2_prepare_downconvert()
3306 lockres->l_action = OCFS2_AST_DOWNCONVERT; in ocfs2_prepare_downconvert()
3307 lockres->l_requested = new_level; in ocfs2_prepare_downconvert()
3308 lockres_or_flags(lockres, OCFS2_LOCK_BUSY); in ocfs2_prepare_downconvert()
3309 return lockres_set_pending(lockres); in ocfs2_prepare_downconvert()
3313 struct ocfs2_lock_res *lockres, in ocfs2_downconvert_lock() argument
3321 mlog(ML_BASTS, "lockres %s, level %d => %d\n", lockres->l_name, in ocfs2_downconvert_lock()
3322 lockres->l_level, new_level); in ocfs2_downconvert_lock()
3329 &lockres->l_lksb, in ocfs2_downconvert_lock()
3331 lockres->l_name, in ocfs2_downconvert_lock()
3333 lockres_clear_pending(lockres, generation, osb); in ocfs2_downconvert_lock()
3335 ocfs2_log_dlm_error("ocfs2_dlm_lock", ret, lockres); in ocfs2_downconvert_lock()
3336 ocfs2_recover_from_dlm_error(lockres, 1); in ocfs2_downconvert_lock()
3347 struct ocfs2_lock_res *lockres) in ocfs2_prepare_cancel_convert() argument
3349 assert_spin_locked(&lockres->l_lock); in ocfs2_prepare_cancel_convert()
3351 if (lockres->l_unlock_action == OCFS2_UNLOCK_CANCEL_CONVERT) { in ocfs2_prepare_cancel_convert()
3355 mlog(ML_BASTS, "lockres %s, skip convert\n", lockres->l_name); in ocfs2_prepare_cancel_convert()
3360 BUG_ON(lockres->l_action != OCFS2_AST_CONVERT && in ocfs2_prepare_cancel_convert()
3361 lockres->l_action != OCFS2_AST_DOWNCONVERT); in ocfs2_prepare_cancel_convert()
3364 lockres->l_unlock_action = OCFS2_UNLOCK_CANCEL_CONVERT; in ocfs2_prepare_cancel_convert()
3366 mlog_bug_on_msg(!(lockres->l_flags & OCFS2_LOCK_BUSY), in ocfs2_prepare_cancel_convert()
3368 lockres->l_name, lockres->l_flags); in ocfs2_prepare_cancel_convert()
3370 mlog(ML_BASTS, "lockres %s\n", lockres->l_name); in ocfs2_prepare_cancel_convert()
3376 struct ocfs2_lock_res *lockres) in ocfs2_cancel_convert() argument
3380 ret = ocfs2_dlm_unlock(osb->cconn, &lockres->l_lksb, in ocfs2_cancel_convert()
3383 ocfs2_log_dlm_error("ocfs2_dlm_unlock", ret, lockres); in ocfs2_cancel_convert()
3384 ocfs2_recover_from_dlm_error(lockres, 0); in ocfs2_cancel_convert()
3387 mlog(ML_BASTS, "lockres %s\n", lockres->l_name); in ocfs2_cancel_convert()
3393 struct ocfs2_lock_res *lockres, in ocfs2_unblock_lock() argument
3404 spin_lock_irqsave(&lockres->l_lock, flags); in ocfs2_unblock_lock()
3410 if (!(lockres->l_flags & OCFS2_LOCK_BLOCKED)) { in ocfs2_unblock_lock()
3411 BUG_ON(lockres->l_blocking != DLM_LOCK_NL); in ocfs2_unblock_lock()
3412 spin_unlock_irqrestore(&lockres->l_lock, flags); in ocfs2_unblock_lock()
3417 if (lockres->l_flags & OCFS2_LOCK_BUSY) { in ocfs2_unblock_lock()
3441 if (lockres->l_flags & OCFS2_LOCK_PENDING) { in ocfs2_unblock_lock()
3443 lockres->l_name); in ocfs2_unblock_lock()
3448 ret = ocfs2_prepare_cancel_convert(osb, lockres); in ocfs2_unblock_lock()
3449 spin_unlock_irqrestore(&lockres->l_lock, flags); in ocfs2_unblock_lock()
3451 ret = ocfs2_cancel_convert(osb, lockres); in ocfs2_unblock_lock()
3467 if (lockres->l_flags & OCFS2_LOCK_UPCONVERT_FINISHING) in ocfs2_unblock_lock()
3475 if (lockres->l_level == DLM_LOCK_NL) { in ocfs2_unblock_lock()
3476 BUG_ON(lockres->l_ex_holders || lockres->l_ro_holders); in ocfs2_unblock_lock()
3477 mlog(ML_BASTS, "lockres %s, Aborting dc\n", lockres->l_name); in ocfs2_unblock_lock()
3478 lockres->l_blocking = DLM_LOCK_NL; in ocfs2_unblock_lock()
3479 lockres_clear_flags(lockres, OCFS2_LOCK_BLOCKED); in ocfs2_unblock_lock()
3480 spin_unlock_irqrestore(&lockres->l_lock, flags); in ocfs2_unblock_lock()
3486 if ((lockres->l_blocking == DLM_LOCK_EX) in ocfs2_unblock_lock()
3487 && (lockres->l_ex_holders || lockres->l_ro_holders)) { in ocfs2_unblock_lock()
3489 lockres->l_name, lockres->l_ex_holders, in ocfs2_unblock_lock()
3490 lockres->l_ro_holders); in ocfs2_unblock_lock()
3496 if (lockres->l_blocking == DLM_LOCK_PR && in ocfs2_unblock_lock()
3497 lockres->l_ex_holders) { in ocfs2_unblock_lock()
3499 lockres->l_name, lockres->l_ex_holders); in ocfs2_unblock_lock()
3507 if ((lockres->l_ops->flags & LOCK_TYPE_REQUIRES_REFRESH) in ocfs2_unblock_lock()
3508 && (lockres->l_flags & OCFS2_LOCK_REFRESHING)) { in ocfs2_unblock_lock()
3510 lockres->l_name); in ocfs2_unblock_lock()
3514 new_level = ocfs2_highest_compat_lock_level(lockres->l_blocking); in ocfs2_unblock_lock()
3516 if (lockres->l_ops->check_downconvert in ocfs2_unblock_lock()
3517 && !lockres->l_ops->check_downconvert(lockres, new_level)) { in ocfs2_unblock_lock()
3519 lockres->l_name); in ocfs2_unblock_lock()
3526 if (!lockres->l_ops->downconvert_worker) in ocfs2_unblock_lock()
3533 blocking = lockres->l_blocking; in ocfs2_unblock_lock()
3534 level = lockres->l_level; in ocfs2_unblock_lock()
3535 spin_unlock_irqrestore(&lockres->l_lock, flags); in ocfs2_unblock_lock()
3537 ctl->unblock_action = lockres->l_ops->downconvert_worker(lockres, blocking); in ocfs2_unblock_lock()
3541 lockres->l_name); in ocfs2_unblock_lock()
3545 spin_lock_irqsave(&lockres->l_lock, flags); in ocfs2_unblock_lock()
3546 if ((blocking != lockres->l_blocking) || (level != lockres->l_level)) { in ocfs2_unblock_lock()
3550 "Recheck\n", lockres->l_name, blocking, in ocfs2_unblock_lock()
3551 lockres->l_blocking, level, lockres->l_level); in ocfs2_unblock_lock()
3558 if (lockres->l_ops->flags & LOCK_TYPE_USES_LVB) { in ocfs2_unblock_lock()
3559 if (lockres->l_level == DLM_LOCK_EX) in ocfs2_unblock_lock()
3568 if (set_lvb && !(lockres->l_flags & OCFS2_LOCK_NEEDS_REFRESH)) in ocfs2_unblock_lock()
3569 lockres->l_ops->set_lvb(lockres); in ocfs2_unblock_lock()
3572 gen = ocfs2_prepare_downconvert(lockres, new_level); in ocfs2_unblock_lock()
3573 spin_unlock_irqrestore(&lockres->l_lock, flags); in ocfs2_unblock_lock()
3574 ret = ocfs2_downconvert_lock(osb, lockres, new_level, set_lvb, in ocfs2_unblock_lock()
3583 spin_unlock_irqrestore(&lockres->l_lock, flags); in ocfs2_unblock_lock()
3589 static int ocfs2_data_convert_worker(struct ocfs2_lock_res *lockres, in ocfs2_data_convert_worker() argument
3596 inode = ocfs2_lock_res_inode(lockres); in ocfs2_data_convert_worker()
3639 struct ocfs2_lock_res *lockres, in ocfs2_ci_checkpointed() argument
3645 BUG_ON(lockres->l_level != DLM_LOCK_EX && !checkpointed); in ocfs2_ci_checkpointed()
3654 static int ocfs2_check_meta_downconvert(struct ocfs2_lock_res *lockres, in ocfs2_check_meta_downconvert() argument
3657 struct inode *inode = ocfs2_lock_res_inode(lockres); in ocfs2_check_meta_downconvert()
3659 return ocfs2_ci_checkpointed(INODE_CACHE(inode), lockres, new_level); in ocfs2_check_meta_downconvert()
3662 static void ocfs2_set_meta_lvb(struct ocfs2_lock_res *lockres) in ocfs2_set_meta_lvb() argument
3664 struct inode *inode = ocfs2_lock_res_inode(lockres); in ocfs2_set_meta_lvb()
3675 struct ocfs2_lock_res *lockres) in ocfs2_dentry_post_unlock() argument
3677 struct ocfs2_dentry_lock *dl = ocfs2_lock_res_dl(lockres); in ocfs2_dentry_post_unlock()
3700 static int ocfs2_dentry_convert_worker(struct ocfs2_lock_res *lockres, in ocfs2_dentry_convert_worker() argument
3703 struct ocfs2_dentry_lock *dl = ocfs2_lock_res_dl(lockres); in ocfs2_dentry_convert_worker()
3735 spin_lock_irqsave(&lockres->l_lock, flags); in ocfs2_dentry_convert_worker()
3737 if (!(lockres->l_flags & OCFS2_LOCK_FREEING) in ocfs2_dentry_convert_worker()
3743 spin_unlock_irqrestore(&lockres->l_lock, flags); in ocfs2_dentry_convert_worker()
3793 static int ocfs2_check_refcount_downconvert(struct ocfs2_lock_res *lockres, in ocfs2_check_refcount_downconvert() argument
3797 ocfs2_lock_res_refcount_tree(lockres); in ocfs2_check_refcount_downconvert()
3799 return ocfs2_ci_checkpointed(&tree->rf_ci, lockres, new_level); in ocfs2_check_refcount_downconvert()
3802 static int ocfs2_refcount_convert_worker(struct ocfs2_lock_res *lockres, in ocfs2_refcount_convert_worker() argument
3806 ocfs2_lock_res_refcount_tree(lockres); in ocfs2_refcount_convert_worker()
3813 static void ocfs2_set_qinfo_lvb(struct ocfs2_lock_res *lockres) in ocfs2_set_qinfo_lvb() argument
3816 struct ocfs2_mem_dqinfo *oinfo = ocfs2_lock_res_qinfo(lockres); in ocfs2_set_qinfo_lvb()
3820 lvb = ocfs2_dlm_lvb(&lockres->l_lksb); in ocfs2_set_qinfo_lvb()
3832 struct ocfs2_lock_res *lockres = &oinfo->dqi_gqlock; in ocfs2_qinfo_unlock() local
3837 ocfs2_cluster_unlock(osb, lockres, level); in ocfs2_qinfo_unlock()
3844 struct ocfs2_lock_res *lockres = &oinfo->dqi_gqlock; in ocfs2_refresh_qinfo() local
3845 struct ocfs2_qinfo_lvb *lvb = ocfs2_dlm_lvb(&lockres->l_lksb); in ocfs2_refresh_qinfo()
3850 if (ocfs2_dlm_lvb_valid(&lockres->l_lksb) && in ocfs2_refresh_qinfo()
3876 ocfs2_track_lock_refresh(lockres); in ocfs2_refresh_qinfo()
3887 struct ocfs2_lock_res *lockres = &oinfo->dqi_gqlock; in ocfs2_qinfo_lock() local
3901 status = ocfs2_cluster_lock(osb, lockres, level, 0, 0); in ocfs2_qinfo_lock()
3906 if (!ocfs2_should_refresh_lock_res(lockres)) in ocfs2_qinfo_lock()
3912 ocfs2_complete_lock_res_refresh(lockres, status); in ocfs2_qinfo_lock()
3921 struct ocfs2_lock_res *lockres = &ref_tree->rf_lockres; in ocfs2_refcount_lock() local
3922 struct ocfs2_super *osb = lockres->l_priv; in ocfs2_refcount_lock()
3931 status = ocfs2_cluster_lock(osb, lockres, level, 0, 0); in ocfs2_refcount_lock()
3941 struct ocfs2_lock_res *lockres = &ref_tree->rf_lockres; in ocfs2_refcount_unlock() local
3942 struct ocfs2_super *osb = lockres->l_priv; in ocfs2_refcount_unlock()
3945 ocfs2_cluster_unlock(osb, lockres, level); in ocfs2_refcount_unlock()
3949 struct ocfs2_lock_res *lockres) in ocfs2_process_blocked_lock() argument
3959 BUG_ON(!lockres); in ocfs2_process_blocked_lock()
3960 BUG_ON(!lockres->l_ops); in ocfs2_process_blocked_lock()
3962 mlog(ML_BASTS, "lockres %s blocked\n", lockres->l_name); in ocfs2_process_blocked_lock()
3969 spin_lock_irqsave(&lockres->l_lock, flags); in ocfs2_process_blocked_lock()
3970 if (lockres->l_flags & OCFS2_LOCK_FREEING) in ocfs2_process_blocked_lock()
3972 spin_unlock_irqrestore(&lockres->l_lock, flags); in ocfs2_process_blocked_lock()
3974 status = ocfs2_unblock_lock(osb, lockres, &ctl); in ocfs2_process_blocked_lock()
3978 spin_lock_irqsave(&lockres->l_lock, flags); in ocfs2_process_blocked_lock()
3980 if (lockres->l_flags & OCFS2_LOCK_FREEING || !ctl.requeue) { in ocfs2_process_blocked_lock()
3981 lockres_clear_flags(lockres, OCFS2_LOCK_QUEUED); in ocfs2_process_blocked_lock()
3983 ocfs2_schedule_blocked_lock(osb, lockres); in ocfs2_process_blocked_lock()
3985 mlog(ML_BASTS, "lockres %s, requeue = %s.\n", lockres->l_name, in ocfs2_process_blocked_lock()
3987 spin_unlock_irqrestore(&lockres->l_lock, flags); in ocfs2_process_blocked_lock()
3990 && lockres->l_ops->post_unlock) in ocfs2_process_blocked_lock()
3991 lockres->l_ops->post_unlock(osb, lockres); in ocfs2_process_blocked_lock()
3995 struct ocfs2_lock_res *lockres) in ocfs2_schedule_blocked_lock() argument
3999 assert_spin_locked(&lockres->l_lock); in ocfs2_schedule_blocked_lock()
4001 if (lockres->l_flags & OCFS2_LOCK_FREEING) { in ocfs2_schedule_blocked_lock()
4006 lockres->l_name, lockres->l_flags); in ocfs2_schedule_blocked_lock()
4010 lockres_or_flags(lockres, OCFS2_LOCK_QUEUED); in ocfs2_schedule_blocked_lock()
4013 if (list_empty(&lockres->l_blocked_list)) { in ocfs2_schedule_blocked_lock()
4014 list_add_tail(&lockres->l_blocked_list, in ocfs2_schedule_blocked_lock()
4025 struct ocfs2_lock_res *lockres; in ocfs2_downconvert_thread_do_work() local
4040 lockres = list_entry(osb->blocked_lock_list.next, in ocfs2_downconvert_thread_do_work()
4042 list_del_init(&lockres->l_blocked_list); in ocfs2_downconvert_thread_do_work()
4049 ocfs2_process_blocked_lock(osb, lockres); in ocfs2_downconvert_thread_do_work()