* [PATCH 1/5] move a jfs_user.h to better place.
@ 2022-08-04  9:56 Alexey Lyashkov
  2022-08-04  9:56 ` [PATCH 2/5] move a journal checksum code into common place Alexey Lyashkov
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Alexey Lyashkov @ 2022-08-04  9:56 UTC (permalink / raw)
  To: linux-ext4, Theodore Ts'o, Andreas Dilger, Artem Blagodarenko
  Cc: Alexey Lyashkov
jfs_user.h used in the debugfs and e2fsck, so
libsupport is better place for it.
just move a header into new place.
---
 debugfs/Makefile.in                | 16 +++++++---------
 debugfs/debugfs.c                  |  2 +-
 debugfs/journal.h                  |  2 +-
 debugfs/logdump.c                  |  2 +-
 e2fsck/Makefile.in                 |  8 ++++----
 e2fsck/journal.c                   |  2 +-
 e2fsck/recovery.c                  |  2 +-
 e2fsck/revoke.c                    |  2 +-
 e2fsck/unix.c                      |  2 +-
 lib/ext2fs/Makefile.in             | 18 ++++++++----------
 {e2fsck => lib/support}/jfs_user.h |  0
 misc/Makefile.in                   | 12 +++++-------
 12 files changed, 31 insertions(+), 37 deletions(-)
 rename {e2fsck => lib/support}/jfs_user.h (100%)
diff --git a/debugfs/Makefile.in b/debugfs/Makefile.in
index ed4ea8d8..33658eea 100644
--- a/debugfs/Makefile.in
+++ b/debugfs/Makefile.in
@@ -47,9 +47,7 @@ STATIC_DEPLIBS= $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBSS) \
 		$(DEPSTATIC_LIBCOM_ERR) $(DEPSTATIC_LIBUUID) \
 		$(DEPSTATIC_LIBE2P)
 
-# This nastiness is needed because of jfs_user.h hackery; when we finally
-# clean up this mess, we should be able to drop it
-LOCAL_CFLAGS = -I$(srcdir)/../e2fsck -DDEBUGFS
+LOCAL_CFLAGS = -DDEBUGFS
 DEPEND_CFLAGS = -I$(srcdir)
 
 .c.o:
@@ -186,7 +184,7 @@ debugfs.o: $(srcdir)/debugfs.c $(top_builddir)/lib/config.h \
  $(top_srcdir)/lib/e2p/e2p.h $(top_srcdir)/lib/support/quotaio.h \
  $(top_srcdir)/lib/support/dqblk_v2.h \
  $(top_srcdir)/lib/support/quotaio_tree.h $(top_srcdir)/version.h \
- $(srcdir)/../e2fsck/jfs_user.h $(top_srcdir)/lib/ext2fs/kernel-jbd.h \
+ $(top_srcdir)/lib/support/jfs_user.h $(top_srcdir)/lib/ext2fs/kernel-jbd.h \
  $(top_srcdir)/lib/ext2fs/jfs_compat.h $(top_srcdir)/lib/ext2fs/kernel-list.h \
  $(top_srcdir)/lib/ext2fs/compiler.h $(top_srcdir)/lib/support/plausible.h
 util.o: $(srcdir)/util.c $(top_builddir)/lib/config.h \
@@ -277,7 +275,7 @@ logdump.o: $(srcdir)/logdump.c $(top_builddir)/lib/config.h \
  $(top_srcdir)/lib/ext2fs/bitops.h $(srcdir)/../misc/create_inode.h \
  $(top_srcdir)/lib/e2p/e2p.h $(top_srcdir)/lib/support/quotaio.h \
  $(top_srcdir)/lib/support/dqblk_v2.h \
- $(top_srcdir)/lib/support/quotaio_tree.h $(srcdir)/../e2fsck/jfs_user.h \
+ $(top_srcdir)/lib/support/quotaio_tree.h $(top_srcdir)/lib/support/jfs_user.h \
  $(top_srcdir)/lib/ext2fs/kernel-jbd.h $(top_srcdir)/lib/ext2fs/jfs_compat.h \
  $(top_srcdir)/lib/ext2fs/kernel-list.h $(top_srcdir)/lib/ext2fs/compiler.h \
  $(top_srcdir)/lib/ext2fs/fast_commit.h
@@ -382,7 +380,7 @@ quota.o: $(srcdir)/quota.c $(top_builddir)/lib/config.h \
  $(top_srcdir)/lib/support/quotaio_tree.h
 journal.o: $(srcdir)/journal.c $(top_builddir)/lib/config.h \
  $(top_builddir)/lib/dirpaths.h $(srcdir)/journal.h \
- $(srcdir)/../e2fsck/jfs_user.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \
+ $(top_srcdir)/lib/support/jfs_user.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \
  $(top_builddir)/lib/ext2fs/ext2_types.h $(top_srcdir)/lib/ext2fs/ext2fs.h \
  $(top_srcdir)/lib/ext2fs/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \
  $(top_srcdir)/lib/ext2fs/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \
@@ -390,7 +388,7 @@ journal.o: $(srcdir)/journal.c $(top_builddir)/lib/config.h \
  $(top_srcdir)/lib/ext2fs/bitops.h $(top_srcdir)/lib/ext2fs/kernel-jbd.h \
  $(top_srcdir)/lib/ext2fs/jfs_compat.h $(top_srcdir)/lib/ext2fs/kernel-list.h \
  $(top_srcdir)/lib/ext2fs/compiler.h
-revoke.o: $(srcdir)/../e2fsck/revoke.c $(srcdir)/../e2fsck/jfs_user.h \
+revoke.o: $(srcdir)/../e2fsck/revoke.c $(top_srcdir)/lib/support/jfs_user.h \
  $(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h \
  $(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/lib/ext2fs/ext3_extents.h \
  $(top_srcdir)/lib/et/com_err.h $(top_srcdir)/lib/ext2fs/ext2_io.h \
@@ -399,7 +397,7 @@ revoke.o: $(srcdir)/../e2fsck/revoke.c $(srcdir)/../e2fsck/jfs_user.h \
  $(top_srcdir)/lib/ext2fs/bitops.h $(top_srcdir)/lib/ext2fs/kernel-jbd.h \
  $(top_srcdir)/lib/ext2fs/jfs_compat.h $(top_srcdir)/lib/ext2fs/kernel-list.h \
  $(top_srcdir)/lib/ext2fs/compiler.h
-recovery.o: $(srcdir)/../e2fsck/recovery.c $(srcdir)/../e2fsck/jfs_user.h \
+recovery.o: $(srcdir)/../e2fsck/recovery.c $(top_srcdir)/lib/support/jfs_user.h \
  $(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h \
  $(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/lib/ext2fs/ext3_extents.h \
  $(top_srcdir)/lib/et/com_err.h $(top_srcdir)/lib/ext2fs/ext2_io.h \
@@ -421,4 +419,4 @@ do_journal.o: $(srcdir)/do_journal.c $(top_builddir)/lib/config.h \
  $(top_srcdir)/lib/support/quotaio_tree.h \
  $(top_srcdir)/lib/ext2fs/kernel-jbd.h $(top_srcdir)/lib/ext2fs/jfs_compat.h \
  $(top_srcdir)/lib/ext2fs/kernel-list.h $(top_srcdir)/lib/ext2fs/compiler.h \
- $(srcdir)/journal.h $(srcdir)/../e2fsck/jfs_user.h
+ $(srcdir)/journal.h $(top_srcdir)/lib/support/jfs_user.h
diff --git a/debugfs/debugfs.c b/debugfs/debugfs.c
index b67a88bc..00b261ac 100644
--- a/debugfs/debugfs.c
+++ b/debugfs/debugfs.c
@@ -37,7 +37,7 @@ extern char *optarg;
 #include <ext2fs/ext2_ext_attr.h>
 
 #include "../version.h"
-#include "jfs_user.h"
+#include "support/jfs_user.h"
 #include "support/plausible.h"
 
 #ifndef BUFSIZ
diff --git a/debugfs/journal.h b/debugfs/journal.h
index 10b638eb..4d889834 100644
--- a/debugfs/journal.h
+++ b/debugfs/journal.h
@@ -12,7 +12,7 @@
  * any later version.
  */
 
-#include "jfs_user.h"
+#include "support/jfs_user.h"
 
 /* journal.c */
 errcode_t ext2fs_open_journal(ext2_filsys fs, journal_t **j);
diff --git a/debugfs/logdump.c b/debugfs/logdump.c
index 4154ef2a..f5427d5c 100644
--- a/debugfs/logdump.c
+++ b/debugfs/logdump.c
@@ -32,7 +32,7 @@ extern char *optarg;
 
 #include "debugfs.h"
 #include "blkid/blkid.h"
-#include "jfs_user.h"
+#include "support/jfs_user.h"
 #if __GNUC_PREREQ (4, 6)
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wunused-function"
diff --git a/e2fsck/Makefile.in b/e2fsck/Makefile.in
index 71ac3cf5..a6e11417 100644
--- a/e2fsck/Makefile.in
+++ b/e2fsck/Makefile.in
@@ -383,7 +383,7 @@ pass5.o: $(srcdir)/pass5.c $(top_builddir)/lib/config.h \
  $(top_srcdir)/lib/ext2fs/kernel-list.h $(top_srcdir)/lib/ext2fs/compiler.h \
  $(srcdir)/problem.h
 journal.o: $(srcdir)/journal.c $(top_builddir)/lib/config.h \
- $(top_builddir)/lib/dirpaths.h $(srcdir)/jfs_user.h $(srcdir)/e2fsck.h \
+ $(top_builddir)/lib/dirpaths.h $(top_srcdir)/lib/support/jfs_user.h $(srcdir)/e2fsck.h \
  $(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h \
  $(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/lib/ext2fs/ext3_extents.h \
  $(top_srcdir)/lib/et/com_err.h $(top_srcdir)/lib/ext2fs/ext2_io.h \
@@ -396,7 +396,7 @@ journal.o: $(srcdir)/journal.c $(top_builddir)/lib/config.h \
  $(top_srcdir)/lib/ext2fs/fast_commit.h $(top_srcdir)/lib/ext2fs/jfs_compat.h \
  $(top_srcdir)/lib/ext2fs/kernel-list.h $(top_srcdir)/lib/ext2fs/compiler.h \
  $(top_srcdir)/lib/ext2fs/kernel-jbd.h $(srcdir)/problem.h
-recovery.o: $(srcdir)/recovery.c $(srcdir)/jfs_user.h \
+recovery.o: $(srcdir)/recovery.c $(top_srcdir)/lib/support/jfs_user.h \
  $(top_builddir)/lib/config.h $(top_builddir)/lib/dirpaths.h \
  $(srcdir)/e2fsck.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \
  $(top_builddir)/lib/ext2fs/ext2_types.h $(top_srcdir)/lib/ext2fs/ext2fs.h \
@@ -410,7 +410,7 @@ recovery.o: $(srcdir)/recovery.c $(srcdir)/jfs_user.h \
  $(top_srcdir)/lib/ext2fs/fast_commit.h $(top_srcdir)/lib/ext2fs/jfs_compat.h \
  $(top_srcdir)/lib/ext2fs/kernel-list.h $(top_srcdir)/lib/ext2fs/compiler.h \
  $(top_srcdir)/lib/ext2fs/kernel-jbd.h
-revoke.o: $(srcdir)/revoke.c $(srcdir)/jfs_user.h \
+revoke.o: $(srcdir)/revoke.c $(top_srcdir)/lib/support/jfs_user.h \
  $(top_builddir)/lib/config.h $(top_builddir)/lib/dirpaths.h \
  $(srcdir)/e2fsck.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \
  $(top_builddir)/lib/ext2fs/ext2_types.h $(top_srcdir)/lib/ext2fs/ext2fs.h \
@@ -464,7 +464,7 @@ unix.o: $(srcdir)/unix.c $(top_builddir)/lib/config.h \
  $(top_srcdir)/lib/support/quotaio_tree.h \
  $(top_srcdir)/lib/ext2fs/fast_commit.h $(top_srcdir)/lib/ext2fs/jfs_compat.h \
  $(top_srcdir)/lib/ext2fs/kernel-list.h $(top_srcdir)/lib/ext2fs/compiler.h \
- $(srcdir)/problem.h $(srcdir)/jfs_user.h \
+ $(srcdir)/problem.h $(top_srcdir)/lib/support/jfs_user.h \
  $(top_srcdir)/lib/ext2fs/kernel-jbd.h $(top_srcdir)/version.h
 dirinfo.o: $(srcdir)/dirinfo.c $(top_builddir)/lib/config.h \
  $(top_builddir)/lib/dirpaths.h $(srcdir)/e2fsck.h \
diff --git a/e2fsck/journal.c b/e2fsck/journal.c
index 2e867234..d3002a62 100644
--- a/e2fsck/journal.c
+++ b/e2fsck/journal.c
@@ -23,7 +23,7 @@
 #endif
 
 #define E2FSCK_INCLUDE_INLINE_FUNCS
-#include "jfs_user.h"
+#include "support/jfs_user.h"
 #include "problem.h"
 #include "uuid/uuid.h"
 
diff --git a/e2fsck/recovery.c b/e2fsck/recovery.c
index 8ca35271..c7328cc5 100644
--- a/e2fsck/recovery.c
+++ b/e2fsck/recovery.c
@@ -11,7 +11,7 @@
  */
 
 #ifndef __KERNEL__
-#include "jfs_user.h"
+#include "support/jfs_user.h"
 #else
 #include <linux/time.h>
 #include <linux/fs.h>
diff --git a/e2fsck/revoke.c b/e2fsck/revoke.c
index fa608788..1d5f910b 100644
--- a/e2fsck/revoke.c
+++ b/e2fsck/revoke.c
@@ -78,7 +78,7 @@
  */
 
 #ifndef __KERNEL__
-#include "jfs_user.h"
+#include "support/jfs_user.h"
 #else
 #include <linux/time.h>
 #include <linux/fs.h>
diff --git a/e2fsck/unix.c b/e2fsck/unix.c
index ae231f93..474dde2d 100644
--- a/e2fsck/unix.c
+++ b/e2fsck/unix.c
@@ -54,7 +54,7 @@ extern int optind;
 #include "support/plausible.h"
 #include "e2fsck.h"
 #include "problem.h"
-#include "jfs_user.h"
+#include "support/jfs_user.h"
 #include "../version.h"
 
 /* Command line options */
diff --git a/lib/ext2fs/Makefile.in b/lib/ext2fs/Makefile.in
index f6a050a2..5fa9693a 100644
--- a/lib/ext2fs/Makefile.in
+++ b/lib/ext2fs/Makefile.in
@@ -5,10 +5,8 @@ top_builddir = ../..
 my_dir = lib/ext2fs
 INSTALL = @INSTALL@
 MKDIR_P = @MKDIR_P@
-DEPEND_CFLAGS = -I$(top_srcdir)/debugfs -I$(srcdir)/../../e2fsck -DDEBUGFS
-# This nastiness is needed because of jfs_user.h hackery; when we finally
-# clean up this mess, we should be able to drop it
-DEBUGFS_CFLAGS = -I$(srcdir)/../../e2fsck $(ALL_CFLAGS) -DDEBUGFS
+DEPEND_CFLAGS = -I$(top_srcdir)/debugfs -DDEBUGFS
+DEBUGFS_CFLAGS = $(ALL_CFLAGS) -DDEBUGFS
 
 @MCONFIG@
 
@@ -1231,7 +1229,7 @@ debugfs.o: $(top_srcdir)/debugfs/debugfs.c $(top_builddir)/lib/config.h \
  $(top_srcdir)/debugfs/../misc/create_inode.h $(top_srcdir)/lib/e2p/e2p.h \
  $(top_srcdir)/lib/support/quotaio.h $(top_srcdir)/lib/support/dqblk_v2.h \
  $(top_srcdir)/lib/support/quotaio_tree.h $(top_srcdir)/debugfs/../version.h \
- $(srcdir)/../../e2fsck/jfs_user.h $(srcdir)/kernel-jbd.h \
+ $(top_srcdir)/lib/support/jfs_user.h $(srcdir)/kernel-jbd.h \
  $(srcdir)/jfs_compat.h $(srcdir)/kernel-list.h $(srcdir)/compiler.h \
  $(top_srcdir)/lib/support/plausible.h
 util.o: $(top_srcdir)/debugfs/util.c $(top_builddir)/lib/config.h \
@@ -1321,7 +1319,7 @@ logdump.o: $(top_srcdir)/debugfs/logdump.c $(top_builddir)/lib/config.h \
  $(srcdir)/hashmap.h $(srcdir)/bitops.h \
  $(top_srcdir)/debugfs/../misc/create_inode.h $(top_srcdir)/lib/e2p/e2p.h \
  $(top_srcdir)/lib/support/quotaio.h $(top_srcdir)/lib/support/dqblk_v2.h \
- $(top_srcdir)/lib/support/quotaio_tree.h $(srcdir)/../../e2fsck/jfs_user.h \
+ $(top_srcdir)/lib/support/quotaio_tree.h $(top_srcdir)/lib/support/jfs_user.h \
  $(srcdir)/kernel-jbd.h $(srcdir)/jfs_compat.h $(srcdir)/kernel-list.h \
  $(srcdir)/compiler.h $(srcdir)/fast_commit.h
 htree.o: $(top_srcdir)/debugfs/htree.c $(top_builddir)/lib/config.h \
@@ -1422,20 +1420,20 @@ create_inode.o: $(top_srcdir)/misc/create_inode.c \
  $(top_srcdir)/lib/e2p/e2p.h $(top_srcdir)/lib/support/nls-enable.h
 journal.o: $(top_srcdir)/debugfs/journal.c $(top_builddir)/lib/config.h \
  $(top_builddir)/lib/dirpaths.h $(top_srcdir)/debugfs/journal.h \
- $(srcdir)/../../e2fsck/jfs_user.h $(srcdir)/ext2_fs.h \
+ $(top_srcdir)/lib/support/jfs_user.h $(srcdir)/ext2_fs.h \
  $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \
  $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h $(srcdir)/ext2_io.h \
  $(top_builddir)/lib/ext2fs/ext2_err.h $(srcdir)/ext2_ext_attr.h \
  $(srcdir)/hashmap.h $(srcdir)/bitops.h $(srcdir)/kernel-jbd.h \
  $(srcdir)/jfs_compat.h $(srcdir)/kernel-list.h $(srcdir)/compiler.h
-revoke.o: $(top_srcdir)/e2fsck/revoke.c $(top_srcdir)/e2fsck/jfs_user.h \
+revoke.o: $(top_srcdir)/e2fsck/revoke.c $(top_srcdir)/lib/support/jfs_user.h \
  $(srcdir)/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h \
  $(srcdir)/ext2fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \
  $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \
  $(srcdir)/ext2_ext_attr.h $(srcdir)/hashmap.h $(srcdir)/bitops.h \
  $(srcdir)/kernel-jbd.h $(srcdir)/jfs_compat.h $(srcdir)/kernel-list.h \
  $(srcdir)/compiler.h
-recovery.o: $(top_srcdir)/e2fsck/recovery.c $(top_srcdir)/e2fsck/jfs_user.h \
+recovery.o: $(top_srcdir)/e2fsck/recovery.c $(top_srcdir)/lib/support/jfs_user.h \
  $(srcdir)/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h \
  $(srcdir)/ext2fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \
  $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \
@@ -1454,4 +1452,4 @@ do_journal.o: $(top_srcdir)/debugfs/do_journal.c $(top_builddir)/lib/config.h \
  $(top_srcdir)/lib/support/quotaio.h $(top_srcdir)/lib/support/dqblk_v2.h \
  $(top_srcdir)/lib/support/quotaio_tree.h $(srcdir)/kernel-jbd.h \
  $(srcdir)/jfs_compat.h $(srcdir)/kernel-list.h $(srcdir)/compiler.h \
- $(top_srcdir)/debugfs/journal.h $(srcdir)/../../e2fsck/jfs_user.h
+ $(top_srcdir)/debugfs/journal.h $(top_srcdir)/lib/support/jfs_user.h
diff --git a/e2fsck/jfs_user.h b/lib/support/jfs_user.h
similarity index 100%
rename from e2fsck/jfs_user.h
rename to lib/support/jfs_user.h
diff --git a/misc/Makefile.in b/misc/Makefile.in
index 4db59cdf..2d4c8087 100644
--- a/misc/Makefile.in
+++ b/misc/Makefile.in
@@ -124,10 +124,8 @@ DEPLIBS_E2P= $(LIBE2P) $(DEPLIBCOM_ERR)
 
 COMPILE_ET=	_ET_DIR_OVERRIDE=$(srcdir)/../lib/et/et ../lib/et/compile_et
 
-# This nastiness is needed because of jfs_user.h hackery; when we finally
-# clean up this mess, we should be able to drop it
-JOURNAL_CFLAGS = -I$(srcdir)/../e2fsck $(ALL_CFLAGS) -DDEBUGFS
-DEPEND_CFLAGS = -I$(top_srcdir)/e2fsck
+JOURNAL_CFLAGS = -I $(ALL_CFLAGS) -DDEBUGFS
+DEPEND_CFLAGS =
 
 .c.o:
 	$(E) "	CC $<"
@@ -878,7 +876,7 @@ check_fuzzer.o: $(srcdir)/check_fuzzer.c $(top_srcdir)/lib/ext2fs/ext2_fs.h \
  $(top_srcdir)/lib/ext2fs/bitops.h
 journal.o: $(srcdir)/../debugfs/journal.c $(top_builddir)/lib/config.h \
  $(top_builddir)/lib/dirpaths.h $(srcdir)/../debugfs/journal.h \
- $(top_srcdir)/e2fsck/jfs_user.h $(top_srcdir)/e2fsck/e2fsck.h \
+ $(top_srcdir)/lib/support/jfs_user.h $(top_srcdir)/e2fsck/e2fsck.h \
  $(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h \
  $(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/lib/ext2fs/ext3_extents.h \
  $(top_srcdir)/lib/et/com_err.h $(top_srcdir)/lib/ext2fs/ext2_io.h \
@@ -891,7 +889,7 @@ journal.o: $(srcdir)/../debugfs/journal.c $(top_builddir)/lib/config.h \
  $(top_srcdir)/lib/ext2fs/fast_commit.h $(top_srcdir)/lib/ext2fs/jfs_compat.h \
  $(top_srcdir)/lib/ext2fs/kernel-list.h $(top_srcdir)/lib/ext2fs/compiler.h \
  $(top_srcdir)/lib/ext2fs/kernel-jbd.h
-revoke.o: $(srcdir)/../e2fsck/revoke.c $(srcdir)/../e2fsck/jfs_user.h \
+revoke.o: $(srcdir)/../e2fsck/revoke.c $(top_srcdir)/lib/support/jfs_user.h \
  $(top_builddir)/lib/config.h $(top_builddir)/lib/dirpaths.h \
  $(srcdir)/../e2fsck/e2fsck.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \
  $(top_builddir)/lib/ext2fs/ext2_types.h $(top_srcdir)/lib/ext2fs/ext2fs.h \
@@ -905,7 +903,7 @@ revoke.o: $(srcdir)/../e2fsck/revoke.c $(srcdir)/../e2fsck/jfs_user.h \
  $(top_srcdir)/lib/ext2fs/fast_commit.h $(top_srcdir)/lib/ext2fs/jfs_compat.h \
  $(top_srcdir)/lib/ext2fs/kernel-list.h $(top_srcdir)/lib/ext2fs/compiler.h \
  $(top_srcdir)/lib/ext2fs/kernel-jbd.h
-recovery.o: $(srcdir)/../e2fsck/recovery.c $(srcdir)/../e2fsck/jfs_user.h \
+recovery.o: $(srcdir)/../e2fsck/recovery.c $(top_srcdir)/lib/support/jfs_user.h \
  $(top_builddir)/lib/config.h $(top_builddir)/lib/dirpaths.h \
  $(srcdir)/../e2fsck/e2fsck.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \
  $(top_builddir)/lib/ext2fs/ext2_types.h $(top_srcdir)/lib/ext2fs/ext2fs.h \
-- 
2.31.1
^ permalink raw reply related	[flat|nested] 11+ messages in thread
* [PATCH 2/5] move a journal checksum code into common place
  2022-08-04  9:56 [PATCH 1/5] move a jfs_user.h to better place Alexey Lyashkov
@ 2022-08-04  9:56 ` Alexey Lyashkov
  2023-09-18 23:19   ` Andreas Dilger
  2022-08-04  9:56 ` [PATCH 3/5] kill a ctx->journal_io Alexey Lyashkov
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Alexey Lyashkov @ 2022-08-04  9:56 UTC (permalink / raw)
  To: linux-ext4, Theodore Ts'o, Andreas Dilger, Artem Blagodarenko
  Cc: Alexey Lyashkov
