xfs_itable.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
  4. * All Rights Reserved.
  5. */
  6. #include "xfs.h"
  7. #include "xfs_fs.h"
  8. #include "xfs_shared.h"
  9. #include "xfs_format.h"
  10. #include "xfs_log_format.h"
  11. #include "xfs_trans_resv.h"
  12. #include "xfs_mount.h"
  13. #include "xfs_inode.h"
  14. #include "xfs_btree.h"
  15. #include "xfs_ialloc.h"
  16. #include "xfs_ialloc_btree.h"
  17. #include "xfs_itable.h"
  18. #include "xfs_error.h"
  19. #include "xfs_trace.h"
  20. #include "xfs_icache.h"
  21. /*
  22. * Return stat information for one inode.
  23. * Return 0 if ok, else errno.
  24. */
  25. int
  26. xfs_bulkstat_one_int(
  27. struct xfs_mount *mp, /* mount point for filesystem */
  28. xfs_ino_t ino, /* inode to get data for */
  29. void __user *buffer, /* buffer to place output in */
  30. int ubsize, /* size of buffer */
  31. bulkstat_one_fmt_pf formatter, /* formatter, copy to user */
  32. int *ubused, /* bytes used by me */
  33. int *stat) /* BULKSTAT_RV_... */
  34. {
  35. struct xfs_icdinode *dic; /* dinode core info pointer */
  36. struct xfs_inode *ip; /* incore inode pointer */
  37. struct inode *inode;
  38. struct xfs_bstat *buf; /* return buffer */
  39. int error = 0; /* error value */
  40. *stat = BULKSTAT_RV_NOTHING;
  41. if (!buffer || xfs_internal_inum(mp, ino))
  42. return -EINVAL;
  43. buf = kmem_zalloc(sizeof(*buf), KM_SLEEP | KM_MAYFAIL);
  44. if (!buf)
  45. return -ENOMEM;
  46. error = xfs_iget(mp, NULL, ino,
  47. (XFS_IGET_DONTCACHE | XFS_IGET_UNTRUSTED),
  48. XFS_ILOCK_SHARED, &ip);
  49. if (error)
  50. goto out_free;
  51. ASSERT(ip != NULL);
  52. ASSERT(ip->i_imap.im_blkno != 0);
  53. inode = VFS_I(ip);
  54. dic = &ip->i_d;
  55. /* xfs_iget returns the following without needing
  56. * further change.
  57. */
  58. buf->bs_projid_lo = dic->di_projid_lo;
  59. buf->bs_projid_hi = dic->di_projid_hi;
  60. buf->bs_ino = ino;
  61. buf->bs_uid = dic->di_uid;
  62. buf->bs_gid = dic->di_gid;
  63. buf->bs_size = dic->di_size;
  64. buf->bs_nlink = inode->i_nlink;
  65. buf->bs_atime.tv_sec = inode->i_atime.tv_sec;
  66. buf->bs_atime.tv_nsec = inode->i_atime.tv_nsec;
  67. buf->bs_mtime.tv_sec = inode->i_mtime.tv_sec;
  68. buf->bs_mtime.tv_nsec = inode->i_mtime.tv_nsec;
  69. buf->bs_ctime.tv_sec = inode->i_ctime.tv_sec;
  70. buf->bs_ctime.tv_nsec = inode->i_ctime.tv_nsec;
  71. buf->bs_gen = inode->i_generation;
  72. buf->bs_mode = inode->i_mode;
  73. buf->bs_xflags = xfs_ip2xflags(ip);
  74. buf->bs_extsize = dic->di_extsize << mp->m_sb.sb_blocklog;
  75. buf->bs_extents = dic->di_nextents;
  76. memset(buf->bs_pad, 0, sizeof(buf->bs_pad));
  77. buf->bs_dmevmask = dic->di_dmevmask;
  78. buf->bs_dmstate = dic->di_dmstate;
  79. buf->bs_aextents = dic->di_anextents;
  80. buf->bs_forkoff = XFS_IFORK_BOFF(ip);
  81. if (dic->di_version == 3) {
  82. if (dic->di_flags2 & XFS_DIFLAG2_COWEXTSIZE)
  83. buf->bs_cowextsize = dic->di_cowextsize <<
  84. mp->m_sb.sb_blocklog;
  85. }
  86. switch (dic->di_format) {
  87. case XFS_DINODE_FMT_DEV:
  88. buf->bs_rdev = sysv_encode_dev(inode->i_rdev);
  89. buf->bs_blksize = BLKDEV_IOSIZE;
  90. buf->bs_blocks = 0;
  91. break;
  92. case XFS_DINODE_FMT_LOCAL:
  93. buf->bs_rdev = 0;
  94. buf->bs_blksize = mp->m_sb.sb_blocksize;
  95. buf->bs_blocks = 0;
  96. break;
  97. case XFS_DINODE_FMT_EXTENTS:
  98. case XFS_DINODE_FMT_BTREE:
  99. buf->bs_rdev = 0;
  100. buf->bs_blksize = mp->m_sb.sb_blocksize;
  101. buf->bs_blocks = dic->di_nblocks + ip->i_delayed_blks;
  102. break;
  103. }
  104. xfs_iunlock(ip, XFS_ILOCK_SHARED);
  105. xfs_irele(ip);
  106. error = formatter(buffer, ubsize, ubused, buf);
  107. if (!error)
  108. *stat = BULKSTAT_RV_DIDONE;
  109. out_free:
  110. kmem_free(buf);
  111. return error;
  112. }
  113. /* Return 0 on success or positive error */
  114. STATIC int
  115. xfs_bulkstat_one_fmt(
  116. void __user *ubuffer,
  117. int ubsize,
  118. int *ubused,
  119. const xfs_bstat_t *buffer)
  120. {
  121. if (ubsize < sizeof(*buffer))
  122. return -ENOMEM;
  123. if (copy_to_user(ubuffer, buffer, sizeof(*buffer)))
  124. return -EFAULT;
  125. if (ubused)
  126. *ubused = sizeof(*buffer);
  127. return 0;
  128. }
  129. int
  130. xfs_bulkstat_one(
  131. xfs_mount_t *mp, /* mount point for filesystem */
  132. xfs_ino_t ino, /* inode number to get data for */
  133. void __user *buffer, /* buffer to place output in */
  134. int ubsize, /* size of buffer */
  135. int *ubused, /* bytes used by me */
  136. int *stat) /* BULKSTAT_RV_... */
  137. {
  138. return xfs_bulkstat_one_int(mp, ino, buffer, ubsize,
  139. xfs_bulkstat_one_fmt, ubused, stat);
  140. }
  141. /*
  142. * Loop over all clusters in a chunk for a given incore inode allocation btree
  143. * record. Do a readahead if there are any allocated inodes in that cluster.
  144. */
  145. STATIC void
  146. xfs_bulkstat_ichunk_ra(
  147. struct xfs_mount *mp,
  148. xfs_agnumber_t agno,
  149. struct xfs_inobt_rec_incore *irec)
  150. {
  151. xfs_agblock_t agbno;
  152. struct blk_plug plug;
  153. int blks_per_cluster;
  154. int inodes_per_cluster;
  155. int i; /* inode chunk index */
  156. agbno = XFS_AGINO_TO_AGBNO(mp, irec->ir_startino);
  157. blks_per_cluster = xfs_icluster_size_fsb(mp);
  158. inodes_per_cluster = blks_per_cluster << mp->m_sb.sb_inopblog;
  159. blk_start_plug(&plug);
  160. for (i = 0; i < XFS_INODES_PER_CHUNK;
  161. i += inodes_per_cluster, agbno += blks_per_cluster) {
  162. if (xfs_inobt_maskn(i, inodes_per_cluster) & ~irec->ir_free) {
  163. xfs_btree_reada_bufs(mp, agno, agbno, blks_per_cluster,
  164. &xfs_inode_buf_ops);
  165. }
  166. }
  167. blk_finish_plug(&plug);
  168. }
  169. /*
  170. * Lookup the inode chunk that the given inode lives in and then get the record
  171. * if we found the chunk. If the inode was not the last in the chunk and there
  172. * are some left allocated, update the data for the pointed-to record as well as
  173. * return the count of grabbed inodes.
  174. */
  175. STATIC int
  176. xfs_bulkstat_grab_ichunk(
  177. struct xfs_btree_cur *cur, /* btree cursor */
  178. xfs_agino_t agino, /* starting inode of chunk */
  179. int *icount,/* return # of inodes grabbed */
  180. struct xfs_inobt_rec_incore *irec) /* btree record */
  181. {
  182. int idx; /* index into inode chunk */
  183. int stat;
  184. int error = 0;
  185. /* Lookup the inode chunk that this inode lives in */
  186. error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_LE, &stat);
  187. if (error)
  188. return error;
  189. if (!stat) {
  190. *icount = 0;
  191. return error;
  192. }
  193. /* Get the record, should always work */
  194. error = xfs_inobt_get_rec(cur, irec, &stat);
  195. if (error)
  196. return error;
  197. XFS_WANT_CORRUPTED_RETURN(cur->bc_mp, stat == 1);
  198. /* Check if the record contains the inode in request */
  199. if (irec->ir_startino + XFS_INODES_PER_CHUNK <= agino) {
  200. *icount = 0;
  201. return 0;
  202. }
  203. idx = agino - irec->ir_startino + 1;
  204. if (idx < XFS_INODES_PER_CHUNK &&
  205. (xfs_inobt_maskn(idx, XFS_INODES_PER_CHUNK - idx) & ~irec->ir_free)) {
  206. int i;
  207. /* We got a right chunk with some left inodes allocated at it.
  208. * Grab the chunk record. Mark all the uninteresting inodes
  209. * free -- because they're before our start point.
  210. */
  211. for (i = 0; i < idx; i++) {
  212. if (XFS_INOBT_MASK(i) & ~irec->ir_free)
  213. irec->ir_freecount++;
  214. }
  215. irec->ir_free |= xfs_inobt_maskn(0, idx);
  216. *icount = irec->ir_count - irec->ir_freecount;
  217. }
  218. return 0;
  219. }
  220. #define XFS_BULKSTAT_UBLEFT(ubleft) ((ubleft) >= statstruct_size)
  221. struct xfs_bulkstat_agichunk {
  222. char __user **ac_ubuffer;/* pointer into user's buffer */
  223. int ac_ubleft; /* bytes left in user's buffer */
  224. int ac_ubelem; /* spaces used in user's buffer */
  225. };
  226. /*
  227. * Process inodes in chunk with a pointer to a formatter function
  228. * that will iget the inode and fill in the appropriate structure.
  229. */
  230. static int
  231. xfs_bulkstat_ag_ichunk(
  232. struct xfs_mount *mp,
  233. xfs_agnumber_t agno,
  234. struct xfs_inobt_rec_incore *irbp,
  235. bulkstat_one_pf formatter,
  236. size_t statstruct_size,
  237. struct xfs_bulkstat_agichunk *acp,
  238. xfs_agino_t *last_agino)
  239. {
  240. char __user **ubufp = acp->ac_ubuffer;
  241. int chunkidx;
  242. int error = 0;
  243. xfs_agino_t agino = irbp->ir_startino;
  244. for (chunkidx = 0; chunkidx < XFS_INODES_PER_CHUNK;
  245. chunkidx++, agino++) {
  246. int fmterror;
  247. int ubused;
  248. /* inode won't fit in buffer, we are done */
  249. if (acp->ac_ubleft < statstruct_size)
  250. break;
  251. /* Skip if this inode is free */
  252. if (XFS_INOBT_MASK(chunkidx) & irbp->ir_free)
  253. continue;
  254. /* Get the inode and fill in a single buffer */
  255. ubused = statstruct_size;
  256. error = formatter(mp, XFS_AGINO_TO_INO(mp, agno, agino),
  257. *ubufp, acp->ac_ubleft, &ubused, &fmterror);
  258. if (fmterror == BULKSTAT_RV_GIVEUP ||
  259. (error && error != -ENOENT && error != -EINVAL)) {
  260. acp->ac_ubleft = 0;
  261. ASSERT(error);
  262. break;
  263. }
  264. /* be careful not to leak error if at end of chunk */
  265. if (fmterror == BULKSTAT_RV_NOTHING || error) {
  266. error = 0;
  267. continue;
  268. }
  269. *ubufp += ubused;
  270. acp->ac_ubleft -= ubused;
  271. acp->ac_ubelem++;
  272. }
  273. /*
  274. * Post-update *last_agino. At this point, agino will always point one
  275. * inode past the last inode we processed successfully. Hence we
  276. * substract that inode when setting the *last_agino cursor so that we
  277. * return the correct cookie to userspace. On the next bulkstat call,
  278. * the inode under the lastino cookie will be skipped as we have already
  279. * processed it here.
  280. */
  281. *last_agino = agino - 1;
  282. return error;
  283. }
  284. /*
  285. * Return stat information in bulk (by-inode) for the filesystem.
  286. */
  287. int /* error status */
  288. xfs_bulkstat(
  289. xfs_mount_t *mp, /* mount point for filesystem */
  290. xfs_ino_t *lastinop, /* last inode returned */
  291. int *ubcountp, /* size of buffer/count returned */
  292. bulkstat_one_pf formatter, /* func that'd fill a single buf */
  293. size_t statstruct_size, /* sizeof struct filling */
  294. char __user *ubuffer, /* buffer with inode stats */
  295. int *done) /* 1 if there are more stats to get */
  296. {
  297. xfs_buf_t *agbp; /* agi header buffer */
  298. xfs_agino_t agino; /* inode # in allocation group */
  299. xfs_agnumber_t agno; /* allocation group number */
  300. xfs_btree_cur_t *cur; /* btree cursor for ialloc btree */
  301. xfs_inobt_rec_incore_t *irbuf; /* start of irec buffer */
  302. int nirbuf; /* size of irbuf */
  303. int ubcount; /* size of user's buffer */
  304. struct xfs_bulkstat_agichunk ac;
  305. int error = 0;
  306. /*
  307. * Get the last inode value, see if there's nothing to do.
  308. */
  309. agno = XFS_INO_TO_AGNO(mp, *lastinop);
  310. agino = XFS_INO_TO_AGINO(mp, *lastinop);
  311. if (agno >= mp->m_sb.sb_agcount ||
  312. *lastinop != XFS_AGINO_TO_INO(mp, agno, agino)) {
  313. *done = 1;
  314. *ubcountp = 0;
  315. return 0;
  316. }
  317. ubcount = *ubcountp; /* statstruct's */
  318. ac.ac_ubuffer = &ubuffer;
  319. ac.ac_ubleft = ubcount * statstruct_size; /* bytes */;
  320. ac.ac_ubelem = 0;
  321. *ubcountp = 0;
  322. *done = 0;
  323. irbuf = kmem_zalloc_large(PAGE_SIZE * 4, KM_SLEEP);
  324. if (!irbuf)
  325. return -ENOMEM;
  326. nirbuf = (PAGE_SIZE * 4) / sizeof(*irbuf);
  327. /*
  328. * Loop over the allocation groups, starting from the last
  329. * inode returned; 0 means start of the allocation group.
  330. */
  331. while (agno < mp->m_sb.sb_agcount) {
  332. struct xfs_inobt_rec_incore *irbp = irbuf;
  333. struct xfs_inobt_rec_incore *irbufend = irbuf + nirbuf;
  334. bool end_of_ag = false;
  335. int icount = 0;
  336. int stat;
  337. error = xfs_ialloc_read_agi(mp, NULL, agno, &agbp);
  338. if (error)
  339. break;
  340. /*
  341. * Allocate and initialize a btree cursor for ialloc btree.
  342. */
  343. cur = xfs_inobt_init_cursor(mp, NULL, agbp, agno,
  344. XFS_BTNUM_INO);
  345. if (agino > 0) {
  346. /*
  347. * In the middle of an allocation group, we need to get
  348. * the remainder of the chunk we're in.
  349. */
  350. struct xfs_inobt_rec_incore r;
  351. error = xfs_bulkstat_grab_ichunk(cur, agino, &icount, &r);
  352. if (error)
  353. goto del_cursor;
  354. if (icount) {
  355. irbp->ir_startino = r.ir_startino;
  356. irbp->ir_holemask = r.ir_holemask;
  357. irbp->ir_count = r.ir_count;
  358. irbp->ir_freecount = r.ir_freecount;
  359. irbp->ir_free = r.ir_free;
  360. irbp++;
  361. }
  362. /* Increment to the next record */
  363. error = xfs_btree_increment(cur, 0, &stat);
  364. } else {
  365. /* Start of ag. Lookup the first inode chunk */
  366. error = xfs_inobt_lookup(cur, 0, XFS_LOOKUP_GE, &stat);
  367. }
  368. if (error || stat == 0) {
  369. end_of_ag = true;
  370. goto del_cursor;
  371. }
  372. /*
  373. * Loop through inode btree records in this ag,
  374. * until we run out of inodes or space in the buffer.
  375. */
  376. while (irbp < irbufend && icount < ubcount) {
  377. struct xfs_inobt_rec_incore r;
  378. error = xfs_inobt_get_rec(cur, &r, &stat);
  379. if (error || stat == 0) {
  380. end_of_ag = true;
  381. goto del_cursor;
  382. }
  383. /*
  384. * If this chunk has any allocated inodes, save it.
  385. * Also start read-ahead now for this chunk.
  386. */
  387. if (r.ir_freecount < r.ir_count) {
  388. xfs_bulkstat_ichunk_ra(mp, agno, &r);
  389. irbp->ir_startino = r.ir_startino;
  390. irbp->ir_holemask = r.ir_holemask;
  391. irbp->ir_count = r.ir_count;
  392. irbp->ir_freecount = r.ir_freecount;
  393. irbp->ir_free = r.ir_free;
  394. irbp++;
  395. icount += r.ir_count - r.ir_freecount;
  396. }
  397. error = xfs_btree_increment(cur, 0, &stat);
  398. if (error || stat == 0) {
  399. end_of_ag = true;
  400. goto del_cursor;
  401. }
  402. cond_resched();
  403. }
  404. /*
  405. * Drop the btree buffers and the agi buffer as we can't hold any
  406. * of the locks these represent when calling iget. If there is a
  407. * pending error, then we are done.
  408. */
  409. del_cursor:
  410. xfs_btree_del_cursor(cur, error);
  411. xfs_buf_relse(agbp);
  412. if (error)
  413. break;
  414. /*
  415. * Now format all the good inodes into the user's buffer. The
  416. * call to xfs_bulkstat_ag_ichunk() sets up the agino pointer
  417. * for the next loop iteration.
  418. */
  419. irbufend = irbp;
  420. for (irbp = irbuf;
  421. irbp < irbufend && ac.ac_ubleft >= statstruct_size;
  422. irbp++) {
  423. error = xfs_bulkstat_ag_ichunk(mp, agno, irbp,
  424. formatter, statstruct_size, &ac,
  425. &agino);
  426. if (error)
  427. break;
  428. cond_resched();
  429. }
  430. /*
  431. * If we've run out of space or had a formatting error, we
  432. * are now done
  433. */
  434. if (ac.ac_ubleft < statstruct_size || error)
  435. break;
  436. if (end_of_ag) {
  437. agno++;
  438. agino = 0;
  439. }
  440. }
  441. /*
  442. * Done, we're either out of filesystem or space to put the data.
  443. */
  444. kmem_free(irbuf);
  445. *ubcountp = ac.ac_ubelem;
  446. /*
  447. * We found some inodes, so clear the error status and return them.
  448. * The lastino pointer will point directly at the inode that triggered
  449. * any error that occurred, so on the next call the error will be
  450. * triggered again and propagated to userspace as there will be no
  451. * formatted inodes in the buffer.
  452. */
  453. if (ac.ac_ubelem)
  454. error = 0;
  455. /*
  456. * If we ran out of filesystem, lastino will point off the end of
  457. * the filesystem so the next call will return immediately.
  458. */
  459. *lastinop = XFS_AGINO_TO_INO(mp, agno, agino);
  460. if (agno >= mp->m_sb.sb_agcount)
  461. *done = 1;
  462. return error;
  463. }
  464. int
  465. xfs_inumbers_fmt(
  466. void __user *ubuffer, /* buffer to write to */
  467. const struct xfs_inogrp *buffer, /* buffer to read from */
  468. long count, /* # of elements to read */
  469. long *written) /* # of bytes written */
  470. {
  471. if (copy_to_user(ubuffer, buffer, count * sizeof(*buffer)))
  472. return -EFAULT;
  473. *written = count * sizeof(*buffer);
  474. return 0;
  475. }
  476. /*
  477. * Return inode number table for the filesystem.
  478. */
  479. int /* error status */
  480. xfs_inumbers(
  481. struct xfs_mount *mp,/* mount point for filesystem */
  482. xfs_ino_t *lastino,/* last inode returned */
  483. int *count,/* size of buffer/count returned */
  484. void __user *ubuffer,/* buffer with inode descriptions */
  485. inumbers_fmt_pf formatter)
  486. {
  487. xfs_agnumber_t agno = XFS_INO_TO_AGNO(mp, *lastino);
  488. xfs_agino_t agino = XFS_INO_TO_AGINO(mp, *lastino);
  489. struct xfs_btree_cur *cur = NULL;
  490. struct xfs_buf *agbp = NULL;
  491. struct xfs_inogrp *buffer;
  492. int bcount;
  493. int left = *count;
  494. int bufidx = 0;
  495. int error = 0;
  496. *count = 0;
  497. if (agno >= mp->m_sb.sb_agcount ||
  498. *lastino != XFS_AGINO_TO_INO(mp, agno, agino))
  499. return error;
  500. bcount = min(left, (int)(PAGE_SIZE / sizeof(*buffer)));
  501. buffer = kmem_zalloc(bcount * sizeof(*buffer), KM_SLEEP);
  502. do {
  503. struct xfs_inobt_rec_incore r;
  504. int stat;
  505. if (!agbp) {
  506. error = xfs_ialloc_read_agi(mp, NULL, agno, &agbp);
  507. if (error)
  508. break;
  509. cur = xfs_inobt_init_cursor(mp, NULL, agbp, agno,
  510. XFS_BTNUM_INO);
  511. error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_GE,
  512. &stat);
  513. if (error)
  514. break;
  515. if (!stat)
  516. goto next_ag;
  517. }
  518. error = xfs_inobt_get_rec(cur, &r, &stat);
  519. if (error)
  520. break;
  521. if (!stat)
  522. goto next_ag;
  523. agino = r.ir_startino + XFS_INODES_PER_CHUNK - 1;
  524. buffer[bufidx].xi_startino =
  525. XFS_AGINO_TO_INO(mp, agno, r.ir_startino);
  526. buffer[bufidx].xi_alloccount = r.ir_count - r.ir_freecount;
  527. buffer[bufidx].xi_allocmask = ~r.ir_free;
  528. if (++bufidx == bcount) {
  529. long written;
  530. error = formatter(ubuffer, buffer, bufidx, &written);
  531. if (error)
  532. break;
  533. ubuffer += written;
  534. *count += bufidx;
  535. bufidx = 0;
  536. }
  537. if (!--left)
  538. break;
  539. error = xfs_btree_increment(cur, 0, &stat);
  540. if (error)
  541. break;
  542. if (stat)
  543. continue;
  544. next_ag:
  545. xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
  546. cur = NULL;
  547. xfs_buf_relse(agbp);
  548. agbp = NULL;
  549. agino = 0;
  550. agno++;
  551. } while (agno < mp->m_sb.sb_agcount);
  552. if (!error) {
  553. if (bufidx) {
  554. long written;
  555. error = formatter(ubuffer, buffer, bufidx, &written);
  556. if (!error)
  557. *count += bufidx;
  558. }
  559. *lastino = XFS_AGINO_TO_INO(mp, agno, agino);
  560. }
  561. kmem_free(buffer);
  562. if (cur)
  563. xfs_btree_del_cursor(cur, error);
  564. if (agbp)
  565. xfs_buf_relse(agbp);
  566. return error;
  567. }