* [PATCH] perf tests: Handle properly readdir DT_UNKNOWN
@ 2017-12-06 17:45 Jiri Olsa
2017-12-07 15:19 ` Arnaldo Carvalho de Melo
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Jiri Olsa @ 2017-12-06 17:45 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Peter Zijlstra,
Michael Petlan
Some system can return DT_UNKNOWN in readdir's struct dirent::d_type
and we must handle it properly. In this case we can directly check
if the entity we found is directory and skip it.
Making is_directory function global.
Reported-by: Michael Petlan <mpetlan@redhat.com>
Link: http://lkml.kernel.org/n/tip-hgwpktyrx657m1i255da46p0@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
tools/perf/builtin-script.c | 14 +-------------
tools/perf/tests/builtin-test.c | 10 +++++-----
tools/perf/util/path.c | 13 +++++++++++++
tools/perf/util/path.h | 4 ++++
4 files changed, 23 insertions(+), 18 deletions(-)
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 39d8b55f0db3..a5c1361ccf26 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -26,6 +26,7 @@
#include "util/string2.h"
#include "util/thread-stack.h"
#include "util/time-utils.h"
+#include "util/path.h"
#include "print_binary.h"
#include <linux/bitmap.h>
#include <linux/kernel.h>
@@ -2399,19 +2400,6 @@ static int parse_output_fields(const struct option *opt __maybe_unused,
return rc;
}
-/* Helper function for filesystems that return a dent->d_type DT_UNKNOWN */
-static int is_directory(const char *base_path, const struct dirent *dent)
-{
- char path[PATH_MAX];
- struct stat st;
-
- sprintf(path, "%s/%s", base_path, dent->d_name);
- if (stat(path, &st))
- return 0;
-
- return S_ISDIR(st.st_mode);
-}
-
#define for_each_lang(scripts_path, scripts_dir, lang_dirent) \
while ((lang_dirent = readdir(scripts_dir)) != NULL) \
if ((lang_dirent->d_type == DT_DIR || \
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 766573e236e4..fafa014240cd 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -411,9 +411,9 @@ static const char *shell_test__description(char *description, size_t size,
return description ? trim(description + 1) : NULL;
}
-#define for_each_shell_test(dir, ent) \
+#define for_each_shell_test(dir, base, ent) \
while ((ent = readdir(dir)) != NULL) \
- if (ent->d_type == DT_REG && ent->d_name[0] != '.')
+ if (!is_directory(base, ent))
static const char *shell_tests__dir(char *path, size_t size)
{
@@ -452,7 +452,7 @@ static int shell_tests__max_desc_width(void)
if (!dir)
return -1;
- for_each_shell_test(dir, ent) {
+ for_each_shell_test(dir, path, ent) {
char bf[256];
const char *desc = shell_test__description(bf, sizeof(bf), path, ent->d_name);
@@ -504,7 +504,7 @@ static int run_shell_tests(int argc, const char *argv[], int i, int width)
if (!dir)
return -1;
- for_each_shell_test(dir, ent) {
+ for_each_shell_test(dir, st.dir, ent) {
int curr = i++;
char desc[256];
struct test test = {
@@ -614,7 +614,7 @@ static int perf_test__list_shell(int argc, const char **argv, int i)
if (!dir)
return -1;
- for_each_shell_test(dir, ent) {
+ for_each_shell_test(dir, path, ent) {
int curr = i++;
char bf[256];
struct test t = {
diff --git a/tools/perf/util/path.c b/tools/perf/util/path.c
index 933f5c6bffb4..ab1be320f3ef 100644
--- a/tools/perf/util/path.c
+++ b/tools/perf/util/path.c
@@ -77,3 +77,16 @@ bool is_regular_file(const char *file)
return S_ISREG(st.st_mode);
}
+
+/* Helper function for filesystems that return a dent->d_type DT_UNKNOWN */
+bool is_directory(const char *base_path, const struct dirent *dent)
+{
+ char path[PATH_MAX];
+ struct stat st;
+
+ sprintf(path, "%s/%s", base_path, dent->d_name);
+ if (stat(path, &st))
+ return false;
+
+ return S_ISDIR(st.st_mode);
+}
diff --git a/tools/perf/util/path.h b/tools/perf/util/path.h
index 14a254ada7eb..f0f3a6bedc57 100644
--- a/tools/perf/util/path.h
+++ b/tools/perf/util/path.h
@@ -2,9 +2,13 @@
#ifndef _PERF_PATH_H
#define _PERF_PATH_H
+#include <sys/types.h>
+#include <dirent.h>
+
int path__join(char *bf, size_t size, const char *path1, const char *path2);
int path__join3(char *bf, size_t size, const char *path1, const char *path2, const char *path3);
bool is_regular_file(const char *file);
+bool is_directory(const char *base_path, const struct dirent *dent);
#endif /* _PERF_PATH_H */
--
2.13.6
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] perf tests: Handle properly readdir DT_UNKNOWN
2017-12-06 17:45 [PATCH] perf tests: Handle properly readdir DT_UNKNOWN Jiri Olsa
@ 2017-12-07 15:19 ` Arnaldo Carvalho de Melo
2017-12-08 11:55 ` Jiri Olsa
2017-12-28 15:26 ` [tip:perf/core] perf utils: Move is_directory() to path.h tip-bot for Jiri Olsa
2017-12-28 15:27 ` [tip:perf/core] perf test: Handle properly readdir DT_UNKNOWN tip-bot for Jiri Olsa
2 siblings, 1 reply; 5+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-12-07 15:19 UTC (permalink / raw)
To: Jiri Olsa
Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Peter Zijlstra,
Michael Petlan
Em Wed, Dec 06, 2017 at 06:45:35PM +0100, Jiri Olsa escreveu:
> Some system can return DT_UNKNOWN in readdir's struct dirent::d_type
> and we must handle it properly. In this case we can directly check
> if the entity we found is directory and skip it.
> Making is_directory function global.
Split this part into a prep patch and left with the previous paragraph
the 'perf test' bits.
[acme@jouet perf]$ git log --oneline -2
de7cee586145 (HEAD -> perf/core, acme.korg/perf/core) perf test: Handle properly readdir DT_UNKNOWN
ef87e1133606 perf utils: Move is_directory() to path.h
[acme@jouet perf]$
Thanks,
- Arnaldo
> Reported-by: Michael Petlan <mpetlan@redhat.com>
> Link: http://lkml.kernel.org/n/tip-hgwpktyrx657m1i255da46p0@git.kernel.org
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
> tools/perf/builtin-script.c | 14 +-------------
> tools/perf/tests/builtin-test.c | 10 +++++-----
> tools/perf/util/path.c | 13 +++++++++++++
> tools/perf/util/path.h | 4 ++++
> 4 files changed, 23 insertions(+), 18 deletions(-)
>
> diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
> index 39d8b55f0db3..a5c1361ccf26 100644
> --- a/tools/perf/builtin-script.c
> +++ b/tools/perf/builtin-script.c
> @@ -26,6 +26,7 @@
> #include "util/string2.h"
> #include "util/thread-stack.h"
> #include "util/time-utils.h"
> +#include "util/path.h"
> #include "print_binary.h"
> #include <linux/bitmap.h>
> #include <linux/kernel.h>
> @@ -2399,19 +2400,6 @@ static int parse_output_fields(const struct option *opt __maybe_unused,
> return rc;
> }
>
> -/* Helper function for filesystems that return a dent->d_type DT_UNKNOWN */
> -static int is_directory(const char *base_path, const struct dirent *dent)
> -{
> - char path[PATH_MAX];
> - struct stat st;
> -
> - sprintf(path, "%s/%s", base_path, dent->d_name);
> - if (stat(path, &st))
> - return 0;
> -
> - return S_ISDIR(st.st_mode);
> -}
> -
> #define for_each_lang(scripts_path, scripts_dir, lang_dirent) \
> while ((lang_dirent = readdir(scripts_dir)) != NULL) \
> if ((lang_dirent->d_type == DT_DIR || \
> diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
> index 766573e236e4..fafa014240cd 100644
> --- a/tools/perf/tests/builtin-test.c
> +++ b/tools/perf/tests/builtin-test.c
> @@ -411,9 +411,9 @@ static const char *shell_test__description(char *description, size_t size,
> return description ? trim(description + 1) : NULL;
> }
>
> -#define for_each_shell_test(dir, ent) \
> +#define for_each_shell_test(dir, base, ent) \
> while ((ent = readdir(dir)) != NULL) \
> - if (ent->d_type == DT_REG && ent->d_name[0] != '.')
> + if (!is_directory(base, ent))
>
> static const char *shell_tests__dir(char *path, size_t size)
> {
> @@ -452,7 +452,7 @@ static int shell_tests__max_desc_width(void)
> if (!dir)
> return -1;
>
> - for_each_shell_test(dir, ent) {
> + for_each_shell_test(dir, path, ent) {
> char bf[256];
> const char *desc = shell_test__description(bf, sizeof(bf), path, ent->d_name);
>
> @@ -504,7 +504,7 @@ static int run_shell_tests(int argc, const char *argv[], int i, int width)
> if (!dir)
> return -1;
>
> - for_each_shell_test(dir, ent) {
> + for_each_shell_test(dir, st.dir, ent) {
> int curr = i++;
> char desc[256];
> struct test test = {
> @@ -614,7 +614,7 @@ static int perf_test__list_shell(int argc, const char **argv, int i)
> if (!dir)
> return -1;
>
> - for_each_shell_test(dir, ent) {
> + for_each_shell_test(dir, path, ent) {
> int curr = i++;
> char bf[256];
> struct test t = {
> diff --git a/tools/perf/util/path.c b/tools/perf/util/path.c
> index 933f5c6bffb4..ab1be320f3ef 100644
> --- a/tools/perf/util/path.c
> +++ b/tools/perf/util/path.c
> @@ -77,3 +77,16 @@ bool is_regular_file(const char *file)
>
> return S_ISREG(st.st_mode);
> }
> +
> +/* Helper function for filesystems that return a dent->d_type DT_UNKNOWN */
> +bool is_directory(const char *base_path, const struct dirent *dent)
> +{
> + char path[PATH_MAX];
> + struct stat st;
> +
> + sprintf(path, "%s/%s", base_path, dent->d_name);
> + if (stat(path, &st))
> + return false;
> +
> + return S_ISDIR(st.st_mode);
> +}
> diff --git a/tools/perf/util/path.h b/tools/perf/util/path.h
> index 14a254ada7eb..f0f3a6bedc57 100644
> --- a/tools/perf/util/path.h
> +++ b/tools/perf/util/path.h
> @@ -2,9 +2,13 @@
> #ifndef _PERF_PATH_H
> #define _PERF_PATH_H
>
> +#include <sys/types.h>
> +#include <dirent.h>
> +
> int path__join(char *bf, size_t size, const char *path1, const char *path2);
> int path__join3(char *bf, size_t size, const char *path1, const char *path2, const char *path3);
>
> bool is_regular_file(const char *file);
> +bool is_directory(const char *base_path, const struct dirent *dent);
>
> #endif /* _PERF_PATH_H */
> --
> 2.13.6
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] perf tests: Handle properly readdir DT_UNKNOWN
2017-12-07 15:19 ` Arnaldo Carvalho de Melo
@ 2017-12-08 11:55 ` Jiri Olsa
0 siblings, 0 replies; 5+ messages in thread
From: Jiri Olsa @ 2017-12-08 11:55 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Jiri Olsa, lkml, Ingo Molnar, Namhyung Kim, David Ahern,
Peter Zijlstra, Michael Petlan
On Thu, Dec 07, 2017 at 12:19:05PM -0300, Arnaldo Carvalho de Melo wrote:
> Em Wed, Dec 06, 2017 at 06:45:35PM +0100, Jiri Olsa escreveu:
> > Some system can return DT_UNKNOWN in readdir's struct dirent::d_type
> > and we must handle it properly. In this case we can directly check
> > if the entity we found is directory and skip it.
>
> > Making is_directory function global.
>
> Split this part into a prep patch and left with the previous paragraph
> the 'perf test' bits.
>
> [acme@jouet perf]$ git log --oneline -2
> de7cee586145 (HEAD -> perf/core, acme.korg/perf/core) perf test: Handle properly readdir DT_UNKNOWN
> ef87e1133606 perf utils: Move is_directory() to path.h
> [acme@jouet perf]$
thanks,
jirka
^ permalink raw reply [flat|nested] 5+ messages in thread
* [tip:perf/core] perf utils: Move is_directory() to path.h
2017-12-06 17:45 [PATCH] perf tests: Handle properly readdir DT_UNKNOWN Jiri Olsa
2017-12-07 15:19 ` Arnaldo Carvalho de Melo
@ 2017-12-28 15:26 ` tip-bot for Jiri Olsa
2017-12-28 15:27 ` [tip:perf/core] perf test: Handle properly readdir DT_UNKNOWN tip-bot for Jiri Olsa
2 siblings, 0 replies; 5+ messages in thread
From: tip-bot for Jiri Olsa @ 2017-12-28 15:26 UTC (permalink / raw)
To: linux-tip-commits
Cc: dsahern, mpetlan, peterz, acme, linux-kernel, namhyung, tglx,
mingo, jolsa, hpa
Commit-ID: 06c3f2aa9fc68e7f3fe3d83e7569d2a2801d9f99
Gitweb: https://git.kernel.org/tip/06c3f2aa9fc68e7f3fe3d83e7569d2a2801d9f99
Author: Jiri Olsa <jolsa@kernel.org>
AuthorDate: Wed, 6 Dec 2017 18:45:35 +0100
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 27 Dec 2017 12:15:48 -0300
perf utils: Move is_directory() to path.h
So that it can be used more widely, like in the next patch, when it will
be used to fix a bug in 'perf test' handling of dirent.d_type ==
DT_UNKNOWN.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20171206174535.25380-1-jolsa@kernel.org
[ Split from a larger patch, removed needless includes in path.h ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/builtin-script.c | 14 +-------------
tools/perf/util/path.c | 14 ++++++++++++++
tools/perf/util/path.h | 3 +++
3 files changed, 18 insertions(+), 13 deletions(-)
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index fac6f05..77e47cf 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -26,6 +26,7 @@
#include "util/string2.h"
#include "util/thread-stack.h"
#include "util/time-utils.h"
+#include "util/path.h"
#include "print_binary.h"
#include <linux/bitmap.h>
#include <linux/kernel.h>
@@ -2401,19 +2402,6 @@ out:
return rc;
}
-/* Helper function for filesystems that return a dent->d_type DT_UNKNOWN */
-static int is_directory(const char *base_path, const struct dirent *dent)
-{
- char path[PATH_MAX];
- struct stat st;
-
- sprintf(path, "%s/%s", base_path, dent->d_name);
- if (stat(path, &st))
- return 0;
-
- return S_ISDIR(st.st_mode);
-}
-
#define for_each_lang(scripts_path, scripts_dir, lang_dirent) \
while ((lang_dirent = readdir(scripts_dir)) != NULL) \
if ((lang_dirent->d_type == DT_DIR || \
diff --git a/tools/perf/util/path.c b/tools/perf/util/path.c
index 933f5c6..ca56ba2 100644
--- a/tools/perf/util/path.c
+++ b/tools/perf/util/path.c
@@ -18,6 +18,7 @@
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <dirent.h>
#include <unistd.h>
static char bad_path[] = "/bad-path/";
@@ -77,3 +78,16 @@ bool is_regular_file(const char *file)
return S_ISREG(st.st_mode);
}
+
+/* Helper function for filesystems that return a dent->d_type DT_UNKNOWN */
+bool is_directory(const char *base_path, const struct dirent *dent)
+{
+ char path[PATH_MAX];
+ struct stat st;
+
+ sprintf(path, "%s/%s", base_path, dent->d_name);
+ if (stat(path, &st))
+ return false;
+
+ return S_ISDIR(st.st_mode);
+}
diff --git a/tools/perf/util/path.h b/tools/perf/util/path.h
index 14a254a..f014f90 100644
--- a/tools/perf/util/path.h
+++ b/tools/perf/util/path.h
@@ -2,9 +2,12 @@
#ifndef _PERF_PATH_H
#define _PERF_PATH_H
+struct dirent;
+
int path__join(char *bf, size_t size, const char *path1, const char *path2);
int path__join3(char *bf, size_t size, const char *path1, const char *path2, const char *path3);
bool is_regular_file(const char *file);
+bool is_directory(const char *base_path, const struct dirent *dent);
#endif /* _PERF_PATH_H */
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [tip:perf/core] perf test: Handle properly readdir DT_UNKNOWN
2017-12-06 17:45 [PATCH] perf tests: Handle properly readdir DT_UNKNOWN Jiri Olsa
2017-12-07 15:19 ` Arnaldo Carvalho de Melo
2017-12-28 15:26 ` [tip:perf/core] perf utils: Move is_directory() to path.h tip-bot for Jiri Olsa
@ 2017-12-28 15:27 ` tip-bot for Jiri Olsa
2 siblings, 0 replies; 5+ messages in thread
From: tip-bot for Jiri Olsa @ 2017-12-28 15:27 UTC (permalink / raw)
To: linux-tip-commits
Cc: namhyung, jolsa, tglx, peterz, mingo, hpa, acme, linux-kernel,
mpetlan, dsahern
Commit-ID: 378811ac303df13efbe49f3ad1795b63d334ac5d
Gitweb: https://git.kernel.org/tip/378811ac303df13efbe49f3ad1795b63d334ac5d
Author: Jiri Olsa <jolsa@kernel.org>
AuthorDate: Wed, 6 Dec 2017 18:45:35 +0100
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 27 Dec 2017 12:15:48 -0300
perf test: Handle properly readdir DT_UNKNOWN
Some system can return DT_UNKNOWN in readdir's struct dirent::d_type and
we must handle it properly. In this case we can directly check if the
entity we found is directory and skip it.
Reported-by: Michael Petlan <mpetlan@redhat.com>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20171206174535.25380-1-jolsa@kernel.org
[ Split from a larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/tests/builtin-test.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 766573e..fafa014 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -411,9 +411,9 @@ static const char *shell_test__description(char *description, size_t size,
return description ? trim(description + 1) : NULL;
}
-#define for_each_shell_test(dir, ent) \
+#define for_each_shell_test(dir, base, ent) \
while ((ent = readdir(dir)) != NULL) \
- if (ent->d_type == DT_REG && ent->d_name[0] != '.')
+ if (!is_directory(base, ent))
static const char *shell_tests__dir(char *path, size_t size)
{
@@ -452,7 +452,7 @@ static int shell_tests__max_desc_width(void)
if (!dir)
return -1;
- for_each_shell_test(dir, ent) {
+ for_each_shell_test(dir, path, ent) {
char bf[256];
const char *desc = shell_test__description(bf, sizeof(bf), path, ent->d_name);
@@ -504,7 +504,7 @@ static int run_shell_tests(int argc, const char *argv[], int i, int width)
if (!dir)
return -1;
- for_each_shell_test(dir, ent) {
+ for_each_shell_test(dir, st.dir, ent) {
int curr = i++;
char desc[256];
struct test test = {
@@ -614,7 +614,7 @@ static int perf_test__list_shell(int argc, const char **argv, int i)
if (!dir)
return -1;
- for_each_shell_test(dir, ent) {
+ for_each_shell_test(dir, path, ent) {
int curr = i++;
char bf[256];
struct test t = {
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-12-28 15:30 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-06 17:45 [PATCH] perf tests: Handle properly readdir DT_UNKNOWN Jiri Olsa
2017-12-07 15:19 ` Arnaldo Carvalho de Melo
2017-12-08 11:55 ` Jiri Olsa
2017-12-28 15:26 ` [tip:perf/core] perf utils: Move is_directory() to path.h tip-bot for Jiri Olsa
2017-12-28 15:27 ` [tip:perf/core] perf test: Handle properly readdir DT_UNKNOWN tip-bot for Jiri Olsa
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.