Skip to content

Commit 663b8db

Browse files
author
Darrick J. Wong
committed
xfs: use accessor functions for summary info words
Create get and set functions for rtsummary words so that we can redefine the ondisk format with a specific endianness. Note that this requires the definition of a distinct type for ondisk summary info words so that the compiler can perform proper typechecking. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de>
1 parent bd85af2 commit 663b8db

File tree

7 files changed

+71
-24
lines changed

7 files changed

+71
-24
lines changed

fs/xfs/libxfs/xfs_format.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,14 @@ union xfs_rtword_raw {
698698
__u32 old;
699699
};
700700

701+
/*
702+
* Realtime summary counts are accessed by the word, which is currently
703+
* stored in host-endian format.
704+
*/
705+
union xfs_suminfo_raw {
706+
__u32 old;
707+
};
708+
701709
/*
702710
* XFS Timestamps
703711
* ==============

fs/xfs/libxfs/xfs_rtbitmap.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,6 @@ xfs_rtmodify_summary_int(
451451
int error; /* error value */
452452
xfs_fileoff_t sb; /* summary fsblock */
453453
xfs_rtsumoff_t so; /* index into the summary file */
454-
xfs_suminfo_t *sp; /* pointer to returned data */
455454
unsigned int infoword;
456455

457456
/*
@@ -490,19 +489,21 @@ xfs_rtmodify_summary_int(
490489
* Point to the summary information, modify/log it, and/or copy it out.
491490
*/
492491
infoword = xfs_rtsumoffs_to_infoword(mp, so);
493-
sp = xfs_rsumblock_infoptr(bp, infoword);
494492
if (delta) {
495-
*sp += delta;
493+
xfs_suminfo_t val = xfs_suminfo_add(bp, infoword, delta);
494+
496495
if (mp->m_rsum_cache) {
497-
if (*sp == 0 && log == mp->m_rsum_cache[bbno])
496+
if (val == 0 && log == mp->m_rsum_cache[bbno])
498497
mp->m_rsum_cache[bbno]++;
499-
if (*sp != 0 && log < mp->m_rsum_cache[bbno])
498+
if (val != 0 && log < mp->m_rsum_cache[bbno])
500499
mp->m_rsum_cache[bbno] = log;
501500
}
502501
xfs_trans_log_rtsummary(tp, bp, infoword);
502+
if (sum)
503+
*sum = val;
504+
} else if (sum) {
505+
*sum = xfs_suminfo_get(bp, infoword);
503506
}
504-
if (sum)
505-
*sum = *sp;
506507
return 0;
507508
}
508509

fs/xfs/libxfs/xfs_rtbitmap.h

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,16 +232,40 @@ xfs_rtsumoffs_to_infoword(
232232
}
233233

234234
/* Return a pointer to a summary info word within a rt summary block. */
235-
static inline xfs_suminfo_t *
235+
static inline union xfs_suminfo_raw *
236236
xfs_rsumblock_infoptr(
237237
struct xfs_buf *bp,
238238
unsigned int index)
239239
{
240-
xfs_suminfo_t *info = bp->b_addr;
240+
union xfs_suminfo_raw *info = bp->b_addr;
241241

242242
return info + index;
243243
}
244244

245+
/* Get the current value of a summary counter. */
246+
static inline xfs_suminfo_t
247+
xfs_suminfo_get(
248+
struct xfs_buf *bp,
249+
unsigned int index)
250+
{
251+
union xfs_suminfo_raw *info = xfs_rsumblock_infoptr(bp, index);
252+
253+
return info->old;
254+
}
255+
256+
/* Add to the current value of a summary counter and return the new value. */
257+
static inline xfs_suminfo_t
258+
xfs_suminfo_add(
259+
struct xfs_buf *bp,
260+
unsigned int index,
261+
int delta)
262+
{
263+
union xfs_suminfo_raw *info = xfs_rsumblock_infoptr(bp, index);
264+
265+
info->old += delta;
266+
return info->old;
267+
}
268+
245269
/*
246270
* Functions for walking free space rtextents in the realtime bitmap.
247271
*/

