2 * Copyright (c) 2000-2006 Silicon Graphics, Inc.
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.
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.
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
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 <linux/list_sort.h>
42 #include "xfs_mount.h"
43 #include "xfs_trace.h"
45 static kmem_zone_t *xfs_buf_zone;
46 STATIC int xfsbufd(void *);
47 STATIC void xfs_buf_delwri_queue(xfs_buf_t *, int);
49 static struct workqueue_struct *xfslogd_workqueue;
50 struct workqueue_struct *xfsdatad_workqueue;
51 struct workqueue_struct *xfsconvertd_workqueue;
53 #ifdef XFS_BUF_LOCK_TRACKING
54 # define XB_SET_OWNER(bp) ((bp)->b_last_holder = current->pid)
55 # define XB_CLEAR_OWNER(bp) ((bp)->b_last_holder = -1)
56 # define XB_GET_OWNER(bp) ((bp)->b_last_holder)
58 # define XB_SET_OWNER(bp) do { } while (0)
59 # define XB_CLEAR_OWNER(bp) do { } while (0)
60 # define XB_GET_OWNER(bp) do { } while (0)
63 #define xb_to_gfp(flags) \
64 ((((flags) & XBF_READ_AHEAD) ? __GFP_NORETRY : \
65 ((flags) & XBF_DONT_BLOCK) ? GFP_NOFS : GFP_KERNEL) | __GFP_NOWARN)
67 #define xb_to_km(flags) \
68 (((flags) & XBF_DONT_BLOCK) ? KM_NOFS : KM_SLEEP)
70 #define xfs_buf_allocate(flags) \
71 kmem_zone_alloc(xfs_buf_zone, xb_to_km(flags))
72 #define xfs_buf_deallocate(bp) \
73 kmem_zone_free(xfs_buf_zone, (bp));
80 * Return true if the buffer is vmapped.
82 * The XBF_MAPPED flag is set if the buffer should be mapped, but the
83 * code is clever enough to know it doesn't have to map a single page,
84 * so the check has to be both for XBF_MAPPED and bp->b_page_count > 1.
86 return (bp->b_flags & XBF_MAPPED) && bp->b_page_count > 1;
93 return (bp->b_page_count * PAGE_SIZE) - bp->b_offset;
97 * Page Region interfaces.
99 * For pages in filesystems where the blocksize is smaller than the
100 * pagesize, we use the page->private field (long) to hold a bitmap
101 * of uptodate regions within the page.
103 * Each such region is "bytes per page / bits per long" bytes long.
105 * NBPPR == number-of-bytes-per-page-region
106 * BTOPR == bytes-to-page-region (rounded up)
107 * BTOPRT == bytes-to-page-region-truncated (rounded down)
109 #if (BITS_PER_LONG == 32)
110 #define PRSHIFT (PAGE_CACHE_SHIFT - 5) /* (32 == 1<<5) */
111 #elif (BITS_PER_LONG == 64)
112 #define PRSHIFT (PAGE_CACHE_SHIFT - 6) /* (64 == 1<<6) */
114 #error BITS_PER_LONG must be 32 or 64
116 #define NBPPR (PAGE_CACHE_SIZE/BITS_PER_LONG)
117 #define BTOPR(b) (((unsigned int)(b) + (NBPPR - 1)) >> PRSHIFT)
118 #define BTOPRT(b) (((unsigned int)(b) >> PRSHIFT))
128 first = BTOPR(offset);
129 final = BTOPRT(offset + length - 1);
130 first = min(first, final);
133 mask <<= BITS_PER_LONG - (final - first);
134 mask >>= BITS_PER_LONG - (final);
136 ASSERT(offset + length <= PAGE_CACHE_SIZE);
137 ASSERT((final - first) < BITS_PER_LONG && (final - first) >= 0);
148 set_page_private(page,
149 page_private(page) | page_region_mask(offset, length));
150 if (page_private(page) == ~0UL)
151 SetPageUptodate(page);
160 unsigned long mask = page_region_mask(offset, length);
162 return (mask && (page_private(page) & mask) == mask);
166 * Internal xfs_buf_t object manipulation
172 xfs_buftarg_t *target,
173 xfs_off_t range_base,
175 xfs_buf_flags_t flags)
178 * We don't want certain flags to appear in b_flags.
180 flags &= ~(XBF_LOCK|XBF_MAPPED|XBF_DONT_BLOCK|XBF_READ_AHEAD);
182 memset(bp, 0, sizeof(xfs_buf_t));
183 atomic_set(&bp->b_hold, 1);
184 init_completion(&bp->b_iowait);
185 INIT_LIST_HEAD(&bp->b_list);
186 RB_CLEAR_NODE(&bp->b_rbnode);
187 sema_init(&bp->b_sema, 0); /* held, no waiters */
189 bp->b_target = target;
190 bp->b_file_offset = range_base;
192 * Set buffer_length and count_desired to the same value initially.
193 * I/O routines should use count_desired, which will be the same in
194 * most cases but may be reset (e.g. XFS recovery).
196 bp->b_buffer_length = bp->b_count_desired = range_length;
198 bp->b_bn = XFS_BUF_DADDR_NULL;
199 atomic_set(&bp->b_pin_count, 0);
200 init_waitqueue_head(&bp->b_waiters);
202 XFS_STATS_INC(xb_create);
204 trace_xfs_buf_init(bp, _RET_IP_);
208 * Allocate a page array capable of holding a specified number
209 * of pages, and point the page buf at it.
215 xfs_buf_flags_t flags)
217 /* Make sure that we have a page list */
218 if (bp->b_pages == NULL) {
219 bp->b_offset = xfs_buf_poff(bp->b_file_offset);
220 bp->b_page_count = page_count;
221 if (page_count <= XB_PAGES) {
222 bp->b_pages = bp->b_page_array;
224 bp->b_pages = kmem_alloc(sizeof(struct page *) *
225 page_count, xb_to_km(flags));
226 if (bp->b_pages == NULL)
229 memset(bp->b_pages, 0, sizeof(struct page *) * page_count);
235 * Frees b_pages if it was allocated.
241 if (bp->b_pages != bp->b_page_array) {
242 kmem_free(bp->b_pages);
248 * Releases the specified buffer.
250 * The modification state of any associated pages is left unchanged.
251 * The buffer most not be on any hash - use xfs_buf_rele instead for
252 * hashed and refcounted buffers
258 trace_xfs_buf_free(bp, _RET_IP_);
260 if (bp->b_flags & (_XBF_PAGE_CACHE|_XBF_PAGES)) {
263 if (xfs_buf_is_vmapped(bp))
264 vm_unmap_ram(bp->b_addr - bp->b_offset,
267 for (i = 0; i < bp->b_page_count; i++) {
268 struct page *page = bp->b_pages[i];
270 if (bp->b_flags & _XBF_PAGE_CACHE)
271 ASSERT(!PagePrivate(page));
272 page_cache_release(page);
275 _xfs_buf_free_pages(bp);
276 xfs_buf_deallocate(bp);
280 * Finds all pages for buffer in question and builds it's page list.
283 _xfs_buf_lookup_pages(
287 struct address_space *mapping = bp->b_target->bt_mapping;
288 size_t blocksize = bp->b_target->bt_bsize;
289 size_t size = bp->b_count_desired;
290 size_t nbytes, offset;
291 gfp_t gfp_mask = xb_to_gfp(flags);
292 unsigned short page_count, i;
297 end = bp->b_file_offset + bp->b_buffer_length;
298 page_count = xfs_buf_btoc(end) - xfs_buf_btoct(bp->b_file_offset);
300 error = _xfs_buf_get_pages(bp, page_count, flags);
303 bp->b_flags |= _XBF_PAGE_CACHE;
305 offset = bp->b_offset;
306 first = bp->b_file_offset >> PAGE_CACHE_SHIFT;
308 for (i = 0; i < bp->b_page_count; i++) {
313 page = find_or_create_page(mapping, first + i, gfp_mask);
314 if (unlikely(page == NULL)) {
315 if (flags & XBF_READ_AHEAD) {
316 bp->b_page_count = i;
317 for (i = 0; i < bp->b_page_count; i++)
318 unlock_page(bp->b_pages[i]);
323 * This could deadlock.
325 * But until all the XFS lowlevel code is revamped to
326 * handle buffer allocation failures we can't do much.
328 if (!(++retries % 100))
330 "XFS: possible memory allocation "
331 "deadlock in %s (mode:0x%x)\n",
334 XFS_STATS_INC(xb_page_retries);
335 congestion_wait(BLK_RW_ASYNC, HZ/50);
339 XFS_STATS_INC(xb_page_found);
341 nbytes = min_t(size_t, size, PAGE_CACHE_SIZE - offset);
344 ASSERT(!PagePrivate(page));
345 if (!PageUptodate(page)) {
347 if (blocksize >= PAGE_CACHE_SIZE) {
348 if (flags & XBF_READ)
349 bp->b_flags |= _XBF_PAGE_LOCKED;
350 } else if (!PagePrivate(page)) {
351 if (test_page_region(page, offset, nbytes))
356 bp->b_pages[i] = page;
360 if (!(bp->b_flags & _XBF_PAGE_LOCKED)) {
361 for (i = 0; i < bp->b_page_count; i++)
362 unlock_page(bp->b_pages[i]);
365 if (page_count == bp->b_page_count)
366 bp->b_flags |= XBF_DONE;
372 * Map buffer into kernel address-space if nessecary.
379 /* A single page buffer is always mappable */
380 if (bp->b_page_count == 1) {
381 bp->b_addr = page_address(bp->b_pages[0]) + bp->b_offset;
382 bp->b_flags |= XBF_MAPPED;
383 } else if (flags & XBF_MAPPED) {
384 bp->b_addr = vm_map_ram(bp->b_pages, bp->b_page_count,
386 if (unlikely(bp->b_addr == NULL))
388 bp->b_addr += bp->b_offset;
389 bp->b_flags |= XBF_MAPPED;
396 * Finding and Reading Buffers
400 * Look up, and creates if absent, a lockable buffer for
401 * a given range of an inode. The buffer is returned
402 * locked. If other overlapping buffers exist, they are
403 * released before the new buffer is created and locked,
404 * which may imply that this call will block until those buffers
405 * are unlocked. No I/O is implied by this call.
409 xfs_buftarg_t *btp, /* block device target */
410 xfs_off_t ioff, /* starting offset of range */
411 size_t isize, /* length of range */
412 xfs_buf_flags_t flags,
415 xfs_off_t range_base;
417 struct xfs_perag *pag;
418 struct rb_node **rbp;
419 struct rb_node *parent;
422 range_base = (ioff << BBSHIFT);
423 range_length = (isize << BBSHIFT);
425 /* Check for IOs smaller than the sector size / not sector aligned */
426 ASSERT(!(range_length < (1 << btp->bt_sshift)));
427 ASSERT(!(range_base & (xfs_off_t)btp->bt_smask));
430 pag = xfs_perag_get(btp->bt_mount,
431 xfs_daddr_to_agno(btp->bt_mount, ioff));
434 spin_lock(&pag->pag_buf_lock);
435 rbp = &pag->pag_buf_tree.rb_node;
440 bp = rb_entry(parent, struct xfs_buf, b_rbnode);
442 if (range_base < bp->b_file_offset)
443 rbp = &(*rbp)->rb_left;
444 else if (range_base > bp->b_file_offset)
445 rbp = &(*rbp)->rb_right;
448 * found a block offset match. If the range doesn't
449 * match, the only way this is allowed is if the buffer
450 * in the cache is stale and the transaction that made
451 * it stale has not yet committed. i.e. we are
452 * reallocating a busy extent. Skip this buffer and
453 * continue searching to the right for an exact match.
455 if (bp->b_buffer_length != range_length) {
456 ASSERT(bp->b_flags & XBF_STALE);
457 rbp = &(*rbp)->rb_right;
460 atomic_inc(&bp->b_hold);
467 _xfs_buf_initialize(new_bp, btp, range_base,
468 range_length, flags);
469 rb_link_node(&new_bp->b_rbnode, parent, rbp);
470 rb_insert_color(&new_bp->b_rbnode, &pag->pag_buf_tree);
471 /* the buffer keeps the perag reference until it is freed */
473 spin_unlock(&pag->pag_buf_lock);
475 XFS_STATS_INC(xb_miss_locked);
476 spin_unlock(&pag->pag_buf_lock);
482 spin_unlock(&pag->pag_buf_lock);
485 if (xfs_buf_cond_lock(bp)) {
486 /* failed, so wait for the lock if requested. */
487 if (!(flags & XBF_TRYLOCK)) {
489 XFS_STATS_INC(xb_get_locked_waited);
492 XFS_STATS_INC(xb_busy_locked);
497 if (bp->b_flags & XBF_STALE) {
498 ASSERT((bp->b_flags & _XBF_DELWRI_Q) == 0);
499 bp->b_flags &= XBF_MAPPED;
502 trace_xfs_buf_find(bp, flags, _RET_IP_);
503 XFS_STATS_INC(xb_get_locked);
508 * Assembles a buffer covering the specified range.
509 * Storage in memory for all portions of the buffer will be allocated,
510 * although backing storage may not be.
514 xfs_buftarg_t *target,/* target for buffer */
515 xfs_off_t ioff, /* starting offset of range */
516 size_t isize, /* length of range */
517 xfs_buf_flags_t flags)
519 xfs_buf_t *bp, *new_bp;
522 new_bp = xfs_buf_allocate(flags);
523 if (unlikely(!new_bp))
526 bp = _xfs_buf_find(target, ioff, isize, flags, new_bp);
528 error = _xfs_buf_lookup_pages(bp, flags);
532 xfs_buf_deallocate(new_bp);
533 if (unlikely(bp == NULL))
537 for (i = 0; i < bp->b_page_count; i++)
538 mark_page_accessed(bp->b_pages[i]);
540 if (!(bp->b_flags & XBF_MAPPED)) {
541 error = _xfs_buf_map_pages(bp, flags);
542 if (unlikely(error)) {
543 printk(KERN_WARNING "%s: failed to map pages\n",
549 XFS_STATS_INC(xb_get);
552 * Always fill in the block number now, the mapped cases can do
553 * their own overlay of this later.
556 bp->b_count_desired = bp->b_buffer_length;
558 trace_xfs_buf_get(bp, flags, _RET_IP_);
562 if (flags & (XBF_LOCK | XBF_TRYLOCK))
571 xfs_buf_flags_t flags)
575 ASSERT(!(flags & (XBF_DELWRI|XBF_WRITE)));
576 ASSERT(bp->b_bn != XFS_BUF_DADDR_NULL);
578 bp->b_flags &= ~(XBF_WRITE | XBF_ASYNC | XBF_DELWRI | \
579 XBF_READ_AHEAD | _XBF_RUN_QUEUES);
580 bp->b_flags |= flags & (XBF_READ | XBF_ASYNC | \
581 XBF_READ_AHEAD | _XBF_RUN_QUEUES);
583 status = xfs_buf_iorequest(bp);
584 if (status || XFS_BUF_ISERROR(bp) || (flags & XBF_ASYNC))
586 return xfs_buf_iowait(bp);
591 xfs_buftarg_t *target,
594 xfs_buf_flags_t flags)
600 bp = xfs_buf_get(target, ioff, isize, flags);
602 trace_xfs_buf_read(bp, flags, _RET_IP_);
604 if (!XFS_BUF_ISDONE(bp)) {
605 XFS_STATS_INC(xb_get_read);
606 _xfs_buf_read(bp, flags);
607 } else if (flags & XBF_ASYNC) {
609 * Read ahead call which is already satisfied,
614 /* We do not want read in the flags */
615 bp->b_flags &= ~XBF_READ;
622 if (flags & (XBF_LOCK | XBF_TRYLOCK))
629 * If we are not low on memory then do the readahead in a deadlock
634 xfs_buftarg_t *target,
638 struct backing_dev_info *bdi;
640 bdi = target->bt_mapping->backing_dev_info;
641 if (bdi_read_congested(bdi))
644 xfs_buf_read(target, ioff, isize,
645 XBF_TRYLOCK|XBF_ASYNC|XBF_READ_AHEAD|XBF_DONT_BLOCK);
649 * Read an uncached buffer from disk. Allocates and returns a locked
650 * buffer containing the disk contents or nothing.
653 xfs_buf_read_uncached(
654 struct xfs_mount *mp,
655 struct xfs_buftarg *target,
663 bp = xfs_buf_get_uncached(target, length, flags);
667 /* set up the buffer for a read IO */
669 XFS_BUF_SET_ADDR(bp, daddr);
674 error = xfs_buf_iowait(bp);
675 if (error || bp->b_error) {
685 xfs_buftarg_t *target)
689 bp = xfs_buf_allocate(0);
691 _xfs_buf_initialize(bp, target, 0, len, 0);
695 static inline struct page *
699 if ((!is_vmalloc_addr(addr))) {
700 return virt_to_page(addr);
702 return vmalloc_to_page(addr);
707 xfs_buf_associate_memory(
714 unsigned long pageaddr;
715 unsigned long offset;
719 pageaddr = (unsigned long)mem & PAGE_CACHE_MASK;
720 offset = (unsigned long)mem - pageaddr;
721 buflen = PAGE_CACHE_ALIGN(len + offset);
722 page_count = buflen >> PAGE_CACHE_SHIFT;
724 /* Free any previous set of page pointers */
726 _xfs_buf_free_pages(bp);
731 rval = _xfs_buf_get_pages(bp, page_count, XBF_DONT_BLOCK);
735 bp->b_offset = offset;
737 for (i = 0; i < bp->b_page_count; i++) {
738 bp->b_pages[i] = mem_to_page((void *)pageaddr);
739 pageaddr += PAGE_CACHE_SIZE;
742 bp->b_count_desired = len;
743 bp->b_buffer_length = buflen;
744 bp->b_flags |= XBF_MAPPED;
745 bp->b_flags &= ~_XBF_PAGE_LOCKED;
751 xfs_buf_get_uncached(
752 struct xfs_buftarg *target,
756 unsigned long page_count = PAGE_ALIGN(len) >> PAGE_SHIFT;
760 bp = xfs_buf_allocate(0);
761 if (unlikely(bp == NULL))
763 _xfs_buf_initialize(bp, target, 0, len, 0);
765 error = _xfs_buf_get_pages(bp, page_count, 0);
769 for (i = 0; i < page_count; i++) {
770 bp->b_pages[i] = alloc_page(xb_to_gfp(flags));
774 bp->b_flags |= _XBF_PAGES;
776 error = _xfs_buf_map_pages(bp, XBF_MAPPED);
777 if (unlikely(error)) {
778 printk(KERN_WARNING "%s: failed to map pages\n",
785 trace_xfs_buf_get_uncached(bp, _RET_IP_);
790 __free_page(bp->b_pages[i]);
791 _xfs_buf_free_pages(bp);
793 xfs_buf_deallocate(bp);
799 * Increment reference count on buffer, to hold the buffer concurrently
800 * with another thread which may release (free) the buffer asynchronously.
801 * Must hold the buffer already to call this function.
807 trace_xfs_buf_hold(bp, _RET_IP_);
808 atomic_inc(&bp->b_hold);
812 * Releases a hold on the specified buffer. If the
813 * the hold count is 1, calls xfs_buf_free.
819 struct xfs_perag *pag = bp->b_pag;
821 trace_xfs_buf_rele(bp, _RET_IP_);
824 ASSERT(!bp->b_relse);
825 ASSERT(RB_EMPTY_NODE(&bp->b_rbnode));
826 if (atomic_dec_and_test(&bp->b_hold))
831 ASSERT(!RB_EMPTY_NODE(&bp->b_rbnode));
832 ASSERT(atomic_read(&bp->b_hold) > 0);
833 if (atomic_dec_and_lock(&bp->b_hold, &pag->pag_buf_lock)) {
835 atomic_inc(&bp->b_hold);
836 spin_unlock(&pag->pag_buf_lock);
839 ASSERT(!(bp->b_flags & (XBF_DELWRI|_XBF_DELWRI_Q)));
840 rb_erase(&bp->b_rbnode, &pag->pag_buf_tree);
841 spin_unlock(&pag->pag_buf_lock);
850 * Mutual exclusion on buffers. Locking model:
852 * Buffers associated with inodes for which buffer locking
853 * is not enabled are not protected by semaphores, and are
854 * assumed to be exclusively owned by the caller. There is a
855 * spinlock in the buffer, used by the caller when concurrent
856 * access is possible.
860 * Locks a buffer object, if it is not already locked. Note that this in
861 * no way locks the underlying pages, so it is only useful for
862 * synchronizing concurrent use of buffer objects, not for synchronizing
863 * independent access to the underlying pages.
865 * If we come across a stale, pinned, locked buffer, we know that we are
866 * being asked to lock a buffer that has been reallocated. Because it is
867 * pinned, we know that the log has not been pushed to disk and hence it
868 * will still be locked. Rather than continuing to have trylock attempts
869 * fail until someone else pushes the log, push it ourselves before
870 * returning. This means that the xfsaild will not get stuck trying
871 * to push on stale inode buffers.
879 locked = down_trylock(&bp->b_sema) == 0;
882 else if (atomic_read(&bp->b_pin_count) && (bp->b_flags & XBF_STALE))
883 xfs_log_force(bp->b_target->bt_mount, 0);
885 trace_xfs_buf_cond_lock(bp, _RET_IP_);
886 return locked ? 0 : -EBUSY;
893 return bp->b_sema.count;
897 * Locks a buffer object.
898 * Note that this in no way locks the underlying pages, so it is only
899 * useful for synchronizing concurrent use of buffer objects, not for
900 * synchronizing independent access to the underlying pages.
902 * If we come across a stale, pinned, locked buffer, we know that we
903 * are being asked to lock a buffer that has been reallocated. Because
904 * it is pinned, we know that the log has not been pushed to disk and
905 * hence it will still be locked. Rather than sleeping until someone
906 * else pushes the log, push it ourselves before trying to get the lock.
912 trace_xfs_buf_lock(bp, _RET_IP_);
914 if (atomic_read(&bp->b_pin_count) && (bp->b_flags & XBF_STALE))
915 xfs_log_force(bp->b_target->bt_mount, 0);
916 if (atomic_read(&bp->b_io_remaining))
917 blk_run_address_space(bp->b_target->bt_mapping);
921 trace_xfs_buf_lock_done(bp, _RET_IP_);
925 * Releases the lock on the buffer object.
926 * If the buffer is marked delwri but is not queued, do so before we
927 * unlock the buffer as we need to set flags correctly. We also need to
928 * take a reference for the delwri queue because the unlocker is going to
929 * drop their's and they don't know we just queued it.
935 if ((bp->b_flags & (XBF_DELWRI|_XBF_DELWRI_Q)) == XBF_DELWRI) {
936 atomic_inc(&bp->b_hold);
937 bp->b_flags |= XBF_ASYNC;
938 xfs_buf_delwri_queue(bp, 0);
944 trace_xfs_buf_unlock(bp, _RET_IP_);
951 DECLARE_WAITQUEUE (wait, current);
953 if (atomic_read(&bp->b_pin_count) == 0)
956 add_wait_queue(&bp->b_waiters, &wait);
958 set_current_state(TASK_UNINTERRUPTIBLE);
959 if (atomic_read(&bp->b_pin_count) == 0)
961 if (atomic_read(&bp->b_io_remaining))
962 blk_run_address_space(bp->b_target->bt_mapping);
965 remove_wait_queue(&bp->b_waiters, &wait);
966 set_current_state(TASK_RUNNING);
970 * Buffer Utility Routines
975 struct work_struct *work)
978 container_of(work, xfs_buf_t, b_iodone_work);
981 (*(bp->b_iodone))(bp);
982 else if (bp->b_flags & XBF_ASYNC)
991 trace_xfs_buf_iodone(bp, _RET_IP_);
993 bp->b_flags &= ~(XBF_READ | XBF_WRITE | XBF_READ_AHEAD);
994 if (bp->b_error == 0)
995 bp->b_flags |= XBF_DONE;
997 if ((bp->b_iodone) || (bp->b_flags & XBF_ASYNC)) {
999 INIT_WORK(&bp->b_iodone_work, xfs_buf_iodone_work);
1000 queue_work(xfslogd_workqueue, &bp->b_iodone_work);
1002 xfs_buf_iodone_work(&bp->b_iodone_work);
1005 complete(&bp->b_iowait);
1014 ASSERT(error >= 0 && error <= 0xffff);
1015 bp->b_error = (unsigned short)error;
1016 trace_xfs_buf_ioerror(bp, error, _RET_IP_);
1021 struct xfs_mount *mp,
1026 bp->b_flags |= XBF_WRITE;
1027 bp->b_flags &= ~(XBF_ASYNC | XBF_READ);
1029 xfs_buf_delwri_dequeue(bp);
1032 error = xfs_buf_iowait(bp);
1034 xfs_force_shutdown(mp, SHUTDOWN_META_IO_ERROR);
1044 trace_xfs_buf_bdwrite(bp, _RET_IP_);
1046 bp->b_flags &= ~XBF_READ;
1047 bp->b_flags |= (XBF_DELWRI | XBF_ASYNC);
1049 xfs_buf_delwri_queue(bp, 1);
1053 * Called when we want to stop a buffer from getting written or read.
1054 * We attach the EIO error, muck with its flags, and call xfs_buf_ioend
1055 * so that the proper iodone callbacks get called.
1061 #ifdef XFSERRORDEBUG
1062 ASSERT(XFS_BUF_ISREAD(bp) || bp->b_iodone);
1066 * No need to wait until the buffer is unpinned, we aren't flushing it.
1068 XFS_BUF_ERROR(bp, EIO);
1071 * We're calling xfs_buf_ioend, so delete XBF_DONE flag.
1074 XFS_BUF_UNDELAYWRITE(bp);
1078 xfs_buf_ioend(bp, 0);
1084 * Same as xfs_bioerror, except that we are releasing the buffer
1085 * here ourselves, and avoiding the xfs_buf_ioend call.
1086 * This is meant for userdata errors; metadata bufs come with
1087 * iodone functions attached, so that we can track down errors.
1093 int64_t fl = XFS_BUF_BFLAGS(bp);
1095 * No need to wait until the buffer is unpinned.
1096 * We aren't flushing it.
1098 * chunkhold expects B_DONE to be set, whether
1099 * we actually finish the I/O or not. We don't want to
1100 * change that interface.
1103 XFS_BUF_UNDELAYWRITE(bp);
1106 XFS_BUF_CLR_IODONE_FUNC(bp);
1107 if (!(fl & XBF_ASYNC)) {
1109 * Mark b_error and B_ERROR _both_.
1110 * Lot's of chunkcache code assumes that.
1111 * There's no reason to mark error for
1114 XFS_BUF_ERROR(bp, EIO);
1115 XFS_BUF_FINISH_IOWAIT(bp);
1125 * All xfs metadata buffers except log state machine buffers
1126 * get this attached as their b_bdstrat callback function.
1127 * This is so that we can catch a buffer
1128 * after prematurely unpinning it to forcibly shutdown the filesystem.
1134 if (XFS_FORCED_SHUTDOWN(bp->b_target->bt_mount)) {
1135 trace_xfs_bdstrat_shut(bp, _RET_IP_);
1137 * Metadata write that didn't get logged but
1138 * written delayed anyway. These aren't associated
1139 * with a transaction, and can be ignored.
1141 if (!bp->b_iodone && !XFS_BUF_ISREAD(bp))
1142 return xfs_bioerror_relse(bp);
1144 return xfs_bioerror(bp);
1147 xfs_buf_iorequest(bp);
1152 * Wrapper around bdstrat so that we can stop data from going to disk in case
1153 * we are shutting down the filesystem. Typically user data goes thru this
1154 * path; one of the exceptions is the superblock.
1158 struct xfs_mount *mp,
1161 if (XFS_FORCED_SHUTDOWN(mp)) {
1162 trace_xfs_bdstrat_shut(bp, _RET_IP_);
1163 xfs_bioerror_relse(bp);
1167 xfs_buf_iorequest(bp);
1175 if (atomic_dec_and_test(&bp->b_io_remaining) == 1) {
1176 bp->b_flags &= ~_XBF_PAGE_LOCKED;
1177 xfs_buf_ioend(bp, schedule);
1186 xfs_buf_t *bp = (xfs_buf_t *)bio->bi_private;
1187 unsigned int blocksize = bp->b_target->bt_bsize;
1188 struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt - 1;
1190 xfs_buf_ioerror(bp, -error);
1192 if (!error && xfs_buf_is_vmapped(bp) && (bp->b_flags & XBF_READ))
1193 invalidate_kernel_vmap_range(bp->b_addr, xfs_buf_vmap_len(bp));
1196 struct page *page = bvec->bv_page;
1198 ASSERT(!PagePrivate(page));
1199 if (unlikely(bp->b_error)) {
1200 if (bp->b_flags & XBF_READ)
1201 ClearPageUptodate(page);
1202 } else if (blocksize >= PAGE_CACHE_SIZE) {
1203 SetPageUptodate(page);
1204 } else if (!PagePrivate(page) &&
1205 (bp->b_flags & _XBF_PAGE_CACHE)) {
1206 set_page_region(page, bvec->bv_offset, bvec->bv_len);
1209 if (--bvec >= bio->bi_io_vec)
1210 prefetchw(&bvec->bv_page->flags);
1212 if (bp->b_flags & _XBF_PAGE_LOCKED)
1214 } while (bvec >= bio->bi_io_vec);
1216 _xfs_buf_ioend(bp, 1);
1224 int rw, map_i, total_nr_pages, nr_pages;
1226 int offset = bp->b_offset;
1227 int size = bp->b_count_desired;
1228 sector_t sector = bp->b_bn;
1229 unsigned int blocksize = bp->b_target->bt_bsize;
1231 total_nr_pages = bp->b_page_count;
1234 if (bp->b_flags & XBF_ORDERED) {
1235 ASSERT(!(bp->b_flags & XBF_READ));
1236 rw = WRITE_FLUSH_FUA;
1237 } else if (bp->b_flags & XBF_LOG_BUFFER) {
1238 ASSERT(!(bp->b_flags & XBF_READ_AHEAD));
1239 bp->b_flags &= ~_XBF_RUN_QUEUES;
1240 rw = (bp->b_flags & XBF_WRITE) ? WRITE_SYNC : READ_SYNC;
1241 } else if (bp->b_flags & _XBF_RUN_QUEUES) {
1242 ASSERT(!(bp->b_flags & XBF_READ_AHEAD));
1243 bp->b_flags &= ~_XBF_RUN_QUEUES;
1244 rw = (bp->b_flags & XBF_WRITE) ? WRITE_META : READ_META;
1246 rw = (bp->b_flags & XBF_WRITE) ? WRITE :
1247 (bp->b_flags & XBF_READ_AHEAD) ? READA : READ;
1250 /* Special code path for reading a sub page size buffer in --
1251 * we populate up the whole page, and hence the other metadata
1252 * in the same page. This optimization is only valid when the
1253 * filesystem block size is not smaller than the page size.
1255 if ((bp->b_buffer_length < PAGE_CACHE_SIZE) &&
1256 ((bp->b_flags & (XBF_READ|_XBF_PAGE_LOCKED)) ==
1257 (XBF_READ|_XBF_PAGE_LOCKED)) &&
1258 (blocksize >= PAGE_CACHE_SIZE)) {
1259 bio = bio_alloc(GFP_NOIO, 1);
1261 bio->bi_bdev = bp->b_target->bt_bdev;
1262 bio->bi_sector = sector - (offset >> BBSHIFT);
1263 bio->bi_end_io = xfs_buf_bio_end_io;
1264 bio->bi_private = bp;
1266 bio_add_page(bio, bp->b_pages[0], PAGE_CACHE_SIZE, 0);
1269 atomic_inc(&bp->b_io_remaining);
1275 atomic_inc(&bp->b_io_remaining);
1276 nr_pages = BIO_MAX_SECTORS >> (PAGE_SHIFT - BBSHIFT);
1277 if (nr_pages > total_nr_pages)
1278 nr_pages = total_nr_pages;
1280 bio = bio_alloc(GFP_NOIO, nr_pages);
1281 bio->bi_bdev = bp->b_target->bt_bdev;
1282 bio->bi_sector = sector;
1283 bio->bi_end_io = xfs_buf_bio_end_io;
1284 bio->bi_private = bp;
1286 for (; size && nr_pages; nr_pages--, map_i++) {
1287 int rbytes, nbytes = PAGE_CACHE_SIZE - offset;
1292 rbytes = bio_add_page(bio, bp->b_pages[map_i], nbytes, offset);
1293 if (rbytes < nbytes)
1297 sector += nbytes >> BBSHIFT;
1303 if (likely(bio->bi_size)) {
1304 if (xfs_buf_is_vmapped(bp)) {
1305 flush_kernel_vmap_range(bp->b_addr,
1306 xfs_buf_vmap_len(bp));
1308 submit_bio(rw, bio);
1313 * if we get here, no pages were added to the bio. However,
1314 * we can't just error out here - if the pages are locked then
1315 * we have to unlock them otherwise we can hang on a later
1316 * access to the page.
1318 xfs_buf_ioerror(bp, EIO);
1319 if (bp->b_flags & _XBF_PAGE_LOCKED) {
1321 for (i = 0; i < bp->b_page_count; i++)
1322 unlock_page(bp->b_pages[i]);
1332 trace_xfs_buf_iorequest(bp, _RET_IP_);
1334 if (bp->b_flags & XBF_DELWRI) {
1335 xfs_buf_delwri_queue(bp, 1);
1339 if (bp->b_flags & XBF_WRITE) {
1340 xfs_buf_wait_unpin(bp);
1345 /* Set the count to 1 initially, this will stop an I/O
1346 * completion callout which happens before we have started
1347 * all the I/O from calling xfs_buf_ioend too early.
1349 atomic_set(&bp->b_io_remaining, 1);
1350 _xfs_buf_ioapply(bp);
1351 _xfs_buf_ioend(bp, 0);
1358 * Waits for I/O to complete on the buffer supplied.
1359 * It returns immediately if no I/O is pending.
1360 * It returns the I/O error code, if any, or 0 if there was no error.
1366 trace_xfs_buf_iowait(bp, _RET_IP_);
1368 if (atomic_read(&bp->b_io_remaining))
1369 blk_run_address_space(bp->b_target->bt_mapping);
1370 wait_for_completion(&bp->b_iowait);
1372 trace_xfs_buf_iowait_done(bp, _RET_IP_);
1383 if (bp->b_flags & XBF_MAPPED)
1384 return XFS_BUF_PTR(bp) + offset;
1386 offset += bp->b_offset;
1387 page = bp->b_pages[offset >> PAGE_CACHE_SHIFT];
1388 return (xfs_caddr_t)page_address(page) + (offset & (PAGE_CACHE_SIZE-1));
1392 * Move data into or out of a buffer.
1396 xfs_buf_t *bp, /* buffer to process */
1397 size_t boff, /* starting buffer offset */
1398 size_t bsize, /* length to copy */
1399 void *data, /* data address */
1400 xfs_buf_rw_t mode) /* read/write/zero flag */
1402 size_t bend, cpoff, csize;
1405 bend = boff + bsize;
1406 while (boff < bend) {
1407 page = bp->b_pages[xfs_buf_btoct(boff + bp->b_offset)];
1408 cpoff = xfs_buf_poff(boff + bp->b_offset);
1409 csize = min_t(size_t,
1410 PAGE_CACHE_SIZE-cpoff, bp->b_count_desired-boff);
1412 ASSERT(((csize + cpoff) <= PAGE_CACHE_SIZE));
1416 memset(page_address(page) + cpoff, 0, csize);
1419 memcpy(data, page_address(page) + cpoff, csize);
1422 memcpy(page_address(page) + cpoff, data, csize);
1431 * Handling of buffer targets (buftargs).
1435 * Wait for any bufs with callbacks that have been submitted but
1436 * have not yet returned... walk the hash list for the target.
1440 struct xfs_buftarg *btp)
1442 struct xfs_perag *pag;
1445 for (i = 0; i < btp->bt_mount->m_sb.sb_agcount; i++) {
1446 pag = xfs_perag_get(btp->bt_mount, i);
1447 spin_lock(&pag->pag_buf_lock);
1448 while (rb_first(&pag->pag_buf_tree)) {
1449 spin_unlock(&pag->pag_buf_lock);
1451 spin_lock(&pag->pag_buf_lock);
1453 spin_unlock(&pag->pag_buf_lock);
1460 struct shrinker *shrink,
1464 struct xfs_buftarg *btp = container_of(shrink,
1465 struct xfs_buftarg, bt_shrinker);
1467 if (test_bit(XBT_FORCE_SLEEP, &btp->bt_flags))
1469 if (list_empty(&btp->bt_delwrite_queue))
1471 set_bit(XBT_FORCE_FLUSH, &btp->bt_flags);
1472 wake_up_process(btp->bt_task);
1474 return list_empty(&btp->bt_delwrite_queue) ? -1 : 1;
1479 struct xfs_mount *mp,
1480 struct xfs_buftarg *btp)
1482 unregister_shrinker(&btp->bt_shrinker);
1484 xfs_flush_buftarg(btp, 1);
1485 if (mp->m_flags & XFS_MOUNT_BARRIER)
1486 xfs_blkdev_issue_flush(btp);
1487 iput(btp->bt_mapping->host);
1489 kthread_stop(btp->bt_task);
1494 xfs_setsize_buftarg_flags(
1496 unsigned int blocksize,
1497 unsigned int sectorsize,
1500 btp->bt_bsize = blocksize;
1501 btp->bt_sshift = ffs(sectorsize) - 1;
1502 btp->bt_smask = sectorsize - 1;
1504 if (set_blocksize(btp->bt_bdev, sectorsize)) {
1506 "XFS: Cannot set_blocksize to %u on device %s\n",
1507 sectorsize, XFS_BUFTARG_NAME(btp));
1512 (PAGE_CACHE_SIZE / BITS_PER_LONG) > sectorsize) {
1514 "XFS: %u byte sectors in use on device %s. "
1515 "This is suboptimal; %u or greater is ideal.\n",
1516 sectorsize, XFS_BUFTARG_NAME(btp),
1517 (unsigned int)PAGE_CACHE_SIZE / BITS_PER_LONG);
1524 * When allocating the initial buffer target we have not yet
1525 * read in the superblock, so don't know what sized sectors
1526 * are being used is at this early stage. Play safe.
1529 xfs_setsize_buftarg_early(
1531 struct block_device *bdev)
1533 return xfs_setsize_buftarg_flags(btp,
1534 PAGE_CACHE_SIZE, bdev_logical_block_size(bdev), 0);
1538 xfs_setsize_buftarg(
1540 unsigned int blocksize,
1541 unsigned int sectorsize)
1543 return xfs_setsize_buftarg_flags(btp, blocksize, sectorsize, 1);
1547 xfs_mapping_buftarg(
1549 struct block_device *bdev)
1551 struct backing_dev_info *bdi;
1552 struct inode *inode;
1553 struct address_space *mapping;
1554 static const struct address_space_operations mapping_aops = {
1555 .sync_page = block_sync_page,
1556 .migratepage = fail_migrate_page,
1559 inode = new_inode(bdev->bd_inode->i_sb);
1562 "XFS: Cannot allocate mapping inode for device %s\n",
1563 XFS_BUFTARG_NAME(btp));
1566 inode->i_ino = get_next_ino();
1567 inode->i_mode = S_IFBLK;
1568 inode->i_bdev = bdev;
1569 inode->i_rdev = bdev->bd_dev;
1570 bdi = blk_get_backing_dev_info(bdev);
1572 bdi = &default_backing_dev_info;
1573 mapping = &inode->i_data;
1574 mapping->a_ops = &mapping_aops;
1575 mapping->backing_dev_info = bdi;
1576 mapping_set_gfp_mask(mapping, GFP_NOFS);
1577 btp->bt_mapping = mapping;
1582 xfs_alloc_delwrite_queue(
1586 INIT_LIST_HEAD(&btp->bt_delwrite_queue);
1587 spin_lock_init(&btp->bt_delwrite_lock);
1589 btp->bt_task = kthread_run(xfsbufd, btp, "xfsbufd/%s", fsname);
1590 if (IS_ERR(btp->bt_task))
1591 return PTR_ERR(btp->bt_task);
1597 struct xfs_mount *mp,
1598 struct block_device *bdev,
1604 btp = kmem_zalloc(sizeof(*btp), KM_SLEEP);
1607 btp->bt_dev = bdev->bd_dev;
1608 btp->bt_bdev = bdev;
1609 if (xfs_setsize_buftarg_early(btp, bdev))
1611 if (xfs_mapping_buftarg(btp, bdev))
1613 if (xfs_alloc_delwrite_queue(btp, fsname))
1615 btp->bt_shrinker.shrink = xfs_buftarg_shrink;
1616 btp->bt_shrinker.seeks = DEFAULT_SEEKS;
1617 register_shrinker(&btp->bt_shrinker);
1627 * Delayed write buffer handling
1630 xfs_buf_delwri_queue(
1634 struct list_head *dwq = &bp->b_target->bt_delwrite_queue;
1635 spinlock_t *dwlk = &bp->b_target->bt_delwrite_lock;
1637 trace_xfs_buf_delwri_queue(bp, _RET_IP_);
1639 ASSERT((bp->b_flags&(XBF_DELWRI|XBF_ASYNC)) == (XBF_DELWRI|XBF_ASYNC));
1642 /* If already in the queue, dequeue and place at tail */
1643 if (!list_empty(&bp->b_list)) {
1644 ASSERT(bp->b_flags & _XBF_DELWRI_Q);
1646 atomic_dec(&bp->b_hold);
1647 list_del(&bp->b_list);
1650 if (list_empty(dwq)) {
1651 /* start xfsbufd as it is about to have something to do */
1652 wake_up_process(bp->b_target->bt_task);
1655 bp->b_flags |= _XBF_DELWRI_Q;
1656 list_add_tail(&bp->b_list, dwq);
1657 bp->b_queuetime = jiffies;
1665 xfs_buf_delwri_dequeue(
1668 spinlock_t *dwlk = &bp->b_target->bt_delwrite_lock;
1672 if ((bp->b_flags & XBF_DELWRI) && !list_empty(&bp->b_list)) {
1673 ASSERT(bp->b_flags & _XBF_DELWRI_Q);
1674 list_del_init(&bp->b_list);
1677 bp->b_flags &= ~(XBF_DELWRI|_XBF_DELWRI_Q);
1683 trace_xfs_buf_delwri_dequeue(bp, _RET_IP_);
1687 * If a delwri buffer needs to be pushed before it has aged out, then promote
1688 * it to the head of the delwri queue so that it will be flushed on the next
1689 * xfsbufd run. We do this by resetting the queuetime of the buffer to be older
1690 * than the age currently needed to flush the buffer. Hence the next time the
1691 * xfsbufd sees it is guaranteed to be considered old enough to flush.
1694 xfs_buf_delwri_promote(
1697 struct xfs_buftarg *btp = bp->b_target;
1698 long age = xfs_buf_age_centisecs * msecs_to_jiffies(10) + 1;
1700 ASSERT(bp->b_flags & XBF_DELWRI);
1701 ASSERT(bp->b_flags & _XBF_DELWRI_Q);
1704 * Check the buffer age before locking the delayed write queue as we
1705 * don't need to promote buffers that are already past the flush age.
1707 if (bp->b_queuetime < jiffies - age)
1709 bp->b_queuetime = jiffies - age;
1710 spin_lock(&btp->bt_delwrite_lock);
1711 list_move(&bp->b_list, &btp->bt_delwrite_queue);
1712 spin_unlock(&btp->bt_delwrite_lock);
1716 xfs_buf_runall_queues(
1717 struct workqueue_struct *queue)
1719 flush_workqueue(queue);
1723 * Move as many buffers as specified to the supplied list
1724 * idicating if we skipped any buffers to prevent deadlocks.
1727 xfs_buf_delwri_split(
1728 xfs_buftarg_t *target,
1729 struct list_head *list,
1733 struct list_head *dwq = &target->bt_delwrite_queue;
1734 spinlock_t *dwlk = &target->bt_delwrite_lock;
1738 force = test_and_clear_bit(XBT_FORCE_FLUSH, &target->bt_flags);
1739 INIT_LIST_HEAD(list);
1741 list_for_each_entry_safe(bp, n, dwq, b_list) {
1742 ASSERT(bp->b_flags & XBF_DELWRI);
1744 if (!XFS_BUF_ISPINNED(bp) && !xfs_buf_cond_lock(bp)) {
1746 time_before(jiffies, bp->b_queuetime + age)) {
1751 bp->b_flags &= ~(XBF_DELWRI|_XBF_DELWRI_Q|
1753 bp->b_flags |= XBF_WRITE;
1754 list_move_tail(&bp->b_list, list);
1755 trace_xfs_buf_delwri_split(bp, _RET_IP_);
1766 * Compare function is more complex than it needs to be because
1767 * the return value is only 32 bits and we are doing comparisons
1773 struct list_head *a,
1774 struct list_head *b)
1776 struct xfs_buf *ap = container_of(a, struct xfs_buf, b_list);
1777 struct xfs_buf *bp = container_of(b, struct xfs_buf, b_list);
1780 diff = ap->b_bn - bp->b_bn;
1789 xfs_buf_delwri_sort(
1790 xfs_buftarg_t *target,
1791 struct list_head *list)
1793 list_sort(NULL, list, xfs_buf_cmp);
1800 xfs_buftarg_t *target = (xfs_buftarg_t *)data;
1802 current->flags |= PF_MEMALLOC;
1807 long age = xfs_buf_age_centisecs * msecs_to_jiffies(10);
1808 long tout = xfs_buf_timer_centisecs * msecs_to_jiffies(10);
1810 struct list_head tmp;
1812 if (unlikely(freezing(current))) {
1813 set_bit(XBT_FORCE_SLEEP, &target->bt_flags);
1816 clear_bit(XBT_FORCE_SLEEP, &target->bt_flags);
1819 /* sleep for a long time if there is nothing to do. */
1820 if (list_empty(&target->bt_delwrite_queue))
1821 tout = MAX_SCHEDULE_TIMEOUT;
1822 schedule_timeout_interruptible(tout);
1824 xfs_buf_delwri_split(target, &tmp, age);
1825 list_sort(NULL, &tmp, xfs_buf_cmp);
1826 while (!list_empty(&tmp)) {
1828 bp = list_first_entry(&tmp, struct xfs_buf, b_list);
1829 list_del_init(&bp->b_list);
1834 blk_run_address_space(target->bt_mapping);
1836 } while (!kthread_should_stop());
1842 * Go through all incore buffers, and release buffers if they belong to
1843 * the given device. This is used in filesystem error handling to
1844 * preserve the consistency of its metadata.
1848 xfs_buftarg_t *target,
1853 LIST_HEAD(tmp_list);
1854 LIST_HEAD(wait_list);
1856 xfs_buf_runall_queues(xfsconvertd_workqueue);
1857 xfs_buf_runall_queues(xfsdatad_workqueue);
1858 xfs_buf_runall_queues(xfslogd_workqueue);
1860 set_bit(XBT_FORCE_FLUSH, &target->bt_flags);
1861 pincount = xfs_buf_delwri_split(target, &tmp_list, 0);
1864 * Dropped the delayed write list lock, now walk the temporary list.
1865 * All I/O is issued async and then if we need to wait for completion
1866 * we do that after issuing all the IO.
1868 list_sort(NULL, &tmp_list, xfs_buf_cmp);
1869 while (!list_empty(&tmp_list)) {
1870 bp = list_first_entry(&tmp_list, struct xfs_buf, b_list);
1871 ASSERT(target == bp->b_target);
1872 list_del_init(&bp->b_list);
1874 bp->b_flags &= ~XBF_ASYNC;
1875 list_add(&bp->b_list, &wait_list);
1881 /* Expedite and wait for IO to complete. */
1882 blk_run_address_space(target->bt_mapping);
1883 while (!list_empty(&wait_list)) {
1884 bp = list_first_entry(&wait_list, struct xfs_buf, b_list);
1886 list_del_init(&bp->b_list);
1898 xfs_buf_zone = kmem_zone_init_flags(sizeof(xfs_buf_t), "xfs_buf",
1899 KM_ZONE_HWALIGN, NULL);
1903 xfslogd_workqueue = alloc_workqueue("xfslogd",
1904 WQ_MEM_RECLAIM | WQ_HIGHPRI, 1);
1905 if (!xfslogd_workqueue)
1906 goto out_free_buf_zone;
1908 xfsdatad_workqueue = create_workqueue("xfsdatad");
1909 if (!xfsdatad_workqueue)
1910 goto out_destroy_xfslogd_workqueue;
1912 xfsconvertd_workqueue = create_workqueue("xfsconvertd");
1913 if (!xfsconvertd_workqueue)
1914 goto out_destroy_xfsdatad_workqueue;
1918 out_destroy_xfsdatad_workqueue:
1919 destroy_workqueue(xfsdatad_workqueue);
1920 out_destroy_xfslogd_workqueue:
1921 destroy_workqueue(xfslogd_workqueue);
1923 kmem_zone_destroy(xfs_buf_zone);
1929 xfs_buf_terminate(void)
1931 destroy_workqueue(xfsconvertd_workqueue);
1932 destroy_workqueue(xfsdatad_workqueue);
1933 destroy_workqueue(xfslogd_workqueue);
1934 kmem_zone_destroy(xfs_buf_zone);
1937 #ifdef CONFIG_KDB_MODULES
1939 xfs_get_buftarg_list(void)
1941 return &xfs_buftarg_list;