[PATCH 1/2] virFileFindResource: Add support for looking in source tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Not all file we want to find using virFileFindResource{,Full} are
generated when libvirt is built, some of them (such as RNG schemas) are
distributed with sources. The current API was not able to find source
files if libvirt was built in VPATH.

Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx>
---
 src/Makefile.am                 |  2 ++
 src/driver.c                    |  1 +
 src/locking/lock_driver_lockd.c |  1 +
 src/locking/lock_manager.c      |  1 +
 src/remote/remote_driver.c      |  1 +
 src/util/virfile.c              | 39 ++++++++++++++++++++++++++++++---------
 src/util/virfile.h              |  8 +++++++-
 7 files changed, 43 insertions(+), 10 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index b41c6d4..a938d7e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -20,6 +20,7 @@
 abs_builddir = $(shell pwd)
 abs_topbuilddir = $(shell cd .. && pwd)
 abs_srcdir = $(shell cd $(srcdir) && pwd)
+abs_topsrcdir = $(shell cd $(srcdir)/.. && pwd)
 
 # No libraries with the exception of LIBXML should be listed
 # here. List them against the individual XXX_la_CFLAGS targets
@@ -32,6 +33,7 @@ INCLUDES =	-I../gnulib/lib					\
 		-I$(srcdir)/util				\
 		-DIN_LIBVIRT					\
 		-Dabs_topbuilddir="\"$(abs_topbuilddir)\""	\
+		-Dabs_topsrcdir="\"$(abs_topsrcdir)\""		\
 		$(GETTEXT_CPPFLAGS)
 
 AM_CFLAGS =	$(LIBXML_CFLAGS)				\
diff --git a/src/driver.c b/src/driver.c
index 1be32ef..1271597 100644
--- a/src/driver.c
+++ b/src/driver.c
@@ -57,6 +57,7 @@ virDriverLoadModule(const char *name)
                                             "libvirt_driver_",
                                             ".so",
                                             "src/.libs",
+                                            VIR_FILE_FIND_RESOURCE_VPATH_BUILD,
                                             LIBDIR "/libvirt/connection-driver",
                                             "LIBVIRT_DRIVER_DIR")))
         return NULL;
diff --git a/src/locking/lock_driver_lockd.c b/src/locking/lock_driver_lockd.c
index 2af3f22..53a7256 100644
--- a/src/locking/lock_driver_lockd.c
+++ b/src/locking/lock_driver_lockd.c
@@ -254,6 +254,7 @@ static virNetClientPtr virLockManagerLockDaemonConnectionNew(bool privileged,
         !(daemonPath = virFileFindResourceFull("virtlockd",
                                                NULL, NULL,
                                                "src",
+                                               VIR_FILE_FIND_RESOURCE_VPATH_BUILD,
                                                SBINDIR,
                                                "VIRTLOCKD_PATH")))
         goto error;
diff --git a/src/locking/lock_manager.c b/src/locking/lock_manager.c
index ec90d04..554e9e2 100644
--- a/src/locking/lock_manager.c
+++ b/src/locking/lock_manager.c
@@ -143,6 +143,7 @@ virLockManagerPluginPtr virLockManagerPluginNew(const char *name,
                                                 NULL,
                                                 ".so",
                                                 "src/.libs",
+                                                VIR_FILE_FIND_RESOURCE_VPATH_BUILD,
                                                 LIBDIR "/libvirt/lock-driver",
                                                 "LIBVIRT_LOCK_MANAGER_PLUGIN_DIR")))
             goto cleanup;
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index d4fd658..4830a48 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -888,6 +888,7 @@ doRemoteOpen(virConnectPtr conn,
             !(daemonPath = virFileFindResourceFull("libvirtd",
                                                    NULL, NULL,
                                                    "daemon",
+                                                   VIR_FILE_FIND_RESOURCE_VPATH_BUILD,
                                                    SBINDIR,
                                                    "LIBVIRTD_PATH")))
             goto failed;
diff --git a/src/util/virfile.c b/src/util/virfile.c
index 1b004d6..e60896f 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -1618,7 +1618,8 @@ static bool useDirOverride;
  * @filename: libvirt distributed filename without any path
  * @prefix: optional string to prepend to filename
  * @suffix: optional string to append to filename
