[LTP] [PATCH v2 2/3] lib/tst_device.c: check for BTRFS_SUPER_MAGIC instead of device major of 0

Petr Vorel pvorel@suse.cz
Wed Feb 12 00:52:32 CET 2025


Hi Jeff,

> stat() may return a major number of 0 in st_dev for any number of
> pseudo file systems.  Check for the exact file system instead.  There
> should be no change in behavior with this patch.

> Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
> ---
>  lib/tst_device.c | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)

> diff --git a/lib/tst_device.c b/lib/tst_device.c
> index 70234a83c..744e08a68 100644
> --- a/lib/tst_device.c
> +++ b/lib/tst_device.c
> @@ -17,6 +17,8 @@
>  #include <sys/sysmacros.h>
>  #include <linux/btrfs.h>
>  #include <linux/limits.h>
> +#include <sys/vfs.h>
This just includes <sys/statfs.h>, could you please use it (if it's really
needed).

> +#include <linux/magic.h>
Please don't use it. We have TST_BTRFS_MAGIC and TST_OVERLAYFS_MAGIC in
tst_fs.h. If you ask why we mirror magic it was (probably) for compatibility
with very old kernel headers.

>  #include "lapi/syscalls.h"
>  #include "test.h"
>  #include "safe_macros.h"
> @@ -546,9 +548,6 @@ static void btrfs_get_uevent_path(char *tmp_path, char *uevent_path)
>  		sprintf(bdev_path,
>  			"/sys/fs/btrfs/%s/devices", btrfs_uuid_str);
>  	} else {
> -		if (errno == ENOTTY)
> -			tst_brkm(TBROK | TERRNO, NULL, "BTRFS ioctl failed. Is %s on a tmpfs?", tmp_path);
> -
>  		tst_brkm(TBROK | TERRNO, NULL, "BTRFS ioctl on %s failed.", tmp_path);
>  	}
>  	SAFE_CLOSE(NULL, fd);
> @@ -578,6 +577,7 @@ __attribute__((nonnull))
>  void tst_find_backing_dev(const char *path, char *dev, size_t dev_size)
>  {
>  	struct stat buf;
> +	struct statfs fsbuf;
>  	char uevent_path[PATH_MAX+PATH_MAX+10]; //10 is for the static uevent path
>  	char dev_name[NAME_MAX];
>  	char tmp_path[PATH_MAX];
> @@ -595,8 +595,13 @@ void tst_find_backing_dev(const char *path, char *dev, size_t dev_size)
>  	dev_minor = minor(buf.st_dev);
>  	*dev = '\0';

> -	if (dev_major == 0) {
> +	if (statfs(path, &fsbuf) < 0)
> +		tst_brkm(TWARN | TERRNO, NULL, "statfs() failed");
Please use SAFE_STATFS() here.

> +
> +	if (fsbuf.f_type == BTRFS_SUPER_MAGIC) {
We have TST_BTRFS_MAGIC tst_fs.h.

Kind regards,
Petr

>  		btrfs_get_uevent_path(tmp_path, uevent_path);
> +	} else if (dev_major == 0) {
> +		tst_brkm(TBROK, NULL, "%s resides on an unsupported pseudo-file system.", path);
>  	} else {
>  		tst_resm(TINFO, "Use uevent strategy");
>  		sprintf(uevent_path,


More information about the ltp mailing list