xfs_inode_buf.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. /*
  2. * Copyright (c) 2000-2006 Silicon Graphics, Inc.
  3. * All Rights Reserved.
  4. *
  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
  7. * published by the Free Software Foundation.
  8. *
  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.
  13. *
  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
  17. */
  18. #include "xfs.h"
  19. #include "xfs_fs.h"
  20. #include "xfs_shared.h"
  21. #include "xfs_format.h"
  22. #include "xfs_log_format.h"
  23. #include "xfs_trans_resv.h"
  24. #include "xfs_mount.h"
  25. #include "xfs_defer.h"
  26. #include "xfs_inode.h"
  27. #include "xfs_error.h"
  28. #include "xfs_cksum.h"
  29. #include "xfs_icache.h"
  30. #include "xfs_trans.h"
  31. #include "xfs_ialloc.h"
  32. /*
  33. * Check that none of the inode's in the buffer have a next
  34. * unlinked field of 0.
  35. */
  36. #if defined(DEBUG)
  37. void
  38. xfs_inobp_check(
  39. xfs_mount_t *mp,
  40. xfs_buf_t *bp)
  41. {
  42. int i;
  43. int j;
  44. xfs_dinode_t *dip;
  45. j = mp->m_inode_cluster_size >> mp->m_sb.sb_inodelog;
  46. for (i = 0; i < j; i++) {
  47. dip = xfs_buf_offset(bp, i * mp->m_sb.sb_inodesize);
  48. if (!dip->di_next_unlinked) {
  49. xfs_alert(mp,
  50. "Detected bogus zero next_unlinked field in inode %d buffer 0x%llx.",
  51. i, (long long)bp->b_bn);
  52. }
  53. }
  54. }
  55. #endif
  56. bool
  57. xfs_dinode_good_version(
  58. struct xfs_mount *mp,
  59. __u8 version)
  60. {
  61. if (xfs_sb_version_hascrc(&mp->m_sb))
  62. return version == 3;
  63. return version == 1 || version == 2;
  64. }
  65. /*
  66. * If we are doing readahead on an inode buffer, we might be in log recovery
  67. * reading an inode allocation buffer that hasn't yet been replayed, and hence
  68. * has not had the inode cores stamped into it. Hence for readahead, the buffer
  69. * may be potentially invalid.
  70. *
  71. * If the readahead buffer is invalid, we need to mark it with an error and
  72. * clear the DONE status of the buffer so that a followup read will re-read it
  73. * from disk. We don't report the error otherwise to avoid warnings during log
  74. * recovery and we don't get unnecssary panics on debug kernels. We use EIO here
  75. * because all we want to do is say readahead failed; there is no-one to report
  76. * the error to, so this will distinguish it from a non-ra verifier failure.
  77. * Changes to this readahead error behavour also need to be reflected in
  78. * xfs_dquot_buf_readahead_verify().
  79. */
  80. static void
  81. xfs_inode_buf_verify(
  82. struct xfs_buf *bp,
  83. bool readahead)
  84. {
  85. struct xfs_mount *mp = bp->b_target->bt_mount;
  86. int i;
  87. int ni;
  88. /*
  89. * Validate the magic number and version of every inode in the buffer
  90. */
  91. ni = XFS_BB_TO_FSB(mp, bp->b_length) * mp->m_sb.sb_inopblock;
  92. for (i = 0; i < ni; i++) {
  93. int di_ok;
  94. xfs_dinode_t *dip;
  95. dip = xfs_buf_offset(bp, (i << mp->m_sb.sb_inodelog));
  96. di_ok = dip->di_magic == cpu_to_be16(XFS_DINODE_MAGIC) &&
  97. xfs_dinode_good_version(mp, dip->di_version);
  98. if (unlikely(XFS_TEST_ERROR(!di_ok, mp,
  99. XFS_ERRTAG_ITOBP_INOTOBP,
  100. XFS_RANDOM_ITOBP_INOTOBP))) {
  101. if (readahead) {
  102. bp->b_flags &= ~XBF_DONE;
  103. xfs_buf_ioerror(bp, -EIO);
  104. return;
  105. }
  106. xfs_buf_ioerror(bp, -EFSCORRUPTED);
  107. xfs_verifier_error(bp);
  108. #ifdef DEBUG
  109. xfs_alert(mp,
  110. "bad inode magic/vsn daddr %lld #%d (magic=%x)",
  111. (unsigned long long)bp->b_bn, i,
  112. be16_to_cpu(dip->di_magic));
  113. #endif
  114. }
  115. }
  116. xfs_inobp_check(mp, bp);
  117. }
  118. static void
  119. xfs_inode_buf_read_verify(
  120. struct xfs_buf *bp)
  121. {
  122. xfs_inode_buf_verify(bp, false);
  123. }
  124. static void
  125. xfs_inode_buf_readahead_verify(
  126. struct xfs_buf *bp)
  127. {
  128. xfs_inode_buf_verify(bp, true);
  129. }
  130. static void
  131. xfs_inode_buf_write_verify(
  132. struct xfs_buf *bp)
  133. {
  134. xfs_inode_buf_verify(bp, false);
  135. }
  136. const struct xfs_buf_ops xfs_inode_buf_ops = {
  137. .name = "xfs_inode",
  138. .verify_read = xfs_inode_buf_read_verify,
  139. .verify_write = xfs_inode_buf_write_verify,
  140. };
  141. const struct xfs_buf_ops xfs_inode_buf_ra_ops = {
  142. .name = "xxfs_inode_ra",
  143. .verify_read = xfs_inode_buf_readahead_verify,
  144. .verify_write = xfs_inode_buf_write_verify,
  145. };
  146. /*
  147. * This routine is called to map an inode to the buffer containing the on-disk
  148. * version of the inode. It returns a pointer to the buffer containing the
  149. * on-disk inode in the bpp parameter, and in the dipp parameter it returns a
  150. * pointer to the on-disk inode within that buffer.
  151. *
  152. * If a non-zero error is returned, then the contents of bpp and dipp are
  153. * undefined.
  154. */
  155. int
  156. xfs_imap_to_bp(
  157. struct xfs_mount *mp,
  158. struct xfs_trans *tp,
  159. struct xfs_imap *imap,
  160. struct xfs_dinode **dipp,
  161. struct xfs_buf **bpp,
  162. uint buf_flags,
  163. uint iget_flags)
  164. {
  165. struct xfs_buf *bp;
  166. int error;
  167. buf_flags |= XBF_UNMAPPED;
  168. error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp, imap->im_blkno,
  169. (int)imap->im_len, buf_flags, &bp,
  170. &xfs_inode_buf_ops);
  171. if (error) {
  172. if (error == -EAGAIN) {
  173. ASSERT(buf_flags & XBF_TRYLOCK);
  174. return error;
  175. }
  176. if (error == -EFSCORRUPTED &&
  177. (iget_flags & XFS_IGET_UNTRUSTED))
  178. return -EINVAL;
  179. xfs_warn(mp, "%s: xfs_trans_read_buf() returned error %d.",
  180. __func__, error);
  181. return error;
  182. }
  183. *bpp = bp;
  184. *dipp = xfs_buf_offset(bp, imap->im_boffset);
  185. return 0;
  186. }
  187. void
  188. xfs_inode_from_disk(
  189. struct xfs_inode *ip,
  190. struct xfs_dinode *from)
  191. {
  192. struct xfs_icdinode *to = &ip->i_d;
  193. struct inode *inode = VFS_I(ip);
  194. /*
  195. * Convert v1 inodes immediately to v2 inode format as this is the
  196. * minimum inode version format we support in the rest of the code.
  197. */
  198. to->di_version = from->di_version;
  199. if (to->di_version == 1) {
  200. set_nlink(inode, be16_to_cpu(from->di_onlink));
  201. to->di_projid_lo = 0;
  202. to->di_projid_hi = 0;
  203. to->di_version = 2;
  204. } else {
  205. set_nlink(inode, be32_to_cpu(from->di_nlink));
  206. to->di_projid_lo = be16_to_cpu(from->di_projid_lo);
  207. to->di_projid_hi = be16_to_cpu(from->di_projid_hi);
  208. }
  209. to->di_format = from->di_format;
  210. to->di_uid = be32_to_cpu(from->di_uid);
  211. to->di_gid = be32_to_cpu(from->di_gid);
  212. to->di_flushiter = be16_to_cpu(from->di_flushiter);
  213. /*
  214. * Time is signed, so need to convert to signed 32 bit before
  215. * storing in inode timestamp which may be 64 bit. Otherwise
  216. * a time before epoch is converted to a time long after epoch
  217. * on 64 bit systems.
  218. */
  219. inode->i_atime.tv_sec = (int)be32_to_cpu(from->di_atime.t_sec);
  220. inode->i_atime.tv_nsec = (int)be32_to_cpu(from->di_atime.t_nsec);
  221. inode->i_mtime.tv_sec = (int)be32_to_cpu(from->di_mtime.t_sec);
  222. inode->i_mtime.tv_nsec = (int)be32_to_cpu(from->di_mtime.t_nsec);
  223. inode->i_ctime.tv_sec = (int)be32_to_cpu(from->di_ctime.t_sec);
  224. inode->i_ctime.tv_nsec = (int)be32_to_cpu(from->di_ctime.t_nsec);
  225. inode->i_generation = be32_to_cpu(from->di_gen);
  226. inode->i_mode = be16_to_cpu(from->di_mode);
  227. to->di_size = be64_to_cpu(from->di_size);
  228. to->di_nblocks = be64_to_cpu(from->di_nblocks);
  229. to->di_extsize = be32_to_cpu(from->di_extsize);
  230. to->di_nextents = be32_to_cpu(from->di_nextents);
  231. to->di_anextents = be16_to_cpu(from->di_anextents);
  232. to->di_forkoff = from->di_forkoff;
  233. to->di_aformat = from->di_aformat;
  234. to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
  235. to->di_dmstate = be16_to_cpu(from->di_dmstate);
  236. to->di_flags = be16_to_cpu(from->di_flags);
  237. if (to->di_version == 3) {
  238. inode->i_version = be64_to_cpu(from->di_changecount);
  239. to->di_crtime.t_sec = be32_to_cpu(from->di_crtime.t_sec);
  240. to->di_crtime.t_nsec = be32_to_cpu(from->di_crtime.t_nsec);
  241. to->di_flags2 = be64_to_cpu(from->di_flags2);
  242. to->di_cowextsize = be32_to_cpu(from->di_cowextsize);
  243. }
  244. }
  245. void
  246. xfs_inode_to_disk(
  247. struct xfs_inode *ip,
  248. struct xfs_dinode *to,
  249. xfs_lsn_t lsn)
  250. {
  251. struct xfs_icdinode *from = &ip->i_d;
  252. struct inode *inode = VFS_I(ip);
  253. to->di_magic = cpu_to_be16(XFS_DINODE_MAGIC);
  254. to->di_onlink = 0;
  255. to->di_version = from->di_version;
  256. to->di_format = from->di_format;
  257. to->di_uid = cpu_to_be32(from->di_uid);
  258. to->di_gid = cpu_to_be32(from->di_gid);
  259. to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
  260. to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
  261. memset(to->di_pad, 0, sizeof(to->di_pad));
  262. to->di_atime.t_sec = cpu_to_be32(inode->i_atime.tv_sec);
  263. to->di_atime.t_nsec = cpu_to_be32(inode->i_atime.tv_nsec);
  264. to->di_mtime.t_sec = cpu_to_be32(inode->i_mtime.tv_sec);
  265. to->di_mtime.t_nsec = cpu_to_be32(inode->i_mtime.tv_nsec);
  266. to->di_ctime.t_sec = cpu_to_be32(inode->i_ctime.tv_sec);
  267. to->di_ctime.t_nsec = cpu_to_be32(inode->i_ctime.tv_nsec);
  268. to->di_nlink = cpu_to_be32(inode->i_nlink);
  269. to->di_gen = cpu_to_be32(inode->i_generation);
  270. to->di_mode = cpu_to_be16(inode->i_mode);
  271. to->di_size = cpu_to_be64(from->di_size);
  272. to->di_nblocks = cpu_to_be64(from->di_nblocks);
  273. to->di_extsize = cpu_to_be32(from->di_extsize);
  274. to->di_nextents = cpu_to_be32(from->di_nextents);
  275. to->di_anextents = cpu_to_be16(from->di_anextents);
  276. to->di_forkoff = from->di_forkoff;
  277. to->di_aformat = from->di_aformat;
  278. to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
  279. to->di_dmstate = cpu_to_be16(from->di_dmstate);
  280. to->di_flags = cpu_to_be16(from->di_flags);
  281. if (from->di_version == 3) {
  282. to->di_changecount = cpu_to_be64(inode->i_version);
  283. to->di_crtime.t_sec = cpu_to_be32(from->di_crtime.t_sec);
  284. to->di_crtime.t_nsec = cpu_to_be32(from->di_crtime.t_nsec);
  285. to->di_flags2 = cpu_to_be64(from->di_flags2);
  286. to->di_cowextsize = cpu_to_be32(from->di_cowextsize);
  287. to->di_ino = cpu_to_be64(ip->i_ino);
  288. to->di_lsn = cpu_to_be64(lsn);
  289. memset(to->di_pad2, 0, sizeof(to->di_pad2));
  290. uuid_copy(&to->di_uuid, &ip->i_mount->m_sb.sb_meta_uuid);
  291. to->di_flushiter = 0;
  292. } else {
  293. to->di_flushiter = cpu_to_be16(from->di_flushiter);
  294. }
  295. }
  296. void
  297. xfs_log_dinode_to_disk(
  298. struct xfs_log_dinode *from,
  299. struct xfs_dinode *to)
  300. {
  301. to->di_magic = cpu_to_be16(from->di_magic);
  302. to->di_mode = cpu_to_be16(from->di_mode);
  303. to->di_version = from->di_version;
  304. to->di_format = from->di_format;
  305. to->di_onlink = 0;
  306. to->di_uid = cpu_to_be32(from->di_uid);
  307. to->di_gid = cpu_to_be32(from->di_gid);
  308. to->di_nlink = cpu_to_be32(from->di_nlink);
  309. to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
  310. to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
  311. memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
  312. to->di_atime.t_sec = cpu_to_be32(from->di_atime.t_sec);
  313. to->di_atime.t_nsec = cpu_to_be32(from->di_atime.t_nsec);
  314. to->di_mtime.t_sec = cpu_to_be32(from->di_mtime.t_sec);
  315. to->di_mtime.t_nsec = cpu_to_be32(from->di_mtime.t_nsec);
  316. to->di_ctime.t_sec = cpu_to_be32(from->di_ctime.t_sec);
  317. to->di_ctime.t_nsec = cpu_to_be32(from->di_ctime.t_nsec);
  318. to->di_size = cpu_to_be64(from->di_size);
  319. to->di_nblocks = cpu_to_be64(from->di_nblocks);
  320. to->di_extsize = cpu_to_be32(from->di_extsize);
  321. to->di_nextents = cpu_to_be32(from->di_nextents);
  322. to->di_anextents = cpu_to_be16(from->di_anextents);
  323. to->di_forkoff = from->di_forkoff;
  324. to->di_aformat = from->di_aformat;
  325. to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
  326. to->di_dmstate = cpu_to_be16(from->di_dmstate);
  327. to->di_flags = cpu_to_be16(from->di_flags);
  328. to->di_gen = cpu_to_be32(from->di_gen);
  329. if (from->di_version == 3) {
  330. to->di_changecount = cpu_to_be64(from->di_changecount);
  331. to->di_crtime.t_sec = cpu_to_be32(from->di_crtime.t_sec);
  332. to->di_crtime.t_nsec = cpu_to_be32(from->di_crtime.t_nsec);
  333. to->di_flags2 = cpu_to_be64(from->di_flags2);
  334. to->di_cowextsize = cpu_to_be32(from->di_cowextsize);
  335. to->di_ino = cpu_to_be64(from->di_ino);
  336. to->di_lsn = cpu_to_be64(from->di_lsn);
  337. memcpy(to->di_pad2, from->di_pad2, sizeof(to->di_pad2));
  338. uuid_copy(&to->di_uuid, &from->di_uuid);
  339. to->di_flushiter = 0;
  340. } else {
  341. to->di_flushiter = cpu_to_be16(from->di_flushiter);
  342. }
  343. }
  344. static bool
  345. xfs_dinode_verify(
  346. struct xfs_mount *mp,
  347. xfs_ino_t ino,
  348. struct xfs_dinode *dip)
  349. {
  350. uint16_t flags;
  351. uint64_t flags2;
  352. if (dip->di_magic != cpu_to_be16(XFS_DINODE_MAGIC))
  353. return false;
  354. /* only version 3 or greater inodes are extensively verified here */
  355. if (dip->di_version < 3)
  356. return true;
  357. if (!xfs_sb_version_hascrc(&mp->m_sb))
  358. return false;
  359. if (!xfs_verify_cksum((char *)dip, mp->m_sb.sb_inodesize,
  360. XFS_DINODE_CRC_OFF))
  361. return false;
  362. if (be64_to_cpu(dip->di_ino) != ino)
  363. return false;
  364. if (!uuid_equal(&dip->di_uuid, &mp->m_sb.sb_meta_uuid))
  365. return false;
  366. flags = be16_to_cpu(dip->di_flags);
  367. flags2 = be64_to_cpu(dip->di_flags2);
  368. /* don't allow reflink/cowextsize if we don't have reflink */
  369. if ((flags2 & (XFS_DIFLAG2_REFLINK | XFS_DIFLAG2_COWEXTSIZE)) &&
  370. !xfs_sb_version_hasreflink(&mp->m_sb))
  371. return false;
  372. /* don't let reflink and realtime mix */
  373. if ((flags2 & XFS_DIFLAG2_REFLINK) && (flags & XFS_DIFLAG_REALTIME))
  374. return false;
  375. /* don't let reflink and dax mix */
  376. if ((flags2 & XFS_DIFLAG2_REFLINK) && (flags2 & XFS_DIFLAG2_DAX))
  377. return false;
  378. return true;
  379. }
  380. void
  381. xfs_dinode_calc_crc(
  382. struct xfs_mount *mp,
  383. struct xfs_dinode *dip)
  384. {
  385. __uint32_t crc;
  386. if (dip->di_version < 3)
  387. return;
  388. ASSERT(xfs_sb_version_hascrc(&mp->m_sb));
  389. crc = xfs_start_cksum((char *)dip, mp->m_sb.sb_inodesize,
  390. XFS_DINODE_CRC_OFF);
  391. dip->di_crc = xfs_end_cksum(crc);
  392. }
  393. /*
  394. * Read the disk inode attributes into the in-core inode structure.
  395. *
  396. * For version 5 superblocks, if we are initialising a new inode and we are not
  397. * utilising the XFS_MOUNT_IKEEP inode cluster mode, we can simple build the new
  398. * inode core with a random generation number. If we are keeping inodes around,
  399. * we need to read the inode cluster to get the existing generation number off
  400. * disk. Further, if we are using version 4 superblocks (i.e. v1/v2 inode
  401. * format) then log recovery is dependent on the di_flushiter field being
  402. * initialised from the current on-disk value and hence we must also read the
  403. * inode off disk.
  404. */
  405. int
  406. xfs_iread(
  407. xfs_mount_t *mp,
  408. xfs_trans_t *tp,
  409. xfs_inode_t *ip,
  410. uint iget_flags)
  411. {
  412. xfs_buf_t *bp;
  413. xfs_dinode_t *dip;
  414. int error;
  415. /*
  416. * Fill in the location information in the in-core inode.
  417. */
  418. error = xfs_imap(mp, tp, ip->i_ino, &ip->i_imap, iget_flags);
  419. if (error)
  420. return error;
  421. /* shortcut IO on inode allocation if possible */
  422. if ((iget_flags & XFS_IGET_CREATE) &&
  423. xfs_sb_version_hascrc(&mp->m_sb) &&
  424. !(mp->m_flags & XFS_MOUNT_IKEEP)) {
  425. /* initialise the on-disk inode core */
  426. memset(&ip->i_d, 0, sizeof(ip->i_d));
  427. VFS_I(ip)->i_generation = prandom_u32();
  428. if (xfs_sb_version_hascrc(&mp->m_sb))
  429. ip->i_d.di_version = 3;
  430. else
  431. ip->i_d.di_version = 2;
  432. return 0;
  433. }
  434. /*
  435. * Get pointers to the on-disk inode and the buffer containing it.
  436. */
  437. error = xfs_imap_to_bp(mp, tp, &ip->i_imap, &dip, &bp, 0, iget_flags);
  438. if (error)
  439. return error;
  440. /* even unallocated inodes are verified */
  441. if (!xfs_dinode_verify(mp, ip->i_ino, dip)) {
  442. xfs_alert(mp, "%s: validation failed for inode %lld failed",
  443. __func__, ip->i_ino);
  444. XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, dip);
  445. error = -EFSCORRUPTED;
  446. goto out_brelse;
  447. }
  448. /*
  449. * If the on-disk inode is already linked to a directory
  450. * entry, copy all of the inode into the in-core inode.
  451. * xfs_iformat_fork() handles copying in the inode format
  452. * specific information.
  453. * Otherwise, just get the truly permanent information.
  454. */
  455. if (dip->di_mode) {
  456. xfs_inode_from_disk(ip, dip);
  457. error = xfs_iformat_fork(ip, dip);
  458. if (error) {
  459. #ifdef DEBUG
  460. xfs_alert(mp, "%s: xfs_iformat() returned error %d",
  461. __func__, error);
  462. #endif /* DEBUG */
  463. goto out_brelse;
  464. }
  465. } else {
  466. /*
  467. * Partial initialisation of the in-core inode. Just the bits
  468. * that xfs_ialloc won't overwrite or relies on being correct.
  469. */
  470. ip->i_d.di_version = dip->di_version;
  471. VFS_I(ip)->i_generation = be32_to_cpu(dip->di_gen);
  472. ip->i_d.di_flushiter = be16_to_cpu(dip->di_flushiter);
  473. /*
  474. * Make sure to pull in the mode here as well in
  475. * case the inode is released without being used.
  476. * This ensures that xfs_inactive() will see that
  477. * the inode is already free and not try to mess
  478. * with the uninitialized part of it.
  479. */
  480. VFS_I(ip)->i_mode = 0;
  481. }
  482. ASSERT(ip->i_d.di_version >= 2);
  483. ip->i_delayed_blks = 0;
  484. /*
  485. * Mark the buffer containing the inode as something to keep
  486. * around for a while. This helps to keep recently accessed
  487. * meta-data in-core longer.
  488. */
  489. xfs_buf_set_ref(bp, XFS_INO_REF);
  490. /*
  491. * Use xfs_trans_brelse() to release the buffer containing the on-disk
  492. * inode, because it was acquired with xfs_trans_read_buf() in
  493. * xfs_imap_to_bp() above. If tp is NULL, this is just a normal
  494. * brelse(). If we're within a transaction, then xfs_trans_brelse()
  495. * will only release the buffer if it is not dirty within the
  496. * transaction. It will be OK to release the buffer in this case,
  497. * because inodes on disk are never destroyed and we will be locking the
  498. * new in-core inode before putting it in the cache where other
  499. * processes can find it. Thus we don't have to worry about the inode
  500. * being changed just because we released the buffer.
  501. */
  502. out_brelse:
  503. xfs_trans_brelse(tp, bp);
  504. return error;
  505. }