Whamcloud - gitweb
LU-9855 obdclass: simplify md_stats code 22/32822/12
authorJames Simmons <uja.ornl@yahoo.com>
Fri, 10 Aug 2018 16:19:30 +0000 (12:19 -0400)
committerOleg Drokin <green@whamcloud.com>
Sat, 1 Sep 2018 03:29:34 +0000 (03:29 +0000)
The md_stats code is layered in many levels of macros that make
the code difficult to read as well as introduce undetected
errors. This peels away the macro wrappers by replacing it with
the function lprocfs_exp_count_increment() which doesn't care
about the order of the function pointers in struct md_ops. The
other change is macros used for initializing the counters. This
is done by replacing lprocfs_init_mps_stats() with very simple
handling in lprocfs_alloc_md_stats().

Change-Id: I036ce4518ffb08d53e2d27bcdea564a4c799181d
Signed-off-by: James Simmons <uja.ornl@yahoo.com>
Reviewed-on: https://review.whamcloud.com/32822
Reviewed-by: Ben Evans <bevans@cray.com>
Reviewed-by: John L. Hammond <jhammond@whamcloud.com>
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/include/lprocfs_status.h
lustre/include/obd.h
lustre/include/obd_class.h
lustre/mdt/mdt_internal.h
lustre/mdt/mdt_lproc.c
lustre/obdclass/lprocfs_status.c

index e0183c0..d0bd2af 100644 (file)
@@ -468,8 +468,6 @@ extern struct lprocfs_stats *
 lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags);
 extern void lprocfs_clear_stats(struct lprocfs_stats *stats);
 extern void lprocfs_free_stats(struct lprocfs_stats **stats);
-extern void lprocfs_init_mps_stats(int num_private_stats,
-                                   struct lprocfs_stats *stats);
 extern void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats);
 extern int lprocfs_alloc_obd_stats(struct obd_device *obddev,
                                   unsigned int num_stats);
@@ -902,9 +900,6 @@ static inline int lprocfs_register_stats(struct proc_dir_entry *root,
                                          const char *name,
                                          struct lprocfs_stats *stats)
 { return 0; }
