From: Richard Palethorpe <rpalethorpe@suse.de>
To: Alessandro Carminati <alessandro.carminati@gmail.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH] Fix tst_find_backing_dev when no initramfs
Date: Mon, 24 Oct 2022 14:49:32 +0100 [thread overview]
Message-ID: <87o7u1xpz1.fsf@suse.de> (raw)
In-Reply-To: <Y0023HcAOlhfAcJw@lab.hqhome163.com>
Hello,
Alessandro Carminati <alessandro.carminati@gmail.com> writes:
> mount_root() is the kernel function responsible for mounting the primary
> rootfs.
> A dynamic there, prevents the /dev/root device node in the not yet mounted
> files system. For this reason, in the embedded system that starts without
> an initramfs, or however a proper initscript, the /dev/root device appears
> into the mount table in the / line.
> The test tries to open this /dev/root and fails with a warning.
> This patch aims to fix this situation.
Thanks I probably would have hit this issue sooner or later.
>
> Signed-off-by: Alessandro Carminati <alessandro.carminati@gmail.com>
>
> typo fixes
> ---
> lib/tst_device.c | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
> diff --git a/lib/tst_device.c b/lib/tst_device.c
> index 8419b80c3..c3427eb31 100644
> --- a/lib/tst_device.c
> +++ b/lib/tst_device.c
> @@ -526,6 +526,8 @@ void tst_find_backing_dev(const char *path, char *dev)
> unsigned int dev_major, dev_minor, line_mjr, line_mnr;
> unsigned int len, best_match_len = 1;
> char mnt_point[PATH_MAX];
> + char tmpbuf1[PATH_MAX];
> + char tmpbuf2[PATH_MAX];
It would be more readable to use three buffers and give them meaningful names.
>
> if (stat(path, &buf) < 0)
> tst_brkm(TWARN | TERRNO, NULL, "stat() failed");
> @@ -562,6 +564,24 @@ void tst_find_backing_dev(const char *path, char *dev)
> if (!*dev)
> tst_brkm(TBROK, NULL, "Cannot find block device for %s", path);
>
> + if (stat(dev, &buf) < 0) {
As there is no harm in calling stat twice; could just do
if (stat(dev, &buf) < 0) && strcmp("/dev/root", dev) == 0) {
Or even replace with strcmp with errno == ENOENT and use this as a
general fallback.
> + if (strcmp("/dev/root", dev) != 0) {
> + tst_brkm(TWARN | TERRNO, NULL, "stat(%s) failed", dev);
> + } else {
Then remove this if statement
> + sprintf(tmpbuf1, "/sys/dev/block/%d:%d/uevent",
> dev_major, dev_minor);
> + file = SAFE_FOPEN(NULL, tmpbuf1, "r");
> + while (fgets(line, sizeof(line), file)) {
> + if (sscanf(line, "%[^=]=%s", tmpbuf1, tmpbuf2) != 2)
> + continue;
> + if (strcmp("DEVNAME", tmpbuf1) == 0) {
> + sprintf(dev, "/dev/%s", tmpbuf2);
> + break;
> + }
> + }
> + SAFE_FCLOSE(NULL, file);
> + }
> + }
> +
> if (stat(dev, &buf) < 0)
> tst_brkm(TWARN | TERRNO, NULL, "stat(%s) failed", dev);
>
> --
> 2.34.1
--
Thank you,
Richard.
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2022-10-24 14:21 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-17 11:05 [LTP] [PATCH] Fix tst_find_backing_dev when no initramfs Alessandro Carminati
2022-10-24 13:49 ` Richard Palethorpe [this message]
2022-10-25 9:11 ` Alessandro Carminati
2022-10-25 14:59 ` [LTP] [PATCH] tst_find_backing_dev: Get dev name from /sys/dev/block/*/uevent Richard Palethorpe via ltp
2022-10-25 20:13 ` Alessandro Carminati
2022-10-26 10:56 ` Jan Stancek
2022-10-27 6:50 ` Alessandro Carminati
-- strict thread matches above, loose matches on Subject: below --
2022-10-21 14:18 [LTP] [PATCH] Fix tst_find_backing_dev when no initramfs Alessandro Carminati
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=87o7u1xpz1.fsf@suse.de \
--to=rpalethorpe@suse.de \
--cc=alessandro.carminati@gmail.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