r351 - in lvm2/trunk: . daemons/clvmd dmeventd/mirror doc include lib/activate lib/cache lib/commands lib/device lib/display lib/error lib/filters lib/format1 lib/format_pool lib/format_text lib/label lib/locking lib/log lib/metadata lib/mirror lib/misc lib/regex lib/report lib/snapshot lib/striped lib/uuid lib/zero man tools

Bastian Blank waldi at costa.debian.org
Sat Jun 10 21:40:11 UTC 2006


Author: waldi
Date: Sat Jun 10 21:40:06 2006
New Revision: 351

Added:
   lvm2/trunk/lib/misc/configure.h.in
Modified:
   lvm2/trunk/   (props changed)
   lvm2/trunk/VERSION
   lvm2/trunk/WHATS_NEW
   lvm2/trunk/configure
   lvm2/trunk/configure.in
   lvm2/trunk/daemons/clvmd/clvmd-command.c
   lvm2/trunk/daemons/clvmd/lvm-functions.c
   lvm2/trunk/daemons/clvmd/tcp-comms.c
   lvm2/trunk/dmeventd/mirror/dmeventd_mirror.c
   lvm2/trunk/doc/example.conf
   lvm2/trunk/include/.symlinks
   lvm2/trunk/lib/activate/activate.c
   lvm2/trunk/lib/activate/activate.h
   lvm2/trunk/lib/activate/dev_manager.c
   lvm2/trunk/lib/activate/dev_manager.h
   lvm2/trunk/lib/activate/targets.h
   lvm2/trunk/lib/cache/lvmcache.c
   lvm2/trunk/lib/cache/lvmcache.h
   lvm2/trunk/lib/commands/toolcontext.c
   lvm2/trunk/lib/config/config.c
   lvm2/trunk/lib/config/defaults.h
   lvm2/trunk/lib/device/dev-io.c
   lvm2/trunk/lib/device/device.c
   lvm2/trunk/lib/device/device.h
   lvm2/trunk/lib/display/display.c
   lvm2/trunk/lib/display/display.h
   lvm2/trunk/lib/error/errseg.c
   lvm2/trunk/lib/filters/filter.c
   lvm2/trunk/lib/format1/disk-rep.c
   lvm2/trunk/lib/format1/disk-rep.h
   lvm2/trunk/lib/format1/format1.c
   lvm2/trunk/lib/format1/import-export.c
   lvm2/trunk/lib/format1/import-extents.c
   lvm2/trunk/lib/format1/lvm1-label.c
   lvm2/trunk/lib/format1/vg_number.c
   lvm2/trunk/lib/format_pool/disk_rep.c
   lvm2/trunk/lib/format_pool/format_pool.c
   lvm2/trunk/lib/format_pool/import_export.c
   lvm2/trunk/lib/format_pool/pool_label.c
   lvm2/trunk/lib/format_text/archive.c
   lvm2/trunk/lib/format_text/export.c
   lvm2/trunk/lib/format_text/flags.c
   lvm2/trunk/lib/format_text/format-text.c
   lvm2/trunk/lib/format_text/format-text.h
   lvm2/trunk/lib/format_text/import.c
   lvm2/trunk/lib/format_text/import_vsn1.c
   lvm2/trunk/lib/format_text/layout.h
   lvm2/trunk/lib/format_text/text_label.c
   lvm2/trunk/lib/label/label.c
   lvm2/trunk/lib/label/label.h
   lvm2/trunk/lib/locking/cluster_locking.c
   lvm2/trunk/lib/locking/file_locking.c
   lvm2/trunk/lib/locking/locking.c
   lvm2/trunk/lib/locking/locking.h
   lvm2/trunk/lib/log/log.c
   lvm2/trunk/lib/log/log.h
   lvm2/trunk/lib/metadata/lv_alloc.h
   lvm2/trunk/lib/metadata/lv_manip.c
   lvm2/trunk/lib/metadata/metadata.c
   lvm2/trunk/lib/metadata/metadata.h
   lvm2/trunk/lib/metadata/mirror.c
   lvm2/trunk/lib/metadata/pv_manip.c
   lvm2/trunk/lib/metadata/segtype.h
   lvm2/trunk/lib/mirror/mirrored.c
   lvm2/trunk/lib/misc/lib.h
   lvm2/trunk/lib/misc/lvm-exec.h
   lvm2/trunk/lib/misc/lvm-file.c
   lvm2/trunk/lib/misc/lvm-file.h
   lvm2/trunk/lib/misc/lvm-string.c
   lvm2/trunk/lib/misc/sharedlib.c
   lvm2/trunk/lib/misc/sharedlib.h
   lvm2/trunk/lib/regex/matcher.c
   lvm2/trunk/lib/report/report.c
   lvm2/trunk/lib/snapshot/snapshot.c
   lvm2/trunk/lib/striped/striped.c
   lvm2/trunk/lib/uuid/uuid.c
   lvm2/trunk/lib/uuid/uuid.h
   lvm2/trunk/lib/zero/zero.c
   lvm2/trunk/make.tmpl.in
   lvm2/trunk/man/lvcreate.8
   lvm2/trunk/man/lvs.8
   lvm2/trunk/tools/Makefile.in
   lvm2/trunk/tools/args.h
   lvm2/trunk/tools/commands.h
   lvm2/trunk/tools/formats.c
   lvm2/trunk/tools/lvchange.c
   lvm2/trunk/tools/lvconvert.c
   lvm2/trunk/tools/lvcreate.c
   lvm2/trunk/tools/lvmchange.c
   lvm2/trunk/tools/lvmcmdline.c
   lvm2/trunk/tools/lvmdiskscan.c
   lvm2/trunk/tools/lvremove.c
   lvm2/trunk/tools/lvresize.c
   lvm2/trunk/tools/lvscan.c
   lvm2/trunk/tools/polldaemon.c
   lvm2/trunk/tools/pvchange.c
   lvm2/trunk/tools/pvcreate.c
   lvm2/trunk/tools/pvdisplay.c
   lvm2/trunk/tools/pvmove.c
   lvm2/trunk/tools/pvremove.c
   lvm2/trunk/tools/pvscan.c
   lvm2/trunk/tools/reporter.c
   lvm2/trunk/tools/segtypes.c
   lvm2/trunk/tools/stub.h
   lvm2/trunk/tools/toollib.c
   lvm2/trunk/tools/toollib.h
   lvm2/trunk/tools/tools.h
   lvm2/trunk/tools/version.h.in
   lvm2/trunk/tools/vgcfgbackup.c
   lvm2/trunk/tools/vgchange.c
   lvm2/trunk/tools/vgck.c
   lvm2/trunk/tools/vgconvert.c
   lvm2/trunk/tools/vgcreate.c
   lvm2/trunk/tools/vgdisplay.c
   lvm2/trunk/tools/vgexport.c
   lvm2/trunk/tools/vgimport.c
   lvm2/trunk/tools/vgmerge.c
   lvm2/trunk/tools/vgmknodes.c
   lvm2/trunk/tools/vgreduce.c
   lvm2/trunk/tools/vgremove.c
   lvm2/trunk/tools/vgrename.c
   lvm2/trunk/tools/vgscan.c
   lvm2/trunk/tools/vgsplit.c

Log:
Merge /lvm2/upstream/current (2.02.06).


Modified: lvm2/trunk/VERSION
==============================================================================
--- lvm2/trunk/VERSION	(original)
+++ lvm2/trunk/VERSION	Sat Jun 10 21:40:06 2006
@@ -1 +1 @@
-2.02.05 (2006-04-21)
+2.02.06 (2006-05-12)

Modified: lvm2/trunk/WHATS_NEW
==============================================================================
--- lvm2/trunk/WHATS_NEW	(original)
+++ lvm2/trunk/WHATS_NEW	Sat Jun 10 21:40:06 2006
@@ -1,3 +1,33 @@
+Version 2.02.06 - 12th May 2006
+===============================
+  Propagate --monitor around cluster.
+  Add --monitor to vgcreate and lvcreate to control dmeventd registration.
+  Filter LCK_NONBLOCK in clvmd lock_vg.
+  Add --nosync to lvcreate with LV flag NOTSYNCED.
+  Use mirror's uuid for a core log.
+  Add mirror log fault-handling policy.
+  Improve mirror warning messages and tidy dmeventd syslog output.
+  Propagate nosync flag around cluster.
+  Allow vgreduce to handle mirror log failures.
+  Add --corelog to lvcreate and lvconvert.
+  Create a log header for replacement in-sync mirror log.
+  Use set_lv() and dev_set() to wipe sections of devices.
+  Add mirror_in_sync() flag to avoid unnecessary resync on activation.
+  Add mirror_library description to example.conf.
+  Fix uuid_from_num() buffer overrun.
+  Make SIZE_SHORT the default for display_size().
+  Fix some memory leaks in error paths found by coverity.
+  Use C99 struct initialisers.
+  Move DEFS into configure.h.
+  Clean-ups to remove miscellaneous compiler warnings.
+  Improve stripe size validation.
+  Increase maximum stripe size limit to physical extent size for lvm2 metadata.
+  Fix activation code to check for pre-existing mirror logs.
+  Tighten region size validation.
+  Ignore empty strings in config files.
+  Require non-zero regionsize and document parameter on lvcreate man page.
+  Invalidate cache if composition of VG changed externally.
+
 Version 2.02.05 - 21st April 2006
 =================================
   Fix vgid string termination in recent cache code.

Modified: lvm2/trunk/configure
==============================================================================
--- lvm2/trunk/configure	(original)
+++ lvm2/trunk/configure	Sat Jun 10 21:40:06 2006
@@ -310,7 +310,7 @@
 #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 build build_cpu build_vendor build_os host host_cpu host_vendor host_os target target_cpu target_vendor target_os AWK CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA LN_S SET_MAKE RANLIB ac_ct_RANLIB CFLOW_CMD CSCOPE_CMD CPP EGREP ALLOCA LIBOBJS POW_LIB MSGFMT MODPROBE_CMD JOBS STATIC_LINK LVM1 POOL SNAPSHOTS MIRRORS OWNER GROUP LVM_DEFS COPTIMISE_FLAG CLDFLAGS CLDWHOLEARCHIVE CLDNOWHOLEARCHIVE LDDEPS LIB_SUFFIX LVM_VERSION LVM1_FALLBACK DEBUG DEVMAPPER HAVE_LIBDL HAVE_SELINUX CMDLIB LOCALEDIR CONFDIR STATICDIR INTL_PACKAGE INTL CLVMD CLUSTER FSADM DMEVENTD 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 build build_cpu build_vendor build_os host host_cpu host_vendor host_os target target_cpu target_vendor target_os AWK CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA LN_S SET_MAKE RANLIB ac_ct_RANLIB CFLOW_CMD CSCOPE_CMD CPP EGREP ALLOCA LIBOBJS POW_LIB MSGFMT MODPROBE_CMD JOBS STATIC_LINK LVM1 POOL SNAPSHOTS MIRRORS OWNER GROUP COPTIMISE_FLAG CLDFLAGS CLDWHOLEARCHIVE CLDNOWHOLEARCHIVE LDDEPS LIB_SUFFIX LVM_VERSION LVM1_FALLBACK DEBUG DEVMAPPER HAVE_LIBDL HAVE_SELINUX CMDLIB LOCALEDIR CONFDIR STATICDIR INTL_PACKAGE INTL CLVMD CLUSTER FSADM DMEVENTD LTLIBOBJS'
 ac_subst_files=''
 
 # Initialize some variables set by options.
@@ -1332,6 +1332,10 @@
 
 
 ################################################################################
+          ac_config_headers="$ac_config_headers lib/misc/configure.h"
+
+
+################################################################################
 ac_aux_dir=
 for ac_dir in autoconf $srcdir/autoconf; do
   if test -f $ac_dir/install-sh; then
@@ -7227,7 +7231,11 @@
 echo "${ECHO_T}$LVM1_FALLBACK" >&6
 
 if test x$LVM1_FALLBACK = xyes; then
-	LVM_DEFS="$LVM_DEFS -DLVM1_FALLBACK"
+
+cat >>confdefs.h <<\_ACEOF
+#define LVM1_FALLBACK 1
+_ACEOF
+
 fi
 
 ################################################################################
@@ -7253,7 +7261,11 @@
 fi;
 
 if test x$LVM1 = xinternal; then
-	LVM_DEFS="$LVM_DEFS -DLVM1_INTERNAL"
+
+cat >>confdefs.h <<\_ACEOF
+#define LVM1_INTERNAL 1
+_ACEOF
+
 fi
 
 ################################################################################
@@ -7279,7 +7291,11 @@
 fi;
 
 if test x$POOL = xinternal; then
-	LVM_DEFS="$LVM_DEFS -DPOOL_INTERNAL"
+
+cat >>confdefs.h <<\_ACEOF
+#define POOL_INTERNAL 1
+_ACEOF
+
 fi
 
 ################################################################################
@@ -7303,7 +7319,11 @@
 fi;
 
 if test x$CLUSTER = xinternal; then
-	LVM_DEFS="$LVM_DEFS -DCLUSTER_LOCKING_INTERNAL"
+
+cat >>confdefs.h <<\_ACEOF
+#define CLUSTER_LOCKING_INTERNAL 1
+_ACEOF
+
 fi
 
 ################################################################################
@@ -7329,7 +7349,11 @@
 fi;
 
 if test x$SNAPSHOTS = xinternal; then
-	LVM_DEFS="$LVM_DEFS -DSNAPSHOT_INTERNAL"
+
+cat >>confdefs.h <<\_ACEOF
+#define SNAPSHOT_INTERNAL 1
+_ACEOF
+
 fi
 
 ################################################################################
@@ -7355,7 +7379,11 @@
 fi;
 
 if test x$MIRRORS = xinternal; then
-	LVM_DEFS="$LVM_DEFS -DMIRRORED_INTERNAL"
+
+cat >>confdefs.h <<\_ACEOF
+#define MIRRORED_INTERNAL 1
+_ACEOF
+
 fi
 
 ################################################################################
@@ -7385,7 +7413,11 @@
 echo "${ECHO_T}$READLINE" >&6
 
 if test x$READLINE = xyes; then
-	LVM_DEFS="$LVM_DEFS -DREADLINE_SUPPORT"
+
+cat >>confdefs.h <<\_ACEOF
+#define READLINE_SUPPORT 1
+_ACEOF
+
 fi
 
 ################################################################################
@@ -7463,7 +7495,11 @@
 echo "${ECHO_T}$DEVMAPPER" >&6
 
 if test x$DEVMAPPER = xyes; then
-	LVM_DEFS="$LVM_DEFS -DDEVMAPPER_SUPPORT"
+
+cat >>confdefs.h <<\_ACEOF
+#define DEVMAPPER_SUPPORT 1
+_ACEOF
+
 fi
 
 ################################################################################
@@ -7478,7 +7514,11 @@
 echo "${ECHO_T}$ODIRECT" >&6
 
 if test x$ODIRECT = xyes; then
-	LVM_DEFS="$LVM_DEFS -DO_DIRECT_SUPPORT"
+
+cat >>confdefs.h <<\_ACEOF
+#define O_DIRECT_SUPPORT 1
+_ACEOF
+
 fi
 
 ################################################################################
@@ -7495,7 +7535,11 @@
 echo "${ECHO_T}$CMDLIB" >&6
 
 if test x$CMDLIB = xyes; then
-	LVM_DEFS="$LVM_DEFS -DCMDLIB"
+
+cat >>confdefs.h <<\_ACEOF
+#define CMDLIB 1
+_ACEOF
+
 fi
 
 ################################################################################
@@ -7529,7 +7573,11 @@
 fi
 
 if test x$DMEVENTD = xyes; then
-	LVM_DEFS="$LVM_DEFS -DDMEVENTD"
+
+cat >>confdefs.h <<\_ACEOF
+#define DMEVENTD 1
+_ACEOF
+
 fi
 ################################################################################
 if [ "x$exec_prefix" = xNONE -a "x$prefix" = xNONE ];
@@ -8190,7 +8238,11 @@
 
 
 if [ "x$HAVE_LIBDL" = xyes ]; then
-	LVM_DEFS="$LVM_DEFS -DHAVE_LIBDL"
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_LIBDL 1
+_ACEOF
+
 	LIBS="-ldl $LIBS"
 else
 	HAVE_LIBDL=no
@@ -8364,7 +8416,11 @@
 echo "${ECHO_T}$HAVE_SELINUX" >&6
 
 	if test x$HAVE_SELINUX = xyes; then
-		LVM_DEFS="$LVM_DEFS -DHAVE_SELINUX"
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_SELINUX 1
+_ACEOF
+
 		LIBS="-lselinux $LIBS"
 	else
 		{ echo "$as_me:$LINENO: WARNING: Disabling selinux" >&5
@@ -8518,7 +8574,11 @@
   cat >>confdefs.h <<_ACEOF
 #define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
 _ACEOF
- LVM_DEFS="$LVM_DEFS -DHAVE_GETOPTLONG"
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_GETOPTLONG 1
+_ACEOF
+
 fi
 
 done
@@ -8708,9 +8768,12 @@
 echo "$as_me:$LINENO: result: $ac_cv_func_rl_completion_matches" >&5
 echo "${ECHO_T}$ac_cv_func_rl_completion_matches" >&6
 if test $ac_cv_func_rl_completion_matches = yes; then
-  LVM_DEFS="$LVM_DEFS -DHAVE_RL_COMPLETION_MATCHES"
-fi
 
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_RL_COMPLETION_MATCHES 1
+_ACEOF
+
+fi
 
 fi
 
@@ -10990,9 +11053,52 @@
 echo "${ECHO_T}no" >&6
 fi
 
+# Extract the first word of "ifconfig", so it can be a program name with args.
+set dummy ifconfig; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_path_MODPROBE_CMD+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  case $MODPROBE_CMD in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_MODPROBE_CMD="$MODPROBE_CMD" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_MODPROBE_CMD="$as_dir/$ac_word$ac_exec_ext"
+    echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+done
+
+  ;;
+esac
+fi
+MODPROBE_CMD=$ac_cv_path_MODPROBE_CMD
+
+if test -n "$MODPROBE_CMD"; then
+  echo "$as_me:$LINENO: result: $MODPROBE_CMD" >&5
+echo "${ECHO_T}$MODPROBE_CMD" >&6
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
 
 if test x$MODPROBE_CMD != x; then
-	LVM_DEFS="$LVM_DEFS -DMODPROBE_CMD=\\\"$MODPROBE_CMD\\\""
+
+cat >>confdefs.h <<_ACEOF
+#define MODPROBE_CMD "$MODPROBE_CMD"
+_ACEOF
+
 fi
 
 ################################################################################
@@ -11040,7 +11146,6 @@
 
 
 
-
 ################################################################################
                                                                                                                                                                                                                                                 ac_config_files="$ac_config_files Makefile make.tmpl daemons/Makefile daemons/clvmd/Makefile dmeventd/Makefile dmeventd/mirror/Makefile doc/Makefile include/Makefile lib/Makefile lib/format1/Makefile lib/format_pool/Makefile lib/locking/Makefile lib/mirror/Makefile lib/snapshot/Makefile man/Makefile po/Makefile tools/Makefile tools/version.h tools/fsadm/Makefile test/mm/Makefile test/device/Makefile test/format1/Makefile test/regex/Makefile test/filters/Makefile"
 cat >confcache <<\_ACEOF
@@ -11117,38 +11222,7 @@
 }'
 fi
 
-# Transform confdefs.h into DEFS.
-# Protect against shell expansion while executing Makefile rules.
-# Protect against Makefile macro expansion.
-#
-# If the first sed substitution is executed (which looks for macros that
-# take arguments), then we branch to the quote section.  Otherwise,
-# look for a macro that doesn't take arguments.
-cat >confdef2opt.sed <<\_ACEOF
-t clear
-: clear
-s,^[	 ]*#[	 ]*define[	 ][	 ]*\([^	 (][^	 (]*([^)]*)\)[	 ]*\(.*\),-D\1=\2,g
-t quote
-s,^[	 ]*#[	 ]*define[	 ][	 ]*\([^	 ][^	 ]*\)[	 ]*\(.*\),-D\1=\2,g
-t quote
-d
-: quote
-s,[	 `~#$^&*(){}\\|;'"<>?],\\&,g
-s,\[,\\&,g
-s,\],\\&,g
-s,\$,$$,g
-p
-_ACEOF
-# We use echo to avoid assuming a particular line-breaking character.
-# The extra dot is to prevent the shell from consuming trailing
-# line-breaks from the sub-command output.  A line-break within
-# single-quotes doesn't work because, if this script is created in a
-# platform that uses two characters for line-breaks (e.g., DOS), tr
-# would break.
-ac_LF_and_DOT=`echo; echo .`
-DEFS=`sed -n -f confdef2opt.sed confdefs.h | tr "$ac_LF_and_DOT" ' .'`
-rm -f confdef2opt.sed
-
+DEFS=-DHAVE_CONFIG_H
 
 ac_libobjs=
 ac_ltlibobjs=
@@ -11482,10 +11556,15 @@
       --recheck    update $as_me by reconfiguring in the same conditions
   --file=FILE[:TEMPLATE]
 		   instantiate the configuration file FILE
+  --header=FILE[:TEMPLATE]
+		   instantiate the configuration header FILE
 
 Configuration files:
 $config_files
 
+Configuration headers:
+$config_headers
+
 Report bugs to <bug-autoconf at gnu.org>."
 _ACEOF
 
@@ -11618,6 +11697,7 @@
   "test/format1/Makefile" ) CONFIG_FILES="$CONFIG_FILES test/format1/Makefile" ;;
   "test/regex/Makefile" ) CONFIG_FILES="$CONFIG_FILES test/regex/Makefile" ;;
   "test/filters/Makefile" ) CONFIG_FILES="$CONFIG_FILES test/filters/Makefile" ;;
+  "lib/misc/configure.h" ) CONFIG_HEADERS="$CONFIG_HEADERS lib/misc/configure.h" ;;
   *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5
 echo "$as_me: error: invalid argument: $ac_config_target" >&2;}
    { (exit 1); exit 1; }; };;
@@ -11630,6 +11710,7 @@
 # bizarre bug on SunOS 4.1.3.
 if $ac_need_defaults; then
   test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files
+  test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers
 fi
 
 # Have a temporary directory for convenience.  Make it in the build tree
@@ -11745,7 +11826,6 @@
 s, at MIRRORS@,$MIRRORS,;t t
 s, at OWNER@,$OWNER,;t t
 s, at GROUP@,$GROUP,;t t
-s, at LVM_DEFS@,$LVM_DEFS,;t t
 s, at COPTIMISE_FLAG@,$COPTIMISE_FLAG,;t t
 s, at CLDFLAGS@,$CLDFLAGS,;t t
 s, at CLDWHOLEARCHIVE@,$CLDWHOLEARCHIVE,;t t
@@ -12007,6 +12087,229 @@
 
 done
 _ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF
+
+#
+# CONFIG_HEADER section.
+#
+
+# These sed commands are passed to sed as "A NAME B NAME C VALUE D", where
+# NAME is the cpp macro being defined and VALUE is the value it is being given.
+#
+# ac_d sets the value in "#define NAME VALUE" lines.
+ac_dA='s,^\([	 ]*\)#\([	 ]*define[	 ][	 ]*\)'
+ac_dB='[	 ].*$,\1#\2'
+ac_dC=' '
+ac_dD=',;t'
+# ac_u turns "#undef NAME" without trailing blanks into "#define NAME VALUE".
+ac_uA='s,^\([	 ]*\)#\([	 ]*\)undef\([	 ][	 ]*\)'
+ac_uB='$,\1#\2define\3'
+ac_uC=' '
+ac_uD=',;t'
+
+for ac_file in : $CONFIG_HEADERS; do test "x$ac_file" = x: && continue
+  # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in".
+  case $ac_file in
+  - | *:- | *:-:* ) # input from stdin
+	cat >$tmp/stdin
+	ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'`
+	ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;;
+  *:* ) ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'`
+	ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;;
+  * )   ac_file_in=$ac_file.in ;;
+  esac
+
+  test x"$ac_file" != x- && { echo "$as_me:$LINENO: creating $ac_file" >&5
+echo "$as_me: creating $ac_file" >&6;}
+
+  # First look for the input files in the build tree, otherwise in the
+  # src tree.
+  ac_file_inputs=`IFS=:
+    for f in $ac_file_in; do
+      case $f in
+      -) echo $tmp/stdin ;;
+      [\\/$]*)
+	 # Absolute (can't be DOS-style, as IFS=:)
+	 test -f "$f" || { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5
+echo "$as_me: error: cannot find input file: $f" >&2;}
+   { (exit 1); exit 1; }; }
+	 # Do quote $f, to prevent DOS paths from being IFS'd.
+	 echo "$f";;
+      *) # Relative
+	 if test -f "$f"; then
+	   # Build tree
+	   echo "$f"
+	 elif test -f "$srcdir/$f"; then
+	   # Source tree
+	   echo "$srcdir/$f"
+	 else
+	   # /dev/null tree
+	   { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5
+echo "$as_me: error: cannot find input file: $f" >&2;}
+   { (exit 1); exit 1; }; }
+	 fi;;
+      esac
+    done` || { (exit 1); exit 1; }
+  # Remove the trailing spaces.
+  sed 's/[	 ]*$//' $ac_file_inputs >$tmp/in
+
+_ACEOF
+
+# Transform confdefs.h into two sed scripts, `conftest.defines' and
+# `conftest.undefs', that substitutes the proper values into
+# config.h.in to produce config.h.  The first handles `#define'
+# templates, and the second `#undef' templates.
+# And first: Protect against being on the right side of a sed subst in
+# config.status.  Protect against being in an unquoted here document
+# in config.status.
+rm -f conftest.defines conftest.undefs
+# Using a here document instead of a string reduces the quoting nightmare.
+# Putting comments in sed scripts is not portable.
+#
+# `end' is used to avoid that the second main sed command (meant for
+# 0-ary CPP macros) applies to n-ary macro definitions.
+# See the Autoconf documentation for `clear'.
+cat >confdef2sed.sed <<\_ACEOF
+s/[\\&,]/\\&/g
+s,[\\$`],\\&,g
+t clear
+: clear
+s,^[	 ]*#[	 ]*define[	 ][	 ]*\([^	 (][^	 (]*\)\(([^)]*)\)[	 ]*\(.*\)$,${ac_dA}\1${ac_dB}\1\2${ac_dC}\3${ac_dD},gp
+t end
+s,^[	 ]*#[	 ]*define[	 ][	 ]*\([^	 ][^	 ]*\)[	 ]*\(.*\)$,${ac_dA}\1${ac_dB}\1${ac_dC}\2${ac_dD},gp
+: end
+_ACEOF
+# If some macros were called several times there might be several times
+# the same #defines, which is useless.  Nevertheless, we may not want to
+# sort them, since we want the *last* AC-DEFINE to be honored.
+uniq confdefs.h | sed -n -f confdef2sed.sed >conftest.defines
+sed 's/ac_d/ac_u/g' conftest.defines >conftest.undefs
+rm -f confdef2sed.sed
+
+# This sed command replaces #undef with comments.  This is necessary, for
+# example, in the case of _POSIX_SOURCE, which is predefined and required
+# on some systems where configure will not decide to define it.
+cat >>conftest.undefs <<\_ACEOF
+s,^[	 ]*#[	 ]*undef[	 ][	 ]*[a-zA-Z_][a-zA-Z_0-9]*,/* & */,
+_ACEOF
+
+# Break up conftest.defines because some shells have a limit on the size
+# of here documents, and old seds have small limits too (100 cmds).
+echo '  # Handle all the #define templates only if necessary.' >>$CONFIG_STATUS
+echo '  if grep "^[	 ]*#[	 ]*define" $tmp/in >/dev/null; then' >>$CONFIG_STATUS
+echo '  # If there are no defines, we may have an empty if/fi' >>$CONFIG_STATUS
+echo '  :' >>$CONFIG_STATUS
+rm -f conftest.tail
+while grep . conftest.defines >/dev/null
+do
+  # Write a limited-size here document to $tmp/defines.sed.
+  echo '  cat >$tmp/defines.sed <<CEOF' >>$CONFIG_STATUS
+  # Speed up: don't consider the non `#define' lines.
+  echo '/^[	 ]*#[	 ]*define/!b' >>$CONFIG_STATUS
+  # Work around the forget-to-reset-the-flag bug.
+  echo 't clr' >>$CONFIG_STATUS
+  echo ': clr' >>$CONFIG_STATUS
+  sed ${ac_max_here_lines}q conftest.defines >>$CONFIG_STATUS
+  echo 'CEOF
+  sed -f $tmp/defines.sed $tmp/in >$tmp/out
+  rm -f $tmp/in
+  mv $tmp/out $tmp/in
+' >>$CONFIG_STATUS
+  sed 1,${ac_max_here_lines}d conftest.defines >conftest.tail
+  rm -f conftest.defines
+  mv conftest.tail conftest.defines
+done
+rm -f conftest.defines
+echo '  fi # grep' >>$CONFIG_STATUS
+echo >>$CONFIG_STATUS
+
+# Break up conftest.undefs because some shells have a limit on the size
+# of here documents, and old seds have small limits too (100 cmds).
+echo '  # Handle all the #undef templates' >>$CONFIG_STATUS
+rm -f conftest.tail
+while grep . conftest.undefs >/dev/null
+do
+  # Write a limited-size here document to $tmp/undefs.sed.
+  echo '  cat >$tmp/undefs.sed <<CEOF' >>$CONFIG_STATUS
+  # Speed up: don't consider the non `#undef'
+  echo '/^[	 ]*#[	 ]*undef/!b' >>$CONFIG_STATUS
+  # Work around the forget-to-reset-the-flag bug.
+  echo 't clr' >>$CONFIG_STATUS
+  echo ': clr' >>$CONFIG_STATUS
+  sed ${ac_max_here_lines}q conftest.undefs >>$CONFIG_STATUS
+  echo 'CEOF
+  sed -f $tmp/undefs.sed $tmp/in >$tmp/out
+  rm -f $tmp/in
+  mv $tmp/out $tmp/in
+' >>$CONFIG_STATUS
+  sed 1,${ac_max_here_lines}d conftest.undefs >conftest.tail
+  rm -f conftest.undefs
+  mv conftest.tail conftest.undefs
+done
+rm -f conftest.undefs
+
+cat >>$CONFIG_STATUS <<\_ACEOF
+  # Let's still pretend it is `configure' which instantiates (i.e., don't
+  # use $as_me), people would be surprised to read:
+  #    /* config.h.  Generated by config.status.  */
+  if test x"$ac_file" = x-; then
+    echo "/* Generated by configure.  */" >$tmp/config.h
+  else
+    echo "/* $ac_file.  Generated by configure.  */" >$tmp/config.h
+  fi
+  cat $tmp/in >>$tmp/config.h
+  rm -f $tmp/in
+  if test x"$ac_file" != x-; then
+    if diff $ac_file $tmp/config.h >/dev/null 2>&1; then
+      { echo "$as_me:$LINENO: $ac_file is unchanged" >&5
+echo "$as_me: $ac_file is unchanged" >&6;}
+    else
+      ac_dir=`(dirname "$ac_file") 2>/dev/null ||
+$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$ac_file" : 'X\(//\)[^/]' \| \
+	 X"$ac_file" : 'X\(//\)$' \| \
+	 X"$ac_file" : 'X\(/\)' \| \
+	 .     : '\(.\)' 2>/dev/null ||
+echo X"$ac_file" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
+  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
+  	  /^X\(\/\/\)$/{ s//\1/; q; }
+  	  /^X\(\/\).*/{ s//\1/; q; }
+  	  s/.*/./; q'`
+      { if $as_mkdir_p; then
+    mkdir -p "$ac_dir"
+  else
+    as_dir="$ac_dir"
+    as_dirs=
+    while test ! -d "$as_dir"; do
+      as_dirs="$as_dir $as_dirs"
+      as_dir=`(dirname "$as_dir") 2>/dev/null ||
+$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$as_dir" : 'X\(//\)[^/]' \| \
+	 X"$as_dir" : 'X\(//\)$' \| \
+	 X"$as_dir" : 'X\(/\)' \| \
+	 .     : '\(.\)' 2>/dev/null ||
+echo X"$as_dir" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
+  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
+  	  /^X\(\/\/\)$/{ s//\1/; q; }
+  	  /^X\(\/\).*/{ s//\1/; q; }
+  	  s/.*/./; q'`
+    done
+    test ! -n "$as_dirs" || mkdir $as_dirs
+  fi || { { echo "$as_me:$LINENO: error: cannot create directory \"$ac_dir\"" >&5
+echo "$as_me: error: cannot create directory \"$ac_dir\"" >&2;}
+   { (exit 1); exit 1; }; }; }
+
+      rm -f $ac_file
+      mv $tmp/config.h $ac_file
+    fi
+  else
+    cat $tmp/config.h
+    rm -f $tmp/config.h
+  fi
+done
+_ACEOF
 
 cat >>$CONFIG_STATUS <<\_ACEOF
 

Modified: lvm2/trunk/configure.in
==============================================================================
--- lvm2/trunk/configure.in	(original)
+++ lvm2/trunk/configure.in	Sat Jun 10 21:40:06 2006
@@ -19,6 +19,9 @@
 AC_INIT(lib/device/dev-cache.h)
 
 ################################################################################
+AC_CONFIG_HEADERS(lib/misc/configure.h)
+
+################################################################################
 dnl -- Setup the directory where autoconf has auxilary files
 AC_CONFIG_AUX_DIR(autoconf) 
 
@@ -152,7 +155,7 @@
 AC_MSG_RESULT($LVM1_FALLBACK)
 
 if test x$LVM1_FALLBACK = xyes; then
-	LVM_DEFS="$LVM_DEFS -DLVM1_FALLBACK"
+	AC_DEFINE([LVM1_FALLBACK], 1, [Define to 1 if 'lvm' should fall back to using LVM1 binaries if device-mapper is missing from the kernel])
 fi
 
 ################################################################################
@@ -172,7 +175,7 @@
 fi;
 
 if test x$LVM1 = xinternal; then
-	LVM_DEFS="$LVM_DEFS -DLVM1_INTERNAL"
+	AC_DEFINE([LVM1_INTERNAL], 1, [Define to 1 to include built-in support for LVM1 metadata.])
 fi
 
 ################################################################################
@@ -192,7 +195,7 @@
 fi;
 
 if test x$POOL = xinternal; then
-	LVM_DEFS="$LVM_DEFS -DPOOL_INTERNAL"
+	AC_DEFINE([POOL_INTERNAL], 1, [Define to 1 to include built-in support for GFS pool metadata.])
 fi
 
 ################################################################################
@@ -211,7 +214,7 @@
 fi;
 
 if test x$CLUSTER = xinternal; then
-	LVM_DEFS="$LVM_DEFS -DCLUSTER_LOCKING_INTERNAL"
+	AC_DEFINE([CLUSTER_LOCKING_INTERNAL], 1, [Define to 1 to include built-in support for clustered LVM locking.])
 fi
 
 ################################################################################
@@ -231,7 +234,7 @@
 fi;
 
 if test x$SNAPSHOTS = xinternal; then
-	LVM_DEFS="$LVM_DEFS -DSNAPSHOT_INTERNAL"
+	AC_DEFINE([SNAPSHOT_INTERNAL], 1, [Define to 1 to include built-in support for snapshots.])
 fi
 
 ################################################################################
@@ -251,7 +254,7 @@
 fi;
 
 if test x$MIRRORS = xinternal; then
-	LVM_DEFS="$LVM_DEFS -DMIRRORED_INTERNAL"
+	AC_DEFINE([MIRRORED_INTERNAL], 1, [Define to 1 to include built-in support for mirrors.])
 fi
 
 ################################################################################
@@ -269,7 +272,7 @@
 AC_MSG_RESULT($READLINE)
 
 if test x$READLINE = xyes; then
-	LVM_DEFS="$LVM_DEFS -DREADLINE_SUPPORT"
+	AC_DEFINE([READLINE_SUPPORT], 1, [Define to 1 to include the LVM readline shell.])
 fi
 
 ################################################################################
@@ -327,7 +330,7 @@
 AC_MSG_RESULT($DEVMAPPER)
 
 if test x$DEVMAPPER = xyes; then
-	LVM_DEFS="$LVM_DEFS -DDEVMAPPER_SUPPORT"
+	AC_DEFINE([DEVMAPPER_SUPPORT], 1, [Define to 1 to enable device-mapper interaction.])
 fi
 
 ################################################################################
@@ -338,7 +341,7 @@
 AC_MSG_RESULT($ODIRECT)
 
 if test x$ODIRECT = xyes; then
-	LVM_DEFS="$LVM_DEFS -DO_DIRECT_SUPPORT"
+	AC_DEFINE([O_DIRECT_SUPPORT], 1, [Define to 1 to enable O_DIRECT support.])
 fi
 
 ################################################################################
@@ -349,7 +352,7 @@
 AC_MSG_RESULT($CMDLIB)
 
 if test x$CMDLIB = xyes; then
-	LVM_DEFS="$LVM_DEFS -DCMDLIB"
+	AC_DEFINE([CMDLIB], 1, [Define to 1 to build the shared command library.])
 fi
 
 ################################################################################
@@ -374,7 +377,7 @@
 fi
 
 if test x$DMEVENTD = xyes; then
-	LVM_DEFS="$LVM_DEFS -DDMEVENTD"
+	AC_DEFINE([DMEVENTD], 1, [Define to 1 to enable the device-mapper event daemon.])
 fi
 ################################################################################
 dnl -- Mess with default exec_prefix
@@ -411,7 +414,7 @@
 AC_CHECK_LIB(dl, dlopen, HAVE_LIBDL=yes, HAVE_LIBDL=no)
 
 if [[ "x$HAVE_LIBDL" = xyes ]]; then
-	LVM_DEFS="$LVM_DEFS -DHAVE_LIBDL"
+	AC_DEFINE([HAVE_LIBDL], 1, [Define to 1 if dynamic libraries are available.])
 	LIBS="-ldl $LIBS"
 else
 	HAVE_LIBDL=no
@@ -443,7 +446,7 @@
 	AC_MSG_RESULT($HAVE_SELINUX)
 
 	if test x$HAVE_SELINUX = xyes; then
-		LVM_DEFS="$LVM_DEFS -DHAVE_SELINUX"
+		AC_DEFINE([HAVE_SELINUX], 1, [Define to 1 to include support for selinux.])
 		LIBS="-lselinux $LIBS"
 	else
 		AC_MSG_WARN(Disabling selinux)
@@ -452,7 +455,7 @@
 
 ################################################################################
 dnl -- Check for getopt
-AC_CHECK_HEADERS(getopt.h, LVM_DEFS="$LVM_DEFS -DHAVE_GETOPTLONG")
+AC_CHECK_HEADERS(getopt.h, AC_DEFINE([HAVE_GETOPTLONG], 1, [Define to 1 to if getopt_long is available.]))
 
 ################################################################################
 dnl -- Check for readline (Shamelessly copied from parted 1.4.17)
@@ -467,8 +470,7 @@
 package as well (which may be called readline-devel or something similar).
 )
 	)
