mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-02 01:18:26 +03:00
Add 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.
This commit is contained in:
parent
29684f590c
commit
968cdc0066
@ -1,3 +1,4 @@
|
|||||||
init_fifos
|
init_fifos
|
||||||
fini_fifos
|
fini_fifos
|
||||||
daemon_talk
|
daemon_talk
|
||||||
|
dm_event_get_version
|
||||||
|
@ -1424,8 +1424,9 @@ static int _do_process_request(struct dm_event_daemon_message *msg)
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
answer = msg->data;
|
answer = msg->data;
|
||||||
if (answer) {
|
if (answer) {
|
||||||
msg->size = dm_asprintf(&(msg->data), "%s %s", answer,
|
msg->size = dm_asprintf(&(msg->data), "%s %s %d", answer,
|
||||||
msg->cmd == DM_EVENT_CMD_DIE ? "DYING" : "HELLO");
|
msg->cmd == DM_EVENT_CMD_DIE ? "DYING" : "HELLO",
|
||||||
|
DM_EVENT_PROTOCOL_VERSION);
|
||||||
dm_free(answer);
|
dm_free(answer);
|
||||||
} else {
|
} else {
|
||||||
msg->size = 0;
|
msg->size = 0;
|
||||||
@ -1704,6 +1705,7 @@ static void restart(void)
|
|||||||
int i, count = 0;
|
int i, count = 0;
|
||||||
char *message;
|
char *message;
|
||||||
int length;
|
int length;
|
||||||
|
int version;
|
||||||
|
|
||||||
/* Get the list of registrations from the running daemon. */
|
/* Get the list of registrations from the running daemon. */
|
||||||
|
|
||||||
@ -1712,12 +1714,19 @@ static void restart(void)
|
|||||||
return;
|
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");
|
fprintf(stderr, "WARNING: Could not communicate with existing dmeventd.\n");
|
||||||
fini_fifos(&fifos);
|
fini_fifos(&fifos);
|
||||||
return;
|
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)) {
|
if (daemon_talk(&fifos, &msg, DM_EVENT_CMD_GET_STATUS, "-", "-", 0, 0)) {
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
@ -69,5 +69,6 @@ int daemon_talk(struct dm_event_fifos *fifos,
|
|||||||
enum dm_event_mask evmask, uint32_t timeout);
|
enum dm_event_mask evmask, uint32_t timeout);
|
||||||
int init_fifos(struct dm_event_fifos *fifos);
|
int init_fifos(struct dm_event_fifos *fifos);
|
||||||
void fini_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__ */
|
#endif /* __DMEVENTD_DOT_H__ */
|
||||||
|
@ -782,6 +782,36 @@ int dm_event_get_registered_device(struct dm_event_handler *dmevh, int next)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* You can (and have to) call this at the stage of the protocol where
|
||||||
|
* daemon_talk(fifos, &msg, DM_EVENT_CMD_HELLO, NULL, NULL, 0, 0)
|
||||||
|
*
|
||||||
|
* would be normally sent. 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.
|
||||||
|
*
|
||||||
|
* This is an internal function, not exposed in the public API.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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 */
|
||||||
|
if (!p) return 0;
|
||||||
|
p = strchr(p, ' ') + 1; /* HELLO */
|
||||||
|
if (!p) return 0;
|
||||||
|
p = strchr(p, ' '); /* HELLO, once more */
|
||||||
|
if (p)
|
||||||
|
*version = atoi(p);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
#if 0 /* left out for now */
|
#if 0 /* left out for now */
|
||||||
|
|
||||||
static char *_skip_string(char *src, const int delimiter)
|
static char *_skip_string(char *src, const int delimiter)
|
||||||
|
@ -46,6 +46,7 @@ enum dm_event_mask {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#define DM_EVENT_ALL_ERRORS DM_EVENT_ERROR_MASK
|
#define DM_EVENT_ALL_ERRORS DM_EVENT_ERROR_MASK
|
||||||
|
#define DM_EVENT_PROTOCOL_VERSION 1
|
||||||
|
|
||||||
struct dm_event_handler;
|
struct dm_event_handler;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user