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

Re: [lvm-devel] [PATCH 01/11] debian: fix library search path in example.conf



Alasdair G Kergon wrote:
> On Mon, Oct 12, 2009 at 06:02:05AM +0200, Fabio M. Di Nitto wrote:
>> On Sun, 2009-10-11 at 22:23 +0200, Bastian Blank wrote:
>>> Its currently unused. The cluster locking lib was the only used external
>>> lib.
>  
>> Alasdair, given that cluster locking lib is gone, do we have a use case
>> to keep this option configurable? 
> 
> It's used for all lvm2 external libraries and needs to stay.  The
> commented-out example is only worth making configurable if people are
> actually installing libraries into private directories (and arguably it
> should then be hard-coded into the source too).
> 
> We only stopped building the cluster locking library externally on Red
> Hat distributions because of some complexities of the Red Hat build
> system.  If they get resolved (as I hope they will be with RHEL6) then
> we will probably reinstate it.  
> 

The patch in attachment:
- allows lvm2libdir to be configurable
- dynamically update docs and man pages
- changes get_shared_library_path to understand LVM2_LIB_DIR
- make get_shared_library_path returns error (void to int)
- update get_shared_library_path users

Fabio

diff --git a/configure b/configure
index 7da2d3c..0e47a6f 100755
--- a/configure
+++ b/configure
@@ -637,6 +637,7 @@ ac_includes_default="\
 
 ac_default_prefix=/usr
 ac_subst_vars='LTLIBOBJS
+lvm2libdir
 usrsbindir
 usrlibdir
 udevdir
@@ -841,6 +842,7 @@ with_confdir
 with_staticdir
 with_usrlibdir
 with_usrsbindir
+with_lvm2libdir
 with_udev_prefix
 with_udevdir
 with_dmeventd_pidfile
@@ -1561,6 +1563,7 @@ Optional Packages:
   --with-staticdir=DIR    Static binary in DIR [EPREFIX/sbin]
   --with-usrlibdir=DIR
   --with-usrsbindir=DIR
+  --with-lvm2libdir=DIR   LVM2 extension libraries in DIR [libdir]
   --with-udev-prefix=UPREFIX      Install udev rule files in UPREFIX [EPREFIX]
   --with-udevdir=DIR      udev rules in DIR [UPREFIX/lib/udev/rules.d]
   --with-dmeventd-pidfile=PATH    dmeventd pidfile [/var/run/dmeventd.pid]
@@ -13651,6 +13654,21 @@ else
 fi
 
 
+
+# Check whether --with-lvm2libdir was given.
+if test "${with_lvm2libdir+set}" = set; then
+  withval=$with_lvm2libdir;  lvm2libdir="$withval"
+else
+   lvm2libdir=${libdir}
+fi
+
+
+
+cat >>confdefs.h <<_ACEOF
+#define LVM2_LIB_DIR "$(eval echo ${lvm2libdir})"
+_ACEOF
+
+
 ################################################################################
 
 # Check whether --with-udev_prefix was given.
@@ -15525,6 +15543,7 @@ LVM_LIBAPI=`echo "$VER" | $AWK -F '[()]' '{print $2}'`
 
 
 
+
 ################################################################################
 ac_config_files="$ac_config_files Makefile make.tmpl daemons/Makefile daemons/clvmd/Makefile daemons/cmirrord/Makefile daemons/dmeventd/Makefile daemons/dmeventd/libdevmapper-event.pc daemons/dmeventd/plugins/Makefile daemons/dmeventd/plugins/mirror/Makefile daemons/dmeventd/plugins/snapshot/Makefile doc/Makefile include/.symlinks include/Makefile lib/Makefile lib/format1/Makefile lib/format_pool/Makefile lib/locking/Makefile lib/mirror/Makefile lib/misc/lvm-version.h lib/snapshot/Makefile libdm/Makefile libdm/libdevmapper.pc liblvm/Makefile liblvm/liblvm2app.pc man/Makefile po/Makefile scripts/clvmd_init_red_hat scripts/lvm2_monitoring_init_red_hat scripts/Makefile test/Makefile test/api/Makefile tools/Makefile udev/Makefile"
 
diff --git a/configure.in b/configure.in
index 834fd6e..fa4583b 100644
--- a/configure.in
+++ b/configure.in
@@ -947,6 +947,13 @@ AC_ARG_WITH(usrsbindir,
 	    [ usrsbindir="$withval"],
 	    [ usrsbindir='${prefix}/sbin' ])
 
