This is the mail archive of the cluster-cvs@sourceware.org mailing list for the cluster.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

STABLE2 - dlm: Make dlm_tcpdump compile for RHEL5 too


Gitweb:        http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=32036c520e81aa0c51079e6726cca588be3bfa33
Commit:        32036c520e81aa0c51079e6726cca588be3bfa33
Parent:        f6c27d970d7e9e9588aa3818f27b93510e1e376d
Author:        Christine Caulfield <ccaulfie@redhat.com>
AuthorDate:    Fri Oct 10 13:50:16 2008 +0100
Committer:     Christine Caulfield <ccaulfie@redhat.com>
CommitterDate: Fri Oct 10 13:50:16 2008 +0100

dlm: Make dlm_tcpdump compile for RHEL5 too

This is a conditional compilation. The RHEL5 code is
untested as yet

Signed-off-by: Christine Caulfield <ccaulfie@redhat.com>
---
 dlm/tests/tcpdump/Makefile      |    2 +-
 dlm/tests/tcpdump/dlm_tcpdump.c |  142 ++++++++++++++++++++++++++-------------
 2 files changed, 96 insertions(+), 48 deletions(-)

diff --git a/dlm/tests/tcpdump/Makefile b/dlm/tests/tcpdump/Makefile
index 6ad2d32..f572e3b 100644
--- a/dlm/tests/tcpdump/Makefile
+++ b/dlm/tests/tcpdump/Makefile
@@ -4,7 +4,7 @@ SBINDIRT=$(TARGET)
 
 all: ${TARGET}
 
-include ../../make/defines.mk
+include ../../../make/defines.mk
 include $(OBJDIR)/make/cobj.mk
 include $(OBJDIR)/make/clean.mk
 include $(OBJDIR)/make/install.mk
diff --git a/dlm/tests/tcpdump/dlm_tcpdump.c b/dlm/tests/tcpdump/dlm_tcpdump.c
index a4f3d7e..a88302c 100644
--- a/dlm/tests/tcpdump/dlm_tcpdump.c
+++ b/dlm/tests/tcpdump/dlm_tcpdump.c
@@ -7,9 +7,12 @@
 *
 * v0.2   Show unlock and lock held times
 * v0.3   Show conversions and all locks in one packet
+* v0.4   Add RHEL5 support(untested)
 *
 **********************************************************************/
 
+#define RHEL4
+
 #include <pcap.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -22,44 +25,89 @@
 #include <arpa/inet.h>
 #include <netinet/if_ether.h>
 
-
 static char *dlm_filter = "port 21064";
 
-// Takeen from dlm_internal.h
+#ifdef RHEL4
 #define DLM_LVB_LEN            (32)
-struct dlm_header {
-	uint32_t		rh_version;
-	uint8_t			rh_cmd;		/* What we are */
-	uint8_t			rh_flags;	/* maybe just a pad */
-	uint16_t		rh_length;	/* Length of struct (so we can
+
+struct dlm_message {
+	uint32_t		m_version;
+	uint8_t			m_cmd;		/* What we are */
+	uint8_t			m_flags;	/* maybe just a pad */
+	uint16_t		m_length;	/* Length of struct (so we can
 						   send many in 1 message) */
-	uint32_t		rh_lkid;	/* Lock ID tag: ie the local
+	uint32_t		m_lkid;     	/* Lock ID tag: ie the local
 						   (requesting) lock ID */
-	uint32_t		rh_lockspace;	/* Lockspace ID */
-} __attribute__((packed));
-
-struct dlm_request {
-	struct dlm_header	rr_header;
-	uint32_t		rr_remlkid;	/* Remote lock ID */
-	uint32_t		rr_remparid;	/* Parent's remote lock ID */
-	uint32_t		rr_flags;	/* Flags from lock/convert req*/
-	uint64_t		rr_range_start; /* Yes, these are in the right
+	uint32_t		m_lockspace;	/* Lockspace ID */
+	uint32_t		m_remlkid;	/* Remote lock ID */
+	uint32_t		m_remparid;	/* Parent's remote lock ID */
+	uint32_t		m_lflags;	/* Flags from lock/convert req*/
+	uint64_t		m_range_start; /* Yes, these are in the right
 						   place... */
-	uint64_t		rr_range_end;
-	uint32_t		rr_status;	/* Status to return if this is
+	uint64_t		m_range_end;
+	uint32_t		m_status;	/* Status to return if this is
 						   an AST request */
-        uint32_t                rr_pid;         /* Owner PID of lock */
-	uint32_t		rr_lvbseq;
-	uint8_t			rr_rqmode;	/* Requested lock mode */
-	uint8_t			rr_asts;	/* Whether the LKB has ASTs */
-	char			rr_lvb[DLM_LVB_LEN];
-	char			rr_name[1];	/* As long as needs be. Only
+        uint32_t                m_pid;         /* Owner PID of lock */
+	uint32_t		m_lvbseq;
+	uint8_t			m_rqmode;	/* Requested lock mode */
+	uint8_t			m_asts;	/* Whether the LKB has ASTs */
+	char			m_lvb[DLM_LVB_LEN];
+	char			m_name[1];	/* As long as needs be. Only
 						   used for directory lookups.
 						   The length of this can be
 						   worked out from the packet
 						   length */
 } __attribute__((packed));
 
