[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240528164829.2105447-6-willy@infradead.org>
Date: Tue, 28 May 2024 17:48:26 +0100
From: "Matthew Wilcox (Oracle)" <willy@...radead.org>
To: Christoph Hellwig <hch@....de>
Cc: "Matthew Wilcox (Oracle)" <willy@...radead.org>,
linux-fsdevel@...r.kernel.org,
linux-ext4@...r.kernel.org
Subject: [PATCH 5/7] ext2: Convert to buffered_write_operations
Move write_begin and write_end from the address_space_operations to
the new buffered_write_operations. Removes a number of hidden calls
to compound_head().
Signed-off-by: Matthew Wilcox (Oracle) <willy@...radead.org>
---
fs/ext2/ext2.h | 1 +
fs/ext2/file.c | 4 ++--
fs/ext2/inode.c | 55 ++++++++++++++++++++++++++-----------------------
fs/ext2/namei.c | 2 +-
4 files changed, 33 insertions(+), 29 deletions(-)
diff --git a/fs/ext2/ext2.h b/fs/ext2/ext2.h
index f38bdd46e4f7..89b498c81f18 100644
--- a/fs/ext2/ext2.h
+++ b/fs/ext2/ext2.h
@@ -784,6 +784,7 @@ extern const struct file_operations ext2_file_operations;
extern void ext2_set_file_ops(struct inode *inode);
extern const struct address_space_operations ext2_aops;
extern const struct iomap_ops ext2_iomap_ops;
+extern const struct buffered_write_operations ext2_bw_ops;
/* namei.c */
extern const struct inode_operations ext2_dir_inode_operations;
diff --git a/fs/ext2/file.c b/fs/ext2/file.c
index 10b061ac5bc0..108e8d2e9654 100644
--- a/fs/ext2/file.c
+++ b/fs/ext2/file.c
@@ -252,7 +252,7 @@ static ssize_t ext2_dio_write_iter(struct kiocb *iocb, struct iov_iter *from)
iocb->ki_flags &= ~IOCB_DIRECT;
pos = iocb->ki_pos;
- status = generic_perform_write(iocb, from);
+ status = filemap_perform_write(iocb, from, &ext2_bw_ops, NULL);
if (unlikely(status < 0)) {
ret = status;
goto out_unlock;
@@ -299,7 +299,7 @@ static ssize_t ext2_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
if (iocb->ki_flags & IOCB_DIRECT)
return ext2_dio_write_iter(iocb, from);
- return generic_file_write_iter(iocb, from);
+ return filemap_write_iter(iocb, from, &ext2_bw_ops, NULL);
}
static int ext2_file_open(struct inode *inode, struct file *filp)
diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c
index 0caa1650cee8..a89525d08aa3 100644
--- a/fs/ext2/inode.c
+++ b/fs/ext2/inode.c
@@ -914,30 +914,6 @@ static void ext2_readahead(struct readahead_control *rac)
mpage_readahead(rac, ext2_get_block);
}
-static int
-ext2_write_begin(struct file *file, struct address_space *mapping,
- loff_t pos, unsigned len, struct page **pagep, void **fsdata)
-{
- int ret;
-
- ret = block_write_begin(mapping, pos, len, pagep, ext2_get_block);
- if (ret < 0)
- ext2_write_failed(mapping, pos + len);
- return ret;
-}
-
-static int ext2_write_end(struct file *file, struct address_space *mapping,
- loff_t pos, unsigned len, unsigned copied,
- struct page *page, void *fsdata)
-{
- int ret;
-
- ret = generic_write_end(file, mapping, pos, len, copied, page, fsdata);
- if (ret < len)
- ext2_write_failed(mapping, pos + len);
- return ret;
-}
-
static sector_t ext2_bmap(struct address_space *mapping, sector_t block)
{
return generic_block_bmap(mapping,block,ext2_get_block);
@@ -962,8 +938,6 @@ const struct address_space_operations ext2_aops = {
.invalidate_folio = block_invalidate_folio,
.read_folio = ext2_read_folio,
.readahead = ext2_readahead,
- .write_begin = ext2_write_begin,
- .write_end = ext2_write_end,
.bmap = ext2_bmap,
.writepages = ext2_writepages,
.migrate_folio = buffer_migrate_folio,
@@ -976,6 +950,35 @@ static const struct address_space_operations ext2_dax_aops = {
.dirty_folio = noop_dirty_folio,
};
+static struct folio *ext2_write_begin(struct file *file,
+ struct address_space *mapping, loff_t pos, size_t len,
+ void **fsdata)
+{
+ struct folio *folio;
+
+ folio = buffer_write_begin(mapping, pos, len, ext2_get_block);
+
+ if (IS_ERR(folio))
+ ext2_write_failed(mapping, pos + len);
+ return folio;
+}
+
+static size_t ext2_write_end(struct file *file, struct address_space *mapping,
+ loff_t pos, size_t len, size_t copied, struct folio *folio,
+ void **fsdata)
+{
+ size_t ret = buffer_write_end(file, mapping, pos, len, copied, folio);
+
+ if (ret < len)
+ ext2_write_failed(mapping, pos + len);
+ return ret;
+}
+
+const struct buffered_write_operations ext2_bw_ops = {
+ .write_begin = ext2_write_begin,
+ .write_end = ext2_write_end,
+};
+
/*
* Probably it should be a library function... search for first non-zero word
* or memcmp with zero_page, whatever is better for particular architecture.
diff --git a/fs/ext2/namei.c b/fs/ext2/namei.c
index 8346ab9534c1..a0edb11be826 100644
--- a/fs/ext2/namei.c
+++ b/fs/ext2/namei.c
@@ -179,7 +179,7 @@ static int ext2_symlink (struct mnt_idmap * idmap, struct inode * dir,
inode->i_op = &ext2_symlink_inode_operations;
inode_nohighmem(inode);
inode->i_mapping->a_ops = &ext2_aops;
- err = page_symlink(inode, symname, l);
+ err = filemap_symlink(inode, symname, l, &ext2_bw_ops, NULL);
if (err)
goto out_fail;
} else {
--
2.43.0
Powered by blists - more mailing lists