Add QEMU driver events for defined/undefined config files

This commit is contained in:
Daniel P. Berrange 2008-11-17 16:52:32 +00:00
parent d3d54d2fc9
commit a5e72f9177
5 changed files with 67 additions and 10 deletions

View File

@ -1,3 +1,13 @@
Mon Nov 17 16:45:00 GMT 2008 Daniel Berrange <berrange@redhat.com>
Generate domain events for QEMU driver config files
* src/qemu_driver.c: Generate events when config is defined
and undefined
* src/domain_conf.c, src/domain_conf.h: Add a callback for
notifications of each loaded config file
* src/lxc_driver.c: Pass NULL for config file notification
callback parameter
Mon Nov 17 16:42:00 GMT 2008 Daniel Berrange <berrange@redhat.com> Mon Nov 17 16:42:00 GMT 2008 Daniel Berrange <berrange@redhat.com>
Include an event 'detail' field providing the cause of Include an event 'detail' field providing the cause of

View File

@ -3242,31 +3242,38 @@ virDomainObjPtr virDomainLoadConfig(virConnectPtr conn,
virDomainObjListPtr doms, virDomainObjListPtr doms,
const char *configDir, const char *configDir,
const char *autostartDir, const char *autostartDir,
const char *name) const char *name,
virDomainLoadConfigNotify notify,
void *opaque)
{ {
char *configFile = NULL, *autostartLink = NULL; char *configFile = NULL, *autostartLink = NULL;
virDomainDefPtr def = NULL; virDomainDefPtr def = NULL;
virDomainObjPtr dom; virDomainObjPtr dom;
int autostart; int autostart;
int newVM = 1;
if ((configFile = virDomainConfigFile(conn, configDir, name)) == NULL) if ((configFile = virDomainConfigFile(conn, configDir, name)) == NULL)
goto error; goto error;
if ((autostartLink = virDomainConfigFile(conn, autostartDir, name)) == NULL) if ((autostartLink = virDomainConfigFile(conn, autostartDir, name)) == NULL)
goto error; goto error;
if ((autostart = virFileLinkPointsTo(autostartLink, configFile)) < 0) if ((autostart = virFileLinkPointsTo(autostartLink, configFile)) < 0)
goto error; goto error;
if (!(def = virDomainDefParseFile(conn, caps, configFile))) if (!(def = virDomainDefParseFile(conn, caps, configFile)))
goto error; goto error;
if (virDomainFindByName(doms, def->name))
newVM = 0;
if (!(dom = virDomainAssignDef(conn, doms, def))) if (!(dom = virDomainAssignDef(conn, doms, def)))
goto error; goto error;
dom->state = VIR_DOMAIN_SHUTOFF;
dom->autostart = autostart; dom->autostart = autostart;
if (notify)
(*notify)(dom, newVM, opaque);
return dom; return dom;
error: error:
@ -3280,7 +3287,9 @@ int virDomainLoadAllConfigs(virConnectPtr conn,
virCapsPtr caps, virCapsPtr caps,
virDomainObjListPtr doms, virDomainObjListPtr doms,
const char *configDir, const char *configDir,
const char *autostartDir) const char *autostartDir,
virDomainLoadConfigNotify notify,
void *opaque)
{ {
DIR *dir; DIR *dir;
struct dirent *entry; struct dirent *entry;
@ -3310,7 +3319,9 @@ int virDomainLoadAllConfigs(virConnectPtr conn,
doms, doms,
configDir, configDir,
autostartDir, autostartDir,
entry->d_name); entry->d_name,
notify,
opaque);
if (dom) if (dom)
dom->persistent = 1; dom->persistent = 1;
} }

View File

