提交 979218cd 编写于 作者: D Daniel P. Berrange

Fix return value in virStateInitialize impl for LXC

The LXC driver was mistakenly returning -1 for lxcStartup()
in scenarios that are not an error. This caused the libvirtd
to quit for unprivileged users. This fixes the return code
of LXC driver, and also adds a "name" field to the virStateDriver
struct and logging to make it easier to find these problems
in the future

* src/driver.h: Add a 'name' field to state driver to allow
  easy identification during failures
* src/libvirt.c: Log name of failed driver for virStateInit
  failures
* src/lxc/lxc_driver.c: Don't return a failure code for
  lxcStartup() if LXC is not available on this host, simply
  disable the driver.
* src/network/bridge_driver.c, src/node_device/node_device_devkit.c,
  src/node_device/node_device_hal.c, src/opennebula/one_driver.c,
  src/qemu/qemu_driver.c, src/remote/remote_driver.c,
  src/secret/secret_driver.c, src/storage/storage_driver.c,
  src/uml/uml_driver.c, src/xen/xen_driver.c: Fill in name
  field in virStateDriver struct
上级 680c92ae
......@@ -731,6 +731,7 @@ typedef struct _virStateDriver virStateDriver;
typedef virStateDriver *virStateDriverPtr;
struct _virStateDriver {
const char *name;
virDrvStateInitialize initialize;
virDrvStateCleanup cleanup;
virDrvStateReload reload;
......
......@@ -827,9 +827,12 @@ int virStateInitialize(int privileged) {
for (i = 0 ; i < virStateDriverTabCount ; i++) {
if (virStateDriverTab[i]->initialize &&
virStateDriverTab[i]->initialize(privileged) < 0)
virStateDriverTab[i]->initialize(privileged) < 0) {
VIR_ERROR("Initialization of %s state driver failed",
virStateDriverTab[i]->name);
ret = -1;
}
}
return ret;
}
......
......@@ -1641,12 +1641,21 @@ static int lxcStartup(int privileged)
* XXX remove this when valgrind is fixed
*/
ld = getenv("LD_PRELOAD");
if (ld && strstr(ld, "vgpreload"))
return -1;
if (ld && strstr(ld, "vgpreload")) {
VIR_INFO0("Running under valgrind, disabling driver");
return 0;
}
/* Check that the user is root */
/* Check that the user is root, silently disable if not */
if (!privileged) {
return -1;
VIR_INFO0("Not running privileged, disabling driver");
return 0;
}
/* Check that this is a container enabled kernel */
if (lxcContainerAvailable(0) < 0) {
VIR_INFO0("LXC support not available in this kernel, disabling driver");
return 0;
}
if (VIR_ALLOC(lxc_driver) < 0) {
......@@ -1658,12 +1667,6 @@ static int lxcStartup(int privileged)
}
lxcDriverLock(lxc_driver);
/* Check that this is a container enabled kernel */
if (lxcContainerAvailable(0) < 0) {
VIR_INFO0("LXC support not available in this kernel, disabling driver");
goto cleanup;
}
if (virDomainObjListInit(&lxc_driver->domains) < 0)
goto cleanup;
......@@ -2322,6 +2325,7 @@ static virDriver lxcDriver = {
};
static virStateDriver lxcStateDriver = {
.name = "LXC",
.initialize = lxcStartup,
.cleanup = lxcShutdown,
.active = lxcActive,
......
......@@ -1509,6 +1509,7 @@ static virNetworkDriver networkDriver = {
};
static virStateDriver networkStateDriver = {
"Network",
networkStartup,
networkShutdown,
networkReload,
......
......@@ -431,6 +431,7 @@ static virDeviceMonitor devkitDeviceMonitor = {
static virStateDriver devkitStateDriver = {
.name = "DeviceKit",
.initialize = devkitDeviceMonitorStartup,
.cleanup = devkitDeviceMonitorShutdown,
.reload = devkitDeviceMonitorReload,
......
......@@ -873,6 +873,7 @@ static virDeviceMonitor halDeviceMonitor = {
static virStateDriver halStateDriver = {
.name = "HAL",
.initialize = halDeviceMonitorStartup,
.cleanup = halDeviceMonitorShutdown,
.reload = halDeviceMonitorReload,
......
......@@ -761,6 +761,7 @@ static virDriver oneDriver = {
};
static virStateDriver oneStateDriver = {
.name = "OpenNebula",
.initialize = oneStartup,
.cleanup = oneShutdown,
.active = oneActive,
......
......@@ -7154,6 +7154,7 @@ static virDriver qemuDriver = {
static virStateDriver qemuStateDriver = {
.name = "QEMU",
.initialize = qemudStartup,
.cleanup = qemudShutdown,
.reload = qemudReload,
......
......@@ -8560,6 +8560,7 @@ static virDeviceMonitor dev_monitor = {
#ifdef WITH_LIBVIRTD
static virStateDriver state_driver = {
.name = "Remote",
.initialize = remoteStartup,
};
#endif
......
......@@ -1074,6 +1074,7 @@ static virSecretDriver secretDriver = {
};
static virStateDriver stateDriver = {
.name = "Secret",
.initialize = secretDriverStartup,
.cleanup = secretDriverCleanup,
.reload = secretDriverReload,
......
......@@ -1744,6 +1744,7 @@ static virStorageDriver storageDriver = {
static virStateDriver stateDriver = {
.name = "Storage",
.initialize = storageDriverStartup,
.cleanup = storageDriverShutdown,
.reload = storageDriverReload,
......
......@@ -1855,6 +1855,7 @@ static virDriver umlDriver = {
static virStateDriver umlStateDriver = {
.name = "UML",
.initialize = umlStartup,
.cleanup = umlShutdown,
.reload = umlReload,
......
......@@ -182,6 +182,7 @@ xenInitialize (int privileged ATTRIBUTE_UNUSED)
}
static virStateDriver state_driver = {
.name = "Xen",
.initialize = xenInitialize,
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册