[libvirt] [PATCH/GSoC] Use virGetLastErrorMessage() rather than open code it
by Hui Yiqun
getting err using virGetLastError() and then retrieving
message from err make developer have to test the value
of err and err->message and default to self-defined
unkown error message.
It's better to avoid it and using uniform
virGetLastErrorMessage
---
daemon/libvirtd.c | 8 +---
examples/object-events/event-test.c | 9 ++---
src/bhyve/bhyve_driver.c | 3 +-
src/libvirt.c | 3 +-
src/libxl/libxl_domain.c | 3 +-
src/libxl/libxl_driver.c | 3 +-
src/locking/lock_daemon.c | 8 +---
src/logging/log_daemon.c | 8 +---
src/lxc/lxc_container.c | 8 +---
src/lxc/lxc_controller.c | 7 +---
src/lxc/lxc_domain.c | 3 +-
src/lxc/lxc_process.c | 6 +--
src/network/bridge_driver.c | 3 +-
src/node_device/node_device_hal.c | 3 +-
src/rpc/virnettlscontext.c | 3 +-
src/secret/secret_driver.c | 6 +--
src/storage/storage_driver.c | 16 ++------
src/uml/uml_driver.c | 3 +-
src/util/iohelper.c | 8 +---
src/util/virhook.c | 3 +-
src/util/virhostdev.c | 20 ++++-----
src/util/virpci.c | 4 +-
tests/commandtest.c | 81 +++++++++++++------------------------
tests/libvirtdconftest.c | 3 +-
tests/openvzutilstest.c | 6 +--
tests/securityselinuxlabeltest.c | 6 +--
tests/securityselinuxtest.c | 6 +--
tests/virnettlscontexttest.c | 3 +-
28 files changed, 75 insertions(+), 168 deletions(-)
diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index 3d38a46..e526e55 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -1273,12 +1273,8 @@ int main(int argc, char **argv) {
/* Read the config file if it exists*/
if (remote_config_file &&
daemonConfigLoadFile(config, remote_config_file, implicit_conf) < 0) {
- virErrorPtr err = virGetLastError();
- if (err && err->message)
- VIR_ERROR(_("Can't load config file: %s: %s"),
- err->message, remote_config_file);
- else
- VIR_ERROR(_("Can't load config file: %s"), remote_config_file);
+ VIR_ERROR(_("Can't load config file: %s: %s"),
+ virGetLastErrorMessage(), remote_config_file);
exit(EXIT_FAILURE);
}
diff --git a/examples/object-events/event-test.c b/examples/object-events/event-test.c
index 7be1d21..4a4ef86 100644
--- a/examples/object-events/event-test.c
+++ b/examples/object-events/event-test.c
@@ -654,9 +654,8 @@ int main(int argc, char **argv)
}
if (virEventRegisterDefaultImpl() < 0) {
- virErrorPtr err = virGetLastError();
fprintf(stderr, "Failed to register event implementation: %s\n",
- err && err->message ? err->message: "Unknown error");
+ virGetLastErrorMessage());
goto cleanup;
}
@@ -794,17 +793,15 @@ int main(int argc, char **argv)
goto cleanup;
if (virConnectSetKeepAlive(dconn, 5, 3) < 0) {
- virErrorPtr err = virGetLastError();
fprintf(stderr, "Failed to start keepalive protocol: %s\n",
- err && err->message ? err->message : "Unknown error");
+ virGetLastErrorMessage());
run = 0;
}
while (run) {
if (virEventRunDefaultImpl() < 0) {
- virErrorPtr err = virGetLastError();
fprintf(stderr, "Failed to run event loop: %s\n",
- err && err->message ? err->message : "Unknown error");
+ virGetLastErrorMessage());
}
}
diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index 9219890..6f2423c 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -88,9 +88,8 @@ bhyveAutostartDomain(virDomainObjPtr vm, void *opaque)
ret = virBhyveProcessStart(data->conn, data->driver, vm,
VIR_DOMAIN_RUNNING_BOOTED, 0);
if (ret < 0) {
- virErrorPtr err = virGetLastError();
VIR_ERROR(_("Failed to autostart VM '%s': %s"),
- vm->def->name, err ? err->message : _("unknown error"));
+ vm->def->name, virGetLastErrorMessage());
}
}
virObjectUnlock(vm);
diff --git a/src/libvirt.c b/src/libvirt.c
index dd58e9c..99b1c47 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -777,10 +777,9 @@ virStateInitialize(bool privileged,
if (virStateDriverTab[i]->stateInitialize(privileged,
callback,
opaque) < 0) {
- virErrorPtr err = virGetLastError();
VIR_ERROR(_("Initialization of %s state driver failed: %s"),
virStateDriverTab[i]->name,
- err && err->message ? err->message : _("Unknown problem"));
+ virGetLastErrorMessage());
return -1;
}
}
diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index c8d09b1..a814ae5 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -514,9 +514,8 @@ libxlDomainShutdownThread(void *opaque)
libxlDomainDestroyInternal(driver, vm);
libxlDomainCleanup(driver, vm);
if (libxlDomainStart(driver, vm, false, -1) < 0) {
- virErrorPtr err = virGetLastError();
VIR_ERROR(_("Failed to restart VM '%s': %s"),
- vm->def->name, err ? err->message : _("unknown error"));
+ vm->def->name, virGetLastErrorMessage());
}
endjob:
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 87ec5a5..767ebbc 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -324,10 +324,9 @@ libxlAutostartDomain(virDomainObjPtr vm,
if (vm->autostart && !virDomainObjIsActive(vm) &&
libxlDomainStart(driver, vm, false, -1) < 0) {
- err = virGetLastError();
VIR_ERROR(_("Failed to autostart VM '%s': %s"),
vm->def->name,
- err ? err->message : _("unknown error"));
+ virGetLastErrorMessage());
goto endjob;
}
diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c
index 973e691..b755a02 100644
--- a/src/locking/lock_daemon.c
+++ b/src/locking/lock_daemon.c
@@ -1266,12 +1266,8 @@ int main(int argc, char **argv) {
/* Read the config file if it exists*/
if (remote_config_file &&
virLockDaemonConfigLoadFile(config, remote_config_file, implicit_conf) < 0) {
- virErrorPtr err = virGetLastError();
- if (err && err->message)
- VIR_ERROR(_("Can't load config file: %s: %s"),
- err->message, remote_config_file);
- else
- VIR_ERROR(_("Can't load config file: %s"), remote_config_file);
+ VIR_ERROR(_("Can't load config file: %s: %s"),
+ virGetLastErrorMessage(), remote_config_file);
exit(EXIT_FAILURE);
}
diff --git a/src/logging/log_daemon.c b/src/logging/log_daemon.c
index 68f0647..83f0475 100644
--- a/src/logging/log_daemon.c
+++ b/src/logging/log_daemon.c
@@ -1023,12 +1023,8 @@ int main(int argc, char **argv) {
/* Read the config file if it exists*/
if (remote_config_file &&
virLogDaemonConfigLoadFile(config, remote_config_file, implicit_conf) < 0) {
- virErrorPtr err = virGetLastError();
- if (err && err->message)
- VIR_ERROR(_("Can't load config file: %s: %s"),
- err->message, remote_config_file);
- else
- VIR_ERROR(_("Can't load config file: %s"), remote_config_file);
+ VIR_ERROR(_("Can't load config file: %s: %s"),
+ virGetLastErrorMessage(), remote_config_file);
exit(EXIT_FAILURE);
}
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 348bbfb..4daba3a 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -2290,12 +2290,8 @@ static int lxcContainerChild(void *data)
if (ret != 0) {
VIR_DEBUG("Tearing down container");
- virErrorPtr err = virGetLastError();
- if (err && err->message)
- fprintf(stderr, "%s\n", err->message);
- else
- fprintf(stderr, "%s\n",
- _("Unknown failure in libvirt_lxc startup"));
+ fprintf(stderr, "Failure in libvirt_lxc startup%s\n",
+ virGetLastErrorMessage());
}
virCommandFree(cmd);
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 8b5ec4c..b20a46f 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -2731,12 +2731,7 @@ int main(int argc, char *argv[])
cleanup:
if (rc < 0) {
- virErrorPtr err = virGetLastError();
- if (err && err->message)
- fprintf(stderr, "%s\n", err->message);
- else
- fprintf(stderr, "%s\n",
- _("Unknown failure in libvirt_lxc startup"));
+ fprintf(stderr, "Failure in libvirt_lxc startup: %s\n", virGetLastErrorMessage());
}
virPidFileDelete(LXC_STATE_DIR, name);
diff --git a/src/lxc/lxc_domain.c b/src/lxc/lxc_domain.c
index 3177a62..5267797 100644
--- a/src/lxc/lxc_domain.c
+++ b/src/lxc/lxc_domain.c
@@ -221,8 +221,7 @@ virLXCDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt,
unsigned long long thepid;
if (virXPathULongLong("string(./init[1]/@pid)", ctxt, &thepid) < 0) {
- virErrorPtr err = virGetLastError();
- VIR_WARN("Failed to load init pid from state %s", err ? err->message : "null");
+ VIR_WARN("Failed to load init pid from state %s", virGetLastErrorMessage());
priv->initpid = 0;
} else {
priv->initpid = thepid;
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index 5e0bbe2..6f6df84 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -757,10 +757,9 @@ static void virLXCProcessMonitorInitNotify(virLXCMonitorPtr mon ATTRIBUTE_UNUSED
priv->initpid = initpid;
if (virLXCProcessGetNsInode(initpid, "pid", &inode) < 0) {
- virErrorPtr err = virGetLastError();
VIR_WARN("Cannot obtain pid NS inode for %llu: %s",
(unsigned long long)initpid,
- err && err->message ? err->message : "<unknown>");
+ virGetLastErrorMessage());
virResetLastError();
}
virDomainAuditInit(vm, initpid, inode);
@@ -1619,10 +1618,9 @@ virLXCProcessAutostartDomain(virDomainObjPtr vm,
VIR_DOMAIN_RUNNING_BOOTED);
virDomainAuditStart(vm, "booted", ret >= 0);
if (ret < 0) {
- virErrorPtr err = virGetLastError();
VIR_ERROR(_("Failed to autostart VM '%s': %s"),
vm->def->name,
- err ? err->message : "");
+ virGetLastErrorMessage());
} else {
virObjectEventPtr event =
virDomainEventLifecycleNewFromObj(vm,
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index a09a7e4..f82ad24 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -694,9 +694,8 @@ networkStateInitialize(bool privileged,
#ifdef HAVE_FIREWALLD
if (!(sysbus = virDBusGetSystemBus())) {
- virErrorPtr err = virGetLastError();
VIR_WARN("DBus not available, disabling firewalld support "
- "in bridge_network_driver: %s", err->message);
+ "in bridge_network_driver: %s", virGetLastErrorMessage());
} else {
/* add matches for
* NameOwnerChanged on org.freedesktop.DBus for firewalld start/stop
diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_device_hal.c
index 6d18a87..6ddfad0 100644
--- a/src/node_device/node_device_hal.c
+++ b/src/node_device/node_device_hal.c
@@ -641,9 +641,8 @@ nodeStateInitialize(bool privileged ATTRIBUTE_UNUSED,
dbus_error_init(&err);
if (!(sysbus = virDBusGetSystemBus())) {
- virErrorPtr verr = virGetLastError();
VIR_ERROR(_("DBus not available, disabling HAL driver: %s"),
- verr->message);
+ virGetLastErrorMessage());
ret = 0;
goto failure;
}
diff --git a/src/rpc/virnettlscontext.c b/src/rpc/virnettlscontext.c
index 947038d..6e78623 100644
--- a/src/rpc/virnettlscontext.c
+++ b/src/rpc/virnettlscontext.c
@@ -1141,8 +1141,7 @@ int virNetTLSContextCheckCertificate(virNetTLSContextPtr ctxt,
virObjectLock(ctxt);
virObjectLock(sess);
if (virNetTLSContextValidCertificate(ctxt, sess) < 0) {
- virErrorPtr err = virGetLastError();
- VIR_WARN("Certificate check failed %s", err && err->message ? err->message : "<unknown>");
+ VIR_WARN("Certificate check failed %s", virGetLastErrorMessage());
if (ctxt->requireValidCert) {
virReportError(VIR_ERR_AUTH_FAILED, "%s",
_("Failed to verify peer's certificate"));
diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c
index 4d15797..b9c82c6 100644
--- a/src/secret/secret_driver.c
+++ b/src/secret/secret_driver.c
@@ -484,11 +484,9 @@ secretLoadAllConfigs(virSecretObjPtr *dest,
VIR_FREE(base64name);
if (!(secret = secretLoad(&list, de->d_name, path, base64path))) {
- virErrorPtr err = virGetLastError();
-
VIR_ERROR(_("Error reading secret: %s"),
- err != NULL ? err->message: _("unknown error"));
- virResetError(err);
+ virGetLastErrorMessage());
+ virResetLastError();
VIR_FREE(path);
VIR_FREE(base64path);
continue;
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 1d96618..ccf1fc1 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -97,10 +97,8 @@ storagePoolUpdateState(virStoragePoolObjPtr pool)
active = false;
if (backend->checkPool &&
backend->checkPool(pool, &active) < 0) {
- virErrorPtr err = virGetLastError();
VIR_ERROR(_("Failed to initialize storage pool '%s': %s"),
- pool->def->name, err ? err->message :
- _("no error message found"));
+ pool->def->name, virGetLastErrorMessage());
goto error;
}
@@ -111,12 +109,10 @@ storagePoolUpdateState(virStoragePoolObjPtr pool)
if (active) {
virStoragePoolObjClearVols(pool);
if (backend->refreshPool(NULL, pool) < 0) {
- virErrorPtr err = virGetLastError();
if (backend->stopPool)
backend->stopPool(NULL, pool);
VIR_ERROR(_("Failed to restart storage pool '%s': %s"),
- pool->def->name, err ? err->message :
- _("no error message found"));
+ pool->def->name, virGetLastErrorMessage());
goto error;
}
}
@@ -175,10 +171,8 @@ storageDriverAutostart(void)
!virStoragePoolObjIsActive(pool)) {
if (backend->startPool &&
backend->startPool(conn, pool) < 0) {
- virErrorPtr err = virGetLastError();
VIR_ERROR(_("Failed to autostart storage pool '%s': %s"),
- pool->def->name, err ? err->message :
- _("no error message found"));
+ pool->def->name, virGetLastErrorMessage());
virStoragePoolObjUnlock(pool);
continue;
}
@@ -194,14 +188,12 @@ storageDriverAutostart(void)
if (!stateFile ||
virStoragePoolSaveState(stateFile, pool->def) < 0 ||
backend->refreshPool(conn, pool) < 0) {
- virErrorPtr err = virGetLastError();
if (stateFile)
unlink(stateFile);
if (backend->stopPool)
backend->stopPool(conn, pool);
VIR_ERROR(_("Failed to autostart storage pool '%s': %s"),
- pool->def->name, err ? err->message :
- _("no error message found"));
+ pool->def->name, virGetLastErrorMessage());
} else {
pool->active = true;
}
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
index 84e1df8..923c3f6 100644
--- a/src/uml/uml_driver.c
+++ b/src/uml/uml_driver.c
@@ -188,9 +188,8 @@ umlAutostartDomain(virDomainObjPtr vm,
ret = umlStartVMDaemon(data->conn, data->driver, vm, false);
virDomainAuditStart(vm, "booted", ret >= 0);
if (ret < 0) {
- virErrorPtr err = virGetLastError();
VIR_ERROR(_("Failed to autostart VM '%s': %s"),
- vm->def->name, err ? err->message : _("unknown error"));
+ vm->def->name, virGetLastErrorMessage());
} else {
virObjectEventPtr event =
virDomainEventLifecycleNewFromObj(vm,
diff --git a/src/util/iohelper.c b/src/util/iohelper.c
index 8a3c377..9fe0f81 100644
--- a/src/util/iohelper.c
+++ b/src/util/iohelper.c
@@ -310,12 +310,6 @@ main(int argc, char **argv)
return 0;
error:
- err = virGetLastError();
- if (err) {
- fprintf(stderr, "%s: %s\n", program_name, err->message);
- } else {
- fprintf(stderr, _("%s: unknown failure with %s\n"),
- program_name, path);
- }
+ fprintf(stderr, "%s: %s\n", program_name, virGetLastErrorMessage());
exit(EXIT_FAILURE);
}
diff --git a/src/util/virhook.c b/src/util/virhook.c
index ba50598..d37d6da 100644
--- a/src/util/virhook.c
+++ b/src/util/virhook.c
@@ -297,9 +297,8 @@ virHookCall(int driver,
ret = virCommandRun(cmd, NULL);
if (ret < 0) {
/* Convert INTERNAL_ERROR into known error. */
- virErrorPtr err = virGetLastError();
virReportError(VIR_ERR_HOOK_SCRIPT_FAILED, "%s",
- err ? err->message : _("unknown error"));
+ virGetLastErrorMessage());
}
virCommandFree(cmd);
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index b397b79..42c146a 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -801,10 +801,9 @@ virHostdevReattachPCIDevice(virHostdevManagerPtr mgr,
VIR_DEBUG("Reattaching PCI device %s", virPCIDeviceGetName(actual));
if (virPCIDeviceReattach(actual, mgr->activePCIHostdevs,
mgr->inactivePCIHostdevs) < 0) {
- virErrorPtr err = virGetLastError();
VIR_ERROR(_("Failed to re-attach PCI device: %s"),
- err ? err->message : _("unknown error"));
- virResetError(err);
+ virGetLastErrorMessage());
+ virResetLastError();
}
}
@@ -829,10 +828,9 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr mgr,
virObjectLock(mgr->inactivePCIHostdevs);
if (!(pcidevs = virHostdevGetPCIHostDeviceList(hostdevs, nhostdevs))) {
- virErrorPtr err = virGetLastError();
VIR_ERROR(_("Failed to allocate PCI device list: %s"),
- err ? err->message : _("unknown error"));
- virResetError(err);
+ virGetLastErrorMessage());
+ virResetLastError();
goto cleanup;
}
@@ -883,10 +881,9 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr mgr,
if (!actual ||
virPCIDeviceListAdd(mgr->inactivePCIHostdevs, actual) < 0) {
- virErrorPtr err = virGetLastError();
VIR_ERROR(_("Failed to add PCI device %s to the inactive list"),
- err ? err->message : _("unknown error"));
- virResetError(err);
+ virGetLastErrorMessage());
+ virResetLastError();
}
}
@@ -928,10 +925,9 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr mgr,
VIR_DEBUG("Resetting PCI device %s", virPCIDeviceGetName(pci));
if (virPCIDeviceReset(pci, mgr->activePCIHostdevs,
mgr->inactivePCIHostdevs) < 0) {
- virErrorPtr err = virGetLastError();
VIR_ERROR(_("Failed to reset PCI device: %s"),
- err ? err->message : _("unknown error"));
- virResetError(err);
+ virGetLastErrorMessage());
+ virResetLastError();
}
}
diff --git a/src/util/virpci.c b/src/util/virpci.c
index f7921f8..2349d7f 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -989,12 +989,10 @@ virPCIDeviceReset(virPCIDevicePtr dev,
ret = virPCIDeviceTrySecondaryBusReset(dev, fd, inactiveDevs);
if (ret < 0) {
- virErrorPtr err = virGetLastError();
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unable to reset PCI device %s: %s"),
dev->name,
- err ? err->message :
- _("no FLR, PM reset or bus reset available"));
+ virGetLastErrorMessage());
}
cleanup:
diff --git a/tests/commandtest.c b/tests/commandtest.c
index cf5f44a..6430e20 100644
--- a/tests/commandtest.c
+++ b/tests/commandtest.c
@@ -178,8 +178,7 @@ static int test2(const void *unused ATTRIBUTE_UNUSED)
int ret;
if (virCommandRun(cmd, NULL) < 0) {
- virErrorPtr err = virGetLastError();
- printf("Cannot run child %s\n", err->message);
+ printf("Cannot run child %s\n", virGetLastErrorMessage());
virCommandFree(cmd);
return -1;
}
@@ -190,8 +189,7 @@ static int test2(const void *unused ATTRIBUTE_UNUSED)
}
if (virCommandRun(cmd, NULL) < 0) {
- virErrorPtr err = virGetLastError();
- printf("Cannot run child %s\n", err->message);
+ printf("Cannot run child %s\n", virGetLastErrorMessage());
virCommandFree(cmd);
return -1;
}
@@ -218,8 +216,7 @@ static int test3(const void *unused ATTRIBUTE_UNUSED)
VIR_COMMAND_PASS_FD_CLOSE_PARENT);
if (virCommandRun(cmd, NULL) < 0) {
- virErrorPtr err = virGetLastError();
- printf("Cannot run child %s\n", err->message);
+ printf("Cannot run child %s\n", virGetLastErrorMessage());
goto cleanup;
}
@@ -260,8 +257,7 @@ static int test4(const void *unused ATTRIBUTE_UNUSED)
virCommandDaemonize(cmd);
if (virCommandRun(cmd, NULL) < 0) {
- virErrorPtr err = virGetLastError();
- printf("Cannot run child %s\n", err->message);
+ printf("Cannot run child %s\n", virGetLastErrorMessage());
goto cleanup;
}
@@ -294,8 +290,7 @@ static int test5(const void *unused ATTRIBUTE_UNUSED)
virCommandAddEnvPassCommon(cmd);
if (virCommandRun(cmd, NULL) < 0) {
- virErrorPtr err = virGetLastError();
- printf("Cannot run child %s\n", err->message);
+ printf("Cannot run child %s\n", virGetLastErrorMessage());
virCommandFree(cmd);
return -1;
}
@@ -318,8 +313,7 @@ static int test6(const void *unused ATTRIBUTE_UNUSED)
virCommandAddEnvPassBlockSUID(cmd, "DOESNOTEXIST", NULL);
if (virCommandRun(cmd, NULL) < 0) {
- virErrorPtr err = virGetLastError();
- printf("Cannot run child %s\n", err->message);
+ printf("Cannot run child %s\n", virGetLastErrorMessage());
virCommandFree(cmd);
return -1;
}
@@ -343,8 +337,7 @@ static int test7(const void *unused ATTRIBUTE_UNUSED)
virCommandAddEnvPassBlockSUID(cmd, "DOESNOTEXIST", NULL);
if (virCommandRun(cmd, NULL) < 0) {
- virErrorPtr err = virGetLastError();
- printf("Cannot run child %s\n", err->message);
+ printf("Cannot run child %s\n", virGetLastErrorMessage());
virCommandFree(cmd);
return -1;
}
@@ -368,8 +361,7 @@ static int test8(const void *unused ATTRIBUTE_UNUSED)
virCommandAddEnvPair(cmd, "USER", "test");
if (virCommandRun(cmd, NULL) < 0) {
- virErrorPtr err = virGetLastError();
- printf("Cannot run child %s\n", err->message);
+ printf("Cannot run child %s\n", virGetLastErrorMessage());
virCommandFree(cmd);
return -1;
}
@@ -406,8 +398,7 @@ static int test9(const void *unused ATTRIBUTE_UNUSED)
}
if (virCommandRun(cmd, NULL) < 0) {
- virErrorPtr err = virGetLastError();
- printf("Cannot run child %s\n", err->message);
+ printf("Cannot run child %s\n", virGetLastErrorMessage());
virCommandFree(cmd);
return -1;
}
@@ -432,8 +423,7 @@ static int test10(const void *unused ATTRIBUTE_UNUSED)
virCommandAddArgSet(cmd, args);
if (virCommandRun(cmd, NULL) < 0) {
- virErrorPtr err = virGetLastError();
- printf("Cannot run child %s\n", err->message);
+ printf("Cannot run child %s\n", virGetLastErrorMessage());
virCommandFree(cmd);
return -1;
}
@@ -456,8 +446,7 @@ static int test11(const void *unused ATTRIBUTE_UNUSED)
virCommandPtr cmd = virCommandNewArgs(args);
if (virCommandRun(cmd, NULL) < 0) {
- virErrorPtr err = virGetLastError();
- printf("Cannot run child %s\n", err->message);
+ printf("Cannot run child %s\n", virGetLastErrorMessage());
virCommandFree(cmd);
return -1;
}
@@ -478,8 +467,7 @@ static int test12(const void *unused ATTRIBUTE_UNUSED)
virCommandSetInputBuffer(cmd, "Hello World\n");
if (virCommandRun(cmd, NULL) < 0) {
- virErrorPtr err = virGetLastError();
- printf("Cannot run child %s\n", err->message);
+ printf("Cannot run child %s\n", virGetLastErrorMessage());
virCommandFree(cmd);
return -1;
}
@@ -506,8 +494,7 @@ static int test13(const void *unused ATTRIBUTE_UNUSED)
virCommandSetOutputBuffer(cmd, &outactual);
if (virCommandRun(cmd, NULL) < 0) {
- virErrorPtr err = virGetLastError();
- printf("Cannot run child %s\n", err->message);
+ printf("Cannot run child %s\n", virGetLastErrorMessage());
goto cleanup;
}
if (!outactual)
@@ -559,8 +546,7 @@ static int test14(const void *unused ATTRIBUTE_UNUSED)
virCommandSetErrorBuffer(cmd, &erractual);
if (virCommandRun(cmd, NULL) < 0) {
- virErrorPtr err = virGetLastError();
- printf("Cannot run child %s\n", err->message);
+ printf("Cannot run child %s\n", virGetLastErrorMessage());
goto cleanup;
}
if (!outactual || !erractual)
@@ -573,8 +559,7 @@ static int test14(const void *unused ATTRIBUTE_UNUSED)
virCommandSetOutputBuffer(cmd, &jointactual);
virCommandSetErrorBuffer(cmd, &jointactual);
if (virCommandRun(cmd, NULL) < 0) {
- virErrorPtr err = virGetLastError();
- printf("Cannot run child %s\n", err->message);
+ printf("Cannot run child %s\n", virGetLastErrorMessage());
goto cleanup;
}
if (!jointactual)
@@ -620,8 +605,7 @@ static int test15(const void *unused ATTRIBUTE_UNUSED)
virCommandSetUmask(cmd, 002);
if (virCommandRun(cmd, NULL) < 0) {
- virErrorPtr err = virGetLastError();
- printf("Cannot run child %s\n", err->message);
+ printf("Cannot run child %s\n", virGetLastErrorMessage());
goto cleanup;
}
@@ -651,8 +635,7 @@ static int test16(const void *unused ATTRIBUTE_UNUSED)
virCommandAddArg(cmd, "G H");
if ((outactual = virCommandToString(cmd)) == NULL) {
- virErrorPtr err = virGetLastError();
- printf("Cannot convert to string: %s\n", err->message);
+ printf("Cannot convert to string: %s\n", virGetLastErrorMessage());
goto cleanup;
}
if ((fd = open(abs_builddir "/commandhelper.log",
@@ -697,8 +680,7 @@ static int test17(const void *unused ATTRIBUTE_UNUSED)
}
if (virCommandRun(cmd, NULL) < 0) {
- virErrorPtr err = virGetLastError();
- printf("Cannot run child %s\n", err->message);
+ printf("Cannot run child %s\n", virGetLastErrorMessage());
goto cleanup;
}
@@ -720,8 +702,7 @@ static int test17(const void *unused ATTRIBUTE_UNUSED)
}
if (virCommandRun(cmd, NULL) < 0) {
- virErrorPtr err = virGetLastError();
- printf("Cannot run child %s\n", err->message);
+ printf("Cannot run child %s\n", virGetLastErrorMessage());
goto cleanup;
}
@@ -756,8 +737,7 @@ static int test18(const void *unused ATTRIBUTE_UNUSED)
alarm(5);
if (virCommandRun(cmd, NULL) < 0) {
- virErrorPtr err = virGetLastError();
- printf("Cannot run child %s\n", err->message);
+ printf("Cannot run child %s\n", virGetLastErrorMessage());
goto cleanup;
}
alarm(0);
@@ -798,8 +778,7 @@ static int test19(const void *unused ATTRIBUTE_UNUSED)
alarm(5);
if (virCommandRunAsync(cmd, &pid) < 0) {
- virErrorPtr err = virGetLastError();
- printf("Cannot run child %s\n", err->message);
+ printf("Cannot run child %s\n", virGetLastErrorMessage());
goto cleanup;
}
@@ -848,8 +827,7 @@ static int test20(const void *unused ATTRIBUTE_UNUSED)
virCommandSetInputBuffer(cmd, buf);
if (virCommandRun(cmd, NULL) < 0) {
- virErrorPtr err = virGetLastError();
- printf("Cannot run child %s\n", err->message);
+ printf("Cannot run child %s\n", virGetLastErrorMessage());
goto cleanup;
}
@@ -891,8 +869,7 @@ static int test21(const void *unused ATTRIBUTE_UNUSED)
virCommandDoAsyncIO(cmd);
if (virCommandRunAsync(cmd, NULL) < 0) {
- virErrorPtr err = virGetLastError();
- printf("Cannot run child %s\n", err->message);
+ printf("Cannot run child %s\n", virGetLastErrorMessage());
goto cleanup;
}
@@ -930,8 +907,7 @@ test22(const void *unused ATTRIBUTE_UNUSED)
cmd = virCommandNewArgList("/bin/sh", "-c", "exit 3", NULL);
if (virCommandRun(cmd, &status) < 0) {
- virErrorPtr err = virGetLastError();
- printf("Cannot run child %s\n", err->message);
+ printf("Cannot run child %s\n", virGetLastErrorMessage());
goto cleanup;
}
if (status != 3) {
@@ -941,8 +917,7 @@ test22(const void *unused ATTRIBUTE_UNUSED)
virCommandRawStatus(cmd);
if (virCommandRun(cmd, &status) < 0) {
- virErrorPtr err = virGetLastError();
- printf("Cannot run child %s\n", err->message);
+ printf("Cannot run child %s\n", virGetLastErrorMessage());
goto cleanup;
}
if (!WIFEXITED(status) || WEXITSTATUS(status) != 3) {
@@ -960,8 +935,7 @@ test22(const void *unused ATTRIBUTE_UNUSED)
virCommandRawStatus(cmd);
if (virCommandRun(cmd, &status) < 0) {
- virErrorPtr err = virGetLastError();
- printf("Cannot run child %s\n", err->message);
+ printf("Cannot run child %s\n", virGetLastErrorMessage());
goto cleanup;
}
if (!WIFSIGNALED(status) || WTERMSIG(status) != SIGKILL) {
@@ -1057,8 +1031,7 @@ static int test24(const void *unused ATTRIBUTE_UNUSED)
virCommandPassListenFDs(cmd);
if (virCommandRun(cmd, NULL) < 0) {
- virErrorPtr err = virGetLastError();
- printf("Cannot run child %s\n", err->message);
+ printf("Cannot run child %s\n", virGetLastErrorMessage());
goto cleanup;
}
diff --git a/tests/libvirtdconftest.c b/tests/libvirtdconftest.c
index 61d861d..06830bb 100644
--- a/tests/libvirtdconftest.c
+++ b/tests/libvirtdconftest.c
@@ -212,8 +212,7 @@ mymain(void)
}
if (virFileReadAll(filename, 1024*1024, &filedata) < 0) {
- virErrorPtr err = virGetLastError();
- fprintf(stderr, "Cannot load %s for testing: %s", filename, err->message);
+ fprintf(stderr, "Cannot load %s for testing: %s", filename, virGetLastErrorMessage());
ret = -1;
goto cleanup;
}
diff --git a/tests/openvzutilstest.c b/tests/openvzutilstest.c
index ccde636..57a8601 100644
--- a/tests/openvzutilstest.c
+++ b/tests/openvzutilstest.c
@@ -110,16 +110,14 @@ testReadNetworkConf(const void *data ATTRIBUTE_UNUSED)
def->os.type = VIR_DOMAIN_OSTYPE_EXE;
if (openvzReadNetworkConf(def, 1) < 0) {
- err = virGetLastError();
- fprintf(stderr, "ERROR: %s\n", err != NULL ? err->message : "<unknown>");
+ fprintf(stderr, "ERROR: %s\n", virGetLastErrorMessage());
goto cleanup;
}
actual = virDomainDefFormat(def, NULL, VIR_DOMAIN_DEF_FORMAT_INACTIVE);
if (actual == NULL) {
- err = virGetLastError();
- fprintf(stderr, "ERROR: %s\n", err != NULL ? err->message : "<unknown>");
+ fprintf(stderr, "ERROR: %s\n", virGetLastErrorMessage());
goto cleanup;
}
diff --git a/tests/securityselinuxlabeltest.c b/tests/securityselinuxlabeltest.c
index c82b3f2..f6caa30 100644
--- a/tests/securityselinuxlabeltest.c
+++ b/tests/securityselinuxlabeltest.c
@@ -332,8 +332,7 @@ testSELinuxLabeling(const void *opaque)
}
VIR_FREE(files);
if (ret < 0) {
- virErrorPtr err = virGetLastError();
- VIR_TEST_VERBOSE("%s\n", err ? err->message : "<unknown>");
+ VIR_TEST_VERBOSE("%s\n", virGetLastErrorMessage());
}
return ret;
}
@@ -354,9 +353,8 @@ mymain(void)
if (!(mgr = virSecurityManagerNew("selinux", "QEMU",
VIR_SECURITY_MANAGER_DEFAULT_CONFINED |
VIR_SECURITY_MANAGER_PRIVILEGED))) {
- virErrorPtr err = virGetLastError();
VIR_TEST_VERBOSE("Unable to initialize security driver: %s\n",
- err->message);
+ virGetLastErrorMessage());
return EXIT_FAILURE;
}
diff --git a/tests/securityselinuxtest.c b/tests/securityselinuxtest.c
index 49694f3..3423e66 100644
--- a/tests/securityselinuxtest.c
+++ b/tests/securityselinuxtest.c
@@ -230,8 +230,7 @@ testSELinuxGenLabel(const void *opaque)
goto cleanup;
if (virSecurityManagerGenLabel(data->mgr, def) < 0) {
- virErrorPtr err = virGetLastError();
- fprintf(stderr, "Cannot generate label: %s\n", err->message);
+ fprintf(stderr, "Cannot generate label: %s\n", virGetLastErrorMessage());
goto cleanup;
}
@@ -275,9 +274,8 @@ mymain(void)
if (!(mgr = virSecurityManagerNew("selinux", "QEMU",
VIR_SECURITY_MANAGER_DEFAULT_CONFINED |
VIR_SECURITY_MANAGER_PRIVILEGED))) {
- virErrorPtr err = virGetLastError();
fprintf(stderr, "Unable to initialize security driver: %s\n",
- err->message);
+ virGetLastErrorMessage());
return EXIT_FAILURE;
}
diff --git a/tests/virnettlscontexttest.c b/tests/virnettlscontexttest.c
index a3e24a3..d33b896 100644
--- a/tests/virnettlscontexttest.c
+++ b/tests/virnettlscontexttest.c
@@ -90,13 +90,12 @@ static int testTLSContextInit(const void *opaque)
goto cleanup;
}
} else {
- virErrorPtr err = virGetLastError();
if (!data->expectFail) {
VIR_WARN("Unexpected failure %s against %s",
data->cacrt, data->crt);
goto cleanup;
}
- VIR_DEBUG("Got error %s", err ? err->message : "<unknown>");
+ VIR_DEBUG("Got error %s", virGetLastErrorMessage());
}
ret = 0;
--
2.7.4
8 years, 12 months
[libvirt] [PATCH] build: work around gcc 6.0 warnings
by Eric Blake
gcc 6.0 added an annoying warning:
fdstream.c: In function 'virFDStreamWrite':
fdstream.c:390:29: error: logical 'or' of equal expressions [-Werror=logical-op]
if (errno == EAGAIN || errno == EWOULDBLOCK) {
^~
fdstream.c: In function 'virFDStreamRead':
fdstream.c:440:29: error: logical 'or' of equal expressions [-Werror=logical-op]
if (errno == EAGAIN || errno == EWOULDBLOCK) {
^~
This makes it impossible to build out-of-the-box on rawhide,
and we aren't guaranteed that the gcc bug will be fixed in a
timely manner:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69602
So work around it by further complicating the logic to thwart the
compiler.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
This is a build-breaker fix for rawhide; but I'll wait for a day
for any reasons why I should not push it during freeze.
src/fdstream.c | 8 +++++---
src/rpc/virnetsshsession.c | 10 +++++++---
src/security/security_selinux.c | 5 +++--
3 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/src/fdstream.c b/src/fdstream.c
index a85cf9d..1c34321 100644
--- a/src/fdstream.c
+++ b/src/fdstream.c
@@ -1,7 +1,7 @@
/*
* fdstream.c: generic streams impl for file descriptors
*
- * Copyright (C) 2009-2012, 2014, 2016 Red Hat, Inc.
+ * Copyright (C) 2009-2012, 2014, 2016 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -387,7 +387,8 @@ static int virFDStreamWrite(virStreamPtr st, const char *bytes, size_t nbytes)
retry:
ret = write(fdst->fd, bytes, nbytes);
if (ret < 0) {
- if (errno == EAGAIN || errno == EWOULDBLOCK) {
+ if (errno == EAGAIN ||
+ (EAGAIN != EWOULDBLOCK && errno == EWOULDBLOCK)) {
ret = -2;
} else if (errno == EINTR) {
goto retry;
@@ -437,7 +438,8 @@ static int virFDStreamRead(virStreamPtr st, char *bytes, size_t nbytes)
retry:
ret = read(fdst->fd, bytes, nbytes);
if (ret < 0) {
- if (errno == EAGAIN || errno == EWOULDBLOCK) {
+ if (errno == EAGAIN ||
+ (EAGAIN != EWOULDBLOCK && errno == EWOULDBLOCK)) {
ret = -2;
} else if (errno == EINTR) {
goto retry;
diff --git a/src/rpc/virnetsshsession.c b/src/rpc/virnetsshsession.c
index 406a831..d7d1c1a 100644
--- a/src/rpc/virnetsshsession.c
+++ b/src/rpc/virnetsshsession.c
@@ -1,7 +1,7 @@
/*
* virnetsshsession.c: ssh network transport provider based on libssh2
*
- * Copyright (C) 2012-2013 Red Hat, Inc.
+ * Copyright (C) 2012-2013, 2016 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -546,7 +546,9 @@ virNetSSHAuthenticateAgent(virNetSSHSessionPtr sess,
return 0; /* key accepted */
if (ret != LIBSSH2_ERROR_AUTHENTICATION_FAILED &&
- ret != LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED &&
+ (LIBSSH2_ERROR_AUTHENTICATION_FAILED !=
+ LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED &&
+ ret != LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED) &&
ret != LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED) {
libssh2_session_last_error(sess->session, &errmsg, NULL, 0);
virReportError(VIR_ERR_AUTH_FAILED,
@@ -674,7 +676,9 @@ virNetSSHAuthenticatePrivkey(virNetSSHSessionPtr sess,
priv->filename, errmsg);
if (ret == LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED ||
- ret == LIBSSH2_ERROR_AUTHENTICATION_FAILED)
+ (LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED !=
+ LIBSSH2_ERROR_AUTHENTICATION_FAILED &&
+ ret == LIBSSH2_ERROR_AUTHENTICATION_FAILED))
return 1;
else
return -1;
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index 26d95d1..25f0bdf 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008-2014 Red Hat, Inc.
+ * Copyright (C) 2008-2014, 2016 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -911,7 +911,8 @@ virSecuritySELinuxSetFileconHelper(const char *path, char *tcon,
* hopefully sets one of the necessary SELinux virt_use_{nfs,usb,pci}
* boolean tunables to allow it ...
*/
- if (setfilecon_errno != EOPNOTSUPP && setfilecon_errno != ENOTSUP &&
+ if (setfilecon_errno != EOPNOTSUPP &&
+ (EOPNOTSUPP != ENOTSUP && setfilecon_errno != ENOTSUP) &&
setfilecon_errno != EROFS) {
virReportSystemError(setfilecon_errno,
_("unable to set security context '%s' on '%s'"),
--
2.5.0
9 years
[libvirt] [PATCH v2] add func to set shared drivers after libvirtd init
by Mikhail Feoktistov
Diff from v1:
Remove vz prefix from the title of this letter. Because this is the common case
for all drivers in libvirt.
Description:
Built-in drivers in libvirt are initialized before libvirtd initialization.
Libvirt loads shared drivers on libvirtd initialization step.
For built-in drivers we can't set shared drivers, because they are not initialized yet.
This patch adds function to set shared drivers after libvirtd init.
---
daemon/libvirtd.c | 4 ++++
src/libvirt.c | 41 +++++++++++++++++++++++++++++++++++++++++
src/libvirt_internal.h | 1 +
src/libvirt_private.syms | 1 +
4 files changed, 47 insertions(+)
diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index 250094b..aac1826 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -431,6 +431,10 @@ static void daemonInitialize(void)
bhyveRegister();
# endif
#endif
+# ifdef WITH_VZ
+ virAssignSharedDrivers("vz");
+ virAssignSharedDrivers("Parallels");
+# endif
}
diff --git a/src/libvirt.c b/src/libvirt.c
index 25a0040..1763be7 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -1433,3 +1433,44 @@ virTypedParameterValidateSet(virConnectPtr conn,
}
return 0;
}
+
+/**
+ * virAssignSharedDrivers:
+ * @name: name of connection driver
+ *
+ * This function fills in any empty pointers for shared drivers
+ * in connect driver structure
+ *
+ * Returns 0 in case of success, -1 in case of error
+*/
+int
+virAssignSharedDrivers(const char *name)
+{
+ size_t i;
+
+ if (name == NULL) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Driver name must be specified"));
+ return -1;
+ }
+
+ for (i = 0; i < virConnectDriverTabCount; i++) {
+ if (STREQ(virConnectDriverTab[i]->hypervisorDriver->name, name)) {
+ if (virConnectDriverTab[i]->interfaceDriver == NULL)
+ virConnectDriverTab[i]->interfaceDriver = virSharedInterfaceDriver;
+ if (virConnectDriverTab[i]->networkDriver == NULL)
+ virConnectDriverTab[i]->networkDriver = virSharedNetworkDriver;
+ if (virConnectDriverTab[i]->nodeDeviceDriver == NULL)
+ virConnectDriverTab[i]->nodeDeviceDriver = virSharedNodeDeviceDriver;
+ if (virConnectDriverTab[i]->nwfilterDriver == NULL)
+ virConnectDriverTab[i]->nwfilterDriver = virSharedNWFilterDriver;
+ if (virConnectDriverTab[i]->secretDriver == NULL)
+ virConnectDriverTab[i]->secretDriver = virSharedSecretDriver;
+ if (virConnectDriverTab[i]->storageDriver == NULL)
+ virConnectDriverTab[i]->storageDriver = virSharedStorageDriver;
+ break;
+ }
+ }
+
+ return 0;
+}
diff --git a/src/libvirt_internal.h b/src/libvirt_internal.h
index 1313b58..2a7227b 100644
--- a/src/libvirt_internal.h
+++ b/src/libvirt_internal.h
@@ -289,4 +289,5 @@ virTypedParameterValidateSet(virConnectPtr conn,
virTypedParameterPtr params,
int nparams);
+int virAssignSharedDrivers(const char *name);
#endif
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index a835f18..a0fcdf5 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -943,6 +943,7 @@ virFDStreamSetInternalCloseCb;
# libvirt_internal.h
+virAssignSharedDrivers;
virConnectSupportsFeature;
virDomainMigrateBegin3;
virDomainMigrateBegin3Params;
--
1.8.3.1
9 years
[libvirt] [PATCH v2] host-validate: Improve CPU flags processing
by Andrea Bolognani
Instead of relying on substring search, tokenize the input
and process each CPU flag separately. This ensures CPU flag
detection will continue to work correctly even if we start
looking for CPU flags whose name might appear as part of
other CPU flags' names.
The result of processing is stored in a virBitmap, which
means we don't have to parse /proc/cpuinfo in its entirety
for each single CPU flag we want to check.
Moreover, use of the newly-introduced virHostValidateCPUFlag
enumeration ensures we don't go looking for random CPU flags
which might actually be simple typos.
---
Changes in v2:
* use virStringSplitCount() and STRPREFIX() instead of
strtok_r() and strcmp(), as suggested by Peter
tools/virt-host-validate-common.c | 67 ++++++++++++++++++++++++++++++++-------
tools/virt-host-validate-common.h | 13 +++++++-
tools/virt-host-validate-qemu.c | 12 +++++--
3 files changed, 77 insertions(+), 15 deletions(-)
diff --git a/tools/virt-host-validate-common.c b/tools/virt-host-validate-common.c
index 8ebf73e..3305a32 100644
--- a/tools/virt-host-validate-common.c
+++ b/tools/virt-host-validate-common.c
@@ -31,7 +31,6 @@
#endif /* HAVE_MNTENT_H */
#include <sys/stat.h>
-#include "virutil.h"
#include "viralloc.h"
#include "virfile.h"
#include "virt-host-validate-common.h"
@@ -39,6 +38,10 @@
#define VIR_FROM_THIS VIR_FROM_NONE
+VIR_ENUM_IMPL(virHostValidateCPUFlag, VIR_HOST_VALIDATE_CPU_FLAG_LAST,
+ "vmx",
+ "svm");
+
static bool quiet;
void virHostMsgSetQuiet(bool quietFlag)
@@ -188,29 +191,64 @@ int virHostValidateNamespace(const char *hvname,
}
-bool virHostValidateHasCPUFlag(const char *name)
+virBitmapPtr virHostValidateGetCPUFlags(void)
{
- FILE *fp = fopen("/proc/cpuinfo", "r");
- bool ret = false;
+ FILE *fp;
+ virBitmapPtr flags;
- if (!fp)
- return false;
+ if (!(fp = fopen("/proc/cpuinfo", "r")))
+ return NULL;
+
+ if (!(flags = virBitmapNewQuiet(VIR_HOST_VALIDATE_CPU_FLAG_LAST)))
+ return NULL;
do {
char line[1024];
+ char *start;
+ char **tokens;
+ size_t ntokens;
+ size_t i;
if (!fgets(line, sizeof(line), fp))
break;
- if (strstr(line, name)) {
- ret = true;
- break;
+ /* The line we're interested in is marked either as "flags" or
+ * as "Features" depending on the architecture, so check both
+ * prefixes */
+ if (!STRPREFIX(line, "flags") && !STRPREFIX(line, "Features"))
+ continue;
+
+ /* fgets() includes the trailing newline in the output buffer,
+ * so we need to clean that up ourselves. We can safely access
+ * line[strlen(line) - 1] because the checks above would cause
+ * us to skip empty strings */
+ line[strlen(line) - 1] = '\0';
+
+ /* Skip to the separator */
+ if (!(start = strstr(line, ":")))
+ continue;
+
+ /* Split the line using " " as a delimiter. The first token
+ * will always be ":", but that's okay */
+ if (!(tokens = virStringSplitCount(start, " ", 0, &ntokens)))
+ continue;
+
+ /* Go through all flags and check whether one of those we
+ * might want to check for later on is present; if that's
+ * the case, set the relevant bit in the bitmap */
+ for (i = 0; i < ntokens; i++) {
+ int value;
+
+ if ((value = virHostValidateCPUFlagTypeFromString(tokens[i])) >= 0)
+ ignore_value(virBitmapSetBit(flags, value));
}
+
+ virStringFreeListCount(tokens, ntokens);
} while (1);
VIR_FORCE_FCLOSE(fp);
- return ret;
+ return flags;
}
@@ -359,15 +397,20 @@ int virHostValidateCGroupController(const char *hvname,
int virHostValidateIOMMU(const char *hvname,
virHostValidateLevel level)
{
+ virBitmapPtr flags;
struct stat sb;
const char *bootarg = NULL;
bool isAMD = false, isIntel = false;
- if (virHostValidateHasCPUFlag("vmx"))
+ flags = virHostValidateGetCPUFlags();
+
+ if (flags && virBitmapIsBitSet(flags, VIR_HOST_VALIDATE_CPU_FLAG_VMX))
isIntel = true;
- else if (virHostValidateHasCPUFlag("svm"))
+ else if (flags && virBitmapIsBitSet(flags, VIR_HOST_VALIDATE_CPU_FLAG_SVM))
isAMD = true;
+ virBitmapFree(flags);
+
virHostMsgCheck(hvname, "%s", _("for device assignment IOMMU support"));
if (isIntel) {
diff --git a/tools/virt-host-validate-common.h b/tools/virt-host-validate-common.h
index d4c4759..26e006b 100644
--- a/tools/virt-host-validate-common.h
+++ b/tools/virt-host-validate-common.h
@@ -23,6 +23,8 @@
# define __VIRT_HOST_VALIDATE_COMMON_H__
# include "internal.h"
+# include "virutil.h"
+# include "virbitmap.h"
typedef enum {
VIR_HOST_VALIDATE_FAIL,
@@ -32,6 +34,15 @@ typedef enum {
VIR_HOST_VALIDATE_LAST,
} virHostValidateLevel;
+typedef enum {
+ VIR_HOST_VALIDATE_CPU_FLAG_VMX = 0,
+ VIR_HOST_VALIDATE_CPU_FLAG_SVM,
+
+ VIR_HOST_VALIDATE_CPU_FLAG_LAST,
+} virHostValidateCPUFlag;
+
+VIR_ENUM_DECL(virHostValidateCPUFlag);
+
extern void virHostMsgSetQuiet(bool quietFlag);
extern void virHostMsgCheck(const char *prefix,
@@ -53,7 +64,7 @@ extern int virHostValidateDeviceAccessible(const char *hvname,
virHostValidateLevel level,
const char *hint);
-extern bool virHostValidateHasCPUFlag(const char *name);
+extern virBitmapPtr virHostValidateGetCPUFlags(void);
extern int virHostValidateLinuxKernel(const char *hvname,
int version,
diff --git a/tools/virt-host-validate-qemu.c b/tools/virt-host-validate-qemu.c
index a9f6c1e..b96b020 100644
--- a/tools/virt-host-validate-qemu.c
+++ b/tools/virt-host-validate-qemu.c
@@ -24,14 +24,20 @@
#include "virt-host-validate-qemu.h"
#include "virt-host-validate-common.h"
+#include "virbitmap.h"
int virHostValidateQEMU(void)
{
+ virBitmapPtr flags;
int ret = 0;
virHostMsgCheck("QEMU", "%s", ("for hardware virtualization"));
- if (virHostValidateHasCPUFlag("svm") ||
- virHostValidateHasCPUFlag("vmx")) {
+
+ flags = virHostValidateGetCPUFlags();
+
+ if (flags &&
+ (virBitmapIsBitSet(flags, VIR_HOST_VALIDATE_CPU_FLAG_SVM) ||
+ virBitmapIsBitSet(flags, VIR_HOST_VALIDATE_CPU_FLAG_VMX))) {
virHostMsgPass();
if (virHostValidateDeviceExists("QEMU", "/dev/kvm",
VIR_HOST_VALIDATE_FAIL,
@@ -48,6 +54,8 @@ int virHostValidateQEMU(void)
_("Only emulated CPUs are available, performance will be significantly limited"));
}
+ virBitmapFree(flags);
+
if (virHostValidateDeviceExists("QEMU", "/dev/vhost-net",
VIR_HOST_VALIDATE_WARN,
_("Load the 'vhost_net' module to improve performance "
--
2.5.5
9 years
[libvirt] [PATCH 0/3] vz: add boot order support
by Nikolay Shirokovskiy
Let's add support for old school boot order via xml os section.
Nikolay Shirokovskiy (3):
vz: support boot order specification on define domain
vz: fix disk order on load domain
vz: support boot order in domain xml dump
src/vz/vz_sdk.c | 390 +++++++++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 341 insertions(+), 49 deletions(-)
--
1.8.3.1
9 years
[libvirt] [PATCH v2 0/4] Add a domain masterKey secret for qemu,
by John Ferlan
v1: http://www.redhat.com/archives/libvir-list/2016-March/msg01206.html
Patch 1 is already ACK'd. I assume this code won't go into 1.3.3, but
would hopefully be early in 1.3.4 and I didn't want to break up the
capability bits across releases...
Differences to v1
- Patch 2 is new - it's taking the virUUIDGenerateRandomBytes and making
it generic since we'll use it in Patch 3 (it already opens/reads from
/dev/urandom, so I figured it'd be better to share than cut, copy, paste).
- Patch 3 has changes from review:
* Less comments in qemuDomainGetMasterKeyFilePath
* Master key no longer base64 encoded to be written (or read). Instead
the Write code will open, truncate, and write the secret directly.
The Read code will read the secret directly
* The fallback algorithm for key generation uses virGenerateRandomBytes
* Changed 'masterKey' from "char *" to "uint8_t *" and added the
masterKeyLen
- Patch 4 changes in order to tell qemu the format of the file is 'raw'.
Also affects test .args file
Removed references to encode/decode, adjusted commit messages.
Ran through Coverity checker... happy...
Created a domain that would pass/read the file... Killed libvirtd, restarted
and read the masterKey file properly. Also ensured the #else of the secret
generation compiled...
John Ferlan (4):
qemu: Add capability bit for qemu secret object
util: Introduce virGenerateRandomBytes
qemu: Create domain master key
qemu: Introduce qemuBuildMasterKeyCommandLine
src/libvirt_private.syms | 1 +
src/qemu/qemu_alias.c | 17 ++
src/qemu/qemu_alias.h | 3 +
src/qemu/qemu_capabilities.c | 2 +
src/qemu/qemu_capabilities.h | 1 +
src/qemu/qemu_command.c | 68 ++++++
src/qemu/qemu_domain.c | 252 +++++++++++++++++++++
src/qemu/qemu_domain.h | 15 ++
src/qemu/qemu_process.c | 11 +
src/util/virutil.c | 36 +++
src/util/virutil.h | 3 +
src/util/viruuid.c | 30 +--
tests/qemucapabilitiesdata/caps_2.6.0-1.caps | 1 +
tests/qemucapabilitiesdata/caps_2.6.0-1.replies | 3 +
.../qemuxml2argvdata/qemuxml2argv-master-key.args | 23 ++
tests/qemuxml2argvdata/qemuxml2argv-master-key.xml | 30 +++
tests/qemuxml2argvtest.c | 2 +
17 files changed, 469 insertions(+), 29 deletions(-)
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-master-key.args
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-master-key.xml
--
2.5.5
9 years
[libvirt] [PATCH] Link xen driver against libxl
by Guido Günther
to avoid the test failure
7) Test driver "xen" ... 2016-03-31 12:53:26.950+0000: 22430: debug : virDriverLoadModule:54 : Module load xen
2016-03-31 12:53:26.950+0000: 22430: error : virDriverLoadModule:73 : failed to load module /build/libvirt-1.3.3~rc1/debian/build/src/.libs/libvirt_driver_xen.so /build/libvirt-1.3.3~rc1/debian/build/src/.libs/libvirt_driver_xen.so: undefined symbol: xlu_cfg_destroy
FAILED
---
I have not yet investigated how this change came about so this is more
of a RFC.
src/Makefile.am | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/Makefile.am b/src/Makefile.am
index 1726d06..5f37607 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1218,7 +1218,9 @@ libvirt_driver_xen_impl_la_CFLAGS = \
-I$(srcdir)/xenconfig \
$(AM_CFLAGS)
libvirt_driver_xen_impl_la_LDFLAGS = $(AM_LDFLAGS)
-libvirt_driver_xen_impl_la_LIBADD = $(XEN_LIBS) libvirt_xenconfig.la
+libvirt_driver_xen_impl_la_LIBADD = $(XEN_LIBS) \
+ $(LIBXL_LIBS) \
+ libvirt_xenconfig.la
libvirt_driver_xen_impl_la_SOURCES = $(XEN_DRIVER_SOURCES)
endif WITH_XEN
--
2.8.0.rc3
9 years
[libvirt] [PATCH v5 0/6] storage:dir: ploop volumes support
by Olga Krishtal
This series of patches introduces the support of ploop volumes
in storage pools (dir, fs, etc).
Ploop volume is a disk loopback block device consists of root.hds
(it is the image file) and DiskDescriptor.xml:
https://openvz.org/Ploop/format. Due to this fact it can't be treated
as file or any other volume type, moreover, in order to successfully
manipulate with such volume, ploop tools should be installed.
All callbacks except the wipeVol are supported.
First patch introduces ploop volume type. This is a directory
with two files inside. The name of the directory is the name of the volume.
Patch 2 deals with creating an empty volume and cloning the existing one.
Clone is done via simle cp operation. If any of this operation fails -
directory will be deleted.
Patch 3 deletes recursively ploop directory.
Patch 4 uses ploop tool to resize volume.
Patch 6 adapts all refreshing functions to work with ploop. To get
information the directory is checked. The volume is treated as the
ploops one only if it contains ploop files. Every time the pool
is refreshed DiskDescriptor.xml is restored. This is necessary, because
the content of the volume may have changed.
Upload and download (patch 7) can't be done if the volume contains snapshots.
v5:
- added ploop volume type
- there is no change in opening volume functions. Now reopening takes place is
the volume is ploops one.
- restore DiskDescriptor.xml every refresh pool
- all information, except format is taken from header
- forbidden upload and download ops for volume with snapshots
- there is no separate function for deleting the volume
- fixed identation and leaks
v4:
- fixed identation issues.
- in case of .uploadVol, DiskDescriptor.xml is restored.
- added check of ploops'accessibility
v3:
- no VIR_STORAGE_VOL_PLOOP type any more
- adapted all patches according to previous change
- fixed comments
v2:
- fixed memory leak
- chenged the return value of all helper functions to 0/-1.
Now check for success is smth like that: vir****Ploop() < 0
- fixed some identation issues.
9 years
[libvirt] [PATCH] spec: Include KVM support on RHEL 7 ppc64 and newer
by Andrea Bolognani
---
Definitely not an expert on spec files, but I did a test build
on RHEL 7.2 ppc64le and it resulted in
libvirt-daemon-driver-qemu-1.3.3-1.el7.ppc64le.rpm
libvirt-daemon-kvm-1.3.3-1.el7.ppc64le.rpm
libvirt-lock-sanlock-1.3.3-1.el7.ppc64le.rpm
being built in addition to what was built even before, so it
looks reasonable I guess? Comments very welcome :)
libvirt.spec.in | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/libvirt.spec.in b/libvirt.spec.in
index 03e2438..fdea12a 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -77,7 +77,11 @@
%if 0%{?rhel}
%define with_qemu_tcg 0
- %define qemu_kvm_arches x86_64
+ %if 0%{?rhel} >= 7
+ %define qemu_kvm_arches x86_64 %{power64}
+ %else
+ %define qemu_kvm_arches x86_64
+ %endif
%endif
%ifarch %{qemu_kvm_arches}
--
2.5.0
9 years
[libvirt] [PATCH 0/2] boot order storage/parsing cleanup
by Peter Krempa
Few patches that I have laying around.
Peter Krempa (2):
conf: Pass the whole device info struct to virDomainDeviceBootParseXML
conf: store bootindex as unsigned int
src/bhyve/bhyve_command.c | 3 +--
src/conf/domain_conf.c | 19 +++++++++----------
src/conf/domain_conf.h | 2 +-
src/qemu/qemu_command.c | 40 +++++++++++++++++++++-------------------
src/qemu/qemu_command.h | 6 +++---
src/qemu/qemu_driver.c | 2 +-
6 files changed, 36 insertions(+), 36 deletions(-)
--
2.8.0
9 years