All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fsck.f2fs: add -O features to tune the bits
@ 2018-04-19 20:54 Jaegeuk Kim
  2018-04-20  1:46 ` Junling Zheng
  2018-04-23  3:55 ` [PATCH] fsck.f2fs: add -O features to tune the bits Chao Yu
  0 siblings, 2 replies; 13+ messages in thread
From: Jaegeuk Kim @ 2018-04-19 20:54 UTC (permalink / raw)
  To: linux-f2fs-devel; +Cc: Jaegeuk Kim

This patch add -O features for fsck.f2fs in order to tune the feature bits.
Currently, it supports -O encrypt only.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
 fsck/fsck.h   |  1 +
 fsck/main.c   |  9 ++++++++-
 fsck/mount.c  | 39 ++++++++++++++++++++++++++++++++++++++-
 fsck/resize.c | 18 +-----------------
 4 files changed, 48 insertions(+), 19 deletions(-)

diff --git a/fsck/fsck.h b/fsck/fsck.h
index 8e133fa..3e13fc6 100644
--- a/fsck/fsck.h
+++ b/fsck/fsck.h
@@ -176,6 +176,7 @@ extern void move_curseg_info(struct f2fs_sb_info *, u64);
 extern void write_curseg_info(struct f2fs_sb_info *);
 extern int find_next_free_block(struct f2fs_sb_info *, u64 *, int, int);
 extern void write_checkpoint(struct f2fs_sb_info *);
+extern void write_superblock(struct f2fs_super_block *);
 extern void update_data_blkaddr(struct f2fs_sb_info *, nid_t, u16, block_t);
 extern void update_nat_blkaddr(struct f2fs_sb_info *, nid_t, nid_t, block_t);
 
diff --git a/fsck/main.c b/fsck/main.c
index 9256d21..c4dd8b1 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -28,6 +28,8 @@ struct f2fs_fsck gfsck;
 extern struct sparse_file *f2fs_sparse_file;
 #endif
 
+INIT_FEATURE_TABLE;
+
 static char *absolute_path(const char *file)
 {
 	char *ret;
@@ -54,6 +56,7 @@ void fsck_usage()
 	MSG(0, "  -d debug level [default:0]\n");
 	MSG(0, "  -f check/fix entire partition\n");
 	MSG(0, "  -g add default options\n");
+	MSG(0, "  -O feature1[feature2,feature3,...] e.g. \"encrypt\"\n");
 	MSG(0, "  -p preen mode [default:0 the same as -a [0|1]]\n");
 	MSG(0, "  -S sparse_mode\n");
 	MSG(0, "  -t show directory tree\n");
@@ -180,7 +183,7 @@ void f2fs_parse_options(int argc, char *argv[])
 	}
 
 	if (!strcmp("fsck.f2fs", prog)) {
-		const char *option_string = ":ad:fg:p:q:StyV";
+		const char *option_string = ":ad:fg:O:p:q:StyV";
 		int opt = 0;
 		struct option long_opt[] = {
 			{"dry-run", no_argument, 0, 1},
@@ -203,6 +206,10 @@ void f2fs_parse_options(int argc, char *argv[])
 				if (!strcmp(optarg, "android"))
 					c.defset = CONF_ANDROID;
 				break;
+			case 'O':
+				if (parse_feature(feature_table, optarg))
+					fsck_usage();
+				break;
 			case 'p':
 				/* preen mode has different levels:
 				 *  0: default level, the same as -a
diff --git a/fsck/mount.c b/fsck/mount.c
index e5574c5..b374b46 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -2144,6 +2144,22 @@ void write_checkpoint(struct f2fs_sb_info *sbi)
 	ASSERT(ret >= 0);
 }
 
+void write_superblock(struct f2fs_super_block *new_sb)
+{
+	int index, ret;
+	u_int8_t *buf;
+
+	buf = calloc(BLOCK_SZ, 1);
+
+	memcpy(buf + F2FS_SUPER_OFFSET, new_sb, sizeof(*new_sb));
+	for (index = 0; index < 2; index++) {
+		ret = dev_write_block(buf, index);
+		ASSERT(ret >= 0);
+	}
+	free(buf);
+	DBG(0, "Info: Done to rebuild superblock\n");
+}
+
 void build_nat_area_bitmap(struct f2fs_sb_info *sbi)
 {
 	struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA);
@@ -2314,6 +2330,26 @@ static int check_sector_size(struct f2fs_super_block *sb)
 	return 0;
 }
 
+static void tune_sb_features(struct f2fs_sb_info *sbi)
+{
+	int sb_changed = 0;
+	struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi);
+
+	if (!(sb->feature & cpu_to_le32(F2FS_FEATURE_ENCRYPT)) &&
+			c.feature & cpu_to_le32(F2FS_FEATURE_ENCRYPT)) {
+		sb->feature |= cpu_to_le32(F2FS_FEATURE_ENCRYPT);
+		MSG(0, "Info: Set Encryption feature\n");
+		sb_changed = 1;
+	}
+	/* TODO: quota needs to allocate inode numbers */
+
+	c.feature = sb->feature;
+	if (!sb_changed)
+		return;
+
+	write_superblock(sb);
+}
+
 int f2fs_do_mount(struct f2fs_sb_info *sbi)
 {
 	struct f2fs_checkpoint *cp = NULL;
@@ -2365,7 +2401,8 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi)
 	}
 
 	c.bug_on = 0;
-	c.feature = sb->feature;
+
+	tune_sb_features(sbi);
 
 	/* precompute checksum seed for metadata */
 	if (c.feature & cpu_to_le32(F2FS_FEATURE_INODE_CHKSUM))
diff --git a/fsck/resize.c b/fsck/resize.c
index 019da71..d285dd7 100644
--- a/fsck/resize.c
+++ b/fsck/resize.c
@@ -569,22 +569,6 @@ static void rebuild_checkpoint(struct f2fs_sb_info *sbi,
 	DBG(0, "Info: Done to rebuild checkpoint blocks\n");
 }
 
-static void rebuild_superblock(struct f2fs_super_block *new_sb)
-{
-	int index, ret;
-	u_int8_t *buf;
-
-	buf = calloc(BLOCK_SZ, 1);
-
-	memcpy(buf + F2FS_SUPER_OFFSET, new_sb, sizeof(*new_sb));
-	for (index = 0; index < 2; index++) {
-		ret = dev_write_block(buf, index);
-		ASSERT(ret >= 0);
-	}
-	free(buf);
-	DBG(0, "Info: Done to rebuild superblock\n");
-}
-
 int f2fs_resize(struct f2fs_sb_info *sbi)
 {
 	struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi);
@@ -636,6 +620,6 @@ int f2fs_resize(struct f2fs_sb_info *sbi)
 	migrate_nat(sbi, new_sb);
 	migrate_sit(sbi, new_sb, offset_seg);
 	rebuild_checkpoint(sbi, new_sb, offset_seg);
-	rebuild_superblock(new_sb);
+	write_superblock(new_sb);
 	return 0;
 }
-- 
2.17.0.484.g0c8726318c-goog


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

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

* Re: [PATCH] fsck.f2fs: add -O features to tune the bits
  2018-04-19 20:54 [PATCH] fsck.f2fs: add -O features to tune the bits Jaegeuk Kim
@ 2018-04-20  1:46 ` Junling Zheng
  2018-04-20  1:57   ` Chao Yu
  2018-04-23  3:55 ` [PATCH] fsck.f2fs: add -O features to tune the bits Chao Yu
  1 sibling, 1 reply; 13+ messages in thread
From: Junling Zheng @ 2018-04-20  1:46 UTC (permalink / raw)
  To: Jaegeuk Kim, linux-f2fs-devel

Hi, Jaegeuk

On 2018/4/20 4:54, Jaegeuk Kim wrote:
> This patch add -O features for fsck.f2fs in order to tune the feature bits.
> Currently, it supports -O encrypt only.
> 

Shall we introduce a new tool like tune.f2fs to tune the parameters of f2fs?
Maybe we will tune others parameters in the future, not only features bits in sb :)

> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
> ---
>  fsck/fsck.h   |  1 +
>  fsck/main.c   |  9 ++++++++-
>  fsck/mount.c  | 39 ++++++++++++++++++++++++++++++++++++++-
>  fsck/resize.c | 18 +-----------------
>  4 files changed, 48 insertions(+), 19 deletions(-)
> 
> diff --git a/fsck/fsck.h b/fsck/fsck.h
> index 8e133fa..3e13fc6 100644
> --- a/fsck/fsck.h
> +++ b/fsck/fsck.h
> @@ -176,6 +176,7 @@ extern void move_curseg_info(struct f2fs_sb_info *, u64);
>  extern void write_curseg_info(struct f2fs_sb_info *);
>  extern int find_next_free_block(struct f2fs_sb_info *, u64 *, int, int);
>  extern void write_checkpoint(struct f2fs_sb_info *);
> +extern void write_superblock(struct f2fs_super_block *);
>  extern void update_data_blkaddr(struct f2fs_sb_info *, nid_t, u16, block_t);
>  extern void update_nat_blkaddr(struct f2fs_sb_info *, nid_t, nid_t, block_t);
>  
> diff --git a/fsck/main.c b/fsck/main.c
> index 9256d21..c4dd8b1 100644
> --- a/fsck/main.c
> +++ b/fsck/main.c
> @@ -28,6 +28,8 @@ struct f2fs_fsck gfsck;
>  extern struct sparse_file *f2fs_sparse_file;
>  #endif
>  
> +INIT_FEATURE_TABLE;
> +
>  static char *absolute_path(const char *file)
>  {
>  	char *ret;
> @@ -54,6 +56,7 @@ void fsck_usage()
>  	MSG(0, "  -d debug level [default:0]\n");
>  	MSG(0, "  -f check/fix entire partition\n");
>  	MSG(0, "  -g add default options\n");
> +	MSG(0, "  -O feature1[feature2,feature3,...] e.g. \"encrypt\"\n");
>  	MSG(0, "  -p preen mode [default:0 the same as -a [0|1]]\n");
>  	MSG(0, "  -S sparse_mode\n");
>  	MSG(0, "  -t show directory tree\n");
> @@ -180,7 +183,7 @@ void f2fs_parse_options(int argc, char *argv[])
>  	}
>  
>  	if (!strcmp("fsck.f2fs", prog)) {
> -		const char *option_string = ":ad:fg:p:q:StyV";
> +		const char *option_string = ":ad:fg:O:p:q:StyV";
>  		int opt = 0;
>  		struct option long_opt[] = {
>  			{"dry-run", no_argument, 0, 1},
> @@ -203,6 +206,10 @@ void f2fs_parse_options(int argc, char *argv[])
>  				if (!strcmp(optarg, "android"))
>  					c.defset = CONF_ANDROID;
>  				break;
> +			case 'O':
> +				if (parse_feature(feature_table, optarg))
> +					fsck_usage();
> +				break;
>  			case 'p':
>  				/* preen mode has different levels:
>  				 *  0: default level, the same as -a
> diff --git a/fsck/mount.c b/fsck/mount.c
> index e5574c5..b374b46 100644
> --- a/fsck/mount.c
> +++ b/fsck/mount.c
> @@ -2144,6 +2144,22 @@ void write_checkpoint(struct f2fs_sb_info *sbi)
>  	ASSERT(ret >= 0);
>  }
>  
> +void write_superblock(struct f2fs_super_block *new_sb)
> +{
> +	int index, ret;
> +	u_int8_t *buf;
> +
> +	buf = calloc(BLOCK_SZ, 1);
> +
> +	memcpy(buf + F2FS_SUPER_OFFSET, new_sb, sizeof(*new_sb));
> +	for (index = 0; index < 2; index++) {
> +		ret = dev_write_block(buf, index);
> +		ASSERT(ret >= 0);
> +	}
> +	free(buf);
> +	DBG(0, "Info: Done to rebuild superblock\n");
> +}
> +
>  void build_nat_area_bitmap(struct f2fs_sb_info *sbi)
>  {
>  	struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA);
> @@ -2314,6 +2330,26 @@ static int check_sector_size(struct f2fs_super_block *sb)
>  	return 0;
>  }
>  
> +static void tune_sb_features(struct f2fs_sb_info *sbi)
> +{
> +	int sb_changed = 0;
> +	struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi);
> +
> +	if (!(sb->feature & cpu_to_le32(F2FS_FEATURE_ENCRYPT)) &&
> +			c.feature & cpu_to_le32(F2FS_FEATURE_ENCRYPT)) {
> +		sb->feature |= cpu_to_le32(F2FS_FEATURE_ENCRYPT);
> +		MSG(0, "Info: Set Encryption feature\n");
> +		sb_changed = 1;
> +	}
> +	/* TODO: quota needs to allocate inode numbers */
> +
> +	c.feature = sb->feature;
> +	if (!sb_changed)
> +		return;
> +
> +	write_superblock(sb);
> +}
> +
>  int f2fs_do_mount(struct f2fs_sb_info *sbi)
>  {
>  	struct f2fs_checkpoint *cp = NULL;
> @@ -2365,7 +2401,8 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi)
>  	}
>  
>  	c.bug_on = 0;
> -	c.feature = sb->feature;
> +
> +	tune_sb_features(sbi);
>  
>  	/* precompute checksum seed for metadata */
>  	if (c.feature & cpu_to_le32(F2FS_FEATURE_INODE_CHKSUM))
> diff --git a/fsck/resize.c b/fsck/resize.c
> index 019da71..d285dd7 100644
> --- a/fsck/resize.c
> +++ b/fsck/resize.c
> @@ -569,22 +569,6 @@ static void rebuild_checkpoint(struct f2fs_sb_info *sbi,
>  	DBG(0, "Info: Done to rebuild checkpoint blocks\n");
>  }
>  
> -static void rebuild_superblock(struct f2fs_super_block *new_sb)
> -{
> -	int index, ret;
> -	u_int8_t *buf;
> -
> -	buf = calloc(BLOCK_SZ, 1);
> -
> -	memcpy(buf + F2FS_SUPER_OFFSET, new_sb, sizeof(*new_sb));
> -	for (index = 0; index < 2; index++) {
> -		ret = dev_write_block(buf, index);
> -		ASSERT(ret >= 0);
> -	}
> -	free(buf);
> -	DBG(0, "Info: Done to rebuild superblock\n");
> -}
> -
>  int f2fs_resize(struct f2fs_sb_info *sbi)
>  {
>  	struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi);
> @@ -636,6 +620,6 @@ int f2fs_resize(struct f2fs_sb_info *sbi)
>  	migrate_nat(sbi, new_sb);
>  	migrate_sit(sbi, new_sb, offset_seg);
>  	rebuild_checkpoint(sbi, new_sb, offset_seg);
> -	rebuild_superblock(new_sb);
> +	write_superblock(new_sb);
>  	return 0;
>  }
> 



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

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

* Re: [PATCH] fsck.f2fs: add -O features to tune the bits
  2018-04-20  1:46 ` Junling Zheng
