1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-26 03:21:44 +03:00

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
This commit is contained in:
Daniel P. Berrange 2009-11-02 18:18:19 -05:00
parent 680c92ae7e
commit 979218cdd9
13 changed files with 29 additions and 11 deletions

View File

@ -731,6 +731,7 @@ typedef struct _virStateDriver virStateDriver;
typedef virStateDriver *virStateDriverPtr; typedef virStateDriver *virStateDriverPtr;
struct _virStateDriver { struct _virStateDriver {
const char *name;
virDrvStateInitialize initialize; virDrvStateInitialize initialize;
virDrvStateCleanup cleanup; virDrvStateCleanup cleanup;
virDrvStateReload reload; virDrvStateReload reload;

View File

@ -827,9 +827,12 @@ int virStateInitialize(int privileged) {
for (i = 0 ; i < virStateDriverTabCount ; i++) { for (i = 0 ; i < virStateDriverTabCount ; i++) {
if (virStateDriverTab[i]->initialize && 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; ret = -1;
} }
}
return ret; return ret;
} }

View File

@ -1641,12 +1641,21 @@ static int lxcStartup(int privileged)
* XXX remove this when valgrind is fixed * XXX remove this when valgrind is fixed
*/ */
ld = getenv("LD_PRELOAD"); ld = getenv("LD_PRELOAD");
if (ld && strstr(ld, "vgpreload")) if (ld && strstr(ld, "vgpreload")) {
return -1; 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) { 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) { if (VIR_ALLOC(lxc_driver) < 0) {
@ -1658,12 +1667,6 @@ static int lxcStartup(int privileged)
} }
lxcDriverLock(lxc_driver); 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) if (virDomainObjListInit(&lxc_driver->domains) < 0)
goto cleanup; goto cleanup;
@ -2322,6 +2325,7 @@ static virDriver lxcDriver = {
}; };
static virStateDriver lxcStateDriver = { static virStateDriver lxcStateDriver = {
.name = "LXC",
.initialize = lxcStartup, .initialize = lxcStartup,
.cleanup = lxcShutdown, .cleanup = lxcShutdown,
.active = lxcActive, .active = lxcActive,

View File

@ -1509,6 +1509,7 @@ static virNetworkDriver networkDriver = {
}; };
static virStateDriver networkStateDriver = { static virStateDriver networkStateDriver = {
"Network",
networkStartup, networkStartup,
networkShutdown, networkShutdown,
networkReload, networkReload,

View File

@ -431,6 +431,7 @@ static virDeviceMonitor devkitDeviceMonitor = {
static virStateDriver devkitStateDriver = { static virStateDriver devkitStateDriver = {
.name = "DeviceKit",
.initialize = devkitDeviceMonitorStartup, .initialize = devkitDeviceMonitorStartup,
.cleanup = devkitDeviceMonitorShutdown, .cleanup = devkitDeviceMonitorShutdown,
.reload = devkitDeviceMonitorReload, .reload = devkitDeviceMonitorReload,

View File

@ -873,6 +873,7 @@ static virDeviceMonitor halDeviceMonitor = {
static virStateDriver halStateDriver = { static virStateDriver halStateDriver = {
.name = "HAL",
.initialize = halDeviceMonitorStartup, .initialize = halDeviceMonitorStartup,
.cleanup = halDeviceMonitorShutdown, .cleanup = halDeviceMonitorShutdown,
.reload = halDeviceMonitorReload, .reload = halDeviceMonitorReload,

View File

@ -761,6 +761,7 @@ static virDriver oneDriver = {
}; };
static virStateDriver oneStateDriver = { static virStateDriver oneStateDriver = {
.name = "OpenNebula",
.initialize = oneStartup, .initialize = oneStartup,
.cleanup = oneShutdown, .cleanup = oneShutdown,
.active = oneActive, .active = oneActive,

View File

@ -7154,6 +7154,7 @@ static virDriver qemuDriver = {
static virStateDriver qemuStateDriver = { static virStateDriver qemuStateDriver = {
.name = "QEMU",
.initialize = qemudStartup, .initialize = qemudStartup,
.cleanup = qemudShutdown, .cleanup = qemudShutdown,
.reload = qemudReload, .reload = qemudReload,

View File

@ -8560,6 +8560,7 @@ static virDeviceMonitor dev_monitor = {
#ifdef WITH_LIBVIRTD #ifdef WITH_LIBVIRTD
static virStateDriver state_driver = { static virStateDriver state_driver = {
.name = "Remote",
.initialize = remoteStartup, .initialize = remoteStartup,
}; };
#endif #endif

View File

@ -1074,6 +1074,7 @@ static virSecretDriver secretDriver = {
}; };
static virStateDriver stateDriver = { static virStateDriver stateDriver = {
.name = "Secret",
.initialize = secretDriverStartup, .initialize = secretDriverStartup,
.cleanup = secretDriverCleanup, .cleanup = secretDriverCleanup,
.reload = secretDriverReload, .reload = secretDriverReload,

View File

@ -1744,6 +1744,7 @@ static virStorageDriver storageDriver = {
static virStateDriver stateDriver = { static virStateDriver stateDriver = {
.name = "Storage",
.initialize = storageDriverStartup, .initialize = storageDriverStartup,
.cleanup = storageDriverShutdown, .cleanup = storageDriverShutdown,
.reload = storageDriverReload, .reload = storageDriverReload,

View File

@ -1855,6 +1855,7 @@ static virDriver umlDriver = {
static virStateDriver umlStateDriver = { static virStateDriver umlStateDriver = {
.name = "UML",
.initialize = umlStartup, .initialize = umlStartup,
.cleanup = umlShutdown, .cleanup = umlShutdown,
.reload = umlReload, .reload = umlReload,

View File

@ -182,6 +182,7 @@ xenInitialize (int privileged ATTRIBUTE_UNUSED)
} }
static virStateDriver state_driver = { static virStateDriver state_driver = {
.name = "Xen",
.initialize = xenInitialize, .initialize = xenInitialize,
}; };