@@ -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(
243248STATIC bool
244249xchk_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 )
0 commit comments