@ 2018-04-20  1:57   ` Chao Yu
  2018-04-20  2:52     ` Jaegeuk Kim
  2018-04-23  7:32     ` [RFC PATCH] f2fs-tools: introduce tune.f2fs Junling Zheng
  0 siblings, 2 replies; 13+ messages in thread
From: Chao Yu @ 2018-04-20  1:57 UTC (permalink / raw)
  To: Junling Zheng, Jaegeuk Kim, linux-f2fs-devel

On 2018/4/20 9:46, Junling Zheng wrote:
> Hi, Jaegeuk
> 
> On 2018/4/20 4:54, Jaegeuk Kim wrote:
>> This patch add -O features for fsck.f2fs in order to tune the feature bits.
>> Currently, it supports -O encrypt only.
>>
> 
> Shall we introduce a new tool like tune.f2fs to tune the parameters of f2fs?
> Maybe we will tune others parameters in the future, not only features bits in sb :)

Agreed, one concern is we'd better separate tune functionality from fsck, other
is that it will be more comfortable to use misc tools for the user changed their
fs from extx to f2fs.

Thanks,

> 
>> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
>> ---
>>  fsck/fsck.h   |  1 +
>>  fsck/main.c   |  9 ++++++++-
>>  fsck/mount.c  | 39 ++++++++++++++++++++++++++++++++++++++-
>>  fsck/resize.c | 18 +-----------------
>>  4 files changed, 48 insertions(+), 19 deletions(-)
>>
>> diff --git a/fsck/fsck.h b/fsck/fsck.h
>> index 8e133fa..3e13fc6 100644
>> --- a/fsck/fsck.h
>> +++ b/fsck/fsck.h
>> @@ -176,6 +176,7 @@ extern void move_curseg_info(struct f2fs_sb_info *, u64);
>>  extern void write_curseg_info(struct f2fs_sb_info *);
>>  extern int find_next_free_block(struct f2fs_sb_info *, u64 *, int, int);
>>  extern void write_checkpoint(struct f2fs_sb_info *);
>> +extern void write_superblock(struct f2fs_super_block *);
>>  extern void update_data_blkaddr(struct f2fs_sb_info *, nid_t, u16, block_t);
>>  extern void update_nat_blkaddr(struct f2fs_sb_info *, nid_t, nid_t, block_t);
>>  
>> diff --git a/fsck/main.c b/fsck/main.c
>> index 9256d21..c4dd8b1 100644
>> --- a/fsck/main.c
>> +++ b/fsck/main.c
>> @@ -28,6 +28,8 @@ struct f2fs_fsck gfsck;
>>  extern struct sparse_file *f2fs_sparse_file;
>>  #endif
>>  
>> +INIT_FEATURE_TABLE;
>> +
>>  static char *absolute_path(const char *file)
>>  {
>>  	char *ret;
>> @@ -54,6 +56,7 @@ void fsck_usage()
>>  	MSG(0, "  -d debug level [default:0]\n");
>>  	MSG(0, "  -f check/fix entire partition\n");
>>  	MSG(0, "  -g add default options\n");
>> +	MSG(0, "  -O feature1[feature2,feature3,...] e.g. \"encrypt\"\n");
>>  	MSG(0, "  -p preen mode [default:0 the same as -a [0|1]]\n");
>>  	MSG(0, "  -S sparse_mode\n");
>>  	MSG(0, "  -t show directory tree\n");
>> @@ -180,7 +183,7 @@ void f2fs_parse_options(int argc, char *argv[])
>>  	}
>>  
>>  	if (!strcmp("fsck.f2fs", prog)) {
>> -		const char *option_string = ":ad:fg:p:q:StyV";
>> +		const char *option_string = ":ad:fg:O:p:q:StyV";
>>  		int opt = 0;
>>  		struct option long_opt[] = {
>>  			{"dry-run", no_argument, 0, 1},
>> @@ -203,6 +206,10 @@ void f2fs_parse_options(int argc, char *argv[])
>>  				if (!strcmp(optarg, "android"))
>>  					c.defset = CONF_ANDROID;
>>  				break;
>> +			case 'O':
>> +				if (parse_feature(feature_table, optarg))
>> +					fsck_usage();
>> +				break;
>>  			case 'p':
>>  				/* preen mode has different levels:
>>  				 *  0: default level, the same as -a
>> diff --git a/fsck/mount.c b/fsck/mount.c
>> index e5574c5..b374b46 100644
>> --- a/fsck/mount.c
>> +++ b/fsck/mount.c
>> @@ -2144,6 +2144,22 @@ void write_checkpoint(struct f2fs_sb_info *sbi)
>>  	ASSERT(ret >= 0);
>>  }
>>  
>> +void write_superblock(struct f2fs_super_block *new_sb)
>> +{
>> +	int index, ret;
>> +	u_int8_t *buf;
>> +
>> +	buf = calloc(BLOCK_SZ, 1);
>> +
>> +	memcpy(buf + F2FS_SUPER_OFFSET, new_sb, sizeof(*new_sb));
>> +	for (index = 0; index < 2; index++) {
>> +		ret = dev_write_block(buf, index);
>> +		ASSERT(ret >= 0);
>> +	}
>> +	free(buf);
>> +	DBG(0, "Info: Done to rebuild superblock\n");
>> +}
>> +
>>  void build_nat_area_bitmap(struct f2fs_sb_info *sbi)
>>  {
>>  	struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA);
>> @@ -2314,6 +2330,26 @@ static int check_sector_size(struct f2fs_super_block *sb)
>>  	return 0;
>>  }
>>  
>> +static void tune_sb_features(struct f2fs_sb_info *sbi)
>> +{
>> +	int sb_changed = 0;
>> +	struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi);
>> +
>> +	if (!(sb->feature & cpu_to_le32(F2FS_FEATURE_ENCRYPT)) &&
>> +			c.feature & cpu_to_le32(F2FS_FEATURE_ENCRYPT)) {
>> +		sb->feature |= cpu_to_le32(F2FS_FEATURE_ENCRYPT);
>> +		MSG(0, "Info: Set Encryption feature\n");
>> +		sb_changed = 1;
>> +	}
>> +	/* TODO: quota needs to allocate inode numbers */
>> +
>> +	c.feature = sb->feature;
>> +	if (!sb_changed)
>> +		return;
>> +
>> +	write_superblock(sb);
>> +}
>> +
>>  int f2fs_do_mount(struct f2fs_sb_info *sbi)
>>  {
>>  	struct f2fs_checkpoint *cp = NULL;
>> @@ -2365,7 +2401,8 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi)
>>  	}
>>  
>>  	c.bug_on = 0;
>> -	c.feature = sb->feature;
>> +
>> +	tune_sb_features(sbi);
>>  
>>  	/* precompute checksum seed for metadata */
>>  	if (c.feature & cpu_to_le32(F2FS_FEATURE_INODE_CHKSUM))
>> diff --git a/fsck/resize.c b/fsck/resize.c
>> index 019da71..d285dd7 100644
>> --- a/fsck/resize.c
>> +++ b/fsck/resize.c
>> @@ -569,22 +569,6 @@ static void rebuild_checkpoint(struct f2fs_sb_info *sbi,
>>  	DBG(0, "Info: Done to rebuild checkpoint blocks\n");
>>  }
>>  
>> -static void rebuild_superblock(struct f2fs_super_block *new_sb)
>> -{
>> -	int index, ret;
>> -	u_int8_t *buf;
>> -
>> -	buf = calloc(BLOCK_SZ, 1);
>> -
>> -	memcpy(buf + F2FS_SUPER_OFFSET, new_sb, sizeof(*new_sb));
>> -	for (index = 0; index < 2; index++) {
>> -		ret = dev_write_block(buf, index);
>> -		ASSERT(ret >= 0);
>> -	}
>> -	free(buf);
>> -	DBG(0, "Info: Done to rebuild superblock\n");
>> -}
>> -
>>  int f2fs_resize(struct f2fs_sb_info *sbi)
>>  {
>>  	struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi);
>> @@ -636,6 +620,6 @@ int f2fs_resize(struct f2fs_sb_info *sbi)
>>  	migrate_nat(sbi, new_sb);
>>  	migrate_sit(sbi, new_sb, offset_seg);
>>  	rebuild_checkpoint(sbi, new_sb, offset_seg);
>> -	rebuild_superblock(new_sb);
>> +	write_superblock(new_sb);
>>  	return 0;
>>  }
>>
> 
> 
> 
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Linux-f2fs-devel mailing list
> Linux-f2fs-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
> 
> .
> 


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

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

* Re: [PATCH] fsck.f2fs: add -O features to tune the bits
  2018-04-20  1:57   ` Chao Yu