@ -549,18 +549,26 @@ int virDomainSaveConfig(virConnectPtr conn,
const char *configDir, const char *configDir,
virDomainDefPtr def); virDomainDefPtr def);
typedef void (*virDomainLoadConfigNotify)(virDomainObjPtr dom,
int newDomain,
void *opaque);
virDomainObjPtr virDomainLoadConfig(virConnectPtr conn, virDomainObjPtr virDomainLoadConfig(virConnectPtr conn,
virCapsPtr caps, virCapsPtr caps,
virDomainObjListPtr doms, virDomainObjListPtr doms,
const char *configDir, const char *configDir,
const char *autostartDir, const char *autostartDir,
const char *name); const char *name,
virDomainLoadConfigNotify notify,
void *opaque);
int virDomainLoadAllConfigs(virConnectPtr conn, int virDomainLoadAllConfigs(virConnectPtr conn,
virCapsPtr caps, virCapsPtr caps,
virDomainObjListPtr doms, virDomainObjListPtr doms,
const char *configDir, const char *configDir,
const char *autostartDir); const char *autostartDir,
virDomainLoadConfigNotify notify,
void *opaque);
int virDomainDeleteConfig(virConnectPtr conn, int virDomainDeleteConfig(virConnectPtr conn,
const char *configDir, const char *configDir,

View File

@ -1015,7 +1015,8 @@ static int lxcStartup(void)
lxc_driver->caps, lxc_driver->caps,
&lxc_driver->domains, &lxc_driver->domains,
lxc_driver->configDir, lxc_driver->configDir,
lxc_driver->autostartDir) < 0) { lxc_driver->autostartDir,
NULL, NULL) < 0) {
lxcShutdown(); lxcShutdown();
return -1; return -1;
} }

View File

@ -226,7 +226,8 @@ qemudStartup(void) {
qemu_driver->caps, qemu_driver->caps,
&qemu_driver->domains, &qemu_driver->domains,
qemu_driver->configDir, qemu_driver->configDir,
qemu_driver->autostartDir) < 0) { qemu_driver->autostartDir,
NULL, NULL) < 0) {
qemudShutdown(); qemudShutdown();
return -1; return -1;
} }
@ -243,6 +244,16 @@ qemudStartup(void) {
return -1; return -1;
} }
static void qemudNotifyLoadDomain(virDomainObjPtr vm, int newVM, void *opaque)
{
struct qemud_driver *driver = opaque;
if (newVM)
qemudDomainEventDispatch(driver, vm,
VIR_DOMAIN_EVENT_DEFINED,
VIR_DOMAIN_EVENT_DEFINED_ADDED);
}
/** /**
* qemudReload: * qemudReload:
* *
@ -258,7 +269,8 @@ qemudReload(void) {
qemu_driver->caps, qemu_driver->caps,
&qemu_driver->domains, &qemu_driver->domains,
qemu_driver->configDir, qemu_driver->configDir,
qemu_driver->autostartDir); qemu_driver->autostartDir,
qemudNotifyLoadDomain, qemu_driver);
qemudAutostartConfigs(qemu_driver); qemudAutostartConfigs(qemu_driver);
@ -2365,10 +2377,15 @@ static virDomainPtr qemudDomainDefine(virConnectPtr conn, const char *xml) {
virDomainDefPtr def; virDomainDefPtr def;
virDomainObjPtr vm; virDomainObjPtr vm;
virDomainPtr dom; virDomainPtr dom;
int newVM = 1;
if (!(def = virDomainDefParseString(conn, driver->caps, xml))) if (!(def = virDomainDefParseString(conn, driver->caps, xml)))
return NULL; return NULL;
vm = virDomainFindByName(&driver->domains, def->name);
if (vm)
newVM = 0;
if (!(vm = virDomainAssignDef(conn, if (!(vm = virDomainAssignDef(conn,
&driver->domains, &driver->domains,
def))) { def))) {
@ -2385,6 +2402,12 @@ static virDomainPtr qemudDomainDefine(virConnectPtr conn, const char *xml) {
return NULL; return NULL;
} }
qemudDomainEventDispatch(driver, vm,
VIR_DOMAIN_EVENT_DEFINED,
newVM ?
VIR_DOMAIN_EVENT_DEFINED_ADDED :
VIR_DOMAIN_EVENT_DEFINED_UPDATED);
dom = virGetDomain(conn, vm->def->name, vm->def->uuid); dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
if (dom) dom->id = vm->def->id; if (dom) dom->id = vm->def->id;
return dom; return dom;
@ -2415,6 +2438,10 @@ static int qemudDomainUndefine(virDomainPtr dom) {
if (virDomainDeleteConfig(dom->conn, driver->configDir, driver->autostartDir, vm) < 0) if (virDomainDeleteConfig(dom->conn, driver->configDir, driver->autostartDir, vm) < 0)
return -1; return -1;
qemudDomainEventDispatch(driver, vm,
VIR_DOMAIN_EVENT_UNDEFINED,
VIR_DOMAIN_EVENT_UNDEFINED_REMOVED);
virDomainRemoveInactive(&driver->domains, virDomainRemoveInactive(&driver->domains,
vm); vm);