CVSROOT: /cvs/cluster Module name: cluster Branch: RHEL5 Changes by: [EMAIL PROTECTED] 2007-11-07 14:59:28
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&only_with_tag=RHEL5&r1=1.5.2.3&r2=1.5.2.4 http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/tool/misc.c.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.8.2.3&r2=1.8.2.4 http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/tool/util.c.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.5.2.2&r2=1.5.2.3 --- cluster/gfs2/tool/gfs2_tool.h 2007/10/30 14:08:33 1.5.2.3 +++ cluster/gfs2/tool/gfs2_tool.h 2007/11/07 14:59:28 1.5.2.4 @@ -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:08:33 1.8.2.3 +++ cluster/gfs2/tool/misc.c 2007/11/07 14:59:28 1.8.2.4 @@ -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:23:59 1.5.2.2 +++ cluster/gfs2/tool/util.c 2007/11/07 14:59:28 1.5.2.3 @@ -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. */