@ 2018-04-20  2:52     ` Jaegeuk Kim
  2018-04-23  7:32     ` [RFC PATCH] f2fs-tools: introduce tune.f2fs Junling Zheng
  1 sibling, 0 replies; 13+ messages in thread
From: Jaegeuk Kim @ 2018-04-20  2:52 UTC (permalink / raw)
  To: Chao Yu; +Cc: linux-f2fs-devel

On 04/20, Chao Yu wrote:
> On 2018/4/20 9:46, Junling Zheng wrote:
> > Hi, Jaegeuk
> > 
> > On 2018/4/20 4:54, Jaegeuk Kim wrote:
> >> This patch add -O features for fsck.f2fs in order to tune the feature bits.
> >> Currently, it supports -O encrypt only.
> >>
> > 
> > Shall we introduce a new tool like tune.f2fs to tune the parameters of f2fs?
> > Maybe we will tune others parameters in the future, not only features bits in sb :)

Of course, that'd be better. But, I don't have strong motivation to add it
for now. In order to tune one feature flag, do we have to say we need another
tool?

> 
> Agreed, one concern is we'd better separate tune functionality from fsck, other
> is that it will be more comfortable to use misc tools for the user changed their
> fs from extx to f2fs.

That's very likely to be a TODO item. ;)

Thanks,

> 
> Thanks,
> 
> > 
> >> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
> >> ---
> >>  fsck/fsck.h   |  1 +
> >>  fsck/main.c   |  9 ++++++++-
> >>  fsck/mount.c  | 39 ++++++++++++++++++++++++++++++++++++++-
> >>  fsck/resize.c | 18 +-----------------
> >>  4 files changed, 48 insertions(+), 19 deletions(-)
> >>
> >> diff --git a/fsck/fsck.h b/fsck/fsck.h
> >> index 8e133fa..3e13fc6 100644
> >> --- a/fsck/fsck.h
> >> +++ b/fsck/fsck.h
> >> @@ -176,6 +176,7 @@ extern void move_curseg_info(struct f2fs_sb_info *, u64);
> >>  extern void write_curseg_info(struct f2fs_sb_info *);
> >>  extern int find_next_free_block(struct f2fs_sb_info *, u64 *, int, int);
> >>  extern void write_checkpoint(struct f2fs_sb_info *);
> >> +extern void write_superblock(struct f2fs_super_block *);
> >>  extern void update_data_blkaddr(struct f2fs_sb_info *, nid_t, u16, block_t);
> >>  extern void update_nat_blkaddr(struct f2fs_sb_info *, nid_t, nid_t, block_t);
> >>  
> >> diff --git a/fsck/main.c b/fsck/main.c
> >> index 9256d21..c4dd8b1 100644
> >> --- a/fsck/main.c
> >> +++ b/fsck/main.c
> >> @@ -28,6 +28,8 @@ struct f2fs_fsck gfsck;
> >>  extern struct sparse_file *f2fs_sparse_file;
> >>  #endif
> >>  
> >> +INIT_FEATURE_TABLE;
> >> +
> >>  static char *absolute_path(const char *file)
> >>  {
> >>  	char *ret;
> >> @@ -54,6 +56,7 @@ void fsck_usage()
> >>  	MSG(0, "  -d debug level [default:0]\n");
> >>  	MSG(0, "  -f check/fix entire partition\n");
> >>  	MSG(0, "  -g add default options\n");
> >> +	MSG(0, "  -O feature1[feature2,feature3,...] e.g. \"encrypt\"\n");
> >>  	MSG(0, "  -p preen mode [default:0 the same as -a [0|1]]\n");
> >>  	MSG(0, "  -S sparse_mode\n");
> >>  	MSG(0, "  -t show directory tree\n");
> >> @@ -180,7 +183,7 @@ void f2fs_parse_options(int argc, char *argv[])
> >>  	}
> >>  
> >>  	if (!strcmp("fsck.f2fs", prog)) {
> >> -		const char *option_string = ":ad:fg:p:q:StyV";
> >> +		const char *option_string = ":ad:fg:O:p:q:StyV";
> >>  		int opt = 0;
> >>  		struct option long_opt[] = {
> >>  			{"dry-run", no_argument, 0, 1},
> >> @@ -203,6 +206,10 @@ void f2fs_parse_options(int argc, char *argv[])
> >>  				if (!strcmp(optarg, "android"))
> >>  					c.defset = CONF_ANDROID;
> >>  				break;
> >> +			case 'O':
> >> +				if (parse_feature(feature_table, optarg))
> >> +					fsck_usage();
> >> +				break;
> >>  			case 'p':
> >>  				/* preen mode has different levels:
> >>  				 *  0: default level, the same as -a
> >> diff --git a/fsck/mount.c b/fsck/mount.c
> >> index e5574c5..b374b46 100644
> >> --- a/fsck/mount.c
> >> +++ b/fsck/mount.c
> >> @@ -2144,6 +2144,22 @@ void write_checkpoint(struct f2fs_sb_info *sbi)
> >>  	ASSERT(ret >= 0);
> >>  }
> >>  
> >> +void write_superblock(struct f2fs_super_block *new_sb)
> >> +{
> >> +	int index, ret;
> >> +	u_int8_t *buf;
> >> +
> >> +	buf = calloc(BLOCK_SZ, 1);
> >> +
> >> +	memcpy(buf + F2FS_SUPER_OFFSET, new_sb, sizeof(*new_sb));
> >> +	for (index = 0; index < 2; index++) {
> >> +		ret = dev_write_block(buf, index);
> >> +		ASSERT(ret >= 0);
> >> +	}
> >> +	free(buf);
> >> +	DBG(0, "Info: Done to rebuild superblock\n");
> >> +}
> >> +
> >>  void build_nat_area_bitmap(struct f2fs_sb_info *sbi)
> >>  {
> >>  	struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA);
> >> @@ -2314,6 +2330,26 @@ static int check_sector_size(struct f2fs_super_block *sb)
> >>  	return 0;
> >>  }
> >>  
> >> +static void tune_sb_features(struct f2fs_sb_info *sbi)
> >> +{
> >> +	int sb_changed = 0;
> >> +	struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi);
> >> +
> >> +	if (!(sb->feature & cpu_to_le32(F2FS_FEATURE_ENCRYPT)) &&
> >> +			c.feature & cpu_to_le32(F2FS_FEATURE_ENCRYPT)) {
> >> +		sb->feature |= cpu_to_le32(F2FS_FEATURE_ENCRYPT);
> >> +		MSG(0, "Info: Set Encryption feature\n");
> >> +		sb_changed = 1;
> >> +	}
> >> +	/* TODO: quota needs to allocate inode numbers */
> >> +
> >> +	c.feature = sb->feature;
> >> +	if (!sb_changed)
> >> +		return;
> >> +
> >> +	write_superblock(sb);
> >> +}
> >> +
> >>  int f2fs_do_mount(struct f2fs_sb_info *sbi)
> >>  {
> >>  	struct f2fs_checkpoint *cp = NULL;
> >> @@ -2365,7 +2401,8 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi)
> >>  	}
> >>  
> >>  	c.bug_on = 0;
> >> -	c.feature = sb->feature;
> >> +
> >> +	tune_sb_features(sbi);
> >>  
> >>  	/* precompute checksum seed for metadata */
> >>  	if (c.feature & cpu_to_le32(F2FS_FEATURE_INODE_CHKSUM))
> >> diff --git a/fsck/resize.c b/fsck/resize.c
> >> index 019da71..d285dd7 100644
> >> --- a/fsck/resize.c
> >> +++ b/fsck/resize.c
> >> @@ -569,22 +569,6 @@ static void rebuild_checkpoint(struct f2fs_sb_info *sbi,
> >>  	DBG(0, "Info: Done to rebuild checkpoint blocks\n");
> >>  }
> >>  
> >> -static void rebuild_superblock(struct f2fs_super_block *new_sb)
> >> -{
> >> -	int index, ret;
> >> -	u_int8_t *buf;
> >> -
> >> -	buf = calloc(BLOCK_SZ, 1);
> >> -
> >> -	memcpy(buf + F2FS_SUPER_OFFSET, new_sb, sizeof(*new_sb));
> >> -	for (index = 0; index < 2; index++) {
> >> -		ret = dev_write_block(buf, index);
> >> -		ASSERT(ret >= 0);
> >> -	}
> >> -	free(buf);
> >> -	DBG(0, "Info: Done to rebuild superblock\n");
> >> -}
> >> -
> >>  int f2fs_resize(struct f2fs_sb_info *sbi)
> >>  {
> >>  	struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi);
> >> @@ -636,6 +620,6 @@ int f2fs_resize(struct f2fs_sb_info *sbi)
> >>  	migrate_nat(sbi, new_sb);
> >>  	migrate_sit(sbi, new_sb, offset_seg);
> >>  	rebuild_checkpoint(sbi, new_sb, offset_seg);
> >> -	rebuild_superblock(new_sb);
> >> +	write_superblock(new_sb);
> >>  	return 0;
> >>  }
> >>
> > 
> > 
> > 
> > ------------------------------------------------------------------------------
> > Check out the vibrant tech community on one of the world's most
> > engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> > _______________________________________________
> > Linux-f2fs-devel mailing list
> > Linux-f2fs-devel@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
> > 
> > .
> > 

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

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

* Re: [PATCH] fsck.f2fs: add -O features to tune the bits
  2018-04-19 20:54 [PATCH] fsck.f2fs: add -O features to tune the bits Jaegeuk Kim
  2018-04-20  1:46 ` Junling Zheng
@ 2018-04-23  3:55 ` Chao Yu
  1 sibling, 0 replies; 13+ messages in thread
From: Chao Yu @ 2018-04-23  3:55 UTC (permalink / raw)
  To: Jaegeuk Kim, linux-f2fs-devel

On 2018/4/20 4:54, Jaegeuk Kim wrote:
> This patch add -O features for fsck.f2fs in order to tune the feature bits.
> Currently, it supports -O encrypt only.
> 
> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

Reviewed-by: Chao Yu <yuchao0@huawei.com>

Thanks,


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

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

* [RFC PATCH] f2fs-tools: introduce tune.f2fs
  2018-04-20  1:57   ` Chao Yu
  2018-04-20  2:52     ` Jaegeuk Kim
@ 2018-04-23  7:32     ` Junling Zheng
  2018-04-26  2:10       ` Junling Zheng
  1 sibling, 1 reply; 13+ messages in thread
From: Junling Zheng @ 2018-04-23  7:32 UTC (permalink / raw)
  To: jaegeuk, yuchao0; +Cc: linux-f2fs-devel

Introduce tune.f2fs tool to change the f2fs parameters.
Currently this tool only supports adding or removing encrypt
feature bit in superblock.

Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
---
 fsck/Makefile.am  |  3 ++-
 fsck/fsck.h       |  5 +++++
 fsck/main.c       | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fsck/tune.c       | 46 +++++++++++++++++++++++++++++++++++++++++
 include/f2fs_fs.h | 61 +++++++++++++++++++++++++++++++++++++++----------------
 man/Makefile.am   |  2 +-
 man/tune.f2fs.8   | 50 +++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 207 insertions(+), 20 deletions(-)
 create mode 100644 fsck/tune.c
 create mode 100644 man/tune.f2fs.8