+#define DLM_MSG_LOCK     2
+#define DLM_MSG_UNLOCK   3
+#define DLM_MSG_CONVERT  4
+
+#define DLM_VERSION      0x00010001
+
+#endif
+
+#ifdef RHEL5
+
+struct dlm_message {
+	uint32_t		m_version;
+	uint32_t		m_lockspace;
+	uint32_t		m_nodeid;	/* nodeid of sender */
+	uint16_t		m_length;
+	uint8_t			m_cmd;		/* DLM_MSG, DLM_RCOM */
+	uint8_t			m_pad;
+	uint32_t		m_type;		/* DLM_MSG_ */
+	uint32_t		m_rnodeid;
+	uint32_t		m_pid;
+	uint32_t		m_lkid;		/* lkid on sender */
+	uint32_t		m_remid;	/* lkid on receiver */
+	uint32_t		m_parent_lkid;
+	uint32_t		m_parent_remid;
+	uint32_t		m_exflags;
+	uint32_t		m_sbflags;
+	uint32_t		m_flags;
+	uint32_t		m_lvbseq;
+	uint32_t		m_hash;
+	int			m_status;
+	int			m_grmode;
+	int			m_rqmode;
+	int			m_bastmode;
+	int			m_asts;
+	int			m_result;	/* 0 or -EXXX */
+	char			m_name[0];	/* name or lvb */
+};
+
+#define DLM_MSG_LOCK     1
+#define DLM_MSG_UNLOCK   3
+#define DLM_MSG_CONVERT  2
+
+#define DLM_VERSION      0x00030000
+
+#endif
+
+#ifndef DLM_MSG_LOCK
+#error You must build for RHEL4 or RHEL5
+#endif
 
 /* Struct for a lock */
 struct saved_lock
