| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* -*- mode: c; c-basic-offset: 8; -*- |
|---|
| 2 | 3 | * vim: noexpandtab sw=8 ts=8 sts=0: |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2002, 2004 Oracle. All rights reserved. |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or |
|---|
| 7 | | - * modify it under the terms of the GNU General Public |
|---|
| 8 | | - * License as published by the Free Software Foundation; either |
|---|
| 9 | | - * version 2 of the License, or (at your option) any later version. |
|---|
| 10 | | - * |
|---|
| 11 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 12 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 14 | | - * General Public License for more details. |
|---|
| 15 | | - * |
|---|
| 16 | | - * You should have received a copy of the GNU General Public |
|---|
| 17 | | - * License along with this program; if not, write to the |
|---|
| 18 | | - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
|---|
| 19 | | - * Boston, MA 021110-1307, USA. |
|---|
| 20 | 6 | */ |
|---|
| 21 | 7 | |
|---|
| 22 | 8 | #include <linux/fs.h> |
|---|
| .. | .. |
|---|
| 25 | 11 | #include <linux/pagemap.h> |
|---|
| 26 | 12 | #include <asm/byteorder.h> |
|---|
| 27 | 13 | #include <linux/swap.h> |
|---|
| 28 | | -#include <linux/pipe_fs_i.h> |
|---|
| 29 | 14 | #include <linux/mpage.h> |
|---|
| 30 | 15 | #include <linux/quotaops.h> |
|---|
| 31 | 16 | #include <linux/blkdev.h> |
|---|
| 32 | 17 | #include <linux/uio.h> |
|---|
| 18 | +#include <linux/mm.h> |
|---|
| 33 | 19 | |
|---|
| 34 | 20 | #include <cluster/masklog.h> |
|---|
| 35 | 21 | |
|---|
| .. | .. |
|---|
| 364 | 350 | * grow out to a tree. If need be, detecting boundary extents could |
|---|
| 365 | 351 | * trivially be added in a future version of ocfs2_get_block(). |
|---|
| 366 | 352 | */ |
|---|
| 367 | | -static int ocfs2_readpages(struct file *filp, struct address_space *mapping, |
|---|
| 368 | | - struct list_head *pages, unsigned nr_pages) |
|---|
| 353 | +static void ocfs2_readahead(struct readahead_control *rac) |
|---|
| 369 | 354 | { |
|---|
| 370 | | - int ret, err = -EIO; |
|---|
| 371 | | - struct inode *inode = mapping->host; |
|---|
| 355 | + int ret; |
|---|
| 356 | + struct inode *inode = rac->mapping->host; |
|---|
| 372 | 357 | struct ocfs2_inode_info *oi = OCFS2_I(inode); |
|---|
| 373 | | - loff_t start; |
|---|
| 374 | | - struct page *last; |
|---|
| 375 | 358 | |
|---|
| 376 | 359 | /* |
|---|
| 377 | 360 | * Use the nonblocking flag for the dlm code to avoid page |
|---|
| .. | .. |
|---|
| 379 | 362 | */ |
|---|
| 380 | 363 | ret = ocfs2_inode_lock_full(inode, NULL, 0, OCFS2_LOCK_NONBLOCK); |
|---|
| 381 | 364 | if (ret) |
|---|
| 382 | | - return err; |
|---|
| 365 | + return; |
|---|
| 383 | 366 | |
|---|
| 384 | | - if (down_read_trylock(&oi->ip_alloc_sem) == 0) { |
|---|
| 385 | | - ocfs2_inode_unlock(inode, 0); |
|---|
| 386 | | - return err; |
|---|
| 387 | | - } |
|---|
| 367 | + if (down_read_trylock(&oi->ip_alloc_sem) == 0) |
|---|
| 368 | + goto out_unlock; |
|---|
| 388 | 369 | |
|---|
| 389 | 370 | /* |
|---|
| 390 | 371 | * Don't bother with inline-data. There isn't anything |
|---|
| 391 | 372 | * to read-ahead in that case anyway... |
|---|
| 392 | 373 | */ |
|---|
| 393 | 374 | if (oi->ip_dyn_features & OCFS2_INLINE_DATA_FL) |
|---|
| 394 | | - goto out_unlock; |
|---|
| 375 | + goto out_up; |
|---|
| 395 | 376 | |
|---|
| 396 | 377 | /* |
|---|
| 397 | 378 | * Check whether a remote node truncated this file - we just |
|---|
| 398 | 379 | * drop out in that case as it's not worth handling here. |
|---|
| 399 | 380 | */ |
|---|
| 400 | | - last = list_entry(pages->prev, struct page, lru); |
|---|
| 401 | | - start = (loff_t)last->index << PAGE_SHIFT; |
|---|
| 402 | | - if (start >= i_size_read(inode)) |
|---|
| 403 | | - goto out_unlock; |
|---|
| 381 | + if (readahead_pos(rac) >= i_size_read(inode)) |
|---|
| 382 | + goto out_up; |
|---|
| 404 | 383 | |
|---|
| 405 | | - err = mpage_readpages(mapping, pages, nr_pages, ocfs2_get_block); |
|---|
| 384 | + mpage_readahead(rac, ocfs2_get_block); |
|---|
| 406 | 385 | |
|---|
| 407 | | -out_unlock: |
|---|
| 386 | +out_up: |
|---|
| 408 | 387 | up_read(&oi->ip_alloc_sem); |
|---|
| 388 | +out_unlock: |
|---|
| 409 | 389 | ocfs2_inode_unlock(inode, 0); |
|---|
| 410 | | - |
|---|
| 411 | | - return err; |
|---|
| 412 | 390 | } |
|---|
| 413 | 391 | |
|---|
| 414 | 392 | /* Note: Because we don't support holes, our allocation has |
|---|
| .. | .. |
|---|
| 955 | 933 | |
|---|
| 956 | 934 | if (tmppage && page_has_buffers(tmppage)) { |
|---|
| 957 | 935 | if (ocfs2_should_order_data(inode)) |
|---|
| 958 | | - ocfs2_jbd2_file_inode(wc->w_handle, inode); |
|---|
| 936 | + ocfs2_jbd2_inode_add_write(wc->w_handle, inode, |
|---|
| 937 | + user_pos, user_len); |
|---|
| 959 | 938 | |
|---|
| 960 | 939 | block_commit_write(tmppage, from, to); |
|---|
| 961 | 940 | } |
|---|
| .. | .. |
|---|
| 1392 | 1371 | unlock: |
|---|
| 1393 | 1372 | spin_unlock(&oi->ip_lock); |
|---|
| 1394 | 1373 | out: |
|---|
| 1395 | | - if (new) |
|---|
| 1396 | | - kfree(new); |
|---|
| 1374 | + kfree(new); |
|---|
| 1397 | 1375 | return ret; |
|---|
| 1398 | 1376 | } |
|---|
| 1399 | 1377 | |
|---|
| .. | .. |
|---|
| 2003 | 1981 | } |
|---|
| 2004 | 1982 | |
|---|
| 2005 | 1983 | if (unlikely(copied < len) && wc->w_target_page) { |
|---|
| 1984 | + loff_t new_isize; |
|---|
| 1985 | + |
|---|
| 2006 | 1986 | if (!PageUptodate(wc->w_target_page)) |
|---|
| 2007 | 1987 | copied = 0; |
|---|
| 2008 | 1988 | |
|---|
| 2009 | | - ocfs2_zero_new_buffers(wc->w_target_page, start+copied, |
|---|
| 2010 | | - start+len); |
|---|
| 1989 | + new_isize = max_t(loff_t, i_size_read(inode), pos + copied); |
|---|
| 1990 | + if (new_isize > page_offset(wc->w_target_page)) |
|---|
| 1991 | + ocfs2_zero_new_buffers(wc->w_target_page, start+copied, |
|---|
| 1992 | + start+len); |
|---|
| 1993 | + else { |
|---|
| 1994 | + /* |
|---|
| 1995 | + * When page is fully beyond new isize (data copy |
|---|
| 1996 | + * failed), do not bother zeroing the page. Invalidate |
|---|
| 1997 | + * it instead so that writeback does not get confused |
|---|
| 1998 | + * put page & buffer dirty bits into inconsistent |
|---|
| 1999 | + * state. |
|---|
| 2000 | + */ |
|---|
| 2001 | + block_invalidatepage(wc->w_target_page, 0, PAGE_SIZE); |
|---|
| 2002 | + } |
|---|
| 2011 | 2003 | } |
|---|
| 2012 | 2004 | if (wc->w_target_page) |
|---|
| 2013 | 2005 | flush_dcache_page(wc->w_target_page); |
|---|
| .. | .. |
|---|
| 2037 | 2029 | } |
|---|
| 2038 | 2030 | |
|---|
| 2039 | 2031 | if (page_has_buffers(tmppage)) { |
|---|
| 2040 | | - if (handle && ocfs2_should_order_data(inode)) |
|---|
| 2041 | | - ocfs2_jbd2_file_inode(handle, inode); |
|---|
| 2032 | + if (handle && ocfs2_should_order_data(inode)) { |
|---|
| 2033 | + loff_t start_byte = |
|---|
| 2034 | + ((loff_t)tmppage->index << PAGE_SHIFT) + |
|---|
| 2035 | + from; |
|---|
| 2036 | + loff_t length = to - from; |
|---|
| 2037 | + ocfs2_jbd2_inode_add_write(handle, inode, |
|---|
| 2038 | + start_byte, length); |
|---|
| 2039 | + } |
|---|
| 2042 | 2040 | block_commit_write(tmppage, from, to); |
|---|
| 2043 | 2041 | } |
|---|
| 2044 | 2042 | } |
|---|
| .. | .. |
|---|
| 2473 | 2471 | |
|---|
| 2474 | 2472 | const struct address_space_operations ocfs2_aops = { |
|---|
| 2475 | 2473 | .readpage = ocfs2_readpage, |
|---|
| 2476 | | - .readpages = ocfs2_readpages, |
|---|
| 2474 | + .readahead = ocfs2_readahead, |
|---|
| 2477 | 2475 | .writepage = ocfs2_writepage, |
|---|
| 2478 | 2476 | .write_begin = ocfs2_write_begin, |
|---|
| 2479 | 2477 | .write_end = ocfs2_write_end, |
|---|