mbox series

[v3,00/15] Fast commit changes for e2fsprogs

Message ID 20210120212641.526556-1-user@harshads-520.kir.corp.google.com
Headers show
Series Fast commit changes for e2fsprogs | expand

Message

harshad shirwadkar Jan. 20, 2021, 9:26 p.m. UTC
From: Harshad Shirwadkar <harshadshirwadkar@gmail.com>

This patch series adds fast commits support in e2fsprogs. This
includes fast commit recovery support in e2fsck and fast commit
configuration support in mke2fs and tune2fs. Along with that this
patch series also makes e2fsck/recovery.c identical with
jbd2/recovery.c in kernel. In addition, this patch imports and makes
fast_commit.h (the file that contains on-disk formats for fast
commits) byte identical with the kernel.

The recovery logic for fast commits follows the same steps as that of
the recovery logic in kernel. The general guidining principle for the
fast commit replay is that the individual tags found in fast commit
area store the result of the operation as their paylod instead of
storing the procedure itself. The recovery logic enforces this result
onto the filesystem thereby making the fast commit replay
idempotent. Unlike kernel, there's no atomic oepration support in
e2fsprogs yet. So, it's possible that we may crash while we are in the
middle of replaying of a fast commit tag. The only way to recover from
that situation would be to run fsck. That's why we mark the file
system as unclean before the fast commit replay and make it clean at
the end.

This series adds new regression test that performs fast commit
replay. I ensured that all the regressions tests pass.

Verified that all the tests pass:
367 tests succeeded     0 tests failed

New fast commit recovery test:
j_recover_fast_commit: ok

The patch series invalidates the initial version of the patch series
which was sent back in Mar 2020. Since then the fast commit code in
kernel has evolved a lot (including the on-disk format change). So,
this patch series is based on the new fast commit kernel code (which
is available in upstream kernel now). This patch series is a complete
revamp of the original series.

Changes Since V2:
----------------

- Fix compilation error by defining jbd2_journal_get_fc_num_blks (also
  rename it to jbd_get_fc_num_blks) as a preprocessor macro instead of
  inline function which gets compiled out when "-g" is passed

Harshad Shirwadkar (15):
  ext2fs: move calculate_summary_stats to ext2fs lib
  e2fsck: add kernel endian-ness conversion macros
  e2fsck: port fc changes from kernel's recovery.c to e2fsck
  libext2fs: provide APIs to configure fast commit blocks
  e2fsprogs: make userspace tools number of fast commits blocks aware
  ext2fs: add new APIs needed for fast commits
  e2fsck: add function to rewrite extent tree
  e2fsck: add fast commit setup code
  e2fsck: add fast commit scan pass
  e2fsck: add fast commit replay skeleton
  e2fsck: add fc replay for link, unlink, creat tags
  e2fsck: add replay for add_range, del_range, and inode tags
  debugfs: add fast commit support to logdump
  tests: add fast commit recovery tests
  ext4: fix tests to account for new dumpe2fs output

 debugfs/journal.c                       |  10 +-
 debugfs/logdump.c                       | 122 ++++-
 e2fsck/e2fsck.h                         |  32 ++
 e2fsck/extents.c                        | 168 +++---
 e2fsck/journal.c                        | 660 +++++++++++++++++++++++-
 e2fsck/recovery.c                       | 232 ++++++---
 e2fsck/unix.c                           |  26 +-
 lib/e2p/e2p.h                           |   1 +
 lib/e2p/ljs.c                           |  16 +-
 lib/ext2fs/ext2_fs.h                    |   1 +
 lib/ext2fs/ext2fs.h                     |  30 ++
 lib/ext2fs/extent.c                     |  63 +++
 lib/ext2fs/fast_commit.h                | 203 ++++++++
 lib/ext2fs/initialize.c                 |  94 ++++
 lib/ext2fs/jfs_compat.h                 |  25 +-
 lib/ext2fs/kernel-jbd.h                 |  16 +-
 lib/ext2fs/mkjournal.c                  |  96 +++-
 lib/ext2fs/unlink.c                     |   6 +-
 misc/dumpe2fs.c                         |  10 +-
 misc/mke2fs.8.in                        |  21 +
 misc/mke2fs.c                           |  26 +-
 misc/tune2fs.8.in                       |  25 +
 misc/tune2fs.c                          |  67 +--
 misc/util.c                             |  61 ++-
 misc/util.h                             |   4 +-
 resize/resize2fs.c                      |   6 +-
 tests/d_corrupt_journal_nr_users/expect |   6 +-
 tests/f_jnl_errno/expect.0              |   6 +-
 tests/f_opt_extent/expect               |   2 +-
 tests/i_bitmaps/expect                  |   8 +-
 tests/j_ext_dumpe2fs/expect             |   6 +-
 tests/j_recover_fast_commit/commands    |   4 +
 tests/j_recover_fast_commit/expect      |  23 +
 tests/j_recover_fast_commit/image.gz    | Bin 0 -> 3595 bytes
 tests/j_recover_fast_commit/script      |  26 +
 tests/m_bigjournal/expect.1             |   6 +-
 tests/m_extent_journal/expect.1         |   6 +-
 tests/m_resize_inode_meta_bg/expect.1   |   6 +-
 tests/m_rootdir/expect                  |   6 +-
 tests/r_32to64bit/expect                |   6 +-
 tests/r_32to64bit_meta/expect           |   4 +-
 tests/r_32to64bit_move_itable/expect    |   8 +-
 tests/r_64to32bit/expect                |   6 +-
 tests/r_64to32bit_meta/expect           |   4 +-
 tests/r_move_itable_nostride/expect     |   6 +-
 tests/r_move_itable_realloc/expect      |   6 +-
 tests/t_disable_mcsum/expect            |   4 +-
 tests/t_disable_mcsum_noinitbg/expect   |   6 +-
 tests/t_disable_mcsum_yesinitbg/expect  |   4 +-
 tests/t_enable_mcsum/expect             |   6 +-
 tests/t_enable_mcsum_ext3/expect        |  10 +-
 tests/t_enable_mcsum_initbg/expect      |   6 +-
 52 files changed, 1861 insertions(+), 341 deletions(-)
 create mode 100644 lib/ext2fs/fast_commit.h
 create mode 100644 tests/j_recover_fast_commit/commands
 create mode 100644 tests/j_recover_fast_commit/expect
 create mode 100644 tests/j_recover_fast_commit/image.gz
 create mode 100755 tests/j_recover_fast_commit/script