-static inline void lprocfs_init_mps_stats(int num_private_stats,
-                                          struct lprocfs_stats *stats)
-{ return; }
 static inline void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats)
 { return; }
 static inline int lprocfs_alloc_obd_stats(struct obd_device *obddev,
index 6984f92..f792347 100644 (file)
@@ -716,7 +716,6 @@ struct obd_device {
        /* Fields used by LProcFS */
        struct lprocfs_stats            *obd_stats;
 
-       unsigned int                     obd_md_cntr_base;
        struct lprocfs_stats            *obd_md_stats;
 
        struct dentry                   *obd_debugfs_entry;
@@ -1028,18 +1027,6 @@ struct lookup_intent;
 struct cl_attr;
 
 struct md_ops {
-       /* Every operation from MD_STATS_FIRST_OP up to and including
-        * MD_STATS_LAST_OP will be counted by EXP_MD_OP_INCREMENT()
-        * and will appear in /proc/fs/lustre/{lmv,mdc}/.../md_stats.
-        * Operations after MD_STATS_LAST_OP are excluded from stats.
-        * There are a few reasons for doing this: we prune the 17
-        * counters which will be of minimal use in understanding
-        * metadata utilization, we save memory by allocating 15
-        * instead of 32 counters, we save cycles by not counting.
-        *
-        * MD_STATS_FIRST_OP must be the first member of md_ops.
-        */
-#define MD_STATS_FIRST_OP m_close
        int (*m_close)(struct obd_export *, struct md_op_data *,
                       struct md_open_data *, struct ptlrpc_request **);
 
@@ -1092,8 +1079,6 @@ struct md_ops {
         int (*m_revalidate_lock)(struct obd_export *, struct lookup_intent *,
                                  struct lu_fid *, __u64 *bits);
 
-#define MD_STATS_LAST_OP m_revalidate_lock
-
        int (*m_file_resync)(struct obd_export *, struct md_op_data *);
 
        int (*m_get_root)(struct obd_export *, const char *, struct lu_fid *);
index 31b06d9..8350cb1 100644 (file)
@@ -417,33 +417,6 @@ do {                                                            \
 } while (0)
 
 
-#ifdef CONFIG_PROC_FS
-#define _MD_COUNTER_OFFSET(m_op)                                              \
-       ((offsetof(struct md_ops, m_op) -                                      \
-         offsetof(struct md_ops, MD_STATS_FIRST_OP)) /                        \
-        sizeof(((struct md_ops *)NULL)->MD_STATS_FIRST_OP))
-
-#define MD_COUNTER_OFFSET(op) _MD_COUNTER_OFFSET(m_ ## op)
-
-#define NUM_MD_STATS                                                          \
-       (_MD_COUNTER_OFFSET(MD_STATS_LAST_OP) -                                \
-        _MD_COUNTER_OFFSET(MD_STATS_FIRST_OP) + 1)
-
-/* Note that we only increment md counters for ops whose offset is less
- * than NUM_MD_STATS. This is explained in a comment in the definition
- * of struct md_ops. */
-#define EXP_MD_COUNTER_INCREMENT(exp, op)                                     \
-       do {                                                                   \
-               if (MD_COUNTER_OFFSET(op) < NUM_MD_STATS)                      \
-                       lprocfs_counter_incr((exp)->exp_obd->obd_md_stats,     \
-                                       (exp)->exp_obd->obd_md_cntr_base +     \
-                                       MD_COUNTER_OFFSET(op));                \
-       } while (0)
-
-#else
-#define EXP_MD_COUNTER_INCREMENT(exp, op)
-#endif
-
 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
 {
        /* Always add in ldlm_stats */
@@ -1301,19 +1274,35 @@ static inline int obd_register_observer(struct obd_device *obd,
 }
 
 /* metadata helpers */
+enum mps_stat_idx {
+       LPROC_MD_CLOSE,
+       LPROC_MD_CREATE,
+       LPROC_MD_ENQUEUE,
+       LPROC_MD_GETATTR,
+       LPROC_MD_INTENT_LOCK,
+       LPROC_MD_LINK,
+       LPROC_MD_RENAME,
+       LPROC_MD_SETATTR,
+       LPROC_MD_FSYNC,
+       LPROC_MD_READ_PAGE,
+       LPROC_MD_UNLINK,
+       LPROC_MD_SETXATTR,
+       LPROC_MD_GETXATTR,
+       LPROC_MD_INTENT_GETATTR_ASYNC,
+       LPROC_MD_REVALIDATE_LOCK,
+       LPROC_MD_LAST_OPC,
+};
+
 static inline int md_get_root(struct obd_export *exp, const char *fileset,
                              struct lu_fid *fid)
 {
        int rc;
 
-       ENTRY;
        rc = exp_check_ops(exp);
        if (rc)
-               RETURN(rc);
-       EXP_MD_COUNTER_INCREMENT(exp, get_root);
-       rc = MDP(exp->exp_obd, get_root)(exp, fileset, fid);
+               return rc;
 
-       RETURN(rc);
+       return MDP(exp->exp_obd, get_root)(exp, fileset, fid);
 }
 
 static inline int md_getattr(struct obd_export *exp,
@@ -1322,40 +1311,42 @@ static inline int md_getattr(struct obd_export *exp,
 {
        int rc;
 
-       ENTRY;
        rc = exp_check_ops(exp);
        if (rc)
-               RETURN(rc);
-       EXP_MD_COUNTER_INCREMENT(exp, getattr);
-       rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
-       RETURN(rc);
+               return rc;
+
+       lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
+                            LPROC_MD_GETATTR);
+
+       return MDP(exp->exp_obd, getattr)(exp, op_data, request);
 }
 
 static inline int md_null_inode(struct obd_export *exp,
                                    const struct lu_fid *fid)
 {
-        int rc;
-        ENTRY;
+       int rc;
+
        rc = exp_check_ops(exp);
        if (rc)
-               RETURN(rc);
-        EXP_MD_COUNTER_INCREMENT(exp, null_inode);
-        rc = MDP(exp->exp_obd, null_inode)(exp, fid);
-        RETURN(rc);
+               return rc;
+
+       return MDP(exp->exp_obd, null_inode)(exp, fid);
 }
 
 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
                            struct md_open_data *mod,
                            struct ptlrpc_request **request)
 {
-        int rc;
-        ENTRY;
+       int rc;
+
        rc = exp_check_ops(exp);
        if (rc)
-               RETURN(rc);
-        EXP_MD_COUNTER_INCREMENT(exp, close);
-        rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
-        RETURN(rc);
+               return rc;
+
+       lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
+                            LPROC_MD_CLOSE);
+
+       return MDP(exp->exp_obd, close)(exp, op_data, mod, request);
 }
 
 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
@@ -1363,15 +1354,18 @@ static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
                            uid_t uid, gid_t gid, cfs_cap_t cap_effective,
                            __u64 rdev, struct ptlrpc_request **request)
 {
-        int rc;
-        ENTRY;
+       int rc;
+
        rc = exp_check_ops(exp);
        if (rc)
-               RETURN(rc);
-        EXP_MD_COUNTER_INCREMENT(exp, create);
-        rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
-                                       uid, gid, cap_effective, rdev, request);
-        RETURN(rc);
+               return rc;
+
+       lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
+                            LPROC_MD_CREATE);
+
+       return MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
+                                        uid, gid, cap_effective, rdev,
+                                        request);
 }
 
 static inline int md_enqueue(struct obd_export *exp,
@@ -1382,28 +1376,29 @@ static inline int md_enqueue(struct obd_export *exp,
                             __u64 extra_lock_flags)
 {
        int rc;
-       ENTRY;
+
        rc = exp_check_ops(exp);
        if (rc)
-               RETURN(rc);
-       EXP_MD_COUNTER_INCREMENT(exp, enqueue);
-       rc = MDP(exp->exp_obd, enqueue)(exp, einfo, policy, op_data, lockh,
-                                       extra_lock_flags);
-        RETURN(rc);
+               return rc;
+
+       lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
+                            LPROC_MD_ENQUEUE);
+
+       return MDP(exp->exp_obd, enqueue)(exp, einfo, policy, op_data, lockh,
+                  extra_lock_flags);
 }
 
 static inline int md_getattr_name(struct obd_export *exp,
                                   struct md_op_data *op_data,
                                   struct ptlrpc_request **request)
 {
-        int rc;
-        ENTRY;
+       int rc;
+
        rc = exp_check_ops(exp);
        if (rc)
-               RETURN(rc);
-        EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
-        rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
-        RETURN(rc);
+               return rc;
+
+       return MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
 }
 
 static inline int md_intent_lock(struct obd_export *exp,
@@ -1414,43 +1409,49 @@ static inline int md_intent_lock(struct obd_export *exp,
                                 __u64 extra_lock_flags)
 {
        int rc;
-       ENTRY;
+
        rc = exp_check_ops(exp);
        if (rc)
-               RETURN(rc);
-       EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
-       rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, it, reqp, cb_blocking,
-                                           extra_lock_flags);
-       RETURN(rc);
+               return rc;
+
+       lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
+                            LPROC_MD_INTENT_LOCK);
+
+       return MDP(exp->exp_obd, intent_lock)(exp, op_data, it, reqp,
+                                             cb_blocking, extra_lock_flags);
 }
 
 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
                           struct ptlrpc_request **request)
 {
-        int rc;
-        ENTRY;
+       int rc;
+
        rc = exp_check_ops(exp);
        if (rc)
-               RETURN(rc);
-        EXP_MD_COUNTER_INCREMENT(exp, link);
-        rc = MDP(exp->exp_obd, link)(exp, op_data, request);
-        RETURN(rc);
+               return rc;
+
+       lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
+                            LPROC_MD_LINK);
+
+       return MDP(exp->exp_obd, link)(exp, op_data, request);
 }
 
 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
