From 701a876e7328dff5a2692073c18301803cc9a350 Mon Sep 17 00:00:00 2001 From: Lon Hohberger Date: Tue, 15 Sep 2009 10:28:20 -0400 Subject: [PATCH] Add sequence numbers to requests for tracking Signed-off-by: Lon Hohberger --- client/mcast.c | 13 ++++++++++--- include/server_plugin.h | 8 +++----- include/xvm.h | 4 +++- server/libvirt.c | 6 +++--- server/main.c | 1 + server/mcast.c | 13 +++++++++---- server/null.c | 9 ++++++--- server/plugin.c | 1 + 8 files changed, 36 insertions(+), 19 deletions(-) diff --git a/client/mcast.c b/client/mcast.c index 0f5ba1b..cf5f37b 100644 --- a/client/mcast.c +++ b/client/mcast.c @@ -133,8 +133,8 @@ tcp_exchange(int fd, fence_auth_type_t auth, void *key, static int -send_multicast_packets(ip_list_t *ipl, fence_virt_args_t *args, void *key, - size_t key_len) +send_multicast_packets(ip_list_t *ipl, fence_virt_args_t *args, + uint32_t seqno, void *key, size_t key_len) { fence_req_t freq; int mc_sock; @@ -180,6 +180,7 @@ send_multicast_packets(ip_list_t *ipl, fence_virt_args_t *args, void *key, sizeof(freq.domain)); freq.request = args->op; freq.hashtype = args->net.hash; + freq.seqno = seqno; /* Store source address */ if (ipa->ipa_family == PF_INET) { @@ -218,8 +219,10 @@ mcast_fence_virt(fence_virt_args_t *args) { ip_list_t ipl; char key[MAX_KEY_LEN]; + struct timeval tv; int lfd, key_len = 0, fd; int attempts = 0; + uint32_t seqno; /* Initialize NSS; required to do hashing, as silly as that sounds... */ @@ -268,8 +271,12 @@ mcast_fence_virt(fence_virt_args_t *args) attempts = args->timeout * 10 / args->retr_time; + gettimeofday(&tv, NULL); + seqno = (uint32_t)tv.tv_usec; + do { - if (send_multicast_packets(&ipl, args, key, key_len)) { + if (send_multicast_packets(&ipl, args, seqno, + key, key_len)) { return -1; } diff --git a/include/server_plugin.h b/include/server_plugin.h index e9c44b5..7f007ed 100644 --- a/include/server_plugin.h +++ b/include/server_plugin.h @@ -1,6 +1,4 @@ /* */ -#include - #define PLUGIN_VERSION_LISTENER ((double)0.1) #define PLUGIN_VERSION_BACKEND ((double)0.1) @@ -28,17 +26,17 @@ typedef int (*fence_null_callback)(const char *vm_name, /* Turn the VM 'off'. Returns 0 to caller if successful or nonzero if unsuccessful. */ -typedef int (*fence_off_callback)(const char *vm_name, +typedef int (*fence_off_callback)(const char *vm_name, uint32_t seqno, void *priv); /* Turn the VM 'on'. Returns 0 to caller if successful or nonzero if unsuccessful. */ -typedef int (*fence_on_callback)(const char *vm_name, +typedef int (*fence_on_callback)(const char *vm_name, uint32_t seqno, void *priv); /* Reboot a VM. Returns 0 to caller if successful or nonzero if unsuccessful. */ -typedef int (*fence_reboot_callback)(const char *vm_name, +typedef int (*fence_reboot_callback)(const char *vm_name, uint32_t seqno, void *priv); /* Get status of a VM. Returns 0 to caller if VM is alive or diff --git a/include/xvm.h b/include/xvm.h index b55b498..54d499e 100644 --- a/include/xvm.h +++ b/include/xvm.h @@ -77,7 +77,8 @@ typedef struct __attribute__ ((packed)) _fence_req { uint8_t address[MAX_ADDR_LEN]; /* We're this IP */ #define DEFAULT_MCAST_PORT 1229 uint16_t port; /* Port we bound to */ - uint8_t random[10]; /* Random Data */ + uint8_t random[6]; /* Random Data */ + uint32_t seqno; /* Request identifier; can be random */ uint32_t family; /* Address family */ uint8_t hash[MAX_HASH_LENGTH]; /* Binary hash */ } fence_req_t; @@ -92,6 +93,7 @@ typedef struct __attribute__((packed)) _serial_fence_req { uint8_t request; uint8_t flags; uint8_t domain[MAX_DOMAINNAME_LENGTH]; + uint32_t seqno; } serial_req_t; typedef struct __attribute__((packed)) _serial_fense_resp { diff --git a/server/libvirt.c b/server/libvirt.c index 97a2914..b74f3e5 100644 --- a/server/libvirt.c +++ b/server/libvirt.c @@ -146,7 +146,7 @@ libvirt_null(const char *vm_name, void *priv) static int -libvirt_off(const char *vm_name, void *priv) +libvirt_off(const char *vm_name, uint32_t seqno, void *priv) { struct libvirt_info *info = (struct libvirt_info *)priv; virDomainPtr vdp; @@ -195,7 +195,7 @@ libvirt_off(const char *vm_name, void *priv) static int -libvirt_on(const char *vm_name, void *priv) +libvirt_on(const char *vm_name, uint32_t seqno, void *priv) { dbg_printf(5, "%s %s\n", __FUNCTION__, vm_name); @@ -244,7 +244,7 @@ libvirt_status(const char *vm_name, void *priv) static int -libvirt_reboot(const char *vm_name, void *priv) +libvirt_reboot(const char *vm_name, uint32_t seqno, void *priv) { struct libvirt_info *info = (struct libvirt_info *)priv; virDomainPtr vdp, nvdp; diff --git a/server/main.c b/server/main.c index e124216..c19e0ba 100644 --- a/server/main.c +++ b/server/main.c @@ -6,6 +6,7 @@ #include /* Local includes */ +#include #include #include #include diff --git a/server/mcast.c b/server/mcast.c index e9881ac..c5ea969 100644 --- a/server/mcast.c +++ b/server/mcast.c @@ -102,6 +102,7 @@ check_history(void *a, void *b) { fence_req_t *old = a, *current = b; if (old->request == current->request && + old->seqno == current->seqno && !strcasecmp((const char *)old->domain, (const char *)current->domain)) { return 1; @@ -187,13 +188,16 @@ do_fence_request_tcp(fence_req_t *req, mcast_info *info) response = info->cb->null((char *)req->domain, info->priv); break; case FENCE_ON: - response = info->cb->on((char *)req->domain, info->priv); + response = info->cb->on((char *)req->domain, req->seqno, + info->priv); break; case FENCE_OFF: - response = info->cb->off((char *)req->domain, info->priv); + response = info->cb->off((char *)req->domain, req->seqno, + info->priv); break; case FENCE_REBOOT: - response = info->cb->reboot((char *)req->domain, info->priv); + response = info->cb->reboot((char *)req->domain, req->seqno, + info->priv); break; case FENCE_STATUS: response = info->cb->status((char *)req->domain, info->priv); @@ -277,7 +281,8 @@ mcast_dispatch(listener_context_t c, struct timeval *timeout) return 0; } - printf("Request %d domain %s\n", data.request, data.domain); + printf("Request %d seqno %d domain %s\n", data.request, data.seqno, + data.domain); if (history_check(info->history, &data) == 1) { printf("We just did this request; dropping packet\n"); diff --git a/server/null.c b/server/null.c index 506365c..3ad461f 100644 --- a/server/null.c +++ b/server/null.c @@ -21,6 +21,9 @@ */ #include #include +#include +#include +#include #include #include #include @@ -58,7 +61,7 @@ null_null(const char *vm_name, void *priv) static int -null_off(const char *vm_name, void *priv) +null_off(const char *vm_name, uint32_t seqno, void *priv) { VALIDATE(priv); printf("[Null] OFF operation on %s\n", vm_name); @@ -68,7 +71,7 @@ null_off(const char *vm_name, void *priv) static int -null_on(const char *vm_name, void *priv) +null_on(const char *vm_name, uint32_t seqno, void *priv) { VALIDATE(priv); printf("[Null] ON operation on %s\n", vm_name); @@ -100,7 +103,7 @@ null_status(const char *vm_name, void *priv) static int -null_reboot(const char *vm_name, void *priv) +null_reboot(const char *vm_name, uint32_t seqno, void *priv) { VALIDATE(priv); printf("[Null] REBOOT operation on %s\n", vm_name); diff --git a/server/plugin.c b/server/plugin.c index 03188c5..fd88c4c 100644 --- a/server/plugin.c +++ b/server/plugin.c @@ -27,6 +27,7 @@ #include #include +#include #include #include #include