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_mount.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include "xfs_bmap_btree.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 29 | #include "xfs_alloc_btree.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include "xfs_ialloc_btree.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include "xfs_dinode.h" |
| 32 | #include "xfs_inode.h" |
| 33 | #include "xfs_ialloc.h" |
| 34 | #include "xfs_itable.h" |
| 35 | #include "xfs_error.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 36 | #include "xfs_btree.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
Eric Sandeen | d96f8f8 | 2009-07-02 00:09:33 -0500 | [diff] [blame] | 38 | STATIC int |
Vlad Apostolov | 6f1f216 | 2006-09-28 11:06:15 +1000 | [diff] [blame] | 39 | xfs_internal_inum( |
| 40 | xfs_mount_t *mp, |
| 41 | xfs_ino_t ino) |
| 42 | { |
| 43 | 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] | 44 | (xfs_sb_version_hasquota(&mp->m_sb) && |
Vlad Apostolov | 6f1f216 | 2006-09-28 11:06:15 +1000 | [diff] [blame] | 45 | (ino == mp->m_sb.sb_uquotino || ino == mp->m_sb.sb_gquotino))); |
| 46 | } |
| 47 | |
Christoph Hellwig | 7dce11d | 2010-06-23 18:11:11 +1000 | [diff] [blame] | 48 | /* |
| 49 | * Return stat information for one inode. |
| 50 | * Return 0 if ok, else errno. |
| 51 | */ |
| 52 | int |
| 53 | xfs_bulkstat_one_int( |
| 54 | struct xfs_mount *mp, /* mount point for filesystem */ |
| 55 | xfs_ino_t ino, /* inode to get data for */ |
| 56 | void __user *buffer, /* buffer to place output in */ |
| 57 | int ubsize, /* size of buffer */ |
| 58 | bulkstat_one_fmt_pf formatter, /* formatter, copy to user */ |
Christoph Hellwig | 7dce11d | 2010-06-23 18:11:11 +1000 | [diff] [blame] | 59 | int *ubused, /* bytes used by me */ |
| 60 | int *stat) /* BULKSTAT_RV_... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | { |
Christoph Hellwig | 7dce11d | 2010-06-23 18:11:11 +1000 | [diff] [blame] | 62 | struct xfs_icdinode *dic; /* dinode core info pointer */ |
| 63 | struct xfs_inode *ip; /* incore inode pointer */ |
| 64 | struct inode *inode; |
| 65 | struct xfs_bstat *buf; /* return buffer */ |
| 66 | int error = 0; /* error value */ |
| 67 | |
| 68 | *stat = BULKSTAT_RV_NOTHING; |
| 69 | |
| 70 | if (!buffer || xfs_internal_inum(mp, ino)) |
| 71 | return XFS_ERROR(EINVAL); |
| 72 | |
| 73 | buf = kmem_alloc(sizeof(*buf), KM_SLEEP | KM_MAYFAIL); |
| 74 | if (!buf) |
| 75 | return XFS_ERROR(ENOMEM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
Nathan Scott | 745b1f47 | 2006-09-28 11:02:23 +1000 | [diff] [blame] | 77 | error = xfs_iget(mp, NULL, ino, |
Dave Chinner | 7b6259e | 2010-06-24 11:35:17 +1000 | [diff] [blame] | 78 | XFS_IGET_UNTRUSTED, XFS_ILOCK_SHARED, &ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | if (error) { |
| 80 | *stat = BULKSTAT_RV_NOTHING; |
Christoph Hellwig | 7dce11d | 2010-06-23 18:11:11 +1000 | [diff] [blame] | 81 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | ASSERT(ip != NULL); |
Christoph Hellwig | 92bfc6e | 2008-11-28 14:23:41 +1100 | [diff] [blame] | 85 | ASSERT(ip->i_imap.im_blkno != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
| 87 | dic = &ip->i_d; |
Christoph Hellwig | f9581b1 | 2009-10-06 20:29:26 +0000 | [diff] [blame] | 88 | inode = VFS_I(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
| 90 | /* xfs_iget returns the following without needing |
| 91 | * further change. |
| 92 | */ |
| 93 | buf->bs_nlink = dic->di_nlink; |
| 94 | buf->bs_projid = dic->di_projid; |
| 95 | buf->bs_ino = ino; |
| 96 | buf->bs_mode = dic->di_mode; |
| 97 | buf->bs_uid = dic->di_uid; |
| 98 | buf->bs_gid = dic->di_gid; |
| 99 | buf->bs_size = dic->di_size; |
Christoph Hellwig | f9581b1 | 2009-10-06 20:29:26 +0000 | [diff] [blame] | 100 | |
Christoph Hellwig | 8fab451 | 2009-03-16 08:24:46 +0100 | [diff] [blame] | 101 | /* |
Christoph Hellwig | f9581b1 | 2009-10-06 20:29:26 +0000 | [diff] [blame] | 102 | * We need to read the timestamps from the Linux inode because |
| 103 | * the VFS keeps writing directly into the inode structure instead |
| 104 | * of telling us about the updates. |
Christoph Hellwig | 8fab451 | 2009-03-16 08:24:46 +0100 | [diff] [blame] | 105 | */ |
Christoph Hellwig | f9581b1 | 2009-10-06 20:29:26 +0000 | [diff] [blame] | 106 | buf->bs_atime.tv_sec = inode->i_atime.tv_sec; |
| 107 | buf->bs_atime.tv_nsec = inode->i_atime.tv_nsec; |
| 108 | buf->bs_mtime.tv_sec = inode->i_mtime.tv_sec; |
| 109 | buf->bs_mtime.tv_nsec = inode->i_mtime.tv_nsec; |
| 110 | buf->bs_ctime.tv_sec = inode->i_ctime.tv_sec; |
| 111 | buf->bs_ctime.tv_nsec = inode->i_ctime.tv_nsec; |
| 112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | buf->bs_xflags = xfs_ip2xflags(ip); |
| 114 | buf->bs_extsize = dic->di_extsize << mp->m_sb.sb_blocklog; |
| 115 | buf->bs_extents = dic->di_nextents; |
| 116 | buf->bs_gen = dic->di_gen; |
| 117 | memset(buf->bs_pad, 0, sizeof(buf->bs_pad)); |
| 118 | buf->bs_dmevmask = dic->di_dmevmask; |
| 119 | buf->bs_dmstate = dic->di_dmstate; |
| 120 | buf->bs_aextents = dic->di_anextents; |
Dave Chinner | 07000ee | 2010-03-05 04:41:14 +0000 | [diff] [blame] | 121 | buf->bs_forkoff = XFS_IFORK_BOFF(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
| 123 | switch (dic->di_format) { |
| 124 | case XFS_DINODE_FMT_DEV: |
| 125 | buf->bs_rdev = ip->i_df.if_u2.if_rdev; |
| 126 | buf->bs_blksize = BLKDEV_IOSIZE; |
| 127 | buf->bs_blocks = 0; |
| 128 | break; |
| 129 | case XFS_DINODE_FMT_LOCAL: |
| 130 | case XFS_DINODE_FMT_UUID: |
| 131 | buf->bs_rdev = 0; |
| 132 | buf->bs_blksize = mp->m_sb.sb_blocksize; |
| 133 | buf->bs_blocks = 0; |
| 134 | break; |
| 135 | case XFS_DINODE_FMT_EXTENTS: |
| 136 | case XFS_DINODE_FMT_BTREE: |
| 137 | buf->bs_rdev = 0; |
| 138 | buf->bs_blksize = mp->m_sb.sb_blocksize; |
| 139 | buf->bs_blocks = dic->di_nblocks + ip->i_delayed_blks; |
| 140 | break; |
| 141 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | xfs_iput(ip, XFS_ILOCK_SHARED); |
Christoph Hellwig | 7dce11d | 2010-06-23 18:11:11 +1000 | [diff] [blame] | 143 | |
| 144 | error = formatter(buffer, ubsize, ubused, buf); |
| 145 | |
| 146 | if (!error) |
| 147 | *stat = BULKSTAT_RV_DIDONE; |
| 148 | |
| 149 | out_free: |
| 150 | kmem_free(buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | return error; |
| 152 | } |
| 153 | |
sandeen@sandeen.net | 65fbaf2 | 2008-11-25 21:20:12 -0600 | [diff] [blame] | 154 | /* Return 0 on success or positive error */ |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 155 | STATIC int |
| 156 | xfs_bulkstat_one_fmt( |
| 157 | void __user *ubuffer, |
sandeen@sandeen.net | 65fbaf2 | 2008-11-25 21:20:12 -0600 | [diff] [blame] | 158 | int ubsize, |
| 159 | int *ubused, |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 160 | const xfs_bstat_t *buffer) |
| 161 | { |
sandeen@sandeen.net | 65fbaf2 | 2008-11-25 21:20:12 -0600 | [diff] [blame] | 162 | if (ubsize < sizeof(*buffer)) |
| 163 | return XFS_ERROR(ENOMEM); |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 164 | if (copy_to_user(ubuffer, buffer, sizeof(*buffer))) |
sandeen@sandeen.net | 65fbaf2 | 2008-11-25 21:20:12 -0600 | [diff] [blame] | 165 | return XFS_ERROR(EFAULT); |
| 166 | if (ubused) |
| 167 | *ubused = sizeof(*buffer); |
| 168 | return 0; |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 169 | } |
| 170 | |
sandeen@sandeen.net | 2ee4fa5 | 2008-11-25 21:20:11 -0600 | [diff] [blame] | 171 | int |
| 172 | xfs_bulkstat_one( |
| 173 | xfs_mount_t *mp, /* mount point for filesystem */ |
| 174 | xfs_ino_t ino, /* inode number to get data for */ |
| 175 | void __user *buffer, /* buffer to place output in */ |
| 176 | int ubsize, /* size of buffer */ |
sandeen@sandeen.net | 2ee4fa5 | 2008-11-25 21:20:11 -0600 | [diff] [blame] | 177 | int *ubused, /* bytes used by me */ |
sandeen@sandeen.net | 2ee4fa5 | 2008-11-25 21:20:11 -0600 | [diff] [blame] | 178 | int *stat) /* BULKSTAT_RV_... */ |
| 179 | { |
| 180 | return xfs_bulkstat_one_int(mp, ino, buffer, ubsize, |
Dave Chinner | 7b6259e | 2010-06-24 11:35:17 +1000 | [diff] [blame] | 181 | xfs_bulkstat_one_fmt, ubused, stat); |
Nathan Scott | 8b56f08 | 2006-09-28 11:01:46 +1000 | [diff] [blame] | 182 | } |
| 183 | |
Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 184 | #define XFS_BULKSTAT_UBLEFT(ubleft) ((ubleft) >= statstruct_size) |
| 185 | |
Nathan Scott | 8b56f08 | 2006-09-28 11:01:46 +1000 | [diff] [blame] | 186 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | * Return stat information in bulk (by-inode) for the filesystem. |
| 188 | */ |
| 189 | int /* error status */ |
| 190 | xfs_bulkstat( |
| 191 | xfs_mount_t *mp, /* mount point for filesystem */ |
| 192 | xfs_ino_t *lastinop, /* last inode returned */ |
| 193 | int *ubcountp, /* size of buffer/count returned */ |
| 194 | bulkstat_one_pf formatter, /* func that'd fill a single buf */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | size_t statstruct_size, /* sizeof struct filling */ |
| 196 | char __user *ubuffer, /* buffer with inode stats */ |
Nathan Scott | c41564b | 2006-03-29 08:55:14 +1000 | [diff] [blame] | 197 | int *done) /* 1 if there are more stats to get */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | { |
| 199 | xfs_agblock_t agbno=0;/* allocation group block number */ |
| 200 | xfs_buf_t *agbp; /* agi header buffer */ |
| 201 | xfs_agi_t *agi; /* agi header data */ |
| 202 | xfs_agino_t agino; /* inode # in allocation group */ |
| 203 | xfs_agnumber_t agno; /* allocation group number */ |
| 204 | xfs_daddr_t bno; /* inode cluster start daddr */ |
| 205 | int chunkidx; /* current index into inode chunk */ |
| 206 | int clustidx; /* current index into inode cluster */ |
| 207 | xfs_btree_cur_t *cur; /* btree cursor for ialloc btree */ |
| 208 | int end_of_ag; /* set if we've seen the ag end */ |
| 209 | int error; /* error code */ |
| 210 | int fmterror;/* bulkstat formatter result */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | int i; /* loop index */ |
| 212 | int icount; /* count of inodes good in irbuf */ |
Nathan Scott | 215101c | 2006-09-28 11:04:43 +1000 | [diff] [blame] | 213 | size_t irbsize; /* size of irec buffer in bytes */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | xfs_ino_t ino; /* inode number (filesystem) */ |
Nathan Scott | 26275093 | 2006-09-28 11:02:03 +1000 | [diff] [blame] | 215 | xfs_inobt_rec_incore_t *irbp; /* current irec buffer pointer */ |
| 216 | xfs_inobt_rec_incore_t *irbuf; /* start of irec buffer */ |
| 217 | xfs_inobt_rec_incore_t *irbufend; /* end of good irec buffer entries */ |
Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 218 | xfs_ino_t lastino; /* last inode number returned */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | int nbcluster; /* # of blocks in a cluster */ |
| 220 | int nicluster; /* # of inodes in a cluster */ |
| 221 | int nimask; /* mask for inode clusters */ |
| 222 | int nirbuf; /* size of irbuf */ |
| 223 | int rval; /* return value error code */ |
| 224 | int tmp; /* result value from btree calls */ |
| 225 | int ubcount; /* size of user's buffer */ |
| 226 | int ubleft; /* bytes left in user's buffer */ |
| 227 | char __user *ubufp; /* pointer into user's buffer */ |
| 228 | int ubelem; /* spaces used in user's buffer */ |
| 229 | int ubused; /* bytes used by formatter */ |
| 230 | xfs_buf_t *bp; /* ptr to on-disk inode cluster buf */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | |
| 232 | /* |
| 233 | * Get the last inode value, see if there's nothing to do. |
| 234 | */ |
| 235 | ino = (xfs_ino_t)*lastinop; |
Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 236 | lastino = ino; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | agno = XFS_INO_TO_AGNO(mp, ino); |
| 238 | agino = XFS_INO_TO_AGINO(mp, ino); |
| 239 | if (agno >= mp->m_sb.sb_agcount || |
| 240 | ino != XFS_AGINO_TO_INO(mp, agno, agino)) { |
| 241 | *done = 1; |
| 242 | *ubcountp = 0; |
| 243 | return 0; |
| 244 | } |
Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 245 | if (!ubcountp || *ubcountp <= 0) { |
| 246 | return EINVAL; |
| 247 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | ubcount = *ubcountp; /* statstruct's */ |
| 249 | ubleft = ubcount * statstruct_size; /* bytes */ |
| 250 | *ubcountp = ubelem = 0; |
| 251 | *done = 0; |
| 252 | fmterror = 0; |
| 253 | ubufp = ubuffer; |
| 254 | nicluster = mp->m_sb.sb_blocksize >= XFS_INODE_CLUSTER_SIZE(mp) ? |
| 255 | mp->m_sb.sb_inopblock : |
| 256 | (XFS_INODE_CLUSTER_SIZE(mp) >> mp->m_sb.sb_inodelog); |
| 257 | nimask = ~(nicluster - 1); |
| 258 | nbcluster = nicluster >> mp->m_sb.sb_inopblog; |
Christoph Hellwig | bdfb043 | 2010-01-20 21:55:30 +0000 | [diff] [blame] | 259 | irbuf = kmem_zalloc_greedy(&irbsize, PAGE_SIZE, PAGE_SIZE * 4); |
| 260 | if (!irbuf) |
| 261 | return ENOMEM; |
| 262 | |
Nathan Scott | bb3c7d2 | 2006-09-28 11:02:09 +1000 | [diff] [blame] | 263 | nirbuf = irbsize / sizeof(*irbuf); |
| 264 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | /* |
| 266 | * Loop over the allocation groups, starting from the last |
| 267 | * inode returned; 0 means start of the allocation group. |
| 268 | */ |
| 269 | rval = 0; |
Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 270 | while (XFS_BULKSTAT_UBLEFT(ubleft) && agno < mp->m_sb.sb_agcount) { |
| 271 | cond_resched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | bp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | error = xfs_ialloc_read_agi(mp, NULL, agno, &agbp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | if (error) { |
| 275 | /* |
| 276 | * Skip this allocation group and go to the next one. |
| 277 | */ |
| 278 | agno++; |
| 279 | agino = 0; |
| 280 | continue; |
| 281 | } |
| 282 | agi = XFS_BUF_TO_AGI(agbp); |
| 283 | /* |
| 284 | * Allocate and initialize a btree cursor for ialloc btree. |
| 285 | */ |
Christoph Hellwig | 561f7d1 | 2008-10-30 16:53:59 +1100 | [diff] [blame] | 286 | cur = xfs_inobt_init_cursor(mp, NULL, agbp, agno); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | irbp = irbuf; |
| 288 | irbufend = irbuf + nirbuf; |
| 289 | end_of_ag = 0; |
| 290 | /* |
| 291 | * If we're returning in the middle of an allocation group, |
| 292 | * we need to get the remainder of the chunk we're in. |
| 293 | */ |
| 294 | if (agino > 0) { |
Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 295 | xfs_inobt_rec_incore_t r; |
| 296 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | /* |
| 298 | * Lookup the inode chunk that this inode lives in. |
| 299 | */ |
Christoph Hellwig | 2187550 | 2009-08-31 20:58:21 -0300 | [diff] [blame] | 300 | error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_LE, |
| 301 | &tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | if (!error && /* no I/O error */ |
| 303 | tmp && /* lookup succeeded */ |
| 304 | /* got the record, should always work */ |
Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 305 | !(error = xfs_inobt_get_rec(cur, &r, &i)) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | i == 1 && |
| 307 | /* this is the right chunk */ |
Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 308 | agino < r.ir_startino + XFS_INODES_PER_CHUNK && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | /* lastino was not last in chunk */ |
Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 310 | (chunkidx = agino - r.ir_startino + 1) < |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | XFS_INODES_PER_CHUNK && |
| 312 | /* there are some left allocated */ |
Eric Sandeen | 9d87c31 | 2009-01-14 23:22:07 -0600 | [diff] [blame] | 313 | xfs_inobt_maskn(chunkidx, |
Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 314 | XFS_INODES_PER_CHUNK - chunkidx) & |
| 315 | ~r.ir_free) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | /* |
| 317 | * Grab the chunk record. Mark all the |
| 318 | * uninteresting inodes (because they're |
| 319 | * before our start point) free. |
| 320 | */ |
| 321 | for (i = 0; i < chunkidx; i++) { |
Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 322 | if (XFS_INOBT_MASK(i) & ~r.ir_free) |
| 323 | r.ir_freecount++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | } |
Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 325 | r.ir_free |= xfs_inobt_maskn(0, chunkidx); |
| 326 | irbp->ir_startino = r.ir_startino; |
| 327 | irbp->ir_freecount = r.ir_freecount; |
| 328 | irbp->ir_free = r.ir_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | irbp++; |
Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 330 | agino = r.ir_startino + XFS_INODES_PER_CHUNK; |
| 331 | icount = XFS_INODES_PER_CHUNK - r.ir_freecount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | } else { |
| 333 | /* |
| 334 | * If any of those tests failed, bump the |
| 335 | * inode number (just in case). |
| 336 | */ |
| 337 | agino++; |
| 338 | icount = 0; |
| 339 | } |
| 340 | /* |
| 341 | * In any case, increment to the next record. |
| 342 | */ |
| 343 | if (!error) |
Christoph Hellwig | 637aa50 | 2008-10-30 16:55:45 +1100 | [diff] [blame] | 344 | error = xfs_btree_increment(cur, 0, &tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | } else { |
| 346 | /* |
| 347 | * Start of ag. Lookup the first inode chunk. |
| 348 | */ |
Christoph Hellwig | 2187550 | 2009-08-31 20:58:21 -0300 | [diff] [blame] | 349 | error = xfs_inobt_lookup(cur, 0, XFS_LOOKUP_GE, &tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | icount = 0; |
| 351 | } |
| 352 | /* |
| 353 | * Loop through inode btree records in this ag, |
| 354 | * until we run out of inodes or space in the buffer. |
| 355 | */ |
| 356 | while (irbp < irbufend && icount < ubcount) { |
Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 357 | xfs_inobt_rec_incore_t r; |
| 358 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | /* |
| 360 | * Loop as long as we're unable to read the |
| 361 | * inode btree. |
| 362 | */ |
| 363 | while (error) { |
| 364 | agino += XFS_INODES_PER_CHUNK; |
| 365 | if (XFS_AGINO_TO_AGBNO(mp, agino) >= |
Christoph Hellwig | 16259e7 | 2005-11-02 15:11:25 +1100 | [diff] [blame] | 366 | be32_to_cpu(agi->agi_length)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | break; |
Christoph Hellwig | 2187550 | 2009-08-31 20:58:21 -0300 | [diff] [blame] | 368 | error = xfs_inobt_lookup(cur, agino, |
| 369 | XFS_LOOKUP_GE, &tmp); |
Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 370 | cond_resched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | } |
| 372 | /* |
| 373 | * If ran off the end of the ag either with an error, |
| 374 | * or the normal way, set end and stop collecting. |
| 375 | */ |
Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 376 | if (error) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | end_of_ag = 1; |
| 378 | break; |
| 379 | } |
Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 380 | |
| 381 | error = xfs_inobt_get_rec(cur, &r, &i); |
| 382 | if (error || i == 0) { |
| 383 | end_of_ag = 1; |
| 384 | break; |
| 385 | } |
| 386 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | /* |
| 388 | * If this chunk has any allocated inodes, save it. |
Nathan Scott | 26275093 | 2006-09-28 11:02:03 +1000 | [diff] [blame] | 389 | * Also start read-ahead now for this chunk. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | */ |
Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 391 | if (r.ir_freecount < XFS_INODES_PER_CHUNK) { |
Nathan Scott | 26275093 | 2006-09-28 11:02:03 +1000 | [diff] [blame] | 392 | /* |
| 393 | * Loop over all clusters in the next chunk. |
| 394 | * Do a readahead if there are any allocated |
| 395 | * inodes in that cluster. |
| 396 | */ |
Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 397 | agbno = XFS_AGINO_TO_AGBNO(mp, r.ir_startino); |
| 398 | for (chunkidx = 0; |
Nathan Scott | 26275093 | 2006-09-28 11:02:03 +1000 | [diff] [blame] | 399 | chunkidx < XFS_INODES_PER_CHUNK; |
| 400 | chunkidx += nicluster, |
| 401 | agbno += nbcluster) { |
Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 402 | if (xfs_inobt_maskn(chunkidx, nicluster) |
| 403 | & ~r.ir_free) |
Nathan Scott | 26275093 | 2006-09-28 11:02:03 +1000 | [diff] [blame] | 404 | xfs_btree_reada_bufs(mp, agno, |
| 405 | agbno, nbcluster); |
| 406 | } |
Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 407 | irbp->ir_startino = r.ir_startino; |
| 408 | irbp->ir_freecount = r.ir_freecount; |
| 409 | irbp->ir_free = r.ir_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | irbp++; |
Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 411 | icount += XFS_INODES_PER_CHUNK - r.ir_freecount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | } |
| 413 | /* |
| 414 | * Set agino to after this chunk and bump the cursor. |
| 415 | */ |
Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 416 | agino = r.ir_startino + XFS_INODES_PER_CHUNK; |
Christoph Hellwig | 637aa50 | 2008-10-30 16:55:45 +1100 | [diff] [blame] | 417 | error = xfs_btree_increment(cur, 0, &tmp); |
Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 418 | cond_resched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | } |
| 420 | /* |
| 421 | * Drop the btree buffers and the agi buffer. |
| 422 | * We can't hold any of the locks these represent |
| 423 | * when calling iget. |
| 424 | */ |
| 425 | xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR); |
| 426 | xfs_buf_relse(agbp); |
| 427 | /* |
| 428 | * Now format all the good inodes into the user's buffer. |
| 429 | */ |
| 430 | irbufend = irbp; |
| 431 | for (irbp = irbuf; |
Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 432 | irbp < irbufend && XFS_BULKSTAT_UBLEFT(ubleft); irbp++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | * Now process this chunk of inodes. |
| 435 | */ |
Nathan Scott | 26275093 | 2006-09-28 11:02:03 +1000 | [diff] [blame] | 436 | for (agino = irbp->ir_startino, chunkidx = clustidx = 0; |
Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 437 | XFS_BULKSTAT_UBLEFT(ubleft) && |
Nathan Scott | 26275093 | 2006-09-28 11:02:03 +1000 | [diff] [blame] | 438 | irbp->ir_freecount < XFS_INODES_PER_CHUNK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | chunkidx++, clustidx++, agino++) { |
| 440 | ASSERT(chunkidx < XFS_INODES_PER_CHUNK); |
| 441 | /* |
| 442 | * Recompute agbno if this is the |
| 443 | * first inode of the cluster. |
| 444 | * |
| 445 | * Careful with clustidx. There can be |
Malcolm Parsons | 9da096f | 2009-03-29 09:55:42 +0200 | [diff] [blame] | 446 | * multiple clusters per chunk, a single |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | * cluster per chunk or a cluster that has |
| 448 | * inodes represented from several different |
| 449 | * chunks (if blocksize is large). |
| 450 | * |
| 451 | * Because of this, the starting clustidx is |
| 452 | * initialized to zero in this loop but must |
| 453 | * later be reset after reading in the cluster |
| 454 | * buffer. |
| 455 | */ |
| 456 | if ((chunkidx & (nicluster - 1)) == 0) { |
| 457 | agbno = XFS_AGINO_TO_AGBNO(mp, |
Nathan Scott | 26275093 | 2006-09-28 11:02:03 +1000 | [diff] [blame] | 458 | irbp->ir_startino) + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | ((chunkidx & nimask) >> |
| 460 | mp->m_sb.sb_inopblog); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | } |
Lachlan McIlroy | c2cba57 | 2007-10-12 11:12:20 +1000 | [diff] [blame] | 462 | ino = XFS_AGINO_TO_INO(mp, agno, agino); |
| 463 | bno = XFS_AGB_TO_DADDR(mp, agno, agbno); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | /* |
| 465 | * Skip if this inode is free. |
| 466 | */ |
Lachlan McIlroy | c2cba57 | 2007-10-12 11:12:20 +1000 | [diff] [blame] | 467 | if (XFS_INOBT_MASK(chunkidx) & irbp->ir_free) { |
| 468 | lastino = ino; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | continue; |
Lachlan McIlroy | c2cba57 | 2007-10-12 11:12:20 +1000 | [diff] [blame] | 470 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | /* |
| 472 | * Count used inodes as free so we can tell |
| 473 | * when the chunk is used up. |
| 474 | */ |
Nathan Scott | 26275093 | 2006-09-28 11:02:03 +1000 | [diff] [blame] | 475 | irbp->ir_freecount++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | |
| 477 | /* |
| 478 | * Get the inode and fill in a single buffer. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | */ |
| 480 | ubused = statstruct_size; |
Dave Chinner | 7b6259e | 2010-06-24 11:35:17 +1000 | [diff] [blame] | 481 | error = formatter(mp, ino, ubufp, ubleft, |
Christoph Hellwig | 7dce11d | 2010-06-23 18:11:11 +1000 | [diff] [blame] | 482 | &ubused, &fmterror); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | if (fmterror == BULKSTAT_RV_NOTHING) { |
Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 484 | if (error && error != ENOENT && |
| 485 | error != EINVAL) { |
Vlad Apostolov | e132f54 | 2006-09-28 11:04:31 +1000 | [diff] [blame] | 486 | ubleft = 0; |
Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 487 | rval = error; |
| 488 | break; |
| 489 | } |
| 490 | lastino = ino; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | continue; |
| 492 | } |
| 493 | if (fmterror == BULKSTAT_RV_GIVEUP) { |
| 494 | ubleft = 0; |
| 495 | ASSERT(error); |
| 496 | rval = error; |
| 497 | break; |
| 498 | } |
| 499 | if (ubufp) |
| 500 | ubufp += ubused; |
| 501 | ubleft -= ubused; |
| 502 | ubelem++; |
| 503 | lastino = ino; |
| 504 | } |
Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 505 | |
| 506 | cond_resched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | if (bp) |
| 510 | xfs_buf_relse(bp); |
| 511 | |
| 512 | /* |
| 513 | * Set up for the next loop iteration. |
| 514 | */ |
Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 515 | if (XFS_BULKSTAT_UBLEFT(ubleft)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | if (end_of_ag) { |
| 517 | agno++; |
| 518 | agino = 0; |
Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 519 | } else |
| 520 | agino = XFS_INO_TO_AGINO(mp, lastino); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | } else |
| 522 | break; |
| 523 | } |
| 524 | /* |
| 525 | * Done, we're either out of filesystem or space to put the data. |
| 526 | */ |
Christoph Hellwig | bdfb043 | 2010-01-20 21:55:30 +0000 | [diff] [blame] | 527 | kmem_free_large(irbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | *ubcountp = ubelem; |
Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 529 | /* |
| 530 | * Found some inodes, return them now and return the error next time. |
| 531 | */ |
| 532 | if (ubelem) |
| 533 | rval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | if (agno >= mp->m_sb.sb_agcount) { |
| 535 | /* |
| 536 | * If we ran out of filesystem, mark lastino as off |
| 537 | * the end of the filesystem, so the next call |
| 538 | * will return immediately. |
| 539 | */ |
| 540 | *lastinop = (xfs_ino_t)XFS_AGINO_TO_INO(mp, agno, 0); |
| 541 | *done = 1; |
| 542 | } else |
| 543 | *lastinop = (xfs_ino_t)lastino; |
| 544 | |
| 545 | return rval; |
| 546 | } |
| 547 | |
| 548 | /* |
| 549 | * Return stat information in bulk (by-inode) for the filesystem. |
| 550 | * Special case for non-sequential one inode bulkstat. |
| 551 | */ |
| 552 | int /* error status */ |
| 553 | xfs_bulkstat_single( |
| 554 | xfs_mount_t *mp, /* mount point for filesystem */ |
| 555 | xfs_ino_t *lastinop, /* inode to return */ |
| 556 | char __user *buffer, /* buffer with inode stats */ |
Nathan Scott | c41564b | 2006-03-29 08:55:14 +1000 | [diff] [blame] | 557 | int *done) /* 1 if there are more stats to get */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | { |
| 559 | int count; /* count value for bulkstat call */ |
| 560 | int error; /* return value */ |
| 561 | xfs_ino_t ino; /* filesystem inode number */ |
| 562 | int res; /* result from bs1 */ |
| 563 | |
| 564 | /* |
| 565 | * note that requesting valid inode numbers which are not allocated |
| 566 | * to inodes will most likely cause xfs_itobp to generate warning |
| 567 | * messages about bad magic numbers. This is ok. The fact that |
| 568 | * the inode isn't actually an inode is handled by the |
| 569 | * error check below. Done this way to make the usual case faster |
| 570 | * at the expense of the error case. |
| 571 | */ |
| 572 | |
| 573 | ino = (xfs_ino_t)*lastinop; |
Dave Chinner | 7b6259e | 2010-06-24 11:35:17 +1000 | [diff] [blame] | 574 | error = xfs_bulkstat_one(mp, ino, buffer, sizeof(xfs_bstat_t), 0, &res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | if (error) { |
| 576 | /* |
| 577 | * Special case way failed, do it the "long" way |
| 578 | * to see if that works. |
| 579 | */ |
| 580 | (*lastinop)--; |
| 581 | count = 1; |
| 582 | if (xfs_bulkstat(mp, lastinop, &count, xfs_bulkstat_one, |
Christoph Hellwig | 7dce11d | 2010-06-23 18:11:11 +1000 | [diff] [blame] | 583 | sizeof(xfs_bstat_t), buffer, done)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | return error; |
| 585 | if (count == 0 || (xfs_ino_t)*lastinop != ino) |
| 586 | return error == EFSCORRUPTED ? |
| 587 | XFS_ERROR(EINVAL) : error; |
| 588 | else |
| 589 | return 0; |
| 590 | } |
| 591 | *done = 0; |
| 592 | return 0; |
| 593 | } |
| 594 | |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 595 | int |
| 596 | xfs_inumbers_fmt( |
| 597 | void __user *ubuffer, /* buffer to write to */ |
| 598 | const xfs_inogrp_t *buffer, /* buffer to read from */ |
| 599 | long count, /* # of elements to read */ |
| 600 | long *written) /* # of bytes written */ |
| 601 | { |
| 602 | if (copy_to_user(ubuffer, buffer, count * sizeof(*buffer))) |
| 603 | return -EFAULT; |
| 604 | *written = count * sizeof(*buffer); |
| 605 | return 0; |
| 606 | } |
| 607 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | /* |
| 609 | * Return inode number table for the filesystem. |
| 610 | */ |
| 611 | int /* error status */ |
| 612 | xfs_inumbers( |
| 613 | xfs_mount_t *mp, /* mount point for filesystem */ |
| 614 | xfs_ino_t *lastino, /* last inode returned */ |
| 615 | int *count, /* size of buffer/count returned */ |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 616 | void __user *ubuffer,/* buffer with inode descriptions */ |
| 617 | inumbers_fmt_pf formatter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | { |
| 619 | xfs_buf_t *agbp; |
| 620 | xfs_agino_t agino; |
| 621 | xfs_agnumber_t agno; |
| 622 | int bcount; |
| 623 | xfs_inogrp_t *buffer; |
| 624 | int bufidx; |
| 625 | xfs_btree_cur_t *cur; |
| 626 | int error; |
Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 627 | xfs_inobt_rec_incore_t r; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | int i; |
| 629 | xfs_ino_t ino; |
| 630 | int left; |
| 631 | int tmp; |
| 632 | |
| 633 | ino = (xfs_ino_t)*lastino; |
| 634 | agno = XFS_INO_TO_AGNO(mp, ino); |
| 635 | agino = XFS_INO_TO_AGINO(mp, ino); |
| 636 | left = *count; |
| 637 | *count = 0; |
Tim Shimmin | e6a4b37 | 2007-11-23 16:30:42 +1100 | [diff] [blame] | 638 | bcount = MIN(left, (int)(PAGE_SIZE / sizeof(*buffer))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | buffer = kmem_alloc(bcount * sizeof(*buffer), KM_SLEEP); |
| 640 | error = bufidx = 0; |
| 641 | cur = NULL; |
| 642 | agbp = NULL; |
| 643 | while (left > 0 && agno < mp->m_sb.sb_agcount) { |
| 644 | if (agbp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | error = xfs_ialloc_read_agi(mp, NULL, agno, &agbp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | if (error) { |
| 647 | /* |
| 648 | * If we can't read the AGI of this ag, |
| 649 | * then just skip to the next one. |
| 650 | */ |
| 651 | ASSERT(cur == NULL); |
| 652 | agbp = NULL; |
| 653 | agno++; |
| 654 | agino = 0; |
| 655 | continue; |
| 656 | } |
Christoph Hellwig | 561f7d1 | 2008-10-30 16:53:59 +1100 | [diff] [blame] | 657 | cur = xfs_inobt_init_cursor(mp, NULL, agbp, agno); |
Christoph Hellwig | 2187550 | 2009-08-31 20:58:21 -0300 | [diff] [blame] | 658 | error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_GE, |
| 659 | &tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | if (error) { |
| 661 | xfs_btree_del_cursor(cur, XFS_BTREE_ERROR); |
| 662 | cur = NULL; |
| 663 | xfs_buf_relse(agbp); |
| 664 | agbp = NULL; |
| 665 | /* |
Michael Opdenacker | 59c5159 | 2007-05-09 08:57:56 +0200 | [diff] [blame] | 666 | * Move up the last inode in the current |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | * chunk. The lookup_ge will always get |
| 668 | * us the first inode in the next chunk. |
| 669 | */ |
| 670 | agino += XFS_INODES_PER_CHUNK - 1; |
| 671 | continue; |
| 672 | } |
| 673 | } |
Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 674 | error = xfs_inobt_get_rec(cur, &r, &i); |
| 675 | if (error || i == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | xfs_buf_relse(agbp); |
| 677 | agbp = NULL; |
| 678 | xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR); |
| 679 | cur = NULL; |
| 680 | agno++; |
| 681 | agino = 0; |
| 682 | continue; |
| 683 | } |
Christoph Hellwig | 2e287a7 | 2009-08-31 20:56:58 -0300 | [diff] [blame] | 684 | agino = r.ir_startino + XFS_INODES_PER_CHUNK - 1; |
| 685 | buffer[bufidx].xi_startino = |
| 686 | XFS_AGINO_TO_INO(mp, agno, r.ir_startino); |
| 687 | buffer[bufidx].xi_alloccount = |
| 688 | XFS_INODES_PER_CHUNK - r.ir_freecount; |
| 689 | buffer[bufidx].xi_allocmask = ~r.ir_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | bufidx++; |
| 691 | left--; |
| 692 | if (bufidx == bcount) { |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 693 | long written; |
| 694 | if (formatter(ubuffer, buffer, bufidx, &written)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | error = XFS_ERROR(EFAULT); |
| 696 | break; |
| 697 | } |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 698 | ubuffer += written; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | *count += bufidx; |
| 700 | bufidx = 0; |
| 701 | } |
| 702 | if (left) { |
Christoph Hellwig | 637aa50 | 2008-10-30 16:55:45 +1100 | [diff] [blame] | 703 | error = xfs_btree_increment(cur, 0, &tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | if (error) { |
| 705 | xfs_btree_del_cursor(cur, XFS_BTREE_ERROR); |
| 706 | cur = NULL; |
| 707 | xfs_buf_relse(agbp); |
| 708 | agbp = NULL; |
| 709 | /* |
| 710 | * The agino value has already been bumped. |
| 711 | * Just try to skip up to it. |
| 712 | */ |
| 713 | agino += XFS_INODES_PER_CHUNK; |
| 714 | continue; |
| 715 | } |
| 716 | } |
| 717 | } |
| 718 | if (!error) { |
| 719 | if (bufidx) { |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 720 | long written; |
| 721 | if (formatter(ubuffer, buffer, bufidx, &written)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | error = XFS_ERROR(EFAULT); |
| 723 | else |
| 724 | *count += bufidx; |
| 725 | } |
| 726 | *lastino = XFS_AGINO_TO_INO(mp, agno, agino); |
| 727 | } |
Denys Vlasenko | f0e2d93 | 2008-05-19 16:31:57 +1000 | [diff] [blame] | 728 | kmem_free(buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | if (cur) |
| 730 | xfs_btree_del_cursor(cur, (error ? XFS_BTREE_ERROR : |
| 731 | XFS_BTREE_NOERROR)); |
| 732 | if (agbp) |
| 733 | xfs_buf_relse(agbp); |
| 734 | return error; |
| 735 | } |