xfs_inode_item.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199
  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_trans.h"
  15. #include "xfs_inode_item.h"
  16. #include "xfs_trace.h"
  17. #include "xfs_trans_priv.h"
  18. #include "xfs_buf_item.h"
  19. #include "xfs_log.h"
  20. #include "xfs_log_priv.h"
  21. #include "xfs_error.h"
  22. #include "xfs_rtbitmap.h"
  23. #include <linux/iversion.h>
  24. struct kmem_cache *xfs_ili_cache; /* inode log item */
  25. static inline struct xfs_inode_log_item *INODE_ITEM(struct xfs_log_item *lip)
  26. {
  27. return container_of(lip, struct xfs_inode_log_item, ili_item);
  28. }
  29. static uint64_t
  30. xfs_inode_item_sort(
  31. struct xfs_log_item *lip)
  32. {
  33. return INODE_ITEM(lip)->ili_inode->i_ino;
  34. }
  35. #ifdef DEBUG_EXPENSIVE
  36. static void
  37. xfs_inode_item_precommit_check(
  38. struct xfs_inode *ip)
  39. {
  40. struct xfs_mount *mp = ip->i_mount;
  41. struct xfs_dinode *dip;
  42. xfs_failaddr_t fa;
  43. dip = kzalloc(mp->m_sb.sb_inodesize, GFP_KERNEL | GFP_NOFS);
  44. if (!dip) {
  45. ASSERT(dip != NULL);
  46. return;
  47. }
  48. xfs_inode_to_disk(ip, dip, 0);
  49. xfs_dinode_calc_crc(mp, dip);
  50. fa = xfs_dinode_verify(mp, ip->i_ino, dip);
  51. if (fa) {
  52. xfs_inode_verifier_error(ip, -EFSCORRUPTED, __func__, dip,
  53. sizeof(*dip), fa);
  54. xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
  55. ASSERT(fa == NULL);
  56. }
  57. kfree(dip);
  58. }
  59. #else
  60. # define xfs_inode_item_precommit_check(ip) ((void)0)
  61. #endif
  62. /*
  63. * Prior to finally logging the inode, we have to ensure that all the
  64. * per-modification inode state changes are applied. This includes VFS inode
  65. * state updates, format conversions, verifier state synchronisation and
  66. * ensuring the inode buffer remains in memory whilst the inode is dirty.
  67. *
  68. * We have to be careful when we grab the inode cluster buffer due to lock
  69. * ordering constraints. The unlinked inode modifications (xfs_iunlink_item)
  70. * require AGI -> inode cluster buffer lock order. The inode cluster buffer is
  71. * not locked until ->precommit, so it happens after everything else has been
  72. * modified.
  73. *
  74. * Further, we have AGI -> AGF lock ordering, and with O_TMPFILE handling we
  75. * have AGI -> AGF -> iunlink item -> inode cluster buffer lock order. Hence we
  76. * cannot safely lock the inode cluster buffer in xfs_trans_log_inode() because
  77. * it can be called on a inode (e.g. via bumplink/droplink) before we take the
  78. * AGF lock modifying directory blocks.
  79. *
  80. * Rather than force a complete rework of all the transactions to call
  81. * xfs_trans_log_inode() once and once only at the end of every transaction, we
  82. * move the pinning of the inode cluster buffer to a ->precommit operation. This
  83. * matches how the xfs_iunlink_item locks the inode cluster buffer, and it
  84. * ensures that the inode cluster buffer locking is always done last in a
  85. * transaction. i.e. we ensure the lock order is always AGI -> AGF -> inode
  86. * cluster buffer.
  87. *
  88. * If we return the inode number as the precommit sort key then we'll also
  89. * guarantee that the order all inode cluster buffer locking is the same all the
  90. * inodes and unlink items in the transaction.
  91. */
  92. static int
  93. xfs_inode_item_precommit(
  94. struct xfs_trans *tp,
  95. struct xfs_log_item *lip)
  96. {
  97. struct xfs_inode_log_item *iip = INODE_ITEM(lip);
  98. struct xfs_inode *ip = iip->ili_inode;
  99. struct inode *inode = VFS_I(ip);
  100. unsigned int flags = iip->ili_dirty_flags;
  101. /*
  102. * Don't bother with i_lock for the I_DIRTY_TIME check here, as races
  103. * don't matter - we either will need an extra transaction in 24 hours
  104. * to log the timestamps, or will clear already cleared fields in the
  105. * worst case.
  106. */
  107. if (inode->i_state & I_DIRTY_TIME) {
  108. spin_lock(&inode->i_lock);
  109. inode->i_state &= ~I_DIRTY_TIME;
  110. spin_unlock(&inode->i_lock);
  111. }
  112. /*
  113. * If we're updating the inode core or the timestamps and it's possible
  114. * to upgrade this inode to bigtime format, do so now.
  115. */
  116. if ((flags & (XFS_ILOG_CORE | XFS_ILOG_TIMESTAMP)) &&
  117. xfs_has_bigtime(ip->i_mount) &&
  118. !xfs_inode_has_bigtime(ip)) {
  119. ip->i_diflags2 |= XFS_DIFLAG2_BIGTIME;
  120. flags |= XFS_ILOG_CORE;
  121. }
  122. /*
  123. * Inode verifiers do not check that the extent size hint is an integer
  124. * multiple of the rt extent size on a directory with both rtinherit
  125. * and extszinherit flags set. If we're logging a directory that is
  126. * misconfigured in this way, clear the hint.
  127. */
  128. if ((ip->i_diflags & XFS_DIFLAG_RTINHERIT) &&
  129. (ip->i_diflags & XFS_DIFLAG_EXTSZINHERIT) &&
  130. xfs_extlen_to_rtxmod(ip->i_mount, ip->i_extsize) > 0) {
  131. ip->i_diflags &= ~(XFS_DIFLAG_EXTSIZE |
  132. XFS_DIFLAG_EXTSZINHERIT);
  133. ip->i_extsize = 0;
  134. flags |= XFS_ILOG_CORE;
  135. }
  136. /*
  137. * Record the specific change for fdatasync optimisation. This allows
  138. * fdatasync to skip log forces for inodes that are only timestamp
  139. * dirty. Once we've processed the XFS_ILOG_IVERSION flag, convert it
  140. * to XFS_ILOG_CORE so that the actual on-disk dirty tracking
  141. * (ili_fields) correctly tracks that the version has changed.
  142. */
  143. spin_lock(&iip->ili_lock);
  144. iip->ili_fsync_fields |= (flags & ~XFS_ILOG_IVERSION);
  145. if (flags & XFS_ILOG_IVERSION)
  146. flags = ((flags & ~XFS_ILOG_IVERSION) | XFS_ILOG_CORE);
  147. if (!iip->ili_item.li_buf) {
  148. struct xfs_buf *bp;
  149. int error;
  150. /*
  151. * We hold the ILOCK here, so this inode is not going to be
  152. * flushed while we are here. Further, because there is no
  153. * buffer attached to the item, we know that there is no IO in
  154. * progress, so nothing will clear the ili_fields while we read
  155. * in the buffer. Hence we can safely drop the spin lock and
  156. * read the buffer knowing that the state will not change from
  157. * here.
  158. */
  159. spin_unlock(&iip->ili_lock);
  160. error = xfs_imap_to_bp(ip->i_mount, tp, &ip->i_imap, &bp);
  161. if (error)
  162. return error;
  163. /*
  164. * We need an explicit buffer reference for the log item but
  165. * don't want the buffer to remain attached to the transaction.
  166. * Hold the buffer but release the transaction reference once
  167. * we've attached the inode log item to the buffer log item
  168. * list.
  169. */
  170. xfs_buf_hold(bp);
  171. spin_lock(&iip->ili_lock);
  172. iip->ili_item.li_buf = bp;
  173. bp->b_flags |= _XBF_INODES;
  174. list_add_tail(&iip->ili_item.li_bio_list, &bp->b_li_list);
  175. xfs_trans_brelse(tp, bp);
  176. }
  177. /*
  178. * Always OR in the bits from the ili_last_fields field. This is to
  179. * coordinate with the xfs_iflush() and xfs_buf_inode_iodone() routines
  180. * in the eventual clearing of the ili_fields bits. See the big comment
  181. * in xfs_iflush() for an explanation of this coordination mechanism.
  182. */
  183. iip->ili_fields |= (flags | iip->ili_last_fields);
  184. spin_unlock(&iip->ili_lock);
  185. xfs_inode_item_precommit_check(ip);
  186. /*
  187. * We are done with the log item transaction dirty state, so clear it so
  188. * that it doesn't pollute future transactions.
  189. */
  190. iip->ili_dirty_flags = 0;
  191. return 0;
  192. }
  193. /*
  194. * The logged size of an inode fork is always the current size of the inode
  195. * fork. This means that when an inode fork is relogged, the size of the logged
  196. * region is determined by the current state, not the combination of the
  197. * previously logged state + the current state. This is different relogging
  198. * behaviour to most other log items which will retain the size of the
  199. * previously logged changes when smaller regions are relogged.
  200. *
  201. * Hence operations that remove data from the inode fork (e.g. shortform
  202. * dir/attr remove, extent form extent removal, etc), the size of the relogged
  203. * inode gets -smaller- rather than stays the same size as the previously logged
  204. * size and this can result in the committing transaction reducing the amount of
  205. * space being consumed by the CIL.
  206. */
  207. STATIC void
  208. xfs_inode_item_data_fork_size(
  209. struct xfs_inode_log_item *iip,
  210. int *nvecs,
  211. int *nbytes)
  212. {
  213. struct xfs_inode *ip = iip->ili_inode;
  214. switch (ip->i_df.if_format) {
  215. case XFS_DINODE_FMT_EXTENTS:
  216. if ((iip->ili_fields & XFS_ILOG_DEXT) &&
  217. ip->i_df.if_nextents > 0 &&
  218. ip->i_df.if_bytes > 0) {
  219. /* worst case, doesn't subtract delalloc extents */
  220. *nbytes += xfs_inode_data_fork_size(ip);
  221. *nvecs += 1;
  222. }
  223. break;
  224. case XFS_DINODE_FMT_BTREE:
  225. if ((iip->ili_fields & XFS_ILOG_DBROOT) &&
  226. ip->i_df.if_broot_bytes > 0) {
  227. *nbytes += ip->i_df.if_broot_bytes;
  228. *nvecs += 1;
  229. }
  230. break;
  231. case XFS_DINODE_FMT_LOCAL:
  232. if ((iip->ili_fields & XFS_ILOG_DDATA) &&
  233. ip->i_df.if_bytes > 0) {
  234. *nbytes += xlog_calc_iovec_len(ip->i_df.if_bytes);
  235. *nvecs += 1;
  236. }
  237. break;
  238. case XFS_DINODE_FMT_DEV:
  239. break;
  240. default:
  241. ASSERT(0);
  242. break;
  243. }
  244. }
  245. STATIC void
  246. xfs_inode_item_attr_fork_size(
  247. struct xfs_inode_log_item *iip,
  248. int *nvecs,
  249. int *nbytes)
  250. {
  251. struct xfs_inode *ip = iip->ili_inode;
  252. switch (ip->i_af.if_format) {
  253. case XFS_DINODE_FMT_EXTENTS:
  254. if ((iip->ili_fields & XFS_ILOG_AEXT) &&
  255. ip->i_af.if_nextents > 0 &&
  256. ip->i_af.if_bytes > 0) {
  257. /* worst case, doesn't subtract unused space */
  258. *nbytes += xfs_inode_attr_fork_size(ip);
  259. *nvecs += 1;
  260. }
  261. break;
  262. case XFS_DINODE_FMT_BTREE:
  263. if ((iip->ili_fields & XFS_ILOG_ABROOT) &&
  264. ip->i_af.if_broot_bytes > 0) {
  265. *nbytes += ip->i_af.if_broot_bytes;
  266. *nvecs += 1;
  267. }
  268. break;
  269. case XFS_DINODE_FMT_LOCAL:
  270. if ((iip->ili_fields & XFS_ILOG_ADATA) &&
  271. ip->i_af.if_bytes > 0) {
  272. *nbytes += xlog_calc_iovec_len(ip->i_af.if_bytes);
  273. *nvecs += 1;
  274. }
  275. break;
  276. default:
  277. ASSERT(0);
  278. break;
  279. }
  280. }
  281. /*
  282. * This returns the number of iovecs needed to log the given inode item.
  283. *
  284. * We need one iovec for the inode log format structure, one for the
  285. * inode core, and possibly one for the inode data/extents/b-tree root
  286. * and one for the inode attribute data/extents/b-tree root.
  287. */
  288. STATIC void
  289. xfs_inode_item_size(
  290. struct xfs_log_item *lip,
  291. int *nvecs,
  292. int *nbytes)
  293. {
  294. struct xfs_inode_log_item *iip = INODE_ITEM(lip);
  295. struct xfs_inode *ip = iip->ili_inode;
  296. *nvecs += 2;
  297. *nbytes += sizeof(struct xfs_inode_log_format) +
  298. xfs_log_dinode_size(ip->i_mount);
  299. xfs_inode_item_data_fork_size(iip, nvecs, nbytes);
  300. if (xfs_inode_has_attr_fork(ip))
  301. xfs_inode_item_attr_fork_size(iip, nvecs, nbytes);
  302. }
  303. STATIC void
  304. xfs_inode_item_format_data_fork(
  305. struct xfs_inode_log_item *iip,
  306. struct xfs_inode_log_format *ilf,
  307. struct xfs_log_vec *lv,
  308. struct xfs_log_iovec **vecp)
  309. {
  310. struct xfs_inode *ip = iip->ili_inode;
  311. size_t data_bytes;
  312. switch (ip->i_df.if_format) {
  313. case XFS_DINODE_FMT_EXTENTS:
  314. iip->ili_fields &=
  315. ~(XFS_ILOG_DDATA | XFS_ILOG_DBROOT | XFS_ILOG_DEV);
  316. if ((iip->ili_fields & XFS_ILOG_DEXT) &&
  317. ip->i_df.if_nextents > 0 &&
  318. ip->i_df.if_bytes > 0) {
  319. struct xfs_bmbt_rec *p;
  320. ASSERT(xfs_iext_count(&ip->i_df) > 0);
  321. p = xlog_prepare_iovec(lv, vecp, XLOG_REG_TYPE_IEXT);
  322. data_bytes = xfs_iextents_copy(ip, p, XFS_DATA_FORK);
  323. xlog_finish_iovec(lv, *vecp, data_bytes);
  324. ASSERT(data_bytes <= ip->i_df.if_bytes);
  325. ilf->ilf_dsize = data_bytes;
  326. ilf->ilf_size++;
  327. } else {
  328. iip->ili_fields &= ~XFS_ILOG_DEXT;
  329. }
  330. break;
  331. case XFS_DINODE_FMT_BTREE:
  332. iip->ili_fields &=
  333. ~(XFS_ILOG_DDATA | XFS_ILOG_DEXT | XFS_ILOG_DEV);
  334. if ((iip->ili_fields & XFS_ILOG_DBROOT) &&
  335. ip->i_df.if_broot_bytes > 0) {
  336. ASSERT(ip->i_df.if_broot != NULL);
  337. xlog_copy_iovec(lv, vecp, XLOG_REG_TYPE_IBROOT,
  338. ip->i_df.if_broot,
  339. ip->i_df.if_broot_bytes);
  340. ilf->ilf_dsize = ip->i_df.if_broot_bytes;
  341. ilf->ilf_size++;
  342. } else {
  343. ASSERT(!(iip->ili_fields &
  344. XFS_ILOG_DBROOT));
  345. iip->ili_fields &= ~XFS_ILOG_DBROOT;
  346. }
  347. break;
  348. case XFS_DINODE_FMT_LOCAL:
  349. iip->ili_fields &=
  350. ~(XFS_ILOG_DEXT | XFS_ILOG_DBROOT | XFS_ILOG_DEV);
  351. if ((iip->ili_fields & XFS_ILOG_DDATA) &&
  352. ip->i_df.if_bytes > 0) {
  353. ASSERT(ip->i_df.if_data != NULL);
  354. ASSERT(ip->i_disk_size > 0);
  355. xlog_copy_iovec(lv, vecp, XLOG_REG_TYPE_ILOCAL,
  356. ip->i_df.if_data, ip->i_df.if_bytes);
  357. ilf->ilf_dsize = (unsigned)ip->i_df.if_bytes;
  358. ilf->ilf_size++;
  359. } else {
  360. iip->ili_fields &= ~XFS_ILOG_DDATA;
  361. }
  362. break;
  363. case XFS_DINODE_FMT_DEV:
  364. iip->ili_fields &=
  365. ~(XFS_ILOG_DDATA | XFS_ILOG_DBROOT | XFS_ILOG_DEXT);
  366. if (iip->ili_fields & XFS_ILOG_DEV)
  367. ilf->ilf_u.ilfu_rdev = sysv_encode_dev(VFS_I(ip)->i_rdev);
  368. break;
  369. default:
  370. ASSERT(0);
  371. break;
  372. }
  373. }
  374. STATIC void
  375. xfs_inode_item_format_attr_fork(
  376. struct xfs_inode_log_item *iip,
  377. struct xfs_inode_log_format *ilf,
  378. struct xfs_log_vec *lv,
  379. struct xfs_log_iovec **vecp)
  380. {
  381. struct xfs_inode *ip = iip->ili_inode;
  382. size_t data_bytes;
  383. switch (ip->i_af.if_format) {
  384. case XFS_DINODE_FMT_EXTENTS:
  385. iip->ili_fields &=
  386. ~(XFS_ILOG_ADATA | XFS_ILOG_ABROOT);
  387. if ((iip->ili_fields & XFS_ILOG_AEXT) &&
  388. ip->i_af.if_nextents > 0 &&
  389. ip->i_af.if_bytes > 0) {
  390. struct xfs_bmbt_rec *p;
  391. ASSERT(xfs_iext_count(&ip->i_af) ==
  392. ip->i_af.if_nextents);
  393. p = xlog_prepare_iovec(lv, vecp, XLOG_REG_TYPE_IATTR_EXT);
  394. data_bytes = xfs_iextents_copy(ip, p, XFS_ATTR_FORK);
  395. xlog_finish_iovec(lv, *vecp, data_bytes);
  396. ilf->ilf_asize = data_bytes;
  397. ilf->ilf_size++;
  398. } else {
  399. iip->ili_fields &= ~XFS_ILOG_AEXT;
  400. }
  401. break;
  402. case XFS_DINODE_FMT_BTREE:
  403. iip->ili_fields &=
  404. ~(XFS_ILOG_ADATA | XFS_ILOG_AEXT);
  405. if ((iip->ili_fields & XFS_ILOG_ABROOT) &&
  406. ip->i_af.if_broot_bytes > 0) {
  407. ASSERT(ip->i_af.if_broot != NULL);
  408. xlog_copy_iovec(lv, vecp, XLOG_REG_TYPE_IATTR_BROOT,
  409. ip->i_af.if_broot,
  410. ip->i_af.if_broot_bytes);
  411. ilf->ilf_asize = ip->i_af.if_broot_bytes;
  412. ilf->ilf_size++;
  413. } else {
  414. iip->ili_fields &= ~XFS_ILOG_ABROOT;
  415. }
  416. break;
  417. case XFS_DINODE_FMT_LOCAL:
  418. iip->ili_fields &=
  419. ~(XFS_ILOG_AEXT | XFS_ILOG_ABROOT);
  420. if ((iip->ili_fields & XFS_ILOG_ADATA) &&
  421. ip->i_af.if_bytes > 0) {
  422. ASSERT(ip->i_af.if_data != NULL);
  423. xlog_copy_iovec(lv, vecp, XLOG_REG_TYPE_IATTR_LOCAL,
  424. ip->i_af.if_data, ip->i_af.if_bytes);
  425. ilf->ilf_asize = (unsigned)ip->i_af.if_bytes;
  426. ilf->ilf_size++;
  427. } else {
  428. iip->ili_fields &= ~XFS_ILOG_ADATA;
  429. }
  430. break;
  431. default:
  432. ASSERT(0);
  433. break;
  434. }
  435. }
  436. /*
  437. * Convert an incore timestamp to a log timestamp. Note that the log format
  438. * specifies host endian format!
  439. */
  440. static inline xfs_log_timestamp_t
  441. xfs_inode_to_log_dinode_ts(
  442. struct xfs_inode *ip,
  443. const struct timespec64 tv)
  444. {
  445. struct xfs_log_legacy_timestamp *lits;
  446. xfs_log_timestamp_t its;
  447. if (xfs_inode_has_bigtime(ip))
  448. return xfs_inode_encode_bigtime(tv);
  449. lits = (struct xfs_log_legacy_timestamp *)&its;
  450. lits->t_sec = tv.tv_sec;
  451. lits->t_nsec = tv.tv_nsec;
  452. return its;
  453. }
  454. /*
  455. * The legacy DMAPI fields are only present in the on-disk and in-log inodes,
  456. * but not in the in-memory one. But we are guaranteed to have an inode buffer
  457. * in memory when logging an inode, so we can just copy it from the on-disk
  458. * inode to the in-log inode here so that recovery of file system with these
  459. * fields set to non-zero values doesn't lose them. For all other cases we zero
  460. * the fields.
  461. */
  462. static void
  463. xfs_copy_dm_fields_to_log_dinode(
  464. struct xfs_inode *ip,
  465. struct xfs_log_dinode *to)
  466. {
  467. struct xfs_dinode *dip;
  468. dip = xfs_buf_offset(ip->i_itemp->ili_item.li_buf,
  469. ip->i_imap.im_boffset);
  470. if (xfs_iflags_test(ip, XFS_IPRESERVE_DM_FIELDS)) {
  471. to->di_dmevmask = be32_to_cpu(dip->di_dmevmask);
  472. to->di_dmstate = be16_to_cpu(dip->di_dmstate);
  473. } else {
  474. to->di_dmevmask = 0;
  475. to->di_dmstate = 0;
  476. }
  477. }
  478. static inline void
  479. xfs_inode_to_log_dinode_iext_counters(
  480. struct xfs_inode *ip,
  481. struct xfs_log_dinode *to)
  482. {
  483. if (xfs_inode_has_large_extent_counts(ip)) {
  484. to->di_big_nextents = xfs_ifork_nextents(&ip->i_df);
  485. to->di_big_anextents = xfs_ifork_nextents(&ip->i_af);
  486. to->di_nrext64_pad = 0;
  487. } else {
  488. to->di_nextents = xfs_ifork_nextents(&ip->i_df);
  489. to->di_anextents = xfs_ifork_nextents(&ip->i_af);
  490. }
  491. }
  492. static void
  493. xfs_inode_to_log_dinode(
  494. struct xfs_inode *ip,
  495. struct xfs_log_dinode *to,
  496. xfs_lsn_t lsn)
  497. {
  498. struct inode *inode = VFS_I(ip);
  499. to->di_magic = XFS_DINODE_MAGIC;
  500. to->di_format = xfs_ifork_format(&ip->i_df);
  501. to->di_uid = i_uid_read(inode);
  502. to->di_gid = i_gid_read(inode);
  503. to->di_projid_lo = ip->i_projid & 0xffff;
  504. to->di_projid_hi = ip->i_projid >> 16;
  505. memset(to->di_pad3, 0, sizeof(to->di_pad3));
  506. to->di_atime = xfs_inode_to_log_dinode_ts(ip, inode_get_atime(inode));
  507. to->di_mtime = xfs_inode_to_log_dinode_ts(ip, inode_get_mtime(inode));
  508. to->di_ctime = xfs_inode_to_log_dinode_ts(ip, inode_get_ctime(inode));
  509. to->di_nlink = inode->i_nlink;
  510. to->di_gen = inode->i_generation;
  511. to->di_mode = inode->i_mode;
  512. to->di_size = ip->i_disk_size;
  513. to->di_nblocks = ip->i_nblocks;
  514. to->di_extsize = ip->i_extsize;
  515. to->di_forkoff = ip->i_forkoff;
  516. to->di_aformat = xfs_ifork_format(&ip->i_af);
  517. to->di_flags = ip->i_diflags;
  518. xfs_copy_dm_fields_to_log_dinode(ip, to);
  519. /* log a dummy value to ensure log structure is fully initialised */
  520. to->di_next_unlinked = NULLAGINO;
  521. if (xfs_has_v3inodes(ip->i_mount)) {
  522. to->di_version = 3;
  523. to->di_changecount = inode_peek_iversion(inode);
  524. to->di_crtime = xfs_inode_to_log_dinode_ts(ip, ip->i_crtime);
  525. to->di_flags2 = ip->i_diflags2;
  526. to->di_cowextsize = ip->i_cowextsize;
  527. to->di_ino = ip->i_ino;
  528. to->di_lsn = lsn;
  529. memset(to->di_pad2, 0, sizeof(to->di_pad2));
  530. uuid_copy(&to->di_uuid, &ip->i_mount->m_sb.sb_meta_uuid);
  531. to->di_v3_pad = 0;
  532. /* dummy value for initialisation */
  533. to->di_crc = 0;
  534. } else {
  535. to->di_version = 2;
  536. to->di_flushiter = ip->i_flushiter;
  537. memset(to->di_v2_pad, 0, sizeof(to->di_v2_pad));
  538. }
  539. xfs_inode_to_log_dinode_iext_counters(ip, to);
  540. }
  541. /*
  542. * Format the inode core. Current timestamp data is only in the VFS inode
  543. * fields, so we need to grab them from there. Hence rather than just copying
  544. * the XFS inode core structure, format the fields directly into the iovec.
  545. */
  546. static void
  547. xfs_inode_item_format_core(
  548. struct xfs_inode *ip,
  549. struct xfs_log_vec *lv,
  550. struct xfs_log_iovec **vecp)
  551. {
  552. struct xfs_log_dinode *dic;
  553. dic = xlog_prepare_iovec(lv, vecp, XLOG_REG_TYPE_ICORE);
  554. xfs_inode_to_log_dinode(ip, dic, ip->i_itemp->ili_item.li_lsn);
  555. xlog_finish_iovec(lv, *vecp, xfs_log_dinode_size(ip->i_mount));
  556. }
  557. /*
  558. * This is called to fill in the vector of log iovecs for the given inode
  559. * log item. It fills the first item with an inode log format structure,
  560. * the second with the on-disk inode structure, and a possible third and/or
  561. * fourth with the inode data/extents/b-tree root and inode attributes
  562. * data/extents/b-tree root.
  563. *
  564. * Note: Always use the 64 bit inode log format structure so we don't
  565. * leave an uninitialised hole in the format item on 64 bit systems. Log
  566. * recovery on 32 bit systems handles this just fine, so there's no reason
  567. * for not using an initialising the properly padded structure all the time.
  568. */
  569. STATIC void
  570. xfs_inode_item_format(
  571. struct xfs_log_item *lip,
  572. struct xfs_log_vec *lv)
  573. {
  574. struct xfs_inode_log_item *iip = INODE_ITEM(lip);
  575. struct xfs_inode *ip = iip->ili_inode;
  576. struct xfs_log_iovec *vecp = NULL;
  577. struct xfs_inode_log_format *ilf;
  578. ilf = xlog_prepare_iovec(lv, &vecp, XLOG_REG_TYPE_IFORMAT);
  579. ilf->ilf_type = XFS_LI_INODE;
  580. ilf->ilf_ino = ip->i_ino;
  581. ilf->ilf_blkno = ip->i_imap.im_blkno;
  582. ilf->ilf_len = ip->i_imap.im_len;
  583. ilf->ilf_boffset = ip->i_imap.im_boffset;
  584. ilf->ilf_fields = XFS_ILOG_CORE;
  585. ilf->ilf_size = 2; /* format + core */
  586. /*
  587. * make sure we don't leak uninitialised data into the log in the case
  588. * when we don't log every field in the inode.
  589. */
  590. ilf->ilf_dsize = 0;
  591. ilf->ilf_asize = 0;
  592. ilf->ilf_pad = 0;
  593. memset(&ilf->ilf_u, 0, sizeof(ilf->ilf_u));
  594. xlog_finish_iovec(lv, vecp, sizeof(*ilf));
  595. xfs_inode_item_format_core(ip, lv, &vecp);
  596. xfs_inode_item_format_data_fork(iip, ilf, lv, &vecp);
  597. if (xfs_inode_has_attr_fork(ip)) {
  598. xfs_inode_item_format_attr_fork(iip, ilf, lv, &vecp);
  599. } else {
  600. iip->ili_fields &=
  601. ~(XFS_ILOG_ADATA | XFS_ILOG_ABROOT | XFS_ILOG_AEXT);
  602. }
  603. /* update the format with the exact fields we actually logged */
  604. ilf->ilf_fields |= (iip->ili_fields & ~XFS_ILOG_TIMESTAMP);
  605. }
  606. /*
  607. * This is called to pin the inode associated with the inode log
  608. * item in memory so it cannot be written out.
  609. */
  610. STATIC void
  611. xfs_inode_item_pin(
  612. struct xfs_log_item *lip)
  613. {
  614. struct xfs_inode *ip = INODE_ITEM(lip)->ili_inode;
  615. xfs_assert_ilocked(ip, XFS_ILOCK_EXCL);
  616. ASSERT(lip->li_buf);
  617. trace_xfs_inode_pin(ip, _RET_IP_);
  618. atomic_inc(&ip->i_pincount);
  619. }
  620. /*
  621. * This is called to unpin the inode associated with the inode log
  622. * item which was previously pinned with a call to xfs_inode_item_pin().
  623. *
  624. * Also wake up anyone in xfs_iunpin_wait() if the count goes to 0.
  625. *
  626. * Note that unpin can race with inode cluster buffer freeing marking the buffer
  627. * stale. In that case, flush completions are run from the buffer unpin call,
  628. * which may happen before the inode is unpinned. If we lose the race, there
  629. * will be no buffer attached to the log item, but the inode will be marked
  630. * XFS_ISTALE.
  631. */
  632. STATIC void
  633. xfs_inode_item_unpin(
  634. struct xfs_log_item *lip,
  635. int remove)
  636. {
  637. struct xfs_inode *ip = INODE_ITEM(lip)->ili_inode;
  638. trace_xfs_inode_unpin(ip, _RET_IP_);
  639. ASSERT(lip->li_buf || xfs_iflags_test(ip, XFS_ISTALE));
  640. ASSERT(atomic_read(&ip->i_pincount) > 0);
  641. if (atomic_dec_and_test(&ip->i_pincount))
  642. wake_up_bit(&ip->i_flags, __XFS_IPINNED_BIT);
  643. }
  644. STATIC uint
  645. xfs_inode_item_push(
  646. struct xfs_log_item *lip,
  647. struct list_head *buffer_list)
  648. __releases(&lip->li_ailp->ail_lock)
  649. __acquires(&lip->li_ailp->ail_lock)
  650. {
  651. struct xfs_inode_log_item *iip = INODE_ITEM(lip);
  652. struct xfs_inode *ip = iip->ili_inode;
  653. struct xfs_buf *bp = lip->li_buf;
  654. uint rval = XFS_ITEM_SUCCESS;
  655. int error;
  656. if (!bp || (ip->i_flags & XFS_ISTALE)) {
  657. /*
  658. * Inode item/buffer is being aborted due to cluster
  659. * buffer deletion. Trigger a log force to have that operation
  660. * completed and items removed from the AIL before the next push
  661. * attempt.
  662. */
  663. return XFS_ITEM_PINNED;
  664. }
  665. if (xfs_ipincount(ip) > 0 || xfs_buf_ispinned(bp))
  666. return XFS_ITEM_PINNED;
  667. if (xfs_iflags_test(ip, XFS_IFLUSHING))
  668. return XFS_ITEM_FLUSHING;
  669. if (!xfs_buf_trylock(bp))
  670. return XFS_ITEM_LOCKED;
  671. spin_unlock(&lip->li_ailp->ail_lock);
  672. /*
  673. * We need to hold a reference for flushing the cluster buffer as it may
  674. * fail the buffer without IO submission. In which case, we better get a
  675. * reference for that completion because otherwise we don't get a
  676. * reference for IO until we queue the buffer for delwri submission.
  677. */
  678. xfs_buf_hold(bp);
  679. error = xfs_iflush_cluster(bp);
  680. if (!error) {
  681. if (!xfs_buf_delwri_queue(bp, buffer_list))
  682. rval = XFS_ITEM_FLUSHING;
  683. xfs_buf_relse(bp);
  684. } else {
  685. /*
  686. * Release the buffer if we were unable to flush anything. On
  687. * any other error, the buffer has already been released.
  688. */
  689. if (error == -EAGAIN)
  690. xfs_buf_relse(bp);
  691. rval = XFS_ITEM_LOCKED;
  692. }
  693. spin_lock(&lip->li_ailp->ail_lock);
  694. return rval;
  695. }
  696. /*
  697. * Unlock the inode associated with the inode log item.
  698. */
  699. STATIC void
  700. xfs_inode_item_release(
  701. struct xfs_log_item *lip)
  702. {
  703. struct xfs_inode_log_item *iip = INODE_ITEM(lip);
  704. struct xfs_inode *ip = iip->ili_inode;
  705. unsigned short lock_flags;
  706. ASSERT(ip->i_itemp != NULL);
  707. xfs_assert_ilocked(ip, XFS_ILOCK_EXCL);
  708. lock_flags = iip->ili_lock_flags;
  709. iip->ili_lock_flags = 0;
  710. if (lock_flags)
  711. xfs_iunlock(ip, lock_flags);
  712. }
  713. /*
  714. * This is called to find out where the oldest active copy of the inode log
  715. * item in the on disk log resides now that the last log write of it completed
  716. * at the given lsn. Since we always re-log all dirty data in an inode, the
  717. * latest copy in the on disk log is the only one that matters. Therefore,
  718. * simply return the given lsn.
  719. *
  720. * If the inode has been marked stale because the cluster is being freed, we
  721. * don't want to (re-)insert this inode into the AIL. There is a race condition
  722. * where the cluster buffer may be unpinned before the inode is inserted into
  723. * the AIL during transaction committed processing. If the buffer is unpinned
  724. * before the inode item has been committed and inserted, then it is possible
  725. * for the buffer to be written and IO completes before the inode is inserted
  726. * into the AIL. In that case, we'd be inserting a clean, stale inode into the
  727. * AIL which will never get removed. It will, however, get reclaimed which
  728. * triggers an assert in xfs_inode_free() complaining about freein an inode
  729. * still in the AIL.
  730. *
  731. * To avoid this, just unpin the inode directly and return a LSN of -1 so the
  732. * transaction committed code knows that it does not need to do any further
  733. * processing on the item.
  734. */
  735. STATIC xfs_lsn_t
  736. xfs_inode_item_committed(
  737. struct xfs_log_item *lip,
  738. xfs_lsn_t lsn)
  739. {
  740. struct xfs_inode_log_item *iip = INODE_ITEM(lip);
  741. struct xfs_inode *ip = iip->ili_inode;
  742. if (xfs_iflags_test(ip, XFS_ISTALE)) {
  743. xfs_inode_item_unpin(lip, 0);
  744. return -1;
  745. }
  746. return lsn;
  747. }
  748. STATIC void
  749. xfs_inode_item_committing(
  750. struct xfs_log_item *lip,
  751. xfs_csn_t seq)
  752. {
  753. INODE_ITEM(lip)->ili_commit_seq = seq;
  754. return xfs_inode_item_release(lip);
  755. }
  756. static const struct xfs_item_ops xfs_inode_item_ops = {
  757. .iop_sort = xfs_inode_item_sort,
  758. .iop_precommit = xfs_inode_item_precommit,
  759. .iop_size = xfs_inode_item_size,
  760. .iop_format = xfs_inode_item_format,
  761. .iop_pin = xfs_inode_item_pin,
  762. .iop_unpin = xfs_inode_item_unpin,
  763. .iop_release = xfs_inode_item_release,
  764. .iop_committed = xfs_inode_item_committed,
  765. .iop_push = xfs_inode_item_push,
  766. .iop_committing = xfs_inode_item_committing,
  767. };
  768. /*
  769. * Initialize the inode log item for a newly allocated (in-core) inode.
  770. */
  771. void
  772. xfs_inode_item_init(
  773. struct xfs_inode *ip,
  774. struct xfs_mount *mp)
  775. {
  776. struct xfs_inode_log_item *iip;
  777. ASSERT(ip->i_itemp == NULL);
  778. iip = ip->i_itemp = kmem_cache_zalloc(xfs_ili_cache,
  779. GFP_KERNEL | __GFP_NOFAIL);
  780. iip->ili_inode = ip;
  781. spin_lock_init(&iip->ili_lock);
  782. xfs_log_item_init(mp, &iip->ili_item, XFS_LI_INODE,
  783. &xfs_inode_item_ops);
  784. }
  785. /*
  786. * Free the inode log item and any memory hanging off of it.
  787. */
  788. void
  789. xfs_inode_item_destroy(
  790. struct xfs_inode *ip)
  791. {
  792. struct xfs_inode_log_item *iip = ip->i_itemp;
  793. ASSERT(iip->ili_item.li_buf == NULL);
  794. ip->i_itemp = NULL;
  795. kvfree(iip->ili_item.li_lv_shadow);
  796. kmem_cache_free(xfs_ili_cache, iip);
  797. }
  798. /*
  799. * We only want to pull the item from the AIL if it is actually there
  800. * and its location in the log has not changed since we started the
  801. * flush. Thus, we only bother if the inode's lsn has not changed.
  802. */
  803. static void
  804. xfs_iflush_ail_updates(
  805. struct xfs_ail *ailp,
  806. struct list_head *list)
  807. {
  808. struct xfs_log_item *lip;
  809. xfs_lsn_t tail_lsn = 0;
  810. /* this is an opencoded batch version of xfs_trans_ail_delete */
  811. spin_lock(&ailp->ail_lock);
  812. list_for_each_entry(lip, list, li_bio_list) {
  813. xfs_lsn_t lsn;
  814. clear_bit(XFS_LI_FAILED, &lip->li_flags);
  815. if (INODE_ITEM(lip)->ili_flush_lsn != lip->li_lsn)
  816. continue;
  817. /*
  818. * dgc: Not sure how this happens, but it happens very
  819. * occassionaly via generic/388. xfs_iflush_abort() also
  820. * silently handles this same "under writeback but not in AIL at
  821. * shutdown" condition via xfs_trans_ail_delete().
  822. */
  823. if (!test_bit(XFS_LI_IN_AIL, &lip->li_flags)) {
  824. ASSERT(xlog_is_shutdown(lip->li_log));
  825. continue;
  826. }
  827. lsn = xfs_ail_delete_one(ailp, lip);
  828. if (!tail_lsn && lsn)
  829. tail_lsn = lsn;
  830. }
  831. xfs_ail_update_finish(ailp, tail_lsn);
  832. }
  833. /*
  834. * Walk the list of inodes that have completed their IOs. If they are clean
  835. * remove them from the list and dissociate them from the buffer. Buffers that
  836. * are still dirty remain linked to the buffer and on the list. Caller must
  837. * handle them appropriately.
  838. */
  839. static void
  840. xfs_iflush_finish(
  841. struct xfs_buf *bp,
  842. struct list_head *list)
  843. {
  844. struct xfs_log_item *lip, *n;
  845. list_for_each_entry_safe(lip, n, list, li_bio_list) {
  846. struct xfs_inode_log_item *iip = INODE_ITEM(lip);
  847. bool drop_buffer = false;
  848. spin_lock(&iip->ili_lock);
  849. /*
  850. * Remove the reference to the cluster buffer if the inode is
  851. * clean in memory and drop the buffer reference once we've
  852. * dropped the locks we hold.
  853. */
  854. ASSERT(iip->ili_item.li_buf == bp);
  855. if (!iip->ili_fields) {
  856. iip->ili_item.li_buf = NULL;
  857. list_del_init(&lip->li_bio_list);
  858. drop_buffer = true;
  859. }
  860. iip->ili_last_fields = 0;
  861. iip->ili_flush_lsn = 0;
  862. clear_bit(XFS_LI_FLUSHING, &lip->li_flags);
  863. spin_unlock(&iip->ili_lock);
  864. xfs_iflags_clear(iip->ili_inode, XFS_IFLUSHING);
  865. if (drop_buffer)
  866. xfs_buf_rele(bp);
  867. }
  868. }
  869. /*
  870. * Inode buffer IO completion routine. It is responsible for removing inodes
  871. * attached to the buffer from the AIL if they have not been re-logged and
  872. * completing the inode flush.
  873. */
  874. void
  875. xfs_buf_inode_iodone(
  876. struct xfs_buf *bp)
  877. {
  878. struct xfs_log_item *lip, *n;
  879. LIST_HEAD(flushed_inodes);
  880. LIST_HEAD(ail_updates);
  881. /*
  882. * Pull the attached inodes from the buffer one at a time and take the
  883. * appropriate action on them.
  884. */
  885. list_for_each_entry_safe(lip, n, &bp->b_li_list, li_bio_list) {
  886. struct xfs_inode_log_item *iip = INODE_ITEM(lip);
  887. if (xfs_iflags_test(iip->ili_inode, XFS_ISTALE)) {
  888. xfs_iflush_abort(iip->ili_inode);
  889. continue;
  890. }
  891. if (!iip->ili_last_fields)
  892. continue;
  893. /* Do an unlocked check for needing the AIL lock. */
  894. if (iip->ili_flush_lsn == lip->li_lsn ||
  895. test_bit(XFS_LI_FAILED, &lip->li_flags))
  896. list_move_tail(&lip->li_bio_list, &ail_updates);
  897. else
  898. list_move_tail(&lip->li_bio_list, &flushed_inodes);
  899. }
  900. if (!list_empty(&ail_updates)) {
  901. xfs_iflush_ail_updates(bp->b_mount->m_ail, &ail_updates);
  902. list_splice_tail(&ail_updates, &flushed_inodes);
  903. }
  904. xfs_iflush_finish(bp, &flushed_inodes);
  905. if (!list_empty(&flushed_inodes))
  906. list_splice_tail(&flushed_inodes, &bp->b_li_list);
  907. }
  908. void
  909. xfs_buf_inode_io_fail(
  910. struct xfs_buf *bp)
  911. {
  912. struct xfs_log_item *lip;
  913. list_for_each_entry(lip, &bp->b_li_list, li_bio_list) {
  914. set_bit(XFS_LI_FAILED, &lip->li_flags);
  915. clear_bit(XFS_LI_FLUSHING, &lip->li_flags);
  916. }
  917. }
  918. /*
  919. * Clear the inode logging fields so no more flushes are attempted. If we are
  920. * on a buffer list, it is now safe to remove it because the buffer is
  921. * guaranteed to be locked. The caller will drop the reference to the buffer
  922. * the log item held.
  923. */
  924. static void
  925. xfs_iflush_abort_clean(
  926. struct xfs_inode_log_item *iip)
  927. {
  928. iip->ili_last_fields = 0;
  929. iip->ili_fields = 0;
  930. iip->ili_fsync_fields = 0;
  931. iip->ili_flush_lsn = 0;
  932. iip->ili_item.li_buf = NULL;
  933. list_del_init(&iip->ili_item.li_bio_list);
  934. clear_bit(XFS_LI_FLUSHING, &iip->ili_item.li_flags);
  935. }
  936. /*
  937. * Abort flushing the inode from a context holding the cluster buffer locked.
  938. *
  939. * This is the normal runtime method of aborting writeback of an inode that is
  940. * attached to a cluster buffer. It occurs when the inode and the backing
  941. * cluster buffer have been freed (i.e. inode is XFS_ISTALE), or when cluster
  942. * flushing or buffer IO completion encounters a log shutdown situation.
  943. *
  944. * If we need to abort inode writeback and we don't already hold the buffer
  945. * locked, call xfs_iflush_shutdown_abort() instead as this should only ever be
  946. * necessary in a shutdown situation.
  947. */
  948. void
  949. xfs_iflush_abort(
  950. struct xfs_inode *ip)
  951. {
  952. struct xfs_inode_log_item *iip = ip->i_itemp;
  953. struct xfs_buf *bp;
  954. if (!iip) {
  955. /* clean inode, nothing to do */
  956. xfs_iflags_clear(ip, XFS_IFLUSHING);
  957. return;
  958. }
  959. /*
  960. * Remove the inode item from the AIL before we clear its internal
  961. * state. Whilst the inode is in the AIL, it should have a valid buffer
  962. * pointer for push operations to access - it is only safe to remove the
  963. * inode from the buffer once it has been removed from the AIL.
  964. *
  965. * We also clear the failed bit before removing the item from the AIL
  966. * as xfs_trans_ail_delete()->xfs_clear_li_failed() will release buffer
  967. * references the inode item owns and needs to hold until we've fully
  968. * aborted the inode log item and detached it from the buffer.
  969. */
  970. clear_bit(XFS_LI_FAILED, &iip->ili_item.li_flags);
  971. xfs_trans_ail_delete(&iip->ili_item, 0);
  972. /*
  973. * Grab the inode buffer so can we release the reference the inode log
  974. * item holds on it.
  975. */
  976. spin_lock(&iip->ili_lock);
  977. bp = iip->ili_item.li_buf;
  978. xfs_iflush_abort_clean(iip);
  979. spin_unlock(&iip->ili_lock);
  980. xfs_iflags_clear(ip, XFS_IFLUSHING);
  981. if (bp)
  982. xfs_buf_rele(bp);
  983. }
  984. /*
  985. * Abort an inode flush in the case of a shutdown filesystem. This can be called
  986. * from anywhere with just an inode reference and does not require holding the
  987. * inode cluster buffer locked. If the inode is attached to a cluster buffer,
  988. * it will grab and lock it safely, then abort the inode flush.
  989. */
  990. void
  991. xfs_iflush_shutdown_abort(
  992. struct xfs_inode *ip)
  993. {
  994. struct xfs_inode_log_item *iip = ip->i_itemp;
  995. struct xfs_buf *bp;
  996. if (!iip) {
  997. /* clean inode, nothing to do */
  998. xfs_iflags_clear(ip, XFS_IFLUSHING);
  999. return;
  1000. }
  1001. spin_lock(&iip->ili_lock);
  1002. bp = iip->ili_item.li_buf;
  1003. if (!bp) {
  1004. spin_unlock(&iip->ili_lock);
  1005. xfs_iflush_abort(ip);
  1006. return;
  1007. }
  1008. /*
  1009. * We have to take a reference to the buffer so that it doesn't get
  1010. * freed when we drop the ili_lock and then wait to lock the buffer.
  1011. * We'll clean up the extra reference after we pick up the ili_lock
  1012. * again.
  1013. */
  1014. xfs_buf_hold(bp);
  1015. spin_unlock(&iip->ili_lock);
  1016. xfs_buf_lock(bp);
  1017. spin_lock(&iip->ili_lock);
  1018. if (!iip->ili_item.li_buf) {
  1019. /*
  1020. * Raced with another removal, hold the only reference
  1021. * to bp now. Inode should not be in the AIL now, so just clean
  1022. * up and return;
  1023. */
  1024. ASSERT(list_empty(&iip->ili_item.li_bio_list));
  1025. ASSERT(!test_bit(XFS_LI_IN_AIL, &iip->ili_item.li_flags));
  1026. xfs_iflush_abort_clean(iip);
  1027. spin_unlock(&iip->ili_lock);
  1028. xfs_iflags_clear(ip, XFS_IFLUSHING);
  1029. xfs_buf_relse(bp);
  1030. return;
  1031. }
  1032. /*
  1033. * Got two references to bp. The first will get dropped by
  1034. * xfs_iflush_abort() when the item is removed from the buffer list, but
  1035. * we can't drop our reference until _abort() returns because we have to
  1036. * unlock the buffer as well. Hence we abort and then unlock and release
  1037. * our reference to the buffer.
  1038. */
  1039. ASSERT(iip->ili_item.li_buf == bp);
  1040. spin_unlock(&iip->ili_lock);
  1041. xfs_iflush_abort(ip);
  1042. xfs_buf_relse(bp);
  1043. }
  1044. /*
  1045. * convert an xfs_inode_log_format struct from the old 32 bit version
  1046. * (which can have different field alignments) to the native 64 bit version
  1047. */
  1048. int
  1049. xfs_inode_item_format_convert(
  1050. struct xfs_log_iovec *buf,
  1051. struct xfs_inode_log_format *in_f)
  1052. {
  1053. struct xfs_inode_log_format_32 *in_f32 = buf->i_addr;
  1054. if (buf->i_len != sizeof(*in_f32)) {
  1055. XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, NULL);
  1056. return -EFSCORRUPTED;
  1057. }
  1058. in_f->ilf_type = in_f32->ilf_type;
  1059. in_f->ilf_size = in_f32->ilf_size;
  1060. in_f->ilf_fields = in_f32->ilf_fields;
  1061. in_f->ilf_asize = in_f32->ilf_asize;
  1062. in_f->ilf_dsize = in_f32->ilf_dsize;
  1063. in_f->ilf_ino = in_f32->ilf_ino;
  1064. memcpy(&in_f->ilf_u, &in_f32->ilf_u, sizeof(in_f->ilf_u));
  1065. in_f->ilf_blkno = in_f32->ilf_blkno;
  1066. in_f->ilf_len = in_f32->ilf_len;
  1067. in_f->ilf_boffset = in_f32->ilf_boffset;
  1068. return 0;
  1069. }