* [LTP] [PATCH] tst_device: Scan /sys/block/* for stat file
@ 2020-01-08 13:48 Cyril Hrubis
2020-01-09 9:03 ` Yang Xu
0 siblings, 1 reply; 5+ messages in thread
From: Cyril Hrubis @ 2020-01-08 13:48 UTC (permalink / raw)
To: ltp
The current tst_dev_bytes_written() function works only for simple cases
where the block device is not divided into partitions. This patch fixes
that scannning the sysfiles for pattern /sys/block/*/devname/stat.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
CC: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
CC: Sumit Garg <sumit.garg@linaro.org>
---
lib/tst_device.c | 33 ++++++++++++++++++++++++++++-----
1 file changed, 28 insertions(+), 5 deletions(-)
diff --git a/lib/tst_device.c b/lib/tst_device.c
index 10f71901d..aca769559 100644
--- a/lib/tst_device.c
+++ b/lib/tst_device.c
@@ -373,16 +373,39 @@ int tst_umount(const char *path)
return -1;
}
+int find_stat_file(const char *dev, char *path, size_t path_len)
+{
+ const char *devname = strrchr(dev, '/') + 1;
+
+ snprintf(path, path_len, "/sys/block/%s/stat", devname);
+
+ if (!access(path, F_OK))
+ return 1;
+
+ DIR *dir = SAFE_OPENDIR(NULL, "/sys/block/");
+ struct dirent *ent;
+
+ while ((ent = readdir(dir))) {
+ snprintf(path, path_len, "/sys/block/%s/%s/stat", ent->d_name, devname);
+
+ fprintf(stderr, "%s\n", path);
+
+ if (!access(path, F_OK)) {
+ SAFE_CLOSEDIR(NULL, dir);
+ return 1;
+ }
+ }
+
+ SAFE_CLOSEDIR(NULL, dir);
+ return 0;
+}
+
unsigned long tst_dev_bytes_written(const char *dev)
{
- struct stat st;
unsigned long dev_sec_write = 0, dev_bytes_written, io_ticks = 0;
char dev_stat_path[1024];
- snprintf(dev_stat_path, sizeof(dev_stat_path), "/sys/block/%s/stat",
- strrchr(dev, '/') + 1);
-
- if (stat(dev_stat_path, &st) != 0)
+ if (!find_stat_file(dev, dev_stat_path, sizeof(dev_stat_path)))
tst_brkm(TCONF, NULL, "Test device stat file: %s not found",
dev_stat_path);
--
2.23.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [LTP] [PATCH] tst_device: Scan /sys/block/* for stat file
2020-01-08 13:48 [LTP] [PATCH] tst_device: Scan /sys/block/* for stat file Cyril Hrubis
@ 2020-01-09 9:03 ` Yang Xu
2020-01-09 14:08 ` Cyril Hrubis
0 siblings, 1 reply; 5+ messages in thread
From: Yang Xu @ 2020-01-09 9:03 UTC (permalink / raw)
To: ltp
Hi
> The current tst_dev_bytes_written() function works only for simple cases
> where the block device is not divided into partitions. This patch fixes
> that scannning the sysfiles for pattern /sys/block/*/devname/stat.
>
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
> CC: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
> CC: Sumit Garg <sumit.garg@linaro.org>
> ---
> lib/tst_device.c | 33 ++++++++++++++++++++++++++++-----
> 1 file changed, 28 insertions(+), 5 deletions(-)
>
> diff --git a/lib/tst_device.c b/lib/tst_device.c
> index 10f71901d..aca769559 100644
> --- a/lib/tst_device.c
> +++ b/lib/tst_device.c
> @@ -373,16 +373,39 @@ int tst_umount(const char *path)
> return -1;
> }
>
> +int find_stat_file(const char *dev, char *path, size_t path_len)
> +{
> + const char *devname = strrchr(dev, '/') + 1;
> +
> + snprintf(path, path_len, "/sys/block/%s/stat", devname);
> +
> + if (!access(path, F_OK))
> + return 1;
> +
> + DIR *dir = SAFE_OPENDIR(NULL, "/sys/block/");
> + struct dirent *ent;
> +
> + while ((ent = readdir(dir))) {
> + snprintf(path, path_len, "/sys/block/%s/%s/stat", ent->d_name, devname);
> +
> + fprintf(stderr, "%s\n", path);
> +
It will make many noise when using .all_filesystem and we can remove it.
Other than, it looks good to me.
> + if (!access(path, F_OK)) {
> + SAFE_CLOSEDIR(NULL, dir);
> + return 1;
> + }
> + }
> +
> + SAFE_CLOSEDIR(NULL, dir);
> + return 0;
> +}
> +
> unsigned long tst_dev_bytes_written(const char *dev)
> {
> - struct stat st;
> unsigned long dev_sec_write = 0, dev_bytes_written, io_ticks = 0;
> char dev_stat_path[1024];
>
> - snprintf(dev_stat_path, sizeof(dev_stat_path), "/sys/block/%s/stat",
> - strrchr(dev, '/') + 1);
> -
> - if (stat(dev_stat_path, &st) != 0)
> + if (!find_stat_file(dev, dev_stat_path, sizeof(dev_stat_path)))
> tst_brkm(TCONF, NULL, "Test device stat file: %s not found",
> dev_stat_path);
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [LTP] [PATCH] tst_device: Scan /sys/block/* for stat file
2020-01-09 9:03 ` Yang Xu
@ 2020-01-09 14:08 ` Cyril Hrubis
2020-01-15 10:39 ` Petr Vorel
0 siblings, 1 reply; 5+ messages in thread
From: Cyril Hrubis @ 2020-01-09 14:08 UTC (permalink / raw)
To: ltp
Hi!
> > The current tst_dev_bytes_written() function works only for simple cases
> > where the block device is not divided into partitions. This patch fixes
> > that scannning the sysfiles for pattern /sys/block/*/devname/stat.
> >
> > Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
> > CC: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
> > CC: Sumit Garg <sumit.garg@linaro.org>
> > ---
> > lib/tst_device.c | 33 ++++++++++++++++++++++++++++-----
> > 1 file changed, 28 insertions(+), 5 deletions(-)
> >
> > diff --git a/lib/tst_device.c b/lib/tst_device.c
> > index 10f71901d..aca769559 100644
> > --- a/lib/tst_device.c
> > +++ b/lib/tst_device.c
> > @@ -373,16 +373,39 @@ int tst_umount(const char *path)
> > return -1;
> > }
> >
> > +int find_stat_file(const char *dev, char *path, size_t path_len)
> > +{
> > + const char *devname = strrchr(dev, '/') + 1;
> > +
> > + snprintf(path, path_len, "/sys/block/%s/stat", devname);
> > +
> > + if (!access(path, F_OK))
> > + return 1;
> > +
> > + DIR *dir = SAFE_OPENDIR(NULL, "/sys/block/");
> > + struct dirent *ent;
> > +
> > + while ((ent = readdir(dir))) {
> > + snprintf(path, path_len, "/sys/block/%s/%s/stat", ent->d_name, devname);
> > +
> > + fprintf(stderr, "%s\n", path);
> > +
> It will make many noise when using .all_filesystem and we can remove it.
> Other than, it looks good to me.
That's forgotten debug print, I should have removed that before sending.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 5+ messages in thread
* [LTP] [PATCH] tst_device: Scan /sys/block/* for stat file
2020-01-09 14:08 ` Cyril Hrubis
@ 2020-01-15 10:39 ` Petr Vorel
2020-01-15 13:17 ` Cyril Hrubis
0 siblings, 1 reply; 5+ messages in thread
From: Petr Vorel @ 2020-01-15 10:39 UTC (permalink / raw)
To: ltp
Hi,
...
> > > +int find_stat_file(const char *dev, char *path, size_t path_len)
> > > +{
> > > + const char *devname = strrchr(dev, '/') + 1;
> > > +
> > > + snprintf(path, path_len, "/sys/block/%s/stat", devname);
> > > +
> > > + if (!access(path, F_OK))
> > > + return 1;
> > > +
> > > + DIR *dir = SAFE_OPENDIR(NULL, "/sys/block/");
> > > + struct dirent *ent;
> > > +
> > > + while ((ent = readdir(dir))) {
> > > + snprintf(path, path_len, "/sys/block/%s/%s/stat", ent->d_name, devname);
> > > +
> > > + fprintf(stderr, "%s\n", path);
> > > +
> > It will make many noise when using .all_filesystem and we can remove it.
> > Other than, it looks good to me.
> That's forgotten debug print, I should have removed that before sending.
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Kind regards,
Petr
^ permalink raw reply [flat|nested] 5+ messages in thread
* [LTP] [PATCH] tst_device: Scan /sys/block/* for stat file
2020-01-15 10:39 ` Petr Vorel
@ 2020-01-15 13:17 ` Cyril Hrubis
0 siblings, 0 replies; 5+ messages in thread
From: Cyril Hrubis @ 2020-01-15 13:17 UTC (permalink / raw)
To: ltp
Hi!
> > That's forgotten debug print, I should have removed that before sending.
>
> Reviewed-by: Petr Vorel <pvorel@suse.cz>
Pushed with the forgotten debug print removed.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-01-15 13:17 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-08 13:48 [LTP] [PATCH] tst_device: Scan /sys/block/* for stat file Cyril Hrubis
2020-01-09 9:03 ` Yang Xu
2020-01-09 14:08 ` Cyril Hrubis
2020-01-15 10:39 ` Petr Vorel
2020-01-15 13:17 ` Cyril Hrubis
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.