-                           const char *old, size_t oldlen, const char *new,
-                           size_t newlen, struct ptlrpc_request **request)
+                           const char *old_name, size_t oldlen,
+                           const char *new_name, size_t newlen,
+                           struct ptlrpc_request **request)
 {
-        int rc;
-        ENTRY;
+       int rc;
+
        rc = exp_check_ops(exp);
        if (rc)
-               RETURN(rc);
+               return rc;
 
-        EXP_MD_COUNTER_INCREMENT(exp, rename);
-        rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
-                                       newlen, request);
-        RETURN(rc);
+       lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
+                            LPROC_MD_RENAME);
+
+       return MDP(exp->exp_obd, rename)(exp, op_data, old_name, oldlen,
+                                        new_name, newlen, request);
 }
 
 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
@@ -1458,14 +1459,15 @@ static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
                             struct ptlrpc_request **request)
 {
        int rc;
-       ENTRY;
+
        rc = exp_check_ops(exp);
        if (rc)
-               RETURN(rc);
+               return rc;
 
-       EXP_MD_COUNTER_INCREMENT(exp, setattr);
-       rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen, request);
-       RETURN(rc);
+       lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
+                            LPROC_MD_SETATTR);
+
+       return MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen, request);
 }
 
 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
@@ -1473,15 +1475,14 @@ static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
 {
        int rc;
 
-       ENTRY;
        rc = exp_check_ops(exp);
        if (rc)
-               RETURN(rc);
+               return rc;
 
-       EXP_MD_COUNTER_INCREMENT(exp, fsync);
-       rc = MDP(exp->exp_obd, fsync)(exp, fid, request);
+       lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
+                            LPROC_MD_FSYNC);
 
-       RETURN(rc);
+       return MDP(exp->exp_obd, fsync)(exp, fid, request);
 }
 
 /* FLR: resync mirrored files. */