diff --git a/fsck/Makefile.am b/fsck/Makefile.am
index 1fc7310..3efacfd 100644
--- a/fsck/Makefile.am
+++ b/fsck/Makefile.am
@@ -5,7 +5,7 @@ AM_CFLAGS = -Wall
 sbin_PROGRAMS = fsck.f2fs
 noinst_HEADERS = common.h dict.h dqblk_v2.h f2fs.h fsck.h node.h quotaio.h quotaio_tree.h quotaio_v2.h xattr.h
 include_HEADERS = $(top_srcdir)/include/quota.h
-fsck_f2fs_SOURCES = main.c fsck.c dump.c mount.c defrag.c resize.c \
+fsck_f2fs_SOURCES = main.c fsck.c dump.c mount.c defrag.c resize.c tune.c \
 		node.c segment.c dir.c sload.c xattr.c \
 		dict.c mkquota.c quotaio.c quotaio_tree.c quotaio_v2.c
 fsck_f2fs_LDADD = ${libselinux_LIBS} ${libuuid_LIBS} $(top_builddir)/lib/libf2fs.la
@@ -15,3 +15,4 @@ install-data-hook:
 	ln -sf fsck.f2fs $(DESTDIR)/$(sbindir)/defrag.f2fs
 	ln -sf fsck.f2fs $(DESTDIR)/$(sbindir)/resize.f2fs
 	ln -sf fsck.f2fs $(DESTDIR)/$(sbindir)/sload.f2fs
+	ln -sf fsck.f2fs $(DESTDIR)/$(sbindir)/tune.f2fs
diff --git a/fsck/fsck.h b/fsck/fsck.h
index 3e13fc6..39d6ed4 100644
--- a/fsck/fsck.h
+++ b/fsck/fsck.h
@@ -180,6 +180,8 @@ extern void write_superblock(struct f2fs_super_block *);
 extern void update_data_blkaddr(struct f2fs_sb_info *, nid_t, u16, block_t);
 extern void update_nat_blkaddr(struct f2fs_sb_info *, nid_t, nid_t, block_t);
 
+extern int validate_super_block(struct f2fs_sb_info *, int);
+extern void print_sb_state(struct f2fs_super_block *);
 extern void print_raw_sb_info(struct f2fs_super_block *);
 
 extern u32 get_free_segments(struct f2fs_sb_info *);
@@ -220,6 +222,9 @@ int f2fs_resize(struct f2fs_sb_info *);
 /* sload.c */
 int f2fs_sload(struct f2fs_sb_info *);
 
+/* tune.c */
+int f2fs_tune(struct f2fs_sb_info *);
+
 /* segment.c */
 void reserve_new_block(struct f2fs_sb_info *, block_t *,
 					struct f2fs_summary *, int);
diff --git a/fsck/main.c b/fsck/main.c
index c4dd8b1..b8e1aee 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -29,6 +29,7 @@ extern struct sparse_file *f2fs_sparse_file;
 #endif
 
 INIT_FEATURE_TABLE;
+INIT_TUNE_FEATURE_TABLE;
 
 static char *absolute_path(const char *file)
 {
@@ -123,6 +124,15 @@ void sload_usage()
 	exit(1);
 }
 
+void tune_usage()
+{
+	MSG(0, "\nUsage: tune.f2fs [options] device\n");
+	MSG(0, "[options]:\n");
+	MSG(0, "  -d debug level [default:0]\n");
+	MSG(0, "  -O [^]feature[,...]\n");
+	exit(1);
+}
+
 static int is_digits(char *optarg)
 {
 	unsigned int i;
@@ -145,6 +155,8 @@ static void error_out(char *prog)
 		resize_usage();
 	else if (!strcmp("sload.f2fs", prog))
 		sload_usage();
+	else if (!strcmp("tune.f2fs", prog))
+		tune_usage();
 	else
 		MSG(0, "\nWrong program.\n");
 }
@@ -528,6 +540,32 @@ void f2fs_parse_options(int argc, char *argv[])
 			if (err != NOERROR)
 				break;
 		}
+	} else if (!strcmp("tune.f2fs", prog)) {
+		const char *option_string = "d:O:";
+
+		c.func = TUNE;
+		while ((option = getopt(argc, argv, option_string)) != EOF) {
+			switch (option) {
+			case 'd':
+				if (!is_digits(optarg)) {
+					err = EWRONG_OPT;
+					break;
+				}
+				c.dbg_lv = atoi(optarg);
+				MSG(0, "Info: Debug level = %d\n",
+							c.dbg_lv);
+				break;
+			case 'O':
+				if (parse_feature(tune_feature_table, optarg))
+					tune_usage();
+				break;
+			default:
+				err = EUNKNOWN_OPT;
+				break;
+			}
+			if (err != NOERROR)
+				break;
+		}
 	}
 
 	add_default_options();
@@ -736,6 +774,13 @@ static int do_sload(struct f2fs_sb_info *sbi)
 	return f2fs_sload(sbi);
 }
 
+static int do_tune(struct f2fs_sb_info *sbi)
+{
+	// TODO: check global configuration
+
+	return f2fs_tune(sbi);
+}
+
 int main(int argc, char **argv)
 {
 	struct f2fs_sb_info *sbi;
@@ -768,6 +813,18 @@ fsck_again:
 	gfsck.sbi.fsck = &gfsck;
 	sbi = &gfsck.sbi;
 
+#ifdef WITH_TUNE
+	if (c.func == TUNE) {
+		ret = do_tune(sbi);
+		if (ret)
+			goto out_err;
+		/* If tune successfully, then call
+		 * f2fs_finalize_device to fsync.
+		 */
+		goto out;
+	}
+#endif
+
 	ret = f2fs_do_mount(sbi);
 	if (ret != 0) {
 		if (ret == 1) {
@@ -836,6 +893,9 @@ retry:
 				goto fsck_again;
 		}
 	}
+#ifdef WITH_TUNE
+out:
+#endif
 	ret = f2fs_finalize_device();
 	if (ret < 0)
 		return ret;
diff --git a/fsck/tune.c b/fsck/tune.c
new file mode 100644
index 0000000..1322639
--- /dev/null
+++ b/fsck/tune.c
@@ -0,0 +1,46 @@
+/**
+ * tune.c
+ *
+ * Copyright (C) 2018 Huawei Ltd.
+ * Witten by:
+ *   Junling Zheng <zhengjunling@huawei.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include "fsck.h"
+
+int f2fs_tune(struct f2fs_sb_info *sbi)
+{
+	int ret;
+
+	/* Get and validate sbi->raw_super */
+	ret = validate_super_block(sbi, 0);
+	if (ret) {
+		ret = validate_super_block(sbi, 1);
+		if (ret)
+			return -1;
+	}
+
+	/* Tune features in sb */
+	if (c.feature)
+		sbi->raw_super->feature |= c.feature;
+	if (c.nofeature)
+		sbi->raw_super->feature &= ~c.nofeature;
+
+	MSG(0, "Info: Tune feature successfully!\n");
+	/* Print features in sb */
+	print_sb_state(sbi->raw_super);
+
+	/* Write raw_super back to both 1st and 2nd sb on disk */
+	ret = dev_write(sbi->raw_super, F2FS_SUPER_OFFSET,
+				sizeof(struct f2fs_super_block));
+	ASSERT(ret >= 0);
+	ret = dev_write(sbi->raw_super, F2FS_SUPER_OFFSET + F2FS_BLKSIZE,
+						sizeof(struct f2fs_super_block));
+	ASSERT(ret >= 0);
+	MSG(0, "Info: Writeback successfully!\n");
+
+	return ret;
+}
diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
index a1274fd..87d2fe9 100644
--- a/include/f2fs_fs.h
+++ b/include/f2fs_fs.h
@@ -13,6 +13,7 @@
 #define __F2FS_FS_H__
 
 #include <stdio.h>
+#include <ctype.h>
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
@@ -28,6 +29,7 @@
 #define WITH_DEFRAG
 #define WITH_RESIZE
 #define WITH_SLOAD
+#define WITH_TUNE
 #endif
 
 #include <inttypes.h>