fs/xfs/scrub/rtsummary.c

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,33 +82,44 @@ static inline int
8282
xfsum_load(
8383
struct xfs_scrub *sc,
8484
xfs_rtsumoff_t sumoff,
85-
xfs_suminfo_t *info)
85+
union xfs_suminfo_raw *rawinfo)
8686
{
87-
return xfile_obj_load(sc->xfile, info, sizeof(xfs_suminfo_t),
87+
return xfile_obj_load(sc->xfile, rawinfo,
88+
sizeof(union xfs_suminfo_raw),
8889
sumoff << XFS_WORDLOG);
8990
}
9091

9192
static inline int
9293
xfsum_store(
9394
struct xfs_scrub *sc,
9495
xfs_rtsumoff_t sumoff,
95-
const xfs_suminfo_t info)
96+
const union xfs_suminfo_raw rawinfo)
9697
{
97-
return xfile_obj_store(sc->xfile, &info, sizeof(xfs_suminfo_t),
98+
return xfile_obj_store(sc->xfile, &rawinfo,
99+
sizeof(union xfs_suminfo_raw),
98100
sumoff << XFS_WORDLOG);
99101
}
100102

101103
static inline int
102104
xfsum_copyout(
103105
struct xfs_scrub *sc,
104106
xfs_rtsumoff_t sumoff,
105-
xfs_suminfo_t *info,
107+
union xfs_suminfo_raw *rawinfo,
106108
unsigned int nr_words)
107109
{
108-
return xfile_obj_load(sc->xfile, info, nr_words << XFS_WORDLOG,
110+
return xfile_obj_load(sc->xfile, rawinfo, nr_words << XFS_WORDLOG,
109111
sumoff << XFS_WORDLOG);
110112
}
111113

114+
static inline xfs_suminfo_t
115+
xchk_rtsum_inc(
116+
struct xfs_mount *mp,
117+
union xfs_suminfo_raw *v)
118+
{
119+
v->old += 1;
120+
return v->old;
121+
}
122+
112123
/* Update the summary file to reflect the free extent that we've accumulated. */
113124
STATIC int
114125
xchk_rtsum_record_free(
@@ -123,7 +134,8 @@ xchk_rtsum_record_free(
123134
xfs_filblks_t rtlen;
124135
xfs_rtsumoff_t offs;
125136
unsigned int lenlog;
126-
xfs_suminfo_t v = 0;
137+
union xfs_suminfo_raw v;
138+
xfs_suminfo_t value;
127139
int error = 0;
128140

129141
if (xchk_should_terminate(sc, &error))
@@ -147,9 +159,9 @@ xchk_rtsum_record_free(
147159
if (error)
148160
return error;
149161

150-
v++;
162+
value = xchk_rtsum_inc(sc->mp, &v);
151163
trace_xchk_rtsum_record_free(mp, rec->ar_startext, rec->ar_extcount,
152-
lenlog, offs, v);
164+
lenlog, offs, value);
153165

154166
return xfsum_store(sc, offs, v);
155167
}
@@ -184,7 +196,7 @@ xchk_rtsum_compare(
184196
int nmap;
185197

186198
for (off = 0; off < XFS_B_TO_FSB(mp, mp->m_rsumsize); off++) {
187-
xfs_suminfo_t *ondisk_info;
199+
union xfs_suminfo_raw *ondisk_info;
188200
int error = 0;
189201

190202
if (xchk_should_terminate(sc, &error))

fs/xfs/scrub/trace.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "xfs_inode.h"
1414
#include "xfs_btree.h"
1515
#include "xfs_ag.h"
16+
#include "xfs_rtbitmap.h"
1617
#include "scrub/scrub.h"
1718
#include "scrub/xfile.h"
1819
#include "scrub/xfarray.h"

fs/xfs/scrub/trace.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,16 +1038,16 @@ TRACE_EVENT(xfarray_sort_stats,
10381038
TRACE_EVENT(xchk_rtsum_record_free,
10391039
TP_PROTO(struct xfs_mount *mp, xfs_rtxnum_t start,
10401040
xfs_rtbxlen_t len, unsigned int log, loff_t pos,
1041-
xfs_suminfo_t v),
1042-
TP_ARGS(mp, start, len, log, pos, v),
1041+
xfs_suminfo_t value),
1042+
TP_ARGS(mp, start, len, log, pos, value),
10431043
TP_STRUCT__entry(
10441044
__field(dev_t, dev)
10451045
__field(dev_t, rtdev)
10461046
__field(xfs_rtxnum_t, start)
10471047
__field(unsigned long long, len)
10481048
__field(unsigned int, log)
10491049
__field(loff_t, pos)
1050-
__field(xfs_suminfo_t, v)
1050+
__field(xfs_suminfo_t, value)
10511051
),
10521052
TP_fast_assign(
10531053
__entry->dev = mp->m_super->s_dev;
@@ -1056,7 +1056,7 @@ TRACE_EVENT(xchk_rtsum_record_free,
10561056
__entry->len = len;
10571057
__entry->log = log;
10581058
__entry->pos = pos;
1059-
__entry->v = v;
1059+
__entry->value = value;
10601060
),
10611061
TP_printk("dev %d:%d rtdev %d:%d rtx 0x%llx rtxcount 0x%llx log %u rsumpos 0x%llx sumcount %u",
10621062
MAJOR(__entry->dev), MINOR(__entry->dev),
@@ -1065,7 +1065,7 @@ TRACE_EVENT(xchk_rtsum_record_free,
10651065
__entry->len,
10661066
__entry->log,
10671067
__entry->pos,
1068-
__entry->v)
1068+
__entry->value)
10691069
);
10701070
#endif /* CONFIG_XFS_RT */
10711071

fs/xfs/xfs_ondisk.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ xfs_check_ondisk_structs(void)
7474

7575
/* realtime structures */
7676
XFS_CHECK_STRUCT_SIZE(union xfs_rtword_raw, 4);
77+
XFS_CHECK_STRUCT_SIZE(union xfs_suminfo_raw, 4);
7778

7879
/*
7980
* m68k has problems with xfs_attr_leaf_name_remote_t, but we pad it to

0 commit comments

Comments
 (0)