Skip to contentSkip to conversation

hfsplus: fix "unused node is not erased" error

PATCH In review Sergei Antonov 2 participants 7 messages May 20, 2014 – May 23, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hfsplus: fix "unused node is not erased" error

Zero newly allocated extents in the catalog tree if volume attributes tell us to. Not doing so we risk getting the "unused node is not erased" error. See kHFSUnusedNodeFix flag in Apple's source code for reference.

There was a previous commit clearing the node when it is freed:
commit 899bed05e9f6bbb21776f9ebd88f5631987f987a
Author: Vyacheslav Dubeyko <[email protected]>
Date: Wed Feb 27 17:03:06 2013 -0800
hfsplus: fix issue with unzeroed unused b-tree nodes
It did not handle newly allocated extents (this patch fixes it). And it zeroed nodes in all trees unconditionally which is an overkill. This patch adds a condition and also switches to 'tree->node_size' as a simpler method of getting the length to zero.

Cc Anton Altaparmakov <[email protected]>
Cc Al Viro <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Vyacheslav Dubeyko <[email protected]>
Cc Hin-Tak Leung <[email protected]>
Cc Kyle Laracey <[email protected]>
Cc Andrew Morton <[email protected]>
---
 fs/hfsplus/bnode.c       | 17 +++++++++++++++--
 fs/hfsplus/btree.c       |  2 +-
 fs/hfsplus/extents.c     | 10 ++++++++--
 fs/hfsplus/hfsplus_fs.h  |  3 ++-
 fs/hfsplus/hfsplus_raw.h |  1 +
 fs/hfsplus/xattr.c       |  2 +-
 6 files changed, 28 insertions(+), 7 deletions(-)
fs/hfsplus/bnode.c +15 -2
index 11c8602..15a844f 100644
@@ -648,8 +648,8 @@ void hfs_bnode_put(struct hfs_bnode *node)
 		if (test_bit(HFS_BNODE_DELETED, &node->flags)) {
 			hfs_bnode_unhash(node);
 			spin_unlock(&tree->hash_lock);
-			hfs_bnode_clear(node, 0,
-				PAGE_CACHE_SIZE * tree->pages_per_bnode);
+			if (hfs_bnode_need_zeroout(tree))
+				hfs_bnode_clear(node, 0, tree->node_size);
 			hfs_bmap_free(node);
 			hfs_bnode_free(node);
 			return;
@@ -658,3 +658,16 @@ void hfs_bnode_put(struct hfs_bnode *node)
 	}
 }
 
+/*
+ * Unused nodes have to be zeroed if this is the catalog tree and
+ * a corresponding flag in the volume header is set.
+ */
+bool hfs_bnode_need_zeroout(struct hfs_btree *tree)
+{
+	struct super_block *sb = tree->inode->i_sb;
+	struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
+	const u32 volume_attr = be32_to_cpu(sbi->s_vhdr->attributes);
+
+	return tree->cnid == HFSPLUS_CAT_CNID &&
+		volume_attr & HFSPLUS_VOL_UNUSED_NODE_FIX;
+}
fs/hfsplus/btree.c +1 -1
index 0fcec8b..3345c75 100644
@@ -358,7 +358,7 @@ struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *tree)
 		u32 count;
 		int res;
 
-		res = hfsplus_file_extend(inode);
+		res = hfsplus_file_extend(inode, hfs_bnode_need_zeroout(tree));
 		if (res)
 			return ERR_PTR(res);
 		hip->phys_size = inode->i_size =
