Linux-ext4 Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] ext2fs: add ext2fs_read_sb that returns superblock
@ 2019-09-05 11:01 Artem Blagodarenko
  2019-09-17 18:22 ` Благодаренко Артём
  0 siblings, 1 reply; 3+ messages in thread
From: Artem Blagodarenko @ 2019-09-05 11:01 UTC (permalink / raw)
  To: linux-ext4; +Cc: adilger.kernel

tune2fs is used to make e2label duties.  ext2fs_open2() reads group
descriptors which are not used during disk label obtaining, but takes
a lot of time on large partitions.

This patch adds ext2fs_read_sb(), there only initialized superblock
is returned This saves time dramatically.

Signed-off-by: Artem Blagodarenko <c17828@cray.com>
Cray-bug-id: LUS-5777
---
 lib/ext2fs/ext2fs.h |  2 ++
 lib/ext2fs/openfs.c | 16 ++++++++++++++++
 misc/tune2fs.c      | 23 +++++++++++++++--------
 3 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h
index 59fd9742..3a63b74d 100644
--- a/lib/ext2fs/ext2fs.h
+++ b/lib/ext2fs/ext2fs.h
@@ -1630,6 +1630,8 @@ extern int ext2fs_journal_sb_start(int blocksize);
 extern errcode_t ext2fs_open(const char *name, int flags, int superblock,
 			     unsigned int block_size, io_manager manager,
 			     ext2_filsys *ret_fs);
+extern errcode_t ext2fs_read_sb(const char *name, io_manager manager,
+				struct ext2_super_block * super);
 extern errcode_t ext2fs_open2(const char *name, const char *io_options,
 			      int flags, int superblock,
 			      unsigned int block_size, io_manager manager,
diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c
index 51b54a44..95f45d84 100644
--- a/lib/ext2fs/openfs.c
+++ b/lib/ext2fs/openfs.c
@@ -99,6 +99,22 @@ static void block_sha_map_free_entry(void *data)
 	return;
 }
 
+errcode_t ext2fs_read_sb(const char *name, io_manager manager,
+			 struct ext2_super_block * super)
+{
+	io_channel	io;
+	errcode_t	retval = 0;
+
+	retval = manager->open(name, 0, &io);
+	if (!retval) {
+		retval = io_channel_read_blk(io, 1, -SUPERBLOCK_SIZE,
+				     super);
+		io_channel_close(io);
+	}
+
+	return retval;
+}
+
 /*
  *  Note: if superblock is non-zero, block-size must also be non-zero.
  * 	Superblock and block_size can be zero to use the default size.
diff --git a/misc/tune2fs.c b/misc/tune2fs.c
index 7d2d38d7..fea607e1 100644
--- a/misc/tune2fs.c
+++ b/misc/tune2fs.c
@@ -2879,6 +2879,21 @@ int tune2fs_main(int argc, char **argv)
 #endif
 		io_ptr = unix_io_manager;
 
+	if (print_label) {
+		/* For e2label emulation */
+		struct ext2_super_block sb;
+
+		/* Read only superblock. Nothing else metters.*/
+		retval = ext2fs_read_sb(device_name, io_ptr, &sb);
+		if (!retval) {
+			printf("%.*s\n", (int) sizeof(sb.s_volume_name),
+			       sb.s_volume_name);
+		}
+
+		remove_error_table(&et_ext2_error_table);
+		return retval;
+	}
+
 retry_open:
 	if ((open_flag & EXT2_FLAG_RW) == 0 || f_flag)
 		open_flag |= EXT2_FLAG_SKIP_MMP;
@@ -2972,14 +2987,6 @@ retry_open:
 	sb = fs->super;
 	fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY;
 
-	if (print_label) {
-		/* For e2label emulation */
-		printf("%.*s\n", (int) sizeof(sb->s_volume_name),
-		       sb->s_volume_name);
-		remove_error_table(&et_ext2_error_table);
-		goto closefs;
-	}
-
 	retval = ext2fs_check_if_mounted(device_name, &mount_flags);
 	if (retval) {
 		com_err("ext2fs_check_if_mount", retval,
-- 
2.14.3


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ext2fs: add ext2fs_read_sb that returns superblock
  2019-09-05 11:01 [PATCH] ext2fs: add ext2fs_read_sb that returns superblock Artem Blagodarenko
@ 2019-09-17 18:22 ` Благодаренко Артём
  2019-09-17 20:20   ` Andreas Dilger
  0 siblings, 1 reply; 3+ messages in thread
From: Благодаренко Артём @ 2019-09-17 18:22 UTC (permalink / raw)
  To: linux-ext4; +Cc: adilger.kernel

Hello,

Should I change anything it this patch?

Thanks,
Artem Blagodarenko.

> On 5 Sep 2019, at 14:01, Artem Blagodarenko <artem.blagodarenko@gmail.com> wrote:
> 
> tune2fs is used to make e2label duties.  ext2fs_open2() reads group
> descriptors which are not used during disk label obtaining, but takes
> a lot of time on large partitions.
> 
> This patch adds ext2fs_read_sb(), there only initialized superblock
> is returned This saves time dramatically.
> 
> Signed-off-by: Artem Blagodarenko <c17828@cray.com>
> Cray-bug-id: LUS-5777
> ---
> lib/ext2fs/ext2fs.h |  2 ++
> lib/ext2fs/openfs.c | 16 ++++++++++++++++
> misc/tune2fs.c      | 23 +++++++++++++++--------
> 3 files changed, 33 insertions(+), 8 deletions(-)
> 
> diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h
> index 59fd9742..3a63b74d 100644
> --- a/lib/ext2fs/ext2fs.h
> +++ b/lib/ext2fs/ext2fs.h
> @@ -1630,6 +1630,8 @@ extern int ext2fs_journal_sb_start(int blocksize);
> extern errcode_t ext2fs_open(const char *name, int flags, int superblock,
> 			     unsigned int block_size, io_manager manager,
> 			     ext2_filsys *ret_fs);
> +extern errcode_t ext2fs_read_sb(const char *name, io_manager manager,
> +				struct ext2_super_block * super);
> extern errcode_t ext2fs_open2(const char *name, const char *io_options,
> 			      int flags, int superblock,
> 			      unsigned int block_size, io_manager manager,
> diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c
> index 51b54a44..95f45d84 100644
> --- a/lib/ext2fs/openfs.c
> +++ b/lib/ext2fs/openfs.c
> @@ -99,6 +99,22 @@ static void block_sha_map_free_entry(void *data)
> 	return;
> }
> 
> +errcode_t ext2fs_read_sb(const char *name, io_manager manager,
> +			 struct ext2_super_block * super)
> +{
> +	io_channel	io;
> +	errcode_t	retval = 0;
> +
> +	retval = manager->open(name, 0, &io);
> +	if (!retval) {
> +		retval = io_channel_read_blk(io, 1, -SUPERBLOCK_SIZE,
> +				     super);
> +		io_channel_close(io);
> +	}
> +
> +	return retval;
> +}
> +
> /*
>  *  Note: if superblock is non-zero, block-size must also be non-zero.
>  * 	Superblock and block_size can be zero to use the default size.
> diff --git a/misc/tune2fs.c b/misc/tune2fs.c
> index 7d2d38d7..fea607e1 100644
> --- a/misc/tune2fs.c
> +++ b/misc/tune2fs.c
> @@ -2879,6 +2879,21 @@ int tune2fs_main(int argc, char **argv)
> #endif
> 		io_ptr = unix_io_manager;
> 
> +	if (print_label) {
> +		/* For e2label emulation */
> +		struct ext2_super_block sb;
> +
> +		/* Read only superblock. Nothing else metters.*/
> +		retval = ext2fs_read_sb(device_name, io_ptr, &sb);
> +		if (!retval) {
> +			printf("%.*s\n", (int) sizeof(sb.s_volume_name),
> +			       sb.s_volume_name);
> +		}
> +
> +		remove_error_table(&et_ext2_error_table);
> +		return retval;
> +	}
> +
> retry_open:
> 	if ((open_flag & EXT2_FLAG_RW) == 0 || f_flag)
> 		open_flag |= EXT2_FLAG_SKIP_MMP;
> @@ -2972,14 +2987,6 @@ retry_open:
> 	sb = fs->super;
> 	fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY;
> 
> -	if (print_label) {
> -		/* For e2label emulation */
> -		printf("%.*s\n", (int) sizeof(sb->s_volume_name),
> -		       sb->s_volume_name);
> -		remove_error_table(&et_ext2_error_table);
> -		goto closefs;
> -	}
> -
> 	retval = ext2fs_check_if_mounted(device_name, &mount_flags);
> 	if (retval) {
> 		com_err("ext2fs_check_if_mount", retval,
> -- 
> 2.14.3
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ext2fs: add ext2fs_read_sb that returns superblock
  2019-09-17 18:22 ` Благодаренко Артём