+AC_ARG_WITH(lvm2libdir,
+	    [  --with-lvm2libdir=DIR   LVM2 extension libraries in DIR [[libdir]]],
+	    [ lvm2libdir="$withval"],
+	    [ lvm2libdir=${libdir} ])
+
+AC_DEFINE_UNQUOTED(LVM2_LIB_DIR, "$(eval echo ${lvm2libdir})", [LVM2 extension libraries DIR])
+
 ################################################################################
 AC_ARG_WITH(udev_prefix,
 	    [  --with-udev-prefix=UPREFIX      Install udev rule files in UPREFIX [[EPREFIX]]],
@@ -1140,6 +1147,7 @@ AC_SUBST(udev_prefix)
 AC_SUBST(udevdir)
 AC_SUBST(usrlibdir)
 AC_SUBST(usrsbindir)
+AC_SUBST(lvm2libdir)
 
 ################################################################################
 dnl -- First and last lines should not contain files to generate in order to
diff --git a/doc/Makefile.in b/doc/Makefile.in
index b4689af..bf21e0e 100644
--- a/doc/Makefile.in
+++ b/doc/Makefile.in
@@ -21,6 +21,11 @@ CONFDEST=lvm.conf
 
 include ../make.tmpl
 
+all: $(CONFSRC)
+
+$(CONFSRC): $(CONFSRC).in
+	$(SED) -e "s #lvm2libdir#@${lvm2libdir} g" $< > $@
+
 install_lvm2: $(CONFSRC)
 	@if [ ! -e $(confdir)/$(CONFDEST) ]; then \
 		echo "Installing $(CONFSRC) as $(confdir)/$(CONFDEST)"; \
@@ -29,3 +34,5 @@ install_lvm2: $(CONFSRC)
 	fi
 
 install: install_lvm2
+
+CLEAN_TARGETS += $(CONFSRC)
diff --git a/doc/example.conf.in b/doc/example.conf.in
index 1067665..2fe7ad7 100644
--- a/doc/example.conf.in
+++ b/doc/example.conf.in
@@ -312,7 +312,7 @@ global {
     # Full pathnames can be given.
 
     # Search this directory first for shared libraries.
-    #   library_dir = "/lib"
+    #   library_dir = "#lvm2libdir#"
 
     # The external locking library to load if locking_type is set to 2.
     #   locking_library = "liblvm2clusterlock.so"
diff --git a/lib/mirror/mirrored.c b/lib/mirror/mirrored.c
index e93ed0b..7595832 100644
--- a/lib/mirror/mirrored.c
+++ b/lib/mirror/mirrored.c
@@ -422,7 +422,10 @@ static int _get_mirror_dso_path(struct cmd_context *cmd, char **dso)
 	libpath = find_config_tree_str(cmd, "dmeventd/mirror_library",
 				       DEFAULT_DMEVENTD_MIRROR_LIB);
 
-	get_shared_library_path(cmd, libpath, path, PATH_MAX);
+	if (get_shared_library_path(cmd, libpath, path, PATH_MAX) == -1) {
+		log_error("Unable to get shared path for mirror_library");
+		return 0;
+	}
 
 	*dso = path;
 
diff --git a/lib/misc/configure.h.in b/lib/misc/configure.h.in
index 4273eeb..ed18616 100644
--- a/lib/misc/configure.h.in
+++ b/lib/misc/configure.h.in
@@ -389,6 +389,9 @@
 /* Define to 1 to include built-in support for LVM1 metadata. */
 #undef LVM1_INTERNAL
 
+/* LVM2 extension libraries DIR */
+#undef LVM2_LIB_DIR
+
 /* Define to 1 to include built-in support for mirrors. */
 #undef MIRRORED_INTERNAL
 
diff --git a/lib/misc/sharedlib.c b/lib/misc/sharedlib.c
index cab2909..a8d05f2 100644
--- a/lib/misc/sharedlib.c
+++ b/lib/misc/sharedlib.c
@@ -23,19 +23,49 @@
 #include <sys/stat.h>
 #include <dlfcn.h>
 
-void get_shared_library_path(struct cmd_context *cmd, const char *libname,
+/* return 0 on success
+ *        -1 on failure
+ */
+int get_shared_library_path(struct cmd_context *cmd, const char *libname,
 			     char *path, size_t path_len)
 {
 	struct stat info;
 	const char *lib_dir;
 
-	/* If libname doesn't begin with '/' then use lib_dir/libname,
-	 * if present */
-	if (libname[0] == '/' ||
-	    !(lib_dir = find_config_tree_str(cmd, "global/library_dir", 0)) ||
-	    (dm_snprintf(path, path_len, "%s/%s", lib_dir,
-			  libname) == -1) || stat(path, &info) == -1)
+	/* If libname begins with '/' we assume it is an absolute path,
+	 * otherwise use lib_dir/libname if present.
+	 */
+	if (libname[0] == '/') {
+		if (strlen(libname) > path_len)
+			return -1;
+
 		strncpy(path, libname, path_len);
+
+		if (strlen(libname) != strlen(path))
+			return -1;
+
+		return 0;
+	}
+
+	/* Determine the library_dir.
+	 * First check if it's available in the configuration file,
+	 * otherwise use build time default value. See --with-lvm2libdir=
+	 */
+	lib_dir = find_config_tree_str(cmd, "global/library_dir", 0);
+	if (!lib_dir) {
+		log_very_verbose("Use built-in global/library_dir");
+		lib_dir = LVM2_LIB_DIR;
+	}
+
+	/* create the path */
+	if (dm_snprintf(path, path_len, "%s/%s", lib_dir, libname) == -1)
+		return -1;
+
+	/* check if the library exists */
+	if (stat(path, &info) == -1)
+		return -1;
+
+	return 0;
 }
 
 void *load_shared_library(struct cmd_context *cmd, const char *libname,
@@ -50,7 +80,10 @@ void *load_shared_library(struct cmd_context *cmd, const char *libname,
 		return NULL;
 	}
 
-	get_shared_library_path(cmd, libname, path, sizeof(path));
+	if (get_shared_library_path(cmd, libname, path, sizeof(path)) == -1) {
+		log_error("Unable get shared %s library %s path.", desc, libname);
+		return NULL;
+	}
 
 	log_very_verbose("Opening shared %s library %s", desc, path);
 
diff --git a/lib/misc/sharedlib.h b/lib/misc/sharedlib.h
index d996a8b..68e3f22 100644
--- a/lib/misc/sharedlib.h
+++ b/lib/misc/sharedlib.h
@@ -19,7 +19,7 @@
 #include "config.h"
 #include <dlfcn.h>
 
-void get_shared_library_path(struct cmd_context *cmd, const char *libname,
+int get_shared_library_path(struct cmd_context *cmd, const char *libname,
 			     char *path, size_t path_len);
 void *load_shared_library(struct cmd_context *cmd, const char *libname,
 			  const char *what, int silent);
diff --git a/lib/snapshot/snapshot.c b/lib/snapshot/snapshot.c
index d5bac31..6bb18e5 100644
--- a/lib/snapshot/snapshot.c
+++ b/lib/snapshot/snapshot.c
@@ -146,7 +146,10 @@ static int _get_snapshot_dso_path(struct cmd_context *cmd, char **dso)
 	if (!libpath)
 		return 0;
 
-	get_shared_library_path(cmd, libpath, path, PATH_MAX);
+	if (get_shared_library_path(cmd, libpath, path, PATH_MAX) == -1) {
+		log_error("Unable to get shared path for snapshot_library");
+		return 0;
+	}
 
 	*dso = path;
 
diff --git a/make.tmpl.in b/make.tmpl.in
index a6e16de..cf935ef 100644
--- a/make.tmpl.in
+++ b/make.tmpl.in
@@ -52,6 +52,7 @@ mandir = $(DESTDIR)@mandir@
 localedir = $(DESTDIR)@LOCALEDIR@
 staticdir = $(DESTDIR)@STATICDIR@
 udevdir = $(DESTDIR)@udevdir@
+lvm2libdir = $(DESTDIR)@lvm2libdir@
 
 interface = @interface@
 interfacedir = $(top_srcdir)/libdm/$(interface)
diff --git a/man/Makefile.in b/man/Makefile.in
index f0c98fd..69b1051 100644
--- a/man/Makefile.in
+++ b/man/Makefile.in
@@ -56,7 +56,8 @@ man: $(MAN5) $(MAN8) $(MAN8CLUSTER)
 $(MAN5) $(MAN8) $(MAN8CLUSTER):	Makefile
 
 %: %.in
-	$(SED) -e "s/#VERSION#/$(LVM_VERSION)/" $< > $@
+	$(SED) -e "s/#VERSION#/$(LVM_VERSION)/" \
+	       -e "s #lvm2libdir#@${lvm2libdir} g" $< > $@
 
 install_lvm2:
 	@echo "Installing $(MAN8) in $(MAN8DIR)"
diff --git a/man/lvm.conf.5.in b/man/lvm.conf.5.in
index 9cc05e8..17caa85 100644
--- a/man/lvm.conf.5.in
+++ b/man/lvm.conf.5.in
@@ -271,7 +271,7 @@ manipulate physical volumes and volume groups created by LVM2 you
 must use \fB--metadataformat lvm1\fP when creating them.
 .IP
 \fBlibrary_dir\fP \(em A directory searched for LVM2's shared libraries
-ahead of the places \fBdlopen\fP (3) searches.
+ahead of the places \fBdlopen\fP (3) searches. Default to #lvm2libdir#.
 .IP
 \fBformat_libraries\fP \(em A list of shared libraries to load that contain
 code to process different formats of metadata. For example, liblvm2formatpool.so

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