mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-24 05:25:18 +00:00
maint: simplify driver registration at startup
We had a lot of repetition of errors that would occur if we ever register too many drivers; this is unlikely to occur unless we start adding a lot of new hypervisor modules, but if it does occur, it's better to have uniform handling of the situation, so that a one-line change is all that would be needed if we decide that an internal error is not the best. * src/libvirt.c (virDriverCheckTabMaxReturn): New define. (virRegister*Driver): Use it for less code duplication. Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
27553573f2
commit
323c2cc46c
@ -107,6 +107,16 @@
|
|||||||
|
|
||||||
#define MAX_DRIVERS 20
|
#define MAX_DRIVERS 20
|
||||||
|
|
||||||
|
#define virDriverCheckTabMaxReturn(count, ret) \
|
||||||
|
do { \
|
||||||
|
if ((count) >= MAX_DRIVERS) { \
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR, \
|
||||||
|
_("Too many drivers, cannot register %s"), \
|
||||||
|
driver->name); \
|
||||||
|
return ret; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
static virDriverPtr virDriverTab[MAX_DRIVERS];
|
static virDriverPtr virDriverTab[MAX_DRIVERS];
|
||||||
static int virDriverTabCount = 0;
|
static int virDriverTabCount = 0;
|
||||||
static virNetworkDriverPtr virNetworkDriverTab[MAX_DRIVERS];
|
static virNetworkDriverPtr virNetworkDriverTab[MAX_DRIVERS];
|
||||||
@ -542,13 +552,7 @@ int
|
|||||||
virRegisterNetworkDriver(virNetworkDriverPtr driver)
|
virRegisterNetworkDriver(virNetworkDriverPtr driver)
|
||||||
{
|
{
|
||||||
virCheckNonNullArgReturn(driver, -1);
|
virCheckNonNullArgReturn(driver, -1);
|
||||||
|
virDriverCheckTabMaxReturn(virNetworkDriverTabCount, -1);
|
||||||
if (virNetworkDriverTabCount >= MAX_DRIVERS) {
|
|
||||||
virLibConnError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("Too many drivers, cannot register %s"),
|
|
||||||
driver->name);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
VIR_DEBUG("registering %s as network driver %d",
|
VIR_DEBUG("registering %s as network driver %d",
|
||||||
driver->name, virNetworkDriverTabCount);
|
driver->name, virNetworkDriverTabCount);
|
||||||
@ -570,13 +574,7 @@ int
|
|||||||
virRegisterInterfaceDriver(virInterfaceDriverPtr driver)
|
virRegisterInterfaceDriver(virInterfaceDriverPtr driver)
|
||||||
{
|
{
|
||||||
virCheckNonNullArgReturn(driver, -1);
|
virCheckNonNullArgReturn(driver, -1);
|
||||||
|
virDriverCheckTabMaxReturn(virInterfaceDriverTabCount, -1);
|
||||||
if (virInterfaceDriverTabCount >= MAX_DRIVERS) {
|
|
||||||
virLibConnError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("Too many drivers, cannot register %s"),
|
|
||||||
driver->name);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
VIR_DEBUG("registering %s as interface driver %d",
|
VIR_DEBUG("registering %s as interface driver %d",
|
||||||
driver->name, virInterfaceDriverTabCount);
|
driver->name, virInterfaceDriverTabCount);
|
||||||
@ -598,13 +596,7 @@ int
|
|||||||
virRegisterStorageDriver(virStorageDriverPtr driver)
|
virRegisterStorageDriver(virStorageDriverPtr driver)
|
||||||
{
|
{
|
||||||
virCheckNonNullArgReturn(driver, -1);
|
virCheckNonNullArgReturn(driver, -1);
|
||||||
|
virDriverCheckTabMaxReturn(virStorageDriverTabCount, -1);
|
||||||
if (virStorageDriverTabCount >= MAX_DRIVERS) {
|
|
||||||
virLibConnError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("Too many drivers, cannot register %s"),
|
|
||||||
driver->name);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
VIR_DEBUG("registering %s as storage driver %d",
|
VIR_DEBUG("registering %s as storage driver %d",
|
||||||
driver->name, virStorageDriverTabCount);
|
driver->name, virStorageDriverTabCount);
|
||||||
@ -626,13 +618,7 @@ int
|
|||||||
virRegisterNodeDeviceDriver(virNodeDeviceDriverPtr driver)
|
virRegisterNodeDeviceDriver(virNodeDeviceDriverPtr driver)
|
||||||
{
|
{
|
||||||
virCheckNonNullArgReturn(driver, -1);
|
virCheckNonNullArgReturn(driver, -1);
|
||||||
|
virDriverCheckTabMaxReturn(virNodeDeviceDriverTabCount, -1);
|
||||||
if (virNodeDeviceDriverTabCount >= MAX_DRIVERS) {
|
|
||||||
virLibConnError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("Too many drivers, cannot register %s"),
|
|
||||||
driver->name);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
VIR_DEBUG("registering %s as device driver %d",
|
VIR_DEBUG("registering %s as device driver %d",
|
||||||
driver->name, virNodeDeviceDriverTabCount);
|
driver->name, virNodeDeviceDriverTabCount);
|
||||||
@ -654,13 +640,7 @@ int
|
|||||||
virRegisterSecretDriver(virSecretDriverPtr driver)
|
virRegisterSecretDriver(virSecretDriverPtr driver)
|
||||||
{
|
{
|
||||||
virCheckNonNullArgReturn(driver, -1);
|
virCheckNonNullArgReturn(driver, -1);
|
||||||
|
virDriverCheckTabMaxReturn(virSecretDriverTabCount, -1);
|
||||||
if (virSecretDriverTabCount >= MAX_DRIVERS) {
|
|
||||||
virLibConnError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("Too many drivers, cannot register %s"),
|
|
||||||
driver->name);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
VIR_DEBUG("registering %s as secret driver %d",
|
VIR_DEBUG("registering %s as secret driver %d",
|
||||||
driver->name, virSecretDriverTabCount);
|
driver->name, virSecretDriverTabCount);
|
||||||
@ -682,13 +662,7 @@ int
|
|||||||
virRegisterNWFilterDriver(virNWFilterDriverPtr driver)
|
virRegisterNWFilterDriver(virNWFilterDriverPtr driver)
|
||||||
{
|
{
|
||||||
virCheckNonNullArgReturn(driver, -1);
|
virCheckNonNullArgReturn(driver, -1);
|
||||||
|
virDriverCheckTabMaxReturn(virNWFilterDriverTabCount, -1);
|
||||||
if (virNWFilterDriverTabCount >= MAX_DRIVERS) {
|
|
||||||
virLibConnError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("Too many drivers, cannot register %s"),
|
|
||||||
driver->name);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
VIR_DEBUG("registering %s as network filter driver %d",
|
VIR_DEBUG("registering %s as network filter driver %d",
|
||||||
driver->name, virNWFilterDriverTabCount);
|
driver->name, virNWFilterDriverTabCount);
|
||||||
@ -709,16 +683,11 @@ virRegisterNWFilterDriver(virNWFilterDriverPtr driver)
|
|||||||
int
|
int
|
||||||
virRegisterDriver(virDriverPtr driver)
|
virRegisterDriver(virDriverPtr driver)
|
||||||
{
|
{
|
||||||
VIR_DEBUG("driver=%p name=%s", driver, driver ? NULLSTR(driver->name) : "(null)");
|
VIR_DEBUG("driver=%p name=%s", driver,
|
||||||
|
driver ? NULLSTR(driver->name) : "(null)");
|
||||||
|
|
||||||
virCheckNonNullArgReturn(driver, -1);
|
virCheckNonNullArgReturn(driver, -1);
|
||||||
|
virDriverCheckTabMaxReturn(virDriverTabCount, -1);
|
||||||
if (virDriverTabCount >= MAX_DRIVERS) {
|
|
||||||
virLibConnError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("Too many drivers, cannot register %s"),
|
|
||||||
driver->name);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
VIR_DEBUG("registering %s as driver %d",
|
VIR_DEBUG("registering %s as driver %d",
|
||||||
driver->name, virDriverTabCount);
|
driver->name, virDriverTabCount);
|
||||||
@ -741,13 +710,7 @@ int
|
|||||||
virRegisterStateDriver(virStateDriverPtr driver)
|
virRegisterStateDriver(virStateDriverPtr driver)
|
||||||
{
|
{
|
||||||
virCheckNonNullArgReturn(driver, -1);
|
virCheckNonNullArgReturn(driver, -1);
|
||||||
|
virDriverCheckTabMaxReturn(virStateDriverTabCount, -1);
|
||||||
if (virStateDriverTabCount >= MAX_DRIVERS) {
|
|
||||||
virLibConnError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("Too many drivers, cannot register %s"),
|
|
||||||
driver->name);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
virStateDriverTab[virStateDriverTabCount] = driver;
|
virStateDriverTab[virStateDriverTabCount] = driver;
|
||||||
return virStateDriverTabCount++;
|
return virStateDriverTabCount++;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user