Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

xfs: use offsetof() in place of offset macros for __xfsstats

Most offset macro mess is used in xfs_stats_format() only, and we can
simply get the right offsets using offsetof(), instead of several macros
to mark the offsets inside __xfsstats structure.

Replace all XFSSTAT_END_* macros by a single helper macro to get the
right offset into __xfsstats, and use this helper in xfs_stats_format()
directly.

The quota stats code, still looks a bit cleaner when using XFSSTAT_*
macros, so, this patch also defines XFSSTAT_START_XQMSTAT and
XFSSTAT_END_XQMSTAT locally to that code. This also should prevent
offset mistakes when updates are done into __xfsstats.

Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>

authored by

Carlos Maiolino and committed by
Dave Chinner
26ca3901 41657e55

+31 -49
+28 -24
fs/xfs/xfs_stats.c
··· 29 29 char *desc; 30 30 int endpoint; 31 31 } xstats[] = { 32 - { "extent_alloc", XFSSTAT_END_EXTENT_ALLOC }, 33 - { "abt", XFSSTAT_END_ALLOC_BTREE }, 34 - { "blk_map", XFSSTAT_END_BLOCK_MAPPING }, 35 - { "bmbt", XFSSTAT_END_BLOCK_MAP_BTREE }, 36 - { "dir", XFSSTAT_END_DIRECTORY_OPS }, 37 - { "trans", XFSSTAT_END_TRANSACTIONS }, 38 - { "ig", XFSSTAT_END_INODE_OPS }, 39 - { "log", XFSSTAT_END_LOG_OPS }, 40 - { "push_ail", XFSSTAT_END_TAIL_PUSHING }, 41 - { "xstrat", XFSSTAT_END_WRITE_CONVERT }, 42 - { "rw", XFSSTAT_END_READ_WRITE_OPS }, 43 - { "attr", XFSSTAT_END_ATTRIBUTE_OPS }, 44 - { "icluster", XFSSTAT_END_INODE_CLUSTER }, 45 - { "vnodes", XFSSTAT_END_VNODE_OPS }, 46 - { "buf", XFSSTAT_END_BUF }, 47 - { "abtb2", XFSSTAT_END_ABTB_V2 }, 48 - { "abtc2", XFSSTAT_END_ABTC_V2 }, 49 - { "bmbt2", XFSSTAT_END_BMBT_V2 }, 50 - { "ibt2", XFSSTAT_END_IBT_V2 }, 51 - { "fibt2", XFSSTAT_END_FIBT_V2 }, 52 - { "rmapbt", XFSSTAT_END_RMAP_V2 }, 53 - { "refcntbt", XFSSTAT_END_REFCOUNT }, 32 + { "extent_alloc", xfsstats_offset(xs_abt_lookup) }, 33 + { "abt", xfsstats_offset(xs_blk_mapr) }, 34 + { "blk_map", xfsstats_offset(xs_bmbt_lookup) }, 35 + { "bmbt", xfsstats_offset(xs_dir_lookup) }, 36 + { "dir", xfsstats_offset(xs_trans_sync) }, 37 + { "trans", xfsstats_offset(xs_ig_attempts) }, 38 + { "ig", xfsstats_offset(xs_log_writes) }, 39 + { "log", xfsstats_offset(xs_try_logspace)}, 40 + { "push_ail", xfsstats_offset(xs_xstrat_quick)}, 41 + { "xstrat", xfsstats_offset(xs_write_calls) }, 42 + { "rw", xfsstats_offset(xs_attr_get) }, 43 + { "attr", xfsstats_offset(xs_iflush_count)}, 44 + { "icluster", xfsstats_offset(vn_active) }, 45 + { "vnodes", xfsstats_offset(xb_get) }, 46 + { "buf", xfsstats_offset(xs_abtb_2) }, 47 + { "abtb2", xfsstats_offset(xs_abtc_2) }, 48 + { "abtc2", xfsstats_offset(xs_bmbt_2) }, 49 + { "bmbt2", xfsstats_offset(xs_ibt_2) }, 50 + { "ibt2", xfsstats_offset(xs_fibt_2) }, 51 + { "fibt2", xfsstats_offset(xs_rmap_2) }, 52 + { "rmapbt", xfsstats_offset(xs_refcbt_2) }, 53 + { "refcntbt", xfsstats_offset(xs_qm_dqreclaims)}, 54 54 /* we print both series of quota information together */ 55 - { "qm", XFSSTAT_END_QM }, 55 + { "qm", xfsstats_offset(xs_xstrat_bytes)}, 56 56 }; 57 57 58 58 /* Loop over all stats groups */ ··· 104 104 #ifdef CONFIG_PROC_FS 105 105 /* legacy quota interfaces */ 106 106 #ifdef CONFIG_XFS_QUOTA 107 + 108 + #define XFSSTAT_START_XQMSTAT xfsstats_offset(xs_qm_dqreclaims) 109 + #define XFSSTAT_END_XQMSTAT xfsstats_offset(xs_qm_dquot) 110 + 107 111 static int xqm_proc_show(struct seq_file *m, void *v) 108 112 { 109 113 /* maximum; incore; ratio free to inuse; freelist */ ··· 123 119 int j; 124 120 125 121 seq_printf(m, "qm"); 126 - for (j = XFSSTAT_END_REFCOUNT; j < XFSSTAT_END_XQMSTAT; j++) 122 + for (j = XFSSTAT_START_XQMSTAT; j < XFSSTAT_END_XQMSTAT; j++) 127 123 seq_printf(m, " %u", counter_val(xfsstats.xs_stats, j)); 128 124 seq_putc(m, '\n'); 129 125 return 0;
+3 -25
fs/xfs/xfs_stats.h
··· 41 41 * XFS global statistics 42 42 */ 43 43 struct __xfsstats { 44 - # define XFSSTAT_END_EXTENT_ALLOC 4 45 44 uint32_t xs_allocx; 46 45 uint32_t xs_allocb; 47 46 uint32_t xs_freex; 48 47 uint32_t xs_freeb; 49 - # define XFSSTAT_END_ALLOC_BTREE (XFSSTAT_END_EXTENT_ALLOC+4) 50 48 uint32_t xs_abt_lookup; 51 49 uint32_t xs_abt_compare; 52 50 uint32_t xs_abt_insrec; 53 51 uint32_t xs_abt_delrec; 54 - # define XFSSTAT_END_BLOCK_MAPPING (XFSSTAT_END_ALLOC_BTREE+7) 55 52 uint32_t xs_blk_mapr; 56 53 uint32_t xs_blk_mapw; 57 54 uint32_t xs_blk_unmap; ··· 56 59 uint32_t xs_del_exlist; 57 60 uint32_t xs_look_exlist; 58 61 uint32_t xs_cmp_exlist; 59 - # define XFSSTAT_END_BLOCK_MAP_BTREE (XFSSTAT_END_BLOCK_MAPPING+4) 60 62 uint32_t xs_bmbt_lookup; 61 63 uint32_t xs_bmbt_compare; 62 64 uint32_t xs_bmbt_insrec; 63 65 uint32_t xs_bmbt_delrec; 64 - # define XFSSTAT_END_DIRECTORY_OPS (XFSSTAT_END_BLOCK_MAP_BTREE+4) 65 66 uint32_t xs_dir_lookup; 66 67 uint32_t xs_dir_create; 67 68 uint32_t xs_dir_remove; 68 69 uint32_t xs_dir_getdents; 69 - # define XFSSTAT_END_TRANSACTIONS (XFSSTAT_END_DIRECTORY_OPS+3) 70 70 uint32_t xs_trans_sync; 71 71 uint32_t xs_trans_async; 72 72 uint32_t xs_trans_empty; 73 - # define XFSSTAT_END_INODE_OPS (XFSSTAT_END_TRANSACTIONS+7) 74 73 uint32_t xs_ig_attempts; 75 74 uint32_t xs_ig_found; 76 75 uint32_t xs_ig_frecycle; ··· 74 81 uint32_t xs_ig_dup; 75 82 uint32_t xs_ig_reclaims; 76 83 uint32_t xs_ig_attrchg; 77 - # define XFSSTAT_END_LOG_OPS (XFSSTAT_END_INODE_OPS+5) 78 84 uint32_t xs_log_writes; 79 85 uint32_t xs_log_blocks; 80 86 uint32_t xs_log_noiclogs; 81 87 uint32_t xs_log_force; 82 88 uint32_t xs_log_force_sleep; 83 - # define XFSSTAT_END_TAIL_PUSHING (XFSSTAT_END_LOG_OPS+10) 84 89 uint32_t xs_try_logspace; 85 90 uint32_t xs_sleep_logspace; 86 91 uint32_t xs_push_ail; ··· 89 98 uint32_t xs_push_ail_flushing; 90 99 uint32_t xs_push_ail_restarts; 91 100 uint32_t xs_push_ail_flush; 92 - # define XFSSTAT_END_WRITE_CONVERT (XFSSTAT_END_TAIL_PUSHING+2) 93 101 uint32_t xs_xstrat_quick; 94 102 uint32_t xs_xstrat_split; 95 - # define XFSSTAT_END_READ_WRITE_OPS (XFSSTAT_END_WRITE_CONVERT+2) 96 103 uint32_t xs_write_calls; 97 104 uint32_t xs_read_calls; 98 - # define XFSSTAT_END_ATTRIBUTE_OPS (XFSSTAT_END_READ_WRITE_OPS+4) 99 105 uint32_t xs_attr_get; 100 106 uint32_t xs_attr_set; 101 107 uint32_t xs_attr_remove; 102 108 uint32_t xs_attr_list; 103 - # define XFSSTAT_END_INODE_CLUSTER (XFSSTAT_END_ATTRIBUTE_OPS+3) 104 109 uint32_t xs_iflush_count; 105 110 uint32_t xs_icluster_flushcnt; 106 111 uint32_t xs_icluster_flushinode; 107 - # define XFSSTAT_END_VNODE_OPS (XFSSTAT_END_INODE_CLUSTER+8) 108 112 uint32_t vn_active; /* # vnodes not on free lists */ 109 113 uint32_t vn_alloc; /* # times vn_alloc called */ 110 114 uint32_t vn_get; /* # times vn_get called */ ··· 108 122 uint32_t vn_reclaim; /* # times vn_reclaim called */ 109 123 uint32_t vn_remove; /* # times vn_remove called */ 110 124 uint32_t vn_free; /* # times vn_free called */ 111 - #define XFSSTAT_END_BUF (XFSSTAT_END_VNODE_OPS+9) 112 125 uint32_t xb_get; 113 126 uint32_t xb_create; 114 127 uint32_t xb_get_locked; ··· 118 133 uint32_t xb_page_found; 119 134 uint32_t xb_get_read; 120 135 /* Version 2 btree counters */ 121 - #define XFSSTAT_END_ABTB_V2 (XFSSTAT_END_BUF + __XBTS_MAX) 122 136 uint32_t xs_abtb_2[__XBTS_MAX]; 123 - #define XFSSTAT_END_ABTC_V2 (XFSSTAT_END_ABTB_V2 + __XBTS_MAX) 124 137 uint32_t xs_abtc_2[__XBTS_MAX]; 125 - #define XFSSTAT_END_BMBT_V2 (XFSSTAT_END_ABTC_V2 + __XBTS_MAX) 126 138 uint32_t xs_bmbt_2[__XBTS_MAX]; 127 - #define XFSSTAT_END_IBT_V2 (XFSSTAT_END_BMBT_V2 + __XBTS_MAX) 128 139 uint32_t xs_ibt_2[__XBTS_MAX]; 129 - #define XFSSTAT_END_FIBT_V2 (XFSSTAT_END_IBT_V2 + __XBTS_MAX) 130 140 uint32_t xs_fibt_2[__XBTS_MAX]; 131 - #define XFSSTAT_END_RMAP_V2 (XFSSTAT_END_FIBT_V2 + __XBTS_MAX) 132 141 uint32_t xs_rmap_2[__XBTS_MAX]; 133 - #define XFSSTAT_END_REFCOUNT (XFSSTAT_END_RMAP_V2 + __XBTS_MAX) 134 142 uint32_t xs_refcbt_2[__XBTS_MAX]; 135 - #define XFSSTAT_END_XQMSTAT (XFSSTAT_END_REFCOUNT + 6) 136 143 uint32_t xs_qm_dqreclaims; 137 144 uint32_t xs_qm_dqreclaim_misses; 138 145 uint32_t xs_qm_dquot_dups; 139 146 uint32_t xs_qm_dqcachemisses; 140 147 uint32_t xs_qm_dqcachehits; 141 148 uint32_t xs_qm_dqwants; 142 - #define XFSSTAT_END_QM (XFSSTAT_END_XQMSTAT+2) 143 149 uint32_t xs_qm_dquot; 144 150 uint32_t xs_qm_dquot_unused; 145 151 /* Extra precision counters */ ··· 139 163 uint64_t xs_read_bytes; 140 164 }; 141 165 166 + #define xfsstats_offset(f) (offsetof(struct __xfsstats, f)/sizeof(uint32_t)) 167 + 142 168 struct xfsstats { 143 169 union { 144 170 struct __xfsstats s; 145 - uint32_t a[XFSSTAT_END_XQMSTAT]; 171 + uint32_t a[xfsstats_offset(xs_qm_dquot)]; 146 172 }; 147 173 }; 148 174