Skip to contentSkip to conversation

debugfs.ocfs2: Allow dumping dlm locks from a file

PATCH New Mark Fasheh 3 participants 4 messages Dec 5, 2008 – Dec 26, 2008 OCFS2

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 debugfs.ocfs2: Allow dumping dlm locks from a file

This way we can review locking state even if all a customer provides us is the contents of /sys/kernel/debug/o2dlm/locking_state.

---
 debugfs.ocfs2/commands.c               |   36 ++++++++++++++++++++++-------
 debugfs.ocfs2/dump_dlm_locks.c         |   38 ++++++++++++++++++++-----------
 debugfs.ocfs2/include/dump_dlm_locks.h |    2 +-
 3 files changed, 52 insertions(+), 24 deletions(-)
debugfs.ocfs2/commands.c +27 -9
index 0e46151..06b6c98 100644
@@ -831,7 +831,7 @@ static void do_help (char **args)
 	printf ("controld dump\t\t\tObtain information from ocfs2_controld\n");
 	printf ("curdev\t\t\t\t\tShow current device\n");
 	printf ("decode <lockname#> ...\t\t\tDecode block#(s) from the lockname(s)\n");
-	printf ("dlm_locks [-l] lockname\t\t\tShow live dlm locking state\n");
+	printf ("dlm_locks [-f <file>] [-l] lockname\t\t\tShow live dlm locking state\n");
 	printf ("dump [-p] <filespec> <outfile>\t\tDumps file to outfile on a mounted fs\n");
 	printf ("encode <filespec>\t\t\tShow lock name\n");
 	printf ("extent <block#>\t\t\t\tShow extent block\n");
@@ -1485,26 +1485,44 @@ static void do_dlm_locks(char **args)
 	int dump_lvbs = 0;
 	int i;
 	struct list_head locklist;
-
-	if (check_device_open())
-		return;
+	char *path = NULL, *uuid_str = NULL;
+	int c, argc;
 
 	init_stringlist(&locklist);
 
