[Intel-gfx] [PATCH i-g-t 3/4] lib/debugfs: Check if debufs is already mounted before attempting to mount it

ville.syrjala at linux.intel.com ville.syrjala at linux.intel.com
Thu Dec 15 15:24:59 UTC 2016


From: Ville Syrjälä <ville.syrjala at linux.intel.com>

mount("/sys/kernel/debug") will return an error if something is already
mounted there. So let's check for that before calling mount(). This
allows many of the tools (eg. intel_reg) to work even when no drm
drivers are loaded since the earlier "/sys/kernel/debug/dri" & co.
path checks will fail in that case and we will fall back to attempting
to mount debugfs ourselves.

Signed-off-by: Ville Syrjälä <ville.syrjala at linux.intel.com>
---
 lib/igt_debugfs.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
index 3d92c6a10a41..5b3167581054 100644
--- a/lib/igt_debugfs.c
+++ b/lib/igt_debugfs.c
@@ -89,6 +89,22 @@ typedef struct {
 	char dri_path[128];
 } igt_debugfs_t;
 
+static bool is_mountpoint(const char *path)
+{
+	char buf[strlen(path) + 4];
+	dev_t dot_dev, dotdot_dev;
+	struct stat st;
+
+	igt_assert_lt(snprintf(buf, sizeof(buf), "%s/.", path), sizeof(buf));
+	igt_assert_eq(stat(buf, &st), 0);
+	dot_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;
+
+	return dot_dev != dotdot_dev;
+}
 
 /**
  * igt_debugfs_mount:
@@ -109,8 +125,9 @@ const char *igt_debugfs_mount(void)
 	if (stat("/sys/kernel/debug/dri", &st) == 0)
 		return "/sys/kernel/debug";
 
-	igt_assert(stat("/sys/kernel/debug", &st) == 0);
-	igt_assert(mount("debug", "/sys/kernel/debug", "debugfs", 0, 0) == 0);
+	igt_assert(is_mountpoint("/sys/kernel/debug") ||
+		   mount("debug", "/sys/kernel/debug", "debugfs", 0, 0) == 0);
+
 	return "/sys/kernel/debug";
 }
 
-- 
2.10.2



More information about the Intel-gfx mailing list