[Ocfs2-tools-devel] [PATCH] libo2cb, debugfs: Handle sysfs attributes living in /sys/fs/o2cb

Joel Becker joel.becker at oracle.com
Tue Jan 29 14:08:14 PST 2008


When the interface_revision and logmask attributes moved from procfs to
sysfs, /sys/fs did not exist.  They were placed under /sys/o2cb as a
best alternative.  These days, /sys/fs does exist, and the kernel
community would like the attributes to live at /sys/fs/o2cb.

Going forward, tools searches /sys/fs/o2cb first, then /sys/o2cb, and
finally the old /proc location.  The kernel will move to /sys/fs/o2cb,
but will provide the old /sys/o2cb location for compatibility.

Signed-off-by: Joel Becker <joel.becker at oracle.com>
---
 debugfs.ocfs2/main.c |   26 +++++++++++++++-----------
 libo2cb/o2cb_abi.c   |    9 ++++++---
 2 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/debugfs.ocfs2/main.c b/debugfs.ocfs2/main.c
index 30846fe..ecd7f70 100644
--- a/debugfs.ocfs2/main.c
+++ b/debugfs.ocfs2/main.c
@@ -321,14 +321,15 @@ static int set_logmode_proc(struct log_entry *entry)
 	return 0;
 }
 
-#define LOG_CTL_SYSFS_DIR "/sys/o2cb/logmask"
-#define LOG_CTL_SYSFS_FORMAT LOG_CTL_SYSFS_DIR "/%s"
-static int set_logmode_sysfs(struct log_entry *entry)
+#define LOG_CTL_SYSFS_DIR_OLD "/sys/o2cb/logmask"
+#define LOG_CTL_SYSFS_DIR "/sys/fs/o2cb/logmask"
+#define LOG_CTL_SYSFS_FORMAT "%s/%s"
+static int set_logmode_sysfs(const char *path, struct log_entry *entry)
 {
 	FILE *f;
 	char *logpath;
 
-	logpath = g_strdup_printf(LOG_CTL_SYSFS_FORMAT, entry->mask);
+	logpath = g_strdup_printf(LOG_CTL_SYSFS_FORMAT, path, entry->mask);
 	f = fopen(logpath, "w");
 	g_free(logpath);
 	if (!f) {
@@ -343,12 +344,12 @@ static int set_logmode_sysfs(struct log_entry *entry)
 	return 0;
 }
 
-static int get_logmode_sysfs(const char *name)
+static int get_logmode_sysfs(const char *path, const char *name)
 {
 	char *logpath;
 	char *current_mask;
 
-	logpath = g_strdup_printf(LOG_CTL_SYSFS_FORMAT, name);
+	logpath = g_strdup_printf(LOG_CTL_SYSFS_FORMAT, path, name);
 	if (g_file_get_contents(logpath, &current_mask,
 				NULL, NULL)) {
 		fprintf(stdout, "%s %s", name, current_mask);
@@ -378,7 +379,7 @@ static void run_logmode_proc(void)
 	}
 }
 
-static void run_logmode_sysfs(void)
+static void run_logmode_sysfs(const char *path)
 {
 	GList *tmp;
 	DIR *dir;
@@ -387,15 +388,15 @@ static void run_logmode_sysfs(void)
 	if (loglist) {
 		tmp = loglist;
 		while (tmp) {
-			if (set_logmode_sysfs(tmp->data))
+			if (set_logmode_sysfs(path, tmp->data))
 				break;
 			tmp = tmp->next;
 		}
 	} else {
-		dir = opendir(LOG_CTL_SYSFS_DIR);
+		dir = opendir(path);
 		if (dir) {
 			while ((d = readdir(dir)) != NULL)
-				get_logmode_sysfs(d->d_name);
+				get_logmode_sysfs(path, d->d_name);
 			closedir(dir);
 		}
 	}
@@ -407,7 +408,10 @@ static void run_logmode(void)
 
 	if (!stat(LOG_CTL_SYSFS_DIR, &stat_buf) &&
 	    S_ISDIR(stat_buf.st_mode))
-		run_logmode_sysfs();
+		run_logmode_sysfs(LOG_CTL_SYSFS_DIR);
+        else if (!stat(LOG_CTL_SYSFS_DIR_OLD, &stat_buf) &&
+	    S_ISDIR(stat_buf.st_mode))
+		run_logmode_sysfs(LOG_CTL_SYSFS_DIR_OLD);
 	else if (!stat(LOG_CTL_PROC, &stat_buf) &&
 		 S_ISREG(stat_buf.st_mode))
 		run_logmode_proc();
diff --git a/libo2cb/o2cb_abi.c b/libo2cb/o2cb_abi.c
index 7cf2efa..7ac89e6 100644
--- a/libo2cb/o2cb_abi.c
+++ b/libo2cb/o2cb_abi.c
@@ -483,8 +483,9 @@ static errcode_t init_configfs(void)
 	return O2CB_ET_SERVICE_UNAVAILABLE;
 }
 
-#define O2CB_INTERFACE_REVISION_PATH_OLD	"/proc/fs/ocfs2_nodemanager/interface_revision"
-#define O2CB_INTERFACE_REVISION_PATH		"/sys/o2cb/interface_revision"
+#define O2CB_INTERFACE_REVISION_PATH_OLD_PROC	"/proc/fs/ocfs2_nodemanager/interface_revision"
+#define O2CB_INTERFACE_REVISION_PATH_OLD_SYS	"/sys/o2cb/interface_revision"
+#define O2CB_INTERFACE_REVISION_PATH		"/sys/fs/o2cb/interface_revision"
 errcode_t o2cb_init(void)
 {
 	int ret, fd;
@@ -494,7 +495,9 @@ errcode_t o2cb_init(void)
 
 	err = try_file(O2CB_INTERFACE_REVISION_PATH, &fd);
 	if (err == O2CB_ET_SERVICE_UNAVAILABLE)
-		err = try_file(O2CB_INTERFACE_REVISION_PATH_OLD, &fd);
+		err = try_file(O2CB_INTERFACE_REVISION_PATH_OLD_SYS, &fd);
+	if (err == O2CB_ET_SERVICE_UNAVAILABLE)
+		err = try_file(O2CB_INTERFACE_REVISION_PATH_OLD_PROC, &fd);
 	if (err)
 		return err;
 
-- 
1.5.3.8




More information about the Ocfs2-tools-devel mailing list