Skip to contentSkip to conversation

mkfs.f2fs: add -r (fake_seed) flag

PATCH In review Theotime Combes via Linux-f2fs-devel 2 participants 4 messages Aug 18, 2020 – Aug 19, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mkfs.f2fs: add -r (fake_seed) flag

r flag sets the checkpointing seed to 0 (initially used to remove randomness for apex generation)

---
 include/f2fs_fs.h       | 1 +
 man/mkfs.f2fs.8         | 6 ++++++
 mkfs/f2fs_format.c      | 2 +-
 mkfs/f2fs_format_main.c | 6 +++++-
 4 files changed, 13 insertions(+), 2 deletions(-)
include/f2fs_fs.h +1 -0
index a9982f0..e6f996b 100644
@@ -407,6 +407,7 @@ struct f2fs_configuration {
 	__le32 feature;			/* defined features */
 
 	/* mkfs parameters */
+	int fake_seed;
 	u_int32_t next_free_nid;
 	u_int32_t quota_inum;
 	u_int32_t quota_dnum;
man/mkfs.f2fs.8 +6 -0
index 022941f..d517165 100644
@@ -59,6 +59,9 @@ mkfs.f2fs \- create an F2FS file system
 .B \-q
 ]
 [
+.B \-r
+]
+[
 .B \-R
 .I root_owner
 ]
@@ -212,6 +215,9 @@ Default is disabled.
 Quiet mode.
 With it, mkfs.f2fs does not show any messages, including the basic messages.
 .TP
+.BI \-r
+Sets the checkpointing srand seed to 0.
+.TP
 .BI \-R
 Give root_owner option for initial uid/gid assignment.
 Default is set by getuid()/getgid(), and assigned by "-R $uid:$gid".
mkfs/f2fs_format.c +1 -1
index 1639752..d31cca4 100644
@@ -692,7 +692,7 @@ static int f2fs_write_check_point_pack(void)
 	}
 
 	/* 1. cp page 1 of checkpoint pack 1 */
-	srand(time(NULL));
+	srand((c.fake_seed) ? 0 : time(NULL));
 	cp->checkpoint_ver = cpu_to_le64(rand() | 0x1);
 	set_cp(cur_node_segno[0], c.cur_seg[CURSEG_HOT_NODE]);
 	set_cp(cur_node_segno[1], c.cur_seg[CURSEG_WARM_NODE]);
mkfs/f2fs_format_main.c +5 -1
index 27c1f1d..ac9d8c8 100644
@@ -59,6 +59,7 @@ static void mkfs_usage()
 	MSG(0, "  -C [encoding[:flag1,...]] Support casefolding with optional flags\n");
 	MSG(0, "  -p number of pinned segments (2MB) [default:0]\n");
 	MSG(0, "  -q quiet mode\n");
+	MSG(0, "  -r set checkpointing seed (srand()) to 0\n");
 	MSG(0, "  -R root_owner [default: 0:0]\n");
 	MSG(0, "  -s # of segments per section [default:1]\n");
 	MSG(0, "  -S sparse mode\n");
