Merge branch 'cow_readahead' of git://oss.oracle.com/git/tma/linux-2.6 into merge-2

+63 -17
+4 -3
fs/ocfs2/aops.c
··· 1642 return ret; 1643 } 1644 1645 - int ocfs2_write_begin_nolock(struct address_space *mapping, 1646 loff_t pos, unsigned len, unsigned flags, 1647 struct page **pagep, void **fsdata, 1648 struct buffer_head *di_bh, struct page *mmap_page) ··· 1693 mlog_errno(ret); 1694 goto out; 1695 } else if (ret == 1) { 1696 - ret = ocfs2_refcount_cow(inode, di_bh, 1697 wc->w_cpos, wc->w_clen, UINT_MAX); 1698 if (ret) { 1699 mlog_errno(ret); ··· 1855 */ 1856 down_write(&OCFS2_I(inode)->ip_alloc_sem); 1857 1858 - ret = ocfs2_write_begin_nolock(mapping, pos, len, flags, pagep, 1859 fsdata, di_bh, NULL); 1860 if (ret) { 1861 mlog_errno(ret);
··· 1642 return ret; 1643 } 1644 1645 + int ocfs2_write_begin_nolock(struct file *filp, 1646 + struct address_space *mapping, 1647 loff_t pos, unsigned len, unsigned flags, 1648 struct page **pagep, void **fsdata, 1649 struct buffer_head *di_bh, struct page *mmap_page) ··· 1692 mlog_errno(ret); 1693 goto out; 1694 } else if (ret == 1) { 1695 + ret = ocfs2_refcount_cow(inode, filp, di_bh, 1696 wc->w_cpos, wc->w_clen, UINT_MAX); 1697 if (ret) { 1698 mlog_errno(ret); ··· 1854 */ 1855 down_write(&OCFS2_I(inode)->ip_alloc_sem); 1856 1857 + ret = ocfs2_write_begin_nolock(file, mapping, pos, len, flags, pagep, 1858 fsdata, di_bh, NULL); 1859 if (ret) { 1860 mlog_errno(ret);
+2 -1
fs/ocfs2/aops.h
··· 48 loff_t pos, unsigned len, unsigned copied, 49 struct page *page, void *fsdata); 50 51 - int ocfs2_write_begin_nolock(struct address_space *mapping, 52 loff_t pos, unsigned len, unsigned flags, 53 struct page **pagep, void **fsdata, 54 struct buffer_head *di_bh, struct page *mmap_page);
··· 48 loff_t pos, unsigned len, unsigned copied, 49 struct page *page, void *fsdata); 50 51 + int ocfs2_write_begin_nolock(struct file *filp, 52 + struct address_space *mapping, 53 loff_t pos, unsigned len, unsigned flags, 54 struct page **pagep, void **fsdata, 55 struct buffer_head *di_bh, struct page *mmap_page);
+10 -7
fs/ocfs2/file.c
··· 360 if (!(ext_flags & OCFS2_EXT_REFCOUNTED)) 361 goto out; 362 363 - return ocfs2_refcount_cow(inode, fe_bh, cpos, 1, cpos+1); 364 365 out: 366 return status; ··· 903 zero_clusters = last_cpos - zero_cpos; 904 905 if (needs_cow) { 906 - rc = ocfs2_refcount_cow(inode, di_bh, zero_cpos, zero_clusters, 907 - UINT_MAX); 908 if (rc) { 909 mlog_errno(rc); 910 goto out; ··· 2052 } 2053 2054 static int ocfs2_prepare_inode_for_refcount(struct inode *inode, 2055 loff_t pos, size_t count, 2056 int *meta_level) 2057 { ··· 2070 2071 *meta_level = 1; 2072 2073 - ret = ocfs2_refcount_cow(inode, di_bh, cpos, clusters, UINT_MAX); 2074 if (ret) 2075 mlog_errno(ret); 2076 out: ··· 2078 return ret; 2079 } 2080 2081 - static int ocfs2_prepare_inode_for_write(struct dentry *dentry, 2082 loff_t *ppos, 2083 size_t count, 2084 int appending, ··· 2086 int *has_refcount) 2087 { 2088 int ret = 0, meta_level = 0; 2089 struct inode *inode = dentry->d_inode; 2090 loff_t saved_pos, end; 2091 ··· 2142 meta_level = -1; 2143 2144 ret = ocfs2_prepare_inode_for_refcount(inode, 2145 saved_pos, 2146 count, 2147 &meta_level); ··· 2257 } 2258 2259 can_do_direct = direct_io; 2260 - ret = ocfs2_prepare_inode_for_write(file->f_path.dentry, ppos, 2261 iocb->ki_left, appending, 2262 &can_do_direct, &has_refcount); 2263 if (ret < 0) { ··· 2376 { 2377 int ret; 2378 2379 - ret = ocfs2_prepare_inode_for_write(out->f_path.dentry, &sd->pos, 2380 sd->total_len, 0, NULL, NULL); 2381 if (ret < 0) { 2382 mlog_errno(ret);
··· 360 if (!(ext_flags & OCFS2_EXT_REFCOUNTED)) 361 goto out; 362 363 + return ocfs2_refcount_cow(inode, NULL, fe_bh, cpos, 1, cpos+1); 364 365 out: 366 return status; ··· 903 zero_clusters = last_cpos - zero_cpos; 904 905 if (needs_cow) { 906 + rc = ocfs2_refcount_cow(inode, NULL, di_bh, zero_cpos, 907 + zero_clusters, UINT_MAX); 908 if (rc) { 909 mlog_errno(rc); 910 goto out; ··· 2052 } 2053 2054 static int ocfs2_prepare_inode_for_refcount(struct inode *inode, 2055 + struct file *file, 2056 loff_t pos, size_t count, 2057 int *meta_level) 2058 { ··· 2069 2070 *meta_level = 1; 2071 2072 + ret = ocfs2_refcount_cow(inode, file, di_bh, cpos, clusters, UINT_MAX); 2073 if (ret) 2074 mlog_errno(ret); 2075 out: ··· 2077 return ret; 2078 } 2079 2080 + static int ocfs2_prepare_inode_for_write(struct file *file, 2081 loff_t *ppos, 2082 size_t count, 2083 int appending, ··· 2085 int *has_refcount) 2086 { 2087 int ret = 0, meta_level = 0; 2088 + struct dentry *dentry = file->f_path.dentry; 2089 struct inode *inode = dentry->d_inode; 2090 loff_t saved_pos, end; 2091 ··· 2140 meta_level = -1; 2141 2142 ret = ocfs2_prepare_inode_for_refcount(inode, 2143 + file, 2144 saved_pos, 2145 count, 2146 &meta_level); ··· 2254 } 2255 2256 can_do_direct = direct_io; 2257 + ret = ocfs2_prepare_inode_for_write(file, ppos, 2258 iocb->ki_left, appending, 2259 &can_do_direct, &has_refcount); 2260 if (ret < 0) { ··· 2373 { 2374 int ret; 2375 2376 + ret = ocfs2_prepare_inode_for_write(out, &sd->pos, 2377 sd->total_len, 0, NULL, NULL); 2378 if (ret < 0) { 2379 mlog_errno(ret);
+4 -3
fs/ocfs2/mmap.c
··· 59 return ret; 60 } 61 62 - static int __ocfs2_page_mkwrite(struct inode *inode, struct buffer_head *di_bh, 63 struct page *page) 64 { 65 int ret; 66 struct address_space *mapping = inode->i_mapping; 67 loff_t pos = page_offset(page); 68 unsigned int len = PAGE_CACHE_SIZE; ··· 112 if (page->index == last_index) 113 len = ((size - 1) & ~PAGE_CACHE_MASK) + 1; 114 115 - ret = ocfs2_write_begin_nolock(mapping, pos, len, 0, &locked_page, 116 &fsdata, di_bh, page); 117 if (ret) { 118 if (ret != -ENOSPC) ··· 160 */ 161 down_write(&OCFS2_I(inode)->ip_alloc_sem); 162 163 - ret = __ocfs2_page_mkwrite(inode, di_bh, page); 164 165 up_write(&OCFS2_I(inode)->ip_alloc_sem); 166
··· 59 return ret; 60 } 61 62 + static int __ocfs2_page_mkwrite(struct file *file, struct buffer_head *di_bh, 63 struct page *page) 64 { 65 int ret; 66 + struct inode *inode = file->f_path.dentry->d_inode; 67 struct address_space *mapping = inode->i_mapping; 68 loff_t pos = page_offset(page); 69 unsigned int len = PAGE_CACHE_SIZE; ··· 111 if (page->index == last_index) 112 len = ((size - 1) & ~PAGE_CACHE_MASK) + 1; 113 114 + ret = ocfs2_write_begin_nolock(file, mapping, pos, len, 0, &locked_page, 115 &fsdata, di_bh, page); 116 if (ret) { 117 if (ret != -ENOSPC) ··· 159 */ 160 down_write(&OCFS2_I(inode)->ip_alloc_sem); 161 162 + ret = __ocfs2_page_mkwrite(vma->vm_file, di_bh, page); 163 164 up_write(&OCFS2_I(inode)->ip_alloc_sem); 165
+41 -2
fs/ocfs2/refcounttree.c
··· 49 50 struct ocfs2_cow_context { 51 struct inode *inode; 52 u32 cow_start; 53 u32 cow_len; 54 struct ocfs2_extent_tree data_et; ··· 2933 u64 new_block = ocfs2_clusters_to_blocks(sb, new_cluster); 2934 struct page *page; 2935 pgoff_t page_index; 2936 - unsigned int from, to; 2937 loff_t offset, end, map_end; 2938 struct address_space *mapping = context->inode->i_mapping; 2939 2940 mlog(0, "old_cluster %u, new %u, len %u at offset %u\n", old_cluster, 2941 new_cluster, new_len, cpos); 2942 2943 offset = ((loff_t)cpos) << OCFS2_SB(sb)->s_clustersize_bits; 2944 end = offset + (new_len << OCFS2_SB(sb)->s_clustersize_bits); 2945 /* ··· 2972 */ 2973 if (PAGE_CACHE_SIZE <= OCFS2_SB(sb)->s_clustersize) 2974 BUG_ON(PageDirty(page)); 2975 2976 if (!PageUptodate(page)) { 2977 ret = block_read_full_page(page, ocfs2_get_block); ··· 3421 return ret; 3422 } 3423 3424 /* 3425 * Starting at cpos, try to CoW write_len clusters. Don't CoW 3426 * past max_cpos. This will stop when it runs into a hole or an 3427 * unrefcounted extent. 3428 */ 3429 static int ocfs2_refcount_cow_hunk(struct inode *inode, 3430 struct buffer_head *di_bh, 3431 u32 cpos, u32 write_len, u32 max_cpos) 3432 { ··· 3478 3479 BUG_ON(cow_len == 0); 3480 3481 context = kzalloc(sizeof(struct ocfs2_cow_context), GFP_NOFS); 3482 if (!context) { 3483 ret = -ENOMEM; ··· 3501 context->ref_root_bh = ref_root_bh; 3502 context->cow_duplicate_clusters = ocfs2_duplicate_clusters_by_page; 3503 context->get_clusters = ocfs2_di_get_clusters; 3504 3505 ocfs2_init_dinode_extent_tree(&context->data_et, 3506 INODE_CACHE(inode), di_bh); ··· 3530 * clusters between cpos and cpos+write_len are safe to modify. 3531 */ 3532 int ocfs2_refcount_cow(struct inode *inode, 3533 struct buffer_head *di_bh, 3534 u32 cpos, u32 write_len, u32 max_cpos) 3535 { ··· 3550 num_clusters = write_len; 3551 3552 if (ext_flags & OCFS2_EXT_REFCOUNTED) { 3553 - ret = ocfs2_refcount_cow_hunk(inode, di_bh, cpos, 3554 num_clusters, max_cpos); 3555 if (ret) { 3556 mlog_errno(ret);
··· 49 50 struct ocfs2_cow_context { 51 struct inode *inode; 52 + struct file *file; 53 u32 cow_start; 54 u32 cow_len; 55 struct ocfs2_extent_tree data_et; ··· 2932 u64 new_block = ocfs2_clusters_to_blocks(sb, new_cluster); 2933 struct page *page; 2934 pgoff_t page_index; 2935 + unsigned int from, to, readahead_pages; 2936 loff_t offset, end, map_end; 2937 struct address_space *mapping = context->inode->i_mapping; 2938 2939 mlog(0, "old_cluster %u, new %u, len %u at offset %u\n", old_cluster, 2940 new_cluster, new_len, cpos); 2941 2942 + readahead_pages = 2943 + (ocfs2_cow_contig_clusters(sb) << 2944 + OCFS2_SB(sb)->s_clustersize_bits) >> PAGE_CACHE_SHIFT; 2945 offset = ((loff_t)cpos) << OCFS2_SB(sb)->s_clustersize_bits; 2946 end = offset + (new_len << OCFS2_SB(sb)->s_clustersize_bits); 2947 /* ··· 2968 */ 2969 if (PAGE_CACHE_SIZE <= OCFS2_SB(sb)->s_clustersize) 2970 BUG_ON(PageDirty(page)); 2971 + 2972 + if (PageReadahead(page) && context->file) { 2973 + page_cache_async_readahead(mapping, 2974 + &context->file->f_ra, 2975 + context->file, 2976 + page, page_index, 2977 + readahead_pages); 2978 + } 2979 2980 if (!PageUptodate(page)) { 2981 ret = block_read_full_page(page, ocfs2_get_block); ··· 3409 return ret; 3410 } 3411 3412 + static void ocfs2_readahead_for_cow(struct inode *inode, 3413 + struct file *file, 3414 + u32 start, u32 len) 3415 + { 3416 + struct address_space *mapping; 3417 + pgoff_t index; 3418 + unsigned long num_pages; 3419 + int cs_bits = OCFS2_SB(inode->i_sb)->s_clustersize_bits; 3420 + 3421 + if (!file) 3422 + return; 3423 + 3424 + mapping = file->f_mapping; 3425 + num_pages = (len << cs_bits) >> PAGE_CACHE_SHIFT; 3426 + if (!num_pages) 3427 + num_pages = 1; 3428 + 3429 + index = ((loff_t)start << cs_bits) >> PAGE_CACHE_SHIFT; 3430 + page_cache_sync_readahead(mapping, &file->f_ra, file, 3431 + index, num_pages); 3432 + } 3433 + 3434 /* 3435 * Starting at cpos, try to CoW write_len clusters. Don't CoW 3436 * past max_cpos. This will stop when it runs into a hole or an 3437 * unrefcounted extent. 3438 */ 3439 static int ocfs2_refcount_cow_hunk(struct inode *inode, 3440 + struct file *file, 3441 struct buffer_head *di_bh, 3442 u32 cpos, u32 write_len, u32 max_cpos) 3443 { ··· 3443 3444 BUG_ON(cow_len == 0); 3445 3446 + ocfs2_readahead_for_cow(inode, file, cow_start, cow_len); 3447 + 3448 context = kzalloc(sizeof(struct ocfs2_cow_context), GFP_NOFS); 3449 if (!context) { 3450 ret = -ENOMEM; ··· 3464 context->ref_root_bh = ref_root_bh; 3465 context->cow_duplicate_clusters = ocfs2_duplicate_clusters_by_page; 3466 context->get_clusters = ocfs2_di_get_clusters; 3467 + context->file = file; 3468 3469 ocfs2_init_dinode_extent_tree(&context->data_et, 3470 INODE_CACHE(inode), di_bh); ··· 3492 * clusters between cpos and cpos+write_len are safe to modify. 3493 */ 3494 int ocfs2_refcount_cow(struct inode *inode, 3495 + struct file *file, 3496 struct buffer_head *di_bh, 3497 u32 cpos, u32 write_len, u32 max_cpos) 3498 { ··· 3511 num_clusters = write_len; 3512 3513 if (ext_flags & OCFS2_EXT_REFCOUNTED) { 3514 + ret = ocfs2_refcount_cow_hunk(inode, file, di_bh, cpos, 3515 num_clusters, max_cpos); 3516 if (ret) { 3517 mlog_errno(ret);
+2 -1
fs/ocfs2/refcounttree.h
··· 52 u32 clusters, 53 int *credits, 54 int *ref_blocks); 55 - int ocfs2_refcount_cow(struct inode *inode, struct buffer_head *di_bh, 56 u32 cpos, u32 write_len, u32 max_cpos); 57 58 typedef int (ocfs2_post_refcount_func)(struct inode *inode,
··· 52 u32 clusters, 53 int *credits, 54 int *ref_blocks); 55 + int ocfs2_refcount_cow(struct inode *inode, 56 + struct file *filep, struct buffer_head *di_bh, 57 u32 cpos, u32 write_len, u32 max_cpos); 58 59 typedef int (ocfs2_post_refcount_func)(struct inode *inode,