Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include "xfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include "xfs_fs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include "xfs_shared.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include "xfs_format.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include "xfs_log_format.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include "xfs_trans_resv.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include "xfs_mount.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include "xfs_inode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "xfs_btree.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "xfs_ialloc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "xfs_ialloc_btree.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "xfs_iwalk.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "xfs_itable.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "xfs_error.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include "xfs_icache.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include "xfs_health.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * Bulk Stat
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * =========
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * Use the inode walking functions to fill out struct xfs_bulkstat for every
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * allocated inode, then pass the stat information to some externally provided
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * iteration function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) struct xfs_bstat_chunk {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	bulkstat_one_fmt_pf	formatter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	struct xfs_ibulk	*breq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	struct xfs_bulkstat	*buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  * Fill out the bulkstat info for a single inode and report it somewhere.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  * bc->breq->lastino is effectively the inode cursor as we walk through the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  * filesystem.  Therefore, we update it any time we need to move the cursor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  * forward, regardless of whether or not we're sending any bstat information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  * back to userspace.  If the inode is internal metadata or, has been freed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  * out from under us, we just simply keep going.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * However, if any other type of error happens we want to stop right where we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * are so that userspace will call back with exact number of the bad inode and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * we can send back an error code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  * Note that if the formatter tells us there's no space left in the buffer we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  * move the cursor forward and abort the walk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) STATIC int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) xfs_bulkstat_one_int(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	struct xfs_mount	*mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	struct xfs_trans	*tp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	xfs_ino_t		ino,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	struct xfs_bstat_chunk	*bc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	struct xfs_icdinode	*dic;		/* dinode core info pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	struct xfs_inode	*ip;		/* incore inode pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	struct inode		*inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	struct xfs_bulkstat	*buf = bc->buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	int			error = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	if (xfs_internal_inum(mp, ino))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		goto out_advance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	error = xfs_iget(mp, tp, ino,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 			 (XFS_IGET_DONTCACHE | XFS_IGET_UNTRUSTED),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 			 XFS_ILOCK_SHARED, &ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	if (error == -ENOENT || error == -EINVAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		goto out_advance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	ASSERT(ip != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	ASSERT(ip->i_imap.im_blkno != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	inode = VFS_I(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	dic = &ip->i_d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	/* xfs_iget returns the following without needing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	 * further change.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	buf->bs_projectid = ip->i_d.di_projid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	buf->bs_ino = ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	buf->bs_uid = i_uid_read(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	buf->bs_gid = i_gid_read(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	buf->bs_size = dic->di_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	buf->bs_nlink = inode->i_nlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	buf->bs_atime = inode->i_atime.tv_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	buf->bs_atime_nsec = inode->i_atime.tv_nsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	buf->bs_mtime = inode->i_mtime.tv_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	buf->bs_mtime_nsec = inode->i_mtime.tv_nsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	buf->bs_ctime = inode->i_ctime.tv_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	buf->bs_ctime_nsec = inode->i_ctime.tv_nsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	buf->bs_btime = dic->di_crtime.tv_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	buf->bs_btime_nsec = dic->di_crtime.tv_nsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	buf->bs_gen = inode->i_generation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	buf->bs_mode = inode->i_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	buf->bs_xflags = xfs_ip2xflags(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	buf->bs_extsize_blks = dic->di_extsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	buf->bs_extents = xfs_ifork_nextents(&ip->i_df);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	xfs_bulkstat_health(ip, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	buf->bs_aextents = xfs_ifork_nextents(ip->i_afp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	buf->bs_forkoff = XFS_IFORK_BOFF(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	buf->bs_version = XFS_BULKSTAT_VERSION_V5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	if (xfs_sb_version_has_v3inode(&mp->m_sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		if (dic->di_flags2 & XFS_DIFLAG2_COWEXTSIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 			buf->bs_cowextsize_blks = dic->di_cowextsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	switch (ip->i_df.if_format) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	case XFS_DINODE_FMT_DEV:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		buf->bs_rdev = sysv_encode_dev(inode->i_rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		buf->bs_blksize = BLKDEV_IOSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		buf->bs_blocks = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	case XFS_DINODE_FMT_LOCAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		buf->bs_rdev = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		buf->bs_blksize = mp->m_sb.sb_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		buf->bs_blocks = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	case XFS_DINODE_FMT_EXTENTS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	case XFS_DINODE_FMT_BTREE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		buf->bs_rdev = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		buf->bs_blksize = mp->m_sb.sb_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		buf->bs_blocks = dic->di_nblocks + ip->i_delayed_blks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	xfs_iunlock(ip, XFS_ILOCK_SHARED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	xfs_irele(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	error = bc->formatter(bc->breq, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	if (error == -ECANCELED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		goto out_advance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) out_advance:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	 * Advance the cursor to the inode that comes after the one we just
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	 * looked at.  We want the caller to move along if the bulkstat
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	 * information was copied successfully; if we tried to grab the inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	 * but it's no longer allocated; or if it's internal metadata.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	bc->breq->startino = ino + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) /* Bulkstat a single inode. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) xfs_bulkstat_one(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	struct xfs_ibulk	*breq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	bulkstat_one_fmt_pf	formatter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	struct xfs_bstat_chunk	bc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		.formatter	= formatter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		.breq		= breq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	int			error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	ASSERT(breq->icount == 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	bc.buf = kmem_zalloc(sizeof(struct xfs_bulkstat),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 			KM_MAYFAIL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	if (!bc.buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	error = xfs_bulkstat_one_int(breq->mp, NULL, breq->startino, &bc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	kmem_free(bc.buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	 * If we reported one inode to userspace then we abort because we hit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	 * the end of the buffer.  Don't leak that back to userspace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	if (error == -ECANCELED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) xfs_bulkstat_iwalk(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	struct xfs_mount	*mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	struct xfs_trans	*tp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	xfs_ino_t		ino,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	void			*data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	int			error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	error = xfs_bulkstat_one_int(mp, tp, ino, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	/* bulkstat just skips over missing inodes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	if (error == -ENOENT || error == -EINVAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)  * Check the incoming lastino parameter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)  * We allow any inode value that could map to physical space inside the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)  * filesystem because if there are no inodes there, bulkstat moves on to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)  * next chunk.  In other words, the magic agino value of zero takes us to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)  * first chunk in the AG, and an agino value past the end of the AG takes us to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)  * the first chunk in the next AG.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)  * Therefore we can end early if the requested inode is beyond the end of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)  * filesystem or doesn't map properly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) static inline bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) xfs_bulkstat_already_done(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	struct xfs_mount	*mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	xfs_ino_t		startino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	xfs_agnumber_t		agno = XFS_INO_TO_AGNO(mp, startino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	xfs_agino_t		agino = XFS_INO_TO_AGINO(mp, startino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	return agno >= mp->m_sb.sb_agcount ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	       startino != XFS_AGINO_TO_INO(mp, agno, agino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) /* Return stat information in bulk (by-inode) for the filesystem. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) xfs_bulkstat(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	struct xfs_ibulk	*breq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	bulkstat_one_fmt_pf	formatter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	struct xfs_bstat_chunk	bc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		.formatter	= formatter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		.breq		= breq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	int			error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	if (xfs_bulkstat_already_done(breq->mp, breq->startino))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	bc.buf = kmem_zalloc(sizeof(struct xfs_bulkstat),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 			KM_MAYFAIL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	if (!bc.buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	error = xfs_iwalk(breq->mp, NULL, breq->startino, breq->flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 			xfs_bulkstat_iwalk, breq->icount, &bc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	kmem_free(bc.buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	 * We found some inodes, so clear the error status and return them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	 * The lastino pointer will point directly at the inode that triggered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	 * any error that occurred, so on the next call the error will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	 * triggered again and propagated to userspace as there will be no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	 * formatted inodes in the buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	if (breq->ocount > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) /* Convert bulkstat (v5) to bstat (v1). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) xfs_bulkstat_to_bstat(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	struct xfs_mount		*mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	struct xfs_bstat		*bs1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	const struct xfs_bulkstat	*bstat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	/* memset is needed here because of padding holes in the structure. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	memset(bs1, 0, sizeof(struct xfs_bstat));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	bs1->bs_ino = bstat->bs_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	bs1->bs_mode = bstat->bs_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	bs1->bs_nlink = bstat->bs_nlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	bs1->bs_uid = bstat->bs_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	bs1->bs_gid = bstat->bs_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	bs1->bs_rdev = bstat->bs_rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	bs1->bs_blksize = bstat->bs_blksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	bs1->bs_size = bstat->bs_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	bs1->bs_atime.tv_sec = bstat->bs_atime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	bs1->bs_mtime.tv_sec = bstat->bs_mtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	bs1->bs_ctime.tv_sec = bstat->bs_ctime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	bs1->bs_atime.tv_nsec = bstat->bs_atime_nsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	bs1->bs_mtime.tv_nsec = bstat->bs_mtime_nsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	bs1->bs_ctime.tv_nsec = bstat->bs_ctime_nsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	bs1->bs_blocks = bstat->bs_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	bs1->bs_xflags = bstat->bs_xflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	bs1->bs_extsize = XFS_FSB_TO_B(mp, bstat->bs_extsize_blks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	bs1->bs_extents = bstat->bs_extents;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	bs1->bs_gen = bstat->bs_gen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	bs1->bs_projid_lo = bstat->bs_projectid & 0xFFFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	bs1->bs_forkoff = bstat->bs_forkoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	bs1->bs_projid_hi = bstat->bs_projectid >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	bs1->bs_sick = bstat->bs_sick;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	bs1->bs_checked = bstat->bs_checked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	bs1->bs_cowextsize = XFS_FSB_TO_B(mp, bstat->bs_cowextsize_blks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	bs1->bs_dmevmask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	bs1->bs_dmstate = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	bs1->bs_aextents = bstat->bs_aextents;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) struct xfs_inumbers_chunk {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	inumbers_fmt_pf		formatter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	struct xfs_ibulk	*breq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)  * INUMBERS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)  * ========
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)  * This is how we export inode btree records to userspace, so that XFS tools
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)  * can figure out where inodes are allocated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)  * Format the inode group structure and report it somewhere.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)  * Similar to xfs_bulkstat_one_int, lastino is the inode cursor as we walk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)  * through the filesystem so we move it forward unless there was a runtime
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)  * error.  If the formatter tells us the buffer is now full we also move the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)  * cursor forward and abort the walk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) STATIC int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) xfs_inumbers_walk(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	struct xfs_mount	*mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	struct xfs_trans	*tp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	xfs_agnumber_t		agno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	const struct xfs_inobt_rec_incore *irec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	void			*data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	struct xfs_inumbers	inogrp = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		.xi_startino	= XFS_AGINO_TO_INO(mp, agno, irec->ir_startino),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		.xi_alloccount	= irec->ir_count - irec->ir_freecount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		.xi_allocmask	= ~irec->ir_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		.xi_version	= XFS_INUMBERS_VERSION_V5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	struct xfs_inumbers_chunk *ic = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	int			error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	error = ic->formatter(ic->breq, &inogrp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	if (error && error != -ECANCELED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	ic->breq->startino = XFS_AGINO_TO_INO(mp, agno, irec->ir_startino) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 			XFS_INODES_PER_CHUNK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)  * Return inode number table for the filesystem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) xfs_inumbers(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	struct xfs_ibulk	*breq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	inumbers_fmt_pf		formatter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	struct xfs_inumbers_chunk ic = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		.formatter	= formatter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		.breq		= breq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	int			error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	if (xfs_bulkstat_already_done(breq->mp, breq->startino))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	error = xfs_inobt_walk(breq->mp, NULL, breq->startino, breq->flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 			xfs_inumbers_walk, breq->icount, &ic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	 * We found some inode groups, so clear the error status and return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	 * them.  The lastino pointer will point directly at the inode that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	 * triggered any error that occurred, so on the next call the error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	 * will be triggered again and propagated to userspace as there will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	 * no formatted inode groups in the buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	if (breq->ocount > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) /* Convert an inumbers (v5) struct to a inogrp (v1) struct. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) xfs_inumbers_to_inogrp(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	struct xfs_inogrp		*ig1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	const struct xfs_inumbers	*ig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	/* memset is needed here because of padding holes in the structure. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	memset(ig1, 0, sizeof(struct xfs_inogrp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	ig1->xi_startino = ig->xi_startino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	ig1->xi_alloccount = ig->xi_alloccount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	ig1->xi_allocmask = ig->xi_allocmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) }