xfs_buf.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942
  1. /*
  2. * Copyright (c) 2000-2006 Silicon Graphics, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it would be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write the Free Software Foundation,
  16. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "xfs.h"
  19. #include <linux/stddef.h>
  20. #include <linux/errno.h>
  21. #include <linux/gfp.h>
  22. #include <linux/pagemap.h>
  23. #include <linux/init.h>
  24. #include <linux/vmalloc.h>
  25. #include <linux/bio.h>
  26. #include <linux/sysctl.h>
  27. #include <linux/proc_fs.h>
  28. #include <linux/workqueue.h>
  29. #include <linux/percpu.h>
  30. #include <linux/blkdev.h>
  31. #include <linux/hash.h>
  32. #include <linux/kthread.h>
  33. #include <linux/migrate.h>
  34. #include <linux/backing-dev.h>
  35. #include <linux/freezer.h>
  36. #include "xfs_format.h"
  37. #include "xfs_log_format.h"
  38. #include "xfs_trans_resv.h"
  39. #include "xfs_sb.h"
  40. #include "xfs_mount.h"
  41. #include "xfs_trace.h"
  42. #include "xfs_log.h"
  43. static kmem_zone_t *xfs_buf_zone;
  44. #ifdef XFS_BUF_LOCK_TRACKING
  45. # define XB_SET_OWNER(bp) ((bp)->b_last_holder = current->pid)
  46. # define XB_CLEAR_OWNER(bp) ((bp)->b_last_holder = -1)
  47. # define XB_GET_OWNER(bp) ((bp)->b_last_holder)
  48. #else
  49. # define XB_SET_OWNER(bp) do { } while (0)
  50. # define XB_CLEAR_OWNER(bp) do { } while (0)
  51. # define XB_GET_OWNER(bp) do { } while (0)
  52. #endif
  53. #define xb_to_gfp(flags) \
  54. ((((flags) & XBF_READ_AHEAD) ? __GFP_NORETRY : GFP_NOFS) | __GFP_NOWARN)
  55. static inline int
  56. xfs_buf_is_vmapped(
  57. struct xfs_buf *bp)
  58. {
  59. /*
  60. * Return true if the buffer is vmapped.
  61. *
  62. * b_addr is null if the buffer is not mapped, but the code is clever
  63. * enough to know it doesn't have to map a single page, so the check has
  64. * to be both for b_addr and bp->b_page_count > 1.
  65. */
  66. return bp->b_addr && bp->b_page_count > 1;
  67. }
  68. static inline int
  69. xfs_buf_vmap_len(
  70. struct xfs_buf *bp)
  71. {
  72. return (bp->b_page_count * PAGE_SIZE) - bp->b_offset;
  73. }
  74. /*
  75. * When we mark a buffer stale, we remove the buffer from the LRU and clear the
  76. * b_lru_ref count so that the buffer is freed immediately when the buffer
  77. * reference count falls to zero. If the buffer is already on the LRU, we need
  78. * to remove the reference that LRU holds on the buffer.
  79. *
  80. * This prevents build-up of stale buffers on the LRU.
  81. */
  82. void
  83. xfs_buf_stale(
  84. struct xfs_buf *bp)
  85. {
  86. ASSERT(xfs_buf_islocked(bp));
  87. bp->b_flags |= XBF_STALE;
  88. /*
  89. * Clear the delwri status so that a delwri queue walker will not
  90. * flush this buffer to disk now that it is stale. The delwri queue has
  91. * a reference to the buffer, so this is safe to do.
  92. */
  93. bp->b_flags &= ~_XBF_DELWRI_Q;
  94. spin_lock(&bp->b_lock);
  95. atomic_set(&bp->b_lru_ref, 0);
  96. if (!(bp->b_state & XFS_BSTATE_DISPOSE) &&
  97. (list_lru_del(&bp->b_target->bt_lru, &bp->b_lru)))
  98. atomic_dec(&bp->b_hold);
  99. ASSERT(atomic_read(&bp->b_hold) >= 1);
  100. spin_unlock(&bp->b_lock);
  101. }
  102. static int
  103. xfs_buf_get_maps(
  104. struct xfs_buf *bp,
  105. int map_count)
  106. {
  107. ASSERT(bp->b_maps == NULL);
  108. bp->b_map_count = map_count;
  109. if (map_count == 1) {
  110. bp->b_maps = &bp->__b_map;
  111. return 0;
  112. }
  113. bp->b_maps = kmem_zalloc(map_count * sizeof(struct xfs_buf_map),
  114. KM_NOFS);
  115. if (!bp->b_maps)
  116. return -ENOMEM;
  117. return 0;
  118. }
  119. /*
  120. * Frees b_pages if it was allocated.
  121. */
  122. static void
  123. xfs_buf_free_maps(
  124. struct xfs_buf *bp)
  125. {
  126. if (bp->b_maps != &bp->__b_map) {
  127. kmem_free(bp->b_maps);
  128. bp->b_maps = NULL;
  129. }
  130. }
  131. struct xfs_buf *
  132. _xfs_buf_alloc(
  133. struct xfs_buftarg *target,
  134. struct xfs_buf_map *map,
  135. int nmaps,
  136. xfs_buf_flags_t flags)
  137. {
  138. struct xfs_buf *bp;
  139. int error;
  140. int i;
  141. bp = kmem_zone_zalloc(xfs_buf_zone, KM_NOFS);
  142. if (unlikely(!bp))
  143. return NULL;
  144. /*
  145. * We don't want certain flags to appear in b_flags unless they are
  146. * specifically set by later operations on the buffer.
  147. */
  148. flags &= ~(XBF_UNMAPPED | XBF_TRYLOCK | XBF_ASYNC | XBF_READ_AHEAD);
  149. atomic_set(&bp->b_hold, 1);
  150. atomic_set(&bp->b_lru_ref, 1);
  151. init_completion(&bp->b_iowait);
  152. INIT_LIST_HEAD(&bp->b_lru);
  153. INIT_LIST_HEAD(&bp->b_list);
  154. RB_CLEAR_NODE(&bp->b_rbnode);
  155. sema_init(&bp->b_sema, 0); /* held, no waiters */
  156. spin_lock_init(&bp->b_lock);
  157. XB_SET_OWNER(bp);
  158. bp->b_target = target;
  159. bp->b_flags = flags;
  160. /*
  161. * Set length and io_length to the same value initially.
  162. * I/O routines should use io_length, which will be the same in
  163. * most cases but may be reset (e.g. XFS recovery).
  164. */
  165. error = xfs_buf_get_maps(bp, nmaps);
  166. if (error) {
  167. kmem_zone_free(xfs_buf_zone, bp);
  168. return NULL;
  169. }
  170. bp->b_bn = map[0].bm_bn;
  171. bp->b_length = 0;
  172. for (i = 0; i < nmaps; i++) {
  173. bp->b_maps[i].bm_bn = map[i].bm_bn;
  174. bp->b_maps[i].bm_len = map[i].bm_len;
  175. bp->b_length += map[i].bm_len;
  176. }
  177. bp->b_io_length = bp->b_length;
  178. atomic_set(&bp->b_pin_count, 0);
  179. init_waitqueue_head(&bp->b_waiters);
  180. XFS_STATS_INC(target->bt_mount, xb_create);
  181. trace_xfs_buf_init(bp, _RET_IP_);
  182. return bp;
  183. }
  184. /*
  185. * Allocate a page array capable of holding a specified number
  186. * of pages, and point the page buf at it.
  187. */
  188. STATIC int
  189. _xfs_buf_get_pages(
  190. xfs_buf_t *bp,
  191. int page_count)
  192. {
  193. /* Make sure that we have a page list */
  194. if (bp->b_pages == NULL) {
  195. bp->b_page_count = page_count;
  196. if (page_count <= XB_PAGES) {
  197. bp->b_pages = bp->b_page_array;
  198. } else {
  199. bp->b_pages = kmem_alloc(sizeof(struct page *) *
  200. page_count, KM_NOFS);
  201. if (bp->b_pages == NULL)
  202. return -ENOMEM;
  203. }
  204. memset(bp->b_pages, 0, sizeof(struct page *) * page_count);
  205. }
  206. return 0;
  207. }
  208. /*
  209. * Frees b_pages if it was allocated.
  210. */
  211. STATIC void
  212. _xfs_buf_free_pages(
  213. xfs_buf_t *bp)
  214. {
  215. if (bp->b_pages != bp->b_page_array) {
  216. kmem_free(bp->b_pages);
  217. bp->b_pages = NULL;
  218. }
  219. }
  220. /*
  221. * Releases the specified buffer.
  222. *
  223. * The modification state of any associated pages is left unchanged.
  224. * The buffer must not be on any hash - use xfs_buf_rele instead for
  225. * hashed and refcounted buffers
  226. */
  227. void
  228. xfs_buf_free(
  229. xfs_buf_t *bp)
  230. {
  231. trace_xfs_buf_free(bp, _RET_IP_);
  232. ASSERT(list_empty(&bp->b_lru));
  233. if (bp->b_flags & _XBF_PAGES) {
  234. uint i;
  235. if (xfs_buf_is_vmapped(bp))
  236. vm_unmap_ram(bp->b_addr - bp->b_offset,
  237. bp->b_page_count);
  238. for (i = 0; i < bp->b_page_count; i++) {
  239. struct page *page = bp->b_pages[i];
  240. __free_page(page);
  241. }
  242. } else if (bp->b_flags & _XBF_KMEM)
  243. kmem_free(bp->b_addr);
  244. _xfs_buf_free_pages(bp);
  245. xfs_buf_free_maps(bp);
  246. kmem_zone_free(xfs_buf_zone, bp);
  247. }
  248. /*
  249. * Allocates all the pages for buffer in question and builds it's page list.
  250. */
  251. STATIC int
  252. xfs_buf_allocate_memory(
  253. xfs_buf_t *bp,
  254. uint flags)
  255. {
  256. size_t size;
  257. size_t nbytes, offset;
  258. gfp_t gfp_mask = xb_to_gfp(flags);
  259. unsigned short page_count, i;
  260. xfs_off_t start, end;
  261. int error;
  262. /*
  263. * for buffers that are contained within a single page, just allocate
  264. * the memory from the heap - there's no need for the complexity of
  265. * page arrays to keep allocation down to order 0.
  266. */
  267. size = BBTOB(bp->b_length);
  268. if (size < PAGE_SIZE) {
  269. bp->b_addr = kmem_alloc(size, KM_NOFS);
  270. if (!bp->b_addr) {
  271. /* low memory - use alloc_page loop instead */
  272. goto use_alloc_page;
  273. }
  274. if (((unsigned long)(bp->b_addr + size - 1) & PAGE_MASK) !=
  275. ((unsigned long)bp->b_addr & PAGE_MASK)) {
  276. /* b_addr spans two pages - use alloc_page instead */
  277. kmem_free(bp->b_addr);
  278. bp->b_addr = NULL;
  279. goto use_alloc_page;
  280. }
  281. bp->b_offset = offset_in_page(bp->b_addr);
  282. bp->b_pages = bp->b_page_array;
  283. bp->b_pages[0] = virt_to_page(bp->b_addr);
  284. bp->b_page_count = 1;
  285. bp->b_flags |= _XBF_KMEM;
  286. return 0;
  287. }
  288. use_alloc_page:
  289. start = BBTOB(bp->b_maps[0].bm_bn) >> PAGE_SHIFT;
  290. end = (BBTOB(bp->b_maps[0].bm_bn + bp->b_length) + PAGE_SIZE - 1)
  291. >> PAGE_SHIFT;
  292. page_count = end - start;
  293. error = _xfs_buf_get_pages(bp, page_count);
  294. if (unlikely(error))
  295. return error;
  296. offset = bp->b_offset;
  297. bp->b_flags |= _XBF_PAGES;
  298. for (i = 0; i < bp->b_page_count; i++) {
  299. struct page *page;
  300. uint retries = 0;
  301. retry:
  302. page = alloc_page(gfp_mask);
  303. if (unlikely(page == NULL)) {
  304. if (flags & XBF_READ_AHEAD) {
  305. bp->b_page_count = i;
  306. error = -ENOMEM;
  307. goto out_free_pages;
  308. }
  309. /*
  310. * This could deadlock.
  311. *
  312. * But until all the XFS lowlevel code is revamped to
  313. * handle buffer allocation failures we can't do much.
  314. */
  315. if (!(++retries % 100))
  316. xfs_err(NULL,
  317. "%s(%u) possible memory allocation deadlock in %s (mode:0x%x)",
  318. current->comm, current->pid,
  319. __func__, gfp_mask);
  320. XFS_STATS_INC(bp->b_target->bt_mount, xb_page_retries);
  321. congestion_wait(BLK_RW_ASYNC, HZ/50);
  322. goto retry;
  323. }
  324. XFS_STATS_INC(bp->b_target->bt_mount, xb_page_found);
  325. nbytes = min_t(size_t, size, PAGE_SIZE - offset);
  326. size -= nbytes;
  327. bp->b_pages[i] = page;
  328. offset = 0;
  329. }
  330. return 0;
  331. out_free_pages:
  332. for (i = 0; i < bp->b_page_count; i++)
  333. __free_page(bp->b_pages[i]);
  334. bp->b_flags &= ~_XBF_PAGES;
  335. return error;
  336. }
  337. /*
  338. * Map buffer into kernel address-space if necessary.
  339. */
  340. STATIC int
  341. _xfs_buf_map_pages(
  342. xfs_buf_t *bp,
  343. uint flags)
  344. {
  345. ASSERT(bp->b_flags & _XBF_PAGES);
  346. if (bp->b_page_count == 1) {
  347. /* A single page buffer is always mappable */
  348. bp->b_addr = page_address(bp->b_pages[0]) + bp->b_offset;
  349. } else if (flags & XBF_UNMAPPED) {
  350. bp->b_addr = NULL;
  351. } else {
  352. int retried = 0;
  353. unsigned noio_flag;
  354. /*
  355. * vm_map_ram() will allocate auxillary structures (e.g.
  356. * pagetables) with GFP_KERNEL, yet we are likely to be under
  357. * GFP_NOFS context here. Hence we need to tell memory reclaim
  358. * that we are in such a context via PF_MEMALLOC_NOIO to prevent
  359. * memory reclaim re-entering the filesystem here and
  360. * potentially deadlocking.
  361. */
  362. noio_flag = memalloc_noio_save();
  363. do {
  364. bp->b_addr = vm_map_ram(bp->b_pages, bp->b_page_count,
  365. -1, PAGE_KERNEL);
  366. if (bp->b_addr)
  367. break;
  368. vm_unmap_aliases();
  369. } while (retried++ <= 1);
  370. memalloc_noio_restore(noio_flag);
  371. if (!bp->b_addr)
  372. return -ENOMEM;
  373. bp->b_addr += bp->b_offset;
  374. }
  375. return 0;
  376. }
  377. /*
  378. * Finding and Reading Buffers
  379. */
  380. /*
  381. * Look up, and creates if absent, a lockable buffer for
  382. * a given range of an inode. The buffer is returned
  383. * locked. No I/O is implied by this call.
  384. */
  385. xfs_buf_t *
  386. _xfs_buf_find(
  387. struct xfs_buftarg *btp,
  388. struct xfs_buf_map *map,
  389. int nmaps,
  390. xfs_buf_flags_t flags,
  391. xfs_buf_t *new_bp)
  392. {
  393. struct xfs_perag *pag;
  394. struct rb_node **rbp;
  395. struct rb_node *parent;
  396. xfs_buf_t *bp;
  397. xfs_daddr_t blkno = map[0].bm_bn;
  398. xfs_daddr_t eofs;
  399. int numblks = 0;
  400. int i;
  401. for (i = 0; i < nmaps; i++)
  402. numblks += map[i].bm_len;
  403. /* Check for IOs smaller than the sector size / not sector aligned */
  404. ASSERT(!(BBTOB(numblks) < btp->bt_meta_sectorsize));
  405. ASSERT(!(BBTOB(blkno) & (xfs_off_t)btp->bt_meta_sectormask));
  406. /*
  407. * Corrupted block numbers can get through to here, unfortunately, so we
  408. * have to check that the buffer falls within the filesystem bounds.
  409. */
  410. eofs = XFS_FSB_TO_BB(btp->bt_mount, btp->bt_mount->m_sb.sb_dblocks);
  411. if (blkno < 0 || blkno >= eofs) {
  412. /*
  413. * XXX (dgc): we should really be returning -EFSCORRUPTED here,
  414. * but none of the higher level infrastructure supports
  415. * returning a specific error on buffer lookup failures.
  416. */
  417. xfs_alert(btp->bt_mount,
  418. "%s: Block out of range: block 0x%llx, EOFS 0x%llx ",
  419. __func__, blkno, eofs);
  420. WARN_ON(1);
  421. return NULL;
  422. }
  423. /* get tree root */
  424. pag = xfs_perag_get(btp->bt_mount,
  425. xfs_daddr_to_agno(btp->bt_mount, blkno));
  426. /* walk tree */
  427. spin_lock(&pag->pag_buf_lock);
  428. rbp = &pag->pag_buf_tree.rb_node;
  429. parent = NULL;
  430. bp = NULL;
  431. while (*rbp) {
  432. parent = *rbp;
  433. bp = rb_entry(parent, struct xfs_buf, b_rbnode);
  434. if (blkno < bp->b_bn)
  435. rbp = &(*rbp)->rb_left;
  436. else if (blkno > bp->b_bn)
  437. rbp = &(*rbp)->rb_right;
  438. else {
  439. /*
  440. * found a block number match. If the range doesn't
  441. * match, the only way this is allowed is if the buffer
  442. * in the cache is stale and the transaction that made
  443. * it stale has not yet committed. i.e. we are
  444. * reallocating a busy extent. Skip this buffer and
  445. * continue searching to the right for an exact match.
  446. */
  447. if (bp->b_length != numblks) {
  448. ASSERT(bp->b_flags & XBF_STALE);
  449. rbp = &(*rbp)->rb_right;
  450. continue;
  451. }
  452. atomic_inc(&bp->b_hold);
  453. goto found;
  454. }
  455. }
  456. /* No match found */
  457. if (new_bp) {
  458. rb_link_node(&new_bp->b_rbnode, parent, rbp);
  459. rb_insert_color(&new_bp->b_rbnode, &pag->pag_buf_tree);
  460. /* the buffer keeps the perag reference until it is freed */
  461. new_bp->b_pag = pag;
  462. spin_unlock(&pag->pag_buf_lock);
  463. } else {
  464. XFS_STATS_INC(btp->bt_mount, xb_miss_locked);
  465. spin_unlock(&pag->pag_buf_lock);
  466. xfs_perag_put(pag);
  467. }
  468. return new_bp;
  469. found:
  470. spin_unlock(&pag->pag_buf_lock);
  471. xfs_perag_put(pag);
  472. if (!xfs_buf_trylock(bp)) {
  473. if (flags & XBF_TRYLOCK) {
  474. xfs_buf_rele(bp);
  475. XFS_STATS_INC(btp->bt_mount, xb_busy_locked);
  476. return NULL;
  477. }
  478. xfs_buf_lock(bp);
  479. XFS_STATS_INC(btp->bt_mount, xb_get_locked_waited);
  480. }
  481. /*
  482. * if the buffer is stale, clear all the external state associated with
  483. * it. We need to keep flags such as how we allocated the buffer memory
  484. * intact here.
  485. */
  486. if (bp->b_flags & XBF_STALE) {
  487. ASSERT((bp->b_flags & _XBF_DELWRI_Q) == 0);
  488. ASSERT(bp->b_iodone == NULL);
  489. bp->b_flags &= _XBF_KMEM | _XBF_PAGES;
  490. bp->b_ops = NULL;
  491. }
  492. trace_xfs_buf_find(bp, flags, _RET_IP_);
  493. XFS_STATS_INC(btp->bt_mount, xb_get_locked);
  494. return bp;
  495. }
  496. /*
  497. * Assembles a buffer covering the specified range. The code is optimised for
  498. * cache hits, as metadata intensive workloads will see 3 orders of magnitude
  499. * more hits than misses.
  500. */
  501. struct xfs_buf *
  502. xfs_buf_get_map(
  503. struct xfs_buftarg *target,
  504. struct xfs_buf_map *map,
  505. int nmaps,
  506. xfs_buf_flags_t flags)
  507. {
  508. struct xfs_buf *bp;
  509. struct xfs_buf *new_bp;
  510. int error = 0;
  511. bp = _xfs_buf_find(target, map, nmaps, flags, NULL);
  512. if (likely(bp))
  513. goto found;
  514. new_bp = _xfs_buf_alloc(target, map, nmaps, flags);
  515. if (unlikely(!new_bp))
  516. return NULL;
  517. error = xfs_buf_allocate_memory(new_bp, flags);
  518. if (error) {
  519. xfs_buf_free(new_bp);
  520. return NULL;
  521. }
  522. bp = _xfs_buf_find(target, map, nmaps, flags, new_bp);
  523. if (!bp) {
  524. xfs_buf_free(new_bp);
  525. return NULL;
  526. }
  527. if (bp != new_bp)
  528. xfs_buf_free(new_bp);
  529. found:
  530. if (!bp->b_addr) {
  531. error = _xfs_buf_map_pages(bp, flags);
  532. if (unlikely(error)) {
  533. xfs_warn(target->bt_mount,
  534. "%s: failed to map pagesn", __func__);
  535. xfs_buf_relse(bp);
  536. return NULL;
  537. }
  538. }
  539. /*
  540. * Clear b_error if this is a lookup from a caller that doesn't expect
  541. * valid data to be found in the buffer.
  542. */
  543. if (!(flags & XBF_READ))
  544. xfs_buf_ioerror(bp, 0);
  545. XFS_STATS_INC(target->bt_mount, xb_get);
  546. trace_xfs_buf_get(bp, flags, _RET_IP_);
  547. return bp;
  548. }
  549. STATIC int
  550. _xfs_buf_read(
  551. xfs_buf_t *bp,
  552. xfs_buf_flags_t flags)
  553. {
  554. ASSERT(!(flags & XBF_WRITE));
  555. ASSERT(bp->b_maps[0].bm_bn != XFS_BUF_DADDR_NULL);
  556. bp->b_flags &= ~(XBF_WRITE | XBF_ASYNC | XBF_READ_AHEAD);
  557. bp->b_flags |= flags & (XBF_READ | XBF_ASYNC | XBF_READ_AHEAD);
  558. if (flags & XBF_ASYNC) {
  559. xfs_buf_submit(bp);
  560. return 0;
  561. }
  562. return xfs_buf_submit_wait(bp);
  563. }
  564. xfs_buf_t *
  565. xfs_buf_read_map(
  566. struct xfs_buftarg *target,
  567. struct xfs_buf_map *map,
  568. int nmaps,
  569. xfs_buf_flags_t flags,
  570. const struct xfs_buf_ops *ops)
  571. {
  572. struct xfs_buf *bp;
  573. flags |= XBF_READ;
  574. bp = xfs_buf_get_map(target, map, nmaps, flags);
  575. if (bp) {
  576. trace_xfs_buf_read(bp, flags, _RET_IP_);
  577. if (!XFS_BUF_ISDONE(bp)) {
  578. XFS_STATS_INC(target->bt_mount, xb_get_read);
  579. bp->b_ops = ops;
  580. _xfs_buf_read(bp, flags);
  581. } else if (flags & XBF_ASYNC) {
  582. /*
  583. * Read ahead call which is already satisfied,
  584. * drop the buffer
  585. */
  586. xfs_buf_relse(bp);
  587. return NULL;
  588. } else {
  589. /* We do not want read in the flags */
  590. bp->b_flags &= ~XBF_READ;
  591. }
  592. }
  593. return bp;
  594. }
  595. /*
  596. * If we are not low on memory then do the readahead in a deadlock
  597. * safe manner.
  598. */
  599. void
  600. xfs_buf_readahead_map(
  601. struct xfs_buftarg *target,
  602. struct xfs_buf_map *map,
  603. int nmaps,
  604. const struct xfs_buf_ops *ops)
  605. {
  606. if (bdi_read_congested(target->bt_bdi))
  607. return;
  608. xfs_buf_read_map(target, map, nmaps,
  609. XBF_TRYLOCK|XBF_ASYNC|XBF_READ_AHEAD, ops);
  610. }
  611. /*
  612. * Read an uncached buffer from disk. Allocates and returns a locked
  613. * buffer containing the disk contents or nothing.
  614. */
  615. int
  616. xfs_buf_read_uncached(
  617. struct xfs_buftarg *target,
  618. xfs_daddr_t daddr,
  619. size_t numblks,
  620. int flags,
  621. struct xfs_buf **bpp,
  622. const struct xfs_buf_ops *ops)
  623. {
  624. struct xfs_buf *bp;
  625. *bpp = NULL;
  626. bp = xfs_buf_get_uncached(target, numblks, flags);
  627. if (!bp)
  628. return -ENOMEM;
  629. /* set up the buffer for a read IO */
  630. ASSERT(bp->b_map_count == 1);
  631. bp->b_bn = XFS_BUF_DADDR_NULL; /* always null for uncached buffers */
  632. bp->b_maps[0].bm_bn = daddr;
  633. bp->b_flags |= XBF_READ;
  634. bp->b_ops = ops;
  635. xfs_buf_submit_wait(bp);
  636. if (bp->b_error) {
  637. int error = bp->b_error;
  638. xfs_buf_relse(bp);
  639. return error;
  640. }
  641. *bpp = bp;
  642. return 0;
  643. }
  644. /*
  645. * Return a buffer allocated as an empty buffer and associated to external
  646. * memory via xfs_buf_associate_memory() back to it's empty state.
  647. */
  648. void
  649. xfs_buf_set_empty(
  650. struct xfs_buf *bp,
  651. size_t numblks)
  652. {
  653. if (bp->b_pages)
  654. _xfs_buf_free_pages(bp);
  655. bp->b_pages = NULL;
  656. bp->b_page_count = 0;
  657. bp->b_addr = NULL;
  658. bp->b_length = numblks;
  659. bp->b_io_length = numblks;
  660. ASSERT(bp->b_map_count == 1);
  661. bp->b_bn = XFS_BUF_DADDR_NULL;
  662. bp->b_maps[0].bm_bn = XFS_BUF_DADDR_NULL;
  663. bp->b_maps[0].bm_len = bp->b_length;
  664. }
  665. static inline struct page *
  666. mem_to_page(
  667. void *addr)
  668. {
  669. if ((!is_vmalloc_addr(addr))) {
  670. return virt_to_page(addr);
  671. } else {
  672. return vmalloc_to_page(addr);
  673. }
  674. }
  675. int
  676. xfs_buf_associate_memory(
  677. xfs_buf_t *bp,
  678. void *mem,
  679. size_t len)
  680. {
  681. int rval;
  682. int i = 0;
  683. unsigned long pageaddr;
  684. unsigned long offset;
  685. size_t buflen;
  686. int page_count;
  687. pageaddr = (unsigned long)mem & PAGE_MASK;
  688. offset = (unsigned long)mem - pageaddr;
  689. buflen = PAGE_ALIGN(len + offset);
  690. page_count = buflen >> PAGE_SHIFT;
  691. /* Free any previous set of page pointers */
  692. if (bp->b_pages)
  693. _xfs_buf_free_pages(bp);
  694. bp->b_pages = NULL;
  695. bp->b_addr = mem;
  696. rval = _xfs_buf_get_pages(bp, page_count);
  697. if (rval)
  698. return rval;
  699. bp->b_offset = offset;
  700. for (i = 0; i < bp->b_page_count; i++) {
  701. bp->b_pages[i] = mem_to_page((void *)pageaddr);
  702. pageaddr += PAGE_SIZE;
  703. }
  704. bp->b_io_length = BTOBB(len);
  705. bp->b_length = BTOBB(buflen);
  706. return 0;
  707. }
  708. xfs_buf_t *
  709. xfs_buf_get_uncached(
  710. struct xfs_buftarg *target,
  711. size_t numblks,
  712. int flags)
  713. {
  714. unsigned long page_count;
  715. int error, i;
  716. struct xfs_buf *bp;
  717. DEFINE_SINGLE_BUF_MAP(map, XFS_BUF_DADDR_NULL, numblks);
  718. bp = _xfs_buf_alloc(target, &map, 1, 0);
  719. if (unlikely(bp == NULL))
  720. goto fail;
  721. page_count = PAGE_ALIGN(numblks << BBSHIFT) >> PAGE_SHIFT;
  722. error = _xfs_buf_get_pages(bp, page_count);
  723. if (error)
  724. goto fail_free_buf;
  725. for (i = 0; i < page_count; i++) {
  726. bp->b_pages[i] = alloc_page(xb_to_gfp(flags));
  727. if (!bp->b_pages[i])
  728. goto fail_free_mem;
  729. }
  730. bp->b_flags |= _XBF_PAGES;
  731. error = _xfs_buf_map_pages(bp, 0);
  732. if (unlikely(error)) {
  733. xfs_warn(target->bt_mount,
  734. "%s: failed to map pages", __func__);
  735. goto fail_free_mem;
  736. }
  737. trace_xfs_buf_get_uncached(bp, _RET_IP_);
  738. return bp;
  739. fail_free_mem:
  740. while (--i >= 0)
  741. __free_page(bp->b_pages[i]);
  742. _xfs_buf_free_pages(bp);
  743. fail_free_buf:
  744. xfs_buf_free_maps(bp);
  745. kmem_zone_free(xfs_buf_zone, bp);
  746. fail:
  747. return NULL;
  748. }
  749. /*
  750. * Increment reference count on buffer, to hold the buffer concurrently
  751. * with another thread which may release (free) the buffer asynchronously.
  752. * Must hold the buffer already to call this function.
  753. */
  754. void
  755. xfs_buf_hold(
  756. xfs_buf_t *bp)
  757. {
  758. trace_xfs_buf_hold(bp, _RET_IP_);
  759. atomic_inc(&bp->b_hold);
  760. }
  761. /*
  762. * Releases a hold on the specified buffer. If the
  763. * the hold count is 1, calls xfs_buf_free.
  764. */
  765. void
  766. xfs_buf_rele(
  767. xfs_buf_t *bp)
  768. {
  769. struct xfs_perag *pag = bp->b_pag;
  770. trace_xfs_buf_rele(bp, _RET_IP_);
  771. if (!pag) {
  772. ASSERT(list_empty(&bp->b_lru));
  773. ASSERT(RB_EMPTY_NODE(&bp->b_rbnode));
  774. if (atomic_dec_and_test(&bp->b_hold))
  775. xfs_buf_free(bp);
  776. return;
  777. }
  778. ASSERT(!RB_EMPTY_NODE(&bp->b_rbnode));
  779. ASSERT(atomic_read(&bp->b_hold) > 0);
  780. if (atomic_dec_and_lock(&bp->b_hold, &pag->pag_buf_lock)) {
  781. spin_lock(&bp->b_lock);
  782. if (!(bp->b_flags & XBF_STALE) && atomic_read(&bp->b_lru_ref)) {
  783. /*
  784. * If the buffer is added to the LRU take a new
  785. * reference to the buffer for the LRU and clear the
  786. * (now stale) dispose list state flag
  787. */
  788. if (list_lru_add(&bp->b_target->bt_lru, &bp->b_lru)) {
  789. bp->b_state &= ~XFS_BSTATE_DISPOSE;
  790. atomic_inc(&bp->b_hold);
  791. }
  792. spin_unlock(&bp->b_lock);
  793. spin_unlock(&pag->pag_buf_lock);
  794. } else {
  795. /*
  796. * most of the time buffers will already be removed from
  797. * the LRU, so optimise that case by checking for the
  798. * XFS_BSTATE_DISPOSE flag indicating the last list the
  799. * buffer was on was the disposal list
  800. */
  801. if (!(bp->b_state & XFS_BSTATE_DISPOSE)) {
  802. list_lru_del(&bp->b_target->bt_lru, &bp->b_lru);
  803. } else {
  804. ASSERT(list_empty(&bp->b_lru));
  805. }
  806. spin_unlock(&bp->b_lock);
  807. ASSERT(!(bp->b_flags & _XBF_DELWRI_Q));
  808. rb_erase(&bp->b_rbnode, &pag->pag_buf_tree);
  809. spin_unlock(&pag->pag_buf_lock);
  810. xfs_perag_put(pag);
  811. xfs_buf_free(bp);
  812. }
  813. }
  814. }
  815. /*
  816. * Lock a buffer object, if it is not already locked.
  817. *
  818. * If we come across a stale, pinned, locked buffer, we know that we are
  819. * being asked to lock a buffer that has been reallocated. Because it is
  820. * pinned, we know that the log has not been pushed to disk and hence it
  821. * will still be locked. Rather than continuing to have trylock attempts
  822. * fail until someone else pushes the log, push it ourselves before
  823. * returning. This means that the xfsaild will not get stuck trying
  824. * to push on stale inode buffers.
  825. */
  826. int
  827. xfs_buf_trylock(
  828. struct xfs_buf *bp)
  829. {
  830. int locked;
  831. locked = down_trylock(&bp->b_sema) == 0;
  832. if (locked)
  833. XB_SET_OWNER(bp);
  834. trace_xfs_buf_trylock(bp, _RET_IP_);
  835. return locked;
  836. }
  837. /*
  838. * Lock a buffer object.
  839. *
  840. * If we come across a stale, pinned, locked buffer, we know that we
  841. * are being asked to lock a buffer that has been reallocated. Because
  842. * it is pinned, we know that the log has not been pushed to disk and
  843. * hence it will still be locked. Rather than sleeping until someone
  844. * else pushes the log, push it ourselves before trying to get the lock.
  845. */
  846. void
  847. xfs_buf_lock(
  848. struct xfs_buf *bp)
  849. {
  850. trace_xfs_buf_lock(bp, _RET_IP_);
  851. if (atomic_read(&bp->b_pin_count) && (bp->b_flags & XBF_STALE))
  852. xfs_log_force(bp->b_target->bt_mount, 0);
  853. down(&bp->b_sema);
  854. XB_SET_OWNER(bp);
  855. trace_xfs_buf_lock_done(bp, _RET_IP_);
  856. }
  857. void
  858. xfs_buf_unlock(
  859. struct xfs_buf *bp)
  860. {
  861. ASSERT(xfs_buf_islocked(bp));
  862. XB_CLEAR_OWNER(bp);
  863. up(&bp->b_sema);
  864. trace_xfs_buf_unlock(bp, _RET_IP_);
  865. }
  866. STATIC void
  867. xfs_buf_wait_unpin(
  868. xfs_buf_t *bp)
  869. {
  870. DECLARE_WAITQUEUE (wait, current);
  871. if (atomic_read(&bp->b_pin_count) == 0)
  872. return;
  873. add_wait_queue(&bp->b_waiters, &wait);
  874. for (;;) {
  875. set_current_state(TASK_UNINTERRUPTIBLE);
  876. if (atomic_read(&bp->b_pin_count) == 0)
  877. break;
  878. io_schedule();
  879. }
  880. remove_wait_queue(&bp->b_waiters, &wait);
  881. set_current_state(TASK_RUNNING);
  882. }
  883. /*
  884. * Buffer Utility Routines
  885. */
  886. void
  887. xfs_buf_ioend(
  888. struct xfs_buf *bp)
  889. {
  890. bool read = bp->b_flags & XBF_READ;
  891. trace_xfs_buf_iodone(bp, _RET_IP_);
  892. bp->b_flags &= ~(XBF_READ | XBF_WRITE | XBF_READ_AHEAD);
  893. /*
  894. * Pull in IO completion errors now. We are guaranteed to be running
  895. * single threaded, so we don't need the lock to read b_io_error.
  896. */
  897. if (!bp->b_error && bp->b_io_error)
  898. xfs_buf_ioerror(bp, bp->b_io_error);
  899. /* Only validate buffers that were read without errors */
  900. if (read && !bp->b_error && bp->b_ops) {
  901. ASSERT(!bp->b_iodone);
  902. bp->b_ops->verify_read(bp);
  903. }
  904. if (!bp->b_error)
  905. bp->b_flags |= XBF_DONE;
  906. if (bp->b_iodone)
  907. (*(bp->b_iodone))(bp);
  908. else if (bp->b_flags & XBF_ASYNC)
  909. xfs_buf_relse(bp);
  910. else
  911. complete(&bp->b_iowait);
  912. }
  913. static void
  914. xfs_buf_ioend_work(
  915. struct work_struct *work)
  916. {
  917. struct xfs_buf *bp =
  918. container_of(work, xfs_buf_t, b_ioend_work);
  919. xfs_buf_ioend(bp);
  920. }
  921. void
  922. xfs_buf_ioend_async(
  923. struct xfs_buf *bp)
  924. {
  925. INIT_WORK(&bp->b_ioend_work, xfs_buf_ioend_work);
  926. queue_work(bp->b_ioend_wq, &bp->b_ioend_work);
  927. }
  928. void
  929. xfs_buf_ioerror(
  930. xfs_buf_t *bp,
  931. int error)
  932. {
  933. ASSERT(error <= 0 && error >= -1000);
  934. bp->b_error = error;
  935. trace_xfs_buf_ioerror(bp, error, _RET_IP_);
  936. }
  937. void
  938. xfs_buf_ioerror_alert(
  939. struct xfs_buf *bp,
  940. const char *func)
  941. {
  942. xfs_alert(bp->b_target->bt_mount,
  943. "metadata I/O error: block 0x%llx (\"%s\") error %d numblks %d",
  944. (__uint64_t)XFS_BUF_ADDR(bp), func, -bp->b_error, bp->b_length);
  945. }
  946. int
  947. xfs_bwrite(
  948. struct xfs_buf *bp)
  949. {
  950. int error;
  951. ASSERT(xfs_buf_islocked(bp));
  952. bp->b_flags |= XBF_WRITE;
  953. bp->b_flags &= ~(XBF_ASYNC | XBF_READ | _XBF_DELWRI_Q |
  954. XBF_WRITE_FAIL | XBF_DONE);
  955. error = xfs_buf_submit_wait(bp);
  956. if (error) {
  957. xfs_force_shutdown(bp->b_target->bt_mount,
  958. SHUTDOWN_META_IO_ERROR);
  959. }
  960. return error;
  961. }
  962. STATIC void
  963. xfs_buf_bio_end_io(
  964. struct bio *bio)
  965. {
  966. xfs_buf_t *bp = (xfs_buf_t *)bio->bi_private;
  967. /*
  968. * don't overwrite existing errors - otherwise we can lose errors on
  969. * buffers that require multiple bios to complete.
  970. */
  971. if (bio->bi_error) {
  972. spin_lock(&bp->b_lock);
  973. if (!bp->b_io_error)
  974. bp->b_io_error = bio->bi_error;
  975. spin_unlock(&bp->b_lock);
  976. }
  977. if (!bp->b_error && xfs_buf_is_vmapped(bp) && (bp->b_flags & XBF_READ))
  978. invalidate_kernel_vmap_range(bp->b_addr, xfs_buf_vmap_len(bp));
  979. if (atomic_dec_and_test(&bp->b_io_remaining) == 1)
  980. xfs_buf_ioend_async(bp);
  981. bio_put(bio);
  982. }
  983. static void
  984. xfs_buf_ioapply_map(
  985. struct xfs_buf *bp,
  986. int map,
  987. int *buf_offset,
  988. int *count,
  989. int rw)
  990. {
  991. int page_index;
  992. int total_nr_pages = bp->b_page_count;
  993. int nr_pages;
  994. struct bio *bio;
  995. sector_t sector = bp->b_maps[map].bm_bn;
  996. int size;
  997. int offset;
  998. total_nr_pages = bp->b_page_count;
  999. /* skip the pages in the buffer before the start offset */
  1000. page_index = 0;
  1001. offset = *buf_offset;
  1002. while (offset >= PAGE_SIZE) {
  1003. page_index++;
  1004. offset -= PAGE_SIZE;
  1005. }
  1006. /*
  1007. * Limit the IO size to the length of the current vector, and update the
  1008. * remaining IO count for the next time around.
  1009. */
  1010. size = min_t(int, BBTOB(bp->b_maps[map].bm_len), *count);
  1011. *count -= size;
  1012. *buf_offset += size;
  1013. next_chunk:
  1014. atomic_inc(&bp->b_io_remaining);
  1015. nr_pages = BIO_MAX_SECTORS >> (PAGE_SHIFT - BBSHIFT);
  1016. if (nr_pages > total_nr_pages)
  1017. nr_pages = total_nr_pages;
  1018. bio = bio_alloc(GFP_NOIO, nr_pages);
  1019. bio->bi_bdev = bp->b_target->bt_bdev;
  1020. bio->bi_iter.bi_sector = sector;
  1021. bio->bi_end_io = xfs_buf_bio_end_io;
  1022. bio->bi_private = bp;
  1023. for (; size && nr_pages; nr_pages--, page_index++) {
  1024. int rbytes, nbytes = PAGE_SIZE - offset;
  1025. if (nbytes > size)
  1026. nbytes = size;
  1027. rbytes = bio_add_page(bio, bp->b_pages[page_index], nbytes,
  1028. offset);
  1029. if (rbytes < nbytes)
  1030. break;
  1031. offset = 0;
  1032. sector += BTOBB(nbytes);
  1033. size -= nbytes;
  1034. total_nr_pages--;
  1035. }
  1036. if (likely(bio->bi_iter.bi_size)) {
  1037. if (xfs_buf_is_vmapped(bp)) {
  1038. flush_kernel_vmap_range(bp->b_addr,
  1039. xfs_buf_vmap_len(bp));
  1040. }
  1041. submit_bio(rw, bio);
  1042. if (size)
  1043. goto next_chunk;
  1044. } else {
  1045. /*
  1046. * This is guaranteed not to be the last io reference count
  1047. * because the caller (xfs_buf_submit) holds a count itself.
  1048. */
  1049. atomic_dec(&bp->b_io_remaining);
  1050. xfs_buf_ioerror(bp, -EIO);
  1051. bio_put(bio);
  1052. }
  1053. }
  1054. STATIC void
  1055. _xfs_buf_ioapply(
  1056. struct xfs_buf *bp)
  1057. {
  1058. struct blk_plug plug;
  1059. int rw;
  1060. int offset;
  1061. int size;
  1062. int i;
  1063. /*
  1064. * Make sure we capture only current IO errors rather than stale errors
  1065. * left over from previous use of the buffer (e.g. failed readahead).
  1066. */
  1067. bp->b_error = 0;
  1068. /*
  1069. * Initialize the I/O completion workqueue if we haven't yet or the
  1070. * submitter has not opted to specify a custom one.
  1071. */
  1072. if (!bp->b_ioend_wq)
  1073. bp->b_ioend_wq = bp->b_target->bt_mount->m_buf_workqueue;
  1074. if (bp->b_flags & XBF_WRITE) {
  1075. if (bp->b_flags & XBF_SYNCIO)
  1076. rw = WRITE_SYNC;
  1077. else
  1078. rw = WRITE;
  1079. if (bp->b_flags & XBF_FUA)
  1080. rw |= REQ_FUA;
  1081. if (bp->b_flags & XBF_FLUSH)
  1082. rw |= REQ_FLUSH;
  1083. /*
  1084. * Run the write verifier callback function if it exists. If
  1085. * this function fails it will mark the buffer with an error and
  1086. * the IO should not be dispatched.
  1087. */
  1088. if (bp->b_ops) {
  1089. bp->b_ops->verify_write(bp);
  1090. if (bp->b_error) {
  1091. xfs_force_shutdown(bp->b_target->bt_mount,
  1092. SHUTDOWN_CORRUPT_INCORE);
  1093. return;
  1094. }
  1095. } else if (bp->b_bn != XFS_BUF_DADDR_NULL) {
  1096. struct xfs_mount *mp = bp->b_target->bt_mount;
  1097. /*
  1098. * non-crc filesystems don't attach verifiers during
  1099. * log recovery, so don't warn for such filesystems.
  1100. */
  1101. if (xfs_sb_version_hascrc(&mp->m_sb)) {
  1102. xfs_warn(mp,
  1103. "%s: no ops on block 0x%llx/0x%x",
  1104. __func__, bp->b_bn, bp->b_length);
  1105. xfs_hex_dump(bp->b_addr, 64);
  1106. dump_stack();
  1107. }
  1108. }
  1109. } else if (bp->b_flags & XBF_READ_AHEAD) {
  1110. rw = READA;
  1111. } else {
  1112. rw = READ;
  1113. }
  1114. /* we only use the buffer cache for meta-data */
  1115. rw |= REQ_META;
  1116. /*
  1117. * Walk all the vectors issuing IO on them. Set up the initial offset
  1118. * into the buffer and the desired IO size before we start -
  1119. * _xfs_buf_ioapply_vec() will modify them appropriately for each
  1120. * subsequent call.
  1121. */
  1122. offset = bp->b_offset;
  1123. size = BBTOB(bp->b_io_length);
  1124. blk_start_plug(&plug);
  1125. for (i = 0; i < bp->b_map_count; i++) {
  1126. xfs_buf_ioapply_map(bp, i, &offset, &size, rw);
  1127. if (bp->b_error)
  1128. break;
  1129. if (size <= 0)
  1130. break; /* all done */
  1131. }
  1132. blk_finish_plug(&plug);
  1133. }
  1134. /*
  1135. * Asynchronous IO submission path. This transfers the buffer lock ownership and
  1136. * the current reference to the IO. It is not safe to reference the buffer after
  1137. * a call to this function unless the caller holds an additional reference
  1138. * itself.
  1139. */
  1140. void
  1141. xfs_buf_submit(
  1142. struct xfs_buf *bp)
  1143. {
  1144. trace_xfs_buf_submit(bp, _RET_IP_);
  1145. ASSERT(!(bp->b_flags & _XBF_DELWRI_Q));
  1146. ASSERT(bp->b_flags & XBF_ASYNC);
  1147. /* on shutdown we stale and complete the buffer immediately */
  1148. if (XFS_FORCED_SHUTDOWN(bp->b_target->bt_mount)) {
  1149. xfs_buf_ioerror(bp, -EIO);
  1150. bp->b_flags &= ~XBF_DONE;
  1151. xfs_buf_stale(bp);
  1152. xfs_buf_ioend(bp);
  1153. return;
  1154. }
  1155. if (bp->b_flags & XBF_WRITE)
  1156. xfs_buf_wait_unpin(bp);
  1157. /* clear the internal error state to avoid spurious errors */
  1158. bp->b_io_error = 0;
  1159. /*
  1160. * The caller's reference is released during I/O completion.
  1161. * This occurs some time after the last b_io_remaining reference is
  1162. * released, so after we drop our Io reference we have to have some
  1163. * other reference to ensure the buffer doesn't go away from underneath
  1164. * us. Take a direct reference to ensure we have safe access to the
  1165. * buffer until we are finished with it.
  1166. */
  1167. xfs_buf_hold(bp);
  1168. /*
  1169. * Set the count to 1 initially, this will stop an I/O completion
  1170. * callout which happens before we have started all the I/O from calling
  1171. * xfs_buf_ioend too early.
  1172. */
  1173. atomic_set(&bp->b_io_remaining, 1);
  1174. _xfs_buf_ioapply(bp);
  1175. /*
  1176. * If _xfs_buf_ioapply failed, we can get back here with only the IO
  1177. * reference we took above. If we drop it to zero, run completion so
  1178. * that we don't return to the caller with completion still pending.
  1179. */
  1180. if (atomic_dec_and_test(&bp->b_io_remaining) == 1) {
  1181. if (bp->b_error)
  1182. xfs_buf_ioend(bp);
  1183. else
  1184. xfs_buf_ioend_async(bp);
  1185. }
  1186. xfs_buf_rele(bp);
  1187. /* Note: it is not safe to reference bp now we've dropped our ref */
  1188. }
  1189. /*
  1190. * Synchronous buffer IO submission path, read or write.
  1191. */
  1192. int
  1193. xfs_buf_submit_wait(
  1194. struct xfs_buf *bp)
  1195. {
  1196. int error;
  1197. trace_xfs_buf_submit_wait(bp, _RET_IP_);
  1198. ASSERT(!(bp->b_flags & (_XBF_DELWRI_Q | XBF_ASYNC)));
  1199. if (XFS_FORCED_SHUTDOWN(bp->b_target->bt_mount)) {
  1200. xfs_buf_ioerror(bp, -EIO);
  1201. xfs_buf_stale(bp);
  1202. bp->b_flags &= ~XBF_DONE;
  1203. return -EIO;
  1204. }
  1205. if (bp->b_flags & XBF_WRITE)
  1206. xfs_buf_wait_unpin(bp);
  1207. /* clear the internal error state to avoid spurious errors */
  1208. bp->b_io_error = 0;
  1209. /*
  1210. * For synchronous IO, the IO does not inherit the submitters reference
  1211. * count, nor the buffer lock. Hence we cannot release the reference we
  1212. * are about to take until we've waited for all IO completion to occur,
  1213. * including any xfs_buf_ioend_async() work that may be pending.
  1214. */
  1215. xfs_buf_hold(bp);
  1216. /*
  1217. * Set the count to 1 initially, this will stop an I/O completion
  1218. * callout which happens before we have started all the I/O from calling
  1219. * xfs_buf_ioend too early.
  1220. */
  1221. atomic_set(&bp->b_io_remaining, 1);
  1222. _xfs_buf_ioapply(bp);
  1223. /*
  1224. * make sure we run completion synchronously if it raced with us and is
  1225. * already complete.
  1226. */
  1227. if (atomic_dec_and_test(&bp->b_io_remaining) == 1)
  1228. xfs_buf_ioend(bp);
  1229. /* wait for completion before gathering the error from the buffer */
  1230. trace_xfs_buf_iowait(bp, _RET_IP_);
  1231. wait_for_completion(&bp->b_iowait);
  1232. trace_xfs_buf_iowait_done(bp, _RET_IP_);
  1233. error = bp->b_error;
  1234. /*
  1235. * all done now, we can release the hold that keeps the buffer
  1236. * referenced for the entire IO.
  1237. */
  1238. xfs_buf_rele(bp);
  1239. return error;
  1240. }
  1241. void *
  1242. xfs_buf_offset(
  1243. struct xfs_buf *bp,
  1244. size_t offset)
  1245. {
  1246. struct page *page;
  1247. if (bp->b_addr)
  1248. return bp->b_addr + offset;
  1249. offset += bp->b_offset;
  1250. page = bp->b_pages[offset >> PAGE_SHIFT];
  1251. return page_address(page) + (offset & (PAGE_SIZE-1));
  1252. }
  1253. /*
  1254. * Move data into or out of a buffer.
  1255. */
  1256. void
  1257. xfs_buf_iomove(
  1258. xfs_buf_t *bp, /* buffer to process */
  1259. size_t boff, /* starting buffer offset */
  1260. size_t bsize, /* length to copy */
  1261. void *data, /* data address */
  1262. xfs_buf_rw_t mode) /* read/write/zero flag */
  1263. {
  1264. size_t bend;
  1265. bend = boff + bsize;
  1266. while (boff < bend) {
  1267. struct page *page;
  1268. int page_index, page_offset, csize;
  1269. page_index = (boff + bp->b_offset) >> PAGE_SHIFT;
  1270. page_offset = (boff + bp->b_offset) & ~PAGE_MASK;
  1271. page = bp->b_pages[page_index];
  1272. csize = min_t(size_t, PAGE_SIZE - page_offset,
  1273. BBTOB(bp->b_io_length) - boff);
  1274. ASSERT((csize + page_offset) <= PAGE_SIZE);
  1275. switch (mode) {
  1276. case XBRW_ZERO:
  1277. memset(page_address(page) + page_offset, 0, csize);
  1278. break;
  1279. case XBRW_READ:
  1280. memcpy(data, page_address(page) + page_offset, csize);
  1281. break;
  1282. case XBRW_WRITE:
  1283. memcpy(page_address(page) + page_offset, data, csize);
  1284. }
  1285. boff += csize;
  1286. data += csize;
  1287. }
  1288. }
  1289. /*
  1290. * Handling of buffer targets (buftargs).
  1291. */
  1292. /*
  1293. * Wait for any bufs with callbacks that have been submitted but have not yet
  1294. * returned. These buffers will have an elevated hold count, so wait on those
  1295. * while freeing all the buffers only held by the LRU.
  1296. */
  1297. static enum lru_status
  1298. xfs_buftarg_wait_rele(
  1299. struct list_head *item,
  1300. struct list_lru_one *lru,
  1301. spinlock_t *lru_lock,
  1302. void *arg)
  1303. {
  1304. struct xfs_buf *bp = container_of(item, struct xfs_buf, b_lru);
  1305. struct list_head *dispose = arg;
  1306. if (atomic_read(&bp->b_hold) > 1) {
  1307. /* need to wait, so skip it this pass */
  1308. trace_xfs_buf_wait_buftarg(bp, _RET_IP_);
  1309. return LRU_SKIP;
  1310. }
  1311. if (!spin_trylock(&bp->b_lock))
  1312. return LRU_SKIP;
  1313. /*
  1314. * clear the LRU reference count so the buffer doesn't get
  1315. * ignored in xfs_buf_rele().
  1316. */
  1317. atomic_set(&bp->b_lru_ref, 0);
  1318. bp->b_state |= XFS_BSTATE_DISPOSE;
  1319. list_lru_isolate_move(lru, item, dispose);
  1320. spin_unlock(&bp->b_lock);
  1321. return LRU_REMOVED;
  1322. }
  1323. void
  1324. xfs_wait_buftarg(
  1325. struct xfs_buftarg *btp)
  1326. {
  1327. LIST_HEAD(dispose);
  1328. int loop = 0;
  1329. /*
  1330. * We need to flush the buffer workqueue to ensure that all IO
  1331. * completion processing is 100% done. Just waiting on buffer locks is
  1332. * not sufficient for async IO as the reference count held over IO is
  1333. * not released until after the buffer lock is dropped. Hence we need to
  1334. * ensure here that all reference counts have been dropped before we
  1335. * start walking the LRU list.
  1336. */
  1337. flush_workqueue(btp->bt_mount->m_buf_workqueue);
  1338. /* loop until there is nothing left on the lru list. */
  1339. while (list_lru_count(&btp->bt_lru)) {
  1340. list_lru_walk(&btp->bt_lru, xfs_buftarg_wait_rele,
  1341. &dispose, LONG_MAX);
  1342. while (!list_empty(&dispose)) {
  1343. struct xfs_buf *bp;
  1344. bp = list_first_entry(&dispose, struct xfs_buf, b_lru);
  1345. list_del_init(&bp->b_lru);
  1346. if (bp->b_flags & XBF_WRITE_FAIL) {
  1347. xfs_alert(btp->bt_mount,
  1348. "Corruption Alert: Buffer at block 0x%llx had permanent write failures!",
  1349. (long long)bp->b_bn);
  1350. xfs_alert(btp->bt_mount,
  1351. "Please run xfs_repair to determine the extent of the problem.");
  1352. }
  1353. xfs_buf_rele(bp);
  1354. }
  1355. if (loop++ != 0)
  1356. delay(100);
  1357. }
  1358. }
  1359. static enum lru_status
  1360. xfs_buftarg_isolate(
  1361. struct list_head *item,
  1362. struct list_lru_one *lru,
  1363. spinlock_t *lru_lock,
  1364. void *arg)
  1365. {
  1366. struct xfs_buf *bp = container_of(item, struct xfs_buf, b_lru);
  1367. struct list_head *dispose = arg;
  1368. /*
  1369. * we are inverting the lru lock/bp->b_lock here, so use a trylock.
  1370. * If we fail to get the lock, just skip it.
  1371. */
  1372. if (!spin_trylock(&bp->b_lock))
  1373. return LRU_SKIP;
  1374. /*
  1375. * Decrement the b_lru_ref count unless the value is already
  1376. * zero. If the value is already zero, we need to reclaim the
  1377. * buffer, otherwise it gets another trip through the LRU.
  1378. */
  1379. if (!atomic_add_unless(&bp->b_lru_ref, -1, 0)) {
  1380. spin_unlock(&bp->b_lock);
  1381. return LRU_ROTATE;
  1382. }
  1383. bp->b_state |= XFS_BSTATE_DISPOSE;
  1384. list_lru_isolate_move(lru, item, dispose);
  1385. spin_unlock(&bp->b_lock);
  1386. return LRU_REMOVED;
  1387. }
  1388. static unsigned long
  1389. xfs_buftarg_shrink_scan(
  1390. struct shrinker *shrink,
  1391. struct shrink_control *sc)
  1392. {
  1393. struct xfs_buftarg *btp = container_of(shrink,
  1394. struct xfs_buftarg, bt_shrinker);
  1395. LIST_HEAD(dispose);
  1396. unsigned long freed;
  1397. freed = list_lru_shrink_walk(&btp->bt_lru, sc,
  1398. xfs_buftarg_isolate, &dispose);
  1399. while (!list_empty(&dispose)) {
  1400. struct xfs_buf *bp;
  1401. bp = list_first_entry(&dispose, struct xfs_buf, b_lru);
  1402. list_del_init(&bp->b_lru);
  1403. xfs_buf_rele(bp);
  1404. }
  1405. return freed;
  1406. }
  1407. static unsigned long
  1408. xfs_buftarg_shrink_count(
  1409. struct shrinker *shrink,
  1410. struct shrink_control *sc)
  1411. {
  1412. struct xfs_buftarg *btp = container_of(shrink,
  1413. struct xfs_buftarg, bt_shrinker);
  1414. return list_lru_shrink_count(&btp->bt_lru, sc);
  1415. }
  1416. void
  1417. xfs_free_buftarg(
  1418. struct xfs_mount *mp,
  1419. struct xfs_buftarg *btp)
  1420. {
  1421. unregister_shrinker(&btp->bt_shrinker);
  1422. list_lru_destroy(&btp->bt_lru);
  1423. if (mp->m_flags & XFS_MOUNT_BARRIER)
  1424. xfs_blkdev_issue_flush(btp);
  1425. kmem_free(btp);
  1426. }
  1427. int
  1428. xfs_setsize_buftarg(
  1429. xfs_buftarg_t *btp,
  1430. unsigned int sectorsize)
  1431. {
  1432. /* Set up metadata sector size info */
  1433. btp->bt_meta_sectorsize = sectorsize;
  1434. btp->bt_meta_sectormask = sectorsize - 1;
  1435. if (set_blocksize(btp->bt_bdev, sectorsize)) {
  1436. char name[BDEVNAME_SIZE];
  1437. bdevname(btp->bt_bdev, name);
  1438. xfs_warn(btp->bt_mount,
  1439. "Cannot set_blocksize to %u on device %s",
  1440. sectorsize, name);
  1441. return -EINVAL;
  1442. }
  1443. /* Set up device logical sector size mask */
  1444. btp->bt_logical_sectorsize = bdev_logical_block_size(btp->bt_bdev);
  1445. btp->bt_logical_sectormask = bdev_logical_block_size(btp->bt_bdev) - 1;
  1446. return 0;
  1447. }
  1448. /*
  1449. * When allocating the initial buffer target we have not yet
  1450. * read in the superblock, so don't know what sized sectors
  1451. * are being used at this early stage. Play safe.
  1452. */
  1453. STATIC int
  1454. xfs_setsize_buftarg_early(
  1455. xfs_buftarg_t *btp,
  1456. struct block_device *bdev)
  1457. {
  1458. return xfs_setsize_buftarg(btp, bdev_logical_block_size(bdev));
  1459. }
  1460. xfs_buftarg_t *
  1461. xfs_alloc_buftarg(
  1462. struct xfs_mount *mp,
  1463. struct block_device *bdev)
  1464. {
  1465. xfs_buftarg_t *btp;
  1466. btp = kmem_zalloc(sizeof(*btp), KM_SLEEP | KM_NOFS);
  1467. btp->bt_mount = mp;
  1468. btp->bt_dev = bdev->bd_dev;
  1469. btp->bt_bdev = bdev;
  1470. btp->bt_bdi = blk_get_backing_dev_info(bdev);
  1471. if (xfs_setsize_buftarg_early(btp, bdev))
  1472. goto error;
  1473. if (list_lru_init(&btp->bt_lru))
  1474. goto error;
  1475. btp->bt_shrinker.count_objects = xfs_buftarg_shrink_count;
  1476. btp->bt_shrinker.scan_objects = xfs_buftarg_shrink_scan;
  1477. btp->bt_shrinker.seeks = DEFAULT_SEEKS;
  1478. btp->bt_shrinker.flags = SHRINKER_NUMA_AWARE;
  1479. register_shrinker(&btp->bt_shrinker);
  1480. return btp;
  1481. error:
  1482. kmem_free(btp);
  1483. return NULL;
  1484. }
  1485. /*
  1486. * Cancel a delayed write list.
  1487. *
  1488. * Remove each buffer from the list, clear the delwri queue flag and drop the
  1489. * associated buffer reference.
  1490. */
  1491. void
  1492. xfs_buf_delwri_cancel(
  1493. struct list_head *list)
  1494. {
  1495. struct xfs_buf *bp;
  1496. while (!list_empty(list)) {
  1497. bp = list_first_entry(list, struct xfs_buf, b_list);
  1498. xfs_buf_lock(bp);
  1499. bp->b_flags &= ~_XBF_DELWRI_Q;
  1500. list_del_init(&bp->b_list);
  1501. xfs_buf_relse(bp);
  1502. }
  1503. }
  1504. /*
  1505. * Add a buffer to the delayed write list.
  1506. *
  1507. * This queues a buffer for writeout if it hasn't already been. Note that
  1508. * neither this routine nor the buffer list submission functions perform
  1509. * any internal synchronization. It is expected that the lists are thread-local
  1510. * to the callers.
  1511. *
  1512. * Returns true if we queued up the buffer, or false if it already had
  1513. * been on the buffer list.
  1514. */
  1515. bool
  1516. xfs_buf_delwri_queue(
  1517. struct xfs_buf *bp,
  1518. struct list_head *list)
  1519. {
  1520. ASSERT(xfs_buf_islocked(bp));
  1521. ASSERT(!(bp->b_flags & XBF_READ));
  1522. /*
  1523. * If the buffer is already marked delwri it already is queued up
  1524. * by someone else for imediate writeout. Just ignore it in that
  1525. * case.
  1526. */
  1527. if (bp->b_flags & _XBF_DELWRI_Q) {
  1528. trace_xfs_buf_delwri_queued(bp, _RET_IP_);
  1529. return false;
  1530. }
  1531. trace_xfs_buf_delwri_queue(bp, _RET_IP_);
  1532. /*
  1533. * If a buffer gets written out synchronously or marked stale while it
  1534. * is on a delwri list we lazily remove it. To do this, the other party
  1535. * clears the _XBF_DELWRI_Q flag but otherwise leaves the buffer alone.
  1536. * It remains referenced and on the list. In a rare corner case it
  1537. * might get readded to a delwri list after the synchronous writeout, in
  1538. * which case we need just need to re-add the flag here.
  1539. */
  1540. bp->b_flags |= _XBF_DELWRI_Q;
  1541. if (list_empty(&bp->b_list)) {
  1542. atomic_inc(&bp->b_hold);
  1543. list_add_tail(&bp->b_list, list);
  1544. }
  1545. return true;
  1546. }
  1547. /*
  1548. * Compare function is more complex than it needs to be because
  1549. * the return value is only 32 bits and we are doing comparisons
  1550. * on 64 bit values
  1551. */
  1552. static int
  1553. xfs_buf_cmp(
  1554. void *priv,
  1555. struct list_head *a,
  1556. struct list_head *b)
  1557. {
  1558. struct xfs_buf *ap = container_of(a, struct xfs_buf, b_list);
  1559. struct xfs_buf *bp = container_of(b, struct xfs_buf, b_list);
  1560. xfs_daddr_t diff;
  1561. diff = ap->b_maps[0].bm_bn - bp->b_maps[0].bm_bn;
  1562. if (diff < 0)
  1563. return -1;
  1564. if (diff > 0)
  1565. return 1;
  1566. return 0;
  1567. }
  1568. static int
  1569. __xfs_buf_delwri_submit(
  1570. struct list_head *buffer_list,
  1571. struct list_head *io_list,
  1572. bool wait)
  1573. {
  1574. struct blk_plug plug;
  1575. struct xfs_buf *bp, *n;
  1576. int pinned = 0;
  1577. list_for_each_entry_safe(bp, n, buffer_list, b_list) {
  1578. if (!wait) {
  1579. if (xfs_buf_ispinned(bp)) {
  1580. pinned++;
  1581. continue;
  1582. }
  1583. if (!xfs_buf_trylock(bp))
  1584. continue;
  1585. } else {
  1586. xfs_buf_lock(bp);
  1587. }
  1588. /*
  1589. * Someone else might have written the buffer synchronously or
  1590. * marked it stale in the meantime. In that case only the
  1591. * _XBF_DELWRI_Q flag got cleared, and we have to drop the
  1592. * reference and remove it from the list here.
  1593. */
  1594. if (!(bp->b_flags & _XBF_DELWRI_Q)) {
  1595. list_del_init(&bp->b_list);
  1596. xfs_buf_relse(bp);
  1597. continue;
  1598. }
  1599. list_move_tail(&bp->b_list, io_list);
  1600. trace_xfs_buf_delwri_split(bp, _RET_IP_);
  1601. }
  1602. list_sort(NULL, io_list, xfs_buf_cmp);
  1603. blk_start_plug(&plug);
  1604. list_for_each_entry_safe(bp, n, io_list, b_list) {
  1605. bp->b_flags &= ~(_XBF_DELWRI_Q | XBF_ASYNC | XBF_WRITE_FAIL);
  1606. bp->b_flags |= XBF_WRITE | XBF_ASYNC;
  1607. /*
  1608. * we do all Io submission async. This means if we need to wait
  1609. * for IO completion we need to take an extra reference so the
  1610. * buffer is still valid on the other side.
  1611. */
  1612. if (wait)
  1613. xfs_buf_hold(bp);
  1614. else
  1615. list_del_init(&bp->b_list);
  1616. xfs_buf_submit(bp);
  1617. }
  1618. blk_finish_plug(&plug);
  1619. return pinned;
  1620. }
  1621. /*
  1622. * Write out a buffer list asynchronously.
  1623. *
  1624. * This will take the @buffer_list, write all non-locked and non-pinned buffers
  1625. * out and not wait for I/O completion on any of the buffers. This interface
  1626. * is only safely useable for callers that can track I/O completion by higher
  1627. * level means, e.g. AIL pushing as the @buffer_list is consumed in this
  1628. * function.
  1629. */
  1630. int
  1631. xfs_buf_delwri_submit_nowait(
  1632. struct list_head *buffer_list)
  1633. {
  1634. LIST_HEAD (io_list);
  1635. return __xfs_buf_delwri_submit(buffer_list, &io_list, false);
  1636. }
  1637. /*
  1638. * Write out a buffer list synchronously.
  1639. *
  1640. * This will take the @buffer_list, write all buffers out and wait for I/O
  1641. * completion on all of the buffers. @buffer_list is consumed by the function,
  1642. * so callers must have some other way of tracking buffers if they require such
  1643. * functionality.
  1644. */
  1645. int
  1646. xfs_buf_delwri_submit(
  1647. struct list_head *buffer_list)
  1648. {
  1649. LIST_HEAD (io_list);
  1650. int error = 0, error2;
  1651. struct xfs_buf *bp;
  1652. __xfs_buf_delwri_submit(buffer_list, &io_list, true);
  1653. /* Wait for IO to complete. */
  1654. while (!list_empty(&io_list)) {
  1655. bp = list_first_entry(&io_list, struct xfs_buf, b_list);
  1656. list_del_init(&bp->b_list);
  1657. /* locking the buffer will wait for async IO completion. */
  1658. xfs_buf_lock(bp);
  1659. error2 = bp->b_error;
  1660. xfs_buf_relse(bp);
  1661. if (!error)
  1662. error = error2;
  1663. }
  1664. return error;
  1665. }
  1666. int __init
  1667. xfs_buf_init(void)
  1668. {
  1669. xfs_buf_zone = kmem_zone_init_flags(sizeof(xfs_buf_t), "xfs_buf",
  1670. KM_ZONE_HWALIGN, NULL);
  1671. if (!xfs_buf_zone)
  1672. goto out;
  1673. return 0;
  1674. out:
  1675. return -ENOMEM;
  1676. }
  1677. void
  1678. xfs_buf_terminate(void)
  1679. {
  1680. kmem_zone_destroy(xfs_buf_zone);
  1681. }