blob: dce74ec570389a21204e40ddd14d4e1f619bebf9 [file] [log] [blame]
Dave Chinner0b61f8a2018-06-05 19:42:14 -07001// SPDX-License-Identifier: GPL-2.0+
Darrick J. Wongeec04822017-10-17 21:37:45 -07002/*
3 * Copyright (C) 2017 Oracle. All Rights Reserved.
Darrick J. Wongeec04822017-10-17 21:37:45 -07004 * Author: Darrick J. Wong <darrick.wong@oracle.com>
Darrick J. Wongeec04822017-10-17 21:37:45 -07005 */
6#include "xfs.h"
7#include "xfs_fs.h"
8#include "xfs_shared.h"
9#include "xfs_format.h"
10#include "xfs_trans_resv.h"
11#include "xfs_mount.h"
12#include "xfs_defer.h"
13#include "xfs_btree.h"
14#include "xfs_bit.h"
15#include "xfs_log_format.h"
16#include "xfs_trans.h"
17#include "xfs_sb.h"
18#include "xfs_inode.h"
19#include "xfs_da_format.h"
20#include "xfs_da_btree.h"
21#include "xfs_dir2.h"
22#include "xfs_attr.h"
23#include "xfs_attr_leaf.h"
24#include "scrub/xfs_scrub.h"
25#include "scrub/scrub.h"
26#include "scrub/common.h"
27#include "scrub/dabtree.h"
28#include "scrub/trace.h"
29
30#include <linux/posix_acl_xattr.h>
31#include <linux/xattr.h>
32
33/* Set us up to scrub an inode's extended attributes. */
34int
Darrick J. Wongc517b3a2018-07-19 12:29:11 -070035xchk_setup_xattr(
Darrick J. Wong1d8a7482018-07-19 12:29:12 -070036 struct xfs_scrub *sc,
Darrick J. Wong032d91f2018-07-19 12:29:12 -070037 struct xfs_inode *ip)
Darrick J. Wongeec04822017-10-17 21:37:45 -070038{
Darrick J. Wong032d91f2018-07-19 12:29:12 -070039 size_t sz;
Darrick J. Wong13791d32017-10-31 12:10:02 -070040
41 /*
42 * Allocate the buffer without the inode lock held. We need enough
43 * space to read every xattr value in the file or enough space to
44 * hold three copies of the xattr free space bitmap. (Not both at
45 * the same time.)
46 */
47 sz = max_t(size_t, XATTR_SIZE_MAX, 3 * sizeof(long) *
48 BITS_TO_LONGS(sc->mp->m_attr_geo->blksize));
49 sc->buf = kmem_zalloc_large(sz, KM_SLEEP);
Darrick J. Wongeec04822017-10-17 21:37:45 -070050 if (!sc->buf)
51 return -ENOMEM;
52
Darrick J. Wongc517b3a2018-07-19 12:29:11 -070053 return xchk_setup_inode_contents(sc, ip, 0);
Darrick J. Wongeec04822017-10-17 21:37:45 -070054}
55
56/* Extended Attributes */
57
Darrick J. Wongc517b3a2018-07-19 12:29:11 -070058struct xchk_xattr {
Darrick J. Wongeec04822017-10-17 21:37:45 -070059 struct xfs_attr_list_context context;
Darrick J. Wong032d91f2018-07-19 12:29:12 -070060 struct xfs_scrub *sc;
Darrick J. Wongeec04822017-10-17 21:37:45 -070061};
62
63/*
64 * Check that an extended attribute key can be looked up by hash.
65 *
66 * We use the XFS attribute list iterator (i.e. xfs_attr_list_int_ilocked)
67 * to call this function for every attribute key in an inode. Once
68 * we're here, we load the attribute value to see if any errors happen,
69 * or if we get more or less data than we expected.
70 */
71static void
Darrick J. Wongc517b3a2018-07-19 12:29:11 -070072xchk_xattr_listent(
Darrick J. Wongeec04822017-10-17 21:37:45 -070073 struct xfs_attr_list_context *context,
74 int flags,
75 unsigned char *name,
76 int namelen,
77 int valuelen)
78{
Darrick J. Wongc517b3a2018-07-19 12:29:11 -070079 struct xchk_xattr *sx;
Christoph Hellwig88aa5de2017-11-06 11:53:58 -080080 struct xfs_da_args args = { NULL };
Darrick J. Wongeec04822017-10-17 21:37:45 -070081 int error = 0;
82
Darrick J. Wongc517b3a2018-07-19 12:29:11 -070083 sx = container_of(context, struct xchk_xattr, context);
Darrick J. Wongeec04822017-10-17 21:37:45 -070084
Darrick J. Wong3258cb22019-02-01 09:08:52 -080085 if (xchk_should_terminate(sx->sc, &error)) {
86 context->seen_enough = 1;
87 return;
88 }
89
Darrick J. Wongeec04822017-10-17 21:37:45 -070090 if (flags & XFS_ATTR_INCOMPLETE) {
91 /* Incomplete attr key, just mark the inode for preening. */
Darrick J. Wongc517b3a2018-07-19 12:29:11 -070092 xchk_ino_set_preen(sx->sc, context->dp->i_ino);
Darrick J. Wongeec04822017-10-17 21:37:45 -070093 return;
94 }
95
Darrick J. Wong65480532019-02-01 09:08:54 -080096 /* Does this name make sense? */
97 if (!xfs_attr_namecheck(name, namelen)) {
98 xchk_fblock_set_corrupt(sx->sc, XFS_ATTR_FORK, args.blkno);
99 return;
100 }
101
Darrick J. Wongeec04822017-10-17 21:37:45 -0700102 args.flags = ATTR_KERNOTIME;
103 if (flags & XFS_ATTR_ROOT)
104 args.flags |= ATTR_ROOT;
105 else if (flags & XFS_ATTR_SECURE)
106 args.flags |= ATTR_SECURE;
107 args.geo = context->dp->i_mount->m_attr_geo;
108 args.whichfork = XFS_ATTR_FORK;
109 args.dp = context->dp;
110 args.name = name;
111 args.namelen = namelen;
112 args.hashval = xfs_da_hashname(args.name, args.namelen);
113 args.trans = context->tp;
114 args.value = sx->sc->buf;
115 args.valuelen = XATTR_SIZE_MAX;
116
117 error = xfs_attr_get_ilocked(context->dp, &args);
118 if (error == -EEXIST)
119 error = 0;
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700120 if (!xchk_fblock_process_error(sx->sc, XFS_ATTR_FORK, args.blkno,
Darrick J. Wongeec04822017-10-17 21:37:45 -0700121 &error))
122 goto fail_xref;
123 if (args.valuelen != valuelen)
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700124 xchk_fblock_set_corrupt(sx->sc, XFS_ATTR_FORK,
Darrick J. Wongeec04822017-10-17 21:37:45 -0700125 args.blkno);
Darrick J. Wongeec04822017-10-17 21:37:45 -0700126fail_xref:
Darrick J. Wong8bc763c2018-05-14 06:34:32 -0700127 if (sx->sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
128 context->seen_enough = 1;
Darrick J. Wongeec04822017-10-17 21:37:45 -0700129 return;
130}
131
Darrick J. Wong13791d32017-10-31 12:10:02 -0700132/*
133 * Mark a range [start, start+len) in this map. Returns true if the
134 * region was free, and false if there's a conflict or a problem.
135 *
136 * Within a char, the lowest bit of the char represents the byte with
137 * the smallest address
138 */
139STATIC bool
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700140xchk_xattr_set_map(
Darrick J. Wong1d8a7482018-07-19 12:29:12 -0700141 struct xfs_scrub *sc,
Darrick J. Wong032d91f2018-07-19 12:29:12 -0700142 unsigned long *map,
143 unsigned int start,
144 unsigned int len)
Darrick J. Wong13791d32017-10-31 12:10:02 -0700145{
Darrick J. Wong032d91f2018-07-19 12:29:12 -0700146 unsigned int mapsize = sc->mp->m_attr_geo->blksize;
147 bool ret = true;
Darrick J. Wong13791d32017-10-31 12:10:02 -0700148
149 if (start >= mapsize)
150 return false;
151 if (start + len > mapsize) {
152 len = mapsize - start;
153 ret = false;
154 }
155
156 if (find_next_bit(map, mapsize, start) < start + len)
157 ret = false;
158 bitmap_set(map, start, len);
159
160 return ret;
161}
162
163/*
164 * Check the leaf freemap from the usage bitmap. Returns false if the
165 * attr freemap has problems or points to used space.
166 */
167STATIC bool
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700168xchk_xattr_check_freemap(
Darrick J. Wong032d91f2018-07-19 12:29:12 -0700169 struct xfs_scrub *sc,
Darrick J. Wong13791d32017-10-31 12:10:02 -0700170 unsigned long *map,
171 struct xfs_attr3_icleaf_hdr *leafhdr)
172{
173 unsigned long *freemap;
174 unsigned long *dstmap;
175 unsigned int mapsize = sc->mp->m_attr_geo->blksize;
176 int i;
177
178 /* Construct bitmap of freemap contents. */
179 freemap = (unsigned long *)sc->buf + BITS_TO_LONGS(mapsize);
180 bitmap_zero(freemap, mapsize);
181 for (i = 0; i < XFS_ATTR_LEAF_MAPSIZE; i++) {
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700182 if (!xchk_xattr_set_map(sc, freemap,
Darrick J. Wong13791d32017-10-31 12:10:02 -0700183 leafhdr->freemap[i].base,
184 leafhdr->freemap[i].size))
185 return false;
186 }
187
188 /* Look for bits that are set in freemap and are marked in use. */
189 dstmap = freemap + BITS_TO_LONGS(mapsize);
190 return bitmap_and(dstmap, freemap, map, mapsize) == 0;
191}
192
193/*
194 * Check this leaf entry's relations to everything else.
195 * Returns the number of bytes used for the name/value data.
196 */
197STATIC void
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700198xchk_xattr_entry(
199 struct xchk_da_btree *ds,
Darrick J. Wong13791d32017-10-31 12:10:02 -0700200 int level,
201 char *buf_end,
202 struct xfs_attr_leafblock *leaf,
203 struct xfs_attr3_icleaf_hdr *leafhdr,
204 unsigned long *usedmap,
205 struct xfs_attr_leaf_entry *ent,
206 int idx,
207 unsigned int *usedbytes,
208 __u32 *last_hashval)
209{
210 struct xfs_mount *mp = ds->state->mp;
211 char *name_end;
212 struct xfs_attr_leaf_name_local *lentry;
213 struct xfs_attr_leaf_name_remote *rentry;
214 unsigned int nameidx;
215 unsigned int namesize;
216
217 if (ent->pad2 != 0)
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700218 xchk_da_set_corrupt(ds, level);
Darrick J. Wong13791d32017-10-31 12:10:02 -0700219
220 /* Hash values in order? */
221 if (be32_to_cpu(ent->hashval) < *last_hashval)
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700222 xchk_da_set_corrupt(ds, level);
Darrick J. Wong13791d32017-10-31 12:10:02 -0700223 *last_hashval = be32_to_cpu(ent->hashval);
224
225 nameidx = be16_to_cpu(ent->nameidx);
226 if (nameidx < leafhdr->firstused ||
227 nameidx >= mp->m_attr_geo->blksize) {
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700228 xchk_da_set_corrupt(ds, level);
Darrick J. Wong13791d32017-10-31 12:10:02 -0700229 return;
230 }
231
232 /* Check the name information. */
233 if (ent->flags & XFS_ATTR_LOCAL) {
234 lentry = xfs_attr3_leaf_name_local(leaf, idx);
235 namesize = xfs_attr_leaf_entsize_local(lentry->namelen,
236 be16_to_cpu(lentry->valuelen));
237 name_end = (char *)lentry + namesize;
238 if (lentry->namelen == 0)
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700239 xchk_da_set_corrupt(ds, level);
Darrick J. Wong13791d32017-10-31 12:10:02 -0700240 } else {
241 rentry = xfs_attr3_leaf_name_remote(leaf, idx);
242 namesize = xfs_attr_leaf_entsize_remote(rentry->namelen);
243 name_end = (char *)rentry + namesize;
244 if (rentry->namelen == 0 || rentry->valueblk == 0)
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700245 xchk_da_set_corrupt(ds, level);
Darrick J. Wong13791d32017-10-31 12:10:02 -0700246 }
247 if (name_end > buf_end)
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700248 xchk_da_set_corrupt(ds, level);
Darrick J. Wong13791d32017-10-31 12:10:02 -0700249
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700250 if (!xchk_xattr_set_map(ds->sc, usedmap, nameidx, namesize))
251 xchk_da_set_corrupt(ds, level);
Darrick J. Wong13791d32017-10-31 12:10:02 -0700252 if (!(ds->sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT))
253 *usedbytes += namesize;
254}
255
256/* Scrub an attribute leaf. */
257STATIC int
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700258xchk_xattr_block(
259 struct xchk_da_btree *ds,
Darrick J. Wong13791d32017-10-31 12:10:02 -0700260 int level)
261{
262 struct xfs_attr3_icleaf_hdr leafhdr;
263 struct xfs_mount *mp = ds->state->mp;
264 struct xfs_da_state_blk *blk = &ds->state->path.blk[level];
265 struct xfs_buf *bp = blk->bp;
266 xfs_dablk_t *last_checked = ds->private;
267 struct xfs_attr_leafblock *leaf = bp->b_addr;
268 struct xfs_attr_leaf_entry *ent;
269 struct xfs_attr_leaf_entry *entries;
270 unsigned long *usedmap = ds->sc->buf;
271 char *buf_end;
272 size_t off;
273 __u32 last_hashval = 0;
274 unsigned int usedbytes = 0;
275 unsigned int hdrsize;
276 int i;
277
278 if (*last_checked == blk->blkno)
279 return 0;
280 *last_checked = blk->blkno;
281 bitmap_zero(usedmap, mp->m_attr_geo->blksize);
282
283 /* Check all the padding. */
284 if (xfs_sb_version_hascrc(&ds->sc->mp->m_sb)) {
285 struct xfs_attr3_leafblock *leaf = bp->b_addr;
286
287 if (leaf->hdr.pad1 != 0 || leaf->hdr.pad2 != 0 ||
288 leaf->hdr.info.hdr.pad != 0)
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700289 xchk_da_set_corrupt(ds, level);
Darrick J. Wong13791d32017-10-31 12:10:02 -0700290 } else {
291 if (leaf->hdr.pad1 != 0 || leaf->hdr.info.pad != 0)
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700292 xchk_da_set_corrupt(ds, level);
Darrick J. Wong13791d32017-10-31 12:10:02 -0700293 }
294
295 /* Check the leaf header */
296 xfs_attr3_leaf_hdr_from_disk(mp->m_attr_geo, &leafhdr, leaf);
297 hdrsize = xfs_attr3_leaf_hdr_size(leaf);
298
299 if (leafhdr.usedbytes > mp->m_attr_geo->blksize)
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700300 xchk_da_set_corrupt(ds, level);
Darrick J. Wong13791d32017-10-31 12:10:02 -0700301 if (leafhdr.firstused > mp->m_attr_geo->blksize)
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700302 xchk_da_set_corrupt(ds, level);
Darrick J. Wong13791d32017-10-31 12:10:02 -0700303 if (leafhdr.firstused < hdrsize)
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700304 xchk_da_set_corrupt(ds, level);
305 if (!xchk_xattr_set_map(ds->sc, usedmap, 0, hdrsize))
306 xchk_da_set_corrupt(ds, level);
Darrick J. Wong13791d32017-10-31 12:10:02 -0700307
308 if (ds->sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
309 goto out;
310
311 entries = xfs_attr3_leaf_entryp(leaf);
312 if ((char *)&entries[leafhdr.count] > (char *)leaf + leafhdr.firstused)
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700313 xchk_da_set_corrupt(ds, level);
Darrick J. Wong13791d32017-10-31 12:10:02 -0700314
315 buf_end = (char *)bp->b_addr + mp->m_attr_geo->blksize;
316 for (i = 0, ent = entries; i < leafhdr.count; ent++, i++) {
317 /* Mark the leaf entry itself. */
318 off = (char *)ent - (char *)leaf;
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700319 if (!xchk_xattr_set_map(ds->sc, usedmap, off,
Darrick J. Wong13791d32017-10-31 12:10:02 -0700320 sizeof(xfs_attr_leaf_entry_t))) {
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700321 xchk_da_set_corrupt(ds, level);
Darrick J. Wong13791d32017-10-31 12:10:02 -0700322 goto out;
323 }
324
325 /* Check the entry and nameval. */
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700326 xchk_xattr_entry(ds, level, buf_end, leaf, &leafhdr,
Darrick J. Wong13791d32017-10-31 12:10:02 -0700327 usedmap, ent, i, &usedbytes, &last_hashval);
328
329 if (ds->sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
330 goto out;
331 }
332
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700333 if (!xchk_xattr_check_freemap(ds->sc, usedmap, &leafhdr))
334 xchk_da_set_corrupt(ds, level);
Darrick J. Wong13791d32017-10-31 12:10:02 -0700335
336 if (leafhdr.usedbytes != usedbytes)
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700337 xchk_da_set_corrupt(ds, level);
Darrick J. Wong13791d32017-10-31 12:10:02 -0700338
339out:
340 return 0;
341}
342
Darrick J. Wongeec04822017-10-17 21:37:45 -0700343/* Scrub a attribute btree record. */
344STATIC int
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700345xchk_xattr_rec(
346 struct xchk_da_btree *ds,
Darrick J. Wongeec04822017-10-17 21:37:45 -0700347 int level,
348 void *rec)
349{
350 struct xfs_mount *mp = ds->state->mp;
351 struct xfs_attr_leaf_entry *ent = rec;
352 struct xfs_da_state_blk *blk;
353 struct xfs_attr_leaf_name_local *lentry;
354 struct xfs_attr_leaf_name_remote *rentry;
355 struct xfs_buf *bp;
356 xfs_dahash_t calc_hash;
357 xfs_dahash_t hash;
358 int nameidx;
359 int hdrsize;
360 unsigned int badflags;
361 int error;
362
363 blk = &ds->state->path.blk[level];
364
Darrick J. Wong13791d32017-10-31 12:10:02 -0700365 /* Check the whole block, if necessary. */
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700366 error = xchk_xattr_block(ds, level);
Darrick J. Wong13791d32017-10-31 12:10:02 -0700367 if (error)
368 goto out;
369 if (ds->sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
370 goto out;
371
Darrick J. Wongeec04822017-10-17 21:37:45 -0700372 /* Check the hash of the entry. */
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700373 error = xchk_da_btree_hash(ds, level, &ent->hashval);
Darrick J. Wongeec04822017-10-17 21:37:45 -0700374 if (error)
375 goto out;
376
377 /* Find the attr entry's location. */
378 bp = blk->bp;
379 hdrsize = xfs_attr3_leaf_hdr_size(bp->b_addr);
380 nameidx = be16_to_cpu(ent->nameidx);
381 if (nameidx < hdrsize || nameidx >= mp->m_attr_geo->blksize) {
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700382 xchk_da_set_corrupt(ds, level);
Darrick J. Wongeec04822017-10-17 21:37:45 -0700383 goto out;
384 }
385
Darrick J. Wongeec04822017-10-17 21:37:45 -0700386 /* Retrieve the entry and check it. */
387 hash = be32_to_cpu(ent->hashval);
388 badflags = ~(XFS_ATTR_LOCAL | XFS_ATTR_ROOT | XFS_ATTR_SECURE |
389 XFS_ATTR_INCOMPLETE);
390 if ((ent->flags & badflags) != 0)
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700391 xchk_da_set_corrupt(ds, level);
Darrick J. Wongeec04822017-10-17 21:37:45 -0700392 if (ent->flags & XFS_ATTR_LOCAL) {
393 lentry = (struct xfs_attr_leaf_name_local *)
394 (((char *)bp->b_addr) + nameidx);
395 if (lentry->namelen <= 0) {
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700396 xchk_da_set_corrupt(ds, level);
Darrick J. Wongeec04822017-10-17 21:37:45 -0700397 goto out;
398 }
399 calc_hash = xfs_da_hashname(lentry->nameval, lentry->namelen);
400 } else {
401 rentry = (struct xfs_attr_leaf_name_remote *)
402 (((char *)bp->b_addr) + nameidx);
403 if (rentry->namelen <= 0) {
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700404 xchk_da_set_corrupt(ds, level);
Darrick J. Wongeec04822017-10-17 21:37:45 -0700405 goto out;
406 }
407 calc_hash = xfs_da_hashname(rentry->name, rentry->namelen);
408 }
409 if (calc_hash != hash)
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700410 xchk_da_set_corrupt(ds, level);
Darrick J. Wongeec04822017-10-17 21:37:45 -0700411
412out:
413 return error;
414}
415
416/* Scrub the extended attribute metadata. */
417int
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700418xchk_xattr(
Darrick J. Wong032d91f2018-07-19 12:29:12 -0700419 struct xfs_scrub *sc)
Darrick J. Wongeec04822017-10-17 21:37:45 -0700420{
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700421 struct xchk_xattr sx;
Darrick J. Wongeec04822017-10-17 21:37:45 -0700422 struct attrlist_cursor_kern cursor = { 0 };
Darrick J. Wong13791d32017-10-31 12:10:02 -0700423 xfs_dablk_t last_checked = -1U;
Darrick J. Wongeec04822017-10-17 21:37:45 -0700424 int error = 0;
425
426 if (!xfs_inode_hasattr(sc->ip))
427 return -ENOENT;
428
429 memset(&sx, 0, sizeof(sx));
430 /* Check attribute tree structure */
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700431 error = xchk_da_btree(sc, XFS_ATTR_FORK, xchk_xattr_rec,
Darrick J. Wong13791d32017-10-31 12:10:02 -0700432 &last_checked);
Darrick J. Wongeec04822017-10-17 21:37:45 -0700433 if (error)
434 goto out;
435
436 if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
437 goto out;
438
439 /* Check that every attr key can also be looked up by hash. */
440 sx.context.dp = sc->ip;
441 sx.context.cursor = &cursor;
442 sx.context.resynch = 1;
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700443 sx.context.put_listent = xchk_xattr_listent;
Darrick J. Wongeec04822017-10-17 21:37:45 -0700444 sx.context.tp = sc->tp;
445 sx.context.flags = ATTR_INCOMPLETE;
446 sx.sc = sc;
447
448 /*
449 * Look up every xattr in this file by name.
450 *
451 * Use the backend implementation of xfs_attr_list to call
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700452 * xchk_xattr_listent on every attribute key in this inode.
Darrick J. Wongeec04822017-10-17 21:37:45 -0700453 * In other words, we use the same iterator/callback mechanism
454 * that listattr uses to scrub extended attributes, though in our
455 * _listent function, we check the value of the attribute.
456 *
457 * The VFS only locks i_rwsem when modifying attrs, so keep all
458 * three locks held because that's the only way to ensure we're
459 * the only thread poking into the da btree. We traverse the da
460 * btree while holding a leaf buffer locked for the xattr name
461 * iteration, which doesn't really follow the usual buffer
462 * locking order.
463 */
464 error = xfs_attr_list_int_ilocked(&sx.context);
Darrick J. Wongc517b3a2018-07-19 12:29:11 -0700465 if (!xchk_fblock_process_error(sc, XFS_ATTR_FORK, 0, &error))
Darrick J. Wongeec04822017-10-17 21:37:45 -0700466 goto out;
467out:
468 return error;
469}