-	AC_CHECK_FUNC(rl_completion_matches, LVM_DEFS="$LVM_DEFS -DHAVE_RL_COMPLETION_MATCHES")
-		
+	AC_CHECK_FUNC(rl_completion_matches, AC_DEFINE([HAVE_RL_COMPLETION_MATCHES], 1, [Define to 1 if rl_completion_matches() is available.]))
 fi
 
 ################################################################################
@@ -548,7 +550,7 @@
 AC_PATH_PROG(MODPROBE_CMD, modprobe)
 
 if test x$MODPROBE_CMD != x; then
-	LVM_DEFS="$LVM_DEFS -DMODPROBE_CMD=\\\"$MODPROBE_CMD\\\""
+	AC_DEFINE_UNQUOTED([MODPROBE_CMD], ["$MODPROBE_CMD"], [The path to 'modprobe', if available.])
 fi
 
 ################################################################################
@@ -568,7 +570,6 @@
 AC_SUBST(OWNER)
 AC_SUBST(GROUP)
 AC_SUBST(CFLAGS)
-AC_SUBST(LVM_DEFS)
 AC_SUBST(COPTIMISE_FLAG)
 AC_SUBST(CLDFLAGS)
 AC_SUBST(CLDWHOLEARCHIVE)

Modified: lvm2/trunk/daemons/clvmd/clvmd-command.c
==============================================================================
--- lvm2/trunk/daemons/clvmd/clvmd-command.c	(original)
+++ lvm2/trunk/daemons/clvmd/clvmd-command.c	Sat Jun 10 21:40:06 2006
@@ -180,7 +180,7 @@
     }
     else {
 
-	status = sync_lock(lockname, (int)lock_cmd, (int)lock_flags, &lkid);
+	status = sync_lock(lockname, (int)lock_cmd, (lock_flags & LCK_NONBLOCK) ? LKF_NOQUEUE : 0, &lkid);
 	if (status)
 	    status = errno;
 	else

Modified: lvm2/trunk/daemons/clvmd/lvm-functions.c
==============================================================================
--- lvm2/trunk/daemons/clvmd/lvm-functions.c	(original)
+++ lvm2/trunk/daemons/clvmd/lvm-functions.c	Sat Jun 10 21:40:06 2006
@@ -306,6 +306,12 @@
 	if (lock_flags & LCK_PARTIAL_MODE)
 		init_partial(1);
 
+	if (lock_flags & LCK_MIRROR_NOSYNC_MODE)
+		init_mirror_in_sync(1);
+
+	if (!(lock_flags & LCK_DMEVENTD_MONITOR))
+		init_dmeventd_register(0);
+
 	switch (command) {
 	case LCK_LV_EXCLUSIVE:
 		status = do_activate_lv(resource, lock_flags, LKM_EXMODE);
@@ -337,6 +343,12 @@
 	if (lock_flags & LCK_PARTIAL_MODE)
 		init_partial(0);
 
+	if (lock_flags & LCK_MIRROR_NOSYNC_MODE)
+		init_mirror_in_sync(0);
+
+	if (!(lock_flags & LCK_DMEVENTD_REGISTER_MODE))
+		init_dmeventd_register(DEFAULT_DMEVENTD_MONITOR);
+
 	/* clean the pool for another command */
 	dm_pool_empty(cmd->mem);
 

Modified: lvm2/trunk/daemons/clvmd/tcp-comms.c
==============================================================================
--- lvm2/trunk/daemons/clvmd/tcp-comms.c	(original)
+++ lvm2/trunk/daemons/clvmd/tcp-comms.c	Sat Jun 10 21:40:06 2006
@@ -57,7 +57,7 @@
     struct sockaddr_in6 addr;
 
     sock_hash = dm_hash_create(100);
-    tcp_port = port ? port : DEFAULT_TCP_PORT;
+    tcp_port = port ? : DEFAULT_TCP_PORT;
 
     listen_fd = socket(AF_INET6, SOCK_STREAM, 0);
 

Modified: lvm2/trunk/dmeventd/mirror/dmeventd_mirror.c
==============================================================================
--- lvm2/trunk/dmeventd/mirror/dmeventd_mirror.c	(original)
+++ lvm2/trunk/dmeventd/mirror/dmeventd_mirror.c	Sat Jun 10 21:40:06 2006
@@ -99,10 +99,13 @@
 	return rtn;
 }
 
-static void _temporary_log_fn(int level, const char *file, int line, const char *format)
+static void _temporary_log_fn(int level, const char *file,
+			      int line, const char *format)
 {
-	return;
-	syslog(LOG_DEBUG, "%s", format);
+	if (!strncmp(format, "WARNING: ", 9) && (level < 5))
+		syslog(LOG_CRIT, "%s", format);
+	else
+		syslog(LOG_DEBUG, "%s", format);
 }
 
 static int _remove_failed_devices(const char *device)
@@ -205,7 +208,7 @@
 
 int register_device(const char *device)
 {
-	syslog(LOG_INFO, "Monitoring %s for events\n", device);
+	syslog(LOG_INFO, "Monitoring mirror device, %s for events\n", device);
 
 	/*
 	 * Need some space for allocations.  1024 should be more
@@ -224,8 +227,6 @@
 
 int unregister_device(const char *device)
 {
-        syslog(LOG_INFO, "Stopped monitoring %s for events\n", device);
-
 	if (!(--register_count)) {
 		dm_pool_destroy(mem_pool);
 		mem_pool = NULL;

Modified: lvm2/trunk/doc/example.conf
==============================================================================
--- lvm2/trunk/doc/example.conf	(original)
+++ lvm2/trunk/doc/example.conf	Sat Jun 10 21:40:06 2006
@@ -238,9 +238,6 @@
     # target or make it return zeros.
     missing_stripe_filler = "/dev/ioerror"
 
-    # Size (in KB) of each copy operation when mirroring
-    mirror_region_size = 512
-
     # How much stack (in KB) to reserve for use while devices suspended
     reserved_stack = 256
 
@@ -260,6 +257,54 @@
 
     # Permissions to use for new devices
     # device_permissions = [ 0, 6, 0660 ]
+
+    # Size (in KB) of each copy operation when mirroring
+    mirror_region_size = 512
+
+    # 'mirror_image_fault_policy' and 'mirror_log_fault_policy' define
+    # how a device failure affecting a mirror is handled.
+    # A mirror is composed of mirror images (copies) and a log.
+    # A disk log ensures that a mirror does not need to be re-synced
+    # (all copies made the same) every time a machine reboots or crashes.
+    #
+    # In the event of a failure, the specified policy will be used to
+    # determine what happens:
+    #
+    # "remove" - Simply remove the faulty device and run without it.  If
+    #            the log device fails, the mirror would convert to using
+    #            an in-memory log.  This means the mirror will not
+    #            remember its sync status across crashes/reboots and
+    #            the entire mirror will be re-synced.  If a
+    #            mirror image fails, the mirror will convert to a
+    #            non-mirrored device if there is only one remaining good
+    #            copy.
+    #
+    # "allocate" - Remove the faulty device and try to allocate space on
+    #            a new device to be a replacement for the failed device.
+    #            Using this policy for the log is fast and maintains the
+    #            ability to remember sync state through crashes/reboots.
+    #            Using this policy for a mirror device is slow, as it
+    #            requires the mirror to resynchronize the devices, but it
+    #            will preserve the mirror characteristic of the device.
+    #            This policy acts like "remove" if no suitable device and
+    #            space can be allocated for the replacement.
+    #            Currently this is not implemented properly and behaves
+    #            similarly to:
+    #
+    # "allocate_anywhere" - Operates like "allocate", but it does not
+    #            require that the new space being allocated be on a
+    #            device is not part of the mirror.  For a log device
+    #            failure, this could mean that the log is allocated on
+    #            the same device as a mirror device.  For a mirror
+    #            device, this could mean that the mirror device is
+    #            allocated on the same device as another mirror device.
+    #            This policy would not be wise for mirror devices
+    #            because it would break the redundant nature of the
+    #            mirror.  This policy acts like "remove" if no suitable
+    #            device and space can be allocated for the replacement.
+
+    mirror_log_fault_policy = "allocate"
+    mirror_device_fault_policy = "remove"
 }
 
 
@@ -300,7 +345,13 @@
 
 # Event daemon
 #
-#dmeventd {
+# dmeventd {
+    # mirror_library is the library used when monitoring a mirror device.
+    #
+    # "libdevmapper-event-lvm2mirror.so" attempts to recover from failures.
+    # It removes failed devices from a volume group and reconfigures a
+    # mirror as necessary.
+    #
     # mirror_library = "libdevmapper-event-lvm2mirror.so"
 #}
 

Modified: lvm2/trunk/include/.symlinks
==============================================================================
--- lvm2/trunk/include/.symlinks	(original)
+++ lvm2/trunk/include/.symlinks	Sat Jun 10 21:40:06 2006
@@ -34,6 +34,7 @@
 ../lib/metadata/segtype.h
 ../lib/mm/memlock.h
 ../lib/mm/xlate.h
+../lib/misc/configure.h
 ../lib/misc/crc.h
 ../lib/misc/intl.h
 ../lib/misc/lib.h

Modified: lvm2/trunk/lib/activate/activate.c
==============================================================================
--- lvm2/trunk/lib/activate/activate.c	(original)
+++ lvm2/trunk/lib/activate/activate.c	Sat Jun 10 21:40:06 2006
@@ -152,7 +152,7 @@
 }
 
 int pv_uses_vg(struct cmd_context *cmd, struct physical_volume *pv,
-               struct volume_group *vg)
+	       struct volume_group *vg)
 {
 	return 0;
 }
@@ -574,15 +574,31 @@
 	return count;
 }
 
-static int _register_dev_for_events(struct cmd_context *cmd,
-				    struct logical_volume *lv, int do_reg)
+/*
+ * register_dev_for_events
+ *
+ * This function uses proper error codes (but breaks convention)
+ * to return:
+ *      -1 on error
+ *       0 if the lv's targets don't do event [un]registration
+ *       0 if the lv is already [un]registered -- FIXME: not implemented
+ *       1 if the lv had a segment which was [un]registered
+ *
+ * Returns: -1 on error
+ */
+int register_dev_for_events(struct cmd_context *cmd,
+			    struct logical_volume *lv, int do_reg)
 {
 #ifdef DMEVENTD
+	int r = 0;
 	struct list *tmp;
 	struct lv_segment *seg;
 	int (*reg) (struct dm_pool *mem, struct lv_segment *,
 		    struct config_tree *cft, int events);
 
+	if (do_reg && !dmeventd_register_mode())
+		return 1;
+
 	list_iterate(tmp, &lv->segments) {
 		seg = list_item(tmp, struct lv_segment);
 
@@ -594,16 +610,22 @@
 		} else if (seg->segtype->ops->target_unregister_events)
 			reg = seg->segtype->ops->target_unregister_events;
 
-		if (reg)
-			/* FIXME specify events */
-			if (!reg(cmd->mem, seg, cmd->cft, 0)) {
-				stack;
-				return 0;
-			}
+		if (!reg)
+			continue;
+
+		/* FIXME specify events */
+		if (!reg(cmd->mem, seg, cmd->cft, 0)) {
+			stack;
+			return -1;
+		}
+
+		r = 1;
 	}
 
-#endif
+	return r;
+#else
 	return 1;
+#endif
 }
 
 static int _lv_suspend(struct cmd_context *cmd, const char *lvid_s,
@@ -641,7 +663,8 @@
 		}
 	}
 
-	if (!_register_dev_for_events(cmd, lv, 0))
+	if (register_dev_for_events(cmd, lv, 0) != 1)
+		/* FIXME Consider aborting here */
 		stack;
 
 	memlock_inc();
@@ -694,7 +717,7 @@
 	memlock_dec();
 	fs_unlock();
 
-	if (!_register_dev_for_events(cmd, lv, 1))
+	if (register_dev_for_events(cmd, lv, 1) != 1)
 		stack;
 
 	return 1;
@@ -740,7 +763,7 @@
 		return 0;
 	}
 
-	if (!_register_dev_for_events(cmd, lv, 0))
+	if (register_dev_for_events(cmd, lv, 0) != 1)
 		stack;
 
 	memlock_inc();
@@ -836,7 +859,7 @@
 	memlock_dec();
 	fs_unlock();
 
-	if (!_register_dev_for_events(cmd, lv, 1))
+	if (!register_dev_for_events(cmd, lv, 1) != 1)
 		stack;
 
 	return r;
@@ -882,28 +905,16 @@
  * Does PV use VG somewhere in its construction?
  * Returns 1 on failure.
  */
-int pv_uses_vg(struct cmd_context *cmd, struct physical_volume *pv,
-               struct volume_group *vg)
+int pv_uses_vg(struct physical_volume *pv,
+	       struct volume_group *vg)
 {
-	struct dev_manager *dm;
-	int r;
-
 	if (!activation())
 		return 0;
 
 	if (!dm_is_dm_major(MAJOR(pv->dev->dev)))
 		return 0;
 
-	if (!(dm = dev_manager_create(cmd, vg->name))) {
-		stack;
-		return 1;
-	}
-
-	r = dev_manager_device_uses_vg(dm, pv->dev, vg);
-
-	dev_manager_destroy(dm);
-
-	return r;
+	return dev_manager_device_uses_vg(pv->dev, vg);
 }
 
 void activation_exit(void)

Modified: lvm2/trunk/lib/activate/activate.h
==============================================================================
--- lvm2/trunk/lib/activate/activate.h	(original)
+++ lvm2/trunk/lib/activate/activate.h	Sat Jun 10 21:40:06 2006
@@ -80,10 +80,14 @@
 int lvs_in_vg_activated(struct volume_group *vg);
 int lvs_in_vg_opened(struct volume_group *vg);
 
+
+int register_dev_for_events(struct cmd_context *cmd,
+			    struct logical_volume *lv, int do_reg);
+
 /*
  * Returns 1 if PV has a dependency tree that uses anything in VG.
  */
-int pv_uses_vg(struct cmd_context *cmd, struct physical_volume *pv,
+int pv_uses_vg(struct physical_volume *pv,
 	       struct volume_group *vg);
 
 #endif

Modified: lvm2/trunk/lib/activate/dev_manager.c
==============================================================================
--- lvm2/trunk/lib/activate/dev_manager.c	(original)
+++ lvm2/trunk/lib/activate/dev_manager.c	Sat Jun 10 21:40:06 2006
@@ -616,6 +616,9 @@
 	if (!_add_dev_to_dtree(dm, dtree, lv, "cow"))
 		return_0;
 
+	if (!_add_dev_to_dtree(dm, dtree, lv, "_mlog"))
+		return_0;
+
 	return 1;
 }
 
@@ -661,7 +664,8 @@
 }
 
 int add_areas_line(struct dev_manager *dm, struct lv_segment *seg,
-		   struct dm_tree_node *node, int start_area, int areas)
+		   struct dm_tree_node *node, uint32_t start_area,
+		   uint32_t areas)
 {
 	uint64_t extent_size = seg->lv->vg->extent_size;
 	uint32_t s;
@@ -675,7 +679,7 @@
 		    (seg_type(seg, s) == AREA_LV && !seg_lv(seg, s)))
 			dm_tree_node_add_target_area(node,
 							dm->stripe_filler,
-							NULL, 0);
+							NULL, UINT64_C(0));
 		else if (seg_type(seg, s) == AREA_PV)
 			dm_tree_node_add_target_area(node,
 							dev_name(seg_dev(seg, s)),
@@ -700,7 +704,6 @@
 }
 
 static int _add_origin_target_to_dtree(struct dev_manager *dm,
-					 struct dm_tree *dtree,
 					 struct dm_tree_node *dnode,
 					 struct logical_volume *lv)
 {
@@ -716,7 +719,6 @@
 }
 
 static int _add_snapshot_target_to_dtree(struct dev_manager *dm,
-					   struct dm_tree *dtree,
 					   struct dm_tree_node *dnode,
 					   struct logical_volume *lv)
 {
@@ -745,7 +747,6 @@
 }
 
 static int _add_target_to_dtree(struct dev_manager *dm,
-				  struct dm_tree *dtree,
 				  struct dm_tree_node *dnode,
 				  struct lv_segment *seg)
 {
@@ -810,12 +811,12 @@
 
 	/* Now we've added its dependencies, we can add the target itself */
 	if (lv_is_origin(seg->lv) && !layer) {
-		if (!_add_origin_target_to_dtree(dm, dtree, dnode, seg->lv))
+		if (!_add_origin_target_to_dtree(dm, dnode, seg->lv))
 			return_0;
 	} else if (lv_is_cow(seg->lv) && !layer) {
-		if (!_add_snapshot_target_to_dtree(dm, dtree, dnode, seg->lv))
+		if (!_add_snapshot_target_to_dtree(dm, dnode, seg->lv))
 			return_0;
-	} else if (!_add_target_to_dtree(dm, dtree, dnode, seg))
+	} else if (!_add_target_to_dtree(dm, dnode, seg))
 		return_0;
 
 	if (lv_is_origin(seg->lv) && !layer)
@@ -860,11 +861,11 @@
 	 * Major/minor settings only apply to the visible layer.
 	 */
 	if (!(dnode = _dm_tree_add_new_dev_mode(dtree, name, dlid,
-					     layer ? lv->major : 0,
-					     layer ? lv->minor : 0,
+					     layer ? (uint32_t) lv->major : UINT32_C(0),
+					     layer ? (uint32_t) lv->minor : UINT32_C(0),
 					     lv->uid, lv->gid, lv->mode,
 					     _read_only_lv(lv),
-					     lv->vg->status & PRECOMMITTED,
+					     (lv->vg->status & PRECOMMITTED) ? 1 : 0,
 					     lvlayer)))
 		return_0;
 
@@ -918,7 +919,7 @@
 	return r;
 }
 
-static int _clean_tree(struct dev_manager *dm, struct logical_volume *lv, struct dm_tree_node *root)
+static int _clean_tree(struct dev_manager *dm, struct dm_tree_node *root)
 {
 	void *handle = NULL;
 	struct dm_tree_node *child;
@@ -970,7 +971,7 @@
 	switch(action) {
 	case CLEAN:
 		/* Deactivate any unused non-toplevel nodes */
-		if (!_clean_tree(dm, lv, root))
+		if (!_clean_tree(dm, root))
 			goto_out;
 		break;
 	case DEACTIVATE:
@@ -1053,7 +1054,7 @@
  * Does device use VG somewhere in its construction?
  * Returns 1 if uncertain.
  */
-int dev_manager_device_uses_vg(struct dev_manager *dm, struct device *dev,
+int dev_manager_device_uses_vg(struct device *dev,
 			       struct volume_group *vg)
 {
 	struct dm_tree *dtree;
@@ -1066,7 +1067,7 @@
 		return r;
 	}
 
-	if (!dm_tree_add_dev(dtree, MAJOR(dev->dev), MINOR(dev->dev))) {
+	if (!dm_tree_add_dev(dtree, (uint32_t) MAJOR(dev->dev), (uint32_t) MINOR(dev->dev))) {
 		log_error("Failed to add device %s (%" PRIu32 ":%" PRIu32") to dtree",
 			  dev_name(dev), (uint32_t) MAJOR(dev->dev), (uint32_t) MINOR(dev->dev));
 		goto out;

Modified: lvm2/trunk/lib/activate/dev_manager.h
==============================================================================
--- lvm2/trunk/lib/activate/dev_manager.h	(original)
+++ lvm2/trunk/lib/activate/dev_manager.h	Sat Jun 10 21:40:06 2006
@@ -59,7 +59,7 @@
  */
 int dev_manager_execute(struct dev_manager *dm);
 
-int dev_manager_device_uses_vg(struct dev_manager *dm, struct device *dev,
+int dev_manager_device_uses_vg(struct device *dev,
 			       struct volume_group *vg);
 
 #endif

Modified: lvm2/trunk/lib/activate/targets.h
==============================================================================
--- lvm2/trunk/lib/activate/targets.h	(original)
+++ lvm2/trunk/lib/activate/targets.h	Sat Jun 10 21:40:06 2006
@@ -24,7 +24,7 @@
 		       int start_area, int areas);
 
 int add_areas_line(struct dev_manager *dm, struct lv_segment *seg,
-                   struct dm_tree_node *node, int start_area, int areas);
+                   struct dm_tree_node *node, uint32_t start_area, uint32_t areas);
 
 int build_dev_string(struct dev_manager *dm, char *dlid, char *devbuf,
 		     size_t bufsize, const char *desc);

Modified: lvm2/trunk/lib/cache/lvmcache.c
==============================================================================
--- lvm2/trunk/lib/cache/lvmcache.c	(original)
+++ lvm2/trunk/lib/cache/lvmcache.c	Sat Jun 10 21:40:06 2006
@@ -50,7 +50,7 @@
 	return 1;
 }
 
-void lvmcache_lock_vgname(const char *vgname, int read_only)
+void lvmcache_lock_vgname(const char *vgname, int read_only __attribute((unused)))
 {
 	if (!_lock_hash && !lvmcache_init()) {
 		log_error("Internal cache initialisation failed");
@@ -123,7 +123,10 @@
  	 * we check cached labels here. Unfortunately vginfo is volatile. */
 	list_init(&devs);
 	list_iterate_items(info, &vginfo->infos) {
-		devl = dm_malloc(sizeof(*devl));
+		if (!(devl = dm_malloc(sizeof(*devl)))) {
+			log_error("device_list element allocation failed");
+			return NULL;
+		}
 		devl->dev = info->dev;
 		list_add(&devs, &devl->list);
 	}
@@ -306,6 +309,32 @@
 	return vgnames;
 }
 
+struct list *lvmcache_get_pvids(struct cmd_context *cmd, const char *vgname,
+				const char *vgid)
+{
+	struct list *pvids;
+	struct lvmcache_vginfo *vginfo;
+	struct lvmcache_info *info;
+
+	if (!(pvids = str_list_create(cmd->mem))) {
+		log_error("pvids list allocation failed");
+		return NULL;
+	}
+
+	if (!(vginfo = vginfo_from_vgname(vgname, vgid)))
+		return pvids;
+
+	list_iterate_items(info, &vginfo->infos) {
+		if (!str_list_add(cmd->mem, pvids, 
+				  dm_pool_strdup(cmd->mem, info->dev->pvid))) {
+			log_error("strlist allocation failed");
+			return NULL;
+		}
+	}
+
+	return pvids;
+}
+
 struct device *device_from_pvid(struct cmd_context *cmd, struct id *pvid)
 {
 	struct label *label;
@@ -448,10 +477,10 @@
 	
 	/* Pre-existing VG takes precedence. Unexported VG takes precedence. */
 	if (primary_vginfo) {
-		if (!id_write_format((struct id *)vgid, uuid_new, sizeof(uuid_new)))
+		if (!id_write_format((const struct id *)vgid, uuid_new, sizeof(uuid_new)))
 			return_0;
 
-		if (!id_write_format((struct id *)&primary_vginfo->vgid, uuid_primary,
+		if (!id_write_format((const struct id *)&primary_vginfo->vgid, uuid_primary,
 				     sizeof(uuid_primary)))
 			return_0;
 
@@ -828,7 +857,7 @@
 	} while ((vginfo = next));
 }
 
-static void _lvmcache_destroy_lockname(int present)
+static void _lvmcache_destroy_lockname(int present __attribute((unused)))
 {
 	/* Nothing to do */
 }

Modified: lvm2/trunk/lib/cache/lvmcache.h
==============================================================================
--- lvm2/trunk/lib/cache/lvmcache.h	(original)
+++ lvm2/trunk/lib/cache/lvmcache.h	Sat Jun 10 21:40:06 2006
@@ -101,4 +101,8 @@
 /* Set full_scan to 1 to reread every filtered device label */
 struct list *lvmcache_get_vgids(struct cmd_context *cmd, int full_scan);
 
+/* Returns list of struct str_lists containing pool-allocated copy of pvids */
+struct list *lvmcache_get_pvids(struct cmd_context *cmd, const char *vgname,
+				const char *vgid);
+
 #endif

Modified: lvm2/trunk/lib/commands/toolcontext.c
==============================================================================
--- lvm2/trunk/lib/commands/toolcontext.c	(original)
+++ lvm2/trunk/lib/commands/toolcontext.c	Sat Jun 10 21:40:06 2006
@@ -952,7 +952,7 @@
 
 	if (!(cmd->mem = dm_pool_create("command", 4 * 1024))) {
 		log_error("Command memory pool creation failed");
-		return 0;
+		goto error;
 	}
 
 	memlock_init(cmd);

Modified: lvm2/trunk/lib/config/config.c
==============================================================================
--- lvm2/trunk/lib/config/config.c	(original)
+++ lvm2/trunk/lib/config/config.c	Sat Jun 10 21:40:06 2006
@@ -688,14 +688,20 @@
 static struct config_value *_create_value(struct parser *p)
 {
 	struct config_value *v = dm_pool_alloc(p->mem, sizeof(*v));
-	memset(v, 0, sizeof(*v));
+
+	if (v)
+		memset(v, 0, sizeof(*v));
+
 	return v;
 }
 
 static struct config_node *_create_node(struct parser *p)
 {
 	struct config_node *n = dm_pool_alloc(p->mem, sizeof(*n));
-	memset(n, 0, sizeof(*n));
+
+	if (n)
+		memset(n, 0, sizeof(*n));
+
 	return n;
 }
 
@@ -752,9 +758,9 @@
 {
 	const struct config_node *n = find_config_node(cn, path);
 
-	if (n && n->v->type == CFG_STRING) {
-		if (*n->v->v.str)
-			log_very_verbose("Setting %s to %s", path, n->v->v.str);
+	/* Empty strings are ignored */
+	if ((n && n->v->type == CFG_STRING) && (*n->v->v.str)) {
+		log_very_verbose("Setting %s to %s", path, n->v->v.str);
 		return n->v->v.str;
 	}
 

Modified: lvm2/trunk/lib/config/defaults.h
==============================================================================
--- lvm2/trunk/lib/config/defaults.h	(original)
+++ lvm2/trunk/lib/config/defaults.h	Sat Jun 10 21:40:06 2006
@@ -34,7 +34,10 @@
 #define DEFAULT_LOCK_DIR "/var/lock/lvm"
 #define DEFAULT_LOCKING_LIB "lvm2_locking.so"
 
+#define DEFAULT_MIRROR_LOG_FAULT_POLICY "allocate"
+#define DEFAULT_MIRROR_DEV_FAULT_POLICY "remove"
 #define DEFAULT_DMEVENTD_MIRROR_LIB "libdevmapper-event-lvm2mirror.so"
+#define DEFAULT_DMEVENTD_MONITOR 1
 
 #define DEFAULT_UMASK 0077
 

Modified: lvm2/trunk/lib/device/dev-io.c
==============================================================================
--- lvm2/trunk/lib/device/dev-io.c	(original)
+++ lvm2/trunk/lib/device/dev-io.c	Sat Jun 10 21:40:06 2006
@@ -604,7 +604,7 @@
 	return _aligned_io(&where, buffer, 1);
 }
 
-int dev_zero(struct device *dev, uint64_t offset, size_t len)
+int dev_set(struct device *dev, uint64_t offset, size_t len, int value)
 {
 	size_t s;
 	char buffer[4096];
@@ -622,7 +622,7 @@
 			  " sectors", dev_name(dev), offset >> SECTOR_SHIFT,
 			  len >> SECTOR_SHIFT);
 
-	memset(buffer, 0, sizeof(buffer));
+	memset(buffer, value, sizeof(buffer));
 	while (1) {
 		s = len > sizeof(buffer) ? sizeof(buffer) : len;
 		if (!dev_write(dev, offset, s, buffer))

Modified: lvm2/trunk/lib/device/device.c
==============================================================================
--- lvm2/trunk/lib/device/device.c	(original)
+++ lvm2/trunk/lib/device/device.c	Sat Jun 10 21:40:06 2006
@@ -62,7 +62,7 @@
 		return -1;
 	}
 
-	if (!dev_read(dev, 0, sizeof(buf), &buf)) {
+	if (!dev_read(dev, UINT64_C(0), sizeof(buf), &buf)) {
 		stack;
 		goto out;
 	}

Modified: lvm2/trunk/lib/device/device.h
==============================================================================
--- lvm2/trunk/lib/device/device.h	(original)
+++ lvm2/trunk/lib/device/device.h	Sat Jun 10 21:40:06 2006
@@ -80,7 +80,7 @@
 int dev_read(struct device *dev, uint64_t offset, size_t len, void *buffer);
 int dev_write(struct device *dev, uint64_t offset, size_t len, void *buffer);
 int dev_append(struct device *dev, size_t len, void *buffer);
-int dev_zero(struct device *dev, uint64_t offset, size_t len);
+int dev_set(struct device *dev, uint64_t offset, size_t len, int value);
 void dev_flush(struct device *dev);
 
 struct device *dev_create_file(const char *filename, struct device *dev,

Modified: lvm2/trunk/lib/display/display.c
==============================================================================
--- lvm2/trunk/lib/display/display.c	(original)
+++ lvm2/trunk/lib/display/display.c	Sat Jun 10 21:40:06 2006
@@ -22,6 +22,8 @@
 
 #define SIZE_BUF 128
 
+typedef enum { SIZE_LONG = 0, SIZE_SHORT = 1, SIZE_UNIT = 2 } size_len_t;
+
 static struct {
 	alloc_policy_t alloc;
 	const char *str;
@@ -132,7 +134,7 @@
 }
 
 /* Size supplied in sectors */
-const char *display_size(struct cmd_context *cmd, uint64_t size, size_len_t sl)
+static const char *_display_size(struct cmd_context *cmd, uint64_t size, size_len_t sl)
 {
 	int s;
 	int suffix = 1, precision;
@@ -200,6 +202,21 @@
 	return size_buf;
 }
 
+const char *display_size_long(struct cmd_context *cmd, uint64_t size)
+{
+	return _display_size(cmd, size, SIZE_LONG);
+}
+
+const char *display_size_units(struct cmd_context *cmd, uint64_t size)
+{
+	return _display_size(cmd, size, SIZE_UNIT);
+}
+
+const char *display_size(struct cmd_context *cmd, uint64_t size)
+{
+	return _display_size(cmd, size, SIZE_SHORT);
+}
+
 void pvdisplay_colons(struct physical_volume *pv)
 {
 	char uuid[64];
@@ -228,7 +245,7 @@
 
 /* FIXME Include label fields */
 void pvdisplay_full(struct cmd_context *cmd, struct physical_volume *pv,
-		    void *handle)
+		    void *handle __attribute((unused)))
 {
 	char uuid[64];
 	const char *size;
@@ -248,18 +265,17 @@
 	log_print("VG Name               %s%s", pv->vg_name,
 		  pv->status & EXPORTED_VG ? " (exported)" : "");
 
-	size = display_size(cmd, (uint64_t) pv->size, SIZE_SHORT);
+	size = display_size(cmd, (uint64_t) pv->size);
 	if (pv->pe_size && pv->pe_count) {
 
 /******** FIXME display LVM on-disk data size
-		size2 = display_size(pv->size, SIZE_SHORT);
+		size2 = display_size(cmd, pv->size);
 ********/
 
 		log_print("PV Size               %s" " / not usable %s",	/*  [LVM: %s]", */
 			  size,
 			  display_size(cmd, (pv->size -
-				       (uint64_t) pv->pe_count * pv->pe_size),
-				       SIZE_SHORT));
+				       (uint64_t) pv->pe_count * pv->pe_size)));
 
 	} else
 		log_print("PV Size               %s", size);
@@ -288,8 +304,10 @@
 	return;
 }
 
-int pvdisplay_short(struct cmd_context *cmd, struct volume_group *vg,
-		    struct physical_volume *pv, void *handle)
+int pvdisplay_short(struct cmd_context *cmd __attribute((unused)),
+		    struct volume_group *vg __attribute((unused)),
+		    struct physical_volume *pv,
+		    void *handle __attribute((unused)))
 {
 	char uuid[64];
 
@@ -334,7 +352,7 @@
 }
 
 int lvdisplay_full(struct cmd_context *cmd, struct logical_volume *lv,
-		   void *handle)
+		   void *handle __attribute((unused)))
 {
 	struct lvinfo info;
 	int inkernel, snap_active = 0;
@@ -404,23 +422,21 @@
 
 	log_print("LV Size                %s",
 		  display_size(cmd,
-			       snap_seg ? snap_seg->origin->size : lv->size,
-			       SIZE_SHORT));
+			       snap_seg ? snap_seg->origin->size : lv->size));
 
 	log_print("Current LE             %u",
 		  snap_seg ? snap_seg->origin->le_count : lv->le_count);
 
 	if (snap_seg) {
 		log_print("COW-table size         %s",
-			  display_size(cmd, (uint64_t) lv->size, SIZE_SHORT));
+			  display_size(cmd, (uint64_t) lv->size));
 		log_print("COW-table LE           %u", lv->le_count);
 
 		if (snap_active)
 			log_print("Allocated to snapshot  %.2f%% ", snap_percent);	
 
 		log_print("Snapshot chunk size    %s",
-			  display_size(cmd, (uint64_t) snap_seg->chunk_size,
-				       SIZE_SHORT));
+			  display_size(cmd, (uint64_t) snap_seg->chunk_size));
 	}
 
 	log_print("Segments               %u", list_size(&lv->segments));
@@ -497,7 +513,7 @@
 	return 1;
 }
 
-void vgdisplay_extents(struct volume_group *vg)
+void vgdisplay_extents(struct volume_group *vg __attribute((unused)))
 {
 	return;
 }
@@ -544,7 +560,7 @@
 	log_print("Open LV               %u", lvs_in_vg_opened(vg));
 /****** FIXME Max LV Size
       log_print ( "MAX LV Size           %s",
-               ( s1 = display_size ( LVM_LV_SIZE_MAX(vg), SIZE_SHORT)));
+               ( s1 = display_size ( LVM_LV_SIZE_MAX(vg))));
       free ( s1);
 *********/
 	log_print("Max PV                %u", vg->max_pv);
@@ -553,12 +569,10 @@
 
 	log_print("VG Size               %s",
 		  display_size(vg->cmd,
-			       (uint64_t) vg->extent_count * vg->extent_size,
-			       SIZE_SHORT));
+			       (uint64_t) vg->extent_count * vg->extent_size));
 
 	log_print("PE Size               %s",
-		  display_size(vg->cmd, (uint64_t) vg->extent_size,
-			       SIZE_SHORT));
+		  display_size(vg->cmd, (uint64_t) vg->extent_size));
 
 	log_print("Total PE              %u", vg->extent_count);
 
@@ -566,12 +580,11 @@
 		  vg->extent_count - vg->free_count,
 		  display_size(vg->cmd,
 			       ((uint64_t) vg->extent_count - vg->free_count) *
-			       vg->extent_size, SIZE_SHORT));
+			       vg->extent_size));
 
 	log_print("Free  PE / Size       %u / %s", vg->free_count,
 		  display_size(vg->cmd,
-			       (uint64_t) vg->free_count * vg->extent_size,
-			       SIZE_SHORT));
+			       (uint64_t) vg->free_count * vg->extent_size));
 
 	if (!id_write_format(&vg->id, uuid, sizeof(uuid))) {
 		stack;
@@ -641,15 +654,12 @@
 	log_print("\"%s\" %-9s [%-9s used / %s free]", vg->name,
 /********* FIXME if "open" print "/used" else print "/idle"???  ******/
 		  display_size(vg->cmd,
-			       (uint64_t) vg->extent_count * vg->extent_size,
-			       SIZE_SHORT),
+			       (uint64_t) vg->extent_count * vg->extent_size),
 		  display_size(vg->cmd,
 			       ((uint64_t) vg->extent_count -
-				vg->free_count) * vg->extent_size,
-			       SIZE_SHORT),
+				vg->free_count) * vg->extent_size),
 		  display_size(vg->cmd,
-			       (uint64_t) vg->free_count * vg->extent_size,
-			       SIZE_SHORT));
+			       (uint64_t) vg->free_count * vg->extent_size));
 	return;
 }
 

Modified: lvm2/trunk/lib/display/display.h
==============================================================================
--- lvm2/trunk/lib/display/display.h	(original)
+++ lvm2/trunk/lib/display/display.h	Sat Jun 10 21:40:06 2006
@@ -20,12 +20,13 @@
 
 #include <stdint.h>
 
-typedef enum { SIZE_LONG = 0, SIZE_SHORT = 1, SIZE_UNIT = 2 } size_len_t;
-
 uint64_t units_to_bytes(const char *units, char *unit_type);
 
 /* Specify size in KB */
-const char *display_size(struct cmd_context *cmd, uint64_t size, size_len_t sl);
+const char *display_size(struct cmd_context *cmd, uint64_t size);
+const char *display_size_long(struct cmd_context *cmd, uint64_t size);
+const char *display_size_units(struct cmd_context *cmd, uint64_t size);
+
 char *display_uuid(char *uuidstr);
 void display_stripe(const struct lv_segment *seg, uint32_t s, const char *pre);
 

Modified: lvm2/trunk/lib/error/errseg.c
==============================================================================
--- lvm2/trunk/lib/error/errseg.c	(original)
+++ lvm2/trunk/lib/error/errseg.c	Sat Jun 10 21:40:06 2006
@@ -38,11 +38,13 @@
 }
 
 #ifdef DEVMAPPER_SUPPORT
-static int _errseg_add_target_line(struct dev_manager *dm, struct dm_pool *mem,
-				struct config_tree *cft, void **target_state,
-				struct lv_segment *seg,
+static int _errseg_add_target_line(struct dev_manager *dm __attribute((unused)),
+				struct dm_pool *mem __attribute((unused)),
+				struct config_tree *cft __attribute((unused)),
+				void **target_state __attribute((unused)),
+				struct lv_segment *seg __attribute((unused)),
 				struct dm_tree_node *node, uint64_t len,
-				uint32_t *pvmove_mirror_count)
+				uint32_t *pvmove_mirror_count __attribute((unused)))
 {
 	return dm_tree_node_add_error_target(node, len);
 }
@@ -64,17 +66,17 @@
 
 static void _errseg_destroy(const struct segment_type *segtype)
 {
-	dm_free((void *) segtype);
+	dm_free((void *)segtype);
 }
 
 static struct segtype_handler _error_ops = {
-	name:_errseg_name,
-	merge_segments:_errseg_merge_segments,
+	.name = _errseg_name,
+	.merge_segments = _errseg_merge_segments,
 #ifdef DEVMAPPER_SUPPORT
-	add_target_line:_errseg_add_target_line,
-	target_present:_errseg_target_present,
+	.add_target_line = _errseg_add_target_line,
+	.target_present = _errseg_target_present,
 #endif
-	destroy:_errseg_destroy,
+	.destroy = _errseg_destroy,
 };
 
 struct segment_type *init_error_segtype(struct cmd_context *cmd)

Modified: lvm2/trunk/lib/filters/filter.c
==============================================================================
--- lvm2/trunk/lib/filters/filter.c	(original)
+++ lvm2/trunk/lib/filters/filter.c	Sat Jun 10 21:40:06 2006
@@ -204,6 +204,7 @@
 			if (cv->type != CFG_STRING) {
 				log_error("Expecting string in devices/types "
 					  "in config file");
+				fclose(pd);
 				return 0;
 			}
 			dev_len = strlen(cv->v.str);
@@ -213,12 +214,14 @@
 				log_error("Max partition count missing for %s "
 					  "in devices/types in config file",
 					  name);
+				fclose(pd);
 				return 0;
 			}
 			if (!cv->v.i) {
 				log_error("Zero partition count invalid for "
 					  "%s in devices/types in config file",
 					  name);
+				fclose(pd);
 				return 0;
 			}
 			if (dev_len <= strlen(line + i) &&
@@ -254,6 +257,7 @@
 
 	if (!_scan_proc_dev(proc, cn)) {
 		stack;
+		dm_free(f);
 		return NULL;
 	}
 

Modified: lvm2/trunk/lib/format1/disk-rep.c
==============================================================================
--- lvm2/trunk/lib/format1/disk-rep.c	(original)
+++ lvm2/trunk/lib/format1/disk-rep.c	Sat Jun 10 21:40:06 2006
@@ -102,7 +102,7 @@
 
 static void _xlate_extents(struct pe_disk *extents, uint32_t count)
 {
-	int i;
+	unsigned i;
 
 	for (i = 0; i < count; i++) {
 		extents[i].lv_num = xlate16(extents[i].lv_num);
@@ -116,7 +116,7 @@
 static int _munge_formats(struct pv_disk *pvd)
 {
 	uint32_t pe_start;
-	int b, e;
+	unsigned b, e;
 
 	switch (pvd->version) {
 	case 1:
@@ -153,8 +153,10 @@
         }
 
 	/* If UUID is missing, create one */
-	if (pvd->pv_uuid[0] == '\0')
-		uuid_from_num(pvd->pv_uuid, pvd->pv_number);
+	if (pvd->pv_uuid[0] == '\0') {
+		uuid_from_num((char *)pvd->pv_uuid, pvd->pv_number);
+		pvd->pv_uuid[ID_LEN] = '\0';
+	}
 
 	return 1;
 }
@@ -172,9 +174,9 @@
 		return;
 	/* FIXME also check vgd->status & VG_EXPORTED? */
 
-	l = strlen(pvd->vg_name);
+	l = strlen((char *)pvd->vg_name);
 	s = sizeof(EXPORTED_TAG);
-	if (!strncmp(pvd->vg_name + l - s + 1, EXPORTED_TAG, s)) {
+	if (!strncmp((char *)pvd->vg_name + l - s + 1, EXPORTED_TAG, s)) {
 		pvd->vg_name[l - s + 1] = '\0';
                 pvd->pv_status |= VG_EXPORTED;
         }
@@ -237,14 +239,14 @@
 		
 	/* If UUID is missing, create one */
 	if (vgd->vg_uuid[0] == '\0')
-		uuid_from_num(vgd->vg_uuid, vgd->vg_number);
+		uuid_from_num((char *)vgd->vg_uuid, vgd->vg_number);
 
 	return 1;
 }
 
 static int _read_uuids(struct disk_list *data)
 {
-	int num_read = 0;
+	unsigned num_read = 0;
 	struct uuid_list *ul;
 	char buffer[NAME_LEN];
 	uint64_t pos = data->pvd.pv_uuidlist_on_disk.base;
@@ -322,12 +324,12 @@
 static void __update_lvmcache(const struct format_type *fmt,
 			      struct disk_list *dl,
 			      struct device *dev, const char *vgid,
-			      int exported)
+			      unsigned exported)
 {
 	struct lvmcache_info *info;
 
-	if (!(info = lvmcache_add(fmt->labeller, dl->pvd.pv_uuid, dev,
-				  dl->pvd.vg_name, vgid,
+	if (!(info = lvmcache_add(fmt->labeller, (char *)dl->pvd.pv_uuid, dev,
+				  (char *)dl->pvd.vg_name, vgid,
 				  exported ? EXPORTED_VG : 0))) {
 		stack;
 		return;
@@ -376,14 +378,14 @@
 		goto bad;
 	}
 
-	if (vg_name && strcmp(vg_name, dl->pvd.vg_name)) {
+	if (vg_name && strcmp(vg_name, (char *)dl->pvd.vg_name)) {
 		log_very_verbose("%s is not a member of the VG %s",
 				 name, vg_name);
 		__update_lvmcache(fmt, dl, dev, NULL, 0);
 		goto bad;
 	}
 
-	__update_lvmcache(fmt, dl, dev, dl->vgd.vg_uuid,
+	__update_lvmcache(fmt, dl, dev, (char *)dl->vgd.vg_uuid,
 			  dl->vgd.vg_status & VG_EXPORTED);
 
 	if (!_read_uuids(dl)) {
@@ -437,7 +439,7 @@
 
 	list_iterate_items(diskl, head) {
 		pvd = &diskl->pvd;
-		if (!strncmp(data->pvd.pv_uuid, pvd->pv_uuid,
+		if (!strncmp((char *)data->pvd.pv_uuid, (char *)pvd->pv_uuid,
 			     sizeof(pvd->pv_uuid))) {
 			if (MAJOR(data->dev->dev) != md_major()) {
 				log_very_verbose("Ignoring duplicate PV %s on "
@@ -574,7 +576,7 @@
 
 	pos = data->pvd.lv_on_disk.base;
 
-	if (!dev_zero(data->dev, pos, data->pvd.lv_on_disk.size)) {
+	if (!dev_set(data->dev, pos, data->pvd.lv_on_disk.size, 0)) {
 		log_error("Couldn't zero lv area on device '%s'",
 			  dev_name(data->dev));
 		return 0;

Modified: lvm2/trunk/lib/format1/disk-rep.h
==============================================================================
--- lvm2/trunk/lib/format1/disk-rep.h	(original)
+++ lvm2/trunk/lib/format1/disk-rep.h	Sat Jun 10 21:40:06 2006
@@ -73,16 +73,16 @@
 } __attribute__ ((packed));
 
 struct pv_disk {
-	uint8_t id[2];
+	int8_t id[2];
 	uint16_t version;	/* lvm version */
 	struct data_area pv_on_disk;
 	struct data_area vg_on_disk;
 	struct data_area pv_uuidlist_on_disk;
 	struct data_area lv_on_disk;
 	struct data_area pe_on_disk;
-	uint8_t pv_uuid[NAME_LEN];
-	uint8_t vg_name[NAME_LEN];
-	uint8_t system_id[NAME_LEN];	/* for vgexport/vgimport */
+	int8_t pv_uuid[NAME_LEN];
+	int8_t vg_name[NAME_LEN];
+	int8_t system_id[NAME_LEN];	/* for vgexport/vgimport */
 	uint32_t pv_major;
 	uint32_t pv_number;
 	uint32_t pv_status;
@@ -98,8 +98,8 @@
 } __attribute__ ((packed));
 
 struct lv_disk {
-	uint8_t lv_name[NAME_LEN];
-	uint8_t vg_name[NAME_LEN];
+	int8_t lv_name[NAME_LEN];
+	int8_t vg_name[NAME_LEN];
 	uint32_t lv_access;
 	uint32_t lv_status;
 	uint32_t lv_open;
@@ -122,8 +122,8 @@
 } __attribute__ ((packed));
 
 struct vg_disk {
-	uint8_t vg_uuid[ID_LEN];	/* volume group UUID */
-	uint8_t vg_name_dummy[NAME_LEN - ID_LEN];	/* rest of v1 VG name */
+	int8_t vg_uuid[ID_LEN];	/* volume group UUID */
+	int8_t vg_name_dummy[NAME_LEN - ID_LEN];	/* rest of v1 VG name */
 	uint32_t vg_number;	/* volume group number */
 	uint32_t vg_access;	/* read/write */
 	uint32_t vg_status;	/* active or not */
@@ -223,7 +223,7 @@
 
 int import_pvs(const struct format_type *fmt, struct dm_pool *mem,
 	       struct volume_group *vg,
-	       struct list *pvds, struct list *results, int *count);
+	       struct list *pvds, struct list *results, uint32_t *count);
 
 int import_lvs(struct dm_pool *mem, struct volume_group *vg, struct list *pvds);
 int export_lvs(struct disk_list *dl, struct volume_group *vg,

Modified: lvm2/trunk/lib/format1/format1.c
==============================================================================
--- lvm2/trunk/lib/format1/format1.c	(original)
+++ lvm2/trunk/lib/format1/format1.c	Sat Jun 10 21:40:06 2006
@@ -337,8 +337,7 @@
 		pv->size--;
 	if (pv->size > MAX_PV_SIZE) {
 		log_error("Physical volumes cannot be bigger than %s",
-			  display_size(fmt->cmd, (uint64_t) MAX_PV_SIZE,
-				       SIZE_SHORT));
+			  display_size(fmt->cmd, (uint64_t) MAX_PV_SIZE));
 		return 0;
 	}
 
@@ -378,8 +377,7 @@
 	}
 	if (lv->size > max_size) {
 		log_error("logical volumes cannot be larger than %s",
-			  display_size(fid->fmt->cmd, max_size,
-				       SIZE_SHORT));
+			  display_size(fid->fmt->cmd, max_size));
 		return 0;
 	}
 
@@ -460,18 +458,15 @@
 
 	if (vg->extent_size > MAX_PE_SIZE || vg->extent_size < MIN_PE_SIZE) {
 		log_error("Extent size must be between %s and %s",
-			  display_size(fid->fmt->cmd, (uint64_t) MIN_PE_SIZE,
-				       SIZE_SHORT),
-			  display_size(fid->fmt->cmd, (uint64_t) MAX_PE_SIZE,
-				       SIZE_SHORT));
+			  display_size(fid->fmt->cmd, (uint64_t) MIN_PE_SIZE),
+			  display_size(fid->fmt->cmd, (uint64_t) MAX_PE_SIZE));
 
 		return 0;
 	}
 
 	if (vg->extent_size % MIN_PE_SIZE) {
 		log_error("Extent size must be multiple of %s",
-			  display_size(fid->fmt->cmd, (uint64_t) MIN_PE_SIZE,
-				       SIZE_SHORT));
+			  display_size(fid->fmt->cmd, (uint64_t) MIN_PE_SIZE));
 		return 0;
 	}
 
@@ -485,7 +480,7 @@
 }
 
 static int _format1_segtype_supported(struct format_instance *fid, 
-			       struct segment_type *segtype)
+				      const struct segment_type *segtype)
 {
 	if (!(segtype->flags & SEG_FORMAT1_SUPPORT)) {
 		stack;
@@ -496,8 +491,8 @@
 }
 
 static struct metadata_area_ops _metadata_format1_ops = {
-	vg_read:_format1_vg_read,
-	vg_write:_format1_vg_write,
+	.vg_read = _format1_vg_read,
+	.vg_write = _format1_vg_write,
 };
 
 static struct format_instance *_format1_create_instance(const struct format_type *fmt,
@@ -541,15 +536,15 @@
 }
 
 static struct format_handler _format1_ops = {
-	pv_read:_format1_pv_read,
-	pv_setup:_format1_pv_setup,
-	pv_write:_format1_pv_write,
-	lv_setup:_format1_lv_setup,
-	vg_setup:_format1_vg_setup,
-	segtype_supported:_format1_segtype_supported,
-	create_instance:_format1_create_instance,
-	destroy_instance:_format1_destroy_instance,
-	destroy:_format1_destroy,
+	.pv_read = _format1_pv_read,
+	.pv_setup = _format1_pv_setup,
+	.pv_write = _format1_pv_write,
+	.lv_setup = _format1_lv_setup,
+	.vg_setup = _format1_vg_setup,
+	.segtype_supported = _format1_segtype_supported,
+	.create_instance = _format1_create_instance,
+	.destroy_instance = _format1_destroy_instance,
+	.destroy = _format1_destroy,
 };
 
 #ifdef LVM1_INTERNAL

Modified: lvm2/trunk/lib/format1/import-export.c
==============================================================================
--- lvm2/trunk/lib/format1/import-export.c	(original)
+++ lvm2/trunk/lib/format1/import-export.c	Sat Jun 10 21:40:06 2006
@@ -56,7 +56,7 @@
 	memcpy(&pv->id, pvd->pv_uuid, ID_LEN);
 
 	pv->dev = dev;
-	if (!(pv->vg_name = dm_pool_strdup(mem, pvd->vg_name))) {
+	if (!(pv->vg_name = dm_pool_strdup(mem, (char *)pvd->vg_name))) {
 		stack;
 		return 0;
 	}
@@ -65,10 +65,10 @@
 
 	/* Store system_id from first PV if PV belongs to a VG */
 	if (vg && !*vg->system_id)
-		strncpy(vg->system_id, pvd->system_id, NAME_LEN);
+		strncpy(vg->system_id, (char *)pvd->system_id, NAME_LEN);
 
 	if (vg &&
-	    strncmp(vg->system_id, pvd->system_id, sizeof(pvd->system_id)))
+	    strncmp(vg->system_id, (char *)pvd->system_id, sizeof(pvd->system_id)))
 		    log_very_verbose("System ID %s on %s differs from %s for "
 				     "volume group", pvd->system_id,
 				     dev_name(pv->dev), vg->system_id);
@@ -124,19 +124,17 @@
 
 	memcpy(pvd->pv_uuid, pv->id.uuid, ID_LEN);
 
-	if (!_check_vg_name(pv->vg_name)) {
-		stack;
-		return 0;
+	if (pv->vg_name) {
+		if (!_check_vg_name(pv->vg_name)) {
+			stack;
+			return 0;
+		}
+		strncpy((char *)pvd->vg_name, pv->vg_name, sizeof(pvd->vg_name));
 	}
 
-	memset(pvd->vg_name, 0, sizeof(pvd->vg_name));
-
-	if (pv->vg_name)
-		strncpy(pvd->vg_name, pv->vg_name, sizeof(pvd->vg_name));
-
 	/* Preserve existing system_id if it exists */
 	if (vg && *vg->system_id)
-		strncpy(pvd->system_id, vg->system_id, sizeof(pvd->system_id));
+		strncpy((char *)pvd->system_id, vg->system_id, sizeof(pvd->system_id));
 
 	/* Is VG already exported or being exported? */
 	if (vg && (vg->status & EXPORTED_VG)) {
@@ -144,24 +142,24 @@
 		if (!*vg->system_id ||
 		    strncmp(vg->system_id, EXPORTED_TAG,
 			    sizeof(EXPORTED_TAG) - 1)) {
-			if (!_system_id(cmd, pvd->system_id, EXPORTED_TAG)) {
+			if (!_system_id(cmd, (char *)pvd->system_id, EXPORTED_TAG)) {
 				stack;
 				return 0;
 			}
 		}
-		if (strlen(pvd->vg_name) + sizeof(EXPORTED_TAG) >
+		if (strlen((char *)pvd->vg_name) + sizeof(EXPORTED_TAG) >
 		    sizeof(pvd->vg_name)) {
 			log_error("Volume group name %s too long to export",
 				  pvd->vg_name);
 			return 0;
 		}
-		strcat(pvd->vg_name, EXPORTED_TAG);
+		strcat((char *)pvd->vg_name, EXPORTED_TAG);
 	}
 
 	/* Is VG being imported? */
 	if (vg && !(vg->status & EXPORTED_VG) && *vg->system_id &&
 	    !strncmp(vg->system_id, EXPORTED_TAG, sizeof(EXPORTED_TAG) - 1)) {
-		if (!_system_id(cmd, pvd->system_id, IMPORTED_TAG)) {
+		if (!_system_id(cmd, (char *)pvd->system_id, IMPORTED_TAG)) {
 			stack;
 			return 0;
 		}
@@ -169,7 +167,7 @@
 
 	/* Generate system_id if PV is in VG */
 	if (!pvd->system_id || !*pvd->system_id)
-		if (!_system_id(cmd, pvd->system_id, "")) {
+		if (!_system_id(cmd, (char *)pvd->system_id, "")) {
 			stack;
 			return 0;
 		}
@@ -177,8 +175,8 @@
 	/* Update internal system_id if we changed it */
 	if (vg &&
 	    (!*vg->system_id ||
-	     strncmp(vg->system_id, pvd->system_id, sizeof(pvd->system_id))))
-		    strncpy(vg->system_id, pvd->system_id, NAME_LEN);
+	     strncmp(vg->system_id, (char *)pvd->system_id, sizeof(pvd->system_id))))
+		    strncpy(vg->system_id, (char *)pvd->system_id, NAME_LEN);
 
 	//pvd->pv_major = MAJOR(pv->dev);
 
@@ -204,12 +202,12 @@
 	struct vg_disk *vgd = &dl->vgd;
 	memcpy(vg->id.uuid, vgd->vg_uuid, ID_LEN);
 
-	if (!_check_vg_name(dl->pvd.vg_name)) {
+	if (!_check_vg_name((char *)dl->pvd.vg_name)) {
 		stack;
 		return 0;
 	}
 
-	if (!(vg->name = dm_pool_strdup(mem, dl->pvd.vg_name))) {
+	if (!(vg->name = dm_pool_strdup(mem, (char *)dl->pvd.vg_name))) {
 		stack;
 		return 0;
 	}
@@ -292,7 +290,7 @@
 {
 	lvid_from_lvnum(&lv->lvid, &lv->vg->id, lvd->lv_number);
 
-	if (!(lv->name = _create_lv_name(mem, lvd->lv_name))) {
+	if (!(lv->name = _create_lv_name(mem, (char *)lvd->lv_name))) {
 		stack;
 		return 0;
 	}
@@ -342,10 +340,10 @@
 		       struct logical_volume *lv, const char *dev_dir)
 {
 	memset(lvd, 0, sizeof(*lvd));
-	snprintf(lvd->lv_name, sizeof(lvd->lv_name), "%s%s/%s",
+	snprintf((char *)lvd->lv_name, sizeof(lvd->lv_name), "%s%s/%s",
 		 dev_dir, vg->name, lv->name);
 
-	strcpy(lvd->vg_name, vg->name);
+	strcpy((char *)lvd->vg_name, vg->name);
 
 	if (lv->status & LVM_READ)
 		lvd->lv_access |= LV_READ;
@@ -416,7 +414,7 @@
 
 int import_pvs(const struct format_type *fmt, struct dm_pool *mem,
 	       struct volume_group *vg,
-	       struct list *pvds, struct list *results, int *count)
+	       struct list *pvds, struct list *results, uint32_t *count)
 {
 	struct disk_list *dl;
 	struct pv_list *pvl;
@@ -478,7 +476,7 @@
 		list_iterate_items(ll, &dl->lvds) {
 			lvd = &ll->lvd;
 
-			if (!find_lv(vg, lvd->lv_name) &&
+			if (!find_lv(vg, (char *)lvd->lv_name) &&
 			    !_add_lv(mem, vg, lvd)) {
 				stack;
 				return 0;
@@ -586,14 +584,14 @@
 
 			lvnum = lvd->lv_number;
 
-			if (lvnum > MAX_LV) {
+			if (lvnum >= MAX_LV) {
 				log_err("Logical volume number "
 					"out of bounds.");
 				return 0;
 			}
 
 			if (!lvs[lvnum] &&
-			    !(lvs[lvnum] = find_lv(vg, lvd->lv_name))) {
+			    !(lvs[lvnum] = find_lv(vg, (char *)lvd->lv_name))) {
 				log_err("Couldn't find logical volume '%s'.",
 					lvd->lv_name);
 				return 0;

Modified: lvm2/trunk/lib/format1/import-extents.c
==============================================================================
--- lvm2/trunk/lib/format1/import-extents.c	(original)
+++ lvm2/trunk/lib/format1/import-extents.c	Sat Jun 10 21:40:06 2006
@@ -93,7 +93,7 @@
 	memset(lvs, 0, sizeof(*lvs) * MAX_LV);
 
 	list_iterate_items(ll, &dl->lvds) {
-		if (!(lvm = dm_hash_lookup(maps, strrchr(ll->lvd.lv_name, '/')
+		if (!(lvm = dm_hash_lookup(maps, strrchr((char *)ll->lvd.lv_name, '/')
 					+ 1))) {
 			log_err("Physical volume (%s) contains an "
 				"unknown logical volume (%s).",

Modified: lvm2/trunk/lib/format1/lvm1-label.c
==============================================================================
--- lvm2/trunk/lib/format1/lvm1-label.c	(original)
+++ lvm2/trunk/lib/format1/lvm1-label.c	Sat Jun 10 21:40:06 2006
@@ -61,16 +61,16 @@
 	struct vg_disk vgd;
 	struct lvmcache_info *info;
 	const char *vgid = NULL;
-	int exported = 0;
+	unsigned exported = 0;
 
 	munge_pvd(dev, pvd);
 
 	if (*pvd->vg_name && read_vgd(dev, &vgd, pvd)) {
-		vgid = vgd.vg_uuid;
+		vgid = (char *) vgd.vg_uuid;
 		exported = pvd->pv_status & VG_EXPORTED;
 	}
 
-	if (!(info = lvmcache_add(l, pvd->pv_uuid, dev, pvd->vg_name, vgid,
+	if (!(info = lvmcache_add(l, (char *)pvd->pv_uuid, dev, (char *)pvd->vg_name, vgid,
 				  exported))) {
 		stack;
 		return 0;
@@ -103,13 +103,13 @@
 }
 
 struct label_ops _lvm1_ops = {
-	can_handle:_lvm1_can_handle,
-	write:_lvm1_write,
-	read:_lvm1_read,
-	verify:_lvm1_can_handle,
-	initialise_label:_lvm1_initialise_label,
-	destroy_label:_lvm1_destroy_label,
-	destroy:_lvm1_destroy
+	.can_handle = _lvm1_can_handle,
+	.write = _lvm1_write,
+	.read = _lvm1_read,
+	.verify = _lvm1_can_handle,
+	.initialise_label = _lvm1_initialise_label,
+	.destroy_label = _lvm1_destroy_label,
+	.destroy = _lvm1_destroy,
 };
 
 struct labeller *lvm1_labeller_create(struct format_type *fmt)

Modified: lvm2/trunk/lib/format1/vg_number.c
==============================================================================
--- lvm2/trunk/lib/format1/vg_number.c	(original)
+++ lvm2/trunk/lib/format1/vg_number.c	Sat Jun 10 21:40:06 2006
@@ -46,7 +46,7 @@
 	memset(numbers, 0, sizeof(numbers));
 
 	list_iterate_items(dl, &all_pvs) {
-		if (!*dl->pvd.vg_name || !strcmp(dl->pvd.vg_name, candidate_vg))
+		if (!*dl->pvd.vg_name || !strcmp((char *)dl->pvd.vg_name, candidate_vg))
 			continue;
 
 		numbers[dl->vgd.vg_number] = 1;

Modified: lvm2/trunk/lib/format_pool/disk_rep.c
==============================================================================
--- lvm2/trunk/lib/format_pool/disk_rep.c	(original)
+++ lvm2/trunk/lib/format_pool/disk_rep.c	Sat Jun 10 21:40:06 2006
@@ -248,7 +248,7 @@
 
 	uint32_t sp_count = 0;
 	uint32_t *sp_devs = NULL;
-	int i;
+	uint32_t i;
 
 	/* FIXME: maybe should return a different error in memory
 	 * allocation failure */

Modified: lvm2/trunk/lib/format_pool/format_pool.c
==============================================================================
--- lvm2/trunk/lib/format_pool/format_pool.c	(original)
+++ lvm2/trunk/lib/format_pool/format_pool.c	Sat Jun 10 21:40:06 2006
@@ -79,7 +79,8 @@
 
 static int _check_usp(char *vgname, struct user_subpool *usp, int sp_count)
 {
-	int i, j;
+	int i;
+	unsigned j;
 
 	for (i = 0; i < sp_count; i++) {
 		if (!usp[i].initialized) {
@@ -88,7 +89,7 @@
 		}
 		for (j = 0; j < usp[i].num_devs; j++) {
 			if (!usp[i].devs[j].initialized) {
-				log_error("Missing device %d for subpool %d"
+				log_error("Missing device %u for subpool %d"
 					  " in pool %s", j, i, vgname);
 				return 0;
 			}
@@ -262,7 +263,7 @@
 
 /* *INDENT-OFF* */
 static struct metadata_area_ops _metadata_format_pool_ops = {
-	vg_read:_pool_vg_read,
+	.vg_read = _pool_vg_read,
 };
 /* *INDENT-ON* */
 
@@ -310,11 +311,11 @@
 
 /* *INDENT-OFF* */
 static struct format_handler _format_pool_ops = {
-	pv_read:_pool_pv_read,
-	pv_setup:_pool_pv_setup,
-	create_instance:_pool_create_instance,
-	destroy_instance:_pool_destroy_instance,
-	destroy:_pool_destroy,
+	.pv_read = _pool_pv_read,
+	.pv_setup = _pool_pv_setup,
+	.create_instance = _pool_create_instance,
+	.destroy_instance = _pool_destroy_instance,
+	.destroy = _pool_destroy,
 };
 /* *INDENT-ON */
 

Modified: lvm2/trunk/lib/format_pool/import_export.c
==============================================================================
--- lvm2/trunk/lib/format_pool/import_export.c	(original)
+++ lvm2/trunk/lib/format_pool/import_export.c	Sat Jun 10 21:40:06 2006
@@ -203,7 +203,7 @@
 {
 	struct lv_segment *seg;
 	struct segment_type *segtype;
-	int j;
+	unsigned j;
 	uint32_t area_len;
 
 	if (usp->striping & (usp->striping - 1)) {
@@ -249,7 +249,7 @@
 {
 	struct lv_segment *seg;
 	struct segment_type *segtype;
-	int j;
+	unsigned j;
 	uint32_t area_len;
 
 	if (!(segtype = get_segtype_from_string(lv->vg->cmd, "striped"))) {

Modified: lvm2/trunk/lib/format_pool/pool_label.c
==============================================================================
--- lvm2/trunk/lib/format_pool/pool_label.c	(original)
+++ lvm2/trunk/lib/format_pool/pool_label.c	Sat Jun 10 21:40:06 2006
@@ -82,13 +82,13 @@
 }
 
 struct label_ops _pool_ops = {
-      can_handle:_pool_can_handle,
-      write:_pool_write,
-      read:_pool_read,
-      verify:_pool_can_handle,
-      initialise_label:_pool_initialise_label,
-      destroy_label:_pool_destroy_label,
-      destroy:_label_pool_destroy
+      .can_handle = _pool_can_handle,
+      .write = _pool_write,
+      .read = _pool_read,
+      .verify = _pool_can_handle,
+      .initialise_label = _pool_initialise_label,
+      .destroy_label = _pool_destroy_label,
+      .destroy = _label_pool_destroy,
 };
 
 struct labeller *pool_labeller_create(struct format_type *fmt)

Modified: lvm2/trunk/lib/format_text/archive.c
==============================================================================
--- lvm2/trunk/lib/format_text/archive.c	(original)
+++ lvm2/trunk/lib/format_text/archive.c	Sat Jun 10 21:40:06 2006
@@ -328,7 +328,7 @@
 	}
 
 	log_print("VG name:    \t%s", vg->name);
-	log_print("Description:\t%s", desc ? desc : "<No description>");
+	log_print("Description:\t%s", desc ? : "<No description>");
 	log_print("Backup Time:\t%s", ctime(&when));
 
 	dm_pool_free(cmd->mem, vg);

Modified: lvm2/trunk/lib/format_text/export.c
==============================================================================
--- lvm2/trunk/lib/format_text/export.c	(original)
+++ lvm2/trunk/lib/format_text/export.c	Sat Jun 10 21:40:06 2006
@@ -183,7 +183,8 @@
 	return 1;
 }
 
-static int _out_with_comment_raw(struct formatter *f, const char *comment,
+static int _out_with_comment_raw(struct formatter *f,
+				 const char *comment __attribute((unused)),
 				 const char *fmt, va_list ap)
 {
 	int n;
@@ -281,7 +282,7 @@
 }
 
 static int _print_header(struct formatter *f,
-			 struct volume_group *vg, const char *desc)
+			 const char *desc)
 {
 	time_t t;
 
@@ -665,7 +666,7 @@
 	}
 #define fail do {stack; goto out;} while(0)
 
-	if (f->header && !_print_header(f, vg, desc))
+	if (f->header && !_print_header(f, desc))
 		fail;
 
 	if (!out_text(f, "%s {", vg->name))
@@ -688,7 +689,7 @@
 	if (!out_text(f, "}"))
 		fail;
 
-	if (!f->header && !_print_header(f, vg, desc))
+	if (!f->header && !_print_header(f, desc))
 		fail;
 
 #undef fail

Modified: lvm2/trunk/lib/format_text/flags.c
==============================================================================
--- lvm2/trunk/lib/format_text/flags.c	(original)
+++ lvm2/trunk/lib/format_text/flags.c	Sat Jun 10 21:40:06 2006
@@ -53,6 +53,7 @@
 	{VISIBLE_LV, "VISIBLE"},
 	{PVMOVE, "PVMOVE"},
 	{LOCKED, "LOCKED"},
+	{MIRROR_NOTSYNCED, "NOTSYNCED"},
 	{MIRROR_IMAGE, NULL},
 	{MIRROR_LOG, NULL},
 	{MIRRORED, NULL},

Modified: lvm2/trunk/lib/format_text/format-text.c
==============================================================================
--- lvm2/trunk/lib/format_text/format-text.c	(original)
+++ lvm2/trunk/lib/format_text/format-text.c	Sat Jun 10 21:40:06 2006
@@ -69,7 +69,8 @@
  * NOTE: Currently there can be only one vg per text file.
  */
 
-static int _text_vg_setup(struct format_instance *fid, struct volume_group *vg)
+static int _text_vg_setup(struct format_instance *fid __attribute((unused)),
+			  struct volume_group *vg)
 {
 	if (vg->extent_size & (vg->extent_size - 1)) {
 		log_error("Extent size must be power of 2");
@@ -79,13 +80,14 @@
 	return 1;
 }
 
-static int _text_lv_setup(struct format_instance *fid, struct logical_volume *lv)
+static int _text_lv_setup(struct format_instance *fid __attribute((unused)),
+			  struct logical_volume *lv)
 {
 /******** FIXME Any LV size restriction? 
 	uint64_t max_size = UINT_MAX;
 
 	if (lv->size > max_size) {
-		char *dummy = display_size(max_size, SIZE_SHORT);
+		char *dummy = display_size(max_size);
 		log_error("logical volumes cannot be larger than %s", dummy);
 		dm_free(dummy);
 		return 0;
@@ -143,7 +145,7 @@
 
 	_xlate_mdah(mdah);
 
-	if (strncmp(mdah->magic, FMTT_MAGIC, sizeof(mdah->magic))) {
+	if (strncmp((char *)mdah->magic, FMTT_MAGIC, sizeof(mdah->magic))) {
 		log_error("Wrong magic number in metadata area header");
 		return NULL;
 	}
@@ -167,7 +169,7 @@
 				 struct device *dev,
 				 uint64_t start_byte, struct mda_header *mdah)
 {
-	strncpy(mdah->magic, FMTT_MAGIC, sizeof(mdah->magic));
+	strncpy((char *)mdah->magic, FMTT_MAGIC, sizeof(mdah->magic));
 	mdah->version = FMTT_VERSION;
 	mdah->start = start_byte;
 
@@ -1071,9 +1073,9 @@
 		if (!add_mda(fmt, fmt->cmd->mem, mdas, pv->dev, start1,
 			     mda_size1)) return 0;
 
-		if (!dev_zero((struct device *) pv->dev, start1,
-			      (size_t) (mda_size1 >
-					wipe_size ? wipe_size : mda_size1))) {
+		if (!dev_set((struct device *) pv->dev, start1,
+			     (size_t) (mda_size1 >
+				       wipe_size ? : mda_size1), 0)) {
 			log_error("Failed to wipe new metadata area");
 			return 0;
 		}
@@ -1117,9 +1119,9 @@
 	if (mda_size2) {
 		if (!add_mda(fmt, fmt->cmd->mem, mdas, pv->dev, start2,
 			     mda_size2)) return 0;
-		if (!dev_zero(pv->dev, start2,
-			      (size_t) (mda_size1 >
-					wipe_size ? wipe_size : mda_size1))) {
+		if (!dev_set(pv->dev, start2,
+			     (size_t) (mda_size1 >
+				       wipe_size ? : mda_size1), 0)) {
 			log_error("Failed to wipe new metadata area");
 			return 0;
 		}
@@ -1202,7 +1204,7 @@
 		}
 	}
 	if (!add_da
-	    (fmt, NULL, &info->das, pv->pe_start << SECTOR_SHIFT, UINT64_C(0))) {
+	    (NULL, &info->das, pv->pe_start << SECTOR_SHIFT, UINT64_C(0))) {
 		stack;
 		return 0;
 	}
@@ -1339,7 +1341,7 @@
 	return 1;
 }
 
-static void _text_destroy_instance(struct format_instance *fid)
+static void _text_destroy_instance(struct format_instance *fid __attribute((unused)))
 {
 	return;
 }
@@ -1372,32 +1374,32 @@
 		dm_free(fmt->private);
 	}
 
-	dm_free((void *) fmt);
+	dm_free((void *)fmt);
 }
 
 static struct metadata_area_ops _metadata_text_file_ops = {
-	vg_read:_vg_read_file,
-	vg_read_precommit:_vg_read_precommit_file,
-	vg_write:_vg_write_file,
-	vg_remove:_vg_remove_file,
-	vg_commit:_vg_commit_file
+	.vg_read = _vg_read_file,
+	.vg_read_precommit = _vg_read_precommit_file,
+	.vg_write = _vg_write_file,
+	.vg_remove = _vg_remove_file,
+	.vg_commit = _vg_commit_file
 };
 
 static struct metadata_area_ops _metadata_text_file_backup_ops = {
-	vg_read:_vg_read_file,
-	vg_write:_vg_write_file,
-	vg_remove:_vg_remove_file,
-	vg_commit:_vg_commit_file_backup
+	.vg_read = _vg_read_file,
+	.vg_write = _vg_write_file,
+	.vg_remove = _vg_remove_file,
+	.vg_commit = _vg_commit_file_backup
 };
 
 static struct metadata_area_ops _metadata_text_raw_ops = {
-	vg_read:_vg_read_raw,
-	vg_read_precommit:_vg_read_precommit_raw,
-	vg_write:_vg_write_raw,
-	vg_remove:_vg_remove_raw,
-	vg_precommit:_vg_precommit_raw,
-	vg_commit:_vg_commit_raw,
-	vg_revert:_vg_revert_raw
+	.vg_read = _vg_read_raw,
+	.vg_read_precommit = _vg_read_precommit_raw,
+	.vg_write = _vg_write_raw,
+	.vg_remove = _vg_remove_raw,
+	.vg_precommit = _vg_precommit_raw,
+	.vg_commit = _vg_commit_raw,
+	.vg_revert = _vg_revert_raw
 };
 
 /* pvmetadatasize in sectors */
@@ -1656,15 +1658,15 @@
 }
 
 static struct format_handler _text_handler = {
-	scan:_text_scan,
-	pv_read:_text_pv_read,
-	pv_setup:_text_pv_setup,
-	pv_write:_text_pv_write,
-	vg_setup:_text_vg_setup,
-	lv_setup:_text_lv_setup,
-	create_instance:_text_create_text_instance,
-	destroy_instance:_text_destroy_instance,
-	destroy:_text_destroy
+	.scan = _text_scan,
+	.pv_read = _text_pv_read,
+	.pv_setup = _text_pv_setup,
+	.pv_write = _text_pv_write,
+	.vg_setup = _text_vg_setup,
+	.lv_setup = _text_lv_setup,
+	.create_instance = _text_create_text_instance,
+	.destroy_instance = _text_destroy_instance,
+	.destroy = _text_destroy
 };
 
 static int _add_dir(const char *dir, struct list *dir_list)
@@ -1754,10 +1756,12 @@
 	fmt->name = FMT_TEXT_NAME;
 	fmt->alias = FMT_TEXT_ALIAS;
 	fmt->features = FMT_SEGMENTS | FMT_MDAS | FMT_TAGS | FMT_PRECOMMIT |
-			FMT_UNLIMITED_VOLS | FMT_RESIZE_PV;
+			FMT_UNLIMITED_VOLS | FMT_RESIZE_PV |
+			FMT_UNLIMITED_STRIPESIZE;
 
 	if (!(mda_lists = dm_malloc(sizeof(struct mda_lists)))) {
 		log_error("Failed to allocate dir_list");
+		dm_free(fmt);
 		return NULL;
 	}
 
@@ -1769,11 +1773,13 @@
 
 	if (!(fmt->labeller = text_labeller_create(fmt))) {
 		log_error("Couldn't create text label handler.");
+		dm_free(fmt);
 		return NULL;
 	}
 
 	if (!(label_register_handler(FMT_TEXT_NAME, fmt->labeller))) {
 		log_error("Couldn't register text label handler.");
+		dm_free(fmt);
 		return NULL;
 	}
 

Modified: lvm2/trunk/lib/format_text/format-text.h
==============================================================================
--- lvm2/trunk/lib/format_text/format-text.h	(original)
+++ lvm2/trunk/lib/format_text/format-text.h	Sat Jun 10 21:40:06 2006
@@ -46,7 +46,7 @@
 
 int pvhdr_read(struct device *dev, char *buf);
 
-int add_da(const struct format_type *fmt, struct dm_pool *mem, struct list *das,
+int add_da(struct dm_pool *mem, struct list *das,
 	   uint64_t start, uint64_t size);
 void del_das(struct list *das);
 

Modified: lvm2/trunk/lib/format_text/import.c
==============================================================================
--- lvm2/trunk/lib/format_text/import.c	(original)
+++ lvm2/trunk/lib/format_text/import.c	Sat Jun 10 21:40:06 2006
@@ -33,7 +33,7 @@
 {
 	struct config_tree *cft;
 	struct text_vg_version_ops **vsn;
-	const char *vgname;
+	const char *vgname = NULL;
 
 	static int _text_import_initialised = 0;
 
@@ -44,7 +44,7 @@
 	}
 
 	if (!(cft = create_config_tree(NULL)))
-		goto_out;
+		return_NULL;
 
 	if ((!dev && !read_config_file(cft)) ||
 	    (dev && !read_config_fd(cft, dev, offset, size,
@@ -94,10 +94,8 @@
 	*desc = NULL;
 	*when = 0;
 
-	if (!(cft = create_config_tree(file))) {
-		stack;
-		goto out;
-	}
+	if (!(cft = create_config_tree(file)))
+		return_NULL;
 
 	if ((!dev && !read_config_file(cft)) ||
 	    (dev && !read_config_fd(cft, dev, offset, size,
@@ -131,6 +129,6 @@
 					 const char *file,
 					 time_t *when, char **desc)
 {
-	return text_vg_import_fd(fid, file, NULL, 0, 0, 0, 0, NULL, 0,
+	return text_vg_import_fd(fid, file, NULL, (off_t)0, 0, (off_t)0, 0, NULL, 0,
 				 when, desc);
 }

Modified: lvm2/trunk/lib/format_text/import_vsn1.c
==============================================================================
--- lvm2/trunk/lib/format_text/import_vsn1.c	(original)
+++ lvm2/trunk/lib/format_text/import_vsn1.c	Sat Jun 10 21:40:06 2006
@@ -370,7 +370,7 @@
 		} else {
 			log_error("Couldn't find volume '%s' "
 				  "for segment '%s'.",
-				  cv->v.str ? cv->v.str : "NULL", seg_name);
+				  cv->v.str ? : "NULL", seg_name);
 			return 0;
 		}
 
@@ -849,13 +849,13 @@
 }
 
 static struct text_vg_version_ops _vsn1_ops = {
-	check_version:_check_version,
-	read_vg:_read_vg,
-	read_desc:_read_desc,
-	read_vgname:_read_vgname
+	.check_version = _check_version,
+	.read_vg = _read_vg,
+	.read_desc = _read_desc,
+	.read_vgname = _read_vgname,
 };
 
 struct text_vg_version_ops *text_vg_vsn1_init(void)
 {
 	return &_vsn1_ops;
-};
+}

Modified: lvm2/trunk/lib/format_text/layout.h
==============================================================================
--- lvm2/trunk/lib/format_text/layout.h	(original)
+++ lvm2/trunk/lib/format_text/layout.h	Sat Jun 10 21:40:06 2006
@@ -36,7 +36,7 @@
 /* Fields with the suffix _xl should be xlate'd wherever they appear */
 /* On disk */
 struct pv_header {
-	uint8_t pv_uuid[ID_LEN];
+	int8_t pv_uuid[ID_LEN];
 
 	/* This size can be overridden if PV belongs to a VG */
 	uint64_t device_size_xl;	/* Bytes */
@@ -58,7 +58,7 @@
 /* Structure size limited to one sector */
 struct mda_header {
 	uint32_t checksum_xl;	/* Checksum of rest of mda_header */
-	uint8_t magic[16];	/* To aid scans for metadata */
+	int8_t magic[16];	/* To aid scans for metadata */
 	uint32_t version;
 	uint64_t start;		/* Absolute start byte of mda_header */
 	uint64_t size;		/* Size of metadata area */
@@ -83,6 +83,6 @@
 #define FMTT_VERSION 1
 #define MDA_HEADER_SIZE 512
 #define LVM2_LABEL "LVM2 001"
-#define MDA_SIZE_MIN (8 * getpagesize())
+#define MDA_SIZE_MIN (8 * (unsigned) getpagesize())
 
 #endif

Modified: lvm2/trunk/lib/format_text/text_label.c
==============================================================================
--- lvm2/trunk/lib/format_text/text_label.c	(original)
+++ lvm2/trunk/lib/format_text/text_label.c	Sat Jun 10 21:40:06 2006
@@ -23,11 +23,13 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 
-static int _text_can_handle(struct labeller *l, char *buf, uint64_t sector)
+static int _text_can_handle(struct labeller *l __attribute((unused)),
+			    char *buf,
+			    uint64_t sector __attribute((unused)))
 {
 	struct label_header *lh = (struct label_header *) buf;
 
-	if (!strncmp(lh->type, LVM2_LABEL, sizeof(lh->type)))
+	if (!strncmp((char *)lh->type, LVM2_LABEL, sizeof(lh->type)))
 		return 1;
 
 	return 0;
@@ -46,7 +48,7 @@
 	/* FIXME Move to where label is created */
 	strncpy(label->type, LVM2_LABEL, sizeof(label->type));
 
-	strncpy(lh->type, label->type, sizeof(label->type));
+	strncpy((char *)lh->type, label->type, sizeof(label->type));
 
 	pvhdr = (struct pv_header *) ((void *) buf + xlate32(lh->offset_xl));
 	info = (struct lvmcache_info *) label->info;
@@ -86,7 +88,7 @@
 	return 1;
 }
 
-int add_da(const struct format_type *fmt, struct dm_pool *mem, struct list *das,
+int add_da(struct dm_pool *mem, struct list *das,
 	   uint64_t start, uint64_t size)
 {
 	struct data_area_list *dal;
@@ -179,7 +181,8 @@
 	}
 }
 
-static int _text_initialise_label(struct labeller *l, struct label *label)
+static int _text_initialise_label(struct labeller *l __attribute((unused)),
+				  struct label *label)
 {
 	strncpy(label->type, LVM2_LABEL, sizeof(label->type));
 
@@ -203,7 +206,7 @@
 
 	pvhdr = (struct pv_header *) ((void *) buf + xlate32(lh->offset_xl));
 
-	if (!(info = lvmcache_add(l, pvhdr->pv_uuid, dev, NULL, NULL, 0)))
+	if (!(info = lvmcache_add(l, (char *)pvhdr->pv_uuid, dev, NULL, NULL, 0)))
 		return_0;
 	*label = info->label;
 
@@ -220,7 +223,7 @@
 	/* Data areas holding the PEs */
 	dlocn_xl = pvhdr->disk_areas_xl;
 	while ((offset = xlate64(dlocn_xl->offset))) {
-		add_da(info->fmt, NULL, &info->das, offset,
+		add_da(NULL, &info->das, offset,
 		       xlate64(dlocn_xl->size));
 		dlocn_xl++;
 	}
@@ -248,7 +251,8 @@
 	return 1;
 }
 
-static void _text_destroy_label(struct labeller *l, struct label *label)
+static void _text_destroy_label(struct labeller *l __attribute((unused)),
+				struct label *label)
 {
 	struct lvmcache_info *info = (struct lvmcache_info *) label->info;
 
@@ -264,13 +268,13 @@
 }
 
 struct label_ops _text_ops = {
-	can_handle:_text_can_handle,
-	write:_text_write,
-	read:_text_read,
-	verify:_text_can_handle,
-	initialise_label:_text_initialise_label,
-	destroy_label:_text_destroy_label,
-	destroy:_fmt_text_destroy
+	.can_handle = _text_can_handle,
+	.write = _text_write,
+	.read = _text_read,
+	.verify = _text_can_handle,
+	.initialise_label = _text_initialise_label,
+	.destroy_label = _text_destroy_label,
+	.destroy = _fmt_text_destroy,
 };
 
 struct labeller *text_labeller_create(const struct format_type *fmt)

Modified: lvm2/trunk/lib/label/label.c
==============================================================================
--- lvm2/trunk/lib/label/label.c	(original)
+++ lvm2/trunk/lib/label/label.c	Sat Jun 10 21:40:06 2006
@@ -128,7 +128,7 @@
 		lh = (struct label_header *) (readbuf +
 					      (sector << SECTOR_SHIFT));
 
-		if (!strncmp(lh->id, LABEL_ID, sizeof(lh->id))) {
+		if (!strncmp((char *)lh->id, LABEL_ID, sizeof(lh->id))) {
 			if (found) {
 				log_error("Ignoring additional label on %s at "
 					  "sector %" PRIu64, dev_name(dev),
@@ -222,7 +222,7 @@
 
 		wipe = 0;
 
-		if (!strncmp(lh->id, LABEL_ID, sizeof(lh->id))) {
+		if (!strncmp((char *)lh->id, LABEL_ID, sizeof(lh->id))) {
 			if (xlate64(lh->sector_xl) == sector)
 				wipe = 1;
 		} else {
@@ -307,7 +307,7 @@
 
 	memset(buf, 0, LABEL_SIZE);
 
-	strncpy(lh->id, LABEL_ID, sizeof(lh->id));
+	strncpy((char *)lh->id, LABEL_ID, sizeof(lh->id));
 	lh->sector_xl = xlate64(label->sector);
 	lh->offset_xl = xlate32(sizeof(*lh));
 

Modified: lvm2/trunk/lib/label/label.h
==============================================================================
--- lvm2/trunk/lib/label/label.h	(original)
+++ lvm2/trunk/lib/label/label.h	Sat Jun 10 21:40:06 2006
@@ -28,11 +28,11 @@
 
 /* On disk - 32 bytes */
 struct label_header {
-	uint8_t id[8];		/* LABELONE */
+	int8_t id[8];		/* LABELONE */
 	uint64_t sector_xl;	/* Sector number of this label */
 	uint32_t crc_xl;	/* From next field to end of sector */
 	uint32_t offset_xl;	/* Offset from start of struct to contents */
-	uint8_t type[8];	/* LVM2 001 */
+	int8_t type[8];		/* LVM2 001 */
 } __attribute__ ((packed));
 
 /* In core */

Modified: lvm2/trunk/lib/locking/cluster_locking.c
==============================================================================
--- lvm2/trunk/lib/locking/cluster_locking.c	(original)
+++ lvm2/trunk/lib/locking/cluster_locking.c	Sat Jun 10 21:40:06 2006
@@ -333,6 +333,12 @@
 	if (partial_mode())
 		args[1] |= LCK_PARTIAL_MODE;
 
+	if (mirror_in_sync())
+		args[1] |= LCK_MIRROR_NOSYNC_MODE;
+
+	if (dmeventd_register_mode())
+		args[1] |= LCK_DMEVENTD_REGISTER_MODE;
+
 	/*
 	 * VG locks are just that: locks, and have no side effects
 	 * so we only need to do them on the local node because all
@@ -386,11 +392,12 @@
 	int cluster_cmd = 0;
 
 	assert(strlen(resource) < sizeof(lockname));
+	assert(resource);
 
 	switch (flags & LCK_SCOPE_MASK) {
 	case LCK_VG:
 		/* If the VG name is empty then lock the unused PVs */
-		if (!resource || !*resource)
+		if (!*resource)
 			lvm_snprintf(lockname, sizeof(lockname), "P_orphans");
 		else
 			lvm_snprintf(lockname, sizeof(lockname), "V_%s",

Modified: lvm2/trunk/lib/locking/file_locking.c
==============================================================================
--- lvm2/trunk/lib/locking/file_locking.c	(original)
+++ lvm2/trunk/lib/locking/file_locking.c	Sat Jun 10 21:40:06 2006
@@ -105,7 +105,7 @@
 		log_sys_error("signal", "_remove_ctrl_c_handler");
 }
 
-static void _trap_ctrl_c(int sig)
+static void _trap_ctrl_c(int sig __attribute((unused)))
 {
 	_remove_ctrl_c_handler();
 	log_error("CTRL-c detected: giving up waiting for lock");
@@ -207,9 +207,11 @@
 {
 	char lockfile[PATH_MAX];
 
+	assert(resource);
+
 	switch (flags & LCK_SCOPE_MASK) {
 	case LCK_VG:
-		if (!resource || !*resource)
+		if (!*resource)
 			lvm_snprintf(lockfile, sizeof(lockfile),
 				     "%s/P_orphans", _lock_dir);
 		else

Modified: lvm2/trunk/lib/locking/locking.c
==============================================================================
--- lvm2/trunk/lib/locking/locking.c	(original)
+++ lvm2/trunk/lib/locking/locking.c	Sat Jun 10 21:40:06 2006
@@ -33,7 +33,7 @@
 static int _vg_write_lock_held = 0;	/* VG write lock held? */
 static int _signals_blocked = 0;
 
-static void _block_signals(int flags)
+static void _block_signals(int flags __attribute((unused)))
 {
 	sigset_t set;
 

Modified: lvm2/trunk/lib/locking/locking.h
==============================================================================
--- lvm2/trunk/lib/locking/locking.h	(original)
+++ lvm2/trunk/lib/locking/locking.h	Sat Jun 10 21:40:06 2006
@@ -13,6 +13,9 @@
  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#ifndef _LVM_LOCKING_H
+#define _LVM_LOCKING_H
+
 #include "uuid.h"
 #include "config.h"
 
@@ -71,6 +74,9 @@
  * Additional lock bits for cluster communication
  */
 #define LCK_PARTIAL_MODE	0x00000001	/* Running in partial mode */
+#define LCK_MIRROR_NOSYNC_MODE	0x00000002	/* Mirrors don't require sync */
+#define LCK_DMEVENTD_REGISTER_MODE	0x00000004	/* Register with dmeventd */
+
 
 /*
  * Common combinations
@@ -109,3 +115,4 @@
 int resume_lvs(struct cmd_context *cmd, struct list *lvs);
 int activate_lvs_excl(struct cmd_context *cmd, struct list *lvs);
 
+#endif

Modified: lvm2/trunk/lib/log/log.c
==============================================================================
--- lvm2/trunk/lib/log/log.c	(original)
+++ lvm2/trunk/lib/log/log.c	Sat Jun 10 21:40:06 2006
@@ -17,6 +17,7 @@
 #include "device.h"
 #include "memlock.h"
 #include "lvm-string.h"
+#include "defaults.h"
 
 #include <stdarg.h>
 #include <syslog.h>
@@ -45,6 +46,8 @@
 static char _cmd_name[30] = "";
 static char _msg_prefix[30] = "  ";
 static int _already_logging = 0;
+static int _mirror_in_sync = 0;
+static int _dmeventd_register = DEFAULT_DMEVENTD_MONITOR;
 
 static lvm2_log_fn_t _lvm2_log_fn = NULL;
 
@@ -175,6 +178,16 @@
 	_security_level = level;
 }
 
+void init_mirror_in_sync(int in_sync)
+{
+	_mirror_in_sync = in_sync;
+}
+
+void init_dmeventd_register(int reg)
+{
+	_dmeventd_register = reg;
+}
+
 void init_cmd_name(int status)
 {
 	_log_cmd_name = status;
@@ -239,6 +252,16 @@
 	return _security_level;
 }
 
+int mirror_in_sync(void)
+{
+	return _mirror_in_sync;
+}
+
+int dmeventd_register_mode(void)
+{
+	return _dmeventd_register;
+}
+
 void init_debug(int level)
 {
 	_debug_level = level;

Modified: lvm2/trunk/lib/log/log.h
==============================================================================
--- lvm2/trunk/lib/log/log.h	(original)
+++ lvm2/trunk/lib/log/log.h	Sat Jun 10 21:40:06 2006
@@ -73,6 +73,8 @@
 void init_ignorelockingfailure(int level);
 void init_lockingfailed(int level);
 void init_security_level(int level);
+void init_mirror_in_sync(int in_sync);
+void init_dmeventd_register(int reg);
 
 void set_cmd_name(const char *cmd_name);
 
@@ -85,6 +87,8 @@
 int ignorelockingfailure(void);
 int lockingfailed(void);
 int security_level(void);
+int mirror_in_sync(void);
+int dmeventd_register_mode(void);
 
 /* Suppress messages to stdout/stderr (1) or everywhere (2) */
 /* Returns previous setting */

Modified: lvm2/trunk/lib/metadata/lv_alloc.h
==============================================================================
--- lvm2/trunk/lib/metadata/lv_alloc.h	(original)
+++ lvm2/trunk/lib/metadata/lv_alloc.h	Sat Jun 10 21:40:06 2006
@@ -16,7 +16,7 @@
 #ifndef _LVM_LV_ALLOC_H
 
 struct lv_segment *alloc_lv_segment(struct dm_pool *mem,
-				    struct segment_type *segtype,
+				    const struct segment_type *segtype,
 				    struct logical_volume *lv,
 				    uint32_t le, uint32_t len,
 				    uint32_t status,
@@ -44,7 +44,7 @@
 struct alloc_handle;
 struct alloc_handle *allocate_extents(struct volume_group *vg,
 				      struct logical_volume *lv,
-                                      struct segment_type *segtype,
+                                      const struct segment_type *segtype,
                                       uint32_t stripes,
                                       uint32_t mirrors, uint32_t log_count,
 				      uint32_t extents,
@@ -58,7 +58,7 @@
 int lv_add_segment(struct alloc_handle *ah,
 		   uint32_t first_area, uint32_t num_areas,
 		   struct logical_volume *lv,
-                   struct segment_type *segtype,
+                   const struct segment_type *segtype,
                    uint32_t stripe_size,
                    struct physical_volume *mirrored_pv,
                    uint32_t mirrored_pe,
@@ -68,12 +68,12 @@
 
 int lv_add_log_segment(struct alloc_handle *ah, struct logical_volume *log_lv);
 int lv_add_virtual_segment(struct logical_volume *lv, uint32_t status,
-                           uint32_t extents, struct segment_type *segtype);
+                           uint32_t extents, const struct segment_type *segtype);
 int lv_add_mirror_segment(struct alloc_handle *ah,
 			  struct logical_volume *lv,
 			  struct logical_volume **sub_lvs,
 			  uint32_t mirrors,
-			  struct segment_type *segtype,
+			  const struct segment_type *segtype,
 			  uint32_t status,
 			  uint32_t region_size,
 			  struct logical_volume *log_lv);

Modified: lvm2/trunk/lib/metadata/lv_manip.c
==============================================================================
--- lvm2/trunk/lib/metadata/lv_manip.c	(original)
+++ lvm2/trunk/lib/metadata/lv_manip.c	Sat Jun 10 21:40:06 2006
@@ -66,7 +66,7 @@
  * All lv_segments get created here.
  */
 struct lv_segment *alloc_lv_segment(struct dm_pool *mem,
-				    struct segment_type *segtype,
+				    const struct segment_type *segtype,
 				    struct logical_volume *lv,
 				    uint32_t le, uint32_t len,
 				    uint32_t status,
@@ -124,7 +124,7 @@
 				      uint32_t status, uint32_t old_le_count)
 {
 	struct lv_segment *seg;
-	struct segment_type *segtype;
+	const struct segment_type *segtype;
 
 	segtype = get_segtype_from_string(lv->vg->cmd, "snapshot");
 	if (!segtype) {
@@ -418,7 +418,7 @@
  * Preparation for a specific allocation attempt
  */
 static struct alloc_handle *_alloc_init(struct dm_pool *mem,
-					struct segment_type *segtype,
+					const struct segment_type *segtype,
 					alloc_policy_t alloc,
 					uint32_t mirrors,
 					uint32_t stripes,
@@ -474,8 +474,6 @@
 	ah->alloc = alloc;
 	ah->area_multiple = segtype_is_striped(segtype) ? ah->area_count : 1;
 
-	list_init(&ah->alloced_areas[0]);
-
 	for (s = 0; s < ah->area_count; s++)
 		list_init(&ah->alloced_areas[s]);
 
@@ -495,12 +493,12 @@
 static int _setup_alloced_segment(struct logical_volume *lv, uint32_t status,
 				  uint32_t area_count,
 				  uint32_t stripe_size,
-				  struct segment_type *segtype,
+				  const struct segment_type *segtype,
 				  struct alloced_area *aa,
 				  struct physical_volume *mirrored_pv,
 				  uint32_t mirrored_pe,
 				  uint32_t region_size,
-				  struct logical_volume *log_lv)
+				  struct logical_volume *log_lv __attribute((unused)))
 {
 	uint32_t s, extents, area_multiple, extra_areas = 0;
 	struct lv_segment *seg;
@@ -553,7 +551,7 @@
 				   uint32_t area_count,
 				   uint32_t status,
 				   uint32_t stripe_size,
-				   struct segment_type *segtype,
+				   const struct segment_type *segtype,
 				   struct physical_volume *mirrored_pv,
 				   uint32_t mirrored_pe,
 				   uint32_t region_size,
@@ -825,7 +823,7 @@
 		     uint32_t new_extents,
 		     struct list *allocatable_pvs,
 		     uint32_t stripes, uint32_t mirrors,
-		     struct segment_type *segtype)
+		     const struct segment_type *segtype)
 {
 	struct pv_area **areas;
 	uint32_t allocated = lv ? lv->le_count : 0;
@@ -927,7 +925,7 @@
 }
 
 int lv_add_virtual_segment(struct logical_volume *lv, uint32_t status,
-			   uint32_t extents, struct segment_type *segtype)
+			   uint32_t extents, const struct segment_type *segtype)
 {
 	struct lv_segment *seg;
 
@@ -953,7 +951,7 @@
  */
 struct alloc_handle *allocate_extents(struct volume_group *vg,
 				      struct logical_volume *lv,
-				      struct segment_type *segtype,
+				      const struct segment_type *segtype,
 				      uint32_t stripes,
 				      uint32_t mirrors, uint32_t log_count,
 				      uint32_t extents,
@@ -1008,7 +1006,7 @@
 int lv_add_segment(struct alloc_handle *ah,
 		   uint32_t first_area, uint32_t num_areas,
 		   struct logical_volume *lv,
-		   struct segment_type *segtype,
+		   const struct segment_type *segtype,
 		   uint32_t stripe_size,
 		   struct physical_volume *mirrored_pv,
 		   uint32_t mirrored_pe,
@@ -1096,7 +1094,7 @@
 			  struct logical_volume *lv,
 			  struct logical_volume **sub_lvs,
 			  uint32_t mirrors,
-			  struct segment_type *segtype,
+			  const struct segment_type *segtype,
 			  uint32_t status,
 			  uint32_t region_size,
 			  struct logical_volume *log_lv)
@@ -1104,7 +1102,7 @@
 	struct lv_segment *seg;
 	uint32_t m;
 
-	if (list_empty(&log_lv->segments)) {
+	if (log_lv && list_empty(&log_lv->segments)) {
 		log_error("Log LV %s is empty.", log_lv->name);
 		return 0;
 	}
@@ -1177,7 +1175,7 @@
  * Entry point for single-step LV allocation + extension.
  */
 int lv_extend(struct logical_volume *lv,
-	      struct segment_type *segtype,
+	      const struct segment_type *segtype,
 	      uint32_t stripes, uint32_t stripe_size,
 	      uint32_t mirrors, uint32_t extents,
 	      struct physical_volume *mirrored_pv, uint32_t mirrored_pe,

Modified: lvm2/trunk/lib/metadata/metadata.c
==============================================================================
--- lvm2/trunk/lib/metadata/metadata.c	(original)
+++ lvm2/trunk/lib/metadata/metadata.c	Sat Jun 10 21:40:06 2006
@@ -60,7 +60,7 @@
 	}
 
 	/* Ensure PV doesn't depend on another PV already in the VG */
-	if (pv_uses_vg(fid->fmt->cmd, pv, vg)) {
+	if (pv_uses_vg(pv, vg)) {
 		log_error("Physical volume %s might be constructed from same "
 			  "volume group %s", pv_name, vg->name);
 		return 0;
@@ -266,7 +266,10 @@
 	vg->seqno = 0;
 
 	vg->status = (RESIZEABLE_VG | LVM_READ | LVM_WRITE);
-	vg->system_id = dm_pool_alloc(mem, NAME_LEN);
+	if (!(vg->system_id = dm_pool_alloc(mem, NAME_LEN))) {
+		stack;
+		goto bad;
+	}
 	*vg->system_id = '\0';
 
 	vg->extent_size = extent_size;
@@ -919,6 +922,8 @@
 	struct metadata_area *mda;
 	int inconsistent = 0;
 	int use_precommitted = precommitted;
+	struct list *pvids;
+	struct pv_list *pvl;
 
 	if (!*vgname) {
 		if (use_precommitted) {
@@ -950,6 +955,12 @@
 	if (use_precommitted && !(fmt->features & FMT_PRECOMMIT))
 		use_precommitted = 0;
 
+	/* Store pvids for later so we can check if any are missing */
+	if (!(pvids = lvmcache_get_pvids(cmd, vgname, vgid))) {
+		stack;
+		return NULL;
+	}
+
 	/* create format instance with appropriate metadata area */
 	if (!(fid = fmt->ops->create_instance(fmt, vgname, vgid, NULL))) {
 		log_error("Failed to create format instance");
@@ -977,6 +988,22 @@
 		}
 	}
 
+	/* Ensure every PV in the VG was in the cache */
+	if (correct_vg) {
+		if (list_size(&correct_vg->pvs) != list_size(pvids)) {
+			log_debug("Cached VG %s had incorrect PV list",
+				  vg->name);
+			correct_vg = NULL;
+		} else list_iterate_items(pvl, &correct_vg->pvs) {
+			if (!str_list_match_item(pvids, pvl->pv->dev->pvid)) {
+				log_debug("Cached VG %s had incorrect PV list",
+					  vg->name);
+				correct_vg = NULL;
+				break;
+			}
+		}
+	}
+
 	/* Failed to find VG where we expected it - full scan and retry */
 	if (!correct_vg) {
 		inconsistent = 0;
@@ -1118,7 +1145,7 @@
 	    vginfo->vgname && *vginfo->vgname) {
 		if ((vg = _vg_read(cmd, vginfo->vgname, vgid,
 				   &consistent, precommitted)) &&
-		    !strncmp(vg->id.uuid, vgid, ID_LEN)) {
+		    !strncmp((char *)vg->id.uuid, vgid, ID_LEN)) {
 			if (!consistent) {
 				log_error("Volume group %s metadata is "
 					  "inconsistent", vginfo->vgname);
@@ -1149,7 +1176,7 @@
 		consistent = 0;
 		if ((vg = _vg_read(cmd, vgname, vgid, &consistent,
 				   precommitted)) &&
-		    !strncmp(vg->id.uuid, vgid, ID_LEN)) {
+		    !strncmp((char *)vg->id.uuid, vgid, ID_LEN)) {
 			if (!consistent) {
 				log_error("Volume group %s metadata is "
 					  "inconsistent", vgname);
@@ -1173,7 +1200,7 @@
 	lvid = (const union lvid *) lvid_s;
 
 	log_very_verbose("Finding volume group for uuid %s", lvid_s);
-	if (!(vg = _vg_read_by_vgid(cmd, lvid->id[0].uuid, precommitted))) {
+	if (!(vg = _vg_read_by_vgid(cmd, (char *)lvid->id[0].uuid, precommitted))) {
 		log_error("Volume group for uuid not found: %s", lvid_s);
 		return NULL;
 	}
@@ -1315,7 +1342,7 @@
 	return results;
 }
 
-int pv_write(struct cmd_context *cmd, struct physical_volume *pv,
+int pv_write(struct cmd_context *cmd __attribute((unused)), struct physical_volume *pv,
 	     struct list *mdas, int64_t label_sector)
 {
 	if (!pv->fmt->ops->pv_write) {

Modified: lvm2/trunk/lib/metadata/metadata.h
==============================================================================
--- lvm2/trunk/lib/metadata/metadata.h	(original)
+++ lvm2/trunk/lib/metadata/metadata.h	Sat Jun 10 21:40:06 2006
@@ -26,11 +26,12 @@
 #include "lvm-string.h"
 #include "uuid.h"
 
-#define MAX_STRIPES 128
+#define MAX_STRIPES 128U
 #define SECTOR_SHIFT 9L
 #define SECTOR_SIZE ( 1L << SECTOR_SHIFT )
-#define STRIPE_SIZE_MIN ( getpagesize() >> SECTOR_SHIFT)	/* PAGESIZE in sectors */
+#define STRIPE_SIZE_MIN ( (unsigned) getpagesize() >> SECTOR_SHIFT)	/* PAGESIZE in sectors */
 #define STRIPE_SIZE_MAX ( 512L * 1024L >> SECTOR_SHIFT)	/* 512 KB in sectors */
+#define STRIPE_SIZE_LIMIT ((UINT_MAX >> 2) + 1)
 #define PV_MIN_SIZE ( 512L * 1024L >> SECTOR_SHIFT)	/* 512 KB in sectors */
 #define PE_ALIGN (65536UL >> SECTOR_SHIFT)	/* PE alignment */
 #define MAX_RESTRICTED_LVS 255	/* Used by FMT_RESTRICTED_LVIDS */
@@ -38,45 +39,47 @@
 /* Various flags */
 /* Note that the bits no longer necessarily correspond to LVM1 disk format */
 
-#define PARTIAL_VG		0x00000001	/* VG */
-#define EXPORTED_VG          	0x00000002	/* VG PV */
-#define RESIZEABLE_VG        	0x00000004	/* VG */
+#define PARTIAL_VG		0x00000001U	/* VG */
+#define EXPORTED_VG          	0x00000002U	/* VG PV */
+#define RESIZEABLE_VG        	0x00000004U	/* VG */
 
 /* May any free extents on this PV be used or must they be left free? */
-#define ALLOCATABLE_PV         	0x00000008	/* PV */
+#define ALLOCATABLE_PV         	0x00000008U	/* PV */
 
-#define SPINDOWN_LV          	0x00000010	/* LV */
-#define BADBLOCK_ON       	0x00000020	/* LV */
-#define VISIBLE_LV		0x00000040	/* LV */
-#define FIXED_MINOR		0x00000080	/* LV */
+#define SPINDOWN_LV          	0x00000010U	/* LV */
+#define BADBLOCK_ON       	0x00000020U	/* LV */
+#define VISIBLE_LV		0x00000040U	/* LV */
+#define FIXED_MINOR		0x00000080U	/* LV */
 /* FIXME Remove when metadata restructuring is completed */
-#define SNAPSHOT		0x00001000	/* LV - internal use only */
-#define PVMOVE			0x00002000	/* VG LV SEG */
-#define LOCKED			0x00004000	/* LV */
-#define MIRRORED		0x00008000	/* LV - internal use only */
-#define VIRTUAL			0x00010000	/* LV - internal use only */
-#define MIRROR_LOG		0x00020000	/* LV */
-#define MIRROR_IMAGE		0x00040000	/* LV */
-#define ACTIVATE_EXCL		0x00080000	/* LV - internal use only */
-#define PRECOMMITTED		0x00100000	/* VG - internal use only */
-
-#define LVM_READ              	0x00000100	/* LV VG */
-#define LVM_WRITE             	0x00000200	/* LV VG */
-#define CLUSTERED         	0x00000400	/* VG */
-#define SHARED            	0x00000800	/* VG */
+#define SNAPSHOT		0x00001000U	/* LV - internal use only */
+#define PVMOVE			0x00002000U	/* VG LV SEG */
+#define LOCKED			0x00004000U	/* LV */
+#define MIRRORED		0x00008000U	/* LV - internal use only */
+#define VIRTUAL			0x00010000U	/* LV - internal use only */
+#define MIRROR_LOG		0x00020000U	/* LV */
+#define MIRROR_IMAGE		0x00040000U	/* LV */
+#define MIRROR_NOTSYNCED	0x00080000U	/* LV */
+#define ACTIVATE_EXCL		0x00100000U	/* LV - internal use only */
+#define PRECOMMITTED		0x00200000U	/* VG - internal use only */
+
+#define LVM_READ              	0x00000100U	/* LV VG */
+#define LVM_WRITE             	0x00000200U	/* LV VG */
+#define CLUSTERED         	0x00000400U	/* VG */
+#define SHARED            	0x00000800U	/* VG */
 
 /* Format features flags */
-#define FMT_SEGMENTS		0x00000001	/* Arbitrary segment params? */
-#define FMT_MDAS		0x00000002	/* Proper metadata areas? */
-#define FMT_TAGS		0x00000004	/* Tagging? */
-#define FMT_UNLIMITED_VOLS	0x00000008	/* Unlimited PVs/LVs? */
-#define FMT_RESTRICTED_LVIDS	0x00000010	/* LVID <= 255 */
-#define FMT_ORPHAN_ALLOCATABLE	0x00000020	/* Orphan PV allocatable? */
-#define FMT_PRECOMMIT		0x00000040	/* Supports pre-commit? */
-#define FMT_RESIZE_PV		0x00000080	/* Supports pvresize? */
+#define FMT_SEGMENTS		0x00000001U	/* Arbitrary segment params? */
+#define FMT_MDAS		0x00000002U	/* Proper metadata areas? */
+#define FMT_TAGS		0x00000004U	/* Tagging? */
+#define FMT_UNLIMITED_VOLS	0x00000008U	/* Unlimited PVs/LVs? */
+#define FMT_RESTRICTED_LVIDS	0x00000010U	/* LVID <= 255 */
+#define FMT_ORPHAN_ALLOCATABLE	0x00000020U	/* Orphan PV allocatable? */
+#define FMT_PRECOMMIT		0x00000040U	/* Supports pre-commit? */
+#define FMT_RESIZE_PV		0x00000080U	/* Supports pvresize? */
+#define FMT_UNLIMITED_STRIPESIZE 0x00000100U	/* Unlimited stripe size? */
 
 typedef enum {
-	ALLOC_INVALID,
+	ALLOC_INVALID = 0,
 	ALLOC_INHERIT,
 	ALLOC_CONTIGUOUS,
 	ALLOC_NORMAL,
@@ -237,7 +240,7 @@
 	struct list list;
 	struct logical_volume *lv;
 
-	struct segment_type *segtype;
+	const struct segment_type *segtype;
 	uint32_t le;
 	uint32_t len;
 
@@ -379,7 +382,7 @@
 	 * Check whether particular segment type is supported.
 	 */
 	int (*segtype_supported) (struct format_instance *fid,
-				  struct segment_type *segtype);
+				  const struct segment_type *segtype);
 
 	/*
 	 * Create format instance with a particular metadata area
@@ -464,7 +467,7 @@
 
 /* Entry point for all LV extent allocations */
 int lv_extend(struct logical_volume *lv,
-	      struct segment_type *segtype,
+	      const struct segment_type *segtype,
 	      uint32_t stripes, uint32_t stripe_size,
 	      uint32_t mirrors, uint32_t extents,
 	      struct physical_volume *mirrored_pv, uint32_t mirrored_pe,
@@ -569,7 +572,7 @@
 			 uint32_t first_area,
 			 uint32_t num_mirrors,
 			 struct logical_volume *lv,
-			 struct segment_type *segtype,
+			 const struct segment_type *segtype,
 			 uint32_t status,
 			 uint32_t region_size,
 			 struct logical_volume *log_lv);
@@ -577,10 +580,12 @@
 		      uint32_t num_mirrors,
 		      uint32_t existing_mirrors,
 		      struct logical_volume *lv,
-		      struct segment_type *segtype);
+		      const struct segment_type *segtype);
 
 int remove_mirror_images(struct lv_segment *mirrored_seg, uint32_t num_mirrors,
 			 struct list *removable_pvs, int remove_log);
+int reconfigure_mirror_images(struct lv_segment *mirrored_seg, uint32_t num_mirrors,
+			      struct list *removable_pvs, int remove_log);
 /*
  * Given mirror image or mirror log segment, find corresponding mirror segment 
  */

Modified: lvm2/trunk/lib/metadata/mirror.c
==============================================================================
--- lvm2/trunk/lib/metadata/mirror.c	(original)
+++ lvm2/trunk/lib/metadata/mirror.c	Sat Jun 10 21:40:06 2006
@@ -23,6 +23,13 @@
 #include "lvm-string.h"
 #include "locking.h"	/* FIXME Should not be used in this file */
 
+#include "defaults.h" /* FIXME: should this be defaults.h? */
+
+/* These are the flags that represent the mirror failure restoration policies */
+#define MIRROR_REMOVE            0
+#define MIRROR_ALLOCATE          1
+#define MIRROR_ALLOCATE_ANYWHERE 2
+
 struct lv_segment *find_mirror_seg(struct lv_segment *seg)
 {
 	return seg->mirror_seg;
@@ -36,7 +43,7 @@
 {
 	uint32_t region_max;
 
-	region_max = (1 << (ffs(extents) - 1)) * extent_size;
+	region_max = (1 << (ffs((int)extents) - 1)) * extent_size;
 
 	if (region_max < region_size) {
 		region_size = region_max;
@@ -230,11 +237,168 @@
 	return 1;
 }
 
+static int get_mirror_fault_policy(struct cmd_context *cmd, int log_policy)
+{
+	const char *policy;
+
+	if (log_policy)
+		policy = find_config_str(NULL, "activation/mirror_log_fault_policy",
+					 DEFAULT_MIRROR_LOG_FAULT_POLICY);
+	else
+		policy = find_config_str(NULL, "activation/mirror_device_fault_policy",
+					 DEFAULT_MIRROR_DEV_FAULT_POLICY);
+
+	if (!strcmp(policy, "remove"))
+		return MIRROR_REMOVE;
+	else if (!strcmp(policy, "allocate"))
+		return MIRROR_ALLOCATE;
+	else if (!strcmp(policy, "allocate_anywhere"))
+		return MIRROR_ALLOCATE_ANYWHERE;
+
+	if (log_policy)
+		log_error("Bad activation/mirror_log_fault_policy");
+	else
+		log_error("Bad activation/mirror_device_fault_policy");
+
+	return MIRROR_REMOVE;
+}
+
+static int get_mirror_log_fault_policy(struct cmd_context *cmd)
+{
+	return get_mirror_fault_policy(cmd, 1);
+}
+
+static int get_mirror_device_fault_policy(struct cmd_context *cmd)
+{
+	return get_mirror_fault_policy(cmd, 0);
+}
+
+/*
+ * replace_mirror_images
+ * @mirrored_seg: segment (which may be linear now) to restore
+ * @num_mirrors: number of copies we should end up with
+ * @replace_log: replace log if not present
+ * @in_sync: was the original mirror in-sync?
+ *
+ * in_sync will be set to 0 if new mirror devices are being added
+ * In other words, it is only useful if the log (and only the log)
+ * is being restored.
+ *
+ * Returns: 0 on failure, 1 on reconfig, -1 if no reconfig done
+ */
+static int replace_mirror_images(struct lv_segment *mirrored_seg,
+				 uint32_t num_mirrors,
+				 int log_policy, int in_sync)
+{
+	int r = -1;
+	struct logical_volume *lv = mirrored_seg->lv;
+
+	/* FIXME: Use lvconvert rather than duplicating its code */
+
+	if (mirrored_seg->area_count < num_mirrors) {
+		log_error("WARNING: Failed to replace mirror device in %s/%s",
+			  mirrored_seg->lv->vg->name, mirrored_seg->lv->name);
+
+		if ((mirrored_seg->area_count > 1) && !mirrored_seg->log_lv)
+			log_error("WARNING: Use 'lvconvert -m %d %s/%s --corelog' to replace failed devices",
+				  num_mirrors - 1, lv->vg->name, lv->name);
+		else
+			log_error("WARNING: Use 'lvconvert -m %d %s/%s' to replace failed devices",
+				  num_mirrors - 1, lv->vg->name, lv->name);
+		r = 0;
+
+		/* REMEMBER/FIXME: set in_sync to 0 if a new mirror device was added */
+		in_sync = 0;
+	}
+
+	/*
+	 * FIXME: right now, we ignore the allocation policy specified to
+	 * allocate the new log.
+	 */
+	if ((mirrored_seg->area_count > 1) && !mirrored_seg->log_lv &&
+	    (log_policy != MIRROR_REMOVE)) {
+		log_error("WARNING: Failed to replace mirror log device in %s/%s",
+			  lv->vg->name, lv->name);
+
+		log_error("WARNING: Use 'lvconvert -m %d %s/%s' to replace failed devices",
+			  mirrored_seg->area_count - 1 , lv->vg->name, lv->name);
+		r = 0;
+	}
+
+	return r;
+}
+
+int reconfigure_mirror_images(struct lv_segment *mirrored_seg, uint32_t num_mirrors,
+			      struct list *removable_pvs, int remove_log)
+{
+	int r;
+	int insync = 0;
+	int log_policy, dev_policy;
+	uint32_t old_num_mirrors = mirrored_seg->area_count;
+	int had_log = (mirrored_seg->log_lv) ? 1 : 0;
+	float sync_percent = 0;
+
+	/* was the mirror in-sync before problems? */
+	if (!lv_mirror_percent(mirrored_seg->lv->vg->cmd,
+			       mirrored_seg->lv, 0, &sync_percent, NULL))
+		log_error("WARNING: Unable to determine mirror sync status of %s/%s.",
+			  mirrored_seg->lv->vg->name, mirrored_seg->lv->name);
+	else if (sync_percent >= 100.0)
+		insync = 1;
+
+	/*
+	 * While we are only removing devices, we can have sync set.
+	 * Setting this is only useful if we are moving to core log
+	 * otherwise the disk log will contain the sync information
+	 */
+	init_mirror_in_sync(insync);
+
+	r = remove_mirror_images(mirrored_seg, num_mirrors,
+				 removable_pvs, remove_log);
+	if (!r)
+		/* Unable to remove bad devices */
+		return 0;
+
+	log_print("WARNING: Bad device removed from mirror volume, %s/%s",
+		  mirrored_seg->lv->vg->name, mirrored_seg->lv->name);
+
+	log_policy = get_mirror_log_fault_policy(mirrored_seg->lv->vg->cmd);
+	dev_policy = get_mirror_device_fault_policy(mirrored_seg->lv->vg->cmd);
+
+	r = replace_mirror_images(mirrored_seg,
+				  (dev_policy != MIRROR_REMOVE) ?
+				  old_num_mirrors : num_mirrors,
+				  log_policy, insync);
+
+	if (!r)
+		/* Failed to replace device(s) */
+		log_error("WARNING: Unable to find substitute device for mirror volume, %s/%s",
+			  mirrored_seg->lv->vg->name, mirrored_seg->lv->name);
+	else if (r > 0)
+		/* Success in replacing device(s) */
+		log_print("WARNING: Mirror volume, %s/%s restored - substitute for failed device found.",
+			  mirrored_seg->lv->vg->name, mirrored_seg->lv->name);
+	else
+		/* Bad device removed, but not replaced because of policy */
+		if (mirrored_seg->area_count == 1) {
+			log_print("WARNING: Mirror volume, %s/%s converted to linear due to device failure.",
+				  mirrored_seg->lv->vg->name, mirrored_seg->lv->name);
+		} else if (had_log && !mirrored_seg->log_lv) {
+			log_print("WARNING: Mirror volume, %s/%s disk log removed due to device failure.",
+				  mirrored_seg->lv->vg->name, mirrored_seg->lv->name);
+		}
+	/*
+	 * If we made it here, we at least removed the bad device.
+	 * Consider this success.
+	 */
+	return 1;
+}
+
 static int _create_layers_for_mirror(struct alloc_handle *ah,
 				     uint32_t first_area,
 				     uint32_t num_mirrors,
 				     struct logical_volume *lv,
-				     struct segment_type *segtype,
+				     const struct segment_type *segtype,
 				     struct logical_volume **img_lvs)
 {
 	uint32_t m;
@@ -284,7 +448,7 @@
 			 uint32_t first_area,
 			 uint32_t num_mirrors,
 			 struct logical_volume *lv,
-			 struct segment_type *segtype,
+			 const struct segment_type *segtype,
 			 uint32_t status,
 			 uint32_t region_size,
 			 struct logical_volume *log_lv)
@@ -328,7 +492,7 @@
 		      uint32_t num_mirrors,
 		      uint32_t existing_mirrors,
 		      struct logical_volume *lv,
-		      struct segment_type *segtype)
+		      const struct segment_type *segtype)
 {
 	struct logical_volume **img_lvs;
 
@@ -367,7 +531,7 @@
 	uint32_t pe;
 	int lv_used = 0;
 	uint32_t s, start_le, extent_count = 0u;
-	struct segment_type *segtype;
+	const struct segment_type *segtype;
 	struct pe_range *per;
 	uint32_t pe_start, pe_end, per_end, stripe_multiplier;
 
@@ -555,7 +719,7 @@
 					return 0;
 				}
 
-				release_lv_segment_area(mir_seg, !c, mir_seg->area_len);
+				release_lv_segment_area(mir_seg, c ? 0 : 1U, mir_seg->area_len);
 
 				/* Replace mirror with error segment */
 				if (!

Modified: lvm2/trunk/lib/metadata/pv_manip.c
==============================================================================
--- lvm2/trunk/lib/metadata/pv_manip.c	(original)
+++ lvm2/trunk/lib/metadata/pv_manip.c	Sat Jun 10 21:40:06 2006
@@ -136,8 +136,8 @@
 }
 
 static struct pv_segment null_pv_segment = {
-	pv: NULL,
-	pe: 0
+	.pv = NULL,
+	.pe = 0,
 };
 
 struct pv_segment *assign_peg_to_lvseg(struct physical_volume *pv,

Modified: lvm2/trunk/lib/metadata/segtype.h
==============================================================================
--- lvm2/trunk/lib/metadata/segtype.h	(original)
+++ lvm2/trunk/lib/metadata/segtype.h	Sat Jun 10 21:40:06 2006
@@ -25,13 +25,13 @@
 struct dev_manager;
 
 /* Feature flags */
-#define SEG_CAN_SPLIT		0x00000001
-#define SEG_AREAS_STRIPED	0x00000002
-#define SEG_AREAS_MIRRORED	0x00000004
-#define SEG_SNAPSHOT		0x00000008
-#define SEG_FORMAT1_SUPPORT	0x00000010
-#define SEG_VIRTUAL		0x00000020
-#define SEG_CANNOT_BE_ZEROED	0x00000040
+#define SEG_CAN_SPLIT		0x00000001U
+#define SEG_AREAS_STRIPED	0x00000002U
+#define SEG_AREAS_MIRRORED	0x00000004U
+#define SEG_SNAPSHOT		0x00000008U
+#define SEG_FORMAT1_SUPPORT	0x00000010U
+#define SEG_VIRTUAL		0x00000020U
+#define SEG_CANNOT_BE_ZEROED	0x00000040U
 
 #define seg_is_mirrored(seg)	((seg)->segtype->flags & SEG_AREAS_MIRRORED ? 1 : 0)
 #define seg_is_striped(seg)	((seg)->segtype->flags & SEG_AREAS_STRIPED ? 1 : 0)

Modified: lvm2/trunk/lib/mirror/mirrored.c
==============================================================================
--- lvm2/trunk/lib/mirror/mirrored.c	(original)
+++ lvm2/trunk/lib/mirror/mirrored.c	Sat Jun 10 21:40:06 2006
@@ -60,8 +60,7 @@
 
 	if (seg->region_size) {
 		size = display_size(seg->lv->vg->cmd,
-				    (uint64_t) seg->region_size,
-				    SIZE_SHORT);
+				    (uint64_t) seg->region_size);
 		log_print("  Mirror region size\t%s", size);
 	}
 
@@ -175,7 +174,8 @@
 static int _mirrored_target_percent(void **target_state, struct dm_pool *mem,
 			   struct config_tree *cft, struct lv_segment *seg,
 			   char *params, uint64_t *total_numerator,
-			   uint64_t *total_denominator, float *percent)
+			   uint64_t *total_denominator,
+			   float *percent __attribute((unused)))
 {
 	struct mirror_state *mirr_state;
 	uint64_t numerator, denominator;
@@ -238,13 +238,26 @@
 	      (seg->lv->vg->status & CLUSTERED)))
 		clustered = 1;
 
-	if (seg->log_lv &&
-	    !(log_dlid = build_dlid(dm, seg->log_lv->lvid.s, NULL))) {
-		log_error("Failed to build uuid for log LV %s.",
-			  seg->log_lv->name);
-		return 0;
+	if (seg->log_lv) {
+		/* If disk log, use its UUID */
+		if (!(log_dlid = build_dlid(dm, seg->log_lv->lvid.s, NULL))) {
+			log_error("Failed to build uuid for log LV %s.",
+				  seg->log_lv->name);
+			return 0;
+		}
+	} else {
+		/* If core log, use mirror's UUID and set DM_CORELOG flag */
+		if (!(log_dlid = build_dlid(dm, seg->lv->lvid.s, NULL))) {
+			log_error("Failed to build uuid for mirror LV %s.",
+				  seg->lv->name);
+			return 0;
+		}
+		log_flags |= DM_CORELOG;
 	}
 
+	if (mirror_in_sync() && !(seg->status & PVMOVE))
+		log_flags |= DM_NOSYNC;
+
 	if (_block_on_error_available && !(seg->status & PVMOVE))
 		log_flags |= DM_BLOCK_ON_ERROR;
 
@@ -259,7 +272,7 @@
 {
 	struct mirror_state *mirr_state;
 	uint32_t area_count = seg->area_count;
-	int start_area = 0u;
+	unsigned start_area = 0u;
 	int mirror_status = MIRR_RUNNING;
 	uint32_t region_size, region_max;
 	int r;
@@ -299,7 +312,7 @@
 		region_size = seg->region_size;
 	} else {
 		/* Find largest power of 2 region size unit we can use */
-		region_max = (1 << (ffs(seg->area_len) - 1)) *
+		region_max = (1 << (ffs((int)seg->area_len) - 1)) *
 		      seg->lv->vg->extent_size;
 
 		region_size = mirr_state->default_region_size;
@@ -442,21 +455,21 @@
 }
 
 static struct segtype_handler _mirrored_ops = {
-	name:_mirrored_name,
-	display:_mirrored_display,
-	text_import_area_count:_mirrored_text_import_area_count,
-	text_import:_mirrored_text_import,
-	text_export:_mirrored_text_export,
+	.name = _mirrored_name,
+	.display = _mirrored_display,
+	.text_import_area_count = _mirrored_text_import_area_count,
+	.text_import = _mirrored_text_import,
+	.text_export = _mirrored_text_export,
 #ifdef DEVMAPPER_SUPPORT
-	add_target_line:_mirrored_add_target_line,
-	target_percent:_mirrored_target_percent,
-	target_present:_mirrored_target_present,
+	.add_target_line = _mirrored_add_target_line,
+	.target_percent = _mirrored_target_percent,
+	.target_present = _mirrored_target_present,
 #ifdef DMEVENTD
-	target_register_events:_target_register_events,
-	target_unregister_events:_target_unregister_events,
+	.target_register_events = _target_register_events,
+	.target_unregister_events = _target_unregister_events,
 #endif
 #endif
-	destroy:_mirrored_destroy,
+	.destroy = _mirrored_destroy,
 };
 
 #ifdef MIRRORED_INTERNAL

Added: lvm2/trunk/lib/misc/configure.h.in
==============================================================================
--- (empty file)
+++ lvm2/trunk/lib/misc/configure.h.in	Sat Jun 10 21:40:06 2006
@@ -0,0 +1,429 @@
+/* lib/misc/configure.h.in.  Generated from configure.in by autoheader.  */
+
+/* Define to 1 if the `closedir' function returns void instead of `int'. */
+#undef CLOSEDIR_VOID
+
+/* Define to 1 to include built-in support for clustered LVM locking. */
+#undef CLUSTER_LOCKING_INTERNAL
+
+/* Define to 1 to build the shared command library. */
+#undef CMDLIB
+
+/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP
+   systems. This function is required for `alloca.c' support on those systems.
+   */
+#undef CRAY_STACKSEG_END
+
+/* Define to 1 if using `alloca.c'. */
+#undef C_ALLOCA
+
+/* Define to 1 to enable device-mapper interaction. */
+#undef DEVMAPPER_SUPPORT
+
+/* Define to 1 to enable the device-mapper event daemon. */
+#undef DMEVENTD
+
+/* Define to 1 if you have `alloca', as a function or macro. */
+#undef HAVE_ALLOCA
+
+/* Define to 1 if you have <alloca.h> and it should be used (not on Ultrix).
+   */
+#undef HAVE_ALLOCA_H
+
+/* Define to 1 if you have the <asm/byteorder.h> header file. */
+#undef HAVE_ASM_BYTEORDER_H
+
+/* Define to 1 if you have the <assert.h> header file. */
+#undef HAVE_ASSERT_H
+
+/* Define to 1 if you have the <ctype.h> header file. */
+#undef HAVE_CTYPE_H
+
+/* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
+   */
+#undef HAVE_DIRENT_H
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#undef HAVE_DLFCN_H
+
+/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */
+#undef HAVE_DOPRNT
+
+/* Define to 1 if you have the `dup2' function. */
+#undef HAVE_DUP2
+
+/* Define to 1 if you have the <fcntl.h> header file. */
+#undef HAVE_FCNTL_H
+
+/* Define to 1 if you have the `fork' function. */
+#undef HAVE_FORK
+
+/* Define to 1 if you have the <fstab.h> header file. */
+#undef HAVE_FSTAB_H
+
+/* Define to 1 if you have the `gethostname' function. */
+#undef HAVE_GETHOSTNAME
+
+/* Define to 1 if you have the `getmntent' function. */
+#undef HAVE_GETMNTENT
+
+/* Define to 1 to if getopt_long is available. */
+#undef HAVE_GETOPTLONG
+
+/* Define to 1 if you have the <getopt.h> header file. */
+#undef HAVE_GETOPT_H
+
+/* Define to 1 if you have the `getpagesize' function. */
+#undef HAVE_GETPAGESIZE
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#undef HAVE_INTTYPES_H
+
+/* Define to 1 if you have the <libdevmapper.h> header file. */
+#undef HAVE_LIBDEVMAPPER_H
+
+/* Define to 1 if dynamic libraries are available. */
+#undef HAVE_LIBDL
+
+/* Define to 1 if you have the <libgen.h> header file. */
+#undef HAVE_LIBGEN_H
+
+/* Define to 1 if you have the <libintl.h> header file. */
+#undef HAVE_LIBINTL_H
+
+/* Define to 1 if you have the `readline' library (-lreadline). */
+#undef HAVE_LIBREADLINE
+
+/* Define to 1 if you have the <limits.h> header file. */
+#undef HAVE_LIMITS_H
+
+/* Define to 1 if you have the <linux/fs.h> header file. */
+#undef HAVE_LINUX_FS_H
+
+/* Define to 1 if you have the <locale.h> header file. */
+#undef HAVE_LOCALE_H
+
+/* Define to 1 if `lstat' has the bug that it succeeds when given the
+   zero-length file name argument. */
+#undef HAVE_LSTAT_EMPTY_STRING_BUG
+
+/* Define to 1 if you have the <machine/endian.h> header file. */
+#undef HAVE_MACHINE_ENDIAN_H
+
+/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
+   to 0 otherwise. */
+#undef HAVE_MALLOC
+
+/* Define to 1 if you have the <malloc.h> header file. */
+#undef HAVE_MALLOC_H
+
+/* Define to 1 if you have the `memmove' function. */
+#undef HAVE_MEMMOVE
+
+/* Define to 1 if you have the <memory.h> header file. */
+#undef HAVE_MEMORY_H
+
+/* Define to 1 if you have the `memset' function. */
+#undef HAVE_MEMSET
+
+/* Define to 1 if you have the `mkdir' function. */
+#undef HAVE_MKDIR
+
+/* Define to 1 if you have a working `mmap' system call. */
+#undef HAVE_MMAP
+
+/* Define to 1 if you have the <mntent.h> header file. */
+#undef HAVE_MNTENT_H
+
+/* Define to 1 if you have the `munmap' function. */
+#undef HAVE_MUNMAP
+
+/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
+#undef HAVE_NDIR_H
+
+/* Define to 1 if you have the <netdb.h> header file. */
+#undef HAVE_NETDB_H
+
+/* Define to 1 if you have the <netinet/in.h> header file. */
+#undef HAVE_NETINET_IN_H
+
+/* Define to 1 if you have the <pthread.h> header file. */
+#undef HAVE_PTHREAD_H
+
+/* Define to 1 if you have the <readline/history.h> header file. */
+#undef HAVE_READLINE_HISTORY_H
+
+/* Define to 1 if you have the <readline/readline.h> header file. */
+#undef HAVE_READLINE_READLINE_H
+
+/* Define to 1 if rl_completion_matches() is available. */
+#undef HAVE_RL_COMPLETION_MATCHES
+
+/* Define to 1 if you have the `rmdir' function. */
+#undef HAVE_RMDIR
+
+/* Define to 1 if you have the <search.h> header file. */
+#undef HAVE_SEARCH_H
+
+/* Define to 1 if you have the `select' function. */
+#undef HAVE_SELECT
+
+/* Define to 1 to include support for selinux. */
+#undef HAVE_SELINUX
+
+/* Define to 1 if you have the <selinux/selinux.h> header file. */
+#undef HAVE_SELINUX_SELINUX_H
+
+/* Define to 1 if you have the `setlocale' function. */
+#undef HAVE_SETLOCALE
+
+/* Define to 1 if you have the <signal.h> header file. */
+#undef HAVE_SIGNAL_H
+
+/* Define to 1 if you have the `socket' function. */
+#undef HAVE_SOCKET
+
+/* Define to 1 if `stat' has the bug that it succeeds when given the
+   zero-length file name argument. */
+#undef HAVE_STAT_EMPTY_STRING_BUG
+
+/* Define to 1 if you have the <stddef.h> header file. */
+#undef HAVE_STDDEF_H
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#undef HAVE_STDINT_H
+
+/* Define to 1 if you have the <stdio.h> header file. */
+#undef HAVE_STDIO_H
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#undef HAVE_STDLIB_H
+
+/* Define to 1 if you have the `strcasecmp' function. */
+#undef HAVE_STRCASECMP
+
+/* Define to 1 if you have the `strchr' function. */
+#undef HAVE_STRCHR
+
+/* Define to 1 if you have the `strdup' function. */
+#undef HAVE_STRDUP
+
+/* Define to 1 if you have the `strerror' function. */
+#undef HAVE_STRERROR
+
+/* Define to 1 if you have the <strings.h> header file. */
+#undef HAVE_STRINGS_H
+
+/* Define to 1 if you have the <string.h> header file. */
+#undef HAVE_STRING_H
+
+/* Define to 1 if you have the `strncasecmp' function. */
+#undef HAVE_STRNCASECMP
+
+/* Define to 1 if you have the `strrchr' function. */
+#undef HAVE_STRRCHR
+
+/* Define to 1 if you have the `strstr' function. */
+#undef HAVE_STRSTR
+
+/* Define to 1 if you have the `strtol' function. */
+#undef HAVE_STRTOL
+
+/* Define to 1 if you have the `strtoul' function. */
+#undef HAVE_STRTOUL
+
+/* Define to 1 if `st_rdev' is member of `struct stat'. */
+#undef HAVE_STRUCT_STAT_ST_RDEV
+
+/* Define to 1 if your `struct stat' has `st_rdev'. Deprecated, use
+   `HAVE_STRUCT_STAT_ST_RDEV' instead. */
+#undef HAVE_ST_RDEV
+
+/* Define to 1 if you have the <syslog.h> header file. */
+#undef HAVE_SYSLOG_H
+
+/* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'.
+   */
+#undef HAVE_SYS_DIR_H
+
+/* Define to 1 if you have the <sys/disk.h> header file. */
+#undef HAVE_SYS_DISK_H
+
+/* Define to 1 if you have the <sys/file.h> header file. */
+#undef HAVE_SYS_FILE_H
+
+/* Define to 1 if you have the <sys/ioctl.h> header file. */
+#undef HAVE_SYS_IOCTL_H
+
+/* Define to 1 if you have the <sys/mman.h> header file. */
+#undef HAVE_SYS_MMAN_H
+
+/* Define to 1 if you have the <sys/mount.h> header file. */
+#undef HAVE_SYS_MOUNT_H
+
+/* Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR'.
+   */
+#undef HAVE_SYS_NDIR_H
+
+/* Define to 1 if you have the <sys/param.h> header file. */
+#undef HAVE_SYS_PARAM_H
+
+/* Define to 1 if you have the <sys/resource.h> header file. */
+#undef HAVE_SYS_RESOURCE_H
+
+/* Define to 1 if you have the <sys/select.h> header file. */
+#undef HAVE_SYS_SELECT_H
+
+/* Define to 1 if you have the <sys/socket.h> header file. */
+#undef HAVE_SYS_SOCKET_H
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#undef HAVE_SYS_STAT_H
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+#undef HAVE_SYS_TIME_H
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#undef HAVE_SYS_TYPES_H
+
+/* Define to 1 if you have the <sys/uio.h> header file. */
+#undef HAVE_SYS_UIO_H
+
+/* Define to 1 if you have the <sys/un.h> header file. */
+#undef HAVE_SYS_UN_H
+
+/* Define to 1 if you have the <sys/utsname.h> header file. */
+#undef HAVE_SYS_UTSNAME_H
+
+/* Define to 1 if you have the <sys/vfs.h> header file. */
+#undef HAVE_SYS_VFS_H
+
+/* Define to 1 if you have the <sys/wait.h> header file. */
+#undef HAVE_SYS_WAIT_H
+
+/* Define to 1 if you have the <time.h> header file. */
+#undef HAVE_TIME_H
+
+/* Define to 1 if you have the `uname' function. */
+#undef HAVE_UNAME
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#undef HAVE_UNISTD_H
+
+/* Define to 1 if you have the <utmpx.h> header file. */
+#undef HAVE_UTMPX_H
+
+/* Define to 1 if you have the `vfork' function. */
+#undef HAVE_VFORK
+
+/* Define to 1 if you have the <vfork.h> header file. */
+#undef HAVE_VFORK_H
+
+/* Define to 1 if you have the `vprintf' function. */
+#undef HAVE_VPRINTF
+
+/* Define to 1 if `fork' works. */
+#undef HAVE_WORKING_FORK
+
+/* Define to 1 if `vfork' works. */
+#undef HAVE_WORKING_VFORK
+
+/* Define to 1 if `lstat' dereferences a symlink specified with a trailing
+   slash. */
+#undef LSTAT_FOLLOWS_SLASHED_SYMLINK
+
+/* Define to 1 if 'lvm' should fall back to using LVM1 binaries if
+   device-mapper is missing from the kernel */
+#undef LVM1_FALLBACK
+
+/* Define to 1 to include built-in support for LVM1 metadata. */
+#undef LVM1_INTERNAL
+
+/* Define to 1 to include built-in support for mirrors. */
+#undef MIRRORED_INTERNAL
+
+/* The path to 'modprobe', if available. */
+#undef MODPROBE_CMD
+
+/* Define to 1 to enable O_DIRECT support. */
+#undef O_DIRECT_SUPPORT
+
+/* Define to the address where bug reports for this package should be sent. */
+#undef PACKAGE_BUGREPORT
+
+/* Define to the full name of this package. */
+#undef PACKAGE_NAME
+
+/* Define to the full name and version of this package. */
+#undef PACKAGE_STRING
+
+/* Define to the one symbol short name of this package. */
+#undef PACKAGE_TARNAME
+
+/* Define to the version of this package. */
+#undef PACKAGE_VERSION
+
+/* Define to 1 to include built-in support for GFS pool metadata. */
+#undef POOL_INTERNAL
+
+/* Define to 1 to include the LVM readline shell. */
+#undef READLINE_SUPPORT
+
+/* Define as the return type of signal handlers (`int' or `void'). */
+#undef RETSIGTYPE
+
+/* Define to the type of arg 1 for `select'. */
+#undef SELECT_TYPE_ARG1
+
+/* Define to the type of args 2, 3 and 4 for `select'. */
+#undef SELECT_TYPE_ARG234
+
+/* Define to the type of arg 5 for `select'. */
+#undef SELECT_TYPE_ARG5
+
+/* Define to 1 to include built-in support for snapshots. */
+#undef SNAPSHOT_INTERNAL
+
+/* If using the C implementation of alloca, define if you know the
+   direction of stack growth for your system; otherwise it will be
+   automatically deduced at run-time.
+	STACK_DIRECTION > 0 => grows toward higher addresses
+	STACK_DIRECTION < 0 => grows toward lower addresses
+	STACK_DIRECTION = 0 => direction of growth unknown */
+#undef STACK_DIRECTION
+
+/* Define to 1 if you have the ANSI C header files. */
+#undef STDC_HEADERS
+
+/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
+#undef TIME_WITH_SYS_TIME
+
+/* Define to 1 if your <sys/time.h> declares `struct tm'. */
+#undef TM_IN_SYS_TIME
+
+/* Define to empty if `const' does not conform to ANSI C. */
+#undef const
+
+/* Define to `__inline__' or `__inline' if that's what the C compiler
+   calls it, or to nothing if 'inline' is not supported under any name.  */
+#ifndef __cplusplus
+#undef inline
+#endif
+
+/* Define to rpl_malloc if the replacement function should be used. */
+#undef malloc
+
+/* Define to `int' if <sys/types.h> does not define. */
+#undef mode_t
+
+/* Define to `long' if <sys/types.h> does not define. */
+#undef off_t
+
+/* Define to `int' if <sys/types.h> does not define. */
+#undef pid_t
+
+/* Define to `unsigned' if <sys/types.h> does not define. */
+#undef size_t
+
+/* Define as `fork' if `vfork' does not work. */
+#undef vfork

Modified: lvm2/trunk/lib/misc/lib.h
==============================================================================
--- lvm2/trunk/lib/misc/lib.h	(original)
+++ lvm2/trunk/lib/misc/lib.h	Sat Jun 10 21:40:06 2006
@@ -19,6 +19,8 @@
 #ifndef _LVM_LIB_H
 #define _LVM_LIB_H
 
+#include <configure.h>
+
 #define _REENTRANT
 #define _GNU_SOURCE
 #define _FILE_OFFSET_BITS 64

Modified: lvm2/trunk/lib/misc/lvm-exec.h
==============================================================================
--- lvm2/trunk/lib/misc/lvm-exec.h	(original)
+++ lvm2/trunk/lib/misc/lvm-exec.h	Sat Jun 10 21:40:06 2006
@@ -13,7 +13,11 @@
  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#ifndef _LVM_EXEC_H
+#define _LVM_EXEC_H
+
 #include "lib.h"
 
 int exec_cmd(const char *command, const char *fscmd, const char *lv_path,
 	     const char *size);
+#endif

Modified: lvm2/trunk/lib/misc/lvm-file.c
==============================================================================
--- lvm2/trunk/lib/misc/lvm-file.c	(original)
+++ lvm2/trunk/lib/misc/lvm-file.c	Sat Jun 10 21:40:06 2006
@@ -35,10 +35,10 @@
 	pid_t pid;
 	char hostname[255];
 	struct flock lock = {
-		l_type:F_WRLCK,
-		l_whence:0,
-		l_start:0,
-		l_len:0
+		.l_type = F_WRLCK,
+		.l_whence = 0,
+		.l_start = 0,
+		.l_len = 0
 	};
 
 	num = rand();

Modified: lvm2/trunk/lib/misc/lvm-file.h
==============================================================================
--- lvm2/trunk/lib/misc/lvm-file.h	(original)
+++ lvm2/trunk/lib/misc/lvm-file.h	Sat Jun 10 21:40:06 2006
@@ -13,6 +13,9 @@
  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#ifndef _LVM_FILE_H
+#define _LVM_FILE_H
+
 /*
  * Create a temporary filename, and opens a descriptor to the file.
  */
@@ -44,3 +47,5 @@
 
 /* Sync directory changes */
 void sync_dir(const char *file);
+
+#endif

Modified: lvm2/trunk/lib/misc/lvm-string.c
==============================================================================
--- lvm2/trunk/lib/misc/lvm-string.c	(original)
+++ lvm2/trunk/lib/misc/lvm-string.c	Sat Jun 10 21:40:06 2006
@@ -159,7 +159,9 @@
 	_quote_hyphens(&out, lvname);
 
 	if (layer && *layer) {
-		*out++ = '-';
+		/* No hyphen if the layer begins with _ e.g. _mlog */
+		if (*layer != '_')
+			*out++ = '-';
 		_quote_hyphens(&out, layer);
 	}
 	*out = '\0';

Modified: lvm2/trunk/lib/misc/sharedlib.c
==============================================================================
--- lvm2/trunk/lib/misc/sharedlib.c	(original)
+++ lvm2/trunk/lib/misc/sharedlib.c	Sat Jun 10 21:40:06 2006
@@ -23,7 +23,7 @@
 #include <dlfcn.h>
 
 void get_shared_library_path(struct config_tree *cft, const char *libname,
-			     char *path, int path_len)
+			     char *path, size_t path_len)
 {
 	struct stat info;
 	const char *lib_dir;

Modified: lvm2/trunk/lib/misc/sharedlib.h
==============================================================================
--- lvm2/trunk/lib/misc/sharedlib.h	(original)
+++ lvm2/trunk/lib/misc/sharedlib.h	Sat Jun 10 21:40:06 2006
@@ -13,10 +13,15 @@
  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#ifndef _LVM_SHAREDLIB_H
+#define _LVM_SHAREDLIB_H
+
 #include "config.h"
 #include <dlfcn.h>
 
 void get_shared_library_path(struct config_tree *cft, const char *libname,
-			     char *path, int path_len);
+			     char *path, size_t path_len);
 void *load_shared_library(struct config_tree *cf, const char *libname,
 			  const char *what, int silent);
+
+#endif

Modified: lvm2/trunk/lib/regex/matcher.c
==============================================================================
--- lvm2/trunk/lib/regex/matcher.c	(original)
+++ lvm2/trunk/lib/regex/matcher.c	Sat Jun 10 21:40:06 2006
@@ -196,17 +196,13 @@
 	struct state_queue *h, *t, *tmp;
 	struct dfa_state *dfa, *ldfa;
 	int i, a, set_bits = 0, count = 0;
-	dm_bitset_t bs = dm_bitset_create(m->scratch, m->num_nodes), dfa_bits;
+	dm_bitset_t bs, dfa_bits;
 
-	if (!tt) {
-		stack;
-		return 0;
-	}
+	if (!tt)
+		return_0;
 
-	if (!bs) {
-		stack;
-		return 0;
-	}
+	if (!(bs = dm_bitset_create(m->scratch, m->num_nodes)))
+		return_0;
 
 	/* create first state */
 	dfa = _create_dfa_state(m->mem);
@@ -284,6 +280,7 @@
 
 	if (!(m = dm_pool_alloc(mem, sizeof(*m)))) {
 		stack;
+		dm_pool_destroy(scratch);
 		return NULL;
 	}
 

Modified: lvm2/trunk/lib/report/report.c
==============================================================================
--- lvm2/trunk/lib/report/report.c	(original)
+++ lvm2/trunk/lib/report/report.c	Sat Jun 10 21:40:06 2006
@@ -333,9 +333,12 @@
 
 	if (lv->status & PVMOVE)
 		repstr[0] = 'p';
-	else if (lv->status & MIRRORED)
-		repstr[0] = 'm';
-	else if (lv->status & MIRROR_IMAGE)
+	else if (lv->status & MIRRORED) {
+		if (lv->status & MIRROR_NOTSYNCED)
+			repstr[0] = 'M';
+		else
+			repstr[0] = 'm';
+	}else if (lv->status & MIRROR_IMAGE)
 		repstr[0] = 'i';
 	else if (lv->status & MIRROR_LOG)
 		repstr[0] = 'l';
@@ -472,7 +475,8 @@
 	return 1;
 }
 
-static int _segtype_disp(struct report_handle *rh, struct field *field,
+static int _segtype_disp(struct report_handle *rh __attribute((unused)),
+			 struct field *field,
 			 const void *data)
 {
 	const struct lv_segment *seg = (const struct lv_segment *) data;
@@ -578,7 +582,7 @@
 	const char *disp;
 	uint64_t *sortval;
 
-	if (!*(disp = display_size(rh->cmd, (uint64_t) size, SIZE_UNIT))) {
+	if (!*(disp = display_size_units(rh->cmd, (uint64_t) size))) {
 		stack;
 		return 0;
 	}
@@ -606,7 +610,7 @@
 	const char *disp;
 	uint64_t *sortval;
 
-	if (!*(disp = display_size(rh->cmd, size, SIZE_UNIT))) {
+	if (!*(disp = display_size_units(rh->cmd, size))) {
 		stack;
 		return 0;
 	}

Modified: lvm2/trunk/lib/snapshot/snapshot.c
==============================================================================
--- lvm2/trunk/lib/snapshot/snapshot.c	(original)
+++ lvm2/trunk/lib/snapshot/snapshot.c	Sat Jun 10 21:40:06 2006
@@ -27,7 +27,7 @@
 }
 
 static int _snap_text_import(struct lv_segment *seg, const struct config_node *sn,
-			struct dm_hash_table *pv_hash)
+			struct dm_hash_table *pv_hash __attribute((unused)))
 {
 	uint32_t chunk_size;
 	const char *org_name, *cow_name;
@@ -87,8 +87,10 @@
 }
 
 #ifdef DEVMAPPER_SUPPORT
-static int _snap_target_percent(void **target_state, struct dm_pool *mem,
-			   struct config_tree *cft, struct lv_segment *seg,
+static int _snap_target_percent(void **target_state __attribute((unused)),
+			   struct dm_pool *mem __attribute((unused)),
+			   struct config_tree *cft __attribute((unused)),
+			   struct lv_segment *seg __attribute((unused)),
 			   char *params, uint64_t *total_numerator,
 			   uint64_t *total_denominator, float *percent)
 {
@@ -126,18 +128,18 @@
 
 static void _snap_destroy(const struct segment_type *segtype)
 {
-	dm_free((void *) segtype);
+	dm_free((void *)segtype);
 }
 
 static struct segtype_handler _snapshot_ops = {
-	name:_snap_name,
-	text_import:_snap_text_import,
-	text_export:_snap_text_export,
+	.name = _snap_name,
+	.text_import = _snap_text_import,
+	.text_export = _snap_text_export,
 #ifdef DEVMAPPER_SUPPORT
-	target_percent:_snap_target_percent,
-	target_present:_snap_target_present,
+	.target_percent = _snap_target_percent,
+	.target_present = _snap_target_present,
 #endif
-	destroy:_snap_destroy,
+	.destroy = _snap_destroy,
 };
 
 #ifdef SNAPSHOT_INTERNAL

Modified: lvm2/trunk/lib/striped/striped.c
==============================================================================
--- lvm2/trunk/lib/striped/striped.c	(original)
+++ lvm2/trunk/lib/striped/striped.c	Sat Jun 10 21:40:06 2006
@@ -151,11 +151,13 @@
 }
 
 #ifdef DEVMAPPER_SUPPORT
-static int _striped_add_target_line(struct dev_manager *dm, struct dm_pool *mem,
-                                struct config_tree *cft, void **target_state,
+static int _striped_add_target_line(struct dev_manager *dm,
+				struct dm_pool *mem __attribute((unused)),
+                                struct config_tree *cft __attribute((unused)),
+				void **target_state __attribute((unused)),
                                 struct lv_segment *seg,
                                 struct dm_tree_node *node, uint64_t len,
-                                uint32_t *pvmove_mirror_count)
+                                uint32_t *pvmove_mirror_count __attribute((unused)))
 {
 	if (!seg->area_count) {
 		log_error("Internal error: striped add_target_line called "
@@ -189,21 +191,21 @@
 
 static void _striped_destroy(const struct segment_type *segtype)
 {
-	dm_free((void *) segtype);
+	dm_free((void *)segtype);
 }
 
 static struct segtype_handler _striped_ops = {
-	name:_striped_name,
-	display:_striped_display,
-	text_import_area_count:_striped_text_import_area_count,
-	text_import:_striped_text_import,
-	text_export:_striped_text_export,
-	merge_segments:_striped_merge_segments,
+	.name = _striped_name,
+	.display = _striped_display,
+	.text_import_area_count = _striped_text_import_area_count,
+	.text_import = _striped_text_import,
+	.text_export = _striped_text_export,
+	.merge_segments = _striped_merge_segments,
 #ifdef DEVMAPPER_SUPPORT
-	add_target_line:_striped_add_target_line,
-	target_present:_striped_target_present,
+	.add_target_line = _striped_add_target_line,
+	.target_present = _striped_target_present,
 #endif
-	destroy:_striped_destroy,
+	.destroy = _striped_destroy,
 };
 
 struct segment_type *init_striped_segtype(struct cmd_context *cmd)

Modified: lvm2/trunk/lib/uuid/uuid.c
==============================================================================
--- lvm2/trunk/lib/uuid/uuid.c	(original)
+++ lvm2/trunk/lib/uuid/uuid.c	Sat Jun 10 21:40:06 2006
@@ -20,11 +20,11 @@
 #include <fcntl.h>
 #include <unistd.h>
 
-static unsigned char _c[] =
+static char _c[] =
     "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!#";
 
 static int _built_inverse;
-static unsigned char _inverse_c[256];
+static char _inverse_c[256];
 
 int lvid_create(union lvid *lvid, struct id *vgid)
 {
@@ -40,8 +40,6 @@
 		uuid[i - 1] = _c[num % (sizeof(_c) - 1)];
 		num /= sizeof(_c) - 1;
 	}
-
-	uuid[ID_LEN] = '\0';
 }
 
 int lvid_from_lvnum(union lvid *lvid, struct id *vgid, uint32_t lv_num)
@@ -63,7 +61,7 @@
 int lvnum_from_lvid(union lvid *lvid)
 {
 	int i, lv_num = 0;
-	unsigned char *c;
+	char *c;
 
 	for (i = 0; i < ID_LEN; i++) {
 		lv_num *= sizeof(_c) - 1;
@@ -76,7 +74,8 @@
 
 int id_create(struct id *id)
 {
-	int randomfile, i;
+	int randomfile;
+	unsigned i;
 	size_t len = sizeof(id->uuid);
 
 	memset(id->uuid, 0, len);
@@ -85,7 +84,7 @@
 		return 0;
 	}
 
-	if (read(randomfile, id->uuid, len) != len) {
+	if (read(randomfile, id->uuid, len) != (ssize_t) len) {
 		log_sys_error("read", "id_create: /dev/urandom");
 		if (close(randomfile))
 			stack;

Modified: lvm2/trunk/lib/uuid/uuid.h
==============================================================================
--- lvm2/trunk/lib/uuid/uuid.h	(original)
+++ lvm2/trunk/lib/uuid/uuid.h	Sat Jun 10 21:40:06 2006
@@ -20,7 +20,7 @@
 #define ID_LEN_S "32"
 
 struct id {
-	uint8_t uuid[ID_LEN];
+	int8_t uuid[ID_LEN];
 };
 
 /*

Modified: lvm2/trunk/lib/zero/zero.c
==============================================================================
--- lvm2/trunk/lib/zero/zero.c	(original)
+++ lvm2/trunk/lib/zero/zero.c	Sat Jun 10 21:40:06 2006
@@ -38,11 +38,13 @@
 }
 
 #ifdef DEVMAPPER_SUPPORT
-static int _zero_add_target_line(struct dev_manager *dm, struct dm_pool *mem,
-                                struct config_tree *cft, void **target_state,
-                                struct lv_segment *seg,
-                                struct dm_tree_node *node, uint64_t len,
-                                uint32_t *pvmove_mirror_count)
+static int _zero_add_target_line(struct dev_manager *dm __attribute((unused)),
+				struct dm_pool *mem __attribute((unused)),
+                                struct config_tree *cft __attribute((unused)),
+				void **target_state __attribute((unused)),
+                                struct lv_segment *seg __attribute((unused)),
+                                struct dm_tree_node *node,uint64_t len,
+                                uint32_t *pvmove_mirror_count __attribute((unused)))
 {
 	return dm_tree_node_add_zero_target(node, len);
 }
@@ -67,13 +69,13 @@
 }
 
 static struct segtype_handler _zero_ops = {
-	name:_zero_name,
-	merge_segments:_zero_merge_segments,
+	.name = _zero_name,
+	.merge_segments = _zero_merge_segments,
 #ifdef DEVMAPPER_SUPPORT
-	add_target_line:_zero_add_target_line,
-	target_present:_zero_target_present,
+	.add_target_line = _zero_add_target_line,
+	.target_present = _zero_target_present,
 #endif
-	destroy:_zero_destroy,
+	.destroy = _zero_destroy,
 };
 
 struct segment_type *init_zero_segtype(struct cmd_context *cmd)

Modified: lvm2/trunk/make.tmpl.in
==============================================================================
--- lvm2/trunk/make.tmpl.in	(original)
+++ lvm2/trunk/make.tmpl.in	Sat Jun 10 21:40:06 2006
@@ -24,7 +24,7 @@
 MSGFMT = @MSGFMT@
 LN_S = @LN_S@
 LIBS = @LIBS@
-DEFS += @DEFS@ @LVM_DEFS@
+DEFS += @DEFS@
 CFLAGS += @CFLAGS@
 CLDFLAGS += @CLDFLAGS@
 LDDEPS += @LDDEPS@
@@ -56,9 +56,10 @@
 
 .SUFFIXES: .c .d .o .so .a .po .pot .mo .dylib
 
-CFLAGS += -fPIC -Wall -Wundef -Wshadow -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -Winline -D_FILE_OFFSET_BITS=64
+CFLAGS += -fPIC -Wall -Wundef -Wshadow -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -Winline -Wmissing-noreturn -D_FILE_OFFSET_BITS=64
 
-#CFLAGS += -W -Wconversion -Wpointer-arith -Wredundant-decls -Wbad-function-cast -Wcast-qual -Wmissing-noreturn
+#CFLAGS += -W -Wconversion -Wpointer-arith -Wredundant-decls -Wbad-function-cast -Wcast-qual
+#CFLAGS += -pedantic -std=gnu99
 
 CFLAGS += @COPTIMISE_FLAG@
 

Modified: lvm2/trunk/man/lvcreate.8
==============================================================================
--- lvm2/trunk/man/lvcreate.8	(original)
+++ lvm2/trunk/man/lvcreate.8	Sat Jun 10 21:40:06 2006
@@ -13,6 +13,7 @@
 [\-M/\-\-persistent y/n] [\-\-minor minor]
 [\-n/\-\-name LogicalVolumeName]
 [\-p/\-\-permission r/rw] [\-r/\-\-readahead ReadAheadSectors]
+[-R|--regionsize MirrorLogRegionSize]
 [\-t/\-\-test]
 [\-v/\-\-verbose] [\-Z/\-\-zero y/n]
 VolumeGroupName [PhysicalVolumePath...]
@@ -57,7 +58,9 @@
 .I \-I, \-\-stripesize StripeSize
 Gives the number of kilobytes for the granularity of the stripes.
 .br
-StripeSize must be 2^n (n = 2 to 9)
+StripeSize must be 2^n (n = 2 to 9) for metadata in LVM1 format.
+For metadata in LVM2 format, the stripe size may be a larger
+power of 2 but must not exceed the physical extent size.
 .TP
 .I \-l, \-\-extents LogicalExtentsNumber
 Gives the number of logical extents to allocate for the new
@@ -91,6 +94,10 @@
 Set read ahead sector count of this logical volume to a value between 2 and 120.
 Ignored by device-mapper.
 .TP
+.I \-R \-\-regionsize MirrorLogRegionSize
+A mirror is divided into regions of this size (in KB), and the mirror log 
+uses this granularity to track which regions are in sync.
+.TP
 .I \-s, \-\-snapshot
 Create a snapshot logical volume (or snapshot) for an existing, so called
 original logical volume (or origin).

Modified: lvm2/trunk/man/lvs.8
==============================================================================
--- lvm2/trunk/man/lvs.8	(original)
+++ lvm2/trunk/man/lvs.8	Sat Jun 10 21:40:06 2006
@@ -44,7 +44,7 @@
 The lv_attr bits are: 
 .RS
 .IP 1 3
-Volume type: (m)irrored, (o)rigin, (p)vmove, (s)napshot, 
+Volume type: (m)irrored, (M)irrored without initial sync, (o)rigin, (p)vmove, (s)napshot, 
 invalid (S)napshot, (v)irtual
 .IP 2 3
 Permissions: (w)riteable, (r)ead-only

Modified: lvm2/trunk/tools/Makefile.in
==============================================================================
--- lvm2/trunk/tools/Makefile.in	(original)
+++ lvm2/trunk/tools/Makefile.in	Sat Jun 10 21:40:06 2006
@@ -86,7 +86,7 @@
 
 LVMLIBS = -llvm
 
-CLEAN_TARGETS = liblvm2cmd.so liblvm2cmd.a lvm lvm.static lvm.cflow lvm.xref lvm.tree lvm.rxref lvm.rtree
+CLEAN_TARGETS = liblvm2cmd.so liblvm2cmd.a lvm lvm.o lvm.static lvm.cflow lvm.xref lvm.tree lvm.rxref lvm.rtree
 
 ifeq ("@CMDLIB@", "yes")
 	TARGETS += liblvm2cmd.so

Modified: lvm2/trunk/tools/args.h
==============================================================================
--- lvm2/trunk/tools/args.h	(original)
+++ lvm2/trunk/tools/args.h	Sat Jun 10 21:40:06 2006
@@ -45,6 +45,9 @@
 arg(alloc_ARG, '\0', "alloc", alloc_arg)
 arg(separator_ARG, '\0', "separator", string_arg)
 arg(mirrorsonly_ARG, '\0', "mirrorsonly", NULL)
+arg(nosync_ARG, '\0', "nosync", NULL)
+arg(corelog_ARG, '\0', "corelog", NULL)
+arg(monitor_ARG, '\0', "monitor", yes_no_arg)
 
 /* Allow some variations */
 arg(resizable_ARG, '\0', "resizable", yes_no_arg)

Modified: lvm2/trunk/tools/commands.h
==============================================================================
--- lvm2/trunk/tools/commands.h	(original)
+++ lvm2/trunk/tools/commands.h	Sat Jun 10 21:40:06 2006
@@ -63,6 +63,7 @@
    "\t[-f|--force]\n"
    "\t[-h|--help]\n"
    "\t[--ignorelockingfailure]\n"
+   "\t[--monitor {y|n}]\n"
    "\t[-M|--persistent y|n] [--major major] [--minor minor]\n"
    "\t[-P|--partial] " "\n"
    "\t[-p|--permission r|rw]\n"
@@ -74,14 +75,14 @@
    "\tLogicalVolume[Path] [LogicalVolume[Path]...]\n",
 
    alloc_ARG, autobackup_ARG, available_ARG, contiguous_ARG, force_ARG,
-   ignorelockingfailure_ARG, major_ARG, minor_ARG, partial_ARG, permission_ARG,
-   persistent_ARG, readahead_ARG, refresh_ARG, addtag_ARG, deltag_ARG,
-   test_ARG)
+   ignorelockingfailure_ARG, major_ARG, minor_ARG, monitor_ARG,
+   partial_ARG, permission_ARG, persistent_ARG, readahead_ARG,
+   refresh_ARG, addtag_ARG, deltag_ARG, test_ARG)
 
 xx(lvconvert,
    "Change logical volume layout",
    "lvconvert "
-   "[-m|--mirrors Mirrors]\n"
+   "[-m|--mirrors Mirrors [--corelog]]\n"
    "\t[--alloc AllocationPolicy]\n"
    "\t[-d|--debug]\n"
    "\t[-h|-?|--help]\n"
@@ -99,7 +100,8 @@
    "\t[--version]" "\n"
    "\tOriginalLogicalVolume[Path] SnapshotLogicalVolume[Path]\n",
 
-   alloc_ARG, chunksize_ARG, mirrors_ARG, snapshot_ARG, test_ARG, zero_ARG)
+   alloc_ARG, chunksize_ARG, mirrors_ARG, corelog_ARG,
+   snapshot_ARG, test_ARG, zero_ARG)
 
 xx(lvcreate,
    "Create a logical volume",
@@ -114,7 +116,7 @@
    "\t{-l|--extents LogicalExtentsNumber |\n"
    "\t -L|--size LogicalVolumeSize[kKmMgGtT]}\n"
    "\t[-M|--persistent {y|n}] [--major major] [--minor minor]\n"
-   "\t[-m|--mirrors Mirrors]\n"
+   "\t[-m|--mirrors Mirrors [--nosync] [--corelog]]\n"
    "\t[-n|--name LogicalVolumeName]\n"
    "\t[-p|--permission {r|rw}]\n"
    "\t[-r|--readahead ReadAheadSectors]\n"
@@ -147,9 +149,10 @@
    "\tOriginalLogicalVolume[Path] [PhysicalVolumePath...]\n\n",
 
    addtag_ARG, alloc_ARG, autobackup_ARG, chunksize_ARG, contiguous_ARG,
-   extents_ARG, major_ARG, minor_ARG, mirrors_ARG, name_ARG, permission_ARG,
-   persistent_ARG, readahead_ARG, regionsize_ARG, size_ARG, snapshot_ARG,
-   stripes_ARG, stripesize_ARG, test_ARG, type_ARG, zero_ARG)
+   corelog_ARG, extents_ARG, major_ARG, minor_ARG, mirrors_ARG, name_ARG,
+   nosync_ARG, permission_ARG, persistent_ARG, readahead_ARG, regionsize_ARG,
+   size_ARG, snapshot_ARG, stripes_ARG, stripesize_ARG, test_ARG, type_ARG,
+   zero_ARG)
 
 xx(lvdisplay,
    "Display information about a logical volume",
@@ -345,7 +348,7 @@
    "\t[-v|--verbose]\n"
    "\t[--version]" "\n"
    "\t[LogicalVolume[Path] [LogicalVolume[Path]...]]\n",
-   
+
    aligned_ARG, all_ARG, ignorelockingfailure_ARG, noheadings_ARG,
    nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG, segments_ARG,
    separator_ARG, sort_ARG, unbuffered_ARG, units_ARG)
@@ -492,7 +495,7 @@
    "\tSourcePhysicalVolume[:PhysicalExtent[-PhysicalExtent]...]}\n"
    "\t[DestinationPhysicalVolume[:PhysicalExtent[-PhysicalExtent]...]...]\n",
 
-   abort_ARG, alloc_ARG, autobackup_ARG, background_ARG, 
+   abort_ARG, alloc_ARG, autobackup_ARG, background_ARG,
    interval_ARG, name_ARG, test_ARG)
 
 xx(pvremove,
@@ -529,7 +532,7 @@
    "\t[-v|--verbose]\n"
    "\t[--version]\n"
    "\t[PhysicalVolume [PhysicalVolume...]]\n",
-   
+
    aligned_ARG, all_ARG, ignorelockingfailure_ARG, noheadings_ARG,
    nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG, segments_ARG,
    separator_ARG, sort_ARG, unbuffered_ARG, units_ARG)
@@ -593,6 +596,7 @@
    "\t[-d|--debug] " "\n"
    "\t[-h|--help] " "\n"
    "\t[--ignorelockingfailure]\n"
+   "\t[--monitor {y|n}]\n"
    "\t[-t|--test]" "\n"
    "\t[-u|--uuid] " "\n"
    "\t[-v|--verbose] " "\n"
@@ -608,8 +612,8 @@
 
    addtag_ARG, alloc_ARG, allocation_ARG, autobackup_ARG, available_ARG,
    clustered_ARG, deltag_ARG, ignorelockingfailure_ARG, logicalvolume_ARG,
-   partial_ARG, physicalextentsize_ARG, resizeable_ARG, resizable_ARG,
-   test_ARG, uuid_ARG)
+   monitor_ARG, partial_ARG, physicalextentsize_ARG, resizeable_ARG,
+   resizable_ARG, test_ARG, uuid_ARG)
 
 xx(vgck,
    "Check the consistency of volume group(s)",
@@ -820,7 +824,7 @@
    "\t[-v|--verbose]\n"
    "\t[--version]\n"
    "\t[VolumeGroupName [VolumeGroupName...]]\n",
-   
+
    aligned_ARG, all_ARG, ignorelockingfailure_ARG, noheadings_ARG,
    nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG, separator_ARG,
    sort_ARG, unbuffered_ARG, units_ARG)
@@ -833,7 +837,7 @@
    "\t[--ignorelockingfailure]\n"
    "\t[--mknodes]\n"
    "\t[-P|--partial] " "\n"
-   "\t[-v|--verbose]\n" 
+   "\t[-v|--verbose]\n"
    "\t[--version]" "\n",
 
    ignorelockingfailure_ARG, mknodes_ARG, partial_ARG)

Modified: lvm2/trunk/tools/formats.c
==============================================================================
--- lvm2/trunk/tools/formats.c	(original)
+++ lvm2/trunk/tools/formats.c	Sat Jun 10 21:40:06 2006
@@ -15,7 +15,8 @@
 
 #include "tools.h"
 
-int formats(struct cmd_context *cmd, int argc, char **argv)
+int formats(struct cmd_context *cmd, int argc __attribute((unused)),
+	    char **argv __attribute((unused)))
 {
 	display_formats(cmd);
 

Modified: lvm2/trunk/tools/lvchange.c
==============================================================================
--- lvm2/trunk/tools/lvchange.c	(original)
+++ lvm2/trunk/tools/lvchange.c	Sat Jun 10 21:40:06 2006
@@ -72,6 +72,38 @@
 	return 1;
 }
 
+static int lvchange_registration(struct cmd_context *cmd,
+				 struct logical_volume *lv)
+{
+	int r;
+	struct lvinfo info;
+
+	if (!lv_info(cmd, lv, &info, 0) || !info.exists) {
+		log_error("Logical volume, %s, is not active", lv->name);
+		return 0;
+	}
+
+	/* do not register pvmove lv's */
+	if (lv->status & PVMOVE)
+		return 1;
+
+	log_verbose("%smonitoring logical volume \"%s\"",
+		    (dmeventd_register_mode()) ? "" : "Not ", lv->name);
+	r = register_dev_for_events(cmd, lv, dmeventd_register_mode());
+
+	if (r < 0) {
+		log_error("Unable to %smonitor logical volume, %s",
+			  (dmeventd_register_mode()) ? "" : "un", lv->name);
+		r = 0;
+	} else if (!r) {
+		log_verbose("Logical volume %s needs no monitoring.",
+			    lv->name);
+		r = 1;
+	}
+
+	return r;
+}
+
 static int lvchange_availability(struct cmd_context *cmd,
 				 struct logical_volume *lv)
 {
@@ -150,7 +182,7 @@
 
 	want_contiguous = strcmp(arg_str_value(cmd, contiguous_ARG, "n"), "n");
 	alloc = want_contiguous ? ALLOC_CONTIGUOUS : ALLOC_INHERIT;
-	alloc = (alloc_policy_t) arg_uint_value(cmd, alloc_ARG, alloc);
+	alloc = arg_uint_value(cmd, alloc_ARG, alloc);
 
 	if (alloc == lv->alloc) {
 		log_error("Allocation policy of logical volume \"%s\" is "
@@ -186,7 +218,7 @@
 static int lvchange_readahead(struct cmd_context *cmd,
 			      struct logical_volume *lv)
 {
-	unsigned int read_ahead = 0;
+	unsigned read_ahead = 0;
 
 	read_ahead = arg_uint_value(cmd, readahead_ARG, 0);
 
@@ -369,7 +401,7 @@
 }
 
 static int lvchange_single(struct cmd_context *cmd, struct logical_volume *lv,
-			   void *handle)
+			   void *handle __attribute((unused)))
 {
 	int doit = 0;
 	int archived = 0;
@@ -422,6 +454,8 @@
 		return ECMD_FAILED;
 	}
 
+	init_dmeventd_register(arg_int_value(cmd, monitor_ARG, DEFAULT_DMEVENTD_MONITOR));
+
 	/* access permission change */
 	if (arg_count(cmd, permission_ARG)) {
 		if (!archive(lv->vg))
@@ -474,14 +508,22 @@
 		log_print("Logical volume \"%s\" changed", lv->name);
 
 	/* availability change */
-	if (arg_count(cmd, available_ARG))
+	if (arg_count(cmd, available_ARG)) {
 		if (!lvchange_availability(cmd, lv))
 			return ECMD_FAILED;
+	}
 
 	if (arg_count(cmd, refresh_ARG))
 		if (!lvchange_refresh(cmd, lv))
 			return ECMD_FAILED;
 
+	if (!arg_count(cmd, available_ARG) &&
+	    !arg_count(cmd, refresh_ARG) &&
+	    arg_count(cmd, monitor_ARG)) {
+		if (!lvchange_registration(cmd, lv))
+			return ECMD_FAILED;
+	}
+
 	return ECMD_PROCESSED;
 }
 
@@ -492,9 +534,10 @@
 	    && !arg_count(cmd, minor_ARG) && !arg_count(cmd, major_ARG)
 	    && !arg_count(cmd, persistent_ARG) && !arg_count(cmd, addtag_ARG)
 	    && !arg_count(cmd, deltag_ARG) && !arg_count(cmd, refresh_ARG)
-	    && !arg_count(cmd, alloc_ARG)) {
-		log_error("One or more of -a, -C, -j, -m, -M, -p, -r, "
-			  "--refresh, --alloc, --addtag or --deltag required");
+	    && !arg_count(cmd, alloc_ARG) && !arg_count(cmd, monitor_ARG)) {
+		log_error("Need 1 or more of -a, -C, -j, -m, -M, -p, -r, "
+			  "--refresh, --alloc, --addtag, --deltag "
+			  "or --monitor");
 		return EINVALID_CMD_LINE;
 	}
 

Modified: lvm2/trunk/tools/lvconvert.c
==============================================================================
--- lvm2/trunk/tools/lvconvert.c	(original)
+++ lvm2/trunk/tools/lvconvert.c	Sat Jun 10 21:40:06 2006
@@ -101,6 +101,9 @@
 static int _read_params(struct lvconvert_params *lp, struct cmd_context *cmd,
 			int argc, char **argv)
 {
+	int region_size;
+	int pagesize = getpagesize();
+
 	memset(lp, 0, sizeof(*lp));
 
 	if (arg_count(cmd, mirrors_ARG) + arg_count(cmd, snapshot_ARG) != 1) {
@@ -119,8 +122,7 @@
 
 	lp->alloc = ALLOC_INHERIT;
 	if (arg_count(cmd, alloc_ARG))
-		lp->alloc = (alloc_policy_t) arg_uint_value(cmd, alloc_ARG,
-							    lp->alloc);
+		lp->alloc = arg_uint_value(cmd, alloc_ARG, lp->alloc);
 
 	if (lp->snapshot) {
 		if (arg_count(cmd, regionsize_ARG)) {
@@ -165,6 +167,7 @@
 	 	 * --regionsize is only valid if converting an LV into a mirror.
 	 	 * Checked when we know the state of the LV being converted.
 	 	 */
+
 		if (arg_count(cmd, regionsize_ARG)) {
 			if (arg_sign_value(cmd, regionsize_ARG, 0) ==
 				    SIGN_MINUS) {
@@ -173,17 +176,37 @@
 			}
 			lp->region_size = 2 * arg_uint_value(cmd,
 							     regionsize_ARG, 0);
-		} else
-			lp->region_size = 2 * find_config_int(cmd->cft->root,
+		} else {
+			region_size = 2 * find_config_int(cmd->cft->root,
 						"activation/mirror_region_size",
 						DEFAULT_MIRROR_REGION_SIZE);
-	
+			if (region_size < 0) {
+				log_error("Negative regionsize in "
+					  "configuration file is invalid");
+				return 0;
+			}
+			lp->region_size = region_size;
+		}
+
+		if (lp->region_size % (pagesize >> SECTOR_SHIFT)) {
+			log_error("Region size (%" PRIu32 ") must be "
+				  "a multiple of machine memory "
+				  "page size (%d)",
+				  lp->region_size, pagesize >> SECTOR_SHIFT);
+			return 0;
+		}
+
 		if (lp->region_size & (lp->region_size - 1)) {
 			log_error("Region size (%" PRIu32
 				  ") must be a power of 2", lp->region_size);
 			return 0;
 		}
 
+		if (!lp->region_size) {
+			log_error("Non-zero region size must be supplied.");
+			return 0;
+		}
+
 		if (!(lp->segtype = get_segtype_from_string(cmd, "striped")))
 			return_0;
 	}
@@ -212,6 +235,8 @@
 	struct alloc_handle *ah = NULL;
 	struct logical_volume *log_lv;
 	struct list *parallel_areas;
+	struct segment_type *segtype;  /* FIXME: could I just use lp->segtype */
+	float sync_percent;
 
 	seg = first_seg(lv);
 	existing_mirrors = seg->area_count;
@@ -254,10 +279,71 @@
 				return 0;
 			}
 			if (lp->mirrors == existing_mirrors) {
-				log_error("Logical volume %s already has %"
-					  PRIu32 " mirror(s).", lv->name,
-					  lp->mirrors - 1);
-				return 1;
+				if (!seg->log_lv && !arg_count(cmd, corelog_ARG)) {
+					/* No disk log present, add one. */
+					/* FIXME: Why doesn't this work?  Without
+					   it, we will probably put the log on the
+					   same device as a mirror leg.
+					  if (!(parallel_areas = build_parallel_areas_from_lv(cmd, lv))) {
+					  stack;
+					  return 0;
+					  }
+					*/
+					parallel_areas = NULL;
+					if (!lv_mirror_percent(cmd, lv, 0, &sync_percent, NULL)) {
+						log_error("Unable to determine mirror sync status.");
+						return 0;
+					}
+
+					segtype = get_segtype_from_string(cmd, "striped");
+
+					if (!(ah = allocate_extents(lv->vg, NULL, segtype, 1,
+								    0, 1, 0,
+								    NULL, 0, 0, lp->pvh,
+								    lp->alloc,
+								    parallel_areas))) {
+						stack;
+						return 0;
+					}
+
+					if (sync_percent >= 100.0)
+						init_mirror_in_sync(1);
+					else
+						init_mirror_in_sync(0);
+
+					if (!(log_lv = create_mirror_log(cmd, lv->vg, ah,
+									 lp->alloc, lv->name,
+									 (sync_percent >= 100.0) ?
+									 1 : 0))) {
+						log_error("Failed to create mirror log.");
+						return 0;
+					}
+					seg->log_lv = log_lv;
+					log_lv->status |= MIRROR_LOG;
+					first_seg(log_lv)->mirror_seg = seg;
+				} else if (seg->log_lv && arg_count(cmd, corelog_ARG)) {
+					/* Had disk log, switch to core. */
+					if (!lv_mirror_percent(cmd, lv, 0, &sync_percent, NULL)) {
+						log_error("Unable to determine mirror sync status.");
+						return 0;
+					}
+
+					if (sync_percent >= 100.0)
+						init_mirror_in_sync(1);
+					else
+						init_mirror_in_sync(0);
+
+					if (!remove_mirror_images(seg, lp->mirrors,
+								  lp->pv_count ?
+								  lp->pvh : NULL, 1))
+						return_0;
+				} else {
+					/* No change */
+					log_error("Logical volume %s already has %"
+						  PRIu32 " mirror(s).", lv->name,
+						  lp->mirrors - 1);
+					return 1;
+				}
 			}
 			if (lp->mirrors > existing_mirrors) {
 				/* FIXME Unless anywhere, remove PV of log_lv 
@@ -291,7 +377,8 @@
 				return_0;
 
 			if (!(ah = allocate_extents(lv->vg, NULL, lp->segtype,
-						    1, lp->mirrors - 1, 1,
+						    1, lp->mirrors - 1,
+						    arg_count(cmd, corelog_ARG) ? 0 : 1,
 						    lv->le_count * (lp->mirrors - 1),
 						    NULL, 0, 0, lp->pvh,
 						    lp->alloc,
@@ -302,9 +389,11 @@
 								      lv->le_count,
 								      lp->region_size);
 
-			if (!(log_lv = create_mirror_log(cmd, lv->vg, ah,
+			log_lv = NULL;
+			if (!arg_count(cmd, corelog_ARG) &&
+			    !(log_lv = create_mirror_log(cmd, lv->vg, ah,
 							 lp->alloc,
-							 lv->name))) {
+							 lv->name, 0))) {
 				log_error("Failed to create mirror log.");
 				return 0;
 			}
@@ -367,7 +456,7 @@
 
 	if (!lp->zero)
 		log_error("WARNING: \"%s\" not zeroed", lv->name);
-	else if (!zero_lv(cmd, lv)) {
+	else if (!set_lv(cmd, lv, 0)) {
 			log_error("Aborting. Failed to wipe snapshot "
 				  "exception store.");
 			return 0;

Modified: lvm2/trunk/tools/lvcreate.c
==============================================================================
--- lvm2/trunk/tools/lvcreate.c	(original)
+++ lvm2/trunk/tools/lvcreate.c	Sat Jun 10 21:40:06 2006
@@ -24,6 +24,8 @@
 	int zero;
 	int major;
 	int minor;
+	int corelog;
+	int nosync;
 
 	char *origin;
 	const char *vg_name;
@@ -36,7 +38,7 @@
 
 	uint32_t mirrors;
 
-	struct segment_type *segtype;
+	const struct segment_type *segtype;
 
 	/* size */
 	uint32_t extents;
@@ -154,7 +156,7 @@
 }
 
 static int _read_size_params(struct lvcreate_params *lp,
-			     struct cmd_context *cmd, int *pargc, char ***pargv)
+			     struct cmd_context *cmd)
 {
 	if (arg_count(cmd, extents_ARG) + arg_count(cmd, size_ARG) != 1) {
 		log_error("Please specify either size or extents (not both)");
@@ -181,9 +183,13 @@
 	return 1;
 }
 
+/* The stripe size is limited by the size of a uint32_t, but since the
+ * value given by the user is doubled, and the final result must be a
+ * power of 2, we must divide UINT_MAX by four and add 1 (to round it
+ * up to the power of 2) */
 static int _read_stripe_params(struct lvcreate_params *lp,
 			       struct cmd_context *cmd,
-			       int *pargc, char ***pargv)
+			       int *pargc)
 {
 	int argc = *pargc;
 
@@ -192,6 +198,12 @@
 			log_error("Negative stripesize is invalid");
 			return 0;
 		}
+		/* Check to make sure we won't overflow lp->stripe_size */
+		if(arg_uint_value(cmd, stripesize_ARG, 0) > STRIPE_SIZE_LIMIT) {
+			log_error("Stripe size cannot be larger than %s",
+				  display_size(cmd, (uint64_t) STRIPE_SIZE_LIMIT));
+			return 0;
+		}
 		lp->stripe_size = 2 * arg_uint_value(cmd, stripesize_ARG, 0);
 	}
 
@@ -204,7 +216,8 @@
 		lp->stripe_size = find_config_int(cmd->cft->root,
 						  "metadata/stripesize",
 						  DEFAULT_STRIPESIZE) * 2;
-		log_print("Using default stripesize %dKB", lp->stripe_size / 2);
+		log_print("Using default stripesize %s",
+			  display_size(cmd, (uint64_t) lp->stripe_size));
 	}
 
 	if (argc && (unsigned) argc < lp->stripes) {
@@ -219,10 +232,11 @@
 		return 0;
 	}
 
+	/* MAX size check is in _lvcreate */
 	if (lp->stripes > 1 && (lp->stripe_size < STRIPE_SIZE_MIN ||
-				lp->stripe_size > STRIPE_SIZE_MAX ||
 				lp->stripe_size & (lp->stripe_size - 1))) {
-		log_error("Invalid stripe size %d", lp->stripe_size);
+		log_error("Invalid stripe size %s",
+			  display_size(cmd, (uint64_t) lp->stripe_size));
 		return 0;
 	}
 
@@ -231,9 +245,11 @@
 
 static int _read_mirror_params(struct lvcreate_params *lp,
 			       struct cmd_context *cmd,
-			       int *pargc, char ***pargv)
+			       int *pargc)
 {
 	int argc = *pargc;
+	int region_size;
+	int pagesize = getpagesize();
 
 	if (argc && (unsigned) argc < lp->mirrors) {
 		log_error("Too few physical volumes on "
@@ -247,10 +263,17 @@
 			return 0;
 		}
 		lp->region_size = 2 * arg_uint_value(cmd, regionsize_ARG, 0);
-	} else
-		lp->region_size = 2 * find_config_int(cmd->cft->root,
+	} else {
+		region_size = 2 * find_config_int(cmd->cft->root,
 					"activation/mirror_region_size",
 					DEFAULT_MIRROR_REGION_SIZE);
+		if (region_size < 0) {
+			log_error("Negative regionsize in configuration file "
+				  "is invalid");
+			return 0;
+		}
+		lp->region_size = region_size;
+	}
 
 	if (lp->region_size & (lp->region_size - 1)) {
 		log_error("Region size (%" PRIu32 ") must be a power of 2",
@@ -258,6 +281,21 @@
 		return 0;
 	}
 
+	if (lp->region_size % (pagesize >> SECTOR_SHIFT)) {
+		log_error("Region size (%" PRIu32 ") must be a multiple of "
+			  "machine memory page size (%d)",
+			  lp->region_size, pagesize >> SECTOR_SHIFT);
+		return 0;
+	}
+
+	if (!lp->region_size) {
+		log_error("Non-zero region size must be supplied.");
+		return 0;
+	}
+
+	lp->corelog = arg_count(cmd, corelog_ARG) ? 1 : 0;
+	lp->nosync = arg_count(cmd, nosync_ARG) ? 1 : 0;
+
 	return 1;
 }
 
@@ -271,7 +309,7 @@
 	/*
 	 * Check selected options are compatible and determine segtype
 	 */
-	lp->segtype = (struct segment_type *)
+	lp->segtype = (const struct segment_type *)
 	    arg_ptr_value(cmd, type_ARG,
 			  get_segtype_from_string(cmd, "striped"));
 
@@ -344,6 +382,16 @@
 			stack;
 			return 0;
 		}
+	} else {
+		if (arg_count(cmd, corelog_ARG)) {
+			log_error("--corelog is only available with mirrors");
+			return 0;
+		}
+
+		if (arg_count(cmd, nosync_ARG)) {
+			log_error("--nosync is only available with mirrors");
+			return 0;
+		}
 	}
 
 	if (activation() && lp->segtype->ops->target_present &&
@@ -354,9 +402,9 @@
 	}
 
 	if (!_lvcreate_name_params(lp, cmd, &argc, &argv) ||
-	    !_read_size_params(lp, cmd, &argc, &argv) ||
-	    !_read_stripe_params(lp, cmd, &argc, &argv) ||
-	    !_read_mirror_params(lp, cmd, &argc, &argv)) {
+	    !_read_size_params(lp, cmd) ||
+	    !_read_stripe_params(lp, cmd, &argc) ||
+	    !_read_mirror_params(lp, cmd, &argc)) {
 		stack;
 		return 0;
 	}
@@ -374,7 +422,7 @@
 
 	lp->alloc = contiguous ? ALLOC_CONTIGUOUS : ALLOC_INHERIT;
 
-	lp->alloc = (alloc_policy_t) arg_uint_value(cmd, alloc_ARG, lp->alloc);
+	lp->alloc = arg_uint_value(cmd, alloc_ARG, lp->alloc);
 
 	if (contiguous && (lp->alloc != ALLOC_CONTIGUOUS)) {
 		log_error("Conflicting contiguous and alloc arguments");
@@ -484,12 +532,22 @@
 		pvh = &vg->pvs;
 
 	if (lp->stripe_size > vg->extent_size) {
-		log_error("Setting stripe size %d KB to physical extent "
-			  "size %u KB", lp->stripe_size / 2,
-			  vg->extent_size / 2);
+		log_error("Reducing requested stripe size %s to maximum, "
+			  "physical extent size %s",
+			  display_size(cmd, (uint64_t) lp->stripe_size),
+			  display_size(cmd, (uint64_t) vg->extent_size));
 		lp->stripe_size = vg->extent_size;
 	}
 
+	/* Need to check the vg's format to verify this - the cmd format isn't setup properly yet */
+	if (lp->stripes > 1 &&
+	    !(vg->fid->fmt->features & FMT_UNLIMITED_STRIPESIZE) &&
+	    (lp->stripe_size > STRIPE_SIZE_MAX)) {
+		log_error("Stripe size may not exceed %s",
+			  display_size(cmd, (uint64_t) STRIPE_SIZE_MAX));
+		return 0;
+	}
+
 	if (lp->size) {
 		/* No of 512-byte sectors */
 		tmp_size = lp->size;
@@ -498,7 +556,7 @@
 			tmp_size += vg->extent_size - tmp_size %
 			    vg->extent_size;
 			log_print("Rounding up size to full physical extent %s",
-				  display_size(cmd, tmp_size, SIZE_SHORT));
+				  display_size(cmd, tmp_size));
 		}
 
 		lp->extents = tmp_size / vg->extent_size;
@@ -591,9 +649,9 @@
 		/* FIXME Calculate how many extents needed for the log */
 
 		if (!(ah = allocate_extents(vg, NULL, lp->segtype, lp->stripes,
-					    lp->mirrors, 1, lp->extents,
-					    NULL, 0, 0, pvh, lp->alloc,
-					    NULL))) {
+					    lp->mirrors, lp->corelog ? 0 : 1,
+					    lp->extents, NULL, 0, 0,
+					    pvh, lp->alloc, NULL))) {
 			stack;
 			return 0;
 		}
@@ -602,8 +660,16 @@
 							      lp->extents,
 							      lp->region_size);
 
+		init_mirror_in_sync(lp->nosync);
+
+		if (lp->nosync) {
+			log_print("WARNING: New mirror won't be synchronised. "
+				  "Don't read what you didn't write!");
+			status |= MIRROR_NOTSYNCED;
+		}
+
 		if (!(log_lv = create_mirror_log(cmd, vg, ah, lp->alloc,
-						 lv_name))) {
+						 lv_name, lp->nosync))) {
 			log_error("Failed to create mirror log.");
 			return 0;
 		}
@@ -687,7 +753,7 @@
 	}
 
 	if ((lp->zero || lp->snapshot) && activation()) {
-		if (!zero_lv(cmd, lv) && lp->snapshot) {
+		if (!set_lv(cmd, lv, 0) && lp->snapshot) {
 			/* FIXME Remove the failed lv we just added */
 			log_error("Aborting. Failed to wipe snapshot "
 				  "exception store. Remove new LV and retry.");

Modified: lvm2/trunk/tools/lvmchange.c
==============================================================================
--- lvm2/trunk/tools/lvmchange.c	(original)
+++ lvm2/trunk/tools/lvmchange.c	Sat Jun 10 21:40:06 2006
@@ -15,7 +15,8 @@
 
 #include "tools.h"
 
-int lvmchange(struct cmd_context *cmd, int argc, char **argv)
+int lvmchange(struct cmd_context *cmd __attribute((unused)),
+	      int argc __attribute((unused)), char **argv __attribute((unused)))
 {
 	log_print("With LVM2 and the device mapper, this program is obsolete.");
 	return ECMD_FAILED;

Modified: lvm2/trunk/tools/lvmcmdline.c
==============================================================================
--- lvm2/trunk/tools/lvmcmdline.c	(original)
+++ lvm2/trunk/tools/lvmcmdline.c	Sat Jun 10 21:40:06 2006
@@ -66,7 +66,7 @@
 
 static int _interactive;
 
-int yes_no_arg(struct cmd_context *cmd, struct arg *a)
+int yes_no_arg(struct cmd_context *cmd __attribute((unused)), struct arg *a)
 {
 	a->sign = SIGN_NONE;
 
@@ -86,7 +86,8 @@
 	return 1;
 }
 
-int yes_no_excl_arg(struct cmd_context *cmd, struct arg *a)
+int yes_no_excl_arg(struct cmd_context *cmd __attribute((unused)),
+		    struct arg *a)
 {
 	a->sign = SIGN_NONE;
 
@@ -177,7 +178,7 @@
 	return 1;
 }
 
-static int _size_arg(struct cmd_context *cmd, struct arg *a, int factor)
+static int _size_arg(struct cmd_context *cmd __attribute((unused)), struct arg *a, int factor)
 {
 	char *ptr;
 	int i;
@@ -238,7 +239,7 @@
 	return _size_arg(cmd, a, 1024);
 }
 
-int int_arg(struct cmd_context *cmd, struct arg *a)
+int int_arg(struct cmd_context *cmd __attribute((unused)), struct arg *a)
 {
 	char *ptr;
 
@@ -248,7 +249,7 @@
 	return 1;
 }
 
-int int_arg_with_sign(struct cmd_context *cmd, struct arg *a)
+int int_arg_with_sign(struct cmd_context *cmd __attribute((unused)), struct arg *a)
 {
 	char *ptr;
 
@@ -258,7 +259,7 @@
 	return 1;
 }
 
-int minor_arg(struct cmd_context *cmd, struct arg *a)
+int minor_arg(struct cmd_context *cmd __attribute((unused)), struct arg *a)
 {
 	char *ptr;
 
@@ -273,7 +274,7 @@
 	return 1;
 }
 
-int major_arg(struct cmd_context *cmd, struct arg *a)
+int major_arg(struct cmd_context *cmd __attribute((unused)), struct arg *a)
 {
 	char *ptr;
 
@@ -290,13 +291,13 @@
 	return 1;
 }
 
-int string_arg(struct cmd_context *cmd, struct arg *a)
+int string_arg(struct cmd_context *cmd __attribute((unused)),
+	       struct arg *a __attribute((unused)))
 {
-
 	return 1;
 }
 
-int tag_arg(struct cmd_context *cmd, struct arg *a)
+int tag_arg(struct cmd_context *cmd __attribute((unused)), struct arg *a)
 {
 	char *pos = a->value;
 
@@ -309,7 +310,7 @@
 	return 1;
 }
 
-int permission_arg(struct cmd_context *cmd, struct arg *a)
+int permission_arg(struct cmd_context *cmd __attribute((unused)), struct arg *a)
 {
 	a->sign = SIGN_NONE;
 
@@ -325,7 +326,7 @@
 	return 1;
 }
 
-int alloc_arg(struct cmd_context *cmd, struct arg *a)
+int alloc_arg(struct cmd_context *cmd __attribute((unused)), struct arg *a)
 {
 	alloc_policy_t alloc;
 
@@ -638,7 +639,9 @@
 	return 1;
 }
 
-int version(struct cmd_context *cmd, int argc, char **argv)
+int version(struct cmd_context *cmd __attribute((unused)),
+	    int argc __attribute((unused)),
+	    char **argv __attribute((unused)))
 {
 	char vsn[80];
 
@@ -710,6 +713,8 @@
 	    !_merge_synonym(cmd, allocation_ARG, resizeable_ARG))
 		return EINVALID_CMD_LINE;
 
+	init_mirror_in_sync(0);
+
 	/* Zero indicates success */
 	return 0;
 }
@@ -744,7 +749,7 @@
 	}
 }
 
-int help(struct cmd_context *cmd, int argc, char **argv)
+int help(struct cmd_context *cmd __attribute((unused)), int argc, char **argv)
 {
 	if (!argc)
 		_display_help();
@@ -918,7 +923,7 @@
 
 static void _init_rand(void)
 {
-	srand((unsigned int) time(NULL) + (unsigned int) getpid());
+	srand((unsigned) time(NULL) + (unsigned) getpid());
 }
 
 static void _close_stray_fds(void)
@@ -963,7 +968,7 @@
 	return cmd;
 }
 
-static void _fin_commands(struct cmd_context *cmd)
+static void _fin_commands(void)
 {
 	int i;
 
@@ -975,7 +980,7 @@
 
 static void _fin(struct cmd_context *cmd)
 {
-	_fin_commands(cmd);
+	_fin_commands();
 	destroy_toolcontext(cmd);
 }
 
@@ -994,8 +999,10 @@
 		if (!magic_number) {
 			if (buffer[0] == '#' && buffer[1] == '!')
 				magic_number = 1;
-			else
-				return ENO_SUCH_CMD;
+			else {
+				ret = ENO_SUCH_CMD;
+				break;
+			}
 		}
 		if ((strlen(buffer) == sizeof(buffer) - 1)
 		    && (buffer[sizeof(buffer) - 1] - 2 != '\n')) {
@@ -1343,7 +1350,7 @@
 	return 1;
 }
 
-static void _exec_lvm1_command(struct cmd_context *cmd, int argc, char **argv)
+static void _exec_lvm1_command(char **argv)
 {
 	char path[PATH_MAX];
 
@@ -1400,7 +1407,7 @@
 				  "command specified.");
 			return ECMD_FAILED;
 		}
-		_exec_lvm1_command(cmd, argc, argv);
+		_exec_lvm1_command(argv);
 		return ECMD_FAILED;
 	}
 #ifdef READLINE_SUPPORT

Modified: lvm2/trunk/tools/lvmdiskscan.c
==============================================================================
--- lvm2/trunk/tools/lvmdiskscan.c	(original)
+++ lvm2/trunk/tools/lvmdiskscan.c	Sat Jun 10 21:40:06 2006
@@ -64,7 +64,7 @@
 		   uint64_t size, const char *what)
 {
 	log_print("%-*s [%15s] %s", max_len, dev_name(dev),
-		  display_size(cmd, size, SIZE_SHORT), what ? : "");
+		  display_size(cmd, size), what ? : "");
 }
 
 static int _check_device(struct cmd_context *cmd, struct device *dev)
@@ -91,7 +91,8 @@
 	return 1;
 }
 
-int lvmdiskscan(struct cmd_context *cmd, int argc, char **argv)
+int lvmdiskscan(struct cmd_context *cmd, int argc __attribute((unused)),
+		char **argv __attribute((unused)))
 {
 	uint64_t size;
 	struct dev_iter *iter;

Modified: lvm2/trunk/tools/lvremove.c
==============================================================================
--- lvm2/trunk/tools/lvremove.c	(original)
+++ lvm2/trunk/tools/lvremove.c	Sat Jun 10 21:40:06 2006
@@ -16,7 +16,7 @@
 #include "tools.h"
 
 static int lvremove_single(struct cmd_context *cmd, struct logical_volume *lv,
-			   void *handle)
+			   void *handle __attribute((unused)))
 {
 	struct volume_group *vg;
 	struct lvinfo info;

Modified: lvm2/trunk/tools/lvresize.c
==============================================================================
--- lvm2/trunk/tools/lvresize.c	(original)
+++ lvm2/trunk/tools/lvresize.c	Sat Jun 10 21:40:06 2006
@@ -25,7 +25,7 @@
 	uint32_t stripe_size;
 	uint32_t mirrors;
 
-	struct segment_type *segtype;
+	const struct segment_type *segtype;
 
 	/* size */
 	uint32_t extents;
@@ -178,15 +178,34 @@
 			log_error("Stripesize may not be negative.");
 			return ECMD_FAILED;
 		}
-		if (vg->fid->fmt->features & FMT_SEGMENTS)
+
+		if (arg_uint_value(cmd, stripesize_ARG, 0) > STRIPE_SIZE_LIMIT) {
+			log_error("Stripe size cannot be larger than %s",
+				  display_size(cmd, (uint64_t) STRIPE_SIZE_LIMIT));
+			return 0;
+		}
+
+		if (!(vg->fid->fmt->features & FMT_SEGMENTS))
+			log_print("Varied stripesize not supported. Ignoring.");
+		else if (arg_uint_value(cmd, stripesize_ARG, 0) > vg->extent_size) {
+                	log_error("Reducing stripe size %s to maximum, "
+				  "physical extent size %s",
+				  display_size(cmd,
+					(uint64_t) arg_uint_value(cmd, stripesize_ARG, 0) * 2),
+	                          display_size(cmd, (uint64_t) vg->extent_size));
+                	lp->stripe_size = vg->extent_size;
+        	} else
 			lp->stripe_size = 2 * arg_uint_value(cmd,
 							     stripesize_ARG, 0);
-		else
-			log_print("Varied stripesize not supported. Ignoring.");
+
 		if (lp->mirrors) {
 			log_error("Mirrors and striping cannot be combined yet.");
 			return ECMD_FAILED;
 		}
+		if (lp->stripe_size & (lp->stripe_size - 1)) {
+			log_error("Stripe size must be power of 2");
+			return 0;
+		}
 	}
 
 	lv = lvl->lv;
@@ -196,7 +215,7 @@
 		return ECMD_FAILED;
 	}
 
-	alloc = (alloc_policy_t) arg_uint_value(cmd, alloc_ARG, lv->alloc);
+	alloc = arg_uint_value(cmd, alloc_ARG, lv->alloc);
 
 	if (lp->size) {
 		if (lp->size % vg->extent_size) {
@@ -207,8 +226,7 @@
 				    (lp->size % vg->extent_size);
 
 			log_print("Rounding up size to full physical extent %s",
-				  display_size(cmd, (uint64_t) lp->size,
-					       SIZE_SHORT));
+				  display_size(cmd, (uint64_t) lp->size));
 		}
 
 		lp->extents = lp->size / vg->extent_size;
@@ -246,8 +264,7 @@
 	}
 
 	/* FIXME Support LVs with mixed segment types */
-	if (lp->segtype != (struct segment_type *) arg_ptr_value(cmd, type_ARG,
-								 lp->segtype)) {
+	if (lp->segtype != arg_ptr_value(cmd, type_ARG, lp->segtype)) {
 		log_error("VolumeType does not match (%s)", lp->segtype->name);
 		return EINVALID_CMD_LINE;
 	}
@@ -279,16 +296,16 @@
 
 		if (!lp->stripe_size && lp->stripes > 1) {
 			if (seg_stripesize) {
-				log_print("Using stripesize of last segment "
-					  "%dKB", seg_stripesize / 2);
+				log_print("Using stripesize of last segment %s",
+					  display_size(cmd, (uint64_t) seg_stripesize));
 				lp->stripe_size = seg_stripesize;
 			} else {
 				lp->stripe_size =
 					find_config_int(cmd->cft->root,
 							"metadata/stripesize",
 							DEFAULT_STRIPESIZE) * 2;
-				log_print("Using default stripesize %dKB",
-					  lp->stripe_size / 2);
+				log_print("Using default stripesize %s",
+					  display_size(cmd, (uint64_t) lp->stripe_size));
 			}
 		}
 	}
@@ -362,6 +379,12 @@
 				  lp->extents, lp->extents - size_rest);
 			lp->extents = lp->extents - size_rest;
 		}
+
+		if (lp->stripe_size < STRIPE_SIZE_MIN) {
+			log_error("Invalid stripe size %s",
+				  display_size(cmd, (uint64_t) lp->stripe_size));
+			return 0;
+		}
 	}
 
 	if (lp->extents == lv->le_count) {
@@ -439,8 +462,7 @@
 			log_print("WARNING: Reducing active%s logical volume "
 				  "to %s", info.open_count ? " and open" : "",
 				  display_size(cmd, (uint64_t) lp->extents *
-						    vg->extent_size,
-					       SIZE_SHORT));
+						    vg->extent_size));
 
 			log_print("THIS MAY DESTROY YOUR DATA "
 				  "(filesystem etc.)");
@@ -495,8 +517,7 @@
 	log_print("%sing logical volume %s to %s",
 		  (lp->resize == LV_REDUCE) ? "Reduc" : "Extend",
 		  lp->lv_name,
-		  display_size(cmd, (uint64_t) lp->extents * vg->extent_size,
-			       SIZE_SHORT));
+		  display_size(cmd, (uint64_t) lp->extents * vg->extent_size));
 
 	if (lp->resize == LV_REDUCE) {
 		if (!lv_reduce(lv, lv->le_count - lp->extents)) {

Modified: lvm2/trunk/tools/lvscan.c
==============================================================================
--- lvm2/trunk/tools/lvscan.c	(original)
+++ lvm2/trunk/tools/lvscan.c	Sat Jun 10 21:40:06 2006
@@ -16,7 +16,7 @@
 #include "tools.h"
 
 static int lvscan_single(struct cmd_context *cmd, struct logical_volume *lv,
-			 void *handle)
+			 void *handle __attribute((unused)))
 {
 	struct lvinfo info;
 	int lv_total = 0;
@@ -63,7 +63,7 @@
 
 	log_print("%s%s '%s%s/%s' [%s] %s", active_str, snapshot_str,
 		  cmd->dev_dir, lv->vg->name, lv->name,
-		  display_size(cmd, lv->size, SIZE_SHORT),
+		  display_size(cmd, lv->size),
 		  get_alloc_string(lv->alloc));
 
 	lv_total++;

Modified: lvm2/trunk/tools/polldaemon.c
==============================================================================
--- lvm2/trunk/tools/polldaemon.c	(original)
+++ lvm2/trunk/tools/polldaemon.c	Sat Jun 10 21:40:06 2006
@@ -18,7 +18,7 @@
 #include <signal.h>
 #include <sys/wait.h>
 
-static void _sigchld_handler(int sig)
+static void _sigchld_handler(int sig __attribute((unused)))
 {
 	while (wait4(-1, NULL, WNOHANG | WUNTRACED, NULL) > 0) ;
 }

Modified: lvm2/trunk/tools/pvchange.c
==============================================================================
--- lvm2/trunk/tools/pvchange.c	(original)
+++ lvm2/trunk/tools/pvchange.c	Sat Jun 10 21:40:06 2006
@@ -18,7 +18,7 @@
 /* FIXME Locking.  PVs in VG. */
 
 static int _pvchange_single(struct cmd_context *cmd, struct physical_volume *pv,
-			    void *handle)
+			    void *handle __attribute((unused)))
 {
 	struct volume_group *vg = NULL;
 	struct pv_list *pvl;

Modified: lvm2/trunk/tools/pvcreate.c
==============================================================================
--- lvm2/trunk/tools/pvcreate.c	(original)
+++ lvm2/trunk/tools/pvcreate.c	Sat Jun 10 21:40:06 2006
@@ -96,7 +96,7 @@
 	     (yes_no_prompt("Software RAID md superblock "
 			    "detected on %s. Wipe it? [y/n] ", name) == 'y'))) {
 		log_print("Wiping software RAID md superblock on %s", name);
-		if (!dev_zero(dev, md_superblock, 4)) {
+		if (!dev_set(dev, md_superblock, 4, 0)) {
 			log_error("Failed to wipe RAID md superblock on %s",
 				  name);
 			return 0;
@@ -225,7 +225,7 @@
 			goto error;
 		}
 
-		if (!dev_zero(dev, UINT64_C(0), (size_t) 2048)) {
+		if (!dev_set(dev, UINT64_C(0), (size_t) 2048, 0)) {
 			log_error("%s not wiped: aborting", pv_name);
 			dev_close(dev);
 			goto error;

Modified: lvm2/trunk/tools/pvdisplay.c
==============================================================================
--- lvm2/trunk/tools/pvdisplay.c	(original)
+++ lvm2/trunk/tools/pvdisplay.c	Sat Jun 10 21:40:06 2006
@@ -15,7 +15,8 @@
 
 #include "tools.h"
 
-static int _pvdisplay_single(struct cmd_context *cmd, struct volume_group *vg,
+static int _pvdisplay_single(struct cmd_context *cmd,
+			     struct volume_group *vg __attribute((unused)),
 			     struct physical_volume *pv, void *handle)
 {
 	uint64_t size;
@@ -29,7 +30,7 @@
 
 	if (arg_count(cmd, short_ARG)) {
 		log_print("Device \"%s\" has a capacity of %s", pv_name,
-			  display_size(cmd, size, SIZE_SHORT));
+			  display_size(cmd, size));
 		return ECMD_PROCESSED;
 	}
 
@@ -39,7 +40,7 @@
 
 	if (!pv->vg_name)
 		log_print("\"%s\" is a new physical volume of \"%s\"",
-			  pv_name, display_size(cmd, size, SIZE_SHORT));
+			  pv_name, display_size(cmd, size));
 
 	if (arg_count(cmd, colon_ARG)) {
 		pvdisplay_colons(pv);

Modified: lvm2/trunk/tools/pvmove.c
==============================================================================
--- lvm2/trunk/tools/pvmove.c	(original)
+++ lvm2/trunk/tools/pvmove.c	Sat Jun 10 21:40:06 2006
@@ -335,8 +335,7 @@
 			return ECMD_FAILED;
 		}
 
-		alloc = (alloc_policy_t) arg_uint_value(cmd, alloc_ARG,
-							ALLOC_INHERIT);
+		alloc = arg_uint_value(cmd, alloc_ARG, ALLOC_INHERIT);
 		if (alloc == ALLOC_INHERIT)
 			alloc = vg->alloc;
 
@@ -483,11 +482,11 @@
 }
 
 static struct poll_functions _pvmove_fns = {
-	get_copy_name_from_lv:get_pvmove_pvname_from_lv_mirr,
-	get_copy_vg:_get_move_vg,
-	get_copy_lv:find_pvmove_lv_from_pvname,
-	update_metadata:_update_metadata,
-	finish_copy:_finish_pvmove,
+	.get_copy_name_from_lv = get_pvmove_pvname_from_lv_mirr,
+	.get_copy_vg = _get_move_vg,
+	.get_copy_lv = find_pvmove_lv_from_pvname,
+	.update_metadata = _update_metadata,
+	.finish_copy = _finish_pvmove,
 };
 
 int pvmove_poll(struct cmd_context *cmd, const char *pv_name,
@@ -525,5 +524,5 @@
 	}
 
 	return pvmove_poll(cmd, pv_name,
-			   arg_count(cmd, background_ARG) ? 1 : 0);
+			   arg_count(cmd, background_ARG) ? 1U : 0);
 }

Modified: lvm2/trunk/tools/pvremove.c
==============================================================================
--- lvm2/trunk/tools/pvremove.c	(original)
+++ lvm2/trunk/tools/pvremove.c	Sat Jun 10 21:40:06 2006
@@ -73,7 +73,7 @@
 }
 
 static int pvremove_single(struct cmd_context *cmd, const char *pv_name,
-			   void *handle)
+			   void *handle __attribute((unused)))
 {
 	struct device *dev;
 

Modified: lvm2/trunk/tools/pvscan.c
==============================================================================
--- lvm2/trunk/tools/pvscan.c	(original)
+++ lvm2/trunk/tools/pvscan.c	Sat Jun 10 21:40:06 2006
@@ -19,10 +19,11 @@
 int vg_max_name_len = 0;
 
 static void _pvscan_display_single(struct cmd_context *cmd,
-				   struct physical_volume *pv, void *handle)
+				   struct physical_volume *pv,
+				   void *handle __attribute((unused)))
 {
 	char uuid[64];
-	unsigned int vg_name_len = 0;
+	unsigned vg_name_len = 0;
 
 	char pv_tmp_name[NAME_LEN] = { 0, };
 	char vg_tmp_name[NAME_LEN] = { 0, };
@@ -66,7 +67,7 @@
 			  pv_max_name_len, pv_tmp_name,
 			  vg_max_name_len, " ",
 			  pv->fmt ? pv->fmt->name : "    ",
-			  display_size(cmd, pv->size, SIZE_SHORT));
+			  display_size(cmd, pv->size));
 		return;
 	}
 
@@ -77,10 +78,10 @@
 			  pv_max_name_len, pv_tmp_name,
 			  vg_name_this,
 			  display_size(cmd, (uint64_t) pv->pe_count *
-				       pv->pe_size, SIZE_SHORT),
+				       pv->pe_size),
 			  display_size(cmd, (uint64_t) (pv->pe_count -
 							pv->pe_alloc_count)
-				       * pv->pe_size, SIZE_SHORT));
+				       * pv->pe_size));
 		return;
 	}
 
@@ -88,16 +89,15 @@
 	log_print("PV %-*s VG %-*s %s [%s / %s free]", pv_max_name_len,
 		  pv_tmp_name, vg_max_name_len, vg_tmp_name,
 		  pv->fmt ? pv->fmt->name : "    ",
-		  display_size(cmd, (uint64_t) pv->pe_count * pv->pe_size,
-			       SIZE_SHORT),
+		  display_size(cmd, (uint64_t) pv->pe_count * pv->pe_size),
 		  display_size(cmd,
 			       (uint64_t) (pv->pe_count - pv->pe_alloc_count) *
-					   pv->pe_size,
-			       SIZE_SHORT));
+					   pv->pe_size));
 	return;
 }
 
-int pvscan(struct cmd_context *cmd, int argc, char **argv)
+int pvscan(struct cmd_context *cmd, int argc __attribute((unused)),
+	   char **argv __attribute((unused)))
 {
 	int new_pvs_found = 0;
 	int pvs_found = 0;
@@ -185,10 +185,10 @@
 
 	log_print("Total: %d [%s] / in use: %d [%s] / in no VG: %d [%s]",
 		  pvs_found,
-		  display_size(cmd, size_total, SIZE_SHORT),
+		  display_size(cmd, size_total),
 		  pvs_found - new_pvs_found,
-		  display_size(cmd, (size_total - size_new), SIZE_SHORT),
-		  new_pvs_found, display_size(cmd, size_new, SIZE_SHORT));
+		  display_size(cmd, (size_total - size_new)),
+		  new_pvs_found, display_size(cmd, size_new));
 
 	return ECMD_PROCESSED;
 }

Modified: lvm2/trunk/tools/reporter.c
==============================================================================
--- lvm2/trunk/tools/reporter.c	(original)
+++ lvm2/trunk/tools/reporter.c	Sat Jun 10 21:40:06 2006
@@ -16,8 +16,9 @@
 #include "tools.h"
 #include "report.h"
 
-static int _vgs_single(struct cmd_context *cmd, const char *vg_name,
-		       struct volume_group *vg, int consistent, void *handle)
+static int _vgs_single(struct cmd_context *cmd __attribute((unused)),
+		       const char *vg_name, struct volume_group *vg,
+		       int consistent __attribute((unused)), void *handle)
 {
 	if (!vg) {
 		log_error("Volume group %s not found", vg_name);
@@ -44,8 +45,8 @@
 	return ECMD_PROCESSED;
 }
 
-static int _segs_single(struct cmd_context *cmd, struct lv_segment *seg,
-			void *handle)
+static int _segs_single(struct cmd_context *cmd __attribute((unused)),
+			struct lv_segment *seg, void *handle)
 {
 	if (!report_object(handle, seg->lv->vg, seg->lv, NULL, seg, NULL))
 		return ECMD_FAILED;
@@ -213,8 +214,11 @@
 			return 0;
 		}
 		if (*opts == '+') {
-			str = dm_pool_alloc(cmd->mem,
-					 strlen(options) + strlen(opts) + 1);
+			if (!(str = dm_pool_alloc(cmd->mem,
+					 strlen(options) + strlen(opts) + 1))) {
+				log_error("options string allocation failed");
+				return 0;
+			}
 			strcpy(str, options);
 			strcat(str, ",");
 			strcat(str, opts + 1);

Modified: lvm2/trunk/tools/segtypes.c
==============================================================================
--- lvm2/trunk/tools/segtypes.c	(original)
+++ lvm2/trunk/tools/segtypes.c	Sat Jun 10 21:40:06 2006
@@ -15,7 +15,8 @@
 
 #include "tools.h"
 
-int segtypes(struct cmd_context *cmd, int argc, char **argv)
+int segtypes(struct cmd_context *cmd, int argc __attribute((unused)),
+	     char **argv __attribute((unused)))
 {
 	display_segtypes(cmd);
 

Modified: lvm2/trunk/tools/stub.h
==============================================================================
--- lvm2/trunk/tools/stub.h	(original)
+++ lvm2/trunk/tools/stub.h	Sat Jun 10 21:40:06 2006
@@ -14,13 +14,27 @@
  */
 
 #define unimplemented \
-	{ log_error("Command not implemented yet."); return ECMD_FAILED;}
+	log_error("Command not implemented yet."); return ECMD_FAILED
 
 /*int e2fsadm(struct cmd_context *cmd, int argc, char **argv) unimplemented*/
-int lvmsadc(struct cmd_context *cmd, int argc, char **argv) unimplemented
-int lvmsar(struct cmd_context *cmd, int argc, char **argv) unimplemented
+int lvmsadc(struct cmd_context *cmd __attribute((unused)),
+	    int argc __attribute((unused)),
+	    char **argv __attribute((unused)))
+{
+	unimplemented;
+}
+
+int lvmsar(struct cmd_context *cmd __attribute((unused)),
+	   int argc __attribute((unused)),
+	   char **argv __attribute((unused)))
+{
+	unimplemented;
+}
 
-int pvdata(struct cmd_context *cmd, int argc, char **argv) {
+int pvdata(struct cmd_context *cmd __attribute((unused)),
+	   int argc __attribute((unused)),
+	   char **argv __attribute((unused)))
+{
 	log_error("There's no 'pvdata' command in LVM2.");
 	log_error("Use lvs, pvs, vgs instead; or use vgcfgbackup and read the text file backup.");
 	log_error("Metadata in LVM1 format can still be displayed using LVM1's pvdata command.");

Modified: lvm2/trunk/tools/toollib.c
==============================================================================
--- lvm2/trunk/tools/toollib.c	(original)
+++ lvm2/trunk/tools/toollib.c	Sat Jun 10 21:40:06 2006
@@ -15,12 +15,17 @@
 
 #include "tools.h"
 #include "lv_alloc.h"
+#include "xlate.h"
 
 #include <sys/stat.h>
 #include <sys/wait.h>
 
+/* From linux/drivers/md/dm-log.c */
+#define MIRROR_MAGIC 0x4D695272
+#define MIRROR_DISK_VERSION 2
+
 /* Command line args */
-unsigned int arg_count(struct cmd_context *cmd, int a)
+unsigned arg_count(struct cmd_context *cmd, int a)
 {
 	return cmd->args[a].count;
 }
@@ -45,7 +50,7 @@
 	return arg_count(cmd, a) ? cmd->args[a].ui_value : def;
 }
 
-int64_t arg_int64_value(struct cmd_context *cmd, int a, const uint64_t def)
+int64_t arg_int64_value(struct cmd_context *cmd, int a, const int64_t def)
 {
 	return arg_count(cmd, a) ? cmd->args[a].i64_value : def;
 }
@@ -87,11 +92,11 @@
 {
 	int ret_max = 0;
 	int ret = 0;
-	int process_all = 0;
-	int process_lv = 0;
-	int tags_supplied = 0;
-	int lvargs_supplied = 0;
-	int lvargs_matched = 0;
+	unsigned process_all = 0;
+	unsigned process_lv = 0;
+	unsigned tags_supplied = 0;
+	unsigned lvargs_supplied = 0;
+	unsigned lvargs_matched = 0;
 
 	struct lv_list *lvl;
 
@@ -405,7 +410,11 @@
 	}
 
 	log_verbose("Finding volume group \"%s\"", vg_name);
-	vg = vg_read(cmd, vg_name, vgid, &consistent);
+	if (!(vg = vg_read(cmd, vg_name, vgid, &consistent))) {
+		log_error("Volume group \"%s\" not found", vg_name);
+		unlock_vg(cmd, vg_name);
+		return ret_max;
+	}
 
 	if (!list_empty(tags)) {
 		/* Only process if a tag matches or it's on arg_vgnames */
@@ -649,7 +658,11 @@
 		if (!list_empty(&tags) && (vgnames = get_vgs(cmd, 0)) &&
 		    !list_empty(vgnames)) {
 			list_iterate_items(sll, vgnames) {
-				vg = vg_read(cmd, sll->str, NULL, &consistent);
+				if (!(vg = vg_read(cmd, sll->str, NULL, &consistent))) {
+					log_error("Volume group \"%s\" not found", sll->str);
+					ret_max = ECMD_FAILED;
+					continue;
+				}
 				if (!consistent)
 					continue;
 				ret = process_each_pv_in_vg(cmd, vg, &tags,
@@ -1082,28 +1095,30 @@
 	return 1;
 }
 
-int generate_log_name_format(struct volume_group *vg, const char *lv_name,
-			     char *buffer, size_t size)
+int generate_log_name_format(struct volume_group *vg __attribute((unused)),
+			     const char *lv_name, char *buffer, size_t size)
 {
 	if (lvm_snprintf(buffer, size, "%s_mlog", lv_name) < 0) {
 		stack;
 		return 0;
 	}
 
+	/* FIXME I think we can cope without this.  Cf. _add_lv_to_dtree()
 	if (find_lv_in_vg(vg, buffer) &&
 	    lvm_snprintf(buffer, size, "%s_mlog_%%d",
 			 lv_name) < 0) {
 		stack;
 		return 0;
 	}
+	*******/
 
 	return 1;
 }
 
 /*
- * Volumes may be zeroed to remove old application data.
+ * Initialize the LV with 'value'.
  */
-int zero_lv(struct cmd_context *cmd, struct logical_volume *lv)
+int set_lv(struct cmd_context *cmd, struct logical_volume *lv, int value)
 {
 	struct device *dev;
 	char *name;
@@ -1116,27 +1131,80 @@
 	 *	   (I know the device is at least 4k, but not 32k)
 	 */
 	if (!(name = dm_pool_alloc(cmd->mem, PATH_MAX))) {
-		log_error("Name allocation failed - device not zeroed");
+		log_error("Name allocation failed - device not cleared");
+		return 0;
+	}
+
+	if (lvm_snprintf(name, PATH_MAX, "%s%s/%s", cmd->dev_dir,
+			 lv->vg->name, lv->name) < 0) {
+		log_error("Name too long - device not cleared (%s)", lv->name);
+		return 0;
+	}
+
+	log_verbose("Clearing start of logical volume \"%s\"", lv->name);
+
+	if (!(dev = dev_cache_get(name, NULL))) {
+		log_error("%s: not found: device not cleared", name);
+		return 0;
+	}
+
+	if (!dev_open_quiet(dev))
+		return 0;
+
+	dev_set(dev, UINT64_C(0), (size_t) 4096, value);
+	dev_close_immediate(dev);
+
+	return 1;
+}
+
+
+/*
+ * This function writes a new header to the mirror log header to the lv
+ *
+ * Returns: 1 on success, 0 on failure
+ */
+static int _write_log_header(struct cmd_context *cmd, struct logical_volume *lv)
+{
+	struct device *dev;
+	char *name;
+	struct { /* The mirror log header */
+		uint32_t magic;
+		uint32_t version;
+		uint64_t nr_regions;
+	} log_header;
+
+	log_header.magic = xlate32(MIRROR_MAGIC);
+	log_header.version = xlate32(MIRROR_DISK_VERSION);
+	log_header.nr_regions = xlate64((uint64_t)-1);
+
+	if (!(name = dm_pool_alloc(cmd->mem, PATH_MAX))) {
+		log_error("Name allocation failed - log header not written (%s)",
+			lv->name);
 		return 0;
 	}
 
 	if (lvm_snprintf(name, PATH_MAX, "%s%s/%s", cmd->dev_dir,
 			 lv->vg->name, lv->name) < 0) {
-		log_error("Name too long - device not zeroed (%s)", lv->name);
+		log_error("Name too long - log header not written (%s)", lv->name);
 		return 0;
 	}
 
-	log_verbose("Zeroing start of logical volume \"%s\"", lv->name);
+	log_verbose("Writing log header to device, %s", lv->name);
 
 	if (!(dev = dev_cache_get(name, NULL))) {
-		log_error("%s: not found: device not zeroed", name);
+		log_error("%s: not found: log header not written", name);
 		return 0;
 	}
 
 	if (!dev_open_quiet(dev))
 		return 0;
 
-	dev_zero(dev, UINT64_C(0), (size_t) 4096);
+	if (!dev_write(dev, UINT64_C(0), sizeof(log_header), &log_header)) {
+		log_error("Failed to write log header to %s", name);
+		dev_close_immediate(dev);
+		return 0;
+	}
+
 	dev_close_immediate(dev);
 
 	return 1;
@@ -1146,7 +1214,8 @@
 					 struct volume_group *vg,
 					 struct alloc_handle *ah,
 					 alloc_policy_t alloc,
-					 const char *lv_name)
+					 const char *lv_name,
+					 int in_sync)
 {
 	struct logical_volume *log_lv;
 	char *log_name;
@@ -1191,12 +1260,18 @@
 		goto error;
 	}
 
-	if (activation() && !zero_lv(cmd, log_lv)) {
+	if (activation() && !set_lv(cmd, log_lv, in_sync)) {
 		log_error("Aborting. Failed to wipe mirror log. "
 			  "Remove new LV and retry.");
 		goto error;
 	}
 
+	if (!_write_log_header(cmd, log_lv)) {
+		log_error("Aborting. Failed to write mirror log header. "
+			  "Remove new LV and retry.");
+		goto error;
+	}
+
 	if (!deactivate_lv(cmd, log_lv)) {
 		log_error("Aborting. Failed to deactivate mirror log. "
 			  "Remove new LV and retry.");

Modified: lvm2/trunk/tools/toollib.h
==============================================================================
--- lvm2/trunk/tools/toollib.h	(original)
+++ lvm2/trunk/tools/toollib.h	Sat Jun 10 21:40:06 2006
@@ -97,8 +97,9 @@
 					 struct volume_group *vg,
 					 struct alloc_handle *ah,
 					 alloc_policy_t alloc,
-					 const char *lv_name);
+					 const char *lv_name,
+					 int in_sync);
 
-int zero_lv(struct cmd_context *cmd, struct logical_volume *lv);
+int set_lv(struct cmd_context *cmd, struct logical_volume *lv, int value);
 
 #endif

Modified: lvm2/trunk/tools/tools.h
==============================================================================
--- lvm2/trunk/tools/tools.h	(original)
+++ lvm2/trunk/tools/tools.h	Sat Jun 10 21:40:06 2006
@@ -19,6 +19,7 @@
 #define _GNU_SOURCE
 #define _FILE_OFFSET_BITS 64
 
+#include <configure.h>
 #include <assert.h>
 #include <libdevmapper.h>
 
@@ -95,7 +96,7 @@
 
 	int (*fn) (struct cmd_context * cmd, struct arg * a);
 
-	unsigned int count;
+	unsigned count;
 	char *value;
 	int32_t i_value;
 	uint32_t ui_value;
@@ -143,7 +144,7 @@
 const char *arg_str_value(struct cmd_context *cmd, int a, const char *def);
 int32_t arg_int_value(struct cmd_context *cmd, int a, const int32_t def); 
 uint32_t arg_uint_value(struct cmd_context *cmd, int a, const uint32_t def);
-int64_t arg_int64_value(struct cmd_context *cmd, int a, const uint64_t def);
+int64_t arg_int64_value(struct cmd_context *cmd, int a, const int64_t def);
 uint64_t arg_uint64_value(struct cmd_context *cmd, int a, const uint64_t def);
 const void *arg_ptr_value(struct cmd_context *cmd, int a, const void *def);
 sign_t arg_sign_value(struct cmd_context *cmd, int a, const sign_t def);

Modified: lvm2/trunk/tools/version.h.in
==============================================================================
--- lvm2/trunk/tools/version.h.in	(original)
+++ lvm2/trunk/tools/version.h.in	Sat Jun 10 21:40:06 2006
@@ -1 +1,3 @@
+#ifndef _LVM_VERSION_H
 #define LVM_VERSION @LVM_VERSION@
+#endif

Modified: lvm2/trunk/tools/vgcfgbackup.c
==============================================================================
--- lvm2/trunk/tools/vgcfgbackup.c	(original)
+++ lvm2/trunk/tools/vgcfgbackup.c	Sat Jun 10 21:40:06 2006
@@ -23,7 +23,11 @@
 	if (security_level())
 		return dm_strdup(template);
 
-	filename = dm_malloc(PATH_MAX);
+	if (!(filename = dm_malloc(PATH_MAX))) {
+		log_error("Failed to allocate filename.");
+		return NULL;
+	}
+
 	if (snprintf(filename, PATH_MAX, template, vg_name) < 0) {
 		log_error("Error processing filename template %s",
 			   template);

Modified: lvm2/trunk/tools/vgchange.c
==============================================================================
--- lvm2/trunk/tools/vgchange.c	(original)
+++ lvm2/trunk/tools/vgchange.c	Sat Jun 10 21:40:06 2006
@@ -15,6 +15,51 @@
 
 #include "tools.h"
 
+static int _register_lvs_in_vg(struct cmd_context *cmd,
+			       struct volume_group *vg, int reg)
+{
+	struct lv_list *lvl;
+	struct logical_volume *lv;
+	struct lvinfo info;
+	int lv_active;
+	int count = 0;
+	int r;
+
+	list_iterate_items(lvl, &vg->lvs) {
+		lv = lvl->lv;
+
+		if (!lv_info(cmd, lv, &info, 0))
+			lv_active = 0;
+		else
+			lv_active = info.exists;
+
+		/*
+		 * FIXME: Need to consider all cases... PVMOVE, etc
+		 */
+		if ((lv->status & PVMOVE) || !lv_active)
+			continue;
+
+		r = register_dev_for_events(cmd, lv, reg);
+
+		if (r < 0) {
+			log_error("Failed to %s logical volume, %s",
+				  (reg) ? "register" : "unregister",
+				  lv->name);
+			continue;
+		}
+
+		if (r)
+			count++;
+	}
+
+	/*
+	 * returns the number of monitored devices, not the number
+	 * of _new_ monitored devices
+	 */
+
+	return count;
+}
+
 static int _activate_lvs_in_vg(struct cmd_context *cmd,
 			       struct volume_group *vg, int activate)
 {
@@ -65,9 +110,23 @@
 	return count;
 }
 
+static int _vgchange_monitoring(struct cmd_context *cmd, struct volume_group *vg)
+{
+	int active, monitored;
+
+	if ((active = lvs_in_vg_activated(vg))) {
+		monitored = _register_lvs_in_vg(cmd, vg, dmeventd_register_mode());
+		log_print("%d logical volume(s) in volume group "
+			    "\"%s\" now %smonitored",
+			    monitored, vg->name, (dmeventd_register_mode()) ? "" : "un");
+	}
+
+	return ECMD_PROCESSED;
+}
+
 static int _vgchange_available(struct cmd_context *cmd, struct volume_group *vg)
 {
-	int lv_open, active;
+	int lv_open, active, monitored;
 	int available;
 	int activate = 1;
 
@@ -93,9 +152,15 @@
 	if (activate && !lockingfailed())
 		check_current_backup(vg);
 
-	if (activate && (active = lvs_in_vg_activated(vg)))
+	if (activate && (active = lvs_in_vg_activated(vg))) {
 		log_verbose("%d logical volume(s) in volume group \"%s\" "
 			    "already active", active, vg->name);
+		monitored = _register_lvs_in_vg(cmd, vg, dmeventd_register_mode());
+		log_verbose("%d existing logical volume(s) in volume "
+			    "group \"%s\" now %smonitored",
+			    monitored, vg->name,
+			    dmeventd_register_mode() ? "" : "un");
+	}
 
 	if (activate && _activate_lvs_in_vg(cmd, vg, available))
 		log_verbose("Activated logical volumes in "
@@ -114,7 +179,7 @@
 {
 	alloc_policy_t alloc;
 
-	alloc = (alloc_policy_t) arg_uint_value(cmd, alloc_ARG, ALLOC_NORMAL);
+	alloc = arg_uint_value(cmd, alloc_ARG, ALLOC_NORMAL);
 
 	if (alloc == ALLOC_INHERIT) {
 		log_error("Volume Group allocation policy cannot inherit "
@@ -290,7 +355,7 @@
 
 	if (extent_size == vg->extent_size) {
 		log_error("Physical extent size of VG %s is already %s",
-			  vg->name, display_size(cmd, extent_size, SIZE_SHORT));
+			  vg->name, display_size(cmd, (uint64_t) extent_size));
 		return ECMD_PROCESSED;
 	}
 
@@ -367,7 +432,8 @@
 	return ECMD_PROCESSED;
 }
 
-static int _vgchange_uuid(struct cmd_context *cmd, struct volume_group *vg)
+static int _vgchange_uuid(struct cmd_context *cmd __attribute((unused)),
+			  struct volume_group *vg)
 {
 	struct lv_list *lvl;
 
@@ -401,7 +467,7 @@
 
 static int vgchange_single(struct cmd_context *cmd, const char *vg_name,
 			   struct volume_group *vg, int consistent,
-			   void *handle)
+			   void *handle __attribute((unused)))
 {
 	int r = ECMD_FAILED;
 
@@ -428,9 +494,14 @@
 		return ECMD_FAILED;
 	}
 
+	init_dmeventd_register(arg_int_value(cmd, monitor_ARG, DEFAULT_DMEVENTD_MONITOR));
+
 	if (arg_count(cmd, available_ARG))
 		r = _vgchange_available(cmd, vg);
 
+	else if (arg_count(cmd, monitor_ARG))
+		r = _vgchange_monitoring(cmd, vg);
+
 	else if (arg_count(cmd, resizeable_ARG))
 		r = _vgchange_resizeable(cmd, vg);
 
@@ -465,7 +536,8 @@
 	     arg_count(cmd, resizeable_ARG) + arg_count(cmd, deltag_ARG) +
 	     arg_count(cmd, addtag_ARG) + arg_count(cmd, uuid_ARG) +
 	     arg_count(cmd, physicalextentsize_ARG) +
-	     arg_count(cmd, clustered_ARG) + arg_count(cmd, alloc_ARG))) {
+	     arg_count(cmd, clustered_ARG) + arg_count(cmd, alloc_ARG) +
+	     arg_count(cmd, monitor_ARG))) {
 		log_error("One of -a, -c, -l, -s, -x, --uuid, --alloc, --addtag or "
 			  "--deltag required");
 		return EINVALID_CMD_LINE;

Modified: lvm2/trunk/tools/vgck.c
==============================================================================
--- lvm2/trunk/tools/vgck.c	(original)
+++ lvm2/trunk/tools/vgck.c	Sat Jun 10 21:40:06 2006
@@ -15,8 +15,10 @@
 
 #include "tools.h"
 
-static int vgck_single(struct cmd_context *cmd, const char *vg_name,
-		       struct volume_group *vg, int consistent, void *handle)
+static int vgck_single(struct cmd_context *cmd __attribute((unused)),
+		       const char *vg_name,
+		       struct volume_group *vg, int consistent,
+		       void *handle __attribute((unused)))
 {
 	if (!vg) {
 		log_error("Volume group \"%s\" not found", vg_name);

Modified: lvm2/trunk/tools/vgconvert.c
==============================================================================
--- lvm2/trunk/tools/vgconvert.c	(original)
+++ lvm2/trunk/tools/vgconvert.c	Sat Jun 10 21:40:06 2006
@@ -17,7 +17,7 @@
 
 static int vgconvert_single(struct cmd_context *cmd, const char *vg_name,
 			    struct volume_group *vg, int consistent,
-			    void *handle)
+			    void *handle __attribute((unused)))
 {
 	struct physical_volume *pv, *existing_pv;
 	struct logical_volume *lv;

Modified: lvm2/trunk/tools/vgcreate.c
==============================================================================
--- lvm2/trunk/tools/vgcreate.c	(original)
+++ lvm2/trunk/tools/vgcreate.c	Sat Jun 10 21:40:06 2006
@@ -41,7 +41,7 @@
 	vg_name = argv[0];
 	max_lv = arg_uint_value(cmd, maxlogicalvolumes_ARG, 0);
 	max_pv = arg_uint_value(cmd, maxphysicalvolumes_ARG, 0);
-	alloc = (alloc_policy_t) arg_uint_value(cmd, alloc_ARG, ALLOC_NORMAL);
+	alloc = arg_uint_value(cmd, alloc_ARG, ALLOC_NORMAL);
 
 	if (alloc == ALLOC_INHERIT) {
 		log_error("Volume Group allocation policy cannot inherit "

Modified: lvm2/trunk/tools/vgdisplay.c
==============================================================================
--- lvm2/trunk/tools/vgdisplay.c	(original)
+++ lvm2/trunk/tools/vgdisplay.c	Sat Jun 10 21:40:06 2006
@@ -17,7 +17,7 @@
 
 static int vgdisplay_single(struct cmd_context *cmd, const char *vg_name,
 			    struct volume_group *vg, int consistent,
-			    void *handle)
+			    void *handle __attribute((unused)))
 {
 	/* FIXME Do the active check here if activevolumegroups_ARG ? */
 	if (!vg) {

Modified: lvm2/trunk/tools/vgexport.c
==============================================================================
--- lvm2/trunk/tools/vgexport.c	(original)
+++ lvm2/trunk/tools/vgexport.c	Sat Jun 10 21:40:06 2006
@@ -15,9 +15,10 @@
 
 #include "tools.h"
 
-static int vgexport_single(struct cmd_context *cmd, const char *vg_name,
+static int vgexport_single(struct cmd_context *cmd __attribute((unused)),
+			   const char *vg_name,
 			   struct volume_group *vg, int consistent,
-			   void *handle)
+			   void *handle __attribute((unused)))
 {
 	struct pv_list *pvl;
 	struct physical_volume *pv;

Modified: lvm2/trunk/tools/vgimport.c
==============================================================================
--- lvm2/trunk/tools/vgimport.c	(original)
+++ lvm2/trunk/tools/vgimport.c	Sat Jun 10 21:40:06 2006
@@ -15,9 +15,10 @@
 
 #include "tools.h"
 
-static int vgimport_single(struct cmd_context *cmd, const char *vg_name,
+static int vgimport_single(struct cmd_context *cmd __attribute((unused)),
+			   const char *vg_name,
 			   struct volume_group *vg, int consistent,
-			   void *handle)
+			   void *handle __attribute((unused)))
 {
 	struct pv_list *pvl;
 	struct physical_volume *pv;

Modified: lvm2/trunk/tools/vgmerge.c
==============================================================================
--- lvm2/trunk/tools/vgmerge.c	(original)
+++ lvm2/trunk/tools/vgmerge.c	Sat Jun 10 21:40:06 2006
@@ -125,7 +125,7 @@
 
 	/* Check no PVs are constructed from either VG */
 	list_iterate_items(pvl, &vg_to->pvs) {
-		if (pv_uses_vg(cmd, pvl->pv, vg_from)) {
+		if (pv_uses_vg(pvl->pv, vg_from)) {
 			log_error("Physical volume %s might be constructed "
 				  "from same volume group %s.",
 				  dev_name(pvl->pv->dev), vg_from->name);
@@ -134,7 +134,7 @@
 	}
 
 	list_iterate_items(pvl, &vg_from->pvs) {
-		if (pv_uses_vg(cmd, pvl->pv, vg_to)) {
+		if (pv_uses_vg(pvl->pv, vg_to)) {
 			log_error("Physical volume %s might be constructed "
 				  "from same volume group %s.",
 				  dev_name(pvl->pv->dev), vg_to->name);

Modified: lvm2/trunk/tools/vgmknodes.c
==============================================================================
--- lvm2/trunk/tools/vgmknodes.c	(original)
+++ lvm2/trunk/tools/vgmknodes.c	Sat Jun 10 21:40:06 2006
@@ -16,7 +16,7 @@
 #include "tools.h"
 
 static int _vgmknodes_single(struct cmd_context *cmd, struct logical_volume *lv,
-			     void *handle)
+			     void *handle __attribute((unused)))
 {
 	if (!lv_mknodes(cmd, lv))
 		return ECMD_FAILED;

Modified: lvm2/trunk/tools/vgreduce.c
==============================================================================
--- lvm2/trunk/tools/vgreduce.c	(original)
+++ lvm2/trunk/tools/vgreduce.c	Sat Jun 10 21:40:06 2006
@@ -111,7 +111,13 @@
 	 * and add to list of LVs to be removed later.
 	 * Doesn't apply to snapshots/origins yet - they're already deactivated.
 	 */
-	if (lv_info(cmd, lv, &info, 0) && info.exists) {
+	/*
+	 * If the LV is a part of mirror segment,
+	 * the mirrored LV also should be cleaned up.
+	 * Clean-up is currently done by caller (_make_vg_consistent()).
+	 */
+	if ((lv_info(cmd, lv, &info, 0) && info.exists)
+	    || first_seg(lv)->mirror_seg) {
 		extents = lv->le_count;
 		mirror_seg = first_seg(lv)->mirror_seg;
 		if (!lv_empty(lv)) {
@@ -157,8 +163,8 @@
 	struct physical_volume *pv;
 	struct lv_segment *seg, *mirrored_seg;
 	struct lv_segment_area area;
-	unsigned int s;
-	uint32_t mimages;
+	unsigned s;
+	uint32_t mimages, remove_log;
 	int list_unsafe, only_mirror_images_found;
 	LIST_INIT(lvs_changed);
 	only_mirror_images_found = 1;
@@ -259,7 +265,10 @@
 			mirrored_seg = first_seg(lvl->lv);
 			if (!seg_is_mirrored(mirrored_seg))
 				continue;
+
 			mimages = mirrored_seg->area_count;
+			remove_log = 0;
+
 			for (s = 0; s < mirrored_seg->area_count; s++) {
 				list_iterate_items_safe(lvl2, lvlt, &lvs_changed) {
 					if (seg_type(mirrored_seg, s) != AREA_LV ||
@@ -272,8 +281,24 @@
 					mimages--;	/* FIXME Assumes uniqueness */
 				}
 			}
-			if (mimages != mirrored_seg->area_count) {
-				if (!remove_mirror_images(mirrored_seg, mimages, NULL, 0)) {
+
+			if (mirrored_seg->log_lv) {
+				list_iterate_items(seg, &mirrored_seg->log_lv->segments) {
+					/* FIXME: The second test shouldn't be required */
+					if ((seg->segtype ==
+					     get_segtype_from_string(vg->cmd, "error")) ||
+					    (!strcmp(seg->segtype->name, "error"))) {
+						log_print("The log device for %s/%s has failed.",
+							  vg->name, mirrored_seg->lv->name);
+						remove_log = 1;
+						break;
+					}
+				}
+			}
+
+			if ((mimages != mirrored_seg->area_count) || (remove_log)){
+				if (!reconfigure_mirror_images(mirrored_seg, mimages,
+							       NULL, remove_log)) {
 					stack;
 					return 0;
 				}
@@ -295,14 +320,20 @@
 
 		/* Deactivate error LVs */
 		if (!test_mode()) {
-			list_iterate_items(lvl, &lvs_changed) {
+			list_iterate_items_safe(lvl, lvlt, &lvs_changed) {
 				log_verbose("Deactivating (if active) logical volume %s",
 					    lvl->lv->name);
 
 				if (!deactivate_lv(cmd, lvl->lv)) {
 					log_error("Failed to deactivate LV %s",
 						  lvl->lv->name);
-					return 0;
+					/*
+					 * We failed to deactivate.
+					 * Probably because this was a mirror log.
+					 * Don't try to lv_remove it.
+					 * Continue work on others.
+					 */
+					list_del(&lvl->list);
 				}
 			}
 		}
@@ -323,7 +354,8 @@
 
 /* Or take pv_name instead? */
 static int _vgreduce_single(struct cmd_context *cmd, struct volume_group *vg,
-			    struct physical_volume *pv, void *handle)
+			    struct physical_volume *pv,
+			    void *handle __attribute((unused)))
 {
 	struct pv_list *pvl;
 	const char *name = dev_name(pv->dev);

Modified: lvm2/trunk/tools/vgremove.c
==============================================================================
--- lvm2/trunk/tools/vgremove.c	(original)
+++ lvm2/trunk/tools/vgremove.c	Sat Jun 10 21:40:06 2006
@@ -17,7 +17,7 @@
 
 static int vgremove_single(struct cmd_context *cmd, const char *vg_name,
 			   struct volume_group *vg, int consistent,
-			   void *handle)
+			   void *handle __attribute((unused)))
 {
 	struct physical_volume *pv;
 	struct pv_list *pvl;

Modified: lvm2/trunk/tools/vgrename.c
==============================================================================
--- lvm2/trunk/tools/vgrename.c	(original)
+++ lvm2/trunk/tools/vgrename.c	Sat Jun 10 21:40:06 2006
@@ -18,7 +18,7 @@
 int vgrename(struct cmd_context *cmd, int argc, char **argv)
 {
 	char *dev_dir;
-	unsigned int length;
+	unsigned length;
 	struct id id;
 	int consistent = 1;
 	int match = 0;
@@ -90,9 +90,9 @@
 	log_suppress(2);
 	found_id = id_read_format(&id, vg_name_old);
 	log_suppress(0);
-	if (found_id && (vg_name = vgname_from_vgid(cmd->mem, id.uuid))) {
+	if (found_id && (vg_name = vgname_from_vgid(cmd->mem, (char *)id.uuid))) {
 		vg_name_old = vg_name;
-		vgid = id.uuid;
+		vgid = (char *)id.uuid;
 	} else
 		vgid = NULL;
 

Modified: lvm2/trunk/tools/vgscan.c
==============================================================================
--- lvm2/trunk/tools/vgscan.c	(original)
+++ lvm2/trunk/tools/vgscan.c	Sat Jun 10 21:40:06 2006
@@ -16,7 +16,8 @@
 #include "tools.h"
 
 static int vgscan_single(struct cmd_context *cmd, const char *vg_name,
-			 struct volume_group *vg, int consistent, void *handle)
+			 struct volume_group *vg, int consistent,
+			 void *handle __attribute((unused)))
 {
 	if (!vg) {
 		log_error("Volume group \"%s\" not found", vg_name);

Modified: lvm2/trunk/tools/vgsplit.c
==============================================================================
--- lvm2/trunk/tools/vgsplit.c	(original)
+++ lvm2/trunk/tools/vgsplit.c	Sat Jun 10 21:40:06 2006
@@ -64,7 +64,7 @@
 	struct lv_segment *seg;
 	struct physical_volume *pv;
 	struct volume_group *vg_with;
-	unsigned int s;
+	unsigned s;
 
 	list_iterate_safe(lvh, lvht, &vg_from->lvs) {
 		lv = list_item(lvh, struct lv_list)->lv;



More information about the pkg-lvm-commits mailing list