[Intel-gfx] [igt RFC 1/3] lib/debugfs: Make is_mountpoint() non-fatal
Ville Syrjälä
ville.syrjala at linux.intel.com
Fri Oct 13 12:33:58 UTC 2017
On Fri, Oct 13, 2017 at 01:02:57PM +0100, Chris Wilson wrote:
> is_mountpoint() asserts rather than report the error. Normally this
> isn't a problem, except for atypical selftests.
>
> Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
Reviewed-by: Ville Syrjälä <ville.syrjala at linux.intel.com>
> ---
> lib/igt_debugfs.c | 33 ++++++++++++++++++++-------------
> 1 file changed, 20 insertions(+), 13 deletions(-)
>
> diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
> index 60b29e3a..2bdcdee1 100644
> --- a/lib/igt_debugfs.c
> +++ b/lib/igt_debugfs.c
> @@ -88,18 +88,26 @@
> static bool is_mountpoint(const char *path)
> {
> char buf[strlen(path) + 4];
> - dev_t dot_dev, dotdot_dev;
> struct stat st;
> + dev_t dev;
>
> igt_assert_lt(snprintf(buf, sizeof(buf), "%s/.", path), sizeof(buf));
> - igt_assert_eq(stat(buf, &st), 0);
> - dot_dev = st.st_dev;
> + if (stat(buf, &st))
> + return false;
> +
> + if (!S_ISDIR(st.st_mode))
> + return false;
> +
> + dev = st.st_dev;
>
> igt_assert_lt(snprintf(buf, sizeof(buf), "%s/..", path), sizeof(buf));
> - igt_assert_eq(stat(buf, &st), 0);
> - dotdot_dev = st.st_dev;
> + if (stat(buf, &st))
> + return false;
> +
> + if (!S_ISDIR(st.st_mode))
> + return false;
>
> - return dot_dev != dotdot_dev;
> + return dev != st.st_dev;
> }
>
> /**
> @@ -113,16 +121,14 @@ static bool is_mountpoint(const char *path)
> */
> const char *igt_debugfs_mount(void)
> {
> - struct stat st;
> + if (is_mountpoint("/sys/kernel/debug"))
> + return "/sys/kernel/debug";
>
> - if (stat("/debug/dri", &st) == 0)
> + if (is_mountpoint("/debug"))
> return "/debug";
>
> - if (stat("/sys/kernel/debug/dri", &st) == 0)
> - return "/sys/kernel/debug";
> -
> - igt_assert(is_mountpoint("/sys/kernel/debug") ||
> - mount("debug", "/sys/kernel/debug", "debugfs", 0, 0) == 0);
> + if (mount("debug", "/sys/kernel/debug", "debugfs", 0, 0))
> + return NULL;
>
> return "/sys/kernel/debug";
> }
> @@ -155,6 +161,7 @@ char *igt_debugfs_path(int device, char *path, int pathlen)
> }
>
> debugfs_root = igt_debugfs_mount();
> + igt_assert(debugfs_root);
>
> idx = minor(st.st_rdev);
> snprintf(path, pathlen, "%s/dri/%d/name", debugfs_root, idx);
> --
> 2.15.0.rc0
>
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gfx
--
Ville Syrjälä
Intel OTC
More information about the Intel-gfx
mailing list