diff mbox series

[RFC,5/5] Enable threaded support for e2fsprogs' applications.

Message ID 20201205045856.895342-6-tytso@mit.edu
State Deferred
Headers show
Series Add threading support to e2fsprogs | expand

Commit Message

Theodore Ts'o Dec. 5, 2020, 4:58 a.m. UTC
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
---
 debugfs/debugfs.c | 6 ++++--
 e2fsck/unix.c     | 2 +-
 misc/dumpe2fs.c   | 2 +-
 misc/e2freefrag.c | 2 +-
 misc/e2fuzz.c     | 4 ++--
 misc/e2image.c    | 3 ++-
 misc/fuse2fs.c    | 3 ++-
 misc/tune2fs.c    | 3 ++-
 resize/main.c     | 2 +-
 9 files changed, 16 insertions(+), 11 deletions(-)

Comments

Andreas Dilger Dec. 11, 2020, 4:10 a.m. UTC | #1
On Dec 4, 2020, at 9:58 PM, Theodore Ts'o <tytso@mit.edu> wrote:
> 
> Signed-off-by: Theodore Ts'o <tytso@mit.edu>

My understanding is that as soon as the EXT2_FLAG_THREADS is added,
and if the backend supports CHANNEL_FLAGS_THREADS, then the pthread
code in the previous patch will "autothread" based on the number of
CPUs in the system.

That will be nice for debugfs, which would otherwise take ages to
start on a large filesystem if "-c" was not used (which also
precludes any kind of modifications).

Reviewed-by: Andreas Dilger <adilger@dilger.ca>