e2fsck and debugfs have own copy a journal checksum functions,
kill duplicates and move into support library.
---
 debugfs/journal.c       | 50 ---------------------------------
 e2fsck/journal.c        | 60 ++++-----------------------------------
 lib/support/Android.bp  |  1 +
 lib/support/Makefile.in |  7 +++--
 lib/support/jfs_user.c  | 62 +++++++++++++++++++++++++++++++++++++++++
 lib/support/jfs_user.h  |  6 ++++
 6 files changed, 79 insertions(+), 107 deletions(-)
 create mode 100644 lib/support/jfs_user.c
diff --git a/debugfs/journal.c b/debugfs/journal.c
index 095fff00..dac17800 100644
--- a/debugfs/journal.c
+++ b/debugfs/journal.c
@@ -43,56 +43,6 @@ static int bh_count = 0;
  */
 #undef USE_INODE_IO
 
-/* Checksumming functions */
-static int ext2fs_journal_verify_csum_type(journal_t *j,
-					   journal_superblock_t *jsb)
-{
-	if (!jbd2_journal_has_csum_v2or3(j))
-		return 1;
-
-	return jsb->s_checksum_type == JBD2_CRC32C_CHKSUM;
-}
-
-static __u32 ext2fs_journal_sb_csum(journal_superblock_t *jsb)
-{
-	__u32 crc, old_crc;
-
-	old_crc = jsb->s_checksum;
-	jsb->s_checksum = 0;
-	crc = ext2fs_crc32c_le(~0, (unsigned char *)jsb,
-			       sizeof(journal_superblock_t));
-	jsb->s_checksum = old_crc;
-
-	return crc;
-}
-
-static int ext2fs_journal_sb_csum_verify(journal_t *j,
-					 journal_superblock_t *jsb)
-{
-	__u32 provided, calculated;
-
-	if (!jbd2_journal_has_csum_v2or3(j))
-		return 1;
-
-	provided = ext2fs_be32_to_cpu(jsb->s_checksum);
-	calculated = ext2fs_journal_sb_csum(jsb);
-
-	return provided == calculated;
-}
-
-static errcode_t ext2fs_journal_sb_csum_set(journal_t *j,
-					    journal_superblock_t *jsb)
-{
-	__u32 crc;
-
-	if (!jbd2_journal_has_csum_v2or3(j))
-		return 0;
-
-	crc = ext2fs_journal_sb_csum(jsb);
-	jsb->s_checksum = ext2fs_cpu_to_be32(crc);
-	return 0;
-}
-
 /* Kernel compatibility functions for handling the journal.  These allow us
  * to use the recovery.c file virtually unchanged from the kernel, so we
  * don't have to do much to keep kernel and user recovery in sync.
diff --git a/e2fsck/journal.c b/e2fsck/journal.c
index d3002a62..46a9bcb7 100644
--- a/e2fsck/journal.c
+++ b/e2fsck/journal.c
@@ -38,56 +38,6 @@ static int bh_count = 0;
  */
 #undef USE_INODE_IO
 
-/* Checksumming functions */
-static int e2fsck_journal_verify_csum_type(journal_t *j,
-					   journal_superblock_t *jsb)
-{
-	if (!jbd2_journal_has_csum_v2or3(j))
-		return 1;
-
-	return jsb->s_checksum_type == JBD2_CRC32C_CHKSUM;
-}
-
-static __u32 e2fsck_journal_sb_csum(journal_superblock_t *jsb)
-{
-	__u32 crc, old_crc;
-
-	old_crc = jsb->s_checksum;
-	jsb->s_checksum = 0;
-	crc = ext2fs_crc32c_le(~0, (unsigned char *)jsb,
-			       sizeof(journal_superblock_t));
-	jsb->s_checksum = old_crc;
-
-	return crc;
-}
-
-static int e2fsck_journal_sb_csum_verify(journal_t *j,
-					 journal_superblock_t *jsb)
-{
-	__u32 provided, calculated;
-
-	if (!jbd2_journal_has_csum_v2or3(j))
-		return 1;
-
-	provided = ext2fs_be32_to_cpu(jsb->s_checksum);
-	calculated = e2fsck_journal_sb_csum(jsb);
-
-	return provided == calculated;
-}
-
-static errcode_t e2fsck_journal_sb_csum_set(journal_t *j,
-					    journal_superblock_t *jsb)
-{
-	__u32 crc;
-
-	if (!jbd2_journal_has_csum_v2or3(j))
-		return 0;
-
-	crc = e2fsck_journal_sb_csum(jsb);
-	jsb->s_checksum = ext2fs_cpu_to_be32(crc);
-	return 0;
-}
-
 /* Kernel compatibility functions for handling the journal.  These allow us
  * to use the recovery.c file virtually unchanged from the kernel, so we
  * don't have to do much to keep kernel and user recovery in sync.
@@ -1330,8 +1280,8 @@ static errcode_t e2fsck_journal_load(journal_t *journal)
 	    jbd2_has_feature_checksum(journal))
 		return EXT2_ET_CORRUPT_JOURNAL_SB;
 
-	if (!e2fsck_journal_verify_csum_type(journal, jsb) ||
-	    !e2fsck_journal_sb_csum_verify(journal, jsb))
+	if (!ext2fs_journal_verify_csum_type(journal, jsb) ||
+	    !ext2fs_journal_sb_csum_verify(journal, jsb))
 		return EXT2_ET_CORRUPT_JOURNAL_SB;
 
 	if (jbd2_journal_has_csum_v2or3(journal))
@@ -1419,7 +1369,7 @@ static void e2fsck_journal_reset_super(e2fsck_t ctx, journal_superblock_t *jsb,
 	for (i = 0; i < 4; i ++)
 		new_seq ^= u.val[i];
 	jsb->s_sequence = htonl(new_seq);
-	e2fsck_journal_sb_csum_set(journal, jsb);
+	ext2fs_journal_sb_csum_set(journal, jsb);
 
 	mark_buffer_dirty(journal->j_sb_buffer);
 	ll_rw_block(REQ_OP_WRITE, 0, 1, &journal->j_sb_buffer);
@@ -1459,7 +1409,7 @@ static void e2fsck_journal_release(e2fsck_t ctx, journal_t *journal,
 		jsb->s_sequence = htonl(journal->j_tail_sequence);
 		if (reset)
 			jsb->s_start = 0; /* this marks the journal as empty */
-		e2fsck_journal_sb_csum_set(journal, jsb);
+		ext2fs_journal_sb_csum_set(journal, jsb);
 		mark_buffer_dirty(journal->j_sb_buffer);
 	}
 	brelse(journal->j_sb_buffer);
@@ -1602,7 +1552,7 @@ no_has_journal:
 		ctx->fs->super->s_state |= EXT2_ERROR_FS;
 		ext2fs_mark_super_dirty(ctx->fs);
 		journal->j_superblock->s_errno = 0;
-		e2fsck_journal_sb_csum_set(journal, journal->j_superblock);
+		ext2fs_journal_sb_csum_set(journal, journal->j_superblock);
 		mark_buffer_dirty(journal->j_sb_buffer);
 	}
 
diff --git a/lib/support/Android.bp b/lib/support/Android.bp
index a0b064dd..efa0f955 100644
--- a/lib/support/Android.bp
+++ b/lib/support/Android.bp
@@ -29,6 +29,7 @@ cc_library {
         "quotaio.c",
         "quotaio_tree.c",
         "quotaio_v2.c",
+        "jfs_user.c"
     ],
     shared_libs: [
         "libext2fs",
diff --git a/lib/support/Makefile.in b/lib/support/Makefile.in
index f3c7981e..04fbcf31 100644
--- a/lib/support/Makefile.in
+++ b/lib/support/Makefile.in
@@ -23,7 +23,8 @@ OBJS=		cstring.o \
 		quotaio.o \
 		quotaio_v2.o \
 		quotaio_tree.o \
-		dict.o
+		dict.o \
+		jfs_user.o
 
 SRCS=		$(srcdir)/argv_parse.c \
 		$(srcdir)/cstring.c \
@@ -36,7 +37,9 @@ SRCS=		$(srcdir)/argv_parse.c \
 		$(srcdir)/quotaio.c \
 		$(srcdir)/quotaio_tree.c \
 		$(srcdir)/quotaio_v2.c \
-		$(srcdir)/dict.c
+		$(srcdir)/dict.c \
+		$(srcdir)/jfs_user.c
+		
 
 LIBRARY= libsupport
 LIBDIR= support
diff --git a/lib/support/jfs_user.c b/lib/support/jfs_user.c
new file mode 100644
index 00000000..4ff1b5c1
--- /dev/null
+++ b/lib/support/jfs_user.c
@@ -0,0 +1,62 @@
+#define DEBUGFS
+#include "jfs_user.h"
+
+/*
+ * Define USE_INODE_IO to use the inode_io.c / fileio.c codepaths.
+ * This creates a larger static binary, and a smaller binary using
+ * shared libraries.  It's also probably slightly less CPU-efficient,
+ * which is why it's not on by default.  But, it's a good way of
+ * testing the functions in inode_io.c and fileio.c.
+ */
+#undef USE_INODE_IO
+
+/* Checksumming functions */
+int ext2fs_journal_verify_csum_type(journal_t *j,
+				    journal_superblock_t *jsb)
+{
+	if (!jbd2_journal_has_csum_v2or3(j))
+		return 1;
+
+	return jsb->s_checksum_type == JBD2_CRC32C_CHKSUM;
+}
+
+__u32 ext2fs_journal_sb_csum(journal_superblock_t *jsb)
+{
+	__u32 crc, old_crc;
+
+	old_crc = jsb->s_checksum;
+	jsb->s_checksum = 0;
+	crc = ext2fs_crc32c_le(~0, (unsigned char *)jsb,
+			       sizeof(journal_superblock_t));
+	jsb->s_checksum = old_crc;
+
+	return crc;
+}
+
+int ext2fs_journal_sb_csum_verify(journal_t *j,
+				  journal_superblock_t *jsb)
+{
+	__u32 provided, calculated;
+
+	if (!jbd2_journal_has_csum_v2or3(j))
+		return 1;
+
+	provided = ext2fs_be32_to_cpu(jsb->s_checksum);
+	calculated = ext2fs_journal_sb_csum(jsb);
+
+	return provided == calculated;
+}
+
+errcode_t ext2fs_journal_sb_csum_set(journal_t *j,
+				     journal_superblock_t *jsb)
+{
+	__u32 crc;
+
+	if (!jbd2_journal_has_csum_v2or3(j))
+		return 0;
+
+	crc = ext2fs_journal_sb_csum(jsb);
+	jsb->s_checksum = ext2fs_cpu_to_be32(crc);
+	return 0;
+}
+
diff --git a/lib/support/jfs_user.h b/lib/support/jfs_user.h
index 4ad2005a..8bdbf85b 100644
--- a/lib/support/jfs_user.h
+++ b/lib/support/jfs_user.h
@@ -212,6 +212,12 @@ _INLINE_ void jbd2_descriptor_block_csum_set(journal_t *j,
 #undef _INLINE_
 #endif
 
+/* Checksumming functions */
+int ext2fs_journal_verify_csum_type(journal_t *j, journal_superblock_t *jsb);
+__u32 ext2fs_journal_sb_csum(journal_superblock_t *jsb);
+int ext2fs_journal_sb_csum_verify(journal_t *j, journal_superblock_t *jsb);
+errcode_t ext2fs_journal_sb_csum_set(journal_t *j, journal_superblock_t *jsb);
+
 /*
  * Kernel compatibility functions are defined in journal.c
  */
-- 
2.31.1
^ permalink raw reply related	[flat|nested] 11+ messages in thread
* [PATCH 3/5] kill a ctx->journal_io
  2022-08-04  9:56 [PATCH 1/5] move a jfs_user.h to better place Alexey Lyashkov
  2022-08-04  9:56 ` [PATCH 2/5] move a journal checksum code into common place Alexey Lyashkov
@ 2022-08-04  9:56 ` Alexey Lyashkov
  2023-09-18 23:43   ` Andreas Dilger
  2022-08-04  9:56 ` [PATCH 4/5] remove an e2fsck context from bh emulation code Alexey Lyashkov
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Alexey Lyashkov @ 2022-08-04  9:56 UTC (permalink / raw)
  To: linux-ext4, Theodore Ts'o, Andreas Dilger, Artem Blagodarenko
  Cc: Alexey Lyashkov
replace a e2fsck own code, with generic one to use
an fs->journal_io.
---
 debugfs/journal.c      | 34 ---------------------------
 e2fsck/e2fsck.c        |  6 +----
 e2fsck/e2fsck.h        |  1 -
 e2fsck/journal.c       | 53 +++++++-----------------------------------
 lib/support/jfs_user.c | 39 +++++++++++++++++++++++++++++++
 lib/support/jfs_user.h |  2 ++
 6 files changed, 50 insertions(+), 85 deletions(-)
diff --git a/debugfs/journal.c b/debugfs/journal.c
index dac17800..202312fe 100644
--- a/debugfs/journal.c
+++ b/debugfs/journal.c
@@ -590,40 +590,6 @@ static errcode_t ext2fs_journal_load(journal_t *journal)
 	return 0;
 }
 
-static void ext2fs_journal_release(ext2_filsys fs, journal_t *journal,
-				   int reset, int drop)
-{
-	journal_superblock_t *jsb;
-
-	if (drop)
-		mark_buffer_clean(journal->j_sb_buffer);
-	else if (fs->flags & EXT2_FLAG_RW) {
-		jsb = journal->j_superblock;
-		jsb->s_sequence = htonl(journal->j_tail_sequence);
-		if (reset)
-			jsb->s_start = 0; /* this marks the journal as empty */
-		ext2fs_journal_sb_csum_set(journal, jsb);
-		mark_buffer_dirty(journal->j_sb_buffer);
-	}
-	brelse(journal->j_sb_buffer);
-
-	if (fs && fs->journal_io) {
-		if (fs->io != fs->journal_io)
-			io_channel_close(fs->journal_io);
-		fs->journal_io = NULL;
-		free(fs->journal_name);
-		fs->journal_name = NULL;
-	}
-
-#ifndef USE_INODE_IO
-	if (journal->j_inode)
-		ext2fs_free_mem(&journal->j_inode);
-#endif
-	if (journal->j_fs_dev)
-		ext2fs_free_mem(&journal->j_fs_dev);
-	ext2fs_free_mem(&journal);
-}
-
 /*
  * This function makes sure that the superblock fields regarding the
  * journal are consistent.
diff --git a/e2fsck/e2fsck.c b/e2fsck/e2fsck.c
index 1e295e3e..421ef4a9 100644
--- a/e2fsck/e2fsck.c
+++ b/e2fsck/e2fsck.c
@@ -83,11 +83,7 @@ errcode_t e2fsck_reset_context(e2fsck_t ctx)
 		ext2fs_free_icount(ctx->inode_link_info);
 		ctx->inode_link_info = 0;
 	}
-	if (ctx->journal_io) {
-		if (ctx->fs && ctx->fs->io != ctx->journal_io)
-			io_channel_close(ctx->journal_io);
-		ctx->journal_io = 0;
-	}
+
 	if (ctx->fs && ctx->fs->dblist) {
 		ext2fs_free_dblist(ctx->fs->dblist);
 		ctx->fs->dblist = 0;
diff --git a/e2fsck/e2fsck.h b/e2fsck/e2fsck.h
index 2db216f5..33334781 100644
--- a/e2fsck/e2fsck.h
+++ b/e2fsck/e2fsck.h
@@ -380,7 +380,6 @@ struct e2fsck_struct {
 	/*
 	 * ext3 journal support
 	 */
-	io_channel	journal_io;
 	char	*journal_name;
 
 	/*
diff --git a/e2fsck/journal.c b/e2fsck/journal.c
index 46a9bcb7..682d82a4 100644
--- a/e2fsck/journal.c
+++ b/e2fsck/journal.c
@@ -86,7 +86,7 @@ struct buffer_head *getblk(kdev_t kdev, unsigned long long blocknr,
 	if (kdev->k_dev == K_DEV_FS)
 		bh->b_io = kdev->k_ctx->fs->io;
 	else
-		bh->b_io = kdev->k_ctx->journal_io;
+		bh->b_io = kdev->k_ctx->fs->journal_io;
 	bh->b_size = blocksize;
 	bh->b_blocknr = blocknr;
 
@@ -100,7 +100,7 @@ int sync_blockdev(kdev_t kdev)
 	if (kdev->k_dev == K_DEV_FS)
 		io = kdev->k_ctx->fs->io;
 	else
-		io = kdev->k_ctx->journal_io;
+		io = kdev->k_ctx->fs->journal_io;
 
 	return io_channel_flush(io) ? -EIO : 0;
 }
@@ -156,11 +156,6 @@ void mark_buffer_dirty(struct buffer_head *bh)
 	bh->b_dirty = 1;
 }
 
-static void mark_buffer_clean(struct buffer_head * bh)
-{
-	bh->b_dirty = 0;
-}
-
 void brelse(struct buffer_head *bh)
 {
 	if (bh->b_dirty)
@@ -1011,7 +1006,7 @@ static errcode_t e2fsck_get_journal(e2fsck_t ctx, journal_t **ret_journal)
 		io_ptr = inode_io_manager;
 #else
 		journal->j_inode = j_inode;
-		ctx->journal_io = ctx->fs->io;
+		ctx->fs->journal_io = ctx->fs->io;
 		if ((ret = jbd2_journal_bmap(journal, 0, &start)) != 0) {
 			retval = (errcode_t) (-1 * ret);
 			goto errout;
@@ -1058,12 +1053,12 @@ static errcode_t e2fsck_get_journal(e2fsck_t ctx, journal_t **ret_journal)
 
 
 		retval = io_ptr->open(journal_name, flags,
-				      &ctx->journal_io);
+				      &ctx->fs->journal_io);
 	}
 	if (retval)
 		goto errout;
 
-	io_channel_set_blksize(ctx->journal_io, ctx->fs->blocksize);
+	io_channel_set_blksize(ctx->fs->journal_io, ctx->fs->blocksize);
 
 	if (ext_journal) {
 		blk64_t maxlen;
@@ -1397,38 +1392,6 @@ static errcode_t e2fsck_journal_fix_corrupt_super(e2fsck_t ctx,
 	return 0;
 }
 
-static void e2fsck_journal_release(e2fsck_t ctx, journal_t *journal,
-				   int reset, int drop)
-{
-	journal_superblock_t *jsb;
-
-	if (drop)
-		mark_buffer_clean(journal->j_sb_buffer);
-	else if (!(ctx->options & E2F_OPT_READONLY)) {
-		jsb = journal->j_superblock;
-		jsb->s_sequence = htonl(journal->j_tail_sequence);
-		if (reset)
-			jsb->s_start = 0; /* this marks the journal as empty */
-		ext2fs_journal_sb_csum_set(journal, jsb);
-		mark_buffer_dirty(journal->j_sb_buffer);
-	}
-	brelse(journal->j_sb_buffer);
-
-	if (ctx->journal_io) {
-		if (ctx->fs && ctx->fs->io != ctx->journal_io)
-			io_channel_close(ctx->journal_io);
-		ctx->journal_io = 0;
-	}
-
-#ifndef USE_INODE_IO
-	if (journal->j_inode)
-		ext2fs_free_mem(&journal->j_inode);
-#endif
-	if (journal->j_fs_dev)
-		ext2fs_free_mem(&journal->j_fs_dev);
-	ext2fs_free_mem(&journal);
-}
-
 /*
  * This function makes sure that the superblock fields regarding the
  * journal are consistent.
@@ -1475,7 +1438,7 @@ errcode_t e2fsck_check_ext3_journal(e2fsck_t ctx)
 		    (!fix_problem(ctx, PR_0_JOURNAL_UNSUPP_VERSION, &pctx))))
 			retval = e2fsck_journal_fix_corrupt_super(ctx, journal,
 								  &pctx);
-		e2fsck_journal_release(ctx, journal, 0, 1);
+		ext2fs_journal_release(ctx->fs, journal, 0, 1);
 		return retval;
 	}
 
@@ -1556,7 +1519,7 @@ no_has_journal:
 		mark_buffer_dirty(journal->j_sb_buffer);
 	}
 
-	e2fsck_journal_release(ctx, journal, reset, 0);
+	ext2fs_journal_release(ctx->fs, journal, reset, 0);
 	return retval;
 }
 
@@ -1605,7 +1568,7 @@ errout:
 	jbd2_journal_destroy_revoke(journal);
 	jbd2_journal_destroy_revoke_record_cache();
 	jbd2_journal_destroy_revoke_table_cache();
-	e2fsck_journal_release(ctx, journal, 1, 0);
+	ext2fs_journal_release(ctx->fs, journal, 1, 0);
 	return retval;
 }
 
diff --git a/lib/support/jfs_user.c b/lib/support/jfs_user.c
index 4ff1b5c1..d8a2f842 100644
--- a/lib/support/jfs_user.c
+++ b/lib/support/jfs_user.c
@@ -60,3 +60,42 @@ errcode_t ext2fs_journal_sb_csum_set(journal_t *j,
 	return 0;
 }
 
+
+static void mark_buffer_clean(struct buffer_head * bh)
+{
+	bh->b_dirty = 0;
+}
+
+void ext2fs_journal_release(ext2_filsys fs, journal_t *journal,
+			    int reset, int drop)
+{
+	journal_superblock_t *jsb;
+
+	if (drop)
+		mark_buffer_clean(journal->j_sb_buffer);
+	else if (fs->flags & EXT2_FLAG_RW) {
+		jsb = journal->j_superblock;
+		jsb->s_sequence = htonl(journal->j_tail_sequence);
+		if (reset)
+			jsb->s_start = 0; /* this marks the journal as empty */
+		ext2fs_journal_sb_csum_set(journal, jsb);
+		mark_buffer_dirty(journal->j_sb_buffer);
+	}
+	brelse(journal->j_sb_buffer);
+
+	if (fs && fs->journal_io) {
+		if (fs->io != fs->journal_io)
+			io_channel_close(fs->journal_io);
+		fs->journal_io = NULL;
+		free(fs->journal_name);
+		fs->journal_name = NULL;
+	}
+
+#ifndef USE_INODE_IO
+	if (journal->j_inode)
+		ext2fs_free_mem(&journal->j_inode);
+#endif
+	if (journal->j_fs_dev)
+		ext2fs_free_mem(&journal->j_fs_dev);
+	ext2fs_free_mem(&journal);
+}
diff --git a/lib/support/jfs_user.h b/lib/support/jfs_user.h
index 8bdbf85b..b9c2fa54 100644
--- a/lib/support/jfs_user.h
+++ b/lib/support/jfs_user.h
@@ -217,6 +217,8 @@ int ext2fs_journal_verify_csum_type(journal_t *j, journal_superblock_t *jsb);
 __u32 ext2fs_journal_sb_csum(journal_superblock_t *jsb);
 int ext2fs_journal_sb_csum_verify(journal_t *j, journal_superblock_t *jsb);
 errcode_t ext2fs_journal_sb_csum_set(journal_t *j, journal_superblock_t *jsb);
