Skip to content

Commit

Permalink
Merge patch series "Finish converting jffs2 to folios"
Browse files Browse the repository at this point in the history
Matthew Wilcox (Oracle) <willy@infradead.org> says:

This patch series applies on top of fs-next. After applying these two
patches, there are no more references to 'struct page' in jffs2.  I
obviously haven't tested it at all beyond compilation.

* patches from https://lore.kernel.org/r/20240814195915.249871-1-willy@infradead.org:
  jffs2: Use a folio in jffs2_garbage_collect_dnode()
  jffs2: Convert jffs2_do_readpage_nolock to take a folio

Link: https://lore.kernel.org/r/20240814195915.249871-1-willy@infradead.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
  • Loading branch information
Christian Brauner committed Aug 19, 2024
2 parents 3e673d6 + 2da4c51 commit 424f8cb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
24 changes: 11 additions & 13 deletions fs/jffs2/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,37 +77,35 @@ const struct address_space_operations jffs2_file_address_operations =
.write_end = jffs2_write_end,
};

static int jffs2_do_readpage_nolock (struct inode *inode, struct page *pg)
static int jffs2_do_readpage_nolock(struct inode *inode, struct folio *folio)
{
struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
unsigned char *pg_buf;
unsigned char *kaddr;
int ret;

jffs2_dbg(2, "%s(): ino #%lu, page at offset 0x%lx\n",
__func__, inode->i_ino, pg->index << PAGE_SHIFT);
__func__, inode->i_ino, folio->index << PAGE_SHIFT);

BUG_ON(!PageLocked(pg));
BUG_ON(!folio_test_locked(folio));

pg_buf = kmap(pg);
/* FIXME: Can kmap fail? */

ret = jffs2_read_inode_range(c, f, pg_buf, pg->index << PAGE_SHIFT,
kaddr = kmap_local_folio(folio, 0);
ret = jffs2_read_inode_range(c, f, kaddr, folio->index << PAGE_SHIFT,
PAGE_SIZE);
kunmap_local(kaddr);

if (!ret)
SetPageUptodate(pg);
folio_mark_uptodate(folio);

flush_dcache_page(pg);
kunmap(pg);
flush_dcache_folio(folio);

jffs2_dbg(2, "readpage finished\n");
return ret;
}

int __jffs2_read_folio(struct file *file, struct folio *folio)
{
int ret = jffs2_do_readpage_nolock(folio->mapping->host, &folio->page);
int ret = jffs2_do_readpage_nolock(folio->mapping->host, folio);
folio_unlock(folio);
return ret;
}
Expand Down Expand Up @@ -221,7 +219,7 @@ static int jffs2_write_begin(struct file *filp, struct address_space *mapping,
*/
if (!folio_test_uptodate(folio)) {
mutex_lock(&f->sem);
ret = jffs2_do_readpage_nolock(inode, &folio->page);
ret = jffs2_do_readpage_nolock(inode, folio);
mutex_unlock(&f->sem);
if (ret) {
folio_unlock(folio);
Expand Down
25 changes: 12 additions & 13 deletions fs/jffs2/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,7 @@ static int jffs2_garbage_collect_dnode(struct jffs2_sb_info *c, struct jffs2_era
uint32_t alloclen, offset, orig_end, orig_start;
int ret = 0;
unsigned char *comprbuf = NULL, *writebuf;
struct page *page;
struct folio *folio;
unsigned char *pg_ptr;

memset(&ri, 0, sizeof(ri));
Expand Down Expand Up @@ -1317,25 +1317,25 @@ static int jffs2_garbage_collect_dnode(struct jffs2_sb_info *c, struct jffs2_era
BUG_ON(start > orig_start);
}

/* The rules state that we must obtain the page lock *before* f->sem, so
/* The rules state that we must obtain the folio lock *before* f->sem, so
* drop f->sem temporarily. Since we also hold c->alloc_sem, nothing's
* actually going to *change* so we're safe; we only allow reading.
*
* It is important to note that jffs2_write_begin() will ensure that its
* page is marked Uptodate before allocating space. That means that if we
* end up here trying to GC the *same* page that jffs2_write_begin() is
* trying to write out, read_cache_page() will not deadlock. */
* folio is marked uptodate before allocating space. That means that if we
* end up here trying to GC the *same* folio that jffs2_write_begin() is
* trying to write out, read_cache_folio() will not deadlock. */
mutex_unlock(&f->sem);
page = read_cache_page(inode->i_mapping, start >> PAGE_SHIFT,
folio = read_cache_folio(inode->i_mapping, start >> PAGE_SHIFT,
__jffs2_read_folio, NULL);
if (IS_ERR(page)) {
pr_warn("read_cache_page() returned error: %ld\n",
PTR_ERR(page));
if (IS_ERR(folio)) {
pr_warn("read_cache_folio() returned error: %ld\n",
PTR_ERR(folio));
mutex_lock(&f->sem);
return PTR_ERR(page);
return PTR_ERR(folio);
}

pg_ptr = kmap(page);
pg_ptr = kmap_local_folio(folio, 0);
mutex_lock(&f->sem);

offset = start;
Expand Down Expand Up @@ -1400,7 +1400,6 @@ static int jffs2_garbage_collect_dnode(struct jffs2_sb_info *c, struct jffs2_era
}
}

kunmap(page);
put_page(page);
folio_release_kmap(folio, pg_ptr);
return ret;
}

0 comments on commit 424f8cb

Please sign in to comment.