> ---
> debugfs/debugfs.c | 6 ++++--
> e2fsck/unix.c     | 2 +-
> misc/dumpe2fs.c   | 2 +-
> misc/e2freefrag.c | 2 +-
> misc/e2fuzz.c     | 4 ++--
> misc/e2image.c    | 3 ++-
> misc/fuse2fs.c    | 3 ++-
> misc/tune2fs.c    | 3 ++-
> resize/main.c     | 2 +-
> 9 files changed, 16 insertions(+), 11 deletions(-)
> 
> diff --git a/debugfs/debugfs.c b/debugfs/debugfs.c
> index 78e557792..132c5f9d9 100644
> --- a/debugfs/debugfs.c
> +++ b/debugfs/debugfs.c
> @@ -231,7 +231,8 @@ void do_open_filesys(int argc, char **argv, int sci_idx EXT2FS_ATTR((unused)),
> 	int	catastrophic = 0;
> 	blk64_t	superblock = 0;
> 	blk64_t	blocksize = 0;
> -	int	open_flags = EXT2_FLAG_SOFTSUPP_FEATURES | EXT2_FLAG_64BITS;
> +	int	open_flags = EXT2_FLAG_SOFTSUPP_FEATURES | EXT2_FLAG_64BITS |
> +		EXT2_FLAG_THREADS;
> 	char	*data_filename = 0;
> 	char	*undo_file = NULL;
> 
> @@ -2532,7 +2533,8 @@ int main(int argc, char **argv)
> #endif
> 		"[-c]] [device]";
> 	int		c;
> -	int		open_flags = EXT2_FLAG_SOFTSUPP_FEATURES | EXT2_FLAG_64BITS;
> +	int		open_flags = EXT2_FLAG_SOFTSUPP_FEATURES |
> +				EXT2_FLAG_64BITS | EXT2_FLAG_THREADS;
> 	char		*request = 0;
> 	int		exit_status = 0;
> 	char		*cmd_file = 0;
> diff --git a/e2fsck/unix.c b/e2fsck/unix.c
> index 1cb516721..dbeaeef5a 100644
> --- a/e2fsck/unix.c
> +++ b/e2fsck/unix.c
> @@ -1474,7 +1474,7 @@ int main (int argc, char *argv[])
> 	}
> 	ctx->superblock = ctx->use_superblock;
> 
> -	flags = EXT2_FLAG_SKIP_MMP;
> +	flags = EXT2_FLAG_SKIP_MMP | EXT2_FLAG_THREADS;
> restart:
> #ifdef CONFIG_TESTIO_DEBUG
> 	if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) {
> diff --git a/misc/dumpe2fs.c b/misc/dumpe2fs.c
> index d295ba4d4..82fb4e630 100644
> --- a/misc/dumpe2fs.c
> +++ b/misc/dumpe2fs.c
> @@ -665,7 +665,7 @@ int main (int argc, char ** argv)
> 
> 	device_name = argv[optind++];
> 	flags = EXT2_FLAG_JOURNAL_DEV_OK | EXT2_FLAG_SOFTSUPP_FEATURES |
> -		EXT2_FLAG_64BITS;
> +		EXT2_FLAG_64BITS | EXT2_FLAG_THREADS;
> 	if (force)
> 		flags |= EXT2_FLAG_FORCE;
> 	if (image_dump)
> diff --git a/misc/e2freefrag.c b/misc/e2freefrag.c
> index 9c23fadce..a9d16fc41 100644
> --- a/misc/e2freefrag.c
> +++ b/misc/e2freefrag.c
> @@ -363,7 +363,7 @@ static void collect_info(ext2_filsys fs, struct chunk_info *chunk_info, FILE *f)
> static void open_device(char *device_name, ext2_filsys *fs)
> {
> 	int retval;
> -	int flag = EXT2_FLAG_FORCE | EXT2_FLAG_64BITS;
> +	int flag = EXT2_FLAG_FORCE | EXT2_FLAG_64BITS | EXT2_FLAG_THREADS;
> 
> 	retval = ext2fs_open(device_name, flag, 0, 0, unix_io_manager, fs);
> 	if (retval) {
> diff --git a/misc/e2fuzz.c b/misc/e2fuzz.c
> index 685cdbe29..1ace1df5a 100644
> --- a/misc/e2fuzz.c
> +++ b/misc/e2fuzz.c
> @@ -201,8 +201,8 @@ static int process_fs(const char *fsname)
> 	}
> 
> 	/* Ensure the fs is clean and does not have errors */
> -	ret = ext2fs_open(fsname, EXT2_FLAG_64BITS, 0, 0, unix_io_manager,
> -			  &fs);
> +	ret = ext2fs_open(fsname, EXT2_FLAG_64BITS | EXT2_FLAG_THREADS,
> +			  0, 0, unix_io_manager, &fs);
> 	if (ret) {
> 		fprintf(stderr, "%s: failed to open filesystem.\n",
> 			fsname);
> diff --git a/misc/e2image.c b/misc/e2image.c
> index 892c5371e..e5e475653 100644
> --- a/misc/e2image.c
> +++ b/misc/e2image.c
> @@ -1482,7 +1482,8 @@ int main (int argc, char ** argv)
> 	ext2_filsys fs;
> 	char *image_fn, offset_opt[64];
> 	struct ext2_qcow2_hdr *header = NULL;
> -	int open_flag = EXT2_FLAG_64BITS | EXT2_FLAG_IGNORE_CSUM_ERRORS;
> +	int open_flag = EXT2_FLAG_64BITS | EXT2_FLAG_THREADS |
> +		EXT2_FLAG_IGNORE_CSUM_ERRORS;
> 	int img_type = 0;
> 	int flags = 0;
> 	int mount_flags = 0;
> diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
> index 4005894d3..c59572129 100644
> --- a/misc/fuse2fs.c
> +++ b/misc/fuse2fs.c
> @@ -3727,7 +3727,8 @@ int main(int argc, char *argv[])
> 	errcode_t err;
> 	char *logfile;
> 	char extra_args[BUFSIZ];
> -	int ret = 0, flags = EXT2_FLAG_64BITS | EXT2_FLAG_EXCLUSIVE;
> +	int ret = 0;
> +	int flags = EXT2_FLAG_64BITS | EXT2_FLAG_THREADS | EXT2_FLAG_EXCLUSIVE;
> 
> 	memset(&fctx, 0, sizeof(fctx));
> 	fctx.magic = FUSE2FS_MAGIC;
> diff --git a/misc/tune2fs.c b/misc/tune2fs.c
> index f942c698a..e5186fe0c 100644
> --- a/misc/tune2fs.c
> +++ b/misc/tune2fs.c
> @@ -2950,7 +2950,8 @@ retry_open:
> 	if ((open_flag & EXT2_FLAG_RW) == 0 || f_flag)
> 		open_flag |= EXT2_FLAG_SKIP_MMP;
> 
> -	open_flag |= EXT2_FLAG_64BITS | EXT2_FLAG_JOURNAL_DEV_OK;
> +	open_flag |= EXT2_FLAG_64BITS | EXT2_FLAG_THREADS |
> +		EXT2_FLAG_JOURNAL_DEV_OK;
> 
> 	/* keep the filesystem struct around to dump MMP data */
> 	open_flag |= EXT2_FLAG_NOFREE_ON_ERROR;
> diff --git a/resize/main.c b/resize/main.c
> index cb0bf6a0d..72a703f6a 100644
> --- a/resize/main.c
> +++ b/resize/main.c
> @@ -402,7 +402,7 @@ int main (int argc, char ** argv)
> 	if (!(mount_flags & EXT2_MF_MOUNTED))
> 		io_flags = EXT2_FLAG_RW | EXT2_FLAG_EXCLUSIVE;
> 
> -	io_flags |= EXT2_FLAG_64BITS;
> +	io_flags |= EXT2_FLAG_64BITS | EXT2_FLAG_THREADS;
> 	if (undo_file) {
> 		retval = resize2fs_setup_tdb(device_name, undo_file, &io_ptr);
> 		if (retval)
> --
> 2.28.0
> 


Cheers, Andreas
Theodore Ts'o Dec. 11, 2020, 10:37 p.m. UTC | #2
On Thu, Dec 10, 2020 at 09:10:09PM -0700, Andreas Dilger wrote:
> On Dec 4, 2020, at 9:58 PM, Theodore Ts'o <tytso@mit.edu> wrote:
> > 
> > Signed-off-by: Theodore Ts'o <tytso@mit.edu>
> 
> My understanding is that as soon as the EXT2_FLAG_THREADS is added,
> and if the backend supports CHANNEL_FLAGS_THREADS, then the pthread
> code in the previous patch will "autothread" based on the number of
> CPUs in the system.

Yep.

> That will be nice for debugfs, which would otherwise take ages to
> start on a large filesystem if "-c" was not used (which also
> precludes any kind of modifications).
> 
> Reviewed-by: Andreas Dilger <adilger@dilger.ca>

Yes, that's an issue that our SRE's have run across as well while
debugging customer problems, which is one of the reasons why I've been
interested in getting this change upstream first, even it takes a bit
longer to get all of the parallel fsck changes reviewed and upstream.

       	      	     	 	  - Ted
diff mbox series

Patch

diff --git a/debugfs/debugfs.c b/debugfs/debugfs.c
index 78e557792..132c5f9d9 100644
--- a/debugfs/debugfs.c
+++ b/debugfs/debugfs.c
@@ -231,7 +231,8 @@  void do_open_filesys(int argc, char **argv, int sci_idx EXT2FS_ATTR((unused)),
 	int	catastrophic = 0;
 	blk64_t	superblock = 0;
 	blk64_t	blocksize = 0;
-	int	open_flags = EXT2_FLAG_SOFTSUPP_FEATURES | EXT2_FLAG_64BITS; 
+	int	open_flags = EXT2_FLAG_SOFTSUPP_FEATURES | EXT2_FLAG_64BITS |
+		EXT2_FLAG_THREADS;
 	char	*data_filename = 0;
 	char	*undo_file = NULL;
 
@@ -2532,7 +2533,8 @@  int main(int argc, char **argv)
 #endif
 		"[-c]] [device]";
 	int		c;
-	int		open_flags = EXT2_FLAG_SOFTSUPP_FEATURES | EXT2_FLAG_64BITS;
+	int		open_flags = EXT2_FLAG_SOFTSUPP_FEATURES |
+				EXT2_FLAG_64BITS | EXT2_FLAG_THREADS;
 	char		*request = 0;
 	int		exit_status = 0;
 	char		*cmd_file = 0;
diff --git a/e2fsck/unix.c b/e2fsck/unix.c
index 1cb516721..dbeaeef5a 100644
--- a/e2fsck/unix.c
+++ b/e2fsck/unix.c
@@ -1474,7 +1474,7 @@  int main (int argc, char *argv[])
 	}
 	ctx->superblock = ctx->use_superblock;
 
-	flags = EXT2_FLAG_SKIP_MMP;
+	flags = EXT2_FLAG_SKIP_MMP | EXT2_FLAG_THREADS;
 restart:
 #ifdef CONFIG_TESTIO_DEBUG
 	if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) {
diff --git a/misc/dumpe2fs.c b/misc/dumpe2fs.c
index d295ba4d4..82fb4e630 100644
--- a/misc/dumpe2fs.c
+++ b/misc/dumpe2fs.c
@@ -665,7 +665,7 @@  int main (int argc, char ** argv)
 
 	device_name = argv[optind++];
 	flags = EXT2_FLAG_JOURNAL_DEV_OK | EXT2_FLAG_SOFTSUPP_FEATURES |
-		EXT2_FLAG_64BITS;
+		EXT2_FLAG_64BITS | EXT2_FLAG_THREADS;
 	if (force)
 		flags |= EXT2_FLAG_FORCE;
 	if (image_dump)
diff --git a/misc/e2freefrag.c b/misc/e2freefrag.c
index 9c23fadce..a9d16fc41 100644
--- a/misc/e2freefrag.c
+++ b/misc/e2freefrag.c
@@ -363,7 +363,7 @@  static void collect_info(ext2_filsys fs, struct chunk_info *chunk_info, FILE *f)
 static void open_device(char *device_name, ext2_filsys *fs)
 {
 	int retval;
-	int flag = EXT2_FLAG_FORCE | EXT2_FLAG_64BITS;
+	int flag = EXT2_FLAG_FORCE | EXT2_FLAG_64BITS | EXT2_FLAG_THREADS;
 
 	retval = ext2fs_open(device_name, flag, 0, 0, unix_io_manager, fs);
 	if (retval) {
diff --git a/misc/e2fuzz.c b/misc/e2fuzz.c
index 685cdbe29..1ace1df5a 100644
--- a/misc/e2fuzz.c
+++ b/misc/e2fuzz.c
@@ -201,8 +201,8 @@  static int process_fs(const char *fsname)
 	}
 
 	/* Ensure the fs is clean and does not have errors */
-	ret = ext2fs_open(fsname, EXT2_FLAG_64BITS, 0, 0, unix_io_manager,
-			  &fs);
+	ret = ext2fs_open(fsname, EXT2_FLAG_64BITS | EXT2_FLAG_THREADS,
+			  0, 0, unix_io_manager, &fs);
 	if (ret) {
 		fprintf(stderr, "%s: failed to open filesystem.\n",
 			fsname);
diff --git a/misc/e2image.c b/misc/e2image.c
index 892c5371e..e5e475653 100644
--- a/misc/e2image.c
+++ b/misc/e2image.c
@@ -1482,7 +1482,8 @@  int main (int argc, char ** argv)
 	ext2_filsys fs;
 	char *image_fn, offset_opt[64];
 	struct ext2_qcow2_hdr *header = NULL;
-	int open_flag = EXT2_FLAG_64BITS | EXT2_FLAG_IGNORE_CSUM_ERRORS;
+	int open_flag = EXT2_FLAG_64BITS | EXT2_FLAG_THREADS |
+		EXT2_FLAG_IGNORE_CSUM_ERRORS;
 	int img_type = 0;
 	int flags = 0;
 	int mount_flags = 0;
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 4005894d3..c59572129 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -3727,7 +3727,8 @@  int main(int argc, char *argv[])
 	errcode_t err;
 	char *logfile;
 	char extra_args[BUFSIZ];
-	int ret = 0, flags = EXT2_FLAG_64BITS | EXT2_FLAG_EXCLUSIVE;
+	int ret = 0;
+	int flags = EXT2_FLAG_64BITS | EXT2_FLAG_THREADS | EXT2_FLAG_EXCLUSIVE;
 
 	memset(&fctx, 0, sizeof(fctx));
 	fctx.magic = FUSE2FS_MAGIC;
diff --git a/misc/tune2fs.c b/misc/tune2fs.c
index f942c698a..e5186fe0c 100644
--- a/misc/tune2fs.c
+++ b/misc/tune2fs.c
@@ -2950,7 +2950,8 @@  retry_open:
 	if ((open_flag & EXT2_FLAG_RW) == 0 || f_flag)
 		open_flag |= EXT2_FLAG_SKIP_MMP;
 
-	open_flag |= EXT2_FLAG_64BITS | EXT2_FLAG_JOURNAL_DEV_OK;
+	open_flag |= EXT2_FLAG_64BITS | EXT2_FLAG_THREADS |
+		EXT2_FLAG_JOURNAL_DEV_OK;
 
 	/* keep the filesystem struct around to dump MMP data */
 	open_flag |= EXT2_FLAG_NOFREE_ON_ERROR;
diff --git a/resize/main.c b/resize/main.c
index cb0bf6a0d..72a703f6a 100644
--- a/resize/main.c
+++ b/resize/main.c
@@ -402,7 +402,7 @@  int main (int argc, char ** argv)
 	if (!(mount_flags & EXT2_MF_MOUNTED))
 		io_flags = EXT2_FLAG_RW | EXT2_FLAG_EXCLUSIVE;
 
-	io_flags |= EXT2_FLAG_64BITS;
+	io_flags |= EXT2_FLAG_64BITS | EXT2_FLAG_THREADS;
 	if (undo_file) {
 		retval = resize2fs_setup_tdb(device_name, undo_file, &io_ptr);
 		if (retval)