linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: tytso@mit.edu, darrick.wong@oracle.com
Cc: linux-ext4@vger.kernel.org
Subject: [PATCH 02/14] undo-io: write out index block after every write
Date: Wed, 13 May 2015 17:21:21 -0700	[thread overview]
Message-ID: <20150514002121.10785.38168.stgit@birch.djwong.org> (raw)
In-Reply-To: <20150514002108.10785.85860.stgit@birch.djwong.org>

Write out the undo file's index block after writing a block to the
undo file.  This ensures that we always have a consistent undo file
in the page cache, even if the program crashes.  When we fill up a
key block in the undo file, we'll call fsync to force the whole
thing to storage; this should happen about every 256 blocks given
the usual 4K block size.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 lib/ext2fs/undo_io.c |   47 ++++++++++++++++++++++-------------------------
 1 file changed, 22 insertions(+), 25 deletions(-)


diff --git a/lib/ext2fs/undo_io.c b/lib/ext2fs/undo_io.c
index 4a48193..b9294c3 100644
--- a/lib/ext2fs/undo_io.c
+++ b/lib/ext2fs/undo_io.c
@@ -165,7 +165,7 @@ errcode_t set_undo_io_backup_file(char *file_name)
 	return 0;
 }
 
-static errcode_t write_undo_indexes(struct undo_private_data *data)
+static errcode_t write_undo_indexes(struct undo_private_data *data, int flush)
 {
 	errcode_t retval;
 	struct ext2_super_block super;
@@ -187,9 +187,14 @@ static errcode_t write_undo_indexes(struct undo_private_data *data)
 						1, data->keyb);
 		if (retval)
 			return retval;
-		memset(data->keyb, 0, data->tdb_data_size);
-		data->keys_in_block = 0;
-		data->key_blk_num = data->undo_blk_num;
+		/* Move on to the next key block if it's full. */
+		if (data->keys_in_block == KEYS_PER_BLOCK(data)) {
+			memset(data->keyb, 0, data->tdb_data_size);
+			data->keys_in_block = 0;
+			data->key_blk_num = data->undo_blk_num;
+			data->undo_blk_num++;
+			flush = 1;
+		}
 	}
 
 	/* Prepare superblock for write */
@@ -230,7 +235,8 @@ static errcode_t write_undo_indexes(struct undo_private_data *data)
 	if (retval)
 		goto err_out;
 
-	retval = io_channel_flush(data->undo_file);
+	if (flush)
+		retval = io_channel_flush(data->undo_file);
 err_out:
 	io_channel_set_blksize(channel, block_size);
 	return retval;
@@ -261,7 +267,7 @@ static errcode_t undo_setup_tdb(struct undo_private_data *data)
 	retval = ext2fs_get_mem(data->tdb_data_size, &data->keyb);
 	if (retval)
 		return retval;
-	data->key_blk_num = data->undo_blk_num;
+	data->key_blk_num = data->first_key_blk;
 
 	/* Record block size */
 	dbg_printf("Undo block size %llu\n", data->tdb_data_size);
@@ -348,22 +354,6 @@ static errcode_t undo_write_tdb(io_channel channel,
 		}
 		ext2fs_mark_block_bitmap2(data->written_block_map, block_num);
 
-		/* Spit out a key block */
-		if (data->keys_in_block == KEYS_PER_BLOCK(data)) {
-			retval = write_undo_indexes(data);
-			if (retval)
-				return retval;
-			retval = io_channel_write_blk64(data->undo_file,
-							data->key_blk_num, 1,
-							data->keyb);
-			if (retval)
-				return retval;
-		}
-
-		/* Allocate new key block */
-		if (data->keys_in_block == 0)
-			data->undo_blk_num++;
-
 		/*
 		 * Read one block using the backing I/O manager
 		 * The backing I/O manager block size may be
@@ -458,6 +448,12 @@ static errcode_t undo_write_tdb(io_channel channel,
 		}
 		data->undo_blk_num++;
 		free(read_ptr);
+
+		/* Write out the key block */
+		retval = write_undo_indexes(data, 0);
+		if (retval)
+			return retval;
+
 		/* Next block */
 		block_num++;
 	}
@@ -668,7 +664,7 @@ static void undo_atexit(void *p)
 	struct undo_private_data *data = p;
 	errcode_t err;
 
-	err = write_undo_indexes(data);
+	err = write_undo_indexes(data, 1);
 	io_channel_close(data->undo_file);
 
 	com_err(data->tdb_file, err, "while force-closing undo file");
