public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: Edward Liaw <edliaw@google.com>
Cc: kernel-team@android.com, ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v3 4/4] tst_find_backing_dev: Also check /dev/block/ for backing device
Date: Mon, 27 Mar 2023 17:26:10 +0200	[thread overview]
Message-ID: <ZCG1ktXb6w/oOXSI@yuki> (raw)
In-Reply-To: <20230324002441.987778-5-edliaw@google.com>

Hi!
>  -------------------------------------------------------------------------------
>  #include "tst_test.h"
>  
> -void tst_find_backing_dev(const char *path, char *dev);
> +void tst_find_backing_dev(const char *path, char *dev, size_t dev_len);
>  -------------------------------------------------------------------------------
>  
>  This function finds the block dev that this path belongs to, using uevent in sysfs.
> diff --git a/include/tst_device.h b/include/tst_device.h
> index 977427f1c..f0aff4473 100644
> --- a/include/tst_device.h
> +++ b/include/tst_device.h
> @@ -110,8 +110,9 @@ void tst_purge_dir(const char *path);
>   * Find the file or path belongs to which block dev
>   * @path  Path to find the backing dev
>   * @dev   The block dev
> + * @dev_len   The length of the dev string
>   */
> -void tst_find_backing_dev(const char *path, char *dev);
> +void tst_find_backing_dev(const char *path, char *dev, size_t dev_len);
                                                                  ^
This would be a bit better as dev_size since the common usage is that
strings have length and buffers have size.

>  /*
>   * Stat the device mounted on a given path.
> diff --git a/lib/newlib_tests/tst_device.c b/lib/newlib_tests/tst_device.c
> index 87cec3961..53099f9bc 100644
> --- a/lib/newlib_tests/tst_device.c
> +++ b/lib/newlib_tests/tst_device.c
> @@ -71,7 +71,7 @@ static void test_tst_find_backing_dev(void)
>  {
>  	char block_dev[100];
>  
> -	tst_find_backing_dev(mntpoint, block_dev);
> +	tst_find_backing_dev(mntpoint, block_dev, sizeof(block_dev));
>  
>  	if (!strcmp(tst_device->dev, block_dev))
>  		tst_res(TPASS, "%s belongs to %s block dev", mntpoint,
> diff --git a/lib/tst_device.c b/lib/tst_device.c
> index ba46b7613..74de307e7 100644
> --- a/lib/tst_device.c
> +++ b/lib/tst_device.c
> @@ -60,6 +60,11 @@ static const char *dev_loop_variants[] = {
>  	"/dev/block/loop%i"
>  };
>  
> +static const char *dev_variants[] = {
> +	"/dev/%s",
> +	"/dev/block/%s"
> +};
> +
>  static int set_dev_loop_path(int dev, char *path, size_t path_len)
>  {
>  	unsigned int i;
> @@ -75,6 +80,21 @@ static int set_dev_loop_path(int dev, char *path, size_t path_len)
>  	return 1;
>  }
>  
> +static int set_dev_path(char *dev, char *path, size_t path_len)
> +{
> +	unsigned int i;
> +	struct stat st;
> +
> +	for (i = 0; i < ARRAY_SIZE(dev_variants); i++) {
> +		snprintf(path, path_len, dev_variants[i], dev);
> +
> +		if (stat(path, &st) == 0 && S_ISBLK(st.st_mode))
> +			return 0;
> +	}
> +
> +	return 1;
> +}
> +
>  int tst_find_free_loopdev(char *path, size_t path_len)
>  {
>  	int ctl_fd, dev_fd, rc, i;
> @@ -511,7 +531,7 @@ unsigned long tst_dev_bytes_written(const char *dev)
>  }
>  
>  __attribute__((nonnull))
> -void tst_find_backing_dev(const char *path, char *dev)
> +void tst_find_backing_dev(const char *path, char *dev, size_t dev_len)
>  {
>  	struct stat buf;
>  	struct btrfs_ioctl_fs_info_args args = {0};
> @@ -574,7 +594,7 @@ void tst_find_backing_dev(const char *path, char *dev)
>  			sprintf(uevent_path, "%s/%s/uevent",
>  				bdev_path, d->d_name);
>  		} else {
> -			tst_brkm(TBROK | TERRNO, NULL, "No backining device found while looking in %s.", bdev_path);
> +			tst_brkm(TBROK | TERRNO, NULL, "No backing device found while looking in %s.", bdev_path);
>  		}
>  
>  		if (SAFE_READDIR(NULL, dir))
> @@ -590,17 +610,12 @@ void tst_find_backing_dev(const char *path, char *dev)
>  	if (!access(uevent_path, R_OK)) {
>  		FILE_LINES_SCANF(NULL, uevent_path, "DEVNAME=%s", dev_name);
>  
> -		if (dev_name[0])
> -			sprintf(dev, "/dev/%s", dev_name);
> +		if (!dev_name[0] || set_dev_path(dev_name, dev, dev_len) != 0)
                                                                          ^
									  isn't
									  this
									  redundant?

These two are the only minor issues I've found in the patchset,
otherwise:

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

      parent reply	other threads:[~2023-03-27 15:25 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-24  0:24 [LTP] [PATCH v3 0/4] tst_device.c: Handle Android path for backing device Edward Liaw via ltp
2023-03-24  0:24 ` [LTP] [PATCH v3 1/4] set_dev_path: Rename to set_dev_loop_path Edward Liaw via ltp
2023-03-27  7:43   ` Petr Vorel
2023-03-24  0:24 ` [LTP] [PATCH v3 2/4] set_dev_loop_path: Change return value to zero on success Edward Liaw via ltp
2023-03-27  7:43   ` Petr Vorel
2023-03-24  0:24 ` [LTP] [PATCH v3 3/4] tst_find_free_loopdev: Check return value of set_dev_loop_path Edward Liaw via ltp
2023-03-27  7:44   ` Petr Vorel
2023-03-24  0:24 ` [LTP] [PATCH v3 4/4] tst_find_backing_dev: Also check /dev/block/ for backing device Edward Liaw via ltp
2023-03-27  9:36   ` Petr Vorel
2023-03-27 15:26   ` Cyril Hrubis [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZCG1ktXb6w/oOXSI@yuki \
    --to=chrubis@suse.cz \
    --cc=edliaw@google.com \
    --cc=kernel-team@android.com \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox