Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 2 | * Copyright (c) 2000-2005 Silicon Graphics, Inc. |
| 3 | * All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * published by the Free Software Foundation. |
| 8 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 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. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include "xfs.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 19 | #include "xfs_bit.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include "xfs_log.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 21 | #include "xfs_inum.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include "xfs_sb.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 23 | #include "xfs_ag.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include "xfs_trans.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include "xfs_mount.h" |
| 26 | #include "xfs_bmap_btree.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include "xfs_dinode.h" |
| 28 | #include "xfs_inode.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 29 | #include "xfs_alloc.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include "xfs_error.h" |
| 31 | #include "xfs_rw.h" |
| 32 | #include "xfs_iomap.h" |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 33 | #include "xfs_vnodeops.h" |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 34 | #include "xfs_trace.h" |
Dave Chinner | 3ed3a43 | 2010-03-05 02:00:42 +0000 | [diff] [blame] | 35 | #include "xfs_bmap.h" |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 36 | #include <linux/gfp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <linux/mpage.h> |
Christoph Hellwig | 10ce444 | 2006-01-11 20:48:14 +1100 | [diff] [blame] | 38 | #include <linux/pagevec.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/writeback.h> |
| 40 | |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 41 | void |
Nathan Scott | f51623b | 2006-03-14 13:26:27 +1100 | [diff] [blame] | 42 | xfs_count_page_state( |
| 43 | struct page *page, |
| 44 | int *delalloc, |
Nathan Scott | f51623b | 2006-03-14 13:26:27 +1100 | [diff] [blame] | 45 | int *unwritten) |
| 46 | { |
| 47 | struct buffer_head *bh, *head; |
| 48 | |
Christoph Hellwig | 20cb52e | 2010-06-24 09:46:01 +1000 | [diff] [blame] | 49 | *delalloc = *unwritten = 0; |
Nathan Scott | f51623b | 2006-03-14 13:26:27 +1100 | [diff] [blame] | 50 | |
| 51 | bh = head = page_buffers(page); |
| 52 | do { |
Christoph Hellwig | 20cb52e | 2010-06-24 09:46:01 +1000 | [diff] [blame] | 53 | if (buffer_unwritten(bh)) |
Nathan Scott | f51623b | 2006-03-14 13:26:27 +1100 | [diff] [blame] | 54 | (*unwritten) = 1; |
| 55 | else if (buffer_delay(bh)) |
| 56 | (*delalloc) = 1; |
| 57 | } while ((bh = bh->b_this_page) != head); |
| 58 | } |
| 59 | |
Christoph Hellwig | 6214ed4 | 2007-09-14 15:23:17 +1000 | [diff] [blame] | 60 | STATIC struct block_device * |
| 61 | xfs_find_bdev_for_inode( |
Christoph Hellwig | 046f168 | 2010-04-28 12:28:52 +0000 | [diff] [blame] | 62 | struct inode *inode) |
Christoph Hellwig | 6214ed4 | 2007-09-14 15:23:17 +1000 | [diff] [blame] | 63 | { |
Christoph Hellwig | 046f168 | 2010-04-28 12:28:52 +0000 | [diff] [blame] | 64 | struct xfs_inode *ip = XFS_I(inode); |
Christoph Hellwig | 6214ed4 | 2007-09-14 15:23:17 +1000 | [diff] [blame] | 65 | struct xfs_mount *mp = ip->i_mount; |
| 66 | |
Eric Sandeen | 71ddabb | 2007-11-23 16:29:42 +1100 | [diff] [blame] | 67 | if (XFS_IS_REALTIME_INODE(ip)) |
Christoph Hellwig | 6214ed4 | 2007-09-14 15:23:17 +1000 | [diff] [blame] | 68 | return mp->m_rtdev_targp->bt_bdev; |
| 69 | else |
| 70 | return mp->m_ddev_targp->bt_bdev; |
| 71 | } |
| 72 | |
Christoph Hellwig | 0829c36 | 2005-09-02 16:58:49 +1000 | [diff] [blame] | 73 | /* |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 74 | * We're now finished for good with this ioend structure. |
| 75 | * Update the page state via the associated buffer_heads, |
| 76 | * release holds on the inode and bio, and finally free |
| 77 | * up memory. Do not use the ioend after this. |
| 78 | */ |
Christoph Hellwig | 0829c36 | 2005-09-02 16:58:49 +1000 | [diff] [blame] | 79 | STATIC void |
| 80 | xfs_destroy_ioend( |
| 81 | xfs_ioend_t *ioend) |
| 82 | { |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 83 | struct buffer_head *bh, *next; |
| 84 | |
| 85 | for (bh = ioend->io_buffer_head; bh; bh = next) { |
| 86 | next = bh->b_private; |
Nathan Scott | 7d04a33 | 2006-06-09 14:58:38 +1000 | [diff] [blame] | 87 | bh->b_end_io(bh, !ioend->io_error); |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 88 | } |
Christoph Hellwig | 583fa58 | 2008-12-03 12:20:38 +0100 | [diff] [blame] | 89 | |
Christoph Hellwig | c859cdd | 2011-08-23 08:28:10 +0000 | [diff] [blame] | 90 | if (ioend->io_iocb) { |
Christoph Hellwig | 04f658e | 2011-08-24 05:59:25 +0000 | [diff] [blame] | 91 | if (ioend->io_isasync) { |
| 92 | aio_complete(ioend->io_iocb, ioend->io_error ? |
| 93 | ioend->io_error : ioend->io_result, 0); |
| 94 | } |
Christoph Hellwig | c859cdd | 2011-08-23 08:28:10 +0000 | [diff] [blame] | 95 | inode_dio_done(ioend->io_inode); |
| 96 | } |
Christoph Hellwig | 4a06fd2 | 2011-08-23 08:28:13 +0000 | [diff] [blame] | 97 | |
Christoph Hellwig | 0829c36 | 2005-09-02 16:58:49 +1000 | [diff] [blame] | 98 | mempool_free(ioend, xfs_ioend_pool); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | /* |
Christoph Hellwig | fc0063c | 2011-08-23 08:28:11 +0000 | [diff] [blame] | 102 | * Fast and loose check if this write could update the on-disk inode size. |
| 103 | */ |
| 104 | static inline bool xfs_ioend_is_append(struct xfs_ioend *ioend) |
| 105 | { |
| 106 | return ioend->io_offset + ioend->io_size > |
| 107 | XFS_I(ioend->io_inode)->i_d.di_size; |
| 108 | } |
| 109 | |
| 110 | /* |
Christoph Hellwig | 2813d68 | 2011-12-18 20:00:12 +0000 | [diff] [blame] | 111 | * Update on-disk file size now that data has been written to disk. |
Lachlan McIlroy | ba87ea6 | 2007-05-08 13:49:46 +1000 | [diff] [blame] | 112 | */ |
Christoph Hellwig | aa6bf01 | 2012-02-29 09:53:48 +0000 | [diff] [blame] | 113 | STATIC void |
Lachlan McIlroy | ba87ea6 | 2007-05-08 13:49:46 +1000 | [diff] [blame] | 114 | xfs_setfilesize( |
Christoph Hellwig | aa6bf01 | 2012-02-29 09:53:48 +0000 | [diff] [blame] | 115 | struct xfs_ioend *ioend) |
Lachlan McIlroy | ba87ea6 | 2007-05-08 13:49:46 +1000 | [diff] [blame] | 116 | { |
Christoph Hellwig | aa6bf01 | 2012-02-29 09:53:48 +0000 | [diff] [blame] | 117 | struct xfs_inode *ip = XFS_I(ioend->io_inode); |
Lachlan McIlroy | ba87ea6 | 2007-05-08 13:49:46 +1000 | [diff] [blame] | 118 | xfs_fsize_t isize; |
Lachlan McIlroy | ba87ea6 | 2007-05-08 13:49:46 +1000 | [diff] [blame] | 119 | |
Christoph Hellwig | aa6bf01 | 2012-02-29 09:53:48 +0000 | [diff] [blame] | 120 | xfs_ilock(ip, XFS_ILOCK_EXCL); |
Christoph Hellwig | 6923e68 | 2012-02-29 09:53:49 +0000 | [diff] [blame] | 121 | isize = xfs_new_eof(ip, ioend->io_offset + ioend->io_size); |
Dave Chinner | 932640e | 2009-10-06 20:29:29 +0000 | [diff] [blame] | 122 | if (isize) { |
Dave Chinner | 55fb25d5 | 2011-07-18 03:40:19 +0000 | [diff] [blame] | 123 | trace_xfs_setfilesize(ip, ioend->io_offset, ioend->io_size); |
Lachlan McIlroy | ba87ea6 | 2007-05-08 13:49:46 +1000 | [diff] [blame] | 124 | ip->i_d.di_size = isize; |
Christoph Hellwig | 66d834e | 2010-02-15 09:44:49 +0000 | [diff] [blame] | 125 | xfs_mark_inode_dirty(ip); |
Lachlan McIlroy | ba87ea6 | 2007-05-08 13:49:46 +1000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | xfs_iunlock(ip, XFS_ILOCK_EXCL); |
Christoph Hellwig | 0829c36 | 2005-09-02 16:58:49 +1000 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | /* |
Christoph Hellwig | 209fb87 | 2010-07-18 21:17:11 +0000 | [diff] [blame] | 132 | * Schedule IO completion handling on the final put of an ioend. |
Christoph Hellwig | fc0063c | 2011-08-23 08:28:11 +0000 | [diff] [blame] | 133 | * |
| 134 | * If there is no work to do we might as well call it a day and free the |
| 135 | * ioend right now. |
Dave Chinner | c626d17 | 2009-04-06 18:42:11 +0200 | [diff] [blame] | 136 | */ |
| 137 | STATIC void |
| 138 | xfs_finish_ioend( |
Christoph Hellwig | 209fb87 | 2010-07-18 21:17:11 +0000 | [diff] [blame] | 139 | struct xfs_ioend *ioend) |
Dave Chinner | c626d17 | 2009-04-06 18:42:11 +0200 | [diff] [blame] | 140 | { |
| 141 | if (atomic_dec_and_test(&ioend->io_remaining)) { |
Christoph Hellwig | aa6bf01 | 2012-02-29 09:53:48 +0000 | [diff] [blame] | 142 | struct xfs_mount *mp = XFS_I(ioend->io_inode)->i_mount; |
| 143 | |
Christoph Hellwig | 209fb87 | 2010-07-18 21:17:11 +0000 | [diff] [blame] | 144 | if (ioend->io_type == IO_UNWRITTEN) |
Christoph Hellwig | aa6bf01 | 2012-02-29 09:53:48 +0000 | [diff] [blame] | 145 | queue_work(mp->m_unwritten_workqueue, &ioend->io_work); |
Christoph Hellwig | fc0063c | 2011-08-23 08:28:11 +0000 | [diff] [blame] | 146 | else if (xfs_ioend_is_append(ioend)) |
Christoph Hellwig | aa6bf01 | 2012-02-29 09:53:48 +0000 | [diff] [blame] | 147 | queue_work(mp->m_data_workqueue, &ioend->io_work); |
Christoph Hellwig | fc0063c | 2011-08-23 08:28:11 +0000 | [diff] [blame] | 148 | else |
| 149 | xfs_destroy_ioend(ioend); |
Dave Chinner | c626d17 | 2009-04-06 18:42:11 +0200 | [diff] [blame] | 150 | } |
| 151 | } |
| 152 | |
| 153 | /* |
Dave Chinner | 77d7a0c | 2010-02-17 05:36:29 +0000 | [diff] [blame] | 154 | * IO write completion. |
| 155 | */ |
| 156 | STATIC void |
| 157 | xfs_end_io( |
| 158 | struct work_struct *work) |
| 159 | { |
| 160 | xfs_ioend_t *ioend = container_of(work, xfs_ioend_t, io_work); |
| 161 | struct xfs_inode *ip = XFS_I(ioend->io_inode); |
Dave Chinner | 6941893 | 2010-03-04 00:57:09 +0000 | [diff] [blame] | 162 | int error = 0; |
Dave Chinner | 77d7a0c | 2010-02-17 05:36:29 +0000 | [diff] [blame] | 163 | |
Christoph Hellwig | 04f658e | 2011-08-24 05:59:25 +0000 | [diff] [blame] | 164 | if (XFS_FORCED_SHUTDOWN(ip->i_mount)) { |
Christoph Hellwig | 810627d | 2011-11-08 08:56:15 +0000 | [diff] [blame] | 165 | ioend->io_error = -EIO; |
Christoph Hellwig | 04f658e | 2011-08-24 05:59:25 +0000 | [diff] [blame] | 166 | goto done; |
| 167 | } |
| 168 | if (ioend->io_error) |
| 169 | goto done; |
| 170 | |
Dave Chinner | 77d7a0c | 2010-02-17 05:36:29 +0000 | [diff] [blame] | 171 | /* |
| 172 | * For unwritten extents we need to issue transactions to convert a |
| 173 | * range to normal written extens after the data I/O has finished. |
| 174 | */ |
Christoph Hellwig | 04f658e | 2011-08-24 05:59:25 +0000 | [diff] [blame] | 175 | if (ioend->io_type == IO_UNWRITTEN) { |
Dave Chinner | 77d7a0c | 2010-02-17 05:36:29 +0000 | [diff] [blame] | 176 | error = xfs_iomap_write_unwritten(ip, ioend->io_offset, |
| 177 | ioend->io_size); |
Christoph Hellwig | 04f658e | 2011-08-24 05:59:25 +0000 | [diff] [blame] | 178 | if (error) { |
| 179 | ioend->io_error = -error; |
| 180 | goto done; |
| 181 | } |
Christoph Hellwig | 84803fb | 2012-02-29 09:53:50 +0000 | [diff] [blame^] | 182 | } else { |
| 183 | /* |
| 184 | * We might have to update the on-disk file size after |
| 185 | * extending writes. |
| 186 | */ |
| 187 | xfs_setfilesize(ioend); |
Dave Chinner | 77d7a0c | 2010-02-17 05:36:29 +0000 | [diff] [blame] | 188 | } |
| 189 | |
Christoph Hellwig | 04f658e | 2011-08-24 05:59:25 +0000 | [diff] [blame] | 190 | done: |
Christoph Hellwig | aa6bf01 | 2012-02-29 09:53:48 +0000 | [diff] [blame] | 191 | xfs_destroy_ioend(ioend); |
Dave Chinner | 77d7a0c | 2010-02-17 05:36:29 +0000 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | /* |
Christoph Hellwig | 209fb87 | 2010-07-18 21:17:11 +0000 | [diff] [blame] | 195 | * Call IO completion handling in caller context on the final put of an ioend. |
| 196 | */ |
| 197 | STATIC void |
| 198 | xfs_finish_ioend_sync( |
| 199 | struct xfs_ioend *ioend) |
| 200 | { |
| 201 | if (atomic_dec_and_test(&ioend->io_remaining)) |
| 202 | xfs_end_io(&ioend->io_work); |
| 203 | } |
| 204 | |
| 205 | /* |
Christoph Hellwig | 0829c36 | 2005-09-02 16:58:49 +1000 | [diff] [blame] | 206 | * Allocate and initialise an IO completion structure. |
| 207 | * We need to track unwritten extent write completion here initially. |
| 208 | * We'll need to extend this for updating the ondisk inode size later |
| 209 | * (vs. incore size). |
| 210 | */ |
| 211 | STATIC xfs_ioend_t * |
| 212 | xfs_alloc_ioend( |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 213 | struct inode *inode, |
| 214 | unsigned int type) |
Christoph Hellwig | 0829c36 | 2005-09-02 16:58:49 +1000 | [diff] [blame] | 215 | { |
| 216 | xfs_ioend_t *ioend; |
| 217 | |
| 218 | ioend = mempool_alloc(xfs_ioend_pool, GFP_NOFS); |
| 219 | |
| 220 | /* |
| 221 | * Set the count to 1 initially, which will prevent an I/O |
| 222 | * completion callback from happening before we have started |
| 223 | * all the I/O from calling the completion routine too early. |
| 224 | */ |
| 225 | atomic_set(&ioend->io_remaining, 1); |
Christoph Hellwig | c859cdd | 2011-08-23 08:28:10 +0000 | [diff] [blame] | 226 | ioend->io_isasync = 0; |
Nathan Scott | 7d04a33 | 2006-06-09 14:58:38 +1000 | [diff] [blame] | 227 | ioend->io_error = 0; |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 228 | ioend->io_list = NULL; |
| 229 | ioend->io_type = type; |
Christoph Hellwig | b677c21 | 2007-08-29 11:46:28 +1000 | [diff] [blame] | 230 | ioend->io_inode = inode; |
Christoph Hellwig | c1a073b | 2005-09-05 08:23:35 +1000 | [diff] [blame] | 231 | ioend->io_buffer_head = NULL; |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 232 | ioend->io_buffer_tail = NULL; |
Christoph Hellwig | 0829c36 | 2005-09-02 16:58:49 +1000 | [diff] [blame] | 233 | ioend->io_offset = 0; |
| 234 | ioend->io_size = 0; |
Christoph Hellwig | fb511f2 | 2010-07-18 21:17:10 +0000 | [diff] [blame] | 235 | ioend->io_iocb = NULL; |
| 236 | ioend->io_result = 0; |
Christoph Hellwig | 0829c36 | 2005-09-02 16:58:49 +1000 | [diff] [blame] | 237 | |
Christoph Hellwig | 5ec4fab | 2009-10-30 09:11:47 +0000 | [diff] [blame] | 238 | INIT_WORK(&ioend->io_work, xfs_end_io); |
Christoph Hellwig | 0829c36 | 2005-09-02 16:58:49 +1000 | [diff] [blame] | 239 | return ioend; |
| 240 | } |
| 241 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | STATIC int |
| 243 | xfs_map_blocks( |
| 244 | struct inode *inode, |
| 245 | loff_t offset, |
Christoph Hellwig | 207d041 | 2010-04-28 12:28:56 +0000 | [diff] [blame] | 246 | struct xfs_bmbt_irec *imap, |
Christoph Hellwig | a206c81 | 2010-12-10 08:42:20 +0000 | [diff] [blame] | 247 | int type, |
| 248 | int nonblocking) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | { |
Christoph Hellwig | a206c81 | 2010-12-10 08:42:20 +0000 | [diff] [blame] | 250 | struct xfs_inode *ip = XFS_I(inode); |
| 251 | struct xfs_mount *mp = ip->i_mount; |
Christoph Hellwig | ed1e7b7 | 2010-12-10 08:42:22 +0000 | [diff] [blame] | 252 | ssize_t count = 1 << inode->i_blkbits; |
Christoph Hellwig | a206c81 | 2010-12-10 08:42:20 +0000 | [diff] [blame] | 253 | xfs_fileoff_t offset_fsb, end_fsb; |
| 254 | int error = 0; |
Christoph Hellwig | a206c81 | 2010-12-10 08:42:20 +0000 | [diff] [blame] | 255 | int bmapi_flags = XFS_BMAPI_ENTIRE; |
| 256 | int nimaps = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | |
Christoph Hellwig | a206c81 | 2010-12-10 08:42:20 +0000 | [diff] [blame] | 258 | if (XFS_FORCED_SHUTDOWN(mp)) |
| 259 | return -XFS_ERROR(EIO); |
| 260 | |
Christoph Hellwig | 8ff2957 | 2010-12-10 08:42:21 +0000 | [diff] [blame] | 261 | if (type == IO_UNWRITTEN) |
Christoph Hellwig | a206c81 | 2010-12-10 08:42:20 +0000 | [diff] [blame] | 262 | bmapi_flags |= XFS_BMAPI_IGSTATE; |
Christoph Hellwig | a206c81 | 2010-12-10 08:42:20 +0000 | [diff] [blame] | 263 | |
Christoph Hellwig | 8ff2957 | 2010-12-10 08:42:21 +0000 | [diff] [blame] | 264 | if (!xfs_ilock_nowait(ip, XFS_ILOCK_SHARED)) { |
| 265 | if (nonblocking) |
| 266 | return -XFS_ERROR(EAGAIN); |
| 267 | xfs_ilock(ip, XFS_ILOCK_SHARED); |
Christoph Hellwig | a206c81 | 2010-12-10 08:42:20 +0000 | [diff] [blame] | 268 | } |
| 269 | |
Christoph Hellwig | 8ff2957 | 2010-12-10 08:42:21 +0000 | [diff] [blame] | 270 | ASSERT(ip->i_d.di_format != XFS_DINODE_FMT_BTREE || |
| 271 | (ip->i_df.if_flags & XFS_IFEXTENTS)); |
Christoph Hellwig | a206c81 | 2010-12-10 08:42:20 +0000 | [diff] [blame] | 272 | ASSERT(offset <= mp->m_maxioffset); |
Christoph Hellwig | 8ff2957 | 2010-12-10 08:42:21 +0000 | [diff] [blame] | 273 | |
Christoph Hellwig | a206c81 | 2010-12-10 08:42:20 +0000 | [diff] [blame] | 274 | if (offset + count > mp->m_maxioffset) |
| 275 | count = mp->m_maxioffset - offset; |
| 276 | end_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)offset + count); |
| 277 | offset_fsb = XFS_B_TO_FSBT(mp, offset); |
Dave Chinner | 5c8ed20 | 2011-09-18 20:40:45 +0000 | [diff] [blame] | 278 | error = xfs_bmapi_read(ip, offset_fsb, end_fsb - offset_fsb, |
| 279 | imap, &nimaps, bmapi_flags); |
Christoph Hellwig | 8ff2957 | 2010-12-10 08:42:21 +0000 | [diff] [blame] | 280 | xfs_iunlock(ip, XFS_ILOCK_SHARED); |
| 281 | |
Christoph Hellwig | a206c81 | 2010-12-10 08:42:20 +0000 | [diff] [blame] | 282 | if (error) |
Christoph Hellwig | 8ff2957 | 2010-12-10 08:42:21 +0000 | [diff] [blame] | 283 | return -XFS_ERROR(error); |
Christoph Hellwig | a206c81 | 2010-12-10 08:42:20 +0000 | [diff] [blame] | 284 | |
Christoph Hellwig | 8ff2957 | 2010-12-10 08:42:21 +0000 | [diff] [blame] | 285 | if (type == IO_DELALLOC && |
| 286 | (!nimaps || isnullstartblock(imap->br_startblock))) { |
Christoph Hellwig | a206c81 | 2010-12-10 08:42:20 +0000 | [diff] [blame] | 287 | error = xfs_iomap_write_allocate(ip, offset, count, imap); |
| 288 | if (!error) |
| 289 | trace_xfs_map_blocks_alloc(ip, offset, count, type, imap); |
Christoph Hellwig | 8ff2957 | 2010-12-10 08:42:21 +0000 | [diff] [blame] | 290 | return -XFS_ERROR(error); |
Christoph Hellwig | a206c81 | 2010-12-10 08:42:20 +0000 | [diff] [blame] | 291 | } |
| 292 | |
Christoph Hellwig | 8ff2957 | 2010-12-10 08:42:21 +0000 | [diff] [blame] | 293 | #ifdef DEBUG |
| 294 | if (type == IO_UNWRITTEN) { |
| 295 | ASSERT(nimaps); |
| 296 | ASSERT(imap->br_startblock != HOLESTARTBLOCK); |
| 297 | ASSERT(imap->br_startblock != DELAYSTARTBLOCK); |
| 298 | } |
| 299 | #endif |
| 300 | if (nimaps) |
| 301 | trace_xfs_map_blocks_found(ip, offset, count, type, imap); |
| 302 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | } |
| 304 | |
Christoph Hellwig | b8f82a4 | 2009-11-14 16:17:22 +0000 | [diff] [blame] | 305 | STATIC int |
Christoph Hellwig | 558e689 | 2010-04-28 12:28:58 +0000 | [diff] [blame] | 306 | xfs_imap_valid( |
Christoph Hellwig | 8699bb0 | 2010-04-28 12:28:54 +0000 | [diff] [blame] | 307 | struct inode *inode, |
Christoph Hellwig | 207d041 | 2010-04-28 12:28:56 +0000 | [diff] [blame] | 308 | struct xfs_bmbt_irec *imap, |
Christoph Hellwig | 558e689 | 2010-04-28 12:28:58 +0000 | [diff] [blame] | 309 | xfs_off_t offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | { |
Christoph Hellwig | 558e689 | 2010-04-28 12:28:58 +0000 | [diff] [blame] | 311 | offset >>= inode->i_blkbits; |
Christoph Hellwig | 8699bb0 | 2010-04-28 12:28:54 +0000 | [diff] [blame] | 312 | |
Christoph Hellwig | 558e689 | 2010-04-28 12:28:58 +0000 | [diff] [blame] | 313 | return offset >= imap->br_startoff && |
| 314 | offset < imap->br_startoff + imap->br_blockcount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | } |
| 316 | |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 317 | /* |
| 318 | * BIO completion handler for buffered IO. |
| 319 | */ |
Al Viro | 782e3b3 | 2007-10-12 07:17:47 +0100 | [diff] [blame] | 320 | STATIC void |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 321 | xfs_end_bio( |
| 322 | struct bio *bio, |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 323 | int error) |
| 324 | { |
| 325 | xfs_ioend_t *ioend = bio->bi_private; |
| 326 | |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 327 | ASSERT(atomic_read(&bio->bi_cnt) >= 1); |
Nathan Scott | 7d04a33 | 2006-06-09 14:58:38 +1000 | [diff] [blame] | 328 | ioend->io_error = test_bit(BIO_UPTODATE, &bio->bi_flags) ? 0 : error; |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 329 | |
| 330 | /* Toss bio and pass work off to an xfsdatad thread */ |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 331 | bio->bi_private = NULL; |
| 332 | bio->bi_end_io = NULL; |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 333 | bio_put(bio); |
Nathan Scott | 7d04a33 | 2006-06-09 14:58:38 +1000 | [diff] [blame] | 334 | |
Christoph Hellwig | 209fb87 | 2010-07-18 21:17:11 +0000 | [diff] [blame] | 335 | xfs_finish_ioend(ioend); |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | STATIC void |
| 339 | xfs_submit_ioend_bio( |
Christoph Hellwig | 06342cf | 2009-10-30 09:09:15 +0000 | [diff] [blame] | 340 | struct writeback_control *wbc, |
| 341 | xfs_ioend_t *ioend, |
| 342 | struct bio *bio) |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 343 | { |
Christoph Hellwig | 6923e68 | 2012-02-29 09:53:49 +0000 | [diff] [blame] | 344 | struct xfs_inode *ip = XFS_I(ioend->io_inode); |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 345 | atomic_inc(&ioend->io_remaining); |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 346 | bio->bi_private = ioend; |
| 347 | bio->bi_end_io = xfs_end_bio; |
| 348 | |
Dave Chinner | 932640e | 2009-10-06 20:29:29 +0000 | [diff] [blame] | 349 | /* |
| 350 | * If the I/O is beyond EOF we mark the inode dirty immediately |
| 351 | * but don't update the inode size until I/O completion. |
| 352 | */ |
Christoph Hellwig | 6923e68 | 2012-02-29 09:53:49 +0000 | [diff] [blame] | 353 | if (xfs_new_eof(ip, ioend->io_offset + ioend->io_size)) |
| 354 | xfs_mark_inode_dirty(ip); |
Dave Chinner | 932640e | 2009-10-06 20:29:29 +0000 | [diff] [blame] | 355 | |
Jens Axboe | 721a960 | 2011-03-09 11:56:30 +0100 | [diff] [blame] | 356 | submit_bio(wbc->sync_mode == WB_SYNC_ALL ? WRITE_SYNC : WRITE, bio); |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | STATIC struct bio * |
| 360 | xfs_alloc_ioend_bio( |
| 361 | struct buffer_head *bh) |
| 362 | { |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 363 | int nvecs = bio_get_nr_vecs(bh->b_bdev); |
Christoph Hellwig | 221cb25 | 2010-12-10 08:42:17 +0000 | [diff] [blame] | 364 | struct bio *bio = bio_alloc(GFP_NOIO, nvecs); |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 365 | |
| 366 | ASSERT(bio->bi_private == NULL); |
| 367 | bio->bi_sector = bh->b_blocknr * (bh->b_size >> 9); |
| 368 | bio->bi_bdev = bh->b_bdev; |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 369 | return bio; |
| 370 | } |
| 371 | |
| 372 | STATIC void |
| 373 | xfs_start_buffer_writeback( |
| 374 | struct buffer_head *bh) |
| 375 | { |
| 376 | ASSERT(buffer_mapped(bh)); |
| 377 | ASSERT(buffer_locked(bh)); |
| 378 | ASSERT(!buffer_delay(bh)); |
| 379 | ASSERT(!buffer_unwritten(bh)); |
| 380 | |
| 381 | mark_buffer_async_write(bh); |
| 382 | set_buffer_uptodate(bh); |
| 383 | clear_buffer_dirty(bh); |
| 384 | } |
| 385 | |
| 386 | STATIC void |
| 387 | xfs_start_page_writeback( |
| 388 | struct page *page, |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 389 | int clear_dirty, |
| 390 | int buffers) |
| 391 | { |
| 392 | ASSERT(PageLocked(page)); |
| 393 | ASSERT(!PageWriteback(page)); |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 394 | if (clear_dirty) |
David Chinner | 9213202 | 2006-12-21 10:24:01 +1100 | [diff] [blame] | 395 | clear_page_dirty_for_io(page); |
| 396 | set_page_writeback(page); |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 397 | unlock_page(page); |
Fengguang Wu | 1f7decf | 2007-10-16 23:30:42 -0700 | [diff] [blame] | 398 | /* If no buffers on the page are to be written, finish it here */ |
| 399 | if (!buffers) |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 400 | end_page_writeback(page); |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | static inline int bio_add_buffer(struct bio *bio, struct buffer_head *bh) |
| 404 | { |
| 405 | return bio_add_page(bio, bh->b_page, bh->b_size, bh_offset(bh)); |
| 406 | } |
| 407 | |
| 408 | /* |
David Chinner | d88992f | 2006-01-18 13:38:12 +1100 | [diff] [blame] | 409 | * Submit all of the bios for all of the ioends we have saved up, covering the |
| 410 | * initial writepage page and also any probed pages. |
| 411 | * |
| 412 | * Because we may have multiple ioends spanning a page, we need to start |
| 413 | * writeback on all the buffers before we submit them for I/O. If we mark the |
| 414 | * buffers as we got, then we can end up with a page that only has buffers |
| 415 | * marked async write and I/O complete on can occur before we mark the other |
| 416 | * buffers async write. |
| 417 | * |
| 418 | * The end result of this is that we trip a bug in end_page_writeback() because |
| 419 | * we call it twice for the one page as the code in end_buffer_async_write() |
| 420 | * assumes that all buffers on the page are started at the same time. |
| 421 | * |
| 422 | * The fix is two passes across the ioend list - one to start writeback on the |
Nathan Scott | c41564b | 2006-03-29 08:55:14 +1000 | [diff] [blame] | 423 | * buffer_heads, and then submit them for I/O on the second pass. |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 424 | */ |
| 425 | STATIC void |
| 426 | xfs_submit_ioend( |
Christoph Hellwig | 06342cf | 2009-10-30 09:09:15 +0000 | [diff] [blame] | 427 | struct writeback_control *wbc, |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 428 | xfs_ioend_t *ioend) |
| 429 | { |
David Chinner | d88992f | 2006-01-18 13:38:12 +1100 | [diff] [blame] | 430 | xfs_ioend_t *head = ioend; |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 431 | xfs_ioend_t *next; |
| 432 | struct buffer_head *bh; |
| 433 | struct bio *bio; |
| 434 | sector_t lastblock = 0; |
| 435 | |
David Chinner | d88992f | 2006-01-18 13:38:12 +1100 | [diff] [blame] | 436 | /* Pass 1 - start writeback */ |
| 437 | do { |
| 438 | next = ioend->io_list; |
Christoph Hellwig | 221cb25 | 2010-12-10 08:42:17 +0000 | [diff] [blame] | 439 | for (bh = ioend->io_buffer_head; bh; bh = bh->b_private) |
David Chinner | d88992f | 2006-01-18 13:38:12 +1100 | [diff] [blame] | 440 | xfs_start_buffer_writeback(bh); |
David Chinner | d88992f | 2006-01-18 13:38:12 +1100 | [diff] [blame] | 441 | } while ((ioend = next) != NULL); |
| 442 | |
| 443 | /* Pass 2 - submit I/O */ |
| 444 | ioend = head; |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 445 | do { |
| 446 | next = ioend->io_list; |
| 447 | bio = NULL; |
| 448 | |
| 449 | for (bh = ioend->io_buffer_head; bh; bh = bh->b_private) { |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 450 | |
| 451 | if (!bio) { |
| 452 | retry: |
| 453 | bio = xfs_alloc_ioend_bio(bh); |
| 454 | } else if (bh->b_blocknr != lastblock + 1) { |
Christoph Hellwig | 06342cf | 2009-10-30 09:09:15 +0000 | [diff] [blame] | 455 | xfs_submit_ioend_bio(wbc, ioend, bio); |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 456 | goto retry; |
| 457 | } |
| 458 | |
| 459 | if (bio_add_buffer(bio, bh) != bh->b_size) { |
Christoph Hellwig | 06342cf | 2009-10-30 09:09:15 +0000 | [diff] [blame] | 460 | xfs_submit_ioend_bio(wbc, ioend, bio); |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 461 | goto retry; |
| 462 | } |
| 463 | |
| 464 | lastblock = bh->b_blocknr; |
| 465 | } |
| 466 | if (bio) |
Christoph Hellwig | 06342cf | 2009-10-30 09:09:15 +0000 | [diff] [blame] | 467 | xfs_submit_ioend_bio(wbc, ioend, bio); |
Christoph Hellwig | 209fb87 | 2010-07-18 21:17:11 +0000 | [diff] [blame] | 468 | xfs_finish_ioend(ioend); |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 469 | } while ((ioend = next) != NULL); |
| 470 | } |
| 471 | |
| 472 | /* |
| 473 | * Cancel submission of all buffer_heads so far in this endio. |
| 474 | * Toss the endio too. Only ever called for the initial page |
| 475 | * in a writepage request, so only ever one page. |
| 476 | */ |
| 477 | STATIC void |
| 478 | xfs_cancel_ioend( |
| 479 | xfs_ioend_t *ioend) |
| 480 | { |
| 481 | xfs_ioend_t *next; |
| 482 | struct buffer_head *bh, *next_bh; |
| 483 | |
| 484 | do { |
| 485 | next = ioend->io_list; |
| 486 | bh = ioend->io_buffer_head; |
| 487 | do { |
| 488 | next_bh = bh->b_private; |
| 489 | clear_buffer_async_write(bh); |
| 490 | unlock_buffer(bh); |
| 491 | } while ((bh = next_bh) != NULL); |
| 492 | |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 493 | mempool_free(ioend, xfs_ioend_pool); |
| 494 | } while ((ioend = next) != NULL); |
| 495 | } |
| 496 | |
| 497 | /* |
| 498 | * Test to see if we've been building up a completion structure for |
| 499 | * earlier buffers -- if so, we try to append to this ioend if we |
| 500 | * can, otherwise we finish off any current ioend and start another. |
| 501 | * Return true if we've finished the given ioend. |
| 502 | */ |
| 503 | STATIC void |
| 504 | xfs_add_to_ioend( |
| 505 | struct inode *inode, |
| 506 | struct buffer_head *bh, |
Christoph Hellwig | 7336cea | 2006-01-11 20:49:16 +1100 | [diff] [blame] | 507 | xfs_off_t offset, |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 508 | unsigned int type, |
| 509 | xfs_ioend_t **result, |
| 510 | int need_ioend) |
| 511 | { |
| 512 | xfs_ioend_t *ioend = *result; |
| 513 | |
| 514 | if (!ioend || need_ioend || type != ioend->io_type) { |
| 515 | xfs_ioend_t *previous = *result; |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 516 | |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 517 | ioend = xfs_alloc_ioend(inode, type); |
| 518 | ioend->io_offset = offset; |
| 519 | ioend->io_buffer_head = bh; |
| 520 | ioend->io_buffer_tail = bh; |
| 521 | if (previous) |
| 522 | previous->io_list = ioend; |
| 523 | *result = ioend; |
| 524 | } else { |
| 525 | ioend->io_buffer_tail->b_private = bh; |
| 526 | ioend->io_buffer_tail = bh; |
| 527 | } |
| 528 | |
| 529 | bh->b_private = NULL; |
| 530 | ioend->io_size += bh->b_size; |
| 531 | } |
| 532 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | STATIC void |
Nathan Scott | 87cbc49 | 2006-03-14 13:26:43 +1100 | [diff] [blame] | 534 | xfs_map_buffer( |
Christoph Hellwig | 046f168 | 2010-04-28 12:28:52 +0000 | [diff] [blame] | 535 | struct inode *inode, |
Nathan Scott | 87cbc49 | 2006-03-14 13:26:43 +1100 | [diff] [blame] | 536 | struct buffer_head *bh, |
Christoph Hellwig | 207d041 | 2010-04-28 12:28:56 +0000 | [diff] [blame] | 537 | struct xfs_bmbt_irec *imap, |
Christoph Hellwig | 046f168 | 2010-04-28 12:28:52 +0000 | [diff] [blame] | 538 | xfs_off_t offset) |
Nathan Scott | 87cbc49 | 2006-03-14 13:26:43 +1100 | [diff] [blame] | 539 | { |
| 540 | sector_t bn; |
Christoph Hellwig | 8699bb0 | 2010-04-28 12:28:54 +0000 | [diff] [blame] | 541 | struct xfs_mount *m = XFS_I(inode)->i_mount; |
Christoph Hellwig | 207d041 | 2010-04-28 12:28:56 +0000 | [diff] [blame] | 542 | xfs_off_t iomap_offset = XFS_FSB_TO_B(m, imap->br_startoff); |
| 543 | xfs_daddr_t iomap_bn = xfs_fsb_to_db(XFS_I(inode), imap->br_startblock); |
Nathan Scott | 87cbc49 | 2006-03-14 13:26:43 +1100 | [diff] [blame] | 544 | |
Christoph Hellwig | 207d041 | 2010-04-28 12:28:56 +0000 | [diff] [blame] | 545 | ASSERT(imap->br_startblock != HOLESTARTBLOCK); |
| 546 | ASSERT(imap->br_startblock != DELAYSTARTBLOCK); |
Nathan Scott | 87cbc49 | 2006-03-14 13:26:43 +1100 | [diff] [blame] | 547 | |
Christoph Hellwig | e513182 | 2010-04-28 12:28:55 +0000 | [diff] [blame] | 548 | bn = (iomap_bn >> (inode->i_blkbits - BBSHIFT)) + |
Christoph Hellwig | 8699bb0 | 2010-04-28 12:28:54 +0000 | [diff] [blame] | 549 | ((offset - iomap_offset) >> inode->i_blkbits); |
Nathan Scott | 87cbc49 | 2006-03-14 13:26:43 +1100 | [diff] [blame] | 550 | |
Christoph Hellwig | 046f168 | 2010-04-28 12:28:52 +0000 | [diff] [blame] | 551 | ASSERT(bn || XFS_IS_REALTIME_INODE(XFS_I(inode))); |
Nathan Scott | 87cbc49 | 2006-03-14 13:26:43 +1100 | [diff] [blame] | 552 | |
| 553 | bh->b_blocknr = bn; |
| 554 | set_buffer_mapped(bh); |
| 555 | } |
| 556 | |
| 557 | STATIC void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | xfs_map_at_offset( |
Christoph Hellwig | 046f168 | 2010-04-28 12:28:52 +0000 | [diff] [blame] | 559 | struct inode *inode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | struct buffer_head *bh, |
Christoph Hellwig | 207d041 | 2010-04-28 12:28:56 +0000 | [diff] [blame] | 561 | struct xfs_bmbt_irec *imap, |
Christoph Hellwig | 046f168 | 2010-04-28 12:28:52 +0000 | [diff] [blame] | 562 | xfs_off_t offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | { |
Christoph Hellwig | 207d041 | 2010-04-28 12:28:56 +0000 | [diff] [blame] | 564 | ASSERT(imap->br_startblock != HOLESTARTBLOCK); |
| 565 | ASSERT(imap->br_startblock != DELAYSTARTBLOCK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | |
Christoph Hellwig | 207d041 | 2010-04-28 12:28:56 +0000 | [diff] [blame] | 567 | xfs_map_buffer(inode, bh, imap, offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | set_buffer_mapped(bh); |
| 569 | clear_buffer_delay(bh); |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 570 | clear_buffer_unwritten(bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | /* |
Christoph Hellwig | 10ce444 | 2006-01-11 20:48:14 +1100 | [diff] [blame] | 574 | * Test if a given page is suitable for writing as part of an unwritten |
| 575 | * or delayed allocate extent. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | */ |
Christoph Hellwig | 10ce444 | 2006-01-11 20:48:14 +1100 | [diff] [blame] | 577 | STATIC int |
| 578 | xfs_is_delayed_page( |
| 579 | struct page *page, |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 580 | unsigned int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | if (PageWriteback(page)) |
Christoph Hellwig | 10ce444 | 2006-01-11 20:48:14 +1100 | [diff] [blame] | 583 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | |
| 585 | if (page->mapping && page_has_buffers(page)) { |
| 586 | struct buffer_head *bh, *head; |
| 587 | int acceptable = 0; |
| 588 | |
| 589 | bh = head = page_buffers(page); |
| 590 | do { |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 591 | if (buffer_unwritten(bh)) |
Christoph Hellwig | 34a52c6 | 2010-04-28 12:28:57 +0000 | [diff] [blame] | 592 | acceptable = (type == IO_UNWRITTEN); |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 593 | else if (buffer_delay(bh)) |
Christoph Hellwig | a206c81 | 2010-12-10 08:42:20 +0000 | [diff] [blame] | 594 | acceptable = (type == IO_DELALLOC); |
David Chinner | 2ddee84 | 2006-03-22 12:47:40 +1100 | [diff] [blame] | 595 | else if (buffer_dirty(bh) && buffer_mapped(bh)) |
Christoph Hellwig | a206c81 | 2010-12-10 08:42:20 +0000 | [diff] [blame] | 596 | acceptable = (type == IO_OVERWRITE); |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 597 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | } while ((bh = bh->b_this_page) != head); |
| 600 | |
| 601 | if (acceptable) |
Christoph Hellwig | 10ce444 | 2006-01-11 20:48:14 +1100 | [diff] [blame] | 602 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | } |
| 604 | |
Christoph Hellwig | 10ce444 | 2006-01-11 20:48:14 +1100 | [diff] [blame] | 605 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | } |
| 607 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | /* |
| 609 | * Allocate & map buffers for page given the extent map. Write it out. |
| 610 | * except for the original page of a writepage, this is called on |
| 611 | * delalloc/unwritten pages only, for the original page it is possible |
| 612 | * that the page has no mapping at all. |
| 613 | */ |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 614 | STATIC int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | xfs_convert_page( |
| 616 | struct inode *inode, |
| 617 | struct page *page, |
Christoph Hellwig | 10ce444 | 2006-01-11 20:48:14 +1100 | [diff] [blame] | 618 | loff_t tindex, |
Christoph Hellwig | 207d041 | 2010-04-28 12:28:56 +0000 | [diff] [blame] | 619 | struct xfs_bmbt_irec *imap, |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 620 | xfs_ioend_t **ioendp, |
Christoph Hellwig | 2fa24f9 | 2010-12-10 08:42:23 +0000 | [diff] [blame] | 621 | struct writeback_control *wbc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | { |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 623 | struct buffer_head *bh, *head; |
Christoph Hellwig | 9260dc6 | 2006-01-11 20:48:47 +1100 | [diff] [blame] | 624 | xfs_off_t end_offset; |
| 625 | unsigned long p_offset; |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 626 | unsigned int type; |
Nathan Scott | 24e17b5 | 2005-05-05 13:33:20 -0700 | [diff] [blame] | 627 | int len, page_dirty; |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 628 | int count = 0, done = 0, uptodate = 1; |
Christoph Hellwig | 9260dc6 | 2006-01-11 20:48:47 +1100 | [diff] [blame] | 629 | xfs_off_t offset = page_offset(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | |
Christoph Hellwig | 10ce444 | 2006-01-11 20:48:14 +1100 | [diff] [blame] | 631 | if (page->index != tindex) |
| 632 | goto fail; |
Nick Piggin | 529ae9a | 2008-08-02 12:01:03 +0200 | [diff] [blame] | 633 | if (!trylock_page(page)) |
Christoph Hellwig | 10ce444 | 2006-01-11 20:48:14 +1100 | [diff] [blame] | 634 | goto fail; |
| 635 | if (PageWriteback(page)) |
| 636 | goto fail_unlock_page; |
| 637 | if (page->mapping != inode->i_mapping) |
| 638 | goto fail_unlock_page; |
| 639 | if (!xfs_is_delayed_page(page, (*ioendp)->io_type)) |
| 640 | goto fail_unlock_page; |
| 641 | |
Nathan Scott | 24e17b5 | 2005-05-05 13:33:20 -0700 | [diff] [blame] | 642 | /* |
| 643 | * page_dirty is initially a count of buffers on the page before |
Nathan Scott | c41564b | 2006-03-29 08:55:14 +1000 | [diff] [blame] | 644 | * EOF and is decremented as we move each into a cleanable state. |
Christoph Hellwig | 9260dc6 | 2006-01-11 20:48:47 +1100 | [diff] [blame] | 645 | * |
| 646 | * Derivation: |
| 647 | * |
| 648 | * End offset is the highest offset that this page should represent. |
| 649 | * If we are on the last page, (end_offset & (PAGE_CACHE_SIZE - 1)) |
| 650 | * will evaluate non-zero and be less than PAGE_CACHE_SIZE and |
| 651 | * hence give us the correct page_dirty count. On any other page, |
| 652 | * it will be zero and in that case we need page_dirty to be the |
| 653 | * count of buffers on the page. |
Nathan Scott | 24e17b5 | 2005-05-05 13:33:20 -0700 | [diff] [blame] | 654 | */ |
Christoph Hellwig | 9260dc6 | 2006-01-11 20:48:47 +1100 | [diff] [blame] | 655 | end_offset = min_t(unsigned long long, |
| 656 | (xfs_off_t)(page->index + 1) << PAGE_CACHE_SHIFT, |
| 657 | i_size_read(inode)); |
| 658 | |
Nathan Scott | 24e17b5 | 2005-05-05 13:33:20 -0700 | [diff] [blame] | 659 | len = 1 << inode->i_blkbits; |
Christoph Hellwig | 9260dc6 | 2006-01-11 20:48:47 +1100 | [diff] [blame] | 660 | p_offset = min_t(unsigned long, end_offset & (PAGE_CACHE_SIZE - 1), |
| 661 | PAGE_CACHE_SIZE); |
| 662 | p_offset = p_offset ? roundup(p_offset, len) : PAGE_CACHE_SIZE; |
| 663 | page_dirty = p_offset / len; |
Nathan Scott | 24e17b5 | 2005-05-05 13:33:20 -0700 | [diff] [blame] | 664 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | bh = head = page_buffers(page); |
| 666 | do { |
Christoph Hellwig | 9260dc6 | 2006-01-11 20:48:47 +1100 | [diff] [blame] | 667 | if (offset >= end_offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | break; |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 669 | if (!buffer_uptodate(bh)) |
| 670 | uptodate = 0; |
| 671 | if (!(PageUptodate(page) || buffer_uptodate(bh))) { |
| 672 | done = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | continue; |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 674 | } |
| 675 | |
Christoph Hellwig | 2fa24f9 | 2010-12-10 08:42:23 +0000 | [diff] [blame] | 676 | if (buffer_unwritten(bh) || buffer_delay(bh) || |
| 677 | buffer_mapped(bh)) { |
Christoph Hellwig | 9260dc6 | 2006-01-11 20:48:47 +1100 | [diff] [blame] | 678 | if (buffer_unwritten(bh)) |
Christoph Hellwig | 34a52c6 | 2010-04-28 12:28:57 +0000 | [diff] [blame] | 679 | type = IO_UNWRITTEN; |
Christoph Hellwig | 2fa24f9 | 2010-12-10 08:42:23 +0000 | [diff] [blame] | 680 | else if (buffer_delay(bh)) |
Christoph Hellwig | a206c81 | 2010-12-10 08:42:20 +0000 | [diff] [blame] | 681 | type = IO_DELALLOC; |
Christoph Hellwig | 2fa24f9 | 2010-12-10 08:42:23 +0000 | [diff] [blame] | 682 | else |
| 683 | type = IO_OVERWRITE; |
Christoph Hellwig | 9260dc6 | 2006-01-11 20:48:47 +1100 | [diff] [blame] | 684 | |
Christoph Hellwig | 558e689 | 2010-04-28 12:28:58 +0000 | [diff] [blame] | 685 | if (!xfs_imap_valid(inode, imap, offset)) { |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 686 | done = 1; |
Christoph Hellwig | 9260dc6 | 2006-01-11 20:48:47 +1100 | [diff] [blame] | 687 | continue; |
| 688 | } |
| 689 | |
Christoph Hellwig | ecff71e | 2010-12-10 08:42:25 +0000 | [diff] [blame] | 690 | lock_buffer(bh); |
| 691 | if (type != IO_OVERWRITE) |
Christoph Hellwig | 2fa24f9 | 2010-12-10 08:42:23 +0000 | [diff] [blame] | 692 | xfs_map_at_offset(inode, bh, imap, offset); |
Christoph Hellwig | 89f3b363 | 2010-06-24 09:45:48 +1000 | [diff] [blame] | 693 | xfs_add_to_ioend(inode, bh, offset, type, |
| 694 | ioendp, done); |
| 695 | |
Christoph Hellwig | 9260dc6 | 2006-01-11 20:48:47 +1100 | [diff] [blame] | 696 | page_dirty--; |
| 697 | count++; |
| 698 | } else { |
Christoph Hellwig | 2fa24f9 | 2010-12-10 08:42:23 +0000 | [diff] [blame] | 699 | done = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | } |
Christoph Hellwig | 7336cea | 2006-01-11 20:49:16 +1100 | [diff] [blame] | 701 | } while (offset += len, (bh = bh->b_this_page) != head); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 703 | if (uptodate && bh == head) |
| 704 | SetPageUptodate(page); |
| 705 | |
Christoph Hellwig | 89f3b363 | 2010-06-24 09:45:48 +1000 | [diff] [blame] | 706 | if (count) { |
Dave Chinner | efceab1 | 2010-08-24 11:44:56 +1000 | [diff] [blame] | 707 | if (--wbc->nr_to_write <= 0 && |
| 708 | wbc->sync_mode == WB_SYNC_NONE) |
Christoph Hellwig | 89f3b363 | 2010-06-24 09:45:48 +1000 | [diff] [blame] | 709 | done = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | } |
Christoph Hellwig | 89f3b363 | 2010-06-24 09:45:48 +1000 | [diff] [blame] | 711 | xfs_start_page_writeback(page, !page_dirty, count); |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 712 | |
| 713 | return done; |
Christoph Hellwig | 10ce444 | 2006-01-11 20:48:14 +1100 | [diff] [blame] | 714 | fail_unlock_page: |
| 715 | unlock_page(page); |
| 716 | fail: |
| 717 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | /* |
| 721 | * Convert & write out a cluster of pages in the same extent as defined |
| 722 | * by mp and following the start page. |
| 723 | */ |
| 724 | STATIC void |
| 725 | xfs_cluster_write( |
| 726 | struct inode *inode, |
| 727 | pgoff_t tindex, |
Christoph Hellwig | 207d041 | 2010-04-28 12:28:56 +0000 | [diff] [blame] | 728 | struct xfs_bmbt_irec *imap, |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 729 | xfs_ioend_t **ioendp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | struct writeback_control *wbc, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | pgoff_t tlast) |
| 732 | { |
Christoph Hellwig | 10ce444 | 2006-01-11 20:48:14 +1100 | [diff] [blame] | 733 | struct pagevec pvec; |
| 734 | int done = 0, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | |
Christoph Hellwig | 10ce444 | 2006-01-11 20:48:14 +1100 | [diff] [blame] | 736 | pagevec_init(&pvec, 0); |
| 737 | while (!done && tindex <= tlast) { |
| 738 | unsigned len = min_t(pgoff_t, PAGEVEC_SIZE, tlast - tindex + 1); |
| 739 | |
| 740 | if (!pagevec_lookup(&pvec, inode->i_mapping, tindex, len)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | break; |
Christoph Hellwig | 10ce444 | 2006-01-11 20:48:14 +1100 | [diff] [blame] | 742 | |
| 743 | for (i = 0; i < pagevec_count(&pvec); i++) { |
| 744 | done = xfs_convert_page(inode, pvec.pages[i], tindex++, |
Christoph Hellwig | 2fa24f9 | 2010-12-10 08:42:23 +0000 | [diff] [blame] | 745 | imap, ioendp, wbc); |
Christoph Hellwig | 10ce444 | 2006-01-11 20:48:14 +1100 | [diff] [blame] | 746 | if (done) |
| 747 | break; |
| 748 | } |
| 749 | |
| 750 | pagevec_release(&pvec); |
| 751 | cond_resched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | } |
| 753 | } |
| 754 | |
Dave Chinner | 3ed3a43 | 2010-03-05 02:00:42 +0000 | [diff] [blame] | 755 | STATIC void |
| 756 | xfs_vm_invalidatepage( |
| 757 | struct page *page, |
| 758 | unsigned long offset) |
| 759 | { |
| 760 | trace_xfs_invalidatepage(page->mapping->host, page, offset); |
| 761 | block_invalidatepage(page, offset); |
| 762 | } |
| 763 | |
| 764 | /* |
| 765 | * If the page has delalloc buffers on it, we need to punch them out before we |
| 766 | * invalidate the page. If we don't, we leave a stale delalloc mapping on the |
| 767 | * inode that can trip a BUG() in xfs_get_blocks() later on if a direct IO read |
| 768 | * is done on that same region - the delalloc extent is returned when none is |
| 769 | * supposed to be there. |
| 770 | * |
| 771 | * We prevent this by truncating away the delalloc regions on the page before |
| 772 | * invalidating it. Because they are delalloc, we can do this without needing a |
| 773 | * transaction. Indeed - if we get ENOSPC errors, we have to be able to do this |
| 774 | * truncation without a transaction as there is no space left for block |
| 775 | * reservation (typically why we see a ENOSPC in writeback). |
| 776 | * |
| 777 | * This is not a performance critical path, so for now just do the punching a |
| 778 | * buffer head at a time. |
| 779 | */ |
| 780 | STATIC void |
| 781 | xfs_aops_discard_page( |
| 782 | struct page *page) |
| 783 | { |
| 784 | struct inode *inode = page->mapping->host; |
| 785 | struct xfs_inode *ip = XFS_I(inode); |
| 786 | struct buffer_head *bh, *head; |
| 787 | loff_t offset = page_offset(page); |
Dave Chinner | 3ed3a43 | 2010-03-05 02:00:42 +0000 | [diff] [blame] | 788 | |
Christoph Hellwig | a206c81 | 2010-12-10 08:42:20 +0000 | [diff] [blame] | 789 | if (!xfs_is_delayed_page(page, IO_DELALLOC)) |
Dave Chinner | 3ed3a43 | 2010-03-05 02:00:42 +0000 | [diff] [blame] | 790 | goto out_invalidate; |
| 791 | |
Dave Chinner | e8c3753 | 2010-03-15 02:36:35 +0000 | [diff] [blame] | 792 | if (XFS_FORCED_SHUTDOWN(ip->i_mount)) |
| 793 | goto out_invalidate; |
| 794 | |
Dave Chinner | 4f10700 | 2011-03-07 10:00:35 +1100 | [diff] [blame] | 795 | xfs_alert(ip->i_mount, |
Dave Chinner | 3ed3a43 | 2010-03-05 02:00:42 +0000 | [diff] [blame] | 796 | "page discard on page %p, inode 0x%llx, offset %llu.", |
| 797 | page, ip->i_ino, offset); |
| 798 | |
| 799 | xfs_ilock(ip, XFS_ILOCK_EXCL); |
| 800 | bh = head = page_buffers(page); |
| 801 | do { |
Dave Chinner | 3ed3a43 | 2010-03-05 02:00:42 +0000 | [diff] [blame] | 802 | int error; |
Dave Chinner | c726de4 | 2010-11-30 15:14:39 +1100 | [diff] [blame] | 803 | xfs_fileoff_t start_fsb; |
Dave Chinner | 3ed3a43 | 2010-03-05 02:00:42 +0000 | [diff] [blame] | 804 | |
| 805 | if (!buffer_delay(bh)) |
| 806 | goto next_buffer; |
| 807 | |
Dave Chinner | c726de4 | 2010-11-30 15:14:39 +1100 | [diff] [blame] | 808 | start_fsb = XFS_B_TO_FSBT(ip->i_mount, offset); |
| 809 | error = xfs_bmap_punch_delalloc_range(ip, start_fsb, 1); |
Dave Chinner | 3ed3a43 | 2010-03-05 02:00:42 +0000 | [diff] [blame] | 810 | if (error) { |
| 811 | /* something screwed, just bail */ |
Dave Chinner | e8c3753 | 2010-03-15 02:36:35 +0000 | [diff] [blame] | 812 | if (!XFS_FORCED_SHUTDOWN(ip->i_mount)) { |
Dave Chinner | 4f10700 | 2011-03-07 10:00:35 +1100 | [diff] [blame] | 813 | xfs_alert(ip->i_mount, |
Dave Chinner | 3ed3a43 | 2010-03-05 02:00:42 +0000 | [diff] [blame] | 814 | "page discard unable to remove delalloc mapping."); |
Dave Chinner | e8c3753 | 2010-03-15 02:36:35 +0000 | [diff] [blame] | 815 | } |
Dave Chinner | 3ed3a43 | 2010-03-05 02:00:42 +0000 | [diff] [blame] | 816 | break; |
| 817 | } |
| 818 | next_buffer: |
Dave Chinner | c726de4 | 2010-11-30 15:14:39 +1100 | [diff] [blame] | 819 | offset += 1 << inode->i_blkbits; |
Dave Chinner | 3ed3a43 | 2010-03-05 02:00:42 +0000 | [diff] [blame] | 820 | |
| 821 | } while ((bh = bh->b_this_page) != head); |
| 822 | |
| 823 | xfs_iunlock(ip, XFS_ILOCK_EXCL); |
| 824 | out_invalidate: |
| 825 | xfs_vm_invalidatepage(page, 0); |
| 826 | return; |
| 827 | } |
| 828 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | /* |
Christoph Hellwig | 89f3b363 | 2010-06-24 09:45:48 +1000 | [diff] [blame] | 830 | * Write out a dirty page. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | * |
Christoph Hellwig | 89f3b363 | 2010-06-24 09:45:48 +1000 | [diff] [blame] | 832 | * For delalloc space on the page we need to allocate space and flush it. |
| 833 | * For unwritten space on the page we need to start the conversion to |
| 834 | * regular allocated space. |
Christoph Hellwig | 89f3b363 | 2010-06-24 09:45:48 +1000 | [diff] [blame] | 835 | * For any other dirty buffer heads on the page we should flush them. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | STATIC int |
Christoph Hellwig | 89f3b363 | 2010-06-24 09:45:48 +1000 | [diff] [blame] | 838 | xfs_vm_writepage( |
| 839 | struct page *page, |
| 840 | struct writeback_control *wbc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | { |
Christoph Hellwig | 89f3b363 | 2010-06-24 09:45:48 +1000 | [diff] [blame] | 842 | struct inode *inode = page->mapping->host; |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 843 | struct buffer_head *bh, *head; |
Christoph Hellwig | 207d041 | 2010-04-28 12:28:56 +0000 | [diff] [blame] | 844 | struct xfs_bmbt_irec imap; |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 845 | xfs_ioend_t *ioend = NULL, *iohead = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | loff_t offset; |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 847 | unsigned int type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | __uint64_t end_offset; |
Christoph Hellwig | bd1556a | 2010-04-28 12:29:00 +0000 | [diff] [blame] | 849 | pgoff_t end_index, last_index; |
Christoph Hellwig | ed1e7b7 | 2010-12-10 08:42:22 +0000 | [diff] [blame] | 850 | ssize_t len; |
Christoph Hellwig | a206c81 | 2010-12-10 08:42:20 +0000 | [diff] [blame] | 851 | int err, imap_valid = 0, uptodate = 1; |
Christoph Hellwig | 89f3b363 | 2010-06-24 09:45:48 +1000 | [diff] [blame] | 852 | int count = 0; |
Christoph Hellwig | a206c81 | 2010-12-10 08:42:20 +0000 | [diff] [blame] | 853 | int nonblocking = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | |
Christoph Hellwig | 89f3b363 | 2010-06-24 09:45:48 +1000 | [diff] [blame] | 855 | trace_xfs_writepage(inode, page, 0); |
| 856 | |
Christoph Hellwig | 20cb52e | 2010-06-24 09:46:01 +1000 | [diff] [blame] | 857 | ASSERT(page_has_buffers(page)); |
| 858 | |
Christoph Hellwig | 89f3b363 | 2010-06-24 09:45:48 +1000 | [diff] [blame] | 859 | /* |
| 860 | * Refuse to write the page out if we are called from reclaim context. |
| 861 | * |
Christoph Hellwig | d4f7a5c | 2010-06-28 10:34:44 -0400 | [diff] [blame] | 862 | * This avoids stack overflows when called from deeply used stacks in |
| 863 | * random callers for direct reclaim or memcg reclaim. We explicitly |
| 864 | * allow reclaim from kswapd as the stack usage there is relatively low. |
Christoph Hellwig | 89f3b363 | 2010-06-24 09:45:48 +1000 | [diff] [blame] | 865 | * |
Mel Gorman | 94054fa | 2011-10-31 17:07:45 -0700 | [diff] [blame] | 866 | * This should never happen except in the case of a VM regression so |
| 867 | * warn about it. |
Christoph Hellwig | 89f3b363 | 2010-06-24 09:45:48 +1000 | [diff] [blame] | 868 | */ |
Mel Gorman | 94054fa | 2011-10-31 17:07:45 -0700 | [diff] [blame] | 869 | if (WARN_ON_ONCE((current->flags & (PF_MEMALLOC|PF_KSWAPD)) == |
| 870 | PF_MEMALLOC)) |
Christoph Hellwig | b5420f2 | 2010-08-24 11:47:51 +1000 | [diff] [blame] | 871 | goto redirty; |
Christoph Hellwig | 89f3b363 | 2010-06-24 09:45:48 +1000 | [diff] [blame] | 872 | |
| 873 | /* |
Christoph Hellwig | 680a647 | 2011-07-08 14:34:05 +0200 | [diff] [blame] | 874 | * Given that we do not allow direct reclaim to call us, we should |
| 875 | * never be called while in a filesystem transaction. |
Christoph Hellwig | 89f3b363 | 2010-06-24 09:45:48 +1000 | [diff] [blame] | 876 | */ |
Christoph Hellwig | 680a647 | 2011-07-08 14:34:05 +0200 | [diff] [blame] | 877 | if (WARN_ON(current->flags & PF_FSTRANS)) |
Christoph Hellwig | b5420f2 | 2010-08-24 11:47:51 +1000 | [diff] [blame] | 878 | goto redirty; |
Christoph Hellwig | 89f3b363 | 2010-06-24 09:45:48 +1000 | [diff] [blame] | 879 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | /* Is this page beyond the end of the file? */ |
| 881 | offset = i_size_read(inode); |
| 882 | end_index = offset >> PAGE_CACHE_SHIFT; |
| 883 | last_index = (offset - 1) >> PAGE_CACHE_SHIFT; |
| 884 | if (page->index >= end_index) { |
| 885 | if ((page->index >= end_index + 1) || |
| 886 | !(i_size_read(inode) & (PAGE_CACHE_SIZE - 1))) { |
Christoph Hellwig | 89f3b363 | 2010-06-24 09:45:48 +1000 | [diff] [blame] | 887 | unlock_page(page); |
Nathan Scott | 19d5bcf | 2005-11-02 15:14:09 +1100 | [diff] [blame] | 888 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | } |
| 890 | } |
| 891 | |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 892 | end_offset = min_t(unsigned long long, |
Christoph Hellwig | 20cb52e | 2010-06-24 09:46:01 +1000 | [diff] [blame] | 893 | (xfs_off_t)(page->index + 1) << PAGE_CACHE_SHIFT, |
| 894 | offset); |
Nathan Scott | 24e17b5 | 2005-05-05 13:33:20 -0700 | [diff] [blame] | 895 | len = 1 << inode->i_blkbits; |
Nathan Scott | 24e17b5 | 2005-05-05 13:33:20 -0700 | [diff] [blame] | 896 | |
Nathan Scott | 24e17b5 | 2005-05-05 13:33:20 -0700 | [diff] [blame] | 897 | bh = head = page_buffers(page); |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 898 | offset = page_offset(page); |
Christoph Hellwig | a206c81 | 2010-12-10 08:42:20 +0000 | [diff] [blame] | 899 | type = IO_OVERWRITE; |
| 900 | |
Christoph Hellwig | dbcdde3 | 2011-07-08 14:34:14 +0200 | [diff] [blame] | 901 | if (wbc->sync_mode == WB_SYNC_NONE) |
Christoph Hellwig | a206c81 | 2010-12-10 08:42:20 +0000 | [diff] [blame] | 902 | nonblocking = 1; |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 903 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | do { |
Christoph Hellwig | 6ac7248 | 2010-12-10 08:42:18 +0000 | [diff] [blame] | 905 | int new_ioend = 0; |
| 906 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | if (offset >= end_offset) |
| 908 | break; |
| 909 | if (!buffer_uptodate(bh)) |
| 910 | uptodate = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | |
Eric Sandeen | 3d9b02e | 2010-06-24 09:45:30 +1000 | [diff] [blame] | 912 | /* |
Christoph Hellwig | ece413f | 2010-11-10 21:39:11 +0000 | [diff] [blame] | 913 | * set_page_dirty dirties all buffers in a page, independent |
| 914 | * of their state. The dirty state however is entirely |
| 915 | * meaningless for holes (!mapped && uptodate), so skip |
| 916 | * buffers covering holes here. |
Eric Sandeen | 3d9b02e | 2010-06-24 09:45:30 +1000 | [diff] [blame] | 917 | */ |
| 918 | if (!buffer_mapped(bh) && buffer_uptodate(bh)) { |
Eric Sandeen | 3d9b02e | 2010-06-24 09:45:30 +1000 | [diff] [blame] | 919 | imap_valid = 0; |
| 920 | continue; |
| 921 | } |
| 922 | |
Christoph Hellwig | aeea1b1 | 2010-12-10 08:42:24 +0000 | [diff] [blame] | 923 | if (buffer_unwritten(bh)) { |
| 924 | if (type != IO_UNWRITTEN) { |
| 925 | type = IO_UNWRITTEN; |
| 926 | imap_valid = 0; |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 927 | } |
Christoph Hellwig | aeea1b1 | 2010-12-10 08:42:24 +0000 | [diff] [blame] | 928 | } else if (buffer_delay(bh)) { |
| 929 | if (type != IO_DELALLOC) { |
| 930 | type = IO_DELALLOC; |
| 931 | imap_valid = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | } |
Christoph Hellwig | 89f3b363 | 2010-06-24 09:45:48 +1000 | [diff] [blame] | 933 | } else if (buffer_uptodate(bh)) { |
Christoph Hellwig | a206c81 | 2010-12-10 08:42:20 +0000 | [diff] [blame] | 934 | if (type != IO_OVERWRITE) { |
| 935 | type = IO_OVERWRITE; |
Christoph Hellwig | 85da94c | 2010-12-10 08:42:16 +0000 | [diff] [blame] | 936 | imap_valid = 0; |
| 937 | } |
Christoph Hellwig | aeea1b1 | 2010-12-10 08:42:24 +0000 | [diff] [blame] | 938 | } else { |
| 939 | if (PageUptodate(page)) { |
| 940 | ASSERT(buffer_mapped(bh)); |
| 941 | imap_valid = 0; |
Christoph Hellwig | 6c4fe19 | 2006-01-11 20:49:28 +1100 | [diff] [blame] | 942 | } |
Christoph Hellwig | aeea1b1 | 2010-12-10 08:42:24 +0000 | [diff] [blame] | 943 | continue; |
| 944 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | |
Christoph Hellwig | aeea1b1 | 2010-12-10 08:42:24 +0000 | [diff] [blame] | 946 | if (imap_valid) |
| 947 | imap_valid = xfs_imap_valid(inode, &imap, offset); |
| 948 | if (!imap_valid) { |
| 949 | /* |
| 950 | * If we didn't have a valid mapping then we need to |
| 951 | * put the new mapping into a separate ioend structure. |
| 952 | * This ensures non-contiguous extents always have |
| 953 | * separate ioends, which is particularly important |
| 954 | * for unwritten extent conversion at I/O completion |
| 955 | * time. |
| 956 | */ |
| 957 | new_ioend = 1; |
| 958 | err = xfs_map_blocks(inode, offset, &imap, type, |
| 959 | nonblocking); |
| 960 | if (err) |
| 961 | goto error; |
| 962 | imap_valid = xfs_imap_valid(inode, &imap, offset); |
| 963 | } |
| 964 | if (imap_valid) { |
Christoph Hellwig | ecff71e | 2010-12-10 08:42:25 +0000 | [diff] [blame] | 965 | lock_buffer(bh); |
| 966 | if (type != IO_OVERWRITE) |
Christoph Hellwig | aeea1b1 | 2010-12-10 08:42:24 +0000 | [diff] [blame] | 967 | xfs_map_at_offset(inode, bh, &imap, offset); |
| 968 | xfs_add_to_ioend(inode, bh, offset, type, &ioend, |
| 969 | new_ioend); |
| 970 | count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | } |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 972 | |
| 973 | if (!iohead) |
| 974 | iohead = ioend; |
| 975 | |
| 976 | } while (offset += len, ((bh = bh->b_this_page) != head)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | |
| 978 | if (uptodate && bh == head) |
| 979 | SetPageUptodate(page); |
| 980 | |
Christoph Hellwig | 89f3b363 | 2010-06-24 09:45:48 +1000 | [diff] [blame] | 981 | xfs_start_page_writeback(page, 1, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | |
Christoph Hellwig | 558e689 | 2010-04-28 12:28:58 +0000 | [diff] [blame] | 983 | if (ioend && imap_valid) { |
Christoph Hellwig | bd1556a | 2010-04-28 12:29:00 +0000 | [diff] [blame] | 984 | xfs_off_t end_index; |
Christoph Hellwig | 8699bb0 | 2010-04-28 12:28:54 +0000 | [diff] [blame] | 985 | |
Christoph Hellwig | bd1556a | 2010-04-28 12:29:00 +0000 | [diff] [blame] | 986 | end_index = imap.br_startoff + imap.br_blockcount; |
| 987 | |
| 988 | /* to bytes */ |
| 989 | end_index <<= inode->i_blkbits; |
| 990 | |
| 991 | /* to pages */ |
| 992 | end_index = (end_index - 1) >> PAGE_CACHE_SHIFT; |
| 993 | |
| 994 | /* check against file size */ |
| 995 | if (end_index > last_index) |
| 996 | end_index = last_index; |
| 997 | |
Christoph Hellwig | 207d041 | 2010-04-28 12:28:56 +0000 | [diff] [blame] | 998 | xfs_cluster_write(inode, page->index + 1, &imap, &ioend, |
Christoph Hellwig | 2fa24f9 | 2010-12-10 08:42:23 +0000 | [diff] [blame] | 999 | wbc, end_index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | } |
| 1001 | |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 1002 | if (iohead) |
Christoph Hellwig | 06342cf | 2009-10-30 09:09:15 +0000 | [diff] [blame] | 1003 | xfs_submit_ioend(wbc, iohead); |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 1004 | |
Christoph Hellwig | 89f3b363 | 2010-06-24 09:45:48 +1000 | [diff] [blame] | 1005 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | |
| 1007 | error: |
Christoph Hellwig | f6d6d4f | 2006-01-11 15:40:13 +1100 | [diff] [blame] | 1008 | if (iohead) |
| 1009 | xfs_cancel_ioend(iohead); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | |
Christoph Hellwig | b5420f2 | 2010-08-24 11:47:51 +1000 | [diff] [blame] | 1011 | if (err == -EAGAIN) |
| 1012 | goto redirty; |
| 1013 | |
Christoph Hellwig | 20cb52e | 2010-06-24 09:46:01 +1000 | [diff] [blame] | 1014 | xfs_aops_discard_page(page); |
Christoph Hellwig | 89f3b363 | 2010-06-24 09:45:48 +1000 | [diff] [blame] | 1015 | ClearPageUptodate(page); |
| 1016 | unlock_page(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | return err; |
Nathan Scott | f51623b | 2006-03-14 13:26:27 +1100 | [diff] [blame] | 1018 | |
Christoph Hellwig | b5420f2 | 2010-08-24 11:47:51 +1000 | [diff] [blame] | 1019 | redirty: |
Nathan Scott | f51623b | 2006-03-14 13:26:27 +1100 | [diff] [blame] | 1020 | redirty_page_for_writepage(wbc, page); |
| 1021 | unlock_page(page); |
| 1022 | return 0; |
Nathan Scott | f51623b | 2006-03-14 13:26:27 +1100 | [diff] [blame] | 1023 | } |
| 1024 | |
Nathan Scott | 7d4fb40 | 2006-06-09 15:27:16 +1000 | [diff] [blame] | 1025 | STATIC int |
| 1026 | xfs_vm_writepages( |
| 1027 | struct address_space *mapping, |
| 1028 | struct writeback_control *wbc) |
| 1029 | { |
Christoph Hellwig | b3aea4e | 2007-08-29 11:44:37 +1000 | [diff] [blame] | 1030 | xfs_iflags_clear(XFS_I(mapping->host), XFS_ITRUNCATED); |
Nathan Scott | 7d4fb40 | 2006-06-09 15:27:16 +1000 | [diff] [blame] | 1031 | return generic_writepages(mapping, wbc); |
| 1032 | } |
| 1033 | |
Nathan Scott | f51623b | 2006-03-14 13:26:27 +1100 | [diff] [blame] | 1034 | /* |
| 1035 | * Called to move a page into cleanable state - and from there |
Christoph Hellwig | 89f3b363 | 2010-06-24 09:45:48 +1000 | [diff] [blame] | 1036 | * to be released. The page should already be clean. We always |
Nathan Scott | f51623b | 2006-03-14 13:26:27 +1100 | [diff] [blame] | 1037 | * have buffer heads in this call. |
| 1038 | * |
Christoph Hellwig | 89f3b363 | 2010-06-24 09:45:48 +1000 | [diff] [blame] | 1039 | * Returns 1 if the page is ok to release, 0 otherwise. |
Nathan Scott | f51623b | 2006-03-14 13:26:27 +1100 | [diff] [blame] | 1040 | */ |
| 1041 | STATIC int |
Nathan Scott | 238f4c5 | 2006-03-17 17:26:25 +1100 | [diff] [blame] | 1042 | xfs_vm_releasepage( |
Nathan Scott | f51623b | 2006-03-14 13:26:27 +1100 | [diff] [blame] | 1043 | struct page *page, |
| 1044 | gfp_t gfp_mask) |
| 1045 | { |
Christoph Hellwig | 20cb52e | 2010-06-24 09:46:01 +1000 | [diff] [blame] | 1046 | int delalloc, unwritten; |
Nathan Scott | f51623b | 2006-03-14 13:26:27 +1100 | [diff] [blame] | 1047 | |
Christoph Hellwig | 89f3b363 | 2010-06-24 09:45:48 +1000 | [diff] [blame] | 1048 | trace_xfs_releasepage(page->mapping->host, page, 0); |
Nathan Scott | 238f4c5 | 2006-03-17 17:26:25 +1100 | [diff] [blame] | 1049 | |
Christoph Hellwig | 20cb52e | 2010-06-24 09:46:01 +1000 | [diff] [blame] | 1050 | xfs_count_page_state(page, &delalloc, &unwritten); |
Nathan Scott | f51623b | 2006-03-14 13:26:27 +1100 | [diff] [blame] | 1051 | |
Christoph Hellwig | 89f3b363 | 2010-06-24 09:45:48 +1000 | [diff] [blame] | 1052 | if (WARN_ON(delalloc)) |
| 1053 | return 0; |
| 1054 | if (WARN_ON(unwritten)) |
Nathan Scott | f51623b | 2006-03-14 13:26:27 +1100 | [diff] [blame] | 1055 | return 0; |
| 1056 | |
Nathan Scott | f51623b | 2006-03-14 13:26:27 +1100 | [diff] [blame] | 1057 | return try_to_free_buffers(page); |
| 1058 | } |
| 1059 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | STATIC int |
Nathan Scott | c253666 | 2006-03-29 10:44:40 +1000 | [diff] [blame] | 1061 | __xfs_get_blocks( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | struct inode *inode, |
| 1063 | sector_t iblock, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | struct buffer_head *bh_result, |
| 1065 | int create, |
Christoph Hellwig | f2bde9b | 2010-06-24 11:44:35 +1000 | [diff] [blame] | 1066 | int direct) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | { |
Christoph Hellwig | a206c81 | 2010-12-10 08:42:20 +0000 | [diff] [blame] | 1068 | struct xfs_inode *ip = XFS_I(inode); |
| 1069 | struct xfs_mount *mp = ip->i_mount; |
| 1070 | xfs_fileoff_t offset_fsb, end_fsb; |
| 1071 | int error = 0; |
| 1072 | int lockmode = 0; |
Christoph Hellwig | 207d041 | 2010-04-28 12:28:56 +0000 | [diff] [blame] | 1073 | struct xfs_bmbt_irec imap; |
Christoph Hellwig | a206c81 | 2010-12-10 08:42:20 +0000 | [diff] [blame] | 1074 | int nimaps = 1; |
Nathan Scott | fdc7ed7 | 2005-11-02 15:13:13 +1100 | [diff] [blame] | 1075 | xfs_off_t offset; |
| 1076 | ssize_t size; |
Christoph Hellwig | 207d041 | 2010-04-28 12:28:56 +0000 | [diff] [blame] | 1077 | int new = 0; |
Christoph Hellwig | a206c81 | 2010-12-10 08:42:20 +0000 | [diff] [blame] | 1078 | |
| 1079 | if (XFS_FORCED_SHUTDOWN(mp)) |
| 1080 | return -XFS_ERROR(EIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | |
Nathan Scott | fdc7ed7 | 2005-11-02 15:13:13 +1100 | [diff] [blame] | 1082 | offset = (xfs_off_t)iblock << inode->i_blkbits; |
Nathan Scott | c253666 | 2006-03-29 10:44:40 +1000 | [diff] [blame] | 1083 | ASSERT(bh_result->b_size >= (1 << inode->i_blkbits)); |
| 1084 | size = bh_result->b_size; |
Lachlan McIlroy | 364f358 | 2008-09-17 16:50:14 +1000 | [diff] [blame] | 1085 | |
| 1086 | if (!create && direct && offset >= i_size_read(inode)) |
| 1087 | return 0; |
| 1088 | |
Christoph Hellwig | a206c81 | 2010-12-10 08:42:20 +0000 | [diff] [blame] | 1089 | if (create) { |
| 1090 | lockmode = XFS_ILOCK_EXCL; |
| 1091 | xfs_ilock(ip, lockmode); |
| 1092 | } else { |
| 1093 | lockmode = xfs_ilock_map_shared(ip); |
| 1094 | } |
Christoph Hellwig | f2bde9b | 2010-06-24 11:44:35 +1000 | [diff] [blame] | 1095 | |
Christoph Hellwig | a206c81 | 2010-12-10 08:42:20 +0000 | [diff] [blame] | 1096 | ASSERT(offset <= mp->m_maxioffset); |
| 1097 | if (offset + size > mp->m_maxioffset) |
| 1098 | size = mp->m_maxioffset - offset; |
| 1099 | end_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)offset + size); |
| 1100 | offset_fsb = XFS_B_TO_FSBT(mp, offset); |
| 1101 | |
Dave Chinner | 5c8ed20 | 2011-09-18 20:40:45 +0000 | [diff] [blame] | 1102 | error = xfs_bmapi_read(ip, offset_fsb, end_fsb - offset_fsb, |
| 1103 | &imap, &nimaps, XFS_BMAPI_ENTIRE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | if (error) |
Christoph Hellwig | a206c81 | 2010-12-10 08:42:20 +0000 | [diff] [blame] | 1105 | goto out_unlock; |
| 1106 | |
| 1107 | if (create && |
| 1108 | (!nimaps || |
| 1109 | (imap.br_startblock == HOLESTARTBLOCK || |
| 1110 | imap.br_startblock == DELAYSTARTBLOCK))) { |
| 1111 | if (direct) { |
| 1112 | error = xfs_iomap_write_direct(ip, offset, size, |
| 1113 | &imap, nimaps); |
| 1114 | } else { |
| 1115 | error = xfs_iomap_write_delay(ip, offset, size, &imap); |
| 1116 | } |
| 1117 | if (error) |
| 1118 | goto out_unlock; |
| 1119 | |
| 1120 | trace_xfs_get_blocks_alloc(ip, offset, size, 0, &imap); |
| 1121 | } else if (nimaps) { |
| 1122 | trace_xfs_get_blocks_found(ip, offset, size, 0, &imap); |
| 1123 | } else { |
| 1124 | trace_xfs_get_blocks_notfound(ip, offset, size); |
| 1125 | goto out_unlock; |
| 1126 | } |
| 1127 | xfs_iunlock(ip, lockmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | |
Christoph Hellwig | 207d041 | 2010-04-28 12:28:56 +0000 | [diff] [blame] | 1129 | if (imap.br_startblock != HOLESTARTBLOCK && |
| 1130 | imap.br_startblock != DELAYSTARTBLOCK) { |
Nathan Scott | 87cbc49 | 2006-03-14 13:26:43 +1100 | [diff] [blame] | 1131 | /* |
| 1132 | * For unwritten extents do not report a disk address on |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | * the read case (treat as if we're reading into a hole). |
| 1134 | */ |
Christoph Hellwig | 207d041 | 2010-04-28 12:28:56 +0000 | [diff] [blame] | 1135 | if (create || !ISUNWRITTEN(&imap)) |
| 1136 | xfs_map_buffer(inode, bh_result, &imap, offset); |
| 1137 | if (create && ISUNWRITTEN(&imap)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | if (direct) |
| 1139 | bh_result->b_private = inode; |
| 1140 | set_buffer_unwritten(bh_result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | } |
| 1142 | } |
| 1143 | |
Nathan Scott | c253666 | 2006-03-29 10:44:40 +1000 | [diff] [blame] | 1144 | /* |
| 1145 | * If this is a realtime file, data may be on a different device. |
| 1146 | * to that pointed to from the buffer_head b_bdev currently. |
| 1147 | */ |
Christoph Hellwig | 046f168 | 2010-04-28 12:28:52 +0000 | [diff] [blame] | 1148 | bh_result->b_bdev = xfs_find_bdev_for_inode(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | |
Nathan Scott | c253666 | 2006-03-29 10:44:40 +1000 | [diff] [blame] | 1150 | /* |
David Chinner | 549054a | 2007-02-10 18:36:35 +1100 | [diff] [blame] | 1151 | * If we previously allocated a block out beyond eof and we are now |
| 1152 | * coming back to use it then we will need to flag it as new even if it |
| 1153 | * has a disk address. |
| 1154 | * |
| 1155 | * With sub-block writes into unwritten extents we also need to mark |
| 1156 | * the buffer as new so that the unwritten parts of the buffer gets |
| 1157 | * correctly zeroed. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | */ |
| 1159 | if (create && |
| 1160 | ((!buffer_mapped(bh_result) && !buffer_uptodate(bh_result)) || |
David Chinner | 549054a | 2007-02-10 18:36:35 +1100 | [diff] [blame] | 1161 | (offset >= i_size_read(inode)) || |
Christoph Hellwig | 207d041 | 2010-04-28 12:28:56 +0000 | [diff] [blame] | 1162 | (new || ISUNWRITTEN(&imap)))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1163 | set_buffer_new(bh_result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | |
Christoph Hellwig | 207d041 | 2010-04-28 12:28:56 +0000 | [diff] [blame] | 1165 | if (imap.br_startblock == DELAYSTARTBLOCK) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | BUG_ON(direct); |
| 1167 | if (create) { |
| 1168 | set_buffer_uptodate(bh_result); |
| 1169 | set_buffer_mapped(bh_result); |
| 1170 | set_buffer_delay(bh_result); |
| 1171 | } |
| 1172 | } |
| 1173 | |
Christoph Hellwig | 2b8f12b | 2010-04-28 12:28:59 +0000 | [diff] [blame] | 1174 | /* |
| 1175 | * If this is O_DIRECT or the mpage code calling tell them how large |
| 1176 | * the mapping is, so that we can avoid repeated get_blocks calls. |
| 1177 | */ |
Nathan Scott | c253666 | 2006-03-29 10:44:40 +1000 | [diff] [blame] | 1178 | if (direct || size > (1 << inode->i_blkbits)) { |
Christoph Hellwig | 2b8f12b | 2010-04-28 12:28:59 +0000 | [diff] [blame] | 1179 | xfs_off_t mapping_size; |
Christoph Hellwig | 9563b3d | 2010-04-28 12:28:53 +0000 | [diff] [blame] | 1180 | |
Christoph Hellwig | 2b8f12b | 2010-04-28 12:28:59 +0000 | [diff] [blame] | 1181 | mapping_size = imap.br_startoff + imap.br_blockcount - iblock; |
| 1182 | mapping_size <<= inode->i_blkbits; |
| 1183 | |
| 1184 | ASSERT(mapping_size > 0); |
| 1185 | if (mapping_size > size) |
| 1186 | mapping_size = size; |
| 1187 | if (mapping_size > LONG_MAX) |
| 1188 | mapping_size = LONG_MAX; |
| 1189 | |
| 1190 | bh_result->b_size = mapping_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | return 0; |
Christoph Hellwig | a206c81 | 2010-12-10 08:42:20 +0000 | [diff] [blame] | 1194 | |
| 1195 | out_unlock: |
| 1196 | xfs_iunlock(ip, lockmode); |
| 1197 | return -error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | } |
| 1199 | |
| 1200 | int |
Nathan Scott | c253666 | 2006-03-29 10:44:40 +1000 | [diff] [blame] | 1201 | xfs_get_blocks( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1202 | struct inode *inode, |
| 1203 | sector_t iblock, |
| 1204 | struct buffer_head *bh_result, |
| 1205 | int create) |
| 1206 | { |
Christoph Hellwig | f2bde9b | 2010-06-24 11:44:35 +1000 | [diff] [blame] | 1207 | return __xfs_get_blocks(inode, iblock, bh_result, create, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | STATIC int |
Nathan Scott | e4c573b | 2006-03-14 13:54:26 +1100 | [diff] [blame] | 1211 | xfs_get_blocks_direct( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | struct inode *inode, |
| 1213 | sector_t iblock, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | struct buffer_head *bh_result, |
| 1215 | int create) |
| 1216 | { |
Christoph Hellwig | f2bde9b | 2010-06-24 11:44:35 +1000 | [diff] [blame] | 1217 | return __xfs_get_blocks(inode, iblock, bh_result, create, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | } |
| 1219 | |
Christoph Hellwig | 209fb87 | 2010-07-18 21:17:11 +0000 | [diff] [blame] | 1220 | /* |
| 1221 | * Complete a direct I/O write request. |
| 1222 | * |
| 1223 | * If the private argument is non-NULL __xfs_get_blocks signals us that we |
| 1224 | * need to issue a transaction to convert the range from unwritten to written |
| 1225 | * extents. In case this is regular synchronous I/O we just call xfs_end_io |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1226 | * to do this and we are done. But in case this was a successful AIO |
Christoph Hellwig | 209fb87 | 2010-07-18 21:17:11 +0000 | [diff] [blame] | 1227 | * request this handler is called from interrupt context, from which we |
| 1228 | * can't start transactions. In that case offload the I/O completion to |
| 1229 | * the workqueues we also use for buffered I/O completion. |
| 1230 | */ |
Christoph Hellwig | f097386 | 2005-09-05 08:22:52 +1000 | [diff] [blame] | 1231 | STATIC void |
Christoph Hellwig | 209fb87 | 2010-07-18 21:17:11 +0000 | [diff] [blame] | 1232 | xfs_end_io_direct_write( |
| 1233 | struct kiocb *iocb, |
| 1234 | loff_t offset, |
| 1235 | ssize_t size, |
| 1236 | void *private, |
| 1237 | int ret, |
| 1238 | bool is_async) |
Christoph Hellwig | f097386 | 2005-09-05 08:22:52 +1000 | [diff] [blame] | 1239 | { |
Christoph Hellwig | 209fb87 | 2010-07-18 21:17:11 +0000 | [diff] [blame] | 1240 | struct xfs_ioend *ioend = iocb->private; |
Christoph Hellwig | f097386 | 2005-09-05 08:22:52 +1000 | [diff] [blame] | 1241 | |
| 1242 | /* |
Christoph Hellwig | 2813d68 | 2011-12-18 20:00:12 +0000 | [diff] [blame] | 1243 | * While the generic direct I/O code updates the inode size, it does |
| 1244 | * so only after the end_io handler is called, which means our |
| 1245 | * end_io handler thinks the on-disk size is outside the in-core |
| 1246 | * size. To prevent this just update it a little bit earlier here. |
| 1247 | */ |
| 1248 | if (offset + size > i_size_read(ioend->io_inode)) |
| 1249 | i_size_write(ioend->io_inode, offset + size); |
| 1250 | |
| 1251 | /* |
Nathan Scott | c41564b | 2006-03-29 08:55:14 +1000 | [diff] [blame] | 1252 | * blockdev_direct_IO can return an error even after the I/O |
Christoph Hellwig | f097386 | 2005-09-05 08:22:52 +1000 | [diff] [blame] | 1253 | * completion handler was called. Thus we need to protect |
| 1254 | * against double-freeing. |
| 1255 | */ |
| 1256 | iocb->private = NULL; |
Christoph Hellwig | 40e2e97 | 2010-07-18 21:17:09 +0000 | [diff] [blame] | 1257 | |
Christoph Hellwig | 209fb87 | 2010-07-18 21:17:11 +0000 | [diff] [blame] | 1258 | ioend->io_offset = offset; |
| 1259 | ioend->io_size = size; |
Christoph Hellwig | c859cdd | 2011-08-23 08:28:10 +0000 | [diff] [blame] | 1260 | ioend->io_iocb = iocb; |
| 1261 | ioend->io_result = ret; |
Christoph Hellwig | 209fb87 | 2010-07-18 21:17:11 +0000 | [diff] [blame] | 1262 | if (private && size > 0) |
| 1263 | ioend->io_type = IO_UNWRITTEN; |
| 1264 | |
| 1265 | if (is_async) { |
Christoph Hellwig | c859cdd | 2011-08-23 08:28:10 +0000 | [diff] [blame] | 1266 | ioend->io_isasync = 1; |
Christoph Hellwig | 209fb87 | 2010-07-18 21:17:11 +0000 | [diff] [blame] | 1267 | xfs_finish_ioend(ioend); |
| 1268 | } else { |
| 1269 | xfs_finish_ioend_sync(ioend); |
| 1270 | } |
Christoph Hellwig | f097386 | 2005-09-05 08:22:52 +1000 | [diff] [blame] | 1271 | } |
| 1272 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 | STATIC ssize_t |
Nathan Scott | e4c573b | 2006-03-14 13:54:26 +1100 | [diff] [blame] | 1274 | xfs_vm_direct_IO( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | int rw, |
| 1276 | struct kiocb *iocb, |
| 1277 | const struct iovec *iov, |
| 1278 | loff_t offset, |
| 1279 | unsigned long nr_segs) |
| 1280 | { |
Christoph Hellwig | 209fb87 | 2010-07-18 21:17:11 +0000 | [diff] [blame] | 1281 | struct inode *inode = iocb->ki_filp->f_mapping->host; |
| 1282 | struct block_device *bdev = xfs_find_bdev_for_inode(inode); |
| 1283 | ssize_t ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | |
Christoph Hellwig | 209fb87 | 2010-07-18 21:17:11 +0000 | [diff] [blame] | 1285 | if (rw & WRITE) { |
Christoph Hellwig | a206c81 | 2010-12-10 08:42:20 +0000 | [diff] [blame] | 1286 | iocb->private = xfs_alloc_ioend(inode, IO_DIRECT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1287 | |
Christoph Hellwig | eafdc7d | 2010-06-04 11:29:53 +0200 | [diff] [blame] | 1288 | ret = __blockdev_direct_IO(rw, iocb, inode, bdev, iov, |
| 1289 | offset, nr_segs, |
| 1290 | xfs_get_blocks_direct, |
| 1291 | xfs_end_io_direct_write, NULL, 0); |
Christoph Hellwig | 209fb87 | 2010-07-18 21:17:11 +0000 | [diff] [blame] | 1292 | if (ret != -EIOCBQUEUED && iocb->private) |
| 1293 | xfs_destroy_ioend(iocb->private); |
| 1294 | } else { |
Christoph Hellwig | eafdc7d | 2010-06-04 11:29:53 +0200 | [diff] [blame] | 1295 | ret = __blockdev_direct_IO(rw, iocb, inode, bdev, iov, |
| 1296 | offset, nr_segs, |
| 1297 | xfs_get_blocks_direct, |
| 1298 | NULL, NULL, 0); |
Christoph Hellwig | 209fb87 | 2010-07-18 21:17:11 +0000 | [diff] [blame] | 1299 | } |
Christoph Hellwig | 5fe878ae | 2009-12-15 16:47:50 -0800 | [diff] [blame] | 1300 | |
Christoph Hellwig | f097386 | 2005-09-05 08:22:52 +1000 | [diff] [blame] | 1301 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1302 | } |
| 1303 | |
Christoph Hellwig | fa9b227 | 2010-06-14 05:17:31 -0400 | [diff] [blame] | 1304 | STATIC void |
| 1305 | xfs_vm_write_failed( |
| 1306 | struct address_space *mapping, |
| 1307 | loff_t to) |
| 1308 | { |
| 1309 | struct inode *inode = mapping->host; |
| 1310 | |
| 1311 | if (to > inode->i_size) { |
Dave Chinner | c726de4 | 2010-11-30 15:14:39 +1100 | [diff] [blame] | 1312 | /* |
Christoph Hellwig | 2813d68 | 2011-12-18 20:00:12 +0000 | [diff] [blame] | 1313 | * Punch out the delalloc blocks we have already allocated. |
| 1314 | * |
| 1315 | * Don't bother with xfs_setattr given that nothing can have |
| 1316 | * made it to disk yet as the page is still locked at this |
| 1317 | * point. |
Dave Chinner | c726de4 | 2010-11-30 15:14:39 +1100 | [diff] [blame] | 1318 | */ |
| 1319 | struct xfs_inode *ip = XFS_I(inode); |
| 1320 | xfs_fileoff_t start_fsb; |
| 1321 | xfs_fileoff_t end_fsb; |
| 1322 | int error; |
| 1323 | |
| 1324 | truncate_pagecache(inode, to, inode->i_size); |
| 1325 | |
| 1326 | /* |
| 1327 | * Check if there are any blocks that are outside of i_size |
| 1328 | * that need to be trimmed back. |
| 1329 | */ |
| 1330 | start_fsb = XFS_B_TO_FSB(ip->i_mount, inode->i_size) + 1; |
| 1331 | end_fsb = XFS_B_TO_FSB(ip->i_mount, to); |
| 1332 | if (end_fsb <= start_fsb) |
| 1333 | return; |
| 1334 | |
| 1335 | xfs_ilock(ip, XFS_ILOCK_EXCL); |
| 1336 | error = xfs_bmap_punch_delalloc_range(ip, start_fsb, |
| 1337 | end_fsb - start_fsb); |
| 1338 | if (error) { |
| 1339 | /* something screwed, just bail */ |
| 1340 | if (!XFS_FORCED_SHUTDOWN(ip->i_mount)) { |
Dave Chinner | 4f10700 | 2011-03-07 10:00:35 +1100 | [diff] [blame] | 1341 | xfs_alert(ip->i_mount, |
Dave Chinner | c726de4 | 2010-11-30 15:14:39 +1100 | [diff] [blame] | 1342 | "xfs_vm_write_failed: unable to clean up ino %lld", |
| 1343 | ip->i_ino); |
| 1344 | } |
| 1345 | } |
| 1346 | xfs_iunlock(ip, XFS_ILOCK_EXCL); |
Christoph Hellwig | fa9b227 | 2010-06-14 05:17:31 -0400 | [diff] [blame] | 1347 | } |
| 1348 | } |
| 1349 | |
Nathan Scott | f51623b | 2006-03-14 13:26:27 +1100 | [diff] [blame] | 1350 | STATIC int |
Nick Piggin | d79689c | 2007-10-16 01:25:06 -0700 | [diff] [blame] | 1351 | xfs_vm_write_begin( |
Nathan Scott | f51623b | 2006-03-14 13:26:27 +1100 | [diff] [blame] | 1352 | struct file *file, |
Nick Piggin | d79689c | 2007-10-16 01:25:06 -0700 | [diff] [blame] | 1353 | struct address_space *mapping, |
| 1354 | loff_t pos, |
| 1355 | unsigned len, |
| 1356 | unsigned flags, |
| 1357 | struct page **pagep, |
| 1358 | void **fsdata) |
Nathan Scott | f51623b | 2006-03-14 13:26:27 +1100 | [diff] [blame] | 1359 | { |
Christoph Hellwig | 155130a | 2010-06-04 11:29:58 +0200 | [diff] [blame] | 1360 | int ret; |
| 1361 | |
| 1362 | ret = block_write_begin(mapping, pos, len, flags | AOP_FLAG_NOFS, |
| 1363 | pagep, xfs_get_blocks); |
Christoph Hellwig | fa9b227 | 2010-06-14 05:17:31 -0400 | [diff] [blame] | 1364 | if (unlikely(ret)) |
| 1365 | xfs_vm_write_failed(mapping, pos + len); |
| 1366 | return ret; |
| 1367 | } |
Christoph Hellwig | 155130a | 2010-06-04 11:29:58 +0200 | [diff] [blame] | 1368 | |
Christoph Hellwig | fa9b227 | 2010-06-14 05:17:31 -0400 | [diff] [blame] | 1369 | STATIC int |
| 1370 | xfs_vm_write_end( |
| 1371 | struct file *file, |
| 1372 | struct address_space *mapping, |
| 1373 | loff_t pos, |
| 1374 | unsigned len, |
| 1375 | unsigned copied, |
| 1376 | struct page *page, |
| 1377 | void *fsdata) |
| 1378 | { |
| 1379 | int ret; |
| 1380 | |
| 1381 | ret = generic_write_end(file, mapping, pos, len, copied, page, fsdata); |
| 1382 | if (unlikely(ret < len)) |
| 1383 | xfs_vm_write_failed(mapping, pos + len); |
Christoph Hellwig | 155130a | 2010-06-04 11:29:58 +0200 | [diff] [blame] | 1384 | return ret; |
Nathan Scott | f51623b | 2006-03-14 13:26:27 +1100 | [diff] [blame] | 1385 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | |
| 1387 | STATIC sector_t |
Nathan Scott | e4c573b | 2006-03-14 13:54:26 +1100 | [diff] [blame] | 1388 | xfs_vm_bmap( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | struct address_space *mapping, |
| 1390 | sector_t block) |
| 1391 | { |
| 1392 | struct inode *inode = (struct inode *)mapping->host; |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 1393 | struct xfs_inode *ip = XFS_I(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1394 | |
Christoph Hellwig | cca28fb | 2010-06-24 11:57:09 +1000 | [diff] [blame] | 1395 | trace_xfs_vm_bmap(XFS_I(inode)); |
Christoph Hellwig | 126468b | 2008-03-06 13:44:57 +1100 | [diff] [blame] | 1396 | xfs_ilock(ip, XFS_IOLOCK_SHARED); |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 1397 | xfs_flush_pages(ip, (xfs_off_t)0, -1, 0, FI_REMAPF); |
Christoph Hellwig | 126468b | 2008-03-06 13:44:57 +1100 | [diff] [blame] | 1398 | xfs_iunlock(ip, XFS_IOLOCK_SHARED); |
Nathan Scott | c253666 | 2006-03-29 10:44:40 +1000 | [diff] [blame] | 1399 | return generic_block_bmap(mapping, block, xfs_get_blocks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | } |
| 1401 | |
| 1402 | STATIC int |
Nathan Scott | e4c573b | 2006-03-14 13:54:26 +1100 | [diff] [blame] | 1403 | xfs_vm_readpage( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | struct file *unused, |
| 1405 | struct page *page) |
| 1406 | { |
Nathan Scott | c253666 | 2006-03-29 10:44:40 +1000 | [diff] [blame] | 1407 | return mpage_readpage(page, xfs_get_blocks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1408 | } |
| 1409 | |
| 1410 | STATIC int |
Nathan Scott | e4c573b | 2006-03-14 13:54:26 +1100 | [diff] [blame] | 1411 | xfs_vm_readpages( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | struct file *unused, |
| 1413 | struct address_space *mapping, |
| 1414 | struct list_head *pages, |
| 1415 | unsigned nr_pages) |
| 1416 | { |
Nathan Scott | c253666 | 2006-03-29 10:44:40 +1000 | [diff] [blame] | 1417 | return mpage_readpages(mapping, pages, nr_pages, xfs_get_blocks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1418 | } |
| 1419 | |
Christoph Hellwig | f5e54d6 | 2006-06-28 04:26:44 -0700 | [diff] [blame] | 1420 | const struct address_space_operations xfs_address_space_operations = { |
Nathan Scott | e4c573b | 2006-03-14 13:54:26 +1100 | [diff] [blame] | 1421 | .readpage = xfs_vm_readpage, |
| 1422 | .readpages = xfs_vm_readpages, |
| 1423 | .writepage = xfs_vm_writepage, |
Nathan Scott | 7d4fb40 | 2006-06-09 15:27:16 +1000 | [diff] [blame] | 1424 | .writepages = xfs_vm_writepages, |
Nathan Scott | 238f4c5 | 2006-03-17 17:26:25 +1100 | [diff] [blame] | 1425 | .releasepage = xfs_vm_releasepage, |
| 1426 | .invalidatepage = xfs_vm_invalidatepage, |
Nick Piggin | d79689c | 2007-10-16 01:25:06 -0700 | [diff] [blame] | 1427 | .write_begin = xfs_vm_write_begin, |
Christoph Hellwig | fa9b227 | 2010-06-14 05:17:31 -0400 | [diff] [blame] | 1428 | .write_end = xfs_vm_write_end, |
Nathan Scott | e4c573b | 2006-03-14 13:54:26 +1100 | [diff] [blame] | 1429 | .bmap = xfs_vm_bmap, |
| 1430 | .direct_IO = xfs_vm_direct_IO, |
Christoph Lameter | e965f96 | 2006-02-01 03:05:41 -0800 | [diff] [blame] | 1431 | .migratepage = buffer_migrate_page, |
Hisashi Hifumi | bddaafa | 2009-03-29 09:53:38 +0200 | [diff] [blame] | 1432 | .is_partially_uptodate = block_is_partially_uptodate, |
Andi Kleen | aa261f5 | 2009-09-16 11:50:16 +0200 | [diff] [blame] | 1433 | .error_remove_page = generic_error_remove_page, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1434 | }; |