Comments

Theodore Ts'o Jan. 21, 2021, 5:22 a.m. UTC | #1
On Wed, Jan 20, 2021 at 01:26:26PM -0800, Harshad Shirwadkar wrote:
> 
> - Fix compilation error by defining jbd2_journal_get_fc_num_blks (also
>   rename it to jbd_get_fc_num_blks) as a preprocessor macro instead of
>   inline function which gets compiled out when "-g" is passed

Unfortunately, this still doesn't quite fix things.  The problem with
this approach is the preprocessor macro uses be32_to_cpu(), which gets
turned into ext2fs_swab32().  And the libe2p shared library is not
allowed to depend on libext2fs.  Otherwise when we build with
configure --enable-elf-shlibs, the link of misc/chattr fails with:

<tytso@cwcc> {/build/e2fsprogs/misc}  
1078% make V=1
../util/subst -f ../util/subst.conf /usr/projects/e2fsprogs/e2fsprogs/lib/dirpaths.h.in ../lib/dirpaths.h
gcc   -Wl,-rpath-link,../lib -o chattr chattr.o ../lib/libe2p.so ../lib/libcom_err.so  \
	 
/bin/ld: ../lib/libe2p.so: undefined reference to `ext2fs_swab32'
collect2: error: ld returned 1 exit status
make: *** [Makefile:636: chattr] Error 1

We had already defined e2p_be32() and use it in other places in
lib/e2p/ljs.c.

So I fixed this by taking your Dec 10th version of the patch series,
and making the following change to patch 4/15:

diff --git a/lib/e2p/ljs.c b/lib/e2p/ljs.c
index 9f866c7e..59728198 100644
--- a/lib/e2p/ljs.c
+++ b/lib/e2p/ljs.c
@@ -36,6 +36,17 @@ static __u32 e2p_swab32(__u32 val)
 #define e2p_be32(x) e2p_swab32(x)
 #endif
 
+/*
+ * This function is copied from kernel-jbd.h's function
+ * jbd2_journal_get_num_fc_blks() to avoid inter-library dependencies.
+ */
+static inline int get_num_fc_blks(journal_superblock_t *jsb)
+{
+	int num_fc_blocks = e2p_be32(jsb->s_num_fc_blks);
+
+	return num_fc_blocks ? num_fc_blocks : JBD2_DEFAULT_FAST_COMMIT_BLOCKS;
+}
+
 static const char *journal_checksum_type_str(__u8 type)
 {
 	switch (type) {
@@ -58,7 +69,7 @@ void e2p_list_journal_super(FILE *f, char *journal_sb_buf,
 	int journal_blks = 0;
 
 	if (flags & E2P_LIST_JOURNAL_FLAG_FC)
-		num_fc_blks = jbd2_journal_get_num_fc_blks((journal_superblock_t *)journal_sb_buf);
+		num_fc_blks = get_num_fc_blks((journal_superblock_t *)journal_sb_buf);
 	journal_blks = ntohl(jsb->s_maxlen) - num_fc_blks;
 	fprintf(f, "%s", "Journal features:        ");
 	for (i=0, mask_ptr=&jsb->s_feature_compat; i <3; i++,mask_ptr++) {