Skip to contentSkip to conversation

gfs2 iomap write support

PATCH Superseded Andreas Gruenbacher 2 participants 11 messages Jun 15, 2018 – Jun 20, 2018

Subsystems (3)

v9 of 10 Superseded Latest is v10 →

lore
Share & tools
lore

Andreas Gruenbacher

author maintainer
#0 lore raw

v9 cover gfs2 iomap write support

Here's another update of my gfs2 iomap write patches on top of:

git://git.infradead.org/users/hch/xfs.git gfs2-iomap

Changes since v8:

* Rebase on top of Christoph's branch.

* New patch to add private pointer to struct iomap.

Changes since v7:

* Drop patch that allows to unconditionally mark the inode dirty in __generic_write_end and mark the inode dirty in iomap_write_inline_data instead.

* Call the page_write_end hook even for IOMAP_INLINE mappings.

* Drop patch "iomap: Put struct iomap_ops into struct iomap".

Significant changes since v6:

* Switch to Christoph's patch for splitting out __generic_write_end and put the inode-dirtying change in a separate commit.

* Switch froma mandatory write_end operation to an optional page_write_end hook.

* Add a patch to pass struct iomap_ops in struct iomap at the end for demonstration purposes.

Significant changes since v5:

* Initial gfs2 specific cleanups split off and posted separately.

* New patch for generic iomap inline data handling.

* Iomap write_begin operation removed.

These patches can be found here:

https://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2.git/log/?h=iomap-write

Thanks,
Andreas

Andreas Gruenbacher (5):
iomap: add private pointer to struct iomap
gfs2: iomap buffered write support
gfs2: gfs2_extent_length cleanup
gfs2: iomap direct I/O support
gfs2: Remove gfs2_write_{begin,end}

 fs/gfs2/aops.c        | 331 ++-------------------------------------
 fs/gfs2/aops.h        |  22 +++
 fs/gfs2/bmap.c        | 352 ++++++++++++++++++++++++++++++++++++------
 fs/gfs2/file.c        | 168 ++++++++++++++++++--
 include/linux/iomap.h |   1 +
 5 files changed, 500 insertions(+), 374 deletions(-)
 create mode 100644 fs/gfs2/aops.h
Signature · 1 line
2.17.1
author maintainer
#1 lore raw

PATCH v9 1/5 iomap: add private pointer to struct iomap

Add a private pointer to struct iomap to allow filesystems to pass data from iomap_begin to iomap_end. Will be used by gfs2 for passing on the on-disk inode buffer head.

---
 include/linux/iomap.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/iomap.h +1 -0
index 43cc9208599f..9962dcb836b9 100644
@@ -59,6 +59,7 @@ struct iomap {
 		struct dax_device   *dax_dev;
 		void		    *inline_data;
 	};
+	void			*private; /* filesystem private */
 
 	/*
 	 * Called when finished processing a page in the mapping returned in
Signature · 1 line
2.17.1
author maintainer
#2 lore raw

Re: [PATCH v9 1/5] iomap: add private pointer to struct iomap

Hi Christoph,

Quoted 22 lines · Andreas Gruenbacher

Add a private pointer to struct iomap to allow filesystems to pass data from iomap_begin to iomap_end. Will be used by gfs2 for passing on the on-disk inode buffer head.

---
 include/linux/iomap.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/iomap.h +1 -1
index 43cc9208599f..9962dcb836b9 100644
@@ -59,6 +59,7 @@ struct iomap {
                struct dax_device   *dax_dev;
                void                *inline_data;
        };
+       void                    *private; /* filesystem private */
 
        /*
         * Called when finished processing a page in the mapping returned in
--
Quoted 1 line

2.17.1

any objections? If not, could you please add this to the shared branch?

Thanks,
Andreas

author maintainer
#4 lore raw

PATCH v9 2/5 gfs2: iomap buffered write support

In reply to Andreas Gruenbacher

With the traditional page-based writes, blocks are allocated separately for each page written to. With iomap writes, we can allocate a lot more blocks at once, with a fraction of the allocation overhead for each page.

Split calculating the number of blocks that can be allocated at a given position (gfs2_alloc_size) off from gfs2_iomap_alloc: that size determines the number of blocks to allocate and reserve in the journal.

In gfs2_iomap_alloc, set the type of newly allocated extents to IOMAP_MAPPED so that iomap_to_bh will set the bh states correctly:
otherwise, the bhs would not be marked as mapped, confusing __mpage_writepage. This means that we need to check for the IOMAP_F_NEW flag in fallocate_chunk now.

---
 fs/gfs2/aops.c |  20 ++--
 fs/gfs2/aops.h |  22 ++++
 fs/gfs2/bmap.c | 317 ++++++++++++++++++++++++++++++++++++++++++++-----
 fs/gfs2/file.c |  46 +++++--
 4 files changed, 359 insertions(+), 46 deletions(-)
 create mode 100644 fs/gfs2/aops.h
fs/gfs2/aops.c +11 -9
index 35f5ee23566d..ecfbca9c88ff 100644
@@ -22,6 +22,7 @@
 #include <linux/backing-dev.h>
 #include <linux/uio.h>
 #include <trace/events/writeback.h>
+#include <linux/sched/signal.h>
 
 #include "gfs2.h"
 #include "incore.h"
@@ -36,10 +37,11 @@
 #include "super.h"
 #include "util.h"
 #include "glops.h"
+#include "aops.h"
 
 
-static void gfs2_page_add_databufs(struct gfs2_inode *ip, struct page *page,
-				   unsigned int from, unsigned int len)
+void gfs2_page_add_databufs(struct gfs2_inode *ip, struct page *page,
+			    unsigned int from, unsigned int len)
 {
 	struct buffer_head *head = page_buffers(page);
 	unsigned int bsize = head->b_size;
@@ -462,7 +464,7 @@ static int gfs2_jdata_writepages(struct address_space *mapping,
  * Returns: errno
  */
 
-static int stuffed_readpage(struct gfs2_inode *ip, struct page *page)
+int stuffed_readpage(struct gfs2_inode *ip, struct page *page)
 {
 	struct buffer_head *dibh;
 	u64 dsize = i_size_read(&ip->i_inode);
@@ -776,7 +778,7 @@ static int gfs2_write_begin(struct file *file, struct address_space *mapping,
  * adjust_fs_space - Adjusts the free space available due to gfs2_grow
  * @inode: the rindex inode
  */
-static void adjust_fs_space(struct inode *inode)
+void adjust_fs_space(struct inode *inode)
 {
 	struct gfs2_sbd *sdp = inode->i_sb->s_fs_info;
 	struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode);
@@ -822,11 +824,11 @@ static void adjust_fs_space(struct inode *inode)
  * This copies the data from the page into the inode block after
  * the inode data structure itself.
  *
- * Returns: errno
+ * Returns: copied bytes or errno
  */
-static int gfs2_stuffed_write_end(struct inode *inode, struct buffer_head *dibh,
-				  loff_t pos, unsigned copied,
-				  struct page *page)
+int gfs2_stuffed_write_end(struct inode *inode, struct buffer_head *dibh,
+			   loff_t pos, unsigned copied,
+			   struct page *page)
 {
 	struct gfs2_inode *ip = GFS2_I(inode);
 	u64 to = pos + copied;
@@ -865,7 +867,7 @@ static int gfs2_stuffed_write_end(struct inode *inode, struct buffer_head *dibh,
  * The main write_end function for GFS2. We just put our locking around the VFS
  * provided functions.
  *
- * Returns: errno
+ * Returns: copied bytes or errno
  */
 
 static int gfs2_write_end(struct file *file, struct address_space *mapping,
fs/gfs2/aops.h new file +22 -0
new file mode 100644
index 000000000000..976bb32dd405
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2017 Red Hat, Inc.  All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU General Public License version 2.
+ */
+
+#ifndef __AOPS_DOT_H__
+#define __AOPS_DOT_H__
+
+#include "incore.h"
+
+extern int stuffed_readpage(struct gfs2_inode *ip, struct page *page);
+extern int gfs2_stuffed_write_end(struct inode *inode, struct buffer_head *dibh,
+				  loff_t pos, unsigned copied,
+				  struct page *page);
+extern void adjust_fs_space(struct inode *inode);
+extern void gfs2_page_add_databufs(struct gfs2_inode *ip, struct page *page,
+				   unsigned int from, unsigned int len);
+
+#endif /* __AOPS_DOT_H__ */
fs/gfs2/bmap.c +287 -30

425 lines not on this page · raw message

fs/gfs2/file.c +39 -7

80 lines not on this page · raw message

Signature · 1 line
2.17.1
#5 lore raw

Re: [PATCH v9 2/5] gfs2: iomap buffered write support

Quoted 7 lines

+/*
+ * Copyright (C) 2017 Red Hat, Inc. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU General Public License version 2.
+ */

Replace with an SPDX tag, please.

Quoted 1 line

+static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos, loff_t length,

overly long line.

fs/gfs2/bmap.c static int gfs2_iomap_get(struct inode *inode, loff_t pos, loff_t length, · line 1014

Quoted 1 line
fs/gfs2/bmap.c +1 -0
+		gfs2_write_calc_reserv(ip, iomap->length, &data_blocks, &ind_blocks);

plus a few more down the function.

fs/gfs2/file.c static ssize_t gfs2_file_write_iter(struct kiocb *iocb, struct iov_iter *from) · line 728

Quoted 2 lines
fs/gfs2/file.c +2 -0
+	if (iocb->ki_flags & IOCB_DIRECT)
+		return generic_file_write_iter(iocb, from);

This looks odd, as generic_file_write_iter duplicate the code below to a large extent, but it's probably ok.

fs/gfs2/file.c static int fallocate_chunk(struct inode *inode, loff_t offset, loff_t len, · line 790

Quoted 7 lines
fs/gfs2/file.c +1 -1
@@ -754,7 +786,7 @@ static int fallocate_chunk(struct inode *inode, loff_t offset, loff_t len,
 		if (error)
 			goto out;
 		offset = iomap.offset + iomap.length;
-		if (iomap.type != IOMAP_HOLE)
+		if (!(iomap.flags & IOMAP_F_NEW))
 			continue;

shouldn't this be a separate patch?

author maintainer
#6 lore raw

PATCH v9 3/5 gfs2: gfs2_extent_length cleanup

In reply to Andreas Gruenbacher

Now that gfs2_extent_length is no longer used for determining the size of a hole and always with an upper size limit, the function can be simplified.

---
 fs/gfs2/bmap.c | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)
fs/gfs2/bmap.c +8 -16
index 704a9150dcbc..b70ef98a9637 100644
@@ -406,22 +406,17 @@ static void release_metapath(struct metapath *mp)
 
 /**
  * gfs2_extent_length - Returns length of an extent of blocks
- * @start: Start of the buffer
- * @len: Length of the buffer in bytes
- * @ptr: Current position in the buffer
- * @limit: Max extent length to return (0 = unlimited)
+ * @bh: The metadata block
+ * @ptr: Current position in @bh
+ * @limit: Max extent length to return
  * @eob: Set to 1 if we hit "end of block"
  *
- * If the first block is zero (unallocated) it will return the number of
- * unallocated blocks in the extent, otherwise it will return the number
- * of contiguous blocks in the extent.
- *
  * Returns: The length of the extent (minimum of one block)
  */
 
-static inline unsigned int gfs2_extent_length(void *start, unsigned int len, __be64 *ptr, size_t limit, int *eob)
+static inline unsigned int gfs2_extent_length(struct buffer_head *bh, __be64 *ptr, size_t limit, int *eob)
 {
-	const __be64 *end = (start + len);
+	const __be64 *end = (__be64 *)(bh->b_data + bh->b_size);
 	const __be64 *first = ptr;
 	u64 d = be64_to_cpu(*ptr);
 
@@ -430,14 +425,11 @@ static inline unsigned int gfs2_extent_length(void *start, unsigned int len, __b
 		ptr++;
 		if (ptr >= end)
 			break;
-		if (limit && --limit == 0)
-			break;
-		if (d)
-			d++;
+		d++;
 	} while(be64_to_cpu(*ptr) == d);
 	if (ptr >= end)
 		*eob = 1;
-	return (ptr - first);
+	return ptr - first;
 }
 
 typedef const __be64 *(*gfs2_metadata_walker)(
@@ -884,7 +876,7 @@ static int gfs2_iomap_get(struct inode *inode, loff_t pos, loff_t length,
 		goto do_alloc;
 
 	bh = mp->mp_bh[ip->i_height - 1];
-	len = gfs2_extent_length(bh->b_data, bh->b_size, ptr, len, &eob);
+	len = gfs2_extent_length(bh, ptr, len, &eob);
 
 	iomap->addr = be64_to_cpu(*ptr) << inode->i_blkbits;
 	iomap->length = len << inode->i_blkbits;
Signature · 1 line
2.17.1
author maintainer
#7 lore raw

PATCH v9 4/5 gfs2: iomap direct I/O support

In reply to Andreas Gruenbacher

The page unmapping previously done in gfs2_direct_IO is now done generically in iomap_dio_rw.

---
 fs/gfs2/aops.c | 100 +----------------------------------
 fs/gfs2/bmap.c |  15 +++++-
 fs/gfs2/file.c | 138 +++++++++++++++++++++++++++++++++++++++++++++----
 3 files changed, 143 insertions(+), 110 deletions(-)
fs/gfs2/aops.c +2 -98
index ecfbca9c88ff..1054cc4a96db 100644
@@ -84,12 +84,6 @@ static int gfs2_get_block_noalloc(struct inode *inode, sector_t lblock,
 	return 0;
 }
 
-static int gfs2_get_block_direct(struct inode *inode, sector_t lblock,
-				 struct buffer_head *bh_result, int create)
-{
-	return gfs2_block_map(inode, lblock, bh_result, 0);
-}
-
 /**
  * gfs2_writepage_common - Common bits of writepage
  * @page: The page to be written
@@ -1024,96 +1018,6 @@ static void gfs2_invalidatepage(struct page *page, unsigned int offset,
 		try_to_release_page(page, 0);
 }
 
-/**
- * gfs2_ok_for_dio - check that dio is valid on this file
- * @ip: The inode
- * @offset: The offset at which we are reading or writing
- *
- * Returns: 0 (to ignore the i/o request and thus fall back to buffered i/o)
- *          1 (to accept the i/o request)
- */
-static int gfs2_ok_for_dio(struct gfs2_inode *ip, loff_t offset)
-{
-	/*
-	 * Should we return an error here? I can't see that O_DIRECT for
-	 * a stuffed file makes any sense. For now we'll silently fall
-	 * back to buffered I/O
-	 */
-	if (gfs2_is_stuffed(ip))
-		return 0;
-
-	if (offset >= i_size_read(&ip->i_inode))
-		return 0;
-	return 1;
-}
-
-
-
-static ssize_t gfs2_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
-{
-	struct file *file = iocb->ki_filp;
-	struct inode *inode = file->f_mapping->host;
-	struct address_space *mapping = inode->i_mapping;
-	struct gfs2_inode *ip = GFS2_I(inode);
-	loff_t offset = iocb->ki_pos;
-	struct gfs2_holder gh;
-	int rv;
-
-	/*
-	 * Deferred lock, even if its a write, since we do no allocation
-	 * on this path. All we need change is atime, and this lock mode
-	 * ensures that other nodes have flushed their buffered read caches
-	 * (i.e. their page cache entries for this inode). We do not,
-	 * unfortunately have the option of only flushing a range like
-	 * the VFS does.
-	 */
-	gfs2_holder_init(ip->i_gl, LM_ST_DEFERRED, 0, &gh);
-	rv = gfs2_glock_nq(&gh);
-	if (rv)
-		goto out_uninit;
-	rv = gfs2_ok_for_dio(ip, offset);
-	if (rv != 1)
-		goto out; /* dio not valid, fall back to buffered i/o */
-
-	/*
-	 * Now since we are holding a deferred (CW) lock at this point, you
-	 * might be wondering why this is ever needed. There is a case however
-	 * where we've granted a deferred local lock against a cached exclusive
-	 * glock. That is ok provided all granted local locks are deferred, but
-	 * it also means that it is possible to encounter pages which are
-	 * cached and possibly also mapped. So here we check for that and sort
-	 * them out ahead of the dio. The glock state machine will take care of
-	 * everything else.
-	 *
-	 * If in fact the cached glock state (gl->gl_state) is deferred (CW) in
-	 * the first place, mapping->nr_pages will always be zero.
-	 */
-	if (mapping->nrpages) {
-		loff_t lstart = offset & ~(PAGE_SIZE - 1);
-		loff_t len = iov_iter_count(iter);
-		loff_t end = PAGE_ALIGN(offset + len) - 1;
-
-		rv = 0;
-		if (len == 0)
-			goto out;
-		if (test_and_clear_bit(GIF_SW_PAGED, &ip->i_flags))
-			unmap_shared_mapping_range(ip->i_inode.i_mapping, offset, len);
-		rv = filemap_write_and_wait_range(mapping, lstart, end);
-		if (rv)
-			goto out;
-		if (iov_iter_rw(iter) == WRITE)
-			truncate_inode_pages_range(mapping, lstart, end);
-	}
-
-	rv = __blockdev_direct_IO(iocb, inode, inode->i_sb->s_bdev, iter,
-				  gfs2_get_block_direct, NULL, NULL, 0);
-out:
-	gfs2_glock_dq(&gh);
-out_uninit:
-	gfs2_holder_uninit(&gh);
-	return rv;
-}
-
 /**
  * gfs2_releasepage - free the metadata associated with a page
  * @page: the page that's being released
@@ -1194,7 +1098,7 @@ static const struct address_space_operations gfs2_writeback_aops = {
 	.bmap = gfs2_bmap,
 	.invalidatepage = gfs2_invalidatepage,
 	.releasepage = gfs2_releasepage,
-	.direct_IO = gfs2_direct_IO,
+	.direct_IO = noop_direct_IO,
 	.migratepage = buffer_migrate_page,
 	.is_partially_uptodate = block_is_partially_uptodate,
 	.error_remove_page = generic_error_remove_page,
@@ -1211,7 +1115,7 @@ static const struct address_space_operations gfs2_ordered_aops = {
 	.bmap = gfs2_bmap,
 	.invalidatepage = gfs2_invalidatepage,
 	.releasepage = gfs2_releasepage,
-	.direct_IO = gfs2_direct_IO,
+	.direct_IO = noop_direct_IO,
 	.migratepage = buffer_migrate_page,
 	.is_partially_uptodate = block_is_partially_uptodate,
 	.error_remove_page = generic_error_remove_page,
fs/gfs2/bmap.c +13 -2
index b70ef98a9637..3978b8cb3178 100644
@@ -906,6 +906,10 @@ static int gfs2_iomap_get(struct inode *inode, loff_t pos, loff_t length,
 			iomap->length = size - pos;
 	} else if (flags & IOMAP_WRITE) {
 		u64 size;
+
+		if (flags & IOMAP_DIRECT)
+			goto out;
+
 		size = gfs2_alloc_size(inode, mp, len) << inode->i_blkbits;
 		if (size < iomap->length)
 			iomap->length = size;
@@ -1080,7 +1084,14 @@ static int gfs2_iomap_begin(struct inode *inode, loff_t pos, loff_t length,
 
 	trace_gfs2_iomap_start(ip, pos, length, flags);
 	if (flags & IOMAP_WRITE) {
-		ret = gfs2_iomap_begin_write(inode, pos, length, flags, iomap);
+		if (flags & IOMAP_DIRECT) {
+			ret = gfs2_iomap_get(inode, pos, length, flags, iomap, &mp);
+			release_metapath(&mp);
+			if (iomap->type != IOMAP_MAPPED)
+				ret = -ENOTBLK;
+		} else {
+			ret = gfs2_iomap_begin_write(inode, pos, length, flags, iomap);
+		}
 	} else {
 		ret = gfs2_iomap_get(inode, pos, length, flags, iomap, &mp);
 		release_metapath(&mp);
@@ -1097,7 +1108,7 @@ static int gfs2_iomap_end(struct inode *inode, loff_t pos, loff_t length,
 	struct gfs2_trans *tr = current->journal_info;
 	struct buffer_head *dibh;
 
-	if (!(flags & IOMAP_WRITE))
+	if ((flags & (IOMAP_WRITE | IOMAP_DIRECT)) != IOMAP_WRITE)
 		return 0;
 
 	dibh = iomap->private;
fs/gfs2/file.c +128 -10

183 lines not on this page · raw message

Signature · 1 line
2.17.1
#8 lore raw

Re: [PATCH v9 4/5] gfs2: iomap direct I/O support

fs/gfs2/bmap.c static int gfs2_iomap_get(struct inode *inode, loff_t pos, loff_t length, · line 912

Quoted 6 lines
fs/gfs2/bmap.c +4 -0
 	} else if (flags & IOMAP_WRITE) {
 		u64 size;
+
+		if (flags & IOMAP_DIRECT)
+			goto out;
+

Maybe add a comment here on why you don't allow block allocations for direct I/O.

fs/gfs2/bmap.c static int gfs2_iomap_begin(struct inode *inode, loff_t pos, loff_t length, · line 1094

Quoted 8 lines
fs/gfs2/bmap.c +8 -0
+		if (flags & IOMAP_DIRECT) {
+			ret = gfs2_iomap_get(inode, pos, length, flags, iomap, &mp);
+			release_metapath(&mp);
+			if (iomap->type != IOMAP_MAPPED)
+				ret = -ENOTBLK;
+		} else {
+			ret = gfs2_iomap_begin_write(inode, pos, length, flags, iomap);
+		}

A couple too long lines.

fs/gfs2/bmap.c static int gfs2_iomap_begin(struct inode *inode, loff_t pos, loff_t length, · line 1097

Quoted 3 lines
fs/gfs2/bmap.c +0 -0
 	} else {
 		ret = gfs2_iomap_get(inode, pos, length, flags, iomap, &mp);
 		release_metapath(&mp);

But shouldn't the direct I/O code try to reuse this part anyway?

E.g. something like:

	if ((flags & (IOMAP_WRITE | IOMAP_DIRECT)) == IOMAP_WRITE)) {
		ret = gfs2_iomap_begin_write(inode, pos, length, flags, iomap);
	} else {
 		ret = gfs2_iomap_get(inode, pos, length, flags, iomap, &mp);
  		release_metapath(&mp);
		if ((flags & IOMAP_WRITE) && iomap->type != IOMAP_MAPPED)
			ret = -ENOTBLK;

fs/gfs2/file.c static int gfs2_fsync(struct file *file, loff_t start, loff_t end, · line 712

Quoted 4 lines
fs/gfs2/file.c +4 -0
+	/* fall back to buffered I/O for stuffed files */
+	ret = -ENOTBLK;
+	if (gfs2_is_stuffed(ip))
+		goto out;

I think we can handle stuffed files in the direct I/O code trivially by copying out the inline data in the iomap. It would be great to just handle this instead of adding fallbacks.

fs/gfs2/file.c static int gfs2_fsync(struct file *file, loff_t start, loff_t end, · line 748

Quoted 3 lines
fs/gfs2/file.c +3 -0
+	/* Silently fall back to buffered I/O for stuffed files */
+	if (gfs2_is_stuffed(ip))
+		goto out;

Same here.

fs/gfs2/file.c static int gfs2_fsync(struct file *file, loff_t start, loff_t end, · line 770

Quoted 8 lines
fs/gfs2/file.c +8 -0
+static ssize_t gfs2_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
+{
+	ssize_t ret;
+
+	if (iocb->ki_flags & IOCB_DIRECT) {
+		ret = gfs2_file_direct_read(iocb, to);
+		if (likely(ret != -ENOTBLK))
+			goto out;
			return ret;

fs/gfs2/file.c static int gfs2_fsync(struct file *file, loff_t start, loff_t end, · line 775

Quoted 5 lines
fs/gfs2/file.c +5 -0
+		iocb->ki_flags &= ~IOCB_DIRECT;
+	}
+	ret = generic_file_read_iter(iocb, to);
+out:
+	return ret;
	return generic_file_read_iter(iocb, to);
author maintainer
#9 lore raw

Re: [PATCH v9 4/5] gfs2: iomap direct I/O support

Quoted 37 lines · Christoph Hellwig

fs/gfs2/bmap.c static int gfs2_iomap_get(struct inode *inode, loff_t pos, loff_t length, · line 912

Quoted 6 lines
      } else if (flags & IOMAP_WRITE) {
              u64 size;
fs/gfs2/bmap.c +4 -0
+
+             if (flags & IOMAP_DIRECT)
+                     goto out;
+

Maybe add a comment here on why you don't allow block allocations for direct I/O.

fs/gfs2/bmap.c static int gfs2_iomap_begin(struct inode *inode, loff_t pos, loff_t length, · line 1094

Quoted 8 lines
fs/gfs2/bmap.c +8 -0
+             if (flags & IOMAP_DIRECT) {
+                     ret = gfs2_iomap_get(inode, pos, length, flags, iomap, &mp);
+                     release_metapath(&mp);
+                     if (iomap->type != IOMAP_MAPPED)
+                             ret = -ENOTBLK;
+             } else {
+                     ret = gfs2_iomap_begin_write(inode, pos, length, flags, iomap);
+             }

A couple too long lines.

Quoted 3 lines
      } else {
              ret = gfs2_iomap_get(inode, pos, length, flags, iomap, &mp);
              release_metapath(&mp);

But shouldn't the direct I/O code try to reuse this part anyway?

E.g. something like:

        if ((flags & (IOMAP_WRITE | IOMAP_DIRECT)) == IOMAP_WRITE)) {
                ret = gfs2_iomap_begin_write(inode, pos, length, flags, iomap);
        } else {
                ret = gfs2_iomap_get(inode, pos, length, flags, iomap, &mp);
                release_metapath(&mp);
                if ((flags & IOMAP_WRITE) && iomap->type != IOMAP_MAPPED)
                        ret = -ENOTBLK;
Quoted 8 lines

fs/gfs2/file.c static int gfs2_fsync(struct file *file, loff_t start, loff_t end, · line 712

Quoted 4 lines
fs/gfs2/file.c +4 -0
+     /* fall back to buffered I/O for stuffed files */
+     ret = -ENOTBLK;
+     if (gfs2_is_stuffed(ip))
+             goto out;

I think we can handle stuffed files in the direct I/O code trivially by copying out the inline data in the iomap. It would be great to just handle this instead of adding fallbacks.

On gfs2, direct I/O uses a "deferred lock", which is a special kind of shared lock. We can probably do inline reads under it, but not inline writes, so falling back to buffered I/O seems inevitable in that case at least.

Quoted 17 lines

fs/gfs2/file.c static int gfs2_fsync(struct file *file, loff_t start, loff_t end, · line 748

Quoted 3 lines
fs/gfs2/file.c +3 -0
+     /* Silently fall back to buffered I/O for stuffed files */
+     if (gfs2_is_stuffed(ip))
+             goto out;

Same here.

fs/gfs2/file.c static int gfs2_fsync(struct file *file, loff_t start, loff_t end, · line 770

Quoted 8 lines
fs/gfs2/file.c +8 -0
+static ssize_t gfs2_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
+{
+     ssize_t ret;
+
+     if (iocb->ki_flags & IOCB_DIRECT) {
+             ret = gfs2_file_direct_read(iocb, to);
+             if (likely(ret != -ENOTBLK))
+                     goto out;
                        return ret;
Quoted 7 lines

fs/gfs2/file.c static int gfs2_fsync(struct file *file, loff_t start, loff_t end, · line 775

Quoted 5 lines
fs/gfs2/file.c +5 -0
+             iocb->ki_flags &= ~IOCB_DIRECT;
+     }
+     ret = generic_file_read_iter(iocb, to);
+out:
+     return ret;
        return generic_file_read_iter(iocb, to);

Andreas

author maintainer
#10 lore raw

PATCH v9 5/5 gfs2: Remove gfs2_write_{begin,end}

In reply to Andreas Gruenbacher

Now that generic_file_write_iter is no longer used, there are no remaining users of these address space operations.

---
 fs/gfs2/aops.c | 213 -------------------------------------------------
 1 file changed, 213 deletions(-)
fs/gfs2/aops.c +0 -213
index 1054cc4a96db..cc80fd71f3dd 100644
@@ -639,135 +639,6 @@ static int gfs2_readpages(struct file *file, struct address_space *mapping,
 	return ret;
 }
 
-/**
- * gfs2_write_begin - Begin to write to a file
- * @file: The file to write to
- * @mapping: The mapping in which to write
- * @pos: The file offset at which to start writing
- * @len: Length of the write
- * @flags: Various flags
- * @pagep: Pointer to return the page
- * @fsdata: Pointer to return fs data (unused by GFS2)
- *
- * Returns: errno
- */
-
-static int gfs2_write_begin(struct file *file, struct address_space *mapping,
-			    loff_t pos, unsigned len, unsigned flags,
-			    struct page **pagep, void **fsdata)
-{
-	struct gfs2_inode *ip = GFS2_I(mapping->host);
-	struct gfs2_sbd *sdp = GFS2_SB(mapping->host);
-	struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode);
-	unsigned int data_blocks = 0, ind_blocks = 0, rblocks;
-	unsigned requested = 0;
-	int alloc_required;
-	int error = 0;
-	pgoff_t index = pos >> PAGE_SHIFT;
-	unsigned from = pos & (PAGE_SIZE - 1);
-	struct page *page;
-
-	gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &ip->i_gh);
-	error = gfs2_glock_nq(&ip->i_gh);
-	if (unlikely(error))
-		goto out_uninit;
-	if (&ip->i_inode == sdp->sd_rindex) {
-		error = gfs2_glock_nq_init(m_ip->i_gl, LM_ST_EXCLUSIVE,
-					   GL_NOCACHE, &m_ip->i_gh);
-		if (unlikely(error)) {
-			gfs2_glock_dq(&ip->i_gh);
-			goto out_uninit;
-		}
-	}
-
-	alloc_required = gfs2_write_alloc_required(ip, pos, len);
-
-	if (alloc_required || gfs2_is_jdata(ip))
-		gfs2_write_calc_reserv(ip, len, &data_blocks, &ind_blocks);
-
-	if (alloc_required) {
-		struct gfs2_alloc_parms ap = { .aflags = 0, };
-		requested = data_blocks + ind_blocks;
-		ap.target = requested;
-		error = gfs2_quota_lock_check(ip, &ap);
-		if (error)
-			goto out_unlock;
-
-		error = gfs2_inplace_reserve(ip, &ap);
-		if (error)
-			goto out_qunlock;
-	}
-
-	rblocks = RES_DINODE + ind_blocks;
-	if (gfs2_is_jdata(ip))
-		rblocks += data_blocks ? data_blocks : 1;
-	if (ind_blocks || data_blocks)
-		rblocks += RES_STATFS + RES_QUOTA;
-	if (&ip->i_inode == sdp->sd_rindex)
-		rblocks += 2 * RES_STATFS;
-	if (alloc_required)
-		rblocks += gfs2_rg_blocks(ip, requested);
-
-	error = gfs2_trans_begin(sdp, rblocks,
-				 PAGE_SIZE/sdp->sd_sb.sb_bsize);
-	if (error)
-		goto out_trans_fail;
-
-	error = -ENOMEM;
-	flags |= AOP_FLAG_NOFS;
-	page = grab_cache_page_write_begin(mapping, index, flags);
-	*pagep = page;
-	if (unlikely(!page))
-		goto out_endtrans;
-
-	if (gfs2_is_stuffed(ip)) {
-		error = 0;
-		if (pos + len > gfs2_max_stuffed_size(ip)) {
-			error = gfs2_unstuff_dinode(ip, page);
-			if (error == 0)
-				goto prepare_write;
-		} else if (!PageUptodate(page)) {
-			error = stuffed_readpage(ip, page);
-		}
-		goto out;
-	}
-
-prepare_write:
-	error = __block_write_begin(page, from, len, gfs2_block_map);
-out:
-	if (error == 0)
-		return 0;
-
-	unlock_page(page);
-	put_page(page);
-
-	gfs2_trans_end(sdp);
-	if (alloc_required) {
-		gfs2_inplace_release(ip);
-		if (pos + len > ip->i_inode.i_size)
-			gfs2_trim_blocks(&ip->i_inode);
-	}
-	goto out_qunlock;
-
-out_endtrans:
-	gfs2_trans_end(sdp);
-out_trans_fail:
-	if (alloc_required)
-		gfs2_inplace_release(ip);
-out_qunlock:
-	if (alloc_required)
-		gfs2_quota_unlock(ip);
-out_unlock:
-	if (&ip->i_inode == sdp->sd_rindex) {
-		gfs2_glock_dq(&m_ip->i_gh);
-		gfs2_holder_uninit(&m_ip->i_gh);
-	}
-	gfs2_glock_dq(&ip->i_gh);
-out_uninit:
-	gfs2_holder_uninit(&ip->i_gh);
-	return error;
-}
-
 /**
  * adjust_fs_space - Adjusts the free space available due to gfs2_grow
  * @inode: the rindex inode
@@ -848,84 +719,6 @@ int gfs2_stuffed_write_end(struct inode *inode, struct buffer_head *dibh,
 	return copied;
 }
 
-/**
- * gfs2_write_end
- * @file: The file to write to
- * @mapping: The address space to write to
- * @pos: The file position
- * @len: The length of the data
- * @copied: How much was actually copied by the VFS
- * @page: The page that has been written
- * @fsdata: The fsdata (unused in GFS2)
- *
- * The main write_end function for GFS2. We just put our locking around the VFS
- * provided functions.
- *
- * Returns: copied bytes or errno
- */
-
-static int gfs2_write_end(struct file *file, struct address_space *mapping,
-			  loff_t pos, unsigned len, unsigned copied,
-			  struct page *page, void *fsdata)
-{
-	struct inode *inode = page->mapping->host;
-	struct gfs2_inode *ip = GFS2_I(inode);
-	struct gfs2_sbd *sdp = GFS2_SB(inode);
-	struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode);
-	struct buffer_head *dibh;
-	int ret;
-	struct gfs2_trans *tr = current->journal_info;
-	BUG_ON(!tr);
-
-	BUG_ON(gfs2_glock_is_locked_by_me(ip->i_gl) == NULL);
-
-	ret = gfs2_meta_inode_buffer(ip, &dibh);
-	if (unlikely(ret))
-		goto out;
-
-	if (gfs2_is_stuffed(ip)) {
-		ret = gfs2_stuffed_write_end(inode, dibh, pos, copied, page);
-		page = NULL;
-		goto out2;
-	}
-
-	if (gfs2_is_jdata(ip))
-		gfs2_page_add_databufs(ip, page, pos & ~PAGE_MASK, len);
-	else
-		gfs2_ordered_add_inode(ip);
-
-	ret = generic_write_end(file, mapping, pos, len, copied, page, fsdata);
-	page = NULL;
-	if (tr->tr_num_buf_new)
-		__mark_inode_dirty(inode, I_DIRTY_DATASYNC);
-	else
-		gfs2_trans_add_meta(ip->i_gl, dibh);
-
-out2:
-	if (inode == sdp->sd_rindex) {
-		adjust_fs_space(inode);
-		sdp->sd_rindex_uptodate = 0;
-	}
-
-	brelse(dibh);
-out:
-	if (page) {
-		unlock_page(page);
-		put_page(page);
-	}
-	gfs2_trans_end(sdp);
-	gfs2_inplace_release(ip);
-	if (ip->i_qadata && ip->i_qadata->qa_qd_num)
-		gfs2_quota_unlock(ip);
-	if (inode == sdp->sd_rindex) {
-		gfs2_glock_dq(&m_ip->i_gh);
-		gfs2_holder_uninit(&m_ip->i_gh);
-	}
-	gfs2_glock_dq(&ip->i_gh);
-	gfs2_holder_uninit(&ip->i_gh);
-	return ret;
-}
-
 /**
  * jdata_set_page_dirty - Page dirtying function
  * @page: The page to dirty
@@ -1093,8 +886,6 @@ static const struct address_space_operations gfs2_writeback_aops = {
 	.writepages = gfs2_writepages,
 	.readpage = gfs2_readpage,
 	.readpages = gfs2_readpages,
-	.write_begin = gfs2_write_begin,
-	.write_end = gfs2_write_end,
 	.bmap = gfs2_bmap,
 	.invalidatepage = gfs2_invalidatepage,
 	.releasepage = gfs2_releasepage,
@@ -1109,8 +900,6 @@ static const struct address_space_operations gfs2_ordered_aops = {
 	.writepages = gfs2_writepages,
 	.readpage = gfs2_readpage,
 	.readpages = gfs2_readpages,
-	.write_begin = gfs2_write_begin,
-	.write_end = gfs2_write_end,
 	.set_page_dirty = __set_page_dirty_buffers,
 	.bmap = gfs2_bmap,
 	.invalidatepage = gfs2_invalidatepage,
@@ -1126,8 +915,6 @@ static const struct address_space_operations gfs2_jdata_aops = {
 	.writepages = gfs2_jdata_writepages,
 	.readpage = gfs2_readpage,
 	.readpages = gfs2_readpages,
-	.write_begin = gfs2_write_begin,
-	.write_end = gfs2_write_end,
 	.set_page_dirty = jdata_set_page_dirty,
 	.bmap = gfs2_bmap,
 	.invalidatepage = gfs2_invalidatepage,
Signature · 1 line
2.17.1