[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[lvm-devel] [PATCH] dmeventd protocol versioning mechanism



Hi,

the attached patch adds rudimentary versioning to the dmevend protocol,
allowing us to detect the (protocol) version of the running dmeventd on
the client side.

Right now this is only used in dmeventd -R.

Index: daemons/dmeventd/.exported_symbols
===================================================================
RCS file: /cvs/lvm2/LVM2/daemons/dmeventd/.exported_symbols,v
retrieving revision 1.11
diff -u -p -r1.11 .exported_symbols
--- daemons/dmeventd/.exported_symbols	20 Oct 2010 15:12:12 -0000	1.11
+++ daemons/dmeventd/.exported_symbols	20 Mar 2011 10:05:08 -0000
@@ -1,3 +1,4 @@
 init_fifos
 fini_fifos
 daemon_talk
+dm_event_get_version
Index: daemons/dmeventd/dmeventd.c
===================================================================
RCS file: /cvs/lvm2/LVM2/daemons/dmeventd/dmeventd.c,v
retrieving revision 1.77
diff -u -p -r1.77 dmeventd.c
--- daemons/dmeventd/dmeventd.c	2 Mar 2011 14:20:48 -0000	1.77
+++ daemons/dmeventd/dmeventd.c	20 Mar 2011 10:05:09 -0000
@@ -1424,8 +1424,9 @@ static int _do_process_request(struct dm
 		ret = 0;
 		answer = msg->data;
 		if (answer) {
-			msg->size = dm_asprintf(&(msg->data), "%s %s", answer,
-						msg->cmd == DM_EVENT_CMD_DIE ? "DYING" : "HELLO");
+			msg->size = dm_asprintf(&(msg->data), "%s %s %d", answer,
+						msg->cmd == DM_EVENT_CMD_DIE ? "DYING" : "HELLO",
+						DM_EVENT_PROTOCOL_VERSION);
 			dm_free(answer);
 		} else {
 			msg->size = 0;
@@ -1704,6 +1705,7 @@ static void restart(void)
 	int i, count = 0;
 	char *message;
 	int length;
+	int version;
 
 	/* Get the list of registrations from the running daemon. */
 
@@ -1712,12 +1714,19 @@ static void restart(void)
 		return;
 	}
 
-	if (daemon_talk(&fifos, &msg, DM_EVENT_CMD_HELLO, NULL, NULL, 0, 0)) {
+	if (!dm_event_get_version(&fifos, &version)) {
 		fprintf(stderr, "WARNING: Could not communicate with existing dmeventd.\n");
 		fini_fifos(&fifos);
 		return;
 	}
 
+	if (version < 1) {
+		fprintf(stderr, "WARNING: The running dmeventd instance is too old.\n"
+			        "Protocol version %d (required: 1). Action cancelled.\n",
+			        version);
+		exit(EXIT_FAILURE);
+	}
+
 	if (daemon_talk(&fifos, &msg, DM_EVENT_CMD_GET_STATUS, "-", "-", 0, 0)) {
 		exit(EXIT_FAILURE);
 	}
Index: daemons/dmeventd/dmeventd.h
===================================================================
RCS file: /cvs/lvm2/LVM2/daemons/dmeventd/dmeventd.h,v
retrieving revision 1.8
diff -u -p -r1.8 dmeventd.h
--- daemons/dmeventd/dmeventd.h	17 Jan 2011 19:02:44 -0000	1.8
+++ daemons/dmeventd/dmeventd.h	20 Mar 2011 10:05:09 -0000
@@ -69,5 +69,6 @@ int daemon_talk(struct dm_event_fifos *f
 		enum dm_event_mask evmask, uint32_t timeout);
 int init_fifos(struct dm_event_fifos *fifos);
 void fini_fifos(struct dm_event_fifos *fifos);
+int dm_event_get_version(struct dm_event_fifos *fifos, int *version);
 
 #endif /* __DMEVENTD_DOT_H__ */
Index: daemons/dmeventd/libdevmapper-event.c
===================================================================
RCS file: /cvs/lvm2/LVM2/daemons/dmeventd/libdevmapper-event.c,v
retrieving revision 1.40
diff -u -p -r1.40 libdevmapper-event.c
--- daemons/dmeventd/libdevmapper-event.c	1 Mar 2011 20:17:56 -0000	1.40
+++ daemons/dmeventd/libdevmapper-event.c	20 Mar 2011 10:05:09 -0000
@@ -782,6 +782,30 @@ int dm_event_get_registered_device(struc
 	return ret;
 }
 
+/*
+ * You can (and have to) call this in place of
+ *     daemon_talk(fifos, &msg, DM_EVENT_CMD_HELLO, NULL, NULL, 0, 0)
+ * -- this call will parse the version reply from dmeventd, in addition to
+ * above call. It is not safe to call this at any other place in the
+ * protocol.
+ */
+int dm_event_get_version(struct dm_event_fifos *fifos, int *version) {
+	char *p;
+	struct dm_event_daemon_message msg = { 0, 0, NULL };
+
+	if (daemon_talk(fifos, &msg, DM_EVENT_CMD_HELLO, NULL, NULL, 0, 0))
+		return 0;
+	p = msg.data;
+	*version = 0;
+
+	p = strchr(p, ' ') + 1; /* Message ID */
+	p = strchr(p, ' ') + 1; /* HELLO */
+	p = strchr(p, ' '); /* HELLO, once more */
+	if (p)
+		*version = atoi(p);
+	return 1;
+}
+
 #if 0				/* left out for now */
 
 static char *_skip_string(char *src, const int delimiter)
Index: daemons/dmeventd/libdevmapper-event.h
===================================================================
RCS file: /cvs/lvm2/LVM2/daemons/dmeventd/libdevmapper-event.h,v
retrieving revision 1.15
diff -u -p -r1.15 libdevmapper-event.h
--- daemons/dmeventd/libdevmapper-event.h	16 Aug 2010 22:54:36 -0000	1.15
+++ daemons/dmeventd/libdevmapper-event.h	20 Mar 2011 10:05:09 -0000
@@ -46,6 +46,7 @@ enum dm_event_mask {
 };
 
 #define DM_EVENT_ALL_ERRORS DM_EVENT_ERROR_MASK
+#define DM_EVENT_PROTOCOL_VERSION 1
 
 struct dm_event_handler;
 
Yours,
   Petr

-- 
id' Ash = Ash; id' Dust = Dust; id' _ = undefined

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]