blob: 365040f61d89a8923360999faee8c37ae0e21b41 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7b718762005-11-02 14:58:39 +11002 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include "xfs.h"
Nathan Scotta844f452005-11-02 14:38:42 +110019#include "xfs_bit.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include "xfs_log.h"
Nathan Scotta844f452005-11-02 14:38:42 +110021#include "xfs_inum.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include "xfs_sb.h"
Nathan Scotta844f452005-11-02 14:38:42 +110023#include "xfs_ag.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include "xfs_trans.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include "xfs_mount.h"
26#include "xfs_bmap_btree.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include "xfs_dinode.h"
28#include "xfs_inode.h"
Nathan Scotta844f452005-11-02 14:38:42 +110029#include "xfs_alloc.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include "xfs_error.h"
31#include "xfs_rw.h"
32#include "xfs_iomap.h"
Christoph Hellwig739bfb22007-08-29 10:58:01 +100033#include "xfs_vnodeops.h"
Christoph Hellwig0b1b2132009-12-14 23:14:59 +000034#include "xfs_trace.h"
Dave Chinner3ed3a432010-03-05 02:00:42 +000035#include "xfs_bmap.h"
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090036#include <linux/gfp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/mpage.h>
Christoph Hellwig10ce4442006-01-11 20:48:14 +110038#include <linux/pagevec.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <linux/writeback.h>
40
Christoph Hellwig25e41b32008-12-03 12:20:39 +010041
42/*
43 * Prime number of hash buckets since address is used as the key.
44 */
45#define NVSYNC 37
46#define to_ioend_wq(v) (&xfs_ioend_wq[((unsigned long)v) % NVSYNC])
47static wait_queue_head_t xfs_ioend_wq[NVSYNC];
48
49void __init
50xfs_ioend_init(void)
51{
52 int i;
53
54 for (i = 0; i < NVSYNC; i++)
55 init_waitqueue_head(&xfs_ioend_wq[i]);
56}
57
58void
59xfs_ioend_wait(
60 xfs_inode_t *ip)
61{
62 wait_queue_head_t *wq = to_ioend_wq(ip);
63
64 wait_event(*wq, (atomic_read(&ip->i_iocount) == 0));
65}
66
67STATIC void
68xfs_ioend_wake(
69 xfs_inode_t *ip)
70{
71 if (atomic_dec_and_test(&ip->i_iocount))
72 wake_up(to_ioend_wq(ip));
73}
74
Christoph Hellwig0b1b2132009-12-14 23:14:59 +000075void
Nathan Scottf51623b2006-03-14 13:26:27 +110076xfs_count_page_state(
77 struct page *page,
78 int *delalloc,
Nathan Scottf51623b2006-03-14 13:26:27 +110079 int *unwritten)
80{
81 struct buffer_head *bh, *head;
82
Christoph Hellwig20cb52e2010-06-24 09:46:01 +100083 *delalloc = *unwritten = 0;
Nathan Scottf51623b2006-03-14 13:26:27 +110084
85 bh = head = page_buffers(page);
86 do {
Christoph Hellwig20cb52e2010-06-24 09:46:01 +100087 if (buffer_unwritten(bh))
Nathan Scottf51623b2006-03-14 13:26:27 +110088 (*unwritten) = 1;
89 else if (buffer_delay(bh))
90 (*delalloc) = 1;
91 } while ((bh = bh->b_this_page) != head);
92}
93
Christoph Hellwig6214ed42007-09-14 15:23:17 +100094STATIC struct block_device *
95xfs_find_bdev_for_inode(
Christoph Hellwig046f1682010-04-28 12:28:52 +000096 struct inode *inode)
Christoph Hellwig6214ed42007-09-14 15:23:17 +100097{
Christoph Hellwig046f1682010-04-28 12:28:52 +000098 struct xfs_inode *ip = XFS_I(inode);
Christoph Hellwig6214ed42007-09-14 15:23:17 +100099 struct xfs_mount *mp = ip->i_mount;
100
Eric Sandeen71ddabb2007-11-23 16:29:42 +1100101 if (XFS_IS_REALTIME_INODE(ip))
Christoph Hellwig6214ed42007-09-14 15:23:17 +1000102 return mp->m_rtdev_targp->bt_bdev;
103 else
104 return mp->m_ddev_targp->bt_bdev;
105}
106
Christoph Hellwig0829c362005-09-02 16:58:49 +1000107/*
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100108 * We're now finished for good with this ioend structure.
109 * Update the page state via the associated buffer_heads,
110 * release holds on the inode and bio, and finally free
111 * up memory. Do not use the ioend after this.
112 */
Christoph Hellwig0829c362005-09-02 16:58:49 +1000113STATIC void
114xfs_destroy_ioend(
115 xfs_ioend_t *ioend)
116{
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100117 struct buffer_head *bh, *next;
Christoph Hellwig583fa582008-12-03 12:20:38 +0100118 struct xfs_inode *ip = XFS_I(ioend->io_inode);
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100119
120 for (bh = ioend->io_buffer_head; bh; bh = next) {
121 next = bh->b_private;
Nathan Scott7d04a332006-06-09 14:58:38 +1000122 bh->b_end_io(bh, !ioend->io_error);
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100123 }
Christoph Hellwig583fa582008-12-03 12:20:38 +0100124
125 /*
126 * Volume managers supporting multiple paths can send back ENODEV
127 * when the final path disappears. In this case continuing to fill
128 * the page cache with dirty data which cannot be written out is
129 * evil, so prevent that.
130 */
131 if (unlikely(ioend->io_error == -ENODEV)) {
132 xfs_do_force_shutdown(ip->i_mount, SHUTDOWN_DEVICE_REQ,
133 __FILE__, __LINE__);
Christoph Hellwigb677c212007-08-29 11:46:28 +1000134 }
Christoph Hellwig583fa582008-12-03 12:20:38 +0100135
Christoph Hellwig25e41b32008-12-03 12:20:39 +0100136 xfs_ioend_wake(ip);
Christoph Hellwig0829c362005-09-02 16:58:49 +1000137 mempool_free(ioend, xfs_ioend_pool);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138}
139
140/*
Dave Chinner932640e2009-10-06 20:29:29 +0000141 * If the end of the current ioend is beyond the current EOF,
142 * return the new EOF value, otherwise zero.
143 */
144STATIC xfs_fsize_t
145xfs_ioend_new_eof(
146 xfs_ioend_t *ioend)
147{
148 xfs_inode_t *ip = XFS_I(ioend->io_inode);
149 xfs_fsize_t isize;
150 xfs_fsize_t bsize;
151
152 bsize = ioend->io_offset + ioend->io_size;
153 isize = MAX(ip->i_size, ip->i_new_size);
154 isize = MIN(isize, bsize);
155 return isize > ip->i_d.di_size ? isize : 0;
156}
157
158/*
Dave Chinner77d7a0c2010-02-17 05:36:29 +0000159 * Update on-disk file size now that data has been written to disk. The
160 * current in-memory file size is i_size. If a write is beyond eof i_new_size
161 * will be the intended file size until i_size is updated. If this write does
162 * not extend all the way to the valid file size then restrict this update to
163 * the end of the write.
164 *
165 * This function does not block as blocking on the inode lock in IO completion
166 * can lead to IO completion order dependency deadlocks.. If it can't get the
167 * inode ilock it will return EAGAIN. Callers must handle this.
Lachlan McIlroyba87ea62007-05-08 13:49:46 +1000168 */
Dave Chinner77d7a0c2010-02-17 05:36:29 +0000169STATIC int
Lachlan McIlroyba87ea62007-05-08 13:49:46 +1000170xfs_setfilesize(
171 xfs_ioend_t *ioend)
172{
Christoph Hellwigb677c212007-08-29 11:46:28 +1000173 xfs_inode_t *ip = XFS_I(ioend->io_inode);
Lachlan McIlroyba87ea62007-05-08 13:49:46 +1000174 xfs_fsize_t isize;
Lachlan McIlroyba87ea62007-05-08 13:49:46 +1000175
Lachlan McIlroyba87ea62007-05-08 13:49:46 +1000176 if (unlikely(ioend->io_error))
Dave Chinner77d7a0c2010-02-17 05:36:29 +0000177 return 0;
Lachlan McIlroyba87ea62007-05-08 13:49:46 +1000178
Dave Chinner77d7a0c2010-02-17 05:36:29 +0000179 if (!xfs_ilock_nowait(ip, XFS_ILOCK_EXCL))
180 return EAGAIN;
181
Dave Chinner932640e2009-10-06 20:29:29 +0000182 isize = xfs_ioend_new_eof(ioend);
183 if (isize) {
Lachlan McIlroyba87ea62007-05-08 13:49:46 +1000184 ip->i_d.di_size = isize;
Christoph Hellwig66d834e2010-02-15 09:44:49 +0000185 xfs_mark_inode_dirty(ip);
Lachlan McIlroyba87ea62007-05-08 13:49:46 +1000186 }
187
188 xfs_iunlock(ip, XFS_ILOCK_EXCL);
Dave Chinner77d7a0c2010-02-17 05:36:29 +0000189 return 0;
Christoph Hellwig0829c362005-09-02 16:58:49 +1000190}
191
192/*
Christoph Hellwig209fb872010-07-18 21:17:11 +0000193 * Schedule IO completion handling on the final put of an ioend.
Dave Chinnerc626d172009-04-06 18:42:11 +0200194 */
195STATIC void
196xfs_finish_ioend(
Christoph Hellwig209fb872010-07-18 21:17:11 +0000197 struct xfs_ioend *ioend)
Dave Chinnerc626d172009-04-06 18:42:11 +0200198{
199 if (atomic_dec_and_test(&ioend->io_remaining)) {
Christoph Hellwig209fb872010-07-18 21:17:11 +0000200 if (ioend->io_type == IO_UNWRITTEN)
201 queue_work(xfsconvertd_workqueue, &ioend->io_work);
202 else
203 queue_work(xfsdatad_workqueue, &ioend->io_work);
Dave Chinnerc626d172009-04-06 18:42:11 +0200204 }
205}
206
207/*
Dave Chinner77d7a0c2010-02-17 05:36:29 +0000208 * IO write completion.
209 */
210STATIC void
211xfs_end_io(
212 struct work_struct *work)
213{
214 xfs_ioend_t *ioend = container_of(work, xfs_ioend_t, io_work);
215 struct xfs_inode *ip = XFS_I(ioend->io_inode);
Dave Chinner69418932010-03-04 00:57:09 +0000216 int error = 0;
Dave Chinner77d7a0c2010-02-17 05:36:29 +0000217
218 /*
219 * For unwritten extents we need to issue transactions to convert a
220 * range to normal written extens after the data I/O has finished.
221 */
Christoph Hellwig34a52c62010-04-28 12:28:57 +0000222 if (ioend->io_type == IO_UNWRITTEN &&
Dave Chinner77d7a0c2010-02-17 05:36:29 +0000223 likely(!ioend->io_error && !XFS_FORCED_SHUTDOWN(ip->i_mount))) {
224
225 error = xfs_iomap_write_unwritten(ip, ioend->io_offset,
226 ioend->io_size);
227 if (error)
228 ioend->io_error = error;
229 }
230
231 /*
232 * We might have to update the on-disk file size after extending
233 * writes.
234 */
Christoph Hellwiga206c812010-12-10 08:42:20 +0000235 error = xfs_setfilesize(ioend);
236 ASSERT(!error || error == EAGAIN);
Dave Chinner77d7a0c2010-02-17 05:36:29 +0000237
238 /*
239 * If we didn't complete processing of the ioend, requeue it to the
240 * tail of the workqueue for another attempt later. Otherwise destroy
241 * it.
242 */
243 if (error == EAGAIN) {
244 atomic_inc(&ioend->io_remaining);
Christoph Hellwig209fb872010-07-18 21:17:11 +0000245 xfs_finish_ioend(ioend);
Dave Chinner77d7a0c2010-02-17 05:36:29 +0000246 /* ensure we don't spin on blocked ioends */
247 delay(1);
Christoph Hellwigfb511f22010-07-18 21:17:10 +0000248 } else {
249 if (ioend->io_iocb)
250 aio_complete(ioend->io_iocb, ioend->io_result, 0);
Dave Chinner77d7a0c2010-02-17 05:36:29 +0000251 xfs_destroy_ioend(ioend);
Christoph Hellwigfb511f22010-07-18 21:17:10 +0000252 }
Dave Chinner77d7a0c2010-02-17 05:36:29 +0000253}
254
255/*
Christoph Hellwig209fb872010-07-18 21:17:11 +0000256 * Call IO completion handling in caller context on the final put of an ioend.
257 */
258STATIC void
259xfs_finish_ioend_sync(
260 struct xfs_ioend *ioend)
261{
262 if (atomic_dec_and_test(&ioend->io_remaining))
263 xfs_end_io(&ioend->io_work);
264}
265
266/*
Christoph Hellwig0829c362005-09-02 16:58:49 +1000267 * Allocate and initialise an IO completion structure.
268 * We need to track unwritten extent write completion here initially.
269 * We'll need to extend this for updating the ondisk inode size later
270 * (vs. incore size).
271 */
272STATIC xfs_ioend_t *
273xfs_alloc_ioend(
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100274 struct inode *inode,
275 unsigned int type)
Christoph Hellwig0829c362005-09-02 16:58:49 +1000276{
277 xfs_ioend_t *ioend;
278
279 ioend = mempool_alloc(xfs_ioend_pool, GFP_NOFS);
280
281 /*
282 * Set the count to 1 initially, which will prevent an I/O
283 * completion callback from happening before we have started
284 * all the I/O from calling the completion routine too early.
285 */
286 atomic_set(&ioend->io_remaining, 1);
Nathan Scott7d04a332006-06-09 14:58:38 +1000287 ioend->io_error = 0;
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100288 ioend->io_list = NULL;
289 ioend->io_type = type;
Christoph Hellwigb677c212007-08-29 11:46:28 +1000290 ioend->io_inode = inode;
Christoph Hellwigc1a073b2005-09-05 08:23:35 +1000291 ioend->io_buffer_head = NULL;
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100292 ioend->io_buffer_tail = NULL;
Christoph Hellwigb677c212007-08-29 11:46:28 +1000293 atomic_inc(&XFS_I(ioend->io_inode)->i_iocount);
Christoph Hellwig0829c362005-09-02 16:58:49 +1000294 ioend->io_offset = 0;
295 ioend->io_size = 0;
Christoph Hellwigfb511f22010-07-18 21:17:10 +0000296 ioend->io_iocb = NULL;
297 ioend->io_result = 0;
Christoph Hellwig0829c362005-09-02 16:58:49 +1000298
Christoph Hellwig5ec4fab2009-10-30 09:11:47 +0000299 INIT_WORK(&ioend->io_work, xfs_end_io);
Christoph Hellwig0829c362005-09-02 16:58:49 +1000300 return ioend;
301}
302
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303STATIC int
304xfs_map_blocks(
305 struct inode *inode,
306 loff_t offset,
307 ssize_t count,
Christoph Hellwig207d0412010-04-28 12:28:56 +0000308 struct xfs_bmbt_irec *imap,
Christoph Hellwiga206c812010-12-10 08:42:20 +0000309 int type,
310 int nonblocking)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311{
Christoph Hellwiga206c812010-12-10 08:42:20 +0000312 struct xfs_inode *ip = XFS_I(inode);
313 struct xfs_mount *mp = ip->i_mount;
314 xfs_fileoff_t offset_fsb, end_fsb;
315 int error = 0;
316 int lockmode = 0;
317 int bmapi_flags = XFS_BMAPI_ENTIRE;
318 int nimaps = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
Christoph Hellwiga206c812010-12-10 08:42:20 +0000320 if (XFS_FORCED_SHUTDOWN(mp))
321 return -XFS_ERROR(EIO);
322
323 switch (type) {
324 case IO_OVERWRITE:
325 lockmode = xfs_ilock_map_shared(ip);
326 break;
327 case IO_UNWRITTEN:
328 lockmode = XFS_ILOCK_EXCL;
329 bmapi_flags |= XFS_BMAPI_IGSTATE;
330 xfs_ilock(ip, lockmode);
331 break;
332 case IO_DELALLOC:
333 lockmode = XFS_ILOCK_SHARED;
334
335 if (!xfs_ilock_nowait(ip, lockmode)) {
336 if (nonblocking)
337 return -XFS_ERROR(EAGAIN);
338 xfs_ilock(ip, lockmode);
339 }
340 break;
341 }
342
343 ASSERT(offset <= mp->m_maxioffset);
344 if (offset + count > mp->m_maxioffset)
345 count = mp->m_maxioffset - offset;
346 end_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)offset + count);
347 offset_fsb = XFS_B_TO_FSBT(mp, offset);
348
349 error = xfs_bmapi(NULL, ip, offset_fsb, end_fsb - offset_fsb,
350 bmapi_flags, NULL, 0, imap, &nimaps, NULL);
351 if (error)
352 goto out;
353
354 switch (type) {
355 case IO_UNWRITTEN:
356 /* If we found an extent, return it */
357 if (nimaps &&
358 (imap->br_startblock != HOLESTARTBLOCK) &&
359 (imap->br_startblock != DELAYSTARTBLOCK)) {
360 trace_xfs_map_blocks_found(ip, offset, count, type, imap);
361 break;
362 }
363
364 error = xfs_iomap_write_delay(ip, offset, count, imap);
365 if (!error)
366 trace_xfs_map_blocks_alloc(ip, offset, count, type, imap);
367 break;
368 case IO_DELALLOC:
369 /* If we found an extent, return it */
370 xfs_iunlock(ip, lockmode);
371 lockmode = 0;
372
373 if (nimaps && !isnullstartblock(imap->br_startblock)) {
374 trace_xfs_map_blocks_found(ip, offset, count, type, imap);
375 break;
376 }
377
378 error = xfs_iomap_write_allocate(ip, offset, count, imap);
379 if (!error)
380 trace_xfs_map_blocks_alloc(ip, offset, count, type, imap);
381 break;
382 default:
383 if (nimaps)
384 trace_xfs_map_blocks_found(ip, offset, count, type, imap);
385 }
386
387out:
388 if (lockmode)
389 xfs_iunlock(ip, lockmode);
390 return -XFS_ERROR(error);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391}
392
Christoph Hellwigb8f82a42009-11-14 16:17:22 +0000393STATIC int
Christoph Hellwig558e6892010-04-28 12:28:58 +0000394xfs_imap_valid(
Christoph Hellwig8699bb02010-04-28 12:28:54 +0000395 struct inode *inode,
Christoph Hellwig207d0412010-04-28 12:28:56 +0000396 struct xfs_bmbt_irec *imap,
Christoph Hellwig558e6892010-04-28 12:28:58 +0000397 xfs_off_t offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398{
Christoph Hellwig558e6892010-04-28 12:28:58 +0000399 offset >>= inode->i_blkbits;
Christoph Hellwig8699bb02010-04-28 12:28:54 +0000400
Christoph Hellwig558e6892010-04-28 12:28:58 +0000401 return offset >= imap->br_startoff &&
402 offset < imap->br_startoff + imap->br_blockcount;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403}
404
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100405/*
406 * BIO completion handler for buffered IO.
407 */
Al Viro782e3b32007-10-12 07:17:47 +0100408STATIC void
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100409xfs_end_bio(
410 struct bio *bio,
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100411 int error)
412{
413 xfs_ioend_t *ioend = bio->bi_private;
414
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100415 ASSERT(atomic_read(&bio->bi_cnt) >= 1);
Nathan Scott7d04a332006-06-09 14:58:38 +1000416 ioend->io_error = test_bit(BIO_UPTODATE, &bio->bi_flags) ? 0 : error;
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100417
418 /* Toss bio and pass work off to an xfsdatad thread */
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100419 bio->bi_private = NULL;
420 bio->bi_end_io = NULL;
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100421 bio_put(bio);
Nathan Scott7d04a332006-06-09 14:58:38 +1000422
Christoph Hellwig209fb872010-07-18 21:17:11 +0000423 xfs_finish_ioend(ioend);
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100424}
425
426STATIC void
427xfs_submit_ioend_bio(
Christoph Hellwig06342cf2009-10-30 09:09:15 +0000428 struct writeback_control *wbc,
429 xfs_ioend_t *ioend,
430 struct bio *bio)
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100431{
432 atomic_inc(&ioend->io_remaining);
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100433 bio->bi_private = ioend;
434 bio->bi_end_io = xfs_end_bio;
435
Dave Chinner932640e2009-10-06 20:29:29 +0000436 /*
437 * If the I/O is beyond EOF we mark the inode dirty immediately
438 * but don't update the inode size until I/O completion.
439 */
440 if (xfs_ioend_new_eof(ioend))
Christoph Hellwig66d834e2010-02-15 09:44:49 +0000441 xfs_mark_inode_dirty(XFS_I(ioend->io_inode));
Dave Chinner932640e2009-10-06 20:29:29 +0000442
Christoph Hellwig06342cf2009-10-30 09:09:15 +0000443 submit_bio(wbc->sync_mode == WB_SYNC_ALL ?
444 WRITE_SYNC_PLUG : WRITE, bio);
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100445}
446
447STATIC struct bio *
448xfs_alloc_ioend_bio(
449 struct buffer_head *bh)
450{
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100451 int nvecs = bio_get_nr_vecs(bh->b_bdev);
Christoph Hellwig221cb252010-12-10 08:42:17 +0000452 struct bio *bio = bio_alloc(GFP_NOIO, nvecs);
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100453
454 ASSERT(bio->bi_private == NULL);
455 bio->bi_sector = bh->b_blocknr * (bh->b_size >> 9);
456 bio->bi_bdev = bh->b_bdev;
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100457 return bio;
458}
459
460STATIC void
461xfs_start_buffer_writeback(
462 struct buffer_head *bh)
463{
464 ASSERT(buffer_mapped(bh));
465 ASSERT(buffer_locked(bh));
466 ASSERT(!buffer_delay(bh));
467 ASSERT(!buffer_unwritten(bh));
468
469 mark_buffer_async_write(bh);
470 set_buffer_uptodate(bh);
471 clear_buffer_dirty(bh);
472}
473
474STATIC void
475xfs_start_page_writeback(
476 struct page *page,
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100477 int clear_dirty,
478 int buffers)
479{
480 ASSERT(PageLocked(page));
481 ASSERT(!PageWriteback(page));
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100482 if (clear_dirty)
David Chinner92132022006-12-21 10:24:01 +1100483 clear_page_dirty_for_io(page);
484 set_page_writeback(page);
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100485 unlock_page(page);
Fengguang Wu1f7decf2007-10-16 23:30:42 -0700486 /* If no buffers on the page are to be written, finish it here */
487 if (!buffers)
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100488 end_page_writeback(page);
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100489}
490
491static inline int bio_add_buffer(struct bio *bio, struct buffer_head *bh)
492{
493 return bio_add_page(bio, bh->b_page, bh->b_size, bh_offset(bh));
494}
495
496/*
David Chinnerd88992f2006-01-18 13:38:12 +1100497 * Submit all of the bios for all of the ioends we have saved up, covering the
498 * initial writepage page and also any probed pages.
499 *
500 * Because we may have multiple ioends spanning a page, we need to start
501 * writeback on all the buffers before we submit them for I/O. If we mark the
502 * buffers as we got, then we can end up with a page that only has buffers
503 * marked async write and I/O complete on can occur before we mark the other
504 * buffers async write.
505 *
506 * The end result of this is that we trip a bug in end_page_writeback() because
507 * we call it twice for the one page as the code in end_buffer_async_write()
508 * assumes that all buffers on the page are started at the same time.
509 *
510 * The fix is two passes across the ioend list - one to start writeback on the
Nathan Scottc41564b2006-03-29 08:55:14 +1000511 * buffer_heads, and then submit them for I/O on the second pass.
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100512 */
513STATIC void
514xfs_submit_ioend(
Christoph Hellwig06342cf2009-10-30 09:09:15 +0000515 struct writeback_control *wbc,
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100516 xfs_ioend_t *ioend)
517{
David Chinnerd88992f2006-01-18 13:38:12 +1100518 xfs_ioend_t *head = ioend;
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100519 xfs_ioend_t *next;
520 struct buffer_head *bh;
521 struct bio *bio;
522 sector_t lastblock = 0;
523
David Chinnerd88992f2006-01-18 13:38:12 +1100524 /* Pass 1 - start writeback */
525 do {
526 next = ioend->io_list;
Christoph Hellwig221cb252010-12-10 08:42:17 +0000527 for (bh = ioend->io_buffer_head; bh; bh = bh->b_private)
David Chinnerd88992f2006-01-18 13:38:12 +1100528 xfs_start_buffer_writeback(bh);
David Chinnerd88992f2006-01-18 13:38:12 +1100529 } while ((ioend = next) != NULL);
530
531 /* Pass 2 - submit I/O */
532 ioend = head;
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100533 do {
534 next = ioend->io_list;
535 bio = NULL;
536
537 for (bh = ioend->io_buffer_head; bh; bh = bh->b_private) {
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100538
539 if (!bio) {
540 retry:
541 bio = xfs_alloc_ioend_bio(bh);
542 } else if (bh->b_blocknr != lastblock + 1) {
Christoph Hellwig06342cf2009-10-30 09:09:15 +0000543 xfs_submit_ioend_bio(wbc, ioend, bio);
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100544 goto retry;
545 }
546
547 if (bio_add_buffer(bio, bh) != bh->b_size) {
Christoph Hellwig06342cf2009-10-30 09:09:15 +0000548 xfs_submit_ioend_bio(wbc, ioend, bio);
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100549 goto retry;
550 }
551
552 lastblock = bh->b_blocknr;
553 }
554 if (bio)
Christoph Hellwig06342cf2009-10-30 09:09:15 +0000555 xfs_submit_ioend_bio(wbc, ioend, bio);
Christoph Hellwig209fb872010-07-18 21:17:11 +0000556 xfs_finish_ioend(ioend);
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100557 } while ((ioend = next) != NULL);
558}
559
560/*
561 * Cancel submission of all buffer_heads so far in this endio.
562 * Toss the endio too. Only ever called for the initial page
563 * in a writepage request, so only ever one page.
564 */
565STATIC void
566xfs_cancel_ioend(
567 xfs_ioend_t *ioend)
568{
569 xfs_ioend_t *next;
570 struct buffer_head *bh, *next_bh;
571
572 do {
573 next = ioend->io_list;
574 bh = ioend->io_buffer_head;
575 do {
576 next_bh = bh->b_private;
577 clear_buffer_async_write(bh);
578 unlock_buffer(bh);
579 } while ((bh = next_bh) != NULL);
580
Christoph Hellwig25e41b32008-12-03 12:20:39 +0100581 xfs_ioend_wake(XFS_I(ioend->io_inode));
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100582 mempool_free(ioend, xfs_ioend_pool);
583 } while ((ioend = next) != NULL);
584}
585
586/*
587 * Test to see if we've been building up a completion structure for
588 * earlier buffers -- if so, we try to append to this ioend if we
589 * can, otherwise we finish off any current ioend and start another.
590 * Return true if we've finished the given ioend.
591 */
592STATIC void
593xfs_add_to_ioend(
594 struct inode *inode,
595 struct buffer_head *bh,
Christoph Hellwig7336cea2006-01-11 20:49:16 +1100596 xfs_off_t offset,
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100597 unsigned int type,
598 xfs_ioend_t **result,
599 int need_ioend)
600{
601 xfs_ioend_t *ioend = *result;
602
603 if (!ioend || need_ioend || type != ioend->io_type) {
604 xfs_ioend_t *previous = *result;
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100605
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100606 ioend = xfs_alloc_ioend(inode, type);
607 ioend->io_offset = offset;
608 ioend->io_buffer_head = bh;
609 ioend->io_buffer_tail = bh;
610 if (previous)
611 previous->io_list = ioend;
612 *result = ioend;
613 } else {
614 ioend->io_buffer_tail->b_private = bh;
615 ioend->io_buffer_tail = bh;
616 }
617
618 bh->b_private = NULL;
619 ioend->io_size += bh->b_size;
620}
621
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622STATIC void
Nathan Scott87cbc492006-03-14 13:26:43 +1100623xfs_map_buffer(
Christoph Hellwig046f1682010-04-28 12:28:52 +0000624 struct inode *inode,
Nathan Scott87cbc492006-03-14 13:26:43 +1100625 struct buffer_head *bh,
Christoph Hellwig207d0412010-04-28 12:28:56 +0000626 struct xfs_bmbt_irec *imap,
Christoph Hellwig046f1682010-04-28 12:28:52 +0000627 xfs_off_t offset)
Nathan Scott87cbc492006-03-14 13:26:43 +1100628{
629 sector_t bn;
Christoph Hellwig8699bb02010-04-28 12:28:54 +0000630 struct xfs_mount *m = XFS_I(inode)->i_mount;
Christoph Hellwig207d0412010-04-28 12:28:56 +0000631 xfs_off_t iomap_offset = XFS_FSB_TO_B(m, imap->br_startoff);
632 xfs_daddr_t iomap_bn = xfs_fsb_to_db(XFS_I(inode), imap->br_startblock);
Nathan Scott87cbc492006-03-14 13:26:43 +1100633
Christoph Hellwig207d0412010-04-28 12:28:56 +0000634 ASSERT(imap->br_startblock != HOLESTARTBLOCK);
635 ASSERT(imap->br_startblock != DELAYSTARTBLOCK);
Nathan Scott87cbc492006-03-14 13:26:43 +1100636
Christoph Hellwige5131822010-04-28 12:28:55 +0000637 bn = (iomap_bn >> (inode->i_blkbits - BBSHIFT)) +
Christoph Hellwig8699bb02010-04-28 12:28:54 +0000638 ((offset - iomap_offset) >> inode->i_blkbits);
Nathan Scott87cbc492006-03-14 13:26:43 +1100639
Christoph Hellwig046f1682010-04-28 12:28:52 +0000640 ASSERT(bn || XFS_IS_REALTIME_INODE(XFS_I(inode)));
Nathan Scott87cbc492006-03-14 13:26:43 +1100641
642 bh->b_blocknr = bn;
643 set_buffer_mapped(bh);
644}
645
646STATIC void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647xfs_map_at_offset(
Christoph Hellwig046f1682010-04-28 12:28:52 +0000648 struct inode *inode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 struct buffer_head *bh,
Christoph Hellwig207d0412010-04-28 12:28:56 +0000650 struct xfs_bmbt_irec *imap,
Christoph Hellwig046f1682010-04-28 12:28:52 +0000651 xfs_off_t offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652{
Christoph Hellwig207d0412010-04-28 12:28:56 +0000653 ASSERT(imap->br_startblock != HOLESTARTBLOCK);
654 ASSERT(imap->br_startblock != DELAYSTARTBLOCK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655
656 lock_buffer(bh);
Christoph Hellwig207d0412010-04-28 12:28:56 +0000657 xfs_map_buffer(inode, bh, imap, offset);
Christoph Hellwig046f1682010-04-28 12:28:52 +0000658 bh->b_bdev = xfs_find_bdev_for_inode(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 set_buffer_mapped(bh);
660 clear_buffer_delay(bh);
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100661 clear_buffer_unwritten(bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662}
663
664/*
Christoph Hellwig6c4fe192006-01-11 20:49:28 +1100665 * Look for a page at index that is suitable for clustering.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 */
667STATIC unsigned int
Christoph Hellwig6c4fe192006-01-11 20:49:28 +1100668xfs_probe_page(
Christoph Hellwig10ce4442006-01-11 20:48:14 +1100669 struct page *page,
Christoph Hellwig20cb52e2010-06-24 09:46:01 +1000670 unsigned int pg_offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671{
Christoph Hellwig20cb52e2010-06-24 09:46:01 +1000672 struct buffer_head *bh, *head;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 int ret = 0;
674
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 if (PageWriteback(page))
Christoph Hellwig10ce4442006-01-11 20:48:14 +1100676 return 0;
Christoph Hellwig20cb52e2010-06-24 09:46:01 +1000677 if (!PageDirty(page))
678 return 0;
679 if (!page->mapping)
680 return 0;
681 if (!page_has_buffers(page))
682 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683
Christoph Hellwig20cb52e2010-06-24 09:46:01 +1000684 bh = head = page_buffers(page);
685 do {
686 if (!buffer_uptodate(bh))
687 break;
688 if (!buffer_mapped(bh))
689 break;
690 ret += bh->b_size;
691 if (ret >= pg_offset)
692 break;
693 } while ((bh = bh->b_this_page) != head);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 return ret;
696}
697
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100698STATIC size_t
Christoph Hellwig6c4fe192006-01-11 20:49:28 +1100699xfs_probe_cluster(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 struct inode *inode,
701 struct page *startpage,
702 struct buffer_head *bh,
Christoph Hellwig20cb52e2010-06-24 09:46:01 +1000703 struct buffer_head *head)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704{
Christoph Hellwig10ce4442006-01-11 20:48:14 +1100705 struct pagevec pvec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 pgoff_t tindex, tlast, tloff;
Christoph Hellwig10ce4442006-01-11 20:48:14 +1100707 size_t total = 0;
708 int done = 0, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709
710 /* First sum forwards in this page */
711 do {
Christoph Hellwig20cb52e2010-06-24 09:46:01 +1000712 if (!buffer_uptodate(bh) || !buffer_mapped(bh))
Christoph Hellwig10ce4442006-01-11 20:48:14 +1100713 return total;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 total += bh->b_size;
715 } while ((bh = bh->b_this_page) != head);
716
Christoph Hellwig10ce4442006-01-11 20:48:14 +1100717 /* if we reached the end of the page, sum forwards in following pages */
718 tlast = i_size_read(inode) >> PAGE_CACHE_SHIFT;
719 tindex = startpage->index + 1;
720
721 /* Prune this back to avoid pathological behavior */
722 tloff = min(tlast, startpage->index + 64);
723
724 pagevec_init(&pvec, 0);
725 while (!done && tindex <= tloff) {
726 unsigned len = min_t(pgoff_t, PAGEVEC_SIZE, tlast - tindex + 1);
727
728 if (!pagevec_lookup(&pvec, inode->i_mapping, tindex, len))
729 break;
730
731 for (i = 0; i < pagevec_count(&pvec); i++) {
732 struct page *page = pvec.pages[i];
Christoph Hellwig265c1fa2007-08-16 15:38:19 +1000733 size_t pg_offset, pg_len = 0;
Christoph Hellwig10ce4442006-01-11 20:48:14 +1100734
735 if (tindex == tlast) {
736 pg_offset =
737 i_size_read(inode) & (PAGE_CACHE_SIZE - 1);
Christoph Hellwig1defeac2006-01-11 20:48:33 +1100738 if (!pg_offset) {
739 done = 1;
Christoph Hellwig10ce4442006-01-11 20:48:14 +1100740 break;
Christoph Hellwig1defeac2006-01-11 20:48:33 +1100741 }
Christoph Hellwig10ce4442006-01-11 20:48:14 +1100742 } else
743 pg_offset = PAGE_CACHE_SIZE;
744
Nick Piggin529ae9a2008-08-02 12:01:03 +0200745 if (page->index == tindex && trylock_page(page)) {
Christoph Hellwig20cb52e2010-06-24 09:46:01 +1000746 pg_len = xfs_probe_page(page, pg_offset);
Christoph Hellwig10ce4442006-01-11 20:48:14 +1100747 unlock_page(page);
748 }
749
Christoph Hellwig265c1fa2007-08-16 15:38:19 +1000750 if (!pg_len) {
Christoph Hellwig10ce4442006-01-11 20:48:14 +1100751 done = 1;
752 break;
753 }
754
Christoph Hellwig265c1fa2007-08-16 15:38:19 +1000755 total += pg_len;
Christoph Hellwig1defeac2006-01-11 20:48:33 +1100756 tindex++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 }
Christoph Hellwig10ce4442006-01-11 20:48:14 +1100758
759 pagevec_release(&pvec);
760 cond_resched();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 }
Christoph Hellwig10ce4442006-01-11 20:48:14 +1100762
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 return total;
764}
765
766/*
Christoph Hellwig10ce4442006-01-11 20:48:14 +1100767 * Test if a given page is suitable for writing as part of an unwritten
768 * or delayed allocate extent.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 */
Christoph Hellwig10ce4442006-01-11 20:48:14 +1100770STATIC int
771xfs_is_delayed_page(
772 struct page *page,
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100773 unsigned int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 if (PageWriteback(page))
Christoph Hellwig10ce4442006-01-11 20:48:14 +1100776 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777
778 if (page->mapping && page_has_buffers(page)) {
779 struct buffer_head *bh, *head;
780 int acceptable = 0;
781
782 bh = head = page_buffers(page);
783 do {
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100784 if (buffer_unwritten(bh))
Christoph Hellwig34a52c62010-04-28 12:28:57 +0000785 acceptable = (type == IO_UNWRITTEN);
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100786 else if (buffer_delay(bh))
Christoph Hellwiga206c812010-12-10 08:42:20 +0000787 acceptable = (type == IO_DELALLOC);
David Chinner2ddee842006-03-22 12:47:40 +1100788 else if (buffer_dirty(bh) && buffer_mapped(bh))
Christoph Hellwiga206c812010-12-10 08:42:20 +0000789 acceptable = (type == IO_OVERWRITE);
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100790 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 } while ((bh = bh->b_this_page) != head);
793
794 if (acceptable)
Christoph Hellwig10ce4442006-01-11 20:48:14 +1100795 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 }
797
Christoph Hellwig10ce4442006-01-11 20:48:14 +1100798 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799}
800
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801/*
802 * Allocate & map buffers for page given the extent map. Write it out.
803 * except for the original page of a writepage, this is called on
804 * delalloc/unwritten pages only, for the original page it is possible
805 * that the page has no mapping at all.
806 */
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100807STATIC int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808xfs_convert_page(
809 struct inode *inode,
810 struct page *page,
Christoph Hellwig10ce4442006-01-11 20:48:14 +1100811 loff_t tindex,
Christoph Hellwig207d0412010-04-28 12:28:56 +0000812 struct xfs_bmbt_irec *imap,
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100813 xfs_ioend_t **ioendp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 struct writeback_control *wbc,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 int all_bh)
816{
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100817 struct buffer_head *bh, *head;
Christoph Hellwig9260dc62006-01-11 20:48:47 +1100818 xfs_off_t end_offset;
819 unsigned long p_offset;
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100820 unsigned int type;
Nathan Scott24e17b52005-05-05 13:33:20 -0700821 int len, page_dirty;
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100822 int count = 0, done = 0, uptodate = 1;
Christoph Hellwig9260dc62006-01-11 20:48:47 +1100823 xfs_off_t offset = page_offset(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824
Christoph Hellwig10ce4442006-01-11 20:48:14 +1100825 if (page->index != tindex)
826 goto fail;
Nick Piggin529ae9a2008-08-02 12:01:03 +0200827 if (!trylock_page(page))
Christoph Hellwig10ce4442006-01-11 20:48:14 +1100828 goto fail;
829 if (PageWriteback(page))
830 goto fail_unlock_page;
831 if (page->mapping != inode->i_mapping)
832 goto fail_unlock_page;
833 if (!xfs_is_delayed_page(page, (*ioendp)->io_type))
834 goto fail_unlock_page;
835
Nathan Scott24e17b52005-05-05 13:33:20 -0700836 /*
837 * page_dirty is initially a count of buffers on the page before
Nathan Scottc41564b2006-03-29 08:55:14 +1000838 * EOF and is decremented as we move each into a cleanable state.
Christoph Hellwig9260dc62006-01-11 20:48:47 +1100839 *
840 * Derivation:
841 *
842 * End offset is the highest offset that this page should represent.
843 * If we are on the last page, (end_offset & (PAGE_CACHE_SIZE - 1))
844 * will evaluate non-zero and be less than PAGE_CACHE_SIZE and
845 * hence give us the correct page_dirty count. On any other page,
846 * it will be zero and in that case we need page_dirty to be the
847 * count of buffers on the page.
Nathan Scott24e17b52005-05-05 13:33:20 -0700848 */
Christoph Hellwig9260dc62006-01-11 20:48:47 +1100849 end_offset = min_t(unsigned long long,
850 (xfs_off_t)(page->index + 1) << PAGE_CACHE_SHIFT,
851 i_size_read(inode));
852
Nathan Scott24e17b52005-05-05 13:33:20 -0700853 len = 1 << inode->i_blkbits;
Christoph Hellwig9260dc62006-01-11 20:48:47 +1100854 p_offset = min_t(unsigned long, end_offset & (PAGE_CACHE_SIZE - 1),
855 PAGE_CACHE_SIZE);
856 p_offset = p_offset ? roundup(p_offset, len) : PAGE_CACHE_SIZE;
857 page_dirty = p_offset / len;
Nathan Scott24e17b52005-05-05 13:33:20 -0700858
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 bh = head = page_buffers(page);
860 do {
Christoph Hellwig9260dc62006-01-11 20:48:47 +1100861 if (offset >= end_offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 break;
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100863 if (!buffer_uptodate(bh))
864 uptodate = 0;
865 if (!(PageUptodate(page) || buffer_uptodate(bh))) {
866 done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 continue;
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100868 }
869
Christoph Hellwig9260dc62006-01-11 20:48:47 +1100870 if (buffer_unwritten(bh) || buffer_delay(bh)) {
871 if (buffer_unwritten(bh))
Christoph Hellwig34a52c62010-04-28 12:28:57 +0000872 type = IO_UNWRITTEN;
Christoph Hellwig9260dc62006-01-11 20:48:47 +1100873 else
Christoph Hellwiga206c812010-12-10 08:42:20 +0000874 type = IO_DELALLOC;
Christoph Hellwig9260dc62006-01-11 20:48:47 +1100875
Christoph Hellwig558e6892010-04-28 12:28:58 +0000876 if (!xfs_imap_valid(inode, imap, offset)) {
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100877 done = 1;
Christoph Hellwig9260dc62006-01-11 20:48:47 +1100878 continue;
879 }
880
Christoph Hellwig207d0412010-04-28 12:28:56 +0000881 ASSERT(imap->br_startblock != HOLESTARTBLOCK);
882 ASSERT(imap->br_startblock != DELAYSTARTBLOCK);
Christoph Hellwig9260dc62006-01-11 20:48:47 +1100883
Christoph Hellwig207d0412010-04-28 12:28:56 +0000884 xfs_map_at_offset(inode, bh, imap, offset);
Christoph Hellwig89f3b362010-06-24 09:45:48 +1000885 xfs_add_to_ioend(inode, bh, offset, type,
886 ioendp, done);
887
Christoph Hellwig9260dc62006-01-11 20:48:47 +1100888 page_dirty--;
889 count++;
890 } else {
Christoph Hellwiga206c812010-12-10 08:42:20 +0000891 type = IO_OVERWRITE;
Christoph Hellwig89f3b362010-06-24 09:45:48 +1000892 if (buffer_mapped(bh) && all_bh) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 lock_buffer(bh);
Christoph Hellwig7336cea2006-01-11 20:49:16 +1100894 xfs_add_to_ioend(inode, bh, offset,
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100895 type, ioendp, done);
896 count++;
Nathan Scott24e17b52005-05-05 13:33:20 -0700897 page_dirty--;
Christoph Hellwig9260dc62006-01-11 20:48:47 +1100898 } else {
899 done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 }
Christoph Hellwig7336cea2006-01-11 20:49:16 +1100902 } while (offset += len, (bh = bh->b_this_page) != head);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100904 if (uptodate && bh == head)
905 SetPageUptodate(page);
906
Christoph Hellwig89f3b362010-06-24 09:45:48 +1000907 if (count) {
Dave Chinnerefceab12010-08-24 11:44:56 +1000908 if (--wbc->nr_to_write <= 0 &&
909 wbc->sync_mode == WB_SYNC_NONE)
Christoph Hellwig89f3b362010-06-24 09:45:48 +1000910 done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 }
Christoph Hellwig89f3b362010-06-24 09:45:48 +1000912 xfs_start_page_writeback(page, !page_dirty, count);
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100913
914 return done;
Christoph Hellwig10ce4442006-01-11 20:48:14 +1100915 fail_unlock_page:
916 unlock_page(page);
917 fail:
918 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919}
920
921/*
922 * Convert & write out a cluster of pages in the same extent as defined
923 * by mp and following the start page.
924 */
925STATIC void
926xfs_cluster_write(
927 struct inode *inode,
928 pgoff_t tindex,
Christoph Hellwig207d0412010-04-28 12:28:56 +0000929 struct xfs_bmbt_irec *imap,
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +1100930 xfs_ioend_t **ioendp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 struct writeback_control *wbc,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 int all_bh,
933 pgoff_t tlast)
934{
Christoph Hellwig10ce4442006-01-11 20:48:14 +1100935 struct pagevec pvec;
936 int done = 0, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937
Christoph Hellwig10ce4442006-01-11 20:48:14 +1100938 pagevec_init(&pvec, 0);
939 while (!done && tindex <= tlast) {
940 unsigned len = min_t(pgoff_t, PAGEVEC_SIZE, tlast - tindex + 1);
941
942 if (!pagevec_lookup(&pvec, inode->i_mapping, tindex, len))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 break;
Christoph Hellwig10ce4442006-01-11 20:48:14 +1100944
945 for (i = 0; i < pagevec_count(&pvec); i++) {
946 done = xfs_convert_page(inode, pvec.pages[i], tindex++,
Christoph Hellwig89f3b362010-06-24 09:45:48 +1000947 imap, ioendp, wbc, all_bh);
Christoph Hellwig10ce4442006-01-11 20:48:14 +1100948 if (done)
949 break;
950 }
951
952 pagevec_release(&pvec);
953 cond_resched();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 }
955}
956
Dave Chinner3ed3a432010-03-05 02:00:42 +0000957STATIC void
958xfs_vm_invalidatepage(
959 struct page *page,
960 unsigned long offset)
961{
962 trace_xfs_invalidatepage(page->mapping->host, page, offset);
963 block_invalidatepage(page, offset);
964}
965
966/*
967 * If the page has delalloc buffers on it, we need to punch them out before we
968 * invalidate the page. If we don't, we leave a stale delalloc mapping on the
969 * inode that can trip a BUG() in xfs_get_blocks() later on if a direct IO read
970 * is done on that same region - the delalloc extent is returned when none is
971 * supposed to be there.
972 *
973 * We prevent this by truncating away the delalloc regions on the page before
974 * invalidating it. Because they are delalloc, we can do this without needing a
975 * transaction. Indeed - if we get ENOSPC errors, we have to be able to do this
976 * truncation without a transaction as there is no space left for block
977 * reservation (typically why we see a ENOSPC in writeback).
978 *
979 * This is not a performance critical path, so for now just do the punching a
980 * buffer head at a time.
981 */
982STATIC void
983xfs_aops_discard_page(
984 struct page *page)
985{
986 struct inode *inode = page->mapping->host;
987 struct xfs_inode *ip = XFS_I(inode);
988 struct buffer_head *bh, *head;
989 loff_t offset = page_offset(page);
Dave Chinner3ed3a432010-03-05 02:00:42 +0000990
Christoph Hellwiga206c812010-12-10 08:42:20 +0000991 if (!xfs_is_delayed_page(page, IO_DELALLOC))
Dave Chinner3ed3a432010-03-05 02:00:42 +0000992 goto out_invalidate;
993
Dave Chinnere8c37532010-03-15 02:36:35 +0000994 if (XFS_FORCED_SHUTDOWN(ip->i_mount))
995 goto out_invalidate;
996
Dave Chinner3ed3a432010-03-05 02:00:42 +0000997 xfs_fs_cmn_err(CE_ALERT, ip->i_mount,
998 "page discard on page %p, inode 0x%llx, offset %llu.",
999 page, ip->i_ino, offset);
1000
1001 xfs_ilock(ip, XFS_ILOCK_EXCL);
1002 bh = head = page_buffers(page);
1003 do {
Dave Chinner3ed3a432010-03-05 02:00:42 +00001004 int error;
Dave Chinnerc726de42010-11-30 15:14:39 +11001005 xfs_fileoff_t start_fsb;
Dave Chinner3ed3a432010-03-05 02:00:42 +00001006
1007 if (!buffer_delay(bh))
1008 goto next_buffer;
1009
Dave Chinnerc726de42010-11-30 15:14:39 +11001010 start_fsb = XFS_B_TO_FSBT(ip->i_mount, offset);
1011 error = xfs_bmap_punch_delalloc_range(ip, start_fsb, 1);
Dave Chinner3ed3a432010-03-05 02:00:42 +00001012 if (error) {
1013 /* something screwed, just bail */
Dave Chinnere8c37532010-03-15 02:36:35 +00001014 if (!XFS_FORCED_SHUTDOWN(ip->i_mount)) {
1015 xfs_fs_cmn_err(CE_ALERT, ip->i_mount,
Dave Chinner3ed3a432010-03-05 02:00:42 +00001016 "page discard unable to remove delalloc mapping.");
Dave Chinnere8c37532010-03-15 02:36:35 +00001017 }
Dave Chinner3ed3a432010-03-05 02:00:42 +00001018 break;
1019 }
1020next_buffer:
Dave Chinnerc726de42010-11-30 15:14:39 +11001021 offset += 1 << inode->i_blkbits;
Dave Chinner3ed3a432010-03-05 02:00:42 +00001022
1023 } while ((bh = bh->b_this_page) != head);
1024
1025 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1026out_invalidate:
1027 xfs_vm_invalidatepage(page, 0);
1028 return;
1029}
1030
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031/*
Christoph Hellwig89f3b362010-06-24 09:45:48 +10001032 * Write out a dirty page.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 *
Christoph Hellwig89f3b362010-06-24 09:45:48 +10001034 * For delalloc space on the page we need to allocate space and flush it.
1035 * For unwritten space on the page we need to start the conversion to
1036 * regular allocated space.
Christoph Hellwig89f3b362010-06-24 09:45:48 +10001037 * For any other dirty buffer heads on the page we should flush them.
1038 *
1039 * If we detect that a transaction would be required to flush the page, we
1040 * have to check the process flags first, if we are already in a transaction
1041 * or disk I/O during allocations is off, we need to fail the writepage and
1042 * redirty the page.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044STATIC int
Christoph Hellwig89f3b362010-06-24 09:45:48 +10001045xfs_vm_writepage(
1046 struct page *page,
1047 struct writeback_control *wbc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048{
Christoph Hellwig89f3b362010-06-24 09:45:48 +10001049 struct inode *inode = page->mapping->host;
Christoph Hellwig20cb52e2010-06-24 09:46:01 +10001050 int delalloc, unwritten;
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +11001051 struct buffer_head *bh, *head;
Christoph Hellwig207d0412010-04-28 12:28:56 +00001052 struct xfs_bmbt_irec imap;
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +11001053 xfs_ioend_t *ioend = NULL, *iohead = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 loff_t offset;
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +11001055 unsigned int type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 __uint64_t end_offset;
Christoph Hellwigbd1556a2010-04-28 12:29:00 +00001057 pgoff_t end_index, last_index;
Christoph Hellwigd5cb48a2006-01-11 20:49:02 +11001058 ssize_t size, len;
Christoph Hellwiga206c812010-12-10 08:42:20 +00001059 int err, imap_valid = 0, uptodate = 1;
Christoph Hellwig89f3b362010-06-24 09:45:48 +10001060 int count = 0;
Christoph Hellwig20cb52e2010-06-24 09:46:01 +10001061 int all_bh = 0;
Christoph Hellwiga206c812010-12-10 08:42:20 +00001062 int nonblocking = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063
Christoph Hellwig89f3b362010-06-24 09:45:48 +10001064 trace_xfs_writepage(inode, page, 0);
1065
Christoph Hellwig20cb52e2010-06-24 09:46:01 +10001066 ASSERT(page_has_buffers(page));
1067
Christoph Hellwig89f3b362010-06-24 09:45:48 +10001068 /*
1069 * Refuse to write the page out if we are called from reclaim context.
1070 *
Christoph Hellwigd4f7a5c2010-06-28 10:34:44 -04001071 * This avoids stack overflows when called from deeply used stacks in
1072 * random callers for direct reclaim or memcg reclaim. We explicitly
1073 * allow reclaim from kswapd as the stack usage there is relatively low.
Christoph Hellwig89f3b362010-06-24 09:45:48 +10001074 *
1075 * This should really be done by the core VM, but until that happens
1076 * filesystems like XFS, btrfs and ext4 have to take care of this
1077 * by themselves.
1078 */
Christoph Hellwigd4f7a5c2010-06-28 10:34:44 -04001079 if ((current->flags & (PF_MEMALLOC|PF_KSWAPD)) == PF_MEMALLOC)
Christoph Hellwigb5420f22010-08-24 11:47:51 +10001080 goto redirty;
Christoph Hellwig89f3b362010-06-24 09:45:48 +10001081
1082 /*
Christoph Hellwig20cb52e2010-06-24 09:46:01 +10001083 * We need a transaction if there are delalloc or unwritten buffers
1084 * on the page.
1085 *
1086 * If we need a transaction and the process flags say we are already
1087 * in a transaction, or no IO is allowed then mark the page dirty
1088 * again and leave the page as is.
Christoph Hellwig89f3b362010-06-24 09:45:48 +10001089 */
Christoph Hellwig20cb52e2010-06-24 09:46:01 +10001090 xfs_count_page_state(page, &delalloc, &unwritten);
1091 if ((current->flags & PF_FSTRANS) && (delalloc || unwritten))
Christoph Hellwigb5420f22010-08-24 11:47:51 +10001092 goto redirty;
Christoph Hellwig89f3b362010-06-24 09:45:48 +10001093
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 /* Is this page beyond the end of the file? */
1095 offset = i_size_read(inode);
1096 end_index = offset >> PAGE_CACHE_SHIFT;
1097 last_index = (offset - 1) >> PAGE_CACHE_SHIFT;
1098 if (page->index >= end_index) {
1099 if ((page->index >= end_index + 1) ||
1100 !(i_size_read(inode) & (PAGE_CACHE_SIZE - 1))) {
Christoph Hellwig89f3b362010-06-24 09:45:48 +10001101 unlock_page(page);
Nathan Scott19d5bcf2005-11-02 15:14:09 +11001102 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 }
1104 }
1105
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +11001106 end_offset = min_t(unsigned long long,
Christoph Hellwig20cb52e2010-06-24 09:46:01 +10001107 (xfs_off_t)(page->index + 1) << PAGE_CACHE_SHIFT,
1108 offset);
Nathan Scott24e17b52005-05-05 13:33:20 -07001109 len = 1 << inode->i_blkbits;
Nathan Scott24e17b52005-05-05 13:33:20 -07001110
Nathan Scott24e17b52005-05-05 13:33:20 -07001111 bh = head = page_buffers(page);
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +11001112 offset = page_offset(page);
Christoph Hellwiga206c812010-12-10 08:42:20 +00001113 type = IO_OVERWRITE;
1114
1115 if (wbc->sync_mode == WB_SYNC_NONE && wbc->nonblocking)
1116 nonblocking = 1;
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +11001117
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 do {
Christoph Hellwig6ac72482010-12-10 08:42:18 +00001119 int new_ioend = 0;
1120
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 if (offset >= end_offset)
1122 break;
1123 if (!buffer_uptodate(bh))
1124 uptodate = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125
Eric Sandeen3d9b02e2010-06-24 09:45:30 +10001126 /*
Christoph Hellwigece413f2010-11-10 21:39:11 +00001127 * set_page_dirty dirties all buffers in a page, independent
1128 * of their state. The dirty state however is entirely
1129 * meaningless for holes (!mapped && uptodate), so skip
1130 * buffers covering holes here.
Eric Sandeen3d9b02e2010-06-24 09:45:30 +10001131 */
1132 if (!buffer_mapped(bh) && buffer_uptodate(bh)) {
Eric Sandeen3d9b02e2010-06-24 09:45:30 +10001133 imap_valid = 0;
1134 continue;
1135 }
1136
Christoph Hellwig558e6892010-04-28 12:28:58 +00001137 if (imap_valid)
1138 imap_valid = xfs_imap_valid(inode, &imap, offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139
Christoph Hellwig20cb52e2010-06-24 09:46:01 +10001140 if (buffer_unwritten(bh) || buffer_delay(bh)) {
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +11001141 if (buffer_unwritten(bh)) {
Christoph Hellwig85da94c2010-12-10 08:42:16 +00001142 if (type != IO_UNWRITTEN) {
1143 type = IO_UNWRITTEN;
1144 imap_valid = 0;
1145 }
Christoph Hellwigd5cb48a2006-01-11 20:49:02 +11001146 } else if (buffer_delay(bh)) {
Christoph Hellwiga206c812010-12-10 08:42:20 +00001147 if (type != IO_DELALLOC) {
1148 type = IO_DELALLOC;
Christoph Hellwig85da94c2010-12-10 08:42:16 +00001149 imap_valid = 0;
1150 }
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +11001151 }
1152
Christoph Hellwig558e6892010-04-28 12:28:58 +00001153 if (!imap_valid) {
David Chinnereffd1202007-06-18 16:49:58 +10001154 /*
Christoph Hellwig20cb52e2010-06-24 09:46:01 +10001155 * If we didn't have a valid mapping then we
David Chinnereffd1202007-06-18 16:49:58 +10001156 * need to ensure that we put the new mapping
1157 * in a new ioend structure. This needs to be
1158 * done to ensure that the ioends correctly
1159 * reflect the block mappings at io completion
1160 * for unwritten extent conversion.
1161 */
1162 new_ioend = 1;
Christoph Hellwiga206c812010-12-10 08:42:20 +00001163 err = xfs_map_blocks(inode, offset, len, &imap,
1164 type, nonblocking);
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +11001165 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 goto error;
Christoph Hellwig558e6892010-04-28 12:28:58 +00001167 imap_valid = xfs_imap_valid(inode, &imap,
1168 offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 }
Christoph Hellwig558e6892010-04-28 12:28:58 +00001170 if (imap_valid) {
Christoph Hellwig207d0412010-04-28 12:28:56 +00001171 xfs_map_at_offset(inode, bh, &imap, offset);
Christoph Hellwig89f3b362010-06-24 09:45:48 +10001172 xfs_add_to_ioend(inode, bh, offset, type,
1173 &ioend, new_ioend);
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +11001174 count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 }
Christoph Hellwig89f3b362010-06-24 09:45:48 +10001176 } else if (buffer_uptodate(bh)) {
Christoph Hellwig6c4fe192006-01-11 20:49:28 +11001177 /*
1178 * we got here because the buffer is already mapped.
1179 * That means it must already have extents allocated
1180 * underneath it. Map the extent by reading it.
1181 */
Christoph Hellwiga206c812010-12-10 08:42:20 +00001182 if (type != IO_OVERWRITE) {
1183 type = IO_OVERWRITE;
Christoph Hellwig85da94c2010-12-10 08:42:16 +00001184 imap_valid = 0;
1185 }
1186 if (!imap_valid) {
Christoph Hellwig6ac72482010-12-10 08:42:18 +00001187 new_ioend = 1;
Christoph Hellwig20cb52e2010-06-24 09:46:01 +10001188 size = xfs_probe_cluster(inode, page, bh, head);
Christoph Hellwig6c4fe192006-01-11 20:49:28 +11001189 err = xfs_map_blocks(inode, offset, size,
Christoph Hellwiga206c812010-12-10 08:42:20 +00001190 &imap, type, nonblocking);
Christoph Hellwig6c4fe192006-01-11 20:49:28 +11001191 if (err)
1192 goto error;
Christoph Hellwig558e6892010-04-28 12:28:58 +00001193 imap_valid = xfs_imap_valid(inode, &imap,
1194 offset);
Christoph Hellwig6c4fe192006-01-11 20:49:28 +11001195 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196
Christoph Hellwig6ac72482010-12-10 08:42:18 +00001197 if (imap_valid) {
1198 all_bh = 1;
1199 lock_buffer(bh);
Christoph Hellwig7336cea2006-01-11 20:49:16 +11001200 xfs_add_to_ioend(inode, bh, offset, type,
Christoph Hellwig6ac72482010-12-10 08:42:18 +00001201 &ioend, new_ioend);
Christoph Hellwigd5cb48a2006-01-11 20:49:02 +11001202 count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 }
Christoph Hellwig89f3b362010-06-24 09:45:48 +10001204 } else if (PageUptodate(page)) {
Christoph Hellwig20cb52e2010-06-24 09:46:01 +10001205 ASSERT(buffer_mapped(bh));
Christoph Hellwig558e6892010-04-28 12:28:58 +00001206 imap_valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 }
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +11001208
1209 if (!iohead)
1210 iohead = ioend;
1211
1212 } while (offset += len, ((bh = bh->b_this_page) != head));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213
1214 if (uptodate && bh == head)
1215 SetPageUptodate(page);
1216
Christoph Hellwig89f3b362010-06-24 09:45:48 +10001217 xfs_start_page_writeback(page, 1, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218
Christoph Hellwig558e6892010-04-28 12:28:58 +00001219 if (ioend && imap_valid) {
Christoph Hellwigbd1556a2010-04-28 12:29:00 +00001220 xfs_off_t end_index;
Christoph Hellwig8699bb02010-04-28 12:28:54 +00001221
Christoph Hellwigbd1556a2010-04-28 12:29:00 +00001222 end_index = imap.br_startoff + imap.br_blockcount;
1223
1224 /* to bytes */
1225 end_index <<= inode->i_blkbits;
1226
1227 /* to pages */
1228 end_index = (end_index - 1) >> PAGE_CACHE_SHIFT;
1229
1230 /* check against file size */
1231 if (end_index > last_index)
1232 end_index = last_index;
1233
Christoph Hellwig207d0412010-04-28 12:28:56 +00001234 xfs_cluster_write(inode, page->index + 1, &imap, &ioend,
Christoph Hellwig89f3b362010-06-24 09:45:48 +10001235 wbc, all_bh, end_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 }
1237
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +11001238 if (iohead)
Christoph Hellwig06342cf2009-10-30 09:09:15 +00001239 xfs_submit_ioend(wbc, iohead);
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +11001240
Christoph Hellwig89f3b362010-06-24 09:45:48 +10001241 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242
1243error:
Christoph Hellwigf6d6d4f2006-01-11 15:40:13 +11001244 if (iohead)
1245 xfs_cancel_ioend(iohead);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246
Christoph Hellwigb5420f22010-08-24 11:47:51 +10001247 if (err == -EAGAIN)
1248 goto redirty;
1249
Christoph Hellwig20cb52e2010-06-24 09:46:01 +10001250 xfs_aops_discard_page(page);
Christoph Hellwig89f3b362010-06-24 09:45:48 +10001251 ClearPageUptodate(page);
1252 unlock_page(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 return err;
Nathan Scottf51623b2006-03-14 13:26:27 +11001254
Christoph Hellwigb5420f22010-08-24 11:47:51 +10001255redirty:
Nathan Scottf51623b2006-03-14 13:26:27 +11001256 redirty_page_for_writepage(wbc, page);
1257 unlock_page(page);
1258 return 0;
Nathan Scottf51623b2006-03-14 13:26:27 +11001259}
1260
Nathan Scott7d4fb402006-06-09 15:27:16 +10001261STATIC int
1262xfs_vm_writepages(
1263 struct address_space *mapping,
1264 struct writeback_control *wbc)
1265{
Christoph Hellwigb3aea4e2007-08-29 11:44:37 +10001266 xfs_iflags_clear(XFS_I(mapping->host), XFS_ITRUNCATED);
Nathan Scott7d4fb402006-06-09 15:27:16 +10001267 return generic_writepages(mapping, wbc);
1268}
1269
Nathan Scottf51623b2006-03-14 13:26:27 +11001270/*
1271 * Called to move a page into cleanable state - and from there
Christoph Hellwig89f3b362010-06-24 09:45:48 +10001272 * to be released. The page should already be clean. We always
Nathan Scottf51623b2006-03-14 13:26:27 +11001273 * have buffer heads in this call.
1274 *
Christoph Hellwig89f3b362010-06-24 09:45:48 +10001275 * Returns 1 if the page is ok to release, 0 otherwise.
Nathan Scottf51623b2006-03-14 13:26:27 +11001276 */
1277STATIC int
Nathan Scott238f4c52006-03-17 17:26:25 +11001278xfs_vm_releasepage(
Nathan Scottf51623b2006-03-14 13:26:27 +11001279 struct page *page,
1280 gfp_t gfp_mask)
1281{
Christoph Hellwig20cb52e2010-06-24 09:46:01 +10001282 int delalloc, unwritten;
Nathan Scottf51623b2006-03-14 13:26:27 +11001283
Christoph Hellwig89f3b362010-06-24 09:45:48 +10001284 trace_xfs_releasepage(page->mapping->host, page, 0);
Nathan Scott238f4c52006-03-17 17:26:25 +11001285
Christoph Hellwig20cb52e2010-06-24 09:46:01 +10001286 xfs_count_page_state(page, &delalloc, &unwritten);
Nathan Scottf51623b2006-03-14 13:26:27 +11001287
Christoph Hellwig89f3b362010-06-24 09:45:48 +10001288 if (WARN_ON(delalloc))
1289 return 0;
1290 if (WARN_ON(unwritten))
Nathan Scottf51623b2006-03-14 13:26:27 +11001291 return 0;
1292
Nathan Scottf51623b2006-03-14 13:26:27 +11001293 return try_to_free_buffers(page);
1294}
1295
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296STATIC int
Nathan Scottc2536662006-03-29 10:44:40 +10001297__xfs_get_blocks(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 struct inode *inode,
1299 sector_t iblock,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 struct buffer_head *bh_result,
1301 int create,
Christoph Hellwigf2bde9b2010-06-24 11:44:35 +10001302 int direct)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303{
Christoph Hellwiga206c812010-12-10 08:42:20 +00001304 struct xfs_inode *ip = XFS_I(inode);
1305 struct xfs_mount *mp = ip->i_mount;
1306 xfs_fileoff_t offset_fsb, end_fsb;
1307 int error = 0;
1308 int lockmode = 0;
Christoph Hellwig207d0412010-04-28 12:28:56 +00001309 struct xfs_bmbt_irec imap;
Christoph Hellwiga206c812010-12-10 08:42:20 +00001310 int nimaps = 1;
Nathan Scottfdc7ed72005-11-02 15:13:13 +11001311 xfs_off_t offset;
1312 ssize_t size;
Christoph Hellwig207d0412010-04-28 12:28:56 +00001313 int new = 0;
Christoph Hellwiga206c812010-12-10 08:42:20 +00001314
1315 if (XFS_FORCED_SHUTDOWN(mp))
1316 return -XFS_ERROR(EIO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317
Nathan Scottfdc7ed72005-11-02 15:13:13 +11001318 offset = (xfs_off_t)iblock << inode->i_blkbits;
Nathan Scottc2536662006-03-29 10:44:40 +10001319 ASSERT(bh_result->b_size >= (1 << inode->i_blkbits));
1320 size = bh_result->b_size;
Lachlan McIlroy364f3582008-09-17 16:50:14 +10001321
1322 if (!create && direct && offset >= i_size_read(inode))
1323 return 0;
1324
Christoph Hellwiga206c812010-12-10 08:42:20 +00001325 if (create) {
1326 lockmode = XFS_ILOCK_EXCL;
1327 xfs_ilock(ip, lockmode);
1328 } else {
1329 lockmode = xfs_ilock_map_shared(ip);
1330 }
Christoph Hellwigf2bde9b2010-06-24 11:44:35 +10001331
Christoph Hellwiga206c812010-12-10 08:42:20 +00001332 ASSERT(offset <= mp->m_maxioffset);
1333 if (offset + size > mp->m_maxioffset)
1334 size = mp->m_maxioffset - offset;
1335 end_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)offset + size);
1336 offset_fsb = XFS_B_TO_FSBT(mp, offset);
1337
1338 error = xfs_bmapi(NULL, ip, offset_fsb, end_fsb - offset_fsb,
1339 XFS_BMAPI_ENTIRE, NULL, 0, &imap, &nimaps, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 if (error)
Christoph Hellwiga206c812010-12-10 08:42:20 +00001341 goto out_unlock;
1342
1343 if (create &&
1344 (!nimaps ||
1345 (imap.br_startblock == HOLESTARTBLOCK ||
1346 imap.br_startblock == DELAYSTARTBLOCK))) {
1347 if (direct) {
1348 error = xfs_iomap_write_direct(ip, offset, size,
1349 &imap, nimaps);
1350 } else {
1351 error = xfs_iomap_write_delay(ip, offset, size, &imap);
1352 }
1353 if (error)
1354 goto out_unlock;
1355
1356 trace_xfs_get_blocks_alloc(ip, offset, size, 0, &imap);
1357 } else if (nimaps) {
1358 trace_xfs_get_blocks_found(ip, offset, size, 0, &imap);
1359 } else {
1360 trace_xfs_get_blocks_notfound(ip, offset, size);
1361 goto out_unlock;
1362 }
1363 xfs_iunlock(ip, lockmode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364
Christoph Hellwig207d0412010-04-28 12:28:56 +00001365 if (imap.br_startblock != HOLESTARTBLOCK &&
1366 imap.br_startblock != DELAYSTARTBLOCK) {
Nathan Scott87cbc492006-03-14 13:26:43 +11001367 /*
1368 * For unwritten extents do not report a disk address on
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 * the read case (treat as if we're reading into a hole).
1370 */
Christoph Hellwig207d0412010-04-28 12:28:56 +00001371 if (create || !ISUNWRITTEN(&imap))
1372 xfs_map_buffer(inode, bh_result, &imap, offset);
1373 if (create && ISUNWRITTEN(&imap)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 if (direct)
1375 bh_result->b_private = inode;
1376 set_buffer_unwritten(bh_result);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 }
1378 }
1379
Nathan Scottc2536662006-03-29 10:44:40 +10001380 /*
1381 * If this is a realtime file, data may be on a different device.
1382 * to that pointed to from the buffer_head b_bdev currently.
1383 */
Christoph Hellwig046f1682010-04-28 12:28:52 +00001384 bh_result->b_bdev = xfs_find_bdev_for_inode(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385
Nathan Scottc2536662006-03-29 10:44:40 +10001386 /*
David Chinner549054a2007-02-10 18:36:35 +11001387 * If we previously allocated a block out beyond eof and we are now
1388 * coming back to use it then we will need to flag it as new even if it
1389 * has a disk address.
1390 *
1391 * With sub-block writes into unwritten extents we also need to mark
1392 * the buffer as new so that the unwritten parts of the buffer gets
1393 * correctly zeroed.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 */
1395 if (create &&
1396 ((!buffer_mapped(bh_result) && !buffer_uptodate(bh_result)) ||
David Chinner549054a2007-02-10 18:36:35 +11001397 (offset >= i_size_read(inode)) ||
Christoph Hellwig207d0412010-04-28 12:28:56 +00001398 (new || ISUNWRITTEN(&imap))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 set_buffer_new(bh_result);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400
Christoph Hellwig207d0412010-04-28 12:28:56 +00001401 if (imap.br_startblock == DELAYSTARTBLOCK) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 BUG_ON(direct);
1403 if (create) {
1404 set_buffer_uptodate(bh_result);
1405 set_buffer_mapped(bh_result);
1406 set_buffer_delay(bh_result);
1407 }
1408 }
1409
Christoph Hellwig2b8f12b2010-04-28 12:28:59 +00001410 /*
1411 * If this is O_DIRECT or the mpage code calling tell them how large
1412 * the mapping is, so that we can avoid repeated get_blocks calls.
1413 */
Nathan Scottc2536662006-03-29 10:44:40 +10001414 if (direct || size > (1 << inode->i_blkbits)) {
Christoph Hellwig2b8f12b2010-04-28 12:28:59 +00001415 xfs_off_t mapping_size;
Christoph Hellwig9563b3d2010-04-28 12:28:53 +00001416
Christoph Hellwig2b8f12b2010-04-28 12:28:59 +00001417 mapping_size = imap.br_startoff + imap.br_blockcount - iblock;
1418 mapping_size <<= inode->i_blkbits;
1419
1420 ASSERT(mapping_size > 0);
1421 if (mapping_size > size)
1422 mapping_size = size;
1423 if (mapping_size > LONG_MAX)
1424 mapping_size = LONG_MAX;
1425
1426 bh_result->b_size = mapping_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 }
1428
1429 return 0;
Christoph Hellwiga206c812010-12-10 08:42:20 +00001430
1431out_unlock:
1432 xfs_iunlock(ip, lockmode);
1433 return -error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434}
1435
1436int
Nathan Scottc2536662006-03-29 10:44:40 +10001437xfs_get_blocks(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 struct inode *inode,
1439 sector_t iblock,
1440 struct buffer_head *bh_result,
1441 int create)
1442{
Christoph Hellwigf2bde9b2010-06-24 11:44:35 +10001443 return __xfs_get_blocks(inode, iblock, bh_result, create, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444}
1445
1446STATIC int
Nathan Scotte4c573b2006-03-14 13:54:26 +11001447xfs_get_blocks_direct(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 struct inode *inode,
1449 sector_t iblock,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 struct buffer_head *bh_result,
1451 int create)
1452{
Christoph Hellwigf2bde9b2010-06-24 11:44:35 +10001453 return __xfs_get_blocks(inode, iblock, bh_result, create, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454}
1455
Christoph Hellwig209fb872010-07-18 21:17:11 +00001456/*
1457 * Complete a direct I/O write request.
1458 *
1459 * If the private argument is non-NULL __xfs_get_blocks signals us that we
1460 * need to issue a transaction to convert the range from unwritten to written
1461 * extents. In case this is regular synchronous I/O we just call xfs_end_io
1462 * to do this and we are done. But in case this was a successfull AIO
1463 * request this handler is called from interrupt context, from which we
1464 * can't start transactions. In that case offload the I/O completion to
1465 * the workqueues we also use for buffered I/O completion.
1466 */
Christoph Hellwigf0973862005-09-05 08:22:52 +10001467STATIC void
Christoph Hellwig209fb872010-07-18 21:17:11 +00001468xfs_end_io_direct_write(
1469 struct kiocb *iocb,
1470 loff_t offset,
1471 ssize_t size,
1472 void *private,
1473 int ret,
1474 bool is_async)
Christoph Hellwigf0973862005-09-05 08:22:52 +10001475{
Christoph Hellwig209fb872010-07-18 21:17:11 +00001476 struct xfs_ioend *ioend = iocb->private;
Christoph Hellwigf0973862005-09-05 08:22:52 +10001477
1478 /*
Nathan Scottc41564b2006-03-29 08:55:14 +10001479 * blockdev_direct_IO can return an error even after the I/O
Christoph Hellwigf0973862005-09-05 08:22:52 +10001480 * completion handler was called. Thus we need to protect
1481 * against double-freeing.
1482 */
1483 iocb->private = NULL;
Christoph Hellwig40e2e972010-07-18 21:17:09 +00001484
Christoph Hellwig209fb872010-07-18 21:17:11 +00001485 ioend->io_offset = offset;
1486 ioend->io_size = size;
1487 if (private && size > 0)
1488 ioend->io_type = IO_UNWRITTEN;
1489
1490 if (is_async) {
1491 /*
1492 * If we are converting an unwritten extent we need to delay
1493 * the AIO completion until after the unwrittent extent
1494 * conversion has completed, otherwise do it ASAP.
1495 */
1496 if (ioend->io_type == IO_UNWRITTEN) {
1497 ioend->io_iocb = iocb;
1498 ioend->io_result = ret;
1499 } else {
1500 aio_complete(iocb, ret, 0);
1501 }
1502 xfs_finish_ioend(ioend);
1503 } else {
1504 xfs_finish_ioend_sync(ioend);
1505 }
Christoph Hellwigf0973862005-09-05 08:22:52 +10001506}
1507
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508STATIC ssize_t
Nathan Scotte4c573b2006-03-14 13:54:26 +11001509xfs_vm_direct_IO(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 int rw,
1511 struct kiocb *iocb,
1512 const struct iovec *iov,
1513 loff_t offset,
1514 unsigned long nr_segs)
1515{
Christoph Hellwig209fb872010-07-18 21:17:11 +00001516 struct inode *inode = iocb->ki_filp->f_mapping->host;
1517 struct block_device *bdev = xfs_find_bdev_for_inode(inode);
1518 ssize_t ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519
Christoph Hellwig209fb872010-07-18 21:17:11 +00001520 if (rw & WRITE) {
Christoph Hellwiga206c812010-12-10 08:42:20 +00001521 iocb->private = xfs_alloc_ioend(inode, IO_DIRECT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522
Christoph Hellwigeafdc7d2010-06-04 11:29:53 +02001523 ret = __blockdev_direct_IO(rw, iocb, inode, bdev, iov,
1524 offset, nr_segs,
1525 xfs_get_blocks_direct,
1526 xfs_end_io_direct_write, NULL, 0);
Christoph Hellwig209fb872010-07-18 21:17:11 +00001527 if (ret != -EIOCBQUEUED && iocb->private)
1528 xfs_destroy_ioend(iocb->private);
1529 } else {
Christoph Hellwigeafdc7d2010-06-04 11:29:53 +02001530 ret = __blockdev_direct_IO(rw, iocb, inode, bdev, iov,
1531 offset, nr_segs,
1532 xfs_get_blocks_direct,
1533 NULL, NULL, 0);
Christoph Hellwig209fb872010-07-18 21:17:11 +00001534 }
Christoph Hellwig5fe878a2009-12-15 16:47:50 -08001535
Christoph Hellwigf0973862005-09-05 08:22:52 +10001536 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537}
1538
Christoph Hellwigfa9b2272010-06-14 05:17:31 -04001539STATIC void
1540xfs_vm_write_failed(
1541 struct address_space *mapping,
1542 loff_t to)
1543{
1544 struct inode *inode = mapping->host;
1545
1546 if (to > inode->i_size) {
Dave Chinnerc726de42010-11-30 15:14:39 +11001547 /*
1548 * punch out the delalloc blocks we have already allocated. We
1549 * don't call xfs_setattr() to do this as we may be in the
1550 * middle of a multi-iovec write and so the vfs inode->i_size
1551 * will not match the xfs ip->i_size and so it will zero too
1552 * much. Hence we jus truncate the page cache to zero what is
1553 * necessary and punch the delalloc blocks directly.
1554 */
1555 struct xfs_inode *ip = XFS_I(inode);
1556 xfs_fileoff_t start_fsb;
1557 xfs_fileoff_t end_fsb;
1558 int error;
1559
1560 truncate_pagecache(inode, to, inode->i_size);
1561
1562 /*
1563 * Check if there are any blocks that are outside of i_size
1564 * that need to be trimmed back.
1565 */
1566 start_fsb = XFS_B_TO_FSB(ip->i_mount, inode->i_size) + 1;
1567 end_fsb = XFS_B_TO_FSB(ip->i_mount, to);
1568 if (end_fsb <= start_fsb)
1569 return;
1570
1571 xfs_ilock(ip, XFS_ILOCK_EXCL);
1572 error = xfs_bmap_punch_delalloc_range(ip, start_fsb,
1573 end_fsb - start_fsb);
1574 if (error) {
1575 /* something screwed, just bail */
1576 if (!XFS_FORCED_SHUTDOWN(ip->i_mount)) {
1577 xfs_fs_cmn_err(CE_ALERT, ip->i_mount,
1578 "xfs_vm_write_failed: unable to clean up ino %lld",
1579 ip->i_ino);
1580 }
1581 }
1582 xfs_iunlock(ip, XFS_ILOCK_EXCL);
Christoph Hellwigfa9b2272010-06-14 05:17:31 -04001583 }
1584}
1585
Nathan Scottf51623b2006-03-14 13:26:27 +11001586STATIC int
Nick Piggind79689c2007-10-16 01:25:06 -07001587xfs_vm_write_begin(
Nathan Scottf51623b2006-03-14 13:26:27 +11001588 struct file *file,
Nick Piggind79689c2007-10-16 01:25:06 -07001589 struct address_space *mapping,
1590 loff_t pos,
1591 unsigned len,
1592 unsigned flags,
1593 struct page **pagep,
1594 void **fsdata)
Nathan Scottf51623b2006-03-14 13:26:27 +11001595{
Christoph Hellwig155130a2010-06-04 11:29:58 +02001596 int ret;
1597
1598 ret = block_write_begin(mapping, pos, len, flags | AOP_FLAG_NOFS,
1599 pagep, xfs_get_blocks);
Christoph Hellwigfa9b2272010-06-14 05:17:31 -04001600 if (unlikely(ret))
1601 xfs_vm_write_failed(mapping, pos + len);
1602 return ret;
1603}
Christoph Hellwig155130a2010-06-04 11:29:58 +02001604
Christoph Hellwigfa9b2272010-06-14 05:17:31 -04001605STATIC int
1606xfs_vm_write_end(
1607 struct file *file,
1608 struct address_space *mapping,
1609 loff_t pos,
1610 unsigned len,
1611 unsigned copied,
1612 struct page *page,
1613 void *fsdata)
1614{
1615 int ret;
1616
1617 ret = generic_write_end(file, mapping, pos, len, copied, page, fsdata);
1618 if (unlikely(ret < len))
1619 xfs_vm_write_failed(mapping, pos + len);
Christoph Hellwig155130a2010-06-04 11:29:58 +02001620 return ret;
Nathan Scottf51623b2006-03-14 13:26:27 +11001621}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622
1623STATIC sector_t
Nathan Scotte4c573b2006-03-14 13:54:26 +11001624xfs_vm_bmap(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 struct address_space *mapping,
1626 sector_t block)
1627{
1628 struct inode *inode = (struct inode *)mapping->host;
Christoph Hellwig739bfb22007-08-29 10:58:01 +10001629 struct xfs_inode *ip = XFS_I(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630
Christoph Hellwigcca28fb2010-06-24 11:57:09 +10001631 trace_xfs_vm_bmap(XFS_I(inode));
Christoph Hellwig126468b2008-03-06 13:44:57 +11001632 xfs_ilock(ip, XFS_IOLOCK_SHARED);
Christoph Hellwig739bfb22007-08-29 10:58:01 +10001633 xfs_flush_pages(ip, (xfs_off_t)0, -1, 0, FI_REMAPF);
Christoph Hellwig126468b2008-03-06 13:44:57 +11001634 xfs_iunlock(ip, XFS_IOLOCK_SHARED);
Nathan Scottc2536662006-03-29 10:44:40 +10001635 return generic_block_bmap(mapping, block, xfs_get_blocks);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636}
1637
1638STATIC int
Nathan Scotte4c573b2006-03-14 13:54:26 +11001639xfs_vm_readpage(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 struct file *unused,
1641 struct page *page)
1642{
Nathan Scottc2536662006-03-29 10:44:40 +10001643 return mpage_readpage(page, xfs_get_blocks);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644}
1645
1646STATIC int
Nathan Scotte4c573b2006-03-14 13:54:26 +11001647xfs_vm_readpages(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648 struct file *unused,
1649 struct address_space *mapping,
1650 struct list_head *pages,
1651 unsigned nr_pages)
1652{
Nathan Scottc2536662006-03-29 10:44:40 +10001653 return mpage_readpages(mapping, pages, nr_pages, xfs_get_blocks);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654}
1655
Christoph Hellwigf5e54d62006-06-28 04:26:44 -07001656const struct address_space_operations xfs_address_space_operations = {
Nathan Scotte4c573b2006-03-14 13:54:26 +11001657 .readpage = xfs_vm_readpage,
1658 .readpages = xfs_vm_readpages,
1659 .writepage = xfs_vm_writepage,
Nathan Scott7d4fb402006-06-09 15:27:16 +10001660 .writepages = xfs_vm_writepages,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 .sync_page = block_sync_page,
Nathan Scott238f4c52006-03-17 17:26:25 +11001662 .releasepage = xfs_vm_releasepage,
1663 .invalidatepage = xfs_vm_invalidatepage,
Nick Piggind79689c2007-10-16 01:25:06 -07001664 .write_begin = xfs_vm_write_begin,
Christoph Hellwigfa9b2272010-06-14 05:17:31 -04001665 .write_end = xfs_vm_write_end,
Nathan Scotte4c573b2006-03-14 13:54:26 +11001666 .bmap = xfs_vm_bmap,
1667 .direct_IO = xfs_vm_direct_IO,
Christoph Lametere965f962006-02-01 03:05:41 -08001668 .migratepage = buffer_migrate_page,
Hisashi Hifumibddaafa2009-03-29 09:53:38 +02001669 .is_partially_uptodate = block_is_partially_uptodate,
Andi Kleenaa261f52009-09-16 11:50:16 +02001670 .error_remove_page = generic_error_remove_page,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671};