master - make: CFLAGS, not CLDFLAGS
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=37853cc7a9e600...
Commit: 37853cc7a9e60036134034718f22ec688917146b
Parent: a65ab773b4ddb06e87d678d3b2f4d0ca3e5b9fd0
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Dec 4 14:28:40 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Dec 4 14:28:40 2013 +0100
make: CFLAGS, not CLDFLAGS
---
daemons/lvmetad/Makefile.in | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/daemons/lvmetad/Makefile.in b/daemons/lvmetad/Makefile.in
index f08198a..67a557f 100644
--- a/daemons/lvmetad/Makefile.in
+++ b/daemons/lvmetad/Makefile.in
@@ -34,7 +34,8 @@ LVMLIBS = -ldaemonserver $(LVMINTERNAL_LIBS) -ldevmapper
LIBS += $(PTHREAD_LIBS)
LDFLAGS += -L$(top_builddir)/libdaemon/server $(DAEMON_LDFLAGS)
-CLDFLAGS += -L$(top_builddir)/libdaemon/server $(DAEMON_CFLAGS)
+CLDFLAGS += -L$(top_builddir)/libdaemon/server
+CFLAGS += $(DAEMON_CFLAGS)
lvmetad: $(OBJECTS) $(top_builddir)/libdaemon/client/libdaemonclient.a \
$(top_builddir)/libdaemon/server/libdaemonserver.a
10 years, 3 months
master - daemons: use PIE and RELRO compiler/linker options
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=a65ab773b4ddb0...
Commit: a65ab773b4ddb06e87d678d3b2f4d0ca3e5b9fd0
Parent: fc37d4fb0dfc47c49b8acdc773a4ad67d59b51b8
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Dec 4 10:16:15 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Dec 4 13:30:08 2013 +0100
daemons: use PIE and RELRO compiler/linker options
The PIE and RELRO compiler/linker options can be used to produce a code
some techniques applied that makes the code more immune to some attacks:
- PIE (Position Independent Executable). It can make use of the ASLR
(Address Space Layout Randomization) provided by kernel to avoid
static locations for .text regions of executables (this is the 'pie'
compiler and linker option)
- RELRO (Relocation Read-Only). This prevents overwrite attacks of
the GOT (Global Offset Table) and PLT (Procedure Lookup Table)
used for relocations by making it read-only after all relocations
are resolved (these are the 'relro' and 'now' linker options) -
hence all symbols are resolved at the very start so there's no
need for those tables to be writeable later.
These compiler/linker options are now used by default for daemons
if the compiler/linker supports it.
---
WHATS_NEW | 1 +
daemons/clvmd/Makefile.in | 3 ++-
daemons/cmirrord/Makefile.in | 3 ++-
daemons/dmeventd/Makefile.in | 4 +++-
daemons/lvmetad/Makefile.in | 4 ++--
make.tmpl.in | 9 +++++++++
6 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index d512ab5..f299b84 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.105 -
=====================================
+ Compile/link daemons with RELRO and PIE options to harden daemon security.
Support per-object compilation cflags via CFLAGS_object.o.
Automatically detect support for compiler/linker options to use RELRO and PIE.
Add --splitsnapshot to lvconvert to separate out cow LV.
diff --git a/daemons/clvmd/Makefile.in b/daemons/clvmd/Makefile.in
index 9ca11ba..4677048 100644
--- a/daemons/clvmd/Makefile.in
+++ b/daemons/clvmd/Makefile.in
@@ -88,7 +88,8 @@ LVMLIBS += -ldevmapper
LIBS += $(PTHREAD_LIBS)
DEFS += -D_REENTRANT
-CFLAGS += -fno-strict-aliasing
+CFLAGS += -fno-strict-aliasing $(DAEMON_CFLAGS)
+LDFLAGS += $(DAEMON_LDFLAGS)
INSTALL_TARGETS = \
install_clvmd
diff --git a/daemons/cmirrord/Makefile.in b/daemons/cmirrord/Makefile.in
index 0efc8d4..df7c2a8 100644
--- a/daemons/cmirrord/Makefile.in
+++ b/daemons/cmirrord/Makefile.in
@@ -28,7 +28,8 @@ include $(top_builddir)/make.tmpl
LIBS += -ldevmapper
LMLIBS += $(CPG_LIBS) $(SACKPT_LIBS)
-CFLAGS += $(CPG_CFLAGS) $(SACKPT_CFLAGS)
+CFLAGS += $(CPG_CFLAGS) $(SACKPT_CFLAGS) $(DAEMON_CFLAGS)
+LDFLAGS += $(DAEMON_LDFLAGS)
cmirrord: $(OBJECTS) $(top_builddir)/lib/liblvm-internal.a
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJECTS) \
diff --git a/daemons/dmeventd/Makefile.in b/daemons/dmeventd/Makefile.in
index 1302a44..fcc5c9e 100644
--- a/daemons/dmeventd/Makefile.in
+++ b/daemons/dmeventd/Makefile.in
@@ -59,8 +59,10 @@ device-mapper: $(TARGETS)
LIBS += -ldevmapper
LVMLIBS += -ldevmapper-event $(PTHREAD_LIBS)
+CFLAGS_dmeventd.o += $(DAEMON_CFLAGS)
+
dmeventd: $(LIB_SHARED) dmeventd.o
- $(CC) $(CFLAGS) $(LDFLAGS) $(ELDFLAGS) -L. -o $@ dmeventd.o \
+ $(CC) $(CFLAGS) $(LDFLAGS) $(DAEMON_LDFLAGS) $(ELDFLAGS) -L. -o $@ dmeventd.o \
$(DL_LIBS) $(LVMLIBS) $(LIBS) -rdynamic
dmeventd.static: $(LIB_STATIC) dmeventd.o $(interfacebuilddir)/libdevmapper.a
diff --git a/daemons/lvmetad/Makefile.in b/daemons/lvmetad/Makefile.in
index 35aa4ab..f08198a 100644
--- a/daemons/lvmetad/Makefile.in
+++ b/daemons/lvmetad/Makefile.in
@@ -33,8 +33,8 @@ LVMLIBS = -ldaemonserver $(LVMINTERNAL_LIBS) -ldevmapper
LIBS += $(PTHREAD_LIBS)
-LDFLAGS += -L$(top_builddir)/libdaemon/server
-CLDFLAGS += -L$(top_builddir)/libdaemon/server
+LDFLAGS += -L$(top_builddir)/libdaemon/server $(DAEMON_LDFLAGS)
+CLDFLAGS += -L$(top_builddir)/libdaemon/server $(DAEMON_CFLAGS)
lvmetad: $(OBJECTS) $(top_builddir)/libdaemon/client/libdaemonclient.a \
$(top_builddir)/libdaemon/server/libdaemonserver.a
diff --git a/make.tmpl.in b/make.tmpl.in
index 944be9b..5f72182 100644
--- a/make.tmpl.in
+++ b/make.tmpl.in
@@ -150,6 +150,15 @@ WFLAGS += -Wclobbered -Wempty-body -Wignored-qualifiers \
-Wtype-limits -Wsync-nand -Wlogical-op
endif
+ifneq ("@STATIC_LINK@", "yes")
+ifeq ("@HAVE_PIE@", "yes")
+ifeq ("@HAVE_FULL_RELRO@", "yes")
+ DAEMON_CFLAGS += -fPIE -DPIE
+ DAEMON_LDFLAGS += -Wl,-z,relro,-z,now -pie
+endif
+endif
+endif
+
#WFLAGS += -W -Wno-sign-compare -Wno-unused-parameter -Wno-missing-field-initializers
#WFLAGS += -Wsign-compare -Wunused-parameter -Wmissing-field-initializers
#WFLAGS += -Wconversion -Wbad-function-cast -Wcast-qual -Waggregate-return -Wpacked
10 years, 3 months
master - make: support per-object defines
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=fc37d4fb0dfc47...
Commit: fc37d4fb0dfc47c49b8acdc773a4ad67d59b51b8
Parent: 6c6bcc00e401262db3b906259674a3231a119603
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Wed Dec 4 12:35:02 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Dec 4 13:30:08 2013 +0100
make: support per-object defines
In the case we have a dir with multiple objects and for
an individual object file we need special define -
allow to define it without adding extra rules.
To ensure dmeventd.o compilation will use EXTRA_FLAGS:
CFLAGS_dmeventd.o += $(EXTRA_FLAGS)
Then it's better to use:
dmeventd.o: CFLAGS += $(EXTRA_FLAGS)
---
WHATS_NEW | 1 +
make.tmpl.in | 2 +-
2 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 9155ddf..d512ab5 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.105 -
=====================================
+ Support per-object compilation cflags via CFLAGS_object.o.
Automatically detect support for compiler/linker options to use RELRO and PIE.
Add --splitsnapshot to lvconvert to separate out cow LV.
Reinstate origin reload to complete lvconvert -s with active LVs. (2.02.98)
diff --git a/make.tmpl.in b/make.tmpl.in
index 35a47be..944be9b 100644
--- a/make.tmpl.in
+++ b/make.tmpl.in
@@ -345,7 +345,7 @@ endif
$(TARGETS): $(OBJECTS)
%.o: %.c
- $(CC) -c $(INCLUDES) $(DEFS) $(WFLAGS) $(CFLAGS) $< -o $@
+ $(CC) -c $(INCLUDES) $(DEFS) $(WFLAGS) $(CFLAGS) $(CFLAGS_$@) $< -o $@
%.pot: %.c Makefile
$(CC) -E $(INCLUDES) -include $(top_srcdir)/include/pogen.h \
10 years, 3 months
master - configure: check compiler/linker support for RELRO and PIE options
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=6c6bcc00e40126...
Commit: 6c6bcc00e401262db3b906259674a3231a119603
Parent: 163666e513848e5d43d3e4f2f91b42d1a8f483a0
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Dec 4 09:58:58 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Dec 4 13:30:08 2013 +0100
configure: check compiler/linker support for RELRO and PIE options
Also, add AC_TRY_LDFLAGS m4 macro to help with checking ld flags.
---
WHATS_NEW | 1 +
acinclude.m4 | 21 +++++++++++++++
configure | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
configure.in | 7 +++++
4 files changed, 110 insertions(+), 0 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 553edfd..9155ddf 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.105 -
=====================================
+ Automatically detect support for compiler/linker options to use RELRO and PIE.
Add --splitsnapshot to lvconvert to separate out cow LV.
Reinstate origin reload to complete lvconvert -s with active LVs. (2.02.98)
Select only active volume groups if vgdisplay -A is used.
diff --git a/acinclude.m4 b/acinclude.m4
index bf9fe09..b9473db 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -36,3 +36,24 @@ AC_DEFUN([AC_TRY_CCFLAG],
ifelse([$4], [], [:], [$4])
fi
])
+
+dnl AC_TRY_LDFLAGS([LDFLAGS], [VAR], [ACTION-IF-WORKS], [ACTION-IF-FAILS])
+dnl check if $CC supports given ld flags
+
+AC_DEFUN([AC_TRY_LDFLAGS],
+[
+ AC_REQUIRE([AC_PROG_CC])
+ ac_save_LDFLAGS=$LDFLAGS
+ LDFLAGS=$1
+ AC_CACHE_CHECK([whether $CC accepts $1 ld flags], [ac_cv_flag_$2],
+ [AC_LINK_IFELSE([AC_LANG_PROGRAM()],
+ [AS_VAR_SET([ac_cv_flag_$2], [yes])],
+ [AS_VAR_SET([ac_cv_flag_$2], [no])])])
+ LDLAGS=$ac_save_LDFLAGS
+ $2=AS_VAR_GET([ac_cv_flag_$2])
+ if test "$2" = yes; then
+ ifelse([$3], [], [:], [$3])
+ else
+ ifelse([$4], [], [:], [$4])
+ fi
+])
diff --git a/configure b/configure
index 564d322..2ecc7ba 100755
--- a/configure
+++ b/configure
@@ -740,6 +740,8 @@ PKG_CONFIG
THIN_REPAIR_CMD
THIN_DUMP_CMD
THIN_CHECK_CMD
+HAVE_FULL_RELRO
+HAVE_PIE
POW_LIB
LIBOBJS
ALLOCA
@@ -6744,6 +6746,85 @@ $as_echo "$STATIC_LINK" >&6; }
################################################################################
+ ac_save_CFLAGS=$CFLAGS
+ CFLAGS=-pie
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -pie flag" >&5
+$as_echo_n "checking whether $CC accepts -pie flag... " >&6; }
+if test "${ac_cv_flag_HAVE_PIE+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ ac_cv_flag_HAVE_PIE=yes
+else
+ ac_cv_flag_HAVE_PIE=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_flag_HAVE_PIE" >&5
+$as_echo "$ac_cv_flag_HAVE_PIE" >&6; }
+ CFLAGS=$ac_save_CFLAGS
+ HAVE_PIE=$ac_cv_flag_HAVE_PIE
+ if test "HAVE_PIE" = yes; then
+ :
+ else
+ :
+ fi
+
+
+
+
+ ac_save_LDFLAGS=$LDFLAGS
+ LDFLAGS=-Wl,-z,relro,-z,now
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -Wl,-z,relro,-z,now ld flags" >&5
+$as_echo_n "checking whether $CC accepts -Wl,-z,relro,-z,now ld flags... " >&6; }
+if test "${ac_cv_flag_HAVE_FULL_RELRO+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ ac_cv_flag_HAVE_FULL_RELRO=yes
+else
+ ac_cv_flag_HAVE_FULL_RELRO=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_flag_HAVE_FULL_RELRO" >&5
+$as_echo "$ac_cv_flag_HAVE_FULL_RELRO" >&6; }
+ LDLAGS=$ac_save_LDFLAGS
+ HAVE_FULL_RELRO=$ac_cv_flag_HAVE_FULL_RELRO
+ if test "HAVE_FULL_RELRO" = yes; then
+ :
+ else
+ :
+ fi
+
+
+
+################################################################################
+
+
################################################################################
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking file owner" >&5
$as_echo_n "checking file owner... " >&6; }
diff --git a/configure.in b/configure.in
index e4d0014..851d3f7 100644
--- a/configure.in
+++ b/configure.in
@@ -159,6 +159,13 @@ AC_ARG_ENABLE(static_link,
AC_MSG_RESULT($STATIC_LINK)
################################################################################
+dnl -- Check if compiler/linker supports PIE and RELRO
+AC_TRY_CCFLAG([-pie], [HAVE_PIE], [], [])
+AC_SUBST(HAVE_PIE)
+AC_TRY_LDFLAGS([-Wl,-z,relro,-z,now], [HAVE_FULL_RELRO], [], [])
+AC_SUBST(HAVE_FULL_RELRO)
+
+################################################################################
dnl -- Prefix is /usr by default, the exec_prefix default is setup later
AC_PREFIX_DEFAULT(/usr)
10 years, 3 months
master - tests: one LV should be active and one inactive in covercmd test
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=163666e513848e...
Commit: 163666e513848e5d43d3e4f2f91b42d1a8f483a0
Parent: 7b65363bf781cd58d45e2d9f12fdfed59b9dee55
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Dec 4 09:37:32 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Dec 4 09:38:00 2013 +0100
tests: one LV should be active and one inactive in covercmd test
---
test/shell/covercmd.sh | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/test/shell/covercmd.sh b/test/shell/covercmd.sh
index 59500d6..7a24a9c 100644
--- a/test/shell/covercmd.sh
+++ b/test/shell/covercmd.sh
@@ -112,7 +112,7 @@ lvcreate -l1 $vg1
# at least one LV active - VG considered active
vgcreate $vg2 $dev2
lvcreate -l1 $vg2
-lvcreate -l1 $vg2
+lvcreate -l1 -an -Zn $vg2
# no LVs active - VG considered inactive
vgcreate $vg3 $dev3
10 years, 3 months
master - lvconvert: Implement --splitsnapshot.
by Alasdair Kergon
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=7b65363bf781cd...
Commit: 7b65363bf781cd58d45e2d9f12fdfed59b9dee55
Parent: ff769ecfe7cdd704ee1e11aa9b6b7a92f932a0c1
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Wed Dec 4 02:09:37 2013 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Wed Dec 4 02:09:37 2013 +0000
lvconvert: Implement --splitsnapshot.
---
WHATS_NEW | 1 +
man/lvconvert.8.in | 21 +++++++-
tools/args.h | 1 +
tools/commands.h | 15 ++++-
tools/lvconvert.c | 142 ++++++++++++++++++++++++++++++++++++++++++++-------
5 files changed, 155 insertions(+), 25 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index c96acce..553edfd 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.105 -
=====================================
+ Add --splitsnapshot to lvconvert to separate out cow LV.
Reinstate origin reload to complete lvconvert -s with active LVs. (2.02.98)
Select only active volume groups if vgdisplay -A is used.
Add -p and LVM_LVMETAD_PID env var to lvmetad to change pid file.
diff --git a/man/lvconvert.8.in b/man/lvconvert.8.in
index 0fe5ab3..30e9809 100644
--- a/man/lvconvert.8.in
+++ b/man/lvconvert.8.in
@@ -38,6 +38,14 @@ lvconvert \- convert a logical volume from linear to mirror or snapshot
.RI [ SplittablePhysicalVolume [ Path ][ :PE [ -PE ]]...]
.sp
.B lvconvert
+.BR \-\-splitsnapshot
+.RB [ \-h | \-? | \-\-help ]
+.RB [ \-\-noudevsync ]
+.RB [ \-v | \-\-verbose ]
+.RB [ \-\-version ]
+.IR SnapshotLogicalVolume [ Path ]
+.sp
+.B lvconvert
.BR \-s | \-\-snapshot
.RB [ \-c | \-\-chunksize
.IR ChunkSize [ bBsSkK ]]
@@ -128,6 +136,7 @@ Exactly one of
.BR \-\-mirrors ,
.BR \-\-repair ,
.BR \-\-replace ,
+.BR \-\-splitsnapshot ,
.BR \-\-snapshot ,
.BR \-\-splitmirrors
or
@@ -200,9 +209,17 @@ the data changed get resynchronized.
Please note that this feature is only supported with the new md-based mirror
implementation and not with the original device-mapper mirror implementation.
.TP
+.B \-\-splitsnapshot
+Separates SnapshotLogicalVolume from its origin.
+The volume that is split off contains the chunks that differ from the origin
+along with the metadata describing them. This volume can be wiped and then
+destroyed with lvremove.
+The inverse of \-\-snapshot.
+.TP
.B \-s, \-\-snapshot
-Creates a snapshot from existing logical volume using another
-existing logical volume as its origin.
+Recreates a snapshot from constituent logical volumes (or copies of them) after
+having been separated using \-\-splitsnapshot. For this to work correctly, no
+changes may be made to the contents of either volume after the split.
.TP
.BR \-c ", " \-\-chunksize " " \fIChunkSize [ \fIbBsSkKmMgG ]
Gives the size of chunk for snapshot and thin pool logical volumes.
diff --git a/tools/args.h b/tools/args.h
index 8ca73a3..1207189 100644
--- a/tools/args.h
+++ b/tools/args.h
@@ -101,6 +101,7 @@ arg(profile_ARG, '\0', "profile", string_arg, 0)
arg(detachprofile_ARG, '\0', "detachprofile", NULL, 0)
arg(mergedconfig_ARG, '\0', "mergedconfig", NULL, 0)
arg(ignoreskippedcluster_ARG, '\0', "ignoreskippedcluster", NULL, 0)
+arg(splitsnapshot_ARG, '\0', "splitsnapshot", NULL, 0)
/* Allow some variations */
arg(resizable_ARG, '\0', "resizable", yes_no_arg, 0)
diff --git a/tools/commands.h b/tools/commands.h
index c54e812..938898b 100644
--- a/tools/commands.h
+++ b/tools/commands.h
@@ -172,6 +172,15 @@ xx(lvconvert,
"\tLogicalVolume[Path] [SplittablePhysicalVolume[Path]...]\n\n"
"lvconvert "
+ "--splitsnapshot\n"
+ "\t[-d|--debug]\n"
+ "\t[-h|-?|--help]\n"
+ "\t[--noudevsync]\n"
+ "\t[-v|--verbose]\n"
+ "\t[--version]" "\n"
+ "\tSnapshotLogicalVolume[Path]\n\n"
+
+ "lvconvert "
"[-s|--snapshot]\n"
"\t[-c|--chunksize]\n"
"\t[-d|--debug]\n"
@@ -209,9 +218,9 @@ xx(lvconvert,
force_ARG, interval_ARG, merge_ARG, mirrorlog_ARG, mirrors_ARG, name_ARG,
noudevsync_ARG, originname_ARG, poolmetadata_ARG, poolmetadatasize_ARG,
poolmetadataspare_ARG, readahead_ARG, regionsize_ARG, repair_ARG,
- replace_ARG, snapshot_ARG, splitmirrors_ARG, stripes_long_ARG,
- stripesize_ARG, test_ARG, thin_ARG, thinpool_ARG, trackchanges_ARG,
- type_ARG, use_policies_ARG, zero_ARG)
+ replace_ARG, snapshot_ARG, splitmirrors_ARG, splitsnapshot_ARG,
+ stripes_long_ARG, stripesize_ARG, test_ARG, thin_ARG, thinpool_ARG,
+ trackchanges_ARG, type_ARG, use_policies_ARG, zero_ARG)
xx(lvcreate,
"Create a logical volume",
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index b040e33..ab1d5a3 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -19,6 +19,7 @@
struct lvconvert_params {
int force;
int snapshot;
+ int splitsnapshot;
int merge;
int merge_mirror;
int poolmetadataspare;
@@ -170,6 +171,11 @@ static int _lvconvert_name_params(struct lvconvert_params *lp,
return 0;
}
+ if (lp->splitsnapshot && *pargc) {
+ log_error("Too many arguments provided with --splitsnapshot.");
+ return 0;
+ }
+
if (lp->pool_data_lv_name && lp->lv_name && lp->poolmetadata_size) {
log_error("Please specify either metadata logical volume or its size.");
return 0;
@@ -223,6 +229,9 @@ static int _read_params(struct lvconvert_params *lp, struct cmd_context *cmd,
if (!_check_conversion_type(cmd, type_str))
return_0;
+ if (arg_count(cmd, splitsnapshot_ARG))
+ lp->splitsnapshot = 1;
+
if ((snapshot_type_requested(cmd, type_str) || arg_count(cmd, merge_ARG)) &&
(arg_count(cmd, mirrorlog_ARG) || mirror_or_raid_type_requested(cmd, type_str) ||
arg_count(cmd, repair_ARG) || arg_count(cmd, thinpool_ARG))) {
@@ -348,9 +357,24 @@ static int _read_params(struct lvconvert_params *lp, struct cmd_context *cmd,
lp->mirrors_sign = arg_sign_value(cmd, mirrors_ARG, SIGN_NONE);
}
+ if (lp->splitsnapshot &&
+ (lp->snapshot || lp->thin || lp->merge || lp->merge_mirror || arg_count(cmd, thinpool_ARG) ||
+ arg_count(cmd, mirrors_ARG) || arg_count(cmd, repair_ARG) || arg_count(cmd, replace_ARG) ||
+ arg_count(cmd, chunksize_ARG) || arg_count(cmd, zero_ARG) || arg_count(cmd, regionsize_ARG) ||
+ arg_count(cmd, poolmetadata_ARG) || arg_count(cmd, poolmetadatasize_ARG) ||
+ arg_count(cmd, readahead_ARG) || arg_count(cmd, stripes_long_ARG) ||
+ arg_count(cmd, stripesize_ARG) || arg_count(cmd, background_ARG) ||
+ arg_count(cmd, interval_ARG) || arg_count(cmd, type_ARG) || arg_count(cmd, alloc_ARG) ||
+ arg_count(cmd, corelog_ARG) || arg_count(cmd, mirrorlog_ARG) ||
+ arg_count(cmd, splitmirrors_ARG) || arg_count(cmd, originname_ARG) ||
+ arg_count(cmd, trackchanges_ARG) || arg_count(cmd, use_policies_ARG))) {
+ log_error("Incompatible arguments supplied with --splitsnapshot.");
+ return 0;
+ }
+
lp->alloc = (alloc_policy_t) arg_uint_value(cmd, alloc_ARG, ALLOC_INHERIT);
- /* There are three types of lvconvert. */
+ /* There are six types of lvconvert. */
if (lp->merge) { /* Snapshot merge */
if (arg_count(cmd, regionsize_ARG) || arg_count(cmd, chunksize_ARG) ||
arg_count(cmd, zero_ARG) || arg_count(cmd, regionsize_ARG) ||
@@ -364,8 +388,9 @@ static int _read_params(struct lvconvert_params *lp, struct cmd_context *cmd,
if (!(lp->segtype = get_segtype_from_string(cmd, "snapshot")))
return_0;
-
- } else if (lp->snapshot) { /* Snapshot creation from pre-existing cow */
+ } else if (lp->splitsnapshot) /* Destroy snapshot retaining cow as separate LV */
+ ;
+ else if (lp->snapshot) { /* Snapshot creation from pre-existing cow */
if (arg_count(cmd, regionsize_ARG)) {
log_error("--regionsize is only available with mirrors");
return 0;
@@ -1648,7 +1673,7 @@ static int _lvconvert_mirrors(struct cmd_context *cmd,
return 1;
}
-static int is_valid_raid_conversion(const struct segment_type *from_segtype,
+static int _is_valid_raid_conversion(const struct segment_type *from_segtype,
const struct segment_type *to_segtype)
{
if (from_segtype == to_segtype)
@@ -1695,7 +1720,7 @@ static void _lvconvert_raid_repair_ask(struct cmd_context *cmd, int *replace_dev
}
}
-static int lvconvert_raid(struct logical_volume *lv, struct lvconvert_params *lp)
+static int _lvconvert_raid(struct logical_volume *lv, struct lvconvert_params *lp)
{
int replace = 0;
int uninitialized_var(image_count);
@@ -1718,7 +1743,7 @@ static int lvconvert_raid(struct logical_volume *lv, struct lvconvert_params *lp
if (!_lvconvert_validate_thin(lv, lp))
return_0;
- if (!is_valid_raid_conversion(seg->segtype, lp->segtype)) {
+ if (!_is_valid_raid_conversion(seg->segtype, lp->segtype)) {
log_error("Unable to convert %s/%s from %s to %s",
lv->vg->name, lv->name,
seg->segtype->ops->name(seg), lp->segtype->name);
@@ -1819,9 +1844,83 @@ static int lvconvert_raid(struct logical_volume *lv, struct lvconvert_params *lp
return 0;
}
-static int lvconvert_snapshot(struct cmd_context *cmd,
- struct logical_volume *lv,
- struct lvconvert_params *lp)
+static int _lvconvert_splitsnapshot(struct cmd_context *cmd, struct logical_volume *cow,
+ struct lvconvert_params *lp)
+{
+ struct lvinfo info;
+ struct volume_group *vg = cow->vg;
+
+ if (!lv_is_cow(cow)) {
+ log_error("%s/%s is not a snapshot.", vg->name, cow->name);
+ return ECMD_FAILED;
+ }
+
+ if (lv_is_origin(cow) || lv_is_external_origin(cow)) {
+ log_error("Unable to split LV %s/%s that is a snapshot origin.", vg->name, cow->name);
+ return ECMD_FAILED;
+ }
+
+ if (lv_is_merging_cow(cow)) {
+ log_error("Unable to split off snapshot %s/%s being merged into its origin.", vg->name, cow->name);
+ return ECMD_FAILED;
+ }
+
+ if (lv_is_virtual_origin(origin_from_cow(cow))) {
+ log_error("Unable to split off snapshot %s/%s with virtual origin.", vg->name, cow->name);
+ return ECMD_FAILED;
+ }
+
+ if (lv_is_thin_pool(cow) || lv_is_pool_metadata_spare(cow)) {
+ log_error("Unable to split off LV %s/%s needed by thin volume(s).", vg->name, cow->name);
+ return ECMD_FAILED;
+ }
+
+ if (!(vg->fid->fmt->features & FMT_MDAS)) {
+ log_error("Unable to split off snapshot %s/%s using old LVM1-style metadata.", vg->name, cow->name);
+ return ECMD_FAILED;
+ }
+
+ if (!vg_check_status(vg, LVM_WRITE))
+ return_ECMD_FAILED;
+
+ if (lv_is_mirror_type(cow) || lv_is_raid_type(cow) || lv_is_thin_type(cow)) {
+ log_error("LV %s/%s type is unsupported with --splitsnapshot.", vg->name, cow->name);
+ return ECMD_FAILED;
+ }
+
+ if (lv_info(cmd, cow, 0, &info, 1, 0)) {
+ if (!lv_check_not_in_use(cmd, cow, &info))
+ return_0;
+
+ if ((lp->force == PROMPT) &&
+ lv_is_visible(cow) &&
+ lv_is_active(cow)) {
+ if (yes_no_prompt("Do you really want to split off active "
+ "logical volume %s? [y/n]: ", cow->name) == 'n') {
+ log_error("Logical volume %s not split.", cow->name);
+ return ECMD_FAILED;
+ }
+ }
+ }
+
+ if (!archive(vg))
+ return_ECMD_FAILED;
+
+ log_verbose("Splitting snapshot %s/%s from its origin.", vg->name, cow->name);
+
+ if (!vg_remove_snapshot(cow))
+ return_ECMD_FAILED;
+
+ backup(vg);
+
+ log_print_unless_silent("Logical Volume %s/%s split from its origin.", vg->name, cow->name);
+
+ return ECMD_PROCESSED;
+}
+
+static int _lvconvert_snapshot(struct cmd_context *cmd,
+ struct logical_volume *lv,
+ struct lvconvert_params *lp)
{
struct logical_volume *org;
@@ -2602,7 +2701,7 @@ static int _lvconvert_single(struct cmd_context *cmd, struct logical_volume *lv,
return ECMD_FAILED;
}
- if (lv_is_cow(lv) && !lp->merge) {
+ if (lv_is_cow(lv) && !lp->merge && !lp->splitsnapshot) {
log_error("Can't convert snapshot logical volume \"%s\"",
lv->name);
return ECMD_FAILED;
@@ -2613,6 +2712,9 @@ static int _lvconvert_single(struct cmd_context *cmd, struct logical_volume *lv,
return ECMD_FAILED;
}
+ if (lp->splitsnapshot)
+ return _lvconvert_splitsnapshot(cmd, lv, lp);
+
if (arg_count(cmd, repair_ARG) && lv_is_thin_pool(lv))
return _lvconvert_thinpool_repair(cmd, lv, lp);
@@ -2652,7 +2754,7 @@ static int _lvconvert_single(struct cmd_context *cmd, struct logical_volume *lv,
if (!archive(lv->vg))
return_ECMD_FAILED;
- if (!lvconvert_snapshot(cmd, lv, lp))
+ if (!_lvconvert_snapshot(cmd, lv, lp))
return_ECMD_FAILED;
} else if (arg_count(cmd, thinpool_ARG)) {
@@ -2667,7 +2769,7 @@ static int _lvconvert_single(struct cmd_context *cmd, struct logical_volume *lv,
if (!archive(lv->vg))
return_ECMD_FAILED;
- if (!lvconvert_raid(lv, lp))
+ if (!_lvconvert_raid(lv, lp))
return_ECMD_FAILED;
if (!(failed_pvs = _failed_pv_list(lv->vg)))
@@ -2698,7 +2800,7 @@ static int _lvconvert_single(struct cmd_context *cmd, struct logical_volume *lv,
/*
* FIXME move to toollib along with the rest of the drop/reacquire
- * VG locking that is used by lvconvert_merge_single()
+ * VG locking that is used by _lvconvert_merge_single()
*/
static struct logical_volume *get_vg_lock_and_logical_volume(struct cmd_context *cmd,
const char *vg_name,
@@ -2727,7 +2829,7 @@ static struct logical_volume *get_vg_lock_and_logical_volume(struct cmd_context
return lv;
}
-static int poll_logical_volume(struct cmd_context *cmd, struct logical_volume *lv,
+static int _poll_logical_volume(struct cmd_context *cmd, struct logical_volume *lv,
int wait_completion)
{
struct lvinfo info;
@@ -2783,7 +2885,7 @@ bad:
unlock_vg(cmd, lp->vg_name);
if (ret == ECMD_PROCESSED && lp->need_polling)
- ret = poll_logical_volume(cmd, lp->lv_to_poll,
+ ret = _poll_logical_volume(cmd, lp->lv_to_poll,
lp->wait_completion);
release_vg(lv->vg);
@@ -2792,7 +2894,7 @@ out:
return ret;
}
-static int lvconvert_merge_single(struct cmd_context *cmd, struct logical_volume *lv,
+static int _lvconvert_merge_single(struct cmd_context *cmd, struct logical_volume *lv,
void *handle)
{
struct lvconvert_params *lp = handle;
@@ -2802,10 +2904,10 @@ static int lvconvert_merge_single(struct cmd_context *cmd, struct logical_volume
/*
* FIXME can't trust lv's VG to be current given that caller
- * is process_each_lv() -- poll_logical_volume() may have
+ * is process_each_lv() -- _poll_logical_volume() may have
* already updated the VG's metadata in an earlier iteration.
* - preemptively drop the VG lock, as is needed for
- * poll_logical_volume(), refresh LV (and VG in the process).
+ * _poll_logical_volume(), refresh LV (and VG in the process).
*/
vg_name = lv->vg->name;
unlock_vg(cmd, vg_name);
@@ -2825,7 +2927,7 @@ static int lvconvert_merge_single(struct cmd_context *cmd, struct logical_volume
*/
unlock_vg(cmd, vg_name);
- ret = poll_logical_volume(cmd, lp->lv_to_poll,
+ ret = _poll_logical_volume(cmd, lp->lv_to_poll,
lp->wait_completion);
/* use LCK_VG_WRITE to match lvconvert()'s READ_FOR_UPDATE */
@@ -2856,7 +2958,7 @@ int lvconvert(struct cmd_context * cmd, int argc, char **argv)
return EINVALID_CMD_LINE;
}
return process_each_lv(cmd, argc, argv, READ_FOR_UPDATE, &lp,
- &lvconvert_merge_single);
+ &_lvconvert_merge_single);
}
return lvconvert_single(cmd, &lp);
10 years, 3 months
master - lvconvert: Fix reload after snapshot conversion.
by Alasdair Kergon
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=ff769ecfe7cdd7...
Commit: ff769ecfe7cdd704ee1e11aa9b6b7a92f932a0c1
Parent: 6232cac86cea332efb1e538fc8cd1922dc35bd01
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Wed Dec 4 02:04:29 2013 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Wed Dec 4 02:04:29 2013 +0000
lvconvert: Fix reload after snapshot conversion.
At the end of lvconvert --snapshot with an active origin, the origin
gets reloaded.
Commit 57c0f72b1d0349382c226c2b5614489b59db99e8 ("lvconvert: use
_reload_lv on more places") accidentally replaced this with a snapshot
LV reload (which does nothing because only the origin is active).
---
WHATS_NEW | 1 +
tools/lvconvert.c | 2 +-
2 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index c91acff..c96acce 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.105 -
=====================================
+ Reinstate origin reload to complete lvconvert -s with active LVs. (2.02.98)
Select only active volume groups if vgdisplay -A is used.
Add -p and LVM_LVMETAD_PID env var to lvmetad to change pid file.
Allow lvmetad to reuse stale socket.
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index 6f81356..b040e33 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -1864,7 +1864,7 @@ static int lvconvert_snapshot(struct cmd_context *cmd,
}
/* store vg on disk(s) */
- if (!_reload_lv(cmd, lv->vg, lv))
+ if (!_reload_lv(cmd, lv->vg, org))
return_0;
log_print_unless_silent("Logical volume %s converted to snapshot.", lv->name);
10 years, 3 months
master - vgdisplay: select only active volumes groups if -A option is used
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=6232cac86cea33...
Commit: 6232cac86cea332efb1e538fc8cd1922dc35bd01
Parent: c35394959758ec17389529f95a33bf7f5b15c56b
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue Dec 3 14:41:25 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue Dec 3 14:43:00 2013 +0100
vgdisplay: select only active volumes groups if -A option is used
Where "active" means "at least one LV is active in the volume group".
---
WHATS_NEW | 1 +
man/vgdisplay.8.in | 3 ++-
test/shell/covercmd.sh | 22 ++++++++++++++++++++++
tools/vgdisplay.c | 4 +++-
4 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 043b7ef..c91acff 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.105 -
=====================================
+ Select only active volume groups if vgdisplay -A is used.
Add -p and LVM_LVMETAD_PID env var to lvmetad to change pid file.
Allow lvmetad to reuse stale socket.
Only unlink lvmetad socket on error if created by the same process.
diff --git a/man/vgdisplay.8.in b/man/vgdisplay.8.in
index 9016a45..4dada16 100644
--- a/man/vgdisplay.8.in
+++ b/man/vgdisplay.8.in
@@ -57,7 +57,8 @@ See \fBlvm\fP(8) for common options and \fBvgs\fP(8) for options given with
\fB\-\-columns\fP.
.TP
.BR \-A ", " \-\-activevolumegroups
-Only select the active volume groups.
+Only select the active volume groups. The volume group is considered active
+if at least one of its logical volumes is active.
.TP
.BR \-c ", " \-\-colon
Generate colon separated output for easier parsing in scripts or programs.
diff --git a/test/shell/covercmd.sh b/test/shell/covercmd.sh
index 04074c1..59500d6 100644
--- a/test/shell/covercmd.sh
+++ b/test/shell/covercmd.sh
@@ -100,3 +100,25 @@ not lvmchange
not lvrename $vg
not lvrename $vg-xxx
not lvrename $vg $vg/$lv-rename $vg/$lv
+
+#test vgdisplay -A to select only active VGs
+# all LVs active - VG considered active
+pvcreate -f $dev1 $dev2 $dev3
+
+vgcreate $vg1 $dev1
+lvcreate -l1 $vg1
+lvcreate -l1 $vg1
+
+# at least one LV active - VG considered active
+vgcreate $vg2 $dev2
+lvcreate -l1 $vg2
+lvcreate -l1 $vg2
+
+# no LVs active - VG considered inactive
+vgcreate $vg3 $dev3
+lvcreate -l1 -an -Zn $vg3
+lvcreate -l1 -an -Zn $vg3
+
+vgdisplay -s -A | grep $vg1
+vgdisplay -s -A | grep $vg2
+vgdisplay -s -A | not grep $vg3
diff --git a/tools/vgdisplay.c b/tools/vgdisplay.c
index afc92fe..81ffbd9 100644
--- a/tools/vgdisplay.c
+++ b/tools/vgdisplay.c
@@ -19,7 +19,9 @@ static int vgdisplay_single(struct cmd_context *cmd, const char *vg_name,
struct volume_group *vg,
void *handle __attribute__((unused)))
{
- /* FIXME Do the active check here if activevolumegroups_ARG ? */
+ if (arg_count(cmd, activevolumegroups_ARG) && !lvs_in_vg_activated(vg))
+ return ECMD_PROCESSED;
+
vg_check_status(vg, EXPORTED_VG);
if (arg_count(cmd, colon_ARG)) {
10 years, 3 months
master - libdm-config: Allow quoted section (and key) names.
by Petr Rockai
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=c35394959758ec...
Commit: c35394959758ec17389529f95a33bf7f5b15c56b
Parent: 2e82a070f3c9224da5c9f383d47e75a1715586cf
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Sun Dec 1 20:02:28 2013 +0100
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Dec 1 20:57:42 2013 +0100
libdm-config: Allow quoted section (and key) names.
---
libdm/libdm-config.c | 22 +++++++++++++++++++---
1 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/libdm/libdm-config.c b/libdm/libdm-config.c
index 3385e18..fbee007 100644
--- a/libdm/libdm-config.c
+++ b/libdm/libdm-config.c
@@ -287,6 +287,7 @@ static int _write_config(const struct dm_config_node *n, int only_one,
char space[MAX_INDENT + 1];
int l = (level < MAX_INDENT) ? level : MAX_INDENT;
int i;
+ char *escaped_key = NULL;
if (!n)
return 1;
@@ -301,7 +302,14 @@ static int _write_config(const struct dm_config_node *n, int only_one,
if (!_line_start(out))
return_0;
- line_append("%s%s", space, n->key);
+ if (strchr(n->key, '#') || strchr(n->key, '"') || strchr(n->key, '!')) {
+ escaped_key = alloca(dm_escaped_len(n->key) + 2);
+ *escaped_key = '"';
+ dm_escape_double_quotes(escaped_key + 1, n->key);
+ strcat(escaped_key, "\"");
+ }
+ line_append("%s%s", space, escaped_key ? escaped_key : n->key);
+ escaped_key = NULL;
if (!n->v) {
/* it's a sub section */
line_append(" {");
@@ -433,15 +441,23 @@ static struct dm_config_node *_section(struct parser *p)
{
/* IDENTIFIER SECTION_B_CHAR VALUE* SECTION_E_CHAR */
struct dm_config_node *root, *n, *l = NULL;
+ char *token;
if (!(root = _create_node(p->mem))) {
log_error("Failed to allocate section node");
return NULL;
}
- if (!(root->key = _dup_tok(p)))
+ if (!(root->key = token = _dup_tok(p)))
return_NULL;
- match(TOK_IDENTIFIER);
+ if (p->t == TOK_STRING_ESCAPED) {
+ token ++; /* OK as the token is pool-allocated */
+ token[strlen(token) - 1] = 0;
+ dm_unescape_double_quotes(token);
+ root->key = token;
+ match(TOK_STRING_ESCAPED);
+ } else
+ match(TOK_IDENTIFIER);
if (p->t == TOK_SECTION_B) {
match(TOK_SECTION_B);
10 years, 3 months