From: Petr Vorel <pvorel@suse.cz>
To: Edward Liaw <edliaw@google.com>
Cc: kernel-team@android.com,
Alessandro Carminati <alessandro.carminati@gmail.com>,
ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v2 2/3] set_dev_loop_path: Refactor set_dev_path and check return value
Date: Thu, 23 Mar 2023 09:52:16 +0100 [thread overview]
Message-ID: <20230323085216.GC405493@pevik> (raw)
In-Reply-To: <20230320235108.2058967-3-edliaw@google.com>
Hi Edward,
> tst_find_free_loopdev does not check the return value of set_dev_path
> and will return the last attempted path even if it does not pass a stat
> check. set_dev_path also has a return value that is not consistent with
> the other functions in this file.
This change and change of return is a bit burden in loop rename changes.
I'm ok it's in single patch, but it'd be more readable if it were separate.
> Renames the function to set_dev_loop_path, the const array to
> dev_loop_variants and changes the return value to 0 on success and 1 on
> failure. Check the return value when called in tst_find_free_loopdev
> for failure to acquire a loop device.
> Signed-off-by: Edward Liaw <edliaw@google.com>
> ---
> lib/tst_device.c | 18 +++++++++---------
> 1 file changed, 9 insertions(+), 9 deletions(-)
> diff --git a/lib/tst_device.c b/lib/tst_device.c
> index a61c5a748..ae665f7b6 100644
> --- a/lib/tst_device.c
> +++ b/lib/tst_device.c
> @@ -54,25 +54,25 @@ static char dev_path[PATH_MAX];
> static int device_acquired;
> static unsigned long prev_dev_sec_write;
> -static const char *dev_variants[] = {
> +static const char *dev_loop_variants[] = {
> "/dev/loop%i",
> "/dev/loop/%i",
> "/dev/block/loop%i"
> };
> -static int set_dev_path(int dev, char *path, size_t path_len)
> +static int set_dev_loop_path(int 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);
> + for (i = 0; i < ARRAY_SIZE(dev_loop_variants); i++) {
> + snprintf(path, path_len, dev_loop_variants[i], dev);
> if (stat(path, &st) == 0 && S_ISBLK(st.st_mode))
> - return 1;
> + return 0;
> }
> - return 0;
> + return 1;
> }
> int tst_find_free_loopdev(char *path, size_t path_len)
> @@ -88,8 +88,8 @@ int tst_find_free_loopdev(char *path, size_t path_len)
> rc = ioctl(ctl_fd, LOOP_CTL_GET_FREE);
> close(ctl_fd);
> if (rc >= 0) {
> - if (path)
> - set_dev_path(rc, path, path_len);
> + if (!path || set_dev_loop_path(rc, path, path_len) != 0)
> + tst_brkm(TBROK, NULL, "Could not stat loop device %i", rc);
set_dev_path() is going to be called only if non-NULL path
(see include/tst_device.h). I haven't found a test which uses it this way,
but shouldn't it be checking path, instead of !path?
if (path && set_dev_loop_path(rc, path, path_len) != 0)
Kind regards,
Petr
> tst_resm(TINFO, "Found free device %d '%s'",
> rc, path ?: "");
> return rc;
> @@ -116,7 +116,7 @@ int tst_find_free_loopdev(char *path, size_t path_len)
> */
> for (i = 0; i < 256; i++) {
> - if (!set_dev_path(i, buf, sizeof(buf)))
> + if (set_dev_loop_path(i, buf, sizeof(buf)) != 0)
> continue;
> dev_fd = open(buf, O_RDONLY);
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2023-03-23 8:52 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-20 23:51 [LTP] [PATCH v2 0/3] tst_device.c: Handle Android path for backing device Edward Liaw via ltp
2023-03-20 23:51 ` [LTP] [PATCH v2 1/3] tst_device.c: Use PATH_MAX more consistently Edward Liaw via ltp
2023-03-23 8:13 ` Petr Vorel
2023-03-20 23:51 ` [LTP] [PATCH v2 2/3] set_dev_loop_path: Refactor set_dev_path and check return value Edward Liaw via ltp
2023-03-23 8:52 ` Petr Vorel [this message]
2023-03-23 23:47 ` Edward Liaw via ltp
2023-03-24 6:12 ` Petr Vorel
2023-03-20 23:51 ` [LTP] [PATCH v2 3/3] tst_find_backing_dev: Also check /dev/block/ for backing device Edward Liaw via ltp
2023-03-23 8:53 ` Petr Vorel
2023-03-23 8:24 ` [LTP] [PATCH v2 0/3] tst_device.c: Handle Android path " Petr Vorel
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=20230323085216.GC405493@pevik \
--to=pvorel@suse.cz \
--cc=alessandro.carminati@gmail.com \
--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;
as well as URLs for NNTP newsgroup(s).