@@ -124,7 +125,7 @@ static void add_default_options(void)
 
 static void f2fs_parse_options(int argc, char *argv[])
 {
-	static const char *option_string = "qa:c:C:d:e:E:g:il:mo:O:p:R:s:S:z:t:U:Vfw:";
+	static const char *option_string = "qa:c:C:d:e:E:g:il:mo:O:p:rR:s:S:z:t:U:Vfw:";
 	int32_t option=0;
 	int val;
 	char *token;
@@ -187,6 +188,9 @@ static void f2fs_parse_options(int argc, char *argv[])
 		case 'p':
 			c.pinned_segments = atof(optarg);
 			break;
+		case 'r':
+			c.fake_seed = 1;
+			break;
 		case 'R':
 			if (parse_root_owner(optarg, &c.root_uid, &c.root_gid))
 				mkfs_usage();
Signature · 8 lines
2.28.0.220.ged08abb693-goog



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
#1 lore raw

Hi Theotime,

The implementation looks clean to me, but could you please describe more about what the problem will be caused by randomness for apex generation?

Quoted 83 lines · On 2020/8/18 19:18, Theotime Combes via Linux-f2fs-devel wrote:

r flag sets the checkpointing seed to 0 (initially used to remove randomness for apex generation)

---
  include/f2fs_fs.h       | 1 +
  man/mkfs.f2fs.8         | 6 ++++++
  mkfs/f2fs_format.c      | 2 +-
  mkfs/f2fs_format_main.c | 6 +++++-
  4 files changed, 13 insertions(+), 2 deletions(-)
include/f2fs_fs.h +1 -0
index a9982f0..e6f996b 100644
@@ -407,6 +407,7 @@ struct f2fs_configuration {
  	__le32 feature;			/* defined features */
 
  	/* mkfs parameters */
+	int fake_seed;
  	u_int32_t next_free_nid;
  	u_int32_t quota_inum;
  	u_int32_t quota_dnum;
man/mkfs.f2fs.8 +6 -0
index 022941f..d517165 100644
@@ -59,6 +59,9 @@ mkfs.f2fs \- create an F2FS file system
  .B \-q
  ]
  [
+.B \-r
+]
+[
  .B \-R
  .I root_owner
  ]
@@ -212,6 +215,9 @@ Default is disabled.
  Quiet mode.
  With it, mkfs.f2fs does not show any messages, including the basic messages.
  .TP
+.BI \-r
+Sets the checkpointing srand seed to 0.
+.TP
  .BI \-R
  Give root_owner option for initial uid/gid assignment.
  Default is set by getuid()/getgid(), and assigned by "-R $uid:$gid".
mkfs/f2fs_format.c +1 -1
index 1639752..d31cca4 100644
@@ -692,7 +692,7 @@ static int f2fs_write_check_point_pack(void)
  	}
 
  	/* 1. cp page 1 of checkpoint pack 1 */
-	srand(time(NULL));
+	srand((c.fake_seed) ? 0 : time(NULL));
  	cp->checkpoint_ver = cpu_to_le64(rand() | 0x1);
  	set_cp(cur_node_segno[0], c.cur_seg[CURSEG_HOT_NODE]);
  	set_cp(cur_node_segno[1], c.cur_seg[CURSEG_WARM_NODE]);
mkfs/f2fs_format_main.c +2 -1
index 27c1f1d..ac9d8c8 100644
@@ -59,6 +59,7 @@ static void mkfs_usage()
  	MSG(0, "  -C [encoding[:flag1,...]] Support casefolding with optional flags\n");
  	MSG(0, "  -p number of pinned segments (2MB) [default:0]\n");
  	MSG(0, "  -q quiet mode\n");
+	MSG(0, "  -r set checkpointing seed (srand()) to 0\n");
  	MSG(0, "  -R root_owner [default: 0:0]\n");
  	MSG(0, "  -s # of segments per section [default:1]\n");
  	MSG(0, "  -S sparse mode\n");
