Commit 371c1414 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'jfs-6.11' of github.com:kleikamp/linux-shaggy

Pull jfs updates from David Kleikamp:
 "Folio conversion from Matthew Wilcox and a few various fixes"

* tag 'jfs-6.11' of github.com:kleikamp/linux-shaggy:
  jfs: don't walk off the end of ealist
  jfs: Fix shift-out-of-bounds in dbDiscardAG
  jfs: Fix array-index-out-of-bounds in diFree
  jfs: fix null ptr deref in dtInsertEntry
  jfs: Remove use of folio error flag
  fs: Remove i_blocks_per_page
  jfs: Change metapage->page to metapage->folio
  jfs: Convert force_metapage to use a folio
  jfs: Convert inc_io to take a folio
  jfs: Convert page_to_mp to folio_to_mp
  jfs; Convert __invalidate_metapages to use a folio
  jfs: Convert dec_io to take a folio
  jfs: Convert drop_metapage and remove_metapage to take a folio
  jfs; Convert release_metapage to use a folio
  jfs: Convert insert_metapage() to take a folio
  jfs: Convert __get_metapage to use a folio
  jfs: Convert metapage_writepage to metapage_write_folio
  jfs: Convert metapage_read_folio to use folio APIs
parents ca83c61c d0fa70ac
...@@ -1626,6 +1626,8 @@ s64 dbDiscardAG(struct inode *ip, int agno, s64 minlen) ...@@ -1626,6 +1626,8 @@ s64 dbDiscardAG(struct inode *ip, int agno, s64 minlen)
} else if (rc == -ENOSPC) { } else if (rc == -ENOSPC) {
/* search for next smaller log2 block */ /* search for next smaller log2 block */
l2nb = BLKSTOL2(nblocks) - 1; l2nb = BLKSTOL2(nblocks) - 1;
if (unlikely(l2nb < 0))
break;
nblocks = 1LL << l2nb; nblocks = 1LL << l2nb;
} else { } else {
/* Trim any already allocated blocks */ /* Trim any already allocated blocks */
......
...@@ -834,6 +834,8 @@ int dtInsert(tid_t tid, struct inode *ip, ...@@ -834,6 +834,8 @@ int dtInsert(tid_t tid, struct inode *ip,
* the full page. * the full page.
*/ */
DT_GETSEARCH(ip, btstack->top, bn, mp, p, index); DT_GETSEARCH(ip, btstack->top, bn, mp, p, index);
if (p->header.freelist == 0)
return -EINVAL;
/* /*
* insert entry for new key * insert entry for new key
......
...@@ -290,7 +290,7 @@ int diSync(struct inode *ipimap) ...@@ -290,7 +290,7 @@ int diSync(struct inode *ipimap)
int diRead(struct inode *ip) int diRead(struct inode *ip)
{ {
struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb); struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
int iagno, ino, extno, rc; int iagno, ino, extno, rc, agno;
struct inode *ipimap; struct inode *ipimap;
struct dinode *dp; struct dinode *dp;
struct iag *iagp; struct iag *iagp;
...@@ -339,8 +339,11 @@ int diRead(struct inode *ip) ...@@ -339,8 +339,11 @@ int diRead(struct inode *ip)
/* get the ag for the iag */ /* get the ag for the iag */
agstart = le64_to_cpu(iagp->agstart); agstart = le64_to_cpu(iagp->agstart);
agno = BLKTOAG(agstart, JFS_SBI(ip->i_sb));
release_metapage(mp); release_metapage(mp);
if (agno >= MAXAG || agno < 0)
return -EIO;
rel_inode = (ino & (INOSPERPAGE - 1)); rel_inode = (ino & (INOSPERPAGE - 1));
pageno = blkno >> sbi->l2nbperpage; pageno = blkno >> sbi->l2nbperpage;
......
...@@ -1600,7 +1600,7 @@ void jfs_flush_journal(struct jfs_log *log, int wait) ...@@ -1600,7 +1600,7 @@ void jfs_flush_journal(struct jfs_log *log, int wait)
mp, sizeof(struct metapage), 0); mp, sizeof(struct metapage), 0);
print_hex_dump(KERN_ERR, "page: ", print_hex_dump(KERN_ERR, "page: ",
DUMP_PREFIX_ADDRESS, 16, DUMP_PREFIX_ADDRESS, 16,
sizeof(long), mp->page, sizeof(long), mp->folio,
sizeof(struct page), 0); sizeof(struct page), 0);
} else } else
print_hex_dump(KERN_ERR, "tblock:", print_hex_dump(KERN_ERR, "tblock:",
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
* Portions Copyright (C) Christoph Hellwig, 2001-2002 * Portions Copyright (C) Christoph Hellwig, 2001-2002
*/ */
#include <linux/blkdev.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/module.h> #include <linux/module.h>
...@@ -46,9 +47,9 @@ static inline void __lock_metapage(struct metapage *mp) ...@@ -46,9 +47,9 @@ static inline void __lock_metapage(struct metapage *mp)
do { do {
set_current_state(TASK_UNINTERRUPTIBLE); set_current_state(TASK_UNINTERRUPTIBLE);
if (metapage_locked(mp)) { if (metapage_locked(mp)) {
unlock_page(mp->page); folio_unlock(mp->folio);
io_schedule(); io_schedule();
lock_page(mp->page); folio_lock(mp->folio);
} }
} while (trylock_metapage(mp)); } while (trylock_metapage(mp));
__set_current_state(TASK_RUNNING); __set_current_state(TASK_RUNNING);
...@@ -56,7 +57,7 @@ static inline void __lock_metapage(struct metapage *mp) ...@@ -56,7 +57,7 @@ static inline void __lock_metapage(struct metapage *mp)
} }
/* /*
* Must have mp->page locked * Must have mp->folio locked
*/ */
static inline void lock_metapage(struct metapage *mp) static inline void lock_metapage(struct metapage *mp)
{ {
...@@ -75,36 +76,36 @@ static mempool_t *metapage_mempool; ...@@ -75,36 +76,36 @@ static mempool_t *metapage_mempool;
struct meta_anchor { struct meta_anchor {
int mp_count; int mp_count;
atomic_t io_count; atomic_t io_count;
blk_status_t status;
struct metapage *mp[MPS_PER_PAGE]; struct metapage *mp[MPS_PER_PAGE];
}; };
#define mp_anchor(page) ((struct meta_anchor *)page_private(page))
static inline struct metapage *page_to_mp(struct page *page, int offset) static inline struct metapage *folio_to_mp(struct folio *folio, int offset)
{ {
if (!PagePrivate(page)) struct meta_anchor *anchor = folio->private;
if (!anchor)
return NULL; return NULL;
return mp_anchor(page)->mp[offset >> L2PSIZE]; return anchor->mp[offset >> L2PSIZE];
} }
static inline int insert_metapage(struct page *page, struct metapage *mp) static inline int insert_metapage(struct folio *folio, struct metapage *mp)
{ {
struct meta_anchor *a; struct meta_anchor *a;
int index; int index;
int l2mp_blocks; /* log2 blocks per metapage */ int l2mp_blocks; /* log2 blocks per metapage */
if (PagePrivate(page)) a = folio->private;
a = mp_anchor(page); if (!a) {
else {
a = kzalloc(sizeof(struct meta_anchor), GFP_NOFS); a = kzalloc(sizeof(struct meta_anchor), GFP_NOFS);
if (!a) if (!a)
return -ENOMEM; return -ENOMEM;
set_page_private(page, (unsigned long)a); folio_attach_private(folio, a);
SetPagePrivate(page); kmap(&folio->page);
kmap(page);
} }
if (mp) { if (mp) {
l2mp_blocks = L2PSIZE - page->mapping->host->i_blkbits; l2mp_blocks = L2PSIZE - folio->mapping->host->i_blkbits;
index = (mp->index >> l2mp_blocks) & (MPS_PER_PAGE - 1); index = (mp->index >> l2mp_blocks) & (MPS_PER_PAGE - 1);
a->mp_count++; a->mp_count++;
a->mp[index] = mp; a->mp[index] = mp;
...@@ -113,10 +114,10 @@ static inline int insert_metapage(struct page *page, struct metapage *mp) ...@@ -113,10 +114,10 @@ static inline int insert_metapage(struct page *page, struct metapage *mp)
return 0; return 0;
} }
static inline void remove_metapage(struct page *page, struct metapage *mp) static inline void remove_metapage(struct folio *folio, struct metapage *mp)
{ {
struct meta_anchor *a = mp_anchor(page); struct meta_anchor *a = folio->private;
int l2mp_blocks = L2PSIZE - page->mapping->host->i_blkbits; int l2mp_blocks = L2PSIZE - folio->mapping->host->i_blkbits;
int index; int index;
index = (mp->index >> l2mp_blocks) & (MPS_PER_PAGE - 1); index = (mp->index >> l2mp_blocks) & (MPS_PER_PAGE - 1);
...@@ -126,48 +127,53 @@ static inline void remove_metapage(struct page *page, struct metapage *mp) ...@@ -126,48 +127,53 @@ static inline void remove_metapage(struct page *page, struct metapage *mp)
a->mp[index] = NULL; a->mp[index] = NULL;
if (--a->mp_count == 0) { if (--a->mp_count == 0) {
kfree(a); kfree(a);
set_page_private(page, 0); folio_detach_private(folio);
ClearPagePrivate(page); kunmap(&folio->page);
kunmap(page);
} }
} }
static inline void inc_io(struct page *page) static inline void inc_io(struct folio *folio)
{ {
atomic_inc(&mp_anchor(page)->io_count); struct meta_anchor *anchor = folio->private;
atomic_inc(&anchor->io_count);
} }
static inline void dec_io(struct page *page, void (*handler) (struct page *)) static inline void dec_io(struct folio *folio, blk_status_t status,
void (*handler)(struct folio *, blk_status_t))
{ {
if (atomic_dec_and_test(&mp_anchor(page)->io_count)) struct meta_anchor *anchor = folio->private;
handler(page);
if (anchor->status == BLK_STS_OK)
anchor->status = status;
if (atomic_dec_and_test(&anchor->io_count))
handler(folio, anchor->status);
} }
#else #else
static inline struct metapage *page_to_mp(struct page *page, int offset) static inline struct metapage *folio_to_mp(struct folio *folio, int offset)
{ {
return PagePrivate(page) ? (struct metapage *)page_private(page) : NULL; return folio->private;
} }
static inline int insert_metapage(struct page *page, struct metapage *mp) static inline int insert_metapage(struct folio *folio, struct metapage *mp)
{ {
if (mp) { if (mp) {
set_page_private(page, (unsigned long)mp); folio_attach_private(folio, mp);
SetPagePrivate(page); kmap(&folio->page);
kmap(page);
} }
return 0; return 0;
} }
static inline void remove_metapage(struct page *page, struct metapage *mp) static inline void remove_metapage(struct folio *folio, struct metapage *mp)
{ {
set_page_private(page, 0); folio_detach_private(folio);
ClearPagePrivate(page); kunmap(&folio->page);
kunmap(page);
} }
#define inc_io(page) do {} while(0) #define inc_io(folio) do {} while(0)
#define dec_io(page, handler) handler(page) #define dec_io(folio, status, handler) handler(folio, status)
#endif #endif
...@@ -218,12 +224,12 @@ void metapage_exit(void) ...@@ -218,12 +224,12 @@ void metapage_exit(void)
kmem_cache_destroy(metapage_cache); kmem_cache_destroy(metapage_cache);
} }
static inline void drop_metapage(struct page *page, struct metapage *mp) static inline void drop_metapage(struct folio *folio, struct metapage *mp)
{ {
if (mp->count || mp->nohomeok || test_bit(META_dirty, &mp->flag) || if (mp->count || mp->nohomeok || test_bit(META_dirty, &mp->flag) ||
test_bit(META_io, &mp->flag)) test_bit(META_io, &mp->flag))
return; return;
remove_metapage(page, mp); remove_metapage(folio, mp);
INCREMENT(mpStat.pagefree); INCREMENT(mpStat.pagefree);
free_metapage(mp); free_metapage(mp);
} }
...@@ -257,23 +263,20 @@ static sector_t metapage_get_blocks(struct inode *inode, sector_t lblock, ...@@ -257,23 +263,20 @@ static sector_t metapage_get_blocks(struct inode *inode, sector_t lblock,
return lblock; return lblock;
} }
static void last_read_complete(struct page *page) static void last_read_complete(struct folio *folio, blk_status_t status)
{ {
if (!PageError(page)) if (status)
SetPageUptodate(page); printk(KERN_ERR "Read error %d at %#llx\n", status,
unlock_page(page); folio_pos(folio));
folio_end_read(folio, status == 0);
} }
static void metapage_read_end_io(struct bio *bio) static void metapage_read_end_io(struct bio *bio)
{ {
struct page *page = bio->bi_private; struct folio *folio = bio->bi_private;
if (bio->bi_status) {
printk(KERN_ERR "metapage_read_end_io: I/O error\n");
SetPageError(page);
}
dec_io(page, last_read_complete); dec_io(folio, bio->bi_status, last_read_complete);
bio_put(bio); bio_put(bio);
} }
...@@ -299,13 +302,19 @@ static void remove_from_logsync(struct metapage *mp) ...@@ -299,13 +302,19 @@ static void remove_from_logsync(struct metapage *mp)
LOGSYNC_UNLOCK(log, flags); LOGSYNC_UNLOCK(log, flags);
} }
static void last_write_complete(struct page *page) static void last_write_complete(struct folio *folio, blk_status_t status)
{ {
struct metapage *mp; struct metapage *mp;
unsigned int offset; unsigned int offset;
if (status) {
int err = blk_status_to_errno(status);
printk(KERN_ERR "metapage_write_end_io: I/O error\n");
mapping_set_error(folio->mapping, err);
}
for (offset = 0; offset < PAGE_SIZE; offset += PSIZE) { for (offset = 0; offset < PAGE_SIZE; offset += PSIZE) {
mp = page_to_mp(page, offset); mp = folio_to_mp(folio, offset);
if (mp && test_bit(META_io, &mp->flag)) { if (mp && test_bit(META_io, &mp->flag)) {
if (mp->lsn) if (mp->lsn)
remove_from_logsync(mp); remove_from_logsync(mp);
...@@ -316,28 +325,25 @@ static void last_write_complete(struct page *page) ...@@ -316,28 +325,25 @@ static void last_write_complete(struct page *page)
* safe unless I have the page locked * safe unless I have the page locked
*/ */
} }
end_page_writeback(page); folio_end_writeback(folio);
} }
static void metapage_write_end_io(struct bio *bio) static void metapage_write_end_io(struct bio *bio)
{ {
struct page *page = bio->bi_private; struct folio *folio = bio->bi_private;
BUG_ON(!PagePrivate(page)); BUG_ON(!folio->private);
if (bio->bi_status) { dec_io(folio, bio->bi_status, last_write_complete);
printk(KERN_ERR "metapage_write_end_io: I/O error\n");
SetPageError(page);
}
dec_io(page, last_write_complete);
bio_put(bio); bio_put(bio);
} }
static int metapage_writepage(struct page *page, struct writeback_control *wbc) static int metapage_write_folio(struct folio *folio,
struct writeback_control *wbc, void *unused)
{ {
struct bio *bio = NULL; struct bio *bio = NULL;
int block_offset; /* block offset of mp within page */ int block_offset; /* block offset of mp within page */
struct inode *inode = page->mapping->host; struct inode *inode = folio->mapping->host;
int blocks_per_mp = JFS_SBI(inode->i_sb)->nbperpage; int blocks_per_mp = JFS_SBI(inode->i_sb)->nbperpage;
int len; int len;
int xlen; int xlen;
...@@ -353,14 +359,13 @@ static int metapage_writepage(struct page *page, struct writeback_control *wbc) ...@@ -353,14 +359,13 @@ static int metapage_writepage(struct page *page, struct writeback_control *wbc)
int offset; int offset;
int bad_blocks = 0; int bad_blocks = 0;
page_start = (sector_t)page->index << page_start = folio_pos(folio) >> inode->i_blkbits;
(PAGE_SHIFT - inode->i_blkbits); BUG_ON(!folio_test_locked(folio));
BUG_ON(!PageLocked(page)); BUG_ON(folio_test_writeback(folio));
BUG_ON(PageWriteback(page)); folio_start_writeback(folio);
set_page_writeback(page);
for (offset = 0; offset < PAGE_SIZE; offset += PSIZE) { for (offset = 0; offset < PAGE_SIZE; offset += PSIZE) {
mp = page_to_mp(page, offset); mp = folio_to_mp(folio, offset);
if (!mp || !test_bit(META_dirty, &mp->flag)) if (!mp || !test_bit(META_dirty, &mp->flag))
continue; continue;
...@@ -389,22 +394,20 @@ static int metapage_writepage(struct page *page, struct writeback_control *wbc) ...@@ -389,22 +394,20 @@ static int metapage_writepage(struct page *page, struct writeback_control *wbc)
continue; continue;
} }
/* Not contiguous */ /* Not contiguous */
if (bio_add_page(bio, page, bio_bytes, bio_offset) < bio_add_folio_nofail(bio, folio, bio_bytes, bio_offset);
bio_bytes)
goto add_failed;
/* /*
* Increment counter before submitting i/o to keep * Increment counter before submitting i/o to keep
* count from hitting zero before we're through * count from hitting zero before we're through
*/ */
inc_io(page); inc_io(folio);
if (!bio->bi_iter.bi_size) if (!bio->bi_iter.bi_size)
goto dump_bio; goto dump_bio;
submit_bio(bio); submit_bio(bio);
nr_underway++; nr_underway++;
bio = NULL; bio = NULL;
} else } else
inc_io(page); inc_io(folio);
xlen = (PAGE_SIZE - offset) >> inode->i_blkbits; xlen = (folio_size(folio) - offset) >> inode->i_blkbits;
pblock = metapage_get_blocks(inode, lblock, &xlen); pblock = metapage_get_blocks(inode, lblock, &xlen);
if (!pblock) { if (!pblock) {
printk(KERN_ERR "JFS: metapage_get_blocks failed\n"); printk(KERN_ERR "JFS: metapage_get_blocks failed\n");
...@@ -420,7 +423,7 @@ static int metapage_writepage(struct page *page, struct writeback_control *wbc) ...@@ -420,7 +423,7 @@ static int metapage_writepage(struct page *page, struct writeback_control *wbc)
bio = bio_alloc(inode->i_sb->s_bdev, 1, REQ_OP_WRITE, GFP_NOFS); bio = bio_alloc(inode->i_sb->s_bdev, 1, REQ_OP_WRITE, GFP_NOFS);
bio->bi_iter.bi_sector = pblock << (inode->i_blkbits - 9); bio->bi_iter.bi_sector = pblock << (inode->i_blkbits - 9);
bio->bi_end_io = metapage_write_end_io; bio->bi_end_io = metapage_write_end_io;
bio->bi_private = page; bio->bi_private = folio;
/* Don't call bio_add_page yet, we may add to this vec */ /* Don't call bio_add_page yet, we may add to this vec */
bio_offset = offset; bio_offset = offset;
...@@ -430,8 +433,7 @@ static int metapage_writepage(struct page *page, struct writeback_control *wbc) ...@@ -430,8 +433,7 @@ static int metapage_writepage(struct page *page, struct writeback_control *wbc)
next_block = lblock + len; next_block = lblock + len;
} }
if (bio) { if (bio) {
if (bio_add_page(bio, page, bio_bytes, bio_offset) < bio_bytes) bio_add_folio_nofail(bio, folio, bio_bytes, bio_offset);
goto add_failed;
if (!bio->bi_iter.bi_size) if (!bio->bi_iter.bi_size)
goto dump_bio; goto dump_bio;
...@@ -439,50 +441,56 @@ static int metapage_writepage(struct page *page, struct writeback_control *wbc) ...@@ -439,50 +441,56 @@ static int metapage_writepage(struct page *page, struct writeback_control *wbc)
nr_underway++; nr_underway++;
} }
if (redirty) if (redirty)
redirty_page_for_writepage(wbc, page); folio_redirty_for_writepage(wbc, folio);
unlock_page(page); folio_unlock(folio);
if (bad_blocks) if (bad_blocks)
goto err_out; goto err_out;
if (nr_underway == 0) if (nr_underway == 0)
end_page_writeback(page); folio_end_writeback(folio);
return 0; return 0;
add_failed:
/* We should never reach here, since we're only adding one vec */
printk(KERN_ERR "JFS: bio_add_page failed unexpectedly\n");
goto skip;
dump_bio: dump_bio:
print_hex_dump(KERN_ERR, "JFS: dump of bio: ", DUMP_PREFIX_ADDRESS, 16, print_hex_dump(KERN_ERR, "JFS: dump of bio: ", DUMP_PREFIX_ADDRESS, 16,
4, bio, sizeof(*bio), 0); 4, bio, sizeof(*bio), 0);
skip:
bio_put(bio); bio_put(bio);
unlock_page(page); folio_unlock(folio);
dec_io(page, last_write_complete); dec_io(folio, BLK_STS_OK, last_write_complete);
err_out: err_out:
while (bad_blocks--) while (bad_blocks--)
dec_io(page, last_write_complete); dec_io(folio, BLK_STS_OK, last_write_complete);
return -EIO; return -EIO;
} }
static int metapage_writepages(struct address_space *mapping,
struct writeback_control *wbc)
{
struct blk_plug plug;
int err;
blk_start_plug(&plug);
err = write_cache_pages(mapping, wbc, metapage_write_folio, NULL);
blk_finish_plug(&plug);
return err;
}
static int metapage_read_folio(struct file *fp, struct folio *folio) static int metapage_read_folio(struct file *fp, struct folio *folio)
{ {
struct page *page = &folio->page; struct inode *inode = folio->mapping->host;
struct inode *inode = page->mapping->host;
struct bio *bio = NULL; struct bio *bio = NULL;
int block_offset; int block_offset;
int blocks_per_page = i_blocks_per_page(inode, page); int blocks_per_page = i_blocks_per_folio(inode, folio);
sector_t page_start; /* address of page in fs blocks */ sector_t page_start; /* address of page in fs blocks */
sector_t pblock; sector_t pblock;
int xlen; int xlen;
unsigned int len; unsigned int len;
int offset; int offset;
BUG_ON(!PageLocked(page)); BUG_ON(!folio_test_locked(folio));
page_start = (sector_t)page->index << page_start = folio_pos(folio) >> inode->i_blkbits;
(PAGE_SHIFT - inode->i_blkbits);
block_offset = 0; block_offset = 0;
while (block_offset < blocks_per_page) { while (block_offset < blocks_per_page) {
...@@ -490,9 +498,9 @@ static int metapage_read_folio(struct file *fp, struct folio *folio) ...@@ -490,9 +498,9 @@ static int metapage_read_folio(struct file *fp, struct folio *folio)
pblock = metapage_get_blocks(inode, page_start + block_offset, pblock = metapage_get_blocks(inode, page_start + block_offset,
&xlen); &xlen);
if (pblock) { if (pblock) {
if (!PagePrivate(page)) if (!folio->private)
insert_metapage(page, NULL); insert_metapage(folio, NULL);
inc_io(page); inc_io(folio);
if (bio) if (bio)
submit_bio(bio); submit_bio(bio);
...@@ -501,11 +509,10 @@ static int metapage_read_folio(struct file *fp, struct folio *folio) ...@@ -501,11 +509,10 @@ static int metapage_read_folio(struct file *fp, struct folio *folio)
bio->bi_iter.bi_sector = bio->bi_iter.bi_sector =
pblock << (inode->i_blkbits - 9); pblock << (inode->i_blkbits - 9);
bio->bi_end_io = metapage_read_end_io; bio->bi_end_io = metapage_read_end_io;
bio->bi_private = page; bio->bi_private = folio;
len = xlen << inode->i_blkbits; len = xlen << inode->i_blkbits;
offset = block_offset << inode->i_blkbits; offset = block_offset << inode->i_blkbits;
if (bio_add_page(bio, page, len, offset) < len) bio_add_folio_nofail(bio, folio, len, offset);
goto add_failed;
block_offset += xlen; block_offset += xlen;
} else } else
block_offset++; block_offset++;
...@@ -513,15 +520,9 @@ static int metapage_read_folio(struct file *fp, struct folio *folio) ...@@ -513,15 +520,9 @@ static int metapage_read_folio(struct file *fp, struct folio *folio)
if (bio) if (bio)
submit_bio(bio); submit_bio(bio);
else else
unlock_page(page); folio_unlock(folio);
return 0; return 0;
add_failed:
printk(KERN_ERR "JFS: bio_add_page failed unexpectedly\n");
bio_put(bio);
dec_io(page, last_read_complete);
return -EIO;
} }
static bool metapage_release_folio(struct folio *folio, gfp_t gfp_mask) static bool metapage_release_folio(struct folio *folio, gfp_t gfp_mask)
...@@ -531,7 +532,7 @@ static bool metapage_release_folio(struct folio *folio, gfp_t gfp_mask) ...@@ -531,7 +532,7 @@ static bool metapage_release_folio(struct folio *folio, gfp_t gfp_mask)
int offset; int offset;
for (offset = 0; offset < PAGE_SIZE; offset += PSIZE) { for (offset = 0; offset < PAGE_SIZE; offset += PSIZE) {
mp = page_to_mp(&folio->page, offset); mp = folio_to_mp(folio, offset);
if (!mp) if (!mp)
continue; continue;
...@@ -546,7 +547,7 @@ static bool metapage_release_folio(struct folio *folio, gfp_t gfp_mask) ...@@ -546,7 +547,7 @@ static bool metapage_release_folio(struct folio *folio, gfp_t gfp_mask)
} }
if (mp->lsn) if (mp->lsn)
remove_from_logsync(mp); remove_from_logsync(mp);
remove_metapage(&folio->page, mp); remove_metapage(folio, mp);
INCREMENT(mpStat.pagefree); INCREMENT(mpStat.pagefree);
free_metapage(mp); free_metapage(mp);
} }
...@@ -565,7 +566,7 @@ static void metapage_invalidate_folio(struct folio *folio, size_t offset, ...@@ -565,7 +566,7 @@ static void metapage_invalidate_folio(struct folio *folio, size_t offset,
const struct address_space_operations jfs_metapage_aops = { const struct address_space_operations jfs_metapage_aops = {
.read_folio = metapage_read_folio, .read_folio = metapage_read_folio,
.writepage = metapage_writepage, .writepages = metapage_writepages,
.release_folio = metapage_release_folio, .release_folio = metapage_release_folio,
.invalidate_folio = metapage_invalidate_folio, .invalidate_folio = metapage_invalidate_folio,
.dirty_folio = filemap_dirty_folio, .dirty_folio = filemap_dirty_folio,
...@@ -579,7 +580,7 @@ struct metapage *__get_metapage(struct inode *inode, unsigned long lblock, ...@@ -579,7 +580,7 @@ struct metapage *__get_metapage(struct inode *inode, unsigned long lblock,
int l2bsize; int l2bsize;
struct address_space *mapping; struct address_space *mapping;
struct metapage *mp = NULL; struct metapage *mp = NULL;
struct page *page; struct folio *folio;
unsigned long page_index; unsigned long page_index;
unsigned long page_offset; unsigned long page_offset;
...@@ -610,22 +611,22 @@ struct metapage *__get_metapage(struct inode *inode, unsigned long lblock, ...@@ -610,22 +611,22 @@ struct metapage *__get_metapage(struct inode *inode, unsigned long lblock,
} }
if (new && (PSIZE == PAGE_SIZE)) { if (new && (PSIZE == PAGE_SIZE)) {
page = grab_cache_page(mapping, page_index); folio = filemap_grab_folio(mapping, page_index);
if (!page) { if (IS_ERR(folio)) {
jfs_err("grab_cache_page failed!"); jfs_err("filemap_grab_folio failed!");
return NULL; return NULL;
} }
SetPageUptodate(page); folio_mark_uptodate(folio);
} else { } else {
page = read_mapping_page(mapping, page_index, NULL); folio = read_mapping_folio(mapping, page_index, NULL);
if (IS_ERR(page)) { if (IS_ERR(folio)) {
jfs_err("read_mapping_page failed!"); jfs_err("read_mapping_page failed!");
return NULL; return NULL;
} }
lock_page(page); folio_lock(folio);
} }
mp = page_to_mp(page, page_offset); mp = folio_to_mp(folio, page_offset);
if (mp) { if (mp) {
if (mp->logical_size != size) { if (mp->logical_size != size) {
jfs_error(inode->i_sb, jfs_error(inode->i_sb,
...@@ -651,16 +652,16 @@ struct metapage *__get_metapage(struct inode *inode, unsigned long lblock, ...@@ -651,16 +652,16 @@ struct metapage *__get_metapage(struct inode *inode, unsigned long lblock,
mp = alloc_metapage(GFP_NOFS); mp = alloc_metapage(GFP_NOFS);
if (!mp) if (!mp)
goto unlock; goto unlock;
mp->page = page; mp->folio = folio;
mp->sb = inode->i_sb; mp->sb = inode->i_sb;
mp->flag = 0; mp->flag = 0;
mp->xflag = COMMIT_PAGE; mp->xflag = COMMIT_PAGE;
mp->count = 1; mp->count = 1;
mp->nohomeok = 0; mp->nohomeok = 0;
mp->logical_size = size; mp->logical_size = size;
mp->data = page_address(page) + page_offset; mp->data = folio_address(folio) + page_offset;
mp->index = lblock; mp->index = lblock;
if (unlikely(insert_metapage(page, mp))) { if (unlikely(insert_metapage(folio, mp))) {
free_metapage(mp); free_metapage(mp);
goto unlock; goto unlock;
} }
...@@ -672,28 +673,27 @@ struct metapage *__get_metapage(struct inode *inode, unsigned long lblock, ...@@ -672,28 +673,27 @@ struct metapage *__get_metapage(struct inode *inode, unsigned long lblock,
memset(mp->data, 0, PSIZE); memset(mp->data, 0, PSIZE);
} }
unlock_page(page); folio_unlock(folio);
jfs_info("__get_metapage: returning = 0x%p data = 0x%p", mp, mp->data); jfs_info("__get_metapage: returning = 0x%p data = 0x%p", mp, mp->data);
return mp; return mp;
unlock: unlock:
unlock_page(page); folio_unlock(folio);
return NULL; return NULL;
} }
void grab_metapage(struct metapage * mp) void grab_metapage(struct metapage * mp)
{ {
jfs_info("grab_metapage: mp = 0x%p", mp); jfs_info("grab_metapage: mp = 0x%p", mp);
get_page(mp->page); folio_get(mp->folio);
lock_page(mp->page); folio_lock(mp->folio);
mp->count++; mp->count++;
lock_metapage(mp); lock_metapage(mp);
unlock_page(mp->page); folio_unlock(mp->folio);
} }
static int metapage_write_one(struct page *page) static int metapage_write_one(struct folio *folio)
{ {
struct folio *folio = page_folio(page);
struct address_space *mapping = folio->mapping; struct address_space *mapping = folio->mapping;
struct writeback_control wbc = { struct writeback_control wbc = {
.sync_mode = WB_SYNC_ALL, .sync_mode = WB_SYNC_ALL,
...@@ -707,7 +707,7 @@ static int metapage_write_one(struct page *page) ...@@ -707,7 +707,7 @@ static int metapage_write_one(struct page *page)
if (folio_clear_dirty_for_io(folio)) { if (folio_clear_dirty_for_io(folio)) {
folio_get(folio); folio_get(folio);
ret = metapage_writepage(page, &wbc); ret = metapage_write_folio(folio, &wbc, NULL);
if (ret == 0) if (ret == 0)
folio_wait_writeback(folio); folio_wait_writeback(folio);
folio_put(folio); folio_put(folio);
...@@ -722,71 +722,69 @@ static int metapage_write_one(struct page *page) ...@@ -722,71 +722,69 @@ static int metapage_write_one(struct page *page)
void force_metapage(struct metapage *mp) void force_metapage(struct metapage *mp)
{ {
struct page *page = mp->page; struct folio *folio = mp->folio;
jfs_info("force_metapage: mp = 0x%p", mp); jfs_info("force_metapage: mp = 0x%p", mp);
set_bit(META_forcewrite, &mp->flag); set_bit(META_forcewrite, &mp->flag);
clear_bit(META_sync, &mp->flag); clear_bit(META_sync, &mp->flag);
get_page(page); folio_get(folio);
lock_page(page); folio_lock(folio);
set_page_dirty(page); folio_mark_dirty(folio);
if (metapage_write_one(page)) if (metapage_write_one(folio))
jfs_error(mp->sb, "metapage_write_one() failed\n"); jfs_error(mp->sb, "metapage_write_one() failed\n");
clear_bit(META_forcewrite, &mp->flag); clear_bit(META_forcewrite, &mp->flag);
put_page(page); folio_put(folio);
} }
void hold_metapage(struct metapage *mp) void hold_metapage(struct metapage *mp)
{ {
lock_page(mp->page); folio_lock(mp->folio);
} }
void put_metapage(struct metapage *mp) void put_metapage(struct metapage *mp)
{ {
if (mp->count || mp->nohomeok) { if (mp->count || mp->nohomeok) {
/* Someone else will release this */ /* Someone else will release this */
unlock_page(mp->page); folio_unlock(mp->folio);
return; return;
} }
get_page(mp->page); folio_get(mp->folio);
mp->count++; mp->count++;
lock_metapage(mp); lock_metapage(mp);
unlock_page(mp->page); folio_unlock(mp->folio);
release_metapage(mp); release_metapage(mp);
} }
void release_metapage(struct metapage * mp) void release_metapage(struct metapage * mp)
{ {
struct page *page = mp->page; struct folio *folio = mp->folio;
jfs_info("release_metapage: mp = 0x%p, flag = 0x%lx", mp, mp->flag); jfs_info("release_metapage: mp = 0x%p, flag = 0x%lx", mp, mp->flag);
BUG_ON(!page); folio_lock(folio);
lock_page(page);
unlock_metapage(mp); unlock_metapage(mp);
assert(mp->count); assert(mp->count);
if (--mp->count || mp->nohomeok) { if (--mp->count || mp->nohomeok) {
unlock_page(page); folio_unlock(folio);
put_page(page); folio_put(folio);
return; return;
} }
if (test_bit(META_dirty, &mp->flag)) { if (test_bit(META_dirty, &mp->flag)) {
set_page_dirty(page); folio_mark_dirty(folio);
if (test_bit(META_sync, &mp->flag)) { if (test_bit(META_sync, &mp->flag)) {
clear_bit(META_sync, &mp->flag); clear_bit(META_sync, &mp->flag);
if (metapage_write_one(page)) if (metapage_write_one(folio))
jfs_error(mp->sb, "metapage_write_one() failed\n"); jfs_error(mp->sb, "metapage_write_one() failed\n");
lock_page(page); folio_lock(folio);
} }
} else if (mp->lsn) /* discard_metapage doesn't remove it */ } else if (mp->lsn) /* discard_metapage doesn't remove it */
remove_from_logsync(mp); remove_from_logsync(mp);
/* Try to keep metapages from using up too much memory */ /* Try to keep metapages from using up too much memory */
drop_metapage(page, mp); drop_metapage(folio, mp);
unlock_page(page); folio_unlock(folio);
put_page(page); folio_put(folio);
} }
void __invalidate_metapages(struct inode *ip, s64 addr, int len) void __invalidate_metapages(struct inode *ip, s64 addr, int len)
...@@ -798,7 +796,6 @@ void __invalidate_metapages(struct inode *ip, s64 addr, int len) ...@@ -798,7 +796,6 @@ void __invalidate_metapages(struct inode *ip, s64 addr, int len)
struct address_space *mapping = struct address_space *mapping =
JFS_SBI(ip->i_sb)->direct_inode->i_mapping; JFS_SBI(ip->i_sb)->direct_inode->i_mapping;
struct metapage *mp; struct metapage *mp;
struct page *page;
unsigned int offset; unsigned int offset;
/* /*
...@@ -807,11 +804,12 @@ void __invalidate_metapages(struct inode *ip, s64 addr, int len) ...@@ -807,11 +804,12 @@ void __invalidate_metapages(struct inode *ip, s64 addr, int len)
*/ */
for (lblock = addr & ~(BlocksPerPage - 1); lblock < addr + len; for (lblock = addr & ~(BlocksPerPage - 1); lblock < addr + len;
lblock += BlocksPerPage) { lblock += BlocksPerPage) {
page = find_lock_page(mapping, lblock >> l2BlocksPerPage); struct folio *folio = filemap_lock_folio(mapping,
if (!page) lblock >> l2BlocksPerPage);
if (IS_ERR(folio))
continue; continue;
for (offset = 0; offset < PAGE_SIZE; offset += PSIZE) { for (offset = 0; offset < PAGE_SIZE; offset += PSIZE) {
mp = page_to_mp(page, offset); mp = folio_to_mp(folio, offset);
if (!mp) if (!mp)
continue; continue;
if (mp->index < addr) if (mp->index < addr)
...@@ -824,8 +822,8 @@ void __invalidate_metapages(struct inode *ip, s64 addr, int len) ...@@ -824,8 +822,8 @@ void __invalidate_metapages(struct inode *ip, s64 addr, int len)
if (mp->lsn) if (mp->lsn)
remove_from_logsync(mp); remove_from_logsync(mp);
} }
unlock_page(page); folio_unlock(folio);
put_page(page); folio_put(folio);
} }
} }
......
...@@ -24,7 +24,7 @@ struct metapage { ...@@ -24,7 +24,7 @@ struct metapage {
wait_queue_head_t wait; wait_queue_head_t wait;
/* implementation */ /* implementation */
struct page *page; struct folio *folio;
struct super_block *sb; struct super_block *sb;
unsigned int logical_size; unsigned int logical_size;
...@@ -90,14 +90,14 @@ static inline void discard_metapage(struct metapage *mp) ...@@ -90,14 +90,14 @@ static inline void discard_metapage(struct metapage *mp)
static inline void metapage_nohomeok(struct metapage *mp) static inline void metapage_nohomeok(struct metapage *mp)
{ {
struct page *page = mp->page; struct folio *folio = mp->folio;
lock_page(page); folio_lock(folio);
if (!mp->nohomeok++) { if (!mp->nohomeok++) {
mark_metapage_dirty(mp); mark_metapage_dirty(mp);
get_page(page); folio_get(folio);
wait_on_page_writeback(page); folio_wait_writeback(folio);
} }
unlock_page(page); folio_unlock(folio);
} }
/* /*
...@@ -107,7 +107,7 @@ static inline void metapage_nohomeok(struct metapage *mp) ...@@ -107,7 +107,7 @@ static inline void metapage_nohomeok(struct metapage *mp)
static inline void metapage_wait_for_io(struct metapage *mp) static inline void metapage_wait_for_io(struct metapage *mp)
{ {
if (test_bit(META_io, &mp->flag)) if (test_bit(META_io, &mp->flag))
wait_on_page_writeback(mp->page); folio_wait_writeback(mp->folio);
} }
/* /*
...@@ -116,7 +116,7 @@ static inline void metapage_wait_for_io(struct metapage *mp) ...@@ -116,7 +116,7 @@ static inline void metapage_wait_for_io(struct metapage *mp)
static inline void _metapage_homeok(struct metapage *mp) static inline void _metapage_homeok(struct metapage *mp)
{ {
if (!--mp->nohomeok) if (!--mp->nohomeok)
put_page(mp->page); folio_put(mp->folio);
} }
static inline void metapage_homeok(struct metapage *mp) static inline void metapage_homeok(struct metapage *mp)
......
...@@ -797,7 +797,7 @@ ssize_t __jfs_getxattr(struct inode *inode, const char *name, void *data, ...@@ -797,7 +797,7 @@ ssize_t __jfs_getxattr(struct inode *inode, const char *name, void *data,
size_t buf_size) size_t buf_size)
{ {
struct jfs_ea_list *ealist; struct jfs_ea_list *ealist;
struct jfs_ea *ea; struct jfs_ea *ea, *ealist_end;
struct ea_buffer ea_buf; struct ea_buffer ea_buf;
int xattr_size; int xattr_size;
ssize_t size; ssize_t size;
...@@ -817,9 +817,16 @@ ssize_t __jfs_getxattr(struct inode *inode, const char *name, void *data, ...@@ -817,9 +817,16 @@ ssize_t __jfs_getxattr(struct inode *inode, const char *name, void *data,
goto not_found; goto not_found;
ealist = (struct jfs_ea_list *) ea_buf.xattr; ealist = (struct jfs_ea_list *) ea_buf.xattr;
ealist_end = END_EALIST(ealist);
/* Find the named attribute */ /* Find the named attribute */
for (ea = FIRST_EA(ealist); ea < END_EALIST(ealist); ea = NEXT_EA(ea)) for (ea = FIRST_EA(ealist); ea < ealist_end; ea = NEXT_EA(ea)) {
if (unlikely(ea + 1 > ealist_end) ||
unlikely(NEXT_EA(ea) > ealist_end)) {
size = -EUCLEAN;
goto release;
}
if ((namelen == ea->namelen) && if ((namelen == ea->namelen) &&
memcmp(name, ea->name, namelen) == 0) { memcmp(name, ea->name, namelen) == 0) {
/* Found it */ /* Found it */
...@@ -834,6 +841,7 @@ ssize_t __jfs_getxattr(struct inode *inode, const char *name, void *data, ...@@ -834,6 +841,7 @@ ssize_t __jfs_getxattr(struct inode *inode, const char *name, void *data,
memcpy(data, value, size); memcpy(data, value, size);
goto release; goto release;
} }
}
not_found: not_found:
size = -ENODATA; size = -ENODATA;
release: release:
...@@ -861,7 +869,7 @@ ssize_t jfs_listxattr(struct dentry * dentry, char *data, size_t buf_size) ...@@ -861,7 +869,7 @@ ssize_t jfs_listxattr(struct dentry * dentry, char *data, size_t buf_size)
ssize_t size = 0; ssize_t size = 0;
int xattr_size; int xattr_size;
struct jfs_ea_list *ealist; struct jfs_ea_list *ealist;
struct jfs_ea *ea; struct jfs_ea *ea, *ealist_end;
struct ea_buffer ea_buf; struct ea_buffer ea_buf;
down_read(&JFS_IP(inode)->xattr_sem); down_read(&JFS_IP(inode)->xattr_sem);
...@@ -876,9 +884,16 @@ ssize_t jfs_listxattr(struct dentry * dentry, char *data, size_t buf_size) ...@@ -876,9 +884,16 @@ ssize_t jfs_listxattr(struct dentry * dentry, char *data, size_t buf_size)
goto release; goto release;
ealist = (struct jfs_ea_list *) ea_buf.xattr; ealist = (struct jfs_ea_list *) ea_buf.xattr;
ealist_end = END_EALIST(ealist);
/* compute required size of list */ /* compute required size of list */
for (ea = FIRST_EA(ealist); ea < END_EALIST(ealist); ea = NEXT_EA(ea)) { for (ea = FIRST_EA(ealist); ea < ealist_end; ea = NEXT_EA(ea)) {
if (unlikely(ea + 1 > ealist_end) ||
unlikely(NEXT_EA(ea) > ealist_end)) {
size = -EUCLEAN;
goto release;
}
if (can_list(ea)) if (can_list(ea))
size += name_size(ea) + 1; size += name_size(ea) + 1;
} }
......
...@@ -1537,10 +1537,4 @@ unsigned int i_blocks_per_folio(struct inode *inode, struct folio *folio) ...@@ -1537,10 +1537,4 @@ unsigned int i_blocks_per_folio(struct inode *inode, struct folio *folio)
{ {
return folio_size(folio) >> inode->i_blkbits; return folio_size(folio) >> inode->i_blkbits;
} }
static inline
unsigned int i_blocks_per_page(struct inode *inode, struct page *page)
{
return i_blocks_per_folio(inode, page_folio(page));
}
#endif /* _LINUX_PAGEMAP_H */ #endif /* _LINUX_PAGEMAP_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment