Before this patch, when flushing out its ail1 list, gfs2_write_jdata_page
called __block_write_full_page passing in function gfs2_get_block_noalloc.
But there was a problem when a process wrote to a jdata file, then
truncated it or punched a hole, leaving references to the blocks within
the new hole in its ail list, which are to be written to the journal log.

In writing them to the journal, after calling gfs2_block_map, function
gfs2_get_block_noalloc, determined that the (hole-punched) block was not
mapped, so it returned -EIO to generic_writepages, which passed it back
to gfs2_ail1_start_one. This, in turn, performed a withdraw, assuming
there was a real IO error writing to the journal.

This might be a valid error when writing metadata to the journal, but for
journaled data writes, it does not warrant with withdraw.

This patch makes a separate function gfs2_get_jblock_noalloc which checks
for this situation and makes an exception for journaled data writes that
correspond to jdata holes. Other errors are returned as before.

Signed-off-by: Bob Peterson <rpete...@redhat.com>
---
 fs/gfs2/aops.c | 27 +++++++++++++++++++++++++--
 fs/gfs2/bmap.c |  8 ++++++--
 2 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/fs/gfs2/aops.c b/fs/gfs2/aops.c
index 9b2e927e6535..b2ab0077e150 100644
--- a/fs/gfs2/aops.c
+++ b/fs/gfs2/aops.c
@@ -81,6 +81,29 @@ static int gfs2_get_block_noalloc(struct inode *inode, 
sector_t lblock,
        return 0;
 }
 
+/**
+ * gfs2_get_jblock_noalloc - Fills in a buffer head with details about a block
+ * @inode: The inode
+ * @lblock: The block number to look up
+ * @bh_result: The buffer head to return the result in
+ * @create: Non-zero if we may add block to the file
+ *
+ * Returns: errno
+ */
+
+static int gfs2_get_jblock_noalloc(struct inode *inode, sector_t lblock,
+                                  struct buffer_head *bh_result, int create)
+{
+       int error;
+
+       error = gfs2_block_map(inode, lblock, bh_result, 0);
+       if (error)
+               return error;
+       if (!buffer_mapped(bh_result))
+               return -EIO;
+       return 0;
+}
+
 /**
  * gfs2_writepage - Write page for writeback mappings
  * @page: The page
@@ -142,8 +165,8 @@ static int gfs2_write_jdata_page(struct page *page,
        if (page->index == end_index && offset)
                zero_user_segment(page, offset, PAGE_SIZE);
 
-       return __block_write_full_page(inode, page, gfs2_get_block_noalloc, wbc,
-                                      end_buffer_async_write);
+       return __block_write_full_page(inode, page, gfs2_get_jblock_noalloc,
+                                     wbc, end_buffer_async_write);
 }
 
 /**
diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c
index 67aff327bf38..2e3b121fb78b 100644
--- a/fs/gfs2/bmap.c
+++ b/fs/gfs2/bmap.c
@@ -1300,8 +1300,12 @@ int gfs2_block_map(struct inode *inode, sector_t lblock,
        trace_gfs2_bmap(ip, bh_map, lblock, create, 1);
 
        ret = gfs2_iomap_get(inode, pos, length, flags, &iomap, &mp);
-       if (create && !ret && iomap.type == IOMAP_HOLE)
-               ret = gfs2_iomap_alloc(inode, &iomap, &mp);
+       if (!ret && iomap.type == IOMAP_HOLE) {
+               if (create)
+                       ret = gfs2_iomap_alloc(inode, &iomap, &mp);
+               else
+                       ret = -ENODATA;
+       }
        release_metapath(&mp);
        if (ret)
                goto out;
-- 
2.26.2

Reply via email to