+void ext2fs_journal_release(ext2_filsys fs, journal_t *journal, int reset,
+			    int drop);
 
 /*
  * Kernel compatibility functions are defined in journal.c
-- 
2.31.1
^ permalink raw reply related	[flat|nested] 11+ messages in thread
* [PATCH 4/5] remove an e2fsck context from bh emulation code.
  2022-08-04  9:56 [PATCH 1/5] move a jfs_user.h to better place Alexey Lyashkov
  2022-08-04  9:56 ` [PATCH 2/5] move a journal checksum code into common place Alexey Lyashkov
  2022-08-04  9:56 ` [PATCH 3/5] kill a ctx->journal_io Alexey Lyashkov
@ 2022-08-04  9:56 ` Alexey Lyashkov
  2023-09-18 23:57   ` Andreas Dilger
  2022-08-04  9:56 ` [PATCH 5/5] deduplicate a buffer_head / kernel device code Alexey Lyashkov
  2023-09-18 23:06 ` [PATCH 1/5] move a jfs_user.h to better place Andreas Dilger
  4 siblings, 1 reply; 11+ messages in thread
From: Alexey Lyashkov @ 2022-08-04  9:56 UTC (permalink / raw)
  To: linux-ext4, Theodore Ts'o, Andreas Dilger, Artem Blagodarenko
  Cc: Alexey Lyashkov
In order to generalize a journal handing, remove a e2fsck context
from generic structures like buffer_head, and device.
But fast commit code want a e2fsck context as well, so move it pointer
to journal struct.
---
 e2fsck/journal.c        | 46 ++++++++++++++++++++---------------------
 lib/ext2fs/jfs_compat.h |  2 ++
 lib/support/jfs_user.h  | 12 -----------
 3 files changed, 25 insertions(+), 35 deletions(-)
diff --git a/e2fsck/journal.c b/e2fsck/journal.c
index 682d82a4..728f5a24 100644
--- a/e2fsck/journal.c
+++ b/e2fsck/journal.c
@@ -58,7 +58,7 @@ int jbd2_journal_bmap(journal_t *journal, unsigned long block,
 		return 0;
 	}
 
-	retval= ext2fs_bmap2(inode->i_ctx->fs, inode->i_ino,
+	retval= ext2fs_bmap2(inode->i_fs, inode->i_ino,
 			     &inode->i_ext2, NULL, 0, (blk64_t) block,
 			     0, &pblk);
 	*phys = pblk;
@@ -70,11 +70,12 @@ struct buffer_head *getblk(kdev_t kdev, unsigned long long blocknr,
 			   int blocksize)
 {
 	struct buffer_head *bh;
-	int bufsize = sizeof(*bh) + kdev->k_ctx->fs->blocksize -
+	int bufsize = sizeof(*bh) + kdev->k_fs->blocksize -
 		sizeof(bh->b_data);
+	errcode_t retval;
 
-	bh = e2fsck_allocate_memory(kdev->k_ctx, bufsize, "block buffer");
-	if (!bh)
+	retval = ext2fs_get_memzero(bufsize, &bh);
+	if (retval)
 		return NULL;
 
 	if (journal_enable_debug >= 3)
@@ -82,11 +83,11 @@ struct buffer_head *getblk(kdev_t kdev, unsigned long long blocknr,
 	jfs_debug(4, "getblk for block %llu (%d bytes)(total %d)\n",
 		  blocknr, blocksize, bh_count);
 
-	bh->b_ctx = kdev->k_ctx;
+	bh->b_fs = kdev->k_fs;
 	if (kdev->k_dev == K_DEV_FS)
-		bh->b_io = kdev->k_ctx->fs->io;
+		bh->b_io = kdev->k_fs->io;
 	else
-		bh->b_io = kdev->k_ctx->fs->journal_io;
+		bh->b_io = kdev->k_fs->journal_io;
 	bh->b_size = blocksize;
 	bh->b_blocknr = blocknr;
 
@@ -98,9 +99,9 @@ int sync_blockdev(kdev_t kdev)
 	io_channel	io;
 
 	if (kdev->k_dev == K_DEV_FS)
-		io = kdev->k_ctx->fs->io;
+		io = kdev->k_fs->io;
 	else
-		io = kdev->k_ctx->fs->journal_io;
+		io = kdev->k_fs->journal_io;
 
 	return io_channel_flush(io) ? -EIO : 0;
 }
@@ -120,7 +121,7 @@ void ll_rw_block(int rw, int op_flags EXT2FS_ATTR((unused)), int nr,
 						     bh->b_blocknr,
 						     1, bh->b_data);
 			if (retval) {
-				com_err(bh->b_ctx->device_name, retval,
+				com_err(bh->b_fs->device_name, retval,
 					"while reading block %llu\n",
 					bh->b_blocknr);
 				bh->b_err = (int) retval;
@@ -135,7 +136,7 @@ void ll_rw_block(int rw, int op_flags EXT2FS_ATTR((unused)), int nr,
 						      bh->b_blocknr,
 						      1, bh->b_data);
 			if (retval) {
-				com_err(bh->b_ctx->device_name, retval,
+				com_err(bh->b_fs->device_name, retval,
 					"while writing block %llu\n",
 					bh->b_blocknr);
 				bh->b_err = (int) retval;
@@ -223,7 +224,7 @@ static int process_journal_block(ext2_filsys fs,
 static int ext4_fc_replay_scan(journal_t *j, struct buffer_head *bh,
 				int off, tid_t expected_tid)
 {
-	e2fsck_t ctx = j->j_fs_dev->k_ctx;
+	e2fsck_t ctx = j->j_ctx;
 	struct e2fsck_fc_replay_state *state;
 	int ret = JBD2_FC_REPLAY_CONTINUE;
 	struct ext4_fc_add_range ext;
@@ -796,7 +797,7 @@ static int ext4_fc_handle_del_range(e2fsck_t ctx, __u8 *val)
 static int ext4_fc_replay(journal_t *journal, struct buffer_head *bh,
 				enum passtype pass, int off, tid_t expected_tid)
 {
-	e2fsck_t ctx = journal->j_fs_dev->k_ctx;
+	e2fsck_t ctx = journal->j_ctx;
 	struct e2fsck_fc_replay_state *state = &ctx->fc_replay_state;
 	int ret = JBD2_FC_REPLAY_CONTINUE;
 	struct ext4_fc_tl tl;
@@ -924,10 +925,11 @@ static errcode_t e2fsck_get_journal(e2fsck_t ctx, journal_t **ret_journal)
 	}
 	dev_journal = dev_fs+1;
 
-	dev_fs->k_ctx = dev_journal->k_ctx = ctx;
+	dev_fs->k_fs = dev_journal->k_fs = ctx->fs;
 	dev_fs->k_dev = K_DEV_FS;
 	dev_journal->k_dev = K_DEV_JOURNAL;
 
+	journal->j_ctx = ctx;
 	journal->j_dev = dev_journal;
 	journal->j_fs_dev = dev_fs;
 	journal->j_inode = NULL;
@@ -945,7 +947,7 @@ static errcode_t e2fsck_get_journal(e2fsck_t ctx, journal_t **ret_journal)
 			goto errout;
 		}
 
-		j_inode->i_ctx = ctx;
+		j_inode->i_fs = ctx->fs;
 		j_inode->i_ino = sb->s_journal_inum;
 
 		if ((retval = ext2fs_read_inode(ctx->fs,
@@ -1186,9 +1188,8 @@ static errcode_t e2fsck_journal_fix_bad_inode(e2fsck_t ctx,
 }
 
 #define V1_SB_SIZE	0x0024
-static void clear_v2_journal_fields(journal_t *journal)
+static void clear_v2_journal_fields(e2fsck_t ctx, journal_t *journal)
 {
-	e2fsck_t ctx = journal->j_dev->k_ctx;
 	struct problem_context pctx;
 
 	clear_problem_context(&pctx);
@@ -1203,9 +1204,8 @@ static void clear_v2_journal_fields(journal_t *journal)
 }
 
 
-static errcode_t e2fsck_journal_load(journal_t *journal)
+static errcode_t e2fsck_journal_load(e2fsck_t ctx, journal_t *journal)
 {
-	e2fsck_t ctx = journal->j_dev->k_ctx;
 	journal_superblock_t *jsb;
 	struct buffer_head *jbh = journal->j_sb_buffer;
 	struct problem_context pctx;
@@ -1231,14 +1231,14 @@ static errcode_t e2fsck_journal_load(journal_t *journal)
 		    jsb->s_feature_incompat ||
 		    jsb->s_feature_ro_compat ||
 		    jsb->s_nr_users)
-			clear_v2_journal_fields(journal);
+			clear_v2_journal_fields(ctx, journal);
 		break;
 
 	case JBD2_SUPERBLOCK_V2:
 		journal->j_format_version = 2;
 		if (ntohl(jsb->s_nr_users) > 1 &&
 		    uuid_is_null(ctx->fs->super->s_journal_uuid))
-			clear_v2_journal_fields(journal);
+			clear_v2_journal_fields(ctx, journal);
 		if (ntohl(jsb->s_nr_users) > 1) {
 			fix_problem(ctx, PR_0_JOURNAL_UNSUPP_MULTIFS, &pctx);
 			return EXT2_ET_JOURNAL_UNSUPP_VERSION;
@@ -1425,7 +1425,7 @@ errcode_t e2fsck_check_ext3_journal(e2fsck_t ctx)
 		return retval;
 	}
 
-	retval = e2fsck_journal_load(journal);
+	retval = e2fsck_journal_load(ctx, journal);
 	if (retval) {
 		if ((retval == EXT2_ET_CORRUPT_JOURNAL_SB) ||
 		    ((retval == EXT2_ET_UNSUPP_FEATURE) &&
@@ -1543,7 +1543,7 @@ static errcode_t recover_ext3_journal(e2fsck_t ctx)
 	if (retval)
 		return retval;
 
-	retval = e2fsck_journal_load(journal);
+	retval = e2fsck_journal_load(ctx, journal);
 	if (retval)
 		goto errout;
 
diff --git a/lib/ext2fs/jfs_compat.h b/lib/ext2fs/jfs_compat.h
index e11cf494..bfafae12 100644
--- a/lib/ext2fs/jfs_compat.h
+++ b/lib/ext2fs/jfs_compat.h
@@ -41,6 +41,7 @@ typedef struct kdev_s *kdev_t;
 
 struct buffer_head;
 struct inode;
+struct e2fsck_struct;
 
 typedef unsigned int gfp_t;
 #define GFP_KERNEL	0
@@ -98,6 +99,7 @@ struct journal_s
 	struct jbd2_revoke_table_s *j_revoke_table[2];
 	tid_t			j_failed_commit;
 	__u32			j_csum_seed;
+	struct e2fsck_struct *	j_ctx;
 	int (*j_fc_replay_callback)(struct journal_s *journal,
 				    struct buffer_head *bh,
 				    enum passtype pass, int off,
diff --git a/lib/support/jfs_user.h b/lib/support/jfs_user.h
index b9c2fa54..bb392811 100644
--- a/lib/support/jfs_user.h
+++ b/lib/support/jfs_user.h
@@ -40,11 +40,7 @@
 #endif
 
 struct buffer_head {
-#ifdef DEBUGFS
 	ext2_filsys	b_fs;
-#else
-	e2fsck_t	b_ctx;
-#endif
 	io_channel	b_io;
 	int		b_size;
 	int		b_err;
@@ -55,21 +51,13 @@ struct buffer_head {
 };
 
 struct inode {
-#ifdef DEBUGFS
 	ext2_filsys	i_fs;
-#else
-	e2fsck_t	i_ctx;
-#endif
 	ext2_ino_t	i_ino;
 	struct ext2_inode i_ext2;
 };
 
 struct kdev_s {
-#ifdef DEBUGFS
 	ext2_filsys	k_fs;
-#else
-	e2fsck_t	k_ctx;
-#endif
 	int		k_dev;
 };
 
-- 
2.31.1
^ permalink raw reply related	[flat|nested] 11+ messages in thread
* [PATCH 5/5] deduplicate a buffer_head / kernel device code.
  2022-08-04  9:56 [PATCH 1/5] move a jfs_user.h to better place Alexey Lyashkov
                   ` (2 preceding siblings ...)
  2022-08-04  9:56 ` [PATCH 4/5] remove an e2fsck context from bh emulation code Alexey Lyashkov
@ 2022-08-04  9:56 ` Alexey Lyashkov
  2023-09-19  0:04   ` Andreas Dilger
  2023-09-18 23:06 ` [PATCH 1/5] move a jfs_user.h to better place Andreas Dilger
  4 siblings, 1 reply; 11+ messages in thread
From: Alexey Lyashkov @ 2022-08-04  9:56 UTC (permalink / raw)
  To: linux-ext4, Theodore Ts'o, Andreas Dilger, Artem Blagodarenko
  Cc: Alexey Lyashkov
move a buffer_head and device code into libsupport.
---
 debugfs/journal.c      | 147 -----------------------------------------
 e2fsck/journal.c       | 143 ---------------------------------------
 lib/support/jfs_user.c | 142 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 142 insertions(+), 290 deletions(-)
diff --git a/debugfs/journal.c b/debugfs/journal.c
index 202312fe..510a0acb 100644
--- a/debugfs/journal.c
+++ b/debugfs/journal.c
@@ -26,8 +26,6 @@
 #include "uuid/uuid.h"
 #include "journal.h"
 
-static int bh_count = 0;
-
 #if EXT2_FLAT_INCLUDES
 #include "blkid.h"
 #else
@@ -47,151 +45,6 @@ static int bh_count = 0;
  * to use the recovery.c file virtually unchanged from the kernel, so we
  * don't have to do much to keep kernel and user recovery in sync.
  */
