hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/fs/ocfs2/aops.c
....@@ -1,22 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /* -*- mode: c; c-basic-offset: 8; -*-
23 * vim: noexpandtab sw=8 ts=8 sts=0:
34 *
45 * 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.
206 */
217
228 #include <linux/fs.h>
....@@ -25,11 +11,11 @@
2511 #include <linux/pagemap.h>
2612 #include <asm/byteorder.h>
2713 #include <linux/swap.h>
28
-#include <linux/pipe_fs_i.h>
2914 #include <linux/mpage.h>
3015 #include <linux/quotaops.h>
3116 #include <linux/blkdev.h>
3217 #include <linux/uio.h>
18
+#include <linux/mm.h>
3319
3420 #include <cluster/masklog.h>
3521
....@@ -364,14 +350,11 @@
364350 * grow out to a tree. If need be, detecting boundary extents could
365351 * trivially be added in a future version of ocfs2_get_block().
366352 */
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)
369354 {
370
- int ret, err = -EIO;
371
- struct inode *inode = mapping->host;
355
+ int ret;
356
+ struct inode *inode = rac->mapping->host;
372357 struct ocfs2_inode_info *oi = OCFS2_I(inode);
373
- loff_t start;
374
- struct page *last;
375358
376359 /*
377360 * Use the nonblocking flag for the dlm code to avoid page
....@@ -379,36 +362,31 @@
379362 */
380363 ret = ocfs2_inode_lock_full(inode, NULL, 0, OCFS2_LOCK_NONBLOCK);
381364 if (ret)
382
- return err;
365
+ return;
383366
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;
388369
389370 /*
390371 * Don't bother with inline-data. There isn't anything
391372 * to read-ahead in that case anyway...
392373 */
393374 if (oi->ip_dyn_features & OCFS2_INLINE_DATA_FL)
394
- goto out_unlock;
375
+ goto out_up;
395376
396377 /*
397378 * Check whether a remote node truncated this file - we just
398379 * drop out in that case as it's not worth handling here.
399380 */
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;
404383
405
- err = mpage_readpages(mapping, pages, nr_pages, ocfs2_get_block);
384
+ mpage_readahead(rac, ocfs2_get_block);
406385
407
-out_unlock:
386
+out_up:
408387 up_read(&oi->ip_alloc_sem);
388
+out_unlock:
409389 ocfs2_inode_unlock(inode, 0);
410
-
411
- return err;
412390 }
413391
414392 /* Note: Because we don't support holes, our allocation has
....@@ -955,7 +933,8 @@
955933
956934 if (tmppage && page_has_buffers(tmppage)) {
957935 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);
959938
960939 block_commit_write(tmppage, from, to);
961940 }
....@@ -1392,8 +1371,7 @@
13921371 unlock:
13931372 spin_unlock(&oi->ip_lock);
13941373 out:
1395
- if (new)
1396
- kfree(new);
1374
+ kfree(new);
13971375 return ret;
13981376 }
13991377
....@@ -2003,11 +1981,25 @@
20031981 }
20041982
20051983 if (unlikely(copied < len) && wc->w_target_page) {
1984
+ loff_t new_isize;
1985
+
20061986 if (!PageUptodate(wc->w_target_page))
20071987 copied = 0;
20081988
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
+ }
20112003 }
20122004 if (wc->w_target_page)
20132005 flush_dcache_page(wc->w_target_page);
....@@ -2037,8 +2029,14 @@
20372029 }
20382030
20392031 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
+ }
20422040 block_commit_write(tmppage, from, to);
20432041 }
20442042 }
....@@ -2473,7 +2471,7 @@
24732471
24742472 const struct address_space_operations ocfs2_aops = {
24752473 .readpage = ocfs2_readpage,
2476
- .readpages = ocfs2_readpages,
2474
+ .readahead = ocfs2_readahead,
24772475 .writepage = ocfs2_writepage,
24782476 .write_begin = ocfs2_write_begin,
24792477 .write_end = ocfs2_write_end,