18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2019 Oracle. All Rights Reserved. 48c2ecf20Sopenharmony_ci * Author: Darrick J. Wong <darrick.wong@oracle.com> 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci#ifndef __XFS_SCRUB_ATTR_H__ 78c2ecf20Sopenharmony_ci#define __XFS_SCRUB_ATTR_H__ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci/* 108c2ecf20Sopenharmony_ci * Temporary storage for online scrub and repair of extended attributes. 118c2ecf20Sopenharmony_ci */ 128c2ecf20Sopenharmony_cistruct xchk_xattr_buf { 138c2ecf20Sopenharmony_ci /* Size of @buf, in bytes. */ 148c2ecf20Sopenharmony_ci size_t sz; 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci /* 178c2ecf20Sopenharmony_ci * Memory buffer -- either used for extracting attr values while 188c2ecf20Sopenharmony_ci * walking the attributes; or for computing attr block bitmaps when 198c2ecf20Sopenharmony_ci * checking the attribute tree. 208c2ecf20Sopenharmony_ci * 218c2ecf20Sopenharmony_ci * Each bitmap contains enough bits to track every byte in an attr 228c2ecf20Sopenharmony_ci * block (rounded up to the size of an unsigned long). The attr block 238c2ecf20Sopenharmony_ci * used space bitmap starts at the beginning of the buffer; the free 248c2ecf20Sopenharmony_ci * space bitmap follows immediately after; and we have a third buffer 258c2ecf20Sopenharmony_ci * for storing intermediate bitmap results. 268c2ecf20Sopenharmony_ci */ 278c2ecf20Sopenharmony_ci uint8_t buf[0]; 288c2ecf20Sopenharmony_ci}; 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci/* A place to store attribute values. */ 318c2ecf20Sopenharmony_cistatic inline uint8_t * 328c2ecf20Sopenharmony_cixchk_xattr_valuebuf( 338c2ecf20Sopenharmony_ci struct xfs_scrub *sc) 348c2ecf20Sopenharmony_ci{ 358c2ecf20Sopenharmony_ci struct xchk_xattr_buf *ab = sc->buf; 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci return ab->buf; 388c2ecf20Sopenharmony_ci} 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci/* A bitmap of space usage computed by walking an attr leaf block. */ 418c2ecf20Sopenharmony_cistatic inline unsigned long * 428c2ecf20Sopenharmony_cixchk_xattr_usedmap( 438c2ecf20Sopenharmony_ci struct xfs_scrub *sc) 448c2ecf20Sopenharmony_ci{ 458c2ecf20Sopenharmony_ci struct xchk_xattr_buf *ab = sc->buf; 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci return (unsigned long *)ab->buf; 488c2ecf20Sopenharmony_ci} 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci/* A bitmap of free space computed by walking attr leaf block free info. */ 518c2ecf20Sopenharmony_cistatic inline unsigned long * 528c2ecf20Sopenharmony_cixchk_xattr_freemap( 538c2ecf20Sopenharmony_ci struct xfs_scrub *sc) 548c2ecf20Sopenharmony_ci{ 558c2ecf20Sopenharmony_ci return xchk_xattr_usedmap(sc) + 568c2ecf20Sopenharmony_ci BITS_TO_LONGS(sc->mp->m_attr_geo->blksize); 578c2ecf20Sopenharmony_ci} 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci/* A bitmap used to hold temporary results. */ 608c2ecf20Sopenharmony_cistatic inline unsigned long * 618c2ecf20Sopenharmony_cixchk_xattr_dstmap( 628c2ecf20Sopenharmony_ci struct xfs_scrub *sc) 638c2ecf20Sopenharmony_ci{ 648c2ecf20Sopenharmony_ci return xchk_xattr_freemap(sc) + 658c2ecf20Sopenharmony_ci BITS_TO_LONGS(sc->mp->m_attr_geo->blksize); 668c2ecf20Sopenharmony_ci} 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ciint xchk_setup_xattr_buf(struct xfs_scrub *sc, size_t value_size, 698c2ecf20Sopenharmony_ci xfs_km_flags_t flags); 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci#endif /* __XFS_SCRUB_ATTR_H__ */ 72