From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
To: jfs-discussion@lists.sourceforge.net, linux-fsdevel@vger.kernel.org
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
Christoph Hellwig <hch@infradead.org>,
"Darrick J . Wong" <djwong@kernel.org>
Subject: [RFC PATCH 2/9] jfs: Add jfs_iomap_begin()
Date: Thu, 26 May 2022 20:29:03 +0100 [thread overview]
Message-ID: <20220526192910.357055-3-willy@infradead.org> (raw)
In-Reply-To: <20220526192910.357055-1-willy@infradead.org>
Turn jfs_get_block() into a wrapper around jfs_iomap_begin(). This fixes
a latent bug where JFS was not setting b_size when it encountered a hole.
At least mpage_readahead() does not look at b_size when the buffer is
unmapped, but iomap will care whether iomap->length is set correctly,
and so we may as well set b_size correctly as well.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
fs/jfs/inode.c | 67 +++++++++++++++++++++++++++++++++++++-------------
1 file changed, 50 insertions(+), 17 deletions(-)
diff --git a/fs/jfs/inode.c b/fs/jfs/inode.c
index a5dd7e53754a..1a5bdaf35e9b 100644
--- a/fs/jfs/inode.c
+++ b/fs/jfs/inode.c
@@ -5,6 +5,7 @@
*/
#include <linux/fs.h>
+#include <linux/iomap.h>
#include <linux/mpage.h>
#include <linux/buffer_head.h>
#include <linux/pagemap.h>
@@ -196,15 +197,21 @@ void jfs_dirty_inode(struct inode *inode, int flags)
set_cflag(COMMIT_Dirty, inode);
}
-int jfs_get_block(struct inode *ip, sector_t lblock,
- struct buffer_head *bh_result, int create)
+int jfs_iomap_begin(struct inode *ip, loff_t pos, loff_t length,
+ unsigned flags, struct iomap *iomap, struct iomap *srcmap)
{
- s64 lblock64 = lblock;
+ s64 lblock64 = pos >> ip->i_blkbits;
+ int create = flags & IOMAP_WRITE;
int rc = 0;
xad_t xad;
s64 xaddr;
int xflag;
- s32 xlen = bh_result->b_size >> ip->i_blkbits;
+ s32 xlen;
+
+ xlen = DIV_ROUND_UP(pos + length - (lblock64 << ip->i_blkbits),
+ i_blocksize(ip));
+ if (xlen < 0)
+ xlen = INT_MAX;
/*
* Take appropriate lock on inode
@@ -214,8 +221,8 @@ int jfs_get_block(struct inode *ip, sector_t lblock,
else
IREAD_LOCK(ip, RDWRLOCK_NORMAL);
- if (((lblock64 << ip->i_sb->s_blocksize_bits) < ip->i_size) &&
- (!xtLookup(ip, lblock64, xlen, &xflag, &xaddr, &xlen, 0)) &&
+ if (pos < ip->i_size &&
+ !xtLookup(ip, lblock64, xlen, &xflag, &xaddr, &xlen, 0) &&
xaddr) {
if (xflag & XAD_NOTRECORDED) {
if (!create)
@@ -238,13 +245,11 @@ int jfs_get_block(struct inode *ip, sector_t lblock,
#endif /* _JFS_4K */
rc = extRecord(ip, &xad);
if (rc)
- goto unlock;
- set_buffer_new(bh_result);
+ goto err;
+ iomap->flags |= IOMAP_F_NEW;
}
- map_bh(bh_result, ip->i_sb, xaddr);
- bh_result->b_size = xlen << ip->i_blkbits;
- goto unlock;
+ goto map;
}
if (!create)
goto unlock;
@@ -254,14 +259,14 @@ int jfs_get_block(struct inode *ip, sector_t lblock,
*/
#ifdef _JFS_4K
if ((rc = extHint(ip, lblock64 << ip->i_sb->s_blocksize_bits, &xad)))
- goto unlock;
+ goto err;
rc = extAlloc(ip, xlen, lblock64, &xad, false);
if (rc)
- goto unlock;
+ goto err;
- set_buffer_new(bh_result);
- map_bh(bh_result, ip->i_sb, addressXAD(&xad));
- bh_result->b_size = lengthXAD(&xad) << ip->i_blkbits;
+ xaddr = addressXAD(&xad);
+ xlen = lengthXAD(&xad);
+ iomap->flags |= IOMAP_F_NEW;
#else /* _JFS_4K */
/*
@@ -271,7 +276,14 @@ int jfs_get_block(struct inode *ip, sector_t lblock,
BUG();
#endif /* _JFS_4K */
- unlock:
+map:
+ iomap->addr = xaddr << ip->i_blkbits;
+ iomap->bdev = ip->i_sb->s_bdev;
+ iomap->type = IOMAP_MAPPED;
+unlock:
+ iomap->offset = lblock64 << ip->i_blkbits;
+ iomap->length = xlen << ip->i_blkbits;
+err:
/*
* Release lock on inode
*/
@@ -282,6 +294,27 @@ int jfs_get_block(struct inode *ip, sector_t lblock,
return rc;
}
+int jfs_get_block(struct inode *ip, sector_t lblock,
+ struct buffer_head *bh_result, int create)
+{
+ struct iomap iomap = { };
+ int ret;
+
+ ret = jfs_iomap_begin(ip, lblock << ip->i_blkbits, bh_result->b_size,
+ create ? IOMAP_WRITE : 0, &iomap, NULL);
+ if (ret)
+ return ret;
+
+ bh_result->b_size = iomap.length;
+ if (iomap.type == IOMAP_HOLE)
+ return 0;
+
+ map_bh(bh_result, ip->i_sb, iomap.addr >> ip->i_blkbits);
+ if (iomap.flags & IOMAP_F_NEW)
+ set_buffer_new(bh_result);
+ return 0;
+}
+
static int jfs_writepage(struct page *page, struct writeback_control *wbc)
{
return block_write_full_page(page, jfs_get_block, wbc);
--
2.34.1
next prev parent reply other threads:[~2022-05-26 19:29 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-26 19:29 [RFC PATCH 0/9] Convert JFS to use iomap Matthew Wilcox (Oracle)
2022-05-26 19:29 ` [RFC PATCH 1/9] IOMAP_DIO_NOSYNC Matthew Wilcox (Oracle)
2022-05-27 5:35 ` Christoph Hellwig
2022-05-27 13:20 ` Matthew Wilcox
2022-05-26 19:29 ` Matthew Wilcox (Oracle) [this message]
2022-05-27 5:41 ` [RFC PATCH 2/9] jfs: Add jfs_iomap_begin() Christoph Hellwig
2022-05-27 13:45 ` Matthew Wilcox
2022-05-27 14:58 ` [Jfs-discussion] " Dave Kleikamp
2022-05-26 19:29 ` [RFC PATCH 3/9] jfs: Convert direct_IO read support to use iomap Matthew Wilcox (Oracle)
2022-05-26 19:29 ` [RFC PATCH 4/9] jfs: Convert direct_IO write " Matthew Wilcox (Oracle)
2022-05-26 19:29 ` [RFC PATCH 5/9] jfs: Remove old direct_IO support Matthew Wilcox (Oracle)
2022-05-26 19:29 ` [RFC PATCH 6/9] jfs: Handle bmap with iomap Matthew Wilcox (Oracle)
2022-05-26 19:29 ` [RFC PATCH 7/9] jfs: Read quota through the page cache Matthew Wilcox (Oracle)
2022-05-27 5:43 ` Christoph Hellwig
2022-05-27 13:56 ` Matthew Wilcox
2022-06-03 14:40 ` generic_quota_read Matthew Wilcox
2022-06-06 7:37 ` generic_quota_read Jan Kara
2022-05-26 19:29 ` [RFC PATCH 8/9] jfs: Write quota through the page cache Matthew Wilcox (Oracle)
2022-05-27 5:46 ` Christoph Hellwig
2022-05-26 19:29 ` [RFC PATCH 9/9] jfs: Convert buffered IO paths to iomap Matthew Wilcox (Oracle)
2022-05-28 0:02 ` [RFC PATCH 0/9] Convert JFS to use iomap Dave Chinner
2022-05-28 2:15 ` Matthew Wilcox
2022-05-28 5:36 ` Dave Chinner
2022-05-28 18:59 ` Theodore Ts'o
2022-05-29 23:51 ` Dave Chinner
2022-05-31 13:51 ` [Jfs-discussion] " Dave Kleikamp
2022-05-31 15:31 ` Matthew Wilcox
2022-05-31 15:56 ` Dave Kleikamp
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220526192910.357055-3-willy@infradead.org \
--to=willy@infradead.org \
--cc=djwong@kernel.org \
--cc=hch@infradead.org \
--cc=jfs-discussion@lists.sourceforge.net \
--cc=linux-fsdevel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).