aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs
diff options
context:
space:
mode:
authorDarrick J. Wong <darrick.wong@oracle.com>2019-07-05 13:29:55 -0400
committerDarrick J. Wong <darrick.wong@oracle.com>2019-07-05 13:29:55 -0400
commit3addd248800c0d278900c064e54e611ae505c622 (patch)
tree62da59ea5aeaba89ac7546e20fe0a21c309c7cef /fs/xfs
parent2c3b83d7ca6d73b9478afc86c89377c15a90b9ed (diff)
xfs: refactor extended attribute buffer pointer functions
Replace the open-coded attribute buffer pointer calculations with helper functions to make it more obvious what we're doing with our freeform memory allocation w.r.t. either storing xattr values or computing btree block free space. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Reviewed-by: Brian Foster <bfoster@redhat.com>
Diffstat (limited to 'fs/xfs')
-rw-r--r--fs/xfs/scrub/attr.c16
-rw-r--r--fs/xfs/scrub/attr.h65
2 files changed, 72 insertions, 9 deletions
diff --git a/fs/xfs/scrub/attr.c b/fs/xfs/scrub/attr.c
index 70f025284c42..13314cf87db8 100644
--- a/fs/xfs/scrub/attr.c
+++ b/fs/xfs/scrub/attr.c
@@ -18,7 +18,7 @@
18#include "scrub/scrub.h" 18#include "scrub/scrub.h"
19#include "scrub/common.h" 19#include "scrub/common.h"
20#include "scrub/dabtree.h" 20#include "scrub/dabtree.h"
21 21#include "scrub/attr.h"
22 22
23/* Set us up to scrub an inode's extended attributes. */ 23/* Set us up to scrub an inode's extended attributes. */
24int 24int
@@ -101,7 +101,7 @@ xchk_xattr_listent(
101 args.namelen = namelen; 101 args.namelen = namelen;
102 args.hashval = xfs_da_hashname(args.name, args.namelen); 102 args.hashval = xfs_da_hashname(args.name, args.namelen);
103 args.trans = context->tp; 103 args.trans = context->tp;
104 args.value = sx->sc->buf; 104 args.value = xchk_xattr_valuebuf(sx->sc);
105 args.valuelen = XATTR_SIZE_MAX; 105 args.valuelen = XATTR_SIZE_MAX;
106 106
107 error = xfs_attr_get_ilocked(context->dp, &args); 107 error = xfs_attr_get_ilocked(context->dp, &args);
@@ -160,13 +160,12 @@ xchk_xattr_check_freemap(
160 unsigned long *map, 160 unsigned long *map,
161 struct xfs_attr3_icleaf_hdr *leafhdr) 161 struct xfs_attr3_icleaf_hdr *leafhdr)
162{ 162{
163 unsigned long *freemap; 163 unsigned long *freemap = xchk_xattr_freemap(sc);
164 unsigned long *dstmap; 164 unsigned long *dstmap = xchk_xattr_dstmap(sc);
165 unsigned int mapsize = sc->mp->m_attr_geo->blksize; 165 unsigned int mapsize = sc->mp->m_attr_geo->blksize;
166 int i; 166 int i;
167 167
168 /* Construct bitmap of freemap contents. */ 168 /* Construct bitmap of freemap contents. */
169 freemap = (unsigned long *)sc->buf + BITS_TO_LONGS(mapsize);
170 bitmap_zero(freemap, mapsize); 169 bitmap_zero(freemap, mapsize);
171 for (i = 0; i < XFS_ATTR_LEAF_MAPSIZE; i++) { 170 for (i = 0; i < XFS_ATTR_LEAF_MAPSIZE; i++) {
172 if (!xchk_xattr_set_map(sc, freemap, 171 if (!xchk_xattr_set_map(sc, freemap,
@@ -176,7 +175,6 @@ xchk_xattr_check_freemap(
176 } 175 }
177 176
178 /* Look for bits that are set in freemap and are marked in use. */ 177 /* Look for bits that are set in freemap and are marked in use. */
179 dstmap = freemap + BITS_TO_LONGS(mapsize);
180 return bitmap_and(dstmap, freemap, map, mapsize) == 0; 178 return bitmap_and(dstmap, freemap, map, mapsize) == 0;
181} 179}
182 180
@@ -191,13 +189,13 @@ xchk_xattr_entry(
191 char *buf_end, 189 char *buf_end,
192 struct xfs_attr_leafblock *leaf, 190 struct xfs_attr_leafblock *leaf,
193 struct xfs_attr3_icleaf_hdr *leafhdr, 191 struct xfs_attr3_icleaf_hdr *leafhdr,
194 unsigned long *usedmap,
195 struct xfs_attr_leaf_entry *ent, 192 struct xfs_attr_leaf_entry *ent,
196 int idx, 193 int idx,
197 unsigned int *usedbytes, 194 unsigned int *usedbytes,
198 __u32 *last_hashval) 195 __u32 *last_hashval)
199{ 196{
200 struct xfs_mount *mp = ds->state->mp; 197 struct xfs_mount *mp = ds->state->mp;
198 unsigned long *usedmap = xchk_xattr_usedmap(ds->sc);
201 char *name_end; 199 char *name_end;
202 struct xfs_attr_leaf_name_local *lentry; 200 struct xfs_attr_leaf_name_local *lentry;
203 struct xfs_attr_leaf_name_remote *rentry; 201 struct xfs_attr_leaf_name_remote *rentry;
@@ -257,7 +255,7 @@ xchk_xattr_block(
257 struct xfs_attr_leafblock *leaf = bp->b_addr; 255 struct xfs_attr_leafblock *leaf = bp->b_addr;
258 struct xfs_attr_leaf_entry *ent; 256 struct xfs_attr_leaf_entry *ent;
259 struct xfs_attr_leaf_entry *entries; 257 struct xfs_attr_leaf_entry *entries;
260 unsigned long *usedmap = ds->sc->buf; 258 unsigned long *usedmap = xchk_xattr_usedmap(ds->sc);
261 char *buf_end; 259 char *buf_end;
262 size_t off; 260 size_t off;
263 __u32 last_hashval = 0; 261 __u32 last_hashval = 0;
@@ -314,7 +312,7 @@ xchk_xattr_block(
314 312
315 /* Check the entry and nameval. */ 313 /* Check the entry and nameval. */
316 xchk_xattr_entry(ds, level, buf_end, leaf, &leafhdr, 314 xchk_xattr_entry(ds, level, buf_end, leaf, &leafhdr,
317 usedmap, ent, i, &usedbytes, &last_hashval); 315 ent, i, &usedbytes, &last_hashval);
318 316
319 if (ds->sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT) 317 if (ds->sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
320 goto out; 318 goto out;
diff --git a/fs/xfs/scrub/attr.h b/fs/xfs/scrub/attr.h
new file mode 100644
index 000000000000..88bb5e29c60c
--- /dev/null
+++ b/fs/xfs/scrub/attr.h
@@ -0,0 +1,65 @@
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*
3 * Copyright (C) 2019 Oracle. All Rights Reserved.
4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
5 */
6#ifndef __XFS_SCRUB_ATTR_H__
7#define __XFS_SCRUB_ATTR_H__
8
9/*
10 * Temporary storage for online scrub and repair of extended attributes.
11 */
12struct xchk_xattr_buf {
13 /*
14 * Memory buffer -- either used for extracting attr values while
15 * walking the attributes; or for computing attr block bitmaps when
16 * checking the attribute tree.
17 *
18 * Each bitmap contains enough bits to track every byte in an attr
19 * block (rounded up to the size of an unsigned long). The attr block
20 * used space bitmap starts at the beginning of the buffer; the free
21 * space bitmap follows immediately after; and we have a third buffer
22 * for storing intermediate bitmap results.
23 */
24 uint8_t buf[0];
25};
26
27/* A place to store attribute values. */
28static inline uint8_t *
29xchk_xattr_valuebuf(
30 struct xfs_scrub *sc)
31{
32 struct xchk_xattr_buf *ab = sc->buf;
33
34 return ab->buf;
35}
36
37/* A bitmap of space usage computed by walking an attr leaf block. */
38static inline unsigned long *
39xchk_xattr_usedmap(
40 struct xfs_scrub *sc)
41{
42 struct xchk_xattr_buf *ab = sc->buf;
43
44 return (unsigned long *)ab->buf;
45}
46
47/* A bitmap of free space computed by walking attr leaf block free info. */
48static inline unsigned long *
49xchk_xattr_freemap(
50 struct xfs_scrub *sc)
51{
52 return xchk_xattr_usedmap(sc) +
53 BITS_TO_LONGS(sc->mp->m_attr_geo->blksize);
54}
55
56/* A bitmap used to hold temporary results. */
57static inline unsigned long *
58xchk_xattr_dstmap(
59 struct xfs_scrub *sc)
60{
61 return xchk_xattr_freemap(sc) +
62 BITS_TO_LONGS(sc->mp->m_attr_geo->blksize);
63}
64
65#endif /* __XFS_SCRUB_ATTR_H__ */