Skip to contentSkip to conversation

mkfs.f2fs: change -c option description

PATCH In review Daeho Jeong 2 participants 3 messages Sep 27, 2024 – Oct 17, 2024

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/2 mkfs.f2fs: change -c option description

From: Daeho Jeong <[email protected]>

Current description confuses users like they can add addtional devices with one -c option using commas(,) at the same time.

---
 mkfs/f2fs_format_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mkfs/f2fs_format_main.c +1 -1
index d9cdd61..b6785cd 100644
@@ -50,7 +50,7 @@ static void mkfs_usage()
 	MSG(0, "\nUsage: mkfs.f2fs [options] device [sectors]\n");
 	MSG(0, "[options]:\n");
 	MSG(0, "  -b filesystem block size [default:4096]\n");
-	MSG(0, "  -c device1[,device2,...] up to 7 additional devices, except meta device\n");
+	MSG(0, "  -c [device_name] up to 7 additional devices, except meta device\n");
 	MSG(0, "  -d debug level [default:0]\n");
 	MSG(0, "  -e [cold file ext list] e.g. \"mp3,gif,mov\"\n");
 	MSG(0, "  -E [hot file ext list] e.g. \"db\"\n");
Signature · 1 line
2.46.1.824.gd892dcdcdd-goog
#1 lore raw

PATCH v3 2/2 mkfs.f2fs: add device aliasing feature

From: Daeho Jeong <[email protected]>

We can add a device aliasing file which can map the whole device with an extent, not using node blocks. This mapped area should be pinned and normally used for read-only usages. After finished using it, we can deallocate the whole area and return it back to use it for other files.

---
v3: Fixed build errors conflicted with whint patch, wrong parameter,
error messages. Added '/' character check for alias_filename.
v2: Removed unnecessary define and renamed IS_ALIASING()

---
 fsck/dump.c             |  13 ++
 fsck/fsck.c             |  49 ++++--
 fsck/fsck.h             |   4 +-
 fsck/main.c             |   5 +
 include/f2fs_fs.h       |   7 +
 mkfs/f2fs_format.c      | 337 ++++++++++++++++++++++++++++++++--------
 mkfs/f2fs_format_main.c |  40 ++++-
 7 files changed, 369 insertions(+), 86 deletions(-)
fsck/dump.c +13 -0
index 448c0ef..dc3c199 100644
@@ -527,6 +527,19 @@ static int dump_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
 	}
 
 	c.show_file_map_max_offset = f2fs_max_file_offset(&node_blk->i);
+
+	if (IS_DEVICE_ALIASING(&node_blk->i)) {
+		u32 blkaddr = le32_to_cpu(node_blk->i.i_ext.blk_addr);
+		u32 len = le32_to_cpu(node_blk->i.i_ext.len);
+		u32 idx;
+
+		for (idx = 0; idx < len; idx++)
+			dump_data_blk(sbi, idx * F2FS_BLKSIZE, blkaddr++, type);
+		print_extent(true);
+
+		goto dump_xattr;
+	}
+
 	addr_per_block = ADDRS_PER_BLOCK(&node_blk->i);
 
 	/* check data blocks in inode */
fsck/fsck.c +39 -10

99 lines not on this page · raw message

