[LTP] [PATCH v2] fsconfig04.c: Check FSCONFIG_SET_PATH

Petr Vorel pvorel@suse.cz
Mon May 26 11:54:56 CEST 2025


Hi Wei,

> Fixes:#1169

> The fsconfig01.c does not test if FSCONFIG_SET_PATH have any effect,
> most of the calls there just set dummy "sync" parameter. This test
> case aims to verify if the FSCONFIG_SET_PATH operation can be used
> to dynamically change the external journal device of ext3 or ext4
> filesystem.

Again, I just pointed out common errors (need more time for a proper feature
review). But on the first look LGTM.

...
> diff --git a/testcases/kernel/syscalls/fsconfig/fsconfig04.c b/testcases/kernel/syscalls/fsconfig/fsconfig04.c
> new file mode 100644
> index 000000000..0df16f0ed
> --- /dev/null
> +++ b/testcases/kernel/syscalls/fsconfig/fsconfig04.c
> @@ -0,0 +1,163 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2025 Wei Gao <wegao@suse.com>
> + */
> +
> +/*\ This test aims to validate the functionality of fsconfig(FSCONFIG_SET_PATH) in
> + * dynamically altering the external journal device of a ext3 or ext4 filesystem.
/*\
 * This test aims to validate the functionality of fsconfig(FSCONFIG_SET_PATH) in
 * dynamically altering the external journal device of a ext3 or ext4 filesystem.
 ...
> +
> +static void setup(void)
> +{
...
> +	SAFE_MKFS(dev1, tst_device->fs_type, mkfs_opts_set_UUID, NULL);
> +	SAFE_MKFS(dev2, tst_device->fs_type, mkfs_opts_set_UUID, NULL);
> +	SAFE_MKFS(dev0, tst_device->fs_type, mkfs_opts_set_journal_dev1, NULL);
> +	SAFE_MKFS(dev0, tst_device->fs_type, mkfs_opts_set_journal_dev2, NULL);
> +	SAFE_MKFS(dev0, tst_device->fs_type, mkfs_opts_set_journal_dev1, NULL);
> +
Please remove this empty line.
> +}
> +
> +static void run(void)
> +{
> +	TEST(fd = fsopen(tst_device->fs_type, 0));
> +	if (fd == -1)
> +		tst_brk(TBROK | TTERRNO, "fsopen() failed");
> +
> +	TEST(fsconfig(fd, FSCONFIG_SET_STRING, "source", dev0, 0));
> +	if (TST_RET == -1)
> +		tst_brk(TFAIL | TTERRNO, "fsconfig(FSCONFIG_SET_STRING) failed");
> +
> +	TEST(fsconfig(fd, FSCONFIG_SET_PATH, "journal_path", dev2, 0));
> +	if (TST_RET == -1) {
> +		if (TST_ERR == EOPNOTSUPP)
> +			tst_brk(TCONF, "fsconfig(FSCONFIG_SET_PATH) not supported");
> +		else
> +			tst_brk(TFAIL | TTERRNO, "fsconfig(FSCONFIG_SET_PATH) failed");
> +	}
> +
> +	TEST(fsconfig(fd, FSCONFIG_CMD_CREATE, NULL, NULL, 0));
> +	if (TST_RET == -1)
> +		tst_brk(TFAIL | TTERRNO, "fsconfig(FSCONFIG_CMD_CREATE) failed");
> +
> +	char loop_name[NAME_MAX];
> +	char path[PATH_MAX];
> +	char device_str[NAME_MAX];
> +	unsigned int major, minor, device_num;
> +	unsigned int found = 0;
> +
> +	int ret = sscanf(dev2, "/dev/%s", loop_name);
> +
> +	if (ret != 1)
> +		tst_brk(TFAIL | TTERRNO, "can not parse loop_name");

Using SAFE_SSCANF() is enough (it checks number of found items), please use it:

	SAFE_SSCANF(dev2, "/dev/%s", loop_name);

> +
> +	sprintf(path, "/sys/block/%s/dev", loop_name);
snprintf() is safer.

> +	SAFE_FILE_SCANF(path, "%u:%u", &major, &minor);
> +	device_num = (major << 8) | minor;
> +	sprintf(device_str, "0x%04X", device_num);
And here as well.
> +
> +	char line[PATH_MAX];
> +	FILE *tune2fs;
> +
> +	sprintf(path, "tune2fs -l %s 2>&1", dev0);
> +	tune2fs = popen(path, "r");
> +
> +	while (fgets(line, PATH_MAX, tune2fs)) {
> +		if (*line && strstr(line, "Journal device:") && strstr(line, device_str)) {
> +			found = 1;
> +			break;
> +		}
> +	}
> +
> +	if (found == 1)
> +		tst_res(TPASS, "Device found in journal");
> +	else
> +		tst_res(TFAIL, "Device not found in journal");
> +
> +	pclose(tune2fs);
> +	SAFE_CLOSE(fd);
> +}
> +
> +static struct tst_test test = {
> +	.test_all = run,
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.needs_root = 1,
> +	.format_device = 1,
> +	.mntpoint = MNTPOINT,
> +	.all_filesystems = 1,
> +	.needs_cmds = (const char *[]) {
> +		"tune2fs",
> +		NULL
> +	},
> +	.skip_filesystems = (const char *const []){"ntfs", "vfat", "exfat",
> +		"ext2", "tmpfs", "xfs", "btrfs", NULL},
You need to skip also bcachefs:

mkfs.bcachefs: invalid option -- 'F'
fsconfig04.c:82: TBROK: mkfs.bcachefs failed with exit code 1

Having a way to specify just ext3 and ext4 would be better, IMHO we don't have
way to do it.

Kind regards,
Petr


More information about the ltp mailing list