@@ -1490,15 +1491,11 @@ static inline int md_file_resync(struct obd_export *exp,
 {
        int rc;
 
-       ENTRY;
        rc = exp_check_ops(exp);
        if (rc)
-               RETURN(rc);
-
-       EXP_MD_COUNTER_INCREMENT(exp, file_resync);
-       rc = MDP(exp->exp_obd, file_resync)(exp, data);
+               return rc;
 
-       RETURN(rc);
+       return MDP(exp->exp_obd, file_resync)(exp, data);
 }
 
 static inline int md_read_page(struct obd_export *exp,
@@ -1508,29 +1505,31 @@ static inline int md_read_page(struct obd_export *exp,
                               struct page **ppage)
 {
        int rc;
-       ENTRY;
+
        rc = exp_check_ops(exp);
        if (rc)
-               RETURN(rc);
+               return rc;
 
-       EXP_MD_COUNTER_INCREMENT(exp, read_page);
-       rc = MDP(exp->exp_obd, read_page)(exp, op_data, cb_op, hash_offset,
-                                         ppage);
-       RETURN(rc);
+       lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
+                            LPROC_MD_READ_PAGE);
+
+       return MDP(exp->exp_obd, read_page)(exp, op_data, cb_op, hash_offset,
+                                           ppage);
 }
 
 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
                             struct ptlrpc_request **request)
 {
-        int rc;
-        ENTRY;
+       int rc;
+
        rc = exp_check_ops(exp);
        if (rc)
-               RETURN(rc);
+               return rc;
 
-        EXP_MD_COUNTER_INCREMENT(exp, unlink);
-        rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
-        RETURN(rc);
+       lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
+                            LPROC_MD_UNLINK);
+
+       return MDP(exp->exp_obd, unlink)(exp, op_data, request);
 }
 
 static inline int md_get_lustre_md(struct obd_export *exp,
@@ -1540,25 +1539,24 @@ static inline int md_get_lustre_md(struct obd_export *exp,
                                    struct lustre_md *md)
 {
        int rc;
-        ENTRY;
+
        rc = exp_check_ops(exp);
        if (rc)
-               RETURN(rc);
+               return rc;
 
-        EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
-        RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
+       return MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md);
 }
 
 static inline int md_free_lustre_md(struct obd_export *exp,
                                     struct lustre_md *md)
 {
        int rc;
-        ENTRY;
+
        rc = exp_check_ops(exp);
        if (rc)
-               RETURN(rc);
-        EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
-        RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
+               return rc;
+
+       return MDP(exp->exp_obd, free_lustre_md)(exp, md);
 }
 
 static inline int md_merge_attr(struct obd_export *exp,
@@ -1567,12 +1565,12 @@ static inline int md_merge_attr(struct obd_export *exp,
                                ldlm_blocking_callback cb)
 {
        int rc;
-       ENTRY;
+
        rc = exp_check_ops(exp);
        if (rc)
-               RETURN(rc);
-       EXP_MD_COUNTER_INCREMENT(exp, merge_attr);
-       RETURN(MDP(exp->exp_obd, merge_attr)(exp, lsm, attr, cb));
+               return rc;
+
+       return MDP(exp->exp_obd, merge_attr)(exp, lsm, attr, cb);
 }
 
 static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
@@ -1582,15 +1580,17 @@ static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
                              struct ptlrpc_request **req)
 {
        int rc;
-       ENTRY;
 
        rc = exp_check_ops(exp);
        if (rc)
-               RETURN(rc);
-       EXP_MD_COUNTER_INCREMENT(exp, setxattr);
-       RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, obd_md_valid, name,
+               return rc;
+
+       lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
+                            LPROC_MD_SETXATTR);
+
+       return MDP(exp->exp_obd, setxattr)(exp, fid, obd_md_valid, name,
                                           value, value_size, xattr_flags,
-                                          suppgid, req));
+                                          suppgid, req);
 }
 
 static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
@@ -1598,13 +1598,16 @@ static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
                              size_t buf_size, struct ptlrpc_request **req)
 {
        int rc;
-       ENTRY;
+
        rc = exp_check_ops(exp);
        if (rc)
-               RETURN(rc);
-       EXP_MD_COUNTER_INCREMENT(exp, getxattr);
-       RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, obd_md_valid, name,
-                                          buf_size, req));
+               return rc;
+
+       lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
+                            LPROC_MD_GETXATTR);
+
+       return MDP(exp->exp_obd, getxattr)(exp, fid, obd_md_valid, name,
+                                          buf_size, req);
 }
 
 static inline int md_set_open_replay_data(struct obd_export *exp,
@@ -1612,24 +1615,24 @@ static inline int md_set_open_replay_data(struct obd_export *exp,
                                          struct lookup_intent *it)
 {
        int rc;
-       ENTRY;
+
        rc = exp_check_ops(exp);
        if (rc)
-               RETURN(rc);
-       EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
-       RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, it));
+               return rc;
+
+       return MDP(exp->exp_obd, set_open_replay_data)(exp, och, it);
 }
 
 static inline int md_clear_open_replay_data(struct obd_export *exp,
                                             struct obd_client_handle *och)
 {
        int rc;
-        ENTRY;
+
        rc = exp_check_ops(exp);
        if (rc)
-               RETURN(rc);
-        EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
-        RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
+               return rc;
+
+       return MDP(exp->exp_obd, clear_open_replay_data)(exp, och);
 }
 
 static inline int md_set_lock_data(struct obd_export *exp,
@@ -1637,12 +1640,12 @@ static inline int md_set_lock_data(struct obd_export *exp,
                                   void *data, __u64 *bits)
 {
        int rc;
-        ENTRY;
+
        rc = exp_check_ops(exp);
        if (rc)
-               RETURN(rc);
-        EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
-        RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
+               return rc;
+
+       return MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits);
 }
 
 static inline
