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