All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: tytso@mit.edu
Cc: linux-ext4@vger.kernel.org
Subject: [PATCH 26/25] libext2fs: call get_alloc_block hook when allocating blocks
Date: Thu, 11 Sep 2014 12:41:53 -0700	[thread overview]
Message-ID: <20140911194153.GR10351@birch.djwong.org> (raw)
In-Reply-To: <20140908231135.25904.66591.stgit@birch.djwong.org>

If a libext2fs client has provided a get_alloc_block hook, we need to
ensure that all code paths in the library use it to allocate blocks.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 lib/ext2fs/bb_inode.c    |   11 ++++++++++-
 lib/ext2fs/expanddir.c   |    3 +--
 lib/ext2fs/inline_data.c |    7 ++++---
 lib/ext2fs/mkdir.c       |    5 ++++-
 lib/ext2fs/mkjournal.c   |    5 ++++-
 lib/ext2fs/symlink.c     |    5 ++++-
 6 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/lib/ext2fs/bb_inode.c b/lib/ext2fs/bb_inode.c
index b0e114b..d659bb9 100644
--- a/lib/ext2fs/bb_inode.c
+++ b/lib/ext2fs/bb_inode.c
@@ -219,6 +219,7 @@ static int set_bad_block_proc(ext2_filsys fs, blk_t *block_nr,
 		priv_data;
 	errcode_t	retval;
 	blk_t		blk;
+	blk64_t		blk2;
 
 	if (blockcnt >= 0) {
 		/*
@@ -241,7 +242,15 @@ static int set_bad_block_proc(ext2_filsys fs, blk_t *block_nr,
 			if (ext2fs_test_block_bitmap2(fs->block_map, blk))
 				goto retry;
 		} else {
-			retval = ext2fs_new_block(fs, 0, 0, &blk);
+			if (fs->get_alloc_block) {
+				retval = fs->get_alloc_block(fs, 0, &blk2);
+				if (!retval && (blk2 >> 32)) {
+					rec->err = EOVERFLOW;
+					return BLOCK_ABORT;
+				}
+				blk = blk2;
+			} else
+				retval = ext2fs_new_block(fs, 0, 0, &blk);
 			if (retval) {
 				rec->err = retval;
 				return BLOCK_ABORT;
diff --git a/lib/ext2fs/expanddir.c b/lib/ext2fs/expanddir.c
index d0f7287..f412923 100644
--- a/lib/ext2fs/expanddir.c
+++ b/lib/ext2fs/expanddir.c
@@ -50,13 +50,12 @@ static int expand_dir_proc(ext2_filsys	fs,
 		new_blk = es->goal+1;
 	else {
 		es->goal &= ~EXT2FS_CLUSTER_MASK(fs);
-		retval = ext2fs_new_block2(fs, es->goal, 0, &new_blk);
+		retval = ext2fs_alloc_block2(fs, es->goal, NULL, &new_blk);
 		if (retval) {
 			es->err = retval;
 			return BLOCK_ABORT;
 		}
 		es->newblocks++;
-		ext2fs_block_alloc_stats2(fs, new_blk, +1);
 	}
 	if (blockcnt > 0) {
 		retval = ext2fs_new_dir_block(fs, 0, 0, &block);
diff --git a/lib/ext2fs/inline_data.c b/lib/ext2fs/inline_data.c
index 7eb8b94..7a6c721 100644
--- a/lib/ext2fs/inline_data.c
+++ b/lib/ext2fs/inline_data.c
@@ -357,7 +357,7 @@ ext2fs_inline_data_dir_expand(ext2_filsys fs, ext2_ino_t ino,
 			      struct ext2_inode *inode, char *buf, size_t size)
 {
 	errcode_t retval;
-	blk64_t blk;
+	blk64_t blk = 0;
 	char *blk_buf;
 
 	retval = ext2fs_get_memzero(fs->blocksize, &blk_buf);
@@ -376,7 +376,7 @@ ext2fs_inline_data_dir_expand(ext2_filsys fs, ext2_ino_t ino,
 	if (retval)
 		goto errout;
 	/* Allocate a new block */
-	retval = ext2fs_new_block2(fs, 0, 0, &blk);
+	retval = ext2fs_alloc_block2(fs, 0, NULL, &blk);
 	if (retval)
 		goto errout;
 	retval = ext2fs_write_dir_block4(fs, blk, blk_buf, 0, ino);
@@ -397,9 +397,10 @@ ext2fs_inline_data_dir_expand(ext2_filsys fs, ext2_ino_t ino,
 	retval = ext2fs_write_inode(fs, ino, inode);
 	if (retval)
 		goto errout;
-	ext2fs_block_alloc_stats(fs, blk, +1);
 
 errout:
+	if (retval && blk)
+		ext2fs_block_alloc_stats(fs, blk, -1);
 	ext2fs_free_mem(&blk_buf);
 	return retval;
 }
diff --git a/lib/ext2fs/mkdir.c b/lib/ext2fs/mkdir.c
index c4c7967..a184129 100644
--- a/lib/ext2fs/mkdir.c
+++ b/lib/ext2fs/mkdir.c
@@ -69,7 +69,10 @@ errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum,
 	 * Allocate a data block for the directory
 	 */
 	if (!inline_data) {
-		retval = ext2fs_new_block2(fs, 0, 0, &blk);
+		if (fs->get_alloc_block)
+			retval = fs->get_alloc_block(fs, 0, &blk);
+		else
+			retval = ext2fs_new_block2(fs, 0, 0, &blk);
 		if (retval)
 			goto cleanup;
 	}
diff --git a/lib/ext2fs/mkjournal.c b/lib/ext2fs/mkjournal.c
index 0a7cd18..f9cec4e 100644
--- a/lib/ext2fs/mkjournal.c
+++ b/lib/ext2fs/mkjournal.c
@@ -242,7 +242,10 @@ static int mkjournal_proc(ext2_filsys	fs,
 		new_blk = es->goal+1;
 	else {
 		es->goal &= ~EXT2FS_CLUSTER_MASK(fs);
-		retval = ext2fs_new_block2(fs, es->goal, 0, &new_blk);
+		if (fs->get_alloc_block)
+			retval = fs->get_alloc_block(fs, es->goal, &new_blk);
+		else
+			retval = ext2fs_new_block2(fs, es->goal, 0, &new_blk);
 		if (retval) {
 			es->err = retval;
 			return BLOCK_ABORT;
diff --git a/lib/ext2fs/symlink.c b/lib/ext2fs/symlink.c
index f6eb6b6..b361e02 100644
--- a/lib/ext2fs/symlink.c
+++ b/lib/ext2fs/symlink.c
@@ -53,7 +53,10 @@ errcode_t ext2fs_symlink(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t ino,
 	 */
 	fastlink = (target_len < sizeof(inode.i_block));
 	if (!fastlink) {
-		retval = ext2fs_new_block2(fs, 0, 0, &blk);
+		if (fs->get_alloc_block)
+			retval = fs->get_alloc_block(fs, 0, &blk);
+		else
+			retval = ext2fs_new_block2(fs, 0, 0, &blk);
 		if (retval)
 			goto cleanup;
 		retval = ext2fs_get_mem(fs->blocksize, &block_buf);

  parent reply	other threads:[~2014-09-11 19:41 UTC|newest]

Thread overview: 81+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-08 23:11 [PATCH 00/25] e2fsprogs Summer 2014 patchbomb, part 5.2 Darrick J. Wong
2014-09-08 23:11 ` [PATCH 01/25] e2fsck/debugfs: fix descriptor block size handling errors with journal_csum Darrick J. Wong
2014-09-11 16:43   ` Theodore Ts'o
2014-09-08 23:11 ` [PATCH 02/25] libext2fs: report bad magic over bad sb checksum Darrick J. Wong
2014-09-11 16:43   ` Theodore Ts'o
2014-09-08 23:11 ` [PATCH 03/25] misc: don't return ENOMEM if we run out of disk space Darrick J. Wong
2014-09-11 16:43   ` Theodore Ts'o
2014-09-08 23:12 ` [PATCH 04/25] libext2fs: write_journal_inode should check iterate return value Darrick J. Wong
2014-09-11 16:43   ` Theodore Ts'o
2014-09-08 23:12 ` [PATCH 05/25] mke2fs: allow creation of journal device with superblock checksum Darrick J. Wong
2014-09-11 16:43   ` Theodore Ts'o
2014-09-08 23:12 ` [PATCH 06/25] e2fsck: detect and repair external journal superblock checksum errors Darrick J. Wong
2014-09-11 16:43   ` Theodore Ts'o
2014-09-08 23:12 ` [PATCH 07/25] tune2fs: explicitly disallow tuning of journal devices Darrick J. Wong
2014-09-11 16:44   ` Theodore Ts'o
2014-09-08 23:12 ` [PATCH 08/25] dumpe2fs: display external journal feature flags Darrick J. Wong
2014-09-11 16:44   ` Theodore Ts'o
2014-09-08 23:12 ` [PATCH 09/25] misc: zero s_jnl_blocks when removing internal journal Darrick J. Wong
2014-09-11 16:44   ` Theodore Ts'o
2014-09-08 23:12 ` [PATCH 10/25] debugfs: create journal handling routines Darrick J. Wong
2014-09-11 18:53   ` Theodore Ts'o
2014-09-11 19:03     ` Darrick J. Wong
2014-09-11 20:14       ` Theodore Ts'o
2014-09-11 20:25         ` Darrick J. Wong
2014-09-08 23:12 ` [PATCH 11/25] e2fsck: fix minor errors in journal handling Darrick J. Wong
2014-09-11 20:58   ` Theodore Ts'o
2014-09-08 23:12 ` [PATCH 12/25] debugfs: add the ability to write transactions to the journal Darrick J. Wong
2014-09-11 20:58   ` Theodore Ts'o
2014-09-08 23:13 ` [PATCH 13/25] tests: test writing and recovering checksum-free 32/64bit journals Darrick J. Wong
2014-09-11 20:59   ` Theodore Ts'o
2014-09-08 23:13 ` [PATCH 14/25] tests: test writing and recovering 64bit csum_v3 journals Darrick J. Wong
2014-09-11 20:59   ` Theodore Ts'o
2014-09-08 23:13 ` [PATCH 15/25] tests: test writing and recovering 32bit " Darrick J. Wong
2014-09-11 20:59   ` Theodore Ts'o
2014-09-08 23:13 ` [PATCH 16/25] tests: write and replay blocks with the old journal checksum Darrick J. Wong
2014-09-11 20:59   ` Theodore Ts'o
2014-09-08 23:13 ` [PATCH 17/25] tests: test recovery of 32 and 64-bit journals with checksum v2 Darrick J. Wong
2014-09-11 20:59   ` Theodore Ts'o
2014-09-08 23:13 ` [PATCH 18/25] tests: test how e2fsck recovers from corrupt journal superblocks Darrick J. Wong
2014-09-11 21:04   ` Theodore Ts'o
2014-09-08 23:13 ` [PATCH 19/25] tests: test e2fsck recovery of corrupt revoke blocks Darrick J. Wong
2014-09-11 21:04   ` Theodore Ts'o
2014-09-08 23:13 ` [PATCH 20/25] tests: test e2fsck recovery with broken commit blocks Darrick J. Wong
2014-09-11 21:04   ` Theodore Ts'o
2014-09-08 23:13 ` [PATCH 21/25] tests: test e2fsck recovery of corrupt descriptor blocks Darrick J. Wong
2014-09-10  1:15   ` Darrick J. Wong
2014-09-11 17:33     ` Darrick J. Wong
2014-09-11 18:18       ` Theodore Ts'o
2014-09-11 18:40         ` Darrick J. Wong
2014-09-11 19:31   ` [PATCH 21/25 v2] " Darrick J. Wong
2014-09-11 22:34     ` Theodore Ts'o
2014-09-08 23:14 ` [PATCH 22/25] tests: test recovery from an external journal Darrick J. Wong
2014-09-11 21:04   ` Theodore Ts'o
2014-09-08 23:14 ` [PATCH 23/25] ext2fs: add readahead method to improve scanning Darrick J. Wong
2014-09-11 21:10   ` Theodore Ts'o
2014-09-11 21:29     ` [PATCH 23/25 v2] " Darrick J. Wong
2014-09-08 23:14 ` [PATCH 24/25] libext2fs/e2fsck: provide routines to read-ahead metadata Darrick J. Wong
2014-09-08 23:14 ` [PATCH 25/25] e2fsck: read-ahead metadata during passes 1, 2, and 4 Darrick J. Wong
2014-09-09 22:53 ` [PATCH 00/25] e2fsprogs Summer 2014 patchbomb, part 5.2 Andreas Dilger
2014-09-10  1:13   ` Darrick J. Wong
2014-09-11 19:41 ` Darrick J. Wong [this message]
2014-09-11 22:05   ` [PATCH 26/25] libext2fs: call get_alloc_block hook when allocating blocks Theodore Ts'o
2014-09-11 22:34     ` Darrick J. Wong
2014-09-12 17:35       ` Theodore Ts'o
2014-09-12 17:57         ` Darrick J. Wong
2014-09-12 22:17           ` Theodore Ts'o
2014-09-13  0:13             ` Darrick J. Wong
2014-09-11 19:43 ` [PATCH 27/25] tune2fs: always check disable_uninit_bg() return code Darrick J. Wong
2014-09-11 22:07   ` Theodore Ts'o
2014-09-11 19:44 ` [PATCH 28/25] e2fsck: ignore badblocks if it says badblocks inode is bad Darrick J. Wong
2014-09-11 22:09   ` Theodore Ts'o
2014-09-11 19:48 ` [PATCH 29/25] e2fsck: expand root dir if linking l+f fails Darrick J. Wong
2014-09-11 22:10   ` Theodore Ts'o
2014-09-11 20:17 ` [PATCH 30/25] libext2fs: check ea value offset when loading Darrick J. Wong
2014-09-11 22:11   ` Theodore Ts'o
2014-09-11 22:33 ` [PATCH 00/25] e2fsprogs Summer 2014 patchbomb, part 5.2 Theodore Ts'o
2014-09-11 22:50   ` Darrick J. Wong
2014-09-11 22:52     ` Theodore Ts'o
2014-09-11 23:07       ` Darrick J. Wong
2014-09-11 23:14         ` Theodore Ts'o
2014-09-11 23:30           ` Darrick J. Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140911194153.GR10351@birch.djwong.org \
    --to=darrick.wong@oracle.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.