orangefs: Pass mapping to orangefs_writepages_work()

Remove two accesses to page->mapping by passing the mapping from
orangefs_writepages() to orangefs_writepages_callback() and then
orangefs_writepages_work().  That makes it obvious that all folios come
from the same mapping, so we can hoist the call to mapping_set_error()
outside the loop.  While I'm here, switch from write_cache_pages()
to writeback_iter() which removes an indirect function call.

Signed-off-by: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Link: https://lore.kernel.org/r/20250305204734.1475264-7-willy@infradead.org
Tested-by: Mike Marshall <hubcap@omnibond.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
Matthew Wilcox (Oracle) 2025-03-05 20:47:30 +00:00 committed by Christian Brauner
parent 40eca026bb
commit 6420f17963
No known key found for this signature in database
GPG Key ID: 91C61BC06578DCA2

View File

@ -71,14 +71,15 @@ struct orangefs_writepages {
kgid_t gid;
int maxpages;
int npages;
struct address_space *mapping;
struct page **pages;
struct bio_vec *bv;
};
static int orangefs_writepages_work(struct orangefs_writepages *ow,
struct writeback_control *wbc)
struct writeback_control *wbc)
{
struct inode *inode = ow->pages[0]->mapping->host;
struct inode *inode = ow->mapping->host;
struct orangefs_write_range *wrp, wr;
struct iov_iter iter;
ssize_t ret;
@ -107,8 +108,8 @@ static int orangefs_writepages_work(struct orangefs_writepages *ow,
ret = wait_for_direct_io(ORANGEFS_IO_WRITE, inode, &off, &iter, ow->len,
0, &wr, NULL, NULL);
if (ret < 0) {
mapping_set_error(ow->mapping, ret);
for (i = 0; i < ow->npages; i++) {
mapping_set_error(ow->pages[i]->mapping, ret);
if (PagePrivate(ow->pages[i])) {
wrp = (struct orangefs_write_range *)
page_private(ow->pages[i]);
@ -137,9 +138,8 @@ static int orangefs_writepages_work(struct orangefs_writepages *ow,
}
static int orangefs_writepages_callback(struct folio *folio,
struct writeback_control *wbc, void *data)
struct writeback_control *wbc, struct orangefs_writepages *ow)
{
struct orangefs_writepages *ow = data;
struct orangefs_write_range *wr = folio->private;
int ret;
@ -197,7 +197,9 @@ static int orangefs_writepages(struct address_space *mapping,
{
struct orangefs_writepages *ow;
struct blk_plug plug;
int ret;
int error;
struct folio *folio = NULL;
ow = kzalloc(sizeof(struct orangefs_writepages), GFP_KERNEL);
if (!ow)
return -ENOMEM;
@ -213,15 +215,17 @@ static int orangefs_writepages(struct address_space *mapping,
kfree(ow);
return -ENOMEM;
}
ow->mapping = mapping;
blk_start_plug(&plug);
ret = write_cache_pages(mapping, wbc, orangefs_writepages_callback, ow);
while ((folio = writeback_iter(mapping, wbc, folio, &error)))
error = orangefs_writepages_callback(folio, wbc, ow);
if (ow->npages)
ret = orangefs_writepages_work(ow, wbc);
error = orangefs_writepages_work(ow, wbc);
blk_finish_plug(&plug);
kfree(ow->pages);
kfree(ow->bv);
kfree(ow);
return ret;
return error;
}
static int orangefs_launder_folio(struct folio *);