@@ -707,7 +703,8 @@ static errcode_t undo_open(const char *name, int flags, io_channel *channel)
 	memset(data, 0, sizeof(struct undo_private_data));
 	data->magic = EXT2_ET_MAGIC_UNIX_IO_CHANNEL;
 	data->super_blk_num = 1;
-	data->undo_blk_num = data->first_key_blk = 2;
+	data->first_key_blk = 2;
+	data->undo_blk_num = 3;
 
 	if (undo_io_backing_manager) {
 		retval = undo_io_backing_manager->open(name, flags,
@@ -789,7 +786,7 @@ static errcode_t undo_close(io_channel channel)
 	/* Before closing write the file system identity */
 	if (!getenv("UNDO_IO_SIMULATE_UNFINISHED"))
 		data->hdr.state = ext2fs_cpu_to_le32(E2UNDO_STATE_FINISHED);
-	err = write_undo_indexes(data);
+	err = write_undo_indexes(data, 1);
 	ext2fs_remove_exit_fn(undo_atexit, data);
 	if (data->real)
 		retval = io_channel_close(data->real);


  parent reply	other threads:[~2015-05-14  0:21 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-14  0:21 [PATCH 00/14] e2fsprogs May 2015 patchbomb Darrick J. Wong
2015-05-14  0:21 ` [PATCH 01/14] misc: fix Coverity bugs Darrick J. Wong
2015-05-16 22:36   ` Theodore Ts'o
2015-05-14  0:21 ` Darrick J. Wong [this message]
2015-05-17  0:18   ` [PATCH 02/14] undo-io: write out index block after every write Theodore Ts'o
2015-05-14  0:21 ` [PATCH 03/14] misc: fix undo file setup Darrick J. Wong
2015-05-17  0:20   ` Theodore Ts'o
2015-05-14  0:21 ` [PATCH 04/14] filefrag: fix broken extent emulation and uninitialized variables Darrick J. Wong
2015-05-17  0:26   ` Theodore Ts'o
2015-05-14  0:21 ` [PATCH 05/14] e2fsck: fix buffer overrun in revoke block scanning Darrick J. Wong
2015-05-14 19:37   ` [PATCH v2 " Darrick J. Wong
2015-05-17  0:50     ` Theodore Ts'o
2015-05-14  0:21 ` [PATCH 06/14] e2fsck: convert block-mapped files to extents on bigalloc fs Darrick J. Wong
2015-05-17  0:51   ` Theodore Ts'o
2015-05-14  0:21 ` [PATCH 07/14] libext2fs: support allocating uninit blocks in bmap2() Darrick J. Wong
2015-05-17  0:54   ` Theodore Ts'o
2015-05-14  0:22 ` [PATCH 08/14] libext2fs: find/alloc a range of empty blocks Darrick J. Wong
2015-05-17  1:02   ` Theodore Ts'o
2015-05-14  0:22 ` [PATCH 09/14] libext2fs: add new hooks to support large allocations Darrick J. Wong
2015-06-11  0:08   ` Theodore Ts'o
2015-05-14  0:22 ` [PATCH 10/14] libext2fs: implement fallocate Darrick J. Wong
2015-06-11  0:09   ` Theodore Ts'o
2015-05-14  0:22 ` [PATCH 11/14] libext2fs: use fallocate for creating journals and hugefiles Darrick J. Wong
2015-05-17  3:39   ` Theodore Ts'o
2015-05-18 19:24     ` Darrick J. Wong
2015-05-18 21:18   ` [PATCH v2 " Darrick J. Wong
2015-06-11  0:12     ` Theodore Ts'o
2015-05-14  0:22 ` [PATCH 12/14] debugfs: implement fallocate Darrick J. Wong
2015-06-11  0:12   ` Theodore Ts'o
2015-05-14  0:22 ` [PATCH 13/14] tests: test debugfs punch command Darrick J. Wong
2015-06-11  0:13   ` Theodore Ts'o
2015-05-18 21:17 ` [PATCH 15/14] libext2fs: remove unnecessary undo file flush calls Darrick J. Wong
2015-06-11  0:13   ` Theodore Ts'o
2015-06-05  1:38 ` [PATCH 16/14] libext2fs: require the inline data xattr on all inline data files Darrick J. Wong
2015-06-11  0:15   ` Theodore Ts'o
2015-07-23 21:12     ` Darrick J. Wong
     [not found] ` <20150514002240.10785.35238.stgit@birch.djwong.org>
2015-06-11  0:13   ` [PATCH 14/14] misc: add fuse2fs, a FUSE server for e2fsprogs (v4.3) Theodore Ts'o
2015-06-15 18:37     ` Darrick J. Wong
2015-06-15 19:21       ` Theodore Ts'o

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=20150514002121.10785.38168.stgit@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).