ch_driver: Don't error out if CH_CMD was not found

The CH driver needs "cloud-hypervisor" binary. And if none was
found then the initialization of the driver fails as
chStateInitialize() returns VIR_DRV_STATE_INIT_ERROR. This in
turn means that whole daemon fails to initialize. Let's return
VIR_DRV_STATE_INIT_SKIPPED in this particular case, which
disables the CH drvier but lets the daemon run.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Michal Privoznik 2021-06-04 14:55:04 +02:00
parent da91bdf836
commit 7a90431d7d
2 changed files with 16 additions and 5 deletions

View File

@ -199,8 +199,12 @@ chExtractVersion(virCHDriver *driver)
char *help = NULL;
char *tmp = NULL;
g_autofree char *ch_cmd = g_find_program_in_path(CH_CMD);
virCommand *cmd = virCommandNewArgList(ch_cmd, "--version", NULL);
virCommand *cmd = NULL;
if (!ch_cmd)
return -2;
cmd = virCommandNewArgList(ch_cmd, "--version", NULL);
virCommandAddEnvString(cmd, "LC_ALL=C");
virCommandSetOutputBuffer(cmd, &help);

View File

@ -836,6 +836,9 @@ static int chStateInitialize(bool privileged,
virStateInhibitCallback callback G_GNUC_UNUSED,
void *opaque G_GNUC_UNUSED)
{
int ret = VIR_DRV_STATE_INIT_ERROR;
int rv;
if (root != NULL) {
virReportError(VIR_ERR_INVALID_ARG, "%s",
_("Driver does not support embedded mode"));
@ -861,14 +864,18 @@ static int chStateInitialize(bool privileged,
if (!(ch_driver->config = virCHDriverConfigNew(privileged)))
goto cleanup;
if (chExtractVersion(ch_driver) < 0)
if ((rv = chExtractVersion(ch_driver)) < 0) {
if (rv == -2)
ret = VIR_DRV_STATE_INIT_SKIPPED;
goto cleanup;
}
return VIR_DRV_STATE_INIT_COMPLETE;
ret = VIR_DRV_STATE_INIT_COMPLETE;
cleanup:
chStateCleanup();
return VIR_DRV_STATE_INIT_ERROR;
if (ret != VIR_DRV_STATE_INIT_COMPLETE)
chStateCleanup();
return ret;
}
/* Function Tables */