Add sequence numbers to requests for tracking

Signed-off-by: Lon Hohberger <lhh@redhat.com>
This commit is contained in:
Lon Hohberger 2009-09-15 10:28:20 -04:00
parent 51f06f5ce3
commit 701a876e73
8 changed files with 36 additions and 19 deletions

View File

@ -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;
}

View File

@ -1,6 +1,4 @@
/* */
#include <uuid/uuid.h>
#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

View File

@ -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 {

View File

@ -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;

View File

@ -6,6 +6,7 @@
#include <sys/types.h>
/* Local includes */
#include <stdint.h>
#include <fence_virt.h>
#include <simpleconfig.h>
#include <server_plugin.h>

View File

@ -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");

View File

@ -21,6 +21,9 @@
*/
#include <stdio.h>
#include <simpleconfig.h>
#include <sys/types.h>
#include <stdint.h>
#include <time.h>
#include <server_plugin.h>
#include <string.h>
#include <malloc.h>
@ -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);

View File

@ -27,6 +27,7 @@
#include <sys/stat.h>
#include <unistd.h>
#include <stdint.h>
#include <list.h>
#include <simpleconfig.h>
#include <server_plugin.h>