mkfs.f2fs: enforce alias_filename to match device name
PATCH 1/1 mkfs.f2fs: enforce alias_filename to match device name
From: Daeho Jeong <[email protected]>
The kernel expects the device alias file in the root directory to match the device basename (strrchr(path, '/') + 1) to identify the target device both during mount in f2fs_restore_device_alias() and during reserve in f2fs_ioc_reserve_dev_alias().
If a custom alias filename that differs from the device name is used, the kernel fails to match the alias file at mount time (leaving FDEV(i).has_alias unset and allowing pinned files to allocate in that range) and subsequently fails to reserve the device range when requested.
Enforce that if an alias filename is specified, it must match the device name. Also allow specifying just '-c <device>@' as a shorthand so users do not have to redundantly type the device basename twice.
--- man/mkfs.f2fs.8 | 4 +++- mkfs/f2fs_format_main.c | 27 +++++++++++++++------------ 2 files changed, 18 insertions(+), 13 deletions(-)
man/mkfs.f2fs.8 +3 -1
@@ -121,10 +121,12 @@ Currently, the kernel is only able to mount f2fs filesystems where the block size matches the page size. The default value is 4096. .TP -.BI \-c " device-list" +.BI \-c " device_name[@alias_filename]" Build f2fs with these additional devices, so that the user can see all the devices as one big volume. Supports up to 7 devices except meta device. +If '@' or '@alias_filename' is given, the device is configured as a device alias. +Note that alias_filename must match the device name. .TP .BI \-d " debug-level" Specify the level of debugging options.
mkfs/f2fs_format_main.c +15 -12
@@ -191,6 +191,7 @@ static void f2fs_parse_options(int argc, char *argv[])int32_t option=0 ;int val;char *token; +bool is_alias;int dev_num;while ((option =getopt_long (argc,argv,option_string,long_opts,NULL )) !=EOF ) {
@@ -218,6 +219,8 @@ static void f2fs_parse_options(int argc, char *argv[])mkfs_usage (); } + is_alias = (strchr (optarg,'@' ) !=NULL ); + token =strtok (optarg,"@" );if (strlen (token) >MAX_PATH_LEN ) { MSG(0, "Error: device path should be equal or "
@@ -226,21 +229,21 @@ static void f2fs_parse_options(int argc, char *argv[])mkfs_usage (); } 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" ); + +if (is_alias) { +char *dev_name =strrchr (token,'/' ); + + dev_name = dev_name ? dev_name +1 : token; + + token =strtok (NULL ,"" ); +if (token &&strcmp (token, dev_name)) { +MSG (0 , +"Error: alias_filename (\"%s\") must match device name (\"%s\")\n" , + token, dev_name);mkfs_usage (); } c.devices[dev_num].alias_filename = -strdup (token); +strdup (dev_name);if (!c.aliased_devices) c.feature |=F2FS_FEATURE_DEVICE_ALIAS ; c.aliased_devices++;
Signature · 1 line
2.55.0.887.g758fc8c411-goog
Thanks,
Wenjie
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 7 lines · Daeho Jeong
From: Daeho Jeong <[email protected]>
The kernel expects the device alias file in the root directory to match the device basename (
strrchr(path, '/')+ 1) to identify the target device both during mount inf2fs_restore_device_alias()and during reserve inf2fs_ioc_reserve_dev_alias().
Quoted 8 lines
If a custom alias filename that differs from the device name is used, the kernel fails to match the alias file at mount time (leaving FDEV(i).has_alias unset and allowing pinned files to allocate in that range) and subsequently fails to reserve the device range when requested.
Enforce that if an alias filename is specified, it must match the device name. Also allow specifying just '-c <device>@' as a shorthand so users do not have to redundantly type the device basename twice.
Do we need to add a sanity check in kernel side as well, show warning info if device name doesn't match device alias file name?
Quoted 5 lines
Reported-by Wenjie Qi <[email protected]>Fixes 8cc4e257ec20 ("mkfs.f2fs: add device aliasing feature")Signed-off-by Daeho Jeong <[email protected]>
Thanks,