[libvirt] New APIs for checking some object properties (v2)

This is a second posting of the proposal from earlier today http://www.redhat.com/archives/libvir-list/2009-October/msg00556.html The changes since last time - Renamed some existing internal APIs which had bad names which clashed with our new public APis. - Fix the comment bugs Daniel mentioned - Change the return status from '> 0' to '1', so we can explicitly add other positive integer return codes if ever required - Implement the new APIs for (nearly) all drivers Daniel

--- src/conf/domain_conf.c | 4 +- src/conf/domain_conf.h | 2 +- src/conf/interface_conf.h | 2 +- src/conf/network_conf.c | 2 +- src/conf/network_conf.h | 2 +- src/lxc/lxc_driver.c | 24 +++++++------- src/network/bridge_driver.c | 20 ++++++------ src/opennebula/one_driver.c | 12 ++++---- src/openvz/openvz_driver.c | 8 ++-- src/qemu/qemu_driver.c | 68 +++++++++++++++++++++--------------------- src/test/test_driver.c | 28 +++++++++--------- src/uml/uml_driver.c | 28 +++++++++--------- 12 files changed, 100 insertions(+), 100 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 7d558e8..5da62cb 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -212,7 +212,7 @@ virDomainObjPtr virDomainFindByID(const virDomainObjListPtr doms, for (i = 0 ; i < doms->count ; i++) { virDomainObjLock(doms->objs[i]); - if (virDomainIsActive(doms->objs[i]) && + if (virDomainObjIsActive(doms->objs[i]) && doms->objs[i]->def->id == id) return doms->objs[i]; virDomainObjUnlock(doms->objs[i]); @@ -603,7 +603,7 @@ virDomainObjPtr virDomainAssignDef(virConnectPtr conn, virDomainObjPtr domain; if ((domain = virDomainFindByUUID(doms, def->uuid))) { - if (!virDomainIsActive(domain)) { + if (!virDomainObjIsActive(domain)) { virDomainDefFree(domain->def); domain->def = def; } else { diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index ff1b0cf..01aa9f3 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -645,7 +645,7 @@ struct _virDomainObjList { }; static inline int -virDomainIsActive(virDomainObjPtr dom) +virDomainObjIsActive(virDomainObjPtr dom) { return dom->def->id != -1; } diff --git a/src/conf/interface_conf.h b/src/conf/interface_conf.h index bb9dce4..92543fc 100644 --- a/src/conf/interface_conf.h +++ b/src/conf/interface_conf.h @@ -172,7 +172,7 @@ struct _virInterfaceObjList { }; static inline int -virInterfaceIsActive(const virInterfaceObjPtr iface) +virInterfaceObjIsActive(const virInterfaceObjPtr iface) { return iface->active; } diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 40f5fdd..ca5a1db 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -152,7 +152,7 @@ virNetworkObjPtr virNetworkAssignDef(virConnectPtr conn, virNetworkObjPtr network; if ((network = virNetworkFindByName(nets, def->name))) { - if (!virNetworkIsActive(network)) { + if (!virNetworkObjIsActive(network)) { virNetworkDefFree(network->def); network->def = def; } else { diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h index e983a01..2b399db 100644 --- a/src/conf/network_conf.h +++ b/src/conf/network_conf.h @@ -105,7 +105,7 @@ struct _virNetworkObjList { }; static inline int -virNetworkIsActive(const virNetworkObjPtr net) +virNetworkObjIsActive(const virNetworkObjPtr net) { return net->active; } diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index ef97364..8224376 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -225,7 +225,7 @@ static int lxcListDomains(virConnectPtr conn, int *ids, int nids) { lxcDriverLock(driver); for (i = 0 ; i < driver->domains.count && got < nids ; i++) { virDomainObjLock(driver->domains.objs[i]); - if (virDomainIsActive(driver->domains.objs[i])) + if (virDomainObjIsActive(driver->domains.objs[i])) ids[got++] = driver->domains.objs[i]->def->id; virDomainObjUnlock(driver->domains.objs[i]); } @@ -241,7 +241,7 @@ static int lxcNumDomains(virConnectPtr conn) { lxcDriverLock(driver); for (i = 0 ; i < driver->domains.count ; i++) { virDomainObjLock(driver->domains.objs[i]); - if (virDomainIsActive(driver->domains.objs[i])) + if (virDomainObjIsActive(driver->domains.objs[i])) n++; virDomainObjUnlock(driver->domains.objs[i]); } @@ -258,7 +258,7 @@ static int lxcListDefinedDomains(virConnectPtr conn, lxcDriverLock(driver); for (i = 0 ; i < driver->domains.count && got < nnames ; i++) { virDomainObjLock(driver->domains.objs[i]); - if (!virDomainIsActive(driver->domains.objs[i])) { + if (!virDomainObjIsActive(driver->domains.objs[i])) { if (!(names[got++] = strdup(driver->domains.objs[i]->def->name))) { virReportOOMError(conn); virDomainObjUnlock(driver->domains.objs[i]); @@ -286,7 +286,7 @@ static int lxcNumDefinedDomains(virConnectPtr conn) { lxcDriverLock(driver); for (i = 0 ; i < driver->domains.count ; i++) { virDomainObjLock(driver->domains.objs[i]); - if (!virDomainIsActive(driver->domains.objs[i])) + if (!virDomainObjIsActive(driver->domains.objs[i])) n++; virDomainObjUnlock(driver->domains.objs[i]); } @@ -394,7 +394,7 @@ static int lxcDomainUndefine(virDomainPtr dom) goto cleanup; } - if (virDomainIsActive(vm)) { + if (virDomainObjIsActive(vm)) { lxcError(dom->conn, dom, VIR_ERR_OPERATION_INVALID, "%s", _("cannot delete active domain")); goto cleanup; @@ -448,7 +448,7 @@ static int lxcDomainGetInfo(virDomainPtr dom, info->state = vm->state; - if (!virDomainIsActive(vm) || driver->cgroup == NULL) { + if (!virDomainObjIsActive(vm) || driver->cgroup == NULL) { info->cpuTime = 0; info->memory = vm->def->memory; } else { @@ -588,7 +588,7 @@ static int lxcDomainSetMemory(virDomainPtr dom, unsigned long newmem) { goto cleanup; } - if (virDomainIsActive(vm)) { + if (virDomainObjIsActive(vm)) { if (virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0) != 0) { lxcError(dom->conn, dom, VIR_ERR_INTERNAL_ERROR, _("Unable to get cgroup for %s\n"), vm->def->name); @@ -1328,7 +1328,7 @@ lxcDomainCreateAndStart(virConnectPtr conn, } /* UUID & name match, but if VM is already active, refuse it */ - if (virDomainIsActive(vm)) { + if (virDomainObjIsActive(vm)) { lxcError(conn, NULL, VIR_ERR_OPERATION_FAILED, _("domain is already active as '%s'"), vm->def->name); goto cleanup; @@ -1588,7 +1588,7 @@ lxcAutostartConfigs(lxc_driver_t *driver) { virDomainObjPtr vm = driver->domains.objs[i]; virDomainObjLock(vm); if (vm->autostart && - !virDomainIsActive(vm)) { + !virDomainObjIsActive(vm)) { int ret = lxcVmStart(conn, driver, vm); if (ret < 0) { virErrorPtr err = virGetLastError(); @@ -1818,7 +1818,7 @@ lxcActive(void) { lxcDriverLock(lxc_driver); for (i = 0 ; i < lxc_driver->domains.count ; i++) { virDomainObjLock(lxc_driver->domains.objs[i]); - if (virDomainIsActive(lxc_driver->domains.objs[i])) + if (virDomainObjIsActive(lxc_driver->domains.objs[i])) active = 1; virDomainObjUnlock(lxc_driver->domains.objs[i]); } @@ -2180,7 +2180,7 @@ static int lxcDomainSuspend(virDomainPtr dom) goto cleanup; } - if (!virDomainIsActive(vm)) { + if (!virDomainObjIsActive(vm)) { lxcError(dom->conn, dom, VIR_ERR_OPERATION_INVALID, "%s", _("domain is not running")); goto cleanup; @@ -2245,7 +2245,7 @@ static int lxcDomainResume(virDomainPtr dom) goto cleanup; } - if (!virDomainIsActive(vm)) { + if (!virDomainObjIsActive(vm)) { lxcError(dom->conn, dom, VIR_ERR_OPERATION_INVALID, "%s", _("domain is not running")); goto cleanup; diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 95bc810..3c62636 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -169,7 +169,7 @@ networkAutostartConfigs(struct network_driver *driver) { for (i = 0 ; i < driver->networks.count ; i++) { virNetworkObjLock(driver->networks.objs[i]); if (driver->networks.objs[i]->autostart && - !virNetworkIsActive(driver->networks.objs[i]) && + !virNetworkObjIsActive(driver->networks.objs[i]) && networkStartNetworkDaemon(NULL, driver, driver->networks.objs[i]) < 0) { /* failed to start but already logged */ } @@ -318,7 +318,7 @@ networkActive(void) { for (i = 0 ; i < driverState->networks.count ; i++) { virNetworkObjPtr net = driverState->networks.objs[i]; virNetworkObjLock(net); - if (virNetworkIsActive(net)) + if (virNetworkObjIsActive(net)) active = 1; virNetworkObjUnlock(net); } @@ -862,7 +862,7 @@ static int networkStartNetworkDaemon(virConnectPtr conn, virNetworkObjPtr network) { int err; - if (virNetworkIsActive(network)) { + if (virNetworkObjIsActive(network)) { networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", _("network is already active")); return -1; @@ -967,7 +967,7 @@ static int networkShutdownNetworkDaemon(virConnectPtr conn, VIR_INFO(_("Shutting down network '%s'\n"), network->def->name); - if (!virNetworkIsActive(network)) + if (!virNetworkObjIsActive(network)) return 0; stateFile = virNetworkConfigFile(conn, NETWORK_STATE_DIR, network->def->name); @@ -1079,7 +1079,7 @@ static int networkNumNetworks(virConnectPtr conn) { networkDriverLock(driver); for (i = 0 ; i < driver->networks.count ; i++) { virNetworkObjLock(driver->networks.objs[i]); - if (virNetworkIsActive(driver->networks.objs[i])) + if (virNetworkObjIsActive(driver->networks.objs[i])) nactive++; virNetworkObjUnlock(driver->networks.objs[i]); } @@ -1095,7 +1095,7 @@ static int networkListNetworks(virConnectPtr conn, char **const names, int nname networkDriverLock(driver); for (i = 0 ; i < driver->networks.count && got < nnames ; i++) { virNetworkObjLock(driver->networks.objs[i]); - if (virNetworkIsActive(driver->networks.objs[i])) { + if (virNetworkObjIsActive(driver->networks.objs[i])) { if (!(names[got] = strdup(driver->networks.objs[i]->def->name))) { virNetworkObjUnlock(driver->networks.objs[i]); virReportOOMError(conn); @@ -1123,7 +1123,7 @@ static int networkNumDefinedNetworks(virConnectPtr conn) { networkDriverLock(driver); for (i = 0 ; i < driver->networks.count ; i++) { virNetworkObjLock(driver->networks.objs[i]); - if (!virNetworkIsActive(driver->networks.objs[i])) + if (!virNetworkObjIsActive(driver->networks.objs[i])) ninactive++; virNetworkObjUnlock(driver->networks.objs[i]); } @@ -1139,7 +1139,7 @@ static int networkListDefinedNetworks(virConnectPtr conn, char **const names, in networkDriverLock(driver); for (i = 0 ; i < driver->networks.count && got < nnames ; i++) { virNetworkObjLock(driver->networks.objs[i]); - if (!virNetworkIsActive(driver->networks.objs[i])) { + if (!virNetworkObjIsActive(driver->networks.objs[i])) { if (!(names[got] = strdup(driver->networks.objs[i]->def->name))) { virNetworkObjUnlock(driver->networks.objs[i]); virReportOOMError(conn); @@ -1251,7 +1251,7 @@ static int networkUndefine(virNetworkPtr net) { goto cleanup; } - if (virNetworkIsActive(network)) { + if (virNetworkObjIsActive(network)) { networkReportError(net->conn, NULL, net, VIR_ERR_INTERNAL_ERROR, "%s", _("network is still active")); goto cleanup; @@ -1312,7 +1312,7 @@ static int networkDestroy(virNetworkPtr net) { goto cleanup; } - if (!virNetworkIsActive(network)) { + if (!virNetworkObjIsActive(network)) { networkReportError(net->conn, NULL, net, VIR_ERR_INTERNAL_ERROR, "%s", _("network is not active")); goto cleanup; diff --git a/src/opennebula/one_driver.c b/src/opennebula/one_driver.c index 9bcd5c3..9c6f120 100644 --- a/src/opennebula/one_driver.c +++ b/src/opennebula/one_driver.c @@ -183,7 +183,7 @@ static int oneListDomains(virConnectPtr conn, int *ids, int nids) oneDriverLock(driver); for (i = 0 ; i < driver->domains.count && got < nids ; i++){ virDomainObjLock(driver->domains.objs[i]); - if (virDomainIsActive(driver->domains.objs[i])) + if (virDomainObjIsActive(driver->domains.objs[i])) ids[got++] = driver->domains.objs[i]->def->id; virDomainObjUnlock(driver->domains.objs[i]); } @@ -200,7 +200,7 @@ static int oneNumDomains(virConnectPtr conn) oneDriverLock(driver); for (i = 0 ; i < driver->domains.count ; i++){ virDomainObjLock(driver->domains.objs[i]); - if (virDomainIsActive(driver->domains.objs[i])) + if (virDomainObjIsActive(driver->domains.objs[i])) n++; virDomainObjUnlock(driver->domains.objs[i]); } @@ -217,7 +217,7 @@ static int oneListDefinedDomains(virConnectPtr conn, oneDriverLock(driver); for (i = 0 ; i < driver->domains.count && got < nnames ; i++) { virDomainObjLock(driver->domains.objs[i]); - if (!virDomainIsActive(driver->domains.objs[i])) { + if (!virDomainObjIsActive(driver->domains.objs[i])) { if (!(names[got++] = strdup(driver->domains.objs[i]->def->name))) { virReportOOMError(conn); virDomainObjUnlock(driver->domains.objs[i]); @@ -246,7 +246,7 @@ static int oneNumDefinedDomains(virConnectPtr conn) oneDriverLock(driver); for (i = 0 ; i < driver->domains.count ; i++){ virDomainObjLock(driver->domains.objs[i]); - if (!virDomainIsActive(driver->domains.objs[i])) + if (!virDomainObjIsActive(driver->domains.objs[i])) n++; virDomainObjUnlock(driver->domains.objs[i]); } @@ -338,7 +338,7 @@ static int oneDomainGetInfo(virDomainPtr dom, return -1; } - if (!virDomainIsActive(vm)) { + if (!virDomainObjIsActive(vm)) { info->cpuTime = 0; } else { char vm_info[257]; @@ -686,7 +686,7 @@ static int oneActive(void){ oneDriverLock(one_driver); for (i = 0 ; i < one_driver->domains.count ; i++) { virDomainObjLock(one_driver->domains.objs[i]); - if (virDomainIsActive(one_driver->domains.objs[i])) + if (virDomainObjIsActive(one_driver->domains.objs[i])) active = 1; virDomainObjUnlock(one_driver->domains.objs[i]); } diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index f64ad1e..57482b8 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -393,7 +393,7 @@ static int openvzDomainGetInfo(virDomainPtr dom, info->state = vm->state; - if (!virDomainIsActive(vm)) { + if (!virDomainObjIsActive(vm)) { info->cpuTime = 0; } else { if (openvzGetProcessInfo(&(info->cpuTime), dom->id) < 0) { @@ -949,7 +949,7 @@ openvzDomainUndefine(virDomainPtr dom) goto cleanup; } - if (virDomainIsActive(vm)) { + if (virDomainObjIsActive(vm)) { openvzError(dom->conn, VIR_ERR_INTERNAL_ERROR, "%s", _("cannot delete active domain")); goto cleanup; } @@ -1252,7 +1252,7 @@ static int openvzNumDomains(virConnectPtr conn) { openvzDriverLock(driver); for (i = 0 ; i < driver->domains.count ; i++) { virDomainObjLock(driver->domains.objs[i]); - if (virDomainIsActive(driver->domains.objs[i])) + if (virDomainObjIsActive(driver->domains.objs[i])) nactive++; virDomainObjUnlock(driver->domains.objs[i]); } @@ -1355,7 +1355,7 @@ static int openvzNumDefinedDomains(virConnectPtr conn) { openvzDriverLock(driver); for (i = 0 ; i < driver->domains.count ; i++) { virDomainObjLock(driver->domains.objs[i]); - if (!virDomainIsActive(driver->domains.objs[i])) + if (!virDomainObjIsActive(driver->domains.objs[i])) ninactive++; virDomainObjUnlock(driver->domains.objs[i]); } diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index d37b184..03e8457 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -219,7 +219,7 @@ qemudAutostartConfigs(struct qemud_driver *driver) { virDomainObjPtr vm = driver->domains.objs[i]; virDomainObjLock(vm); if (vm->autostart && - !virDomainIsActive(vm)) { + !virDomainObjIsActive(vm)) { int ret; virResetLastError(); @@ -689,7 +689,7 @@ qemudActive(void) { for (i = 0 ; i < qemu_driver->domains.count ; i++) { virDomainObjPtr vm = qemu_driver->domains.objs[i]; virDomainObjLock(vm); - if (virDomainIsActive(vm)) + if (virDomainObjIsActive(vm)) active = 1; virDomainObjUnlock(vm); } @@ -1964,7 +1964,7 @@ static int qemudStartVMDaemon(virConnectPtr conn, FD_ZERO(&keepfd); - if (virDomainIsActive(vm)) { + if (virDomainObjIsActive(vm)) { qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_INVALID, "%s", _("VM is already active")); return -1; @@ -2171,7 +2171,7 @@ static void qemudShutdownVMDaemon(virConnectPtr conn, int ret; int retries = 0; - if (!virDomainIsActive(vm)) + if (!virDomainObjIsActive(vm)) return; VIR_DEBUG(_("Shutting down VM '%s'\n"), vm->def->name); @@ -2265,7 +2265,7 @@ qemudDispatchVMEvent(int watch, int fd, int events, void *opaque) { for (i = 0 ; i < driver->domains.count ; i++) { virDomainObjPtr tmpvm = driver->domains.objs[i]; virDomainObjLock(tmpvm); - if (virDomainIsActive(tmpvm) && + if (virDomainObjIsActive(tmpvm) && tmpvm->monitorWatch == watch) { vm = tmpvm; break; @@ -2642,7 +2642,7 @@ static int qemudListDomains(virConnectPtr conn, int *ids, int nids) { qemuDriverLock(driver); for (i = 0 ; i < driver->domains.count && got < nids ; i++) { virDomainObjLock(driver->domains.objs[i]); - if (virDomainIsActive(driver->domains.objs[i])) + if (virDomainObjIsActive(driver->domains.objs[i])) ids[got++] = driver->domains.objs[i]->def->id; virDomainObjUnlock(driver->domains.objs[i]); } @@ -2658,7 +2658,7 @@ static int qemudNumDomains(virConnectPtr conn) { qemuDriverLock(driver); for (i = 0 ; i < driver->domains.count ; i++) { virDomainObjLock(driver->domains.objs[i]); - if (virDomainIsActive(driver->domains.objs[i])) + if (virDomainObjIsActive(driver->domains.objs[i])) n++; virDomainObjUnlock(driver->domains.objs[i]); } @@ -2697,7 +2697,7 @@ static virDomainPtr qemudDomainCreate(virConnectPtr conn, const char *xml, } /* UUID & name match, but if VM is already active, refuse it */ - if (virDomainIsActive(vm)) { + if (virDomainObjIsActive(vm)) { qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_FAILED, _("domain is already active as '%s'"), vm->def->name); goto cleanup; @@ -2764,7 +2764,7 @@ static int qemudDomainSuspend(virDomainPtr dom) { _("no domain with matching uuid '%s'"), uuidstr); goto cleanup; } - if (!virDomainIsActive(vm)) { + if (!virDomainObjIsActive(vm)) { qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_INVALID, "%s", _("domain is not running")); goto cleanup; @@ -2808,7 +2808,7 @@ static int qemudDomainResume(virDomainPtr dom) { _("no domain with matching uuid '%s'"), uuidstr); goto cleanup; } - if (!virDomainIsActive(vm)) { + if (!virDomainObjIsActive(vm)) { qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_INVALID, "%s", _("domain is not running")); goto cleanup; @@ -2856,7 +2856,7 @@ static int qemudDomainShutdown(virDomainPtr dom) { goto cleanup; } - if (!virDomainIsActive(vm)) { + if (!virDomainObjIsActive(vm)) { qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_INVALID, "%s", _("domain is not running")); goto cleanup; @@ -2889,7 +2889,7 @@ static int qemudDomainDestroy(virDomainPtr dom) { _("no domain with matching uuid '%s'"), uuidstr); goto cleanup; } - if (!virDomainIsActive(vm)) { + if (!virDomainObjIsActive(vm)) { qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_INVALID, "%s", _("domain is not running")); goto cleanup; @@ -3022,7 +3022,7 @@ static int qemudDomainSetMemory(virDomainPtr dom, unsigned long newmem) { goto cleanup; } - if (virDomainIsActive(vm)) { + if (virDomainObjIsActive(vm)) { int r = qemuMonitorSetBalloon(vm, newmem); if (r < 0) goto cleanup; @@ -3065,7 +3065,7 @@ static int qemudDomainGetInfo(virDomainPtr dom, info->state = vm->state; - if (!virDomainIsActive(vm)) { + if (!virDomainObjIsActive(vm)) { info->cpuTime = 0; } else { if (qemudGetProcessInfo(&(info->cpuTime), NULL, vm->pid, 0) < 0) { @@ -3076,7 +3076,7 @@ static int qemudDomainGetInfo(virDomainPtr dom, info->maxMem = vm->def->maxmem; - if (virDomainIsActive(vm)) { + if (virDomainObjIsActive(vm)) { err = qemuMonitorGetBalloonInfo(vm, &balloon); if (err < 0) goto cleanup; @@ -3176,7 +3176,7 @@ static int qemudDomainSave(virDomainPtr dom, goto cleanup; } - if (!virDomainIsActive(vm)) { + if (!virDomainObjIsActive(vm)) { qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_INVALID, "%s", _("domain is not running")); goto cleanup; @@ -3292,7 +3292,7 @@ static int qemudDomainCoreDump(virDomainPtr dom, goto cleanup; } - if (!virDomainIsActive(vm)) { + if (!virDomainObjIsActive(vm)) { qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_INVALID, "%s", _("domain is not running")); goto cleanup; @@ -3349,7 +3349,7 @@ static int qemudDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus) { goto cleanup; } - if (virDomainIsActive(vm)) { + if (virDomainObjIsActive(vm)) { qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_INVALID, "%s", _("cannot change vcpu count of an active domain")); goto cleanup; @@ -3410,7 +3410,7 @@ qemudDomainPinVcpu(virDomainPtr dom, goto cleanup; } - if (!virDomainIsActive(vm)) { + if (!virDomainObjIsActive(vm)) { qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_INVALID, "%s",_("cannot pin vcpus on an inactive domain")); goto cleanup; @@ -3479,7 +3479,7 @@ qemudDomainGetVcpus(virDomainPtr dom, goto cleanup; } - if (!virDomainIsActive(vm)) { + if (!virDomainObjIsActive(vm)) { qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_INVALID, "%s",_("cannot pin vcpus on an inactive domain")); goto cleanup; @@ -3624,7 +3624,7 @@ static int qemudDomainGetSecurityLabel(virDomainPtr dom, virSecurityLabelPtr sec * after reading the label, by checking that our FD connecting to the * QEMU monitor hasn't seen SIGHUP/ERR on poll(). */ - if (virDomainIsActive(vm)) { + if (virDomainObjIsActive(vm)) { if (driver->securityDriver && driver->securityDriver->domainGetSecurityLabel) { if (driver->securityDriver->domainGetSecurityLabel(dom->conn, vm, seclabel) == -1) { qemudReportError(dom->conn, dom, NULL, VIR_ERR_INTERNAL_ERROR, @@ -3756,7 +3756,7 @@ static int qemudDomainRestore(virConnectPtr conn, } /* UUID & name match, but if VM is already active, refuse it */ - if (virDomainIsActive(vm)) { + if (virDomainObjIsActive(vm)) { qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_INVALID, _("domain is already active as '%s'"), vm->def->name); goto cleanup; @@ -3879,7 +3879,7 @@ static char *qemudDomainDumpXML(virDomainPtr dom, } /* Refresh current memory based on balloon info */ - if (virDomainIsActive(vm)) { + if (virDomainObjIsActive(vm)) { err = qemuMonitorGetBalloonInfo(vm, &balloon); if (err < 0) goto cleanup; @@ -4064,7 +4064,7 @@ static int qemudListDefinedDomains(virConnectPtr conn, qemuDriverLock(driver); for (i = 0 ; i < driver->domains.count && got < nnames ; i++) { virDomainObjLock(driver->domains.objs[i]); - if (!virDomainIsActive(driver->domains.objs[i])) { + if (!virDomainObjIsActive(driver->domains.objs[i])) { if (!(names[got++] = strdup(driver->domains.objs[i]->def->name))) { virReportOOMError(conn); virDomainObjUnlock(driver->domains.objs[i]); @@ -4090,7 +4090,7 @@ static int qemudNumDefinedDomains(virConnectPtr conn) { qemuDriverLock(driver); for (i = 0 ; i < driver->domains.count ; i++) - if (!virDomainIsActive(driver->domains.objs[i])) + if (!virDomainObjIsActive(driver->domains.objs[i])) n++; qemuDriverUnlock(driver); @@ -4333,7 +4333,7 @@ static int qemudDomainUndefine(virDomainPtr dom) { goto cleanup; } - if (virDomainIsActive(vm)) { + if (virDomainObjIsActive(vm)) { qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_INVALID, "%s", _("cannot delete active domain")); goto cleanup; @@ -4791,7 +4791,7 @@ static int qemudDomainAttachDevice(virDomainPtr dom, goto cleanup; } - if (!virDomainIsActive(vm)) { + if (!virDomainObjIsActive(vm)) { qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_INVALID, "%s", _("cannot attach device on inactive domain")); goto cleanup; @@ -5147,7 +5147,7 @@ static int qemudDomainDetachDevice(virDomainPtr dom, goto cleanup; } - if (!virDomainIsActive(vm)) { + if (!virDomainObjIsActive(vm)) { qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_INVALID, "%s", _("cannot detach device on inactive domain")); goto cleanup; @@ -5462,7 +5462,7 @@ qemudDomainBlockStats (virDomainPtr dom, _("no domain with matching uuid '%s'"), uuidstr); goto cleanup; } - if (!virDomainIsActive (vm)) { + if (!virDomainObjIsActive (vm)) { qemudReportError (dom->conn, dom, NULL, VIR_ERR_OPERATION_INVALID, "%s", _("domain is not running")); goto cleanup; @@ -5525,7 +5525,7 @@ qemudDomainInterfaceStats (virDomainPtr dom, goto cleanup; } - if (!virDomainIsActive(vm)) { + if (!virDomainObjIsActive(vm)) { qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_INVALID, "%s", _("domain is not running")); goto cleanup; @@ -5664,7 +5664,7 @@ qemudDomainMemoryPeek (virDomainPtr dom, goto cleanup; } - if (!virDomainIsActive(vm)) { + if (!virDomainObjIsActive(vm)) { qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_INVALID, "%s", _("domain is not running")); goto cleanup; @@ -6129,7 +6129,7 @@ qemudDomainMigratePrepareTunnel(virConnectPtr dconn, if (!vm) vm = virDomainFindByName(&driver->domains, dname); if (vm) { - if (virDomainIsActive(vm)) { + if (virDomainObjIsActive(vm)) { qemudReportError(dconn, NULL, NULL, VIR_ERR_OPERATION_FAILED, _("domain with the same name or UUID already exists as '%s'"), vm->def->name); @@ -6350,7 +6350,7 @@ qemudDomainMigratePrepare2 (virConnectPtr dconn, if (!vm) vm = virDomainFindByName(&driver->domains, dname); if (vm) { - if (virDomainIsActive(vm)) { + if (virDomainObjIsActive(vm)) { qemudReportError (dconn, NULL, NULL, VIR_ERR_OPERATION_FAILED, _("domain with the same name or UUID already exists as '%s'"), vm->def->name); @@ -6811,7 +6811,7 @@ qemudDomainMigratePerform (virDomainPtr dom, goto cleanup; } - if (!virDomainIsActive(vm)) { + if (!virDomainObjIsActive(vm)) { qemudReportError (dom->conn, dom, NULL, VIR_ERR_OPERATION_INVALID, "%s", _("domain is not running")); goto cleanup; diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 0541a73..b0f91de 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1040,7 +1040,7 @@ static int testNumOfDomains(virConnectPtr conn) testDriverLock(privconn); for (i = 0 ; i < privconn->domains.count ; i++) - if (virDomainIsActive(privconn->domains.objs[i])) + if (virDomainObjIsActive(privconn->domains.objs[i])) numActive++; testDriverUnlock(privconn); @@ -1178,7 +1178,7 @@ static int testListDomains (virConnectPtr conn, testDriverLock(privconn); for (i = 0 ; i < privconn->domains.count && n < maxids ; i++) { virDomainObjLock(privconn->domains.objs[i]); - if (virDomainIsActive(privconn->domains.objs[i])) + if (virDomainObjIsActive(privconn->domains.objs[i])) ids[n++] = privconn->domains.objs[i]->def->id; virDomainObjUnlock(privconn->domains.objs[i]); } @@ -1857,7 +1857,7 @@ static int testNumOfDefinedDomains(virConnectPtr conn) { testDriverLock(privconn); for (i = 0 ; i < privconn->domains.count ; i++) { virDomainObjLock(privconn->domains.objs[i]); - if (!virDomainIsActive(privconn->domains.objs[i])) + if (!virDomainObjIsActive(privconn->domains.objs[i])) numInactive++; virDomainObjUnlock(privconn->domains.objs[i]); } @@ -1876,7 +1876,7 @@ static int testListDefinedDomains(virConnectPtr conn, memset(names, 0, sizeof(*names)*maxnames); for (i = 0 ; i < privconn->domains.count && n < maxnames ; i++) { virDomainObjLock(privconn->domains.objs[i]); - if (!virDomainIsActive(privconn->domains.objs[i]) && + if (!virDomainObjIsActive(privconn->domains.objs[i]) && !(names[n++] = strdup(privconn->domains.objs[i]->def->name))) { virDomainObjUnlock(privconn->domains.objs[i]); goto no_memory; @@ -2362,7 +2362,7 @@ static int testNumNetworks(virConnectPtr conn) { testDriverLock(privconn); for (i = 0 ; i < privconn->networks.count ; i++) { virNetworkObjLock(privconn->networks.objs[i]); - if (virNetworkIsActive(privconn->networks.objs[i])) + if (virNetworkObjIsActive(privconn->networks.objs[i])) numActive++; virNetworkObjUnlock(privconn->networks.objs[i]); } @@ -2379,7 +2379,7 @@ static int testListNetworks(virConnectPtr conn, char **const names, int nnames) memset(names, 0, sizeof(*names)*nnames); for (i = 0 ; i < privconn->networks.count && n < nnames ; i++) { virNetworkObjLock(privconn->networks.objs[i]); - if (virNetworkIsActive(privconn->networks.objs[i]) && + if (virNetworkObjIsActive(privconn->networks.objs[i]) && !(names[n++] = strdup(privconn->networks.objs[i]->def->name))) { virNetworkObjUnlock(privconn->networks.objs[i]); goto no_memory; @@ -2405,7 +2405,7 @@ static int testNumDefinedNetworks(virConnectPtr conn) { testDriverLock(privconn); for (i = 0 ; i < privconn->networks.count ; i++) { virNetworkObjLock(privconn->networks.objs[i]); - if (!virNetworkIsActive(privconn->networks.objs[i])) + if (!virNetworkObjIsActive(privconn->networks.objs[i])) numInactive++; virNetworkObjUnlock(privconn->networks.objs[i]); } @@ -2422,7 +2422,7 @@ static int testListDefinedNetworks(virConnectPtr conn, char **const names, int n memset(names, 0, sizeof(*names)*nnames); for (i = 0 ; i < privconn->networks.count && n < nnames ; i++) { virNetworkObjLock(privconn->networks.objs[i]); - if (!virNetworkIsActive(privconn->networks.objs[i]) && + if (!virNetworkObjIsActive(privconn->networks.objs[i]) && !(names[n++] = strdup(privconn->networks.objs[i]->def->name))) { virNetworkObjUnlock(privconn->networks.objs[i]); goto no_memory; @@ -2505,7 +2505,7 @@ static int testNetworkUndefine(virNetworkPtr network) { goto cleanup; } - if (virNetworkIsActive(privnet)) { + if (virNetworkObjIsActive(privnet)) { testError(network->conn, VIR_ERR_INTERNAL_ERROR, _("Network '%s' is still running"), network->name); goto cleanup; @@ -2538,7 +2538,7 @@ static int testNetworkStart(virNetworkPtr network) { goto cleanup; } - if (virNetworkIsActive(privnet)) { + if (virNetworkObjIsActive(privnet)) { testError(network->conn, VIR_ERR_INTERNAL_ERROR, _("Network '%s' is already running"), network->name); goto cleanup; @@ -2719,7 +2719,7 @@ static int testNumOfInterfaces(virConnectPtr conn) testDriverLock(privconn); for (i = 0 ; (i < privconn->ifaces.count); i++) { virInterfaceObjLock(privconn->ifaces.objs[i]); - if (virInterfaceIsActive(privconn->ifaces.objs[i])) { + if (virInterfaceObjIsActive(privconn->ifaces.objs[i])) { count++; } virInterfaceObjUnlock(privconn->ifaces.objs[i]); @@ -2737,7 +2737,7 @@ static int testListInterfaces(virConnectPtr conn, char **const names, int nnames memset(names, 0, sizeof(*names)*nnames); for (i = 0 ; (i < privconn->ifaces.count) && (n < nnames); i++) { virInterfaceObjLock(privconn->ifaces.objs[i]); - if (virInterfaceIsActive(privconn->ifaces.objs[i])) { + if (virInterfaceObjIsActive(privconn->ifaces.objs[i])) { if (!(names[n++] = strdup(privconn->ifaces.objs[i]->def->name))) { virInterfaceObjUnlock(privconn->ifaces.objs[i]); goto no_memory; @@ -2765,7 +2765,7 @@ static int testNumOfDefinedInterfaces(virConnectPtr conn) testDriverLock(privconn); for (i = 0 ; i < privconn->ifaces.count; i++) { virInterfaceObjLock(privconn->ifaces.objs[i]); - if (!virInterfaceIsActive(privconn->ifaces.objs[i])) { + if (!virInterfaceObjIsActive(privconn->ifaces.objs[i])) { count++; } virInterfaceObjUnlock(privconn->ifaces.objs[i]); @@ -2783,7 +2783,7 @@ static int testListDefinedInterfaces(virConnectPtr conn, char **const names, int memset(names, 0, sizeof(*names)*nnames); for (i = 0 ; (i < privconn->ifaces.count) && (n < nnames); i++) { virInterfaceObjLock(privconn->ifaces.objs[i]); - if (!virInterfaceIsActive(privconn->ifaces.objs[i])) { + if (!virInterfaceObjIsActive(privconn->ifaces.objs[i])) { if (!(names[n++] = strdup(privconn->ifaces.objs[i]->def->name))) { virInterfaceObjUnlock(privconn->ifaces.objs[i]); goto no_memory; diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index 9a7fe42..6f60592 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -130,7 +130,7 @@ umlAutostartConfigs(struct uml_driver *driver) { for (i = 0 ; i < driver->domains.count ; i++) { if (driver->domains.objs[i]->autostart && - !virDomainIsActive(driver->domains.objs[i]) && + !virDomainObjIsActive(driver->domains.objs[i]) && umlStartVMDaemon(conn, driver, driver->domains.objs[i]) < 0) { virErrorPtr err = virGetLastError(); VIR_ERROR(_("Failed to autostart VM '%s': %s"), @@ -257,7 +257,7 @@ reread: if (e->mask & IN_DELETE) { VIR_DEBUG("Got inotify domain shutdown '%s'", name); - if (!virDomainIsActive(dom)) { + if (!virDomainObjIsActive(dom)) { virDomainObjUnlock(dom); continue; } @@ -265,7 +265,7 @@ reread: umlShutdownVMDaemon(NULL, driver, dom); } else if (e->mask & (IN_CREATE | IN_MODIFY)) { VIR_DEBUG("Got inotify domain startup '%s'", name); - if (virDomainIsActive(dom)) { + if (virDomainObjIsActive(dom)) { virDomainObjUnlock(dom); continue; } @@ -458,7 +458,7 @@ umlActive(void) { umlDriverLock(uml_driver); for (i = 0 ; i < uml_driver->domains.count ; i++) { virDomainObjLock(uml_driver->domains.objs[i]); - if (virDomainIsActive(uml_driver->domains.objs[i])) + if (virDomainObjIsActive(uml_driver->domains.objs[i])) active = 1; virDomainObjUnlock(uml_driver->domains.objs[i]); } @@ -489,7 +489,7 @@ umlShutdown(void) { for (i = 0 ; i < uml_driver->domains.count ; i++) { virDomainObjPtr dom = uml_driver->domains.objs[i]; virDomainObjLock(dom); - if (virDomainIsActive(dom)) + if (virDomainObjIsActive(dom)) umlShutdownVMDaemon(NULL, uml_driver, dom); virDomainObjUnlock(dom); } @@ -766,7 +766,7 @@ static int umlStartVMDaemon(virConnectPtr conn, FD_ZERO(&keepfd); - if (virDomainIsActive(vm)) { + if (virDomainObjIsActive(vm)) { umlReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s", _("VM is already active")); return -1; @@ -882,7 +882,7 @@ static void umlShutdownVMDaemon(virConnectPtr conn ATTRIBUTE_UNUSED, virDomainObjPtr vm) { int ret; - if (!virDomainIsActive(vm)) + if (!virDomainObjIsActive(vm)) return; virKillProcess(vm->pid, SIGTERM); @@ -1150,7 +1150,7 @@ static int umlListDomains(virConnectPtr conn, int *ids, int nids) { umlDriverLock(driver); for (i = 0 ; i < driver->domains.count && got < nids ; i++) { virDomainObjLock(driver->domains.objs[i]); - if (virDomainIsActive(driver->domains.objs[i])) + if (virDomainObjIsActive(driver->domains.objs[i])) ids[got++] = driver->domains.objs[i]->def->id; virDomainObjUnlock(driver->domains.objs[i]); } @@ -1165,7 +1165,7 @@ static int umlNumDomains(virConnectPtr conn) { umlDriverLock(driver); for (i = 0 ; i < driver->domains.count ; i++) { virDomainObjLock(driver->domains.objs[i]); - if (virDomainIsActive(driver->domains.objs[i])) + if (virDomainObjIsActive(driver->domains.objs[i])) n++; virDomainObjUnlock(driver->domains.objs[i]); } @@ -1389,7 +1389,7 @@ static int umlDomainSetMemory(virDomainPtr dom, unsigned long newmem) { goto cleanup; } - if (virDomainIsActive(vm)) { + if (virDomainObjIsActive(vm)) { umlReportError(dom->conn, dom, NULL, VIR_ERR_NO_SUPPORT, "%s", _("cannot set memory of an active domain")); goto cleanup; @@ -1428,7 +1428,7 @@ static int umlDomainGetInfo(virDomainPtr dom, info->state = vm->state; - if (!virDomainIsActive(vm)) { + if (!virDomainObjIsActive(vm)) { info->cpuTime = 0; } else { if (umlGetProcessInfo(&(info->cpuTime), vm->pid) < 0) { @@ -1486,7 +1486,7 @@ static int umlListDefinedDomains(virConnectPtr conn, umlDriverLock(driver); for (i = 0 ; i < driver->domains.count && got < nnames ; i++) { virDomainObjLock(driver->domains.objs[i]); - if (!virDomainIsActive(driver->domains.objs[i])) { + if (!virDomainObjIsActive(driver->domains.objs[i])) { if (!(names[got++] = strdup(driver->domains.objs[i]->def->name))) { virReportOOMError(conn); virDomainObjUnlock(driver->domains.objs[i]); @@ -1513,7 +1513,7 @@ static int umlNumDefinedDomains(virConnectPtr conn) { umlDriverLock(driver); for (i = 0 ; i < driver->domains.count ; i++) { virDomainObjLock(driver->domains.objs[i]); - if (!virDomainIsActive(driver->domains.objs[i])) + if (!virDomainObjIsActive(driver->domains.objs[i])) n++; virDomainObjUnlock(driver->domains.objs[i]); } @@ -1598,7 +1598,7 @@ static int umlDomainUndefine(virDomainPtr dom) { goto cleanup; } - if (virDomainIsActive(vm)) { + if (virDomainObjIsActive(vm)) { umlReportError(dom->conn, dom, NULL, VIR_ERR_INTERNAL_ERROR, "%s", _("cannot delete active domain")); goto cleanup; -- 1.6.2.5

2009/10/21 Daniel P. Berrange <berrange@redhat.com>:
--- src/conf/domain_conf.c | 4 +- src/conf/domain_conf.h | 2 +- src/conf/interface_conf.h | 2 +- src/conf/network_conf.c | 2 +- src/conf/network_conf.h | 2 +- src/lxc/lxc_driver.c | 24 +++++++------- src/network/bridge_driver.c | 20 ++++++------ src/opennebula/one_driver.c | 12 ++++---- src/openvz/openvz_driver.c | 8 ++-- src/qemu/qemu_driver.c | 68 +++++++++++++++++++++--------------------- src/test/test_driver.c | 28 +++++++++--------- src/uml/uml_driver.c | 28 +++++++++--------- 12 files changed, 100 insertions(+), 100 deletions(-)
ACK Matthias

On Wed, Oct 21, 2009 at 07:15:23PM +0100, Daniel P. Berrange wrote:
--- src/conf/domain_conf.c | 4 +- src/conf/domain_conf.h | 2 +- src/conf/interface_conf.h | 2 +- src/conf/network_conf.c | 2 +- src/conf/network_conf.h | 2 +- src/lxc/lxc_driver.c | 24 +++++++------- src/network/bridge_driver.c | 20 ++++++------ src/opennebula/one_driver.c | 12 ++++---- src/openvz/openvz_driver.c | 8 ++-- src/qemu/qemu_driver.c | 68 +++++++++++++++++++++--------------------- src/test/test_driver.c | 28 +++++++++--------- src/uml/uml_driver.c | 28 +++++++++--------- 12 files changed, 100 insertions(+), 100 deletions(-)
ACK, please push :-) Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

Introduce a number of new APIs to expose some boolean properties of objects, which cannot otherwise reliably determined, nor are aspects of the XML configuration. * virDomainIsActive: Checking virDomainGetID is not reliable since it is not possible to distinguish between error condition and inactive domain for ID of -1. * virDomainIsPersistent: Check whether a persistent config exists for the domain * virNetworkIsActive: Check whether the network is active * virNetworkIsPersistent: Check whether a persistent config exists for the network * virStoragePoolIsActive: Check whether the storage pool is active * virStoragePoolIsPersistent: Check whether a persistent config exists for the storage pool * virInterfaceIsActive: Check whether the host interface is active * virConnectIsSecure: whether the communication channel to the hypervisor is secure * virConnectIsEncrypted: whether any network based commnunication channels are encrypted NB, a channel can be secure, even if not encrypted, eg if it does not involve the network, like a UNIX socket, or pipe. --- include/libvirt/libvirt.h.in | 16 +++ src/driver.h | 34 +++++ src/esx/esx_driver.c | 4 + src/interface/netcf_driver.c | 1 + src/libvirt.c | 301 ++++++++++++++++++++++++++++++++++++++++++ src/libvirt_public.syms | 13 ++ src/lxc/lxc_driver.c | 4 + src/network/bridge_driver.c | 2 + src/opennebula/one_driver.c | 4 + src/openvz/openvz_driver.c | 4 + src/phyp/phyp_driver.c | 4 + src/qemu/qemu_driver.c | 4 + src/remote/remote_driver.c | 10 ++ src/test/test_driver.c | 10 ++ src/uml/uml_driver.c | 4 + src/vbox/vbox_tmpl.c | 4 + src/xen/xen_driver.c | 4 + 17 files changed, 423 insertions(+), 0 deletions(-) diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index 6186d4e..05a164b 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -1649,6 +1649,22 @@ int virStreamAbort(virStreamPtr st); int virStreamFree(virStreamPtr st); +int virDomainIsActive(virDomainPtr dom); +int virDomainIsPersistent(virDomainPtr dom); + +int virNetworkIsActive(virNetworkPtr net); +int virNetworkIsPersistent(virNetworkPtr net); + +int virStoragePoolIsActive(virStoragePoolPtr pool); +int virStoragePoolIsPersistent(virStoragePoolPtr pool); + +int virInterfaceIsActive(virInterfacePtr iface); + +int virConnectIsEncrypted(virConnectPtr conn); +int virConnectIsSecure(virConnectPtr conn); + + + #ifdef __cplusplus } #endif diff --git a/src/driver.h b/src/driver.h index 0c8f923..7ab915d 100644 --- a/src/driver.h +++ b/src/driver.h @@ -337,6 +337,15 @@ typedef int unsigned long resource, const char *dom_xml); +typedef int + (*virDrvConnectIsEncrypted)(virConnectPtr conn); +typedef int + (*virDrvConnectIsSecure)(virConnectPtr conn); +typedef int + (*virDrvDomainIsActive)(virDomainPtr dom); +typedef int + (*virDrvDomainIsPersistent)(virDomainPtr dom); + /** * _virDriver: * @@ -418,6 +427,10 @@ struct _virDriver { virDrvNodeDeviceReAttach nodeDeviceReAttach; virDrvNodeDeviceReset nodeDeviceReset; virDrvDomainMigratePrepareTunnel domainMigratePrepareTunnel; + virDrvConnectIsEncrypted isEncrypted; + virDrvConnectIsSecure isSecure; + virDrvDomainIsActive domainIsActive; + virDrvDomainIsPersistent domainIsPersistent; }; typedef int @@ -462,6 +475,12 @@ typedef int (*virDrvNetworkSetAutostart) (virNetworkPtr network, int autostart); +typedef int + (*virDrvNetworkIsActive)(virNetworkPtr net); +typedef int + (*virDrvNetworkIsPersistent)(virNetworkPtr net); + + typedef struct _virNetworkDriver virNetworkDriver; typedef virNetworkDriver *virNetworkDriverPtr; @@ -495,6 +514,8 @@ struct _virNetworkDriver { virDrvNetworkGetBridgeName networkGetBridgeName; virDrvNetworkGetAutostart networkGetAutostart; virDrvNetworkSetAutostart networkSetAutostart; + virDrvNetworkIsActive networkIsActive; + virDrvNetworkIsPersistent networkIsPersistent; }; /*-------*/ @@ -534,6 +555,10 @@ typedef int (*virDrvInterfaceDestroy) (virInterfacePtr iface, unsigned int flags); +typedef int + (*virDrvInterfaceIsActive)(virInterfacePtr iface); + + typedef struct _virInterfaceDriver virInterfaceDriver; typedef virInterfaceDriver *virInterfaceDriverPtr; @@ -562,6 +587,7 @@ struct _virInterfaceDriver { virDrvInterfaceUndefine interfaceUndefine; virDrvInterfaceCreate interfaceCreate; virDrvInterfaceDestroy interfaceDestroy; + virDrvInterfaceIsActive interfaceIsActive; }; @@ -668,6 +694,12 @@ typedef virStorageVolPtr virStorageVolPtr clone, unsigned int flags); +typedef int + (*virDrvStoragePoolIsActive)(virStoragePoolPtr pool); +typedef int + (*virDrvStoragePoolIsPersistent)(virStoragePoolPtr pool); + + typedef struct _virStorageDriver virStorageDriver; typedef virStorageDriver *virStorageDriverPtr; @@ -719,6 +751,8 @@ struct _virStorageDriver { virDrvStorageVolGetInfo volGetInfo; virDrvStorageVolGetXMLDesc volGetXMLDesc; virDrvStorageVolGetPath volGetPath; + virDrvStoragePoolIsPersistent poolIsActive; + virDrvStoragePoolIsPersistent poolIsPersistent; }; #ifdef WITH_LIBVIRTD diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index e063b46..3a57613 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -3275,6 +3275,10 @@ static virDriver esxDriver = { NULL, /* nodeDeviceReAttach */ NULL, /* nodeDeviceReset */ NULL, /* domainMigratePrepareTunnel */ + NULL, /* isEncrypted */ + NULL, /* isSecure */ + NULL, /* domainIsActive */ + NULL, /* domainIsEncrypted */ }; diff --git a/src/interface/netcf_driver.c b/src/interface/netcf_driver.c index ca14fb0..6742bbb 100644 --- a/src/interface/netcf_driver.c +++ b/src/interface/netcf_driver.c @@ -522,6 +522,7 @@ static virInterfaceDriver interfaceDriver = { interfaceUndefine, /* interfaceUndefine */ interfaceCreate, /* interfaceCreate */ interfaceDestroy, /* interfaceDestroy */ + NULL, /* interfaceIsActive */ }; int interfaceRegister(void) { diff --git a/src/libvirt.c b/src/libvirt.c index 9e87900..3244489 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -10321,3 +10321,304 @@ int virStreamFree(virStreamPtr stream) return (-1); return (0); } + + +/** + * virDomainIsActive: + * + * Determine if the domain is currently running + * + * Returns 1 if running, 0 if inactive, -1 on error + */ +int virDomainIsActive(virDomainPtr dom) +{ + DEBUG("dom=%p", dom); + + virResetLastError(); + + if (!VIR_IS_CONNECTED_DOMAIN(dom)) { + virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__); + return (-1); + } + if (dom->conn->driver->domainIsActive) { + int ret; + ret = dom->conn->driver->domainIsActive(dom); + if (ret < 0) + goto error; + return ret; + } + + virLibConnError(dom->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__); +error: + /* Copy to connection error object for back compatability */ + virSetConnError(dom->conn); + return -1; +} + +/** + * virDomainIsPersistent: + * + * Determine if the domain has a persistent configuration + * which means it will still exist after shutting down + * + * Returns 1 if persistent, 0 if transient, -1 on error + */ +int virDomainIsPersistent(virDomainPtr dom) +{ + DEBUG("dom=%p", dom); + + virResetLastError(); + + if (!VIR_IS_CONNECTED_DOMAIN(dom)) { + virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__); + return (-1); + } + if (dom->conn->driver->domainIsPersistent) { + int ret; + ret = dom->conn->driver->domainIsPersistent(dom); + if (ret < 0) + goto error; + return ret; + } + + virLibConnError(dom->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__); +error: + /* Copy to connection error object for back compatability */ + virSetConnError(dom->conn); + return -1; +} + +/** + * virNetworkIsActive: + * + * Determine if the network is currently running + * + * Returns 1 if running, 0 if inactive, -1 on error + */ +int virNetworkIsActive(virNetworkPtr net) +{ + DEBUG("net=%p", net); + + virResetLastError(); + + if (!VIR_IS_CONNECTED_NETWORK(net)) { + virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__); + return (-1); + } + if (net->conn->networkDriver->networkIsActive) { + int ret; + ret = net->conn->networkDriver->networkIsActive(net); + if (ret < 0) + goto error; + return ret; + } + + virLibConnError(net->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__); +error: + /* Copy to connection error object for back compatability */ + virSetConnError(net->conn); + return -1; +} + + +/** + * virNetworkIsPersistent: + * + * Determine if the network has a persistent configuration + * which means it will still exist after shutting down + * + * Returns 1 if persistent, 0 if transient, -1 on error + */ +int virNetworkIsPersistent(virNetworkPtr net) +{ + DEBUG("net=%p", net); + + virResetLastError(); + + if (!VIR_IS_CONNECTED_NETWORK(net)) { + virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__); + return (-1); + } + if (net->conn->networkDriver->networkIsPersistent) { + int ret; + ret = net->conn->networkDriver->networkIsPersistent(net); + if (ret < 0) + goto error; + return ret; + } + + virLibConnError(net->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__); +error: + /* Copy to connection error object for back compatability */ + virSetConnError(net->conn); + return -1; +} + + +/** + * virStoragePoolIsActive: + * + * Determine if the storage pool is currently running + * + * Returns 1 if running, 0 if inactive, -1 on error + */ +int virStoragePoolIsActive(virStoragePoolPtr pool) +{ + DEBUG("pool=%p", pool); + + virResetLastError(); + + if (!VIR_IS_CONNECTED_STORAGE_POOL(pool)) { + virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__); + return (-1); + } + if (pool->conn->storageDriver->poolIsActive) { + int ret; + ret = pool->conn->storageDriver->poolIsActive(pool); + if (ret < 0) + goto error; + return ret; + } + + virLibConnError(pool->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__); +error: + /* Copy to connection error object for back compatability */ + virSetConnError(pool->conn); + return -1; +} + + +/** + * virStoragePoolIsPersistent: + * + * Determine if the storagepool has a persistent configuration + * which means it will still exist after shutting down + * + * Returns 1 if persistent, 0 if transient, -1 on error + */ +int virStoragePoolIsPersistent(virStoragePoolPtr pool) +{ + DEBUG("pool=%p", pool); + + virResetLastError(); + + if (!VIR_IS_CONNECTED_STORAGE_POOL(pool)) { + virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__); + return (-1); + } + if (pool->conn->storageDriver->poolIsPersistent) { + int ret; + ret = pool->conn->storageDriver->poolIsPersistent(pool); + if (ret < 0) + goto error; + return ret; + } + + virLibConnError(pool->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__); +error: + /* Copy to connection error object for back compatability */ + virSetConnError(pool->conn); + return -1; +} + + +/** + * virInterfaceIsActive: + * + * Determine if the interface is currently running + * + * Returns 1 if running, 0 if inactive, -1 on error + */ +int virInterfaceIsActive(virInterfacePtr iface) +{ + DEBUG("iface=%p", iface); + + virResetLastError(); + + if (!VIR_IS_CONNECTED_INTERFACE(iface)) { + virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__); + return (-1); + } + if (iface->conn->interfaceDriver->interfaceIsActive) { + int ret; + ret = iface->conn->interfaceDriver->interfaceIsActive(iface); + if (ret < 0) + goto error; + return ret; + } + + virLibConnError(iface->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__); +error: + /* Copy to connection error object for back compatability */ + virSetConnError(iface->conn); + return -1; +} + + +/** + * virConnectIsEncrypted: + * + * Determine if the connection to the hypervisor is encrypted + * + * Returns 1 if encrypted, 0 if not encrypted, -1 on error + */ +int virConnectIsEncrypted(virConnectPtr conn) +{ + DEBUG("conn=%p", conn); + + virResetLastError(); + + if (!VIR_IS_CONNECT(conn)) { + virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__); + return (-1); + } + if (conn->driver->isEncrypted) { + int ret; + ret = conn->driver->isEncrypted(conn); + if (ret < 0) + goto error; + return ret; + } + + virLibConnError(conn, VIR_ERR_NO_SUPPORT, __FUNCTION__); +error: + /* Copy to connection error object for back compatability */ + virSetConnError(conn); + return -1; +} + +/** + * virConnectIsSecure: + * + * Determine if the connection to the hypervisor is secure + * + * A connection will be classed as secure if it is either + * encrypted, or running over a channel which is not exposed + * to eavesdropping (eg a UNIX domain socket, or pipe) + * + * Returns 1 if secure, 0 if secure, -1 on error + */ +int virConnectIsSecure(virConnectPtr conn) +{ + DEBUG("conn=%p", conn); + + virResetLastError(); + + if (!VIR_IS_CONNECT(conn)) { + virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__); + return (-1); + } + if (conn->driver->isSecure) { + int ret; + ret = conn->driver->isSecure(conn); + if (ret < 0) + goto error; + return ret; + } + + virLibConnError(conn, VIR_ERR_NO_SUPPORT, __FUNCTION__); +error: + /* Copy to connection error object for back compatability */ + virSetConnError(conn); + return -1; +} diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 8921c1a..62fa6cf 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -329,4 +329,17 @@ LIBVIRT_0.7.2 { virDomainMigrateToURI; } LIBVIRT_0.7.1; +LIBVIRT_0.7.4 { + global: + virConnectIsEncrypted; + virConnectIsSecure; + virDomainIsActive; + virDomainIsPersistent; + virNetworkIsActive; + virNetworkIsPersistent; + virStoragePoolIsActive; + virStoragePoolIsPersistent; + virInterfaceIsActive; +} LIBVIRT_0.7.2; + # .... define new API here using predicted next version number .... diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 8224376..92502fe 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -2348,6 +2348,10 @@ static virDriver lxcDriver = { NULL, /* nodeDeviceReAttach */ NULL, /* nodeDeviceReset */ NULL, /* domainMigratePrepareTunnel */ + NULL, /* isEncrypted */ + NULL, /* isSecure */ + NULL, /* domainIsActive */ + NULL, /* domainIsEncrypted */ }; static virStateDriver lxcStateDriver = { diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 3c62636..311838c 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -1497,6 +1497,8 @@ static virNetworkDriver networkDriver = { networkGetBridgeName, /* networkGetBridgeName */ networkGetAutostart, /* networkGetAutostart */ networkSetAutostart, /* networkSetAutostart */ + NULL, /* networkIsActive */ + NULL, /* networkIsEncrypted */ }; static virStateDriver networkStateDriver = { diff --git a/src/opennebula/one_driver.c b/src/opennebula/one_driver.c index 9c6f120..9707bf8 100644 --- a/src/opennebula/one_driver.c +++ b/src/opennebula/one_driver.c @@ -788,6 +788,10 @@ static virDriver oneDriver = { NULL, /* nodeDeviceReAttach; */ NULL, /* nodeDeviceReset; */ NULL, /* domainMigratePrepareTunnel */ + NULL, /* isEncrypted */ + NULL, /* isSecure */ + NULL, /* domainIsActive */ + NULL, /* domainIsEncrypted */ }; static virStateDriver oneStateDriver = { diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 57482b8..4d7f56c 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -1433,6 +1433,10 @@ static virDriver openvzDriver = { NULL, /* nodeDeviceReAttach */ NULL, /* nodeDeviceReset */ NULL, /* domainMigratePrepareTunnel */ + NULL, /* isEncrypted */ + NULL, /* isSecure */ + NULL, /* domainIsActive */ + NULL, /* domainIsEncrypted */ }; int openvzRegister(void) { diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index ef465ed..cd0e9a7 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -1378,6 +1378,10 @@ virDriver phypDriver = { NULL, /* nodeDeviceReAttach */ NULL, /* nodeDeviceReset */ NULL, /* domainMigratePrepareTunnel */ + NULL, /* isEncrypted */ + NULL, /* isSecure */ + NULL, /* domainIsActive */ + NULL, /* domainIsEncrypted */ }; int diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 03e8457..0264797 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7166,6 +7166,10 @@ static virDriver qemuDriver = { qemudNodeDeviceReAttach, /* nodeDeviceReAttach */ qemudNodeDeviceReset, /* nodeDeviceReset */ qemudDomainMigratePrepareTunnel, /* domainMigratePrepareTunnel */ + NULL, /* isEncrypted */ + NULL, /* isSecure */ + NULL, /* domainIsActive */ + NULL, /* domainIsEncrypted */ }; diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index bf001eb..9a265ac 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -8449,6 +8449,10 @@ static virDriver remote_driver = { remoteNodeDeviceReAttach, /* nodeDeviceReAttach */ remoteNodeDeviceReset, /* nodeDeviceReset */ remoteDomainMigratePrepareTunnel, /* domainMigratePrepareTunnel */ + NULL, /* isEncrypted */ + NULL, /* isSecure */ + NULL, /* domainIsActive */ + NULL, /* domainIsEncrypted */ }; static virNetworkDriver network_driver = { @@ -8470,6 +8474,8 @@ static virNetworkDriver network_driver = { .networkGetBridgeName = remoteNetworkGetBridgeName, .networkGetAutostart = remoteNetworkGetAutostart, .networkSetAutostart = remoteNetworkSetAutostart, + .networkIsActive = NULL, + .networkIsPersistent = NULL, }; static virInterfaceDriver interface_driver = { @@ -8487,6 +8493,7 @@ static virInterfaceDriver interface_driver = { .interfaceUndefine = remoteInterfaceUndefine, .interfaceCreate = remoteInterfaceCreate, .interfaceDestroy = remoteInterfaceDestroy, + .interfaceIsActive = NULL, /* interfaceIsActive */ }; static virStorageDriver storage_driver = { @@ -8525,6 +8532,9 @@ static virStorageDriver storage_driver = { .volGetInfo = remoteStorageVolGetInfo, .volGetXMLDesc = remoteStorageVolDumpXML, .volGetPath = remoteStorageVolGetPath, + + .poolIsActive = NULL, /* poolIsActive */ + .poolIsPersistent = NULL, /* poolIsEncrypted */ }; static virSecretDriver secret_driver = { diff --git a/src/test/test_driver.c b/src/test/test_driver.c index b0f91de..88dc6a5 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -4558,6 +4558,10 @@ static virDriver testDriver = { NULL, /* nodeDeviceReAttach */ NULL, /* nodeDeviceReset */ NULL, /* domainMigratePrepareTunnel */ + NULL, /* isEncrypted */ + NULL, /* isSecure */ + NULL, /* domainIsActive */ + NULL, /* domainIsEncrypted */ }; static virNetworkDriver testNetworkDriver = { @@ -4579,6 +4583,8 @@ static virNetworkDriver testNetworkDriver = { testNetworkGetBridgeName, /* networkGetBridgeName */ testNetworkGetAutostart, /* networkGetAutostart */ testNetworkSetAutostart, /* networkSetAutostart */ + NULL, /* networkIsActive */ + NULL, /* networkIsEncrypted */ }; static virInterfaceDriver testInterfaceDriver = { @@ -4596,6 +4602,7 @@ static virInterfaceDriver testInterfaceDriver = { testInterfaceUndefine, /* interfaceUndefine */ testInterfaceCreate, /* interfaceCreate */ testInterfaceDestroy, /* interfaceDestroy */ + NULL, /* interfaceIsActive */ }; @@ -4636,6 +4643,9 @@ static virStorageDriver testStorageDriver = { .volGetInfo = testStorageVolumeGetInfo, .volGetXMLDesc = testStorageVolumeGetXMLDesc, .volGetPath = testStorageVolumeGetPath, + + .poolIsActive = NULL, /* poolIsActive */ + .poolIsPersistent = NULL, /* poolIsEncrypted */ }; static virDeviceMonitor testDevMonitor = { diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index 6f60592..9b450d9 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -1862,6 +1862,10 @@ static virDriver umlDriver = { NULL, /* nodeDeviceReAttach */ NULL, /* nodeDeviceReset */ NULL, /* domainMigratePrepareTunnel */ + NULL, /* isEncrypted */ + NULL, /* isSecure */ + NULL, /* domainIsActive */ + NULL, /* domainIsEncrypted */ }; diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 4f43901..5878154 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -6468,6 +6468,10 @@ virDriver NAME(Driver) = { NULL, /* nodeDeviceReAttach */ NULL, /* nodeDeviceReset */ NULL, /* domainMigratePrepareTunnel */ + NULL, /* isEncrypted */ + NULL, /* isSecure */ + NULL, /* domainIsActive */ + NULL, /* domainIsEncrypted */ }; virNetworkDriver NAME(NetworkDriver) = { diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c index 5273a11..da05253 100644 --- a/src/xen/xen_driver.c +++ b/src/xen/xen_driver.c @@ -1726,6 +1726,10 @@ static virDriver xenUnifiedDriver = { xenUnifiedNodeDeviceReAttach, /* nodeDeviceReAttach */ xenUnifiedNodeDeviceReset, /* nodeDeviceReset */ NULL, /* domainMigratePrepareTunnel */ + NULL, /* isEncrypted */ + NULL, /* isSecure */ + NULL, /* domainIsActive */ + NULL, /* domainIsEncrypted */ }; /** -- 1.6.2.5

2009/10/21 Daniel P. Berrange <berrange@redhat.com>:
Introduce a number of new APIs to expose some boolean properties of objects, which cannot otherwise reliably determined, nor are aspects of the XML configuration.
* virDomainIsActive: Checking virDomainGetID is not reliable since it is not possible to distinguish between error condition and inactive domain for ID of -1. * virDomainIsPersistent: Check whether a persistent config exists for the domain
* virNetworkIsActive: Check whether the network is active * virNetworkIsPersistent: Check whether a persistent config exists for the network
* virStoragePoolIsActive: Check whether the storage pool is active * virStoragePoolIsPersistent: Check whether a persistent config exists for the storage pool
* virInterfaceIsActive: Check whether the host interface is active
* virConnectIsSecure: whether the communication channel to the hypervisor is secure * virConnectIsEncrypted: whether any network based commnunication channels are encrypted
NB, a channel can be secure, even if not encrypted, eg if it does not involve the network, like a UNIX socket, or pipe. --- include/libvirt/libvirt.h.in | 16 +++ src/driver.h | 34 +++++ src/esx/esx_driver.c | 4 + src/interface/netcf_driver.c | 1 + src/libvirt.c | 301 ++++++++++++++++++++++++++++++++++++++++++ src/libvirt_public.syms | 13 ++ src/lxc/lxc_driver.c | 4 + src/network/bridge_driver.c | 2 + src/opennebula/one_driver.c | 4 + src/openvz/openvz_driver.c | 4 + src/phyp/phyp_driver.c | 4 + src/qemu/qemu_driver.c | 4 + src/remote/remote_driver.c | 10 ++ src/test/test_driver.c | 10 ++ src/uml/uml_driver.c | 4 + src/vbox/vbox_tmpl.c | 4 + src/xen/xen_driver.c | 4 + 17 files changed, 423 insertions(+), 0 deletions(-)
[...]
diff --git a/src/driver.h b/src/driver.h index 0c8f923..7ab915d 100644 --- a/src/driver.h +++ b/src/driver.h [...]
@@ -668,6 +694,12 @@ typedef virStorageVolPtr virStorageVolPtr clone, unsigned int flags);
+typedef int + (*virDrvStoragePoolIsActive)(virStoragePoolPtr pool); +typedef int + (*virDrvStoragePoolIsPersistent)(virStoragePoolPtr pool); + +
typedef struct _virStorageDriver virStorageDriver; typedef virStorageDriver *virStorageDriverPtr; @@ -719,6 +751,8 @@ struct _virStorageDriver { virDrvStorageVolGetInfo volGetInfo; virDrvStorageVolGetXMLDesc volGetXMLDesc; virDrvStorageVolGetPath volGetPath; + virDrvStoragePoolIsPersistent poolIsActive; + virDrvStoragePoolIsPersistent poolIsPersistent; };
You added virDrvStoragePoolIsPersistent twice instead of virDrvStoragePoolIsActive once and virDrvStoragePoolIsPersistent once. I assume it compiles because the signature is the same.
#ifdef WITH_LIBVIRTD diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index e063b46..3a57613 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -3275,6 +3275,10 @@ static virDriver esxDriver = { NULL, /* nodeDeviceReAttach */ NULL, /* nodeDeviceReset */ NULL, /* domainMigratePrepareTunnel */ + NULL, /* isEncrypted */ + NULL, /* isSecure */ + NULL, /* domainIsActive */ + NULL, /* domainIsEncrypted */ };
s/domainIsEncrypted/domainIsPersistent/ [...]
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 8921c1a..62fa6cf 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -329,4 +329,17 @@ LIBVIRT_0.7.2 { virDomainMigrateToURI; } LIBVIRT_0.7.1;
+LIBVIRT_0.7.4 { + global: + virConnectIsEncrypted; + virConnectIsSecure; + virDomainIsActive; + virDomainIsPersistent; + virNetworkIsActive; + virNetworkIsPersistent; + virStoragePoolIsActive; + virStoragePoolIsPersistent; + virInterfaceIsActive; +} LIBVIRT_0.7.2; + # .... define new API here using predicted next version number ....
Shouldn't that be LIBVIRT_0.7.3 instead of LIBVIRT_0.7.4?
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 8224376..92502fe 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -2348,6 +2348,10 @@ static virDriver lxcDriver = { NULL, /* nodeDeviceReAttach */ NULL, /* nodeDeviceReset */ NULL, /* domainMigratePrepareTunnel */ + NULL, /* isEncrypted */ + NULL, /* isSecure */ + NULL, /* domainIsActive */ + NULL, /* domainIsEncrypted */ };
s/domainIsEncrypted/domainIsPersistent/
static virStateDriver lxcStateDriver = { diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 3c62636..311838c 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -1497,6 +1497,8 @@ static virNetworkDriver networkDriver = { networkGetBridgeName, /* networkGetBridgeName */ networkGetAutostart, /* networkGetAutostart */ networkSetAutostart, /* networkSetAutostart */ + NULL, /* networkIsActive */ + NULL, /* networkIsEncrypted */ };
s/networkIsEncrypted/networkIsPersistent/
static virStateDriver networkStateDriver = { diff --git a/src/opennebula/one_driver.c b/src/opennebula/one_driver.c index 9c6f120..9707bf8 100644 --- a/src/opennebula/one_driver.c +++ b/src/opennebula/one_driver.c @@ -788,6 +788,10 @@ static virDriver oneDriver = { NULL, /* nodeDeviceReAttach; */ NULL, /* nodeDeviceReset; */ NULL, /* domainMigratePrepareTunnel */ + NULL, /* isEncrypted */ + NULL, /* isSecure */ + NULL, /* domainIsActive */ + NULL, /* domainIsEncrypted */ };
s/domainIsEncrypted/domainIsPersistent/
static virStateDriver oneStateDriver = { diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 57482b8..4d7f56c 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -1433,6 +1433,10 @@ static virDriver openvzDriver = { NULL, /* nodeDeviceReAttach */ NULL, /* nodeDeviceReset */ NULL, /* domainMigratePrepareTunnel */ + NULL, /* isEncrypted */ + NULL, /* isSecure */ + NULL, /* domainIsActive */ + NULL, /* domainIsEncrypted */ };
s/domainIsEncrypted/domainIsPersistent/
int openvzRegister(void) { diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index ef465ed..cd0e9a7 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -1378,6 +1378,10 @@ virDriver phypDriver = { NULL, /* nodeDeviceReAttach */ NULL, /* nodeDeviceReset */ NULL, /* domainMigratePrepareTunnel */ + NULL, /* isEncrypted */ + NULL, /* isSecure */ + NULL, /* domainIsActive */ + NULL, /* domainIsEncrypted */ };
s/domainIsEncrypted/domainIsPersistent/
int diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 03e8457..0264797 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7166,6 +7166,10 @@ static virDriver qemuDriver = { qemudNodeDeviceReAttach, /* nodeDeviceReAttach */ qemudNodeDeviceReset, /* nodeDeviceReset */ qemudDomainMigratePrepareTunnel, /* domainMigratePrepareTunnel */ + NULL, /* isEncrypted */ + NULL, /* isSecure */ + NULL, /* domainIsActive */ + NULL, /* domainIsEncrypted */ };
s/domainIsEncrypted/domainIsPersistent/
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index bf001eb..9a265ac 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -8449,6 +8449,10 @@ static virDriver remote_driver = { remoteNodeDeviceReAttach, /* nodeDeviceReAttach */ remoteNodeDeviceReset, /* nodeDeviceReset */ remoteDomainMigratePrepareTunnel, /* domainMigratePrepareTunnel */ + NULL, /* isEncrypted */ + NULL, /* isSecure */ + NULL, /* domainIsActive */ + NULL, /* domainIsEncrypted */ };
s/domainIsEncrypted/domainIsPersistent/ [...]
diff --git a/src/test/test_driver.c b/src/test/test_driver.c index b0f91de..88dc6a5 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -4558,6 +4558,10 @@ static virDriver testDriver = { NULL, /* nodeDeviceReAttach */ NULL, /* nodeDeviceReset */ NULL, /* domainMigratePrepareTunnel */ + NULL, /* isEncrypted */ + NULL, /* isSecure */ + NULL, /* domainIsActive */ + NULL, /* domainIsEncrypted */ };
s/domainIsEncrypted/domainIsPersistent/
static virNetworkDriver testNetworkDriver = { @@ -4579,6 +4583,8 @@ static virNetworkDriver testNetworkDriver = { testNetworkGetBridgeName, /* networkGetBridgeName */ testNetworkGetAutostart, /* networkGetAutostart */ testNetworkSetAutostart, /* networkSetAutostart */ + NULL, /* networkIsActive */ + NULL, /* networkIsEncrypted */ };
s/networkIsEncrypted/networkIsPersistent/ [...]
@@ -4636,6 +4643,9 @@ static virStorageDriver testStorageDriver = { .volGetInfo = testStorageVolumeGetInfo, .volGetXMLDesc = testStorageVolumeGetXMLDesc, .volGetPath = testStorageVolumeGetPath, + + .poolIsActive = NULL, /* poolIsActive */ + .poolIsPersistent = NULL, /* poolIsEncrypted */ };
s/poolIsEncrypted/poolIsPersistent/
static virDeviceMonitor testDevMonitor = { diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index 6f60592..9b450d9 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -1862,6 +1862,10 @@ static virDriver umlDriver = { NULL, /* nodeDeviceReAttach */ NULL, /* nodeDeviceReset */ NULL, /* domainMigratePrepareTunnel */ + NULL, /* isEncrypted */ + NULL, /* isSecure */ + NULL, /* domainIsActive */ + NULL, /* domainIsEncrypted */ };
s/domainIsEncrypted/domainIsPersistent/
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 4f43901..5878154 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -6468,6 +6468,10 @@ virDriver NAME(Driver) = { NULL, /* nodeDeviceReAttach */ NULL, /* nodeDeviceReset */ NULL, /* domainMigratePrepareTunnel */ + NULL, /* isEncrypted */ + NULL, /* isSecure */ + NULL, /* domainIsActive */ + NULL, /* domainIsEncrypted */ };
s/domainIsEncrypted/domainIsPersistent/
virNetworkDriver NAME(NetworkDriver) = { diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c index 5273a11..da05253 100644 --- a/src/xen/xen_driver.c +++ b/src/xen/xen_driver.c @@ -1726,6 +1726,10 @@ static virDriver xenUnifiedDriver = { xenUnifiedNodeDeviceReAttach, /* nodeDeviceReAttach */ xenUnifiedNodeDeviceReset, /* nodeDeviceReset */ NULL, /* domainMigratePrepareTunnel */ + NULL, /* isEncrypted */ + NULL, /* isSecure */ + NULL, /* domainIsActive */ + NULL, /* domainIsEncrypted */ };
s/domainIsEncrypted/domainIsPersistent/ ACK, once this minor issues are fixed. Matthias

On Wed, Oct 21, 2009 at 08:56:25PM +0200, Matthias Bolte wrote:
2009/10/21 Daniel P. Berrange <berrange@redhat.com>:
[...]
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 8921c1a..62fa6cf 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -329,4 +329,17 @@ LIBVIRT_0.7.2 { virDomainMigrateToURI; } LIBVIRT_0.7.1;
+LIBVIRT_0.7.4 { + global: + virConnectIsEncrypted; + virConnectIsSecure; + virDomainIsActive; + virDomainIsPersistent; + virNetworkIsActive; + virNetworkIsPersistent; + virStoragePoolIsActive; + virStoragePoolIsPersistent; + virInterfaceIsActive; +} LIBVIRT_0.7.2; + # .... define new API here using predicted next version number ....
Shouldn't that be LIBVIRT_0.7.3 instead of LIBVIRT_0.7.4?
No, in the symbol file the named versions need to be continuous. So since there were no new APIs in 0.7.3, we go from 0.7.2 straight to 0.7.4 directly. Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

2009/10/21 Daniel P. Berrange <berrange@redhat.com>:
On Wed, Oct 21, 2009 at 08:56:25PM +0200, Matthias Bolte wrote:
2009/10/21 Daniel P. Berrange <berrange@redhat.com>:
[...]
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 8921c1a..62fa6cf 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -329,4 +329,17 @@ LIBVIRT_0.7.2 { virDomainMigrateToURI; } LIBVIRT_0.7.1;
+LIBVIRT_0.7.4 { + global: + virConnectIsEncrypted; + virConnectIsSecure; + virDomainIsActive; + virDomainIsPersistent; + virNetworkIsActive; + virNetworkIsPersistent; + virStoragePoolIsActive; + virStoragePoolIsPersistent; + virInterfaceIsActive; +} LIBVIRT_0.7.2; + # .... define new API here using predicted next version number ....
Shouldn't that be LIBVIRT_0.7.3 instead of LIBVIRT_0.7.4?
No, in the symbol file the named versions need to be continuous. So since there were no new APIs in 0.7.3, we go from 0.7.2 straight to 0.7.4 directly.
Daniel
AFAIK there was no 0.7.3 release yet. Did I miss something? Matthias

On Wed, Oct 21, 2009 at 07:15:24PM +0100, Daniel P. Berrange wrote:
Introduce a number of new APIs to expose some boolean properties of objects, which cannot otherwise reliably determined, nor are aspects of the XML configuration. [...] +/** + * virStoragePoolIsPersistent: + * + * Determine if the storagepool has a persistent configuration
space missing :-) storage pool
+/** + * virInterfaceIsActive:
description for @iface is missing here
+ * + * Determine if the interface is currently running + * + * Returns 1 if running, 0 if inactive, -1 on error + */ +int virInterfaceIsActive(virInterfacePtr iface) +/** + * virConnectIsEncrypted:
here missing @conn
+ * + * Determine if the connection to the hypervisor is encrypted + * + * Returns 1 if encrypted, 0 if not encrypted, -1 on error + */ +int virConnectIsEncrypted(virConnectPtr conn)
+/** + * virConnectIsSecure:
idem
+ * + * Determine if the connection to the hypervisor is secure + * + * A connection will be classed as secure if it is either + * encrypted, or running over a channel which is not exposed + * to eavesdropping (eg a UNIX domain socket, or pipe) + * + * Returns 1 if secure, 0 if secure, -1 on error + */ +int virConnectIsSecure(virConnectPtr conn) [...]
+LIBVIRT_0.7.4 {
0_7_3 as raised by Matthias
+ global: + virConnectIsEncrypted; + virConnectIsSecure; + virDomainIsActive; + virDomainIsPersistent; + virNetworkIsActive; + virNetworkIsPersistent; + virStoragePoolIsActive; + virStoragePoolIsPersistent; + virInterfaceIsActive; +} LIBVIRT_0.7.2; + # .... define new API here using predicted next version number .... [...] static virNetworkDriver network_driver = { @@ -8470,6 +8474,8 @@ static virNetworkDriver network_driver = { .networkGetBridgeName = remoteNetworkGetBridgeName, .networkGetAutostart = remoteNetworkGetAutostart, .networkSetAutostart = remoteNetworkSetAutostart, + .networkIsActive = NULL, + .networkIsPersistent = NULL, };
static virInterfaceDriver interface_driver = { @@ -8487,6 +8493,7 @@ static virInterfaceDriver interface_driver = { .interfaceUndefine = remoteInterfaceUndefine, .interfaceCreate = remoteInterfaceCreate, .interfaceDestroy = remoteInterfaceDestroy, + .interfaceIsActive = NULL, /* interfaceIsActive */ };
static virStorageDriver storage_driver = { @@ -8525,6 +8532,9 @@ static virStorageDriver storage_driver = { .volGetInfo = remoteStorageVolGetInfo, .volGetXMLDesc = remoteStorageVolDumpXML, .volGetPath = remoteStorageVolGetPath, + + .poolIsActive = NULL, /* poolIsActive */ + .poolIsPersistent = NULL, /* poolIsEncrypted */ };
I though we had switched back all driver tabs to old style initialization, apparently not those :-) ACK once the comments are updated as well as those pointed by Matthias Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

This implements the virConnectIsSecure, virConnectIsEncrypted, virDomainIsPersistent, virDomainIsActive, virNetworkIsActive, virNetworkIsPersistent, virStoragePoolIsActive, virStoragePoolIsPersistent, virInterfaceIsActive APIs in (nearly) all drivers. Exceptions are: phyp: missing domainIsActive/Persistent esx: missing domainIsPersistent opennebula: missing domainIsActive/Persistent * src/remote/remote_protocol.x: Define remote wire ABI for newly added APIs. * daemon/remote_dispatch*.h: Re-generated from remote_protocol.x * src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c, src/opennebula/one_driver.c, src/openvz/openvz_conf.c, src/openvz/openvz_driver.c, src/phyp/phyp_driver.c, src/remote/remote_driver.c, src/storage/storage_driver.c, src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c, src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c, src/xen/xen_inotify.h: Implement all the new APIs where possible --- daemon/remote.c | 202 ++++++++++++++++++++++++++ daemon/remote_dispatch_args.h | 7 + daemon/remote_dispatch_prototypes.h | 64 +++++++++ daemon/remote_dispatch_ret.h | 8 + daemon/remote_dispatch_table.h | 40 ++++++ src/esx/esx_driver.c | 106 +++++++++++++- src/lxc/lxc_driver.c | 68 +++++++++- src/network/bridge_driver.c | 50 ++++++- src/opennebula/one_driver.c | 21 +++- src/openvz/openvz_conf.c | 2 + src/openvz/openvz_driver.c | 66 ++++++++- src/phyp/phyp_driver.c | 25 +++- src/qemu/qemu_driver.c | 65 ++++++++- src/remote/remote_driver.c | 266 +++++++++++++++++++++++++++++++++-- src/remote/remote_protocol.c | 137 ++++++++++++++++++- src/remote/remote_protocol.h | 112 +++++++++++++++ src/remote/remote_protocol.x | 87 +++++++++++- src/storage/storage_driver.c | 46 ++++++ src/test/test_driver.c | 184 +++++++++++++++++++++++-- src/uml/uml_driver.c | 67 ++++++++- src/vbox/vbox_tmpl.c | 108 ++++++++++++++- src/xen/xen_driver.c | 98 ++++++++++++- src/xen/xen_driver.h | 2 + src/xen/xen_inotify.c | 8 +- src/xen/xen_inotify.h | 1 + 25 files changed, 1772 insertions(+), 68 deletions(-) diff --git a/daemon/remote.c b/daemon/remote.c index 4296fc3..1f239cd 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -5005,6 +5005,208 @@ remoteDispatchSecretLookupByUsage (struct qemud_server *server ATTRIBUTE_UNUSED, } +static int remoteDispatchDomainIsActive(struct qemud_server *server ATTRIBUTE_UNUSED, + struct qemud_client *client ATTRIBUTE_UNUSED, + virConnectPtr conn, + remote_message_header *hdr ATTRIBUTE_UNUSED, + remote_error *err, + remote_domain_is_active_args *args, + remote_domain_is_active_ret *ret) +{ + virDomainPtr domain; + + domain = get_nonnull_domain(conn, args->dom); + if (domain == NULL) { + remoteDispatchConnError(err, conn); + return -1; + } + + ret->active = virDomainIsActive(domain); + + if (ret->active < 0) { + remoteDispatchConnError(err, conn); + return -1; + } + + return 0; +} + +static int remoteDispatchDomainIsPersistent(struct qemud_server *server ATTRIBUTE_UNUSED, + struct qemud_client *client ATTRIBUTE_UNUSED, + virConnectPtr conn, + remote_message_header *hdr ATTRIBUTE_UNUSED, + remote_error *err, + remote_domain_is_persistent_args *args, + remote_domain_is_persistent_ret *ret) +{ + virDomainPtr domain; + + domain = get_nonnull_domain(conn, args->dom); + if (domain == NULL) { + remoteDispatchConnError(err, conn); + return -1; + } + + ret->persistent = virDomainIsPersistent(domain); + + if (ret->persistent < 0) { + remoteDispatchConnError(err, conn); + return -1; + } + + return 0; +} + +static int remoteDispatchInterfaceIsActive(struct qemud_server *server ATTRIBUTE_UNUSED, + struct qemud_client *client ATTRIBUTE_UNUSED, + virConnectPtr conn, + remote_message_header *hdr ATTRIBUTE_UNUSED, + remote_error *err, + remote_interface_is_active_args *args, + remote_interface_is_active_ret *ret) +{ + virInterfacePtr iface; + + iface = get_nonnull_interface(conn, args->iface); + if (iface == NULL) { + remoteDispatchConnError(err, conn); + return -1; + } + + ret->active = virInterfaceIsActive(iface); + + if (ret->active < 0) { + remoteDispatchConnError(err, conn); + return -1; + } + + return 0; +} + +static int remoteDispatchNetworkIsActive(struct qemud_server *server ATTRIBUTE_UNUSED, + struct qemud_client *client ATTRIBUTE_UNUSED, + virConnectPtr conn, + remote_message_header *hdr ATTRIBUTE_UNUSED, + remote_error *err, + remote_network_is_active_args *args, + remote_network_is_active_ret *ret) +{ + virNetworkPtr network; + + network = get_nonnull_network(conn, args->net); + if (network == NULL) { + remoteDispatchConnError(err, conn); + return -1; + } + + ret->active = virNetworkIsActive(network); + + if (ret->active < 0) { + remoteDispatchConnError(err, conn); + return -1; + } + + return 0; +} + +static int remoteDispatchNetworkIsPersistent(struct qemud_server *server ATTRIBUTE_UNUSED, + struct qemud_client *client ATTRIBUTE_UNUSED, + virConnectPtr conn, + remote_message_header *hdr ATTRIBUTE_UNUSED, + remote_error *err, + remote_network_is_persistent_args *args, + remote_network_is_persistent_ret *ret) +{ + virNetworkPtr network; + + network = get_nonnull_network(conn, args->net); + if (network == NULL) { + remoteDispatchConnError(err, conn); + return -1; + } + + ret->persistent = virNetworkIsPersistent(network); + + if (ret->persistent < 0) { + remoteDispatchConnError(err, conn); + return -1; + } + + return 0; +} + +static int remoteDispatchStoragePoolIsActive(struct qemud_server *server ATTRIBUTE_UNUSED, + struct qemud_client *client ATTRIBUTE_UNUSED, + virConnectPtr conn, + remote_message_header *hdr ATTRIBUTE_UNUSED, + remote_error *err, + remote_storage_pool_is_active_args *args, + remote_storage_pool_is_active_ret *ret) +{ + virStoragePoolPtr pool; + + pool = get_nonnull_storage_pool(conn, args->pool); + if (pool == NULL) { + remoteDispatchConnError(err, conn); + return -1; + } + + ret->active = virStoragePoolIsActive(pool); + + if (ret->active < 0) { + remoteDispatchConnError(err, conn); + return -1; + } + + return 0; +} + +static int remoteDispatchStoragePoolIsPersistent(struct qemud_server *server ATTRIBUTE_UNUSED, + struct qemud_client *client ATTRIBUTE_UNUSED, + virConnectPtr conn, + remote_message_header *hdr ATTRIBUTE_UNUSED, + remote_error *err, + remote_storage_pool_is_persistent_args *args, + remote_storage_pool_is_persistent_ret *ret) +{ + virStoragePoolPtr pool; + + pool = get_nonnull_storage_pool(conn, args->pool); + if (pool == NULL) { + remoteDispatchConnError(err, conn); + return -1; + } + + ret->persistent = virStoragePoolIsPersistent(pool); + + if (ret->persistent < 0) { + remoteDispatchConnError(err, conn); + return -1; + } + + return 0; +} + + +static int remoteDispatchIsSecure(struct qemud_server *server ATTRIBUTE_UNUSED, + struct qemud_client *client ATTRIBUTE_UNUSED, + virConnectPtr conn, + remote_message_header *hdr ATTRIBUTE_UNUSED, + remote_error *err, + void *args ATTRIBUTE_UNUSED, + remote_is_secure_ret *ret) +{ + ret->secure = virConnectIsSecure(conn); + + if (ret->secure < 0) { + remoteDispatchConnError(err, conn); + return -1; + } + + return 0; +} + + /*----- Helpers. -----*/ /* get_nonnull_domain and get_nonnull_network turn an on-wire diff --git a/daemon/remote_dispatch_args.h b/daemon/remote_dispatch_args.h index aceead1..87dcdae 100644 --- a/daemon/remote_dispatch_args.h +++ b/daemon/remote_dispatch_args.h @@ -126,3 +126,10 @@ remote_secret_undefine_args val_remote_secret_undefine_args; remote_secret_lookup_by_usage_args val_remote_secret_lookup_by_usage_args; remote_domain_migrate_prepare_tunnel_args val_remote_domain_migrate_prepare_tunnel_args; + remote_domain_is_active_args val_remote_domain_is_active_args; + remote_domain_is_persistent_args val_remote_domain_is_persistent_args; + remote_network_is_active_args val_remote_network_is_active_args; + remote_network_is_persistent_args val_remote_network_is_persistent_args; + remote_storage_pool_is_active_args val_remote_storage_pool_is_active_args; + remote_storage_pool_is_persistent_args val_remote_storage_pool_is_persistent_args; + remote_interface_is_active_args val_remote_interface_is_active_args; diff --git a/daemon/remote_dispatch_prototypes.h b/daemon/remote_dispatch_prototypes.h index 9afd2c7..7c2da07 100644 --- a/daemon/remote_dispatch_prototypes.h +++ b/daemon/remote_dispatch_prototypes.h @@ -226,6 +226,22 @@ static int remoteDispatchDomainInterfaceStats( remote_error *err, remote_domain_interface_stats_args *args, remote_domain_interface_stats_ret *ret); +static int remoteDispatchDomainIsActive( + struct qemud_server *server, + struct qemud_client *client, + virConnectPtr conn, + remote_message_header *hdr, + remote_error *err, + remote_domain_is_active_args *args, + remote_domain_is_active_ret *ret); +static int remoteDispatchDomainIsPersistent( + struct qemud_server *server, + struct qemud_client *client, + virConnectPtr conn, + remote_message_header *hdr, + remote_error *err, + remote_domain_is_persistent_args *args, + remote_domain_is_persistent_ret *ret); static int remoteDispatchDomainLookupById( struct qemud_server *server, struct qemud_client *client, @@ -514,6 +530,14 @@ static int remoteDispatchInterfaceGetXmlDesc( remote_error *err, remote_interface_get_xml_desc_args *args, remote_interface_get_xml_desc_ret *ret); +static int remoteDispatchInterfaceIsActive( + struct qemud_server *server, + struct qemud_client *client, + virConnectPtr conn, + remote_message_header *hdr, + remote_error *err, + remote_interface_is_active_args *args, + remote_interface_is_active_ret *ret); static int remoteDispatchInterfaceLookupByMacString( struct qemud_server *server, struct qemud_client *client, @@ -538,6 +562,14 @@ static int remoteDispatchInterfaceUndefine( remote_error *err, remote_interface_undefine_args *args, void *ret); +static int remoteDispatchIsSecure( + struct qemud_server *server, + struct qemud_client *client, + virConnectPtr conn, + remote_message_header *hdr, + remote_error *err, + void *args, + remote_is_secure_ret *ret); static int remoteDispatchListDefinedDomains( struct qemud_server *server, struct qemud_client *client, @@ -666,6 +698,22 @@ static int remoteDispatchNetworkGetBridgeName( remote_error *err, remote_network_get_bridge_name_args *args, remote_network_get_bridge_name_ret *ret); +static int remoteDispatchNetworkIsActive( + struct qemud_server *server, + struct qemud_client *client, + virConnectPtr conn, + remote_message_header *hdr, + remote_error *err, + remote_network_is_active_args *args, + remote_network_is_active_ret *ret); +static int remoteDispatchNetworkIsPersistent( + struct qemud_server *server, + struct qemud_client *client, + virConnectPtr conn, + remote_message_header *hdr, + remote_error *err, + remote_network_is_persistent_args *args, + remote_network_is_persistent_ret *ret); static int remoteDispatchNetworkLookupByName( struct qemud_server *server, struct qemud_client *client, @@ -1034,6 +1082,22 @@ static int remoteDispatchStoragePoolGetInfo( remote_error *err, remote_storage_pool_get_info_args *args, remote_storage_pool_get_info_ret *ret); +static int remoteDispatchStoragePoolIsActive( + struct qemud_server *server, + struct qemud_client *client, + virConnectPtr conn, + remote_message_header *hdr, + remote_error *err, + remote_storage_pool_is_active_args *args, + remote_storage_pool_is_active_ret *ret); +static int remoteDispatchStoragePoolIsPersistent( + struct qemud_server *server, + struct qemud_client *client, + virConnectPtr conn, + remote_message_header *hdr, + remote_error *err, + remote_storage_pool_is_persistent_args *args, + remote_storage_pool_is_persistent_ret *ret); static int remoteDispatchStoragePoolListVolumes( struct qemud_server *server, struct qemud_client *client, diff --git a/daemon/remote_dispatch_ret.h b/daemon/remote_dispatch_ret.h index 6ced13a..c37744a 100644 --- a/daemon/remote_dispatch_ret.h +++ b/daemon/remote_dispatch_ret.h @@ -106,3 +106,11 @@ remote_secret_get_xml_desc_ret val_remote_secret_get_xml_desc_ret; remote_secret_get_value_ret val_remote_secret_get_value_ret; remote_secret_lookup_by_usage_ret val_remote_secret_lookup_by_usage_ret; + remote_is_secure_ret val_remote_is_secure_ret; + remote_domain_is_active_ret val_remote_domain_is_active_ret; + remote_domain_is_persistent_ret val_remote_domain_is_persistent_ret; + remote_network_is_active_ret val_remote_network_is_active_ret; + remote_network_is_persistent_ret val_remote_network_is_persistent_ret; + remote_storage_pool_is_active_ret val_remote_storage_pool_is_active_ret; + remote_storage_pool_is_persistent_ret val_remote_storage_pool_is_persistent_ret; + remote_interface_is_active_ret val_remote_interface_is_active_ret; diff --git a/daemon/remote_dispatch_table.h b/daemon/remote_dispatch_table.h index bb13f4c..cb640b6 100644 --- a/daemon/remote_dispatch_table.h +++ b/daemon/remote_dispatch_table.h @@ -747,3 +747,43 @@ .args_filter = (xdrproc_t) xdr_remote_domain_migrate_prepare_tunnel_args, .ret_filter = (xdrproc_t) xdr_void, }, +{ /* IsSecure => 149 */ + .fn = (dispatch_fn) remoteDispatchIsSecure, + .args_filter = (xdrproc_t) xdr_void, + .ret_filter = (xdrproc_t) xdr_remote_is_secure_ret, +}, +{ /* DomainIsActive => 150 */ + .fn = (dispatch_fn) remoteDispatchDomainIsActive, + .args_filter = (xdrproc_t) xdr_remote_domain_is_active_args, + .ret_filter = (xdrproc_t) xdr_remote_domain_is_active_ret, +}, +{ /* DomainIsPersistent => 151 */ + .fn = (dispatch_fn) remoteDispatchDomainIsPersistent, + .args_filter = (xdrproc_t) xdr_remote_domain_is_persistent_args, + .ret_filter = (xdrproc_t) xdr_remote_domain_is_persistent_ret, +}, +{ /* NetworkIsActive => 152 */ + .fn = (dispatch_fn) remoteDispatchNetworkIsActive, + .args_filter = (xdrproc_t) xdr_remote_network_is_active_args, + .ret_filter = (xdrproc_t) xdr_remote_network_is_active_ret, +}, +{ /* NetworkIsPersistent => 153 */ + .fn = (dispatch_fn) remoteDispatchNetworkIsPersistent, + .args_filter = (xdrproc_t) xdr_remote_network_is_persistent_args, + .ret_filter = (xdrproc_t) xdr_remote_network_is_persistent_ret, +}, +{ /* StoragePoolIsActive => 154 */ + .fn = (dispatch_fn) remoteDispatchStoragePoolIsActive, + .args_filter = (xdrproc_t) xdr_remote_storage_pool_is_active_args, + .ret_filter = (xdrproc_t) xdr_remote_storage_pool_is_active_ret, +}, +{ /* StoragePoolIsPersistent => 155 */ + .fn = (dispatch_fn) remoteDispatchStoragePoolIsPersistent, + .args_filter = (xdrproc_t) xdr_remote_storage_pool_is_persistent_args, + .ret_filter = (xdrproc_t) xdr_remote_storage_pool_is_persistent_ret, +}, +{ /* InterfaceIsActive => 156 */ + .fn = (dispatch_fn) remoteDispatchInterfaceIsActive, + .args_filter = (xdrproc_t) xdr_remote_interface_is_active_args, + .ret_filter = (xdrproc_t) xdr_remote_interface_is_active_ret, +}, diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index 3a57613..c3d1eac 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -503,6 +503,30 @@ esxClose(virConnectPtr conn) } +static int +esxIsSecure(virConnectPtr conn) +{ + esxPrivate *priv = (esxPrivate *)conn->privateData; + + if (STRCASEEQ(priv->transport, "https")) { + return 1; + } else { + return 0; + } +} + + +static int +esxIsEncrypted(virConnectPtr conn) +{ + esxPrivate *priv = (esxPrivate *)conn->privateData; + + if (STRCASEEQ(priv->transport, "https")) { + return 1; + } else { + return 0; + } +} static esxVI_Boolean esxSupportsVMotion(virConnectPtr conn) @@ -1227,6 +1251,80 @@ esxDomainLookupByName(virConnectPtr conn, const char *name) } +static int +esxDomainIsActive(virDomainPtr dom) +{ + esxPrivate *priv = (esxPrivate *)dom->conn->privateData; + esxVI_String *propertyNameList = NULL; + esxVI_ObjectContent *virtualMachineList = NULL; + esxVI_ObjectContent *virtualMachine = NULL; + esxVI_VirtualMachinePowerState powerState; + int id_candidate = -1; + char *name_candidate = NULL; + unsigned char uuid_candidate[VIR_UUID_BUFLEN]; + char uuid_string[VIR_UUID_STRING_BUFLEN]; + int ret = -1; + + if (esxVI_EnsureSession(dom->conn, priv->host) < 0) { + goto cleanup; + } + + if (esxVI_String_AppendValueListToList(dom->conn, &propertyNameList, + "configStatus\0" + "name\0" + "runtime.powerState\0" + "config.uuid\0") < 0 || + esxVI_GetObjectContent(dom->conn, priv->host, priv->host->vmFolder, + "VirtualMachine", propertyNameList, + esxVI_Boolean_True, &virtualMachineList) < 0) { + goto cleanup; + } + + for (virtualMachine = virtualMachineList; virtualMachine != NULL; + virtualMachine = virtualMachine->_next) { + VIR_FREE(name_candidate); + + if (esxVI_GetVirtualMachineIdentity(dom->conn, virtualMachine, + &id_candidate, &name_candidate, + uuid_candidate) < 0) { + goto cleanup; + } + + if (memcmp(dom->uuid, uuid_candidate, + VIR_UUID_BUFLEN * sizeof(unsigned char)) != 0) { + continue; + } + + if (esxVI_GetVirtualMachinePowerState(dom->conn, virtualMachine, + &powerState) < 0) { + goto cleanup; + } + + /* Only running/suspended virtual machines have an ID != -1 */ + if (powerState != esxVI_VirtualMachinePowerState_PoweredOff) { + ret = 1; + } else { + ret = 0; + } + + break; + } + + if (ret == -1) { + virUUIDFormat(dom->uuid, uuid_string); + + ESX_ERROR(dom->conn, VIR_ERR_NO_DOMAIN, "No domain with UUID '%s'", + uuid_string); + } + + cleanup: + esxVI_String_Free(&propertyNameList); + esxVI_ObjectContent_Free(&virtualMachineList); + VIR_FREE(name_candidate); + + return ret; +} + static int esxDomainSuspend(virDomainPtr domain) @@ -3275,10 +3373,10 @@ static virDriver esxDriver = { NULL, /* nodeDeviceReAttach */ NULL, /* nodeDeviceReset */ NULL, /* domainMigratePrepareTunnel */ - NULL, /* isEncrypted */ - NULL, /* isSecure */ - NULL, /* domainIsActive */ - NULL, /* domainIsEncrypted */ + esxIsEncrypted, /* isEncrypted */ + esxIsSecure, /* isSecure */ + esxDomainIsActive, /* domainIsActive */ + NULL, /* domainIsPersistent */ }; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 92502fe..313342e 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -128,6 +128,21 @@ static int lxcClose(virConnectPtr conn) return 0; } + +static int lxcIsSecure(virConnectPtr conn ATTRIBUTE_UNUSED) +{ + /* Trivially secure, since always inside the daemon */ + return 1; +} + + +static int lxcIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED) +{ + /* Not encrypted, but remote driver takes care of that */ + return 0; +} + + static char *lxcGetCapabilities(virConnectPtr conn) { lxc_driver_t *driver = conn->privateData; char *xml; @@ -218,6 +233,51 @@ cleanup: return dom; } + +static int lxcDomainIsActive(virDomainPtr dom) +{ + lxc_driver_t *driver = dom->conn->privateData; + virDomainObjPtr obj; + int ret = -1; + + lxcDriverLock(driver); + obj = virDomainFindByUUID(&driver->domains, dom->uuid); + lxcDriverUnlock(driver); + if (!obj) { + lxcError(dom->conn, NULL, VIR_ERR_NO_DOMAIN, NULL); + goto cleanup; + } + ret = virDomainObjIsActive(obj); + +cleanup: + if (obj) + virDomainObjUnlock(obj); + return ret; +} + + +static int lxcDomainIsPersistent(virDomainPtr dom) +{ + lxc_driver_t *driver = dom->conn->privateData; + virDomainObjPtr obj; + int ret = -1; + + lxcDriverLock(driver); + obj = virDomainFindByUUID(&driver->domains, dom->uuid); + lxcDriverUnlock(driver); + if (!obj) { + lxcError(dom->conn, NULL, VIR_ERR_NO_DOMAIN, NULL); + goto cleanup; + } + ret = obj->persistent; + +cleanup: + if (obj) + virDomainObjUnlock(obj); + return ret; +} + + static int lxcListDomains(virConnectPtr conn, int *ids, int nids) { lxc_driver_t *driver = conn->privateData; int got = 0, i; @@ -2348,10 +2408,10 @@ static virDriver lxcDriver = { NULL, /* nodeDeviceReAttach */ NULL, /* nodeDeviceReset */ NULL, /* domainMigratePrepareTunnel */ - NULL, /* isEncrypted */ - NULL, /* isSecure */ - NULL, /* domainIsActive */ - NULL, /* domainIsEncrypted */ + lxcIsEncrypted, + lxcIsSecure, + lxcDomainIsActive, + lxcDomainIsPersistent, }; static virStateDriver lxcStateDriver = { diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 311838c..60c1acc 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -1159,6 +1159,50 @@ static int networkListDefinedNetworks(virConnectPtr conn, char **const names, in return -1; } + +static int networkIsActive(virNetworkPtr net) +{ + struct network_driver *driver = net->conn->privateData; + virNetworkObjPtr obj; + int ret = -1; + + networkDriverLock(driver); + obj = virNetworkFindByUUID(&driver->networks, net->uuid); + networkDriverUnlock(driver); + if (!obj) { + networkReportError(net->conn, NULL, NULL, VIR_ERR_NO_NETWORK, NULL); + goto cleanup; + } + ret = virNetworkObjIsActive(obj); + +cleanup: + if (obj) + virNetworkObjUnlock(obj); + return ret; +} + +static int networkIsPersistent(virNetworkPtr net) +{ + struct network_driver *driver = net->conn->privateData; + virNetworkObjPtr obj; + int ret = -1; + + networkDriverLock(driver); + obj = virNetworkFindByUUID(&driver->networks, net->uuid); + networkDriverUnlock(driver); + if (!obj) { + networkReportError(net->conn, NULL, NULL, VIR_ERR_NO_NETWORK, NULL); + goto cleanup; + } + ret = obj->persistent; + +cleanup: + if (obj) + virNetworkObjUnlock(obj); + return ret; +} + + static virNetworkPtr networkCreate(virConnectPtr conn, const char *xml) { struct network_driver *driver = conn->networkPrivateData; virNetworkDefPtr def; @@ -1246,7 +1290,7 @@ static int networkUndefine(virNetworkPtr net) { network = virNetworkFindByUUID(&driver->networks, net->uuid); if (!network) { - networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_DOMAIN, + networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_NETWORK, "%s", _("no network with matching uuid")); goto cleanup; } @@ -1497,8 +1541,8 @@ static virNetworkDriver networkDriver = { networkGetBridgeName, /* networkGetBridgeName */ networkGetAutostart, /* networkGetAutostart */ networkSetAutostart, /* networkSetAutostart */ - NULL, /* networkIsActive */ - NULL, /* networkIsEncrypted */ + networkIsActive, + networkIsPersistent, }; static virStateDriver networkStateDriver = { diff --git a/src/opennebula/one_driver.c b/src/opennebula/one_driver.c index 9707bf8..ba61432 100644 --- a/src/opennebula/one_driver.c +++ b/src/opennebula/one_driver.c @@ -90,6 +90,21 @@ static int oneClose(virConnectPtr conn) return 0; } + +static int oneIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED) +{ + /* Not encrypted because it uses HTTP, not HTTPs */ + return 0; +} + + +static int oneIsSecure(virConnectPtr conn ATTRIBUTE_UNUSED) +{ + /* Not secure because it uses HTTP, not HTTPs */ + return 0; +} + + static virDomainPtr oneDomainLookupByID(virConnectPtr conn, int id) { @@ -788,10 +803,10 @@ static virDriver oneDriver = { NULL, /* nodeDeviceReAttach; */ NULL, /* nodeDeviceReset; */ NULL, /* domainMigratePrepareTunnel */ - NULL, /* isEncrypted */ - NULL, /* isSecure */ + oneIsEncrypted, + oneIsSecure, NULL, /* domainIsActive */ - NULL, /* domainIsEncrypted */ + NULL, /* domainIsPersistent */ }; static virStateDriver oneStateDriver = { diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index 403f537..83687a2 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -473,6 +473,8 @@ int openvzLoadDomains(struct openvz_driver *driver) { dom->pid = veid; dom->def->id = dom->state == VIR_DOMAIN_SHUTOFF ? -1 : veid; + /* XXX OpenVZ doesn't appear to have concept of a transient domain */ + dom->persistent = 1; if (virAsprintf(&dom->def->name, "%i", veid) < 0) goto no_memory; diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 4d7f56c..c9fb8a2 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -415,6 +415,50 @@ cleanup: } +static int openvzDomainIsActive(virDomainPtr dom) +{ + struct openvz_driver *driver = dom->conn->privateData; + virDomainObjPtr obj; + int ret = -1; + + openvzDriverLock(driver); + obj = virDomainFindByUUID(&driver->domains, dom->uuid); + openvzDriverUnlock(driver); + if (!obj) { + openvzError(dom->conn, VIR_ERR_NO_DOMAIN, NULL); + goto cleanup; + } + ret = virDomainObjIsActive(obj); + +cleanup: + if (obj) + virDomainObjUnlock(obj); + return ret; +} + + +static int openvzDomainIsPersistent(virDomainPtr dom) +{ + struct openvz_driver *driver = dom->conn->privateData; + virDomainObjPtr obj; + int ret = -1; + + openvzDriverLock(driver); + obj = virDomainFindByUUID(&driver->domains, dom->uuid); + openvzDriverUnlock(driver); + if (!obj) { + openvzError(dom->conn, VIR_ERR_NO_DOMAIN, NULL); + goto cleanup; + } + ret = obj->persistent; + +cleanup: + if (obj) + virDomainObjUnlock(obj); + return ret; +} + + static char *openvzDomainDumpXML(virDomainPtr dom, int flags) { struct openvz_driver *driver = dom->conn->privateData; virDomainObjPtr vm; @@ -777,6 +821,7 @@ openvzDomainDefineXML(virConnectPtr conn, const char *xml) if (!(vm = virDomainAssignDef(conn, &driver->domains, vmdef))) goto cleanup; vmdef = NULL; + vm->persistent = 1; if (openvzSetInitialConfig(conn, vm->def) < 0) { openvzError(conn, VIR_ERR_INTERNAL_ERROR, @@ -844,6 +889,9 @@ openvzDomainCreateXML(virConnectPtr conn, const char *xml, if (!(vm = virDomainAssignDef(conn, &driver->domains, vmdef))) goto cleanup; vmdef = NULL; + /* All OpenVZ domains seem to be persistent - this is a bit of a violation + * of this libvirt API which is intended for transient domain creation */ + vm->persistent = 1; if (openvzSetInitialConfig(conn, vm->def) < 0) { openvzError(conn, VIR_ERR_INTERNAL_ERROR, @@ -1199,6 +1247,16 @@ static const char *openvzGetType(virConnectPtr conn ATTRIBUTE_UNUSED) { return "OpenVZ"; } +static int openvzIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED) { + /* Encryption is not relevant / applicable to way we talk to openvz */ + return 0; +} + +static int openvzIsSecure(virConnectPtr conn ATTRIBUTE_UNUSED) { + /* We run CLI tools directly so this is secure */ + return 1; +} + static char *openvzGetCapabilities(virConnectPtr conn) { struct openvz_driver *driver = conn->privateData; char *ret; @@ -1433,10 +1491,10 @@ static virDriver openvzDriver = { NULL, /* nodeDeviceReAttach */ NULL, /* nodeDeviceReset */ NULL, /* domainMigratePrepareTunnel */ - NULL, /* isEncrypted */ - NULL, /* isSecure */ - NULL, /* domainIsActive */ - NULL, /* domainIsEncrypted */ + openvzIsEncrypted, + openvzIsSecure, + openvzDomainIsActive, + openvzDomainIsPersistent, }; int openvzRegister(void) { diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index cd0e9a7..52bdcce 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -159,6 +159,23 @@ phypClose(virConnectPtr conn) return 0; } + +static int +phypIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED) +{ + /* Phyp uses an SSH tunnel, so is always encrypted */ + return 1; +} + + +static int +phypIsSecure(virConnectPtr conn ATTRIBUTE_UNUSED) +{ + /* Phyp uses an SSH tunnel, so is always secure */ + return 1; +} + + LIBSSH2_SESSION * openSSHSession(virConnectPtr conn, virConnectAuthPtr auth, int *internal_socket) @@ -1378,10 +1395,10 @@ virDriver phypDriver = { NULL, /* nodeDeviceReAttach */ NULL, /* nodeDeviceReset */ NULL, /* domainMigratePrepareTunnel */ - NULL, /* isEncrypted */ - NULL, /* isSecure */ - NULL, /* domainIsActive */ - NULL, /* domainIsEncrypted */ + phypIsEncrypted, + phypIsSecure, + NULL, /* domainIsActive */ + NULL, /* domainIsPersistent */ }; int diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 0264797..c98fa58 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -2395,6 +2395,19 @@ static const char *qemudGetType(virConnectPtr conn ATTRIBUTE_UNUSED) { } +static int qemuIsSecure(virConnectPtr conn ATTRIBUTE_UNUSED) +{ + /* Trivially secure, since always inside the daemon */ + return 1; +} + +static int qemuIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED) +{ + /* Not encrypted, but remote driver takes care of that */ + return 0; +} + + static int kvmGetMaxVCPUs(void) { int maxvcpus = 1; @@ -2604,6 +2617,50 @@ cleanup: return dom; } + +static int qemuDomainIsActive(virDomainPtr dom) +{ + struct qemud_driver *driver = dom->conn->privateData; + virDomainObjPtr obj; + int ret = -1; + + qemuDriverLock(driver); + obj = virDomainFindByUUID(&driver->domains, dom->uuid); + qemuDriverUnlock(driver); + if (!obj) { + qemudReportError(dom->conn, NULL, NULL, VIR_ERR_NO_DOMAIN, NULL); + goto cleanup; + } + ret = virDomainObjIsActive(obj); + +cleanup: + if (obj) + virDomainObjUnlock(obj); + return ret; +} + +static int qemuDomainIsPersistent(virDomainPtr dom) +{ + struct qemud_driver *driver = dom->conn->privateData; + virDomainObjPtr obj; + int ret = -1; + + qemuDriverLock(driver); + obj = virDomainFindByUUID(&driver->domains, dom->uuid); + qemuDriverUnlock(driver); + if (!obj) { + qemudReportError(dom->conn, NULL, NULL, VIR_ERR_NO_DOMAIN, NULL); + goto cleanup; + } + ret = obj->persistent; + +cleanup: + if (obj) + virDomainObjUnlock(obj); + return ret; +} + + static int qemudGetVersion(virConnectPtr conn, unsigned long *version) { struct qemud_driver *driver = conn->privateData; int ret = -1; @@ -7166,10 +7223,10 @@ static virDriver qemuDriver = { qemudNodeDeviceReAttach, /* nodeDeviceReAttach */ qemudNodeDeviceReset, /* nodeDeviceReset */ qemudDomainMigratePrepareTunnel, /* domainMigratePrepareTunnel */ - NULL, /* isEncrypted */ - NULL, /* isSecure */ - NULL, /* domainIsActive */ - NULL, /* domainIsEncrypted */ + qemuIsEncrypted, + qemuIsSecure, + qemuDomainIsActive, + qemuDomainIsPersistent, }; diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 9a265ac..5eeba00 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -157,6 +157,7 @@ struct private_data { int watch; /* File handle watch */ pid_t pid; /* PID of tunnel process */ int uses_tls; /* TLS enabled on socket? */ + int is_secure; /* Secure if TLS or SASL or UNIX sockets */ gnutls_session_t session; /* GnuTLS session (if uses_tls != 0). */ char *type; /* Cached return from remoteType. */ int counter; /* Generates serial numbers for RPC. */ @@ -574,6 +575,7 @@ doRemoteOpen (virConnectPtr conn, case trans_tls: if (initialise_gnutls (conn) == -1) goto failed; priv->uses_tls = 1; + priv->is_secure = 1; /*FALLTHROUGH*/ case trans_tcp: { @@ -691,6 +693,7 @@ doRemoteOpen (virConnectPtr conn, addr.sun_path[0] = '\0'; autostart_retry: + priv->is_secure = 1; priv->sock = socket (AF_UNIX, SOCK_STREAM, 0); if (priv->sock == -1) { virReportSystemError(conn, errno, "%s", @@ -771,6 +774,8 @@ doRemoteOpen (virConnectPtr conn, for (j = 0; j < (nr_args-1); j++) if (cmd_argv[j] == NULL) goto out_of_memory; + + priv->is_secure = 1; } /*FALLTHROUGH*/ @@ -797,6 +802,10 @@ doRemoteOpen (virConnectPtr conn, close (sv[1]); priv->sock = sv[0]; priv->pid = pid; + + /* Do not set 'is_secure' flag since we can't guarentee + * an external program is secure, and this flag must be + * pessimistic */ } #else /* WIN32 */ @@ -1562,6 +1571,72 @@ done: return rv; } +static int remoteIsSecure(virConnectPtr conn) +{ + int rv = -1; + struct private_data *priv = conn->privateData; + remote_is_secure_ret ret; + remoteDriverLock(priv); + + memset (&ret, 0, sizeof ret); + if (call (conn, priv, 0, REMOTE_PROC_IS_SECURE, + (xdrproc_t) xdr_void, (char *) NULL, + (xdrproc_t) xdr_remote_is_secure_ret, (char *) &ret) == -1) + goto done; + + /* We claim to be secure, if the remote driver + * transport itself is secure, and the remote + * HV connection is secure + * + * ie, we don't want to claim to be secure if the + * remote driver is used to connect to a XenD + * driver using unencrypted HTTP:/// access + */ + rv = priv->is_secure && ret.secure ? 1 : 0; + +done: + remoteDriverUnlock(priv); + return rv; +} + +static int remoteIsEncrypted(virConnectPtr conn) +{ + int rv = -1; + int encrypted = 0; + struct private_data *priv = conn->privateData; + remote_is_secure_ret ret; + remoteDriverLock(priv); + + memset (&ret, 0, sizeof ret); + if (call (conn, priv, 0, REMOTE_PROC_IS_SECURE, + (xdrproc_t) xdr_void, (char *) NULL, + (xdrproc_t) xdr_remote_is_secure_ret, (char *) &ret) == -1) + goto done; + + if (priv->uses_tls) + encrypted = 1; +#if HAVE_SASL + else if (priv->saslconn) + encrypted = 1; +#endif + + + /* We claim to be encrypted, if the remote driver + * transport itself is encrypted, and the remote + * HV connection is secure. + * + * Yes, we really don't check the remote 'encrypted' + * option, since it will almost always be false, + * even if secure (eg UNIX sockets). + */ + rv = encrypted && ret.secure ? 1 : 0; + +done: + remoteDriverUnlock(priv); + return rv; +} + + static int remoteGetMaxVcpus (virConnectPtr conn, const char *type) { @@ -1773,6 +1848,54 @@ done: return rv; } +static int +remoteDomainIsActive(virDomainPtr domain) +{ + int rv = -1; + remote_domain_is_active_args args; + remote_domain_is_active_ret ret; + struct private_data *priv = domain->conn->privateData; + + remoteDriverLock(priv); + + make_nonnull_domain (&args.dom, domain); + + if (call (domain->conn, priv, 0, REMOTE_PROC_DOMAIN_IS_ACTIVE, + (xdrproc_t) xdr_remote_domain_is_active_args, (char *) &args, + (xdrproc_t) xdr_remote_domain_is_active_ret, (char *) &ret) == -1) + goto done; + + rv = ret.active; + +done: + remoteDriverUnlock(priv); + return rv; +} + +static int +remoteDomainIsPersistent(virDomainPtr domain) +{ + int rv = -1; + remote_domain_is_persistent_args args; + remote_domain_is_persistent_ret ret; + struct private_data *priv = domain->conn->privateData; + + remoteDriverLock(priv); + + make_nonnull_domain (&args.dom, domain); + + if (call (domain->conn, priv, 0, REMOTE_PROC_DOMAIN_IS_PERSISTENT, + (xdrproc_t) xdr_remote_domain_is_persistent_args, (char *) &args, + (xdrproc_t) xdr_remote_domain_is_persistent_ret, (char *) &ret) == -1) + goto done; + + rv = ret.persistent; + +done: + remoteDriverUnlock(priv); + return rv; +} + static virDomainPtr remoteDomainCreateXML (virConnectPtr conn, const char *xmlDesc, @@ -3572,6 +3695,54 @@ done: return net; } +static int +remoteNetworkIsActive(virNetworkPtr network) +{ + int rv = -1; + remote_network_is_active_args args; + remote_network_is_active_ret ret; + struct private_data *priv = network->conn->privateData; + + remoteDriverLock(priv); + + make_nonnull_network (&args.net, network); + + if (call (network->conn, priv, 0, REMOTE_PROC_NETWORK_IS_ACTIVE, + (xdrproc_t) xdr_remote_network_is_active_args, (char *) &args, + (xdrproc_t) xdr_remote_network_is_active_ret, (char *) &ret) == -1) + goto done; + + rv = ret.active; + +done: + remoteDriverUnlock(priv); + return rv; +} + +static int +remoteNetworkIsPersistent(virNetworkPtr network) +{ + int rv = -1; + remote_network_is_persistent_args args; + remote_network_is_persistent_ret ret; + struct private_data *priv = network->conn->privateData; + + remoteDriverLock(priv); + + make_nonnull_network (&args.net, network); + + if (call (network->conn, priv, 0, REMOTE_PROC_NETWORK_IS_PERSISTENT, + (xdrproc_t) xdr_remote_network_is_persistent_args, (char *) &args, + (xdrproc_t) xdr_remote_network_is_persistent_ret, (char *) &ret) == -1) + goto done; + + rv = ret.persistent; + +done: + remoteDriverUnlock(priv); + return rv; +} + static virNetworkPtr remoteNetworkCreateXML (virConnectPtr conn, const char *xmlDesc) { @@ -4060,6 +4231,32 @@ done: return iface; } + +static int +remoteInterfaceIsActive(virInterfacePtr iface) +{ + int rv = -1; + remote_interface_is_active_args args; + remote_interface_is_active_ret ret; + struct private_data *priv = iface->conn->privateData; + + remoteDriverLock(priv); + + make_nonnull_interface (&args.iface, iface); + + if (call (iface->conn, priv, 0, REMOTE_PROC_INTERFACE_IS_ACTIVE, + (xdrproc_t) xdr_remote_interface_is_active_args, (char *) &args, + (xdrproc_t) xdr_remote_interface_is_active_ret, (char *) &ret) == -1) + goto done; + + rv = ret.active; + +done: + remoteDriverUnlock(priv); + return rv; +} + + static char * remoteInterfaceGetXMLDesc (virInterfacePtr iface, unsigned int flags) @@ -4522,6 +4719,55 @@ done: } +static int +remoteStoragePoolIsActive(virStoragePoolPtr pool) +{ + int rv = -1; + remote_storage_pool_is_active_args args; + remote_storage_pool_is_active_ret ret; + struct private_data *priv = pool->conn->privateData; + + remoteDriverLock(priv); + + make_nonnull_storage_pool (&args.pool, pool); + + if (call (pool->conn, priv, 0, REMOTE_PROC_STORAGE_POOL_IS_ACTIVE, + (xdrproc_t) xdr_remote_storage_pool_is_active_args, (char *) &args, + (xdrproc_t) xdr_remote_storage_pool_is_active_ret, (char *) &ret) == -1) + goto done; + + rv = ret.active; + +done: + remoteDriverUnlock(priv); + return rv; +} + +static int +remoteStoragePoolIsPersistent(virStoragePoolPtr pool) +{ + int rv = -1; + remote_storage_pool_is_persistent_args args; + remote_storage_pool_is_persistent_ret ret; + struct private_data *priv = pool->conn->privateData; + + remoteDriverLock(priv); + + make_nonnull_storage_pool (&args.pool, pool); + + if (call (pool->conn, priv, 0, REMOTE_PROC_STORAGE_POOL_IS_PERSISTENT, + (xdrproc_t) xdr_remote_storage_pool_is_persistent_args, (char *) &args, + (xdrproc_t) xdr_remote_storage_pool_is_persistent_ret, (char *) &ret) == -1) + goto done; + + rv = ret.persistent; + +done: + remoteDriverUnlock(priv); + return rv; +} + + static virStoragePoolPtr remoteStoragePoolCreateXML (virConnectPtr conn, const char *xmlDesc, unsigned int flags) { @@ -6205,6 +6451,7 @@ remoteAuthSASL (virConnectPtr conn, struct private_data *priv, int in_open, _("negotiation SSF %d was not strong enough"), ssf); goto cleanup; } + priv->is_secure = 1; } DEBUG0("SASL authentication complete"); @@ -8449,10 +8696,10 @@ static virDriver remote_driver = { remoteNodeDeviceReAttach, /* nodeDeviceReAttach */ remoteNodeDeviceReset, /* nodeDeviceReset */ remoteDomainMigratePrepareTunnel, /* domainMigratePrepareTunnel */ - NULL, /* isEncrypted */ - NULL, /* isSecure */ - NULL, /* domainIsActive */ - NULL, /* domainIsEncrypted */ + remoteIsEncrypted, /* isEncrypted */ + remoteIsSecure, /* isSecure */ + remoteDomainIsActive, /* domainIsActive */ + remoteDomainIsPersistent, /* domainIsPersistent */ }; static virNetworkDriver network_driver = { @@ -8474,8 +8721,8 @@ static virNetworkDriver network_driver = { .networkGetBridgeName = remoteNetworkGetBridgeName, .networkGetAutostart = remoteNetworkGetAutostart, .networkSetAutostart = remoteNetworkSetAutostart, - .networkIsActive = NULL, - .networkIsPersistent = NULL, + .networkIsActive = remoteNetworkIsActive, + .networkIsPersistent = remoteNetworkIsPersistent, }; static virInterfaceDriver interface_driver = { @@ -8493,7 +8740,7 @@ static virInterfaceDriver interface_driver = { .interfaceUndefine = remoteInterfaceUndefine, .interfaceCreate = remoteInterfaceCreate, .interfaceDestroy = remoteInterfaceDestroy, - .interfaceIsActive = NULL, /* interfaceIsActive */ + .interfaceIsActive = remoteInterfaceIsActive, }; static virStorageDriver storage_driver = { @@ -8532,9 +8779,8 @@ static virStorageDriver storage_driver = { .volGetInfo = remoteStorageVolGetInfo, .volGetXMLDesc = remoteStorageVolDumpXML, .volGetPath = remoteStorageVolGetPath, - - .poolIsActive = NULL, /* poolIsActive */ - .poolIsPersistent = NULL, /* poolIsEncrypted */ + .poolIsActive = remoteStoragePoolIsActive, + .poolIsPersistent = remoteStoragePoolIsPersistent, }; static virSecretDriver secret_driver = { diff --git a/src/remote/remote_protocol.c b/src/remote/remote_protocol.c index 1449ed4..b6a85a8 100644 --- a/src/remote/remote_protocol.c +++ b/src/remote/remote_protocol.c @@ -4,7 +4,7 @@ * It was generated using rpcgen. */ -#include "remote_protocol.h" +#include "./remote/remote_protocol.h" #include "internal.h" #include <arpa/inet.h> @@ -2713,6 +2713,141 @@ xdr_remote_domain_migrate_prepare_tunnel_args (XDR *xdrs, remote_domain_migrate_ } bool_t +xdr_remote_is_secure_ret (XDR *xdrs, remote_is_secure_ret *objp) +{ + + if (!xdr_int (xdrs, &objp->secure)) + return FALSE; + return TRUE; +} + +bool_t +xdr_remote_domain_is_active_args (XDR *xdrs, remote_domain_is_active_args *objp) +{ + + if (!xdr_remote_nonnull_domain (xdrs, &objp->dom)) + return FALSE; + return TRUE; +} + +bool_t +xdr_remote_domain_is_active_ret (XDR *xdrs, remote_domain_is_active_ret *objp) +{ + + if (!xdr_int (xdrs, &objp->active)) + return FALSE; + return TRUE; +} + +bool_t +xdr_remote_domain_is_persistent_args (XDR *xdrs, remote_domain_is_persistent_args *objp) +{ + + if (!xdr_remote_nonnull_domain (xdrs, &objp->dom)) + return FALSE; + return TRUE; +} + +bool_t +xdr_remote_domain_is_persistent_ret (XDR *xdrs, remote_domain_is_persistent_ret *objp) +{ + + if (!xdr_int (xdrs, &objp->persistent)) + return FALSE; + return TRUE; +} + +bool_t +xdr_remote_network_is_active_args (XDR *xdrs, remote_network_is_active_args *objp) +{ + + if (!xdr_remote_nonnull_network (xdrs, &objp->net)) + return FALSE; + return TRUE; +} + +bool_t +xdr_remote_network_is_active_ret (XDR *xdrs, remote_network_is_active_ret *objp) +{ + + if (!xdr_int (xdrs, &objp->active)) + return FALSE; + return TRUE; +} + +bool_t +xdr_remote_network_is_persistent_args (XDR *xdrs, remote_network_is_persistent_args *objp) +{ + + if (!xdr_remote_nonnull_network (xdrs, &objp->net)) + return FALSE; + return TRUE; +} + +bool_t +xdr_remote_network_is_persistent_ret (XDR *xdrs, remote_network_is_persistent_ret *objp) +{ + + if (!xdr_int (xdrs, &objp->persistent)) + return FALSE; + return TRUE; +} + +bool_t +xdr_remote_storage_pool_is_active_args (XDR *xdrs, remote_storage_pool_is_active_args *objp) +{ + + if (!xdr_remote_nonnull_storage_pool (xdrs, &objp->pool)) + return FALSE; + return TRUE; +} + +bool_t +xdr_remote_storage_pool_is_active_ret (XDR *xdrs, remote_storage_pool_is_active_ret *objp) +{ + + if (!xdr_int (xdrs, &objp->active)) + return FALSE; + return TRUE; +} + +bool_t +xdr_remote_storage_pool_is_persistent_args (XDR *xdrs, remote_storage_pool_is_persistent_args *objp) +{ + + if (!xdr_remote_nonnull_storage_pool (xdrs, &objp->pool)) + return FALSE; + return TRUE; +} + +bool_t +xdr_remote_storage_pool_is_persistent_ret (XDR *xdrs, remote_storage_pool_is_persistent_ret *objp) +{ + + if (!xdr_int (xdrs, &objp->persistent)) + return FALSE; + return TRUE; +} + +bool_t +xdr_remote_interface_is_active_args (XDR *xdrs, remote_interface_is_active_args *objp) +{ + + if (!xdr_remote_nonnull_interface (xdrs, &objp->iface)) + return FALSE; + return TRUE; +} + +bool_t +xdr_remote_interface_is_active_ret (XDR *xdrs, remote_interface_is_active_ret *objp) +{ + + if (!xdr_int (xdrs, &objp->active)) + return FALSE; + return TRUE; +} + +bool_t xdr_remote_procedure (XDR *xdrs, remote_procedure *objp) { diff --git a/src/remote/remote_protocol.h b/src/remote/remote_protocol.h index d87e8bc..885695c 100644 --- a/src/remote/remote_protocol.h +++ b/src/remote/remote_protocol.h @@ -1537,6 +1537,80 @@ struct remote_domain_migrate_prepare_tunnel_args { }; typedef struct remote_domain_migrate_prepare_tunnel_args remote_domain_migrate_prepare_tunnel_args; +struct remote_is_secure_ret { + int secure; +}; +typedef struct remote_is_secure_ret remote_is_secure_ret; + +struct remote_domain_is_active_args { + remote_nonnull_domain dom; +}; +typedef struct remote_domain_is_active_args remote_domain_is_active_args; + +struct remote_domain_is_active_ret { + int active; +}; +typedef struct remote_domain_is_active_ret remote_domain_is_active_ret; + +struct remote_domain_is_persistent_args { + remote_nonnull_domain dom; +}; +typedef struct remote_domain_is_persistent_args remote_domain_is_persistent_args; + +struct remote_domain_is_persistent_ret { + int persistent; +}; +typedef struct remote_domain_is_persistent_ret remote_domain_is_persistent_ret; + +struct remote_network_is_active_args { + remote_nonnull_network net; +}; +typedef struct remote_network_is_active_args remote_network_is_active_args; + +struct remote_network_is_active_ret { + int active; +}; +typedef struct remote_network_is_active_ret remote_network_is_active_ret; + +struct remote_network_is_persistent_args { + remote_nonnull_network net; +}; +typedef struct remote_network_is_persistent_args remote_network_is_persistent_args; + +struct remote_network_is_persistent_ret { + int persistent; +}; +typedef struct remote_network_is_persistent_ret remote_network_is_persistent_ret; + +struct remote_storage_pool_is_active_args { + remote_nonnull_storage_pool pool; +}; +typedef struct remote_storage_pool_is_active_args remote_storage_pool_is_active_args; + +struct remote_storage_pool_is_active_ret { + int active; +}; +typedef struct remote_storage_pool_is_active_ret remote_storage_pool_is_active_ret; + +struct remote_storage_pool_is_persistent_args { + remote_nonnull_storage_pool pool; +}; +typedef struct remote_storage_pool_is_persistent_args remote_storage_pool_is_persistent_args; + +struct remote_storage_pool_is_persistent_ret { + int persistent; +}; +typedef struct remote_storage_pool_is_persistent_ret remote_storage_pool_is_persistent_ret; + +struct remote_interface_is_active_args { + remote_nonnull_interface iface; +}; +typedef struct remote_interface_is_active_args remote_interface_is_active_args; + +struct remote_interface_is_active_ret { + int active; +}; +typedef struct remote_interface_is_active_ret remote_interface_is_active_ret; #define REMOTE_PROGRAM 0x20008086 #define REMOTE_PROTOCOL_VERSION 1 @@ -1689,6 +1763,14 @@ enum remote_procedure { REMOTE_PROC_SECRET_UNDEFINE = 146, REMOTE_PROC_SECRET_LOOKUP_BY_USAGE = 147, REMOTE_PROC_DOMAIN_MIGRATE_PREPARE_TUNNEL = 148, + REMOTE_PROC_IS_SECURE = 149, + REMOTE_PROC_DOMAIN_IS_ACTIVE = 150, + REMOTE_PROC_DOMAIN_IS_PERSISTENT = 151, + REMOTE_PROC_NETWORK_IS_ACTIVE = 152, + REMOTE_PROC_NETWORK_IS_PERSISTENT = 153, + REMOTE_PROC_STORAGE_POOL_IS_ACTIVE = 154, + REMOTE_PROC_STORAGE_POOL_IS_PERSISTENT = 155, + REMOTE_PROC_INTERFACE_IS_ACTIVE = 156, }; typedef enum remote_procedure remote_procedure; @@ -1970,6 +2052,21 @@ extern bool_t xdr_remote_secret_undefine_args (XDR *, remote_secret_undefine_ar extern bool_t xdr_remote_secret_lookup_by_usage_args (XDR *, remote_secret_lookup_by_usage_args*); extern bool_t xdr_remote_secret_lookup_by_usage_ret (XDR *, remote_secret_lookup_by_usage_ret*); extern bool_t xdr_remote_domain_migrate_prepare_tunnel_args (XDR *, remote_domain_migrate_prepare_tunnel_args*); +extern bool_t xdr_remote_is_secure_ret (XDR *, remote_is_secure_ret*); +extern bool_t xdr_remote_domain_is_active_args (XDR *, remote_domain_is_active_args*); +extern bool_t xdr_remote_domain_is_active_ret (XDR *, remote_domain_is_active_ret*); +extern bool_t xdr_remote_domain_is_persistent_args (XDR *, remote_domain_is_persistent_args*); +extern bool_t xdr_remote_domain_is_persistent_ret (XDR *, remote_domain_is_persistent_ret*); +extern bool_t xdr_remote_network_is_active_args (XDR *, remote_network_is_active_args*); +extern bool_t xdr_remote_network_is_active_ret (XDR *, remote_network_is_active_ret*); +extern bool_t xdr_remote_network_is_persistent_args (XDR *, remote_network_is_persistent_args*); +extern bool_t xdr_remote_network_is_persistent_ret (XDR *, remote_network_is_persistent_ret*); +extern bool_t xdr_remote_storage_pool_is_active_args (XDR *, remote_storage_pool_is_active_args*); +extern bool_t xdr_remote_storage_pool_is_active_ret (XDR *, remote_storage_pool_is_active_ret*); +extern bool_t xdr_remote_storage_pool_is_persistent_args (XDR *, remote_storage_pool_is_persistent_args*); +extern bool_t xdr_remote_storage_pool_is_persistent_ret (XDR *, remote_storage_pool_is_persistent_ret*); +extern bool_t xdr_remote_interface_is_active_args (XDR *, remote_interface_is_active_args*); +extern bool_t xdr_remote_interface_is_active_ret (XDR *, remote_interface_is_active_ret*); extern bool_t xdr_remote_procedure (XDR *, remote_procedure*); extern bool_t xdr_remote_message_type (XDR *, remote_message_type*); extern bool_t xdr_remote_message_status (XDR *, remote_message_status*); @@ -2225,6 +2322,21 @@ extern bool_t xdr_remote_secret_undefine_args (); extern bool_t xdr_remote_secret_lookup_by_usage_args (); extern bool_t xdr_remote_secret_lookup_by_usage_ret (); extern bool_t xdr_remote_domain_migrate_prepare_tunnel_args (); +extern bool_t xdr_remote_is_secure_ret (); +extern bool_t xdr_remote_domain_is_active_args (); +extern bool_t xdr_remote_domain_is_active_ret (); +extern bool_t xdr_remote_domain_is_persistent_args (); +extern bool_t xdr_remote_domain_is_persistent_ret (); +extern bool_t xdr_remote_network_is_active_args (); +extern bool_t xdr_remote_network_is_active_ret (); +extern bool_t xdr_remote_network_is_persistent_args (); +extern bool_t xdr_remote_network_is_persistent_ret (); +extern bool_t xdr_remote_storage_pool_is_active_args (); +extern bool_t xdr_remote_storage_pool_is_active_ret (); +extern bool_t xdr_remote_storage_pool_is_persistent_args (); +extern bool_t xdr_remote_storage_pool_is_persistent_ret (); +extern bool_t xdr_remote_interface_is_active_args (); +extern bool_t xdr_remote_interface_is_active_ret (); extern bool_t xdr_remote_procedure (); extern bool_t xdr_remote_message_type (); extern bool_t xdr_remote_message_status (); diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 2b3c03b..1886282 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -1362,6 +1362,73 @@ struct remote_domain_migrate_prepare_tunnel_args { remote_nonnull_string dom_xml; }; + +struct remote_is_secure_ret { + int secure; +}; + + +struct remote_domain_is_active_args { + remote_nonnull_domain dom; +}; + +struct remote_domain_is_active_ret { + int active; +}; + + +struct remote_domain_is_persistent_args { + remote_nonnull_domain dom; +}; + +struct remote_domain_is_persistent_ret { + int persistent; +}; + + +struct remote_network_is_active_args { + remote_nonnull_network net; +}; + +struct remote_network_is_active_ret { + int active; +}; + +struct remote_network_is_persistent_args { + remote_nonnull_network net; +}; + +struct remote_network_is_persistent_ret { + int persistent; +}; + + +struct remote_storage_pool_is_active_args { + remote_nonnull_storage_pool pool; +}; + +struct remote_storage_pool_is_active_ret { + int active; +}; + +struct remote_storage_pool_is_persistent_args { + remote_nonnull_storage_pool pool; +}; + +struct remote_storage_pool_is_persistent_ret { + int persistent; +}; + + +struct remote_interface_is_active_args { + remote_nonnull_interface iface; +}; + +struct remote_interface_is_active_ret { + int active; +}; + + /*----- Protocol. -----*/ /* Define the program number, protocol version and procedure numbers here. */ @@ -1518,12 +1585,11 @@ enum remote_procedure { REMOTE_PROC_INTERFACE_DESTROY = 134, REMOTE_PROC_DOMAIN_XML_FROM_NATIVE = 135, REMOTE_PROC_DOMAIN_XML_TO_NATIVE = 136, - REMOTE_PROC_NUM_OF_DEFINED_INTERFACES = 137, REMOTE_PROC_LIST_DEFINED_INTERFACES = 138, - REMOTE_PROC_NUM_OF_SECRETS = 139, REMOTE_PROC_LIST_SECRETS = 140, + REMOTE_PROC_SECRET_LOOKUP_BY_UUID = 141, REMOTE_PROC_SECRET_DEFINE_XML = 142, REMOTE_PROC_SECRET_GET_XML_DESC = 143, @@ -1531,11 +1597,24 @@ enum remote_procedure { REMOTE_PROC_SECRET_GET_VALUE = 145, REMOTE_PROC_SECRET_UNDEFINE = 146, REMOTE_PROC_SECRET_LOOKUP_BY_USAGE = 147, + REMOTE_PROC_DOMAIN_MIGRATE_PREPARE_TUNNEL = 148, + REMOTE_PROC_IS_SECURE = 149, + REMOTE_PROC_DOMAIN_IS_ACTIVE = 150, - REMOTE_PROC_DOMAIN_MIGRATE_PREPARE_TUNNEL = 148 -}; + REMOTE_PROC_DOMAIN_IS_PERSISTENT = 151, + REMOTE_PROC_NETWORK_IS_ACTIVE = 152, + REMOTE_PROC_NETWORK_IS_PERSISTENT = 153, + REMOTE_PROC_STORAGE_POOL_IS_ACTIVE = 154, + REMOTE_PROC_STORAGE_POOL_IS_PERSISTENT = 155, + REMOTE_PROC_INTERFACE_IS_ACTIVE = 156 + /* + * Notice how the entries are grouped in sets of 10 ? + * Nice isn't it. Please keep it this way when adding more. + */ +}; + /* * RPC wire format * diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 4f8949b..00ee472 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -464,6 +464,49 @@ cleanup: } +static int storagePoolIsActive(virStoragePoolPtr net) +{ + virStorageDriverStatePtr driver = net->conn->privateData; + virStoragePoolObjPtr obj; + int ret = -1; + + storageDriverLock(driver); + obj = virStoragePoolObjFindByUUID(&driver->pools, net->uuid); + storageDriverUnlock(driver); + if (!obj) { + virStorageReportError(net->conn, VIR_ERR_NO_STORAGE_POOL, NULL); + goto cleanup; + } + ret = virStoragePoolObjIsActive(obj); + +cleanup: + if (obj) + virStoragePoolObjUnlock(obj); + return ret; +} + +static int storagePoolIsPersistent(virStoragePoolPtr net) +{ + virStorageDriverStatePtr driver = net->conn->privateData; + virStoragePoolObjPtr obj; + int ret = -1; + + storageDriverLock(driver); + obj = virStoragePoolObjFindByUUID(&driver->pools, net->uuid); + storageDriverUnlock(driver); + if (!obj) { + virStorageReportError(net->conn, VIR_ERR_NO_STORAGE_POOL, NULL); + goto cleanup; + } + ret = obj->configFile ? 1 : 0; + +cleanup: + if (obj) + virStoragePoolObjUnlock(obj); + return ret; +} + + static virStoragePoolPtr storagePoolCreate(virConnectPtr conn, const char *xml, @@ -1740,6 +1783,9 @@ static virStorageDriver storageDriver = { .volGetInfo = storageVolumeGetInfo, .volGetXMLDesc = storageVolumeGetXMLDesc, .volGetPath = storageVolumeGetPath, + + .poolIsActive = storagePoolIsActive, + .poolIsPersistent = storagePoolIsPersistent, }; diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 88dc6a5..afa9b02 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1006,6 +1006,17 @@ static char *testGetHostname (virConnectPtr conn) return result; } + +static int testIsSecure(virConnectPtr conn ATTRIBUTE_UNUSED) +{ + return 1; +} + +static int testIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED) +{ + return 0; +} + static int testGetMaxVCPUs(virConnectPtr conn ATTRIBUTE_UNUSED, const char *type ATTRIBUTE_UNUSED) { @@ -1047,6 +1058,48 @@ static int testNumOfDomains(virConnectPtr conn) return numActive; } +static int testDomainIsActive(virDomainPtr dom) +{ + testConnPtr privconn = dom->conn->privateData; + virDomainObjPtr obj; + int ret = -1; + + testDriverLock(privconn); + obj = virDomainFindByUUID(&privconn->domains, dom->uuid); + testDriverUnlock(privconn); + if (!obj) { + testError(dom->conn, VIR_ERR_NO_DOMAIN, NULL); + goto cleanup; + } + ret = virDomainObjIsActive(obj); + +cleanup: + if (obj) + virDomainObjUnlock(obj); + return ret; +} + +static int testDomainIsPersistent(virDomainPtr dom) +{ + testConnPtr privconn = dom->conn->privateData; + virDomainObjPtr obj; + int ret = -1; + + testDriverLock(privconn); + obj = virDomainFindByUUID(&privconn->domains, dom->uuid); + testDriverUnlock(privconn); + if (!obj) { + testError(dom->conn, VIR_ERR_NO_DOMAIN, NULL); + goto cleanup; + } + ret = obj->persistent; + +cleanup: + if (obj) + virDomainObjUnlock(obj); + return ret; +} + static virDomainPtr testDomainCreateXML(virConnectPtr conn, const char *xml, unsigned int flags ATTRIBUTE_UNUSED) @@ -2441,6 +2494,50 @@ no_memory: return -1; } + +static int testNetworkIsActive(virNetworkPtr net) +{ + testConnPtr privconn = net->conn->privateData; + virNetworkObjPtr obj; + int ret = -1; + + testDriverLock(privconn); + obj = virNetworkFindByUUID(&privconn->networks, net->uuid); + testDriverUnlock(privconn); + if (!obj) { + testError(net->conn, VIR_ERR_NO_NETWORK, NULL); + goto cleanup; + } + ret = virNetworkObjIsActive(obj); + +cleanup: + if (obj) + virNetworkObjUnlock(obj); + return ret; +} + +static int testNetworkIsPersistent(virNetworkPtr net) +{ + testConnPtr privconn = net->conn->privateData; + virNetworkObjPtr obj; + int ret = -1; + + testDriverLock(privconn); + obj = virNetworkFindByUUID(&privconn->networks, net->uuid); + testDriverUnlock(privconn); + if (!obj) { + testError(net->conn, VIR_ERR_NO_NETWORK, NULL); + goto cleanup; + } + ret = obj->persistent; + +cleanup: + if (obj) + virNetworkObjUnlock(obj); + return ret; +} + + static virNetworkPtr testNetworkCreate(virConnectPtr conn, const char *xml) { testConnPtr privconn = conn->privateData; virNetworkDefPtr def; @@ -2857,6 +2954,28 @@ cleanup: return ret; } +static int testInterfaceIsActive(virInterfacePtr iface) +{ + testConnPtr privconn = iface->conn->privateData; + virInterfaceObjPtr obj; + int ret = -1; + + testDriverLock(privconn); + obj = virInterfaceFindByName(&privconn->ifaces, iface->name); + testDriverUnlock(privconn); + if (!obj) { + testError(iface->conn, VIR_ERR_NO_INTERFACE, NULL); + goto cleanup; + } + ret = virInterfaceObjIsActive(obj); + +cleanup: + if (obj) + virInterfaceObjUnlock(obj); + return ret; +} + + static char *testInterfaceGetXMLDesc(virInterfacePtr iface, unsigned int flags ATTRIBUTE_UNUSED) { @@ -3001,6 +3120,7 @@ cleanup: * Storage Driver routines */ + static int testStoragePoolObjSetDefaults(virConnectPtr conn, virStoragePoolObjPtr pool) { @@ -3032,6 +3152,7 @@ static int testStorageClose(virConnectPtr conn) { return 0; } + static virStoragePoolPtr testStoragePoolLookupByUUID(virConnectPtr conn, const unsigned char *uuid) { @@ -3177,6 +3298,50 @@ no_memory: } +static int testStoragePoolIsActive(virStoragePoolPtr pool) +{ + testConnPtr privconn = pool->conn->privateData; + virStoragePoolObjPtr obj; + int ret = -1; + + testDriverLock(privconn); + obj = virStoragePoolObjFindByUUID(&privconn->pools, pool->uuid); + testDriverUnlock(privconn); + if (!obj) { + testError(pool->conn, VIR_ERR_NO_STORAGE_POOL, NULL); + goto cleanup; + } + ret = virStoragePoolObjIsActive(obj); + +cleanup: + if (obj) + virStoragePoolObjUnlock(obj); + return ret; +} + +static int testStoragePoolIsPersistent(virStoragePoolPtr pool) +{ + testConnPtr privconn = pool->conn->privateData; + virStoragePoolObjPtr obj; + int ret = -1; + + testDriverLock(privconn); + obj = virStoragePoolObjFindByUUID(&privconn->pools, pool->uuid); + testDriverUnlock(privconn); + if (!obj) { + testError(pool->conn, VIR_ERR_NO_STORAGE_POOL, NULL); + goto cleanup; + } + ret = obj->configFile ? 1 : 0; + +cleanup: + if (obj) + virStoragePoolObjUnlock(obj); + return ret; +} + + + static int testStoragePoolStart(virStoragePoolPtr pool, unsigned int flags ATTRIBUTE_UNUSED) { @@ -4558,10 +4723,10 @@ static virDriver testDriver = { NULL, /* nodeDeviceReAttach */ NULL, /* nodeDeviceReset */ NULL, /* domainMigratePrepareTunnel */ - NULL, /* isEncrypted */ - NULL, /* isSecure */ - NULL, /* domainIsActive */ - NULL, /* domainIsEncrypted */ + testIsEncrypted, /* isEncrypted */ + testIsSecure, /* isEncrypted */ + testDomainIsActive, /* domainIsActive */ + testDomainIsPersistent, /* domainIsPersistent */ }; static virNetworkDriver testNetworkDriver = { @@ -4583,8 +4748,8 @@ static virNetworkDriver testNetworkDriver = { testNetworkGetBridgeName, /* networkGetBridgeName */ testNetworkGetAutostart, /* networkGetAutostart */ testNetworkSetAutostart, /* networkSetAutostart */ - NULL, /* networkIsActive */ - NULL, /* networkIsEncrypted */ + testNetworkIsActive, /* domainIsActive */ + testNetworkIsPersistent, /* domainIsPersistent */ }; static virInterfaceDriver testInterfaceDriver = { @@ -4602,7 +4767,7 @@ static virInterfaceDriver testInterfaceDriver = { testInterfaceUndefine, /* interfaceUndefine */ testInterfaceCreate, /* interfaceCreate */ testInterfaceDestroy, /* interfaceDestroy */ - NULL, /* interfaceIsActive */ + testInterfaceIsActive, /* domainIsActive */ }; @@ -4643,9 +4808,8 @@ static virStorageDriver testStorageDriver = { .volGetInfo = testStorageVolumeGetInfo, .volGetXMLDesc = testStorageVolumeGetXMLDesc, .volGetPath = testStorageVolumeGetPath, - - .poolIsActive = NULL, /* poolIsActive */ - .poolIsPersistent = NULL, /* poolIsEncrypted */ + .poolIsActive = testStoragePoolIsActive, + .poolIsPersistent = testStoragePoolIsPersistent, }; static virDeviceMonitor testDevMonitor = { diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index 9b450d9..0a87341 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -981,6 +981,20 @@ static const char *umlGetType(virConnectPtr conn ATTRIBUTE_UNUSED) { } +static int umlIsSecure(virConnectPtr conn ATTRIBUTE_UNUSED) +{ + /* Trivially secure, since always inside the daemon */ + return 1; +} + + +static int umlIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED) +{ + /* Not encrypted, but remote driver takes care of that */ + return 0; +} + + static char *umlGetCapabilities(virConnectPtr conn) { struct uml_driver *driver = (struct uml_driver *)conn->privateData; char *xml; @@ -1104,6 +1118,51 @@ cleanup: return dom; } + +static int umlDomainIsActive(virDomainPtr dom) +{ + struct uml_driver *driver = dom->conn->privateData; + virDomainObjPtr obj; + int ret = -1; + + umlDriverLock(driver); + obj = virDomainFindByUUID(&driver->domains, dom->uuid); + umlDriverUnlock(driver); + if (!obj) { + umlReportError(dom->conn, NULL, NULL, VIR_ERR_NO_DOMAIN, NULL); + goto cleanup; + } + ret = virDomainObjIsActive(obj); + +cleanup: + if (obj) + virDomainObjUnlock(obj); + return ret; +} + + +static int umlDomainIsPersistent(virDomainPtr dom) +{ + struct uml_driver *driver = dom->conn->privateData; + virDomainObjPtr obj; + int ret = -1; + + umlDriverLock(driver); + obj = virDomainFindByUUID(&driver->domains, dom->uuid); + umlDriverUnlock(driver); + if (!obj) { + umlReportError(dom->conn, NULL, NULL, VIR_ERR_NO_DOMAIN, NULL); + goto cleanup; + } + ret = obj->persistent; + +cleanup: + if (obj) + virDomainObjUnlock(obj); + return ret; +} + + static int umlGetVersion(virConnectPtr conn, unsigned long *version) { struct uml_driver *driver = conn->privateData; struct utsname ut; @@ -1862,10 +1921,10 @@ static virDriver umlDriver = { NULL, /* nodeDeviceReAttach */ NULL, /* nodeDeviceReset */ NULL, /* domainMigratePrepareTunnel */ - NULL, /* isEncrypted */ - NULL, /* isSecure */ - NULL, /* domainIsActive */ - NULL, /* domainIsEncrypted */ + umlIsEncrypted, + umlIsSecure, + umlDomainIsActive, + umlDomainIsPersistent, }; diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 5878154..28651a4 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -607,6 +607,19 @@ static char *vboxGetHostname(virConnectPtr conn) { return hostname; } + +static int vboxIsSecure(virConnectPtr conn ATTRIBUTE_UNUSED) { + /* Driver is using local, non-network based transport */ + return 1; +} + + +static int vboxIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED) { + /* No encryption is needed, or used on the local transport*/ + return 0; +} + + static int vboxGetMaxVcpus(virConnectPtr conn, const char *type ATTRIBUTE_UNUSED) { vboxGlobalData *data = conn->privateData; PRUint32 maxCPUCount = 0; @@ -1030,6 +1043,93 @@ static virDomainPtr vboxDomainLookupByName(virConnectPtr conn, const char *name) return dom; } + +static int vboxDomainIsActive(virDomainPtr dom) { + nsresult rc; + vboxGlobalData *data = dom->conn->privateData; + IMachine **machines = NULL; + PRUint32 machineCnt = 0; + vboxIID *iid = NULL; + char *machineNameUtf8 = NULL; + PRUnichar *machineNameUtf16 = NULL; + unsigned char iidl[VIR_UUID_BUFLEN]; + int i, matched = 0; + int ret = -1; + + if(data->vboxObj) { + rc = data->vboxObj->vtbl->GetMachines(data->vboxObj, &machineCnt, &machines); + if (NS_FAILED(rc)) { + vboxError(dom->conn, VIR_ERR_INTERNAL_ERROR,"%s, rc=%08x", + "Could not get list of machines",(unsigned)rc); + return -1; + } + + for (i = 0; i < machineCnt; ++i) { + IMachine *machine = machines[i]; + PRBool isAccessible = PR_FALSE; + + if (!machine) + continue; + + machine->vtbl->GetAccessible(machine, &isAccessible); + if (isAccessible) { + + machine->vtbl->GetId(machine, &iid); + if (!iid) + continue; + vboxIIDToUUID(iidl, iid); + vboxIIDUnalloc(iid); + + if (memcmp(dom->uuid, iidl, VIR_UUID_BUFLEN) == 0) { + + PRUint32 state; + + matched = 1; + + machine->vtbl->GetName(machine, &machineNameUtf16); + data->pFuncs->pfnUtf16ToUtf8(machineNameUtf16, &machineNameUtf8); + + machine->vtbl->GetState(machine, &state); + + if ((state == MachineState_Starting) || + (state == MachineState_Running) || + (state == MachineState_Stuck) || + (state == MachineState_Stopping) || + (state == MachineState_Saving) || + (state == MachineState_Restoring) || + (state == MachineState_Discarding) || + (state == MachineState_Paused) ) + ret = 1; + else + ret = 0; + } + + if (matched == 1) + break; + } + } + + /* Do the cleanup and take care you dont leak any memory */ + if (machineNameUtf8) + data->pFuncs->pfnUtf8Free(machineNameUtf8); + if (machineNameUtf16) + data->pFuncs->pfnComUnallocMem(machineNameUtf16); + for (i = 0; i < machineCnt; ++i) { + if (machines[i]) + machines[i]->vtbl->nsisupports.Release((nsISupports *)machines[i]); + } + } + + return ret; +} + + +static int vboxDomainIsPersistent(virDomainPtr dom ATTRIBUTE_UNUSED) { + /* XXX All domains appear to be persistent. Is this true ? */ + return 1; +} + + static int vboxDomainSuspend(virDomainPtr dom) { nsresult rc; vboxGlobalData *data = dom->conn->privateData; @@ -6468,10 +6568,10 @@ virDriver NAME(Driver) = { NULL, /* nodeDeviceReAttach */ NULL, /* nodeDeviceReset */ NULL, /* domainMigratePrepareTunnel */ - NULL, /* isEncrypted */ - NULL, /* isSecure */ - NULL, /* domainIsActive */ - NULL, /* domainIsEncrypted */ + vboxIsEncrypted, + vboxIsSecure, + vboxDomainIsActive, + vboxDomainIsPersistent, }; virNetworkDriver NAME(NetworkDriver) = { diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c index da05253..fcf0506 100644 --- a/src/xen/xen_driver.c +++ b/src/xen/xen_driver.c @@ -45,6 +45,7 @@ #include "memory.h" #include "node_device_conf.h" #include "pci.h" +#include "uuid.h" #define VIR_FROM_THIS VIR_FROM_XEN @@ -497,6 +498,26 @@ xenUnifiedGetHostname (virConnectPtr conn) } static int +xenUnifiedIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED) +{ + return 0; +} + +static int +xenUnifiedIsSecure(virConnectPtr conn) +{ + GET_PRIVATE(conn); + int ret = 1; + + /* All drivers are secure, except for XenD over TCP */ + if (priv->opened[XEN_UNIFIED_XEND_OFFSET] && + priv->addrfamily != AF_UNIX) + ret = 0; + + return ret; +} + +static int xenUnifiedGetMaxVcpus (virConnectPtr conn, const char *type) { GET_PRIVATE(conn); @@ -738,6 +759,75 @@ xenUnifiedDomainLookupByName (virConnectPtr conn, return NULL; } + +static int +xenUnifiedDomainIsActive(virDomainPtr dom) +{ + virDomainPtr currdom; + int ret = -1; + + /* ID field in dom may be outdated, so re-lookup */ + currdom = xenUnifiedDomainLookupByUUID(dom->conn, dom->uuid); + + if (currdom) { + ret = currdom->id == -1 ? 0 : 1; + virDomainFree(currdom); + } + + return ret; +} + +static int +xenUnifiedDomainisPersistent(virDomainPtr dom) +{ + GET_PRIVATE(dom->conn); + virDomainPtr currdom = NULL; + int ret = -1; + + if (priv->opened[XEN_UNIFIED_XM_OFFSET]) { + /* Old Xen, pre-inactive domain management. + * If the XM driver can see the guest, it is definitely persistent */ + currdom = xenXMDomainLookupByUUID(dom->conn, dom->uuid); + if (currdom) + ret = 1; + else + ret = 0; + } else { + /* New Xen with inactive domain management */ + if (priv->opened[XEN_UNIFIED_XEND_OFFSET]) { + currdom = xenDaemonLookupByUUID(dom->conn, dom->uuid); + if (currdom) { + if (currdom->id == -1) { + /* If its inactive, then trivially, it must be persistent */ + ret = 1; + } else { + char *path; + char uuidstr[VIR_UUID_STRING_BUFLEN]; + + /* If its running there's no official way to tell, so we + * go behind xend's back & look at the config dir */ + + virUUIDFormat(dom->uuid, uuidstr); + if (virAsprintf(&path, "%s/%s", XEND_DOMAINS_DIR, uuidstr) < 0) { + virReportOOMError(NULL); + goto done; + } + if (access(path, R_OK) == 0) + ret = 1; + else if (errno == ENOENT) + ret = 0; + } + } + } + } + +done: + if (currdom) + virDomainFree(currdom); + + return ret; +} + static int xenUnifiedDomainSuspend (virDomainPtr dom) { @@ -1726,10 +1816,10 @@ static virDriver xenUnifiedDriver = { xenUnifiedNodeDeviceReAttach, /* nodeDeviceReAttach */ xenUnifiedNodeDeviceReset, /* nodeDeviceReset */ NULL, /* domainMigratePrepareTunnel */ - NULL, /* isEncrypted */ - NULL, /* isSecure */ - NULL, /* domainIsActive */ - NULL, /* domainIsEncrypted */ + xenUnifiedIsEncrypted, + xenUnifiedIsSecure, + xenUnifiedDomainIsActive, + xenUnifiedDomainisPersistent, }; /** diff --git a/src/xen/xen_driver.h b/src/xen/xen_driver.h index 9cc877b..185eb2b 100644 --- a/src/xen/xen_driver.h +++ b/src/xen/xen_driver.h @@ -49,6 +49,8 @@ extern int xenRegister (void); #define XEN_CONFIG_FORMAT_XM "xen-xm" #define XEN_CONFIG_FORMAT_SEXPR "xen-sxpr" +#define XEND_DOMAINS_DIR "/var/lib/xend/domains" + /* _xenUnifiedDriver: * * Entry points into the underlying Xen drivers. This structure diff --git a/src/xen/xen_inotify.c b/src/xen/xen_inotify.c index 9e0407f..d47565d 100644 --- a/src/xen/xen_inotify.c +++ b/src/xen/xen_inotify.c @@ -47,8 +47,6 @@ virReportErrorHelper(NULL, VIR_FROM_XEN_INOTIFY, code, __FILE__, \ __FUNCTION__, __LINE__, fmt) -#define LIBVIRTD_DOMAINS_DIR "/var/lib/xend/domains" - struct xenUnifiedDriver xenInotifyDriver = { xenInotifyOpen, /* open */ xenInotifyClose, /* close */ @@ -125,7 +123,7 @@ xenInotifyXendDomainsDirLookup(virConnectPtr conn, const char *filename, * a filename in the manner: * /var/lib/xend/domains/<uuid>/ */ - uuid_str = filename + strlen(LIBVIRTD_DOMAINS_DIR) + 1; + uuid_str = filename + strlen(XEND_DOMAINS_DIR) + 1; if (virUUIDParse(uuid_str, rawuuid) < 0) { virXenInotifyError(NULL, VIR_ERR_INTERNAL_ERROR, @@ -198,7 +196,7 @@ static int xenInotifyXendDomainsDirRemoveEntry(virConnectPtr conn, const char *fname) { xenUnifiedPrivatePtr priv = conn->privateData; - const char *uuidstr = fname + strlen(LIBVIRTD_DOMAINS_DIR) + 1; + const char *uuidstr = fname + strlen(XEND_DOMAINS_DIR) + 1; unsigned char uuid[VIR_UUID_BUFLEN]; int i; @@ -393,7 +391,7 @@ xenInotifyOpen(virConnectPtr conn ATTRIBUTE_UNUSED, priv->useXenConfigCache = 1; } else { /* /var/lib/xend/domains/<uuid>/config.sxp */ - priv->configDir = LIBVIRTD_DOMAINS_DIR; + priv->configDir = XEND_DOMAINS_DIR; priv->useXenConfigCache = 0; if (VIR_ALLOC(priv->configInfoList) < 0) { diff --git a/src/xen/xen_inotify.h b/src/xen/xen_inotify.h index 70bc63c..48490e7 100644 --- a/src/xen/xen_inotify.h +++ b/src/xen/xen_inotify.h @@ -31,4 +31,5 @@ virDrvOpenStatus xenInotifyOpen (virConnectPtr conn, virConnectAuthPtr auth, int flags); int xenInotifyClose (virConnectPtr conn); + #endif -- 1.6.2.5

2009/10/21 Daniel P. Berrange <berrange@redhat.com>:
This implements the virConnectIsSecure, virConnectIsEncrypted, virDomainIsPersistent, virDomainIsActive, virNetworkIsActive, virNetworkIsPersistent, virStoragePoolIsActive, virStoragePoolIsPersistent, virInterfaceIsActive APIs in (nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent esx: missing domainIsPersistent
That one is simple, ESX has no concept of transient domains, all are persistent.
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly added APIs. * daemon/remote_dispatch*.h: Re-generated from remote_protocol.x * src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c, src/opennebula/one_driver.c, src/openvz/openvz_conf.c, src/openvz/openvz_driver.c, src/phyp/phyp_driver.c, src/remote/remote_driver.c, src/storage/storage_driver.c, src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c, src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c, src/xen/xen_inotify.h: Implement all the new APIs where possible --- daemon/remote.c | 202 ++++++++++++++++++++++++++ daemon/remote_dispatch_args.h | 7 + daemon/remote_dispatch_prototypes.h | 64 +++++++++ daemon/remote_dispatch_ret.h | 8 + daemon/remote_dispatch_table.h | 40 ++++++ src/esx/esx_driver.c | 106 +++++++++++++- src/lxc/lxc_driver.c | 68 +++++++++- src/network/bridge_driver.c | 50 ++++++- src/opennebula/one_driver.c | 21 +++- src/openvz/openvz_conf.c | 2 + src/openvz/openvz_driver.c | 66 ++++++++- src/phyp/phyp_driver.c | 25 +++- src/qemu/qemu_driver.c | 65 ++++++++- src/remote/remote_driver.c | 266 +++++++++++++++++++++++++++++++++-- src/remote/remote_protocol.c | 137 ++++++++++++++++++- src/remote/remote_protocol.h | 112 +++++++++++++++ src/remote/remote_protocol.x | 87 +++++++++++- src/storage/storage_driver.c | 46 ++++++ src/test/test_driver.c | 184 +++++++++++++++++++++++-- src/uml/uml_driver.c | 67 ++++++++- src/vbox/vbox_tmpl.c | 108 ++++++++++++++- src/xen/xen_driver.c | 98 ++++++++++++- src/xen/xen_driver.h | 2 + src/xen/xen_inotify.c | 8 +- src/xen/xen_inotify.h | 1 + 25 files changed, 1772 insertions(+), 68 deletions(-)
[...]
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index 3a57613..c3d1eac 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c [...] +static int +esxDomainIsActive(virDomainPtr dom) +{ + esxPrivate *priv = (esxPrivate *)dom->conn->privateData; + esxVI_String *propertyNameList = NULL; + esxVI_ObjectContent *virtualMachineList = NULL; + esxVI_ObjectContent *virtualMachine = NULL; + esxVI_VirtualMachinePowerState powerState; + int id_candidate = -1; + char *name_candidate = NULL; + unsigned char uuid_candidate[VIR_UUID_BUFLEN]; + char uuid_string[VIR_UUID_STRING_BUFLEN]; + int ret = -1; + + if (esxVI_EnsureSession(dom->conn, priv->host) < 0) { + goto cleanup; + } + + if (esxVI_String_AppendValueListToList(dom->conn, &propertyNameList, + "configStatus\0" + "name\0" + "runtime.powerState\0" + "config.uuid\0") < 0 || + esxVI_GetObjectContent(dom->conn, priv->host, priv->host->vmFolder, + "VirtualMachine", propertyNameList, + esxVI_Boolean_True, &virtualMachineList) < 0) { + goto cleanup; + } + + for (virtualMachine = virtualMachineList; virtualMachine != NULL; + virtualMachine = virtualMachine->_next) { + VIR_FREE(name_candidate); + + if (esxVI_GetVirtualMachineIdentity(dom->conn, virtualMachine, + &id_candidate, &name_candidate, + uuid_candidate) < 0) { + goto cleanup; + } + + if (memcmp(dom->uuid, uuid_candidate, + VIR_UUID_BUFLEN * sizeof(unsigned char)) != 0) { + continue; + } + + if (esxVI_GetVirtualMachinePowerState(dom->conn, virtualMachine, + &powerState) < 0) { + goto cleanup; + } + + /* Only running/suspended virtual machines have an ID != -1 */ + if (powerState != esxVI_VirtualMachinePowerState_PoweredOff) { + ret = 1; + } else { + ret = 0; + } + + break; + } + + if (ret == -1) { + virUUIDFormat(dom->uuid, uuid_string); + + ESX_ERROR(dom->conn, VIR_ERR_NO_DOMAIN, "No domain with UUID '%s'", + uuid_string); + } + + cleanup: + esxVI_String_Free(&propertyNameList); + esxVI_ObjectContent_Free(&virtualMachineList); + VIR_FREE(name_candidate); + + return ret; +}
This looks like based on a verbatim copy of esxDomainLookupByUUID() :) While looking at it I notice that esxDomainLookupByUUID() and esxDomainIsActive() can be improved by using esxVI_LookupVirtualMachineByUuid(). The current version of this functions enumerates all virtual machines of an ESX host and searchs for a matching one. This works but can be improved. The VI API allows to lookup a virtual machine by its UUID. I'll post a separate patch for this. [...]
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 311838c..60c1acc 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c [...] static virNetworkPtr networkCreate(virConnectPtr conn, const char *xml) { struct network_driver *driver = conn->networkPrivateData; virNetworkDefPtr def; @@ -1246,7 +1290,7 @@ static int networkUndefine(virNetworkPtr net) {
network = virNetworkFindByUUID(&driver->networks, net->uuid); if (!network) { - networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_DOMAIN, + networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_NETWORK, "%s", _("no network with matching uuid")); goto cleanup; }
IMHO this should be fixed in a separate patch. [...]
diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index 403f537..83687a2 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -473,6 +473,8 @@ int openvzLoadDomains(struct openvz_driver *driver) {
dom->pid = veid; dom->def->id = dom->state == VIR_DOMAIN_SHUTOFF ? -1 : veid; + /* XXX OpenVZ doesn't appear to have concept of a transient domain */ + dom->persistent = 1;
if (virAsprintf(&dom->def->name, "%i", veid) < 0) goto no_memory;
IMHO this should be fixed in a separate patch
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 4d7f56c..c9fb8a2 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c [...] @@ -777,6 +821,7 @@ openvzDomainDefineXML(virConnectPtr conn, const char *xml) if (!(vm = virDomainAssignDef(conn, &driver->domains, vmdef))) goto cleanup; vmdef = NULL; + vm->persistent = 1;
if (openvzSetInitialConfig(conn, vm->def) < 0) { openvzError(conn, VIR_ERR_INTERNAL_ERROR, @@ -844,6 +889,9 @@ openvzDomainCreateXML(virConnectPtr conn, const char *xml, if (!(vm = virDomainAssignDef(conn, &driver->domains, vmdef))) goto cleanup; vmdef = NULL; + /* All OpenVZ domains seem to be persistent - this is a bit of a violation + * of this libvirt API which is intended for transient domain creation */ + vm->persistent = 1;
if (openvzSetInitialConfig(conn, vm->def) < 0) { openvzError(conn, VIR_ERR_INTERNAL_ERROR,
IMHO this should be fixed in a separate patch too. [...]
diff --git a/src/remote/remote_protocol.c b/src/remote/remote_protocol.c index 1449ed4..b6a85a8 100644 --- a/src/remote/remote_protocol.c +++ b/src/remote/remote_protocol.c @@ -4,7 +4,7 @@ * It was generated using rpcgen. */
-#include "remote_protocol.h" +#include "./remote/remote_protocol.h"
Why change this include? [...]
diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 88dc6a5..afa9b02 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c [...] @@ -4583,8 +4748,8 @@ static virNetworkDriver testNetworkDriver = { testNetworkGetBridgeName, /* networkGetBridgeName */ testNetworkGetAutostart, /* networkGetAutostart */ testNetworkSetAutostart, /* networkSetAutostart */ - NULL, /* networkIsActive */ - NULL, /* networkIsEncrypted */ + testNetworkIsActive, /* domainIsActive */ + testNetworkIsPersistent, /* domainIsPersistent */ };
s/domainIsActive/networkIsActive/ s/domainIsPersistent/networkIsPersistent/
static virInterfaceDriver testInterfaceDriver = { @@ -4602,7 +4767,7 @@ static virInterfaceDriver testInterfaceDriver = { testInterfaceUndefine, /* interfaceUndefine */ testInterfaceCreate, /* interfaceCreate */ testInterfaceDestroy, /* interfaceDestroy */ - NULL, /* interfaceIsActive */ + testInterfaceIsActive, /* domainIsActive */ };
s/domainIsActive/interfaceIsActive/ ACK. Matthias

On Wed, Oct 21, 2009 at 07:15:25PM +0100, Daniel P. Berrange wrote:
This implements the virConnectIsSecure, virConnectIsEncrypted, virDomainIsPersistent, virDomainIsActive, virNetworkIsActive, virNetworkIsPersistent, virStoragePoolIsActive, virStoragePoolIsPersistent, virInterfaceIsActive APIs in (nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent esx: missing domainIsPersistent opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly added APIs. * daemon/remote_dispatch*.h: Re-generated from remote_protocol.x * src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c, src/opennebula/one_driver.c, src/openvz/openvz_conf.c, src/openvz/openvz_driver.c, src/phyp/phyp_driver.c, src/remote/remote_driver.c, src/storage/storage_driver.c, src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c, src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c, src/xen/xen_inotify.h: Implement all the new APIs where possible --- daemon/remote.c | 202 ++++++++++++++++++++++++++ daemon/remote_dispatch_args.h | 7 + daemon/remote_dispatch_prototypes.h | 64 +++++++++ daemon/remote_dispatch_ret.h | 8 + daemon/remote_dispatch_table.h | 40 ++++++ src/esx/esx_driver.c | 106 +++++++++++++- src/lxc/lxc_driver.c | 68 +++++++++- src/network/bridge_driver.c | 50 ++++++- src/opennebula/one_driver.c | 21 +++- src/openvz/openvz_conf.c | 2 + src/openvz/openvz_driver.c | 66 ++++++++- src/phyp/phyp_driver.c | 25 +++- src/qemu/qemu_driver.c | 65 ++++++++- src/remote/remote_driver.c | 266 +++++++++++++++++++++++++++++++++-- src/remote/remote_protocol.c | 137 ++++++++++++++++++- src/remote/remote_protocol.h | 112 +++++++++++++++ src/remote/remote_protocol.x | 87 +++++++++++- src/storage/storage_driver.c | 46 ++++++ src/test/test_driver.c | 184 +++++++++++++++++++++++-- src/uml/uml_driver.c | 67 ++++++++- src/vbox/vbox_tmpl.c | 108 ++++++++++++++- src/xen/xen_driver.c | 98 ++++++++++++- src/xen/xen_driver.h | 2 + src/xen/xen_inotify.c | 8 +- src/xen/xen_inotify.h | 1 + 25 files changed, 1772 insertions(+), 68 deletions(-)
diff --git a/daemon/remote.c b/daemon/remote.c index 4296fc3..1f239cd 100644
ACK though there are some cleanups as part of the patch, and Matthias has some good points. Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

On Wed, Oct 21, 2009 at 07:15:22PM +0100, Daniel P. Berrange wrote:
This is a second posting of the proposal from earlier today
http://www.redhat.com/archives/libvir-list/2009-October/msg00556.html
The changes since last time
- Renamed some existing internal APIs which had bad names which clashed with our new public APis. - Fix the comment bugs Daniel mentioned - Change the return status from '> 0' to '1', so we can explicitly add other positive integer return codes if ever required
yup, good point !
- Implement the new APIs for (nearly) all drivers
Okay will review individual patches, Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/
participants (3)
-
Daniel P. Berrange
-
Daniel Veillard
-
Matthias Bolte