From: Andreas Gruenbacher <agruenba@redhat.com>
To: cluster-devel@redhat.com, Christoph Hellwig <hch@lst.de>
Cc: linux-fsdevel@vger.kernel.org, Andreas Gruenbacher <agruenba@redhat.com>
Subject: [PATCH v6 5/9] iomap: Add write_end iomap operation
Date: Sat, 2 Jun 2018 11:57:13 +0200 [thread overview]
Message-ID: <20180602095717.31641-6-agruenba@redhat.com> (raw)
In-Reply-To: <20180602095717.31641-1-agruenba@redhat.com>
Add a write_end operation to struct iomap_ops to provide a way of
overriding the default behavior of iomap_write_end. This will be used
for implementing data journaling in gfs2: in the data journaling case,
pages are written into the journal before being written back to their
proper on-disk locations.
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
fs/ext2/inode.c | 1 +
fs/ext4/inode.c | 1 +
fs/iomap.c | 53 +++++++++++++++++++++++++++++++------------
fs/xfs/xfs_iomap.c | 1 +
include/linux/iomap.h | 12 ++++++++++
5 files changed, 53 insertions(+), 15 deletions(-)
diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c
index 71635909df3b..2744bf15b74b 100644
--- a/fs/ext2/inode.c
+++ b/fs/ext2/inode.c
@@ -848,6 +848,7 @@ ext2_iomap_end(struct inode *inode, loff_t offset, loff_t length,
const struct iomap_ops ext2_iomap_ops = {
.iomap_begin = ext2_iomap_begin,
+ .write_end = iomap_write_end,
.iomap_end = ext2_iomap_end,
};
#else
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 1e50c5efae67..16dd1b4cc9f9 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -3604,6 +3604,7 @@ static int ext4_iomap_end(struct inode *inode, loff_t offset, loff_t length,
const struct iomap_ops ext4_iomap_ops = {
.iomap_begin = ext4_iomap_begin,
+ .write_end = iomap_write_end,
.iomap_end = ext4_iomap_end,
};
diff --git a/fs/iomap.c b/fs/iomap.c
index 857c4b7b54eb..8f7dca17300d 100644
--- a/fs/iomap.c
+++ b/fs/iomap.c
@@ -178,7 +178,7 @@ iomap_write_begin(struct inode *inode, loff_t pos, unsigned len, unsigned flags,
return status;
}
-static int
+int
iomap_write_end(struct inode *inode, loff_t pos, unsigned len,
unsigned copied, struct page *page, struct iomap *iomap)
{
@@ -197,12 +197,19 @@ iomap_write_end(struct inode *inode, loff_t pos, unsigned len,
iomap_write_failed(inode, pos, len);
return ret;
}
+EXPORT_SYMBOL_GPL(iomap_write_end);
+
+struct iomap_write_args {
+ const struct iomap_ops *ops;
+ struct iov_iter *iter;
+};
static loff_t
iomap_write_actor(struct inode *inode, loff_t pos, loff_t length, void *data,
struct iomap *iomap)
{
- struct iov_iter *i = data;
+ struct iomap_write_args *args = data;
+ struct iov_iter *i = args->iter;
long status = 0;
ssize_t written = 0;
unsigned int flags = AOP_FLAG_NOFS;
@@ -247,7 +254,7 @@ 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 = args->ops->write_end(inode, pos, bytes, copied, page,
iomap);
if (unlikely(status < 0))
break;
@@ -285,10 +292,14 @@ iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *iter,
{
struct inode *inode = iocb->ki_filp->f_mapping->host;
loff_t pos = iocb->ki_pos, ret = 0, written = 0;
+ struct iomap_write_args args = {
+ .ops = ops,
+ .iter = iter,
+ };
while (iov_iter_count(iter)) {
ret = iomap_apply(inode, pos, iov_iter_count(iter),
- IOMAP_WRITE, ops, iter, iomap_write_actor);
+ IOMAP_WRITE, ops, &args, iomap_write_actor);
if (ret <= 0)
break;
pos += ret;
@@ -319,6 +330,7 @@ static loff_t
iomap_dirty_actor(struct inode *inode, loff_t pos, loff_t length, void *data,
struct iomap *iomap)
{
+ const struct iomap_ops *ops = data;
long status = 0;
ssize_t written = 0;
@@ -335,14 +347,14 @@ iomap_dirty_actor(struct inode *inode, loff_t pos, loff_t length, void *data,
return PTR_ERR(rpage);
status = iomap_write_begin(inode, pos, bytes,
- AOP_FLAG_NOFS, &page, iomap);
+ AOP_FLAG_NOFS, &page, iomap);
put_page(rpage);
if (unlikely(status))
return status;
WARN_ON_ONCE(!PageUptodate(page));
- status = iomap_write_end(inode, pos, bytes, bytes, page, iomap);
+ status = ops->write_end(inode, pos, bytes, bytes, page, iomap);
if (unlikely(status <= 0)) {
if (WARN_ON_ONCE(status == 0))
return -EIO;
@@ -368,7 +380,7 @@ iomap_file_dirty(struct inode *inode, loff_t pos, loff_t len,
loff_t ret;
while (len) {
- ret = iomap_apply(inode, pos, len, IOMAP_WRITE, ops, NULL,
+ ret = iomap_apply(inode, pos, len, IOMAP_WRITE, ops, (void *)ops,
iomap_dirty_actor);
if (ret <= 0)
return ret;
@@ -381,20 +393,21 @@ iomap_file_dirty(struct inode *inode, loff_t pos, loff_t len,
EXPORT_SYMBOL_GPL(iomap_file_dirty);
static int iomap_zero(struct inode *inode, loff_t pos, unsigned offset,
- unsigned bytes, struct iomap *iomap)
+ unsigned bytes, const struct iomap_ops *ops,
+ struct iomap *iomap)
{
struct page *page;
int status;
status = iomap_write_begin(inode, pos, bytes, AOP_FLAG_NOFS, &page,
- iomap);
+ iomap);
if (status)
return status;
zero_user(page, offset, bytes);
mark_page_accessed(page);
- return iomap_write_end(inode, pos, bytes, bytes, page, iomap);
+ return ops->write_end(inode, pos, bytes, bytes, page, iomap);
}
static int iomap_dax_zero(loff_t pos, unsigned offset, unsigned bytes,
@@ -407,11 +420,16 @@ static int iomap_dax_zero(loff_t pos, unsigned offset, unsigned bytes,
offset, bytes);
}
+struct iomap_zero_range_args {
+ const struct iomap_ops *ops;
+ bool *did_zero;
+};
+
static loff_t
iomap_zero_range_actor(struct inode *inode, loff_t pos, loff_t count,
void *data, struct iomap *iomap)
{
- bool *did_zero = data;
+ struct iomap_zero_range_args *args = data;
loff_t written = 0;
int status;
@@ -428,15 +446,16 @@ iomap_zero_range_actor(struct inode *inode, loff_t pos, loff_t count,
if (IS_DAX(inode))
status = iomap_dax_zero(pos, offset, bytes, iomap);
else
- status = iomap_zero(inode, pos, offset, bytes, iomap);
+ status = iomap_zero(inode, pos, offset, bytes,
+ (void *)args->ops, iomap);
if (status < 0)
return status;
pos += bytes;
count -= bytes;
written += bytes;
- if (did_zero)
- *did_zero = true;
+ if (args->did_zero)
+ *args->did_zero = true;
} while (count > 0);
return written;
@@ -446,11 +465,15 @@ int
iomap_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero,
const struct iomap_ops *ops)
{
+ struct iomap_zero_range_args args = {
+ .ops = ops,
+ .did_zero = did_zero,
+ };
loff_t ret;
while (len > 0) {
ret = iomap_apply(inode, pos, len, IOMAP_ZERO,
- ops, did_zero, iomap_zero_range_actor);
+ ops, &args, iomap_zero_range_actor);
if (ret <= 0)
return ret;
diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
index 046469fcc1b8..6b817b83a078 100644
--- a/fs/xfs/xfs_iomap.c
+++ b/fs/xfs/xfs_iomap.c
@@ -1199,6 +1199,7 @@ xfs_file_iomap_end(
const struct iomap_ops xfs_iomap_ops = {
.iomap_begin = xfs_file_iomap_begin,
+ .write_end = iomap_write_end,
.iomap_end = xfs_file_iomap_end,
};
diff --git a/include/linux/iomap.h b/include/linux/iomap.h
index c61113c71a60..8cd67afe78d7 100644
--- a/include/linux/iomap.h
+++ b/include/linux/iomap.h
@@ -62,6 +62,8 @@ struct iomap {
#define IOMAP_DIRECT (1 << 4) /* direct I/O */
#define IOMAP_NOWAIT (1 << 5) /* Don't wait for writeback */
+struct page;
+
struct iomap_ops {
/*
* Return the existing mapping at pos, or reserve space starting at
@@ -71,6 +73,13 @@ struct iomap_ops {
int (*iomap_begin)(struct inode *inode, loff_t pos, loff_t length,
unsigned flags, struct iomap *iomap);
+ /*
+ * End writing to a page. Usually initialized to iomap_write_end.
+ */
+ int (*write_end)(struct inode *inode, loff_t pos, unsigned len,
+ unsigned copied, struct page *page,
+ struct iomap *iomap);
+
/*
* Commit and/or unreserve space previous allocated using iomap_begin.
* Written indicates the length of the successful write operation which
@@ -81,6 +90,9 @@ struct iomap_ops {
ssize_t written, unsigned flags, struct iomap *iomap);
};
+int iomap_write_end(struct inode *inode, loff_t pos, unsigned len,
+ unsigned copied, struct page *page, struct iomap *iomap);
+
ssize_t iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *from,
const struct iomap_ops *ops);
int iomap_file_dirty(struct inode *inode, loff_t pos, loff_t len,
--
2.17.0
next prev parent reply other threads:[~2018-06-02 9:57 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-02 9:57 [PATCH v6 0/9] gfs2 iomap write support Andreas Gruenbacher
2018-06-02 9:57 ` [PATCH v6 1/9] iomap: inline data should be an iomap type, not a flag Andreas Gruenbacher
2018-06-02 9:57 ` [PATCH v6 2/9] iomap: Mark newly allocated buffer heads as new Andreas Gruenbacher
2018-06-02 16:58 ` Christoph Hellwig
2018-06-02 9:57 ` [PATCH v6 3/9] iomap: Complete partial direct I/O writes synchronously Andreas Gruenbacher
2018-06-02 16:58 ` Christoph Hellwig
2018-06-02 9:57 ` [PATCH v6 4/9] iomap: Generic inline data handling Andreas Gruenbacher
2018-06-02 17:04 ` Christoph Hellwig
2018-06-04 12:02 ` Andreas Grünbacher
2018-06-04 12:12 ` Christoph Hellwig
2018-06-04 17:01 ` Andreas Grünbacher
2018-06-02 9:57 ` Andreas Gruenbacher [this message]
2018-06-02 17:06 ` [PATCH v6 5/9] iomap: Add write_end iomap operation Christoph Hellwig
2018-06-04 12:03 ` Andreas Grünbacher
2018-06-02 9:57 ` [PATCH v6 6/9] gfs2: iomap buffered write support Andreas Gruenbacher
2018-06-02 9:57 ` [PATCH v6 7/9] gfs2: gfs2_extent_length cleanup Andreas Gruenbacher
2018-06-02 9:57 ` [PATCH v6 8/9] gfs2: iomap direct I/O support Andreas Gruenbacher
2018-06-02 9:57 ` [PATCH v6 9/9] gfs2: Remove gfs2_write_{begin,end} Andreas Gruenbacher
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=20180602095717.31641-6-agruenba@redhat.com \
--to=agruenba@redhat.com \
--cc=cluster-devel@redhat.com \
--cc=hch@lst.de \
--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).