diff --git a/kmod/src/counters.h b/kmod/src/counters.h index c2d3a453..f0c02f50 100644 --- a/kmod/src/counters.h +++ b/kmod/src/counters.h @@ -60,6 +60,8 @@ EXPAND_COUNTER(lock_busy_wait) \ EXPAND_COUNTER(lock_free) \ EXPAND_COUNTER(lock_incompat_wait) \ + EXPAND_COUNTER(lock_type_ino_downconvert) \ + EXPAND_COUNTER(lock_type_idx_downconvert) \ EXPAND_COUNTER(manifest_compact_migrate) \ EXPAND_COUNTER(manifest_hard_stale_error) \ EXPAND_COUNTER(seg_alloc) \ diff --git a/kmod/src/dlmglue.c b/kmod/src/dlmglue.c index 4393f595..ec04af87 100644 --- a/kmod/src/dlmglue.c +++ b/kmod/src/dlmglue.c @@ -104,6 +104,13 @@ static inline void lockres_name(struct ocfs2_lock_res *lockres, char *buf, snprintf(buf, len, "%s", lockres->l_name); } +static inline void lockres_notify_event(struct ocfs2_lock_res *lockres, + enum ocfs2_lock_events event) +{ + if (lockres->l_ops->notify_event) + lockres->l_ops->notify_event(lockres, event); +} + static inline int ocfs2_may_continue_on_blocked_lock(struct ocfs2_lock_res *lockres, int wanted); static void __ocfs2_cluster_unlock(struct ocfs2_super *osb, @@ -1220,10 +1227,13 @@ again: gen = lockres_set_pending(lockres); spin_unlock_irqrestore(&lockres->l_lock, flags); - if (lkm_flags & DLM_LKF_CONVERT) + if (lkm_flags & DLM_LKF_CONVERT) { scoutfs_inc_counter(osb->sb, dlm_convert_request); - else + lockres_notify_event(lockres, EVENT_DLM_CONVERT); + } else { scoutfs_inc_counter(osb->sb, dlm_lock_request); + lockres_notify_event(lockres, EVENT_DLM_LOCK); + } BUG_ON(level == DLM_LOCK_IV); BUG_ON(level == DLM_LOCK_NL); @@ -2161,6 +2171,7 @@ static int ocfs2_drop_lock(struct ocfs2_super *osb, lockres->l_name); scoutfs_inc_counter(osb->sb, dlm_unlock_request); + lockres_notify_event(lockres, EVENT_DLM_UNLOCK); ocfs2_wait_on_busy_lock(lockres); out: @@ -2366,6 +2377,7 @@ static int ocfs2_cancel_convert(struct ocfs2_super *osb, mlog(ML_BASTS, "lockres %s\n", lockres->l_name); scoutfs_inc_counter(osb->sb, dlm_cancel_convert); + lockres_notify_event(lockres, EVENT_DLM_CONVERT); return ret; } @@ -2532,6 +2544,8 @@ recheck: spin_unlock_irqrestore(&lockres->l_lock, flags); + lockres_notify_event(lockres, EVENT_DLM_DOWNCONVERT_WORK); + ctl->unblock_action = lockres->l_ops->downconvert_worker(lockres, blocking); if (ctl->unblock_action == UNBLOCK_STOP_POST) { diff --git a/kmod/src/dlmglue.h b/kmod/src/dlmglue.h index d6b8c639..d4cb298e 100644 --- a/kmod/src/dlmglue.h +++ b/kmod/src/dlmglue.h @@ -199,6 +199,14 @@ enum ocfs2_unblock_action { * ->post_unlock() callback. */ }; +enum ocfs2_lock_events { + EVENT_DLM_LOCK = 0, + EVENT_DLM_UNLOCK, + EVENT_DLM_CONVERT, + EVENT_DLM_CANCEL_CONVERT, + EVENT_DLM_DOWNCONVERT_WORK, +}; + /* * OCFS2 Lock Resource Operations * @@ -269,6 +277,12 @@ struct ocfs2_lock_res_ops { */ void (*print)(struct ocfs2_lock_res *, char *, unsigned int); + /* + * Optional: Lightweight event callback, intended for quick + * operations like collecting stats, etc. + */ + void (*notify_event)(struct ocfs2_lock_res *, enum ocfs2_lock_events); + /* * LOCK_TYPE_* flags which describe the specific requirements * of a lock type. Descriptions of each individual flag follow. diff --git a/kmod/src/lock.c b/kmod/src/lock.c index 9c8e0ccf..b16b2264 100644 --- a/kmod/src/lock.c +++ b/kmod/src/lock.c @@ -332,17 +332,45 @@ static void lock_name_string(struct ocfs2_lock_res *lockres, char *buf, snprintf(buf, len, LN_FMT, LN_ARG(&lock->lock_name)); } +static void count_ino_lock_event(struct ocfs2_lock_res *lockres, + enum ocfs2_lock_events event) +{ + struct scoutfs_lock *lock = container_of(lockres, struct scoutfs_lock, + lockres); + struct super_block *sb = lock->sb; + + if (event == EVENT_DLM_DOWNCONVERT_WORK) + scoutfs_inc_counter(sb, lock_type_ino_downconvert); +} + +static void count_idx_lock_event(struct ocfs2_lock_res *lockres, + enum ocfs2_lock_events event) +{ + struct scoutfs_lock *lock = container_of(lockres, struct scoutfs_lock, + lockres); + struct super_block *sb = lock->sb; + + /* + * Treat all indicies together. Later we can decode the + * lockres name to get at specific indicies. + */ + if (event == EVENT_DLM_DOWNCONVERT_WORK) + scoutfs_inc_counter(sb, lock_type_idx_downconvert); +} + static struct ocfs2_lock_res_ops scoufs_ino_lops = { .get_osb = get_ino_lock_osb, .downconvert_worker = ino_lock_downconvert, /* XXX: .check_downconvert that queries the item cache for dirty items */ .print = lock_name_string, + .notify_event = count_ino_lock_event, .flags = LOCK_TYPE_REQUIRES_REFRESH, }; static struct ocfs2_lock_res_ops scoufs_ino_index_lops = { .get_osb = get_ino_lock_osb, .downconvert_worker = ino_lock_downconvert, + .notify_event = count_idx_lock_event, /* XXX: .check_downconvert that queries the item cache for dirty items */ .print = lock_name_string, };