Skip to content

Commit 26ca390

Browse files
cmaiolinodchinner
authored andcommitted
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>
1 parent 41657e5 commit 26ca390

File tree

2 files changed

+31
-49
lines changed

2 files changed

+31
-49
lines changed

fs/xfs/xfs_stats.c

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,30 @@ int xfs_stats_format(struct xfsstats __percpu *stats, char *buf)
2929
char *desc;
3030
int endpoint;
3131
} 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)},
5454
/* we print both series of quota information together */
55-
{ "qm", XFSSTAT_END_QM },
55+
{ "qm", xfsstats_offset(xs_xstrat_bytes)},
5656
};
5757

5858
/* Loop over all stats groups */
@@ -104,6 +104,10 @@ void xfs_stats_clearall(struct xfsstats __percpu *stats)
104104
#ifdef CONFIG_PROC_FS
105105
/* legacy quota interfaces */
106106
#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+
107111
static int xqm_proc_show(struct seq_file *m, void *v)
108112
{
109113
/* maximum; incore; ratio free to inuse; freelist */
@@ -119,7 +123,7 @@ static int xqmstat_proc_show(struct seq_file *m, void *v)
119123
int j;
120124

121125
seq_printf(m, "qm");
122-
for (j = XFSSTAT_END_REFCOUNT; j < XFSSTAT_END_XQMSTAT; j++)
126+
for (j = XFSSTAT_START_XQMSTAT; j < XFSSTAT_END_XQMSTAT; j++)
123127
seq_printf(m, " %u", counter_val(xfsstats.xs_stats, j));
124128
seq_putc(m, '\n');
125129
return 0;

fs/xfs/xfs_stats.h

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,53 +41,44 @@ enum {
4141
* XFS global statistics
4242
*/
4343
struct __xfsstats {
44-
# define XFSSTAT_END_EXTENT_ALLOC 4
4544
uint32_t xs_allocx;
4645
uint32_t xs_allocb;
4746
uint32_t xs_freex;
4847
uint32_t xs_freeb;
49-
# define XFSSTAT_END_ALLOC_BTREE (XFSSTAT_END_EXTENT_ALLOC+4)
5048
uint32_t xs_abt_lookup;
5149
uint32_t xs_abt_compare;
5250
uint32_t xs_abt_insrec;
5351
uint32_t xs_abt_delrec;
54-
# define XFSSTAT_END_BLOCK_MAPPING (XFSSTAT_END_ALLOC_BTREE+7)
5552
uint32_t xs_blk_mapr;
5653
uint32_t xs_blk_mapw;
5754
uint32_t xs_blk_unmap;
5855
uint32_t xs_add_exlist;
5956
uint32_t xs_del_exlist;
6057
uint32_t xs_look_exlist;
6158
uint32_t xs_cmp_exlist;
62-
# define XFSSTAT_END_BLOCK_MAP_BTREE (XFSSTAT_END_BLOCK_MAPPING+4)
6359
uint32_t xs_bmbt_lookup;
6460
uint32_t xs_bmbt_compare;
6561
uint32_t xs_bmbt_insrec;
6662
uint32_t xs_bmbt_delrec;
67-
# define XFSSTAT_END_DIRECTORY_OPS (XFSSTAT_END_BLOCK_MAP_BTREE+4)
6863
uint32_t xs_dir_lookup;
6964
uint32_t xs_dir_create;
7065
uint32_t xs_dir_remove;
7166
uint32_t xs_dir_getdents;
72-
# define XFSSTAT_END_TRANSACTIONS (XFSSTAT_END_DIRECTORY_OPS+3)
7367
uint32_t xs_trans_sync;
7468
uint32_t xs_trans_async;
7569
uint32_t xs_trans_empty;
76-
# define XFSSTAT_END_INODE_OPS (XFSSTAT_END_TRANSACTIONS+7)
7770
uint32_t xs_ig_attempts;
7871
uint32_t xs_ig_found;
7972
uint32_t xs_ig_frecycle;
8073
uint32_t xs_ig_missed;
8174
uint32_t xs_ig_dup;
8275
uint32_t xs_ig_reclaims;
8376
uint32_t xs_ig_attrchg;
84-
# define XFSSTAT_END_LOG_OPS (XFSSTAT_END_INODE_OPS+5)
8577
uint32_t xs_log_writes;
8678
uint32_t xs_log_blocks;
8779
uint32_t xs_log_noiclogs;
8880
uint32_t xs_log_force;
8981
uint32_t xs_log_force_sleep;
90-
# define XFSSTAT_END_TAIL_PUSHING (XFSSTAT_END_LOG_OPS+10)
9182
uint32_t xs_try_logspace;
9283
uint32_t xs_sleep_logspace;
9384
uint32_t xs_push_ail;
@@ -98,22 +89,17 @@ struct __xfsstats {
9889
uint32_t xs_push_ail_flushing;
9990
uint32_t xs_push_ail_restarts;
10091
uint32_t xs_push_ail_flush;
101-
# define XFSSTAT_END_WRITE_CONVERT (XFSSTAT_END_TAIL_PUSHING+2)
10292
uint32_t xs_xstrat_quick;
10393
uint32_t xs_xstrat_split;
104-
# define XFSSTAT_END_READ_WRITE_OPS (XFSSTAT_END_WRITE_CONVERT+2)
10594
uint32_t xs_write_calls;
10695
uint32_t xs_read_calls;
107-
# define XFSSTAT_END_ATTRIBUTE_OPS (XFSSTAT_END_READ_WRITE_OPS+4)
10896
uint32_t xs_attr_get;
10997
uint32_t xs_attr_set;
11098
uint32_t xs_attr_remove;
11199
uint32_t xs_attr_list;
112-
# define XFSSTAT_END_INODE_CLUSTER (XFSSTAT_END_ATTRIBUTE_OPS+3)
113100
uint32_t xs_iflush_count;
114101
uint32_t xs_icluster_flushcnt;
115102
uint32_t xs_icluster_flushinode;
116-
# define XFSSTAT_END_VNODE_OPS (XFSSTAT_END_INODE_CLUSTER+8)
117103
uint32_t vn_active; /* # vnodes not on free lists */
118104
uint32_t vn_alloc; /* # times vn_alloc called */
119105
uint32_t vn_get; /* # times vn_get called */
@@ -122,7 +108,6 @@ struct __xfsstats {
122108
uint32_t vn_reclaim; /* # times vn_reclaim called */
123109
uint32_t vn_remove; /* # times vn_remove called */
124110
uint32_t vn_free; /* # times vn_free called */
125-
#define XFSSTAT_END_BUF (XFSSTAT_END_VNODE_OPS+9)
126111
uint32_t xb_get;
127112
uint32_t xb_create;
128113
uint32_t xb_get_locked;
@@ -133,28 +118,19 @@ struct __xfsstats {
133118
uint32_t xb_page_found;
134119
uint32_t xb_get_read;
135120
/* Version 2 btree counters */
136-
#define XFSSTAT_END_ABTB_V2 (XFSSTAT_END_BUF + __XBTS_MAX)
137121
uint32_t xs_abtb_2[__XBTS_MAX];
138-
#define XFSSTAT_END_ABTC_V2 (XFSSTAT_END_ABTB_V2 + __XBTS_MAX)
139122
uint32_t xs_abtc_2[__XBTS_MAX];
140-
#define XFSSTAT_END_BMBT_V2 (XFSSTAT_END_ABTC_V2 + __XBTS_MAX)
141123
uint32_t xs_bmbt_2[__XBTS_MAX];
142-
#define XFSSTAT_END_IBT_V2 (XFSSTAT_END_BMBT_V2 + __XBTS_MAX)
143124
uint32_t xs_ibt_2[__XBTS_MAX];
144-
#define XFSSTAT_END_FIBT_V2 (XFSSTAT_END_IBT_V2 + __XBTS_MAX)
145125
uint32_t xs_fibt_2[__XBTS_MAX];
146-
#define XFSSTAT_END_RMAP_V2 (XFSSTAT_END_FIBT_V2 + __XBTS_MAX)
147126
uint32_t xs_rmap_2[__XBTS_MAX];
148-
#define XFSSTAT_END_REFCOUNT (XFSSTAT_END_RMAP_V2 + __XBTS_MAX)
149127
uint32_t xs_refcbt_2[__XBTS_MAX];
150-
#define XFSSTAT_END_XQMSTAT (XFSSTAT_END_REFCOUNT + 6)
151128
uint32_t xs_qm_dqreclaims;
152129
uint32_t xs_qm_dqreclaim_misses;
153130
uint32_t xs_qm_dquot_dups;
154131
uint32_t xs_qm_dqcachemisses;
155132
uint32_t xs_qm_dqcachehits;
156133
uint32_t xs_qm_dqwants;
157-
#define XFSSTAT_END_QM (XFSSTAT_END_XQMSTAT+2)
158134
uint32_t xs_qm_dquot;
159135
uint32_t xs_qm_dquot_unused;
160136
/* Extra precision counters */
@@ -163,10 +139,12 @@ struct __xfsstats {
163139
uint64_t xs_read_bytes;
164140
};
165141

142+
#define xfsstats_offset(f) (offsetof(struct __xfsstats, f)/sizeof(uint32_t))
143+
166144
struct xfsstats {
167145
union {
168146
struct __xfsstats s;
169-
uint32_t a[XFSSTAT_END_XQMSTAT];
147+
uint32_t a[xfsstats_offset(xs_qm_dquot)];
170148
};
171149
};
172150

0 commit comments

Comments
 (0)