@ 2019-09-17 20:20   ` Andreas Dilger
  0 siblings, 0 replies; 3+ messages in thread
From: Andreas Dilger @ 2019-09-17 20:20 UTC (permalink / raw)
  To: Благодаренко
	Артём
  Cc: linux-ext4

[-- Attachment #1: Type: text/plain, Size: 3780 bytes --]


> On Sep 17, 2019, at 12:22 PM, Благодаренко Артём <artem.blagodarenko@gmail.com> wrote:
> 
> Hello,
> 
> Should I change anything it this patch?

Looks OK to me:

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

> 
> Thanks,
> Artem Blagodarenko.
> 
>> On 5 Sep 2019, at 14:01, Artem Blagodarenko <artem.blagodarenko@gmail.com> wrote:
>> 
>> tune2fs is used to make e2label duties.  ext2fs_open2() reads group
>> descriptors which are not used during disk label obtaining, but takes
>> a lot of time on large partitions.
>> 
>> This patch adds ext2fs_read_sb(), there only initialized superblock
>> is returned This saves time dramatically.
>> 
>> Signed-off-by: Artem Blagodarenko <c17828@cray.com>
>> Cray-bug-id: LUS-5777
>> ---
>> lib/ext2fs/ext2fs.h |  2 ++
>> lib/ext2fs/openfs.c | 16 ++++++++++++++++
>> misc/tune2fs.c      | 23 +++++++++++++++--------
>> 3 files changed, 33 insertions(+), 8 deletions(-)
>> 
>> diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h
>> index 59fd9742..3a63b74d 100644
>> --- a/lib/ext2fs/ext2fs.h
>> +++ b/lib/ext2fs/ext2fs.h
>> @@ -1630,6 +1630,8 @@ extern int ext2fs_journal_sb_start(int blocksize);
>> extern errcode_t ext2fs_open(const char *name, int flags, int superblock,
>> 			     unsigned int block_size, io_manager manager,
>> 			     ext2_filsys *ret_fs);
>> +extern errcode_t ext2fs_read_sb(const char *name, io_manager manager,
>> +				struct ext2_super_block * super);
>> extern errcode_t ext2fs_open2(const char *name, const char *io_options,
>> 			      int flags, int superblock,
>> 			      unsigned int block_size, io_manager manager,
>> diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c
>> index 51b54a44..95f45d84 100644
>> --- a/lib/ext2fs/openfs.c
>> +++ b/lib/ext2fs/openfs.c
>> @@ -99,6 +99,22 @@ static void block_sha_map_free_entry(void *data)
>> 	return;
>> }
>> 
>> +errcode_t ext2fs_read_sb(const char *name, io_manager manager,
>> +			 struct ext2_super_block * super)
>> +{
>> +	io_channel	io;
>> +	errcode_t	retval = 0;
>> +
>> +	retval = manager->open(name, 0, &io);
>> +	if (!retval) {
>> +		retval = io_channel_read_blk(io, 1, -SUPERBLOCK_SIZE,
>> +				     super);
>> +		io_channel_close(io);
>> +	}
>> +
>> +	return retval;
>> +}
>> +
>> /*
>> *  Note: if superblock is non-zero, block-size must also be non-zero.
>> * 	Superblock and block_size can be zero to use the default size.
>> diff --git a/misc/tune2fs.c b/misc/tune2fs.c
>> index 7d2d38d7..fea607e1 100644
>> --- a/misc/tune2fs.c
>> +++ b/misc/tune2fs.c
>> @@ -2879,6 +2879,21 @@ int tune2fs_main(int argc, char **argv)
>> #endif
>> 		io_ptr = unix_io_manager;
>> 
>> +	if (print_label) {
>> +		/* For e2label emulation */
>> +		struct ext2_super_block sb;
>> +
>> +		/* Read only superblock. Nothing else metters.*/
>> +		retval = ext2fs_read_sb(device_name, io_ptr, &sb);
>> +		if (!retval) {
>> +			printf("%.*s\n", (int) sizeof(sb.s_volume_name),
>> +			       sb.s_volume_name);
>> +		}
>> +
>> +		remove_error_table(&et_ext2_error_table);
>> +		return retval;
>> +	}
>> +
>> retry_open:
>> 	if ((open_flag & EXT2_FLAG_RW) == 0 || f_flag)
>> 		open_flag |= EXT2_FLAG_SKIP_MMP;
>> @@ -2972,14 +2987,6 @@ retry_open:
>> 	sb = fs->super;
>> 	fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY;
>> 
>> -	if (print_label) {
>> -		/* For e2label emulation */
>> -		printf("%.*s\n", (int) sizeof(sb->s_volume_name),
>> -		       sb->s_volume_name);
>> -		remove_error_table(&et_ext2_error_table);
>> -		goto closefs;
>> -	}
>> -
>> 	retval = ext2fs_check_if_mounted(device_name, &mount_flags);
>> 	if (retval) {
>> 		com_err("ext2fs_check_if_mount", retval,
>> --
>> 2.14.3
>> 
> 


Cheers, Andreas






[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 873 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-05 11:01 [PATCH] ext2fs: add ext2fs_read_sb that returns superblock Artem Blagodarenko
2019-09-17 18:22 ` Благодаренко Артём
2019-09-17 20:20   ` Andreas Dilger

Linux-ext4 Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-ext4/0 linux-ext4/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-ext4 linux-ext4/ https://lore.kernel.org/linux-ext4 \
		linux-ext4@vger.kernel.org linux-ext4@archiver.kernel.org
	public-inbox-index linux-ext4


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-ext4


AGPL code for this site: git clone https://public-inbox.org/ public-inbox