diff options
Diffstat (limited to 'fs/xfs/linux-2.6/xfs_aops.c')
-rw-r--r-- | fs/xfs/linux-2.6/xfs_aops.c | 484 |
1 files changed, 242 insertions, 242 deletions
diff --git a/fs/xfs/linux-2.6/xfs_aops.c b/fs/xfs/linux-2.6/xfs_aops.c index 74d8be87f98..97fc056130e 100644 --- a/fs/xfs/linux-2.6/xfs_aops.c +++ b/fs/xfs/linux-2.6/xfs_aops.c | |||
@@ -43,7 +43,29 @@ | |||
43 | #include <linux/pagevec.h> | 43 | #include <linux/pagevec.h> |
44 | #include <linux/writeback.h> | 44 | #include <linux/writeback.h> |
45 | 45 | ||
46 | STATIC void xfs_count_page_state(struct page *, int *, int *, int *); | 46 | STATIC void |
47 | xfs_count_page_state( | ||
48 | struct page *page, | ||
49 | int *delalloc, | ||
50 | int *unmapped, | ||
51 | int *unwritten) | ||
52 | { | ||
53 | struct buffer_head *bh, *head; | ||
54 | |||
55 | *delalloc = *unmapped = *unwritten = 0; | ||
56 | |||
57 | bh = head = page_buffers(page); | ||
58 | do { | ||
59 | if (buffer_uptodate(bh) && !buffer_mapped(bh)) | ||
60 | (*unmapped) = 1; | ||
61 | else if (buffer_unwritten(bh) && !buffer_delay(bh)) | ||
62 | clear_buffer_unwritten(bh); | ||
63 | else if (buffer_unwritten(bh)) | ||
64 | (*unwritten) = 1; | ||
65 | else if (buffer_delay(bh)) | ||
66 | (*delalloc) = 1; | ||
67 | } while ((bh = bh->b_this_page) != head); | ||
68 | } | ||
47 | 69 | ||
48 | #if defined(XFS_RW_TRACE) | 70 | #if defined(XFS_RW_TRACE) |
49 | void | 71 | void |
@@ -54,7 +76,7 @@ xfs_page_trace( | |||
54 | int mask) | 76 | int mask) |
55 | { | 77 | { |
56 | xfs_inode_t *ip; | 78 | xfs_inode_t *ip; |
57 | vnode_t *vp = LINVFS_GET_VP(inode); | 79 | vnode_t *vp = vn_from_inode(inode); |
58 | loff_t isize = i_size_read(inode); | 80 | loff_t isize = i_size_read(inode); |
59 | loff_t offset = page_offset(page); | 81 | loff_t offset = page_offset(page); |
60 | int delalloc = -1, unmapped = -1, unwritten = -1; | 82 | int delalloc = -1, unmapped = -1, unwritten = -1; |
@@ -81,7 +103,7 @@ xfs_page_trace( | |||
81 | (void *)((unsigned long)delalloc), | 103 | (void *)((unsigned long)delalloc), |
82 | (void *)((unsigned long)unmapped), | 104 | (void *)((unsigned long)unmapped), |
83 | (void *)((unsigned long)unwritten), | 105 | (void *)((unsigned long)unwritten), |
84 | (void *)NULL, | 106 | (void *)((unsigned long)current_pid()), |
85 | (void *)NULL); | 107 | (void *)NULL); |
86 | } | 108 | } |
87 | #else | 109 | #else |
@@ -192,7 +214,7 @@ xfs_alloc_ioend( | |||
192 | ioend->io_uptodate = 1; /* cleared if any I/O fails */ | 214 | ioend->io_uptodate = 1; /* cleared if any I/O fails */ |
193 | ioend->io_list = NULL; | 215 | ioend->io_list = NULL; |
194 | ioend->io_type = type; | 216 | ioend->io_type = type; |
195 | ioend->io_vnode = LINVFS_GET_VP(inode); | 217 | ioend->io_vnode = vn_from_inode(inode); |
196 | ioend->io_buffer_head = NULL; | 218 | ioend->io_buffer_head = NULL; |
197 | ioend->io_buffer_tail = NULL; | 219 | ioend->io_buffer_tail = NULL; |
198 | atomic_inc(&ioend->io_vnode->v_iocount); | 220 | atomic_inc(&ioend->io_vnode->v_iocount); |
@@ -217,7 +239,7 @@ xfs_map_blocks( | |||
217 | xfs_iomap_t *mapp, | 239 | xfs_iomap_t *mapp, |
218 | int flags) | 240 | int flags) |
219 | { | 241 | { |
220 | vnode_t *vp = LINVFS_GET_VP(inode); | 242 | vnode_t *vp = vn_from_inode(inode); |
221 | int error, nmaps = 1; | 243 | int error, nmaps = 1; |
222 | 244 | ||
223 | VOP_BMAP(vp, offset, count, flags, mapp, &nmaps, error); | 245 | VOP_BMAP(vp, offset, count, flags, mapp, &nmaps, error); |
@@ -462,28 +484,37 @@ xfs_add_to_ioend( | |||
462 | } | 484 | } |
463 | 485 | ||
464 | STATIC void | 486 | STATIC void |
487 | xfs_map_buffer( | ||
488 | struct buffer_head *bh, | ||
489 | xfs_iomap_t *mp, | ||
490 | xfs_off_t offset, | ||
491 | uint block_bits) | ||
492 | { | ||
493 | sector_t bn; | ||
494 | |||
495 | ASSERT(mp->iomap_bn != IOMAP_DADDR_NULL); | ||
496 | |||
497 | bn = (mp->iomap_bn >> (block_bits - BBSHIFT)) + | ||
498 | ((offset - mp->iomap_offset) >> block_bits); | ||
499 | |||
500 | ASSERT(bn || (mp->iomap_flags & IOMAP_REALTIME)); | ||
501 | |||
502 | bh->b_blocknr = bn; | ||
503 | set_buffer_mapped(bh); | ||
504 | } | ||
505 | |||
506 | STATIC void | ||
465 | xfs_map_at_offset( | 507 | xfs_map_at_offset( |
466 | struct buffer_head *bh, | 508 | struct buffer_head *bh, |
467 | loff_t offset, | 509 | loff_t offset, |
468 | int block_bits, | 510 | int block_bits, |
469 | xfs_iomap_t *iomapp) | 511 | xfs_iomap_t *iomapp) |
470 | { | 512 | { |
471 | xfs_daddr_t bn; | ||
472 | int sector_shift; | ||
473 | |||
474 | ASSERT(!(iomapp->iomap_flags & IOMAP_HOLE)); | 513 | ASSERT(!(iomapp->iomap_flags & IOMAP_HOLE)); |
475 | ASSERT(!(iomapp->iomap_flags & IOMAP_DELAY)); | 514 | ASSERT(!(iomapp->iomap_flags & IOMAP_DELAY)); |
476 | ASSERT(iomapp->iomap_bn != IOMAP_DADDR_NULL); | ||
477 | |||
478 | sector_shift = block_bits - BBSHIFT; | ||
479 | bn = (iomapp->iomap_bn >> sector_shift) + | ||
480 | ((offset - iomapp->iomap_offset) >> block_bits); | ||
481 | |||
482 | ASSERT(bn || (iomapp->iomap_flags & IOMAP_REALTIME)); | ||
483 | ASSERT((bn << sector_shift) >= iomapp->iomap_bn); | ||
484 | 515 | ||
485 | lock_buffer(bh); | 516 | lock_buffer(bh); |
486 | bh->b_blocknr = bn; | 517 | xfs_map_buffer(bh, iomapp, offset, block_bits); |
487 | bh->b_bdev = iomapp->iomap_target->bt_bdev; | 518 | bh->b_bdev = iomapp->iomap_target->bt_bdev; |
488 | set_buffer_mapped(bh); | 519 | set_buffer_mapped(bh); |
489 | clear_buffer_delay(bh); | 520 | clear_buffer_delay(bh); |
@@ -616,7 +647,7 @@ xfs_is_delayed_page( | |||
616 | acceptable = (type == IOMAP_UNWRITTEN); | 647 | acceptable = (type == IOMAP_UNWRITTEN); |
617 | else if (buffer_delay(bh)) | 648 | else if (buffer_delay(bh)) |
618 | acceptable = (type == IOMAP_DELAY); | 649 | acceptable = (type == IOMAP_DELAY); |
619 | else if (buffer_mapped(bh)) | 650 | else if (buffer_dirty(bh) && buffer_mapped(bh)) |
620 | acceptable = (type == 0); | 651 | acceptable = (type == 0); |
621 | else | 652 | else |
622 | break; | 653 | break; |
@@ -1040,8 +1071,159 @@ error: | |||
1040 | return err; | 1071 | return err; |
1041 | } | 1072 | } |
1042 | 1073 | ||
1074 | /* | ||
1075 | * writepage: Called from one of two places: | ||
1076 | * | ||
1077 | * 1. we are flushing a delalloc buffer head. | ||
1078 | * | ||
1079 | * 2. we are writing out a dirty page. Typically the page dirty | ||
1080 | * state is cleared before we get here. In this case is it | ||
1081 | * conceivable we have no buffer heads. | ||
1082 | * | ||
1083 | * For delalloc space on the page we need to allocate space and | ||
1084 | * flush it. For unmapped buffer heads on the page we should | ||
1085 | * allocate space if the page is uptodate. For any other dirty | ||
1086 | * buffer heads on the page we should flush them. | ||
1087 | * | ||
1088 | * If we detect that a transaction would be required to flush | ||
1089 | * the page, we have to check the process flags first, if we | ||
1090 | * are already in a transaction or disk I/O during allocations | ||
1091 | * is off, we need to fail the writepage and redirty the page. | ||
1092 | */ | ||
1093 | |||
1094 | STATIC int | ||
1095 | xfs_vm_writepage( | ||
1096 | struct page *page, | ||
1097 | struct writeback_control *wbc) | ||
1098 | { | ||
1099 | int error; | ||
1100 | int need_trans; | ||
1101 | int delalloc, unmapped, unwritten; | ||
1102 | struct inode *inode = page->mapping->host; | ||
1103 | |||
1104 | xfs_page_trace(XFS_WRITEPAGE_ENTER, inode, page, 0); | ||
1105 | |||
1106 | /* | ||
1107 | * We need a transaction if: | ||
1108 | * 1. There are delalloc buffers on the page | ||
1109 | * 2. The page is uptodate and we have unmapped buffers | ||
1110 | * 3. The page is uptodate and we have no buffers | ||
1111 | * 4. There are unwritten buffers on the page | ||
1112 | */ | ||
1113 | |||
1114 | if (!page_has_buffers(page)) { | ||
1115 | unmapped = 1; | ||
1116 | need_trans = 1; | ||
1117 | } else { | ||
1118 | xfs_count_page_state(page, &delalloc, &unmapped, &unwritten); | ||
1119 | if (!PageUptodate(page)) | ||
1120 | unmapped = 0; | ||
1121 | need_trans = delalloc + unmapped + unwritten; | ||
1122 | } | ||
1123 | |||
1124 | /* | ||
1125 | * If we need a transaction and the process flags say | ||
1126 | * we are already in a transaction, or no IO is allowed | ||
1127 | * then mark the page dirty again and leave the page | ||
1128 | * as is. | ||
1129 | */ | ||
1130 | if (PFLAGS_TEST_FSTRANS() && need_trans) | ||
1131 | goto out_fail; | ||
1132 | |||
1133 | /* | ||
1134 | * Delay hooking up buffer heads until we have | ||
1135 | * made our go/no-go decision. | ||
1136 | */ | ||
1137 | if (!page_has_buffers(page)) | ||
1138 | create_empty_buffers(page, 1 << inode->i_blkbits, 0); | ||
1139 | |||
1140 | /* | ||
1141 | * Convert delayed allocate, unwritten or unmapped space | ||
1142 | * to real space and flush out to disk. | ||
1143 | */ | ||
1144 | error = xfs_page_state_convert(inode, page, wbc, 1, unmapped); | ||
1145 | if (error == -EAGAIN) | ||
1146 | goto out_fail; | ||
1147 | if (unlikely(error < 0)) | ||
1148 | goto out_unlock; | ||
1149 | |||
1150 | return 0; | ||
1151 | |||
1152 | out_fail: | ||
1153 | redirty_page_for_writepage(wbc, page); | ||
1154 | unlock_page(page); | ||
1155 | return 0; | ||
1156 | out_unlock: | ||
1157 | unlock_page(page); | ||
1158 | return error; | ||
1159 | } | ||
1160 | |||
1161 | /* | ||
1162 | * Called to move a page into cleanable state - and from there | ||
1163 | * to be released. Possibly the page is already clean. We always | ||
1164 | * have buffer heads in this call. | ||
1165 | * | ||
1166 | * Returns 0 if the page is ok to release, 1 otherwise. | ||
1167 | * | ||
1168 | * Possible scenarios are: | ||
1169 | * | ||
1170 | * 1. We are being called to release a page which has been written | ||
1171 | * to via regular I/O. buffer heads will be dirty and possibly | ||
1172 | * delalloc. If no delalloc buffer heads in this case then we | ||
1173 | * can just return zero. | ||
1174 | * | ||
1175 | * 2. We are called to release a page which has been written via | ||
1176 | * mmap, all we need to do is ensure there is no delalloc | ||
1177 | * state in the buffer heads, if not we can let the caller | ||
1178 | * free them and we should come back later via writepage. | ||
1179 | */ | ||
1043 | STATIC int | 1180 | STATIC int |
1044 | __linvfs_get_block( | 1181 | xfs_vm_releasepage( |
1182 | struct page *page, | ||
1183 | gfp_t gfp_mask) | ||
1184 | { | ||
1185 | struct inode *inode = page->mapping->host; | ||
1186 | int dirty, delalloc, unmapped, unwritten; | ||
1187 | struct writeback_control wbc = { | ||
1188 | .sync_mode = WB_SYNC_ALL, | ||
1189 | .nr_to_write = 1, | ||
1190 | }; | ||
1191 | |||
1192 | xfs_page_trace(XFS_RELEASEPAGE_ENTER, inode, page, gfp_mask); | ||
1193 | |||
1194 | if (!page_has_buffers(page)) | ||
1195 | return 0; | ||
1196 | |||
1197 | xfs_count_page_state(page, &delalloc, &unmapped, &unwritten); | ||
1198 | if (!delalloc && !unwritten) | ||
1199 | goto free_buffers; | ||
1200 | |||
1201 | if (!(gfp_mask & __GFP_FS)) | ||
1202 | return 0; | ||
1203 | |||
1204 | /* If we are already inside a transaction or the thread cannot | ||
1205 | * do I/O, we cannot release this page. | ||
1206 | */ | ||
1207 | if (PFLAGS_TEST_FSTRANS()) | ||
1208 | return 0; | ||
1209 | |||
1210 | /* | ||
1211 | * Convert delalloc space to real space, do not flush the | ||
1212 | * data out to disk, that will be done by the caller. | ||
1213 | * Never need to allocate space here - we will always | ||
1214 | * come back to writepage in that case. | ||
1215 | */ | ||
1216 | dirty = xfs_page_state_convert(inode, page, &wbc, 0, 0); | ||
1217 | if (dirty == 0 && !unwritten) | ||
1218 | goto free_buffers; | ||
1219 | return 0; | ||
1220 | |||
1221 | free_buffers: | ||
1222 | return try_to_free_buffers(page); | ||
1223 | } | ||
1224 | |||
1225 | STATIC int | ||
1226 | __xfs_get_block( | ||
1045 | struct inode *inode, | 1227 | struct inode *inode, |
1046 | sector_t iblock, | 1228 | sector_t iblock, |
1047 | unsigned long blocks, | 1229 | unsigned long blocks, |
@@ -1050,7 +1232,7 @@ __linvfs_get_block( | |||
1050 | int direct, | 1232 | int direct, |
1051 | bmapi_flags_t flags) | 1233 | bmapi_flags_t flags) |
1052 | { | 1234 | { |
1053 | vnode_t *vp = LINVFS_GET_VP(inode); | 1235 | vnode_t *vp = vn_from_inode(inode); |
1054 | xfs_iomap_t iomap; | 1236 | xfs_iomap_t iomap; |
1055 | xfs_off_t offset; | 1237 | xfs_off_t offset; |
1056 | ssize_t size; | 1238 | ssize_t size; |
@@ -1073,21 +1255,13 @@ __linvfs_get_block( | |||
1073 | return 0; | 1255 | return 0; |
1074 | 1256 | ||
1075 | if (iomap.iomap_bn != IOMAP_DADDR_NULL) { | 1257 | if (iomap.iomap_bn != IOMAP_DADDR_NULL) { |
1076 | xfs_daddr_t bn; | 1258 | /* |
1077 | xfs_off_t delta; | 1259 | * For unwritten extents do not report a disk address on |
1078 | |||
1079 | /* For unwritten extents do not report a disk address on | ||
1080 | * the read case (treat as if we're reading into a hole). | 1260 | * the read case (treat as if we're reading into a hole). |
1081 | */ | 1261 | */ |
1082 | if (create || !(iomap.iomap_flags & IOMAP_UNWRITTEN)) { | 1262 | if (create || !(iomap.iomap_flags & IOMAP_UNWRITTEN)) { |
1083 | delta = offset - iomap.iomap_offset; | 1263 | xfs_map_buffer(bh_result, &iomap, offset, |
1084 | delta >>= inode->i_blkbits; | 1264 | inode->i_blkbits); |
1085 | |||
1086 | bn = iomap.iomap_bn >> (inode->i_blkbits - BBSHIFT); | ||
1087 | bn += delta; | ||
1088 | BUG_ON(!bn && !(iomap.iomap_flags & IOMAP_REALTIME)); | ||
1089 | bh_result->b_blocknr = bn; | ||
1090 | set_buffer_mapped(bh_result); | ||
1091 | } | 1265 | } |
1092 | if (create && (iomap.iomap_flags & IOMAP_UNWRITTEN)) { | 1266 | if (create && (iomap.iomap_flags & IOMAP_UNWRITTEN)) { |
1093 | if (direct) | 1267 | if (direct) |
@@ -1130,30 +1304,30 @@ __linvfs_get_block( | |||
1130 | } | 1304 | } |
1131 | 1305 | ||
1132 | int | 1306 | int |
1133 | linvfs_get_block( | 1307 | xfs_get_block( |
1134 | struct inode *inode, | 1308 | struct inode *inode, |
1135 | sector_t iblock, | 1309 | sector_t iblock, |
1136 | struct buffer_head *bh_result, | 1310 | struct buffer_head *bh_result, |
1137 | int create) | 1311 | int create) |
1138 | { | 1312 | { |
1139 | return __linvfs_get_block(inode, iblock, 0, bh_result, | 1313 | return __xfs_get_block(inode, iblock, 0, bh_result, |
1140 | create, 0, BMAPI_WRITE); | 1314 | create, 0, BMAPI_WRITE); |
1141 | } | 1315 | } |
1142 | 1316 | ||
1143 | STATIC int | 1317 | STATIC int |
1144 | linvfs_get_blocks_direct( | 1318 | xfs_get_blocks_direct( |
1145 | struct inode *inode, | 1319 | struct inode *inode, |
1146 | sector_t iblock, | 1320 | sector_t iblock, |
1147 | unsigned long max_blocks, | 1321 | unsigned long max_blocks, |
1148 | struct buffer_head *bh_result, | 1322 | struct buffer_head *bh_result, |
1149 | int create) | 1323 | int create) |
1150 | { | 1324 | { |
1151 | return __linvfs_get_block(inode, iblock, max_blocks, bh_result, | 1325 | return __xfs_get_block(inode, iblock, max_blocks, bh_result, |
1152 | create, 1, BMAPI_WRITE|BMAPI_DIRECT); | 1326 | create, 1, BMAPI_WRITE|BMAPI_DIRECT); |
1153 | } | 1327 | } |
1154 | 1328 | ||
1155 | STATIC void | 1329 | STATIC void |
1156 | linvfs_end_io_direct( | 1330 | xfs_end_io_direct( |
1157 | struct kiocb *iocb, | 1331 | struct kiocb *iocb, |
1158 | loff_t offset, | 1332 | loff_t offset, |
1159 | ssize_t size, | 1333 | ssize_t size, |
@@ -1191,7 +1365,7 @@ linvfs_end_io_direct( | |||
1191 | } | 1365 | } |
1192 | 1366 | ||
1193 | STATIC ssize_t | 1367 | STATIC ssize_t |
1194 | linvfs_direct_IO( | 1368 | xfs_vm_direct_IO( |
1195 | int rw, | 1369 | int rw, |
1196 | struct kiocb *iocb, | 1370 | struct kiocb *iocb, |
1197 | const struct iovec *iov, | 1371 | const struct iovec *iov, |
@@ -1200,7 +1374,7 @@ linvfs_direct_IO( | |||
1200 | { | 1374 | { |
1201 | struct file *file = iocb->ki_filp; | 1375 | struct file *file = iocb->ki_filp; |
1202 | struct inode *inode = file->f_mapping->host; | 1376 | struct inode *inode = file->f_mapping->host; |
1203 | vnode_t *vp = LINVFS_GET_VP(inode); | 1377 | vnode_t *vp = vn_from_inode(inode); |
1204 | xfs_iomap_t iomap; | 1378 | xfs_iomap_t iomap; |
1205 | int maps = 1; | 1379 | int maps = 1; |
1206 | int error; | 1380 | int error; |
@@ -1215,164 +1389,61 @@ linvfs_direct_IO( | |||
1215 | ret = blockdev_direct_IO_own_locking(rw, iocb, inode, | 1389 | ret = blockdev_direct_IO_own_locking(rw, iocb, inode, |
1216 | iomap.iomap_target->bt_bdev, | 1390 | iomap.iomap_target->bt_bdev, |
1217 | iov, offset, nr_segs, | 1391 | iov, offset, nr_segs, |
1218 | linvfs_get_blocks_direct, | 1392 | xfs_get_blocks_direct, |
1219 | linvfs_end_io_direct); | 1393 | xfs_end_io_direct); |
1220 | 1394 | ||
1221 | if (unlikely(ret <= 0 && iocb->private)) | 1395 | if (unlikely(ret <= 0 && iocb->private)) |
1222 | xfs_destroy_ioend(iocb->private); | 1396 | xfs_destroy_ioend(iocb->private); |
1223 | return ret; | 1397 | return ret; |
1224 | } | 1398 | } |
1225 | 1399 | ||
1400 | STATIC int | ||
1401 | xfs_vm_prepare_write( | ||
1402 | struct file *file, | ||
1403 | struct page *page, | ||
1404 | unsigned int from, | ||
1405 | unsigned int to) | ||
1406 | { | ||
1407 | return block_prepare_write(page, from, to, xfs_get_block); | ||
1408 | } | ||
1226 | 1409 | ||
1227 | STATIC sector_t | 1410 | STATIC sector_t |
1228 | linvfs_bmap( | 1411 | xfs_vm_bmap( |
1229 | struct address_space *mapping, | 1412 | struct address_space *mapping, |
1230 | sector_t block) | 1413 | sector_t block) |
1231 | { | 1414 | { |
1232 | struct inode *inode = (struct inode *)mapping->host; | 1415 | struct inode *inode = (struct inode *)mapping->host; |
1233 | vnode_t *vp = LINVFS_GET_VP(inode); | 1416 | vnode_t *vp = vn_from_inode(inode); |
1234 | int error; | 1417 | int error; |
1235 | 1418 | ||
1236 | vn_trace_entry(vp, "linvfs_bmap", (inst_t *)__return_address); | 1419 | vn_trace_entry(vp, __FUNCTION__, (inst_t *)__return_address); |
1237 | 1420 | ||
1238 | VOP_RWLOCK(vp, VRWLOCK_READ); | 1421 | VOP_RWLOCK(vp, VRWLOCK_READ); |
1239 | VOP_FLUSH_PAGES(vp, (xfs_off_t)0, -1, 0, FI_REMAPF, error); | 1422 | VOP_FLUSH_PAGES(vp, (xfs_off_t)0, -1, 0, FI_REMAPF, error); |
1240 | VOP_RWUNLOCK(vp, VRWLOCK_READ); | 1423 | VOP_RWUNLOCK(vp, VRWLOCK_READ); |
1241 | return generic_block_bmap(mapping, block, linvfs_get_block); | 1424 | return generic_block_bmap(mapping, block, xfs_get_block); |
1242 | } | 1425 | } |
1243 | 1426 | ||
1244 | STATIC int | 1427 | STATIC int |
1245 | linvfs_readpage( | 1428 | xfs_vm_readpage( |
1246 | struct file *unused, | 1429 | struct file *unused, |
1247 | struct page *page) | 1430 | struct page *page) |
1248 | { | 1431 | { |
1249 | return mpage_readpage(page, linvfs_get_block); | 1432 | return mpage_readpage(page, xfs_get_block); |
1250 | } | 1433 | } |
1251 | 1434 | ||
1252 | STATIC int | 1435 | STATIC int |
1253 | linvfs_readpages( | 1436 | xfs_vm_readpages( |
1254 | struct file *unused, | 1437 | struct file *unused, |
1255 | struct address_space *mapping, | 1438 | struct address_space *mapping, |
1256 | struct list_head *pages, | 1439 | struct list_head *pages, |
1257 | unsigned nr_pages) | 1440 | unsigned nr_pages) |
1258 | { | 1441 | { |
1259 | return mpage_readpages(mapping, pages, nr_pages, linvfs_get_block); | 1442 | return mpage_readpages(mapping, pages, nr_pages, xfs_get_block); |
1260 | } | ||
1261 | |||
1262 | STATIC void | ||
1263 | xfs_count_page_state( | ||
1264 | struct page *page, | ||
1265 | int *delalloc, | ||
1266 | int *unmapped, | ||
1267 | int *unwritten) | ||
1268 | { | ||
1269 | struct buffer_head *bh, *head; | ||
1270 | |||
1271 | *delalloc = *unmapped = *unwritten = 0; | ||
1272 | |||
1273 | bh = head = page_buffers(page); | ||
1274 | do { | ||
1275 | if (buffer_uptodate(bh) && !buffer_mapped(bh)) | ||
1276 | (*unmapped) = 1; | ||
1277 | else if (buffer_unwritten(bh) && !buffer_delay(bh)) | ||
1278 | clear_buffer_unwritten(bh); | ||
1279 | else if (buffer_unwritten(bh)) | ||
1280 | (*unwritten) = 1; | ||
1281 | else if (buffer_delay(bh)) | ||
1282 | (*delalloc) = 1; | ||
1283 | } while ((bh = bh->b_this_page) != head); | ||
1284 | } | 1443 | } |
1285 | 1444 | ||
1286 | |||
1287 | /* | ||
1288 | * writepage: Called from one of two places: | ||
1289 | * | ||
1290 | * 1. we are flushing a delalloc buffer head. | ||
1291 | * | ||
1292 | * 2. we are writing out a dirty page. Typically the page dirty | ||
1293 | * state is cleared before we get here. In this case is it | ||
1294 | * conceivable we have no buffer heads. | ||
1295 | * | ||
1296 | * For delalloc space on the page we need to allocate space and | ||
1297 | * flush it. For unmapped buffer heads on the page we should | ||
1298 | * allocate space if the page is uptodate. For any other dirty | ||
1299 | * buffer heads on the page we should flush them. | ||
1300 | * | ||
1301 | * If we detect that a transaction would be required to flush | ||
1302 | * the page, we have to check the process flags first, if we | ||
1303 | * are already in a transaction or disk I/O during allocations | ||
1304 | * is off, we need to fail the writepage and redirty the page. | ||
1305 | */ | ||
1306 | |||
1307 | STATIC int | 1445 | STATIC int |
1308 | linvfs_writepage( | 1446 | xfs_vm_invalidatepage( |
1309 | struct page *page, | ||
1310 | struct writeback_control *wbc) | ||
1311 | { | ||
1312 | int error; | ||
1313 | int need_trans; | ||
1314 | int delalloc, unmapped, unwritten; | ||
1315 | struct inode *inode = page->mapping->host; | ||
1316 | |||
1317 | xfs_page_trace(XFS_WRITEPAGE_ENTER, inode, page, 0); | ||
1318 | |||
1319 | /* | ||
1320 | * We need a transaction if: | ||
1321 | * 1. There are delalloc buffers on the page | ||
1322 | * 2. The page is uptodate and we have unmapped buffers | ||
1323 | * 3. The page is uptodate and we have no buffers | ||
1324 | * 4. There are unwritten buffers on the page | ||
1325 | */ | ||
1326 | |||
1327 | if (!page_has_buffers(page)) { | ||
1328 | unmapped = 1; | ||
1329 | need_trans = 1; | ||
1330 | } else { | ||
1331 | xfs_count_page_state(page, &delalloc, &unmapped, &unwritten); | ||
1332 | if (!PageUptodate(page)) | ||
1333 | unmapped = 0; | ||
1334 | need_trans = delalloc + unmapped + unwritten; | ||
1335 | } | ||
1336 | |||
1337 | /* | ||
1338 | * If we need a transaction and the process flags say | ||
1339 | * we are already in a transaction, or no IO is allowed | ||
1340 | * then mark the page dirty again and leave the page | ||
1341 | * as is. | ||
1342 | */ | ||
1343 | if (PFLAGS_TEST_FSTRANS() && need_trans) | ||
1344 | goto out_fail; | ||
1345 | |||
1346 | /* | ||
1347 | * Delay hooking up buffer heads until we have | ||
1348 | * made our go/no-go decision. | ||
1349 | */ | ||
1350 | if (!page_has_buffers(page)) | ||
1351 | create_empty_buffers(page, 1 << inode->i_blkbits, 0); | ||
1352 | |||
1353 | /* | ||
1354 | * Convert delayed allocate, unwritten or unmapped space | ||
1355 | * to real space and flush out to disk. | ||
1356 | */ | ||
1357 | error = xfs_page_state_convert(inode, page, wbc, 1, unmapped); | ||
1358 | if (error == -EAGAIN) | ||
1359 | goto out_fail; | ||
1360 | if (unlikely(error < 0)) | ||
1361 | goto out_unlock; | ||
1362 | |||
1363 | return 0; | ||
1364 | |||
1365 | out_fail: | ||
1366 | redirty_page_for_writepage(wbc, page); | ||
1367 | unlock_page(page); | ||
1368 | return 0; | ||
1369 | out_unlock: | ||
1370 | unlock_page(page); | ||
1371 | return error; | ||
1372 | } | ||
1373 | |||
1374 | STATIC int | ||
1375 | linvfs_invalidate_page( | ||
1376 | struct page *page, | 1447 | struct page *page, |
1377 | unsigned long offset) | 1448 | unsigned long offset) |
1378 | { | 1449 | { |
@@ -1381,87 +1452,16 @@ linvfs_invalidate_page( | |||
1381 | return block_invalidatepage(page, offset); | 1452 | return block_invalidatepage(page, offset); |
1382 | } | 1453 | } |
1383 | 1454 | ||
1384 | /* | 1455 | struct address_space_operations xfs_address_space_operations = { |
1385 | * Called to move a page into cleanable state - and from there | 1456 | .readpage = xfs_vm_readpage, |
1386 | * to be released. Possibly the page is already clean. We always | 1457 | .readpages = xfs_vm_readpages, |
1387 | * have buffer heads in this call. | 1458 | .writepage = xfs_vm_writepage, |
1388 | * | ||
1389 | * Returns 0 if the page is ok to release, 1 otherwise. | ||
1390 | * | ||
1391 | * Possible scenarios are: | ||
1392 | * | ||
1393 | * 1. We are being called to release a page which has been written | ||
1394 | * to via regular I/O. buffer heads will be dirty and possibly | ||
1395 | * delalloc. If no delalloc buffer heads in this case then we | ||
1396 | * can just return zero. | ||
1397 | * | ||
1398 | * 2. We are called to release a page which has been written via | ||
1399 | * mmap, all we need to do is ensure there is no delalloc | ||
1400 | * state in the buffer heads, if not we can let the caller | ||
1401 | * free them and we should come back later via writepage. | ||
1402 | */ | ||
1403 | STATIC int | ||
1404 | linvfs_release_page( | ||
1405 | struct page *page, | ||
1406 | gfp_t gfp_mask) | ||
1407 | { | ||
1408 | struct inode *inode = page->mapping->host; | ||
1409 | int dirty, delalloc, unmapped, unwritten; | ||
1410 | struct writeback_control wbc = { | ||
1411 | .sync_mode = WB_SYNC_ALL, | ||
1412 | .nr_to_write = 1, | ||
1413 | }; | ||
1414 | |||
1415 | xfs_page_trace(XFS_RELEASEPAGE_ENTER, inode, page, gfp_mask); | ||
1416 | |||
1417 | xfs_count_page_state(page, &delalloc, &unmapped, &unwritten); | ||
1418 | if (!delalloc && !unwritten) | ||
1419 | goto free_buffers; | ||
1420 | |||
1421 | if (!(gfp_mask & __GFP_FS)) | ||
1422 | return 0; | ||
1423 | |||
1424 | /* If we are already inside a transaction or the thread cannot | ||
1425 | * do I/O, we cannot release this page. | ||
1426 | */ | ||
1427 | if (PFLAGS_TEST_FSTRANS()) | ||
1428 | return 0; | ||
1429 | |||
1430 | /* | ||
1431 | * Convert delalloc space to real space, do not flush the | ||
1432 | * data out to disk, that will be done by the caller. | ||
1433 | * Never need to allocate space here - we will always | ||
1434 | * come back to writepage in that case. | ||
1435 | */ | ||
1436 | dirty = xfs_page_state_convert(inode, page, &wbc, 0, 0); | ||
1437 | if (dirty == 0 && !unwritten) | ||
1438 | goto free_buffers; | ||
1439 | return 0; | ||
1440 | |||
1441 | free_buffers: | ||
1442 | return try_to_free_buffers(page); | ||
1443 | } | ||
1444 | |||
1445 | STATIC int | ||
1446 | linvfs_prepare_write( | ||
1447 | struct file *file, | ||
1448 | struct page *page, | ||
1449 | unsigned int from, | ||
1450 | unsigned int to) | ||
1451 | { | ||
1452 | return block_prepare_write(page, from, to, linvfs_get_block); | ||
1453 | } | ||
1454 | |||
1455 | struct address_space_operations linvfs_aops = { | ||
1456 | .readpage = linvfs_readpage, | ||
1457 | .readpages = linvfs_readpages, | ||
1458 | .writepage = linvfs_writepage, | ||
1459 | .sync_page = block_sync_page, | 1459 | .sync_page = block_sync_page, |
1460 | .releasepage = linvfs_release_page, | 1460 | .releasepage = xfs_vm_releasepage, |
1461 | .invalidatepage = linvfs_invalidate_page, | 1461 | .invalidatepage = xfs_vm_invalidatepage, |
1462 | .prepare_write = linvfs_prepare_write, | 1462 | .prepare_write = xfs_vm_prepare_write, |
1463 | .commit_write = generic_commit_write, | 1463 | .commit_write = generic_commit_write, |
1464 | .bmap = linvfs_bmap, | 1464 | .bmap = xfs_vm_bmap, |
1465 | .direct_IO = linvfs_direct_IO, | 1465 | .direct_IO = xfs_vm_direct_IO, |
1466 | .migratepage = buffer_migrate_page, | 1466 | .migratepage = buffer_migrate_page, |
1467 | }; | 1467 | }; |