@@ -309,6 +311,7 @@ enum f2fs_config_func {
 	DEFRAG,
 	RESIZE,
 	SLOAD,
+	TUNE,
 };
 
 enum default_set {
@@ -381,7 +384,8 @@ struct f2fs_configuration {
 	int ro;
 	int preserve_limits;		/* preserve quota limits */
 	int large_nat_bitmap;
-	__le32 feature;			/* defined features */
+	__le32 feature;			/* defined features to enable */
+	__le32 nofeature;		/* defined features to disable */
 
 	/* mkfs parameters */
 	u_int32_t next_free_nid;
@@ -1334,6 +1338,12 @@ struct feature feature_table[] = {					\
 	{ NULL,				0x0},				\
 };
 
+#define INIT_TUNE_FEATURE_TABLE						\
+struct feature tune_feature_table[] = {					\
+	{ "encrypt",			F2FS_FEATURE_ENCRYPT },		\
+	{ NULL,				0x0},				\
+};
+
 static inline u32 feature_map(struct feature *table, char *feature)
 {
 	struct feature *p;
@@ -1342,21 +1352,11 @@ static inline u32 feature_map(struct feature *table, char *feature)
 	return p->mask;
 }
 
-static inline int set_feature_bits(struct feature *table, char *features)
-{
-	u32 mask = feature_map(table, features);
-	if (mask) {
-		c.feature |= cpu_to_le32(mask);
-	} else {
-		MSG(0, "Error: Wrong features %s\n", features);
-		return -1;
-	}
-	return 0;
-}
-
 static inline int parse_feature(struct feature *table, const char *features)
 {
-	char *buf, *sub, *next;
+	char op, *buf, *sub, *next;
+	u32 feature_bit = 0;
+	int ret = 0;
 
 	buf = calloc(strlen(features) + 1, sizeof(char));
 	ASSERT(buf);
@@ -1376,12 +1376,37 @@ static inline int parse_feature(struct feature *table, const char *features)
 		else
 			*next = 0;
 
-		if (set_feature_bits(table, sub)) {
-			free(buf);
-			return -1;
+		if (!isalnum(*sub)) {
+			op = *sub;
+			sub++;
+		} else {
+			op = '+';
+		}
+
+		feature_bit = feature_map(table, sub);
+		if (!feature_bit) {
+			ERR_MSG("\tError: Not support feature %s\n", sub);
+			ret = -1;
+			goto out;
+		}
+
+		switch (op) {
+		case '+':
+			c.feature |= cpu_to_le32(feature_bit);
+			break;
+		case '-':
+		case '^':
+			c.nofeature |= cpu_to_le32(feature_bit);
+			break;
+		default:
+			ERR_MSG("\tError: Wrong operation %c\n", op);
+			ret = -1;
+			goto out;
 		}
 	}
+
+out:
 	free(buf);
-	return 0;
+	return ret;
 }
 #endif	/*__F2FS_FS_H */
diff --git a/man/Makefile.am b/man/Makefile.am
index 7856586..bfc4d19 100644
--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -1,3 +1,3 @@
 ## Makefile.am
 
-dist_man_MANS = mkfs.f2fs.8 fsck.f2fs.8 dump.f2fs.8 defrag.f2fs.8 resize.f2fs.8 sload.f2fs.8
+dist_man_MANS = mkfs.f2fs.8 fsck.f2fs.8 dump.f2fs.8 defrag.f2fs.8 resize.f2fs.8 sload.f2fs.8 tune.f2fs.8
diff --git a/man/tune.f2fs.8 b/man/tune.f2fs.8
new file mode 100644
index 0000000..5ee6790
--- /dev/null
+++ b/man/tune.f2fs.8
@@ -0,0 +1,50 @@
+.\" Copyright (C) 2015 Huawei Ltd.
+.\"
+.TH TUNE.F2FS 8
+.SH NAME
+tune.f2fs \- change the parameters of f2fs
+.SH SYNOPSIS
+.B tune.f2fs
+[
+.B \-d
+.I debugging-level
+]
+[
+.B \-O
+.I features to change
+]
+.I device
+.SH DESCRIPTION
+.B tune.f2fs
+is used to change the parameters of an f2fs file system (usually in a disk partition).
+\fIdevice\fP is the special file corresponding to the device (e.g.
+\fI/dev/sdXX\fP).
+
+Current version only supports enabling and disabling 'encrypt' feature.
+
+.PP
+The exit code returned by
+.B tune.f2fs
+is 0 on success and -1 on failure.
+.SH OPTIONS
+.TP
+.BI \-d " debug-level"
+Specify the level of debugging options.
+The default number is 0, which shows basic debugging messages.
+.TP
+.BI \-O " features"
+Specify the features to enable or disable. Currently only support 'encrypt' feature.
+.TP
+.SH AUTHOR
+This version of
+.B tune.f2fs
+has been written by Junling Zheng <zhengjunling@huawei.com>.
+.SH AVAILABILITY
+.B tune.f2fs
+is available from git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs-tools.git.
+.SH SEE ALSO
+.BR mkfs.f2fs(8),
+.BR fsck.f2fs(8),
+.BR dump.f2fs(8),
+.BR defrag.f2fs(8),
+.BR sload.f2fs(8).
-- 
2.16.2


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

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

* Re: [RFC PATCH] f2fs-tools: introduce tune.f2fs
  2018-04-23  7:32     ` [RFC PATCH] f2fs-tools: introduce tune.f2fs Junling Zheng
@ 2018-04-26  2:10       ` Junling Zheng
  2018-04-26 16:13         ` Jaegeuk Kim
  0 siblings, 1 reply; 13+ messages in thread
From: Junling Zheng @ 2018-04-26  2:10 UTC (permalink / raw)
  To: jaegeuk, yuchao0; +Cc: linux-f2fs-devel

Ping...

On 2018/4/23 15:32, Junling Zheng wrote:
> Introduce tune.f2fs tool to change the f2fs parameters.
> Currently this tool only supports adding or removing encrypt
> feature bit in superblock.
> 
> Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
> ---
>  fsck/Makefile.am  |  3 ++-
>  fsck/fsck.h       |  5 +++++
>  fsck/main.c       | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  fsck/tune.c       | 46 +++++++++++++++++++++++++++++++++++++++++
>  include/f2fs_fs.h | 61 +++++++++++++++++++++++++++++++++++++++----------------
>  man/Makefile.am   |  2 +-
>  man/tune.f2fs.8   | 50 +++++++++++++++++++++++++++++++++++++++++++++
>  7 files changed, 207 insertions(+), 20 deletions(-)
>  create mode 100644 fsck/tune.c
>  create mode 100644 man/tune.f2fs.8
> 
> diff --git a/fsck/Makefile.am b/fsck/Makefile.am
> index 1fc7310..3efacfd 100644
> --- a/fsck/Makefile.am
> +++ b/fsck/Makefile.am
> @@ -5,7 +5,7 @@ AM_CFLAGS = -Wall
>  sbin_PROGRAMS = fsck.f2fs
>  noinst_HEADERS = common.h dict.h dqblk_v2.h f2fs.h fsck.h node.h quotaio.h quotaio_tree.h quotaio_v2.h xattr.h
>  include_HEADERS = $(top_srcdir)/include/quota.h
> -fsck_f2fs_SOURCES = main.c fsck.c dump.c mount.c defrag.c resize.c \
> +fsck_f2fs_SOURCES = main.c fsck.c dump.c mount.c defrag.c resize.c tune.c \
>  		node.c segment.c dir.c sload.c xattr.c \
>  		dict.c mkquota.c quotaio.c quotaio_tree.c quotaio_v2.c
>  fsck_f2fs_LDADD = ${libselinux_LIBS} ${libuuid_LIBS} $(top_builddir)/lib/libf2fs.la
> @@ -15,3 +15,4 @@ install-data-hook:
>  	ln -sf fsck.f2fs $(DESTDIR)/$(sbindir)/defrag.f2fs
>  	ln -sf fsck.f2fs $(DESTDIR)/$(sbindir)/resize.f2fs
>  	ln -sf fsck.f2fs $(DESTDIR)/$(sbindir)/sload.f2fs
> +	ln -sf fsck.f2fs $(DESTDIR)/$(sbindir)/tune.f2fs
> diff --git a/fsck/fsck.h b/fsck/fsck.h
> index 3e13fc6..39d6ed4 100644
> --- a/fsck/fsck.h
> +++ b/fsck/fsck.h
> @@ -180,6 +180,8 @@ extern void write_superblock(struct f2fs_super_block *);
>  extern void update_data_blkaddr(struct f2fs_sb_info *, nid_t, u16, block_t);
>  extern void update_nat_blkaddr(struct f2fs_sb_info *, nid_t, nid_t, block_t);
>  
> +extern int validate_super_block(struct f2fs_sb_info *, int);
> +extern void print_sb_state(struct f2fs_super_block *);
>  extern void print_raw_sb_info(struct f2fs_super_block *);
>  
>  extern u32 get_free_segments(struct f2fs_sb_info *);
> @@ -220,6 +222,9 @@ int f2fs_resize(struct f2fs_sb_info *);
>  /* sload.c */
>  int f2fs_sload(struct f2fs_sb_info *);
>  
> +/* tune.c */
> +int f2fs_tune(struct f2fs_sb_info *);
> +
>  /* segment.c */
>  void reserve_new_block(struct f2fs_sb_info *, block_t *,
>  					struct f2fs_summary *, int);
> diff --git a/fsck/main.c b/fsck/main.c
> index c4dd8b1..b8e1aee 100644
> --- a/fsck/main.c
> +++ b/fsck/main.c
> @@ -29,6 +29,7 @@ extern struct sparse_file *f2fs_sparse_file;
>  #endif
>  
>  INIT_FEATURE_TABLE;
> +INIT_TUNE_FEATURE_TABLE;
>  
>  static char *absolute_path(const char *file)
>  {
> @@ -123,6 +124,15 @@ void sload_usage()
>  	exit(1);
>  }
>  
> +void tune_usage()
> +{
> +	MSG(0, "\nUsage: tune.f2fs [options] device\n");
> +	MSG(0, "[options]:\n");
> +	MSG(0, "  -d debug level [default:0]\n");
> +	MSG(0, "  -O [^]feature[,...]\n");
> +	exit(1);
> +}
> +
>  static int is_digits(char *optarg)
>  {
>  	unsigned int i;
> @@ -145,6 +155,8 @@ static void error_out(char *prog)
>  		resize_usage();
>  	else if (!strcmp("sload.f2fs", prog))
>  		sload_usage();
> +	else if (!strcmp("tune.f2fs", prog))
> +		tune_usage();
>  	else
>  		MSG(0, "\nWrong program.\n");
>  }
> @@ -528,6 +540,32 @@ void f2fs_parse_options(int argc, char *argv[])
>  			if (err != NOERROR)
>  				break;
>  		}
> +	} else if (!strcmp("tune.f2fs", prog)) {
> +		const char *option_string = "d:O:";
> +
> +		c.func = TUNE;
> +		while ((option = getopt(argc, argv, option_string)) != EOF) {
> +			switch (option) {
> +			case 'd':
> +				if (!is_digits(optarg)) {
> +					err = EWRONG_OPT;
> +					break;
> +				}
> +				c.dbg_lv = atoi(optarg);
> +				MSG(0, "Info: Debug level = %d\n",
> +							c.dbg_lv);
> +				break;
> +			case 'O':
> +				if (parse_feature(tune_feature_table, optarg))
> +					tune_usage();
> +				break;
> +			default:
> +				err = EUNKNOWN_OPT;
> +				break;
> +			}
> +			if (err != NOERROR)
> +				break;
> +		}
>  	}
>  
>  	add_default_options();
> @@ -736,6 +774,13 @@ static int do_sload(struct f2fs_sb_info *sbi)
>  	return f2fs_sload(sbi);
>  }
>  
> +static int do_tune(struct f2fs_sb_info *sbi)
> +{
> +	// TODO: check global configuration
> +
> +	return f2fs_tune(sbi);
> +}
> +
>  int main(int argc, char **argv)
>  {
>  	struct f2fs_sb_info *sbi;
> @@ -768,6 +813,18 @@ fsck_again:
>  	gfsck.sbi.fsck = &gfsck;
>  	sbi = &gfsck.sbi;
>  
> +#ifdef WITH_TUNE
> +	if (c.func == TUNE) {
> +		ret = do_tune(sbi);
> +		if (ret)
> +			goto out_err;
> +		/* If tune successfully, then call
> +		 * f2fs_finalize_device to fsync.
> +		 */
> +		goto out;
> +	}
> +#endif
> +
>  	ret = f2fs_do_mount(sbi);
>  	if (ret != 0) {
>  		if (ret == 1) {
> @@ -836,6 +893,9 @@ retry:
>  				goto fsck_again;
>  		}
>  	}
> +#ifdef WITH_TUNE
> +out:
> +#endif
>  	ret = f2fs_finalize_device();
>  	if (ret < 0)
>  		return ret;
> diff --git a/fsck/tune.c b/fsck/tune.c
> new file mode 100644
> index 0000000..1322639
> --- /dev/null
> +++ b/fsck/tune.c
> @@ -0,0 +1,46 @@
> +/**
> + * tune.c
> + *
> + * Copyright (C) 2018 Huawei Ltd.
> + * Witten by:
> + *   Junling Zheng <zhengjunling@huawei.com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + */
> +#include "fsck.h"
> +
> +int f2fs_tune(struct f2fs_sb_info *sbi)
> +{
> +	int ret;
> +
> +	/* Get and validate sbi->raw_super */
> +	ret = validate_super_block(sbi, 0);
> +	if (ret) {
> +		ret = validate_super_block(sbi, 1);
> +		if (ret)
> +			return -1;
> +	}
> +
> +	/* Tune features in sb */
> +	if (c.feature)
> +		sbi->raw_super->feature |= c.feature;
> +	if (c.nofeature)
> +		sbi->raw_super->feature &= ~c.nofeature;
> +
> +	MSG(0, "Info: Tune feature successfully!\n");
> +	/* Print features in sb */
> +	print_sb_state(sbi->raw_super);
> +
> +	/* Write raw_super back to both 1st and 2nd sb on disk */
> +	ret = dev_write(sbi->raw_super, F2FS_SUPER_OFFSET,
> +				sizeof(struct f2fs_super_block));
> +	ASSERT(ret >= 0);
> +	ret = dev_write(sbi->raw_super, F2FS_SUPER_OFFSET + F2FS_BLKSIZE,
> +						sizeof(struct f2fs_super_block));
> +	ASSERT(ret >= 0);
> +	MSG(0, "Info: Writeback successfully!\n");
> +
> +	return ret;
> +}
> diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
> index a1274fd..87d2fe9 100644
> --- a/include/f2fs_fs.h
> +++ b/include/f2fs_fs.h
> @@ -13,6 +13,7 @@
>  #define __F2FS_FS_H__
>  
>  #include <stdio.h>
> +#include <ctype.h>
>  #ifdef HAVE_CONFIG_H
>  #include <config.h>
>  #endif
> @@ -28,6 +29,7 @@
>  #define WITH_DEFRAG
>  #define WITH_RESIZE
>  #define WITH_SLOAD
> +#define WITH_TUNE
>  #endif
>  
>  #include <inttypes.h>
> @@ -309,6 +311,7 @@ enum f2fs_config_func {
>  	DEFRAG,
>  	RESIZE,
>  	SLOAD,
> +	TUNE,
>  };
>  
>  enum default_set {
> @@ -381,7 +384,8 @@ struct f2fs_configuration {
>  	int ro;
>  	int preserve_limits;		/* preserve quota limits */
>  	int large_nat_bitmap;
> -	__le32 feature;			/* defined features */
> +	__le32 feature;			/* defined features to enable */
> +	__le32 nofeature;		/* defined features to disable */
>  
>  	/* mkfs parameters */
>  	u_int32_t next_free_nid;
> @@ -1334,6 +1338,12 @@ struct feature feature_table[] = {					\
>  	{ NULL,				0x0},				\
>  };
>  
> +#define INIT_TUNE_FEATURE_TABLE						\
> +struct feature tune_feature_table[] = {					\
> +	{ "encrypt",			F2FS_FEATURE_ENCRYPT },		\
> +	{ NULL,				0x0},				\
> +};
> +
>  static inline u32 feature_map(struct feature *table, char *feature)
>  {
>  	struct feature *p;
> @@ -1342,21 +1352,11 @@ static inline u32 feature_map(struct feature *table, char *feature)
>  	return p->mask;
>  }
>  
> -static inline int set_feature_bits(struct feature *table, char *features)
> -{
> -	u32 mask = feature_map(table, features);
> -	if (mask) {
> -		c.feature |= cpu_to_le32(mask);
> -	} else {
> -		MSG(0, "Error: Wrong features %s\n", features);
> -		return -1;
> -	}
> -	return 0;
> -}
> -
>  static inline int parse_feature(struct feature *table, const char *features)
>  {
> -	char *buf, *sub, *next;
> +	char op, *buf, *sub, *next;
> +	u32 feature_bit = 0;
> +	int ret = 0;
>  
>  	buf = calloc(strlen(features) + 1, sizeof(char));
>  	ASSERT(buf);
> @@ -1376,12 +1376,37 @@ static inline int parse_feature(struct feature *table, const char *features)
>  		else
>  			*next = 0;
>  
> -		if (set_feature_bits(table, sub)) {
> -			free(buf);
> -			return -1;
> +		if (!isalnum(*sub)) {
> +			op = *sub;
> +			sub++;
> +		} else {
> +			op = '+';
> +		}
> +
> +		feature_bit = feature_map(table, sub);
> +		if (!feature_bit) {
> +			ERR_MSG("\tError: Not support feature %s\n", sub);
> +			ret = -1;
> +			goto out;
> +		}
> +
> +		switch (op) {
> +		case '+':
> +			c.feature |= cpu_to_le32(feature_bit);
> +			break;
> +		case '-':
> +		case '^':
> +			c.nofeature |= cpu_to_le32(feature_bit);
> +			break;
> +		default:
> +			ERR_MSG("\tError: Wrong operation %c\n", op);
> +			ret = -1;
> +			goto out;
>  		}
>  	}
> +
> +out:
>  	free(buf);
> -	return 0;
> +	return ret;
>  }
>  #endif	/*__F2FS_FS_H */
> diff --git a/man/Makefile.am b/man/Makefile.am
> index 7856586..bfc4d19 100644
> --- a/man/Makefile.am
> +++ b/man/Makefile.am
> @@ -1,3 +1,3 @@
>  ## Makefile.am
>  
> -dist_man_MANS = mkfs.f2fs.8 fsck.f2fs.8 dump.f2fs.8 defrag.f2fs.8 resize.f2fs.8 sload.f2fs.8
> +dist_man_MANS = mkfs.f2fs.8 fsck.f2fs.8 dump.f2fs.8 defrag.f2fs.8 resize.f2fs.8 sload.f2fs.8 tune.f2fs.8
> diff --git a/man/tune.f2fs.8 b/man/tune.f2fs.8
> new file mode 100644
> index 0000000..5ee6790
> --- /dev/null
> +++ b/man/tune.f2fs.8
> @@ -0,0 +1,50 @@
> +.\" Copyright (C) 2015 Huawei Ltd.
> +.\"
> +.TH TUNE.F2FS 8
> +.SH NAME
> +tune.f2fs \- change the parameters of f2fs
> +.SH SYNOPSIS
> +.B tune.f2fs
> +[
> +.B \-d
> +.I debugging-level
> +]
> +[
> +.B \-O
> +.I features to change
> +]
> +.I device
> +.SH DESCRIPTION
> +.B tune.f2fs
> +is used to change the parameters of an f2fs file system (usually in a disk partition).
> +\fIdevice\fP is the special file corresponding to the device (e.g.
> +\fI/dev/sdXX\fP).
> +
> +Current version only supports enabling and disabling 'encrypt' feature.
> +
> +.PP
> +The exit code returned by
> +.B tune.f2fs
> +is 0 on success and -1 on failure.
> +.SH OPTIONS
> +.TP
> +.BI \-d " debug-level"
> +Specify the level of debugging options.
> +The default number is 0, which shows basic debugging messages.
> +.TP
> +.BI \-O " features"
> +Specify the features to enable or disable. Currently only support 'encrypt' feature.
> +.TP
> +.SH AUTHOR
> +This version of
> +.B tune.f2fs
> +has been written by Junling Zheng <zhengjunling@huawei.com>.
> +.SH AVAILABILITY
> +.B tune.f2fs
> +is available from git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs-tools.git.
> +.SH SEE ALSO
> +.BR mkfs.f2fs(8),
> +.BR fsck.f2fs(8),
> +.BR dump.f2fs(8),
> +.BR defrag.f2fs(8),
> +.BR sload.f2fs(8).
> 



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

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

* Re: [RFC PATCH] f2fs-tools: introduce tune.f2fs
  2018-04-26  2:10       ` Junling Zheng
@ 2018-04-26 16:13         ` Jaegeuk Kim
  2018-04-27  2:32           ` Chao Yu
  0 siblings, 1 reply; 13+ messages in thread
From: Jaegeuk Kim @ 2018-04-26 16:13 UTC (permalink / raw)
  To: Junling Zheng; +Cc: linux-f2fs-devel

On 04/26, Junling Zheng wrote:
> Ping...
> 
> On 2018/4/23 15:32, Junling Zheng wrote:
> > Introduce tune.f2fs tool to change the f2fs parameters.
> > Currently this tool only supports adding or removing encrypt
> > feature bit in superblock.

What is the purpose of this empty tune.f2fs? How can we say we have this
tool to users? You have to design what kind of things to support first.

Thanks,

> > 
> > Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
> > ---
> >  fsck/Makefile.am  |  3 ++-
> >  fsck/fsck.h       |  5 +++++
> >  fsck/main.c       | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  fsck/tune.c       | 46 +++++++++++++++++++++++++++++++++++++++++
> >  include/f2fs_fs.h | 61 +++++++++++++++++++++++++++++++++++++++----------------
> >  man/Makefile.am   |  2 +-
> >  man/tune.f2fs.8   | 50 +++++++++++++++++++++++++++++++++++++++++++++
> >  7 files changed, 207 insertions(+), 20 deletions(-)
> >  create mode 100644 fsck/tune.c
> >  create mode 100644 man/tune.f2fs.8
> > 
> > diff --git a/fsck/Makefile.am b/fsck/Makefile.am
> > index 1fc7310..3efacfd 100644
> > --- a/fsck/Makefile.am
> > +++ b/fsck/Makefile.am
> > @@ -5,7 +5,7 @@ AM_CFLAGS = -Wall
> >  sbin_PROGRAMS = fsck.f2fs
> >  noinst_HEADERS = common.h dict.h dqblk_v2.h f2fs.h fsck.h node.h quotaio.h quotaio_tree.h quotaio_v2.h xattr.h
> >  include_HEADERS = $(top_srcdir)/include/quota.h
> > -fsck_f2fs_SOURCES = main.c fsck.c dump.c mount.c defrag.c resize.c \
> > +fsck_f2fs_SOURCES = main.c fsck.c dump.c mount.c defrag.c resize.c tune.c \
> >  		node.c segment.c dir.c sload.c xattr.c \
> >  		dict.c mkquota.c quotaio.c quotaio_tree.c quotaio_v2.c
> >  fsck_f2fs_LDADD = ${libselinux_LIBS} ${libuuid_LIBS} $(top_builddir)/lib/libf2fs.la
> > @@ -15,3 +15,4 @@ install-data-hook:
> >  	ln -sf fsck.f2fs $(DESTDIR)/$(sbindir)/defrag.f2fs
> >  	ln -sf fsck.f2fs $(DESTDIR)/$(sbindir)/resize.f2fs
> >  	ln -sf fsck.f2fs $(DESTDIR)/$(sbindir)/sload.f2fs
> > +	ln -sf fsck.f2fs $(DESTDIR)/$(sbindir)/tune.f2fs
> > diff --git a/fsck/fsck.h b/fsck/fsck.h
> > index 3e13fc6..39d6ed4 100644
> > --- a/fsck/fsck.h
> > +++ b/fsck/fsck.h
> > @@ -180,6 +180,8 @@ extern void write_superblock(struct f2fs_super_block *);
> >  extern void update_data_blkaddr(struct f2fs_sb_info *, nid_t, u16, block_t);
> >  extern void update_nat_blkaddr(struct f2fs_sb_info *, nid_t, nid_t, block_t);
> >  
> > +extern int validate_super_block(struct f2fs_sb_info *, int);
> > +extern void print_sb_state(struct f2fs_super_block *);
> >  extern void print_raw_sb_info(struct f2fs_super_block *);
> >  
> >  extern u32 get_free_segments(struct f2fs_sb_info *);
> > @@ -220,6 +222,9 @@ int f2fs_resize(struct f2fs_sb_info *);
> >  /* sload.c */
> >  int f2fs_sload(struct f2fs_sb_info *);
> >  
> > +/* tune.c */
> > +int f2fs_tune(struct f2fs_sb_info *);
> > +
> >  /* segment.c */
> >  void reserve_new_block(struct f2fs_sb_info *, block_t *,
> >  					struct f2fs_summary *, int);
> > diff --git a/fsck/main.c b/fsck/main.c
> > index c4dd8b1..b8e1aee 100644
> > --- a/fsck/main.c
> > +++ b/fsck/main.c
> > @@ -29,6 +29,7 @@ extern struct sparse_file *f2fs_sparse_file;
> >  #endif
> >  
> >  INIT_FEATURE_TABLE;
> > +INIT_TUNE_FEATURE_TABLE;
> >  
> >  static char *absolute_path(const char *file)
> >  {
> > @@ -123,6 +124,15 @@ void sload_usage()
> >  	exit(1);
> >  }
> >  
> > +void tune_usage()
> > +{
> > +	MSG(0, "\nUsage: tune.f2fs [options] device\n");
> > +	MSG(0, "[options]:\n");
> > +	MSG(0, "  -d debug level [default:0]\n");
> > +	MSG(0, "  -O [^]feature[,...]\n");
> > +	exit(1);
> > +}
> > +
> >  static int is_digits(char *optarg)
> >  {
> >  	unsigned int i;
> > @@ -145,6 +155,8 @@ static void error_out(char *prog)
> >  		resize_usage();
> >  	else if (!strcmp("sload.f2fs", prog))
> >  		sload_usage();
> > +	else if (!strcmp("tune.f2fs", prog))
> > +		tune_usage();
> >  	else
> >  		MSG(0, "\nWrong program.\n");
> >  }
> > @@ -528,6 +540,32 @@ void f2fs_parse_options(int argc, char *argv[])
> >  			if (err != NOERROR)
> >  				break;
> >  		}
> > +	} else if (!strcmp("tune.f2fs", prog)) {
> > +		const char *option_string = "d:O:";
> > +
> > +		c.func = TUNE;
> > +		while ((option = getopt(argc, argv, option_string)) != EOF) {
> > +			switch (option) {
> > +			case 'd':
> > +				if (!is_digits(optarg)) {
> > +					err = EWRONG_OPT;
> > +					break;
> > +				}
> > +				c.dbg_lv = atoi(optarg);
> > +				MSG(0, "Info: Debug level = %d\n",
> > +							c.dbg_lv);
> > +				break;
> > +			case 'O':
> > +				if (parse_feature(tune_feature_table, optarg))
> > +					tune_usage();
> > +				break;
> > +			default:
> > +				err = EUNKNOWN_OPT;
> > +				break;
> > +			}
> > +			if (err != NOERROR)
> > +				break;
> > +		}
> >  	}
> >  
> >  	add_default_options();
> > @@ -736,6 +774,13 @@ static int do_sload(struct f2fs_sb_info *sbi)
> >  	return f2fs_sload(sbi);
> >  }
> >  
> > +static int do_tune(struct f2fs_sb_info *sbi)
> > +{
> > +	// TODO: check global configuration
> > +
> > +	return f2fs_tune(sbi);
> > +}
> > +
> >  int main(int argc, char **argv)
> >  {
> >  	struct f2fs_sb_info *sbi;
> > @@ -768,6 +813,18 @@ fsck_again:
> >  	gfsck.sbi.fsck = &gfsck;
> >  	sbi = &gfsck.sbi;
> >  
> > +#ifdef WITH_TUNE
> > +	if (c.func == TUNE) {
> > +		ret = do_tune(sbi);
> > +		if (ret)
> > +			goto out_err;
> > +		/* If tune successfully, then call
> > +		 * f2fs_finalize_device to fsync.
> > +		 */
> > +		goto out;
> > +	}
> > +#endif
> > +
> >  	ret = f2fs_do_mount(sbi);
> >  	if (ret != 0) {
> >  		if (ret == 1) {
> > @@ -836,6 +893,9 @@ retry:
> >  				goto fsck_again;
> >  		}
> >  	}
> > +#ifdef WITH_TUNE
> > +out:
> > +#endif
> >  	ret = f2fs_finalize_device();
> >  	if (ret < 0)
> >  		return ret;
> > diff --git a/fsck/tune.c b/fsck/tune.c
> > new file mode 100644
> > index 0000000..1322639
> > --- /dev/null
> > +++ b/fsck/tune.c
> > @@ -0,0 +1,46 @@
> > +/**
> > + * tune.c
> > + *
> > + * Copyright (C) 2018 Huawei Ltd.
> > + * Witten by:
> > + *   Junling Zheng <zhengjunling@huawei.com>
> > + *
> > + * This program is free software; you can redistribute it and/or modify
> > + * it under the terms of the GNU General Public License version 2 as
> > + * published by the Free Software Foundation.
> > + */
> > +#include "fsck.h"
> > +
> > +int f2fs_tune(struct f2fs_sb_info *sbi)
> > +{
> > +	int ret;
> > +
> > +	/* Get and validate sbi->raw_super */
> > +	ret = validate_super_block(sbi, 0);
> > +	if (ret) {
> > +		ret = validate_super_block(sbi, 1);
> > +		if (ret)
> > +			return -1;
> > +	}
> > +
> > +	/* Tune features in sb */
> > +	if (c.feature)
> > +		sbi->raw_super->feature |= c.feature;
> > +	if (c.nofeature)
> > +		sbi->raw_super->feature &= ~c.nofeature;
> > +
> > +	MSG(0, "Info: Tune feature successfully!\n");
> > +	/* Print features in sb */
> > +	print_sb_state(sbi->raw_super);
> > +
> > +	/* Write raw_super back to both 1st and 2nd sb on disk */
> > +	ret = dev_write(sbi->raw_super, F2FS_SUPER_OFFSET,
> > +				sizeof(struct f2fs_super_block));
> > +	ASSERT(ret >= 0);
> > +	ret = dev_write(sbi->raw_super, F2FS_SUPER_OFFSET + F2FS_BLKSIZE,
> > +						sizeof(struct f2fs_super_block));
> > +	ASSERT(ret >= 0);
> > +	MSG(0, "Info: Writeback successfully!\n");
> > +
> > +	return ret;
> > +}
> > diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
> > index a1274fd..87d2fe9 100644
> > --- a/include/f2fs_fs.h
> > +++ b/include/f2fs_fs.h
> > @@ -13,6 +13,7 @@
> >  #define __F2FS_FS_H__
> >  
> >  #include <stdio.h>
> > +#include <ctype.h>
> >  #ifdef HAVE_CONFIG_H
> >  #include <config.h>
> >  #endif
> > @@ -28,6 +29,7 @@
> >  #define WITH_DEFRAG
> >  #define WITH_RESIZE
> >  #define WITH_SLOAD
> > +#define WITH_TUNE
> >  #endif
> >  
> >  #include <inttypes.h>
> > @@ -309,6 +311,7 @@ enum f2fs_config_func {
> >  	DEFRAG,
> >  	RESIZE,
> >  	SLOAD,
> > +	TUNE,
> >  };
> >  
> >  enum default_set {
> > @@ -381,7 +384,8 @@ struct f2fs_configuration {
> >  	int ro;
> >  	int preserve_limits;		/* preserve quota limits */
> >  	int large_nat_bitmap;
> > -	__le32 feature;			/* defined features */
> > +	__le32 feature;			/* defined features to enable */
> > +	__le32 nofeature;		/* defined features to disable */
> >  
> >  	/* mkfs parameters */
> >  	u_int32_t next_free_nid;
> > @@ -1334,6 +1338,12 @@ struct feature feature_table[] = {					\
> >  	{ NULL,				0x0},				\
> >  };
> >  
> > +#define INIT_TUNE_FEATURE_TABLE						\
> > +struct feature tune_feature_table[] = {					\
> > +	{ "encrypt",			F2FS_FEATURE_ENCRYPT },		\
> > +	{ NULL,				0x0},				\
> > +};
> > +
> >  static inline u32 feature_map(struct feature *table, char *feature)
> >  {
> >  	struct feature *p;
> > @@ -1342,21 +1352,11 @@ static inline u32 feature_map(struct feature *table, char *feature)
> >  	return p->mask;
> >  }
> >  
> > -static inline int set_feature_bits(struct feature *table, char *features)
> > -{
> > -	u32 mask = feature_map(table, features);
> > -	if (mask) {
> > -		c.feature |= cpu_to_le32(mask);
> > -	} else {
> > -		MSG(0, "Error: Wrong features %s\n", features);
> > -		return -1;
> > -	}
> > -	return 0;
> > -}
> > -
> >  static inline int parse_feature(struct feature *table, const char *features)
> >  {
> > -	char *buf, *sub, *next;
> > +	char op, *buf, *sub, *next;
> > +	u32 feature_bit = 0;
> > +	int ret = 0;
> >  
> >  	buf = calloc(strlen(features) + 1, sizeof(char));
> >  	ASSERT(buf);
> > @@ -1376,12 +1376,37 @@ static inline int parse_feature(struct feature *table, const char *features)
> >  		else
> >  			*next = 0;
> >  
> > -		if (set_feature_bits(table, sub)) {
> > -			free(buf);
> > -			return -1;
> > +		if (!isalnum(*sub)) {
> > +			op = *sub;
> > +			sub++;
> > +		} else {
> > +			op = '+';
> > +		}
> > +
> > +		feature_bit = feature_map(table, sub);
> > +		if (!feature_bit) {
> > +			ERR_MSG("\tError: Not support feature %s\n", sub);
> > +			ret = -1;
> > +			goto out;
> > +		}
> > +
> > +		switch (op) {
> > +		case '+':
> > +			c.feature |= cpu_to_le32(feature_bit);
> > +			break;
> > +		case '-':
> > +		case '^':
> > +			c.nofeature |= cpu_to_le32(feature_bit);
> > +			break;
> > +		default:
> > +			ERR_MSG("\tError: Wrong operation %c\n", op);
> > +			ret = -1;
> > +			goto out;
> >  		}
> >  	}
> > +
> > +out:
> >  	free(buf);
> > -	return 0;
> > +	return ret;
> >  }
> >  #endif	/*__F2FS_FS_H */
> > diff --git a/man/Makefile.am b/man/Makefile.am
> > index 7856586..bfc4d19 100644
> > --- a/man/Makefile.am
> > +++ b/man/Makefile.am
> > @@ -1,3 +1,3 @@
> >  ## Makefile.am
> >  
> > -dist_man_MANS = mkfs.f2fs.8 fsck.f2fs.8 dump.f2fs.8 defrag.f2fs.8 resize.f2fs.8 sload.f2fs.8
> > +dist_man_MANS = mkfs.f2fs.8 fsck.f2fs.8 dump.f2fs.8 defrag.f2fs.8 resize.f2fs.8 sload.f2fs.8 tune.f2fs.8
> > diff --git a/man/tune.f2fs.8 b/man/tune.f2fs.8
> > new file mode 100644
> > index 0000000..5ee6790
> > --- /dev/null
> > +++ b/man/tune.f2fs.8
> > @@ -0,0 +1,50 @@
> > +.\" Copyright (C) 2015 Huawei Ltd.
> > +.\"
> > +.TH TUNE.F2FS 8
> > +.SH NAME
> > +tune.f2fs \- change the parameters of f2fs
> > +.SH SYNOPSIS
> > +.B tune.f2fs
> > +[
> > +.B \-d
> > +.I debugging-level
> > +]
> > +[
> > +.B \-O
> > +.I features to change
> > +]
> > +.I device
> > +.SH DESCRIPTION
> > +.B tune.f2fs
> > +is used to change the parameters of an f2fs file system (usually in a disk partition).
> > +\fIdevice\fP is the special file corresponding to the device (e.g.
> > +\fI/dev/sdXX\fP).
> > +
> > +Current version only supports enabling and disabling 'encrypt' feature.
> > +
> > +.PP
> > +The exit code returned by
> > +.B tune.f2fs
> > +is 0 on success and -1 on failure.
> > +.SH OPTIONS
> > +.TP
> > +.BI \-d " debug-level"
> > +Specify the level of debugging options.
> > +The default number is 0, which shows basic debugging messages.
> > +.TP
> > +.BI \-O " features"
> > +Specify the features to enable or disable. Currently only support 'encrypt' feature.
> > +.TP
> > +.SH AUTHOR
> > +This version of
> > +.B tune.f2fs
> > +has been written by Junling Zheng <zhengjunling@huawei.com>.
> > +.SH AVAILABILITY
> > +.B tune.f2fs
> > +is available from git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs-tools.git.
> > +.SH SEE ALSO
> > +.BR mkfs.f2fs(8),
> > +.BR fsck.f2fs(8),
> > +.BR dump.f2fs(8),
> > +.BR defrag.f2fs(8),
> > +.BR sload.f2fs(8).
> > 
> 

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

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

* Re: [RFC PATCH] f2fs-tools: introduce tune.f2fs
  2018-04-26 16:13         ` Jaegeuk Kim
@ 2018-04-27  2:32           ` Chao Yu
  2018-04-28  2:49             ` Jaegeuk Kim
  0 siblings, 1 reply; 13+ messages in thread
From: Chao Yu @ 2018-04-27  2:32 UTC (permalink / raw)
  To: Jaegeuk Kim, Junling Zheng; +Cc: linux-f2fs-devel

On 2018/4/27 0:13, Jaegeuk Kim wrote:
> On 04/26, Junling Zheng wrote:
>> Ping...
>>
>> On 2018/4/23 15:32, Junling Zheng wrote:
>>> Introduce tune.f2fs tool to change the f2fs parameters.
>>> Currently this tool only supports adding or removing encrypt
>>> feature bit in superblock.
> 
> What is the purpose of this empty tune.f2fs? How can we say we have this
> tool to users? You have to design what kind of things to support first.

I checked very initial tune2fs.c, it only supports very few parameters tuning
functionality, but, can not say that is a bad start to introduce the misc tool.

+       fprintf (stderr, "Usage: %s [-c max-mounts-count] [-e errors-behavior] "
+                "[-i interval[d|m]]\n"
+                "\t[-l] [-m reserved-blocks-percent] device\n", program_name);

Maybe tuning 1. extension list, 2. multi device name later? just guess.

Using fsck.f2fs to tune parameter, IMO, maybe a little confuse for user to
understand the tool's functionality.

Thanks,


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

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

* Re: [RFC PATCH] f2fs-tools: introduce tune.f2fs
  2018-04-27  2:32           ` Chao Yu
@ 2018-04-28  2:49             ` Jaegeuk Kim
  2018-05-02  2:20               ` Chao Yu
  0 siblings, 1 reply; 13+ messages in thread
From: Jaegeuk Kim @ 2018-04-28  2:49 UTC (permalink / raw)
  To: Chao Yu; +Cc: linux-f2fs-devel

On 04/27, Chao Yu wrote:
> On 2018/4/27 0:13, Jaegeuk Kim wrote:
> > On 04/26, Junling Zheng wrote:
> >> Ping...
> >>
> >> On 2018/4/23 15:32, Junling Zheng wrote:
> >>> Introduce tune.f2fs tool to change the f2fs parameters.
> >>> Currently this tool only supports adding or removing encrypt
> >>> feature bit in superblock.
> > 
> > What is the purpose of this empty tune.f2fs? How can we say we have this
> > tool to users? You have to design what kind of things to support first.
> 
> I checked very initial tune2fs.c, it only supports very few parameters tuning
> functionality, but, can not say that is a bad start to introduce the misc tool.
> 
> +       fprintf (stderr, "Usage: %s [-c max-mounts-count] [-e errors-behavior] "
> +                "[-i interval[d|m]]\n"
> +                "\t[-l] [-m reserved-blocks-percent] device\n", program_name);

I don't think We have to follow that.

> 
> Maybe tuning 1. extension list, 2. multi device name later? just guess.

First of all, does it make sense to unset feature bits? I don't think so.

Agreed to your suggestion where:
1. feature set
  - enable system quota
2. extension list
3. multi device name -- which may be really big trial

> 
> Using fsck.f2fs to tune parameter, IMO, maybe a little confuse for user to
> understand the tool's functionality.
> 
> Thanks,

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

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

* Re: [RFC PATCH] f2fs-tools: introduce tune.f2fs
  2018-04-28  2:49             ` Jaegeuk Kim
@ 2018-05-02  2:20               ` Chao Yu
  2018-05-04 19:06                 ` Jaegeuk Kim
  0 siblings, 1 reply; 13+ messages in thread
From: Chao Yu @ 2018-05-02  2:20 UTC (permalink / raw)
  To: Jaegeuk Kim; +Cc: linux-f2fs-devel

On 2018/4/28 10:49, Jaegeuk Kim wrote:
> On 04/27, Chao Yu wrote:
>> On 2018/4/27 0:13, Jaegeuk Kim wrote:
>>> On 04/26, Junling Zheng wrote:
>>>> Ping...
>>>>
>>>> On 2018/4/23 15:32, Junling Zheng wrote:
>>>>> Introduce tune.f2fs tool to change the f2fs parameters.
>>>>> Currently this tool only supports adding or removing encrypt
>>>>> feature bit in superblock.
>>>
>>> What is the purpose of this empty tune.f2fs? How can we say we have this
>>> tool to users? You have to design what kind of things to support first.
>>
>> I checked very initial tune2fs.c, it only supports very few parameters tuning
>> functionality, but, can not say that is a bad start to introduce the misc tool.
>>
>> +       fprintf (stderr, "Usage: %s [-c max-mounts-count] [-e errors-behavior] "
>> +                "[-i interval[d|m]]\n"
>> +                "\t[-l] [-m reserved-blocks-percent] device\n", program_name);
> 
> I don't think We have to follow that.
> 
>>
>> Maybe tuning 1. extension list, 2. multi device name later? just guess.
> 
> First of all, does it make sense to unset feature bits? I don't think so.

Some features can be turned off in a initial image? like encrypted, extra_attr,
checksum...?

> 
> Agreed to your suggestion where:
> 1. feature set
>   - enable system quota
> 2. extension list
> 3. multi device name -- which may be really big trial

So what's our plan now? fill those features into fsck when we need them?

Thanks,

> 
>>
>> Using fsck.f2fs to tune parameter, IMO, maybe a little confuse for user to
>> understand the tool's functionality.
>>
>> Thanks,
> 
> .
> 


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

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

* Re: [RFC PATCH] f2fs-tools: introduce tune.f2fs
  2018-05-02  2:20               ` Chao Yu
@ 2018-05-04 19:06                 ` Jaegeuk Kim
  2018-05-07 12:25                   ` Chao Yu
  0 siblings, 1 reply; 13+ messages in thread
From: Jaegeuk Kim @ 2018-05-04 19:06 UTC (permalink / raw)
  To: Chao Yu; +Cc: linux-f2fs-devel

On 05/02, Chao Yu wrote:
> On 2018/4/28 10:49, Jaegeuk Kim wrote:
> > On 04/27, Chao Yu wrote:
> >> On 2018/4/27 0:13, Jaegeuk Kim wrote:
> >>> On 04/26, Junling Zheng wrote:
> >>>> Ping...
> >>>>
> >>>> On 2018/4/23 15:32, Junling Zheng wrote:
> >>>>> Introduce tune.f2fs tool to change the f2fs parameters.
> >>>>> Currently this tool only supports adding or removing encrypt
> >>>>> feature bit in superblock.
> >>>
> >>> What is the purpose of this empty tune.f2fs? How can we say we have this
> >>> tool to users? You have to design what kind of things to support first.
> >>
> >> I checked very initial tune2fs.c, it only supports very few parameters tuning
> >> functionality, but, can not say that is a bad start to introduce the misc tool.
> >>
> >> +       fprintf (stderr, "Usage: %s [-c max-mounts-count] [-e errors-behavior] "
> >> +                "[-i interval[d|m]]\n"
> >> +                "\t[-l] [-m reserved-blocks-percent] device\n", program_name);
> > 
> > I don't think We have to follow that.
> > 
> >>
> >> Maybe tuning 1. extension list, 2. multi device name later? just guess.
> > 
> > First of all, does it make sense to unset feature bits? I don't think so.
> 
> Some features can be turned off in a initial image? like encrypted, extra_attr,
> checksum...?

Any reason to do thtat? And, we need to find all the files whether there is
any encrypted file.

> 
> > 
> > Agreed to your suggestion where:
> > 1. feature set
> >   - enable system quota
> > 2. extension list
> > 3. multi device name -- which may be really big trial
> 
> So what's our plan now? fill those features into fsck when we need them?

No. If you want to add tune.f2fs, I'd like to see some demand, or very useful
features like this. I just want to avoid introducing an (almost) empty tool.

Thanks,

> 
> Thanks,
> 
> > 
> >>
> >> Using fsck.f2fs to tune parameter, IMO, maybe a little confuse for user to
> >> understand the tool's functionality.
> >>
> >> Thanks,
> > 
> > .
> > 

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

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

* Re: [RFC PATCH] f2fs-tools: introduce tune.f2fs
  2018-05-04 19:06                 ` Jaegeuk Kim
@ 2018-05-07 12:25                   ` Chao Yu
  0 siblings, 0 replies; 13+ messages in thread
From: Chao Yu @ 2018-05-07 12:25 UTC (permalink / raw)
  To: Jaegeuk Kim; +Cc: linux-f2fs-devel

On 2018/5/5 3:06, Jaegeuk Kim wrote:
> On 05/02, Chao Yu wrote:
>> On 2018/4/28 10:49, Jaegeuk Kim wrote:
>>> On 04/27, Chao Yu wrote:
>>>> On 2018/4/27 0:13, Jaegeuk Kim wrote:
>>>>> On 04/26, Junling Zheng wrote:
>>>>>> Ping...
>>>>>>
>>>>>> On 2018/4/23 15:32, Junling Zheng wrote:
>>>>>>> Introduce tune.f2fs tool to change the f2fs parameters.
>>>>>>> Currently this tool only supports adding or removing encrypt
>>>>>>> feature bit in superblock.
>>>>>
>>>>> What is the purpose of this empty tune.f2fs? How can we say we have this
>>>>> tool to users? You have to design what kind of things to support first.
>>>>
>>>> I checked very initial tune2fs.c, it only supports very few parameters tuning
>>>> functionality, but, can not say that is a bad start to introduce the misc tool.
>>>>
>>>> +       fprintf (stderr, "Usage: %s [-c max-mounts-count] [-e errors-behavior] "
>>>> +                "[-i interval[d|m]]\n"
>>>> +                "\t[-l] [-m reserved-blocks-percent] device\n", program_name);
>>>
>>> I don't think We have to follow that.
>>>
>>>>
>>>> Maybe tuning 1. extension list, 2. multi device name later? just guess.
>>>
>>> First of all, does it make sense to unset feature bits? I don't think so.
>>
>> Some features can be turned off in a initial image? like encrypted, extra_attr,
>> checksum...?
> 
> Any reason to do thtat? And, we need to find all the files whether there is

Not very sure, just checked tune2fs, and found them in manual, guessing that
there came demand from user who want to disable some feature in a formatted
partition?

> any encrypted file.
> 
>>
>>>
>>> Agreed to your suggestion where:
>>> 1. feature set
>>>   - enable system quota
>>> 2. extension list
>>> 3. multi device name -- which may be really big trial
>>
>> So what's our plan now? fill those features into fsck when we need them?
> 
> No. If you want to add tune.f2fs, I'd like to see some demand, or very useful
> features like this. I just want to avoid introducing an (almost) empty tool.

Yeah, I see.

Maybe we can support below options except feature/extension_list/device_name.
-Q quota-options	set,clear user/group/prjquota sysfile inode.
-U UUID			set,clear uuid
-L volume-label		set,clear volume name

Thanks,

> 
> Thanks,
> 
>>
>> Thanks,
>>
>>>
>>>>
>>>> Using fsck.f2fs to tune parameter, IMO, maybe a little confuse for user to
>>>> understand the tool's functionality.
>>>>
>>>> Thanks,
>>>
>>> .
>>>
> 
> .
> 


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

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

end of thread, other threads:[~2018-05-07 12:25 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-19 20:54 [PATCH] fsck.f2fs: add -O features to tune the bits Jaegeuk Kim
2018-04-20  1:46 ` Junling Zheng
2018-04-20  1:57   ` Chao Yu
2018-04-20  2:52     ` Jaegeuk Kim
2018-04-23  7:32     ` [RFC PATCH] f2fs-tools: introduce tune.f2fs Junling Zheng
2018-04-26  2:10       ` Junling Zheng
2018-04-26 16:13         ` Jaegeuk Kim
2018-04-27  2:32           ` Chao Yu
2018-04-28  2:49             ` Jaegeuk Kim
2018-05-02  2:20               ` Chao Yu
2018-05-04 19:06                 ` Jaegeuk Kim
2018-05-07 12:25                   ` Chao Yu
2018-04-23  3:55 ` [PATCH] fsck.f2fs: add -O features to tune the bits Chao Yu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.