fs/hfsplus/extents.c +8 -2
index a7aafb35..a09fcb6 100644
@@ -235,7 +235,7 @@ int hfsplus_get_block(struct inode *inode, sector_t iblock,
 		if (iblock > hip->fs_blocks || !create)
 			return -EIO;
 		if (ablock >= hip->alloc_blocks) {
-			res = hfsplus_file_extend(inode);
+			res = hfsplus_file_extend(inode, false);
 			if (res)
 				return res;
 		}
@@ -425,7 +425,7 @@ int hfsplus_free_fork(struct super_block *sb, u32 cnid,
 	return res;
 }
 
-int hfsplus_file_extend(struct inode *inode)
+int hfsplus_file_extend(struct inode *inode, bool zeroout)
 {
 	struct super_block *sb = inode->i_sb;
 	struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
@@ -463,6 +463,12 @@ int hfsplus_file_extend(struct inode *inode)
 		}
 	}
 
+	if (zeroout) {
+		res = sb_issue_zeroout(sb, start, len, GFP_NOFS);
+		if (res)
+			goto out;
+	}
+
 	hfs_dbg(EXTENT, "extend %lu: %u,%u\n", inode->i_ino, start, len);
 
 	if (hip->alloc_blocks <= hip->first_blocks) {
fs/hfsplus/hfsplus_fs.h +2 -1
index 83dc292..3c872b2 100644
@@ -417,6 +417,7 @@ void hfs_bnode_free(struct hfs_bnode *);
 struct hfs_bnode *hfs_bnode_create(struct hfs_btree *, u32);
 void hfs_bnode_get(struct hfs_bnode *);
 void hfs_bnode_put(struct hfs_bnode *);
+bool hfs_bnode_need_zeroout(struct hfs_btree *);
 
 /* brec.c */
 u16 hfs_brec_lenoff(struct hfs_bnode *, u16, u16 *);
@@ -463,7 +464,7 @@ int hfsplus_ext_write_extent(struct inode *);
 int hfsplus_get_block(struct inode *, sector_t, struct buffer_head *, int);
 int hfsplus_free_fork(struct super_block *, u32,
 		struct hfsplus_fork_raw *, int);
-int hfsplus_file_extend(struct inode *);
+int hfsplus_file_extend(struct inode *, bool zeroout);
 void hfsplus_file_truncate(struct inode *);
 
 /* inode.c */
fs/hfsplus/hfsplus_raw.h +1 -0
index 5a12682..8298d09 100644
@@ -144,6 +144,7 @@ struct hfsplus_vh {
 #define HFSPLUS_VOL_NODEID_REUSED	(1 << 12)
 #define HFSPLUS_VOL_JOURNALED		(1 << 13)
 #define HFSPLUS_VOL_SOFTLOCK		(1 << 15)
+#define HFSPLUS_VOL_UNUSED_NODE_FIX	(1 << 31)
 
 /* HFS+ BTree node descriptor */
 struct hfs_bnode_desc {
fs/hfsplus/xattr.c +1 -1
index 4e27edc..1ed05d0 100644
@@ -195,7 +195,7 @@ check_attr_tree_state_again:
 	}
 
 	while (hip->alloc_blocks < hip->clump_blocks) {
-		err = hfsplus_file_extend(attr_file);
+		err = hfsplus_file_extend(attr_file, false);
 		if (unlikely(err)) {
 			pr_err("failed to extend attributes file\n");
 			goto end_attr_file_creation;
Signature · 1 line
1.9.0
#1 lore raw

On Tue, 2014-05-20 at 19:44 +0200, Sergei Antonov wrote:

[snip]

fs/hfsplus/extents.c int hfsplus_file_extend(struct inode *inode) · line 467

Quoted 12 lines
fs/hfsplus/extents.c +3 -1
-int hfsplus_file_extend(struct inode *inode)
+int hfsplus_file_extend(struct inode *inode, bool zeroout)
 {
 	struct super_block *sb = inode->i_sb;
 	struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
@@ -463,6 +463,12 @@ int hfsplus_file_extend(struct inode *inode)
 		}
 	}
 
+	if (zeroout) {
+		res = sb_issue_zeroout(sb, start, len, GFP_NOFS);

As I can see, sb_issue_zeroout() initiate request for write. But previously the hfsplus_file_extend() operated by page cache only during file extending. From one point of view, we can fail during operation of file extending but, anyway, we will zero out blocks by means of writing.

Quoted 1 line

From another point of view, prepared pages are returned as tree's nodes

for filling by some data and, finally, it will be written on volume as a result of node creation.

So, I think that it makes sense to zero out namely prepared pages but not to initiate request for write via sb_issue_zeroout().

Quoted 20 lines
fs/hfsplus/extents.c +4 -0
+		if (res)
+			goto out;
+	}
+
 	hfs_dbg(EXTENT, "extend %lu: %u,%u\n", inode->i_ino, start, len);
 
 	if (hip->alloc_blocks <= hip->first_blocks) {
fs/hfsplus/hfsplus_fs.h +1 -0
index 83dc292..3c872b2 100644
@@ -417,6 +417,7 @@ void hfs_bnode_free(struct hfs_bnode *);
 struct hfs_bnode *hfs_bnode_create(struct hfs_btree *, u32);
 void hfs_bnode_get(struct hfs_bnode *);
 void hfs_bnode_put(struct hfs_bnode *);
+bool hfs_bnode_need_zeroout(struct hfs_btree *);
 
 /* brec.c */
 u16 hfs_brec_lenoff(struct hfs_bnode *, u16, u16 *);

fs/hfsplus/hfsplus_fs.h int hfsplus_ext_write_extent(struct inode *); · line 467

Quoted 5 lines
fs/hfsplus/hfsplus_fs.h +1 -1
@@ -463,7 +464,7 @@ int hfsplus_ext_write_extent(struct inode *);
 int hfsplus_get_block(struct inode *, sector_t, struct buffer_head *, int);
 int hfsplus_free_fork(struct super_block *, u32,
 		struct hfsplus_fork_raw *, int);
-int hfsplus_file_extend(struct inode *);
+int hfsplus_file_extend(struct inode *, bool zeroout);

I think that it doesn't make sense to keep name of second argument here.

Thanks,
Vyacheslav Dubeyko.

#2 lore raw
Quoted 13 lines · Vyacheslav Dubeyko

On Tue, 2014-05-20 at 19:44 +0200, Sergei Antonov wrote:

[snip]

Quoted 10 lines
fs/hfsplus/extents.c +1 -1
-int hfsplus_file_extend(struct inode *inode)
+int hfsplus_file_extend(struct inode *inode, bool zeroout)
 {
      struct super_block *sb = inode->i_sb;
      struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
@@ -463,6 +463,12 @@ int hfsplus_file_extend(struct inode *inode)
              }
      }
 
Quoted 7 lines

fs/hfsplus/extents.c int hfsplus_file_extend(struct inode *inode) · line 467

Quoted 2 lines
fs/hfsplus/extents.c +2 -0
+     if (zeroout) {
+             res = sb_issue_zeroout(sb, start, len, GFP_NOFS);

As I can see, sb_issue_zeroout() initiate request for write. But previously the hfsplus_file_extend() operated by page cache only during file extending. From one point of view, we can fail during operation of file extending but, anyway, we will zero out blocks by means of writing.

Which is not bad. Those blocks are free space.

Quoted 3 lines

From another point of view, prepared pages are returned as tree's nodes for filling by some data and, finally, it will be written on volume as a result of node creation.

A result of node creation is only 1 node, but catalog file is expanded in clumps. Normally a clump is at least several megabytes. So the task is to zero these megabytes on disk before (or immediately after) the new extent is added to the catalog.

Quoted 2 lines

So, I think that it makes sense to zero out namely prepared pages but not to initiate request for write via sb_issue_zeroout().

You mean mapping pages, do memset(,0,) and flushing them? Slower, memory consuming, complicated.

Quoted 17 lines
Quoted 17 lines
fs/hfsplus/extents.c +4 -0
+             if (res)
+                     goto out;
+     }
+
      hfs_dbg(EXTENT, "extend %lu: %u,%u\n", inode->i_ino, start, len);
 
      if (hip->alloc_blocks <= hip->first_blocks) {
fs/hfsplus/hfsplus_fs.h +1 -0
index 83dc292..3c872b2 100644
@@ -417,6 +417,7 @@ void hfs_bnode_free(struct hfs_bnode *);
 struct hfs_bnode *hfs_bnode_create(struct hfs_btree *, u32);
 void hfs_bnode_get(struct hfs_bnode *);
 void hfs_bnode_put(struct hfs_bnode *);
+bool hfs_bnode_need_zeroout(struct hfs_btree *);
 
Quoted 10 lines

fs/hfsplus/hfsplus_fs.h int hfsplus_ext_write_extent(struct inode *); · line 467

Quoted 8 lines
fs/hfsplus/hfsplus_fs.h +1 -1
 /* brec.c */
 u16 hfs_brec_lenoff(struct hfs_bnode *, u16, u16 *);
@@ -463,7 +464,7 @@ int hfsplus_ext_write_extent(struct inode *);
 int hfsplus_get_block(struct inode *, sector_t, struct buffer_head *, int);
 int hfsplus_free_fork(struct super_block *, u32,
              struct hfsplus_fork_raw *, int);
-int hfsplus_file_extend(struct inode *);
+int hfsplus_file_extend(struct inode *, bool zeroout);

I think that it doesn't make sense to keep name of second argument here.

Yes, for consistency with other prototypes.

#3 lore raw
Quoted 22 lines · Sergei Antonov
Quoted 13 lines · Vyacheslav Dubeyko

On Tue, 2014-05-20 at 19:44 +0200, Sergei Antonov wrote:

[snip]

Quoted 10 lines
fs/hfsplus/extents.c +1 -1
-int hfsplus_file_extend(struct inode *inode)
+int hfsplus_file_extend(struct inode *inode, bool zeroout)
 {
      struct super_block *sb = inode->i_sb;
      struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
@@ -463,6 +463,12 @@ int hfsplus_file_extend(struct inode *inode)
              }
      }
 
Quoted 7 lines

fs/hfsplus/extents.c int hfsplus_file_extend(struct inode *inode) · line 467

Quoted 2 lines
fs/hfsplus/extents.c +2 -0
+     if (zeroout) {
+             res = sb_issue_zeroout(sb, start, len, GFP_NOFS);

As I can see, sb_issue_zeroout() initiate request for write. But previously the hfsplus_file_extend() operated by page cache only during file extending. From one point of view, we can fail during operation of file extending but, anyway, we will zero out blocks by means of writing.

Quoted 2 lines

Which is not bad. Those blocks are free space.

For me personally, proper place for sb_issue_zeroout() can be in hfs_bmap_alloc() method
(http://lxr.free-electrons.com/source/fs/hfsplus/btree.c#L364):

        while (!tree->free_nodes) {
                struct inode *inode = tree->inode;
                struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
                u32 count;
                int res;

                res = hfsplus_file_extend(inode);
                if (res)
                        return ERR_PTR(res);

                /* here can be added sb_issue_zeroout() call */

                hip->phys_size = inode->i_size =
                        (loff_t)hip->alloc_blocks <<
                                HFSPLUS_SB(tree->sb)->alloc_blksz_shift;
                hip->fs_blocks =
                        hip->alloc_blocks << HFSPLUS_SB(tree->sb)->fs_shift;
                inode_set_bytes(inode, inode->i_size);
                count = inode->i_size >> tree->node_size_shift;
                tree->free_nodes = count - tree->node_count;
                tree->node_count = count;
        }

First of all, here we know that trying to extend file was successful. And, secondly, hfs_bmap_alloc() method is dedicated b-tree case only. I think that modification of hfsplus_file_extend() is not very good idea. The hfs_bmap_alloc() method is more clear solution, from my viewpoint.

Quoted 9 lines
Quoted 3 lines

From another point of view, prepared pages are returned as tree's nodes for filling by some data and, finally, it will be written on volume as a result of node creation.

A result of node creation is only 1 node, but catalog file is expanded in clumps. Normally a clump is at least several megabytes. So the task is to zero these megabytes on disk before (or immediately after) the new extent is added to the catalog.

Quoted 6 lines
Quoted 2 lines

So, I think that it makes sense to zero out namely prepared pages but not to initiate request for write via sb_issue_zeroout().

You mean mapping pages, do memset(,0,) and flushing them? Slower, memory consuming, complicated.

I worried here about consistency between block state and memory page state during a new node allocation. But as I can see __hfs_bnode_create() zero out memory page during node creation
(http://lxr.free-electrons.com/source/fs/hfsplus/bnode.c#L421). So, all should be OK.

Thanks,
Vyacheslav Dubeyko.

#4 lore raw
Quoted 54 lines · Vyacheslav Dubeyko
Quoted 22 lines · Sergei Antonov
Quoted 13 lines · Vyacheslav Dubeyko

On Tue, 2014-05-20 at 19:44 +0200, Sergei Antonov wrote:

[snip]

Quoted 10 lines
fs/hfsplus/extents.c +1 -1
-int hfsplus_file_extend(struct inode *inode)
+int hfsplus_file_extend(struct inode *inode, bool zeroout)
 {
      struct super_block *sb = inode->i_sb;
      struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
@@ -463,6 +463,12 @@ int hfsplus_file_extend(struct inode *inode)
              }
      }
 
Quoted 7 lines

fs/hfsplus/extents.c int hfsplus_file_extend(struct inode *inode) · line 467

Quoted 2 lines
fs/hfsplus/extents.c +2 -0
+     if (zeroout) {
+             res = sb_issue_zeroout(sb, start, len, GFP_NOFS);

As I can see, sb_issue_zeroout() initiate request for write. But previously the hfsplus_file_extend() operated by page cache only during file extending. From one point of view, we can fail during operation of file extending but, anyway, we will zero out blocks by means of writing.

Quoted 2 lines

Which is not bad. Those blocks are free space.

For me personally, proper place for sb_issue_zeroout() can be in hfs_bmap_alloc() method
(http://lxr.free-electrons.com/source/fs/hfsplus/btree.c#L364):

        while (!tree->free_nodes) {
                struct inode *inode = tree->inode;
                struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
                u32 count;
                int res;

                res = hfsplus_file_extend(inode);
                if (res)
                        return ERR_PTR(res);

                /* here can be added sb_issue_zeroout() call */

                hip->phys_size = inode->i_size =
                        (loff_t)hip->alloc_blocks <<
                                HFSPLUS_SB(tree->sb)->alloc_blksz_shift;
                hip->fs_blocks =
                        hip->alloc_blocks << HFSPLUS_SB(tree->sb)->fs_shift;
                inode_set_bytes(inode, inode->i_size);
                count = inode->i_size >> tree->node_size_shift;
                tree->free_nodes = count - tree->node_count;
                tree->node_count = count;
        }
Quoted 5 lines

First of all, here we know that trying to extend file was successful. And, secondly, hfs_bmap_alloc() method is dedicated b-tree case only. I think that modification of hfsplus_file_extend() is not very good idea. The hfs_bmap_alloc() method is more clear solution, from my viewpoint.

hfs_bmap_alloc() does not know about volume blocks. It is on a higher level of abstraction. Try, as an experiment, to write a call to sb_issue_zeroout() passing correct arguments from hfs_bmap_alloc().

Quoted 26 lines
Quoted 9 lines
Quoted 3 lines

From another point of view, prepared pages are returned as tree's nodes for filling by some data and, finally, it will be written on volume as a result of node creation.

A result of node creation is only 1 node, but catalog file is expanded in clumps. Normally a clump is at least several megabytes. So the task is to zero these megabytes on disk before (or immediately after) the new extent is added to the catalog.

Quoted 6 lines
Quoted 2 lines

So, I think that it makes sense to zero out namely prepared pages but not to initiate request for write via sb_issue_zeroout().

You mean mapping pages, do memset(,0,) and flushing them? Slower, memory consuming, complicated.

I worried here about consistency between block state and memory page state during a new node allocation. But as I can see __hfs_bnode_create() zero out memory page during node creation
(http://lxr.free-electrons.com/source/fs/hfsplus/bnode.c#L421). So, all should be OK.

Thanks,
Vyacheslav Dubeyko.

#5 lore raw
Quoted 61 lines · Sergei Antonov
Quoted 54 lines · Vyacheslav Dubeyko
Quoted 22 lines · Sergei Antonov
Quoted 13 lines · Vyacheslav Dubeyko

On Tue, 2014-05-20 at 19:44 +0200, Sergei Antonov wrote:

[snip]

Quoted 10 lines
fs/hfsplus/extents.c +1 -1
-int hfsplus_file_extend(struct inode *inode)
+int hfsplus_file_extend(struct inode *inode, bool zeroout)
 {
      struct super_block *sb = inode->i_sb;
      struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
@@ -463,6 +463,12 @@ int hfsplus_file_extend(struct inode *inode)
              }
      }
 
Quoted 7 lines

fs/hfsplus/extents.c int hfsplus_file_extend(struct inode *inode) · line 467

Quoted 2 lines
fs/hfsplus/extents.c +2 -0
+     if (zeroout) {
+             res = sb_issue_zeroout(sb, start, len, GFP_NOFS);

As I can see, sb_issue_zeroout() initiate request for write. But previously the hfsplus_file_extend() operated by page cache only during file extending. From one point of view, we can fail during operation of file extending but, anyway, we will zero out blocks by means of writing.

Quoted 2 lines

Which is not bad. Those blocks are free space.

For me personally, proper place for sb_issue_zeroout() can be in hfs_bmap_alloc() method
(http://lxr.free-electrons.com/source/fs/hfsplus/btree.c#L364):

        while (!tree->free_nodes) {
                struct inode *inode = tree->inode;
                struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
                u32 count;
                int res;

                res = hfsplus_file_extend(inode);
                if (res)
                        return ERR_PTR(res);

                /* here can be added sb_issue_zeroout() call */

                hip->phys_size = inode->i_size =
                        (loff_t)hip->alloc_blocks <<
                                HFSPLUS_SB(tree->sb)->alloc_blksz_shift;
                hip->fs_blocks =
                        hip->alloc_blocks << HFSPLUS_SB(tree->sb)->fs_shift;
                inode_set_bytes(inode, inode->i_size);
                count = inode->i_size >> tree->node_size_shift;
                tree->free_nodes = count - tree->node_count;
                tree->node_count = count;
        }
Quoted 5 lines

First of all, here we know that trying to extend file was successful. And, secondly, hfs_bmap_alloc() method is dedicated b-tree case only. I think that modification of hfsplus_file_extend() is not very good idea. The hfs_bmap_alloc() method is more clear solution, from my viewpoint.

Quoted 4 lines

hfs_bmap_alloc() does not know about volume blocks. It is on a higher level of abstraction. Try, as an experiment, to write a call to sb_issue_zeroout() passing correct arguments from hfs_bmap_alloc().

The hfs_bmap_alloc() has pointer on hfsplus_inode_info structure of btree's inode. The hfsplus_inode_info structure contains hip->first_extents, hip->first_blocks, hip->cached_extents, hip->cached_blocks and so on fields. Finally, hfsplus_file_extend() method stores allocated extent in hip->first_extents or in hip->cached_extents. So, I don't see anything impossible in calling sb_issue_zeroout() with correct arguments from hfs_bmap_alloc(). Maybe only to call sb_issue_zeroout() from hfsplus_file_extend() is more easy way. But I think that placement this logic in hfs_bmap_alloc() is more correct way, from architecture point of view.

Thanks,
Vyacheslav Dubeyko.

#6 lore raw
Quoted 67 lines · Vyacheslav Dubeyko
Quoted 61 lines · Sergei Antonov
Quoted 54 lines · Vyacheslav Dubeyko
Quoted 22 lines · Sergei Antonov
Quoted 13 lines · Vyacheslav Dubeyko

On Tue, 2014-05-20 at 19:44 +0200, Sergei Antonov wrote:

[snip]

Quoted 10 lines
fs/hfsplus/extents.c +1 -1
-int hfsplus_file_extend(struct inode *inode)
+int hfsplus_file_extend(struct inode *inode, bool zeroout)
 {
      struct super_block *sb = inode->i_sb;
      struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
@@ -463,6 +463,12 @@ int hfsplus_file_extend(struct inode *inode)
              }
      }
 
Quoted 7 lines

fs/hfsplus/extents.c int hfsplus_file_extend(struct inode *inode) · line 467

Quoted 2 lines
fs/hfsplus/extents.c +2 -0
+     if (zeroout) {
+             res = sb_issue_zeroout(sb, start, len, GFP_NOFS);

As I can see, sb_issue_zeroout() initiate request for write. But previously the hfsplus_file_extend() operated by page cache only during file extending. From one point of view, we can fail during operation of file extending but, anyway, we will zero out blocks by means of writing.

Quoted 2 lines

Which is not bad. Those blocks are free space.

For me personally, proper place for sb_issue_zeroout() can be in hfs_bmap_alloc() method
(http://lxr.free-electrons.com/source/fs/hfsplus/btree.c#L364):

        while (!tree->free_nodes) {
                struct inode *inode = tree->inode;
                struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
                u32 count;
                int res;

                res = hfsplus_file_extend(inode);
                if (res)
                        return ERR_PTR(res);

                /* here can be added sb_issue_zeroout() call */

                hip->phys_size = inode->i_size =
                        (loff_t)hip->alloc_blocks <<
                                HFSPLUS_SB(tree->sb)->alloc_blksz_shift;
                hip->fs_blocks =
                        hip->alloc_blocks << HFSPLUS_SB(tree->sb)->fs_shift;
                inode_set_bytes(inode, inode->i_size);
                count = inode->i_size >> tree->node_size_shift;
                tree->free_nodes = count - tree->node_count;
                tree->node_count = count;
        }
Quoted 5 lines

First of all, here we know that trying to extend file was successful. And, secondly, hfs_bmap_alloc() method is dedicated b-tree case only. I think that modification of hfsplus_file_extend() is not very good idea. The hfs_bmap_alloc() method is more clear solution, from my viewpoint.

Quoted 4 lines

hfs_bmap_alloc() does not know about volume blocks. It is on a higher level of abstraction. Try, as an experiment, to write a call to sb_issue_zeroout() passing correct arguments from hfs_bmap_alloc().

Quoted 6 lines

The hfs_bmap_alloc() has pointer on hfsplus_inode_info structure of btree's inode. The hfsplus_inode_info structure contains hip->first_extents, hip->first_blocks, hip->cached_extents, hip->cached_blocks and so on fields. Finally, hfsplus_file_extend() method stores allocated extent in hip->first_extents or in hip->cached_extents.

Yo-ho! What a ride!

Quoted 2 lines

So, I don't see anything impossible in calling sb_issue_zeroout() with correct arguments from hfs_bmap_alloc().

And you seem to like riding.

Quoted 4 lines

Maybe
only to call sb_issue_zeroout() from hfsplus_file_extend() is more easy way. But I think that placement this logic in hfs_bmap_alloc() is more correct way, from architecture point of view.

It is nasty from an architectural point of view for reasons provided earlier. hfsplus_file_extend() is volume blocks level and that's what one needs for sb_issue_*.