All of lore.kernel.org
 help / color / mirror / Atom feed
From: rpeterso@sourceware.org <rpeterso@sourceware.org>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] cluster/gfs2/tool gfs2_tool.h misc.c util.c
Date: 7 Nov 2007 14:58:00 -0000	[thread overview]
Message-ID: <20071107145800.16039.qmail@sourceware.org> (raw)

CVSROOT:	/cvs/cluster
Module name:	cluster
Changes by:	rpeterso at sourceware.org	2007-11-07 14:58:00

Modified files:
	gfs2/tool      : gfs2_tool.h misc.c util.c 

Log message:
	Resolves: bz 352581: GFS2: implement gfs2_tool lockdump

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/tool/gfs2_tool.h.diff?cvsroot=cluster&r1=1.8&r2=1.9
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/tool/misc.c.diff?cvsroot=cluster&r1=1.11&r2=1.12
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/tool/util.c.diff?cvsroot=cluster&r1=1.7&r2=1.8

--- cluster/gfs2/tool/gfs2_tool.h	2007/10/30 14:06:06	1.8
+++ cluster/gfs2/tool/gfs2_tool.h	2007/11/07 14:57:59	1.9
@@ -95,7 +95,7 @@
 
 char *get_list(void);
 char **str2lines(char *str);
-const char *find_debugfs_mount(void);
+char *find_debugfs_mount(void);
 char *mp2fsname(char *mp);
 char *name2value(char *str, char *name);
 uint32_t name2u32(char *str, char *name);
--- cluster/gfs2/tool/misc.c	2007/10/30 14:06:06	1.11
+++ cluster/gfs2/tool/misc.c	2007/11/07 14:57:59	1.12
@@ -28,6 +28,7 @@
 
 #define __user
 #include <linux/gfs2_ondisk.h>
+#include <sys/mount.h>
 #include <linux/fs.h>
 
 #include "libgfs2.h"
@@ -110,7 +111,67 @@
 void
 print_lockdump(int argc, char **argv)
 {
-	die("lockdump not implemented: use debugfs instead.  \ne.g. cat /sys/kernel/debug/gfs2/clustname\\:fsname/glocks\n");
+	char path[PATH_MAX];
+	char *name, line[PATH_MAX];
+	char *debugfs;
+	FILE *file;
+	int rc = -1, debug_dir_existed = 1;
+
+	/* See if debugfs is mounted, and if not, mount it. */
+	debugfs = find_debugfs_mount();
+	if (!debugfs) {
+		debugfs = malloc(20);
+		if (!debugfs)
+			die("Can't allocate memory for debugfs.\n");
+		memset(debugfs, 0, 20);
+		strcpy(debugfs, "/tmp/debugfs");
+
+		if (access(debugfs, F_OK)) {
+			debug_dir_existed = mkdir(debugfs, 644);
+			if (debug_dir_existed) {
+				fprintf(stderr,
+					"Can't create %s mount point.\n",
+					debugfs);
+				free(debugfs);
+				exit(-1);
+			}
+		}
+		rc = mount("none", debugfs, "debugfs", 0, NULL);
+		if (rc) {
+			fprintf(stderr,
+				"Can't mount debugfs.  "
+				"Maybe your kernel doesn't support it.\n");
+				free(debugfs);
+				exit(-1);
+		}
+	}
+	name = mp2fsname(argv[optind]);
+	if (name) {
+		sprintf(path, "%s/gfs2/%s/glocks", debugfs, name);
+		free(name);
+		file = fopen(path, "rt");
+		if (file) {
+			while (fgets(line, PATH_MAX, file)) {
+				printf(line);
+			}
+			fclose(file);
+		} else {
+			fprintf(stderr, "Can't open %s: %s\n", path,
+				strerror(errno));
+		}
+	} else {
+		fprintf(stderr, "Unable to locate sysfs for mount point %s.\n",
+			argv[optind]);
+	}
+	/* Check if we mounted the debugfs and if so, unmount it. */
+	if (!rc) {
+		umount(debugfs);
+		/* Check if we created the debugfs mount point and if so,
+		   delete it. */
+		if (!debug_dir_existed)
+			rmdir(debugfs);
+	}
+	free(debugfs);
 }
 
 /**
--- cluster/gfs2/tool/util.c	2007/11/06 20:22:55	1.7
+++ cluster/gfs2/tool/util.c	2007/11/07 14:57:59	1.8
@@ -283,6 +283,36 @@
 	return name;
 }
 
+char *
+find_debugfs_mount(void)
+{
+	FILE *file;
+	char line[PATH_MAX];
+	char device[PATH_MAX], type[PATH_MAX];
+	char *path;
+
+	file = fopen("/proc/mounts", "rt");
+	if (!file)
+		die("can't open /proc/mounts: %s\n", strerror(errno));
+
+	path = malloc(PATH_MAX);
+	if (!path)
+		die("Can't allocate memory for debugfs.\n");
+	while (fgets(line, PATH_MAX, file)) {
+
+		if (sscanf(line, "%s %s %s", device, path, type) != 3)
+			continue;
+		if (!strcmp(type, "debugfs")) {
+			fclose(file);
+			return path;
+		}
+	}
+
+	free(path);
+	fclose(file);
+	return NULL;
+}
+
 /* The fsname can be substituted for the mountpoint on the command line.
    This is necessary when we can't resolve a devname from /proc/mounts
    to a fsname. */



             reply	other threads:[~2007-11-07 14:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-07 14:58 rpeterso [this message]
  -- strict thread matches above, loose matches on Subject: below --
2007-11-07 14:59 [Cluster-devel] cluster/gfs2/tool gfs2_tool.h misc.c util.c rpeterso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20071107145800.16039.qmail@sourceware.org \
    --to=rpeterso@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.