[LTP] [PATCH v3 07/12] syscalls/quotactl08: Test quoatctl01 but quota info hidden in filesystem

Cyril Hrubis chrubis@suse.cz
Wed Nov 10 17:32:42 CET 2021


Hi!
> +	f = SAFE_POPEN("mkfs.ext4 -V 2>&1", "r");
> +	rc = fscanf(f, "mke2fs %d.%d.%d", &major, &minor, &patch);
> +	if (rc != 3)
> +		tst_res(TWARN, "Unable parse version number");
> +	else if (major * 10000 + minor * 100 + patch < 14300)
> +		tst_brk(TCONF, "Test needs mkfs.ext4 >= 1.43 for quota option, test skipped");
> +	pclose(f);

Ideally this should be added to the .needs_cmds instead so that we get
the minimal version in the test metadata too.

I wonder how this should be done.

One possibility would be adding support for version in the needs_cmds
strings as:

"mkfs.ext4 >= 1.43"

Then we would have to add a table of version checks to the library as
well so that we could lookup a function based on the command name.

Something as:

static long mkfs_ext4_version_parser(void)
{
	f = SAFE_POPEN("mkfs.ext4 -V 2>&1", "r");
	rc = fscanf(f, "mke2fs %d.%d.%d", &major, &minor, &patch);
	pclose(f);
	if (rc != 3) {
		tst_res(TWARN, "Unable to parse mkfs.ext4 version");
		return -1;
	}

	return major * 10000 * minor * 100 + patch;
}

static struct version_parser {
	const char *name,
	long (*parser)(void);
} version_parsers[] = {
	{.cmd = "mkfs.ext4", .parser = mkfs_ext4_version_parser},
	{},
};

Then the library would do:

	struct version_parser *p;
	size_t cmd_len;
	long version;
	char *str, *version;

	str = strchr(cmd, ' ');
	if (!str)
		return;

	version = strchr(str, ' ');
	if (!version)
		tst_brk(TBROK, "Missing version in %s", cmd);

	//TODO: check that the string between str and version is a
	//correct operator

	cmd_len = str - cmd;

	for (p = *version_parsers; *p; p++) {
		if (strlen(p->name) != cmd_len)
			continue;

		if (!strncmp(p->name, cmd, cmd_len))
			break;
	}

	if (!p->name)
		tst_brk(TBROK, "No version parser for %s implemented!");

	long ver = p->parser();
	if (ver < 0)
		tst_brk(TBROK, "Failed to parse %s version", p->name);

	/* now we have to parse the version from the version variable
	 * and compare it with the ver variable */

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list