From: Christoph Hellwig <hch@lst.de>
To: Andreas Gruenbacher <agruenba@redhat.com>, linux-xfs@vger.kernel.org
Cc: Dan Williams <dan.j.williams@intel.com>,
linux-fsdevel@vger.kernel.org, cluster-devel@redhat.com,
linux-ext4@vger.kernel.org
Subject: [PATCH 5/6] iomap: generic inline data handling
Date: Wed, 6 Jun 2018 12:40:32 +0200 [thread overview]
Message-ID: <20180606104033.4947-6-hch@lst.de> (raw)
In-Reply-To: <20180606104033.4947-1-hch@lst.de>
From: Andreas Gruenbacher <agruenba@redhat.com>
Add generic inline data handling by adding a pointer to the inline data
region to struct iomap. When handling a buffered IOMAP_INLINE write,
iomap_write_begin will copy the current inline data from the inline data
region into the page cache, and iomap_write_end will copy the changes in
the page cache back to the inline data region.
This doesn't cover inline data reads and direct I/O yet because so far,
we have no users.
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
[hch: small cleanups to better fit in with other iomap work]
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/iomap.c | 62 +++++++++++++++++++++++++++++++++++++++++++++------
include/linux/iomap.h | 1 +
2 files changed, 56 insertions(+), 7 deletions(-)
diff --git a/fs/iomap.c b/fs/iomap.c
index f428baa32185..f2a491b98b7c 100644
--- a/fs/iomap.c
+++ b/fs/iomap.c
@@ -116,6 +116,26 @@ iomap_write_failed(struct inode *inode, loff_t pos, unsigned len)
truncate_pagecache_range(inode, max(pos, i_size), pos + len);
}
+static void
+iomap_read_inline_data(struct inode *inode, struct page *page,
+ struct iomap *iomap)
+{
+ size_t size = i_size_read(inode);
+ void *addr;
+
+ if (PageUptodate(page))
+ return;
+
+ BUG_ON(page->index);
+ BUG_ON(size > PAGE_SIZE - offset_in_page(iomap->inline_data));
+
+ addr = kmap_atomic(page);
+ memcpy(addr, iomap->inline_data, size);
+ memset(addr + size, 0, PAGE_SIZE - size);
+ kunmap_atomic(addr);
+ SetPageUptodate(page);
+}
+
static int
iomap_write_begin(struct inode *inode, loff_t pos, unsigned len, unsigned flags,
struct page **pagep, struct iomap *iomap)
@@ -133,7 +153,11 @@ iomap_write_begin(struct inode *inode, loff_t pos, unsigned len, unsigned flags,
if (!page)
return -ENOMEM;
- status = __block_write_begin_int(page, pos, len, NULL, iomap);
+ if (iomap->type == IOMAP_INLINE)
+ iomap_read_inline_data(inode, page, iomap);
+ else
+ status = __block_write_begin_int(page, pos, len, NULL, iomap);
+
if (unlikely(status)) {
unlock_page(page);
put_page(page);
@@ -146,14 +170,37 @@ iomap_write_begin(struct inode *inode, loff_t pos, unsigned len, unsigned flags,
return status;
}
+static int
+iomap_write_end_inline(struct inode *inode, struct page *page,
+ struct iomap *iomap, loff_t pos, unsigned copied)
+{
+ void *addr;
+
+ WARN_ON_ONCE(!PageUptodate(page));
+ BUG_ON(pos + copied > PAGE_SIZE - offset_in_page(iomap->inline_data));
+
+ addr = kmap_atomic(page);
+ memcpy(iomap->inline_data + pos, addr + pos, copied);
+ kunmap_atomic(addr);
+
+ mark_inode_dirty(inode);
+ __generic_write_end(inode, pos, copied, page);
+ return copied;
+}
+
static int
iomap_write_end(struct inode *inode, loff_t pos, unsigned len,
- unsigned copied, struct page *page)
+ unsigned copied, struct page *page, struct iomap *iomap)
{
int ret;
- ret = generic_write_end(NULL, inode->i_mapping, pos, len,
- copied, page, NULL);
+ if (iomap->type == IOMAP_INLINE) {
+ ret = iomap_write_end_inline(inode, page, iomap, pos, copied);
+ } else {
+ ret = generic_write_end(NULL, inode->i_mapping, pos, len,
+ copied, page, NULL);
+ }
+
if (ret < len)
iomap_write_failed(inode, pos, len);
return ret;
@@ -208,7 +255,8 @@ iomap_write_actor(struct inode *inode, loff_t pos, loff_t length, void *data,
flush_dcache_page(page);
- status = iomap_write_end(inode, pos, bytes, copied, page);
+ status = iomap_write_end(inode, pos, bytes, copied, page,
+ iomap);
if (unlikely(status < 0))
break;
copied = status;
@@ -302,7 +350,7 @@ iomap_dirty_actor(struct inode *inode, loff_t pos, loff_t length, void *data,
WARN_ON_ONCE(!PageUptodate(page));
- status = iomap_write_end(inode, pos, bytes, bytes, page);
+ status = iomap_write_end(inode, pos, bytes, bytes, page, iomap);
if (unlikely(status <= 0)) {
if (WARN_ON_ONCE(status == 0))
return -EIO;
@@ -354,7 +402,7 @@ static int iomap_zero(struct inode *inode, loff_t pos, unsigned offset,
zero_user(page, offset, bytes);
mark_page_accessed(page);
- return iomap_write_end(inode, pos, bytes, bytes, page);
+ return iomap_write_end(inode, pos, bytes, bytes, page, iomap);
}
static int iomap_dax_zero(loff_t pos, unsigned offset, unsigned bytes,
diff --git a/include/linux/iomap.h b/include/linux/iomap.h
index 212f4d59bcbf..69ef622f650e 100644
--- a/include/linux/iomap.h
+++ b/include/linux/iomap.h
@@ -56,6 +56,7 @@ struct iomap {
union {
struct block_device *bdev;
struct dax_device *dax_dev;
+ void *inline_data;
};
};
--
2.14.2
next prev parent reply other threads:[~2018-06-06 10:40 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-06 10:40 iomap preparations for GFS2 Christoph Hellwig
2018-06-06 10:40 ` [PATCH 1/6] fs: factor out a __generic_write_end helper Christoph Hellwig
2018-06-06 10:59 ` Christoph Hellwig
2018-06-06 11:09 ` Andreas Grünbacher
2018-06-06 10:40 ` [PATCH 2/6] iomap: move bdev and dax_dev in a union Christoph Hellwig
2018-06-06 11:37 ` Andreas Gruenbacher
2018-06-06 12:05 ` Christoph Hellwig
2018-06-06 10:40 ` [PATCH 3/6] iomap: mark newly allocated buffer heads as new Christoph Hellwig
2018-06-06 10:40 ` [PATCH 4/6] iomap: complete partial direct I/O writes synchronously Christoph Hellwig
2018-06-06 10:40 ` Christoph Hellwig [this message]
2018-06-07 13:50 ` [PATCH 5/6] iomap: generic inline data handling Andreas Grünbacher
2018-06-06 10:40 ` [PATCH 6/6] iomap: add a page_done callback Christoph Hellwig
2018-06-06 11:37 ` Andreas Gruenbacher
2018-06-06 11:38 ` iomap preparations for GFS2 Andreas Gruenbacher
2018-06-06 15:31 ` Andreas Grünbacher
2018-06-06 15:39 ` Christoph Hellwig
2018-06-14 12:04 iomap preparations for GFS2 v2 Christoph Hellwig
2018-06-14 12:04 ` [PATCH 5/6] iomap: generic inline data handling Christoph Hellwig
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=20180606104033.4947-6-hch@lst.de \
--to=hch@lst.de \
--cc=agruenba@redhat.com \
--cc=cluster-devel@redhat.com \
--cc=dan.j.williams@intel.com \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-xfs@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).