| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
| Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 2 | * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc. | 
|  | 3 | * All Rights Reserved. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * | 
| Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 5 | * This program is free software; you can redistribute it and/or | 
|  | 6 | * modify it under the terms of the GNU General Public License as | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * published by the Free Software Foundation. | 
|  | 8 | * | 
| Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 9 | * This program is distributed in the hope that it would be useful, | 
|  | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|  | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|  | 12 | * GNU General Public License for more details. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * | 
| Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 14 | * You should have received a copy of the GNU General Public License | 
|  | 15 | * along with this program; if not, write the Free Software Foundation, | 
|  | 16 | * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include "xfs.h" | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 19 | #include "xfs_fs.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include "xfs_types.h" | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 21 | #include "xfs_bit.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include "xfs_log.h" | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 23 | #include "xfs_inum.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include "xfs_trans.h" | 
|  | 25 | #include "xfs_sb.h" | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 26 | #include "xfs_ag.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include "xfs_dir2.h" | 
|  | 28 | #include "xfs_dmapi.h" | 
|  | 29 | #include "xfs_mount.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include "xfs_bmap_btree.h" | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 31 | #include "xfs_alloc_btree.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include "xfs_ialloc_btree.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include "xfs_dir2_sf.h" | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 34 | #include "xfs_attr_sf.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include "xfs_dinode.h" | 
|  | 36 | #include "xfs_inode.h" | 
|  | 37 | #include "xfs_ialloc.h" | 
|  | 38 | #include "xfs_itable.h" | 
|  | 39 | #include "xfs_error.h" | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 40 | #include "xfs_btree.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 |  | 
| Eric Sandeen | d96f8f8 | 2009-07-02 00:09:33 -0500 | [diff] [blame] | 42 | STATIC int | 
| Vlad Apostolov | 6f1f216 | 2006-09-28 11:06:15 +1000 | [diff] [blame] | 43 | xfs_internal_inum( | 
|  | 44 | xfs_mount_t	*mp, | 
|  | 45 | xfs_ino_t	ino) | 
|  | 46 | { | 
|  | 47 | return (ino == mp->m_sb.sb_rbmino || ino == mp->m_sb.sb_rsumino || | 
| Eric Sandeen | 6211870 | 2008-03-06 13:44:28 +1100 | [diff] [blame] | 48 | (xfs_sb_version_hasquota(&mp->m_sb) && | 
| Vlad Apostolov | 6f1f216 | 2006-09-28 11:06:15 +1000 | [diff] [blame] | 49 | (ino == mp->m_sb.sb_uquotino || ino == mp->m_sb.sb_gquotino))); | 
|  | 50 | } | 
|  | 51 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | STATIC int | 
|  | 53 | xfs_bulkstat_one_iget( | 
|  | 54 | xfs_mount_t	*mp,		/* mount point for filesystem */ | 
|  | 55 | xfs_ino_t	ino,		/* inode number to get data for */ | 
|  | 56 | xfs_daddr_t	bno,		/* starting bno of inode cluster */ | 
|  | 57 | xfs_bstat_t	*buf,		/* return buffer */ | 
|  | 58 | int		*stat)		/* BULKSTAT_RV_... */ | 
|  | 59 | { | 
| Christoph Hellwig | 347d1c0 | 2007-08-28 13:57:51 +1000 | [diff] [blame] | 60 | xfs_icdinode_t	*dic;	/* dinode core info pointer */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | xfs_inode_t	*ip;		/* incore inode pointer */ | 
| Christoph Hellwig | f9581b1 | 2009-10-06 20:29:26 +0000 | [diff] [blame] | 62 | struct inode	*inode; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | int		error; | 
|  | 64 |  | 
| Nathan Scott | 745b1f47 | 2006-09-28 11:02:23 +1000 | [diff] [blame] | 65 | error = xfs_iget(mp, NULL, ino, | 
|  | 66 | XFS_IGET_BULKSTAT, XFS_ILOCK_SHARED, &ip, bno); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | if (error) { | 
|  | 68 | *stat = BULKSTAT_RV_NOTHING; | 
|  | 69 | return error; | 
|  | 70 | } | 
|  | 71 |  | 
|  | 72 | ASSERT(ip != NULL); | 
| Christoph Hellwig | 92bfc6e | 2008-11-28 14:23:41 +1100 | [diff] [blame] | 73 | ASSERT(ip->i_imap.im_blkno != 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 |  | 
|  | 75 | dic = &ip->i_d; | 
| Christoph Hellwig | f9581b1 | 2009-10-06 20:29:26 +0000 | [diff] [blame] | 76 | inode = VFS_I(ip); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 |  | 
|  | 78 | /* xfs_iget returns the following without needing | 
|  | 79 | * further change. | 
|  | 80 | */ | 
|  | 81 | buf->bs_nlink = dic->di_nlink; | 
|  | 82 | buf->bs_projid = dic->di_projid; | 
|  | 83 | buf->bs_ino = ino; | 
|  | 84 | buf->bs_mode = dic->di_mode; | 
|  | 85 | buf->bs_uid = dic->di_uid; | 
|  | 86 | buf->bs_gid = dic->di_gid; | 
|  | 87 | buf->bs_size = dic->di_size; | 
| Christoph Hellwig | f9581b1 | 2009-10-06 20:29:26 +0000 | [diff] [blame] | 88 |  | 
| Christoph Hellwig | 8fab451 | 2009-03-16 08:24:46 +0100 | [diff] [blame] | 89 | /* | 
| Christoph Hellwig | f9581b1 | 2009-10-06 20:29:26 +0000 | [diff] [blame] | 90 | * We need to read the timestamps from the Linux inode because | 
|  | 91 | * the VFS keeps writing directly into the inode structure instead | 
|  | 92 | * of telling us about the updates. | 
| Christoph Hellwig | 8fab451 | 2009-03-16 08:24:46 +0100 | [diff] [blame] | 93 | */ | 
| Christoph Hellwig | f9581b1 | 2009-10-06 20:29:26 +0000 | [diff] [blame] | 94 | buf->bs_atime.tv_sec = inode->i_atime.tv_sec; | 
|  | 95 | buf->bs_atime.tv_nsec = inode->i_atime.tv_nsec; | 
|  | 96 | buf->bs_mtime.tv_sec = inode->i_mtime.tv_sec; | 
|  | 97 | buf->bs_mtime.tv_nsec = inode->i_mtime.tv_nsec; | 
|  | 98 | buf->bs_ctime.tv_sec = inode->i_ctime.tv_sec; | 
|  | 99 | buf->bs_ctime.tv_nsec = inode->i_ctime.tv_nsec; | 
|  | 100 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | buf->bs_xflags = xfs_ip2xflags(ip); | 
|  | 102 | buf->bs_extsize = dic->di_extsize << mp->m_sb.sb_blocklog; | 
|  | 103 | buf->bs_extents = dic->di_nextents; | 
|  | 104 | buf->bs_gen = dic->di_gen; | 
|  | 105 | memset(buf->bs_pad, 0, sizeof(buf->bs_pad)); | 
|  | 106 | buf->bs_dmevmask = dic->di_dmevmask; | 
|  | 107 | buf->bs_dmstate = dic->di_dmstate; | 
|  | 108 | buf->bs_aextents = dic->di_anextents; | 
|  | 109 |  | 
|  | 110 | switch (dic->di_format) { | 
|  | 111 | case XFS_DINODE_FMT_DEV: | 
|  | 112 | buf->bs_rdev = ip->i_df.if_u2.if_rdev; | 
|  | 113 | buf->bs_blksize = BLKDEV_IOSIZE; | 
|  | 114 | buf->bs_blocks = 0; | 
|  | 115 | break; | 
|  | 116 | case XFS_DINODE_FMT_LOCAL: | 
|  | 117 | case XFS_DINODE_FMT_UUID: | 
|  | 118 | buf->bs_rdev = 0; | 
|  | 119 | buf->bs_blksize = mp->m_sb.sb_blocksize; | 
|  | 120 | buf->bs_blocks = 0; | 
|  | 121 | break; | 
|  | 122 | case XFS_DINODE_FMT_EXTENTS: | 
|  | 123 | case XFS_DINODE_FMT_BTREE: | 
|  | 124 | buf->bs_rdev = 0; | 
|  | 125 | buf->bs_blksize = mp->m_sb.sb_blocksize; | 
|  | 126 | buf->bs_blocks = dic->di_nblocks + ip->i_delayed_blks; | 
|  | 127 | break; | 
|  | 128 | } | 
|  | 129 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | xfs_iput(ip, XFS_ILOCK_SHARED); | 
|  | 131 | return error; | 
|  | 132 | } | 
|  | 133 |  | 
| David Chinner | 7b07339 | 2008-04-10 12:24:04 +1000 | [diff] [blame] | 134 | STATIC void | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | xfs_bulkstat_one_dinode( | 
|  | 136 | xfs_mount_t	*mp,		/* mount point for filesystem */ | 
|  | 137 | xfs_ino_t	ino,		/* inode number to get data for */ | 
| Christoph Hellwig | 81591fe | 2008-11-28 14:23:39 +1100 | [diff] [blame] | 138 | xfs_dinode_t	*dic,		/* dinode inode pointer */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | xfs_bstat_t	*buf)		/* return buffer */ | 
|  | 140 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | /* | 
|  | 142 | * The inode format changed when we moved the link count and | 
|  | 143 | * made it 32 bits long.  If this is an old format inode, | 
|  | 144 | * convert it in memory to look like a new one.  If it gets | 
|  | 145 | * flushed to disk we will convert back before flushing or | 
|  | 146 | * logging it.  We zero out the new projid field and the old link | 
|  | 147 | * count field.  We'll handle clearing the pad field (the remains | 
|  | 148 | * of the old uuid field) when we actually convert the inode to | 
|  | 149 | * the new format. We don't change the version number so that we | 
|  | 150 | * can distinguish this from a real new format inode. | 
|  | 151 | */ | 
| Christoph Hellwig | 51ce16d | 2008-11-28 14:23:39 +1100 | [diff] [blame] | 152 | if (dic->di_version == 1) { | 
| Christoph Hellwig | 347d1c0 | 2007-08-28 13:57:51 +1000 | [diff] [blame] | 153 | buf->bs_nlink = be16_to_cpu(dic->di_onlink); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | buf->bs_projid = 0; | 
|  | 155 | } else { | 
| Christoph Hellwig | 347d1c0 | 2007-08-28 13:57:51 +1000 | [diff] [blame] | 156 | buf->bs_nlink = be32_to_cpu(dic->di_nlink); | 
|  | 157 | buf->bs_projid = be16_to_cpu(dic->di_projid); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | } | 
|  | 159 |  | 
|  | 160 | buf->bs_ino = ino; | 
| Christoph Hellwig | 347d1c0 | 2007-08-28 13:57:51 +1000 | [diff] [blame] | 161 | buf->bs_mode = be16_to_cpu(dic->di_mode); | 
|  | 162 | buf->bs_uid = be32_to_cpu(dic->di_uid); | 
|  | 163 | buf->bs_gid = be32_to_cpu(dic->di_gid); | 
|  | 164 | buf->bs_size = be64_to_cpu(dic->di_size); | 
|  | 165 | buf->bs_atime.tv_sec = be32_to_cpu(dic->di_atime.t_sec); | 
|  | 166 | buf->bs_atime.tv_nsec = be32_to_cpu(dic->di_atime.t_nsec); | 
|  | 167 | buf->bs_mtime.tv_sec = be32_to_cpu(dic->di_mtime.t_sec); | 
|  | 168 | buf->bs_mtime.tv_nsec = be32_to_cpu(dic->di_mtime.t_nsec); | 
|  | 169 | buf->bs_ctime.tv_sec = be32_to_cpu(dic->di_ctime.t_sec); | 
|  | 170 | buf->bs_ctime.tv_nsec = be32_to_cpu(dic->di_ctime.t_nsec); | 
| Christoph Hellwig | 81591fe | 2008-11-28 14:23:39 +1100 | [diff] [blame] | 171 | buf->bs_xflags = xfs_dic2xflags(dic); | 
| Christoph Hellwig | 347d1c0 | 2007-08-28 13:57:51 +1000 | [diff] [blame] | 172 | buf->bs_extsize = be32_to_cpu(dic->di_extsize) << mp->m_sb.sb_blocklog; | 
|  | 173 | buf->bs_extents = be32_to_cpu(dic->di_nextents); | 
|  | 174 | buf->bs_gen = be32_to_cpu(dic->di_gen); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | memset(buf->bs_pad, 0, sizeof(buf->bs_pad)); | 
| Christoph Hellwig | 347d1c0 | 2007-08-28 13:57:51 +1000 | [diff] [blame] | 176 | buf->bs_dmevmask = be32_to_cpu(dic->di_dmevmask); | 
|  | 177 | buf->bs_dmstate = be16_to_cpu(dic->di_dmstate); | 
|  | 178 | buf->bs_aextents = be16_to_cpu(dic->di_anextents); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 |  | 
| Christoph Hellwig | 347d1c0 | 2007-08-28 13:57:51 +1000 | [diff] [blame] | 180 | switch (dic->di_format) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | case XFS_DINODE_FMT_DEV: | 
| Christoph Hellwig | 81591fe | 2008-11-28 14:23:39 +1100 | [diff] [blame] | 182 | buf->bs_rdev = xfs_dinode_get_rdev(dic); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | buf->bs_blksize = BLKDEV_IOSIZE; | 
|  | 184 | buf->bs_blocks = 0; | 
|  | 185 | break; | 
|  | 186 | case XFS_DINODE_FMT_LOCAL: | 
|  | 187 | case XFS_DINODE_FMT_UUID: | 
|  | 188 | buf->bs_rdev = 0; | 
|  | 189 | buf->bs_blksize = mp->m_sb.sb_blocksize; | 
|  | 190 | buf->bs_blocks = 0; | 
|  | 191 | break; | 
|  | 192 | case XFS_DINODE_FMT_EXTENTS: | 
|  | 193 | case XFS_DINODE_FMT_BTREE: | 
|  | 194 | buf->bs_rdev = 0; | 
|  | 195 | buf->bs_blksize = mp->m_sb.sb_blocksize; | 
| Christoph Hellwig | 347d1c0 | 2007-08-28 13:57:51 +1000 | [diff] [blame] | 196 | buf->bs_blocks = be64_to_cpu(dic->di_nblocks); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | break; | 
|  | 198 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | } | 
|  | 200 |  | 
| sandeen@sandeen.net | 65fbaf2 | 2008-11-25 21:20:12 -0600 | [diff] [blame] | 201 | /* Return 0 on success or positive error */ | 
| Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 202 | STATIC int | 
|  | 203 | xfs_bulkstat_one_fmt( | 
|  | 204 | void			__user *ubuffer, | 
| sandeen@sandeen.net | 65fbaf2 | 2008-11-25 21:20:12 -0600 | [diff] [blame] | 205 | int			ubsize, | 
|  | 206 | int			*ubused, | 
| Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 207 | const xfs_bstat_t	*buffer) | 
|  | 208 | { | 
| sandeen@sandeen.net | 65fbaf2 | 2008-11-25 21:20:12 -0600 | [diff] [blame] | 209 | if (ubsize < sizeof(*buffer)) | 
|  | 210 | return XFS_ERROR(ENOMEM); | 
| Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 211 | if (copy_to_user(ubuffer, buffer, sizeof(*buffer))) | 
| sandeen@sandeen.net | 65fbaf2 | 2008-11-25 21:20:12 -0600 | [diff] [blame] | 212 | return XFS_ERROR(EFAULT); | 
|  | 213 | if (ubused) | 
|  | 214 | *ubused = sizeof(*buffer); | 
|  | 215 | return 0; | 
| Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 216 | } | 
|  | 217 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | /* | 
|  | 219 | * Return stat information for one inode. | 
|  | 220 | * Return 0 if ok, else errno. | 
|  | 221 | */ | 
| sandeen@sandeen.net | 2ee4fa5 | 2008-11-25 21:20:11 -0600 | [diff] [blame] | 222 | int		   	    		/* error status */ | 
|  | 223 | xfs_bulkstat_one_int( | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | xfs_mount_t	*mp,		/* mount point for filesystem */ | 
|  | 225 | xfs_ino_t	ino,		/* inode number to get data for */ | 
|  | 226 | void		__user *buffer,	/* buffer to place output in */ | 
|  | 227 | int		ubsize,		/* size of buffer */ | 
| sandeen@sandeen.net | 2ee4fa5 | 2008-11-25 21:20:11 -0600 | [diff] [blame] | 228 | bulkstat_one_fmt_pf formatter,	/* formatter, copy to user */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | xfs_daddr_t	bno,		/* starting bno of inode cluster */ | 
|  | 230 | int		*ubused,	/* bytes used by me */ | 
|  | 231 | void		*dibuff,	/* on-disk inode buffer */ | 
|  | 232 | int		*stat)		/* BULKSTAT_RV_... */ | 
|  | 233 | { | 
|  | 234 | xfs_bstat_t	*buf;		/* return buffer */ | 
|  | 235 | int		error = 0;	/* error value */ | 
|  | 236 | xfs_dinode_t	*dip;		/* dinode inode pointer */ | 
|  | 237 |  | 
|  | 238 | dip = (xfs_dinode_t *)dibuff; | 
| Vlad Apostolov | 6f1f216 | 2006-09-28 11:06:15 +1000 | [diff] [blame] | 239 | *stat = BULKSTAT_RV_NOTHING; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 |  | 
| Vlad Apostolov | 6f1f216 | 2006-09-28 11:06:15 +1000 | [diff] [blame] | 241 | if (!buffer || xfs_internal_inum(mp, ino)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | return XFS_ERROR(EINVAL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 |  | 
|  | 244 | buf = kmem_alloc(sizeof(*buf), KM_SLEEP); | 
|  | 245 |  | 
|  | 246 | if (dip == NULL) { | 
|  | 247 | /* We're not being passed a pointer to a dinode.  This happens | 
|  | 248 | * if BULKSTAT_FG_IGET is selected.  Do the iget. | 
|  | 249 | */ | 
|  | 250 | error = xfs_bulkstat_one_iget(mp, ino, bno, buf, stat); | 
|  | 251 | if (error) | 
|  | 252 | goto out_free; | 
|  | 253 | } else { | 
|  | 254 | xfs_bulkstat_one_dinode(mp, ino, dip, buf); | 
|  | 255 | } | 
|  | 256 |  | 
| sandeen@sandeen.net | 65fbaf2 | 2008-11-25 21:20:12 -0600 | [diff] [blame] | 257 | error = formatter(buffer, ubsize, ubused, buf); | 
|  | 258 | if (error) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | goto out_free; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 |  | 
|  | 261 | *stat = BULKSTAT_RV_DIDONE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 |  | 
|  | 263 | out_free: | 
| Denys Vlasenko | f0e2d93 | 2008-05-19 16:31:57 +1000 | [diff] [blame] | 264 | kmem_free(buf); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | return error; | 
|  | 266 | } | 
|  | 267 |  | 
| sandeen@sandeen.net | 2ee4fa5 | 2008-11-25 21:20:11 -0600 | [diff] [blame] | 268 | int | 
|  | 269 | xfs_bulkstat_one( | 
|  | 270 | xfs_mount_t	*mp,		/* mount point for filesystem */ | 
|  | 271 | xfs_ino_t	ino,		/* inode number to get data for */ | 
|  | 272 | void		__user *buffer,	/* buffer to place output in */ | 
|  | 273 | int		ubsize,		/* size of buffer */ | 
|  | 274 | void		*private_data,	/* my private data */ | 
|  | 275 | xfs_daddr_t	bno,		/* starting bno of inode cluster */ | 
|  | 276 | int		*ubused,	/* bytes used by me */ | 
|  | 277 | void		*dibuff,	/* on-disk inode buffer */ | 
|  | 278 | int		*stat)		/* BULKSTAT_RV_... */ | 
|  | 279 | { | 
|  | 280 | return xfs_bulkstat_one_int(mp, ino, buffer, ubsize, | 
|  | 281 | xfs_bulkstat_one_fmt, bno, | 
|  | 282 | ubused, dibuff, stat); | 
|  | 283 | } | 
|  | 284 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | /* | 
| Nathan Scott | 8b56f08 | 2006-09-28 11:01:46 +1000 | [diff] [blame] | 286 | * Test to see whether we can use the ondisk inode directly, based | 
|  | 287 | * on the given bulkstat flags, filling in dipp accordingly. | 
|  | 288 | * Returns zero if the inode is dodgey. | 
|  | 289 | */ | 
|  | 290 | STATIC int | 
|  | 291 | xfs_bulkstat_use_dinode( | 
|  | 292 | xfs_mount_t	*mp, | 
|  | 293 | int		flags, | 
|  | 294 | xfs_buf_t	*bp, | 
|  | 295 | int		clustidx, | 
|  | 296 | xfs_dinode_t	**dipp) | 
|  | 297 | { | 
|  | 298 | xfs_dinode_t	*dip; | 
|  | 299 | unsigned int	aformat; | 
|  | 300 |  | 
|  | 301 | *dipp = NULL; | 
|  | 302 | if (!bp || (flags & BULKSTAT_FG_IGET)) | 
|  | 303 | return 1; | 
|  | 304 | dip = (xfs_dinode_t *) | 
|  | 305 | xfs_buf_offset(bp, clustidx << mp->m_sb.sb_inodelog); | 
| Vlad Apostolov | 859d718 | 2007-10-11 17:44:18 +1000 | [diff] [blame] | 306 | /* | 
| Vlad Apostolov | c319b58 | 2007-11-23 16:27:51 +1100 | [diff] [blame] | 307 | * Check the buffer containing the on-disk inode for di_mode == 0. | 
| Vlad Apostolov | 859d718 | 2007-10-11 17:44:18 +1000 | [diff] [blame] | 308 | * This is to prevent xfs_bulkstat from picking up just reclaimed | 
|  | 309 | * inodes that have their in-core state initialized but not flushed | 
|  | 310 | * to disk yet. This is a temporary hack that would require a proper | 
|  | 311 | * fix in the future. | 
|  | 312 | */ | 
| Christoph Hellwig | 81591fe | 2008-11-28 14:23:39 +1100 | [diff] [blame] | 313 | if (be16_to_cpu(dip->di_magic) != XFS_DINODE_MAGIC || | 
|  | 314 | !XFS_DINODE_GOOD_VERSION(dip->di_version) || | 
|  | 315 | !dip->di_mode) | 
| Nathan Scott | 8b56f08 | 2006-09-28 11:01:46 +1000 | [diff] [blame] | 316 | return 0; | 
|  | 317 | if (flags & BULKSTAT_FG_QUICK) { | 
|  | 318 | *dipp = dip; | 
|  | 319 | return 1; | 
|  | 320 | } | 
|  | 321 | /* BULKSTAT_FG_INLINE: if attr fork is local, or not there, use it */ | 
| Christoph Hellwig | 81591fe | 2008-11-28 14:23:39 +1100 | [diff] [blame] | 322 | aformat = dip->di_aformat; | 
| Christoph Hellwig | 45ba598 | 2007-12-07 14:07:20 +1100 | [diff] [blame] | 323 | if ((XFS_DFORK_Q(dip) == 0) || | 
| Nathan Scott | 8b56f08 | 2006-09-28 11:01:46 +1000 | [diff] [blame] | 324 | (aformat == XFS_DINODE_FMT_LOCAL) || | 
| Christoph Hellwig | 81591fe | 2008-11-28 14:23:39 +1100 | [diff] [blame] | 325 | (aformat == XFS_DINODE_FMT_EXTENTS && !dip->di_anextents)) { | 
| Nathan Scott | 8b56f08 | 2006-09-28 11:01:46 +1000 | [diff] [blame] | 326 | *dipp = dip; | 
|  | 327 | return 1; | 
|  | 328 | } | 
|  | 329 | return 1; | 
|  | 330 | } | 
|  | 331 |  | 
| Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 332 | #define XFS_BULKSTAT_UBLEFT(ubleft)	((ubleft) >= statstruct_size) | 
|  | 333 |  | 
| Nathan Scott | 8b56f08 | 2006-09-28 11:01:46 +1000 | [diff] [blame] | 334 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | * Return stat information in bulk (by-inode) for the filesystem. | 
|  | 336 | */ | 
|  | 337 | int					/* error status */ | 
|  | 338 | xfs_bulkstat( | 
|  | 339 | xfs_mount_t		*mp,	/* mount point for filesystem */ | 
|  | 340 | xfs_ino_t		*lastinop, /* last inode returned */ | 
|  | 341 | int			*ubcountp, /* size of buffer/count returned */ | 
|  | 342 | bulkstat_one_pf		formatter, /* func that'd fill a single buf */ | 
|  | 343 | void			*private_data,/* private data for formatter */ | 
|  | 344 | size_t			statstruct_size, /* sizeof struct filling */ | 
|  | 345 | char			__user *ubuffer, /* buffer with inode stats */ | 
|  | 346 | int			flags,	/* defined in xfs_itable.h */ | 
| Nathan Scott | c41564b | 2006-03-29 08:55:14 +1000 | [diff] [blame] | 347 | int			*done)	/* 1 if there are more stats to get */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | { | 
|  | 349 | xfs_agblock_t		agbno=0;/* allocation group block number */ | 
|  | 350 | xfs_buf_t		*agbp;	/* agi header buffer */ | 
|  | 351 | xfs_agi_t		*agi;	/* agi header data */ | 
|  | 352 | xfs_agino_t		agino;	/* inode # in allocation group */ | 
|  | 353 | xfs_agnumber_t		agno;	/* allocation group number */ | 
|  | 354 | xfs_daddr_t		bno;	/* inode cluster start daddr */ | 
|  | 355 | int			chunkidx; /* current index into inode chunk */ | 
|  | 356 | int			clustidx; /* current index into inode cluster */ | 
|  | 357 | xfs_btree_cur_t		*cur;	/* btree cursor for ialloc btree */ | 
|  | 358 | int			end_of_ag; /* set if we've seen the ag end */ | 
|  | 359 | int			error;	/* error code */ | 
|  | 360 | int                     fmterror;/* bulkstat formatter result */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | int			i;	/* loop index */ | 
|  | 362 | int			icount;	/* count of inodes good in irbuf */ | 
| Nathan Scott | 215101c | 2006-09-28 11:04:43 +1000 | [diff] [blame] | 363 | size_t			irbsize; /* size of irec buffer in bytes */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | xfs_ino_t		ino;	/* inode number (filesystem) */ | 
| Nathan Scott | 26275093 | 2006-09-28 11:02:03 +1000 | [diff] [blame] | 365 | xfs_inobt_rec_incore_t	*irbp;	/* current irec buffer pointer */ | 
|  | 366 | xfs_inobt_rec_incore_t	*irbuf;	/* start of irec buffer */ | 
|  | 367 | xfs_inobt_rec_incore_t	*irbufend; /* end of good irec buffer entries */ | 
| Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 368 | xfs_ino_t		lastino; /* last inode number returned */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | int			nbcluster; /* # of blocks in a cluster */ | 
|  | 370 | int			nicluster; /* # of inodes in a cluster */ | 
|  | 371 | int			nimask;	/* mask for inode clusters */ | 
|  | 372 | int			nirbuf;	/* size of irbuf */ | 
|  | 373 | int			rval;	/* return value error code */ | 
|  | 374 | int			tmp;	/* result value from btree calls */ | 
|  | 375 | int			ubcount; /* size of user's buffer */ | 
|  | 376 | int			ubleft;	/* bytes left in user's buffer */ | 
|  | 377 | char			__user *ubufp;	/* pointer into user's buffer */ | 
|  | 378 | int			ubelem;	/* spaces used in user's buffer */ | 
|  | 379 | int			ubused;	/* bytes used by formatter */ | 
|  | 380 | xfs_buf_t		*bp;	/* ptr to on-disk inode cluster buf */ | 
|  | 381 | xfs_dinode_t		*dip;	/* ptr into bp for specific inode */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 |  | 
|  | 383 | /* | 
|  | 384 | * Get the last inode value, see if there's nothing to do. | 
|  | 385 | */ | 
|  | 386 | ino = (xfs_ino_t)*lastinop; | 
| Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 387 | lastino = ino; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | dip = NULL; | 
|  | 389 | agno = XFS_INO_TO_AGNO(mp, ino); | 
|  | 390 | agino = XFS_INO_TO_AGINO(mp, ino); | 
|  | 391 | if (agno >= mp->m_sb.sb_agcount || | 
|  | 392 | ino != XFS_AGINO_TO_INO(mp, agno, agino)) { | 
|  | 393 | *done = 1; | 
|  | 394 | *ubcountp = 0; | 
|  | 395 | return 0; | 
|  | 396 | } | 
| Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 397 | if (!ubcountp || *ubcountp <= 0) { | 
|  | 398 | return EINVAL; | 
|  | 399 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | ubcount = *ubcountp; /* statstruct's */ | 
|  | 401 | ubleft = ubcount * statstruct_size; /* bytes */ | 
|  | 402 | *ubcountp = ubelem = 0; | 
|  | 403 | *done = 0; | 
|  | 404 | fmterror = 0; | 
|  | 405 | ubufp = ubuffer; | 
|  | 406 | nicluster = mp->m_sb.sb_blocksize >= XFS_INODE_CLUSTER_SIZE(mp) ? | 
|  | 407 | mp->m_sb.sb_inopblock : | 
|  | 408 | (XFS_INODE_CLUSTER_SIZE(mp) >> mp->m_sb.sb_inodelog); | 
|  | 409 | nimask = ~(nicluster - 1); | 
|  | 410 | nbcluster = nicluster >> mp->m_sb.sb_inopblog; | 
| Tim Shimmin | e6a4b37 | 2007-11-23 16:30:42 +1100 | [diff] [blame] | 411 | irbuf = kmem_zalloc_greedy(&irbsize, PAGE_SIZE, PAGE_SIZE * 4, | 
| Nathan Scott | 77e4635 | 2006-09-28 11:03:27 +1000 | [diff] [blame] | 412 | KM_SLEEP | KM_MAYFAIL | KM_LARGE); | 
| Nathan Scott | bb3c7d2 | 2006-09-28 11:02:09 +1000 | [diff] [blame] | 413 | nirbuf = irbsize / sizeof(*irbuf); | 
|  | 414 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | /* | 
|  | 416 | * Loop over the allocation groups, starting from the last | 
|  | 417 | * inode returned; 0 means start of the allocation group. | 
|  | 418 | */ | 
|  | 419 | rval = 0; | 
| Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 420 | while (XFS_BULKSTAT_UBLEFT(ubleft) && agno < mp->m_sb.sb_agcount) { | 
|  | 421 | cond_resched(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | bp = NULL; | 
|  | 423 | down_read(&mp->m_peraglock); | 
|  | 424 | error = xfs_ialloc_read_agi(mp, NULL, agno, &agbp); | 
|  | 425 | up_read(&mp->m_peraglock); | 
|  | 426 | if (error) { | 
|  | 427 | /* | 
|  | 428 | * Skip this allocation group and go to the next one. | 
|  | 429 | */ | 
|  | 430 | agno++; | 
|  | 431 | agino = 0; | 
|  | 432 | continue; | 
|  | 433 | } | 
|  | 434 | agi = XFS_BUF_TO_AGI(agbp); | 
|  | 435 | /* | 
|  | 436 | * Allocate and initialize a btree cursor for ialloc btree. | 
|  | 437 | */ | 
| Christoph Hellwig | 561f7d1 | 2008-10-30 16:53:59 +1100 | [diff] [blame] | 438 | cur = xfs_inobt_init_cursor(mp, NULL, agbp, agno); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | irbp = irbuf; | 
|  | 440 | irbufend = irbuf + nirbuf; | 
|  | 441 | end_of_ag = 0; | 
|  | 442 | /* | 
|  | 443 | * If we're returning in the middle of an allocation group, | 
|  | 444 | * we need to get the remainder of the chunk we're in. | 
|  | 445 | */ | 
|  | 446 | if (agino > 0) { | 
| Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 447 | xfs_inobt_rec_incore_t r; | 
|  | 448 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | /* | 
|  | 450 | * Lookup the inode chunk that this inode lives in. | 
|  | 451 | */ | 
| Christoph Hellwig | 2187550 | 2009-08-31 20:58:21 -0300 | [diff] [blame] | 452 | error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_LE, | 
|  | 453 | &tmp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | if (!error &&	/* no I/O error */ | 
|  | 455 | tmp &&	/* lookup succeeded */ | 
|  | 456 | /* got the record, should always work */ | 
| Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 457 | !(error = xfs_inobt_get_rec(cur, &r, &i)) && | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | i == 1 && | 
|  | 459 | /* this is the right chunk */ | 
| Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 460 | agino < r.ir_startino + XFS_INODES_PER_CHUNK && | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | /* lastino was not last in chunk */ | 
| Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 462 | (chunkidx = agino - r.ir_startino + 1) < | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | XFS_INODES_PER_CHUNK && | 
|  | 464 | /* there are some left allocated */ | 
| Eric Sandeen | 9d87c31 | 2009-01-14 23:22:07 -0600 | [diff] [blame] | 465 | xfs_inobt_maskn(chunkidx, | 
| Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 466 | XFS_INODES_PER_CHUNK - chunkidx) & | 
|  | 467 | ~r.ir_free) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | /* | 
|  | 469 | * Grab the chunk record.  Mark all the | 
|  | 470 | * uninteresting inodes (because they're | 
|  | 471 | * before our start point) free. | 
|  | 472 | */ | 
|  | 473 | for (i = 0; i < chunkidx; i++) { | 
| Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 474 | if (XFS_INOBT_MASK(i) & ~r.ir_free) | 
|  | 475 | r.ir_freecount++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | } | 
| Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 477 | r.ir_free |= xfs_inobt_maskn(0, chunkidx); | 
|  | 478 | irbp->ir_startino = r.ir_startino; | 
|  | 479 | irbp->ir_freecount = r.ir_freecount; | 
|  | 480 | irbp->ir_free = r.ir_free; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | irbp++; | 
| Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 482 | agino = r.ir_startino + XFS_INODES_PER_CHUNK; | 
|  | 483 | icount = XFS_INODES_PER_CHUNK - r.ir_freecount; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | } else { | 
|  | 485 | /* | 
|  | 486 | * If any of those tests failed, bump the | 
|  | 487 | * inode number (just in case). | 
|  | 488 | */ | 
|  | 489 | agino++; | 
|  | 490 | icount = 0; | 
|  | 491 | } | 
|  | 492 | /* | 
|  | 493 | * In any case, increment to the next record. | 
|  | 494 | */ | 
|  | 495 | if (!error) | 
| Christoph Hellwig | 637aa50 | 2008-10-30 16:55:45 +1100 | [diff] [blame] | 496 | error = xfs_btree_increment(cur, 0, &tmp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | } else { | 
|  | 498 | /* | 
|  | 499 | * Start of ag.  Lookup the first inode chunk. | 
|  | 500 | */ | 
| Christoph Hellwig | 2187550 | 2009-08-31 20:58:21 -0300 | [diff] [blame] | 501 | error = xfs_inobt_lookup(cur, 0, XFS_LOOKUP_GE, &tmp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | icount = 0; | 
|  | 503 | } | 
|  | 504 | /* | 
|  | 505 | * Loop through inode btree records in this ag, | 
|  | 506 | * until we run out of inodes or space in the buffer. | 
|  | 507 | */ | 
|  | 508 | while (irbp < irbufend && icount < ubcount) { | 
| Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 509 | xfs_inobt_rec_incore_t r; | 
|  | 510 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | /* | 
|  | 512 | * Loop as long as we're unable to read the | 
|  | 513 | * inode btree. | 
|  | 514 | */ | 
|  | 515 | while (error) { | 
|  | 516 | agino += XFS_INODES_PER_CHUNK; | 
|  | 517 | if (XFS_AGINO_TO_AGBNO(mp, agino) >= | 
| Christoph Hellwig | 16259e7 | 2005-11-02 15:11:25 +1100 | [diff] [blame] | 518 | be32_to_cpu(agi->agi_length)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | break; | 
| Christoph Hellwig | 2187550 | 2009-08-31 20:58:21 -0300 | [diff] [blame] | 520 | error = xfs_inobt_lookup(cur, agino, | 
|  | 521 | XFS_LOOKUP_GE, &tmp); | 
| Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 522 | cond_resched(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | } | 
|  | 524 | /* | 
|  | 525 | * If ran off the end of the ag either with an error, | 
|  | 526 | * or the normal way, set end and stop collecting. | 
|  | 527 | */ | 
| Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 528 | if (error) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | end_of_ag = 1; | 
|  | 530 | break; | 
|  | 531 | } | 
| Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 532 |  | 
|  | 533 | error = xfs_inobt_get_rec(cur, &r, &i); | 
|  | 534 | if (error || i == 0) { | 
|  | 535 | end_of_ag = 1; | 
|  | 536 | break; | 
|  | 537 | } | 
|  | 538 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | /* | 
|  | 540 | * If this chunk has any allocated inodes, save it. | 
| Nathan Scott | 26275093 | 2006-09-28 11:02:03 +1000 | [diff] [blame] | 541 | * Also start read-ahead now for this chunk. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | */ | 
| Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 543 | if (r.ir_freecount < XFS_INODES_PER_CHUNK) { | 
| Nathan Scott | 26275093 | 2006-09-28 11:02:03 +1000 | [diff] [blame] | 544 | /* | 
|  | 545 | * Loop over all clusters in the next chunk. | 
|  | 546 | * Do a readahead if there are any allocated | 
|  | 547 | * inodes in that cluster. | 
|  | 548 | */ | 
| Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 549 | agbno = XFS_AGINO_TO_AGBNO(mp, r.ir_startino); | 
|  | 550 | for (chunkidx = 0; | 
| Nathan Scott | 26275093 | 2006-09-28 11:02:03 +1000 | [diff] [blame] | 551 | chunkidx < XFS_INODES_PER_CHUNK; | 
|  | 552 | chunkidx += nicluster, | 
|  | 553 | agbno += nbcluster) { | 
| Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 554 | if (xfs_inobt_maskn(chunkidx, nicluster) | 
|  | 555 | & ~r.ir_free) | 
| Nathan Scott | 26275093 | 2006-09-28 11:02:03 +1000 | [diff] [blame] | 556 | xfs_btree_reada_bufs(mp, agno, | 
|  | 557 | agbno, nbcluster); | 
|  | 558 | } | 
| Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 559 | irbp->ir_startino = r.ir_startino; | 
|  | 560 | irbp->ir_freecount = r.ir_freecount; | 
|  | 561 | irbp->ir_free = r.ir_free; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | irbp++; | 
| Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 563 | icount += XFS_INODES_PER_CHUNK - r.ir_freecount; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | } | 
|  | 565 | /* | 
|  | 566 | * Set agino to after this chunk and bump the cursor. | 
|  | 567 | */ | 
| Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 568 | agino = r.ir_startino + XFS_INODES_PER_CHUNK; | 
| Christoph Hellwig | 637aa50 | 2008-10-30 16:55:45 +1100 | [diff] [blame] | 569 | error = xfs_btree_increment(cur, 0, &tmp); | 
| Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 570 | cond_resched(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | } | 
|  | 572 | /* | 
|  | 573 | * Drop the btree buffers and the agi buffer. | 
|  | 574 | * We can't hold any of the locks these represent | 
|  | 575 | * when calling iget. | 
|  | 576 | */ | 
|  | 577 | xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR); | 
|  | 578 | xfs_buf_relse(agbp); | 
|  | 579 | /* | 
|  | 580 | * Now format all the good inodes into the user's buffer. | 
|  | 581 | */ | 
|  | 582 | irbufend = irbp; | 
|  | 583 | for (irbp = irbuf; | 
| Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 584 | irbp < irbufend && XFS_BULKSTAT_UBLEFT(ubleft); irbp++) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | * Now process this chunk of inodes. | 
|  | 587 | */ | 
| Nathan Scott | 26275093 | 2006-09-28 11:02:03 +1000 | [diff] [blame] | 588 | for (agino = irbp->ir_startino, chunkidx = clustidx = 0; | 
| Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 589 | XFS_BULKSTAT_UBLEFT(ubleft) && | 
| Nathan Scott | 26275093 | 2006-09-28 11:02:03 +1000 | [diff] [blame] | 590 | irbp->ir_freecount < XFS_INODES_PER_CHUNK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | chunkidx++, clustidx++, agino++) { | 
|  | 592 | ASSERT(chunkidx < XFS_INODES_PER_CHUNK); | 
|  | 593 | /* | 
|  | 594 | * Recompute agbno if this is the | 
|  | 595 | * first inode of the cluster. | 
|  | 596 | * | 
|  | 597 | * Careful with clustidx.   There can be | 
| Malcolm Parsons | 9da096f | 2009-03-29 09:55:42 +0200 | [diff] [blame] | 598 | * multiple clusters per chunk, a single | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | * cluster per chunk or a cluster that has | 
|  | 600 | * inodes represented from several different | 
|  | 601 | * chunks (if blocksize is large). | 
|  | 602 | * | 
|  | 603 | * Because of this, the starting clustidx is | 
|  | 604 | * initialized to zero in this loop but must | 
|  | 605 | * later be reset after reading in the cluster | 
|  | 606 | * buffer. | 
|  | 607 | */ | 
|  | 608 | if ((chunkidx & (nicluster - 1)) == 0) { | 
|  | 609 | agbno = XFS_AGINO_TO_AGBNO(mp, | 
| Nathan Scott | 26275093 | 2006-09-28 11:02:03 +1000 | [diff] [blame] | 610 | irbp->ir_startino) + | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | ((chunkidx & nimask) >> | 
|  | 612 | mp->m_sb.sb_inopblog); | 
|  | 613 |  | 
| Nathan Scott | 8b56f08 | 2006-09-28 11:01:46 +1000 | [diff] [blame] | 614 | if (flags & (BULKSTAT_FG_QUICK | | 
|  | 615 | BULKSTAT_FG_INLINE)) { | 
| Christoph Hellwig | c679eef | 2008-10-30 18:04:13 +1100 | [diff] [blame] | 616 | int offset; | 
|  | 617 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | ino = XFS_AGINO_TO_INO(mp, agno, | 
|  | 619 | agino); | 
|  | 620 | bno = XFS_AGB_TO_DADDR(mp, agno, | 
|  | 621 | agbno); | 
|  | 622 |  | 
|  | 623 | /* | 
|  | 624 | * Get the inode cluster buffer | 
|  | 625 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | if (bp) | 
|  | 627 | xfs_buf_relse(bp); | 
| Christoph Hellwig | c679eef | 2008-10-30 18:04:13 +1100 | [diff] [blame] | 628 |  | 
|  | 629 | error = xfs_inotobp(mp, NULL, ino, &dip, | 
|  | 630 | &bp, &offset, | 
| Christoph Hellwig | b48d8d6 | 2008-11-28 14:23:41 +1100 | [diff] [blame] | 631 | XFS_IGET_BULKSTAT); | 
| Christoph Hellwig | c679eef | 2008-10-30 18:04:13 +1100 | [diff] [blame] | 632 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | if (!error) | 
| Christoph Hellwig | c679eef | 2008-10-30 18:04:13 +1100 | [diff] [blame] | 634 | clustidx = offset / mp->m_sb.sb_inodesize; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | if (XFS_TEST_ERROR(error != 0, | 
|  | 636 | mp, XFS_ERRTAG_BULKSTAT_READ_CHUNK, | 
|  | 637 | XFS_RANDOM_BULKSTAT_READ_CHUNK)) { | 
|  | 638 | bp = NULL; | 
| Nathan Scott | b12dd34 | 2006-03-17 17:26:04 +1100 | [diff] [blame] | 639 | ubleft = 0; | 
|  | 640 | rval = error; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | break; | 
|  | 642 | } | 
|  | 643 | } | 
|  | 644 | } | 
| Lachlan McIlroy | c2cba57 | 2007-10-12 11:12:20 +1000 | [diff] [blame] | 645 | ino = XFS_AGINO_TO_INO(mp, agno, agino); | 
|  | 646 | bno = XFS_AGB_TO_DADDR(mp, agno, agbno); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | /* | 
|  | 648 | * Skip if this inode is free. | 
|  | 649 | */ | 
| Lachlan McIlroy | c2cba57 | 2007-10-12 11:12:20 +1000 | [diff] [blame] | 650 | if (XFS_INOBT_MASK(chunkidx) & irbp->ir_free) { | 
|  | 651 | lastino = ino; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | continue; | 
| Lachlan McIlroy | c2cba57 | 2007-10-12 11:12:20 +1000 | [diff] [blame] | 653 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | /* | 
|  | 655 | * Count used inodes as free so we can tell | 
|  | 656 | * when the chunk is used up. | 
|  | 657 | */ | 
| Nathan Scott | 26275093 | 2006-09-28 11:02:03 +1000 | [diff] [blame] | 658 | irbp->ir_freecount++; | 
| Nathan Scott | 8b56f08 | 2006-09-28 11:01:46 +1000 | [diff] [blame] | 659 | if (!xfs_bulkstat_use_dinode(mp, flags, bp, | 
| Lachlan McIlroy | c2cba57 | 2007-10-12 11:12:20 +1000 | [diff] [blame] | 660 | clustidx, &dip)) { | 
|  | 661 | lastino = ino; | 
| Nathan Scott | 8b56f08 | 2006-09-28 11:01:46 +1000 | [diff] [blame] | 662 | continue; | 
| Lachlan McIlroy | c2cba57 | 2007-10-12 11:12:20 +1000 | [diff] [blame] | 663 | } | 
| Nathan Scott | 8b56f08 | 2006-09-28 11:01:46 +1000 | [diff] [blame] | 664 | /* | 
|  | 665 | * If we need to do an iget, cannot hold bp. | 
|  | 666 | * Drop it, until starting the next cluster. | 
|  | 667 | */ | 
|  | 668 | if ((flags & BULKSTAT_FG_INLINE) && !dip) { | 
|  | 669 | if (bp) | 
|  | 670 | xfs_buf_relse(bp); | 
|  | 671 | bp = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | } | 
|  | 673 |  | 
|  | 674 | /* | 
|  | 675 | * Get the inode and fill in a single buffer. | 
|  | 676 | * BULKSTAT_FG_QUICK uses dip to fill it in. | 
|  | 677 | * BULKSTAT_FG_IGET uses igets. | 
| Nathan Scott | 8b56f08 | 2006-09-28 11:01:46 +1000 | [diff] [blame] | 678 | * BULKSTAT_FG_INLINE uses dip if we have an | 
|  | 679 | * inline attr fork, else igets. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | * See: xfs_bulkstat_one & xfs_dm_bulkstat_one. | 
|  | 681 | * This is also used to count inodes/blks, etc | 
|  | 682 | * in xfs_qm_quotacheck. | 
|  | 683 | */ | 
|  | 684 | ubused = statstruct_size; | 
|  | 685 | error = formatter(mp, ino, ubufp, | 
|  | 686 | ubleft, private_data, | 
|  | 687 | bno, &ubused, dip, &fmterror); | 
|  | 688 | if (fmterror == BULKSTAT_RV_NOTHING) { | 
| Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 689 | if (error && error != ENOENT && | 
|  | 690 | error != EINVAL) { | 
| Vlad Apostolov | e132f54 | 2006-09-28 11:04:31 +1000 | [diff] [blame] | 691 | ubleft = 0; | 
| Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 692 | rval = error; | 
|  | 693 | break; | 
|  | 694 | } | 
|  | 695 | lastino = ino; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | continue; | 
|  | 697 | } | 
|  | 698 | if (fmterror == BULKSTAT_RV_GIVEUP) { | 
|  | 699 | ubleft = 0; | 
|  | 700 | ASSERT(error); | 
|  | 701 | rval = error; | 
|  | 702 | break; | 
|  | 703 | } | 
|  | 704 | if (ubufp) | 
|  | 705 | ubufp += ubused; | 
|  | 706 | ubleft -= ubused; | 
|  | 707 | ubelem++; | 
|  | 708 | lastino = ino; | 
|  | 709 | } | 
| Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 710 |  | 
|  | 711 | cond_resched(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | } | 
|  | 713 |  | 
|  | 714 | if (bp) | 
|  | 715 | xfs_buf_relse(bp); | 
|  | 716 |  | 
|  | 717 | /* | 
|  | 718 | * Set up for the next loop iteration. | 
|  | 719 | */ | 
| Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 720 | if (XFS_BULKSTAT_UBLEFT(ubleft)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | if (end_of_ag) { | 
|  | 722 | agno++; | 
|  | 723 | agino = 0; | 
| Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 724 | } else | 
|  | 725 | agino = XFS_INO_TO_AGINO(mp, lastino); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | } else | 
|  | 727 | break; | 
|  | 728 | } | 
|  | 729 | /* | 
|  | 730 | * Done, we're either out of filesystem or space to put the data. | 
|  | 731 | */ | 
| Denys Vlasenko | f0e2d93 | 2008-05-19 16:31:57 +1000 | [diff] [blame] | 732 | kmem_free(irbuf); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | *ubcountp = ubelem; | 
| Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 734 | /* | 
|  | 735 | * Found some inodes, return them now and return the error next time. | 
|  | 736 | */ | 
|  | 737 | if (ubelem) | 
|  | 738 | rval = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | if (agno >= mp->m_sb.sb_agcount) { | 
|  | 740 | /* | 
|  | 741 | * If we ran out of filesystem, mark lastino as off | 
|  | 742 | * the end of the filesystem, so the next call | 
|  | 743 | * will return immediately. | 
|  | 744 | */ | 
|  | 745 | *lastinop = (xfs_ino_t)XFS_AGINO_TO_INO(mp, agno, 0); | 
|  | 746 | *done = 1; | 
|  | 747 | } else | 
|  | 748 | *lastinop = (xfs_ino_t)lastino; | 
|  | 749 |  | 
|  | 750 | return rval; | 
|  | 751 | } | 
|  | 752 |  | 
|  | 753 | /* | 
|  | 754 | * Return stat information in bulk (by-inode) for the filesystem. | 
|  | 755 | * Special case for non-sequential one inode bulkstat. | 
|  | 756 | */ | 
|  | 757 | int					/* error status */ | 
|  | 758 | xfs_bulkstat_single( | 
|  | 759 | xfs_mount_t		*mp,	/* mount point for filesystem */ | 
|  | 760 | xfs_ino_t		*lastinop, /* inode to return */ | 
|  | 761 | char			__user *buffer, /* buffer with inode stats */ | 
| Nathan Scott | c41564b | 2006-03-29 08:55:14 +1000 | [diff] [blame] | 762 | int			*done)	/* 1 if there are more stats to get */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | { | 
|  | 764 | int			count;	/* count value for bulkstat call */ | 
|  | 765 | int			error;	/* return value */ | 
|  | 766 | xfs_ino_t		ino;	/* filesystem inode number */ | 
|  | 767 | int			res;	/* result from bs1 */ | 
|  | 768 |  | 
|  | 769 | /* | 
|  | 770 | * note that requesting valid inode numbers which are not allocated | 
|  | 771 | * to inodes will most likely cause xfs_itobp to generate warning | 
|  | 772 | * messages about bad magic numbers. This is ok. The fact that | 
|  | 773 | * the inode isn't actually an inode is handled by the | 
|  | 774 | * error check below. Done this way to make the usual case faster | 
|  | 775 | * at the expense of the error case. | 
|  | 776 | */ | 
|  | 777 |  | 
|  | 778 | ino = (xfs_ino_t)*lastinop; | 
|  | 779 | error = xfs_bulkstat_one(mp, ino, buffer, sizeof(xfs_bstat_t), | 
|  | 780 | NULL, 0, NULL, NULL, &res); | 
|  | 781 | if (error) { | 
|  | 782 | /* | 
|  | 783 | * Special case way failed, do it the "long" way | 
|  | 784 | * to see if that works. | 
|  | 785 | */ | 
|  | 786 | (*lastinop)--; | 
|  | 787 | count = 1; | 
|  | 788 | if (xfs_bulkstat(mp, lastinop, &count, xfs_bulkstat_one, | 
|  | 789 | NULL, sizeof(xfs_bstat_t), buffer, | 
|  | 790 | BULKSTAT_FG_IGET, done)) | 
|  | 791 | return error; | 
|  | 792 | if (count == 0 || (xfs_ino_t)*lastinop != ino) | 
|  | 793 | return error == EFSCORRUPTED ? | 
|  | 794 | XFS_ERROR(EINVAL) : error; | 
|  | 795 | else | 
|  | 796 | return 0; | 
|  | 797 | } | 
|  | 798 | *done = 0; | 
|  | 799 | return 0; | 
|  | 800 | } | 
|  | 801 |  | 
| Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 802 | int | 
|  | 803 | xfs_inumbers_fmt( | 
|  | 804 | void			__user *ubuffer, /* buffer to write to */ | 
|  | 805 | const xfs_inogrp_t	*buffer,	/* buffer to read from */ | 
|  | 806 | long			count,		/* # of elements to read */ | 
|  | 807 | long			*written)	/* # of bytes written */ | 
|  | 808 | { | 
|  | 809 | if (copy_to_user(ubuffer, buffer, count * sizeof(*buffer))) | 
|  | 810 | return -EFAULT; | 
|  | 811 | *written = count * sizeof(*buffer); | 
|  | 812 | return 0; | 
|  | 813 | } | 
|  | 814 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | /* | 
|  | 816 | * Return inode number table for the filesystem. | 
|  | 817 | */ | 
|  | 818 | int					/* error status */ | 
|  | 819 | xfs_inumbers( | 
|  | 820 | xfs_mount_t	*mp,		/* mount point for filesystem */ | 
|  | 821 | xfs_ino_t	*lastino,	/* last inode returned */ | 
|  | 822 | int		*count,		/* size of buffer/count returned */ | 
| Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 823 | void		__user *ubuffer,/* buffer with inode descriptions */ | 
|  | 824 | inumbers_fmt_pf	formatter) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | { | 
|  | 826 | xfs_buf_t	*agbp; | 
|  | 827 | xfs_agino_t	agino; | 
|  | 828 | xfs_agnumber_t	agno; | 
|  | 829 | int		bcount; | 
|  | 830 | xfs_inogrp_t	*buffer; | 
|  | 831 | int		bufidx; | 
|  | 832 | xfs_btree_cur_t	*cur; | 
|  | 833 | int		error; | 
| Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 834 | xfs_inobt_rec_incore_t r; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | int		i; | 
|  | 836 | xfs_ino_t	ino; | 
|  | 837 | int		left; | 
|  | 838 | int		tmp; | 
|  | 839 |  | 
|  | 840 | ino = (xfs_ino_t)*lastino; | 
|  | 841 | agno = XFS_INO_TO_AGNO(mp, ino); | 
|  | 842 | agino = XFS_INO_TO_AGINO(mp, ino); | 
|  | 843 | left = *count; | 
|  | 844 | *count = 0; | 
| Tim Shimmin | e6a4b37 | 2007-11-23 16:30:42 +1100 | [diff] [blame] | 845 | bcount = MIN(left, (int)(PAGE_SIZE / sizeof(*buffer))); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | buffer = kmem_alloc(bcount * sizeof(*buffer), KM_SLEEP); | 
|  | 847 | error = bufidx = 0; | 
|  | 848 | cur = NULL; | 
|  | 849 | agbp = NULL; | 
|  | 850 | while (left > 0 && agno < mp->m_sb.sb_agcount) { | 
|  | 851 | if (agbp == NULL) { | 
|  | 852 | down_read(&mp->m_peraglock); | 
|  | 853 | error = xfs_ialloc_read_agi(mp, NULL, agno, &agbp); | 
|  | 854 | up_read(&mp->m_peraglock); | 
|  | 855 | if (error) { | 
|  | 856 | /* | 
|  | 857 | * If we can't read the AGI of this ag, | 
|  | 858 | * then just skip to the next one. | 
|  | 859 | */ | 
|  | 860 | ASSERT(cur == NULL); | 
|  | 861 | agbp = NULL; | 
|  | 862 | agno++; | 
|  | 863 | agino = 0; | 
|  | 864 | continue; | 
|  | 865 | } | 
| Christoph Hellwig | 561f7d1 | 2008-10-30 16:53:59 +1100 | [diff] [blame] | 866 | cur = xfs_inobt_init_cursor(mp, NULL, agbp, agno); | 
| Christoph Hellwig | 2187550 | 2009-08-31 20:58:21 -0300 | [diff] [blame] | 867 | error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_GE, | 
|  | 868 | &tmp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | if (error) { | 
|  | 870 | xfs_btree_del_cursor(cur, XFS_BTREE_ERROR); | 
|  | 871 | cur = NULL; | 
|  | 872 | xfs_buf_relse(agbp); | 
|  | 873 | agbp = NULL; | 
|  | 874 | /* | 
| Michael Opdenacker | 59c5159 | 2007-05-09 08:57:56 +0200 | [diff] [blame] | 875 | * Move up the last inode in the current | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | * chunk.  The lookup_ge will always get | 
|  | 877 | * us the first inode in the next chunk. | 
|  | 878 | */ | 
|  | 879 | agino += XFS_INODES_PER_CHUNK - 1; | 
|  | 880 | continue; | 
|  | 881 | } | 
|  | 882 | } | 
| Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 883 | error = xfs_inobt_get_rec(cur, &r, &i); | 
|  | 884 | if (error || i == 0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | xfs_buf_relse(agbp); | 
|  | 886 | agbp = NULL; | 
|  | 887 | xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR); | 
|  | 888 | cur = NULL; | 
|  | 889 | agno++; | 
|  | 890 | agino = 0; | 
|  | 891 | continue; | 
|  | 892 | } | 
| Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 893 | agino = r.ir_startino + XFS_INODES_PER_CHUNK - 1; | 
|  | 894 | buffer[bufidx].xi_startino = | 
|  | 895 | XFS_AGINO_TO_INO(mp, agno, r.ir_startino); | 
|  | 896 | buffer[bufidx].xi_alloccount = | 
|  | 897 | XFS_INODES_PER_CHUNK - r.ir_freecount; | 
|  | 898 | buffer[bufidx].xi_allocmask = ~r.ir_free; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | bufidx++; | 
|  | 900 | left--; | 
|  | 901 | if (bufidx == bcount) { | 
| Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 902 | long written; | 
|  | 903 | if (formatter(ubuffer, buffer, bufidx, &written)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | error = XFS_ERROR(EFAULT); | 
|  | 905 | break; | 
|  | 906 | } | 
| Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 907 | ubuffer += written; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | *count += bufidx; | 
|  | 909 | bufidx = 0; | 
|  | 910 | } | 
|  | 911 | if (left) { | 
| Christoph Hellwig | 637aa50 | 2008-10-30 16:55:45 +1100 | [diff] [blame] | 912 | error = xfs_btree_increment(cur, 0, &tmp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | if (error) { | 
|  | 914 | xfs_btree_del_cursor(cur, XFS_BTREE_ERROR); | 
|  | 915 | cur = NULL; | 
|  | 916 | xfs_buf_relse(agbp); | 
|  | 917 | agbp = NULL; | 
|  | 918 | /* | 
|  | 919 | * The agino value has already been bumped. | 
|  | 920 | * Just try to skip up to it. | 
|  | 921 | */ | 
|  | 922 | agino += XFS_INODES_PER_CHUNK; | 
|  | 923 | continue; | 
|  | 924 | } | 
|  | 925 | } | 
|  | 926 | } | 
|  | 927 | if (!error) { | 
|  | 928 | if (bufidx) { | 
| Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 929 | long written; | 
|  | 930 | if (formatter(ubuffer, buffer, bufidx, &written)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | error = XFS_ERROR(EFAULT); | 
|  | 932 | else | 
|  | 933 | *count += bufidx; | 
|  | 934 | } | 
|  | 935 | *lastino = XFS_AGINO_TO_INO(mp, agno, agino); | 
|  | 936 | } | 
| Denys Vlasenko | f0e2d93 | 2008-05-19 16:31:57 +1000 | [diff] [blame] | 937 | kmem_free(buffer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | if (cur) | 
|  | 939 | xfs_btree_del_cursor(cur, (error ? XFS_BTREE_ERROR : | 
|  | 940 | XFS_BTREE_NOERROR)); | 
|  | 941 | if (agbp) | 
|  | 942 | xfs_buf_relse(agbp); | 
|  | 943 | return error; | 
|  | 944 | } |