xfs_inode_buf.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  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_errortag.h"
  28. #include "xfs_error.h"
  29. #include "xfs_cksum.h"
  30. #include "xfs_icache.h"
  31. #include "xfs_trans.h"
  32. #include "xfs_ialloc.h"
  33. #include "xfs_dir2.h"
  34. /*
  35. * Check that none of the inode's in the buffer have a next
  36. * unlinked field of 0.
  37. */
  38. #if defined(DEBUG)
  39. void
  40. xfs_inobp_check(
  41. xfs_mount_t *mp,
  42. xfs_buf_t *bp)
  43. {
  44. int i;
  45. int j;
  46. xfs_dinode_t *dip;
  47. j = mp->m_inode_cluster_size >> mp->m_sb.sb_inodelog;
  48. for (i = 0; i < j; i++) {
  49. dip = xfs_buf_offset(bp, i * mp->m_sb.sb_inodesize);
  50. if (!dip->di_next_unlinked) {
  51. xfs_alert(mp,
  52. "Detected bogus zero next_unlinked field in inode %d buffer 0x%llx.",
  53. i, (long long)bp->b_bn);
  54. }
  55. }
  56. }
  57. #endif
  58. bool
  59. xfs_dinode_good_version(
  60. struct xfs_mount *mp,
  61. __u8 version)
  62. {
  63. if (xfs_sb_version_hascrc(&mp->m_sb))
  64. return version == 3;
  65. return version == 1 || version == 2;
  66. }
  67. /*
  68. * If we are doing readahead on an inode buffer, we might be in log recovery
  69. * reading an inode allocation buffer that hasn't yet been replayed, and hence
  70. * has not had the inode cores stamped into it. Hence for readahead, the buffer
  71. * may be potentially invalid.
  72. *
  73. * If the readahead buffer is invalid, we need to mark it with an error and
  74. * clear the DONE status of the buffer so that a followup read will re-read it
  75. * from disk. We don't report the error otherwise to avoid warnings during log
  76. * recovery and we don't get unnecssary panics on debug kernels. We use EIO here
  77. * because all we want to do is say readahead failed; there is no-one to report
  78. * the error to, so this will distinguish it from a non-ra verifier failure.
  79. * Changes to this readahead error behavour also need to be reflected in
  80. * xfs_dquot_buf_readahead_verify().
  81. */
  82. static void
  83. xfs_inode_buf_verify(
  84. struct xfs_buf *bp,
  85. bool readahead)
  86. {
  87. struct xfs_mount *mp = bp->b_target->bt_mount;
  88. int i;
  89. int ni;
  90. /*
  91. * Validate the magic number and version of every inode in the buffer
  92. */
  93. ni = XFS_BB_TO_FSB(mp, bp->b_length) * mp->m_sb.sb_inopblock;
  94. for (i = 0; i < ni; i++) {
  95. int di_ok;
  96. xfs_dinode_t *dip;
  97. dip = xfs_buf_offset(bp, (i << mp->m_sb.sb_inodelog));
  98. di_ok = dip->di_magic == cpu_to_be16(XFS_DINODE_MAGIC) &&
  99. xfs_dinode_good_version(mp, dip->di_version);
  100. if (unlikely(XFS_TEST_ERROR(!di_ok, mp,
  101. XFS_ERRTAG_ITOBP_INOTOBP))) {
  102. if (readahead) {
  103. bp->b_flags &= ~XBF_DONE;
  104. xfs_buf_ioerror(bp, -EIO);
  105. return;
  106. }
  107. xfs_verifier_error(bp, -EFSCORRUPTED, __this_address);
  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. xfs_failaddr_t
  345. xfs_dinode_verify(
  346. struct xfs_mount *mp,
  347. xfs_ino_t ino,
  348. struct xfs_dinode *dip)
  349. {
  350. uint16_t mode;
  351. uint16_t flags;
  352. uint64_t flags2;
  353. if (dip->di_magic != cpu_to_be16(XFS_DINODE_MAGIC))
  354. return __this_address;
  355. /* don't allow invalid i_size */
  356. if (be64_to_cpu(dip->di_size) & (1ULL << 63))
  357. return __this_address;
  358. mode = be16_to_cpu(dip->di_mode);
  359. if (mode && xfs_mode_to_ftype(mode) == XFS_DIR3_FT_UNKNOWN)
  360. return __this_address;
  361. /* No zero-length symlinks/dirs. */
  362. if ((S_ISLNK(mode) || S_ISDIR(mode)) && dip->di_size == 0)
  363. return __this_address;
  364. /* only version 3 or greater inodes are extensively verified here */
  365. if (dip->di_version < 3)
  366. return NULL;
  367. if (!xfs_sb_version_hascrc(&mp->m_sb))
  368. return __this_address;
  369. if (!xfs_verify_cksum((char *)dip, mp->m_sb.sb_inodesize,
  370. XFS_DINODE_CRC_OFF))
  371. return __this_address;
  372. if (be64_to_cpu(dip->di_ino) != ino)
  373. return __this_address;
  374. if (!uuid_equal(&dip->di_uuid, &mp->m_sb.sb_meta_uuid))
  375. return __this_address;
  376. flags = be16_to_cpu(dip->di_flags);
  377. flags2 = be64_to_cpu(dip->di_flags2);
  378. /* don't allow reflink/cowextsize if we don't have reflink */
  379. if ((flags2 & (XFS_DIFLAG2_REFLINK | XFS_DIFLAG2_COWEXTSIZE)) &&
  380. !xfs_sb_version_hasreflink(&mp->m_sb))
  381. return __this_address;
  382. /* don't let reflink and realtime mix */
  383. if ((flags2 & XFS_DIFLAG2_REFLINK) && (flags & XFS_DIFLAG_REALTIME))
  384. return __this_address;
  385. /* don't let reflink and dax mix */
  386. if ((flags2 & XFS_DIFLAG2_REFLINK) && (flags2 & XFS_DIFLAG2_DAX))
  387. return __this_address;
  388. return NULL;
  389. }
  390. void
  391. xfs_dinode_calc_crc(
  392. struct xfs_mount *mp,
  393. struct xfs_dinode *dip)
  394. {
  395. uint32_t crc;
  396. if (dip->di_version < 3)
  397. return;
  398. ASSERT(xfs_sb_version_hascrc(&mp->m_sb));
  399. crc = xfs_start_cksum_update((char *)dip, mp->m_sb.sb_inodesize,
  400. XFS_DINODE_CRC_OFF);
  401. dip->di_crc = xfs_end_cksum(crc);
  402. }
  403. /*
  404. * Read the disk inode attributes into the in-core inode structure.
  405. *
  406. * For version 5 superblocks, if we are initialising a new inode and we are not
  407. * utilising the XFS_MOUNT_IKEEP inode cluster mode, we can simple build the new
  408. * inode core with a random generation number. If we are keeping inodes around,
  409. * we need to read the inode cluster to get the existing generation number off
  410. * disk. Further, if we are using version 4 superblocks (i.e. v1/v2 inode
  411. * format) then log recovery is dependent on the di_flushiter field being
  412. * initialised from the current on-disk value and hence we must also read the
  413. * inode off disk.
  414. */
  415. int
  416. xfs_iread(
  417. xfs_mount_t *mp,
  418. xfs_trans_t *tp,
  419. xfs_inode_t *ip,
  420. uint iget_flags)
  421. {
  422. xfs_buf_t *bp;
  423. xfs_dinode_t *dip;
  424. xfs_failaddr_t fa;
  425. int error;
  426. /*
  427. * Fill in the location information in the in-core inode.
  428. */
  429. error = xfs_imap(mp, tp, ip->i_ino, &ip->i_imap, iget_flags);
  430. if (error)
  431. return error;
  432. /* shortcut IO on inode allocation if possible */
  433. if ((iget_flags & XFS_IGET_CREATE) &&
  434. xfs_sb_version_hascrc(&mp->m_sb) &&
  435. !(mp->m_flags & XFS_MOUNT_IKEEP)) {
  436. /* initialise the on-disk inode core */
  437. memset(&ip->i_d, 0, sizeof(ip->i_d));
  438. VFS_I(ip)->i_generation = prandom_u32();
  439. if (xfs_sb_version_hascrc(&mp->m_sb))
  440. ip->i_d.di_version = 3;
  441. else
  442. ip->i_d.di_version = 2;
  443. return 0;
  444. }
  445. /*
  446. * Get pointers to the on-disk inode and the buffer containing it.
  447. */
  448. error = xfs_imap_to_bp(mp, tp, &ip->i_imap, &dip, &bp, 0, iget_flags);
  449. if (error)
  450. return error;
  451. /* even unallocated inodes are verified */
  452. fa = xfs_dinode_verify(mp, ip->i_ino, dip);
  453. if (fa) {
  454. xfs_alert(mp, "%s: validation failed for inode %lld at %pS",
  455. __func__, ip->i_ino, fa);
  456. XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, dip);
  457. error = -EFSCORRUPTED;
  458. goto out_brelse;
  459. }
  460. /*
  461. * If the on-disk inode is already linked to a directory
  462. * entry, copy all of the inode into the in-core inode.
  463. * xfs_iformat_fork() handles copying in the inode format
  464. * specific information.
  465. * Otherwise, just get the truly permanent information.
  466. */
  467. if (dip->di_mode) {
  468. xfs_inode_from_disk(ip, dip);
  469. error = xfs_iformat_fork(ip, dip);
  470. if (error) {
  471. #ifdef DEBUG
  472. xfs_alert(mp, "%s: xfs_iformat() returned error %d",
  473. __func__, error);
  474. #endif /* DEBUG */
  475. goto out_brelse;
  476. }
  477. } else {
  478. /*
  479. * Partial initialisation of the in-core inode. Just the bits
  480. * that xfs_ialloc won't overwrite or relies on being correct.
  481. */
  482. ip->i_d.di_version = dip->di_version;
  483. VFS_I(ip)->i_generation = be32_to_cpu(dip->di_gen);
  484. ip->i_d.di_flushiter = be16_to_cpu(dip->di_flushiter);
  485. /*
  486. * Make sure to pull in the mode here as well in
  487. * case the inode is released without being used.
  488. * This ensures that xfs_inactive() will see that
  489. * the inode is already free and not try to mess
  490. * with the uninitialized part of it.
  491. */
  492. VFS_I(ip)->i_mode = 0;
  493. }
  494. ASSERT(ip->i_d.di_version >= 2);
  495. ip->i_delayed_blks = 0;
  496. /*
  497. * Mark the buffer containing the inode as something to keep
  498. * around for a while. This helps to keep recently accessed
  499. * meta-data in-core longer.
  500. */
  501. xfs_buf_set_ref(bp, XFS_INO_REF);
  502. /*
  503. * Use xfs_trans_brelse() to release the buffer containing the on-disk
  504. * inode, because it was acquired with xfs_trans_read_buf() in
  505. * xfs_imap_to_bp() above. If tp is NULL, this is just a normal
  506. * brelse(). If we're within a transaction, then xfs_trans_brelse()
  507. * will only release the buffer if it is not dirty within the
  508. * transaction. It will be OK to release the buffer in this case,
  509. * because inodes on disk are never destroyed and we will be locking the
  510. * new in-core inode before putting it in the cache where other
  511. * processes can find it. Thus we don't have to worry about the inode
  512. * being changed just because we released the buffer.
  513. */
  514. out_brelse:
  515. xfs_trans_brelse(tp, bp);
  516. return error;
  517. }