- * @builddir: location of the binary in the source tree build tree
+ * @builddir: location of the filename in the build tree
+ * @vpath: switch between source and build directory in VPATH build
  * @installdir: location of the installed binary
  * @envname: environment variable used to override all dirs
  *
@@ -1627,8 +1628,14 @@ static bool useDirOverride;
  * run from the source tree. Otherwise it will return the
  * path in the installed location.
  *
+ * If libvirt was built in VPATH, @vpath switches between source and build
+ * directory when useDirOverride is in effect.  If @vpath is
+ * VIR_FILE_FIND_RESOURCE_VPATH_BUILD, @builddir refers to the build
+ * directory; VIR_FILE_FIND_RESOURCE_VPATH_SOURCE says @builddir is a
+ * subdirectory of the source directory.
+ *
  * If @envname is non-NULL it will override all other
- * directory lookup
+ * directory lookup.
  *
  * Only use this with @filename files that are part of
  * the libvirt tree, not 3rd party binaries/files.
@@ -1640,11 +1647,14 @@ virFileFindResourceFull(const char *filename,
                         const char *prefix,
                         const char *suffix,
                         const char *builddir,
+                        virFileFindResourceVPath vpath,
                         const char *installdir,
                         const char *envname)
 {
     char *ret = NULL;
     const char *envval = envname ? virGetEnvBlockSUID(envname) : NULL;
+    const char *base = "";
+    const char *path = "";
 
     if (!prefix)
         prefix = "";
@@ -1652,16 +1662,25 @@ virFileFindResourceFull(const char *filename,
         suffix = "";
 
     if (envval) {
-        if (virAsprintf(&ret, "%s/%s%s%s", envval, prefix, filename, suffix) < 0)
-            return NULL;
+        base = envval;
     } else if (useDirOverride) {
-        if (virAsprintf(&ret, "%s/%s/%s%s%s", abs_topbuilddir, builddir, prefix, filename, suffix) < 0)
-            return NULL;
+        switch (vpath) {
+        case VIR_FILE_FIND_RESOURCE_VPATH_BUILD:
+            base = abs_topbuilddir;
+            break;
+        case VIR_FILE_FIND_RESOURCE_VPATH_SOURCE:
+            base = abs_topsrcdir;
+            break;
+        }
+        path = builddir;
     } else {
-        if (virAsprintf(&ret, "%s/%s%s%s", installdir, prefix, filename, suffix) < 0)
-            return NULL;
+        base = installdir;
     }
 
+    if (virAsprintf(&ret, "%s%s%s/%s%s%s",
+                    base, *path ? "/" : "", path, prefix, filename, suffix) < 0)
+        return NULL;
+
     VIR_DEBUG("Resolved '%s' to '%s'", filename, ret);
     return ret;
 }
@@ -1671,7 +1690,9 @@ virFileFindResource(const char *filename,
                     const char *builddir,
                     const char *installdir)
 {
-    return virFileFindResourceFull(filename, NULL, NULL, builddir, installdir, NULL);
+    return virFileFindResourceFull(filename, NULL, NULL,
+                                   builddir, VIR_FILE_FIND_RESOURCE_VPATH_BUILD,
+                                   installdir, NULL);
 }
 
 
diff --git a/src/util/virfile.h b/src/util/virfile.h
index 403d0ba..0e481c2 100644
--- a/src/util/virfile.h
+++ b/src/util/virfile.h
@@ -163,6 +163,11 @@ int virFileIsLink(const char *linkpath)
 
 char *virFindFileInPath(const char *file);
 
+typedef enum {
+    VIR_FILE_FIND_RESOURCE_VPATH_BUILD,
+    VIR_FILE_FIND_RESOURCE_VPATH_SOURCE
+} virFileFindResourceVPath;
+
 char *virFileFindResource(const char *filename,
                           const char *builddir,
                           const char *installdir)
@@ -171,9 +176,10 @@ char *virFileFindResourceFull(const char *filename,
                               const char *prefix,
                               const char *suffix,
                               const char *builddir,
+                              virFileFindResourceVPath vpath,
                               const char *installdir,
                               const char *envname)
-    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(5);
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(6);
 void virFileActivateDirOverride(const char *argv0)
     ATTRIBUTE_NONNULL(1);
 
-- 
2.3.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]