-	i = 1;
-	if (args[i] && strlen(args[i])) {
-		if (!strcmp("-l", args[i])) {
+	for (argc = 0; (args[argc]); ++argc);
+	optind = 0;
+
+	while ((c = getopt(argc, args, "lf:")) != -1) {
+		switch (c) {
+		case 'l':
 			dump_lvbs = 1;
-			i++;
+			break;
+		case 'f':
+			path = optarg;
+			break;
+		default:
+			break;
 		}
+	}
+	if ((path == NULL)) {
+		/* Only error for a missing device if we're asked to
+		 * read from a live file system. */
+		if (check_device_open())
+			return;
+
+		uuid_str = gbls.fs->uuid_str;
+	}
 
+	i = optind;
+	if (args[i] && strlen(args[i])) {
 		for ( ; args[i] && strlen(args[i]); ++i)
 			if (add_to_stringlist(args[i], &locklist))
 				break;
 	}
 
 	out = open_pager(gbls.interactive);
-	dump_dlm_locks(gbls.fs->uuid_str, out, dump_lvbs, &locklist);
+	dump_dlm_locks(uuid_str, out, path, dump_lvbs, &locklist);
 	close_pager(out);
 
 	free_stringlist(&locklist);
debugfs.ocfs2/dump_dlm_locks.c +24 -14
index b946821..6344ff1 100644
@@ -411,7 +411,7 @@ static int get_next_dlm_lockname(FILE *file, char *name, int len)
 	return 0;
 }
 
-void dump_dlm_locks(char *uuid, FILE *out, int dump_lvbs,
+void dump_dlm_locks(char *uuid, FILE *out, char *path, int dump_lvbs,
 		    struct list_head *locklist)
 {
 	errcode_t ret;
@@ -421,20 +421,30 @@ void dump_dlm_locks(char *uuid, FILE *out, int dump_lvbs,
 	struct lockres res;
 	int show_all_locks = 0;
 
-	ret = get_debugfs_path(debugfs_path, sizeof(debugfs_path));
-	if (ret) {
-		fprintf(stderr, "Could not locate debugfs file system. "
-			"Perhaps it is not mounted?\n");
-		return;
-	}
+	if (path == NULL) {
+		ret = get_debugfs_path(debugfs_path, sizeof(debugfs_path));
+		if (ret) {
+			fprintf(stderr, "Could not locate debugfs file system. "
+				"Perhaps it is not mounted?\n");
+			return;
+		}
 
-	ret = open_debugfs_file(debugfs_path, "o2dlm", uuid, "locking_state",
-				&file);
-	if (ret) {
-		fprintf(stderr, "Could not open debug state for \"%s\".\n"
-			"Perhaps that OCFS2 file system is not mounted?\n",
-			uuid);
-		return;
+		ret = open_debugfs_file(debugfs_path, "o2dlm", uuid,
+					"locking_state", &file);
+		if (ret) {
+			fprintf(stderr,
+				"Could not open debug state for \"%s\".\n"
+				"Perhaps that OCFS2 file system is not mounted?\n",
+				uuid);
+			return;
+		}
+	} else {
+		file = fopen(path, "r");
+		if (!file) {
+			fprintf(stderr, "Could not open file at \"%s\"\n",
+				path);
+			return;
+		}
 	}
 
 	show_all_locks = list_empty(locklist);
debugfs.ocfs2/include/dump_dlm_locks.h +1 -1
index 2cbb72a..7bc35ba 100644
@@ -74,7 +74,7 @@ struct lock {
 	struct list_head list;
 };
 
-void dump_dlm_locks(char *uuid, FILE *out, int dump_lvbs,
+void dump_dlm_locks(char *uuid, FILE *out, char *path, int dump_lvbs,
 		    struct list_head *locklist);
 
 #endif		/* _DUMP_DLM_LOCKS_H_ */
Signature · 1 line
1.6.0.2
#1 lore raw

PATCH 1/1 debugfs.ocfs2: Allow dumping dlm locks from a file

Quoted 146 lines · Mark Fasheh

This way we can review locking state even if all a customer provides us is the contents of /sys/kernel/debug/o2dlm/locking_state.

---
 debugfs.ocfs2/commands.c               |   36 ++++++++++++++++++++++-------
 debugfs.ocfs2/dump_dlm_locks.c         |   38 ++++++++++++++++++++-----------
 debugfs.ocfs2/include/dump_dlm_locks.h |    2 +-
 3 files changed, 52 insertions(+), 24 deletions(-)
debugfs.ocfs2/commands.c +27 -9
index 0e46151..06b6c98 100644
@@ -831,7 +831,7 @@ static void do_help (char **args)
 	printf ("controld dump\t\t\tObtain information from ocfs2_controld\n");
 	printf ("curdev\t\t\t\t\tShow current device\n");
 	printf ("decode <lockname#> ...\t\t\tDecode block#(s) from the lockname(s)\n");
-	printf ("dlm_locks [-l] lockname\t\t\tShow live dlm locking state\n");
+	printf ("dlm_locks [-f <file>] [-l] lockname\t\t\tShow live dlm locking state\n");
 	printf ("dump [-p] <filespec> <outfile>\t\tDumps file to outfile on a mounted fs\n");
 	printf ("encode <filespec>\t\t\tShow lock name\n");
 	printf ("extent <block#>\t\t\t\tShow extent block\n");
@@ -1485,26 +1485,44 @@ static void do_dlm_locks(char **args)
 	int dump_lvbs = 0;
 	int i;
 	struct list_head locklist;
-
-	if (check_device_open())
-		return;
+	char *path = NULL, *uuid_str = NULL;
+	int c, argc;
 
 	init_stringlist(&locklist);
 
-	i = 1;
-	if (args[i] && strlen(args[i])) {
-		if (!strcmp("-l", args[i])) {
+	for (argc = 0; (args[argc]); ++argc);
+	optind = 0;
+
+	while ((c = getopt(argc, args, "lf:")) != -1) {
+		switch (c) {
+		case 'l':
 			dump_lvbs = 1;
-			i++;
+			break;
+		case 'f':
+			path = optarg;
+			break;
+		default:
+			break;
 		}
+	}
+	if ((path == NULL)) {
+		/* Only error for a missing device if we're asked to
+		 * read from a live file system. */
+		if (check_device_open())
+			return;
+
+		uuid_str = gbls.fs->uuid_str;
+	}
 
+	i = optind;
+	if (args[i] && strlen(args[i])) {
 		for ( ; args[i] && strlen(args[i]); ++i)
 			if (add_to_stringlist(args[i], &locklist))
 				break;
 	}
 
 	out = open_pager(gbls.interactive);
-	dump_dlm_locks(gbls.fs->uuid_str, out, dump_lvbs, &locklist);
+	dump_dlm_locks(uuid_str, out, path, dump_lvbs, &locklist);
 	close_pager(out);
 
 	free_stringlist(&locklist);
debugfs.ocfs2/dump_dlm_locks.c +24 -14
index b946821..6344ff1 100644
@@ -411,7 +411,7 @@ static int get_next_dlm_lockname(FILE *file, char *name, int len)
 	return 0;
 }
 
-void dump_dlm_locks(char *uuid, FILE *out, int dump_lvbs,
+void dump_dlm_locks(char *uuid, FILE *out, char *path, int dump_lvbs,
 		    struct list_head *locklist)
 {
 	errcode_t ret;
@@ -421,20 +421,30 @@ void dump_dlm_locks(char *uuid, FILE *out, int dump_lvbs,
 	struct lockres res;
 	int show_all_locks = 0;
 
-	ret = get_debugfs_path(debugfs_path, sizeof(debugfs_path));
-	if (ret) {
-		fprintf(stderr, "Could not locate debugfs file system. "
-			"Perhaps it is not mounted?\n");
-		return;
-	}
+	if (path == NULL) {
+		ret = get_debugfs_path(debugfs_path, sizeof(debugfs_path));
+		if (ret) {
+			fprintf(stderr, "Could not locate debugfs file system. "
+				"Perhaps it is not mounted?\n");
+			return;
+		}
 
-	ret = open_debugfs_file(debugfs_path, "o2dlm", uuid, "locking_state",
-				&file);
-	if (ret) {
-		fprintf(stderr, "Could not open debug state for \"%s\".\n"
-			"Perhaps that OCFS2 file system is not mounted?\n",
-			uuid);
-		return;
+		ret = open_debugfs_file(debugfs_path, "o2dlm", uuid,
+					"locking_state", &file);
+		if (ret) {
+			fprintf(stderr,
+				"Could not open debug state for \"%s\".\n"
+				"Perhaps that OCFS2 file system is not mounted?\n",
+				uuid);
+			return;
+		}
+	} else {
+		file = fopen(path, "r");
+		if (!file) {
+			fprintf(stderr, "Could not open file at \"%s\"\n",
+				path);
+			return;
+		}
 	}
 
 	show_all_locks = list_empty(locklist);
debugfs.ocfs2/include/dump_dlm_locks.h +1 -1
index 2cbb72a..7bc35ba 100644
@@ -74,7 +74,7 @@ struct lock {
 	struct list_head list;
 };
 
-void dump_dlm_locks(char *uuid, FILE *out, int dump_lvbs,
+void dump_dlm_locks(char *uuid, FILE *out, char *path, int dump_lvbs,
 		    struct list_head *locklist);
 
 #endif		/* _DUMP_DLM_LOCKS_H_ */
#2 lore raw

PATCH 1/1 debugfs.ocfs2: Allow dumping dlm locks from a file

In reply to Mark Fasheh

Anyone get a chance to sob this? It's pretty much a copy of the fs locks patch...

	--Mark
Quoted 154 lines · Mark Fasheh

This way we can review locking state even if all a customer provides us is the contents of /sys/kernel/debug/o2dlm/locking_state.

---
 debugfs.ocfs2/commands.c               |   36 ++++++++++++++++++++++-------
 debugfs.ocfs2/dump_dlm_locks.c         |   38 ++++++++++++++++++++-----------
 debugfs.ocfs2/include/dump_dlm_locks.h |    2 +-
 3 files changed, 52 insertions(+), 24 deletions(-)
debugfs.ocfs2/commands.c +27 -9
index 0e46151..06b6c98 100644
@@ -831,7 +831,7 @@ static void do_help (char **args)
 	printf ("controld dump\t\t\tObtain information from ocfs2_controld\n");
 	printf ("curdev\t\t\t\t\tShow current device\n");
 	printf ("decode <lockname#> ...\t\t\tDecode block#(s) from the lockname(s)\n");
-	printf ("dlm_locks [-l] lockname\t\t\tShow live dlm locking state\n");
+	printf ("dlm_locks [-f <file>] [-l] lockname\t\t\tShow live dlm locking state\n");
 	printf ("dump [-p] <filespec> <outfile>\t\tDumps file to outfile on a mounted fs\n");
 	printf ("encode <filespec>\t\t\tShow lock name\n");
 	printf ("extent <block#>\t\t\t\tShow extent block\n");
@@ -1485,26 +1485,44 @@ static void do_dlm_locks(char **args)
 	int dump_lvbs = 0;
 	int i;
 	struct list_head locklist;
-
-	if (check_device_open())
-		return;
+	char *path = NULL, *uuid_str = NULL;
+	int c, argc;
 
 	init_stringlist(&locklist);
 
-	i = 1;
-	if (args[i] && strlen(args[i])) {
-		if (!strcmp("-l", args[i])) {
+	for (argc = 0; (args[argc]); ++argc);
+	optind = 0;
+
+	while ((c = getopt(argc, args, "lf:")) != -1) {
+		switch (c) {
+		case 'l':
 			dump_lvbs = 1;
-			i++;
+			break;
+		case 'f':
+			path = optarg;
+			break;
+		default:
+			break;
 		}
+	}
+	if ((path == NULL)) {
+		/* Only error for a missing device if we're asked to
+		 * read from a live file system. */
+		if (check_device_open())
+			return;
+
+		uuid_str = gbls.fs->uuid_str;
+	}
 
+	i = optind;
+	if (args[i] && strlen(args[i])) {
 		for ( ; args[i] && strlen(args[i]); ++i)
 			if (add_to_stringlist(args[i], &locklist))
 				break;
 	}
 
 	out = open_pager(gbls.interactive);
-	dump_dlm_locks(gbls.fs->uuid_str, out, dump_lvbs, &locklist);
+	dump_dlm_locks(uuid_str, out, path, dump_lvbs, &locklist);
 	close_pager(out);
 
 	free_stringlist(&locklist);
debugfs.ocfs2/dump_dlm_locks.c +24 -14
index b946821..6344ff1 100644
@@ -411,7 +411,7 @@ static int get_next_dlm_lockname(FILE *file, char *name, int len)
 	return 0;
 }
 
-void dump_dlm_locks(char *uuid, FILE *out, int dump_lvbs,
+void dump_dlm_locks(char *uuid, FILE *out, char *path, int dump_lvbs,
 		    struct list_head *locklist)
 {
 	errcode_t ret;
@@ -421,20 +421,30 @@ void dump_dlm_locks(char *uuid, FILE *out, int dump_lvbs,
 	struct lockres res;
 	int show_all_locks = 0;
 
-	ret = get_debugfs_path(debugfs_path, sizeof(debugfs_path));
-	if (ret) {
-		fprintf(stderr, "Could not locate debugfs file system. "
-			"Perhaps it is not mounted?\n");
-		return;
-	}
+	if (path == NULL) {
+		ret = get_debugfs_path(debugfs_path, sizeof(debugfs_path));
+		if (ret) {
+			fprintf(stderr, "Could not locate debugfs file system. "
+				"Perhaps it is not mounted?\n");
+			return;
+		}
 
-	ret = open_debugfs_file(debugfs_path, "o2dlm", uuid, "locking_state",
-				&file);
-	if (ret) {
-		fprintf(stderr, "Could not open debug state for \"%s\".\n"
-			"Perhaps that OCFS2 file system is not mounted?\n",
-			uuid);
-		return;
+		ret = open_debugfs_file(debugfs_path, "o2dlm", uuid,
+					"locking_state", &file);
+		if (ret) {
+			fprintf(stderr,
+				"Could not open debug state for \"%s\".\n"
+				"Perhaps that OCFS2 file system is not mounted?\n",
+				uuid);
+			return;
+		}
+	} else {
+		file = fopen(path, "r");
+		if (!file) {
+			fprintf(stderr, "Could not open file at \"%s\"\n",
+				path);
+			return;
+		}
 	}
 
 	show_all_locks = list_empty(locklist);
debugfs.ocfs2/include/dump_dlm_locks.h +1 -1
index 2cbb72a..7bc35ba 100644
@@ -74,7 +74,7 @@ struct lock {
 	struct list_head list;
 };
 
-void dump_dlm_locks(char *uuid, FILE *out, int dump_lvbs,
+void dump_dlm_locks(char *uuid, FILE *out, char *path, int dump_lvbs,
 		    struct list_head *locklist);
 
 #endif		/* _DUMP_DLM_LOCKS_H_ */
Signature · 7 lines
1.6.0.2


_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel at oss.oracle.com
http://oss.oracle.com/mailman/listinfo/ocfs2-devel

--
Mark Fasheh

#3 lore raw

PATCH 1/1 debugfs.ocfs2: Allow dumping dlm locks from a file

I thought Tao had sob-ed it.

Quoted 182 lines · Mark Fasheh

Anyone get a chance to sob this? It's pretty much a copy of the fs locks
patch...
--Mark

Quoted 160 lines · Mark Fasheh

This way we can review locking state even if all a customer provides us is
the contents of /sys/kernel/debug/o2dlm/locking_state.

---
debugfs.ocfs2/commands.c | 36 +++++++++++++++++++++

+-------
debugfs.ocfs2/dump_dlm_locks.c         |   38 +++++++++++++++++++ 
+-----------
debugfs.ocfs2/include/dump_dlm_locks.h |    2 +-
3 files changed, 52 insertions(+), 24 deletions(-)
debugfs.ocfs2/commands.c +1 -1
index 0e46151..06b6c98 100644
@@ -831,7 +831,7 @@ static void do_help (char **args)
   printf ("controld dump\t\t\tObtain information from  
 ocfs2_controld\n");
   printf ("curdev\t\t\t\t\tShow current device\n");
   printf ("decode <lockname#> ...\t\t\tDecode block#(s) from the  
 lockname(s)\n");
-    printf ("dlm_locks [-l] lockname\t\t\tShow live dlm locking  
 state\n");
+    printf ("dlm_locks [-f <file>] [-l] lockname\t\t\tShow live  

dlm locking state\n");
printf ("dump [-p] <filespec> <outfile>\t\tDumps file to outfile

on a mounted fs\n");
   printf ("encode <filespec>\t\t\tShow lock name\n");
   printf ("extent <block#>\t\t\t\tShow extent block\n");
debugfs.ocfs2/commands.c +26 -8
@@ -1485,26 +1485,44 @@ static void do_dlm_locks(char **args)
   int dump_lvbs = 0;
   int i;
   struct list_head locklist;
-
-    if (check_device_open())
-        return;
+    char *path = NULL, *uuid_str = NULL;
+    int c, argc;
 
   init_stringlist(&locklist);
 
-    i = 1;
-    if (args[i] && strlen(args[i])) {
-        if (!strcmp("-l", args[i])) {
+    for (argc = 0; (args[argc]); ++argc);
+    optind = 0;
+
+    while ((c = getopt(argc, args, "lf:")) != -1) {
+        switch (c) {
+        case 'l':
           dump_lvbs = 1;
-            i++;
+            break;
+        case 'f':
+            path = optarg;
+            break;
+        default:
+            break;
       }
+    }
+    if ((path == NULL)) {
+        /* Only error for a missing device if we're asked to
+         * read from a live file system. */
+        if (check_device_open())
+            return;
+
+        uuid_str = gbls.fs->uuid_str;
+    }
 
+    i = optind;
+    if (args[i] && strlen(args[i])) {
       for ( ; args[i] && strlen(args[i]); ++i)
           if (add_to_stringlist(args[i], &locklist))
               break;
   }
 
   out = open_pager(gbls.interactive);
-    dump_dlm_locks(gbls.fs->uuid_str, out, dump_lvbs, &locklist);
+    dump_dlm_locks(uuid_str, out, path, dump_lvbs, &locklist);
   close_pager(out);
 
   free_stringlist(&locklist);
debugfs.ocfs2/ renamed from debugfs.ocfs2/dump_dlm_locks.c +0 -0

dump_dlm_locks.c
index b946821..6344ff1 100644

debugfs.ocfs2/dump_dlm_locks.c +1 -1
@@ -411,7 +411,7 @@ static int get_next_dlm_lockname(FILE *file,  
 char *name, int len)
   return 0;
 }
 
-void dump_dlm_locks(char *uuid, FILE *out, int dump_lvbs,
+void dump_dlm_locks(char *uuid, FILE *out, char *path, int  
 dump_lvbs,
           struct list_head *locklist)
{
   errcode_t ret;
debugfs.ocfs2/dump_dlm_locks.c +23 -13
@@ -421,20 +421,30 @@ void dump_dlm_locks(char *uuid, FILE *out,  
 int dump_lvbs,
   struct lockres res;
   int show_all_locks = 0;
 
-    ret = get_debugfs_path(debugfs_path, sizeof(debugfs_path));
-    if (ret) {
-        fprintf(stderr, "Could not locate debugfs file system. "
-            "Perhaps it is not mounted?\n");
-        return;
-    }
+    if (path == NULL) {
+        ret = get_debugfs_path(debugfs_path, sizeof(debugfs_path));
+        if (ret) {
+            fprintf(stderr, "Could not locate debugfs file system. "
+                "Perhaps it is not mounted?\n");
+            return;
+        }
 
-    ret = open_debugfs_file(debugfs_path, "o2dlm", uuid,  
 "locking_state",
-                &file);
-    if (ret) {
-        fprintf(stderr, "Could not open debug state for \"%s\".\n"
-            "Perhaps that OCFS2 file system is not mounted?\n",
-            uuid);
-        return;
+        ret = open_debugfs_file(debugfs_path, "o2dlm", uuid,
+                    "locking_state", &file);
+        if (ret) {
+            fprintf(stderr,
+                "Could not open debug state for \"%s\".\n"
+                "Perhaps that OCFS2 file system is not mounted?\n",
+                uuid);
+            return;
+        }
+    } else {
+        file = fopen(path, "r");
+        if (!file) {
+            fprintf(stderr, "Could not open file at \"%s\"\n",
+                path);
+            return;
+        }
   }
   show_all_locks = list_empty(locklist);
debugfs.ocfs2/ renamed from debugfs.ocfs2/include/dump_dlm_locks.h +0 -0

include/dump_dlm_locks.h
index 2cbb72a..7bc35ba 100644

debugfs.ocfs2/include/dump_dlm_locks.h +1 -1
@@ -74,7 +74,7 @@ struct lock {
   struct list_head list;
 };
 
-void dump_dlm_locks(char *uuid, FILE *out, int dump_lvbs,
+void dump_dlm_locks(char *uuid, FILE *out, char *path, int  
 dump_lvbs,
           struct list_head *locklist);
 
Quoted 9 lines

#endif /* _DUMP_DLM_LOCKS_H_ */

Signature · 7 lines
1.6.0.2


_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel at oss.oracle.com
http://oss.oracle.com/mailman/listinfo/ocfs2-devel

--
Mark Fasheh

_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel at oss.oracle.com
http://oss.oracle.com/mailman/listinfo/ocfs2-devel