Skip to content

Commit 8006928

Browse files
author
Darrick J. Wong
committed
xfs: split usedmap from xchk_xattr_buf.buf
Move the used space bitmap from somewhere in xchk_xattr_buf.buf[] to an explicit pointer. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Dave Chinner <dchinner@redhat.com>
1 parent 91781ff commit 8006928

2 files changed

Lines changed: 26 additions & 35 deletions

File tree

fs/xfs/scrub/attr.c

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ xchk_xattr_buf_cleanup(
2929

3030
kvfree(ab->freemap);
3131
ab->freemap = NULL;
32+
kvfree(ab->usedmap);
33+
ab->usedmap = NULL;
3234
}
3335

3436
/*
@@ -42,20 +44,14 @@ xchk_setup_xattr_buf(
4244
size_t value_size,
4345
gfp_t flags)
4446
{
45-
size_t sz;
47+
size_t sz = value_size;
4648
size_t bmp_sz;
4749
struct xchk_xattr_buf *ab = sc->buf;
50+
unsigned long *old_usedmap = NULL;
4851
unsigned long *old_freemap = NULL;
4952

5053
bmp_sz = sizeof(long) * BITS_TO_LONGS(sc->mp->m_attr_geo->blksize);
5154

52-
/*
53-
* We need enough space to read an xattr value from the file or enough
54-
* space to hold one copy of the xattr free space bitmap. We don't
55-
* need the buffer space for both purposes at the same time.
56-
*/
57-
sz = max_t(size_t, bmp_sz, value_size);
58-
5955
/*
6056
* If there's already a buffer, figure out if we need to reallocate it
6157
* to accommodate a larger size.
@@ -64,6 +60,7 @@ xchk_setup_xattr_buf(
6460
if (sz <= ab->sz)
6561
return 0;
6662
old_freemap = ab->freemap;
63+
old_usedmap = ab->usedmap;
6764
kvfree(ab);
6865
sc->buf = NULL;
6966
}
@@ -79,6 +76,14 @@ xchk_setup_xattr_buf(
7976
sc->buf = ab;
8077
sc->buf_cleanup = xchk_xattr_buf_cleanup;
8178

79+
if (old_usedmap) {
80+
ab->usedmap = old_usedmap;
81+
} else {
82+
ab->usedmap = kvmalloc(bmp_sz, flags);
83+
if (!ab->usedmap)
84+
return -ENOMEM;
85+
}
86+
8287
if (old_freemap) {
8388
ab->freemap = old_freemap;
8489
} else {
@@ -243,7 +248,6 @@ xchk_xattr_set_map(
243248
STATIC bool
244249
xchk_xattr_check_freemap(
245250
struct xfs_scrub *sc,
246-
unsigned long *map,
247251
struct xfs_attr3_icleaf_hdr *leafhdr)
248252
{
249253
struct xchk_xattr_buf *ab = sc->buf;
@@ -260,7 +264,7 @@ xchk_xattr_check_freemap(
260264
}
261265

262266
/* Look for bits that are set in freemap and are marked in use. */
263-
return !bitmap_intersects(ab->freemap, map, mapsize);
267+
return !bitmap_intersects(ab->freemap, ab->usedmap, mapsize);
264268
}
265269

