From nobody Wed May 14 08:08:27 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1524157856442759.2915416758913; Thu, 19 Apr 2018 10:10:56 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F1F6A5F739; Thu, 19 Apr 2018 17:10:54 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B97E7850B; Thu, 19 Apr 2018 17:10:54 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 76CFD180BAD4; Thu, 19 Apr 2018 17:10:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w3JHAFtK015144 for ; Thu, 19 Apr 2018 13:10:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 561552026E04; Thu, 19 Apr 2018 17:10:15 +0000 (UTC) Received: from t460.redhat.com (unknown [10.33.36.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id D67A12026DFD; Thu, 19 Apr 2018 17:10:14 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 19 Apr 2018 18:09:56 +0100 Message-Id: <20180419171002.17117-9-berrange@redhat.com> In-Reply-To: <20180419171002.17117-1-berrange@redhat.com> References: <20180419171002.17117-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 08/14] driver: add option to make missing drivers a fatal problem X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 19 Apr 2018 17:10:55 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Currently the driver module loading code does not report an error if the driver module is physically missing on disk. This is useful for distro packaging optional pieces. When the daemons are split up into one daemon per driver, we will expect module loading to always succeed. If a driver is not desired, the entire daemon should not be installed. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/driver.c | 37 ++++++++++++++++++++++++++----------- src/driver.h | 6 ++++-- src/remote/remote_daemon.c | 2 +- src/storage/storage_backend.c | 9 +-------- tests/virdrivermoduletest.c | 2 +- 5 files changed, 33 insertions(+), 23 deletions(-) diff --git a/src/driver.c b/src/driver.c index 9b137c39e4..447f61d554 100644 --- a/src/driver.c +++ b/src/driver.c @@ -103,15 +103,22 @@ virDriverLoadModuleFunc(void *handle, */ int virDriverLoadModuleFull(const char *path, - const char *regfunc) + const char *regfunc, + bool required) { void *rethandle =3D NULL; int (*regsym)(void); int ret =3D -1; =20 if (!virFileExists(path)) { - VIR_INFO("Module '%s' does not exists", path); - return 1; + if (required) { + virReportSystemError(errno, + _("Failed to find module '%s'"), path); + return -1; + } else { + VIR_INFO("Module '%s' does not exist", path); + return 1; + } } =20 if (!(rethandle =3D virDriverLoadModuleFile(path))) @@ -144,21 +151,29 @@ virDriverLoadModuleFull(const char *path, #else /* ! HAVE_DLFCN_H */ int virDriverLoadModuleFull(const char *path ATTRIBUTE_UNUSED, - const char *regfunc ATTRIBUTE_UNUSED) + const char *regfunc ATTRIBUTE_UNUSED, + bool required) { VIR_DEBUG("dlopen not available on this platform"); - /* Since we have no dlopen(), but definition we have no - * loadable modules on disk, so we can resaonably - * return '1' instead of an error. - */ - return 1; + if (required) { + virReportSystemError(ENOSYS, + _("Failed to find module '%s': %s"), path); + return -1; + } else { + /* Since we have no dlopen(), but definition we have no + * loadable modules on disk, so we can resaonably + * return '1' instead of an error. + */ + return 1; + } } #endif /* ! HAVE_DLFCN_H */ =20 =20 int virDriverLoadModule(const char *name, - const char *regfunc) + const char *regfunc, + bool required) { char *modfile =3D NULL; int ret; @@ -173,7 +188,7 @@ virDriverLoadModule(const char *name, "LIBVIRT_DRIVER_DIR"))) return -1; =20 - ret =3D virDriverLoadModuleFull(modfile, regfunc); + ret =3D virDriverLoadModuleFull(modfile, regfunc, required); =20 VIR_FREE(modfile); =20 diff --git a/src/driver.h b/src/driver.h index e28c63ecc2..b4e50ab987 100644 --- a/src/driver.h +++ b/src/driver.h @@ -108,9 +108,11 @@ int virSetSharedSecretDriver(virSecretDriverPtr driver= ) ATTRIBUTE_RETURN_CHECK; int virSetSharedStorageDriver(virStorageDriverPtr driver) ATTRIBUTE_RETURN= _CHECK; =20 int virDriverLoadModule(const char *name, - const char *regfunc); + const char *regfunc, + bool required); int virDriverLoadModuleFull(const char *path, - const char *regfunc); + const char *regfunc, + bool required); =20 virConnectPtr virGetConnectInterface(void); virConnectPtr virGetConnectNetwork(void); diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c index 3e02297eee..b4f89d4fd7 100644 --- a/src/remote/remote_daemon.c +++ b/src/remote/remote_daemon.c @@ -295,7 +295,7 @@ static int daemonErrorLogFilter(virErrorPtr err, int pr= iority) =20 =20 #define VIR_DAEMON_LOAD_MODULE(func, module) \ - virDriverLoadModule(module, #func) + virDriverLoadModule(module, #func, false) static void daemonInitialize(void) { /* diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index 8c1dcf31b1..cb1bcc0944 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -97,14 +97,7 @@ virStorageDriverLoadBackendModule(const char *name, "LIBVIRT_STORAGE_BACKEND_DIR")= )) return -1; =20 - if ((ret =3D virDriverLoadModuleFull(modfile, regfunc)) !=3D 0) { - if (forceload) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("failed to load storage backend module '%s'"), - name); - ret =3D -1; - } - } + ret =3D virDriverLoadModuleFull(modfile, regfunc, forceload); =20 VIR_FREE(modfile); =20 diff --git a/tests/virdrivermoduletest.c b/tests/virdrivermoduletest.c index 6c63ecd52b..125183327b 100644 --- a/tests/virdrivermoduletest.c +++ b/tests/virdrivermoduletest.c @@ -41,7 +41,7 @@ static int testDriverModule(const void *args) const struct testDriverModuleData *data =3D args; =20 /* coverity[leaked_storage] */ - if (virDriverLoadModule(data->module, data->regfunc) !=3D 0) + if (virDriverLoadModule(data->module, data->regfunc, true) !=3D 0) return -1; =20 return 0; --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list