@@ -1651,16 +1654,13 @@ int md_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
                     enum ldlm_cancel_flags cancel_flags, void *opaque)
 {
        int rc;
-       ENTRY;
 
        rc = exp_check_ops(exp);
        if (rc)
-               RETURN(rc);
-       EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
+               return rc;
 
-       rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
-                                             cancel_flags, opaque);
-       RETURN(rc);
+       return MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
+                                               cancel_flags, opaque);
 }
 
 static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags,
@@ -1671,52 +1671,56 @@ static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags,
                                           struct lustre_handle *lockh)
 {
        int rc;
-       ENTRY;
+
        rc = exp_check_ops(exp);
        if (rc)
-               RETURN(rc);
-       EXP_MD_COUNTER_INCREMENT(exp, lock_match);
-       RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
-                                            policy, mode, lockh));
+               return rc;
+
+       return MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
+                                            policy, mode, lockh);
 }
 
 static inline int md_init_ea_size(struct obd_export *exp, __u32 ea_size,
                                  __u32 def_ea_size)
 {
        int rc;
-       ENTRY;
+
        rc = exp_check_ops(exp);
        if (rc)
-               RETURN(rc);
-       EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
-       RETURN(MDP(exp->exp_obd, init_ea_size)(exp, ea_size, def_ea_size));
+               return rc;
+
+       return MDP(exp->exp_obd, init_ea_size)(exp, ea_size, def_ea_size);
 }
 
 static inline int md_intent_getattr_async(struct obd_export *exp,
                                          struct md_enqueue_info *minfo)
 {
        int rc;
-       ENTRY;
+
        rc = exp_check_ops(exp);
        if (rc)
-               RETURN(rc);
-       EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
-       rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo);
-       RETURN(rc);
+               return rc;
+
+       lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
+                            LPROC_MD_INTENT_GETATTR_ASYNC);
+
+       return MDP(exp->exp_obd, intent_getattr_async)(exp, minfo);
 }
 
 static inline int md_revalidate_lock(struct obd_export *exp,
                                      struct lookup_intent *it,
                                      struct lu_fid *fid, __u64 *bits)
 {
-        int rc;
-        ENTRY;
+       int rc;
+
        rc = exp_check_ops(exp);
        if (rc)
-               RETURN(rc);
-        EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
-        rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
-        RETURN(rc);
+               return rc;
+
+       lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
+                            LPROC_MD_REVALIDATE_LOCK);
+
+       return MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
 }
 
 static inline int md_get_fid_from_lsm(struct obd_export *exp,
@@ -1725,15 +1729,14 @@ static inline int md_get_fid_from_lsm(struct obd_export *exp,
                                      struct lu_fid *fid)
 {
        int rc;
-       ENTRY;
+
        rc = exp_check_ops(exp);
        if (rc)
-               RETURN(rc);
-       EXP_MD_COUNTER_INCREMENT(exp, get_fid_from_lsm);
-       rc = MDP(exp->exp_obd, get_fid_from_lsm)(exp, lsm, name, namelen, fid);
-       RETURN(rc);
-}
+               return rc;
 
+       return MDP(exp->exp_obd, get_fid_from_lsm)(exp, lsm, name, namelen,
+                                                  fid);
+}
 
 /* Unpack an MD struct from disk to in-memory format.
  * Returns +ve size of unpacked MD (0 for free), or -ve error.
@@ -1746,13 +1749,12 @@ static inline int md_unpackmd(struct obd_export *exp,
                              const union lmv_mds_md *lmm, size_t lmm_size)
 {
        int rc;
-       ENTRY;
+
        rc = exp_check_ops(exp);
        if (rc)
-               RETURN(rc);
-       EXP_MD_COUNTER_INCREMENT(exp, unpackmd);
-       rc = MDP(exp->exp_obd, unpackmd)(exp, plsm, lmm, lmm_size);
-       RETURN(rc);
+               return rc;
+
+       return MDP(exp->exp_obd, unpackmd)(exp, plsm, lmm, lmm_size);
 }
 
 /* OBD Metadata Support */
index 8917002..ab71750 100644 (file)
@@ -1188,8 +1188,8 @@ void mdt_enable_cos(struct mdt_device *dev, bool enable);
 int mdt_cos_is_enabled(struct mdt_device *);
 
 /* lprocfs stuff */