@@ -125,7 +173,7 @@ void finish_up(int sig)
 void my_callback(u_char *useless,const struct pcap_pkthdr* pkthdr,
 		 const u_char* packet)
 {
-	struct dlm_request *req;
+	struct dlm_message *req;
 	char lockname[65];
 	int namelen;
 	unsigned int lock_type;
@@ -138,42 +186,42 @@ void my_callback(u_char *useless,const struct pcap_pkthdr* pkthdr,
 
 	packets++;
 	while (offset < pkthdr->caplen) {
-		req = (struct dlm_request *)((char *)packet+offset);
+		req = (struct dlm_message *)((char *)packet+offset);
 
 		/* Non-dlm packet */
-		if (req->rr_header.rh_version != 0x00010001) {
+		if (req->m_version != DLM_VERSION) {
 			nondlm++;
 			return;
 		}
 
-		if (req->rr_header.rh_cmd == 2 ||   // lockrequest
-		    req->rr_header.rh_cmd == 4) {   // convrequest
+		if (req->m_cmd == DLM_MSG_LOCK ||
+		    req->m_cmd == DLM_MSG_CONVERT) {
 			locks++;
 
-			if (!req->rr_pid)
+			if (!req->m_pid)
 				cmd[0] = '\0';
-			if (req->rr_pid && last_pid != req->rr_pid) {
+			if (req->m_pid && last_pid != req->m_pid) {
 				char name[1024];
 				FILE *f;
-				sprintf(name, "/proc/%d/cmdline", req->rr_pid);
+				sprintf(name, "/proc/%d/cmdline", req->m_pid);
 				f = fopen(name, "r");
 				if (f) {
 					fgets(cmd, sizeof(cmd), f);
 					fclose(f);
 				}
-				last_pid = req->rr_pid;
+				last_pid = req->m_pid;
 			}
 
 
-			namelen = req->rr_header.rh_length - sizeof(*req) + 1;
-			memcpy(lockname, req->rr_name, namelen);
+			namelen = req->m_length - sizeof(*req) + 1;
+			memcpy(lockname, req->m_name, namelen);
 			lockname[namelen] = 0;
 			lockname[8] = 0;// Lock type
 
 			lock_type = atoi(lockname);
 			inode_num = atoi(lockname+9);
-			printf("    %s %s for pid %8d   lkid %8x  ", (req->rr_header.rh_cmd == 2)?"LOCK":"CONV", lkmode(req->rr_rqmode),
-			       req->rr_pid, req->rr_header.rh_lkid);
+			printf("    %s %s for pid %8d   lkid %8x  ", (req->m_cmd == 2)?"LOCK":"CONV", lkmode(req->m_rqmode),
+			       req->m_pid, req->m_lkid);
 			switch (lock_type) {
 			case 1:
 				printf("nondisk(1) = %8d\n", inode_num);
@@ -205,11 +253,11 @@ void my_callback(u_char *useless,const struct pcap_pkthdr* pkthdr,
 			}
 			linfo = malloc(sizeof(struct saved_lock));
 			if (linfo) {
-				sprintf(linfo->lkid_string, "%x", req->rr_header.rh_lkid);
+				sprintf(linfo->lkid_string, "%x", req->m_lkid);
 
 				lockname[8] = ' ';
 				memcpy(linfo->name, lockname, namelen+1);
-				linfo->lkid = req->rr_header.rh_lkid;
+				linfo->lkid = req->m_lkid;
 				gettimeofday(&linfo->locktime, NULL);
 				hentry.key = linfo->lkid_string;
 				hentry.data = linfo;
@@ -218,11 +266,11 @@ void my_callback(u_char *useless,const struct pcap_pkthdr* pkthdr,
 			printed++;
 		}
 
-		if (req->rr_header.rh_cmd == 3) { // unlockrequest
+		if (req->m_cmd == DLM_MSG_UNLOCK) {
 			char lkid_string[32];
 			ENTRY *found_entry;
 
-			sprintf(lkid_string, "%x", req->rr_header.rh_lkid);
+			sprintf(lkid_string, "%x", req->m_lkid);
 			hentry.key = lkid_string;
 			hentry.data = NULL;
 
@@ -235,19 +283,19 @@ void my_callback(u_char *useless,const struct pcap_pkthdr* pkthdr,
 				gettimeofday(&now, NULL);
 				interval = now.tv_sec - linfo->locktime.tv_sec;
 
-				printf("    UNLOCK for lkid %x, held %d seconds. '%s'\n", req->rr_header.rh_lkid,
+				printf("    UNLOCK for lkid %x, held %d seconds. '%s'\n", req->m_lkid,
 				       interval, linfo->name);
 			}
 			printed++;
 		}
 #if 0
-		if (req->rr_header.rh_cmd == 5) { // lockreply
-			if (req->rr_status) {
-				printf("    ERROR Return %d for lkid %x\n", req->rr_status, req->rr_remlkid);
+		if (req->m_cmd == 5) { // lockreply
+			if (req->m_status) {
+				printf("    ERROR Return %d for lkid %x\n", req->m_status, req->m_remlkid);
 			}
 		}
 #endif
-		offset += req->rr_header.rh_length;
+		offset += req->m_length;
 	}
 }
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]