xfs: refactor attr scrub memory allocation function
Move the code that allocates memory buffers for the extended attribute scrub code into a separate function so we can reduce memory allocations in the next patch. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Reviewed-by: Brian Foster <bfoster@redhat.com>
This commit is contained in:
parent
3addd24880
commit
0081675933
@ -20,25 +20,40 @@
|
|||||||
#include "scrub/dabtree.h"
|
#include "scrub/dabtree.h"
|
||||||
#include "scrub/attr.h"
|
#include "scrub/attr.h"
|
||||||
|
|
||||||
|
/* Allocate enough memory to hold an attr value and attr block bitmaps. */
|
||||||
|
int
|
||||||
|
xchk_setup_xattr_buf(
|
||||||
|
struct xfs_scrub *sc,
|
||||||
|
size_t value_size)
|
||||||
|
{
|
||||||
|
size_t sz;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We need enough space to read an xattr value from the file or enough
|
||||||
|
* space to hold three copies of the xattr free space bitmap. We don't
|
||||||
|
* need the buffer space for both purposes at the same time.
|
||||||
|
*/
|
||||||
|
sz = 3 * sizeof(long) * BITS_TO_LONGS(sc->mp->m_attr_geo->blksize);
|
||||||
|
sz = max_t(size_t, sz, value_size);
|
||||||
|
|
||||||
|
sc->buf = kmem_zalloc_large(sz, KM_SLEEP);
|
||||||
|
if (!sc->buf)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Set us up to scrub an inode's extended attributes. */
|
/* Set us up to scrub an inode's extended attributes. */
|
||||||
int
|
int
|
||||||
xchk_setup_xattr(
|
xchk_setup_xattr(
|
||||||
struct xfs_scrub *sc,
|
struct xfs_scrub *sc,
|
||||||
struct xfs_inode *ip)
|
struct xfs_inode *ip)
|
||||||
{
|
{
|
||||||
size_t sz;
|
int error;
|
||||||
|
|
||||||
/*
|
error = xchk_setup_xattr_buf(sc, XATTR_SIZE_MAX);
|
||||||
* Allocate the buffer without the inode lock held. We need enough
|
if (error)
|
||||||
* space to read every xattr value in the file or enough space to
|
return error;
|
||||||
* hold three copies of the xattr free space bitmap. (Not both at
|
|
||||||
* the same time.)
|
|
||||||
*/
|
|
||||||
sz = max_t(size_t, XATTR_SIZE_MAX, 3 * sizeof(long) *
|
|
||||||
BITS_TO_LONGS(sc->mp->m_attr_geo->blksize));
|
|
||||||
sc->buf = kmem_zalloc_large(sz, KM_SLEEP);
|
|
||||||
if (!sc->buf)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
return xchk_setup_inode_contents(sc, ip, 0);
|
return xchk_setup_inode_contents(sc, ip, 0);
|
||||||
}
|
}
|
||||||
|
@ -62,4 +62,6 @@ xchk_xattr_dstmap(
|
|||||||
BITS_TO_LONGS(sc->mp->m_attr_geo->blksize);
|
BITS_TO_LONGS(sc->mp->m_attr_geo->blksize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int xchk_setup_xattr_buf(struct xfs_scrub *sc, size_t value_size);
|
||||||
|
|
||||||
#endif /* __XFS_SCRUB_ATTR_H__ */
|
#endif /* __XFS_SCRUB_ATTR_H__ */
|
||||||
|
Loading…
Reference in New Issue
Block a user