Skip to content

Commit af10dd1

Browse files
Matthew Wilcox (Oracle)jmberg-intel
authored andcommitted
hostfs: Convert to writepages
If we add a migrate_folio operation, we can convert the writepage operation to writepages. The large folio support here is illusory; we would need to kmap each page in turn for proper support. But we do remove a few hidden calls to compound_head(). Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Link: https://patch.msgid.link/20241220051500.1919389-1-willy@infradead.org Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent 579e7fd commit af10dd1

File tree

1 file changed

+25
-29
lines changed

1 file changed

+25
-29
lines changed

fs/hostfs/hostfs_kern.c

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -410,38 +410,33 @@ static const struct file_operations hostfs_dir_fops = {
410410
.fsync = hostfs_fsync,
411411
};
412412

413-
static int hostfs_writepage(struct page *page, struct writeback_control *wbc)
413+
static int hostfs_writepages(struct address_space *mapping,
414+
struct writeback_control *wbc)
414415
{
415-
struct address_space *mapping = page->mapping;
416416
struct inode *inode = mapping->host;
417-
char *buffer;
418-
loff_t base = page_offset(page);
419-
int count = PAGE_SIZE;
420-
int end_index = inode->i_size >> PAGE_SHIFT;
421-
int err;
422-
423-
if (page->index >= end_index)
424-
count = inode->i_size & (PAGE_SIZE-1);
425-
426-
buffer = kmap_local_page(page);
427-
428-
err = write_file(HOSTFS_I(inode)->fd, &base, buffer, count);
429-
if (err != count) {
430-
if (err >= 0)
431-
err = -EIO;
432-
mapping_set_error(mapping, err);
433-
goto out;
417+
struct folio *folio = NULL;
418+
loff_t i_size = i_size_read(inode);
419+
int err = 0;
420+
421+
while ((folio = writeback_iter(mapping, wbc, folio, &err))) {
422+
loff_t pos = folio_pos(folio);
423+
size_t count = folio_size(folio);
424+
char *buffer;
425+
int ret;
426+
427+
if (count > i_size - pos)
428+
count = i_size - pos;
429+
430+
buffer = kmap_local_folio(folio, 0);
431+
ret = write_file(HOSTFS_I(inode)->fd, &pos, buffer, count);
432+
kunmap_local(buffer);
433+
folio_unlock(folio);
434+
if (ret != count) {
435+
err = ret < 0 ? ret : -EIO;
436+
mapping_set_error(mapping, err);
437+
}
434438
}
435439

436-
if (base > inode->i_size)
437-
inode->i_size = base;
438-
439-
err = 0;
440-
441-
out:
442-
kunmap_local(buffer);
443-
unlock_page(page);
444-
445440
return err;
446441
}
447442

@@ -506,11 +501,12 @@ static int hostfs_write_end(struct file *file, struct address_space *mapping,
506501
}
507502

508503
static const struct address_space_operations hostfs_aops = {
509-
.writepage = hostfs_writepage,
504+
.writepages = hostfs_writepages,
510505
.read_folio = hostfs_read_folio,
511506
.dirty_folio = filemap_dirty_folio,
512507
.write_begin = hostfs_write_begin,
513508
.write_end = hostfs_write_end,
509+
.migrate_folio = filemap_migrate_folio,
514510
};
515511

516512
static int hostfs_inode_update(struct inode *ino, const struct hostfs_stat *st)

0 commit comments

Comments
 (0)