From 7a90431d7df5911aedf172bd275a4093486e3fe0 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Fri, 4 Jun 2021 14:55:04 +0200 Subject: [PATCH] ch_driver: Don't error out if CH_CMD was not found MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Daniel P. Berrangé --- src/ch/ch_conf.c | 6 +++++- src/ch/ch_driver.c | 15 +++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/ch/ch_conf.c b/src/ch/ch_conf.c index dfebc8525a..b2812de7ad 100644 --- a/src/ch/ch_conf.c +++ b/src/ch/ch_conf.c @@ -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); diff --git a/src/ch/ch_driver.c b/src/ch/ch_driver.c index 7d1e97098a..8c458a20bd 100644 --- a/src/ch/ch_driver.c +++ b/src/ch/ch_driver.c @@ -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 */