xfs_iomap.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182
  1. /*
  2. * Copyright (c) 2000-2006 Silicon Graphics, Inc.
  3. * Copyright (c) 2016 Christoph Hellwig.
  4. * All Rights Reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it would be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write the Free Software Foundation,
  17. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. #include <linux/iomap.h>
  20. #include "xfs.h"
  21. #include "xfs_fs.h"
  22. #include "xfs_shared.h"
  23. #include "xfs_format.h"
  24. #include "xfs_log_format.h"
  25. #include "xfs_trans_resv.h"
  26. #include "xfs_mount.h"
  27. #include "xfs_defer.h"
  28. #include "xfs_inode.h"
  29. #include "xfs_btree.h"
  30. #include "xfs_bmap_btree.h"
  31. #include "xfs_bmap.h"
  32. #include "xfs_bmap_util.h"
  33. #include "xfs_error.h"
  34. #include "xfs_trans.h"
  35. #include "xfs_trans_space.h"
  36. #include "xfs_iomap.h"
  37. #include "xfs_trace.h"
  38. #include "xfs_icache.h"
  39. #include "xfs_quota.h"
  40. #include "xfs_dquot_item.h"
  41. #include "xfs_dquot.h"
  42. #include "xfs_reflink.h"
  43. #define XFS_WRITEIO_ALIGN(mp,off) (((off) >> mp->m_writeio_log) \
  44. << mp->m_writeio_log)
  45. void
  46. xfs_bmbt_to_iomap(
  47. struct xfs_inode *ip,
  48. struct iomap *iomap,
  49. struct xfs_bmbt_irec *imap)
  50. {
  51. struct xfs_mount *mp = ip->i_mount;
  52. if (imap->br_startblock == HOLESTARTBLOCK) {
  53. iomap->blkno = IOMAP_NULL_BLOCK;
  54. iomap->type = IOMAP_HOLE;
  55. } else if (imap->br_startblock == DELAYSTARTBLOCK) {
  56. iomap->blkno = IOMAP_NULL_BLOCK;
  57. iomap->type = IOMAP_DELALLOC;
  58. } else {
  59. iomap->blkno = xfs_fsb_to_db(ip, imap->br_startblock);
  60. if (imap->br_state == XFS_EXT_UNWRITTEN)
  61. iomap->type = IOMAP_UNWRITTEN;
  62. else
  63. iomap->type = IOMAP_MAPPED;
  64. }
  65. iomap->offset = XFS_FSB_TO_B(mp, imap->br_startoff);
  66. iomap->length = XFS_FSB_TO_B(mp, imap->br_blockcount);
  67. iomap->bdev = xfs_find_bdev_for_inode(VFS_I(ip));
  68. }
  69. xfs_extlen_t
  70. xfs_eof_alignment(
  71. struct xfs_inode *ip,
  72. xfs_extlen_t extsize)
  73. {
  74. struct xfs_mount *mp = ip->i_mount;
  75. xfs_extlen_t align = 0;
  76. if (!XFS_IS_REALTIME_INODE(ip)) {
  77. /*
  78. * Round up the allocation request to a stripe unit
  79. * (m_dalign) boundary if the file size is >= stripe unit
  80. * size, and we are allocating past the allocation eof.
  81. *
  82. * If mounted with the "-o swalloc" option the alignment is
  83. * increased from the strip unit size to the stripe width.
  84. */
  85. if (mp->m_swidth && (mp->m_flags & XFS_MOUNT_SWALLOC))
  86. align = mp->m_swidth;
  87. else if (mp->m_dalign)
  88. align = mp->m_dalign;
  89. if (align && XFS_ISIZE(ip) < XFS_FSB_TO_B(mp, align))
  90. align = 0;
  91. }
  92. /*
  93. * Always round up the allocation request to an extent boundary
  94. * (when file on a real-time subvolume or has di_extsize hint).
  95. */
  96. if (extsize) {
  97. if (align)
  98. align = roundup_64(align, extsize);
  99. else
  100. align = extsize;
  101. }
  102. return align;
  103. }
  104. STATIC int
  105. xfs_iomap_eof_align_last_fsb(
  106. struct xfs_inode *ip,
  107. xfs_extlen_t extsize,
  108. xfs_fileoff_t *last_fsb)
  109. {
  110. xfs_extlen_t align = xfs_eof_alignment(ip, extsize);
  111. if (align) {
  112. xfs_fileoff_t new_last_fsb = roundup_64(*last_fsb, align);
  113. int eof, error;
  114. error = xfs_bmap_eof(ip, new_last_fsb, XFS_DATA_FORK, &eof);
  115. if (error)
  116. return error;
  117. if (eof)
  118. *last_fsb = new_last_fsb;
  119. }
  120. return 0;
  121. }
  122. STATIC int
  123. xfs_alert_fsblock_zero(
  124. xfs_inode_t *ip,
  125. xfs_bmbt_irec_t *imap)
  126. {
  127. xfs_alert_tag(ip->i_mount, XFS_PTAG_FSBLOCK_ZERO,
  128. "Access to block zero in inode %llu "
  129. "start_block: %llx start_off: %llx "
  130. "blkcnt: %llx extent-state: %x",
  131. (unsigned long long)ip->i_ino,
  132. (unsigned long long)imap->br_startblock,
  133. (unsigned long long)imap->br_startoff,
  134. (unsigned long long)imap->br_blockcount,
  135. imap->br_state);
  136. return -EFSCORRUPTED;
  137. }
  138. int
  139. xfs_iomap_write_direct(
  140. xfs_inode_t *ip,
  141. xfs_off_t offset,
  142. size_t count,
  143. xfs_bmbt_irec_t *imap,
  144. int nmaps)
  145. {
  146. xfs_mount_t *mp = ip->i_mount;
  147. xfs_fileoff_t offset_fsb;
  148. xfs_fileoff_t last_fsb;
  149. xfs_filblks_t count_fsb, resaligned;
  150. xfs_fsblock_t firstfsb;
  151. xfs_extlen_t extsz, temp;
  152. int nimaps;
  153. int quota_flag;
  154. int rt;
  155. xfs_trans_t *tp;
  156. struct xfs_defer_ops dfops;
  157. uint qblocks, resblks, resrtextents;
  158. int error;
  159. int lockmode;
  160. int bmapi_flags = XFS_BMAPI_PREALLOC;
  161. uint tflags = 0;
  162. rt = XFS_IS_REALTIME_INODE(ip);
  163. extsz = xfs_get_extsz_hint(ip);
  164. lockmode = XFS_ILOCK_SHARED; /* locked by caller */
  165. ASSERT(xfs_isilocked(ip, lockmode));
  166. offset_fsb = XFS_B_TO_FSBT(mp, offset);
  167. last_fsb = XFS_B_TO_FSB(mp, ((xfs_ufsize_t)(offset + count)));
  168. if ((offset + count) > XFS_ISIZE(ip)) {
  169. /*
  170. * Assert that the in-core extent list is present since this can
  171. * call xfs_iread_extents() and we only have the ilock shared.
  172. * This should be safe because the lock was held around a bmapi
  173. * call in the caller and we only need it to access the in-core
  174. * list.
  175. */
  176. ASSERT(XFS_IFORK_PTR(ip, XFS_DATA_FORK)->if_flags &
  177. XFS_IFEXTENTS);
  178. error = xfs_iomap_eof_align_last_fsb(ip, extsz, &last_fsb);
  179. if (error)
  180. goto out_unlock;
  181. } else {
  182. if (nmaps && (imap->br_startblock == HOLESTARTBLOCK))
  183. last_fsb = MIN(last_fsb, (xfs_fileoff_t)
  184. imap->br_blockcount +
  185. imap->br_startoff);
  186. }
  187. count_fsb = last_fsb - offset_fsb;
  188. ASSERT(count_fsb > 0);
  189. resaligned = count_fsb;
  190. if (unlikely(extsz)) {
  191. if ((temp = do_mod(offset_fsb, extsz)))
  192. resaligned += temp;
  193. if ((temp = do_mod(resaligned, extsz)))
  194. resaligned += extsz - temp;
  195. }
  196. if (unlikely(rt)) {
  197. resrtextents = qblocks = resaligned;
  198. resrtextents /= mp->m_sb.sb_rextsize;
  199. resblks = XFS_DIOSTRAT_SPACE_RES(mp, 0);
  200. quota_flag = XFS_QMOPT_RES_RTBLKS;
  201. } else {
  202. resrtextents = 0;
  203. resblks = qblocks = XFS_DIOSTRAT_SPACE_RES(mp, resaligned);
  204. quota_flag = XFS_QMOPT_RES_REGBLKS;
  205. }
  206. /*
  207. * Drop the shared lock acquired by the caller, attach the dquot if
  208. * necessary and move on to transaction setup.
  209. */
  210. xfs_iunlock(ip, lockmode);
  211. error = xfs_qm_dqattach(ip, 0);
  212. if (error)
  213. return error;
  214. /*
  215. * For DAX, we do not allocate unwritten extents, but instead we zero
  216. * the block before we commit the transaction. Ideally we'd like to do
  217. * this outside the transaction context, but if we commit and then crash
  218. * we may not have zeroed the blocks and this will be exposed on
  219. * recovery of the allocation. Hence we must zero before commit.
  220. *
  221. * Further, if we are mapping unwritten extents here, we need to zero
  222. * and convert them to written so that we don't need an unwritten extent
  223. * callback for DAX. This also means that we need to be able to dip into
  224. * the reserve block pool for bmbt block allocation if there is no space
  225. * left but we need to do unwritten extent conversion.
  226. */
  227. if (IS_DAX(VFS_I(ip))) {
  228. bmapi_flags = XFS_BMAPI_CONVERT | XFS_BMAPI_ZERO;
  229. if (ISUNWRITTEN(imap)) {
  230. tflags |= XFS_TRANS_RESERVE;
  231. resblks = XFS_DIOSTRAT_SPACE_RES(mp, 0) << 1;
  232. }
  233. }
  234. error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, resblks, resrtextents,
  235. tflags, &tp);
  236. if (error)
  237. return error;
  238. lockmode = XFS_ILOCK_EXCL;
  239. xfs_ilock(ip, lockmode);
  240. error = xfs_trans_reserve_quota_nblks(tp, ip, qblocks, 0, quota_flag);
  241. if (error)
  242. goto out_trans_cancel;
  243. xfs_trans_ijoin(tp, ip, 0);
  244. /*
  245. * From this point onwards we overwrite the imap pointer that the
  246. * caller gave to us.
  247. */
  248. xfs_defer_init(&dfops, &firstfsb);
  249. nimaps = 1;
  250. error = xfs_bmapi_write(tp, ip, offset_fsb, count_fsb,
  251. bmapi_flags, &firstfsb, resblks, imap,
  252. &nimaps, &dfops);
  253. if (error)
  254. goto out_bmap_cancel;
  255. /*
  256. * Complete the transaction
  257. */
  258. error = xfs_defer_finish(&tp, &dfops, NULL);
  259. if (error)
  260. goto out_bmap_cancel;
  261. error = xfs_trans_commit(tp);
  262. if (error)
  263. goto out_unlock;
  264. /*
  265. * Copy any maps to caller's array and return any error.
  266. */
  267. if (nimaps == 0) {
  268. error = -ENOSPC;
  269. goto out_unlock;
  270. }
  271. if (!(imap->br_startblock || XFS_IS_REALTIME_INODE(ip)))
  272. error = xfs_alert_fsblock_zero(ip, imap);
  273. out_unlock:
  274. xfs_iunlock(ip, lockmode);
  275. return error;
  276. out_bmap_cancel:
  277. xfs_defer_cancel(&dfops);
  278. xfs_trans_unreserve_quota_nblks(tp, ip, (long)qblocks, 0, quota_flag);
  279. out_trans_cancel:
  280. xfs_trans_cancel(tp);
  281. goto out_unlock;
  282. }
  283. STATIC bool
  284. xfs_quota_need_throttle(
  285. struct xfs_inode *ip,
  286. int type,
  287. xfs_fsblock_t alloc_blocks)
  288. {
  289. struct xfs_dquot *dq = xfs_inode_dquot(ip, type);
  290. if (!dq || !xfs_this_quota_on(ip->i_mount, type))
  291. return false;
  292. /* no hi watermark, no throttle */
  293. if (!dq->q_prealloc_hi_wmark)
  294. return false;
  295. /* under the lo watermark, no throttle */
  296. if (dq->q_res_bcount + alloc_blocks < dq->q_prealloc_lo_wmark)
  297. return false;
  298. return true;
  299. }
  300. STATIC void
  301. xfs_quota_calc_throttle(
  302. struct xfs_inode *ip,
  303. int type,
  304. xfs_fsblock_t *qblocks,
  305. int *qshift,
  306. int64_t *qfreesp)
  307. {
  308. int64_t freesp;
  309. int shift = 0;
  310. struct xfs_dquot *dq = xfs_inode_dquot(ip, type);
  311. /* no dq, or over hi wmark, squash the prealloc completely */
  312. if (!dq || dq->q_res_bcount >= dq->q_prealloc_hi_wmark) {
  313. *qblocks = 0;
  314. *qfreesp = 0;
  315. return;
  316. }
  317. freesp = dq->q_prealloc_hi_wmark - dq->q_res_bcount;
  318. if (freesp < dq->q_low_space[XFS_QLOWSP_5_PCNT]) {
  319. shift = 2;
  320. if (freesp < dq->q_low_space[XFS_QLOWSP_3_PCNT])
  321. shift += 2;
  322. if (freesp < dq->q_low_space[XFS_QLOWSP_1_PCNT])
  323. shift += 2;
  324. }
  325. if (freesp < *qfreesp)
  326. *qfreesp = freesp;
  327. /* only overwrite the throttle values if we are more aggressive */
  328. if ((freesp >> shift) < (*qblocks >> *qshift)) {
  329. *qblocks = freesp;
  330. *qshift = shift;
  331. }
  332. }
  333. /*
  334. * If we are doing a write at the end of the file and there are no allocations
  335. * past this one, then extend the allocation out to the file system's write
  336. * iosize.
  337. *
  338. * If we don't have a user specified preallocation size, dynamically increase
  339. * the preallocation size as the size of the file grows. Cap the maximum size
  340. * at a single extent or less if the filesystem is near full. The closer the
  341. * filesystem is to full, the smaller the maximum prealocation.
  342. *
  343. * As an exception we don't do any preallocation at all if the file is smaller
  344. * than the minimum preallocation and we are using the default dynamic
  345. * preallocation scheme, as it is likely this is the only write to the file that
  346. * is going to be done.
  347. *
  348. * We clean up any extra space left over when the file is closed in
  349. * xfs_inactive().
  350. */
  351. STATIC xfs_fsblock_t
  352. xfs_iomap_prealloc_size(
  353. struct xfs_inode *ip,
  354. loff_t offset,
  355. loff_t count,
  356. xfs_extnum_t idx)
  357. {
  358. struct xfs_mount *mp = ip->i_mount;
  359. struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, XFS_DATA_FORK);
  360. xfs_fileoff_t offset_fsb = XFS_B_TO_FSBT(mp, offset);
  361. struct xfs_bmbt_irec prev;
  362. int shift = 0;
  363. int64_t freesp;
  364. xfs_fsblock_t qblocks;
  365. int qshift = 0;
  366. xfs_fsblock_t alloc_blocks = 0;
  367. if (offset + count <= XFS_ISIZE(ip))
  368. return 0;
  369. if (!(mp->m_flags & XFS_MOUNT_DFLT_IOSIZE) &&
  370. (XFS_ISIZE(ip) < XFS_FSB_TO_B(mp, mp->m_writeio_blocks)))
  371. return 0;
  372. /*
  373. * If an explicit allocsize is set, the file is small, or we
  374. * are writing behind a hole, then use the minimum prealloc:
  375. */
  376. if ((mp->m_flags & XFS_MOUNT_DFLT_IOSIZE) ||
  377. XFS_ISIZE(ip) < XFS_FSB_TO_B(mp, mp->m_dalign) ||
  378. !xfs_iext_get_extent(ifp, idx - 1, &prev) ||
  379. prev.br_startoff + prev.br_blockcount < offset_fsb)
  380. return mp->m_writeio_blocks;
  381. /*
  382. * Determine the initial size of the preallocation. We are beyond the
  383. * current EOF here, but we need to take into account whether this is
  384. * a sparse write or an extending write when determining the
  385. * preallocation size. Hence we need to look up the extent that ends
  386. * at the current write offset and use the result to determine the
  387. * preallocation size.
  388. *
  389. * If the extent is a hole, then preallocation is essentially disabled.
  390. * Otherwise we take the size of the preceding data extent as the basis
  391. * for the preallocation size. If the size of the extent is greater than
  392. * half the maximum extent length, then use the current offset as the
  393. * basis. This ensures that for large files the preallocation size
  394. * always extends to MAXEXTLEN rather than falling short due to things
  395. * like stripe unit/width alignment of real extents.
  396. */
  397. if (prev.br_blockcount <= (MAXEXTLEN >> 1))
  398. alloc_blocks = prev.br_blockcount << 1;
  399. else
  400. alloc_blocks = XFS_B_TO_FSB(mp, offset);
  401. if (!alloc_blocks)
  402. goto check_writeio;
  403. qblocks = alloc_blocks;
  404. /*
  405. * MAXEXTLEN is not a power of two value but we round the prealloc down
  406. * to the nearest power of two value after throttling. To prevent the
  407. * round down from unconditionally reducing the maximum supported prealloc
  408. * size, we round up first, apply appropriate throttling, round down and
  409. * cap the value to MAXEXTLEN.
  410. */
  411. alloc_blocks = XFS_FILEOFF_MIN(roundup_pow_of_two(MAXEXTLEN),
  412. alloc_blocks);
  413. freesp = percpu_counter_read_positive(&mp->m_fdblocks);
  414. if (freesp < mp->m_low_space[XFS_LOWSP_5_PCNT]) {
  415. shift = 2;
  416. if (freesp < mp->m_low_space[XFS_LOWSP_4_PCNT])
  417. shift++;
  418. if (freesp < mp->m_low_space[XFS_LOWSP_3_PCNT])
  419. shift++;
  420. if (freesp < mp->m_low_space[XFS_LOWSP_2_PCNT])
  421. shift++;
  422. if (freesp < mp->m_low_space[XFS_LOWSP_1_PCNT])
  423. shift++;
  424. }
  425. /*
  426. * Check each quota to cap the prealloc size, provide a shift value to
  427. * throttle with and adjust amount of available space.
  428. */
  429. if (xfs_quota_need_throttle(ip, XFS_DQ_USER, alloc_blocks))
  430. xfs_quota_calc_throttle(ip, XFS_DQ_USER, &qblocks, &qshift,
  431. &freesp);
  432. if (xfs_quota_need_throttle(ip, XFS_DQ_GROUP, alloc_blocks))
  433. xfs_quota_calc_throttle(ip, XFS_DQ_GROUP, &qblocks, &qshift,
  434. &freesp);
  435. if (xfs_quota_need_throttle(ip, XFS_DQ_PROJ, alloc_blocks))
  436. xfs_quota_calc_throttle(ip, XFS_DQ_PROJ, &qblocks, &qshift,
  437. &freesp);
  438. /*
  439. * The final prealloc size is set to the minimum of free space available
  440. * in each of the quotas and the overall filesystem.
  441. *
  442. * The shift throttle value is set to the maximum value as determined by
  443. * the global low free space values and per-quota low free space values.
  444. */
  445. alloc_blocks = MIN(alloc_blocks, qblocks);
  446. shift = MAX(shift, qshift);
  447. if (shift)
  448. alloc_blocks >>= shift;
  449. /*
  450. * rounddown_pow_of_two() returns an undefined result if we pass in
  451. * alloc_blocks = 0.
  452. */
  453. if (alloc_blocks)
  454. alloc_blocks = rounddown_pow_of_two(alloc_blocks);
  455. if (alloc_blocks > MAXEXTLEN)
  456. alloc_blocks = MAXEXTLEN;
  457. /*
  458. * If we are still trying to allocate more space than is
  459. * available, squash the prealloc hard. This can happen if we
  460. * have a large file on a small filesystem and the above
  461. * lowspace thresholds are smaller than MAXEXTLEN.
  462. */
  463. while (alloc_blocks && alloc_blocks >= freesp)
  464. alloc_blocks >>= 4;
  465. check_writeio:
  466. if (alloc_blocks < mp->m_writeio_blocks)
  467. alloc_blocks = mp->m_writeio_blocks;
  468. trace_xfs_iomap_prealloc_size(ip, alloc_blocks, shift,
  469. mp->m_writeio_blocks);
  470. return alloc_blocks;
  471. }
  472. static int
  473. xfs_file_iomap_begin_delay(
  474. struct inode *inode,
  475. loff_t offset,
  476. loff_t count,
  477. unsigned flags,
  478. struct iomap *iomap)
  479. {
  480. struct xfs_inode *ip = XFS_I(inode);
  481. struct xfs_mount *mp = ip->i_mount;
  482. struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, XFS_DATA_FORK);
  483. xfs_fileoff_t offset_fsb = XFS_B_TO_FSBT(mp, offset);
  484. xfs_fileoff_t maxbytes_fsb =
  485. XFS_B_TO_FSB(mp, mp->m_super->s_maxbytes);
  486. xfs_fileoff_t end_fsb;
  487. int error = 0, eof = 0;
  488. struct xfs_bmbt_irec got;
  489. xfs_extnum_t idx;
  490. xfs_fsblock_t prealloc_blocks = 0;
  491. ASSERT(!XFS_IS_REALTIME_INODE(ip));
  492. ASSERT(!xfs_get_extsz_hint(ip));
  493. xfs_ilock(ip, XFS_ILOCK_EXCL);
  494. if (unlikely(XFS_TEST_ERROR(
  495. (XFS_IFORK_FORMAT(ip, XFS_DATA_FORK) != XFS_DINODE_FMT_EXTENTS &&
  496. XFS_IFORK_FORMAT(ip, XFS_DATA_FORK) != XFS_DINODE_FMT_BTREE),
  497. mp, XFS_ERRTAG_BMAPIFORMAT, XFS_RANDOM_BMAPIFORMAT))) {
  498. XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, mp);
  499. error = -EFSCORRUPTED;
  500. goto out_unlock;
  501. }
  502. XFS_STATS_INC(mp, xs_blk_mapw);
  503. if (!(ifp->if_flags & XFS_IFEXTENTS)) {
  504. error = xfs_iread_extents(NULL, ip, XFS_DATA_FORK);
  505. if (error)
  506. goto out_unlock;
  507. }
  508. eof = !xfs_iext_lookup_extent(ip, ifp, offset_fsb, &idx, &got);
  509. if (!eof && got.br_startoff <= offset_fsb) {
  510. if (xfs_is_reflink_inode(ip)) {
  511. bool shared;
  512. end_fsb = min(XFS_B_TO_FSB(mp, offset + count),
  513. maxbytes_fsb);
  514. xfs_trim_extent(&got, offset_fsb, end_fsb - offset_fsb);
  515. error = xfs_reflink_reserve_cow(ip, &got, &shared);
  516. if (error)
  517. goto out_unlock;
  518. }
  519. trace_xfs_iomap_found(ip, offset, count, 0, &got);
  520. goto done;
  521. }
  522. error = xfs_qm_dqattach_locked(ip, 0);
  523. if (error)
  524. goto out_unlock;
  525. /*
  526. * We cap the maximum length we map here to MAX_WRITEBACK_PAGES pages
  527. * to keep the chunks of work done where somewhat symmetric with the
  528. * work writeback does. This is a completely arbitrary number pulled
  529. * out of thin air as a best guess for initial testing.
  530. *
  531. * Note that the values needs to be less than 32-bits wide until
  532. * the lower level functions are updated.
  533. */
  534. count = min_t(loff_t, count, 1024 * PAGE_SIZE);
  535. end_fsb = min(XFS_B_TO_FSB(mp, offset + count), maxbytes_fsb);
  536. if (eof) {
  537. prealloc_blocks = xfs_iomap_prealloc_size(ip, offset, count, idx);
  538. if (prealloc_blocks) {
  539. xfs_extlen_t align;
  540. xfs_off_t end_offset;
  541. xfs_fileoff_t p_end_fsb;
  542. end_offset = XFS_WRITEIO_ALIGN(mp, offset + count - 1);
  543. p_end_fsb = XFS_B_TO_FSBT(mp, end_offset) +
  544. prealloc_blocks;
  545. align = xfs_eof_alignment(ip, 0);
  546. if (align)
  547. p_end_fsb = roundup_64(p_end_fsb, align);
  548. p_end_fsb = min(p_end_fsb, maxbytes_fsb);
  549. ASSERT(p_end_fsb > offset_fsb);
  550. prealloc_blocks = p_end_fsb - end_fsb;
  551. }
  552. }
  553. retry:
  554. error = xfs_bmapi_reserve_delalloc(ip, XFS_DATA_FORK, offset_fsb,
  555. end_fsb - offset_fsb, prealloc_blocks, &got, &idx, eof);
  556. switch (error) {
  557. case 0:
  558. break;
  559. case -ENOSPC:
  560. case -EDQUOT:
  561. /* retry without any preallocation */
  562. trace_xfs_delalloc_enospc(ip, offset, count);
  563. if (prealloc_blocks) {
  564. prealloc_blocks = 0;
  565. goto retry;
  566. }
  567. /*FALLTHRU*/
  568. default:
  569. goto out_unlock;
  570. }
  571. /*
  572. * Flag newly allocated delalloc blocks with IOMAP_F_NEW so we punch
  573. * them out if the write happens to fail.
  574. */
  575. iomap->flags = IOMAP_F_NEW;
  576. trace_xfs_iomap_alloc(ip, offset, count, 0, &got);
  577. done:
  578. if (isnullstartblock(got.br_startblock))
  579. got.br_startblock = DELAYSTARTBLOCK;
  580. if (!got.br_startblock) {
  581. error = xfs_alert_fsblock_zero(ip, &got);
  582. if (error)
  583. goto out_unlock;
  584. }
  585. xfs_bmbt_to_iomap(ip, iomap, &got);
  586. out_unlock:
  587. xfs_iunlock(ip, XFS_ILOCK_EXCL);
  588. return error;
  589. }
  590. /*
  591. * Pass in a delayed allocate extent, convert it to real extents;
  592. * return to the caller the extent we create which maps on top of
  593. * the originating callers request.
  594. *
  595. * Called without a lock on the inode.
  596. *
  597. * We no longer bother to look at the incoming map - all we have to
  598. * guarantee is that whatever we allocate fills the required range.
  599. */
  600. int
  601. xfs_iomap_write_allocate(
  602. xfs_inode_t *ip,
  603. int whichfork,
  604. xfs_off_t offset,
  605. xfs_bmbt_irec_t *imap)
  606. {
  607. xfs_mount_t *mp = ip->i_mount;
  608. xfs_fileoff_t offset_fsb, last_block;
  609. xfs_fileoff_t end_fsb, map_start_fsb;
  610. xfs_fsblock_t first_block;
  611. struct xfs_defer_ops dfops;
  612. xfs_filblks_t count_fsb;
  613. xfs_trans_t *tp;
  614. int nimaps;
  615. int error = 0;
  616. int flags = XFS_BMAPI_DELALLOC;
  617. int nres;
  618. if (whichfork == XFS_COW_FORK)
  619. flags |= XFS_BMAPI_COWFORK | XFS_BMAPI_PREALLOC;
  620. /*
  621. * Make sure that the dquots are there.
  622. */
  623. error = xfs_qm_dqattach(ip, 0);
  624. if (error)
  625. return error;
  626. offset_fsb = XFS_B_TO_FSBT(mp, offset);
  627. count_fsb = imap->br_blockcount;
  628. map_start_fsb = imap->br_startoff;
  629. XFS_STATS_ADD(mp, xs_xstrat_bytes, XFS_FSB_TO_B(mp, count_fsb));
  630. while (count_fsb != 0) {
  631. /*
  632. * Set up a transaction with which to allocate the
  633. * backing store for the file. Do allocations in a
  634. * loop until we get some space in the range we are
  635. * interested in. The other space that might be allocated
  636. * is in the delayed allocation extent on which we sit
  637. * but before our buffer starts.
  638. */
  639. nimaps = 0;
  640. while (nimaps == 0) {
  641. nres = XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK);
  642. /*
  643. * We have already reserved space for the extent and any
  644. * indirect blocks when creating the delalloc extent,
  645. * there is no need to reserve space in this transaction
  646. * again.
  647. */
  648. error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, 0,
  649. 0, XFS_TRANS_RESERVE, &tp);
  650. if (error)
  651. return error;
  652. xfs_ilock(ip, XFS_ILOCK_EXCL);
  653. xfs_trans_ijoin(tp, ip, 0);
  654. xfs_defer_init(&dfops, &first_block);
  655. /*
  656. * it is possible that the extents have changed since
  657. * we did the read call as we dropped the ilock for a
  658. * while. We have to be careful about truncates or hole
  659. * punchs here - we are not allowed to allocate
  660. * non-delalloc blocks here.
  661. *
  662. * The only protection against truncation is the pages
  663. * for the range we are being asked to convert are
  664. * locked and hence a truncate will block on them
  665. * first.
  666. *
  667. * As a result, if we go beyond the range we really
  668. * need and hit an delalloc extent boundary followed by
  669. * a hole while we have excess blocks in the map, we
  670. * will fill the hole incorrectly and overrun the
  671. * transaction reservation.
  672. *
  673. * Using a single map prevents this as we are forced to
  674. * check each map we look for overlap with the desired
  675. * range and abort as soon as we find it. Also, given
  676. * that we only return a single map, having one beyond
  677. * what we can return is probably a bit silly.
  678. *
  679. * We also need to check that we don't go beyond EOF;
  680. * this is a truncate optimisation as a truncate sets
  681. * the new file size before block on the pages we
  682. * currently have locked under writeback. Because they
  683. * are about to be tossed, we don't need to write them
  684. * back....
  685. */
  686. nimaps = 1;
  687. end_fsb = XFS_B_TO_FSB(mp, XFS_ISIZE(ip));
  688. error = xfs_bmap_last_offset(ip, &last_block,
  689. XFS_DATA_FORK);
  690. if (error)
  691. goto trans_cancel;
  692. last_block = XFS_FILEOFF_MAX(last_block, end_fsb);
  693. if ((map_start_fsb + count_fsb) > last_block) {
  694. count_fsb = last_block - map_start_fsb;
  695. if (count_fsb == 0) {
  696. error = -EAGAIN;
  697. goto trans_cancel;
  698. }
  699. }
  700. /*
  701. * From this point onwards we overwrite the imap
  702. * pointer that the caller gave to us.
  703. */
  704. error = xfs_bmapi_write(tp, ip, map_start_fsb,
  705. count_fsb, flags, &first_block,
  706. nres, imap, &nimaps,
  707. &dfops);
  708. if (error)
  709. goto trans_cancel;
  710. error = xfs_defer_finish(&tp, &dfops, NULL);
  711. if (error)
  712. goto trans_cancel;
  713. error = xfs_trans_commit(tp);
  714. if (error)
  715. goto error0;
  716. xfs_iunlock(ip, XFS_ILOCK_EXCL);
  717. }
  718. /*
  719. * See if we were able to allocate an extent that
  720. * covers at least part of the callers request
  721. */
  722. if (!(imap->br_startblock || XFS_IS_REALTIME_INODE(ip)))
  723. return xfs_alert_fsblock_zero(ip, imap);
  724. if ((offset_fsb >= imap->br_startoff) &&
  725. (offset_fsb < (imap->br_startoff +
  726. imap->br_blockcount))) {
  727. XFS_STATS_INC(mp, xs_xstrat_quick);
  728. return 0;
  729. }
  730. /*
  731. * So far we have not mapped the requested part of the
  732. * file, just surrounding data, try again.
  733. */
  734. count_fsb -= imap->br_blockcount;
  735. map_start_fsb = imap->br_startoff + imap->br_blockcount;
  736. }
  737. trans_cancel:
  738. xfs_defer_cancel(&dfops);
  739. xfs_trans_cancel(tp);
  740. error0:
  741. xfs_iunlock(ip, XFS_ILOCK_EXCL);
  742. return error;
  743. }
  744. int
  745. xfs_iomap_write_unwritten(
  746. xfs_inode_t *ip,
  747. xfs_off_t offset,
  748. xfs_off_t count,
  749. bool update_isize)
  750. {
  751. xfs_mount_t *mp = ip->i_mount;
  752. xfs_fileoff_t offset_fsb;
  753. xfs_filblks_t count_fsb;
  754. xfs_filblks_t numblks_fsb;
  755. xfs_fsblock_t firstfsb;
  756. int nimaps;
  757. xfs_trans_t *tp;
  758. xfs_bmbt_irec_t imap;
  759. struct xfs_defer_ops dfops;
  760. struct inode *inode = VFS_I(ip);
  761. xfs_fsize_t i_size;
  762. uint resblks;
  763. int error;
  764. trace_xfs_unwritten_convert(ip, offset, count);
  765. offset_fsb = XFS_B_TO_FSBT(mp, offset);
  766. count_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)offset + count);
  767. count_fsb = (xfs_filblks_t)(count_fsb - offset_fsb);
  768. /*
  769. * Reserve enough blocks in this transaction for two complete extent
  770. * btree splits. We may be converting the middle part of an unwritten
  771. * extent and in this case we will insert two new extents in the btree
  772. * each of which could cause a full split.
  773. *
  774. * This reservation amount will be used in the first call to
  775. * xfs_bmbt_split() to select an AG with enough space to satisfy the
  776. * rest of the operation.
  777. */
  778. resblks = XFS_DIOSTRAT_SPACE_RES(mp, 0) << 1;
  779. do {
  780. /*
  781. * Set up a transaction to convert the range of extents
  782. * from unwritten to real. Do allocations in a loop until
  783. * we have covered the range passed in.
  784. *
  785. * Note that we can't risk to recursing back into the filesystem
  786. * here as we might be asked to write out the same inode that we
  787. * complete here and might deadlock on the iolock.
  788. */
  789. error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, resblks, 0,
  790. XFS_TRANS_RESERVE | XFS_TRANS_NOFS, &tp);
  791. if (error)
  792. return error;
  793. xfs_ilock(ip, XFS_ILOCK_EXCL);
  794. xfs_trans_ijoin(tp, ip, 0);
  795. /*
  796. * Modify the unwritten extent state of the buffer.
  797. */
  798. xfs_defer_init(&dfops, &firstfsb);
  799. nimaps = 1;
  800. error = xfs_bmapi_write(tp, ip, offset_fsb, count_fsb,
  801. XFS_BMAPI_CONVERT, &firstfsb, resblks,
  802. &imap, &nimaps, &dfops);
  803. if (error)
  804. goto error_on_bmapi_transaction;
  805. /*
  806. * Log the updated inode size as we go. We have to be careful
  807. * to only log it up to the actual write offset if it is
  808. * halfway into a block.
  809. */
  810. i_size = XFS_FSB_TO_B(mp, offset_fsb + count_fsb);
  811. if (i_size > offset + count)
  812. i_size = offset + count;
  813. if (update_isize && i_size > i_size_read(inode))
  814. i_size_write(inode, i_size);
  815. i_size = xfs_new_eof(ip, i_size);
  816. if (i_size) {
  817. ip->i_d.di_size = i_size;
  818. xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
  819. }
  820. error = xfs_defer_finish(&tp, &dfops, NULL);
  821. if (error)
  822. goto error_on_bmapi_transaction;
  823. error = xfs_trans_commit(tp);
  824. xfs_iunlock(ip, XFS_ILOCK_EXCL);
  825. if (error)
  826. return error;
  827. if (!(imap.br_startblock || XFS_IS_REALTIME_INODE(ip)))
  828. return xfs_alert_fsblock_zero(ip, &imap);
  829. if ((numblks_fsb = imap.br_blockcount) == 0) {
  830. /*
  831. * The numblks_fsb value should always get
  832. * smaller, otherwise the loop is stuck.
  833. */
  834. ASSERT(imap.br_blockcount);
  835. break;
  836. }
  837. offset_fsb += numblks_fsb;
  838. count_fsb -= numblks_fsb;
  839. } while (count_fsb > 0);
  840. return 0;
  841. error_on_bmapi_transaction:
  842. xfs_defer_cancel(&dfops);
  843. xfs_trans_cancel(tp);
  844. xfs_iunlock(ip, XFS_ILOCK_EXCL);
  845. return error;
  846. }
  847. static inline bool imap_needs_alloc(struct inode *inode,
  848. struct xfs_bmbt_irec *imap, int nimaps)
  849. {
  850. return !nimaps ||
  851. imap->br_startblock == HOLESTARTBLOCK ||
  852. imap->br_startblock == DELAYSTARTBLOCK ||
  853. (IS_DAX(inode) && ISUNWRITTEN(imap));
  854. }
  855. static int
  856. xfs_file_iomap_begin(
  857. struct inode *inode,
  858. loff_t offset,
  859. loff_t length,
  860. unsigned flags,
  861. struct iomap *iomap)
  862. {
  863. struct xfs_inode *ip = XFS_I(inode);
  864. struct xfs_mount *mp = ip->i_mount;
  865. struct xfs_bmbt_irec imap;
  866. xfs_fileoff_t offset_fsb, end_fsb;
  867. int nimaps = 1, error = 0;
  868. bool shared = false, trimmed = false;
  869. unsigned lockmode;
  870. if (XFS_FORCED_SHUTDOWN(mp))
  871. return -EIO;
  872. if ((flags & IOMAP_WRITE) && !IS_DAX(inode) &&
  873. !xfs_get_extsz_hint(ip)) {
  874. /* Reserve delalloc blocks for regular writeback. */
  875. return xfs_file_iomap_begin_delay(inode, offset, length, flags,
  876. iomap);
  877. }
  878. /*
  879. * COW writes will allocate delalloc space, so we need to make sure
  880. * to take the lock exclusively here.
  881. */
  882. if ((flags & (IOMAP_WRITE | IOMAP_ZERO)) && xfs_is_reflink_inode(ip)) {
  883. lockmode = XFS_ILOCK_EXCL;
  884. xfs_ilock(ip, XFS_ILOCK_EXCL);
  885. } else {
  886. lockmode = xfs_ilock_data_map_shared(ip);
  887. }
  888. ASSERT(offset <= mp->m_super->s_maxbytes);
  889. if ((xfs_fsize_t)offset + length > mp->m_super->s_maxbytes)
  890. length = mp->m_super->s_maxbytes - offset;
  891. offset_fsb = XFS_B_TO_FSBT(mp, offset);
  892. end_fsb = XFS_B_TO_FSB(mp, offset + length);
  893. error = xfs_bmapi_read(ip, offset_fsb, end_fsb - offset_fsb, &imap,
  894. &nimaps, 0);
  895. if (error)
  896. goto out_unlock;
  897. if (flags & IOMAP_REPORT) {
  898. /* Trim the mapping to the nearest shared extent boundary. */
  899. error = xfs_reflink_trim_around_shared(ip, &imap, &shared,
  900. &trimmed);
  901. if (error)
  902. goto out_unlock;
  903. }
  904. if ((flags & (IOMAP_WRITE | IOMAP_ZERO)) && xfs_is_reflink_inode(ip)) {
  905. error = xfs_reflink_reserve_cow(ip, &imap, &shared);
  906. if (error)
  907. goto out_unlock;
  908. end_fsb = imap.br_startoff + imap.br_blockcount;
  909. length = XFS_FSB_TO_B(mp, end_fsb) - offset;
  910. }
  911. if ((flags & IOMAP_WRITE) && imap_needs_alloc(inode, &imap, nimaps)) {
  912. /*
  913. * We cap the maximum length we map here to MAX_WRITEBACK_PAGES
  914. * pages to keep the chunks of work done where somewhat symmetric
  915. * with the work writeback does. This is a completely arbitrary
  916. * number pulled out of thin air as a best guess for initial
  917. * testing.
  918. *
  919. * Note that the values needs to be less than 32-bits wide until
  920. * the lower level functions are updated.
  921. */
  922. length = min_t(loff_t, length, 1024 * PAGE_SIZE);
  923. /*
  924. * xfs_iomap_write_direct() expects the shared lock. It
  925. * is unlocked on return.
  926. */
  927. if (lockmode == XFS_ILOCK_EXCL)
  928. xfs_ilock_demote(ip, lockmode);
  929. error = xfs_iomap_write_direct(ip, offset, length, &imap,
  930. nimaps);
  931. if (error)
  932. return error;
  933. iomap->flags = IOMAP_F_NEW;
  934. trace_xfs_iomap_alloc(ip, offset, length, 0, &imap);
  935. } else {
  936. ASSERT(nimaps);
  937. xfs_iunlock(ip, lockmode);
  938. trace_xfs_iomap_found(ip, offset, length, 0, &imap);
  939. }
  940. xfs_bmbt_to_iomap(ip, iomap, &imap);
  941. if (shared)
  942. iomap->flags |= IOMAP_F_SHARED;
  943. return 0;
  944. out_unlock:
  945. xfs_iunlock(ip, lockmode);
  946. return error;
  947. }
  948. static int
  949. xfs_file_iomap_end_delalloc(
  950. struct xfs_inode *ip,
  951. loff_t offset,
  952. loff_t length,
  953. ssize_t written,
  954. struct iomap *iomap)
  955. {
  956. struct xfs_mount *mp = ip->i_mount;
  957. xfs_fileoff_t start_fsb;
  958. xfs_fileoff_t end_fsb;
  959. int error = 0;
  960. /*
  961. * start_fsb refers to the first unused block after a short write. If
  962. * nothing was written, round offset down to point at the first block in
  963. * the range.
  964. */
  965. if (unlikely(!written))
  966. start_fsb = XFS_B_TO_FSBT(mp, offset);
  967. else
  968. start_fsb = XFS_B_TO_FSB(mp, offset + written);
  969. end_fsb = XFS_B_TO_FSB(mp, offset + length);
  970. /*
  971. * Trim delalloc blocks if they were allocated by this write and we
  972. * didn't manage to write the whole range.
  973. *
  974. * We don't need to care about racing delalloc as we hold i_mutex
  975. * across the reserve/allocate/unreserve calls. If there are delalloc
  976. * blocks in the range, they are ours.
  977. */
  978. if ((iomap->flags & IOMAP_F_NEW) && start_fsb < end_fsb) {
  979. truncate_pagecache_range(VFS_I(ip), XFS_FSB_TO_B(mp, start_fsb),
  980. XFS_FSB_TO_B(mp, end_fsb) - 1);
  981. xfs_ilock(ip, XFS_ILOCK_EXCL);
  982. error = xfs_bmap_punch_delalloc_range(ip, start_fsb,
  983. end_fsb - start_fsb);
  984. xfs_iunlock(ip, XFS_ILOCK_EXCL);
  985. if (error && !XFS_FORCED_SHUTDOWN(mp)) {
  986. xfs_alert(mp, "%s: unable to clean up ino %lld",
  987. __func__, ip->i_ino);
  988. return error;
  989. }
  990. }
  991. return 0;
  992. }
  993. static int
  994. xfs_file_iomap_end(
  995. struct inode *inode,
  996. loff_t offset,
  997. loff_t length,
  998. ssize_t written,
  999. unsigned flags,
  1000. struct iomap *iomap)
  1001. {
  1002. if ((flags & IOMAP_WRITE) && iomap->type == IOMAP_DELALLOC)
  1003. return xfs_file_iomap_end_delalloc(XFS_I(inode), offset,
  1004. length, written, iomap);
  1005. return 0;
  1006. }
  1007. struct iomap_ops xfs_iomap_ops = {
  1008. .iomap_begin = xfs_file_iomap_begin,
  1009. .iomap_end = xfs_file_iomap_end,
  1010. };
  1011. static int
  1012. xfs_xattr_iomap_begin(
  1013. struct inode *inode,
  1014. loff_t offset,
  1015. loff_t length,
  1016. unsigned flags,
  1017. struct iomap *iomap)
  1018. {
  1019. struct xfs_inode *ip = XFS_I(inode);
  1020. struct xfs_mount *mp = ip->i_mount;
  1021. xfs_fileoff_t offset_fsb = XFS_B_TO_FSBT(mp, offset);
  1022. xfs_fileoff_t end_fsb = XFS_B_TO_FSB(mp, offset + length);
  1023. struct xfs_bmbt_irec imap;
  1024. int nimaps = 1, error = 0;
  1025. unsigned lockmode;
  1026. if (XFS_FORCED_SHUTDOWN(mp))
  1027. return -EIO;
  1028. lockmode = xfs_ilock_attr_map_shared(ip);
  1029. /* if there are no attribute fork or extents, return ENOENT */
  1030. if (!XFS_IFORK_Q(ip) || !ip->i_d.di_anextents) {
  1031. error = -ENOENT;
  1032. goto out_unlock;
  1033. }
  1034. ASSERT(ip->i_d.di_aformat != XFS_DINODE_FMT_LOCAL);
  1035. error = xfs_bmapi_read(ip, offset_fsb, end_fsb - offset_fsb, &imap,
  1036. &nimaps, XFS_BMAPI_ENTIRE | XFS_BMAPI_ATTRFORK);
  1037. out_unlock:
  1038. xfs_iunlock(ip, lockmode);
  1039. if (!error) {
  1040. ASSERT(nimaps);
  1041. xfs_bmbt_to_iomap(ip, iomap, &imap);
  1042. }
  1043. return error;
  1044. }
  1045. struct iomap_ops xfs_xattr_iomap_ops = {
  1046. .iomap_begin = xfs_xattr_iomap_begin,
  1047. };