Create a new segment type, "multisnapshot". Signed-off-by: Mikulas Patocka --- configure.in | 22 ++++ lib/Makefile.in | 9 + lib/commands/toolcontext.c | 5 lib/metadata/segtype.h | 4 lib/misc/configure.h.in | 3 lib/multisnapshot/.exported_symbols | 1 lib/multisnapshot/Makefile.in | 32 ++++++ lib/multisnapshot/multisnapshot.c | 181 ++++++++++++++++++++++++++++++++++++ tools/lvcreate.c | 3 9 files changed, 259 insertions(+), 1 deletion(-) Index: LVM2.2.02.70/configure.in =================================================================== --- LVM2.2.02.70.orig/configure.in 2010-07-06 00:23:15.000000000 +0200 +++ LVM2.2.02.70/configure.in 2010-07-10 04:07:39.000000000 +0200 @@ -299,6 +299,26 @@ if test x$SNAPSHOTS = xinternal; then fi ################################################################################ +dnl -- multisnapshots inclusion type +AC_MSG_CHECKING(whether to include multisnapshots) +AC_ARG_WITH(multisnapshots, + [ --with-multisnapshots=TYPE Multisnapshot support: internal/shared/none + [TYPE=internal] ], + [ MULTISNAPSHOTS="$withval" ], + [ MULTISNAPSHOTS="internal" ]) +AC_MSG_RESULT($MULTISNAPSHOTS) + +if [[ "x$MULTISNAPSHOTS" != xnone -a "x$MULTISNAPSHOTS" != xinternal -a "x$MULTISNAPSHOTS" != xshared ]]; + then AC_MSG_ERROR( +--with-multisnapshots parameter invalid +) +fi; + +if test x$MULTISNAPSHOTS = xinternal; then + AC_DEFINE([MULTISNAPSHOT_INTERNAL], 1, [Define to 1 to include built-in support for multisnapshots.]) +fi + +################################################################################ dnl -- mirrors inclusion type AC_MSG_CHECKING(whether to include mirrors) AC_ARG_WITH(mirrors, @@ -1205,6 +1225,7 @@ AC_SUBST(SALCK_LIBS) AC_SUBST(SELINUX_LIBS) AC_SUBST(SELINUX_PC) AC_SUBST(SNAPSHOTS) +AC_SUBST(MULTISNAPSHOTS) AC_SUBST(STATICDIR) AC_SUBST(STATIC_LINK) AC_SUBST(UDEV_LIBS) @@ -1249,6 +1270,7 @@ lib/mirror/Makefile lib/replicator/Makefile lib/misc/lvm-version.h lib/snapshot/Makefile +lib/multisnapshot/Makefile libdm/Makefile libdm/libdevmapper.pc liblvm/Makefile Index: LVM2.2.02.70/lib/commands/toolcontext.c =================================================================== --- LVM2.2.02.70.orig/lib/commands/toolcontext.c 2010-07-02 12:25:16.000000000 +0200 +++ LVM2.2.02.70/lib/commands/toolcontext.c 2010-07-10 04:07:39.000000000 +0200 @@ -942,6 +942,11 @@ static int _init_segtypes(struct cmd_con return 0; #endif +#ifdef MULTISNAPSHOT_INTERNAL + if (!init_multisnapshot_multiple_segtypes(cmd, &seglib)) + return 0; +#endif + #ifdef HAVE_LIBDL /* Load any formats in shared libs unless static */ if (!is_static() && Index: LVM2.2.02.70/lib/metadata/segtype.h =================================================================== --- LVM2.2.02.70.orig/lib/metadata/segtype.h 2010-05-24 17:32:21.000000000 +0200 +++ LVM2.2.02.70/lib/metadata/segtype.h 2010-07-10 04:07:39.000000000 +0200 @@ -131,4 +131,8 @@ struct segment_type *init_mirrored_segty struct segment_type *init_crypt_segtype(struct cmd_context *cmd); #endif +#ifdef MULTISNAPSHOT_INTERNAL +int init_multisnapshot_multiple_segtypes(struct cmd_context *cmd, struct segtype_library *lib); +#endif + #endif Index: LVM2.2.02.70/lib/misc/configure.h.in =================================================================== --- LVM2.2.02.70.orig/lib/misc/configure.h.in 2010-07-06 00:23:15.000000000 +0200 +++ LVM2.2.02.70/lib/misc/configure.h.in 2010-07-10 04:07:39.000000000 +0200 @@ -454,6 +454,9 @@ /* The path to 'modprobe', if available. */ #undef MODPROBE_CMD +/* Define to 1 to include built-in support for multisnapshots. */ +#undef MULTISNAPSHOT_INTERNAL + /* Define to 1 to enable O_DIRECT support. */ #undef O_DIRECT_SUPPORT Index: LVM2.2.02.70/lib/multisnapshot/.exported_symbols =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ LVM2.2.02.70/lib/multisnapshot/.exported_symbols 2010-07-10 04:07:39.000000000 +0200 @@ -0,0 +1 @@ +init_multiple_segtypes Index: LVM2.2.02.70/lib/multisnapshot/Makefile.in =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ LVM2.2.02.70/lib/multisnapshot/Makefile.in 2010-07-10 04:07:39.000000000 +0200 @@ -0,0 +1,32 @@ +# +# Copyright (C) 2002-2004 Sistina Software, Inc. All rights reserved. +# Copyright (C) 2004 Red Hat, Inc. All rights reserved. +# +# This file is part of LVM2. +# +# This copyrighted material is made available to anyone wishing to use, +# modify, copy, or redistribute it subject to the terms and conditions +# of the GNU General Public License v.2. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +top_builddir = @top_builddir@ +VPATH = @srcdir@ + +SOURCES = multisnapshot.c + +LIB_SHARED = liblvm2multisnapshot.so +LIB_VERSION = $(LIB_VERSION_LVM) + +include ../../make.tmpl + +install: liblvm2multisnapshot.so + $(INSTALL) -D $(OWNER) $(GROUP) -m 555 $(STRIP) $< \ + $(libdir)/liblvm2multisnapshot.so.$(LIB_VERSION) + $(LN_S) -f liblvm2multisnapshot.so.$(LIB_VERSION) \ + $(libdir)/liblvm2multisnapshot.so + Index: LVM2.2.02.70/lib/multisnapshot/multisnapshot.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ LVM2.2.02.70/lib/multisnapshot/multisnapshot.c 2010-07-10 04:07:39.000000000 +0200 @@ -0,0 +1,181 @@ +/* + * Copyright (C) 2003-2004 Sistina Software, Inc. All rights reserved. + * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved. + * + * This file is part of LVM2. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU Lesser General Public License v.2.1. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "lib.h" +#include "toolcontext.h" +#include "metadata.h" +#include "segtype.h" +#include "text_export.h" +#include "config.h" +#include "activate.h" +#include "str_list.h" +#ifdef DMEVENTD +# include "sharedlib.h" +# include "libdevmapper-event.h" +#endif + +static const char *_multisnap_name(const struct lv_segment *seg) +{ + return seg->segtype->name; +} + +static int _multisnap_modules_needed(struct dm_pool *mem, + const struct lv_segment *seg __attribute((unused)), + struct dm_list *modules) +{ + if (!str_list_add(mem, modules, "multisnapshot")) { + log_error("multisnapshot string list allocation failed"); + return 0; + } + + return 1; +} + +static int _multisnapshot_text_import(struct lv_segment *seg, + const struct config_node *sn, + struct dm_hash_table *pv_hash __attribute((unused))) +{ + uint32_t chunk_size; + const char *org_name, *cow_name, *exception_store; + struct logical_volume *org, *cow; + int old_suppress; + + if (!get_config_uint32(sn, "chunk_size", &chunk_size)) { + log_error("Couldn't read chunk size for snapshot."); + return 0; + } + + old_suppress = log_suppress(1); + + if (!(cow_name = find_config_str(sn, "shared_store", NULL))) { + log_suppress(old_suppress); + log_error("Snapshot cow storage not specified."); + return 0; + } + + if (!(org_name = find_config_str(sn, "origin", NULL))) { + log_suppress(old_suppress); + log_error("Snapshot origin not specified."); + return 0; + } + + log_suppress(old_suppress); + + if (!(cow = find_lv(seg->lv->vg, cow_name))) { + log_error("Unknown logical volume specified for " + "snapshot cow store."); + return 0; + } + + if (!(org = find_lv(seg->lv->vg, org_name))) { + log_error("Unknown logical volume specified for " + "snapshot origin."); + return 0; + } + + exception_store = find_config_str(sn, "exception_store", NULL); + if (!exception_store) { + log_error("Couldn't find exception store type."); + return 0; + } + + return init_snapshot_seg(seg, org, cow, exception_store, chunk_size, 0); +} + +static int _multisnapshot_text_export(const struct lv_segment *seg, + struct formatter *f) +{ + outf(f, "chunk_size = %u", seg->chunk_size); + outf(f, "origin = \"%s\"", seg->origin->name); + outf(f, "shared_store = \"%s\"", seg->cow->name); + outf(f, "exception_store = \"%s\"", seg->exception_store); + + return 1; +} + +#ifdef DEVMAPPER_SUPPORT +static int _multisnapshot_target_percent(void **target_state __attribute((unused)), + percent_range_t *percent_range, + struct dm_pool *mem __attribute((unused)), + struct cmd_context *cmd __attribute((unused)), + struct lv_segment *seg __attribute((unused)), + char *params, uint64_t *total_numerator, + uint64_t *total_denominator) +{ + *percent_range = PERCENT_INVALID; + return 0; +} + +static int _multisnap_target_present(struct cmd_context *cmd, + const struct lv_segment *seg __attribute((unused)), + unsigned *attributes __attribute((unused))) +{ + static int _multisnap_checked = 0; + static int _multisnap_present = 0; + + if (!_multisnap_checked) + _multisnap_present = target_present(cmd, "multisnapshot", 1) && + target_present(cmd, "multisnap-snap", 1); + + _multisnap_checked = 1; + + return _multisnap_present; +} + +#endif + +static void _multisnap_destroy(const struct segment_type *segtype) +{ + dm_free((void *)segtype); +} + +static struct segtype_handler _multisnapshot_ops = { + .name = _multisnap_name, + .modules_needed = _multisnap_modules_needed, + .destroy = _multisnap_destroy, +#ifdef DEVMAPPER_SUPPORT + .target_present = _multisnap_target_present, + .target_percent = _multisnapshot_target_percent, +#endif + .text_import = _multisnapshot_text_import, + .text_export = _multisnapshot_text_export, +}; + +#ifdef MULTISNAPSHOT_INTERNAL +int init_multisnapshot_multiple_segtypes(struct cmd_context *cmd, struct segtype_library *lib) +#else /* Shared */ +int init_multiple_segtypes(struct cmd_context *cmd, struct segtype_library *lib); +int init_multiple_segtypes(struct cmd_context *cmd, struct segtype_library *lib) +#endif +{ + struct segment_type *segtype; + + segtype = dm_malloc(sizeof(*segtype)); + if (!segtype) + return 0; + + segtype->cmd = cmd; + segtype->ops = &_multisnapshot_ops; + segtype->name = "multisnapshot"; + segtype->private = NULL; + segtype->flags = SEG_SNAPSHOT; + + if (!lvm_register_segtype(lib, segtype)) + return 0; + + log_very_verbose("Initialised segtype: %s", segtype->name); + + return 1; +} Index: LVM2.2.02.70/lib/Makefile.in =================================================================== --- LVM2.2.02.70.orig/lib/Makefile.in 2010-05-21 14:36:30.000000000 +0200 +++ LVM2.2.02.70/lib/Makefile.in 2010-07-10 04:07:39.000000000 +0200 @@ -28,6 +28,10 @@ ifeq ("@SNAPSHOTS@", "shared") SUBDIRS += snapshot endif +ifeq ("@MULTISNAPSHOTS@", "shared") + SUBDIRS += multisnapshot +endif + ifeq ("@MIRRORS@", "shared") SUBDIRS += mirror endif @@ -130,6 +134,10 @@ ifeq ("@SNAPSHOTS@", "internal") SOURCES += snapshot/snapshot.c endif +ifeq ("@MULTISNAPSHOTS@", "internal") + SOURCES += multisnapshot/multisnapshot.c +endif + ifeq ("@MIRRORS@", "internal") SOURCES += mirror/mirrored.c endif @@ -163,6 +171,7 @@ ifeq ($(MAKECMDGOALS),distclean) format1 \ format_pool \ snapshot \ + multisnapshot \ mirror \ replicator \ locking Index: LVM2.2.02.70/tools/lvcreate.c =================================================================== --- LVM2.2.02.70.orig/tools/lvcreate.c 2010-07-10 04:07:31.000000000 +0200 +++ LVM2.2.02.70/tools/lvcreate.c 2010-07-10 04:07:39.000000000 +0200 @@ -376,7 +376,8 @@ static int _lvcreate_params(struct lvcre } log_verbose("Setting chunksize to %d sectors.", lp->chunk_size); - if (!(lp->segtype = get_segtype_from_string(cmd, "snapshot"))) + if (!(lp->segtype = get_segtype_from_string(cmd, + !lp->shared_store ? "snapshot" : "multisnapshot"))) return_0; } else { if (arg_count(cmd, chunksize_ARG)) {