diff options
author | Andreas Gruenbacher <agruenba@redhat.com> | 2019-04-30 17:45:34 +0200 |
---|---|---|
committer | Darrick J. Wong <darrick.wong@oracle.com> | 2019-05-01 16:47:37 +0200 |
commit | df0db3ecdb8fc942e9d812558b8e15ecd3e050b1 (patch) | |
tree | 85e9df7f72f0aba01f16944860f80daf76d272e4 /fs/iomap.c | |
parent | iomap: Fix use-after-free error in page_done callback (diff) | |
download | linux-df0db3ecdb8fc942e9d812558b8e15ecd3e050b1.tar.xz linux-df0db3ecdb8fc942e9d812558b8e15ecd3e050b1.zip |
iomap: Add a page_prepare callback
Move the page_done callback into a separate iomap_page_ops structure and
add a page_prepare calback to be called before the next page is written
to. In gfs2, we'll want to start a transaction in page_prepare and end
it in page_done. Other filesystems that implement data journaling will
require the same kind of mechanism.
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Diffstat (limited to 'fs/iomap.c')
-rw-r--r-- | fs/iomap.c | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/fs/iomap.c b/fs/iomap.c index e6453c1c831e..fbfe20b7f6f0 100644 --- a/fs/iomap.c +++ b/fs/iomap.c @@ -657,6 +657,7 @@ static int iomap_write_begin(struct inode *inode, loff_t pos, unsigned len, unsigned flags, struct page **pagep, struct iomap *iomap) { + const struct iomap_page_ops *page_ops = iomap->page_ops; pgoff_t index = pos >> PAGE_SHIFT; struct page *page; int status = 0; @@ -666,9 +667,17 @@ iomap_write_begin(struct inode *inode, loff_t pos, unsigned len, unsigned flags, if (fatal_signal_pending(current)) return -EINTR; + if (page_ops && page_ops->page_prepare) { + status = page_ops->page_prepare(inode, pos, len, iomap); + if (status) + return status; + } + page = grab_cache_page_write_begin(inode->i_mapping, index, flags); - if (!page) - return -ENOMEM; + if (!page) { + status = -ENOMEM; + goto out_no_page; + } if (iomap->type == IOMAP_INLINE) iomap_read_inline_data(inode, page, iomap); @@ -676,15 +685,21 @@ iomap_write_begin(struct inode *inode, loff_t pos, unsigned len, unsigned flags, status = __block_write_begin_int(page, pos, len, NULL, iomap); else status = __iomap_write_begin(inode, pos, len, page, iomap); - if (unlikely(status)) { - unlock_page(page); - put_page(page); - page = NULL; - iomap_write_failed(inode, pos, len); - } + if (unlikely(status)) + goto out_unlock; *pagep = page; + return 0; + +out_unlock: + unlock_page(page); + put_page(page); + iomap_write_failed(inode, pos, len); + +out_no_page: + if (page_ops && page_ops->page_done) + page_ops->page_done(inode, pos, 0, NULL, iomap); return status; } @@ -758,6 +773,7 @@ static int iomap_write_end(struct inode *inode, loff_t pos, unsigned len, unsigned copied, struct page *page, struct iomap *iomap) { + const struct iomap_page_ops *page_ops = iomap->page_ops; int ret; if (iomap->type == IOMAP_INLINE) { @@ -770,8 +786,8 @@ iomap_write_end(struct inode *inode, loff_t pos, unsigned len, } __generic_write_end(inode, pos, ret, page); - if (iomap->page_done) - iomap->page_done(inode, pos, copied, page, iomap); + if (page_ops && page_ops->page_done) + page_ops->page_done(inode, pos, copied, page, iomap); put_page(page); if (ret < len) |