@@ -124,7 +125,7 @@ static void add_default_options(void)
 
  static void f2fs_parse_options(int argc, char *argv[])
  {
-	static const char *option_string = "qa:c:C:d:e:E:g:il:mo:O:p:R:s:S:z:t:U:Vfw:";
+	static const char *option_string = "qa:c:C:d:e:E:g:il:mo:O:p:rR:s:S:z:t:U:Vfw:";
  	int32_t option=0;
  	int val;
  	char *token;

mkfs/f2fs_format_main.c static void f2fs_parse_options(int argc, char *argv[]) · line 196

Quoted 9 lines
mkfs/f2fs_format_main.c +3 -0
@@ -187,6 +188,9 @@ static void f2fs_parse_options(int argc, char *argv[])
  		case 'p':
  			c.pinned_segments = atof(optarg);
  			break;
+		case 'r':
+			c.fake_seed = 1;
+			break;
  		case 'R':
  			if (parse_root_owner(optarg, &c.root_uid, &c.root_gid))
  				mkfs_usage();

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#2 lore raw
Quoted 6 lines · Chao Yu

Hi Theotime,

The implementation looks clean to me, but could you please describe more about what the problem will be caused by randomness for apex generation?

Hi Chao,
We are adding F2FS support for apex_payload.img (read-only filesystem;
https://source.android.com/devices/tech/ota/apex).
It is necessary for the APEX workflow to have a deterministic output at generation time (i.e: given the same set of input files, we need to have the exact same payload regardless of the time of creation). Fixing the seed is part of solving this problem!
I hope that it makes sense.

Quoted 85 lines · On 2020/8/18 19:18, Theotime Combes via Linux-f2fs-devel wrote:
Quoted 84 lines

r flag sets the checkpointing seed to 0 (initially used to remove randomness for apex generation)

---
  include/f2fs_fs.h       | 1 +
  man/mkfs.f2fs.8         | 6 ++++++
  mkfs/f2fs_format.c      | 2 +-
  mkfs/f2fs_format_main.c | 6 +++++-
  4 files changed, 13 insertions(+), 2 deletions(-)
include/f2fs_fs.h +1 -0
index a9982f0..e6f996b 100644
@@ -407,6 +407,7 @@ struct f2fs_configuration {
      __le32 feature;                 /* defined features */
 
      /* mkfs parameters */
+     int fake_seed;
      u_int32_t next_free_nid;
      u_int32_t quota_inum;
      u_int32_t quota_dnum;
man/mkfs.f2fs.8 +6 -0
index 022941f..d517165 100644
@@ -59,6 +59,9 @@ mkfs.f2fs \- create an F2FS file system
  .B \-q
  ]
  [
+.B \-r
+]
+[
  .B \-R
  .I root_owner
  ]
@@ -212,6 +215,9 @@ Default is disabled.
  Quiet mode.
  With it, mkfs.f2fs does not show any messages, including the basic messages.
  .TP
+.BI \-r
+Sets the checkpointing srand seed to 0.
+.TP
  .BI \-R
  Give root_owner option for initial uid/gid assignment.
  Default is set by getuid()/getgid(), and assigned by "-R $uid:$gid".
mkfs/f2fs_format.c +1 -1
index 1639752..d31cca4 100644
@@ -692,7 +692,7 @@ static int f2fs_write_check_point_pack(void)
      }
 
      /* 1. cp page 1 of checkpoint pack 1 */
-     srand(time(NULL));
+     srand((c.fake_seed) ? 0 : time(NULL));
      cp->checkpoint_ver = cpu_to_le64(rand() | 0x1);
      set_cp(cur_node_segno[0], c.cur_seg[CURSEG_HOT_NODE]);
      set_cp(cur_node_segno[1], c.cur_seg[CURSEG_WARM_NODE]);
mkfs/f2fs_format_main.c +2 -1
index 27c1f1d..ac9d8c8 100644
@@ -59,6 +59,7 @@ static void mkfs_usage()
      MSG(0, "  -C [encoding[:flag1,...]] Support casefolding with optional flags\n");
      MSG(0, "  -p number of pinned segments (2MB) [default:0]\n");
      MSG(0, "  -q quiet mode\n");
+     MSG(0, "  -r set checkpointing seed (srand()) to 0\n");
      MSG(0, "  -R root_owner [default: 0:0]\n");
      MSG(0, "  -s # of segments per section [default:1]\n");
      MSG(0, "  -S sparse mode\n");
@@ -124,7 +125,7 @@ static void add_default_options(void)
 
  static void f2fs_parse_options(int argc, char *argv[])
  {
-     static const char *option_string = "qa:c:C:d:e:E:g:il:mo:O:p:R:s:S:z:t:U:Vfw:";
+     static const char *option_string = "qa:c:C:d:e:E:g:il:mo:O:p:rR:s:S:z:t:U:Vfw:";
      int32_t option=0;
      int val;
      char *token;
@@ -187,6 +188,9 @@ static void f2fs_parse_options(int argc, char *argv[])
              case 'p':
                      c.pinned_segments = atof(optarg);
Quoted 8 lines

mkfs/f2fs_format_main.c static void f2fs_parse_options(int argc, char *argv[]) · line 196

Quoted 8 lines
mkfs/f2fs_format_main.c +3 -0
                      break;
+             case 'r':
+                     c.fake_seed = 1;
+                     break;
              case 'R':
                      if (parse_root_owner(optarg, &c.root_uid, &c.root_gid))
                              mkfs_usage();

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Reviewed-by
#3 lore raw
Quoted 4 lines · Theotime Combes
Quoted 3 lines · Chao Yu

Hi Theotime,

Quoted 8 lines
Quoted 3 lines

The implementation looks clean to me, but could you please describe more about what the problem will be caused by randomness for apex generation?

Hi Chao,
We are adding F2FS support for apex_payload.img (read-only filesystem;
https://source.android.com/devices/tech/ota/apex).
It is necessary for the APEX workflow to have a deterministic output

Ah, I got it, the purpose is to get rid of random bits in apex image during its initialization.

Thanks for the explanation. :)

Thanks,

Quoted 91 lines

at generation time (i.e: given the same set of input files, we need to have the exact same payload regardless of the time of creation). Fixing the seed is part of solving this problem!
I hope that it makes sense.

Quoted 86 lines · On 2020/8/18 19:18, Theotime Combes via Linux-f2fs-devel wrote:
Quoted 85 lines

r flag sets the checkpointing seed to 0 (initially used to remove randomness for apex generation)

---
   include/f2fs_fs.h       | 1 +
   man/mkfs.f2fs.8         | 6 ++++++
   mkfs/f2fs_format.c      | 2 +-
   mkfs/f2fs_format_main.c | 6 +++++-
   4 files changed, 13 insertions(+), 2 deletions(-)
include/f2fs_fs.h +1 -0
index a9982f0..e6f996b 100644
@@ -407,6 +407,7 @@ struct f2fs_configuration {
       __le32 feature;                 /* defined features */
 
       /* mkfs parameters */
+     int fake_seed;
       u_int32_t next_free_nid;
       u_int32_t quota_inum;
       u_int32_t quota_dnum;
man/mkfs.f2fs.8 +6 -0
index 022941f..d517165 100644
@@ -59,6 +59,9 @@ mkfs.f2fs \- create an F2FS file system
   .B \-q
   ]
   [
+.B \-r
+]
+[
   .B \-R
   .I root_owner
   ]
@@ -212,6 +215,9 @@ Default is disabled.
   Quiet mode.
   With it, mkfs.f2fs does not show any messages, including the basic messages.
   .TP
+.BI \-r
+Sets the checkpointing srand seed to 0.
+.TP
   .BI \-R
   Give root_owner option for initial uid/gid assignment.
   Default is set by getuid()/getgid(), and assigned by "-R $uid:$gid".
mkfs/f2fs_format.c +1 -1
index 1639752..d31cca4 100644
@@ -692,7 +692,7 @@ static int f2fs_write_check_point_pack(void)
       }
 
       /* 1. cp page 1 of checkpoint pack 1 */
-     srand(time(NULL));
+     srand((c.fake_seed) ? 0 : time(NULL));
       cp->checkpoint_ver = cpu_to_le64(rand() | 0x1);
       set_cp(cur_node_segno[0], c.cur_seg[CURSEG_HOT_NODE]);
       set_cp(cur_node_segno[1], c.cur_seg[CURSEG_WARM_NODE]);
mkfs/f2fs_format_main.c +2 -1
index 27c1f1d..ac9d8c8 100644
@@ -59,6 +59,7 @@ static void mkfs_usage()
       MSG(0, "  -C [encoding[:flag1,...]] Support casefolding with optional flags\n");
       MSG(0, "  -p number of pinned segments (2MB) [default:0]\n");
       MSG(0, "  -q quiet mode\n");
+     MSG(0, "  -r set checkpointing seed (srand()) to 0\n");
       MSG(0, "  -R root_owner [default: 0:0]\n");
       MSG(0, "  -s # of segments per section [default:1]\n");
       MSG(0, "  -S sparse mode\n");
@@ -124,7 +125,7 @@ static void add_default_options(void)
 
   static void f2fs_parse_options(int argc, char *argv[])
   {
-     static const char *option_string = "qa:c:C:d:e:E:g:il:mo:O:p:R:s:S:z:t:U:Vfw:";
+     static const char *option_string = "qa:c:C:d:e:E:g:il:mo:O:p:rR:s:S:z:t:U:Vfw:";
       int32_t option=0;
       int val;
       char *token;
@@ -187,6 +188,9 @@ static void f2fs_parse_options(int argc, char *argv[])
               case 'p':
                       c.pinned_segments = atof(optarg);
                       break;
Quoted 9 lines
Quoted 7 lines

mkfs/f2fs_format_main.c static void f2fs_parse_options(int argc, char *argv[]) · line 196

Quoted 7 lines
mkfs/f2fs_format_main.c +3 -0
+             case 'r':
+                     c.fake_seed = 1;
+                     break;
               case 'R':
                       if (parse_root_owner(optarg, &c.root_uid, &c.root_gid))
                               mkfs_usage();

.

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel