]> sourceware.org Git - lvm2.git/commitdiff
Option for auto-fallback to LVM1 tools if running 2.4 without device-mapper.
authorAlasdair Kergon <agk@redhat.com>
Thu, 8 Apr 2004 15:23:23 +0000 (15:23 +0000)
committerAlasdair Kergon <agk@redhat.com>
Thu, 8 Apr 2004 15:23:23 +0000 (15:23 +0000)
configure
configure.in
doc/example.conf
lib/activate/activate.c
lib/activate/activate.h
lib/commands/toolcontext.c
lib/commands/toolcontext.h
lib/config/defaults.h
tools/lvmcmdline.c

index 2ad376a0f41594a21d2682e0da08b46e0d9465e7..cba1df8efbdcd5c931ccf2d990188c938123dff3 100755 (executable)
--- a/configure
+++ b/configure
@@ -309,7 +309,7 @@ ac_includes_default="\
 #endif"
 
 ac_default_prefix=/usr
-ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS AWK CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA LN_S SET_MAKE RANLIB ac_ct_RANLIB CPP EGREP build build_cpu build_vendor build_os host host_cpu host_vendor host_os target target_cpu target_vendor target_os MSGFMT JOBS STATIC_LINK LVM1 OWNER GROUP CLDFLAGS CLDWHOLEARCHIVE CLDNOWHOLEARCHIVE LD_DEPS LD_FLAGS SOFLAG LVM_VERSION DEBUG DEVMAPPER HAVE_LIBDL HAVE_SELINUX CMDLIB LOCALEDIR INTL_PACKAGE INTL LIBOBJS LTLIBOBJS'
+ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS AWK CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA LN_S SET_MAKE RANLIB ac_ct_RANLIB CPP EGREP build build_cpu build_vendor build_os host host_cpu host_vendor host_os target target_cpu target_vendor target_os MSGFMT JOBS STATIC_LINK LVM1 OWNER GROUP CLDFLAGS CLDWHOLEARCHIVE CLDNOWHOLEARCHIVE LD_DEPS LD_FLAGS SOFLAG LVM_VERSION LVM1_FALLBACK DEBUG DEVMAPPER HAVE_LIBDL HAVE_SELINUX CMDLIB LOCALEDIR INTL_PACKAGE INTL LIBOBJS LTLIBOBJS'
 ac_subst_files=''
 
 # Initialize some variables set by options.
@@ -845,6 +845,8 @@ if test -n "$ac_init_help"; then
 Optional Features:
   --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
   --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
+  --enable-lvm1_fallback  Use this to fall back and use LVM1 binaries if
+                          device-mapper is missing from the kernel
   --enable-jobs=NUM       Number of jobs to run simultaneously
   --enable-static_link    Use this to link the tools to their libraries
                           statically.  Default is dynamic linking
@@ -3921,6 +3923,18 @@ else
    GROUP="root"
 fi;
 
+# Check whether --enable-lvm1_fallback or --disable-lvm1_fallback was given.
+if test "${enable_lvm1_fallback+set}" = set; then
+  enableval="$enable_lvm1_fallback"
+  LVM1_FALLBACK=$enableval
+else
+  LVM1_FALLBACK=no
+fi;
+
+if test x$LVM1_FALLBACK = xyes; then
+       CFLAGS="$CFLAGS -DLVM1_FALLBACK"
+fi
+
 
 # Check whether --with-lvm1 or --without-lvm1 was given.
 if test "${with_lvm1+set}" = set; then
@@ -5070,6 +5084,7 @@ fi
 
 
 
+
 
 
                                                                                                                                             ac_config_files="$ac_config_files Makefile make.tmpl include/Makefile lib/Makefile lib/format1/Makefile man/Makefile po/Makefile tools/Makefile tools/version.h test/mm/Makefile test/device/Makefile test/format1/Makefile test/regex/Makefile test/filters/Makefile"
@@ -5762,6 +5777,7 @@ s,@LD_DEPS@,$LD_DEPS,;t t
 s,@LD_FLAGS@,$LD_FLAGS,;t t
 s,@SOFLAG@,$SOFLAG,;t t
 s,@LVM_VERSION@,$LVM_VERSION,;t t
+s,@LVM1_FALLBACK@,$LVM1_FALLBACK,;t t
 s,@DEBUG@,$DEBUG,;t t
 s,@DEVMAPPER@,$DEVMAPPER,;t t
 s,@HAVE_LIBDL@,$HAVE_LIBDL,;t t
index 14a106825076af190bf3902e524f14c5b44e7e85..1897d9b8fc9b0bbbbd21d5d620ee7787b857edcd 100644 (file)
@@ -86,6 +86,14 @@ AC_ARG_WITH(group,
   [ GROUP="$withval" ],
   [ GROUP="root" ])
 
+dnl -- LVM1 tool fallback option
+AC_ARG_ENABLE(lvm1_fallback, [  --enable-lvm1_fallback  Use this to fall back and use LVM1 binaries if
+                          device-mapper is missing from the kernel],  LVM1_FALLBACK=$enableval, LVM1_FALLBACK=no)
+
+if test x$LVM1_FALLBACK = xyes; then
+       CFLAGS="$CFLAGS -DLVM1_FALLBACK"
+fi
+
 dnl -- format1 inclusion type
 AC_ARG_WITH(lvm1,
   [  --with-lvm1=TYPE        LVM1 metadata support: internal/shared/none
@@ -270,6 +278,7 @@ AC_SUBST(LD_FLAGS)
 AC_SUBST(SOFLAG)
 AC_SUBST(LIBS)
 AC_SUBST(LVM_VERSION)
+AC_SUBST(LVM1_FALLBACK)
 AC_SUBST(DEBUG)
 AC_SUBST(DEVMAPPER)
 AC_SUBST(HAVE_LIBDL)
index a0e7ec49637f75d72be0d332168930a429d122ad..057239699cbb74bdc3e7c541bab8c26b6024d8d1 100644 (file)
@@ -175,6 +175,16 @@ global {
     # setting this to 0 should suppress the error messages.
     activation = 1
 
+    # If we can't communicate with device-mapper, should we try running 
+    # the LVM1 tools?
+    # This option only applies to 2.4 kernels and is provided to help you
+    # switch between device-mapper kernels and LVM1 kernels.
+    # The LVM1 tools need to be installed with .lvm1 suffices
+    # e.g. vgscan.lvm1 and they will stop working after you start using
+    # the new lvm2 on-disk metadata format.
+    # The default value is set when the tools are built.
+    # fallback_to_lvm1 = 0
+
     # The default metadata format that commands should use - "lvm1" or "lvm2".
     # The command line override is -M1 or -M2.
     # Defaults to "lvm1" if compiled in, else "lvm2".
index cf32ec016b270c7292425cfd58f12d68cccb2c2b..6ed93a31e82af9c9b65fd0996cc992343bac619a 100644 (file)
@@ -19,6 +19,7 @@
 #include "memlock.h"
 #include "display.h"
 #include "fs.h"
+#include "lvm-file.h"
 #include "lvm-string.h"
 #include "pool.h"
 #include "toolcontext.h"
 
 #define _skip(fmt, args...) log_very_verbose("Skipping: " fmt , ## args)
 
+int lvm1_present(struct cmd_context *cmd)
+{
+       char path[PATH_MAX];
+
+       if (lvm_snprintf(path, sizeof(path), "%s/lvm/global", cmd->proc_dir)
+           < 0) {
+               log_error("LVM1 proc global snprintf failed");
+               return 0;
+       }
+
+       if (path_exists(path))
+               return 1;
+       else
+               return 0;
+}
+
 #ifndef DEVMAPPER_SUPPORT
 void set_activation(int act)
 {
index 590ee0b5d1f650fb37ece3475a96764b5df1d4b6..0f9cd530b1a46b730ed1f351838fefd3d4cfbf62 100644 (file)
@@ -36,6 +36,7 @@ int activation(void);
 
 int driver_version(char *version, size_t size);
 int library_version(char *version, size_t size);
+int lvm1_present(struct cmd_context *cmd);
 
 int target_present(const char *target_name);
 
index 5ce1a034db6ffb7b55fe10ab7a06398b777eb575..c1e6cd82fc5726791b4ad12ad8db7c643ac11bfd 100644 (file)
@@ -462,6 +462,11 @@ static int _set_tag(struct cmd_context *cmd, const char *tag)
                return 0;
        }
 
+       if (!(cmd->kernel_vsn = pool_strdup(cmd->libmem, uts.release))) {
+               log_error("_init_hostname: pool_strdup kernel_vsn failed");
+               return 0;
+       }
+
        return 1;
 }
 
index 4dd7fb3ecfe2ac583402e6c6ada3318128bb3e8d..eebe7c8283ed00af4a5b7d3567a6a41937740bd8 100644 (file)
@@ -58,6 +58,7 @@ struct cmd_context {
 
        struct list formats;    /* Available formats */
        const char *hostname;
+       const char *kernel_vsn;
 
        char *cmd_line;
        struct command *command;
index c47421259413fdc201f4fd7cf97bf994159a4ea8..d1e6d2908e213be2d675b8e5511932d1cda04837 100644 (file)
 
 #define DEFAULT_UMASK 0077
 
+#ifdef LVM1_FALLBACK
+#  define DEFAULT_FALLBACK_TO_LVM1 1
+#else
+#  define DEFAULT_FALLBACK_TO_LVM1 0
+#endif
+
 #ifdef LVM1_SUPPORT
 #  define DEFAULT_FORMAT "lvm1"
 #else
index 9b5a856210a254850bbd9cee5191afdd06880171..7d7fd6aa12e849ef81046cfd67d93d7f960e8558 100644 (file)
@@ -1054,7 +1054,7 @@ static char *_list_args(const char *text, int state)
                        char c;
                        if (!(c = (the_args +
                                   com->valid_args[match_no++])->short_arg))
-                               continue;
+                                   continue;
 
                        sprintf(s, "-%c", c);
                        if (!strncmp(text, s, len))
@@ -1285,6 +1285,42 @@ void lvm2_exit(void *handle)
 
 #endif
 
+/*
+ * Determine whether we should fall back and exec the equivalent LVM1 tool
+ */
+static int _lvm1_fallback(struct cmd_context *cmd)
+{
+       char vsn[80];
+       int dm_present;
+
+       if (!find_config_int(cmd->cft->root, "global/fallback_to_lvm1",
+                            DEFAULT_FALLBACK_TO_LVM1) ||
+           strncmp(cmd->kernel_vsn, "2.4.", 4))
+               return 0;
+
+       log_suppress(1);
+       dm_present = driver_version(vsn, sizeof(vsn));
+       log_suppress(0);
+
+       if (dm_present || !lvm1_present(cmd))
+               return 0;
+
+       return 1;
+}
+
+static void _exec_lvm1_command(struct cmd_context *cmd, int argc, char **argv)
+{
+       char path[PATH_MAX];
+
+       if (lvm_snprintf(path, sizeof(path), "%s.lvm1", argv[0]) < 0) {
+               log_error("Failed to create LVM1 tool pathname");
+               return;
+       }
+
+       execvp(path, argv);
+       log_sys_error("execvp", path);
+}
+
 int lvm2_main(int argc, char **argv)
 {
        char *namebase, *base;
@@ -1305,6 +1341,21 @@ int lvm2_main(int argc, char **argv)
 
        _register_commands();
 
+       if (_lvm1_fallback(cmd)) {
+               /* Attempt to run equivalent LVM1 tool instead */
+               if (!alias) {
+                       argv++;
+                       argc--;
+                       alias = 0;
+               }
+               if (!argc) {
+                       log_error("Falling back to LVM1 tools, but no "
+                                 "command specified.");
+                       return ECMD_FAILED;
+               }
+               _exec_lvm1_command(cmd, argc, argv);
+               return ECMD_FAILED;
+       }
 #ifdef READLINE_SUPPORT
        if (!alias && argc == 1) {
                ret = _shell(cmd);
This page took 0.0524 seconds and 5 git commands to generate.