xfs_iomap.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195
  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. trace_xfs_iomap_alloc(ip, offset, count, 0, &got);
  572. done:
  573. if (isnullstartblock(got.br_startblock))
  574. got.br_startblock = DELAYSTARTBLOCK;
  575. if (!got.br_startblock) {
  576. error = xfs_alert_fsblock_zero(ip, &got);
  577. if (error)
  578. goto out_unlock;
  579. }
  580. xfs_bmbt_to_iomap(ip, iomap, &got);
  581. out_unlock:
  582. xfs_iunlock(ip, XFS_ILOCK_EXCL);
  583. return error;
  584. }
  585. /*
  586. * Pass in a delayed allocate extent, convert it to real extents;
  587. * return to the caller the extent we create which maps on top of
  588. * the originating callers request.
  589. *
  590. * Called without a lock on the inode.
  591. *
  592. * We no longer bother to look at the incoming map - all we have to
  593. * guarantee is that whatever we allocate fills the required range.
  594. */
  595. int
  596. xfs_iomap_write_allocate(
  597. xfs_inode_t *ip,
  598. int whichfork,
  599. xfs_off_t offset,
  600. xfs_bmbt_irec_t *imap)
  601. {
  602. xfs_mount_t *mp = ip->i_mount;
  603. xfs_fileoff_t offset_fsb, last_block;
  604. xfs_fileoff_t end_fsb, map_start_fsb;
  605. xfs_fsblock_t first_block;
  606. struct xfs_defer_ops dfops;
  607. xfs_filblks_t count_fsb;
  608. xfs_trans_t *tp;
  609. int nimaps;
  610. int error = 0;
  611. int flags = 0;
  612. int nres;
  613. if (whichfork == XFS_COW_FORK)
  614. flags |= XFS_BMAPI_COWFORK;
  615. /*
  616. * Make sure that the dquots are there.
  617. */
  618. error = xfs_qm_dqattach(ip, 0);
  619. if (error)
  620. return error;
  621. offset_fsb = XFS_B_TO_FSBT(mp, offset);
  622. count_fsb = imap->br_blockcount;
  623. map_start_fsb = imap->br_startoff;
  624. XFS_STATS_ADD(mp, xs_xstrat_bytes, XFS_FSB_TO_B(mp, count_fsb));
  625. while (count_fsb != 0) {
  626. /*
  627. * Set up a transaction with which to allocate the
  628. * backing store for the file. Do allocations in a
  629. * loop until we get some space in the range we are
  630. * interested in. The other space that might be allocated
  631. * is in the delayed allocation extent on which we sit
  632. * but before our buffer starts.
  633. */
  634. nimaps = 0;
  635. while (nimaps == 0) {
  636. nres = XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK);
  637. /*
  638. * We have already reserved space for the extent and any
  639. * indirect blocks when creating the delalloc extent,
  640. * there is no need to reserve space in this transaction
  641. * again.
  642. */
  643. error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, 0,
  644. 0, XFS_TRANS_RESERVE, &tp);
  645. if (error)
  646. return error;
  647. xfs_ilock(ip, XFS_ILOCK_EXCL);
  648. xfs_trans_ijoin(tp, ip, 0);
  649. xfs_defer_init(&dfops, &first_block);
  650. /*
  651. * it is possible that the extents have changed since
  652. * we did the read call as we dropped the ilock for a
  653. * while. We have to be careful about truncates or hole
  654. * punchs here - we are not allowed to allocate
  655. * non-delalloc blocks here.
  656. *
  657. * The only protection against truncation is the pages
  658. * for the range we are being asked to convert are
  659. * locked and hence a truncate will block on them
  660. * first.
  661. *
  662. * As a result, if we go beyond the range we really
  663. * need and hit an delalloc extent boundary followed by
  664. * a hole while we have excess blocks in the map, we
  665. * will fill the hole incorrectly and overrun the
  666. * transaction reservation.
  667. *
  668. * Using a single map prevents this as we are forced to
  669. * check each map we look for overlap with the desired
  670. * range and abort as soon as we find it. Also, given
  671. * that we only return a single map, having one beyond
  672. * what we can return is probably a bit silly.
  673. *
  674. * We also need to check that we don't go beyond EOF;
  675. * this is a truncate optimisation as a truncate sets
  676. * the new file size before block on the pages we
  677. * currently have locked under writeback. Because they
  678. * are about to be tossed, we don't need to write them
  679. * back....
  680. */
  681. nimaps = 1;
  682. end_fsb = XFS_B_TO_FSB(mp, XFS_ISIZE(ip));
  683. error = xfs_bmap_last_offset(ip, &last_block,
  684. XFS_DATA_FORK);
  685. if (error)
  686. goto trans_cancel;
  687. last_block = XFS_FILEOFF_MAX(last_block, end_fsb);
  688. if ((map_start_fsb + count_fsb) > last_block) {
  689. count_fsb = last_block - map_start_fsb;
  690. if (count_fsb == 0) {
  691. error = -EAGAIN;
  692. goto trans_cancel;
  693. }
  694. }
  695. /*
  696. * From this point onwards we overwrite the imap
  697. * pointer that the caller gave to us.
  698. */
  699. error = xfs_bmapi_write(tp, ip, map_start_fsb,
  700. count_fsb, flags, &first_block,
  701. nres, imap, &nimaps,
  702. &dfops);
  703. if (error)
  704. goto trans_cancel;
  705. error = xfs_defer_finish(&tp, &dfops, NULL);
  706. if (error)
  707. goto trans_cancel;
  708. error = xfs_trans_commit(tp);
  709. if (error)
  710. goto error0;
  711. xfs_iunlock(ip, XFS_ILOCK_EXCL);
  712. }
  713. /*
  714. * See if we were able to allocate an extent that
  715. * covers at least part of the callers request
  716. */
  717. if (!(imap->br_startblock || XFS_IS_REALTIME_INODE(ip)))
  718. return xfs_alert_fsblock_zero(ip, imap);
  719. if ((offset_fsb >= imap->br_startoff) &&
  720. (offset_fsb < (imap->br_startoff +
  721. imap->br_blockcount))) {
  722. XFS_STATS_INC(mp, xs_xstrat_quick);
  723. return 0;
  724. }
  725. /*
  726. * So far we have not mapped the requested part of the
  727. * file, just surrounding data, try again.
  728. */
  729. count_fsb -= imap->br_blockcount;
  730. map_start_fsb = imap->br_startoff + imap->br_blockcount;
  731. }
  732. trans_cancel:
  733. xfs_defer_cancel(&dfops);
  734. xfs_trans_cancel(tp);
  735. error0:
  736. xfs_iunlock(ip, XFS_ILOCK_EXCL);
  737. return error;
  738. }
  739. int
  740. xfs_iomap_write_unwritten(
  741. xfs_inode_t *ip,
  742. xfs_off_t offset,
  743. xfs_off_t count)
  744. {
  745. xfs_mount_t *mp = ip->i_mount;
  746. xfs_fileoff_t offset_fsb;
  747. xfs_filblks_t count_fsb;
  748. xfs_filblks_t numblks_fsb;
  749. xfs_fsblock_t firstfsb;
  750. int nimaps;
  751. xfs_trans_t *tp;
  752. xfs_bmbt_irec_t imap;
  753. struct xfs_defer_ops dfops;
  754. xfs_fsize_t i_size;
  755. uint resblks;
  756. int error;
  757. trace_xfs_unwritten_convert(ip, offset, count);
  758. offset_fsb = XFS_B_TO_FSBT(mp, offset);
  759. count_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)offset + count);
  760. count_fsb = (xfs_filblks_t)(count_fsb - offset_fsb);
  761. /*
  762. * Reserve enough blocks in this transaction for two complete extent
  763. * btree splits. We may be converting the middle part of an unwritten
  764. * extent and in this case we will insert two new extents in the btree
  765. * each of which could cause a full split.
  766. *
  767. * This reservation amount will be used in the first call to
  768. * xfs_bmbt_split() to select an AG with enough space to satisfy the
  769. * rest of the operation.
  770. */
  771. resblks = XFS_DIOSTRAT_SPACE_RES(mp, 0) << 1;
  772. do {
  773. /*
  774. * Set up a transaction to convert the range of extents
  775. * from unwritten to real. Do allocations in a loop until
  776. * we have covered the range passed in.
  777. *
  778. * Note that we can't risk to recursing back into the filesystem
  779. * here as we might be asked to write out the same inode that we
  780. * complete here and might deadlock on the iolock.
  781. */
  782. error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, resblks, 0,
  783. XFS_TRANS_RESERVE | XFS_TRANS_NOFS, &tp);
  784. if (error)
  785. return error;
  786. xfs_ilock(ip, XFS_ILOCK_EXCL);
  787. xfs_trans_ijoin(tp, ip, 0);
  788. /*
  789. * Modify the unwritten extent state of the buffer.
  790. */
  791. xfs_defer_init(&dfops, &firstfsb);
  792. nimaps = 1;
  793. error = xfs_bmapi_write(tp, ip, offset_fsb, count_fsb,
  794. XFS_BMAPI_CONVERT, &firstfsb, resblks,
  795. &imap, &nimaps, &dfops);
  796. if (error)
  797. goto error_on_bmapi_transaction;
  798. /*
  799. * Log the updated inode size as we go. We have to be careful
  800. * to only log it up to the actual write offset if it is
  801. * halfway into a block.
  802. */
  803. i_size = XFS_FSB_TO_B(mp, offset_fsb + count_fsb);
  804. if (i_size > offset + count)
  805. i_size = offset + count;
  806. i_size = xfs_new_eof(ip, i_size);
  807. if (i_size) {
  808. ip->i_d.di_size = i_size;
  809. xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
  810. }
  811. error = xfs_defer_finish(&tp, &dfops, NULL);
  812. if (error)
  813. goto error_on_bmapi_transaction;
  814. error = xfs_trans_commit(tp);
  815. xfs_iunlock(ip, XFS_ILOCK_EXCL);
  816. if (error)
  817. return error;
  818. if (!(imap.br_startblock || XFS_IS_REALTIME_INODE(ip)))
  819. return xfs_alert_fsblock_zero(ip, &imap);
  820. if ((numblks_fsb = imap.br_blockcount) == 0) {
  821. /*
  822. * The numblks_fsb value should always get
  823. * smaller, otherwise the loop is stuck.
  824. */
  825. ASSERT(imap.br_blockcount);
  826. break;
  827. }
  828. offset_fsb += numblks_fsb;
  829. count_fsb -= numblks_fsb;
  830. } while (count_fsb > 0);
  831. return 0;
  832. error_on_bmapi_transaction:
  833. xfs_defer_cancel(&dfops);
  834. xfs_trans_cancel(tp);
  835. xfs_iunlock(ip, XFS_ILOCK_EXCL);
  836. return error;
  837. }
  838. static inline bool imap_needs_alloc(struct inode *inode,
  839. struct xfs_bmbt_irec *imap, int nimaps)
  840. {
  841. return !nimaps ||
  842. imap->br_startblock == HOLESTARTBLOCK ||
  843. imap->br_startblock == DELAYSTARTBLOCK ||
  844. (IS_DAX(inode) && ISUNWRITTEN(imap));
  845. }
  846. static inline bool need_excl_ilock(struct xfs_inode *ip, unsigned flags)
  847. {
  848. /*
  849. * COW writes will allocate delalloc space, so we need to make sure
  850. * to take the lock exclusively here.
  851. */
  852. if (xfs_is_reflink_inode(ip) && (flags & (IOMAP_WRITE | IOMAP_ZERO)))
  853. return true;
  854. if ((flags & IOMAP_DIRECT) && (flags & IOMAP_WRITE))
  855. return true;
  856. return false;
  857. }
  858. static int
  859. xfs_file_iomap_begin(
  860. struct inode *inode,
  861. loff_t offset,
  862. loff_t length,
  863. unsigned flags,
  864. struct iomap *iomap)
  865. {
  866. struct xfs_inode *ip = XFS_I(inode);
  867. struct xfs_mount *mp = ip->i_mount;
  868. struct xfs_bmbt_irec imap;
  869. xfs_fileoff_t offset_fsb, end_fsb;
  870. int nimaps = 1, error = 0;
  871. bool shared = false, trimmed = false;
  872. unsigned lockmode;
  873. if (XFS_FORCED_SHUTDOWN(mp))
  874. return -EIO;
  875. if (((flags & (IOMAP_WRITE | IOMAP_DIRECT)) == IOMAP_WRITE) &&
  876. !IS_DAX(inode) && !xfs_get_extsz_hint(ip)) {
  877. /* Reserve delalloc blocks for regular writeback. */
  878. return xfs_file_iomap_begin_delay(inode, offset, length, flags,
  879. iomap);
  880. }
  881. if (need_excl_ilock(ip, flags)) {
  882. lockmode = XFS_ILOCK_EXCL;
  883. xfs_ilock(ip, XFS_ILOCK_EXCL);
  884. } else {
  885. lockmode = xfs_ilock_data_map_shared(ip);
  886. }
  887. ASSERT(offset <= mp->m_super->s_maxbytes);
  888. if ((xfs_fsize_t)offset + length > mp->m_super->s_maxbytes)
  889. length = mp->m_super->s_maxbytes - offset;
  890. offset_fsb = XFS_B_TO_FSBT(mp, offset);
  891. end_fsb = XFS_B_TO_FSB(mp, offset + length);
  892. if (xfs_is_reflink_inode(ip) &&
  893. (flags & IOMAP_WRITE) && (flags & IOMAP_DIRECT)) {
  894. shared = xfs_reflink_find_cow_mapping(ip, offset, &imap);
  895. if (shared) {
  896. xfs_iunlock(ip, lockmode);
  897. goto alloc_done;
  898. }
  899. ASSERT(!isnullstartblock(imap.br_startblock));
  900. }
  901. error = xfs_bmapi_read(ip, offset_fsb, end_fsb - offset_fsb, &imap,
  902. &nimaps, 0);
  903. if (error)
  904. goto out_unlock;
  905. if ((flags & IOMAP_REPORT) ||
  906. (xfs_is_reflink_inode(ip) &&
  907. (flags & IOMAP_WRITE) && (flags & IOMAP_DIRECT))) {
  908. /* Trim the mapping to the nearest shared extent boundary. */
  909. error = xfs_reflink_trim_around_shared(ip, &imap, &shared,
  910. &trimmed);
  911. if (error)
  912. goto out_unlock;
  913. /*
  914. * We're here because we're trying to do a directio write to a
  915. * region that isn't aligned to a filesystem block. If the
  916. * extent is shared, fall back to buffered mode to handle the
  917. * RMW.
  918. */
  919. if (!(flags & IOMAP_REPORT) && shared) {
  920. trace_xfs_reflink_bounce_dio_write(ip, &imap);
  921. error = -EREMCHG;
  922. goto out_unlock;
  923. }
  924. }
  925. if ((flags & (IOMAP_WRITE | IOMAP_ZERO)) && xfs_is_reflink_inode(ip)) {
  926. error = xfs_reflink_reserve_cow(ip, &imap, &shared);
  927. if (error)
  928. goto out_unlock;
  929. end_fsb = imap.br_startoff + imap.br_blockcount;
  930. length = XFS_FSB_TO_B(mp, end_fsb) - offset;
  931. }
  932. if ((flags & IOMAP_WRITE) && imap_needs_alloc(inode, &imap, nimaps)) {
  933. /*
  934. * We cap the maximum length we map here to MAX_WRITEBACK_PAGES
  935. * pages to keep the chunks of work done where somewhat symmetric
  936. * with the work writeback does. This is a completely arbitrary
  937. * number pulled out of thin air as a best guess for initial
  938. * testing.
  939. *
  940. * Note that the values needs to be less than 32-bits wide until
  941. * the lower level functions are updated.
  942. */
  943. length = min_t(loff_t, length, 1024 * PAGE_SIZE);
  944. /*
  945. * xfs_iomap_write_direct() expects the shared lock. It
  946. * is unlocked on return.
  947. */
  948. if (lockmode == XFS_ILOCK_EXCL)
  949. xfs_ilock_demote(ip, lockmode);
  950. error = xfs_iomap_write_direct(ip, offset, length, &imap,
  951. nimaps);
  952. if (error)
  953. return error;
  954. alloc_done:
  955. iomap->flags = IOMAP_F_NEW;
  956. trace_xfs_iomap_alloc(ip, offset, length, 0, &imap);
  957. } else {
  958. ASSERT(nimaps);
  959. xfs_iunlock(ip, lockmode);
  960. trace_xfs_iomap_found(ip, offset, length, 0, &imap);
  961. }
  962. xfs_bmbt_to_iomap(ip, iomap, &imap);
  963. if (shared)
  964. iomap->flags |= IOMAP_F_SHARED;
  965. return 0;
  966. out_unlock:
  967. xfs_iunlock(ip, lockmode);
  968. return error;
  969. }
  970. static int
  971. xfs_file_iomap_end_delalloc(
  972. struct xfs_inode *ip,
  973. loff_t offset,
  974. loff_t length,
  975. ssize_t written)
  976. {
  977. struct xfs_mount *mp = ip->i_mount;
  978. xfs_fileoff_t start_fsb;
  979. xfs_fileoff_t end_fsb;
  980. int error = 0;
  981. start_fsb = XFS_B_TO_FSB(mp, offset + written);
  982. end_fsb = XFS_B_TO_FSB(mp, offset + length);
  983. /*
  984. * Trim back delalloc blocks if we didn't manage to write the whole
  985. * range reserved.
  986. *
  987. * We don't need to care about racing delalloc as we hold i_mutex
  988. * across the reserve/allocate/unreserve calls. If there are delalloc
  989. * blocks in the range, they are ours.
  990. */
  991. if (start_fsb < end_fsb) {
  992. xfs_ilock(ip, XFS_ILOCK_EXCL);
  993. error = xfs_bmap_punch_delalloc_range(ip, start_fsb,
  994. end_fsb - start_fsb);
  995. xfs_iunlock(ip, XFS_ILOCK_EXCL);
  996. if (error && !XFS_FORCED_SHUTDOWN(mp)) {
  997. xfs_alert(mp, "%s: unable to clean up ino %lld",
  998. __func__, ip->i_ino);
  999. return error;
  1000. }
  1001. }
  1002. return 0;
  1003. }
  1004. static int
  1005. xfs_file_iomap_end(
  1006. struct inode *inode,
  1007. loff_t offset,
  1008. loff_t length,
  1009. ssize_t written,
  1010. unsigned flags,
  1011. struct iomap *iomap)
  1012. {
  1013. if ((flags & IOMAP_WRITE) && iomap->type == IOMAP_DELALLOC)
  1014. return xfs_file_iomap_end_delalloc(XFS_I(inode), offset,
  1015. length, written);
  1016. return 0;
  1017. }
  1018. struct iomap_ops xfs_iomap_ops = {
  1019. .iomap_begin = xfs_file_iomap_begin,
  1020. .iomap_end = xfs_file_iomap_end,
  1021. };
  1022. static int
  1023. xfs_xattr_iomap_begin(
  1024. struct inode *inode,
  1025. loff_t offset,
  1026. loff_t length,
  1027. unsigned flags,
  1028. struct iomap *iomap)
  1029. {
  1030. struct xfs_inode *ip = XFS_I(inode);
  1031. struct xfs_mount *mp = ip->i_mount;
  1032. xfs_fileoff_t offset_fsb = XFS_B_TO_FSBT(mp, offset);
  1033. xfs_fileoff_t end_fsb = XFS_B_TO_FSB(mp, offset + length);
  1034. struct xfs_bmbt_irec imap;
  1035. int nimaps = 1, error = 0;
  1036. unsigned lockmode;
  1037. if (XFS_FORCED_SHUTDOWN(mp))
  1038. return -EIO;
  1039. lockmode = xfs_ilock_data_map_shared(ip);
  1040. /* if there are no attribute fork or extents, return ENOENT */
  1041. if (XFS_IFORK_Q(ip) || !ip->i_d.di_anextents) {
  1042. error = -ENOENT;
  1043. goto out_unlock;
  1044. }
  1045. ASSERT(ip->i_d.di_aformat != XFS_DINODE_FMT_LOCAL);
  1046. error = xfs_bmapi_read(ip, offset_fsb, end_fsb - offset_fsb, &imap,
  1047. &nimaps, XFS_BMAPI_ENTIRE | XFS_BMAPI_ATTRFORK);
  1048. out_unlock:
  1049. xfs_iunlock(ip, lockmode);
  1050. if (!error) {
  1051. ASSERT(nimaps);
  1052. xfs_bmbt_to_iomap(ip, iomap, &imap);
  1053. }
  1054. return error;
  1055. }
  1056. struct iomap_ops xfs_xattr_iomap_ops = {
  1057. .iomap_begin = xfs_xattr_iomap_begin,
  1058. };