Add simple 'null' skeleton backend plugin

Signed-off-by: Lon Hohberger <lhh@redhat.com>
This commit is contained in:
Lon Hohberger 2009-09-01 19:11:15 -04:00
parent 5beaad3390
commit e94b653f7a
2 changed files with 202 additions and 4 deletions

View File

@ -15,14 +15,12 @@ include ../Makefile.top
TARGETS=fence_virtd TARGETS=fence_virtd
MODULES=libvirt.so checkpoint.so multicast.so MODULES=libvirt.so checkpoint.so multicast.so null.so
fence_virtd_SOURCES = main.c plugin.c fence_virtd_SOURCES = main.c plugin.c
libvirt_so_SOURCES = libvirt.c libvirt_so_SOURCES = libvirt.c
null_so_SOURCES = null.c
multicast_so_SOURCES = mcast.c multicast_so_SOURCES = mcast.c
checkpoint_so_SOURCES = virt.c vm_states.c checkpoint_so_SOURCES = virt.c vm_states.c
INCLUDES=-I../include\ INCLUDES=-I../include\
@ -49,6 +47,9 @@ multicast.so: ${multicast_so_SOURCES:.c=.o}
libvirt.so: ${libvirt_so_SOURCES:.c=.o} libvirt.so: ${libvirt_so_SOURCES:.c=.o}
gcc -o $@ $^ $(LIBS) -shared gcc -o $@ $^ $(LIBS) -shared
null.so: ${null_so_SOURCES:.c=.o}
gcc -o $@ $^ $(LIBS) -shared
checkpoint.so: ${checkpoint_so_SOURCES:.c=.o} checkpoint.so: ${checkpoint_so_SOURCES:.c=.o}
gcc -o $@ $^ $(LIBS) -shared gcc -o $@ $^ $(LIBS) -shared

197
server/null.c Normal file
View File

@ -0,0 +1,197 @@
/*
Copyright Red Hat, Inc. 2009
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
MA 02139, USA.
*/
/*
* Author: Lon Hohberger <lhh at redhat.com>
*/
#include <stdio.h>
#include <simpleconfig.h>
#include <server_plugin.h>
#include <string.h>
#include <malloc.h>
#include <errno.h>
/* Local includes */
#include "debug.h"
#define NAME "null"
#define VERSION "0.8"
#define MAGIC 0x1e00017a
struct null_info {
int magic;
int pad;
char *message;
};
#define VALIDATE(arg) \
do {\
if (!arg || ((struct null_info *)arg)->magic != MAGIC) { \
errno = EINVAL;\
return -1; \
} \
} while(0)
static int
null_null(const char *vm_name, void *priv)
{
VALIDATE(priv);
printf("[Null] Null operation on %s\n", vm_name);
return 1;
}
static int
null_off(const char *vm_name, void *priv)
{
VALIDATE(priv);
printf("[Null] OFF operation on %s\n", vm_name);
return 1;
}
static int
null_on(const char *vm_name, void *priv)
{
VALIDATE(priv);
printf("[Null] ON operation on %s\n", vm_name);
return 1;
}
static int
null_devstatus(void *priv)
{
printf("[Null] Device status\n");
VALIDATE(priv);
printf("[Null] Message for you: %s\n",
((struct null_info *)priv)->message);
return 0;
}
static int
null_status(const char *vm_name, void *priv)
{
VALIDATE(priv);
printf("[Null] STATUS operation on %s\n", vm_name);
return 1;
}
static int
null_reboot(const char *vm_name, void *priv)
{
VALIDATE(priv);
printf("[Null] REBOOT operation on %s\n", vm_name);
return 1;
}
static int
null_init(backend_context_t *c, config_object_t *config)
{
char value[256];
struct null_info *info = NULL;
char *null_message = NULL;
info = malloc(sizeof(*info));
if (!info)
return -1;
memset(info, 0, sizeof(*info));
if (sc_get(config, "backends/null/@message",
value, sizeof(value)) != 0) {
snprintf(value, sizeof(value), "Hi!");
}
null_message = strdup(value);
if (!null_message) {
free(info);
return -1;
}
info->magic = MAGIC;
info->message = null_message;
*c = (void *)info;
return 0;
}
static int
null_shutdown(backend_context_t c)
{
struct null_info *info = (struct null_info *)c;
VALIDATE(info);
info->magic = 0;
free(info->message);
free(info);
return 0;
}
static fence_callbacks_t null_callbacks = {
.null = null_null,
.off = null_off,
.on = null_on,
.reboot = null_reboot,
.status = null_status,
.devstatus = null_devstatus
};
static backend_plugin_t null_plugin = {
.name = NAME,
.version = VERSION,
.callbacks = &null_callbacks,
.init = null_init,
.cleanup = null_shutdown,
};
#ifdef _MODULE
double
BACKEND_VER_SYM(void)
{
return PLUGIN_VERSION_BACKEND;
}
const backend_plugin_t *
BACKEND_INFO_SYM(void)
{
return &null_plugin;
}
#else
static void __attribute__((constructor))
null_register_plugin(void)
{
plugin_register(&null_plugin);
}
#endif