266270
/*
@@ -280,7 +284,7 @@ xchk_xattr_entry(
280284
__u32 *last_hashval)
281285
{
282286
struct xfs_mount *mp = ds->state->mp;
283-
unsigned long *usedmap = xchk_xattr_usedmap(ds->sc);
287+
struct xchk_xattr_buf *ab = ds->sc->buf;
284288
char *name_end;
285289
struct xfs_attr_leaf_name_local *lentry;
286290
struct xfs_attr_leaf_name_remote *rentry;
@@ -320,7 +324,7 @@ xchk_xattr_entry(
320324
if (name_end > buf_end)
321325
xchk_da_set_corrupt(ds, level);
322326

323-
if (!xchk_xattr_set_map(ds->sc, usedmap, nameidx, namesize))
327+
if (!xchk_xattr_set_map(ds->sc, ab->usedmap, nameidx, namesize))
324328
xchk_da_set_corrupt(ds, level);
325329
if (!(ds->sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT))
326330
*usedbytes += namesize;
@@ -340,7 +344,7 @@ xchk_xattr_block(
340344
struct xfs_attr_leafblock *leaf = bp->b_addr;
341345
struct xfs_attr_leaf_entry *ent;
342346
struct xfs_attr_leaf_entry *entries;
343-
unsigned long *usedmap;
347+
struct xchk_xattr_buf *ab = ds->sc->buf;
344348
char *buf_end;
345349
size_t off;
346350
__u32 last_hashval = 0;
@@ -358,10 +362,9 @@ xchk_xattr_block(
358362
return -EDEADLOCK;
359363
if (error)
360364
return error;
361-
usedmap = xchk_xattr_usedmap(ds->sc);
362365

363366
*last_checked = blk->blkno;
364-
bitmap_zero(usedmap, mp->m_attr_geo->blksize);
367+
bitmap_zero(ab->usedmap, mp->m_attr_geo->blksize);
365368

366369
/* Check all the padding. */
367370
if (xfs_has_crc(ds->sc->mp)) {
@@ -385,7 +388,7 @@ xchk_xattr_block(
385388
xchk_da_set_corrupt(ds, level);
386389
if (leafhdr.firstused < hdrsize)
387390
xchk_da_set_corrupt(ds, level);
388-
if (!xchk_xattr_set_map(ds->sc, usedmap, 0, hdrsize))
391+
if (!xchk_xattr_set_map(ds->sc, ab->usedmap, 0, hdrsize))
389392
xchk_da_set_corrupt(ds, level);
390393

391394
if (ds->sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
@@ -399,7 +402,7 @@ xchk_xattr_block(
399402
for (i = 0, ent = entries; i < leafhdr.count; ent++, i++) {
400403
/* Mark the leaf entry itself. */
401404
off = (char *)ent - (char *)leaf;
402-
if (!xchk_xattr_set_map(ds->sc, usedmap, off,
405+
if (!xchk_xattr_set_map(ds->sc, ab->usedmap, off,
403406
sizeof(xfs_attr_leaf_entry_t))) {
404407
xchk_da_set_corrupt(ds, level);
405408
goto out;
@@ -413,7 +416,7 @@ xchk_xattr_block(
413416
goto out;
414417
}
415418

416-
if (!xchk_xattr_check_freemap(ds->sc, usedmap, &leafhdr))
419+
if (!xchk_xattr_check_freemap(ds->sc, &leafhdr))
417420
xchk_da_set_corrupt(ds, level);
418421

419422
if (leafhdr.usedbytes != usedbytes)

fs/xfs/scrub/attr.h

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,18 @@
1010
* Temporary storage for online scrub and repair of extended attributes.
1111
*/
1212
struct xchk_xattr_buf {
13+
/* Bitmap of used space in xattr leaf blocks. */
14+
unsigned long *usedmap;
15+
1316
/* Bitmap of free space in xattr leaf blocks. */
1417
unsigned long *freemap;
1518

1619
/* Size of @buf, in bytes. */
1720
size_t sz;
1821

1922
/*
20-
* Memory buffer -- either used for extracting attr values while
21-
* walking the attributes; or for computing attr block bitmaps when
22-
* checking the attribute tree.
23-
*
24-
* Each bitmap contains enough bits to track every byte in an attr
25-
* block (rounded up to the size of an unsigned long). The attr block
26-
* used space bitmap starts at the beginning of the buffer.
23+
* Memory buffer -- used for extracting attr values while walking the
24+
* attributes.
2725
*/
2826
uint8_t buf[];
2927
};
@@ -38,14 +36,4 @@ xchk_xattr_valuebuf(
3836
return ab->buf;
3937
}
4038

41-
/* A bitmap of space usage computed by walking an attr leaf block. */
42-
static inline unsigned long *
43-
xchk_xattr_usedmap(
44-
struct xfs_scrub *sc)
45-
{
46-
struct xchk_xattr_buf *ab = sc->buf;
47-
48-
return (unsigned long *)ab->buf;
49-
}
50-
5139
#endif /* __XFS_SCRUB_ATTR_H__ */

0 commit comments

Comments
 (0)