xref: /OK3568_Linux_fs/kernel/fs/xfs/scrub/attr.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-or-later */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright (C) 2019 Oracle.  All Rights Reserved.
4*4882a593Smuzhiyun  * Author: Darrick J. Wong <darrick.wong@oracle.com>
5*4882a593Smuzhiyun  */
6*4882a593Smuzhiyun #ifndef __XFS_SCRUB_ATTR_H__
7*4882a593Smuzhiyun #define __XFS_SCRUB_ATTR_H__
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun /*
10*4882a593Smuzhiyun  * Temporary storage for online scrub and repair of extended attributes.
11*4882a593Smuzhiyun  */
12*4882a593Smuzhiyun struct xchk_xattr_buf {
13*4882a593Smuzhiyun 	/* Size of @buf, in bytes. */
14*4882a593Smuzhiyun 	size_t			sz;
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun 	/*
17*4882a593Smuzhiyun 	 * Memory buffer -- either used for extracting attr values while
18*4882a593Smuzhiyun 	 * walking the attributes; or for computing attr block bitmaps when
19*4882a593Smuzhiyun 	 * checking the attribute tree.
20*4882a593Smuzhiyun 	 *
21*4882a593Smuzhiyun 	 * Each bitmap contains enough bits to track every byte in an attr
22*4882a593Smuzhiyun 	 * block (rounded up to the size of an unsigned long).  The attr block
23*4882a593Smuzhiyun 	 * used space bitmap starts at the beginning of the buffer; the free
24*4882a593Smuzhiyun 	 * space bitmap follows immediately after; and we have a third buffer
25*4882a593Smuzhiyun 	 * for storing intermediate bitmap results.
26*4882a593Smuzhiyun 	 */
27*4882a593Smuzhiyun 	uint8_t			buf[0];
28*4882a593Smuzhiyun };
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun /* A place to store attribute values. */
31*4882a593Smuzhiyun static inline uint8_t *
xchk_xattr_valuebuf(struct xfs_scrub * sc)32*4882a593Smuzhiyun xchk_xattr_valuebuf(
33*4882a593Smuzhiyun 	struct xfs_scrub	*sc)
34*4882a593Smuzhiyun {
35*4882a593Smuzhiyun 	struct xchk_xattr_buf	*ab = sc->buf;
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun 	return ab->buf;
38*4882a593Smuzhiyun }
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun /* A bitmap of space usage computed by walking an attr leaf block. */
41*4882a593Smuzhiyun static inline unsigned long *
xchk_xattr_usedmap(struct xfs_scrub * sc)42*4882a593Smuzhiyun xchk_xattr_usedmap(
43*4882a593Smuzhiyun 	struct xfs_scrub	*sc)
44*4882a593Smuzhiyun {
45*4882a593Smuzhiyun 	struct xchk_xattr_buf	*ab = sc->buf;
46*4882a593Smuzhiyun 
47*4882a593Smuzhiyun 	return (unsigned long *)ab->buf;
48*4882a593Smuzhiyun }
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun /* A bitmap of free space computed by walking attr leaf block free info. */
51*4882a593Smuzhiyun static inline unsigned long *
xchk_xattr_freemap(struct xfs_scrub * sc)52*4882a593Smuzhiyun xchk_xattr_freemap(
53*4882a593Smuzhiyun 	struct xfs_scrub	*sc)
54*4882a593Smuzhiyun {
55*4882a593Smuzhiyun 	return xchk_xattr_usedmap(sc) +
56*4882a593Smuzhiyun 			BITS_TO_LONGS(sc->mp->m_attr_geo->blksize);
57*4882a593Smuzhiyun }
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun /* A bitmap used to hold temporary results. */
60*4882a593Smuzhiyun static inline unsigned long *
xchk_xattr_dstmap(struct xfs_scrub * sc)61*4882a593Smuzhiyun xchk_xattr_dstmap(
62*4882a593Smuzhiyun 	struct xfs_scrub	*sc)
63*4882a593Smuzhiyun {
64*4882a593Smuzhiyun 	return xchk_xattr_freemap(sc) +
65*4882a593Smuzhiyun 			BITS_TO_LONGS(sc->mp->m_attr_geo->blksize);
66*4882a593Smuzhiyun }
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun int xchk_setup_xattr_buf(struct xfs_scrub *sc, size_t value_size,
69*4882a593Smuzhiyun 		xfs_km_flags_t flags);
70*4882a593Smuzhiyun 
71*4882a593Smuzhiyun #endif	/* __XFS_SCRUB_ATTR_H__ */
72