--- Makefile.in | 1 configure.in | 22 ++++ lib/Makefile.in | 8 + lib/commands/toolcontext.c | 7 + lib/metadata/segtype.h | 4 lib/misc/configure.h.in | 3 lib/multisnapshot/.exported_symbols | 1 lib/multisnapshot/Makefile.in | 31 +++++ lib/multisnapshot/multisnapshot.c | 188 ++++++++++++++++++++++++++++++++++++ tools/lvcreate.c | 3 10 files changed, 267 insertions(+), 1 deletion(-) Index: LVM2.2.02.45/configure.in =================================================================== --- LVM2.2.02.45.orig/configure.in 2009-05-19 20:46:29.000000000 +0200 +++ LVM2.2.02.45/configure.in 2009-05-19 20:46:56.000000000 +0200 @@ -286,6 +286,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, @@ -800,6 +820,7 @@ AC_SUBST(POOL) AC_SUBST(QUORUM_CFLAGS) AC_SUBST(QUORUM_LIBS) AC_SUBST(SNAPSHOTS) +AC_SUBST(MULTISNAPSHOTS) AC_SUBST(STATICDIR) AC_SUBST(STATIC_LINK) AC_SUBST([LIB_PTHREAD]) @@ -833,6 +854,7 @@ lib/locking/Makefile lib/mirror/Makefile lib/misc/lvm-version.h lib/snapshot/Makefile +lib/multisnapshot/Makefile libdm/Makefile libdm/libdevmapper.pc man/Makefile Index: LVM2.2.02.45/lib/commands/toolcontext.c =================================================================== --- LVM2.2.02.45.orig/lib/commands/toolcontext.c 2009-05-19 20:46:29.000000000 +0200 +++ LVM2.2.02.45/lib/commands/toolcontext.c 2009-05-19 20:46:56.000000000 +0200 @@ -839,6 +839,13 @@ static int _init_segtypes(struct cmd_con dm_list_add(&cmd->segtypes, &segtype->list); #endif +#ifdef MUTISNAPSHOT_INTERNAL + if (!(segtype = init_multisnapshot_segtype(cmd))) + return 0; + segtype->library = NULL; + dm_list_add(&cmd->segtypes, &segtype->list); +#endif + #ifdef MIRRORED_INTERNAL if (!(segtype = init_mirrored_segtype(cmd))) return 0; Index: LVM2.2.02.45/lib/metadata/segtype.h =================================================================== --- LVM2.2.02.45.orig/lib/metadata/segtype.h 2009-05-19 20:46:29.000000000 +0200 +++ LVM2.2.02.45/lib/metadata/segtype.h 2009-05-19 20:46:56.000000000 +0200 @@ -108,6 +108,10 @@ struct segment_type *init_free_segtype(s struct segment_type *init_snapshot_segtype(struct cmd_context *cmd); #endif +#ifdef MULTISNAPSHOT_INTERNAL +struct segment_type *init_multisnapshot_segtype(struct cmd_context *cmd); +#endif + #ifdef MIRRORED_INTERNAL struct segment_type *init_mirrored_segtype(struct cmd_context *cmd); #endif Index: LVM2.2.02.45/lib/misc/configure.h.in =================================================================== --- LVM2.2.02.45.orig/lib/misc/configure.h.in 2009-05-19 20:46:29.000000000 +0200 +++ LVM2.2.02.45/lib/misc/configure.h.in 2009-05-19 20:46:56.000000000 +0200 @@ -361,6 +361,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.45/lib/multisnapshot/.exported_symbols =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ LVM2.2.02.45/lib/multisnapshot/.exported_symbols 2009-05-19 20:46:56.000000000 +0200 @@ -0,0 +1 @@ +init_segtype Index: LVM2.2.02.45/lib/multisnapshot/Makefile.in =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ LVM2.2.02.45/lib/multisnapshot/Makefile.in 2009-05-19 20:46:56.000000000 +0200 @@ -0,0 +1,31 @@ +# +# 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@ +VPATH = @srcdir@ + +SOURCES = multisnapshot.c + +LIB_SHARED = liblvm2multisnapshot.so +LIB_VERSION = $(LIB_VERSION_LVM) + +include $(top_srcdir)/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.45/lib/multisnapshot/multisnapshot.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ LVM2.2.02.45/lib/multisnapshot/multisnapshot.c 2009-05-19 21:42:36.000000000 +0200 @@ -0,0 +1,188 @@ +/* + * 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 *_snap_name(const struct lv_segment *seg) +{ + return seg->segtype->name; +} + +static int _snap_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; + struct logical_volume *org, *cow; + + seg->lv->status |= SNAPSHOT; + + if (!get_config_uint32(sn, "chunk_size", &chunk_size)) { + log_error("Couldn't read chunk size for snapshot."); + return 0; + } + + log_suppress(1); + + if (!(cow_name = find_config_str(sn, "shared_store", NULL))) { + log_suppress(0); + log_error("Snapshot cow storage not specified."); + return 0; + } + + if (!(org_name = find_config_str(sn, "origin", NULL))) { + log_suppress(0); + log_error("Snapshot origin not specified."); + return 0; + } + + log_suppress(0); + + 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; + } + + if (!vg_add_snapshot(seg->lv->name, org, cow, + &seg->lv->lvid, seg->len, chunk_size, + 0)) + return_0; + + return 1; +} + +static int _snap_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); + + return 1; +} + +#ifdef DEVMAPPER_SUPPORT +static int _snap_target_percent(void **target_state __attribute((unused)), + 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) +{ + uint64_t numerator, denominator; + + if (sscanf(params, "%" PRIu64 "/%" PRIu64, + &numerator, &denominator) == 2) { + *total_numerator += numerator; + *total_denominator += denominator; + if (!numerator) return TARGET_STATUS_FINISHED; + else return TARGET_STATUS_PROCESSING; + } else if (!strcmp(params, "Invalid")) { + return TARGET_STATUS_INVALIDATED; + } else { + return TARGET_STATUS_ERROR; + } +} + +static int _snap_target_present(struct cmd_context *cmd, + const struct lv_segment *seg __attribute((unused)), + unsigned *attributes __attribute((unused))) +{ + static int _snap_checked = 0; + static int _snap_present = 0; + + if (!_snap_checked) + _snap_present = target_present(cmd, "multisnapshot", 1); + + _snap_checked = 1; + + return _snap_present; +} + +#endif + +static int _snap_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 void _snap_destroy(const struct segment_type *segtype) +{ + dm_free((void *)segtype); +} + +static struct segtype_handler _multisnapshot_ops = { + .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, +#ifdef DMEVENTD + .target_monitored = _target_registered, + .target_monitor_events = _target_register_events, + .target_unmonitor_events = _target_unregister_events, +#endif +#endif + .modules_needed = _snap_modules_needed, + .destroy = _snap_destroy, +}; + +#ifdef MULTISNAPSHOT_INTERNAL +struct segment_type *init_multisnapshot_segtype(struct cmd_context *cmd) +#else /* Shared */ +struct segment_type *init_segtype(struct cmd_context *cmd); +struct segment_type *init_segtype(struct cmd_context *cmd) +#endif +{ + struct segment_type *segtype = dm_malloc(sizeof(*segtype)); + + if (!segtype) + return_NULL; + + segtype->cmd = cmd; + segtype->ops = &_multisnapshot_ops; + segtype->name = "multisnapshot"; + segtype->private = NULL; + segtype->flags = SEG_SNAPSHOT; + + log_very_verbose("Initialised segtype: %s", segtype->name); + + return segtype; +} Index: LVM2.2.02.45/lib/Makefile.in =================================================================== --- LVM2.2.02.45.orig/lib/Makefile.in 2009-05-19 20:46:29.000000000 +0200 +++ LVM2.2.02.45/lib/Makefile.in 2009-05-19 20:46:56.000000000 +0200 @@ -28,6 +28,10 @@ ifeq ("@SNAPSHOTS@", "shared") SUBDIRS += snapshot endif +ifeq ("@MULTISNAPSHOTS@", "shared") + SUBDIRS += multisnapshot +endif + ifeq ("@MIRRORS@", "shared") SUBDIRS += mirror endif @@ -120,6 +124,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 Index: LVM2.2.02.45/Makefile.in =================================================================== --- LVM2.2.02.45.orig/Makefile.in 2009-05-19 20:46:29.000000000 +0200 +++ LVM2.2.02.45/Makefile.in 2009-05-19 20:46:56.000000000 +0200 @@ -32,6 +32,7 @@ ifeq ($(MAKECMDGOALS),distclean) lib/locking \ lib/mirror \ lib/snapshot \ + lib/multisnapshot \ test \ po DISTCLEAN_TARGETS += lib/misc/configure.h Index: LVM2.2.02.45/tools/lvcreate.c =================================================================== --- LVM2.2.02.45.orig/tools/lvcreate.c 2009-05-19 20:46:41.000000000 +0200 +++ LVM2.2.02.45/tools/lvcreate.c 2009-05-19 21:42:36.000000000 +0200 @@ -391,7 +391,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)) {