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