Commit d8456eaf authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'iomap-5.2-merge-2' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux

Pull iomap updates from Darrick Wong:
 "Nothing particularly exciting here, just adding some callouts for gfs2
  and cleaning a few things.

  Summary:

   - Add some extra hooks to the iomap buffered write path to enable
     gfs2 journalled writes

   - SPDX conversion

   - Various refactoring"

* tag 'iomap-5.2-merge-2' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux:
  iomap: move iomap_read_inline_data around
  iomap: Add a page_prepare callback
  iomap: Fix use-after-free error in page_done callback
  fs: Turn __generic_write_end into a void function
  iomap: Clean up __generic_write_end calling
  iomap: convert to SPDX identifier
parents b8cac3cd cbbf4c0b
...@@ -2085,7 +2085,7 @@ int block_write_begin(struct address_space *mapping, loff_t pos, unsigned len, ...@@ -2085,7 +2085,7 @@ int block_write_begin(struct address_space *mapping, loff_t pos, unsigned len,
} }
EXPORT_SYMBOL(block_write_begin); EXPORT_SYMBOL(block_write_begin);
int __generic_write_end(struct inode *inode, loff_t pos, unsigned copied, void __generic_write_end(struct inode *inode, loff_t pos, unsigned copied,
struct page *page) struct page *page)
{ {
loff_t old_size = inode->i_size; loff_t old_size = inode->i_size;
...@@ -2104,7 +2104,6 @@ int __generic_write_end(struct inode *inode, loff_t pos, unsigned copied, ...@@ -2104,7 +2104,6 @@ int __generic_write_end(struct inode *inode, loff_t pos, unsigned copied,
} }
unlock_page(page); unlock_page(page);
put_page(page);
if (old_size < pos) if (old_size < pos)
pagecache_isize_extended(inode, old_size, pos); pagecache_isize_extended(inode, old_size, pos);
...@@ -2116,7 +2115,6 @@ int __generic_write_end(struct inode *inode, loff_t pos, unsigned copied, ...@@ -2116,7 +2115,6 @@ int __generic_write_end(struct inode *inode, loff_t pos, unsigned copied,
*/ */
if (i_size_changed) if (i_size_changed)
mark_inode_dirty(inode); mark_inode_dirty(inode);
return copied;
} }
int block_write_end(struct file *file, struct address_space *mapping, int block_write_end(struct file *file, struct address_space *mapping,
...@@ -2160,7 +2158,9 @@ int generic_write_end(struct file *file, struct address_space *mapping, ...@@ -2160,7 +2158,9 @@ int generic_write_end(struct file *file, struct address_space *mapping,
struct page *page, void *fsdata) struct page *page, void *fsdata)
{ {
copied = block_write_end(file, mapping, pos, len, copied, page, fsdata); copied = block_write_end(file, mapping, pos, len, copied, page, fsdata);
return __generic_write_end(mapping->host, pos, copied, page); __generic_write_end(mapping->host, pos, copied, page);
put_page(page);
return copied;
} }
EXPORT_SYMBOL(generic_write_end); EXPORT_SYMBOL(generic_write_end);
......
...@@ -965,15 +965,20 @@ static void gfs2_write_unlock(struct inode *inode) ...@@ -965,15 +965,20 @@ static void gfs2_write_unlock(struct inode *inode)
gfs2_glock_dq_uninit(&ip->i_gh); gfs2_glock_dq_uninit(&ip->i_gh);
} }
static void gfs2_iomap_journaled_page_done(struct inode *inode, loff_t pos, static void gfs2_iomap_page_done(struct inode *inode, loff_t pos,
unsigned copied, struct page *page, unsigned copied, struct page *page,
struct iomap *iomap) struct iomap *iomap)
{ {
struct gfs2_inode *ip = GFS2_I(inode); struct gfs2_inode *ip = GFS2_I(inode);
gfs2_page_add_databufs(ip, page, offset_in_page(pos), copied); if (page)
gfs2_page_add_databufs(ip, page, offset_in_page(pos), copied);
} }
static const struct iomap_page_ops gfs2_iomap_page_ops = {
.page_done = gfs2_iomap_page_done,
};
static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos, static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos,
loff_t length, unsigned flags, loff_t length, unsigned flags,
struct iomap *iomap, struct iomap *iomap,
...@@ -1051,7 +1056,7 @@ static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos, ...@@ -1051,7 +1056,7 @@ static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos,
} }
} }
if (!gfs2_is_stuffed(ip) && gfs2_is_jdata(ip)) if (!gfs2_is_stuffed(ip) && gfs2_is_jdata(ip))
iomap->page_done = gfs2_iomap_journaled_page_done; iomap->page_ops = &gfs2_iomap_page_ops;
return 0; return 0;
out_trans_end: out_trans_end:
......
...@@ -44,7 +44,7 @@ static inline int __sync_blockdev(struct block_device *bdev, int wait) ...@@ -44,7 +44,7 @@ static inline int __sync_blockdev(struct block_device *bdev, int wait)
extern void guard_bio_eod(int rw, struct bio *bio); extern void guard_bio_eod(int rw, struct bio *bio);
extern int __block_write_begin_int(struct page *page, loff_t pos, unsigned len, extern int __block_write_begin_int(struct page *page, loff_t pos, unsigned len,
get_block_t *get_block, struct iomap *iomap); get_block_t *get_block, struct iomap *iomap);
int __generic_write_end(struct inode *inode, loff_t pos, unsigned copied, void __generic_write_end(struct inode *inode, loff_t pos, unsigned copied,
struct page *page); struct page *page);
/* /*
......
// SPDX-License-Identifier: GPL-2.0
/* /*
* Copyright (C) 2010 Red Hat, Inc. * Copyright (C) 2010 Red Hat, Inc.
* Copyright (c) 2016-2018 Christoph Hellwig. * Copyright (c) 2016-2018 Christoph Hellwig.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*/ */
#include <linux/module.h> #include <linux/module.h>
#include <linux/compiler.h> #include <linux/compiler.h>
...@@ -248,26 +240,6 @@ iomap_read_page_end_io(struct bio_vec *bvec, int error) ...@@ -248,26 +240,6 @@ iomap_read_page_end_io(struct bio_vec *bvec, int error)
iomap_read_finish(iop, page); iomap_read_finish(iop, page);
} }
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 void static void
iomap_read_end_io(struct bio *bio) iomap_read_end_io(struct bio *bio)
{ {
...@@ -289,6 +261,26 @@ struct iomap_readpage_ctx { ...@@ -289,6 +261,26 @@ struct iomap_readpage_ctx {
struct list_head *pages; struct list_head *pages;
}; };
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 loff_t static loff_t
iomap_readpage_actor(struct inode *inode, loff_t pos, loff_t length, void *data, iomap_readpage_actor(struct inode *inode, loff_t pos, loff_t length, void *data,
struct iomap *iomap) struct iomap *iomap)
...@@ -665,6 +657,7 @@ static int ...@@ -665,6 +657,7 @@ static int
iomap_write_begin(struct inode *inode, loff_t pos, unsigned len, unsigned flags, iomap_write_begin(struct inode *inode, loff_t pos, unsigned len, unsigned flags,
struct page **pagep, struct iomap *iomap) struct page **pagep, struct iomap *iomap)
{ {
const struct iomap_page_ops *page_ops = iomap->page_ops;
pgoff_t index = pos >> PAGE_SHIFT; pgoff_t index = pos >> PAGE_SHIFT;
struct page *page; struct page *page;
int status = 0; int status = 0;
...@@ -674,9 +667,17 @@ iomap_write_begin(struct inode *inode, loff_t pos, unsigned len, unsigned flags, ...@@ -674,9 +667,17 @@ iomap_write_begin(struct inode *inode, loff_t pos, unsigned len, unsigned flags,
if (fatal_signal_pending(current)) if (fatal_signal_pending(current))
return -EINTR; 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); page = grab_cache_page_write_begin(inode->i_mapping, index, flags);
if (!page) if (!page) {
return -ENOMEM; status = -ENOMEM;
goto out_no_page;
}
if (iomap->type == IOMAP_INLINE) if (iomap->type == IOMAP_INLINE)
iomap_read_inline_data(inode, page, iomap); iomap_read_inline_data(inode, page, iomap);
...@@ -684,15 +685,21 @@ iomap_write_begin(struct inode *inode, loff_t pos, unsigned len, unsigned flags, ...@@ -684,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); status = __block_write_begin_int(page, pos, len, NULL, iomap);
else else
status = __iomap_write_begin(inode, pos, len, page, iomap); 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; *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; return status;
} }
...@@ -738,13 +745,11 @@ __iomap_write_end(struct inode *inode, loff_t pos, unsigned len, ...@@ -738,13 +745,11 @@ __iomap_write_end(struct inode *inode, loff_t pos, unsigned len,
* uptodate page as a zero-length write, and force the caller to redo * uptodate page as a zero-length write, and force the caller to redo
* the whole thing. * the whole thing.
*/ */
if (unlikely(copied < len && !PageUptodate(page))) { if (unlikely(copied < len && !PageUptodate(page)))
copied = 0; return 0;
} else { iomap_set_range_uptodate(page, offset_in_page(pos), len);
iomap_set_range_uptodate(page, offset_in_page(pos), len); iomap_set_page_dirty(page);
iomap_set_page_dirty(page); return copied;
}
return __generic_write_end(inode, pos, copied, page);
} }
static int static int
...@@ -761,7 +766,6 @@ iomap_write_end_inline(struct inode *inode, struct page *page, ...@@ -761,7 +766,6 @@ iomap_write_end_inline(struct inode *inode, struct page *page,
kunmap_atomic(addr); kunmap_atomic(addr);
mark_inode_dirty(inode); mark_inode_dirty(inode);
__generic_write_end(inode, pos, copied, page);
return copied; return copied;
} }
...@@ -769,19 +773,22 @@ static int ...@@ -769,19 +773,22 @@ static int
iomap_write_end(struct inode *inode, loff_t pos, unsigned len, iomap_write_end(struct inode *inode, loff_t pos, unsigned len,
unsigned copied, struct page *page, struct iomap *iomap) unsigned copied, struct page *page, struct iomap *iomap)
{ {
const struct iomap_page_ops *page_ops = iomap->page_ops;
int ret; int ret;
if (iomap->type == IOMAP_INLINE) { if (iomap->type == IOMAP_INLINE) {
ret = iomap_write_end_inline(inode, page, iomap, pos, copied); ret = iomap_write_end_inline(inode, page, iomap, pos, copied);
} else if (iomap->flags & IOMAP_F_BUFFER_HEAD) { } else if (iomap->flags & IOMAP_F_BUFFER_HEAD) {
ret = generic_write_end(NULL, inode->i_mapping, pos, len, ret = block_write_end(NULL, inode->i_mapping, pos, len, copied,
copied, page, NULL); page, NULL);
} else { } else {
ret = __iomap_write_end(inode, pos, len, copied, page, iomap); ret = __iomap_write_end(inode, pos, len, copied, page, iomap);
} }
if (iomap->page_done) __generic_write_end(inode, pos, ret, page);
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) if (ret < len)
iomap_write_failed(inode, pos, len); iomap_write_failed(inode, pos, len);
......
...@@ -53,6 +53,8 @@ struct vm_fault; ...@@ -53,6 +53,8 @@ struct vm_fault;
*/ */
#define IOMAP_NULL_ADDR -1ULL /* addr is not valid */ #define IOMAP_NULL_ADDR -1ULL /* addr is not valid */
struct iomap_page_ops;
struct iomap { struct iomap {
u64 addr; /* disk offset of mapping, bytes */ u64 addr; /* disk offset of mapping, bytes */
loff_t offset; /* file offset of mapping, bytes */ loff_t offset; /* file offset of mapping, bytes */
...@@ -63,12 +65,22 @@ struct iomap { ...@@ -63,12 +65,22 @@ struct iomap {
struct dax_device *dax_dev; /* dax_dev for dax operations */ struct dax_device *dax_dev; /* dax_dev for dax operations */
void *inline_data; void *inline_data;
void *private; /* filesystem private */ void *private; /* filesystem private */
const struct iomap_page_ops *page_ops;
};
/* /*
* Called when finished processing a page in the mapping returned in * When a filesystem sets page_ops in an iomap mapping it returns, page_prepare
* this iomap. At least for now this is only supported in the buffered * and page_done will be called for each page written to. This only applies to
* write path. * buffered writes as unbuffered writes will not typically have pages
*/ * associated with them.
*
* When page_prepare succeeds, page_done will always be called to do any
* cleanup work necessary. In that page_done call, @page will be NULL if the
* associated page could not be obtained.
*/
struct iomap_page_ops {
int (*page_prepare)(struct inode *inode, loff_t pos, unsigned len,
struct iomap *iomap);
void (*page_done)(struct inode *inode, loff_t pos, unsigned copied, void (*page_done)(struct inode *inode, loff_t pos, unsigned copied,
struct page *page, struct iomap *iomap); struct page *page, struct iomap *iomap);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment