diff options
| author | Darrick J. Wong <darrick.wong@oracle.com> | 2019-07-05 13:29:55 -0400 |
|---|---|---|
| committer | Darrick J. Wong <darrick.wong@oracle.com> | 2019-07-05 13:29:55 -0400 |
| commit | 00816759337cd28bc5290a24dcb527fd9d30680e (patch) | |
| tree | 104cbe5b7756cb55eb46a6610ec23b5e6309291f | |
| parent | 3addd248800c0d278900c064e54e611ae505c622 (diff) | |
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>
| -rw-r--r-- | fs/xfs/scrub/attr.c | 33 | ||||
| -rw-r--r-- | fs/xfs/scrub/attr.h | 2 |
2 files changed, 26 insertions, 9 deletions
diff --git a/fs/xfs/scrub/attr.c b/fs/xfs/scrub/attr.c index 13314cf87db8..7cb412ca473c 100644 --- a/fs/xfs/scrub/attr.c +++ b/fs/xfs/scrub/attr.c | |||
| @@ -20,26 +20,41 @@ | |||
| 20 | #include "scrub/dabtree.h" | 20 | #include "scrub/dabtree.h" |
| 21 | #include "scrub/attr.h" | 21 | #include "scrub/attr.h" |
| 22 | 22 | ||
| 23 | /* Set us up to scrub an inode's extended attributes. */ | 23 | /* Allocate enough memory to hold an attr value and attr block bitmaps. */ |
| 24 | int | 24 | int |
| 25 | xchk_setup_xattr( | 25 | xchk_setup_xattr_buf( |
| 26 | struct xfs_scrub *sc, | 26 | struct xfs_scrub *sc, |
| 27 | struct xfs_inode *ip) | 27 | size_t value_size) |
| 28 | { | 28 | { |
| 29 | size_t sz; | 29 | size_t sz; |
| 30 | 30 | ||
| 31 | /* | 31 | /* |
| 32 | * Allocate the buffer without the inode lock held. We need enough | 32 | * We need enough space to read an xattr value from the file or enough |
| 33 | * space to read every xattr value in the file or enough space to | 33 | * space to hold three copies of the xattr free space bitmap. We don't |
| 34 | * hold three copies of the xattr free space bitmap. (Not both at | 34 | * need the buffer space for both purposes at the same time. |
| 35 | * the same time.) | ||
| 36 | */ | 35 | */ |
| 37 | sz = max_t(size_t, XATTR_SIZE_MAX, 3 * sizeof(long) * | 36 | sz = 3 * sizeof(long) * BITS_TO_LONGS(sc->mp->m_attr_geo->blksize); |
| 38 | BITS_TO_LONGS(sc->mp->m_attr_geo->blksize)); | 37 | sz = max_t(size_t, sz, value_size); |
| 38 | |||
| 39 | sc->buf = kmem_zalloc_large(sz, KM_SLEEP); | 39 | sc->buf = kmem_zalloc_large(sz, KM_SLEEP); |
| 40 | if (!sc->buf) | 40 | if (!sc->buf) |
| 41 | return -ENOMEM; | 41 | return -ENOMEM; |
| 42 | 42 | ||
| 43 | return 0; | ||
| 44 | } | ||
| 45 | |||
| 46 | /* Set us up to scrub an inode's extended attributes. */ | ||
| 47 | int | ||
| 48 | xchk_setup_xattr( | ||
| 49 | struct xfs_scrub *sc, | ||
| 50 | struct xfs_inode *ip) | ||
| 51 | { | ||
| 52 | int error; | ||
| 53 | |||
| 54 | error = xchk_setup_xattr_buf(sc, XATTR_SIZE_MAX); | ||
| 55 | if (error) | ||
| 56 | return error; | ||
| 57 | |||
| 43 | return xchk_setup_inode_contents(sc, ip, 0); | 58 | return xchk_setup_inode_contents(sc, ip, 0); |
| 44 | } | 59 | } |
| 45 | 60 | ||
diff --git a/fs/xfs/scrub/attr.h b/fs/xfs/scrub/attr.h index 88bb5e29c60c..27e879aeaafc 100644 --- a/fs/xfs/scrub/attr.h +++ b/fs/xfs/scrub/attr.h | |||
| @@ -62,4 +62,6 @@ xchk_xattr_dstmap( | |||
| 62 | BITS_TO_LONGS(sc->mp->m_attr_geo->blksize); | 62 | BITS_TO_LONGS(sc->mp->m_attr_geo->blksize); |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | int xchk_setup_xattr_buf(struct xfs_scrub *sc, size_t value_size); | ||
| 66 | |||
| 65 | #endif /* __XFS_SCRUB_ATTR_H__ */ | 67 | #endif /* __XFS_SCRUB_ATTR_H__ */ |