fsck/fsck.h +2 -2
index efccfbc..b581d3e 100644
@@ -180,9 +180,9 @@ extern int fsck_chk_idnode_blk(struct f2fs_sb_info *, struct f2fs_inode *,
 extern int fsck_chk_didnode_blk(struct f2fs_sb_info *, struct f2fs_inode *,
 		enum FILE_TYPE, struct f2fs_node *, u32 *,
 		struct f2fs_compr_blk_cnt *, struct child_info *);
-extern int fsck_chk_data_blk(struct f2fs_sb_info *, int,
+extern int fsck_chk_data_blk(struct f2fs_sb_info *, struct f2fs_inode *,
 		u32, struct child_info *, int, enum FILE_TYPE, u32, u16, u8,
-		int, struct f2fs_node *);
+		struct f2fs_node *);
 extern int fsck_chk_dentry_blk(struct f2fs_sb_info *, int,
 		u32, struct child_info *, int, int, struct f2fs_node *);
 int fsck_chk_inline_dentries(struct f2fs_sb_info *, struct f2fs_node *,
fsck/main.c +5 -0
index 62b3235..25d50e2 100644
@@ -1039,6 +1039,11 @@ static int do_defrag(struct f2fs_sb_info *sbi)
 		return -1;
 	}
 
+	if (get_sb(feature) & F2FS_FEATURE_DEVICE_ALIAS) {
+		MSG(0, "Not support on image with device aliasing feature.\n");
+		return -1;
+	}
+
 	if (c.defrag_start > get_sb(block_count))
 		goto out_range;
 	if (c.defrag_start < SM_I(sbi)->main_blkaddr)
include/f2fs_fs.h +7 -0
index ae052f0..9534da9 100644
@@ -457,6 +457,7 @@ struct device_info {
 	uint64_t start_blkaddr;
 	uint64_t end_blkaddr;
 	uint32_t total_segments;
+	char *alias_filename;
 
 	/* to handle zone block devices */
 	int zoned_model;
@@ -679,6 +680,8 @@ enum {
 #define F2FS_IMMUTABLE_FL		0x00000010 /* Immutable file */
 #define F2FS_NOATIME_FL			0x00000080 /* do not update atime */
 #define F2FS_CASEFOLD_FL		0x40000000 /* Casefolded file */
+#define F2FS_DEVICE_ALIAS_FL		0x80000000 /* File for aliasing a device */
+#define IS_DEVICE_ALIASING(fi)	((fi)->i_flags & cpu_to_le32(F2FS_DEVICE_ALIAS_FL))
 
 #define F2FS_ENC_UTF8_12_1	1
 #define F2FS_ENC_STRICT_MODE_FL	(1 << 0)
@@ -711,6 +714,7 @@ enum {
 #define F2FS_FEATURE_CASEFOLD		0x1000
 #define F2FS_FEATURE_COMPRESSION	0x2000
 #define F2FS_FEATURE_RO			0x4000
+#define F2FS_FEATURE_DEVICE_ALIAS	0x8000
 
 #define MAX_NR_FEATURE			32
 
@@ -1541,11 +1545,14 @@ struct f2fs_configuration {
 	bool need_fsync;
 	bool need_whint;
 	int whint;
+	int aliased_devices;
+	uint32_t aliased_segments;
 
 	/* mkfs parameters */
 	int fake_seed;
 	uint32_t next_free_nid;
 	uint32_t lpf_ino;
+	uint32_t first_alias_ino;
 	uint32_t root_uid;
 	uint32_t root_gid;
 	uint32_t blksize;
mkfs/f2fs_format.c +269 -68

462 lines not on this page · raw message

mkfs/f2fs_format_main.c +34 -6
index b6785cd..9407f5b 100644
@@ -50,7 +50,7 @@ static void mkfs_usage()
 	MSG(0, "\nUsage: mkfs.f2fs [options] device [sectors]\n");
 	MSG(0, "[options]:\n");
 	MSG(0, "  -b filesystem block size [default:4096]\n");
-	MSG(0, "  -c [device_name] up to 7 additional devices, except meta device\n");
+	MSG(0, "  -c [device_name[@alias_filename]] up to 7 additional devices, except meta device\n");
 	MSG(0, "  -d debug level [default:0]\n");
 	MSG(0, "  -e [cold file ext list] e.g. \"mp3,gif,mov\"\n");
 	MSG(0, "  -E [hot file ext list] e.g. \"db\"\n");
@@ -106,6 +106,9 @@ static void f2fs_show_info()
 
 	if (c.feature & F2FS_FEATURE_COMPRESSION)
 		MSG(0, "Info: Enable Compression\n");
+
+	if (c.feature & F2FS_FEATURE_DEVICE_ALIAS)
+		MSG(0, "Info: Enable device aliasing\n");
 }
 
 #if defined(ANDROID_TARGET) && defined(HAVE_SYS_UTSNAME_H)
@@ -182,6 +185,7 @@ static void f2fs_parse_options(int argc, char *argv[])
 	int32_t option=0;
 	int val;
 	char *token;
+	int dev_num;
 
 	while ((option = getopt_long(argc,argv,option_string,long_opts,NULL)) != EOF) {
 		switch (option) {
@@ -201,17 +205,41 @@ static void f2fs_parse_options(int argc, char *argv[])
 			}
 			break;
 		case 'c':
-			if (c.ndevs >= MAX_DEVICES) {
+			dev_num = c.ndevs;
+
+			if (dev_num >= MAX_DEVICES) {
 				MSG(0, "Error: Too many devices\n");
 				mkfs_usage();
 			}
 
-			if (strlen(optarg) > MAX_PATH_LEN) {
-				MSG(0, "Error: device path should be less than "
-					"%d characters\n", MAX_PATH_LEN);
+			token = strtok(optarg, "@");
+			if (strlen(token) > MAX_PATH_LEN) {
+				MSG(0, "Error: device path should be equal or "
+					"less than %d characters\n",
+					MAX_PATH_LEN);
 				mkfs_usage();
 			}
-			c.devices[c.ndevs++].path = strdup(optarg);
+			c.devices[dev_num].path = strdup(token);
+			token = strtok(NULL, "");
+			if (token) {
+				if (strlen(token) > MAX_PATH_LEN) {
+					MSG(0, "Error: alias_filename should "
+						"be equal or less than %d "
+						"characters\n", MAX_PATH_LEN);
+					mkfs_usage();
+				}
+				if (strchr(token, '/')) {
+					MSG(0, "Error: alias_filename has "
+						"invalid '/' character\n");
+					mkfs_usage();
+				}
+				c.devices[dev_num].alias_filename =
+					strdup(token);
+				if (!c.aliased_devices)
+					c.feature |= F2FS_FEATURE_DEVICE_ALIAS;
+				c.aliased_devices++;
+			}
+			c.ndevs++;
 			break;
 		case 'd':
 			c.dbg_lv = atoi(optarg);
Signature · 1 line
2.46.1.824.gd892dcdcdd-goog
#2 lore raw
In reply to Daeho Jeong
Quoted 17 lines · Daeho Jeong <[email protected]> 于2024年9月28日周六 00:08写道:

From: Daeho Jeong <[email protected]>

Current description confuses users like they can add addtional devices with one -c option using commas(,) at the same time.

---
 mkfs/f2fs_format_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mkfs/f2fs_format_main.c +0 -0
index d9cdd61..b6785cd 100644

mkfs/f2fs_format_main.c static void mkfs_usage() · line 53

Quoted 5 lines
mkfs/f2fs_format_main.c +1 -1
@@ -50,7 +50,7 @@ static void mkfs_usage()
        MSG(0, "\nUsage: mkfs.f2fs [options] device [sectors]\n");
        MSG(0, "[options]:\n");
        MSG(0, "  -b filesystem block size [default:4096]\n");
-       MSG(0, "  -c device1[,device2,...] up to 7 additional devices, except meta device\n");
+       MSG(0, "  -c [device_name] up to 7 additional devices, except meta device\n");

Dears,
it seems that man should be updated too?
.BI \-c " device-list"
Build f2fs with these additional "comma separated devices", so that the user can see all the devices as one big volume.
Supports up to 7 devices except meta device.
thanks!

Quoted 12 lines
mkfs/f2fs_format_main.c +0 -1
        MSG(0, "  -d debug level [default:0]\n");
        MSG(0, "  -e [cold file ext list] e.g. \"mp3,gif,mov\"\n");
        MSG(0, "  -E [hot file ext list] e.g. \"db\"\n");
--

2.46.1.824.gd892dcdcdd-goog

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