-enum {
-        LPROC_MDT_OPEN = 0,
+enum mdt_stat_idx {
+       LPROC_MDT_OPEN,
         LPROC_MDT_CLOSE,
         LPROC_MDT_MKNOD,
         LPROC_MDT_LINK,
@@ -1210,6 +1210,7 @@ enum {
        LPROC_MDT_IO_PUNCH,
        LPROC_MDT_LAST,
 };
+
 void mdt_counter_incr(struct ptlrpc_request *req, int opcode);
 void mdt_stats_counter_init(struct lprocfs_stats *stats);
 int mdt_procfs_init(struct mdt_device *mdt, const char *name);
index 3bfbcf1..ed1d9a8 100644 (file)
@@ -1031,7 +1031,8 @@ void mdt_counter_incr(struct ptlrpc_request *req, int opcode)
        struct obd_export *exp = req->rq_export;
 
        if (exp->exp_obd && exp->exp_obd->obd_md_stats)
-               lprocfs_counter_incr(exp->exp_obd->obd_md_stats, opcode);
+               lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
+                                    opcode + LPROC_MD_LAST_OPC);
        if (exp->exp_nid_stats && exp->exp_nid_stats->nid_stats != NULL)
                lprocfs_counter_incr(exp->exp_nid_stats->nid_stats, opcode);
        if (exp->exp_obd && exp->exp_obd->u.obt.obt_jobstats.ojs_hash &&
@@ -1041,41 +1042,51 @@ void mdt_counter_incr(struct ptlrpc_request *req, int opcode)
                                      opcode, 1);
 }
 
+static const char * const mdt_stats[] = {
+       [LPROC_MDT_OPEN]                = "open",
+       [LPROC_MDT_CLOSE]               = "close",
+       [LPROC_MDT_MKNOD]               = "mknod",
+       [LPROC_MDT_LINK]                = "link",
+       [LPROC_MDT_UNLINK]              = "unlink",
+       [LPROC_MDT_MKDIR]               = "mkdir",
+       [LPROC_MDT_RMDIR]               = "rmdir",
+       [LPROC_MDT_RENAME]              = "rename",
+       [LPROC_MDT_GETATTR]             = "getattr",
+       [LPROC_MDT_SETATTR]             = "setattr",
+       [LPROC_MDT_GETXATTR]            = "getxattr",
+       [LPROC_MDT_SETXATTR]            = "setxattr",
+       [LPROC_MDT_STATFS]              = "statfs",
+       [LPROC_MDT_SYNC]                = "sync",
+       [LPROC_MDT_SAMEDIR_RENAME]      = "samedir_rename",
+       [LPROC_MDT_CROSSDIR_RENAME]     = "crossdir_rename",
+       [LPROC_MDT_IO_READ]             = "read_bytes",
+       [LPROC_MDT_IO_WRITE]            = "write_bytes",
+       [LPROC_MDT_IO_PUNCH]            = "punch",
+};
+
 void mdt_stats_counter_init(struct lprocfs_stats *stats)
 {
-       LASSERT(stats && stats->ls_num >= LPROC_MDT_LAST);
-
-        lprocfs_counter_init(stats, LPROC_MDT_OPEN, 0, "open", "reqs");
-        lprocfs_counter_init(stats, LPROC_MDT_CLOSE, 0, "close", "reqs");
-        lprocfs_counter_init(stats, LPROC_MDT_MKNOD, 0, "mknod", "reqs");
-        lprocfs_counter_init(stats, LPROC_MDT_LINK, 0, "link", "reqs");
-        lprocfs_counter_init(stats, LPROC_MDT_UNLINK, 0, "unlink", "reqs");
-        lprocfs_counter_init(stats, LPROC_MDT_MKDIR, 0, "mkdir", "reqs");
-        lprocfs_counter_init(stats, LPROC_MDT_RMDIR, 0, "rmdir", "reqs");
-        lprocfs_counter_init(stats, LPROC_MDT_RENAME, 0, "rename", "reqs");
-        lprocfs_counter_init(stats, LPROC_MDT_GETATTR, 0, "getattr", "reqs");
-        lprocfs_counter_init(stats, LPROC_MDT_SETATTR, 0, "setattr", "reqs");
-        lprocfs_counter_init(stats, LPROC_MDT_GETXATTR, 0, "getxattr", "reqs");
-        lprocfs_counter_init(stats, LPROC_MDT_SETXATTR, 0, "setxattr", "reqs");
-        lprocfs_counter_init(stats, LPROC_MDT_STATFS, 0, "statfs", "reqs");
-        lprocfs_counter_init(stats, LPROC_MDT_SYNC, 0, "sync", "reqs");
-        lprocfs_counter_init(stats, LPROC_MDT_SAMEDIR_RENAME, 0,
-                             "samedir_rename", "reqs");
-        lprocfs_counter_init(stats, LPROC_MDT_CROSSDIR_RENAME, 0,
-                             "crossdir_rename", "reqs");
-       lprocfs_counter_init(stats, LPROC_MDT_IO_READ,
-                            LPROCFS_CNTR_AVGMINMAX, "read_bytes", "bytes");
-       lprocfs_counter_init(stats, LPROC_MDT_IO_WRITE,
-                            LPROCFS_CNTR_AVGMINMAX, "write_bytes", "bytes");
-       lprocfs_counter_init(stats, LPROC_MDT_IO_PUNCH, 0, "punch", "reqs");
+       int idx;
+
+       LASSERT(stats && stats->ls_num >= ARRAY_SIZE(mdt_stats));
+
+       for (idx = 0; idx < ARRAY_SIZE(mdt_stats); idx++) {
+               int flags = 0;
+
+               if (idx == LPROC_MDT_IO_WRITE || idx == LPROC_MDT_IO_READ)
+                       flags = LPROCFS_CNTR_AVGMINMAX;
+
+               lprocfs_counter_init(stats, idx, flags, mdt_stats[idx], "reqs");
+       }
 }
 
 int mdt_procfs_init(struct mdt_device *mdt, const char *name)
 {
-       struct obd_device               *obd = mdt2obd_dev(mdt);
-       int                              rc;
-       ENTRY;
+       struct obd_device *obd = mdt2obd_dev(mdt);
+       int rc;
+       int i;
 
+       ENTRY;
        LASSERT(name != NULL);
 
        obd->obd_vars = lprocfs_mdt_obd_vars;
@@ -1098,12 +1109,24 @@ int mdt_procfs_init(struct mdt_device *mdt, const char *name)
        if (obd->obd_proc_exports_entry)
                lprocfs_add_simple(obd->obd_proc_exports_entry, "clear",
                                   obd, &mdt_nid_stats_clear_fops);
-       rc = lprocfs_alloc_md_stats(obd, LPROC_MDT_LAST);
+
+       rc = lprocfs_alloc_md_stats(obd, ARRAY_SIZE(mdt_stats));
        if (rc)
                return rc;
-       mdt_stats_counter_init(obd->obd_md_stats);
 
-       rc = lprocfs_job_stats_init(obd, LPROC_MDT_LAST,
+       /* add additional MDT md_stats after the default ones */
+       for (i = 0; i < ARRAY_SIZE(mdt_stats); i++) {
+               int idx = i + LPROC_MD_LAST_OPC;
+               int flags = 0;
+
+               if (idx == LPROC_MDT_IO_WRITE || idx == LPROC_MDT_IO_READ)
+                       flags = LPROCFS_CNTR_AVGMINMAX;
+
+               lprocfs_counter_init(obd->obd_md_stats, idx, flags,
+                                    mdt_stats[i], "reqs");
+       }
+
+       rc = lprocfs_job_stats_init(obd, ARRAY_SIZE(mdt_stats),
                                    mdt_stats_counter_init);
 
        rc = lproc_mdt_attach_rename_seqstat(mdt);
index 85dec3e..663fdf1 100644 (file)
@@ -1655,49 +1655,23 @@ void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
 }
 EXPORT_SYMBOL(lprocfs_counter_init);
 
-/* Note that we only init md counters for ops whose offset is less
- * than NUM_MD_STATS. This is explained in a comment in the definition
- * of struct md_ops. */
-#define LPROCFS_MD_OP_INIT(base, stats, op)                                   \
-       do {                                                                   \
-               unsigned int _idx = base + MD_COUNTER_OFFSET(op);              \
-                                                                              \
-               if (MD_COUNTER_OFFSET(op) < NUM_MD_STATS) {                    \
-                       LASSERT(_idx < stats->ls_num);                         \
-                       lprocfs_counter_init(stats, _idx, 0, #op, "reqs");     \
-               }                                                              \
-       } while (0)
-
-void lprocfs_init_mps_stats(int num_private_stats, struct lprocfs_stats *stats)
-{
-       LPROCFS_MD_OP_INIT(num_private_stats, stats, get_root);
-        LPROCFS_MD_OP_INIT(num_private_stats, stats, null_inode);
-        LPROCFS_MD_OP_INIT(num_private_stats, stats, close);
-        LPROCFS_MD_OP_INIT(num_private_stats, stats, create);
-        LPROCFS_MD_OP_INIT(num_private_stats, stats, enqueue);
-        LPROCFS_MD_OP_INIT(num_private_stats, stats, getattr);
-        LPROCFS_MD_OP_INIT(num_private_stats, stats, getattr_name);
-        LPROCFS_MD_OP_INIT(num_private_stats, stats, intent_lock);
-        LPROCFS_MD_OP_INIT(num_private_stats, stats, link);
-        LPROCFS_MD_OP_INIT(num_private_stats, stats, rename);
-        LPROCFS_MD_OP_INIT(num_private_stats, stats, setattr);
-       LPROCFS_MD_OP_INIT(num_private_stats, stats, fsync);
-       LPROCFS_MD_OP_INIT(num_private_stats, stats, read_page);
-        LPROCFS_MD_OP_INIT(num_private_stats, stats, unlink);
-        LPROCFS_MD_OP_INIT(num_private_stats, stats, setxattr);
-        LPROCFS_MD_OP_INIT(num_private_stats, stats, getxattr);
-        LPROCFS_MD_OP_INIT(num_private_stats, stats, init_ea_size);
-        LPROCFS_MD_OP_INIT(num_private_stats, stats, get_lustre_md);
-        LPROCFS_MD_OP_INIT(num_private_stats, stats, free_lustre_md);
-       LPROCFS_MD_OP_INIT(num_private_stats, stats, merge_attr);
-        LPROCFS_MD_OP_INIT(num_private_stats, stats, set_open_replay_data);
-        LPROCFS_MD_OP_INIT(num_private_stats, stats, clear_open_replay_data);
-        LPROCFS_MD_OP_INIT(num_private_stats, stats, set_lock_data);
-        LPROCFS_MD_OP_INIT(num_private_stats, stats, lock_match);
-        LPROCFS_MD_OP_INIT(num_private_stats, stats, cancel_unused);
-        LPROCFS_MD_OP_INIT(num_private_stats, stats, intent_getattr_async);
-        LPROCFS_MD_OP_INIT(num_private_stats, stats, revalidate_lock);
-}
+static const char * const mps_stats[] = {
+       [LPROC_MD_CLOSE]                = "close",
+       [LPROC_MD_CREATE]               = "create",
+       [LPROC_MD_ENQUEUE]              = "enqueue",
+       [LPROC_MD_GETATTR]              = "getattr",
+       [LPROC_MD_INTENT_LOCK]          = "intent_lock",
+       [LPROC_MD_LINK]                 = "link",
+       [LPROC_MD_RENAME]               = "rename",
+       [LPROC_MD_SETATTR]              = "setattr",
+       [LPROC_MD_FSYNC]                = "fsync",
+       [LPROC_MD_READ_PAGE]            = "read_page",
+       [LPROC_MD_UNLINK]               = "unlink",
+       [LPROC_MD_SETXATTR]             = "setxattr",
+       [LPROC_MD_GETXATTR]             = "getxattr",
+       [LPROC_MD_INTENT_GETATTR_ASYNC] = "intent_getattr_async",
+       [LPROC_MD_REVALIDATE_LOCK]      = "revalidate_lock",
+};
 
 int lprocfs_alloc_md_stats(struct obd_device *obd,
                           unsigned int num_private_stats)
@@ -1706,10 +1680,6 @@ int lprocfs_alloc_md_stats(struct obd_device *obd,
        unsigned int num_stats;
        int rc, i;
 
-       CLASSERT(offsetof(struct md_ops, MD_STATS_FIRST_OP) == 0);
-       CLASSERT(_MD_COUNTER_OFFSET(MD_STATS_FIRST_OP) == 0);
-       CLASSERT(_MD_COUNTER_OFFSET(MD_STATS_LAST_OP) > 0);
-
        /* TODO Ensure that this function is only used where
         * appropriate by adding an assertion to the effect that
         * obd->obd_type->typ_md_ops is not NULL. We can't do this now
@@ -1720,20 +1690,17 @@ int lprocfs_alloc_md_stats(struct obd_device *obd,
         */
        LASSERT(obd->obd_proc_entry != NULL);
        LASSERT(obd->obd_md_stats == NULL);
-       LASSERT(obd->obd_md_cntr_base == 0);
 
-       num_stats = NUM_MD_STATS + num_private_stats;
+       num_stats = ARRAY_SIZE(mps_stats) + num_private_stats;
        stats = lprocfs_alloc_stats(num_stats, 0);
-       if (stats == NULL)
+       if (!stats)
                return -ENOMEM;
 
-       lprocfs_init_mps_stats(num_private_stats, stats);
-
-       for (i = num_private_stats; i < num_stats; i++) {
-               if (stats->ls_cnt_header[i].lc_name == NULL) {
-                       CERROR("Missing md_stat initializer md_op "
-                              "operation at offset %d. Aborting.\n",
-                              i - num_private_stats);
+       for (i = 0; i < ARRAY_SIZE(mps_stats); i++) {
+               lprocfs_counter_init(stats, i, 0, mps_stats[i], "reqs");
+               if (!stats->ls_cnt_header[i].lc_name) {
+                       CERROR("Missing md_stat initializer md_op operation at offset %d. Aborting.\n",
+                              i);
                        LBUG();
                }
        }
@@ -1743,7 +1710,6 @@ int lprocfs_alloc_md_stats(struct obd_device *obd,
                lprocfs_free_stats(&stats);
        } else {
                obd->obd_md_stats = stats;
-               obd->obd_md_cntr_base = num_private_stats;
        }
 
        return rc;
@@ -1756,7 +1722,6 @@ void lprocfs_free_md_stats(struct obd_device *obd)
 
        if (stats != NULL) {
                obd->obd_md_stats = NULL;
-               obd->obd_md_cntr_base = 0;
                lprocfs_free_stats(&stats);
        }
 }