11da177e4SLinus Torvalds /* 27b718769SNathan Scott * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc. 37b718769SNathan Scott * All Rights Reserved. 41da177e4SLinus Torvalds * 57b718769SNathan Scott * This program is free software; you can redistribute it and/or 67b718769SNathan Scott * modify it under the terms of the GNU General Public License as 71da177e4SLinus Torvalds * published by the Free Software Foundation. 81da177e4SLinus Torvalds * 97b718769SNathan Scott * This program is distributed in the hope that it would be useful, 107b718769SNathan Scott * but WITHOUT ANY WARRANTY; without even the implied warranty of 117b718769SNathan Scott * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 127b718769SNathan Scott * GNU General Public License for more details. 131da177e4SLinus Torvalds * 147b718769SNathan Scott * You should have received a copy of the GNU General Public License 157b718769SNathan Scott * along with this program; if not, write the Free Software Foundation, 167b718769SNathan Scott * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 171da177e4SLinus Torvalds */ 181da177e4SLinus Torvalds #include "xfs.h" 19a844f451SNathan Scott #include "xfs_fs.h" 201da177e4SLinus Torvalds #include "xfs_types.h" 211da177e4SLinus Torvalds #include "xfs_log.h" 22a844f451SNathan Scott #include "xfs_inum.h" 231da177e4SLinus Torvalds #include "xfs_trans.h" 241da177e4SLinus Torvalds #include "xfs_sb.h" 25a844f451SNathan Scott #include "xfs_ag.h" 261da177e4SLinus Torvalds #include "xfs_mount.h" 271da177e4SLinus Torvalds #include "xfs_bmap_btree.h" 28a844f451SNathan Scott #include "xfs_alloc_btree.h" 291da177e4SLinus Torvalds #include "xfs_ialloc_btree.h" 301da177e4SLinus Torvalds #include "xfs_dinode.h" 311da177e4SLinus Torvalds #include "xfs_inode.h" 321da177e4SLinus Torvalds #include "xfs_ialloc.h" 331da177e4SLinus Torvalds #include "xfs_itable.h" 341da177e4SLinus Torvalds #include "xfs_error.h" 35a844f451SNathan Scott #include "xfs_btree.h" 36f2d67614SChristoph Hellwig #include "xfs_trace.h" 371da177e4SLinus Torvalds 38d96f8f89SEric Sandeen STATIC int 396f1f2168SVlad Apostolov xfs_internal_inum( 406f1f2168SVlad Apostolov xfs_mount_t *mp, 416f1f2168SVlad Apostolov xfs_ino_t ino) 426f1f2168SVlad Apostolov { 436f1f2168SVlad Apostolov return (ino == mp->m_sb.sb_rbmino || ino == mp->m_sb.sb_rsumino || 4462118709SEric Sandeen (xfs_sb_version_hasquota(&mp->m_sb) && 456f1f2168SVlad Apostolov (ino == mp->m_sb.sb_uquotino || ino == mp->m_sb.sb_gquotino))); 466f1f2168SVlad Apostolov } 476f1f2168SVlad Apostolov 487dce11dbSChristoph Hellwig /* 497dce11dbSChristoph Hellwig * Return stat information for one inode. 507dce11dbSChristoph Hellwig * Return 0 if ok, else errno. 517dce11dbSChristoph Hellwig */ 527dce11dbSChristoph Hellwig int 537dce11dbSChristoph Hellwig xfs_bulkstat_one_int( 547dce11dbSChristoph Hellwig struct xfs_mount *mp, /* mount point for filesystem */ 557dce11dbSChristoph Hellwig xfs_ino_t ino, /* inode to get data for */ 567dce11dbSChristoph Hellwig void __user *buffer, /* buffer to place output in */ 577dce11dbSChristoph Hellwig int ubsize, /* size of buffer */ 587dce11dbSChristoph Hellwig bulkstat_one_fmt_pf formatter, /* formatter, copy to user */ 597dce11dbSChristoph Hellwig int *ubused, /* bytes used by me */ 601da177e4SLinus Torvalds int *stat) /* BULKSTAT_RV_... */ 611da177e4SLinus Torvalds { 627dce11dbSChristoph Hellwig struct xfs_icdinode *dic; /* dinode core info pointer */ 637dce11dbSChristoph Hellwig struct xfs_inode *ip; /* incore inode pointer */ 647dce11dbSChristoph Hellwig struct xfs_bstat *buf; /* return buffer */ 657dce11dbSChristoph Hellwig int error = 0; /* error value */ 667dce11dbSChristoph Hellwig 677dce11dbSChristoph Hellwig *stat = BULKSTAT_RV_NOTHING; 687dce11dbSChristoph Hellwig 697dce11dbSChristoph Hellwig if (!buffer || xfs_internal_inum(mp, ino)) 707dce11dbSChristoph Hellwig return XFS_ERROR(EINVAL); 717dce11dbSChristoph Hellwig 727dce11dbSChristoph Hellwig buf = kmem_alloc(sizeof(*buf), KM_SLEEP | KM_MAYFAIL); 737dce11dbSChristoph Hellwig if (!buf) 747dce11dbSChristoph Hellwig return XFS_ERROR(ENOMEM); 751da177e4SLinus Torvalds 76745b1f47SNathan Scott error = xfs_iget(mp, NULL, ino, 775132ba8fSDave Chinner (XFS_IGET_DONTCACHE | XFS_IGET_UNTRUSTED), 785132ba8fSDave Chinner XFS_ILOCK_SHARED, &ip); 791da177e4SLinus Torvalds if (error) { 801da177e4SLinus Torvalds *stat = BULKSTAT_RV_NOTHING; 817dce11dbSChristoph Hellwig goto out_free; 821da177e4SLinus Torvalds } 831da177e4SLinus Torvalds 841da177e4SLinus Torvalds ASSERT(ip != NULL); 8592bfc6e7SChristoph Hellwig ASSERT(ip->i_imap.im_blkno != 0); 861da177e4SLinus Torvalds 871da177e4SLinus Torvalds dic = &ip->i_d; 881da177e4SLinus Torvalds 891da177e4SLinus Torvalds /* xfs_iget returns the following without needing 901da177e4SLinus Torvalds * further change. 911da177e4SLinus Torvalds */ 921da177e4SLinus Torvalds buf->bs_nlink = dic->di_nlink; 936743099cSArkadiusz Mi?kiewicz buf->bs_projid_lo = dic->di_projid_lo; 946743099cSArkadiusz Mi?kiewicz buf->bs_projid_hi = dic->di_projid_hi; 951da177e4SLinus Torvalds buf->bs_ino = ino; 961da177e4SLinus Torvalds buf->bs_mode = dic->di_mode; 971da177e4SLinus Torvalds buf->bs_uid = dic->di_uid; 981da177e4SLinus Torvalds buf->bs_gid = dic->di_gid; 991da177e4SLinus Torvalds buf->bs_size = dic->di_size; 1008a9c9980SChristoph Hellwig buf->bs_atime.tv_sec = dic->di_atime.t_sec; 1018a9c9980SChristoph Hellwig buf->bs_atime.tv_nsec = dic->di_atime.t_nsec; 1028a9c9980SChristoph Hellwig buf->bs_mtime.tv_sec = dic->di_mtime.t_sec; 1038a9c9980SChristoph Hellwig buf->bs_mtime.tv_nsec = dic->di_mtime.t_nsec; 1048a9c9980SChristoph Hellwig buf->bs_ctime.tv_sec = dic->di_ctime.t_sec; 1058a9c9980SChristoph Hellwig buf->bs_ctime.tv_nsec = dic->di_ctime.t_nsec; 1061da177e4SLinus Torvalds buf->bs_xflags = xfs_ip2xflags(ip); 1071da177e4SLinus Torvalds buf->bs_extsize = dic->di_extsize << mp->m_sb.sb_blocklog; 1081da177e4SLinus Torvalds buf->bs_extents = dic->di_nextents; 1091da177e4SLinus Torvalds buf->bs_gen = dic->di_gen; 1101da177e4SLinus Torvalds memset(buf->bs_pad, 0, sizeof(buf->bs_pad)); 1111da177e4SLinus Torvalds buf->bs_dmevmask = dic->di_dmevmask; 1121da177e4SLinus Torvalds buf->bs_dmstate = dic->di_dmstate; 1131da177e4SLinus Torvalds buf->bs_aextents = dic->di_anextents; 11407000ee6SDave Chinner buf->bs_forkoff = XFS_IFORK_BOFF(ip); 1151da177e4SLinus Torvalds 1161da177e4SLinus Torvalds switch (dic->di_format) { 1171da177e4SLinus Torvalds case XFS_DINODE_FMT_DEV: 1181da177e4SLinus Torvalds buf->bs_rdev = ip->i_df.if_u2.if_rdev; 1191da177e4SLinus Torvalds buf->bs_blksize = BLKDEV_IOSIZE; 1201da177e4SLinus Torvalds buf->bs_blocks = 0; 1211da177e4SLinus Torvalds break; 1221da177e4SLinus Torvalds case XFS_DINODE_FMT_LOCAL: 1231da177e4SLinus Torvalds case XFS_DINODE_FMT_UUID: 1241da177e4SLinus Torvalds buf->bs_rdev = 0; 1251da177e4SLinus Torvalds buf->bs_blksize = mp->m_sb.sb_blocksize; 1261da177e4SLinus Torvalds buf->bs_blocks = 0; 1271da177e4SLinus Torvalds break; 1281da177e4SLinus Torvalds case XFS_DINODE_FMT_EXTENTS: 1291da177e4SLinus Torvalds case XFS_DINODE_FMT_BTREE: 1301da177e4SLinus Torvalds buf->bs_rdev = 0; 1311da177e4SLinus Torvalds buf->bs_blksize = mp->m_sb.sb_blocksize; 1321da177e4SLinus Torvalds buf->bs_blocks = dic->di_nblocks + ip->i_delayed_blks; 1331da177e4SLinus Torvalds break; 1341da177e4SLinus Torvalds } 135f2d67614SChristoph Hellwig xfs_iunlock(ip, XFS_ILOCK_SHARED); 136f2d67614SChristoph Hellwig IRELE(ip); 1377dce11dbSChristoph Hellwig 1387dce11dbSChristoph Hellwig error = formatter(buffer, ubsize, ubused, buf); 1397dce11dbSChristoph Hellwig 1407dce11dbSChristoph Hellwig if (!error) 1417dce11dbSChristoph Hellwig *stat = BULKSTAT_RV_DIDONE; 1427dce11dbSChristoph Hellwig 1437dce11dbSChristoph Hellwig out_free: 1447dce11dbSChristoph Hellwig kmem_free(buf); 1451da177e4SLinus Torvalds return error; 1461da177e4SLinus Torvalds } 1471da177e4SLinus Torvalds 14865fbaf24Ssandeen@sandeen.net /* Return 0 on success or positive error */ 149faa63e95SMichal Marek STATIC int 150faa63e95SMichal Marek xfs_bulkstat_one_fmt( 151faa63e95SMichal Marek void __user *ubuffer, 15265fbaf24Ssandeen@sandeen.net int ubsize, 15365fbaf24Ssandeen@sandeen.net int *ubused, 154faa63e95SMichal Marek const xfs_bstat_t *buffer) 155faa63e95SMichal Marek { 15665fbaf24Ssandeen@sandeen.net if (ubsize < sizeof(*buffer)) 15765fbaf24Ssandeen@sandeen.net return XFS_ERROR(ENOMEM); 158faa63e95SMichal Marek if (copy_to_user(ubuffer, buffer, sizeof(*buffer))) 15965fbaf24Ssandeen@sandeen.net return XFS_ERROR(EFAULT); 16065fbaf24Ssandeen@sandeen.net if (ubused) 16165fbaf24Ssandeen@sandeen.net *ubused = sizeof(*buffer); 16265fbaf24Ssandeen@sandeen.net return 0; 163faa63e95SMichal Marek } 164faa63e95SMichal Marek 1652ee4fa5cSsandeen@sandeen.net int 1662ee4fa5cSsandeen@sandeen.net xfs_bulkstat_one( 1672ee4fa5cSsandeen@sandeen.net xfs_mount_t *mp, /* mount point for filesystem */ 1682ee4fa5cSsandeen@sandeen.net xfs_ino_t ino, /* inode number to get data for */ 1692ee4fa5cSsandeen@sandeen.net void __user *buffer, /* buffer to place output in */ 1702ee4fa5cSsandeen@sandeen.net int ubsize, /* size of buffer */ 1712ee4fa5cSsandeen@sandeen.net int *ubused, /* bytes used by me */ 1722ee4fa5cSsandeen@sandeen.net int *stat) /* BULKSTAT_RV_... */ 1732ee4fa5cSsandeen@sandeen.net { 1742ee4fa5cSsandeen@sandeen.net return xfs_bulkstat_one_int(mp, ino, buffer, ubsize, 1757b6259e7SDave Chinner xfs_bulkstat_one_fmt, ubused, stat); 1768b56f083SNathan Scott } 1778b56f083SNathan Scott 178cd57e594SLachlan McIlroy #define XFS_BULKSTAT_UBLEFT(ubleft) ((ubleft) >= statstruct_size) 179cd57e594SLachlan McIlroy 1808b56f083SNathan Scott /* 1811da177e4SLinus Torvalds * Return stat information in bulk (by-inode) for the filesystem. 1821da177e4SLinus Torvalds */ 1831da177e4SLinus Torvalds int /* error status */ 1841da177e4SLinus Torvalds xfs_bulkstat( 1851da177e4SLinus Torvalds xfs_mount_t *mp, /* mount point for filesystem */ 1861da177e4SLinus Torvalds xfs_ino_t *lastinop, /* last inode returned */ 1871da177e4SLinus Torvalds int *ubcountp, /* size of buffer/count returned */ 1881da177e4SLinus Torvalds bulkstat_one_pf formatter, /* func that'd fill a single buf */ 1891da177e4SLinus Torvalds size_t statstruct_size, /* sizeof struct filling */ 1901da177e4SLinus Torvalds char __user *ubuffer, /* buffer with inode stats */ 191c41564b5SNathan Scott int *done) /* 1 if there are more stats to get */ 1921da177e4SLinus Torvalds { 1931da177e4SLinus Torvalds xfs_agblock_t agbno=0;/* allocation group block number */ 1941da177e4SLinus Torvalds xfs_buf_t *agbp; /* agi header buffer */ 1951da177e4SLinus Torvalds xfs_agi_t *agi; /* agi header data */ 1961da177e4SLinus Torvalds xfs_agino_t agino; /* inode # in allocation group */ 1971da177e4SLinus Torvalds xfs_agnumber_t agno; /* allocation group number */ 1981da177e4SLinus Torvalds int chunkidx; /* current index into inode chunk */ 1991da177e4SLinus Torvalds int clustidx; /* current index into inode cluster */ 2001da177e4SLinus Torvalds xfs_btree_cur_t *cur; /* btree cursor for ialloc btree */ 2011da177e4SLinus Torvalds int end_of_ag; /* set if we've seen the ag end */ 2021da177e4SLinus Torvalds int error; /* error code */ 2031da177e4SLinus Torvalds int fmterror;/* bulkstat formatter result */ 2041da177e4SLinus Torvalds int i; /* loop index */ 2051da177e4SLinus Torvalds int icount; /* count of inodes good in irbuf */ 206215101c3SNathan Scott size_t irbsize; /* size of irec buffer in bytes */ 2071da177e4SLinus Torvalds xfs_ino_t ino; /* inode number (filesystem) */ 20826275093SNathan Scott xfs_inobt_rec_incore_t *irbp; /* current irec buffer pointer */ 20926275093SNathan Scott xfs_inobt_rec_incore_t *irbuf; /* start of irec buffer */ 21026275093SNathan Scott xfs_inobt_rec_incore_t *irbufend; /* end of good irec buffer entries */ 211cd57e594SLachlan McIlroy xfs_ino_t lastino; /* last inode number returned */ 2121da177e4SLinus Torvalds int nbcluster; /* # of blocks in a cluster */ 2131da177e4SLinus Torvalds int nicluster; /* # of inodes in a cluster */ 2141da177e4SLinus Torvalds int nimask; /* mask for inode clusters */ 2151da177e4SLinus Torvalds int nirbuf; /* size of irbuf */ 2161da177e4SLinus Torvalds int rval; /* return value error code */ 2171da177e4SLinus Torvalds int tmp; /* result value from btree calls */ 2181da177e4SLinus Torvalds int ubcount; /* size of user's buffer */ 2191da177e4SLinus Torvalds int ubleft; /* bytes left in user's buffer */ 2201da177e4SLinus Torvalds char __user *ubufp; /* pointer into user's buffer */ 2211da177e4SLinus Torvalds int ubelem; /* spaces used in user's buffer */ 2221da177e4SLinus Torvalds int ubused; /* bytes used by formatter */ 2231da177e4SLinus Torvalds xfs_buf_t *bp; /* ptr to on-disk inode cluster buf */ 2241da177e4SLinus Torvalds 2251da177e4SLinus Torvalds /* 2261da177e4SLinus Torvalds * Get the last inode value, see if there's nothing to do. 2271da177e4SLinus Torvalds */ 2281da177e4SLinus Torvalds ino = (xfs_ino_t)*lastinop; 229cd57e594SLachlan McIlroy lastino = ino; 2301da177e4SLinus Torvalds agno = XFS_INO_TO_AGNO(mp, ino); 2311da177e4SLinus Torvalds agino = XFS_INO_TO_AGINO(mp, ino); 2321da177e4SLinus Torvalds if (agno >= mp->m_sb.sb_agcount || 2331da177e4SLinus Torvalds ino != XFS_AGINO_TO_INO(mp, agno, agino)) { 2341da177e4SLinus Torvalds *done = 1; 2351da177e4SLinus Torvalds *ubcountp = 0; 2361da177e4SLinus Torvalds return 0; 2371da177e4SLinus Torvalds } 238cd57e594SLachlan McIlroy if (!ubcountp || *ubcountp <= 0) { 239cd57e594SLachlan McIlroy return EINVAL; 240cd57e594SLachlan McIlroy } 2411da177e4SLinus Torvalds ubcount = *ubcountp; /* statstruct's */ 2421da177e4SLinus Torvalds ubleft = ubcount * statstruct_size; /* bytes */ 2431da177e4SLinus Torvalds *ubcountp = ubelem = 0; 2441da177e4SLinus Torvalds *done = 0; 2451da177e4SLinus Torvalds fmterror = 0; 2461da177e4SLinus Torvalds ubufp = ubuffer; 2471da177e4SLinus Torvalds nicluster = mp->m_sb.sb_blocksize >= XFS_INODE_CLUSTER_SIZE(mp) ? 2481da177e4SLinus Torvalds mp->m_sb.sb_inopblock : 2491da177e4SLinus Torvalds (XFS_INODE_CLUSTER_SIZE(mp) >> mp->m_sb.sb_inodelog); 2501da177e4SLinus Torvalds nimask = ~(nicluster - 1); 2511da177e4SLinus Torvalds nbcluster = nicluster >> mp->m_sb.sb_inopblog; 252bdfb0430SChristoph Hellwig irbuf = kmem_zalloc_greedy(&irbsize, PAGE_SIZE, PAGE_SIZE * 4); 253bdfb0430SChristoph Hellwig if (!irbuf) 254bdfb0430SChristoph Hellwig return ENOMEM; 255bdfb0430SChristoph Hellwig 256bb3c7d29SNathan Scott nirbuf = irbsize / sizeof(*irbuf); 257bb3c7d29SNathan Scott 2581da177e4SLinus Torvalds /* 2591da177e4SLinus Torvalds * Loop over the allocation groups, starting from the last 2601da177e4SLinus Torvalds * inode returned; 0 means start of the allocation group. 2611da177e4SLinus Torvalds */ 2621da177e4SLinus Torvalds rval = 0; 263cd57e594SLachlan McIlroy while (XFS_BULKSTAT_UBLEFT(ubleft) && agno < mp->m_sb.sb_agcount) { 264cd57e594SLachlan McIlroy cond_resched(); 2651da177e4SLinus Torvalds bp = NULL; 2661da177e4SLinus Torvalds error = xfs_ialloc_read_agi(mp, NULL, agno, &agbp); 2671da177e4SLinus Torvalds if (error) { 2681da177e4SLinus Torvalds /* 2691da177e4SLinus Torvalds * Skip this allocation group and go to the next one. 2701da177e4SLinus Torvalds */ 2711da177e4SLinus Torvalds agno++; 2721da177e4SLinus Torvalds agino = 0; 2731da177e4SLinus Torvalds continue; 2741da177e4SLinus Torvalds } 2751da177e4SLinus Torvalds agi = XFS_BUF_TO_AGI(agbp); 2761da177e4SLinus Torvalds /* 2771da177e4SLinus Torvalds * Allocate and initialize a btree cursor for ialloc btree. 2781da177e4SLinus Torvalds */ 279561f7d17SChristoph Hellwig cur = xfs_inobt_init_cursor(mp, NULL, agbp, agno); 2801da177e4SLinus Torvalds irbp = irbuf; 2811da177e4SLinus Torvalds irbufend = irbuf + nirbuf; 2821da177e4SLinus Torvalds end_of_ag = 0; 2831da177e4SLinus Torvalds /* 2841da177e4SLinus Torvalds * If we're returning in the middle of an allocation group, 2851da177e4SLinus Torvalds * we need to get the remainder of the chunk we're in. 2861da177e4SLinus Torvalds */ 2871da177e4SLinus Torvalds if (agino > 0) { 2882e287a73SChristoph Hellwig xfs_inobt_rec_incore_t r; 2892e287a73SChristoph Hellwig 2901da177e4SLinus Torvalds /* 2911da177e4SLinus Torvalds * Lookup the inode chunk that this inode lives in. 2921da177e4SLinus Torvalds */ 29321875505SChristoph Hellwig error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_LE, 29421875505SChristoph Hellwig &tmp); 2951da177e4SLinus Torvalds if (!error && /* no I/O error */ 2961da177e4SLinus Torvalds tmp && /* lookup succeeded */ 2971da177e4SLinus Torvalds /* got the record, should always work */ 2982e287a73SChristoph Hellwig !(error = xfs_inobt_get_rec(cur, &r, &i)) && 2991da177e4SLinus Torvalds i == 1 && 3001da177e4SLinus Torvalds /* this is the right chunk */ 3012e287a73SChristoph Hellwig agino < r.ir_startino + XFS_INODES_PER_CHUNK && 3021da177e4SLinus Torvalds /* lastino was not last in chunk */ 3032e287a73SChristoph Hellwig (chunkidx = agino - r.ir_startino + 1) < 3041da177e4SLinus Torvalds XFS_INODES_PER_CHUNK && 3051da177e4SLinus Torvalds /* there are some left allocated */ 3069d87c319SEric Sandeen xfs_inobt_maskn(chunkidx, 3072e287a73SChristoph Hellwig XFS_INODES_PER_CHUNK - chunkidx) & 3082e287a73SChristoph Hellwig ~r.ir_free) { 3091da177e4SLinus Torvalds /* 3101da177e4SLinus Torvalds * Grab the chunk record. Mark all the 3111da177e4SLinus Torvalds * uninteresting inodes (because they're 3121da177e4SLinus Torvalds * before our start point) free. 3131da177e4SLinus Torvalds */ 3141da177e4SLinus Torvalds for (i = 0; i < chunkidx; i++) { 3152e287a73SChristoph Hellwig if (XFS_INOBT_MASK(i) & ~r.ir_free) 3162e287a73SChristoph Hellwig r.ir_freecount++; 3171da177e4SLinus Torvalds } 3182e287a73SChristoph Hellwig r.ir_free |= xfs_inobt_maskn(0, chunkidx); 3192e287a73SChristoph Hellwig irbp->ir_startino = r.ir_startino; 3202e287a73SChristoph Hellwig irbp->ir_freecount = r.ir_freecount; 3212e287a73SChristoph Hellwig irbp->ir_free = r.ir_free; 3221da177e4SLinus Torvalds irbp++; 3232e287a73SChristoph Hellwig agino = r.ir_startino + XFS_INODES_PER_CHUNK; 3242e287a73SChristoph Hellwig icount = XFS_INODES_PER_CHUNK - r.ir_freecount; 3251da177e4SLinus Torvalds } else { 3261da177e4SLinus Torvalds /* 3271da177e4SLinus Torvalds * If any of those tests failed, bump the 3281da177e4SLinus Torvalds * inode number (just in case). 3291da177e4SLinus Torvalds */ 3301da177e4SLinus Torvalds agino++; 3311da177e4SLinus Torvalds icount = 0; 3321da177e4SLinus Torvalds } 3331da177e4SLinus Torvalds /* 3341da177e4SLinus Torvalds * In any case, increment to the next record. 3351da177e4SLinus Torvalds */ 3361da177e4SLinus Torvalds if (!error) 337637aa50fSChristoph Hellwig error = xfs_btree_increment(cur, 0, &tmp); 3381da177e4SLinus Torvalds } else { 3391da177e4SLinus Torvalds /* 3401da177e4SLinus Torvalds * Start of ag. Lookup the first inode chunk. 3411da177e4SLinus Torvalds */ 34221875505SChristoph Hellwig error = xfs_inobt_lookup(cur, 0, XFS_LOOKUP_GE, &tmp); 3431da177e4SLinus Torvalds icount = 0; 3441da177e4SLinus Torvalds } 3451da177e4SLinus Torvalds /* 3461da177e4SLinus Torvalds * Loop through inode btree records in this ag, 3471da177e4SLinus Torvalds * until we run out of inodes or space in the buffer. 3481da177e4SLinus Torvalds */ 3491da177e4SLinus Torvalds while (irbp < irbufend && icount < ubcount) { 3502e287a73SChristoph Hellwig xfs_inobt_rec_incore_t r; 3512e287a73SChristoph Hellwig 3521da177e4SLinus Torvalds /* 3531da177e4SLinus Torvalds * Loop as long as we're unable to read the 3541da177e4SLinus Torvalds * inode btree. 3551da177e4SLinus Torvalds */ 3561da177e4SLinus Torvalds while (error) { 3571da177e4SLinus Torvalds agino += XFS_INODES_PER_CHUNK; 3581da177e4SLinus Torvalds if (XFS_AGINO_TO_AGBNO(mp, agino) >= 35916259e7dSChristoph Hellwig be32_to_cpu(agi->agi_length)) 3601da177e4SLinus Torvalds break; 36121875505SChristoph Hellwig error = xfs_inobt_lookup(cur, agino, 36221875505SChristoph Hellwig XFS_LOOKUP_GE, &tmp); 363cd57e594SLachlan McIlroy cond_resched(); 3641da177e4SLinus Torvalds } 3651da177e4SLinus Torvalds /* 3661da177e4SLinus Torvalds * If ran off the end of the ag either with an error, 3671da177e4SLinus Torvalds * or the normal way, set end and stop collecting. 3681da177e4SLinus Torvalds */ 3692e287a73SChristoph Hellwig if (error) { 3701da177e4SLinus Torvalds end_of_ag = 1; 3711da177e4SLinus Torvalds break; 3721da177e4SLinus Torvalds } 3732e287a73SChristoph Hellwig 3742e287a73SChristoph Hellwig error = xfs_inobt_get_rec(cur, &r, &i); 3752e287a73SChristoph Hellwig if (error || i == 0) { 3762e287a73SChristoph Hellwig end_of_ag = 1; 3772e287a73SChristoph Hellwig break; 3782e287a73SChristoph Hellwig } 3792e287a73SChristoph Hellwig 3801da177e4SLinus Torvalds /* 3811da177e4SLinus Torvalds * If this chunk has any allocated inodes, save it. 38226275093SNathan Scott * Also start read-ahead now for this chunk. 3831da177e4SLinus Torvalds */ 3842e287a73SChristoph Hellwig if (r.ir_freecount < XFS_INODES_PER_CHUNK) { 38526275093SNathan Scott /* 38626275093SNathan Scott * Loop over all clusters in the next chunk. 38726275093SNathan Scott * Do a readahead if there are any allocated 38826275093SNathan Scott * inodes in that cluster. 38926275093SNathan Scott */ 3902e287a73SChristoph Hellwig agbno = XFS_AGINO_TO_AGBNO(mp, r.ir_startino); 3912e287a73SChristoph Hellwig for (chunkidx = 0; 39226275093SNathan Scott chunkidx < XFS_INODES_PER_CHUNK; 39326275093SNathan Scott chunkidx += nicluster, 39426275093SNathan Scott agbno += nbcluster) { 3952e287a73SChristoph Hellwig if (xfs_inobt_maskn(chunkidx, nicluster) 3962e287a73SChristoph Hellwig & ~r.ir_free) 39726275093SNathan Scott xfs_btree_reada_bufs(mp, agno, 39826275093SNathan Scott agbno, nbcluster); 39926275093SNathan Scott } 4002e287a73SChristoph Hellwig irbp->ir_startino = r.ir_startino; 4012e287a73SChristoph Hellwig irbp->ir_freecount = r.ir_freecount; 4022e287a73SChristoph Hellwig irbp->ir_free = r.ir_free; 4031da177e4SLinus Torvalds irbp++; 4042e287a73SChristoph Hellwig icount += XFS_INODES_PER_CHUNK - r.ir_freecount; 4051da177e4SLinus Torvalds } 4061da177e4SLinus Torvalds /* 4071da177e4SLinus Torvalds * Set agino to after this chunk and bump the cursor. 4081da177e4SLinus Torvalds */ 4092e287a73SChristoph Hellwig agino = r.ir_startino + XFS_INODES_PER_CHUNK; 410637aa50fSChristoph Hellwig error = xfs_btree_increment(cur, 0, &tmp); 411cd57e594SLachlan McIlroy cond_resched(); 4121da177e4SLinus Torvalds } 4131da177e4SLinus Torvalds /* 4141da177e4SLinus Torvalds * Drop the btree buffers and the agi buffer. 4151da177e4SLinus Torvalds * We can't hold any of the locks these represent 4161da177e4SLinus Torvalds * when calling iget. 4171da177e4SLinus Torvalds */ 4181da177e4SLinus Torvalds xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR); 4191da177e4SLinus Torvalds xfs_buf_relse(agbp); 4201da177e4SLinus Torvalds /* 4211da177e4SLinus Torvalds * Now format all the good inodes into the user's buffer. 4221da177e4SLinus Torvalds */ 4231da177e4SLinus Torvalds irbufend = irbp; 4241da177e4SLinus Torvalds for (irbp = irbuf; 425cd57e594SLachlan McIlroy irbp < irbufend && XFS_BULKSTAT_UBLEFT(ubleft); irbp++) { 4261da177e4SLinus Torvalds /* 4271da177e4SLinus Torvalds * Now process this chunk of inodes. 4281da177e4SLinus Torvalds */ 42926275093SNathan Scott for (agino = irbp->ir_startino, chunkidx = clustidx = 0; 430cd57e594SLachlan McIlroy XFS_BULKSTAT_UBLEFT(ubleft) && 43126275093SNathan Scott irbp->ir_freecount < XFS_INODES_PER_CHUNK; 4321da177e4SLinus Torvalds chunkidx++, clustidx++, agino++) { 4331da177e4SLinus Torvalds ASSERT(chunkidx < XFS_INODES_PER_CHUNK); 4341da177e4SLinus Torvalds /* 4351da177e4SLinus Torvalds * Recompute agbno if this is the 4361da177e4SLinus Torvalds * first inode of the cluster. 4371da177e4SLinus Torvalds * 4381da177e4SLinus Torvalds * Careful with clustidx. There can be 4399da096fdSMalcolm Parsons * multiple clusters per chunk, a single 4401da177e4SLinus Torvalds * cluster per chunk or a cluster that has 4411da177e4SLinus Torvalds * inodes represented from several different 4421da177e4SLinus Torvalds * chunks (if blocksize is large). 4431da177e4SLinus Torvalds * 4441da177e4SLinus Torvalds * Because of this, the starting clustidx is 4451da177e4SLinus Torvalds * initialized to zero in this loop but must 4461da177e4SLinus Torvalds * later be reset after reading in the cluster 4471da177e4SLinus Torvalds * buffer. 4481da177e4SLinus Torvalds */ 4491da177e4SLinus Torvalds if ((chunkidx & (nicluster - 1)) == 0) { 4501da177e4SLinus Torvalds agbno = XFS_AGINO_TO_AGBNO(mp, 45126275093SNathan Scott irbp->ir_startino) + 4521da177e4SLinus Torvalds ((chunkidx & nimask) >> 4531da177e4SLinus Torvalds mp->m_sb.sb_inopblog); 4541da177e4SLinus Torvalds } 455c2cba57eSLachlan McIlroy ino = XFS_AGINO_TO_INO(mp, agno, agino); 4561da177e4SLinus Torvalds /* 4571da177e4SLinus Torvalds * Skip if this inode is free. 4581da177e4SLinus Torvalds */ 459c2cba57eSLachlan McIlroy if (XFS_INOBT_MASK(chunkidx) & irbp->ir_free) { 460c2cba57eSLachlan McIlroy lastino = ino; 4611da177e4SLinus Torvalds continue; 462c2cba57eSLachlan McIlroy } 4631da177e4SLinus Torvalds /* 4641da177e4SLinus Torvalds * Count used inodes as free so we can tell 4651da177e4SLinus Torvalds * when the chunk is used up. 4661da177e4SLinus Torvalds */ 46726275093SNathan Scott irbp->ir_freecount++; 4681da177e4SLinus Torvalds 4691da177e4SLinus Torvalds /* 4701da177e4SLinus Torvalds * Get the inode and fill in a single buffer. 4711da177e4SLinus Torvalds */ 4721da177e4SLinus Torvalds ubused = statstruct_size; 4737b6259e7SDave Chinner error = formatter(mp, ino, ubufp, ubleft, 4747dce11dbSChristoph Hellwig &ubused, &fmterror); 4751da177e4SLinus Torvalds if (fmterror == BULKSTAT_RV_NOTHING) { 476cd57e594SLachlan McIlroy if (error && error != ENOENT && 477cd57e594SLachlan McIlroy error != EINVAL) { 47822de606aSVlad Apostolov ubleft = 0; 47922de606aSVlad Apostolov rval = error; 48022de606aSVlad Apostolov break; 48122de606aSVlad Apostolov } 4826e73b418SVlad Apostolov lastino = ino; 4831da177e4SLinus Torvalds continue; 4841da177e4SLinus Torvalds } 4851da177e4SLinus Torvalds if (fmterror == BULKSTAT_RV_GIVEUP) { 4861da177e4SLinus Torvalds ubleft = 0; 4871da177e4SLinus Torvalds ASSERT(error); 4881da177e4SLinus Torvalds rval = error; 4891da177e4SLinus Torvalds break; 4901da177e4SLinus Torvalds } 4911da177e4SLinus Torvalds if (ubufp) 4921da177e4SLinus Torvalds ubufp += ubused; 4931da177e4SLinus Torvalds ubleft -= ubused; 4941da177e4SLinus Torvalds ubelem++; 4951da177e4SLinus Torvalds lastino = ino; 4961da177e4SLinus Torvalds } 497cd57e594SLachlan McIlroy 498cd57e594SLachlan McIlroy cond_resched(); 4991da177e4SLinus Torvalds } 5001da177e4SLinus Torvalds 5011da177e4SLinus Torvalds if (bp) 5021da177e4SLinus Torvalds xfs_buf_relse(bp); 5031da177e4SLinus Torvalds 5041da177e4SLinus Torvalds /* 5051da177e4SLinus Torvalds * Set up for the next loop iteration. 5061da177e4SLinus Torvalds */ 507cd57e594SLachlan McIlroy if (XFS_BULKSTAT_UBLEFT(ubleft)) { 5081da177e4SLinus Torvalds if (end_of_ag) { 5091da177e4SLinus Torvalds agno++; 5101da177e4SLinus Torvalds agino = 0; 511cd57e594SLachlan McIlroy } else 512cd57e594SLachlan McIlroy agino = XFS_INO_TO_AGINO(mp, lastino); 5131da177e4SLinus Torvalds } else 5141da177e4SLinus Torvalds break; 5151da177e4SLinus Torvalds } 5161da177e4SLinus Torvalds /* 5171da177e4SLinus Torvalds * Done, we're either out of filesystem or space to put the data. 5181da177e4SLinus Torvalds */ 519bdfb0430SChristoph Hellwig kmem_free_large(irbuf); 5201da177e4SLinus Torvalds *ubcountp = ubelem; 521cd57e594SLachlan McIlroy /* 522cd57e594SLachlan McIlroy * Found some inodes, return them now and return the error next time. 523cd57e594SLachlan McIlroy */ 524cd57e594SLachlan McIlroy if (ubelem) 525cd57e594SLachlan McIlroy rval = 0; 5261da177e4SLinus Torvalds if (agno >= mp->m_sb.sb_agcount) { 5271da177e4SLinus Torvalds /* 5281da177e4SLinus Torvalds * If we ran out of filesystem, mark lastino as off 5291da177e4SLinus Torvalds * the end of the filesystem, so the next call 5301da177e4SLinus Torvalds * will return immediately. 5311da177e4SLinus Torvalds */ 5321da177e4SLinus Torvalds *lastinop = (xfs_ino_t)XFS_AGINO_TO_INO(mp, agno, 0); 5331da177e4SLinus Torvalds *done = 1; 5341da177e4SLinus Torvalds } else 5351da177e4SLinus Torvalds *lastinop = (xfs_ino_t)lastino; 5361da177e4SLinus Torvalds 5371da177e4SLinus Torvalds return rval; 5381da177e4SLinus Torvalds } 5391da177e4SLinus Torvalds 5401da177e4SLinus Torvalds /* 5411da177e4SLinus Torvalds * Return stat information in bulk (by-inode) for the filesystem. 5421da177e4SLinus Torvalds * Special case for non-sequential one inode bulkstat. 5431da177e4SLinus Torvalds */ 5441da177e4SLinus Torvalds int /* error status */ 5451da177e4SLinus Torvalds xfs_bulkstat_single( 5461da177e4SLinus Torvalds xfs_mount_t *mp, /* mount point for filesystem */ 5471da177e4SLinus Torvalds xfs_ino_t *lastinop, /* inode to return */ 5481da177e4SLinus Torvalds char __user *buffer, /* buffer with inode stats */ 549c41564b5SNathan Scott int *done) /* 1 if there are more stats to get */ 5501da177e4SLinus Torvalds { 5511da177e4SLinus Torvalds int count; /* count value for bulkstat call */ 5521da177e4SLinus Torvalds int error; /* return value */ 5531da177e4SLinus Torvalds xfs_ino_t ino; /* filesystem inode number */ 5541da177e4SLinus Torvalds int res; /* result from bs1 */ 5551da177e4SLinus Torvalds 5561da177e4SLinus Torvalds /* 5571da177e4SLinus Torvalds * note that requesting valid inode numbers which are not allocated 558*475ee413SChristoph Hellwig * to inodes will most likely cause xfs_imap_to_bp to generate warning 5591da177e4SLinus Torvalds * messages about bad magic numbers. This is ok. The fact that 5601da177e4SLinus Torvalds * the inode isn't actually an inode is handled by the 5611da177e4SLinus Torvalds * error check below. Done this way to make the usual case faster 5621da177e4SLinus Torvalds * at the expense of the error case. 5631da177e4SLinus Torvalds */ 5641da177e4SLinus Torvalds 5651da177e4SLinus Torvalds ino = (xfs_ino_t)*lastinop; 5667b6259e7SDave Chinner error = xfs_bulkstat_one(mp, ino, buffer, sizeof(xfs_bstat_t), 0, &res); 5671da177e4SLinus Torvalds if (error) { 5681da177e4SLinus Torvalds /* 5691da177e4SLinus Torvalds * Special case way failed, do it the "long" way 5701da177e4SLinus Torvalds * to see if that works. 5711da177e4SLinus Torvalds */ 5721da177e4SLinus Torvalds (*lastinop)--; 5731da177e4SLinus Torvalds count = 1; 5741da177e4SLinus Torvalds if (xfs_bulkstat(mp, lastinop, &count, xfs_bulkstat_one, 5757dce11dbSChristoph Hellwig sizeof(xfs_bstat_t), buffer, done)) 5761da177e4SLinus Torvalds return error; 5771da177e4SLinus Torvalds if (count == 0 || (xfs_ino_t)*lastinop != ino) 5781da177e4SLinus Torvalds return error == EFSCORRUPTED ? 5791da177e4SLinus Torvalds XFS_ERROR(EINVAL) : error; 5801da177e4SLinus Torvalds else 5811da177e4SLinus Torvalds return 0; 5821da177e4SLinus Torvalds } 5831da177e4SLinus Torvalds *done = 0; 5841da177e4SLinus Torvalds return 0; 5851da177e4SLinus Torvalds } 5861da177e4SLinus Torvalds 587faa63e95SMichal Marek int 588faa63e95SMichal Marek xfs_inumbers_fmt( 589faa63e95SMichal Marek void __user *ubuffer, /* buffer to write to */ 590faa63e95SMichal Marek const xfs_inogrp_t *buffer, /* buffer to read from */ 591faa63e95SMichal Marek long count, /* # of elements to read */ 592faa63e95SMichal Marek long *written) /* # of bytes written */ 593faa63e95SMichal Marek { 594faa63e95SMichal Marek if (copy_to_user(ubuffer, buffer, count * sizeof(*buffer))) 595faa63e95SMichal Marek return -EFAULT; 596faa63e95SMichal Marek *written = count * sizeof(*buffer); 597faa63e95SMichal Marek return 0; 598faa63e95SMichal Marek } 599faa63e95SMichal Marek 6001da177e4SLinus Torvalds /* 6011da177e4SLinus Torvalds * Return inode number table for the filesystem. 6021da177e4SLinus Torvalds */ 6031da177e4SLinus Torvalds int /* error status */ 6041da177e4SLinus Torvalds xfs_inumbers( 6051da177e4SLinus Torvalds xfs_mount_t *mp, /* mount point for filesystem */ 6061da177e4SLinus Torvalds xfs_ino_t *lastino, /* last inode returned */ 6071da177e4SLinus Torvalds int *count, /* size of buffer/count returned */ 608faa63e95SMichal Marek void __user *ubuffer,/* buffer with inode descriptions */ 609faa63e95SMichal Marek inumbers_fmt_pf formatter) 6101da177e4SLinus Torvalds { 6111da177e4SLinus Torvalds xfs_buf_t *agbp; 6121da177e4SLinus Torvalds xfs_agino_t agino; 6131da177e4SLinus Torvalds xfs_agnumber_t agno; 6141da177e4SLinus Torvalds int bcount; 6151da177e4SLinus Torvalds xfs_inogrp_t *buffer; 6161da177e4SLinus Torvalds int bufidx; 6171da177e4SLinus Torvalds xfs_btree_cur_t *cur; 6181da177e4SLinus Torvalds int error; 6192e287a73SChristoph Hellwig xfs_inobt_rec_incore_t r; 6201da177e4SLinus Torvalds int i; 6211da177e4SLinus Torvalds xfs_ino_t ino; 6221da177e4SLinus Torvalds int left; 6231da177e4SLinus Torvalds int tmp; 6241da177e4SLinus Torvalds 6251da177e4SLinus Torvalds ino = (xfs_ino_t)*lastino; 6261da177e4SLinus Torvalds agno = XFS_INO_TO_AGNO(mp, ino); 6271da177e4SLinus Torvalds agino = XFS_INO_TO_AGINO(mp, ino); 6281da177e4SLinus Torvalds left = *count; 6291da177e4SLinus Torvalds *count = 0; 630e6a4b37fSTim Shimmin bcount = MIN(left, (int)(PAGE_SIZE / sizeof(*buffer))); 6311da177e4SLinus Torvalds buffer = kmem_alloc(bcount * sizeof(*buffer), KM_SLEEP); 6321da177e4SLinus Torvalds error = bufidx = 0; 6331da177e4SLinus Torvalds cur = NULL; 6341da177e4SLinus Torvalds agbp = NULL; 6351da177e4SLinus Torvalds while (left > 0 && agno < mp->m_sb.sb_agcount) { 6361da177e4SLinus Torvalds if (agbp == NULL) { 6371da177e4SLinus Torvalds error = xfs_ialloc_read_agi(mp, NULL, agno, &agbp); 6381da177e4SLinus Torvalds if (error) { 6391da177e4SLinus Torvalds /* 6401da177e4SLinus Torvalds * If we can't read the AGI of this ag, 6411da177e4SLinus Torvalds * then just skip to the next one. 6421da177e4SLinus Torvalds */ 6431da177e4SLinus Torvalds ASSERT(cur == NULL); 6441da177e4SLinus Torvalds agbp = NULL; 6451da177e4SLinus Torvalds agno++; 6461da177e4SLinus Torvalds agino = 0; 6471da177e4SLinus Torvalds continue; 6481da177e4SLinus Torvalds } 649561f7d17SChristoph Hellwig cur = xfs_inobt_init_cursor(mp, NULL, agbp, agno); 65021875505SChristoph Hellwig error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_GE, 65121875505SChristoph Hellwig &tmp); 6521da177e4SLinus Torvalds if (error) { 6531da177e4SLinus Torvalds xfs_btree_del_cursor(cur, XFS_BTREE_ERROR); 6541da177e4SLinus Torvalds cur = NULL; 6551da177e4SLinus Torvalds xfs_buf_relse(agbp); 6561da177e4SLinus Torvalds agbp = NULL; 6571da177e4SLinus Torvalds /* 65859c51591SMichael Opdenacker * Move up the last inode in the current 6591da177e4SLinus Torvalds * chunk. The lookup_ge will always get 6601da177e4SLinus Torvalds * us the first inode in the next chunk. 6611da177e4SLinus Torvalds */ 6621da177e4SLinus Torvalds agino += XFS_INODES_PER_CHUNK - 1; 6631da177e4SLinus Torvalds continue; 6641da177e4SLinus Torvalds } 6651da177e4SLinus Torvalds } 6662e287a73SChristoph Hellwig error = xfs_inobt_get_rec(cur, &r, &i); 6672e287a73SChristoph Hellwig if (error || i == 0) { 6681da177e4SLinus Torvalds xfs_buf_relse(agbp); 6691da177e4SLinus Torvalds agbp = NULL; 6701da177e4SLinus Torvalds xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR); 6711da177e4SLinus Torvalds cur = NULL; 6721da177e4SLinus Torvalds agno++; 6731da177e4SLinus Torvalds agino = 0; 6741da177e4SLinus Torvalds continue; 6751da177e4SLinus Torvalds } 6762e287a73SChristoph Hellwig agino = r.ir_startino + XFS_INODES_PER_CHUNK - 1; 6772e287a73SChristoph Hellwig buffer[bufidx].xi_startino = 6782e287a73SChristoph Hellwig XFS_AGINO_TO_INO(mp, agno, r.ir_startino); 6792e287a73SChristoph Hellwig buffer[bufidx].xi_alloccount = 6802e287a73SChristoph Hellwig XFS_INODES_PER_CHUNK - r.ir_freecount; 6812e287a73SChristoph Hellwig buffer[bufidx].xi_allocmask = ~r.ir_free; 6821da177e4SLinus Torvalds bufidx++; 6831da177e4SLinus Torvalds left--; 6841da177e4SLinus Torvalds if (bufidx == bcount) { 685faa63e95SMichal Marek long written; 686faa63e95SMichal Marek if (formatter(ubuffer, buffer, bufidx, &written)) { 6871da177e4SLinus Torvalds error = XFS_ERROR(EFAULT); 6881da177e4SLinus Torvalds break; 6891da177e4SLinus Torvalds } 690faa63e95SMichal Marek ubuffer += written; 6911da177e4SLinus Torvalds *count += bufidx; 6921da177e4SLinus Torvalds bufidx = 0; 6931da177e4SLinus Torvalds } 6941da177e4SLinus Torvalds if (left) { 695637aa50fSChristoph Hellwig error = xfs_btree_increment(cur, 0, &tmp); 6961da177e4SLinus Torvalds if (error) { 6971da177e4SLinus Torvalds xfs_btree_del_cursor(cur, XFS_BTREE_ERROR); 6981da177e4SLinus Torvalds cur = NULL; 6991da177e4SLinus Torvalds xfs_buf_relse(agbp); 7001da177e4SLinus Torvalds agbp = NULL; 7011da177e4SLinus Torvalds /* 7021da177e4SLinus Torvalds * The agino value has already been bumped. 7031da177e4SLinus Torvalds * Just try to skip up to it. 7041da177e4SLinus Torvalds */ 7051da177e4SLinus Torvalds agino += XFS_INODES_PER_CHUNK; 7061da177e4SLinus Torvalds continue; 7071da177e4SLinus Torvalds } 7081da177e4SLinus Torvalds } 7091da177e4SLinus Torvalds } 7101da177e4SLinus Torvalds if (!error) { 7111da177e4SLinus Torvalds if (bufidx) { 712faa63e95SMichal Marek long written; 713faa63e95SMichal Marek if (formatter(ubuffer, buffer, bufidx, &written)) 7141da177e4SLinus Torvalds error = XFS_ERROR(EFAULT); 7151da177e4SLinus Torvalds else 7161da177e4SLinus Torvalds *count += bufidx; 7171da177e4SLinus Torvalds } 7181da177e4SLinus Torvalds *lastino = XFS_AGINO_TO_INO(mp, agno, agino); 7191da177e4SLinus Torvalds } 720f0e2d93cSDenys Vlasenko kmem_free(buffer); 7211da177e4SLinus Torvalds if (cur) 7221da177e4SLinus Torvalds xfs_btree_del_cursor(cur, (error ? XFS_BTREE_ERROR : 7231da177e4SLinus Torvalds XFS_BTREE_NOERROR)); 7241da177e4SLinus Torvalds if (agbp) 7251da177e4SLinus Torvalds xfs_buf_relse(agbp); 7261da177e4SLinus Torvalds return error; 7271da177e4SLinus Torvalds } 728