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 8/9] jfs: Write quota through the page cache
Date: Thu, 26 May 2022 20:29:09 +0100 [thread overview]
Message-ID: <20220526192910.357055-9-willy@infradead.org> (raw)
In-Reply-To: <20220526192910.357055-1-willy@infradead.org>
Remove call to jfs_get_block() and use the page cache directly instead
of wrapping it in a buffer_head.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
fs/jfs/super.c | 71 ++++++++++++++++++++++++++------------------------
1 file changed, 37 insertions(+), 34 deletions(-)
diff --git a/fs/jfs/super.c b/fs/jfs/super.c
index 1e7d117b555d..151c62e2a08f 100644
--- a/fs/jfs/super.c
+++ b/fs/jfs/super.c
@@ -14,7 +14,6 @@
#include <linux/moduleparam.h>
#include <linux/kthread.h>
#include <linux/posix_acl.h>
-#include <linux/buffer_head.h>
#include <linux/exportfs.h>
#include <linux/crc32.h>
#include <linux/slab.h>
@@ -760,54 +759,58 @@ static ssize_t jfs_quota_read(struct super_block *sb, int type, char *data,
/* Write to quotafile */
static ssize_t jfs_quota_write(struct super_block *sb, int type,
- const char *data, size_t len, loff_t off)
+ const char *data, size_t len, loff_t pos)
{
struct inode *inode = sb_dqopt(sb)->files[type];
- sector_t blk = off >> sb->s_blocksize_bits;
+ struct address_space *mapping = inode->i_mapping;
int err = 0;
- int offset = off & (sb->s_blocksize - 1);
- int tocopy;
size_t towrite = len;
- struct buffer_head tmp_bh;
- struct buffer_head *bh;
inode_lock(inode);
while (towrite > 0) {
- tocopy = sb->s_blocksize - offset < towrite ?
- sb->s_blocksize - offset : towrite;
-
- tmp_bh.b_state = 0;
- tmp_bh.b_size = i_blocksize(inode);
- err = jfs_get_block(inode, blk, &tmp_bh, 1);
- if (err)
- goto out;
- if (offset || tocopy != sb->s_blocksize)
- bh = sb_bread(sb, tmp_bh.b_blocknr);
- else
- bh = sb_getblk(sb, tmp_bh.b_blocknr);
- if (!bh) {
- err = -EIO;
- goto out;
+ pgoff_t index = pos / PAGE_SIZE;
+ size_t tocopy = min(PAGE_SIZE - offset_in_page(pos), towrite);
+ struct folio *folio;
+ void *dst;
+
+ if (offset_in_page(pos) ||
+ (towrite < PAGE_SIZE && (pos + towrite < inode->i_size))) {
+ folio = read_mapping_folio(mapping, index, NULL);
+ if (IS_ERR(folio)) {
+ err = PTR_ERR(folio);
+ break;
+ }
+ } else {
+ folio = __filemap_get_folio(mapping, index,
+ FGP_CREAT|FGP_WRITE, GFP_KERNEL);
+ if (!folio) {
+ err = -ENOMEM;
+ break;
+ }
}
- lock_buffer(bh);
- memcpy(bh->b_data+offset, data, tocopy);
- flush_dcache_page(bh->b_page);
- set_buffer_uptodate(bh);
- mark_buffer_dirty(bh);
- unlock_buffer(bh);
- brelse(bh);
- offset = 0;
+
+ folio_lock(folio);
+ dst = kmap_local_folio(folio, offset_in_folio(folio, pos));
+ memcpy(dst, data, tocopy);
towrite -= tocopy;
data += tocopy;
- blk++;
+ pos += tocopy;
+ if (!towrite && pos >= inode->i_size)
+ memset(dst + tocopy, 0, PAGE_SIZE - tocopy);
+ kunmap_local(dst);
+
+ folio_mark_uptodate(folio);
+ folio_mark_dirty(folio);
+ folio_unlock(folio);
+ folio_put(folio);
}
-out:
+
if (len == towrite) {
inode_unlock(inode);
return err;
}
- if (inode->i_size < off+len-towrite)
- i_size_write(inode, off+len-towrite);
+ if (inode->i_size < pos + len - towrite)
+ i_size_write(inode, pos + len - towrite);
inode->i_mtime = inode->i_ctime = current_time(inode);
mark_inode_dirty(inode);
inode_unlock(inode);
--
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 ` [RFC PATCH 2/9] jfs: Add jfs_iomap_begin() Matthew Wilcox (Oracle)
2022-05-27 5:41 ` 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 ` Matthew Wilcox (Oracle) [this message]
2022-05-27 5:46 ` [RFC PATCH 8/9] jfs: Write quota through the page cache 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-9-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).