[Ocfs2-tools-commits] mfasheh commits r731 - trunk/extras

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Mon Mar 21 20:27:10 CST 2005


Author: mfasheh
Signed-off-by: zab
Date: 2005-03-21 20:27:08 -0600 (Mon, 21 Mar 2005)
New Revision: 731

Added:
   trunk/extras/decode_lockres.c
Modified:
   trunk/extras/Makefile
Log:
* throw in a little utility i've been using for decoding lockres names
  for a while now.

Signed-off-by: zab



Modified: trunk/extras/Makefile
===================================================================
--- trunk/extras/Makefile	2005-03-22 02:04:39 UTC (rev 730)
+++ trunk/extras/Makefile	2005-03-22 02:27:08 UTC (rev 731)
@@ -11,7 +11,7 @@
 
 CFLAGS = $(OPTS) $(WARNINGS) 
 
-UNINST_PROGRAMS = find_hardlinks find_dup_extents find_inode_paths set_random_bits
+UNINST_PROGRAMS = find_hardlinks find_dup_extents find_inode_paths set_random_bits decode_lockres
 
 INCLUDES = -I../libocfs2/include -I$(TOPDIR)/libo2dlm/include -I$(TOPDIR)/libo2cb/include
 
@@ -25,6 +25,7 @@
 FIND_DUP_EXTENTS_CFILES = find_dup_extents.c
 FIND_INODE_PATHS_CFILES = find_inode_paths.c
 SET_RANDOM_BITS_CFILES = set_random_bits.c
+DECODE_LOCKRES_CFILES = decode_lockres.c
 
 DIST_FILES = $(FIND_HARDLINKS_CFILES) $(FIND_DUP_EXTENTS_CFILES) $(FIND_INODE_PATHS_CFILES) $(SET_RANDOM_BITS_CFILES)
 
@@ -32,6 +33,7 @@
 FIND_DUP_EXTENTS_OBJS = $(subst .c,.o,$(FIND_DUP_EXTENTS_CFILES))
 FIND_INODE_PATHS_OBJS = $(subst .c,.o,$(FIND_INODE_PATHS_CFILES))
 SET_RANDOM_BITS_OBJS  = $(subst .c,.o,$(SET_RANDOM_BITS_CFILES))
+DECODE_LOCKRES_OBJS  = $(subst .c,.o,$(DECODE_LOCKRES_CFILES))
 LIBOCFS2 = ../libocfs2/libocfs2.a
 LIBS = $(LIBOCFS2) $(COM_ERR_LIBS)
 
@@ -47,4 +49,7 @@
 set_random_bits: $(SET_RANDOM_BITS_OBJS) $(LIBS)
 	$(LINK) 
 
+decode_lockres: $(DECODE_LOCKRES_OBJS) $(LIBS)
+	$(LINK) 
+
 include $(TOPDIR)/Postamble.make

Added: trunk/extras/decode_lockres.c
===================================================================
--- trunk/extras/decode_lockres.c	2005-03-22 02:04:39 UTC (rev 730)
+++ trunk/extras/decode_lockres.c	2005-03-22 02:27:08 UTC (rev 731)
@@ -0,0 +1,139 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * decode_lockres.c
+ *
+ * Tells you all the information about an ocfs2 lockres available
+ * based on it's name. Very useful for debugging dlm issues.
+ *
+ * Copyright (C) 2004 Oracle.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License, version 2,  as published by the Free Software Foundation.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ *
+ * Authors: Mark Fasheh
+ */
+
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+
+/* Begin paste from kernel module */
+enum ocfs2_lock_type {
+	OCFS_TYPE_META = 0,
+	OCFS_TYPE_DATA,
+	OCFS_TYPE_SUPER,
+	OCFS_NUM_LOCK_TYPES
+};
+
+/* lock ids are made up in the following manner:
+ * name[0]     --> type
+ * name[1-6]   --> 6 pad characters, reserved for now
+ * name[7-22]  --> block number, expressed in hex as 16 chars
+ * name[23-30] --> i_generation, expressed in hex 8 chars
+ * name[31]    --> '\0' */
+#define OCFS2_LOCK_ID_MAX_LEN  32
+#define OCFS2_LOCK_ID_PAD "000000"
+
+static char ocfs2_lock_type_char[OCFS_NUM_LOCK_TYPES] = {
+	[OCFS_TYPE_META]	'M',
+	[OCFS_TYPE_DATA] 	'D',
+	[OCFS_TYPE_SUPER]       'S'
+};
+/* End paste from kernel module */
+
+static char * ocfs2_lock_type_string[OCFS_NUM_LOCK_TYPES] = {
+	[OCFS_TYPE_META]	"Metadata",
+	[OCFS_TYPE_DATA] 	"Data",
+	[OCFS_TYPE_SUPER]       "Superblock"
+};
+
+static void usage(char *program)
+{
+	printf("%s LOCKRES\n", program);
+	printf("prints out information based on the lockres name\n");
+}
+
+static const char *get_lock_type_string(char c)
+{
+	enum ocfs2_lock_type t;
+
+	if (c == ocfs2_lock_type_char[OCFS_TYPE_META])
+		t = OCFS_TYPE_META;
+	else if (c == ocfs2_lock_type_char[OCFS_TYPE_DATA])
+		t = OCFS_TYPE_DATA;
+	else if (c == ocfs2_lock_type_char[OCFS_TYPE_SUPER])
+		t = OCFS_TYPE_SUPER;
+	else
+		return NULL;
+
+	return ocfs2_lock_type_string[t];
+}
+
+static int decode_one_lockres(const char *lockres)
+{
+	const char *type;
+	int i;
+	unsigned long long blkno;
+	unsigned int generation;
+	char blkstr[17];
+
+	if ((strlen(lockres) + 1) != OCFS2_LOCK_ID_MAX_LEN) {
+		fprintf(stderr, "Invalid lockres id \"%s\"\n", lockres);
+		return 1;
+	}
+
+	type = get_lock_type_string(lockres[0]);
+	if (!type) {
+		fprintf(stderr, "Invalid lockres type, '%c'\n", lockres[0]);
+		return 1;
+	}
+
+	printf("Lockres:    %s\n", lockres);
+	printf("Type:       %s\n", type);
+
+	i = 1 + strlen(OCFS2_LOCK_ID_PAD);
+	memset(blkstr, 0, 17);
+	memcpy(blkstr, &lockres[i], 16);
+	blkno = strtoull(blkstr, NULL, 16);
+	printf("Block:      %llu\n", blkno);
+
+	i+= 16;
+	generation = strtoul(&lockres[i], NULL, 16);
+	printf("Generation: 0x%08x\n", generation);
+
+	printf("\n");
+
+	return 0;
+}
+
+int main(int argc, char **argv)
+{
+	int i, status = 0;
+
+	if (argc < 2) {
+		usage(argv[0]);
+		return 0;
+	}
+
+	for(i = 1; i < argc; i++) {
+		status = decode_one_lockres(argv[i]);
+		if (status)
+			break;
+	}
+
+	return status;
+}



More information about the Ocfs2-tools-commits mailing list