-int jbd2_journal_bmap(journal_t *journal, unsigned long block,
-		      unsigned long long *phys)
-{
-#ifdef USE_INODE_IO
-	*phys = block;
-	return 0;
-#else
-	struct inode	*inode = journal->j_inode;
-	errcode_t	retval;
-	blk64_t		pblk;
-
-	if (!inode) {
-		*phys = block;
-		return 0;
-	}
-
-	retval = ext2fs_bmap2(inode->i_fs, inode->i_ino,
-			      &inode->i_ext2, NULL, 0, (blk64_t) block,
-			      0, &pblk);
-	*phys = pblk;
-	return (int) retval;
-#endif
-}
-
-struct buffer_head *getblk(kdev_t kdev, unsigned long long blocknr,
-			   int blocksize)
-{
-	struct buffer_head *bh;
-	int bufsize = sizeof(*bh) + kdev->k_fs->blocksize -
-		sizeof(bh->b_data);
-	errcode_t retval;
-
-	retval = ext2fs_get_memzero(bufsize, &bh);
-	if (retval)
-		return NULL;
-
-	if (journal_enable_debug >= 3)
-		bh_count++;
-	jfs_debug(4, "getblk for block %llu (%d bytes)(total %d)\n",
-		  blocknr, blocksize, bh_count);
-
-	bh->b_fs = kdev->k_fs;
-	if (kdev->k_dev == K_DEV_FS)
-		bh->b_io = kdev->k_fs->io;
-	else
-		bh->b_io = kdev->k_fs->journal_io;
-	bh->b_size = blocksize;
-	bh->b_blocknr = blocknr;
-
-	return bh;
-}
-
-int sync_blockdev(kdev_t kdev)
-{
-	io_channel	io;
-
-	if (kdev->k_dev == K_DEV_FS)
-		io = kdev->k_fs->io;
-	else
-		io = kdev->k_fs->journal_io;
-
-	return io_channel_flush(io) ? EIO : 0;
-}
-
-void ll_rw_block(int rw, int op_flags EXT2FS_ATTR((unused)), int nr,
-		 struct buffer_head *bhp[])
-{
-	errcode_t retval;
-	struct buffer_head *bh;
-
-	for (; nr > 0; --nr) {
-		bh = *bhp++;
-		if (rw == REQ_OP_READ && !bh->b_uptodate) {
-			jfs_debug(3, "reading block %llu/%p\n",
-				  bh->b_blocknr, (void *) bh);
-			retval = io_channel_read_blk64(bh->b_io,
-						     bh->b_blocknr,
-						     1, bh->b_data);
-			if (retval) {
-				com_err(bh->b_fs->device_name, retval,
-					"while reading block %llu\n",
-					bh->b_blocknr);
-				bh->b_err = (int) retval;
-				continue;
-			}
-			bh->b_uptodate = 1;
-		} else if (rw == REQ_OP_WRITE && bh->b_dirty) {
-			jfs_debug(3, "writing block %llu/%p\n",
-				  bh->b_blocknr,
-				  (void *) bh);
-			retval = io_channel_write_blk64(bh->b_io,
-						      bh->b_blocknr,
-						      1, bh->b_data);
-			if (retval) {
-				com_err(bh->b_fs->device_name, retval,
-					"while writing block %llu\n",
-					bh->b_blocknr);
-				bh->b_err = (int) retval;
-				continue;
-			}
-			bh->b_dirty = 0;
-			bh->b_uptodate = 1;
-		} else {
-			jfs_debug(3, "no-op %s for block %llu\n",
-				  rw == REQ_OP_READ ? "read" : "write",
-				  bh->b_blocknr);
-		}
-	}
-}
-
-void mark_buffer_dirty(struct buffer_head *bh)
-{
-	bh->b_dirty = 1;
-}
-
-static void mark_buffer_clean(struct buffer_head *bh)
-{
-	bh->b_dirty = 0;
-}
-
-void brelse(struct buffer_head *bh)
-{
-	if (bh->b_dirty)
-		ll_rw_block(REQ_OP_WRITE, 0, 1, &bh);
-	jfs_debug(3, "freeing block %llu/%p (total %d)\n",
-		  bh->b_blocknr, (void *) bh, --bh_count);
-	ext2fs_free_mem(&bh);
-}
-
-int buffer_uptodate(struct buffer_head *bh)
-{
-	return bh->b_uptodate;
-}
-
-void mark_buffer_uptodate(struct buffer_head *bh, int val)
-{
-	bh->b_uptodate = val;
-}
-
-void wait_on_buffer(struct buffer_head *bh)
-{
-	if (!bh->b_uptodate)
-		ll_rw_block(REQ_OP_READ, 0, 1, &bh);
-}
-
 
 static void ext2fs_clear_recover(ext2_filsys fs, int error)
 {
diff --git a/e2fsck/journal.c b/e2fsck/journal.c
index 728f5a24..9ff1dc94 100644
--- a/e2fsck/journal.c
+++ b/e2fsck/journal.c
@@ -27,8 +27,6 @@
 #include "problem.h"
 #include "uuid/uuid.h"
 
-static int bh_count = 0;
-
 /*
  * Define USE_INODE_IO to use the inode_io.c / fileio.c codepaths.
  * This creates a larger static binary, and a smaller binary using
@@ -42,147 +40,6 @@ static int bh_count = 0;
  * to use the recovery.c file virtually unchanged from the kernel, so we
  * don't have to do much to keep kernel and user recovery in sync.
  */
-int jbd2_journal_bmap(journal_t *journal, unsigned long block,
-		      unsigned long long *phys)
-{
-#ifdef USE_INODE_IO
-	*phys = block;
-	return 0;
-#else
-	struct inode 	*inode = journal->j_inode;
-	errcode_t	retval;
-	blk64_t		pblk;
-
-	if (!inode) {
-		*phys = block;
-		return 0;
-	}
-
-	retval= ext2fs_bmap2(inode->i_fs, inode->i_ino,
-			     &inode->i_ext2, NULL, 0, (blk64_t) block,
-			     0, &pblk);
-	*phys = pblk;
-	return -1 * ((int) retval);
-#endif
-}
-
-struct buffer_head *getblk(kdev_t kdev, unsigned long long blocknr,
-			   int blocksize)
-{
-	struct buffer_head *bh;
-	int bufsize = sizeof(*bh) + kdev->k_fs->blocksize -
-		sizeof(bh->b_data);
-	errcode_t retval;
-
-	retval = ext2fs_get_memzero(bufsize, &bh);
-	if (retval)
-		return NULL;
-
-	if (journal_enable_debug >= 3)
-		bh_count++;
-	jfs_debug(4, "getblk for block %llu (%d bytes)(total %d)\n",
-		  blocknr, blocksize, bh_count);
-
-	bh->b_fs = kdev->k_fs;
-	if (kdev->k_dev == K_DEV_FS)
-		bh->b_io = kdev->k_fs->io;
-	else
-		bh->b_io = kdev->k_fs->journal_io;
-	bh->b_size = blocksize;
-	bh->b_blocknr = blocknr;
-
-	return bh;
-}
-
-int sync_blockdev(kdev_t kdev)
-{
-	io_channel	io;
-
-	if (kdev->k_dev == K_DEV_FS)
-		io = kdev->k_fs->io;
-	else
-		io = kdev->k_fs->journal_io;
-
-	return io_channel_flush(io) ? -EIO : 0;
-}
-
-void ll_rw_block(int rw, int op_flags EXT2FS_ATTR((unused)), int nr,
-		 struct buffer_head *bhp[])
-{
-	errcode_t retval;
-	struct buffer_head *bh;
-
-	for (; nr > 0; --nr) {
-		bh = *bhp++;
-		if (rw == REQ_OP_READ && !bh->b_uptodate) {
-			jfs_debug(3, "reading block %llu/%p\n",
-				  bh->b_blocknr, (void *) bh);
-			retval = io_channel_read_blk64(bh->b_io,
-						     bh->b_blocknr,
-						     1, bh->b_data);
-			if (retval) {
-				com_err(bh->b_fs->device_name, retval,
-					"while reading block %llu\n",
-					bh->b_blocknr);
-				bh->b_err = (int) retval;
-				continue;
-			}
-			bh->b_uptodate = 1;
-		} else if (rw == REQ_OP_WRITE && bh->b_dirty) {
-			jfs_debug(3, "writing block %llu/%p\n",
-				  bh->b_blocknr,
-				  (void *) bh);
-			retval = io_channel_write_blk64(bh->b_io,
-						      bh->b_blocknr,
-						      1, bh->b_data);
-			if (retval) {
-				com_err(bh->b_fs->device_name, retval,
-					"while writing block %llu\n",
-					bh->b_blocknr);
-				bh->b_err = (int) retval;
-				continue;
-			}
-			bh->b_dirty = 0;
-			bh->b_uptodate = 1;
-		} else {
-			jfs_debug(3, "no-op %s for block %llu\n",
-				  rw == REQ_OP_READ ? "read" : "write",
-				  bh->b_blocknr);
-		}
-	}
-}
-
-void mark_buffer_dirty(struct buffer_head *bh)
-{
-	bh->b_dirty = 1;
-}
-
-void brelse(struct buffer_head *bh)
-{
-	if (bh->b_dirty)
-		ll_rw_block(REQ_OP_WRITE, 0, 1, &bh);
-	jfs_debug(3, "freeing block %llu/%p (total %d)\n",
-		  bh->b_blocknr, (void *) bh, --bh_count);
-	ext2fs_free_mem(&bh);
-}
-
-int buffer_uptodate(struct buffer_head *bh)
-{
-	return bh->b_uptodate;
-}
-
-void mark_buffer_uptodate(struct buffer_head *bh, int val)
-{
-	bh->b_uptodate = val;
-}
-
-void wait_on_buffer(struct buffer_head *bh)
-{
-	if (!bh->b_uptodate)
-		ll_rw_block(REQ_OP_READ, 0, 1, &bh);
-}
-
-
 static void e2fsck_clear_recover(e2fsck_t ctx, int error)
 {
 	ext2fs_clear_feature_journal_needs_recovery(ctx->fs->super);
diff --git a/lib/support/jfs_user.c b/lib/support/jfs_user.c
index d8a2f842..26f0090b 100644
--- a/lib/support/jfs_user.c
+++ b/lib/support/jfs_user.c
@@ -1,6 +1,8 @@
 #define DEBUGFS
 #include "jfs_user.h"
 
+static int bh_count = 0;
+
 /*
  * Define USE_INODE_IO to use the inode_io.c / fileio.c codepaths.
  * This creates a larger static binary, and a smaller binary using
@@ -60,12 +62,116 @@ errcode_t ext2fs_journal_sb_csum_set(journal_t *j,
 	return 0;
 }
 
+void mark_buffer_dirty(struct buffer_head *bh)
+{
+	bh->b_dirty = 1;
+}
+
+int buffer_uptodate(struct buffer_head *bh)
+{
+	return bh->b_uptodate;
+}
+
+void mark_buffer_uptodate(struct buffer_head *bh, int val)
+{
+	bh->b_uptodate = val;
+}
+
+void wait_on_buffer(struct buffer_head *bh)
+{
+	if (!bh->b_uptodate)
+		ll_rw_block(REQ_OP_READ, 0, 1, &bh);
+}
 
 static void mark_buffer_clean(struct buffer_head * bh)
 {
 	bh->b_dirty = 0;
 }
 
+struct buffer_head *getblk(kdev_t kdev, unsigned long long blocknr,
+			   int blocksize)
+{
+	struct buffer_head *bh;
+	int bufsize = sizeof(*bh) + kdev->k_fs->blocksize -
+		sizeof(bh->b_data);
+	errcode_t retval;
+
+	retval = ext2fs_get_memzero(bufsize, &bh);
+	if (retval)
+		return NULL;
+
+	if (journal_enable_debug >= 3)
+		bh_count++;
+	jfs_debug(4, "getblk for block %llu (%d bytes)(total %d)\n",
+		  blocknr, blocksize, bh_count);
+
+	bh->b_fs = kdev->k_fs;
+	if (kdev->k_dev == K_DEV_FS)
+		bh->b_io = kdev->k_fs->io;
+	else
+		bh->b_io = kdev->k_fs->journal_io;
+	bh->b_size = blocksize;
+	bh->b_blocknr = blocknr;
+
+	return bh;
+}
+
+void brelse(struct buffer_head *bh)
+{
+	if (bh->b_dirty)
+		ll_rw_block(REQ_OP_WRITE, 0, 1, &bh);
+	jfs_debug(3, "freeing block %llu/%p (total %d)\n",
+		  bh->b_blocknr, (void *) bh, --bh_count);
+	ext2fs_free_mem(&bh);
+}
+
+void ll_rw_block(int rw, int op_flags EXT2FS_ATTR((unused)), int nr,
+		 struct buffer_head *bhp[])
+{
+	errcode_t retval;
+	struct buffer_head *bh;
+
+	for (; nr > 0; --nr) {
+		bh = *bhp++;
+		if (rw == REQ_OP_READ && !bh->b_uptodate) {
+			jfs_debug(3, "reading block %llu/%p\n",
+				  bh->b_blocknr, (void *) bh);
+			retval = io_channel_read_blk64(bh->b_io,
+						     bh->b_blocknr,
+						     1, bh->b_data);
+			if (retval) {
+				com_err(bh->b_fs->device_name, retval,
+					"while reading block %llu\n",
+					bh->b_blocknr);
+				bh->b_err = (int) retval;
+				continue;
+			}
+			bh->b_uptodate = 1;
+		} else if (rw == REQ_OP_WRITE && bh->b_dirty) {
+			jfs_debug(3, "writing block %llu/%p\n",
+				  bh->b_blocknr,
+				  (void *) bh);
+			retval = io_channel_write_blk64(bh->b_io,
+						      bh->b_blocknr,
+						      1, bh->b_data);
+			if (retval) {
+				com_err(bh->b_fs->device_name, retval,
+					"while writing block %llu\n",
+					bh->b_blocknr);
+				bh->b_err = (int) retval;
+				continue;
+			}
+			bh->b_dirty = 0;
+			bh->b_uptodate = 1;
+		} else {
+			jfs_debug(3, "no-op %s for block %llu\n",
+				  rw == REQ_OP_READ ? "read" : "write",
+				  bh->b_blocknr);
+		}
+	}
+}
+
+
 void ext2fs_journal_release(ext2_filsys fs, journal_t *journal,
 			    int reset, int drop)
 {
@@ -99,3 +205,39 @@ void ext2fs_journal_release(ext2_filsys fs, journal_t *journal,
 		ext2fs_free_mem(&journal->j_fs_dev);
 	ext2fs_free_mem(&journal);
 }
+
+int jbd2_journal_bmap(journal_t *journal, unsigned long block,
+		      unsigned long long *phys)
+{
+#ifdef USE_INODE_IO
+	*phys = block;
+	return 0;
+#else
+	struct inode	*inode = journal->j_inode;
+	errcode_t	retval;
+	blk64_t		pblk;
+
+	if (!inode) {
+		*phys = block;
+		return 0;
+	}
+
+	retval = ext2fs_bmap2(inode->i_fs, inode->i_ino,
+			      &inode->i_ext2, NULL, 0, (blk64_t) block,
+			      0, &pblk);
+	*phys = pblk;
+	return (int) retval;
+#endif
+}
+
+int sync_blockdev(kdev_t kdev)
+{
+	io_channel	io;
+
+	if (kdev->k_dev == K_DEV_FS)
+		io = kdev->k_fs->io;
+	else
+		io = kdev->k_fs->journal_io;
+
+	return io_channel_flush(io) ? EIO : 0;
+}
-- 
2.31.1
^ permalink raw reply related	[flat|nested] 11+ messages in thread
* Re: [PATCH 1/5] move a jfs_user.h to better place.
  2022-08-04  9:56 [PATCH 1/5] move a jfs_user.h to better place Alexey Lyashkov
                   ` (3 preceding siblings ...)
  2022-08-04  9:56 ` [PATCH 5/5] deduplicate a buffer_head / kernel device code Alexey Lyashkov
@ 2023-09-18 23:06 ` Andreas Dilger
  2023-09-21 14:19   ` Alexey Lyahkov
  4 siblings, 1 reply; 11+ messages in thread
From: Andreas Dilger @ 2023-09-18 23:06 UTC (permalink / raw)
  To: Alexey Lyashkov
  Cc: Ext4 Developers List, Theodore Ts'o, Artem Blagodarenko
[-- Attachment #1: Type: text/plain, Size: 17588 bytes --]
On Aug 4, 2022, at 3:56 AM, Alexey Lyashkov <alexey.lyashkov@gmail.com> wrote:
> 
> jfs_user.h used in the debugfs and e2fsck, so
> libsupport is better place for it.
> just move a header into new place.
Alexey, this patch is missing a Signed-off-by: line.
The only other suggestion I would have is to rename the new file
"jbd2_user.h" since the "jfs" filesystem name is conflicting.
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
> ---
> debugfs/Makefile.in                | 16 +++++++---------
> debugfs/debugfs.c                  |  2 +-
> debugfs/journal.h                  |  2 +-
> debugfs/logdump.c                  |  2 +-
> e2fsck/Makefile.in                 |  8 ++++----
> e2fsck/journal.c                   |  2 +-
> e2fsck/recovery.c                  |  2 +-
> e2fsck/revoke.c                    |  2 +-
> e2fsck/unix.c                      |  2 +-
> lib/ext2fs/Makefile.in             | 18 ++++++++----------
> {e2fsck => lib/support}/jfs_user.h |  0
> misc/Makefile.in                   | 12 +++++-------
> 12 files changed, 31 insertions(+), 37 deletions(-)
> rename {e2fsck => lib/support}/jfs_user.h (100%)
> 
> diff --git a/debugfs/Makefile.in b/debugfs/Makefile.in
> index ed4ea8d8..33658eea 100644
> --- a/debugfs/Makefile.in
> +++ b/debugfs/Makefile.in
> @@ -47,9 +47,7 @@ STATIC_DEPLIBS= $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBSS) \
> 		$(DEPSTATIC_LIBCOM_ERR) $(DEPSTATIC_LIBUUID) \
> 		$(DEPSTATIC_LIBE2P)
> 
> -# This nastiness is needed because of jfs_user.h hackery; when we finally
> -# clean up this mess, we should be able to drop it
> -LOCAL_CFLAGS = -I$(srcdir)/../e2fsck -DDEBUGFS
> +LOCAL_CFLAGS = -DDEBUGFS
> DEPEND_CFLAGS = -I$(srcdir)
> 
> .c.o:
> @@ -186,7 +184,7 @@ debugfs.o: $(srcdir)/debugfs.c $(top_builddir)/lib/config.h \
>  $(top_srcdir)/lib/e2p/e2p.h $(top_srcdir)/lib/support/quotaio.h \
>  $(top_srcdir)/lib/support/dqblk_v2.h \
>  $(top_srcdir)/lib/support/quotaio_tree.h $(top_srcdir)/version.h \
> - $(srcdir)/../e2fsck/jfs_user.h $(top_srcdir)/lib/ext2fs/kernel-jbd.h \
> + $(top_srcdir)/lib/support/jfs_user.h $(top_srcdir)/lib/ext2fs/kernel-jbd.h \
>  $(top_srcdir)/lib/ext2fs/jfs_compat.h $(top_srcdir)/lib/ext2fs/kernel-list.h \
>  $(top_srcdir)/lib/ext2fs/compiler.h $(top_srcdir)/lib/support/plausible.h
> util.o: $(srcdir)/util.c $(top_builddir)/lib/config.h \
> @@ -277,7 +275,7 @@ logdump.o: $(srcdir)/logdump.c $(top_builddir)/lib/config.h \
>  $(top_srcdir)/lib/ext2fs/bitops.h $(srcdir)/../misc/create_inode.h \
>  $(top_srcdir)/lib/e2p/e2p.h $(top_srcdir)/lib/support/quotaio.h \
>  $(top_srcdir)/lib/support/dqblk_v2.h \
> - $(top_srcdir)/lib/support/quotaio_tree.h $(srcdir)/../e2fsck/jfs_user.h \
> + $(top_srcdir)/lib/support/quotaio_tree.h $(top_srcdir)/lib/support/jfs_user.h \
>  $(top_srcdir)/lib/ext2fs/kernel-jbd.h $(top_srcdir)/lib/ext2fs/jfs_compat.h \
>  $(top_srcdir)/lib/ext2fs/kernel-list.h $(top_srcdir)/lib/ext2fs/compiler.h \
>  $(top_srcdir)/lib/ext2fs/fast_commit.h
> @@ -382,7 +380,7 @@ quota.o: $(srcdir)/quota.c $(top_builddir)/lib/config.h \
>  $(top_srcdir)/lib/support/quotaio_tree.h
> journal.o: $(srcdir)/journal.c $(top_builddir)/lib/config.h \
>  $(top_builddir)/lib/dirpaths.h $(srcdir)/journal.h \
> - $(srcdir)/../e2fsck/jfs_user.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \
> + $(top_srcdir)/lib/support/jfs_user.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \
>  $(top_builddir)/lib/ext2fs/ext2_types.h $(top_srcdir)/lib/ext2fs/ext2fs.h \
>  $(top_srcdir)/lib/ext2fs/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \
>  $(top_srcdir)/lib/ext2fs/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \
> @@ -390,7 +388,7 @@ journal.o: $(srcdir)/journal.c $(top_builddir)/lib/config.h \
>  $(top_srcdir)/lib/ext2fs/bitops.h $(top_srcdir)/lib/ext2fs/kernel-jbd.h \
>  $(top_srcdir)/lib/ext2fs/jfs_compat.h $(top_srcdir)/lib/ext2fs/kernel-list.h \
>  $(top_srcdir)/lib/ext2fs/compiler.h
> -revoke.o: $(srcdir)/../e2fsck/revoke.c $(srcdir)/../e2fsck/jfs_user.h \
> +revoke.o: $(srcdir)/../e2fsck/revoke.c $(top_srcdir)/lib/support/jfs_user.h \
>  $(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h \
>  $(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/lib/ext2fs/ext3_extents.h \
>  $(top_srcdir)/lib/et/com_err.h $(top_srcdir)/lib/ext2fs/ext2_io.h \
> @@ -399,7 +397,7 @@ revoke.o: $(srcdir)/../e2fsck/revoke.c $(srcdir)/../e2fsck/jfs_user.h \
>  $(top_srcdir)/lib/ext2fs/bitops.h $(top_srcdir)/lib/ext2fs/kernel-jbd.h \
>  $(top_srcdir)/lib/ext2fs/jfs_compat.h $(top_srcdir)/lib/ext2fs/kernel-list.h \
>  $(top_srcdir)/lib/ext2fs/compiler.h
> -recovery.o: $(srcdir)/../e2fsck/recovery.c $(srcdir)/../e2fsck/jfs_user.h \
> +recovery.o: $(srcdir)/../e2fsck/recovery.c $(top_srcdir)/lib/support/jfs_user.h \
>  $(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h \
>  $(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/lib/ext2fs/ext3_extents.h \
>  $(top_srcdir)/lib/et/com_err.h $(top_srcdir)/lib/ext2fs/ext2_io.h \
> @@ -421,4 +419,4 @@ do_journal.o: $(srcdir)/do_journal.c $(top_builddir)/lib/config.h \
>  $(top_srcdir)/lib/support/quotaio_tree.h \
>  $(top_srcdir)/lib/ext2fs/kernel-jbd.h $(top_srcdir)/lib/ext2fs/jfs_compat.h \
>  $(top_srcdir)/lib/ext2fs/kernel-list.h $(top_srcdir)/lib/ext2fs/compiler.h \
> - $(srcdir)/journal.h $(srcdir)/../e2fsck/jfs_user.h
> + $(srcdir)/journal.h $(top_srcdir)/lib/support/jfs_user.h
> diff --git a/debugfs/debugfs.c b/debugfs/debugfs.c
> index b67a88bc..00b261ac 100644
> --- a/debugfs/debugfs.c
> +++ b/debugfs/debugfs.c
> @@ -37,7 +37,7 @@ extern char *optarg;
> #include <ext2fs/ext2_ext_attr.h>
> 
> #include "../version.h"
> -#include "jfs_user.h"
> +#include "support/jfs_user.h"
> #include "support/plausible.h"
> 
> #ifndef BUFSIZ
> diff --git a/debugfs/journal.h b/debugfs/journal.h
> index 10b638eb..4d889834 100644
> --- a/debugfs/journal.h
> +++ b/debugfs/journal.h
> @@ -12,7 +12,7 @@
>  * any later version.
>  */
> 
> -#include "jfs_user.h"
> +#include "support/jfs_user.h"
> 
> /* journal.c */
> errcode_t ext2fs_open_journal(ext2_filsys fs, journal_t **j);
> diff --git a/debugfs/logdump.c b/debugfs/logdump.c
> index 4154ef2a..f5427d5c 100644
> --- a/debugfs/logdump.c
> +++ b/debugfs/logdump.c
> @@ -32,7 +32,7 @@ extern char *optarg;
> 
> #include "debugfs.h"
> #include "blkid/blkid.h"
> -#include "jfs_user.h"
> +#include "support/jfs_user.h"
> #if __GNUC_PREREQ (4, 6)
> #pragma GCC diagnostic push
> #pragma GCC diagnostic ignored "-Wunused-function"
> diff --git a/e2fsck/Makefile.in b/e2fsck/Makefile.in
> index 71ac3cf5..a6e11417 100644
> --- a/e2fsck/Makefile.in
> +++ b/e2fsck/Makefile.in
> @@ -383,7 +383,7 @@ pass5.o: $(srcdir)/pass5.c $(top_builddir)/lib/config.h \
>  $(top_srcdir)/lib/ext2fs/kernel-list.h $(top_srcdir)/lib/ext2fs/compiler.h \
>  $(srcdir)/problem.h
> journal.o: $(srcdir)/journal.c $(top_builddir)/lib/config.h \
> - $(top_builddir)/lib/dirpaths.h $(srcdir)/jfs_user.h $(srcdir)/e2fsck.h \
> + $(top_builddir)/lib/dirpaths.h $(top_srcdir)/lib/support/jfs_user.h $(srcdir)/e2fsck.h \
>  $(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h \
>  $(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/lib/ext2fs/ext3_extents.h \
>  $(top_srcdir)/lib/et/com_err.h $(top_srcdir)/lib/ext2fs/ext2_io.h \
> @@ -396,7 +396,7 @@ journal.o: $(srcdir)/journal.c $(top_builddir)/lib/config.h \
>  $(top_srcdir)/lib/ext2fs/fast_commit.h $(top_srcdir)/lib/ext2fs/jfs_compat.h \
>  $(top_srcdir)/lib/ext2fs/kernel-list.h $(top_srcdir)/lib/ext2fs/compiler.h \
>  $(top_srcdir)/lib/ext2fs/kernel-jbd.h $(srcdir)/problem.h
> -recovery.o: $(srcdir)/recovery.c $(srcdir)/jfs_user.h \
> +recovery.o: $(srcdir)/recovery.c $(top_srcdir)/lib/support/jfs_user.h \
>  $(top_builddir)/lib/config.h $(top_builddir)/lib/dirpaths.h \
>  $(srcdir)/e2fsck.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \
>  $(top_builddir)/lib/ext2fs/ext2_types.h $(top_srcdir)/lib/ext2fs/ext2fs.h \
> @@ -410,7 +410,7 @@ recovery.o: $(srcdir)/recovery.c $(srcdir)/jfs_user.h \
>  $(top_srcdir)/lib/ext2fs/fast_commit.h $(top_srcdir)/lib/ext2fs/jfs_compat.h \
>  $(top_srcdir)/lib/ext2fs/kernel-list.h $(top_srcdir)/lib/ext2fs/compiler.h \
>  $(top_srcdir)/lib/ext2fs/kernel-jbd.h
> -revoke.o: $(srcdir)/revoke.c $(srcdir)/jfs_user.h \
> +revoke.o: $(srcdir)/revoke.c $(top_srcdir)/lib/support/jfs_user.h \
>  $(top_builddir)/lib/config.h $(top_builddir)/lib/dirpaths.h \
>  $(srcdir)/e2fsck.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \
>  $(top_builddir)/lib/ext2fs/ext2_types.h $(top_srcdir)/lib/ext2fs/ext2fs.h \
> @@ -464,7 +464,7 @@ unix.o: $(srcdir)/unix.c $(top_builddir)/lib/config.h \
>  $(top_srcdir)/lib/support/quotaio_tree.h \
>  $(top_srcdir)/lib/ext2fs/fast_commit.h $(top_srcdir)/lib/ext2fs/jfs_compat.h \
>  $(top_srcdir)/lib/ext2fs/kernel-list.h $(top_srcdir)/lib/ext2fs/compiler.h \
> - $(srcdir)/problem.h $(srcdir)/jfs_user.h \
> + $(srcdir)/problem.h $(top_srcdir)/lib/support/jfs_user.h \
>  $(top_srcdir)/lib/ext2fs/kernel-jbd.h $(top_srcdir)/version.h
> dirinfo.o: $(srcdir)/dirinfo.c $(top_builddir)/lib/config.h \
>  $(top_builddir)/lib/dirpaths.h $(srcdir)/e2fsck.h \
> diff --git a/e2fsck/journal.c b/e2fsck/journal.c
> index 2e867234..d3002a62 100644
> --- a/e2fsck/journal.c
> +++ b/e2fsck/journal.c
> @@ -23,7 +23,7 @@
> #endif
> 
> #define E2FSCK_INCLUDE_INLINE_FUNCS
> -#include "jfs_user.h"
> +#include "support/jfs_user.h"
> #include "problem.h"
> #include "uuid/uuid.h"
> 
> diff --git a/e2fsck/recovery.c b/e2fsck/recovery.c
> index 8ca35271..c7328cc5 100644
> --- a/e2fsck/recovery.c
> +++ b/e2fsck/recovery.c
> @@ -11,7 +11,7 @@
>  */
> 
> #ifndef __KERNEL__
> -#include "jfs_user.h"
> +#include "support/jfs_user.h"
> #else
> #include <linux/time.h>
> #include <linux/fs.h>
> diff --git a/e2fsck/revoke.c b/e2fsck/revoke.c
> index fa608788..1d5f910b 100644
> --- a/e2fsck/revoke.c
> +++ b/e2fsck/revoke.c
> @@ -78,7 +78,7 @@
>  */
> 
> #ifndef __KERNEL__
> -#include "jfs_user.h"
> +#include "support/jfs_user.h"
> #else
> #include <linux/time.h>
> #include <linux/fs.h>
> diff --git a/e2fsck/unix.c b/e2fsck/unix.c
> index ae231f93..474dde2d 100644
> --- a/e2fsck/unix.c
> +++ b/e2fsck/unix.c
> @@ -54,7 +54,7 @@ extern int optind;
> #include "support/plausible.h"
> #include "e2fsck.h"
> #include "problem.h"
> -#include "jfs_user.h"
> +#include "support/jfs_user.h"
> #include "../version.h"
> 
> /* Command line options */
> diff --git a/lib/ext2fs/Makefile.in b/lib/ext2fs/Makefile.in
> index f6a050a2..5fa9693a 100644
> --- a/lib/ext2fs/Makefile.in
> +++ b/lib/ext2fs/Makefile.in
> @@ -5,10 +5,8 @@ top_builddir = ../..
> my_dir = lib/ext2fs
> INSTALL = @INSTALL@
> MKDIR_P = @MKDIR_P@
> -DEPEND_CFLAGS = -I$(top_srcdir)/debugfs -I$(srcdir)/../../e2fsck -DDEBUGFS
> -# This nastiness is needed because of jfs_user.h hackery; when we finally
> -# clean up this mess, we should be able to drop it
> -DEBUGFS_CFLAGS = -I$(srcdir)/../../e2fsck $(ALL_CFLAGS) -DDEBUGFS
> +DEPEND_CFLAGS = -I$(top_srcdir)/debugfs -DDEBUGFS
> +DEBUGFS_CFLAGS = $(ALL_CFLAGS) -DDEBUGFS
> 
> @MCONFIG@
> 
> @@ -1231,7 +1229,7 @@ debugfs.o: $(top_srcdir)/debugfs/debugfs.c $(top_builddir)/lib/config.h \
>  $(top_srcdir)/debugfs/../misc/create_inode.h $(top_srcdir)/lib/e2p/e2p.h \
>  $(top_srcdir)/lib/support/quotaio.h $(top_srcdir)/lib/support/dqblk_v2.h \
>  $(top_srcdir)/lib/support/quotaio_tree.h $(top_srcdir)/debugfs/../version.h \
> - $(srcdir)/../../e2fsck/jfs_user.h $(srcdir)/kernel-jbd.h \
> + $(top_srcdir)/lib/support/jfs_user.h $(srcdir)/kernel-jbd.h \
>  $(srcdir)/jfs_compat.h $(srcdir)/kernel-list.h $(srcdir)/compiler.h \
>  $(top_srcdir)/lib/support/plausible.h
> util.o: $(top_srcdir)/debugfs/util.c $(top_builddir)/lib/config.h \
> @@ -1321,7 +1319,7 @@ logdump.o: $(top_srcdir)/debugfs/logdump.c $(top_builddir)/lib/config.h \
>  $(srcdir)/hashmap.h $(srcdir)/bitops.h \
>  $(top_srcdir)/debugfs/../misc/create_inode.h $(top_srcdir)/lib/e2p/e2p.h \
>  $(top_srcdir)/lib/support/quotaio.h $(top_srcdir)/lib/support/dqblk_v2.h \
> - $(top_srcdir)/lib/support/quotaio_tree.h $(srcdir)/../../e2fsck/jfs_user.h \
> + $(top_srcdir)/lib/support/quotaio_tree.h $(top_srcdir)/lib/support/jfs_user.h \
>  $(srcdir)/kernel-jbd.h $(srcdir)/jfs_compat.h $(srcdir)/kernel-list.h \
>  $(srcdir)/compiler.h $(srcdir)/fast_commit.h
> htree.o: $(top_srcdir)/debugfs/htree.c $(top_builddir)/lib/config.h \
> @@ -1422,20 +1420,20 @@ create_inode.o: $(top_srcdir)/misc/create_inode.c \
>  $(top_srcdir)/lib/e2p/e2p.h $(top_srcdir)/lib/support/nls-enable.h
> journal.o: $(top_srcdir)/debugfs/journal.c $(top_builddir)/lib/config.h \
>  $(top_builddir)/lib/dirpaths.h $(top_srcdir)/debugfs/journal.h \
> - $(srcdir)/../../e2fsck/jfs_user.h $(srcdir)/ext2_fs.h \
> + $(top_srcdir)/lib/support/jfs_user.h $(srcdir)/ext2_fs.h \
>  $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \
>  $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h $(srcdir)/ext2_io.h \
>  $(top_builddir)/lib/ext2fs/ext2_err.h $(srcdir)/ext2_ext_attr.h \
>  $(srcdir)/hashmap.h $(srcdir)/bitops.h $(srcdir)/kernel-jbd.h \
>  $(srcdir)/jfs_compat.h $(srcdir)/kernel-list.h $(srcdir)/compiler.h
> -revoke.o: $(top_srcdir)/e2fsck/revoke.c $(top_srcdir)/e2fsck/jfs_user.h \
> +revoke.o: $(top_srcdir)/e2fsck/revoke.c $(top_srcdir)/lib/support/jfs_user.h \
>  $(srcdir)/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h \
>  $(srcdir)/ext2fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \
>  $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \
>  $(srcdir)/ext2_ext_attr.h $(srcdir)/hashmap.h $(srcdir)/bitops.h \
>  $(srcdir)/kernel-jbd.h $(srcdir)/jfs_compat.h $(srcdir)/kernel-list.h \
>  $(srcdir)/compiler.h
> -recovery.o: $(top_srcdir)/e2fsck/recovery.c $(top_srcdir)/e2fsck/jfs_user.h \
> +recovery.o: $(top_srcdir)/e2fsck/recovery.c $(top_srcdir)/lib/support/jfs_user.h \
>  $(srcdir)/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h \
>  $(srcdir)/ext2fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \
>  $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \
> @@ -1454,4 +1452,4 @@ do_journal.o: $(top_srcdir)/debugfs/do_journal.c $(top_builddir)/lib/config.h \
>  $(top_srcdir)/lib/support/quotaio.h $(top_srcdir)/lib/support/dqblk_v2.h \
>  $(top_srcdir)/lib/support/quotaio_tree.h $(srcdir)/kernel-jbd.h \
>  $(srcdir)/jfs_compat.h $(srcdir)/kernel-list.h $(srcdir)/compiler.h \
> - $(top_srcdir)/debugfs/journal.h $(srcdir)/../../e2fsck/jfs_user.h
> + $(top_srcdir)/debugfs/journal.h $(top_srcdir)/lib/support/jfs_user.h
> diff --git a/e2fsck/jfs_user.h b/lib/support/jfs_user.h
> similarity index 100%
> rename from e2fsck/jfs_user.h
> rename to lib/support/jfs_user.h
> diff --git a/misc/Makefile.in b/misc/Makefile.in
> index 4db59cdf..2d4c8087 100644
> --- a/misc/Makefile.in
> +++ b/misc/Makefile.in
> @@ -124,10 +124,8 @@ DEPLIBS_E2P= $(LIBE2P) $(DEPLIBCOM_ERR)
> 
> COMPILE_ET=	_ET_DIR_OVERRIDE=$(srcdir)/../lib/et/et ../lib/et/compile_et
> 
> -# This nastiness is needed because of jfs_user.h hackery; when we finally
> -# clean up this mess, we should be able to drop it
> -JOURNAL_CFLAGS = -I$(srcdir)/../e2fsck $(ALL_CFLAGS) -DDEBUGFS
> -DEPEND_CFLAGS = -I$(top_srcdir)/e2fsck
> +JOURNAL_CFLAGS = -I $(ALL_CFLAGS) -DDEBUGFS
> +DEPEND_CFLAGS =
> 
> .c.o:
> 	$(E) "	CC $<"
> @@ -878,7 +876,7 @@ check_fuzzer.o: $(srcdir)/check_fuzzer.c $(top_srcdir)/lib/ext2fs/ext2_fs.h \
>  $(top_srcdir)/lib/ext2fs/bitops.h
> journal.o: $(srcdir)/../debugfs/journal.c $(top_builddir)/lib/config.h \
>  $(top_builddir)/lib/dirpaths.h $(srcdir)/../debugfs/journal.h \
> - $(top_srcdir)/e2fsck/jfs_user.h $(top_srcdir)/e2fsck/e2fsck.h \
> + $(top_srcdir)/lib/support/jfs_user.h $(top_srcdir)/e2fsck/e2fsck.h \
>  $(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h \
>  $(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/lib/ext2fs/ext3_extents.h \
>  $(top_srcdir)/lib/et/com_err.h $(top_srcdir)/lib/ext2fs/ext2_io.h \
> @@ -891,7 +889,7 @@ journal.o: $(srcdir)/../debugfs/journal.c $(top_builddir)/lib/config.h \
>  $(top_srcdir)/lib/ext2fs/fast_commit.h $(top_srcdir)/lib/ext2fs/jfs_compat.h \
>  $(top_srcdir)/lib/ext2fs/kernel-list.h $(top_srcdir)/lib/ext2fs/compiler.h \
>  $(top_srcdir)/lib/ext2fs/kernel-jbd.h
> -revoke.o: $(srcdir)/../e2fsck/revoke.c $(srcdir)/../e2fsck/jfs_user.h \
> +revoke.o: $(srcdir)/../e2fsck/revoke.c $(top_srcdir)/lib/support/jfs_user.h \
>  $(top_builddir)/lib/config.h $(top_builddir)/lib/dirpaths.h \
>  $(srcdir)/../e2fsck/e2fsck.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \
>  $(top_builddir)/lib/ext2fs/ext2_types.h $(top_srcdir)/lib/ext2fs/ext2fs.h \
> @@ -905,7 +903,7 @@ revoke.o: $(srcdir)/../e2fsck/revoke.c $(srcdir)/../e2fsck/jfs_user.h \
>  $(top_srcdir)/lib/ext2fs/fast_commit.h $(top_srcdir)/lib/ext2fs/jfs_compat.h \
>  $(top_srcdir)/lib/ext2fs/kernel-list.h $(top_srcdir)/lib/ext2fs/compiler.h \
>  $(top_srcdir)/lib/ext2fs/kernel-jbd.h
> -recovery.o: $(srcdir)/../e2fsck/recovery.c $(srcdir)/../e2fsck/jfs_user.h \
> +recovery.o: $(srcdir)/../e2fsck/recovery.c $(top_srcdir)/lib/support/jfs_user.h \
>  $(top_builddir)/lib/config.h $(top_builddir)/lib/dirpaths.h \
>  $(srcdir)/../e2fsck/e2fsck.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \
>  $(top_builddir)/lib/ext2fs/ext2_types.h $(top_srcdir)/lib/ext2fs/ext2fs.h \
> --
> 2.31.1
> 
Cheers, Andreas
[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 873 bytes --]
^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: [PATCH 2/5] move a journal checksum code into common place
  2022-08-04  9:56 ` [PATCH 2/5] move a journal checksum code into common place Alexey Lyashkov
@ 2023-09-18 23:19   ` Andreas Dilger
  0 siblings, 0 replies; 11+ messages in thread
From: Andreas Dilger @ 2023-09-18 23:19 UTC (permalink / raw)
  To: Alexey Lyashkov; +Cc: linux-ext4, Theodore Ts'o, Artem Blagodarenko
[-- Attachment #1: Type: text/plain, Size: 9508 bytes --]
On Aug 4, 2022, at 3:56 AM, Alexey Lyashkov <alexey.lyashkov@gmail.com> wrote:
> 
> e2fsck and debugfs have own copy a journal checksum functions,
> kill duplicates and move into support library.
Missing a Signed-off-by: line.
It would be better to name the new file "jbd2_user.c" if patch is refreshed,
or Ted can rename and amend the commit locally.
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
> ---
> debugfs/journal.c       | 50 ---------------------------------
> e2fsck/journal.c        | 60 ++++-----------------------------------
> lib/support/Android.bp  |  1 +
> lib/support/Makefile.in |  7 +++--
> lib/support/jfs_user.c  | 62 +++++++++++++++++++++++++++++++++++++++++
> lib/support/jfs_user.h  |  6 ++++
> 6 files changed, 79 insertions(+), 107 deletions(-)
> create mode 100644 lib/support/jfs_user.c
> 
> diff --git a/debugfs/journal.c b/debugfs/journal.c
> index 095fff00..dac17800 100644
> --- a/debugfs/journal.c
> +++ b/debugfs/journal.c
> @@ -43,56 +43,6 @@ static int bh_count = 0;
>  */
> #undef USE_INODE_IO
> 
> -/* Checksumming functions */
> -static int ext2fs_journal_verify_csum_type(journal_t *j,
> -					   journal_superblock_t *jsb)
> -{
> -	if (!jbd2_journal_has_csum_v2or3(j))
> -		return 1;
> -
> -	return jsb->s_checksum_type == JBD2_CRC32C_CHKSUM;
> -}
> -
> -static __u32 ext2fs_journal_sb_csum(journal_superblock_t *jsb)
> -{
> -	__u32 crc, old_crc;
> -
> -	old_crc = jsb->s_checksum;
> -	jsb->s_checksum = 0;
> -	crc = ext2fs_crc32c_le(~0, (unsigned char *)jsb,
> -			       sizeof(journal_superblock_t));
> -	jsb->s_checksum = old_crc;
> -
> -	return crc;
> -}
> -
> -static int ext2fs_journal_sb_csum_verify(journal_t *j,
> -					 journal_superblock_t *jsb)
> -{
> -	__u32 provided, calculated;
> -
> -	if (!jbd2_journal_has_csum_v2or3(j))
> -		return 1;
> -
> -	provided = ext2fs_be32_to_cpu(jsb->s_checksum);
> -	calculated = ext2fs_journal_sb_csum(jsb);
> -
> -	return provided == calculated;
> -}
> -
> -static errcode_t ext2fs_journal_sb_csum_set(journal_t *j,
> -					    journal_superblock_t *jsb)
> -{
> -	__u32 crc;
> -
> -	if (!jbd2_journal_has_csum_v2or3(j))
> -		return 0;
> -
> -	crc = ext2fs_journal_sb_csum(jsb);
> -	jsb->s_checksum = ext2fs_cpu_to_be32(crc);
> -	return 0;
> -}
> -
> /* Kernel compatibility functions for handling the journal.  These allow us
>  * to use the recovery.c file virtually unchanged from the kernel, so we
>  * don't have to do much to keep kernel and user recovery in sync.
> diff --git a/e2fsck/journal.c b/e2fsck/journal.c
> index d3002a62..46a9bcb7 100644
> --- a/e2fsck/journal.c
> +++ b/e2fsck/journal.c
> @@ -38,56 +38,6 @@ static int bh_count = 0;
>  */
> #undef USE_INODE_IO
> 
> -/* Checksumming functions */
> -static int e2fsck_journal_verify_csum_type(journal_t *j,
> -					   journal_superblock_t *jsb)
> -{
> -	if (!jbd2_journal_has_csum_v2or3(j))
> -		return 1;
> -
> -	return jsb->s_checksum_type == JBD2_CRC32C_CHKSUM;
> -}
> -
> -static __u32 e2fsck_journal_sb_csum(journal_superblock_t *jsb)
> -{
> -	__u32 crc, old_crc;
> -
> -	old_crc = jsb->s_checksum;
> -	jsb->s_checksum = 0;
> -	crc = ext2fs_crc32c_le(~0, (unsigned char *)jsb,
> -			       sizeof(journal_superblock_t));
> -	jsb->s_checksum = old_crc;
> -
> -	return crc;
> -}
> -
> -static int e2fsck_journal_sb_csum_verify(journal_t *j,
> -					 journal_superblock_t *jsb)
> -{
> -	__u32 provided, calculated;
> -
> -	if (!jbd2_journal_has_csum_v2or3(j))
> -		return 1;
> -
> -	provided = ext2fs_be32_to_cpu(jsb->s_checksum);
> -	calculated = e2fsck_journal_sb_csum(jsb);
> -
> -	return provided == calculated;
> -}
> -
> -static errcode_t e2fsck_journal_sb_csum_set(journal_t *j,
> -					    journal_superblock_t *jsb)
> -{
> -	__u32 crc;
> -
> -	if (!jbd2_journal_has_csum_v2or3(j))
> -		return 0;
> -
> -	crc = e2fsck_journal_sb_csum(jsb);
> -	jsb->s_checksum = ext2fs_cpu_to_be32(crc);
> -	return 0;
> -}
> -
> /* Kernel compatibility functions for handling the journal.  These allow us
>  * to use the recovery.c file virtually unchanged from the kernel, so we
>  * don't have to do much to keep kernel and user recovery in sync.
> @@ -1330,8 +1280,8 @@ static errcode_t e2fsck_journal_load(journal_t *journal)
> 	    jbd2_has_feature_checksum(journal))
> 		return EXT2_ET_CORRUPT_JOURNAL_SB;
> 
> -	if (!e2fsck_journal_verify_csum_type(journal, jsb) ||
> -	    !e2fsck_journal_sb_csum_verify(journal, jsb))
> +	if (!ext2fs_journal_verify_csum_type(journal, jsb) ||
> +	    !ext2fs_journal_sb_csum_verify(journal, jsb))
> 		return EXT2_ET_CORRUPT_JOURNAL_SB;
> 
> 	if (jbd2_journal_has_csum_v2or3(journal))
> @@ -1419,7 +1369,7 @@ static void e2fsck_journal_reset_super(e2fsck_t ctx, journal_superblock_t *jsb,
> 	for (i = 0; i < 4; i ++)
> 		new_seq ^= u.val[i];
> 	jsb->s_sequence = htonl(new_seq);
> -	e2fsck_journal_sb_csum_set(journal, jsb);
> +	ext2fs_journal_sb_csum_set(journal, jsb);
> 
> 	mark_buffer_dirty(journal->j_sb_buffer);
> 	ll_rw_block(REQ_OP_WRITE, 0, 1, &journal->j_sb_buffer);
> @@ -1459,7 +1409,7 @@ static void e2fsck_journal_release(e2fsck_t ctx, journal_t *journal,
> 		jsb->s_sequence = htonl(journal->j_tail_sequence);
> 		if (reset)
> 			jsb->s_start = 0; /* this marks the journal as empty */
> -		e2fsck_journal_sb_csum_set(journal, jsb);
> +		ext2fs_journal_sb_csum_set(journal, jsb);
> 		mark_buffer_dirty(journal->j_sb_buffer);
> 	}
> 	brelse(journal->j_sb_buffer);
> @@ -1602,7 +1552,7 @@ no_has_journal:
> 		ctx->fs->super->s_state |= EXT2_ERROR_FS;
> 		ext2fs_mark_super_dirty(ctx->fs);
> 		journal->j_superblock->s_errno = 0;
> -		e2fsck_journal_sb_csum_set(journal, journal->j_superblock);
> +		ext2fs_journal_sb_csum_set(journal, journal->j_superblock);
> 		mark_buffer_dirty(journal->j_sb_buffer);
> 	}
> 
> diff --git a/lib/support/Android.bp b/lib/support/Android.bp
> index a0b064dd..efa0f955 100644
> --- a/lib/support/Android.bp
> +++ b/lib/support/Android.bp
> @@ -29,6 +29,7 @@ cc_library {
>         "quotaio.c",
>         "quotaio_tree.c",
>         "quotaio_v2.c",
> +        "jfs_user.c"
>     ],
>     shared_libs: [
>         "libext2fs",
> diff --git a/lib/support/Makefile.in b/lib/support/Makefile.in
> index f3c7981e..04fbcf31 100644
> --- a/lib/support/Makefile.in
> +++ b/lib/support/Makefile.in
> @@ -23,7 +23,8 @@ OBJS=		cstring.o \
> 		quotaio.o \
> 		quotaio_v2.o \
> 		quotaio_tree.o \
> -		dict.o
> +		dict.o \
> +		jfs_user.o
> 
> SRCS=		$(srcdir)/argv_parse.c \
> 		$(srcdir)/cstring.c \
> @@ -36,7 +37,9 @@ SRCS=		$(srcdir)/argv_parse.c \
> 		$(srcdir)/quotaio.c \
> 		$(srcdir)/quotaio_tree.c \
> 		$(srcdir)/quotaio_v2.c \
> -		$(srcdir)/dict.c
> +		$(srcdir)/dict.c \
> +		$(srcdir)/jfs_user.c
> +
> 
> LIBRARY= libsupport
> LIBDIR= support
> diff --git a/lib/support/jfs_user.c b/lib/support/jfs_user.c
> new file mode 100644
> index 00000000..4ff1b5c1
> --- /dev/null
> +++ b/lib/support/jfs_user.c
> @@ -0,0 +1,62 @@
> +#define DEBUGFS
> +#include "jfs_user.h"
> +
> +/*
> + * Define USE_INODE_IO to use the inode_io.c / fileio.c codepaths.
> + * This creates a larger static binary, and a smaller binary using
> + * shared libraries.  It's also probably slightly less CPU-efficient,
> + * which is why it's not on by default.  But, it's a good way of
> + * testing the functions in inode_io.c and fileio.c.
> + */
> +#undef USE_INODE_IO
> +
> +/* Checksumming functions */
> +int ext2fs_journal_verify_csum_type(journal_t *j,
> +				    journal_superblock_t *jsb)
> +{
> +	if (!jbd2_journal_has_csum_v2or3(j))
> +		return 1;
> +
> +	return jsb->s_checksum_type == JBD2_CRC32C_CHKSUM;
> +}
> +
> +__u32 ext2fs_journal_sb_csum(journal_superblock_t *jsb)
> +{
> +	__u32 crc, old_crc;
> +
> +	old_crc = jsb->s_checksum;
> +	jsb->s_checksum = 0;
> +	crc = ext2fs_crc32c_le(~0, (unsigned char *)jsb,
> +			       sizeof(journal_superblock_t));
> +	jsb->s_checksum = old_crc;
> +
> +	return crc;
> +}
> +
> +int ext2fs_journal_sb_csum_verify(journal_t *j,
> +				  journal_superblock_t *jsb)
> +{
> +	__u32 provided, calculated;
> +
> +	if (!jbd2_journal_has_csum_v2or3(j))
> +		return 1;
> +
> +	provided = ext2fs_be32_to_cpu(jsb->s_checksum);
> +	calculated = ext2fs_journal_sb_csum(jsb);
> +
> +	return provided == calculated;
> +}
> +
> +errcode_t ext2fs_journal_sb_csum_set(journal_t *j,
> +				     journal_superblock_t *jsb)
> +{
> +	__u32 crc;
> +
> +	if (!jbd2_journal_has_csum_v2or3(j))
> +		return 0;
> +
> +	crc = ext2fs_journal_sb_csum(jsb);
> +	jsb->s_checksum = ext2fs_cpu_to_be32(crc);
> +	return 0;
> +}
> +
> diff --git a/lib/support/jfs_user.h b/lib/support/jfs_user.h
> index 4ad2005a..8bdbf85b 100644
> --- a/lib/support/jfs_user.h
> +++ b/lib/support/jfs_user.h
> @@ -212,6 +212,12 @@ _INLINE_ void jbd2_descriptor_block_csum_set(journal_t *j,
> #undef _INLINE_
> #endif
> 
> +/* Checksumming functions */
> +int ext2fs_journal_verify_csum_type(journal_t *j, journal_superblock_t *jsb);
> +__u32 ext2fs_journal_sb_csum(journal_superblock_t *jsb);
> +int ext2fs_journal_sb_csum_verify(journal_t *j, journal_superblock_t *jsb);
> +errcode_t ext2fs_journal_sb_csum_set(journal_t *j, journal_superblock_t *jsb);
> +
> /*
>  * Kernel compatibility functions are defined in journal.c
>  */
> --
> 2.31.1
> 
Cheers, Andreas
[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 873 bytes --]
^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: [PATCH 3/5] kill a ctx->journal_io
  2022-08-04  9:56 ` [PATCH 3/5] kill a ctx->journal_io Alexey Lyashkov
@ 2023-09-18 23:43   ` Andreas Dilger
  0 siblings, 0 replies; 11+ messages in thread
From: Andreas Dilger @ 2023-09-18 23:43 UTC (permalink / raw)
  To: Alexey Lyashkov
  Cc: Ext4 Developers List, Theodore Ts'o, Artem Blagodarenko
[-- Attachment #1: Type: text/plain, Size: 8768 bytes --]
On Aug 4, 2022, at 3:56 AM, Alexey Lyashkov <alexey.lyashkov@gmail.com> wrote:
> 
> replace a e2fsck own code, with generic one to use
> an fs->journal_io.
Missing Signed-off-by: line, but otherwise looks fine.
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
> ---
> debugfs/journal.c      | 34 ---------------------------
> e2fsck/e2fsck.c        |  6 +----
> e2fsck/e2fsck.h        |  1 -
> e2fsck/journal.c       | 53 +++++++-----------------------------------
> lib/support/jfs_user.c | 39 +++++++++++++++++++++++++++++++
> lib/support/jfs_user.h |  2 ++
> 6 files changed, 50 insertions(+), 85 deletions(-)
> 
> diff --git a/debugfs/journal.c b/debugfs/journal.c
> index dac17800..202312fe 100644
> --- a/debugfs/journal.c
> +++ b/debugfs/journal.c
> @@ -590,40 +590,6 @@ static errcode_t ext2fs_journal_load(journal_t *journal)
> 	return 0;
> }
> 
> -static void ext2fs_journal_release(ext2_filsys fs, journal_t *journal,
> -				   int reset, int drop)
> -{
> -	journal_superblock_t *jsb;
> -
> -	if (drop)
> -		mark_buffer_clean(journal->j_sb_buffer);
> -	else if (fs->flags & EXT2_FLAG_RW) {
> -		jsb = journal->j_superblock;
> -		jsb->s_sequence = htonl(journal->j_tail_sequence);
> -		if (reset)
> -			jsb->s_start = 0; /* this marks the journal as empty */
> -		ext2fs_journal_sb_csum_set(journal, jsb);
> -		mark_buffer_dirty(journal->j_sb_buffer);
> -	}
> -	brelse(journal->j_sb_buffer);
> -
> -	if (fs && fs->journal_io) {
> -		if (fs->io != fs->journal_io)
> -			io_channel_close(fs->journal_io);
> -		fs->journal_io = NULL;
> -		free(fs->journal_name);
> -		fs->journal_name = NULL;
> -	}
> -
> -#ifndef USE_INODE_IO
> -	if (journal->j_inode)
> -		ext2fs_free_mem(&journal->j_inode);
> -#endif
> -	if (journal->j_fs_dev)
> -		ext2fs_free_mem(&journal->j_fs_dev);
> -	ext2fs_free_mem(&journal);
> -}
> -
> /*
>  * This function makes sure that the superblock fields regarding the
>  * journal are consistent.
> diff --git a/e2fsck/e2fsck.c b/e2fsck/e2fsck.c
> index 1e295e3e..421ef4a9 100644
> --- a/e2fsck/e2fsck.c
> +++ b/e2fsck/e2fsck.c
> @@ -83,11 +83,7 @@ errcode_t e2fsck_reset_context(e2fsck_t ctx)
> 		ext2fs_free_icount(ctx->inode_link_info);
> 		ctx->inode_link_info = 0;
> 	}
> -	if (ctx->journal_io) {
> -		if (ctx->fs && ctx->fs->io != ctx->journal_io)
> -			io_channel_close(ctx->journal_io);
> -		ctx->journal_io = 0;
> -	}
> +
> 	if (ctx->fs && ctx->fs->dblist) {
> 		ext2fs_free_dblist(ctx->fs->dblist);
> 		ctx->fs->dblist = 0;
> diff --git a/e2fsck/e2fsck.h b/e2fsck/e2fsck.h
> index 2db216f5..33334781 100644
> --- a/e2fsck/e2fsck.h
> +++ b/e2fsck/e2fsck.h
> @@ -380,7 +380,6 @@ struct e2fsck_struct {
> 	/*
> 	 * ext3 journal support
> 	 */
> -	io_channel	journal_io;
> 	char	*journal_name;
> 
> 	/*
> diff --git a/e2fsck/journal.c b/e2fsck/journal.c
> index 46a9bcb7..682d82a4 100644
> --- a/e2fsck/journal.c
> +++ b/e2fsck/journal.c
> @@ -86,7 +86,7 @@ struct buffer_head *getblk(kdev_t kdev, unsigned long long blocknr,
> 	if (kdev->k_dev == K_DEV_FS)
> 		bh->b_io = kdev->k_ctx->fs->io;
> 	else
> -		bh->b_io = kdev->k_ctx->journal_io;
> +		bh->b_io = kdev->k_ctx->fs->journal_io;
> 	bh->b_size = blocksize;
> 	bh->b_blocknr = blocknr;
> 
> @@ -100,7 +100,7 @@ int sync_blockdev(kdev_t kdev)
> 	if (kdev->k_dev == K_DEV_FS)
> 		io = kdev->k_ctx->fs->io;
> 	else
> -		io = kdev->k_ctx->journal_io;
> +		io = kdev->k_ctx->fs->journal_io;
> 
> 	return io_channel_flush(io) ? -EIO : 0;
> }
> @@ -156,11 +156,6 @@ void mark_buffer_dirty(struct buffer_head *bh)
> 	bh->b_dirty = 1;
> }
> 
> -static void mark_buffer_clean(struct buffer_head * bh)
> -{
> -	bh->b_dirty = 0;
> -}
> -
> void brelse(struct buffer_head *bh)
> {
> 	if (bh->b_dirty)
> @@ -1011,7 +1006,7 @@ static errcode_t e2fsck_get_journal(e2fsck_t ctx, journal_t **ret_journal)
> 		io_ptr = inode_io_manager;
> #else
> 		journal->j_inode = j_inode;
> -		ctx->journal_io = ctx->fs->io;
> +		ctx->fs->journal_io = ctx->fs->io;
> 		if ((ret = jbd2_journal_bmap(journal, 0, &start)) != 0) {
> 			retval = (errcode_t) (-1 * ret);
> 			goto errout;
> @@ -1058,12 +1053,12 @@ static errcode_t e2fsck_get_journal(e2fsck_t ctx, journal_t **ret_journal)
> 
> 
> 		retval = io_ptr->open(journal_name, flags,
> -				      &ctx->journal_io);
> +				      &ctx->fs->journal_io);
> 	}
> 	if (retval)
> 		goto errout;
> 
> -	io_channel_set_blksize(ctx->journal_io, ctx->fs->blocksize);
> +	io_channel_set_blksize(ctx->fs->journal_io, ctx->fs->blocksize);
> 
> 	if (ext_journal) {
> 		blk64_t maxlen;
> @@ -1397,38 +1392,6 @@ static errcode_t e2fsck_journal_fix_corrupt_super(e2fsck_t ctx,
> 	return 0;
> }
> 
> -static void e2fsck_journal_release(e2fsck_t ctx, journal_t *journal,
> -				   int reset, int drop)
> -{
> -	journal_superblock_t *jsb;
> -
> -	if (drop)
> -		mark_buffer_clean(journal->j_sb_buffer);
> -	else if (!(ctx->options & E2F_OPT_READONLY)) {
> -		jsb = journal->j_superblock;
> -		jsb->s_sequence = htonl(journal->j_tail_sequence);
> -		if (reset)
> -			jsb->s_start = 0; /* this marks the journal as empty */
> -		ext2fs_journal_sb_csum_set(journal, jsb);
> -		mark_buffer_dirty(journal->j_sb_buffer);
> -	}
> -	brelse(journal->j_sb_buffer);
> -
> -	if (ctx->journal_io) {
> -		if (ctx->fs && ctx->fs->io != ctx->journal_io)
> -			io_channel_close(ctx->journal_io);
> -		ctx->journal_io = 0;
> -	}
> -
> -#ifndef USE_INODE_IO
> -	if (journal->j_inode)
> -		ext2fs_free_mem(&journal->j_inode);
> -#endif
> -	if (journal->j_fs_dev)
> -		ext2fs_free_mem(&journal->j_fs_dev);
> -	ext2fs_free_mem(&journal);
> -}
> -
> /*
>  * This function makes sure that the superblock fields regarding the
>  * journal are consistent.
> @@ -1475,7 +1438,7 @@ errcode_t e2fsck_check_ext3_journal(e2fsck_t ctx)
> 		    (!fix_problem(ctx, PR_0_JOURNAL_UNSUPP_VERSION, &pctx))))
> 			retval = e2fsck_journal_fix_corrupt_super(ctx, journal,
> 								  &pctx);
> -		e2fsck_journal_release(ctx, journal, 0, 1);
> +		ext2fs_journal_release(ctx->fs, journal, 0, 1);
> 		return retval;
> 	}
> 
> @@ -1556,7 +1519,7 @@ no_has_journal:
> 		mark_buffer_dirty(journal->j_sb_buffer);
> 	}
> 
> -	e2fsck_journal_release(ctx, journal, reset, 0);
> +	ext2fs_journal_release(ctx->fs, journal, reset, 0);
> 	return retval;
> }
> 
> @@ -1605,7 +1568,7 @@ errout:
> 	jbd2_journal_destroy_revoke(journal);
> 	jbd2_journal_destroy_revoke_record_cache();
> 	jbd2_journal_destroy_revoke_table_cache();
> -	e2fsck_journal_release(ctx, journal, 1, 0);
> +	ext2fs_journal_release(ctx->fs, journal, 1, 0);
> 	return retval;
> }
> 
> diff --git a/lib/support/jfs_user.c b/lib/support/jfs_user.c
> index 4ff1b5c1..d8a2f842 100644
> --- a/lib/support/jfs_user.c
> +++ b/lib/support/jfs_user.c
> @@ -60,3 +60,42 @@ errcode_t ext2fs_journal_sb_csum_set(journal_t *j,
> 	return 0;
> }
> 
> +
> +static void mark_buffer_clean(struct buffer_head * bh)
> +{
> +	bh->b_dirty = 0;
> +}
> +
> +void ext2fs_journal_release(ext2_filsys fs, journal_t *journal,
> +			    int reset, int drop)
> +{
> +	journal_superblock_t *jsb;
> +
> +	if (drop)
> +		mark_buffer_clean(journal->j_sb_buffer);
> +	else if (fs->flags & EXT2_FLAG_RW) {
> +		jsb = journal->j_superblock;
> +		jsb->s_sequence = htonl(journal->j_tail_sequence);
> +		if (reset)
> +			jsb->s_start = 0; /* this marks the journal as empty */
> +		ext2fs_journal_sb_csum_set(journal, jsb);
> +		mark_buffer_dirty(journal->j_sb_buffer);
> +	}
> +	brelse(journal->j_sb_buffer);
> +
> +	if (fs && fs->journal_io) {
> +		if (fs->io != fs->journal_io)
> +			io_channel_close(fs->journal_io);
> +		fs->journal_io = NULL;
> +		free(fs->journal_name);
> +		fs->journal_name = NULL;
> +	}
> +
> +#ifndef USE_INODE_IO
> +	if (journal->j_inode)
> +		ext2fs_free_mem(&journal->j_inode);
> +#endif
> +	if (journal->j_fs_dev)
> +		ext2fs_free_mem(&journal->j_fs_dev);
> +	ext2fs_free_mem(&journal);
> +}
> diff --git a/lib/support/jfs_user.h b/lib/support/jfs_user.h
> index 8bdbf85b..b9c2fa54 100644
> --- a/lib/support/jfs_user.h
> +++ b/lib/support/jfs_user.h
> @@ -217,6 +217,8 @@ int ext2fs_journal_verify_csum_type(journal_t *j, journal_superblock_t *jsb);
> __u32 ext2fs_journal_sb_csum(journal_superblock_t *jsb);
> int ext2fs_journal_sb_csum_verify(journal_t *j, journal_superblock_t *jsb);
> errcode_t ext2fs_journal_sb_csum_set(journal_t *j, journal_superblock_t *jsb);
> +void ext2fs_journal_release(ext2_filsys fs, journal_t *journal, int reset,
> +			    int drop);
> 
> /*
>  * Kernel compatibility functions are defined in journal.c
> --
> 2.31.1
> 
Cheers, Andreas
[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 873 bytes --]
^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: [PATCH 4/5] remove an e2fsck context from bh emulation code.
  2022-08-04  9:56 ` [PATCH 4/5] remove an e2fsck context from bh emulation code Alexey Lyashkov
@ 2023-09-18 23:57   ` Andreas Dilger
  0 siblings, 0 replies; 11+ messages in thread
From: Andreas Dilger @ 2023-09-18 23:57 UTC (permalink / raw)
  To: Alexey Lyashkov; +Cc: linux-ext4, Theodore Ts'o, Artem Blagodarenko
[-- Attachment #1: Type: text/plain, Size: 8068 bytes --]
On Aug 4, 2022, at 3:56 AM, Alexey Lyashkov <alexey.lyashkov@gmail.com> wrote:
> 
> In order to generalize a journal handing, remove a e2fsck context
> from generic structures like buffer_head, and device.
> But fast commit code want a e2fsck context as well, so move it pointer
> to journal struct.
Missing Signed-off-by: line.
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
> ---
> e2fsck/journal.c        | 46 ++++++++++++++++++++---------------------
> lib/ext2fs/jfs_compat.h |  2 ++
> lib/support/jfs_user.h  | 12 -----------
> 3 files changed, 25 insertions(+), 35 deletions(-)
> 
> diff --git a/e2fsck/journal.c b/e2fsck/journal.c
> index 682d82a4..728f5a24 100644
> --- a/e2fsck/journal.c
> +++ b/e2fsck/journal.c
> @@ -58,7 +58,7 @@ int jbd2_journal_bmap(journal_t *journal, unsigned long block,
> 		return 0;
> 	}
> 
> -	retval= ext2fs_bmap2(inode->i_ctx->fs, inode->i_ino,
> +	retval= ext2fs_bmap2(inode->i_fs, inode->i_ino,
> 			     &inode->i_ext2, NULL, 0, (blk64_t) block,
> 			     0, &pblk);
> 	*phys = pblk;
> @@ -70,11 +70,12 @@ struct buffer_head *getblk(kdev_t kdev, unsigned long long blocknr,
> 			   int blocksize)
> {
> 	struct buffer_head *bh;
> -	int bufsize = sizeof(*bh) + kdev->k_ctx->fs->blocksize -
> +	int bufsize = sizeof(*bh) + kdev->k_fs->blocksize -
> 		sizeof(bh->b_data);
> +	errcode_t retval;
> 
> -	bh = e2fsck_allocate_memory(kdev->k_ctx, bufsize, "block buffer");
> -	if (!bh)
> +	retval = ext2fs_get_memzero(bufsize, &bh);
> +	if (retval)
> 		return NULL;
> 
> 	if (journal_enable_debug >= 3)
> @@ -82,11 +83,11 @@ struct buffer_head *getblk(kdev_t kdev, unsigned long long blocknr,
> 	jfs_debug(4, "getblk for block %llu (%d bytes)(total %d)\n",
> 		  blocknr, blocksize, bh_count);
> 
> -	bh->b_ctx = kdev->k_ctx;
> +	bh->b_fs = kdev->k_fs;
> 	if (kdev->k_dev == K_DEV_FS)
> -		bh->b_io = kdev->k_ctx->fs->io;
> +		bh->b_io = kdev->k_fs->io;
> 	else
> -		bh->b_io = kdev->k_ctx->fs->journal_io;
> +		bh->b_io = kdev->k_fs->journal_io;
> 	bh->b_size = blocksize;
> 	bh->b_blocknr = blocknr;
> 
> @@ -98,9 +99,9 @@ int sync_blockdev(kdev_t kdev)
> 	io_channel	io;
> 
> 	if (kdev->k_dev == K_DEV_FS)
> -		io = kdev->k_ctx->fs->io;
> +		io = kdev->k_fs->io;
> 	else
> -		io = kdev->k_ctx->fs->journal_io;
> +		io = kdev->k_fs->journal_io;
> 
> 	return io_channel_flush(io) ? -EIO : 0;
> }
> @@ -120,7 +121,7 @@ void ll_rw_block(int rw, int op_flags EXT2FS_ATTR((unused)), int nr,
> 						     bh->b_blocknr,
> 						     1, bh->b_data);
> 			if (retval) {
> -				com_err(bh->b_ctx->device_name, retval,
> +				com_err(bh->b_fs->device_name, retval,
> 					"while reading block %llu\n",
> 					bh->b_blocknr);
> 				bh->b_err = (int) retval;
> @@ -135,7 +136,7 @@ void ll_rw_block(int rw, int op_flags EXT2FS_ATTR((unused)), int nr,
> 						      bh->b_blocknr,
> 						      1, bh->b_data);
> 			if (retval) {
> -				com_err(bh->b_ctx->device_name, retval,
> +				com_err(bh->b_fs->device_name, retval,
> 					"while writing block %llu\n",
> 					bh->b_blocknr);
> 				bh->b_err = (int) retval;
> @@ -223,7 +224,7 @@ static int process_journal_block(ext2_filsys fs,
> static int ext4_fc_replay_scan(journal_t *j, struct buffer_head *bh,
> 				int off, tid_t expected_tid)
> {
> -	e2fsck_t ctx = j->j_fs_dev->k_ctx;
> +	e2fsck_t ctx = j->j_ctx;
> 	struct e2fsck_fc_replay_state *state;
> 	int ret = JBD2_FC_REPLAY_CONTINUE;
> 	struct ext4_fc_add_range ext;
> @@ -796,7 +797,7 @@ static int ext4_fc_handle_del_range(e2fsck_t ctx, __u8 *val)
> static int ext4_fc_replay(journal_t *journal, struct buffer_head *bh,
> 				enum passtype pass, int off, tid_t expected_tid)
> {
> -	e2fsck_t ctx = journal->j_fs_dev->k_ctx;
> +	e2fsck_t ctx = journal->j_ctx;
> 	struct e2fsck_fc_replay_state *state = &ctx->fc_replay_state;
> 	int ret = JBD2_FC_REPLAY_CONTINUE;
> 	struct ext4_fc_tl tl;
> @@ -924,10 +925,11 @@ static errcode_t e2fsck_get_journal(e2fsck_t ctx, journal_t **ret_journal)
> 	}
> 	dev_journal = dev_fs+1;
> 
> -	dev_fs->k_ctx = dev_journal->k_ctx = ctx;
> +	dev_fs->k_fs = dev_journal->k_fs = ctx->fs;
> 	dev_fs->k_dev = K_DEV_FS;
> 	dev_journal->k_dev = K_DEV_JOURNAL;
> 
> +	journal->j_ctx = ctx;
> 	journal->j_dev = dev_journal;
> 	journal->j_fs_dev = dev_fs;
> 	journal->j_inode = NULL;
> @@ -945,7 +947,7 @@ static errcode_t e2fsck_get_journal(e2fsck_t ctx, journal_t **ret_journal)
> 			goto errout;
> 		}
> 
> -		j_inode->i_ctx = ctx;
> +		j_inode->i_fs = ctx->fs;
> 		j_inode->i_ino = sb->s_journal_inum;
> 
> 		if ((retval = ext2fs_read_inode(ctx->fs,
> @@ -1186,9 +1188,8 @@ static errcode_t e2fsck_journal_fix_bad_inode(e2fsck_t ctx,
> }
> 
> #define V1_SB_SIZE	0x0024
> -static void clear_v2_journal_fields(journal_t *journal)
> +static void clear_v2_journal_fields(e2fsck_t ctx, journal_t *journal)
> {
> -	e2fsck_t ctx = journal->j_dev->k_ctx;
> 	struct problem_context pctx;
> 
> 	clear_problem_context(&pctx);
> @@ -1203,9 +1204,8 @@ static void clear_v2_journal_fields(journal_t *journal)
> }
> 
> 
> -static errcode_t e2fsck_journal_load(journal_t *journal)
> +static errcode_t e2fsck_journal_load(e2fsck_t ctx, journal_t *journal)
> {
> -	e2fsck_t ctx = journal->j_dev->k_ctx;
> 	journal_superblock_t *jsb;
> 	struct buffer_head *jbh = journal->j_sb_buffer;
> 	struct problem_context pctx;
> @@ -1231,14 +1231,14 @@ static errcode_t e2fsck_journal_load(journal_t *journal)
> 		    jsb->s_feature_incompat ||
> 		    jsb->s_feature_ro_compat ||
> 		    jsb->s_nr_users)
> -			clear_v2_journal_fields(journal);
> +			clear_v2_journal_fields(ctx, journal);
> 		break;
> 
> 	case JBD2_SUPERBLOCK_V2:
> 		journal->j_format_version = 2;
> 		if (ntohl(jsb->s_nr_users) > 1 &&
> 		    uuid_is_null(ctx->fs->super->s_journal_uuid))
> -			clear_v2_journal_fields(journal);
> +			clear_v2_journal_fields(ctx, journal);
> 		if (ntohl(jsb->s_nr_users) > 1) {
> 			fix_problem(ctx, PR_0_JOURNAL_UNSUPP_MULTIFS, &pctx);
> 			return EXT2_ET_JOURNAL_UNSUPP_VERSION;
> @@ -1425,7 +1425,7 @@ errcode_t e2fsck_check_ext3_journal(e2fsck_t ctx)
> 		return retval;
> 	}
> 
> -	retval = e2fsck_journal_load(journal);
> +	retval = e2fsck_journal_load(ctx, journal);
> 	if (retval) {
> 		if ((retval == EXT2_ET_CORRUPT_JOURNAL_SB) ||
> 		    ((retval == EXT2_ET_UNSUPP_FEATURE) &&
> @@ -1543,7 +1543,7 @@ static errcode_t recover_ext3_journal(e2fsck_t ctx)
> 	if (retval)
> 		return retval;
> 
> -	retval = e2fsck_journal_load(journal);
> +	retval = e2fsck_journal_load(ctx, journal);
> 	if (retval)
> 		goto errout;
> 
> diff --git a/lib/ext2fs/jfs_compat.h b/lib/ext2fs/jfs_compat.h
> index e11cf494..bfafae12 100644
> --- a/lib/ext2fs/jfs_compat.h
> +++ b/lib/ext2fs/jfs_compat.h
> @@ -41,6 +41,7 @@ typedef struct kdev_s *kdev_t;
> 
> struct buffer_head;
> struct inode;
> +struct e2fsck_struct;
> 
> typedef unsigned int gfp_t;
> #define GFP_KERNEL	0
> @@ -98,6 +99,7 @@ struct journal_s
> 	struct jbd2_revoke_table_s *j_revoke_table[2];
> 	tid_t			j_failed_commit;
> 	__u32			j_csum_seed;
> +	struct e2fsck_struct *	j_ctx;
> 	int (*j_fc_replay_callback)(struct journal_s *journal,
> 				    struct buffer_head *bh,
> 				    enum passtype pass, int off,
> diff --git a/lib/support/jfs_user.h b/lib/support/jfs_user.h
> index b9c2fa54..bb392811 100644
> --- a/lib/support/jfs_user.h
> +++ b/lib/support/jfs_user.h
> @@ -40,11 +40,7 @@
> #endif
> 
> struct buffer_head {
> -#ifdef DEBUGFS
> 	ext2_filsys	b_fs;
> -#else
> -	e2fsck_t	b_ctx;
> -#endif
> 	io_channel	b_io;
> 	int		b_size;
> 	int		b_err;
> @@ -55,21 +51,13 @@ struct buffer_head {
> };
> 
> struct inode {
> -#ifdef DEBUGFS
> 	ext2_filsys	i_fs;
> -#else
> -	e2fsck_t	i_ctx;
> -#endif
> 	ext2_ino_t	i_ino;
> 	struct ext2_inode i_ext2;
> };
> 
> struct kdev_s {
> -#ifdef DEBUGFS
> 	ext2_filsys	k_fs;
> -#else
> -	e2fsck_t	k_ctx;
> -#endif
> 	int		k_dev;
> };
> 
> --
> 2.31.1
> 
Cheers, Andreas
[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 873 bytes --]
^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: [PATCH 5/5] deduplicate a buffer_head / kernel device code.
  2022-08-04  9:56 ` [PATCH 5/5] deduplicate a buffer_head / kernel device code Alexey Lyashkov
@ 2023-09-19  0:04   ` Andreas Dilger
  0 siblings, 0 replies; 11+ messages in thread
From: Andreas Dilger @ 2023-09-19  0:04 UTC (permalink / raw)
  To: Alexey Lyashkov; +Cc: linux-ext4, Theodore Ts'o, Artem Blagodarenko
[-- Attachment #1: Type: text/plain, Size: 14019 bytes --]
On Aug 4, 2022, at 3:56 AM, Alexey Lyashkov <alexey.lyashkov@gmail.com> wrote:
> 
> move a buffer_head and device code into libsupport.
Missing Signed-off-by: line, but looks fine otherwise.
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
--
This patch was pushed before 1.47.0 was released, so debugfs/journal.c
is still missing the ext4_fc_replay*() code only in e2fsck/journal.c,
but at least it removes much of the duplication between these files.
We _might_ be able to merge the rest of this code into a single file with
something tricky, like having the fix_problem() calls handled via function
pointers in the journal context for e2fsck_journal_load() and similar,
and do nothing in the debugfs case.  I haven't looked into that yet.
Cheers, Andreas
> ---
> debugfs/journal.c      | 147 -----------------------------------------
> e2fsck/journal.c       | 143 ---------------------------------------
> lib/support/jfs_user.c | 142 +++++++++++++++++++++++++++++++++++++++
> 3 files changed, 142 insertions(+), 290 deletions(-)
> 
> diff --git a/debugfs/journal.c b/debugfs/journal.c
> index 202312fe..510a0acb 100644
> --- a/debugfs/journal.c
> +++ b/debugfs/journal.c
> @@ -26,8 +26,6 @@
> #include "uuid/uuid.h"
> #include "journal.h"
> 
> -static int bh_count = 0;
> -
> #if EXT2_FLAT_INCLUDES
> #include "blkid.h"
> #else
> @@ -47,151 +45,6 @@ static int bh_count = 0;
>  * to use the recovery.c file virtually unchanged from the kernel, so we
>  * don't have to do much to keep kernel and user recovery in sync.
>  */
> -int jbd2_journal_bmap(journal_t *journal, unsigned long block,
> -		      unsigned long long *phys)
> -{
> -#ifdef USE_INODE_IO
> -	*phys = block;
> -	return 0;
> -#else
> -	struct inode	*inode = journal->j_inode;
> -	errcode_t	retval;
> -	blk64_t		pblk;
> -
> -	if (!inode) {
> -		*phys = block;
> -		return 0;
> -	}
> -
> -	retval = ext2fs_bmap2(inode->i_fs, inode->i_ino,
> -			      &inode->i_ext2, NULL, 0, (blk64_t) block,
> -			      0, &pblk);
> -	*phys = pblk;
> -	return (int) retval;
> -#endif
> -}
> -
> -struct buffer_head *getblk(kdev_t kdev, unsigned long long blocknr,
> -			   int blocksize)
> -{
> -	struct buffer_head *bh;
> -	int bufsize = sizeof(*bh) + kdev->k_fs->blocksize -
> -		sizeof(bh->b_data);
> -	errcode_t retval;
> -
> -	retval = ext2fs_get_memzero(bufsize, &bh);
> -	if (retval)
> -		return NULL;
> -
> -	if (journal_enable_debug >= 3)
> -		bh_count++;
> -	jfs_debug(4, "getblk for block %llu (%d bytes)(total %d)\n",
> -		  blocknr, blocksize, bh_count);
> -
> -	bh->b_fs = kdev->k_fs;
> -	if (kdev->k_dev == K_DEV_FS)
> -		bh->b_io = kdev->k_fs->io;
> -	else
> -		bh->b_io = kdev->k_fs->journal_io;
> -	bh->b_size = blocksize;
> -	bh->b_blocknr = blocknr;
> -
> -	return bh;
> -}
> -
> -int sync_blockdev(kdev_t kdev)
> -{
> -	io_channel	io;
> -
> -	if (kdev->k_dev == K_DEV_FS)
> -		io = kdev->k_fs->io;
> -	else
> -		io = kdev->k_fs->journal_io;
> -
> -	return io_channel_flush(io) ? EIO : 0;
> -}
> -
> -void ll_rw_block(int rw, int op_flags EXT2FS_ATTR((unused)), int nr,
> -		 struct buffer_head *bhp[])
> -{
> -	errcode_t retval;
> -	struct buffer_head *bh;
> -
> -	for (; nr > 0; --nr) {
> -		bh = *bhp++;
> -		if (rw == REQ_OP_READ && !bh->b_uptodate) {
> -			jfs_debug(3, "reading block %llu/%p\n",
> -				  bh->b_blocknr, (void *) bh);
> -			retval = io_channel_read_blk64(bh->b_io,
> -						     bh->b_blocknr,
> -						     1, bh->b_data);
> -			if (retval) {
> -				com_err(bh->b_fs->device_name, retval,
> -					"while reading block %llu\n",
> -					bh->b_blocknr);
> -				bh->b_err = (int) retval;
> -				continue;
> -			}
> -			bh->b_uptodate = 1;
> -		} else if (rw == REQ_OP_WRITE && bh->b_dirty) {
> -			jfs_debug(3, "writing block %llu/%p\n",
> -				  bh->b_blocknr,
> -				  (void *) bh);
> -			retval = io_channel_write_blk64(bh->b_io,
> -						      bh->b_blocknr,
> -						      1, bh->b_data);
> -			if (retval) {
> -				com_err(bh->b_fs->device_name, retval,
> -					"while writing block %llu\n",
> -					bh->b_blocknr);
> -				bh->b_err = (int) retval;
> -				continue;
> -			}
> -			bh->b_dirty = 0;
> -			bh->b_uptodate = 1;
> -		} else {
> -			jfs_debug(3, "no-op %s for block %llu\n",
> -				  rw == REQ_OP_READ ? "read" : "write",
> -				  bh->b_blocknr);
> -		}
> -	}
> -}
> -
> -void mark_buffer_dirty(struct buffer_head *bh)
> -{
> -	bh->b_dirty = 1;
> -}
> -
> -static void mark_buffer_clean(struct buffer_head *bh)
> -{
> -	bh->b_dirty = 0;
> -}
> -
> -void brelse(struct buffer_head *bh)
> -{
> -	if (bh->b_dirty)
> -		ll_rw_block(REQ_OP_WRITE, 0, 1, &bh);
> -	jfs_debug(3, "freeing block %llu/%p (total %d)\n",
> -		  bh->b_blocknr, (void *) bh, --bh_count);
> -	ext2fs_free_mem(&bh);
> -}
> -
> -int buffer_uptodate(struct buffer_head *bh)
> -{
> -	return bh->b_uptodate;
> -}
> -
> -void mark_buffer_uptodate(struct buffer_head *bh, int val)
> -{
> -	bh->b_uptodate = val;
> -}
> -
> -void wait_on_buffer(struct buffer_head *bh)
> -{
> -	if (!bh->b_uptodate)
> -		ll_rw_block(REQ_OP_READ, 0, 1, &bh);
> -}
> -
> 
> static void ext2fs_clear_recover(ext2_filsys fs, int error)
> {
> diff --git a/e2fsck/journal.c b/e2fsck/journal.c
> index 728f5a24..9ff1dc94 100644
> --- a/e2fsck/journal.c
> +++ b/e2fsck/journal.c
> @@ -27,8 +27,6 @@
> #include "problem.h"
> #include "uuid/uuid.h"
> 
> -static int bh_count = 0;
> -
> /*
>  * Define USE_INODE_IO to use the inode_io.c / fileio.c codepaths.
>  * This creates a larger static binary, and a smaller binary using
> @@ -42,147 +40,6 @@ static int bh_count = 0;
>  * to use the recovery.c file virtually unchanged from the kernel, so we
>  * don't have to do much to keep kernel and user recovery in sync.
>  */
> -int jbd2_journal_bmap(journal_t *journal, unsigned long block,
> -		      unsigned long long *phys)
> -{
> -#ifdef USE_INODE_IO
> -	*phys = block;
> -	return 0;
> -#else
> -	struct inode 	*inode = journal->j_inode;
> -	errcode_t	retval;
> -	blk64_t		pblk;
> -
> -	if (!inode) {
> -		*phys = block;
> -		return 0;
> -	}
> -
> -	retval= ext2fs_bmap2(inode->i_fs, inode->i_ino,
> -			     &inode->i_ext2, NULL, 0, (blk64_t) block,
> -			     0, &pblk);
> -	*phys = pblk;
> -	return -1 * ((int) retval);
> -#endif
> -}
> -
> -struct buffer_head *getblk(kdev_t kdev, unsigned long long blocknr,
> -			   int blocksize)
> -{
> -	struct buffer_head *bh;
> -	int bufsize = sizeof(*bh) + kdev->k_fs->blocksize -
> -		sizeof(bh->b_data);
> -	errcode_t retval;
> -
> -	retval = ext2fs_get_memzero(bufsize, &bh);
> -	if (retval)
> -		return NULL;
> -
> -	if (journal_enable_debug >= 3)
> -		bh_count++;
> -	jfs_debug(4, "getblk for block %llu (%d bytes)(total %d)\n",
> -		  blocknr, blocksize, bh_count);
> -
> -	bh->b_fs = kdev->k_fs;
> -	if (kdev->k_dev == K_DEV_FS)
> -		bh->b_io = kdev->k_fs->io;
> -	else
> -		bh->b_io = kdev->k_fs->journal_io;
> -	bh->b_size = blocksize;
> -	bh->b_blocknr = blocknr;
> -
> -	return bh;
> -}
> -
> -int sync_blockdev(kdev_t kdev)
> -{
> -	io_channel	io;
> -
> -	if (kdev->k_dev == K_DEV_FS)
> -		io = kdev->k_fs->io;
> -	else
> -		io = kdev->k_fs->journal_io;
> -
> -	return io_channel_flush(io) ? -EIO : 0;
> -}
> -
> -void ll_rw_block(int rw, int op_flags EXT2FS_ATTR((unused)), int nr,
> -		 struct buffer_head *bhp[])
> -{
> -	errcode_t retval;
> -	struct buffer_head *bh;
> -
> -	for (; nr > 0; --nr) {
> -		bh = *bhp++;
> -		if (rw == REQ_OP_READ && !bh->b_uptodate) {
> -			jfs_debug(3, "reading block %llu/%p\n",
> -				  bh->b_blocknr, (void *) bh);
> -			retval = io_channel_read_blk64(bh->b_io,
> -						     bh->b_blocknr,
> -						     1, bh->b_data);
> -			if (retval) {
> -				com_err(bh->b_fs->device_name, retval,
> -					"while reading block %llu\n",
> -					bh->b_blocknr);
> -				bh->b_err = (int) retval;
> -				continue;
> -			}
> -			bh->b_uptodate = 1;
> -		} else if (rw == REQ_OP_WRITE && bh->b_dirty) {
> -			jfs_debug(3, "writing block %llu/%p\n",
> -				  bh->b_blocknr,
> -				  (void *) bh);
> -			retval = io_channel_write_blk64(bh->b_io,
> -						      bh->b_blocknr,
> -						      1, bh->b_data);
> -			if (retval) {
> -				com_err(bh->b_fs->device_name, retval,
> -					"while writing block %llu\n",
> -					bh->b_blocknr);
> -				bh->b_err = (int) retval;
> -				continue;
> -			}
> -			bh->b_dirty = 0;
> -			bh->b_uptodate = 1;
> -		} else {
> -			jfs_debug(3, "no-op %s for block %llu\n",
> -				  rw == REQ_OP_READ ? "read" : "write",
> -				  bh->b_blocknr);
> -		}
> -	}
> -}
> -
> -void mark_buffer_dirty(struct buffer_head *bh)
> -{
> -	bh->b_dirty = 1;
> -}
> -
> -void brelse(struct buffer_head *bh)
> -{
> -	if (bh->b_dirty)
> -		ll_rw_block(REQ_OP_WRITE, 0, 1, &bh);
> -	jfs_debug(3, "freeing block %llu/%p (total %d)\n",
> -		  bh->b_blocknr, (void *) bh, --bh_count);
> -	ext2fs_free_mem(&bh);
> -}
> -
> -int buffer_uptodate(struct buffer_head *bh)
> -{
> -	return bh->b_uptodate;
> -}
> -
> -void mark_buffer_uptodate(struct buffer_head *bh, int val)
> -{
> -	bh->b_uptodate = val;
> -}
> -
> -void wait_on_buffer(struct buffer_head *bh)
> -{
> -	if (!bh->b_uptodate)
> -		ll_rw_block(REQ_OP_READ, 0, 1, &bh);
> -}
> -
> -
> static void e2fsck_clear_recover(e2fsck_t ctx, int error)
> {
> 	ext2fs_clear_feature_journal_needs_recovery(ctx->fs->super);
> diff --git a/lib/support/jfs_user.c b/lib/support/jfs_user.c
> index d8a2f842..26f0090b 100644
> --- a/lib/support/jfs_user.c
> +++ b/lib/support/jfs_user.c
> @@ -1,6 +1,8 @@
> #define DEBUGFS
> #include "jfs_user.h"
> 
> +static int bh_count = 0;
> +
> /*
>  * Define USE_INODE_IO to use the inode_io.c / fileio.c codepaths.
>  * This creates a larger static binary, and a smaller binary using
> @@ -60,12 +62,116 @@ errcode_t ext2fs_journal_sb_csum_set(journal_t *j,
> 	return 0;
> }
> 
> +void mark_buffer_dirty(struct buffer_head *bh)
> +{
> +	bh->b_dirty = 1;
> +}
> +
> +int buffer_uptodate(struct buffer_head *bh)
> +{
> +	return bh->b_uptodate;
> +}
> +
> +void mark_buffer_uptodate(struct buffer_head *bh, int val)
> +{
> +	bh->b_uptodate = val;
> +}
> +
> +void wait_on_buffer(struct buffer_head *bh)
> +{
> +	if (!bh->b_uptodate)
> +		ll_rw_block(REQ_OP_READ, 0, 1, &bh);
> +}
> 
> static void mark_buffer_clean(struct buffer_head * bh)
> {
> 	bh->b_dirty = 0;
> }
> 
> +struct buffer_head *getblk(kdev_t kdev, unsigned long long blocknr,
> +			   int blocksize)
> +{
> +	struct buffer_head *bh;
> +	int bufsize = sizeof(*bh) + kdev->k_fs->blocksize -
> +		sizeof(bh->b_data);
> +	errcode_t retval;
> +
> +	retval = ext2fs_get_memzero(bufsize, &bh);
> +	if (retval)
> +		return NULL;
> +
> +	if (journal_enable_debug >= 3)
> +		bh_count++;
> +	jfs_debug(4, "getblk for block %llu (%d bytes)(total %d)\n",
> +		  blocknr, blocksize, bh_count);
> +
> +	bh->b_fs = kdev->k_fs;
> +	if (kdev->k_dev == K_DEV_FS)
> +		bh->b_io = kdev->k_fs->io;
> +	else
> +		bh->b_io = kdev->k_fs->journal_io;
> +	bh->b_size = blocksize;
> +	bh->b_blocknr = blocknr;
> +
> +	return bh;
> +}
> +
> +void brelse(struct buffer_head *bh)
> +{
> +	if (bh->b_dirty)
> +		ll_rw_block(REQ_OP_WRITE, 0, 1, &bh);
> +	jfs_debug(3, "freeing block %llu/%p (total %d)\n",
> +		  bh->b_blocknr, (void *) bh, --bh_count);
> +	ext2fs_free_mem(&bh);
> +}
> +
> +void ll_rw_block(int rw, int op_flags EXT2FS_ATTR((unused)), int nr,
> +		 struct buffer_head *bhp[])
> +{
> +	errcode_t retval;
> +	struct buffer_head *bh;
> +
> +	for (; nr > 0; --nr) {
> +		bh = *bhp++;
> +		if (rw == REQ_OP_READ && !bh->b_uptodate) {
> +			jfs_debug(3, "reading block %llu/%p\n",
> +				  bh->b_blocknr, (void *) bh);
> +			retval = io_channel_read_blk64(bh->b_io,
> +						     bh->b_blocknr,
> +						     1, bh->b_data);
> +			if (retval) {
> +				com_err(bh->b_fs->device_name, retval,
> +					"while reading block %llu\n",
> +					bh->b_blocknr);
> +				bh->b_err = (int) retval;
> +				continue;
> +			}
> +			bh->b_uptodate = 1;
> +		} else if (rw == REQ_OP_WRITE && bh->b_dirty) {
> +			jfs_debug(3, "writing block %llu/%p\n",
> +				  bh->b_blocknr,
> +				  (void *) bh);
> +			retval = io_channel_write_blk64(bh->b_io,
> +						      bh->b_blocknr,
> +						      1, bh->b_data);
> +			if (retval) {
> +				com_err(bh->b_fs->device_name, retval,
> +					"while writing block %llu\n",
> +					bh->b_blocknr);
> +				bh->b_err = (int) retval;
> +				continue;
> +			}
> +			bh->b_dirty = 0;
> +			bh->b_uptodate = 1;
> +		} else {
> +			jfs_debug(3, "no-op %s for block %llu\n",
> +				  rw == REQ_OP_READ ? "read" : "write",
> +				  bh->b_blocknr);
> +		}
> +	}
> +}
> +
> +
> void ext2fs_journal_release(ext2_filsys fs, journal_t *journal,
> 			    int reset, int drop)
> {
> @@ -99,3 +205,39 @@ void ext2fs_journal_release(ext2_filsys fs, journal_t *journal,
> 		ext2fs_free_mem(&journal->j_fs_dev);
> 	ext2fs_free_mem(&journal);
> }
> +
> +int jbd2_journal_bmap(journal_t *journal, unsigned long block,
> +		      unsigned long long *phys)
> +{
> +#ifdef USE_INODE_IO
> +	*phys = block;
> +	return 0;
> +#else
> +	struct inode	*inode = journal->j_inode;
> +	errcode_t	retval;
> +	blk64_t		pblk;
> +
> +	if (!inode) {
> +		*phys = block;
> +		return 0;
> +	}
> +
> +	retval = ext2fs_bmap2(inode->i_fs, inode->i_ino,
> +			      &inode->i_ext2, NULL, 0, (blk64_t) block,
> +			      0, &pblk);
> +	*phys = pblk;
> +	return (int) retval;
> +#endif
> +}
> +
> +int sync_blockdev(kdev_t kdev)
> +{
> +	io_channel	io;
> +
> +	if (kdev->k_dev == K_DEV_FS)
> +		io = kdev->k_fs->io;
> +	else
> +		io = kdev->k_fs->journal_io;
> +
> +	return io_channel_flush(io) ? EIO : 0;
> +}
> --
> 2.31.1
> 
Cheers, Andreas
[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 873 bytes --]
^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: [PATCH 1/5] move a jfs_user.h to better place.
  2023-09-18 23:06 ` [PATCH 1/5] move a jfs_user.h to better place Andreas Dilger
@ 2023-09-21 14:19   ` Alexey Lyahkov
  0 siblings, 0 replies; 11+ messages in thread
From: Alexey Lyahkov @ 2023-09-21 14:19 UTC (permalink / raw)
  To: Andreas Dilger
  Cc: Ext4 Developers List, Theodore Ts'o, Artem Blagodarenko
Andreas,
Thanks for rebase to top of master branch. Adding a Signed-off-by: line is OK.
Alex
> On 19 Sep 2023, at 02:06, Andreas Dilger <adilger@dilger.ca> wrote:
> 
> On Aug 4, 2022, at 3:56 AM, Alexey Lyashkov <alexey.lyashkov@gmail.com> wrote:
>> 
>> jfs_user.h used in the debugfs and e2fsck, so
>> libsupport is better place for it.
>> just move a header into new place.
> 
> Alexey, this patch is missing a Signed-off-by: line.
> 
> The only other suggestion I would have is to rename the new file
> "jbd2_user.h" since the "jfs" filesystem name is conflicting.
> 
> Reviewed-by: Andreas Dilger <adilger@dilger.ca>
> 
>> ---
>> debugfs/Makefile.in                | 16 +++++++---------
>> debugfs/debugfs.c                  |  2 +-
>> debugfs/journal.h                  |  2 +-
>> debugfs/logdump.c                  |  2 +-
>> e2fsck/Makefile.in                 |  8 ++++----
>> e2fsck/journal.c                   |  2 +-
>> e2fsck/recovery.c                  |  2 +-
>> e2fsck/revoke.c                    |  2 +-
>> e2fsck/unix.c                      |  2 +-
>> lib/ext2fs/Makefile.in             | 18 ++++++++----------
>> {e2fsck => lib/support}/jfs_user.h |  0
>> misc/Makefile.in                   | 12 +++++-------
>> 12 files changed, 31 insertions(+), 37 deletions(-)
>> rename {e2fsck => lib/support}/jfs_user.h (100%)
>> 
>> diff --git a/debugfs/Makefile.in b/debugfs/Makefile.in
>> index ed4ea8d8..33658eea 100644
>> --- a/debugfs/Makefile.in
>> +++ b/debugfs/Makefile.in
>> @@ -47,9 +47,7 @@ STATIC_DEPLIBS= $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBSS) \
>> 		$(DEPSTATIC_LIBCOM_ERR) $(DEPSTATIC_LIBUUID) \
>> 		$(DEPSTATIC_LIBE2P)
>> 
>> -# This nastiness is needed because of jfs_user.h hackery; when we finally
>> -# clean up this mess, we should be able to drop it
>> -LOCAL_CFLAGS = -I$(srcdir)/../e2fsck -DDEBUGFS
>> +LOCAL_CFLAGS = -DDEBUGFS
>> DEPEND_CFLAGS = -I$(srcdir)
>> 
>> .c.o:
>> @@ -186,7 +184,7 @@ debugfs.o: $(srcdir)/debugfs.c $(top_builddir)/lib/config.h \
>> $(top_srcdir)/lib/e2p/e2p.h $(top_srcdir)/lib/support/quotaio.h \
>> $(top_srcdir)/lib/support/dqblk_v2.h \
>> $(top_srcdir)/lib/support/quotaio_tree.h $(top_srcdir)/version.h \
>> - $(srcdir)/../e2fsck/jfs_user.h $(top_srcdir)/lib/ext2fs/kernel-jbd.h \
>> + $(top_srcdir)/lib/support/jfs_user.h $(top_srcdir)/lib/ext2fs/kernel-jbd.h \
>> $(top_srcdir)/lib/ext2fs/jfs_compat.h $(top_srcdir)/lib/ext2fs/kernel-list.h \
>> $(top_srcdir)/lib/ext2fs/compiler.h $(top_srcdir)/lib/support/plausible.h
>> util.o: $(srcdir)/util.c $(top_builddir)/lib/config.h \
>> @@ -277,7 +275,7 @@ logdump.o: $(srcdir)/logdump.c $(top_builddir)/lib/config.h \
>> $(top_srcdir)/lib/ext2fs/bitops.h $(srcdir)/../misc/create_inode.h \
>> $(top_srcdir)/lib/e2p/e2p.h $(top_srcdir)/lib/support/quotaio.h \
>> $(top_srcdir)/lib/support/dqblk_v2.h \
>> - $(top_srcdir)/lib/support/quotaio_tree.h $(srcdir)/../e2fsck/jfs_user.h \
>> + $(top_srcdir)/lib/support/quotaio_tree.h $(top_srcdir)/lib/support/jfs_user.h \
>> $(top_srcdir)/lib/ext2fs/kernel-jbd.h $(top_srcdir)/lib/ext2fs/jfs_compat.h \
>> $(top_srcdir)/lib/ext2fs/kernel-list.h $(top_srcdir)/lib/ext2fs/compiler.h \
>> $(top_srcdir)/lib/ext2fs/fast_commit.h
>> @@ -382,7 +380,7 @@ quota.o: $(srcdir)/quota.c $(top_builddir)/lib/config.h \
>> $(top_srcdir)/lib/support/quotaio_tree.h
>> journal.o: $(srcdir)/journal.c $(top_builddir)/lib/config.h \
>> $(top_builddir)/lib/dirpaths.h $(srcdir)/journal.h \
>> - $(srcdir)/../e2fsck/jfs_user.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \
>> + $(top_srcdir)/lib/support/jfs_user.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \
>> $(top_builddir)/lib/ext2fs/ext2_types.h $(top_srcdir)/lib/ext2fs/ext2fs.h \
>> $(top_srcdir)/lib/ext2fs/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \
>> $(top_srcdir)/lib/ext2fs/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \
>> @@ -390,7 +388,7 @@ journal.o: $(srcdir)/journal.c $(top_builddir)/lib/config.h \
>> $(top_srcdir)/lib/ext2fs/bitops.h $(top_srcdir)/lib/ext2fs/kernel-jbd.h \
>> $(top_srcdir)/lib/ext2fs/jfs_compat.h $(top_srcdir)/lib/ext2fs/kernel-list.h \
>> $(top_srcdir)/lib/ext2fs/compiler.h
>> -revoke.o: $(srcdir)/../e2fsck/revoke.c $(srcdir)/../e2fsck/jfs_user.h \
>> +revoke.o: $(srcdir)/../e2fsck/revoke.c $(top_srcdir)/lib/support/jfs_user.h \
>> $(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h \
>> $(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/lib/ext2fs/ext3_extents.h \
>> $(top_srcdir)/lib/et/com_err.h $(top_srcdir)/lib/ext2fs/ext2_io.h \
>> @@ -399,7 +397,7 @@ revoke.o: $(srcdir)/../e2fsck/revoke.c $(srcdir)/../e2fsck/jfs_user.h \
>> $(top_srcdir)/lib/ext2fs/bitops.h $(top_srcdir)/lib/ext2fs/kernel-jbd.h \
>> $(top_srcdir)/lib/ext2fs/jfs_compat.h $(top_srcdir)/lib/ext2fs/kernel-list.h \
>> $(top_srcdir)/lib/ext2fs/compiler.h
>> -recovery.o: $(srcdir)/../e2fsck/recovery.c $(srcdir)/../e2fsck/jfs_user.h \
>> +recovery.o: $(srcdir)/../e2fsck/recovery.c $(top_srcdir)/lib/support/jfs_user.h \
>> $(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h \
>> $(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/lib/ext2fs/ext3_extents.h \
>> $(top_srcdir)/lib/et/com_err.h $(top_srcdir)/lib/ext2fs/ext2_io.h \
>> @@ -421,4 +419,4 @@ do_journal.o: $(srcdir)/do_journal.c $(top_builddir)/lib/config.h \
>> $(top_srcdir)/lib/support/quotaio_tree.h \
>> $(top_srcdir)/lib/ext2fs/kernel-jbd.h $(top_srcdir)/lib/ext2fs/jfs_compat.h \
>> $(top_srcdir)/lib/ext2fs/kernel-list.h $(top_srcdir)/lib/ext2fs/compiler.h \
>> - $(srcdir)/journal.h $(srcdir)/../e2fsck/jfs_user.h
>> + $(srcdir)/journal.h $(top_srcdir)/lib/support/jfs_user.h
>> diff --git a/debugfs/debugfs.c b/debugfs/debugfs.c
>> index b67a88bc..00b261ac 100644
>> --- a/debugfs/debugfs.c
>> +++ b/debugfs/debugfs.c
>> @@ -37,7 +37,7 @@ extern char *optarg;
>> #include <ext2fs/ext2_ext_attr.h>
>> 
>> #include "../version.h"
>> -#include "jfs_user.h"
>> +#include "support/jfs_user.h"
>> #include "support/plausible.h"
>> 
>> #ifndef BUFSIZ
>> diff --git a/debugfs/journal.h b/debugfs/journal.h
>> index 10b638eb..4d889834 100644
>> --- a/debugfs/journal.h
>> +++ b/debugfs/journal.h
>> @@ -12,7 +12,7 @@
>> * any later version.
>> */
>> 
>> -#include "jfs_user.h"
>> +#include "support/jfs_user.h"
>> 
>> /* journal.c */
>> errcode_t ext2fs_open_journal(ext2_filsys fs, journal_t **j);
>> diff --git a/debugfs/logdump.c b/debugfs/logdump.c
>> index 4154ef2a..f5427d5c 100644
>> --- a/debugfs/logdump.c
>> +++ b/debugfs/logdump.c
>> @@ -32,7 +32,7 @@ extern char *optarg;
>> 
>> #include "debugfs.h"
>> #include "blkid/blkid.h"
>> -#include "jfs_user.h"
>> +#include "support/jfs_user.h"
>> #if __GNUC_PREREQ (4, 6)
>> #pragma GCC diagnostic push
>> #pragma GCC diagnostic ignored "-Wunused-function"
>> diff --git a/e2fsck/Makefile.in b/e2fsck/Makefile.in
>> index 71ac3cf5..a6e11417 100644
>> --- a/e2fsck/Makefile.in
>> +++ b/e2fsck/Makefile.in
>> @@ -383,7 +383,7 @@ pass5.o: $(srcdir)/pass5.c $(top_builddir)/lib/config.h \
>> $(top_srcdir)/lib/ext2fs/kernel-list.h $(top_srcdir)/lib/ext2fs/compiler.h \
>> $(srcdir)/problem.h
>> journal.o: $(srcdir)/journal.c $(top_builddir)/lib/config.h \
>> - $(top_builddir)/lib/dirpaths.h $(srcdir)/jfs_user.h $(srcdir)/e2fsck.h \
>> + $(top_builddir)/lib/dirpaths.h $(top_srcdir)/lib/support/jfs_user.h $(srcdir)/e2fsck.h \
>> $(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h \
>> $(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/lib/ext2fs/ext3_extents.h \
>> $(top_srcdir)/lib/et/com_err.h $(top_srcdir)/lib/ext2fs/ext2_io.h \
>> @@ -396,7 +396,7 @@ journal.o: $(srcdir)/journal.c $(top_builddir)/lib/config.h \
>> $(top_srcdir)/lib/ext2fs/fast_commit.h $(top_srcdir)/lib/ext2fs/jfs_compat.h \
>> $(top_srcdir)/lib/ext2fs/kernel-list.h $(top_srcdir)/lib/ext2fs/compiler.h \
>> $(top_srcdir)/lib/ext2fs/kernel-jbd.h $(srcdir)/problem.h
>> -recovery.o: $(srcdir)/recovery.c $(srcdir)/jfs_user.h \
>> +recovery.o: $(srcdir)/recovery.c $(top_srcdir)/lib/support/jfs_user.h \
>> $(top_builddir)/lib/config.h $(top_builddir)/lib/dirpaths.h \
>> $(srcdir)/e2fsck.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \
>> $(top_builddir)/lib/ext2fs/ext2_types.h $(top_srcdir)/lib/ext2fs/ext2fs.h \
>> @@ -410,7 +410,7 @@ recovery.o: $(srcdir)/recovery.c $(srcdir)/jfs_user.h \
>> $(top_srcdir)/lib/ext2fs/fast_commit.h $(top_srcdir)/lib/ext2fs/jfs_compat.h \
>> $(top_srcdir)/lib/ext2fs/kernel-list.h $(top_srcdir)/lib/ext2fs/compiler.h \
>> $(top_srcdir)/lib/ext2fs/kernel-jbd.h
>> -revoke.o: $(srcdir)/revoke.c $(srcdir)/jfs_user.h \
>> +revoke.o: $(srcdir)/revoke.c $(top_srcdir)/lib/support/jfs_user.h \
>> $(top_builddir)/lib/config.h $(top_builddir)/lib/dirpaths.h \
>> $(srcdir)/e2fsck.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \
>> $(top_builddir)/lib/ext2fs/ext2_types.h $(top_srcdir)/lib/ext2fs/ext2fs.h \
>> @@ -464,7 +464,7 @@ unix.o: $(srcdir)/unix.c $(top_builddir)/lib/config.h \
>> $(top_srcdir)/lib/support/quotaio_tree.h \
>> $(top_srcdir)/lib/ext2fs/fast_commit.h $(top_srcdir)/lib/ext2fs/jfs_compat.h \
>> $(top_srcdir)/lib/ext2fs/kernel-list.h $(top_srcdir)/lib/ext2fs/compiler.h \
>> - $(srcdir)/problem.h $(srcdir)/jfs_user.h \
>> + $(srcdir)/problem.h $(top_srcdir)/lib/support/jfs_user.h \
>> $(top_srcdir)/lib/ext2fs/kernel-jbd.h $(top_srcdir)/version.h
>> dirinfo.o: $(srcdir)/dirinfo.c $(top_builddir)/lib/config.h \
>> $(top_builddir)/lib/dirpaths.h $(srcdir)/e2fsck.h \
>> diff --git a/e2fsck/journal.c b/e2fsck/journal.c
>> index 2e867234..d3002a62 100644
>> --- a/e2fsck/journal.c
>> +++ b/e2fsck/journal.c
>> @@ -23,7 +23,7 @@
>> #endif
>> 
>> #define E2FSCK_INCLUDE_INLINE_FUNCS
>> -#include "jfs_user.h"
>> +#include "support/jfs_user.h"
>> #include "problem.h"
>> #include "uuid/uuid.h"
>> 
>> diff --git a/e2fsck/recovery.c b/e2fsck/recovery.c
>> index 8ca35271..c7328cc5 100644
>> --- a/e2fsck/recovery.c
>> +++ b/e2fsck/recovery.c
>> @@ -11,7 +11,7 @@
>> */
>> 
>> #ifndef __KERNEL__
>> -#include "jfs_user.h"
>> +#include "support/jfs_user.h"
>> #else
>> #include <linux/time.h>
>> #include <linux/fs.h>
>> diff --git a/e2fsck/revoke.c b/e2fsck/revoke.c
>> index fa608788..1d5f910b 100644
>> --- a/e2fsck/revoke.c
>> +++ b/e2fsck/revoke.c
>> @@ -78,7 +78,7 @@
>> */
>> 
>> #ifndef __KERNEL__
>> -#include "jfs_user.h"
>> +#include "support/jfs_user.h"
>> #else
>> #include <linux/time.h>
>> #include <linux/fs.h>
>> diff --git a/e2fsck/unix.c b/e2fsck/unix.c
>> index ae231f93..474dde2d 100644
>> --- a/e2fsck/unix.c
>> +++ b/e2fsck/unix.c
>> @@ -54,7 +54,7 @@ extern int optind;
>> #include "support/plausible.h"
>> #include "e2fsck.h"
>> #include "problem.h"
>> -#include "jfs_user.h"
>> +#include "support/jfs_user.h"
>> #include "../version.h"
>> 
>> /* Command line options */
>> diff --git a/lib/ext2fs/Makefile.in b/lib/ext2fs/Makefile.in
>> index f6a050a2..5fa9693a 100644
>> --- a/lib/ext2fs/Makefile.in
>> +++ b/lib/ext2fs/Makefile.in
>> @@ -5,10 +5,8 @@ top_builddir = ../..
>> my_dir = lib/ext2fs
>> INSTALL = @INSTALL@
>> MKDIR_P = @MKDIR_P@
>> -DEPEND_CFLAGS = -I$(top_srcdir)/debugfs -I$(srcdir)/../../e2fsck -DDEBUGFS
>> -# This nastiness is needed because of jfs_user.h hackery; when we finally
>> -# clean up this mess, we should be able to drop it
>> -DEBUGFS_CFLAGS = -I$(srcdir)/../../e2fsck $(ALL_CFLAGS) -DDEBUGFS
>> +DEPEND_CFLAGS = -I$(top_srcdir)/debugfs -DDEBUGFS
>> +DEBUGFS_CFLAGS = $(ALL_CFLAGS) -DDEBUGFS
>> 
>> @MCONFIG@
>> 
>> @@ -1231,7 +1229,7 @@ debugfs.o: $(top_srcdir)/debugfs/debugfs.c $(top_builddir)/lib/config.h \
>> $(top_srcdir)/debugfs/../misc/create_inode.h $(top_srcdir)/lib/e2p/e2p.h \
>> $(top_srcdir)/lib/support/quotaio.h $(top_srcdir)/lib/support/dqblk_v2.h \
>> $(top_srcdir)/lib/support/quotaio_tree.h $(top_srcdir)/debugfs/../version.h \
>> - $(srcdir)/../../e2fsck/jfs_user.h $(srcdir)/kernel-jbd.h \
>> + $(top_srcdir)/lib/support/jfs_user.h $(srcdir)/kernel-jbd.h \
>> $(srcdir)/jfs_compat.h $(srcdir)/kernel-list.h $(srcdir)/compiler.h \
>> $(top_srcdir)/lib/support/plausible.h
>> util.o: $(top_srcdir)/debugfs/util.c $(top_builddir)/lib/config.h \
>> @@ -1321,7 +1319,7 @@ logdump.o: $(top_srcdir)/debugfs/logdump.c $(top_builddir)/lib/config.h \
>> $(srcdir)/hashmap.h $(srcdir)/bitops.h \
>> $(top_srcdir)/debugfs/../misc/create_inode.h $(top_srcdir)/lib/e2p/e2p.h \
>> $(top_srcdir)/lib/support/quotaio.h $(top_srcdir)/lib/support/dqblk_v2.h \
>> - $(top_srcdir)/lib/support/quotaio_tree.h $(srcdir)/../../e2fsck/jfs_user.h \
>> + $(top_srcdir)/lib/support/quotaio_tree.h $(top_srcdir)/lib/support/jfs_user.h \
>> $(srcdir)/kernel-jbd.h $(srcdir)/jfs_compat.h $(srcdir)/kernel-list.h \
>> $(srcdir)/compiler.h $(srcdir)/fast_commit.h
>> htree.o: $(top_srcdir)/debugfs/htree.c $(top_builddir)/lib/config.h \
>> @@ -1422,20 +1420,20 @@ create_inode.o: $(top_srcdir)/misc/create_inode.c \
>> $(top_srcdir)/lib/e2p/e2p.h $(top_srcdir)/lib/support/nls-enable.h
>> journal.o: $(top_srcdir)/debugfs/journal.c $(top_builddir)/lib/config.h \
>> $(top_builddir)/lib/dirpaths.h $(top_srcdir)/debugfs/journal.h \
>> - $(srcdir)/../../e2fsck/jfs_user.h $(srcdir)/ext2_fs.h \
>> + $(top_srcdir)/lib/support/jfs_user.h $(srcdir)/ext2_fs.h \
>> $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \
>> $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h $(srcdir)/ext2_io.h \
>> $(top_builddir)/lib/ext2fs/ext2_err.h $(srcdir)/ext2_ext_attr.h \
>> $(srcdir)/hashmap.h $(srcdir)/bitops.h $(srcdir)/kernel-jbd.h \
>> $(srcdir)/jfs_compat.h $(srcdir)/kernel-list.h $(srcdir)/compiler.h
>> -revoke.o: $(top_srcdir)/e2fsck/revoke.c $(top_srcdir)/e2fsck/jfs_user.h \
>> +revoke.o: $(top_srcdir)/e2fsck/revoke.c $(top_srcdir)/lib/support/jfs_user.h \
>> $(srcdir)/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h \
>> $(srcdir)/ext2fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \
>> $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \
>> $(srcdir)/ext2_ext_attr.h $(srcdir)/hashmap.h $(srcdir)/bitops.h \
>> $(srcdir)/kernel-jbd.h $(srcdir)/jfs_compat.h $(srcdir)/kernel-list.h \
>> $(srcdir)/compiler.h
>> -recovery.o: $(top_srcdir)/e2fsck/recovery.c $(top_srcdir)/e2fsck/jfs_user.h \
>> +recovery.o: $(top_srcdir)/e2fsck/recovery.c $(top_srcdir)/lib/support/jfs_user.h \
>> $(srcdir)/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h \
>> $(srcdir)/ext2fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \
>> $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \
>> @@ -1454,4 +1452,4 @@ do_journal.o: $(top_srcdir)/debugfs/do_journal.c $(top_builddir)/lib/config.h \
>> $(top_srcdir)/lib/support/quotaio.h $(top_srcdir)/lib/support/dqblk_v2.h \
>> $(top_srcdir)/lib/support/quotaio_tree.h $(srcdir)/kernel-jbd.h \
>> $(srcdir)/jfs_compat.h $(srcdir)/kernel-list.h $(srcdir)/compiler.h \
>> - $(top_srcdir)/debugfs/journal.h $(srcdir)/../../e2fsck/jfs_user.h
>> + $(top_srcdir)/debugfs/journal.h $(top_srcdir)/lib/support/jfs_user.h
>> diff --git a/e2fsck/jfs_user.h b/lib/support/jfs_user.h
>> similarity index 100%
>> rename from e2fsck/jfs_user.h
>> rename to lib/support/jfs_user.h
>> diff --git a/misc/Makefile.in b/misc/Makefile.in
>> index 4db59cdf..2d4c8087 100644
>> --- a/misc/Makefile.in
>> +++ b/misc/Makefile.in
>> @@ -124,10 +124,8 @@ DEPLIBS_E2P= $(LIBE2P) $(DEPLIBCOM_ERR)
>> 
>> COMPILE_ET=	_ET_DIR_OVERRIDE=$(srcdir)/../lib/et/et ../lib/et/compile_et
>> 
>> -# This nastiness is needed because of jfs_user.h hackery; when we finally
>> -# clean up this mess, we should be able to drop it
>> -JOURNAL_CFLAGS = -I$(srcdir)/../e2fsck $(ALL_CFLAGS) -DDEBUGFS
>> -DEPEND_CFLAGS = -I$(top_srcdir)/e2fsck
>> +JOURNAL_CFLAGS = -I $(ALL_CFLAGS) -DDEBUGFS
>> +DEPEND_CFLAGS =
>> 
>> .c.o:
>> 	$(E) "	CC $<"
>> @@ -878,7 +876,7 @@ check_fuzzer.o: $(srcdir)/check_fuzzer.c $(top_srcdir)/lib/ext2fs/ext2_fs.h \
>> $(top_srcdir)/lib/ext2fs/bitops.h
>> journal.o: $(srcdir)/../debugfs/journal.c $(top_builddir)/lib/config.h \
>> $(top_builddir)/lib/dirpaths.h $(srcdir)/../debugfs/journal.h \
>> - $(top_srcdir)/e2fsck/jfs_user.h $(top_srcdir)/e2fsck/e2fsck.h \
>> + $(top_srcdir)/lib/support/jfs_user.h $(top_srcdir)/e2fsck/e2fsck.h \
>> $(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h \
>> $(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/lib/ext2fs/ext3_extents.h \
>> $(top_srcdir)/lib/et/com_err.h $(top_srcdir)/lib/ext2fs/ext2_io.h \
>> @@ -891,7 +889,7 @@ journal.o: $(srcdir)/../debugfs/journal.c $(top_builddir)/lib/config.h \
>> $(top_srcdir)/lib/ext2fs/fast_commit.h $(top_srcdir)/lib/ext2fs/jfs_compat.h \
>> $(top_srcdir)/lib/ext2fs/kernel-list.h $(top_srcdir)/lib/ext2fs/compiler.h \
>> $(top_srcdir)/lib/ext2fs/kernel-jbd.h
>> -revoke.o: $(srcdir)/../e2fsck/revoke.c $(srcdir)/../e2fsck/jfs_user.h \
>> +revoke.o: $(srcdir)/../e2fsck/revoke.c $(top_srcdir)/lib/support/jfs_user.h \
>> $(top_builddir)/lib/config.h $(top_builddir)/lib/dirpaths.h \
>> $(srcdir)/../e2fsck/e2fsck.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \
>> $(top_builddir)/lib/ext2fs/ext2_types.h $(top_srcdir)/lib/ext2fs/ext2fs.h \
>> @@ -905,7 +903,7 @@ revoke.o: $(srcdir)/../e2fsck/revoke.c $(srcdir)/../e2fsck/jfs_user.h \
>> $(top_srcdir)/lib/ext2fs/fast_commit.h $(top_srcdir)/lib/ext2fs/jfs_compat.h \
>> $(top_srcdir)/lib/ext2fs/kernel-list.h $(top_srcdir)/lib/ext2fs/compiler.h \
>> $(top_srcdir)/lib/ext2fs/kernel-jbd.h
>> -recovery.o: $(srcdir)/../e2fsck/recovery.c $(srcdir)/../e2fsck/jfs_user.h \
>> +recovery.o: $(srcdir)/../e2fsck/recovery.c $(top_srcdir)/lib/support/jfs_user.h \
>> $(top_builddir)/lib/config.h $(top_builddir)/lib/dirpaths.h \
>> $(srcdir)/../e2fsck/e2fsck.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \
>> $(top_builddir)/lib/ext2fs/ext2_types.h $(top_srcdir)/lib/ext2fs/ext2fs.h \
>> --
>> 2.31.1
>> 
> 
> 
> Cheers, Andreas
> 
> 
> 
> 
> 
^ permalink raw reply	[flat|nested] 11+ messages in thread
end of thread, other threads:[~2023-09-21 21:14 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-04  9:56 [PATCH 1/5] move a jfs_user.h to better place Alexey Lyashkov
2022-08-04  9:56 ` [PATCH 2/5] move a journal checksum code into common place Alexey Lyashkov
2023-09-18 23:19   ` Andreas Dilger
2022-08-04  9:56 ` [PATCH 3/5] kill a ctx->journal_io Alexey Lyashkov
2023-09-18 23:43   ` Andreas Dilger
2022-08-04  9:56 ` [PATCH 4/5] remove an e2fsck context from bh emulation code Alexey Lyashkov
2023-09-18 23:57   ` Andreas Dilger
2022-08-04  9:56 ` [PATCH 5/5] deduplicate a buffer_head / kernel device code Alexey Lyashkov
2023-09-19  0:04   ` Andreas Dilger
2023-09-18 23:06 ` [PATCH 1/5] move a jfs_user.h to better place Andreas Dilger
2023-09-21 14:19   ` Alexey Lyahkov
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).