Skip to contentSkip to conversation

LVM RAID: new features

PATCH New Jonathan Brassow 1 participant 7 messages Aug 3, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 LVM RAID: new features

The next five patches expand the available operations for LVM RAID devices.

- Basic monitoring support is added - only reporting on RAID kernel events
- Ability to down-convert RAID1 arrays (similar to the current mirroring target)
- Add '--splitmirrors' support for RAID1 (only 1 device so far)

brassow

#1 lore raw

PATCH 1/1 LVM RAID: Add monitoring support

Add dmeventd monitoring for RAID segment types.

This only reports RAID events right now. 'lvconvert --repair' comes later.

daemons/dmeventd/plugins/raid/dmeventd_raid.c new file +145 -0
Index: LVM2/daemons/dmeventd/plugins/raid/dmeventd_raid.c
===================================================================
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2005-2010 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 "lvm2cmd.h"
+#include "errors.h"
+#include "libdevmapper-event.h"
+#include "dmeventd_lvm.h"
+
+#include <syslog.h> /* FIXME Replace syslog with multilog */
+/* FIXME Missing openlog? */
+/* FIXME Replace most syslogs with log_error() style messages and add complete context. */
+/* FIXME Reformat to 80 char lines. */
+
+static int _process_raid_event(char *params, const char *device)
+{
+	int i, n, failure = 0;
+	char *p, *a[4];
+	char *raid_type;
+	char *num_devices;
+	char *health_chars;
+	char *resync_ratio;
+
+	/*
+	 * RAID parms:     <raid_type> <#raid_disks> \
+	 *                 <health chars> <resync ratio>
+	 */
+	if (!dm_split_words(params, 4, 0, a)) {
+		syslog(LOG_ERR, "Failed to process status line for %s\n",
+		       device);
+		return -EINVAL;
+	}
+	raid_type = a[0];
+	num_devices = a[1];
+	health_chars = a[2];
+	resync_ratio = a[3];
+
+	if (!(n = atoi(num_devices))) {
+		syslog(LOG_ERR, "Failed to parse number of devices for %s: %s",
+		       device, num_devices);
+		return -EINVAL;
+	}
+
+	for (i = 0; i < n; i++) {
+		switch (health_chars[i]) {
+		case 'A':
+			/* Device is 'A'live and well */
+		case 'a':
+			/* Device is 'a'live, but not yet in-sync */
+			break;
+		case 'D':
+			syslog(LOG_ERR,
+			       "Device #%d of %s array, %s, has failed.",
+			       i, raid_type, device);
+			failure++;
+			break;
+		default:
+			/* Unhandled character returned from kernel */
+			break;
+		}
+		if (failure)
+			return 0; /* Don't bother parsing rest of status */
+	}
+
+	p = strstr(resync_ratio, "/");
+	if (!p) {
+		syslog(LOG_ERR, "Failed to parse resync_ratio for %s: %s",
+		       device, resync_ratio);
+		return -EINVAL;
+	}
+	p[0] = '\0';
+	syslog(LOG_INFO, "%s array, %s, is %s in-sync.",
+	       raid_type, device, strcmp(resync_ratio, p+1) ? "not" : "now");
+
+	return 0;
+}
+
+void process_event(struct dm_task *dmt,
+		   enum dm_event_mask event __attribute__((unused)),
+		   void **unused __attribute__((unused)))
+{
+	void *next = NULL;
+	uint64_t start, length;
+	char *target_type = NULL;
+	char *params;
+	const char *device = dm_task_get_name(dmt);
+
+	dmeventd_lvm2_lock();
+
+	do {
+		next = dm_get_next_target(dmt, next, &start, &length,
+					  &target_type, &params);
+
+		if (!target_type) {
+			syslog(LOG_INFO, "%s mapping lost.", device);
+			continue;
+		}
+
+		if (strcmp(target_type, "raid")) {
+			syslog(LOG_INFO, "%s has non-raid portion.", device);
+			continue;
+		}
+
+		if (_process_raid_event(params, device))
+			syslog(LOG_ERR, "Failed to process event for %s",
+			       device);
+	} while (next);
+
+	dmeventd_lvm2_unlock();
+}
+
+int register_device(const char *device,
+		    const char *uuid __attribute__((unused)),
+		    int major __attribute__((unused)),
+		    int minor __attribute__((unused)),
+		    void **unused __attribute__((unused)))
+{
+	int r = dmeventd_lvm2_init();
+	syslog(LOG_INFO, "Monitoring RAID device %s for events.", device);
+	return r;
+}
+
+int unregister_device(const char *device,
+		      const char *uuid __attribute__((unused)),
+		      int major __attribute__((unused)),
+		      int minor __attribute__((unused)),
+		      void **unused __attribute__((unused)))
+{
+	syslog(LOG_INFO, "No longer monitoring RAID device %s for events.",
+	       device);
+	dmeventd_lvm2_exit();
+	return 1;
+}
lib/raid/raid.c +43 -0

67 lines not on this page · raw message

daemons/dmeventd/plugins/Makefile.in +1 -1
Index: LVM2/daemons/dmeventd/plugins/Makefile.in
===================================================================
@@ -16,7 +16,7 @@ srcdir = @srcdir@
 top_srcdir = @top_srcdir@
 top_builddir = @top_builddir@
 
-SUBDIRS += lvm2 mirror snapshot
+SUBDIRS += lvm2 mirror snapshot raid
 
 include $(top_builddir)/make.tmpl
 
daemons/dmeventd/plugins/raid/Makefile.in new file +39 -0
Index: LVM2/daemons/dmeventd/plugins/raid/Makefile.in
===================================================================
@@ -0,0 +1,39 @@
+#
+# Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
+# Copyright (C) 2004-2005, 2008-2010 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@
+
+INCLUDES += -I$(top_srcdir)/tools -I$(top_srcdir)/daemons/dmeventd/plugins/lvm2
+CLDFLAGS += -L$(top_builddir)/tools -L$(top_builddir)/daemons/dmeventd/plugins/lvm2
+
+SOURCES = dmeventd_raid.c
+
+LIB_NAME = libdevmapper-event-lvm2raid
+LIB_SHARED = $(LIB_NAME).$(LIB_SUFFIX)
+LIB_VERSION = $(LIB_VERSION_LVM)
+
+CFLOW_LIST = $(SOURCES)
+CFLOW_LIST_TARGET = $(LIB_NAME).cflow
+
+include $(top_builddir)/make.tmpl
+
+LIBS += -ldevmapper-event-lvm2 -ldevmapper
+
+install_lvm2: install_dm_plugin
+
+install: install_lvm2
+
+DISTCLEAN_TARGETS += .exported_symbols_generated
lib/config/defaults.h +1 -0
Index: LVM2/lib/config/defaults.h
===================================================================
@@ -54,6 +54,7 @@
 #define DEFAULT_MIRROR_LOG_FAULT_POLICY "allocate"
 #define DEFAULT_MIRROR_IMAGE_FAULT_POLICY "remove"
 #define DEFAULT_MIRROR_MAX_IMAGES 8 /* limited by kernel DM_KCOPYD_MAX_REGIONS */
+#define DEFAULT_DMEVENTD_RAID_LIB "libdevmapper-event-lvm2raid.so"
 #define DEFAULT_DMEVENTD_MIRROR_LIB "libdevmapper-event-lvm2mirror.so"
 #define DEFAULT_DMEVENTD_SNAPSHOT_LIB "libdevmapper-event-lvm2snapshot.so"
 #define DEFAULT_DMEVENTD_MONITOR 1
daemons/dmeventd/plugins/raid/.exported_symbols new file +3 -0
Index: LVM2/daemons/dmeventd/plugins/raid/.exported_symbols
===================================================================
@@ -0,0 +1,3 @@
+process_event
+register_device
+unregister_device
configure.in +1 -0
Index: LVM2/configure.in
===================================================================
@@ -1417,6 +1417,7 @@ daemons/dmeventd/Makefile
 daemons/dmeventd/libdevmapper-event.pc
 daemons/dmeventd/plugins/Makefile
 daemons/dmeventd/plugins/lvm2/Makefile
+daemons/dmeventd/plugins/raid/Makefile
 daemons/dmeventd/plugins/mirror/Makefile
 daemons/dmeventd/plugins/snapshot/Makefile
 doc/Makefile
#2 lore raw

PATCH 1/1 LVM: New function - lv_is_on_pv

In reply to Jonathan Brassow

lv_is_on_pv - A useful function when devices are specified for removal from RAID

This function should also be useful for mirror down-converting.

lib/metadata/lv_manip.c +55 -0
Index: LVM2/lib/metadata/lv_manip.c
===================================================================
@@ -3513,6 +3513,61 @@ static int _match_seg_area_to_pe_range(s
 }
 
 /*
+ * pv_is_in_lv
+ * @lv:
+ * @pv:
+ *
+ * If any of the component devices of the LV are on the given PV, 1
+ * is returned; otherwise 0.  For example if one of the images of a mirror
+ * (or its log) is on the PV, 1 would be returned for the top-level LV.
+ * If you wish to check the images themselves, you should pass them.
+ */
+int pv_is_in_lv(struct logical_volume *lv, struct physical_volume *pv)
+{
+	uint32_t s;
+	struct physical_volume *pv2;
+	struct lv_segment *seg;
+
+	if (!lv)
+		return 0;
+
+	seg = first_seg(lv);
+	if (!seg)
+		return 0;
+
+	/* Check mirror log */
+	if (pv_is_in_lv(seg->log_lv, pv))
+		return 1;
+
+	/* Check stack of LVs */
+	dm_list_iterate_items(seg, &lv->segments) {
+		for (s = 0; s < seg->area_count; s++) {
+			if (seg_type(seg, s) == AREA_PV) {
+				pv2 = seg_pv(seg, s);
+				if (id_equal(&pv->id, &pv2->id))
+					return 1;
+				if (pv->dev && pv2->dev &&
+				    (pv->dev->dev == pv2->dev->dev))
+					return 1;
+			}
+
+			if ((seg_type(seg, s) == AREA_LV) &&
+			    pv_is_in_lv(seg_lv(seg, s), pv))
+				return 1;
+
+			if (!seg_is_raid(seg))
+				continue;
+
+			/* This is RAID, so we know the meta_area is AREA_LV */
+			if (pv_is_in_lv(seg_metalv(seg, s), pv))
+				return 1;
+		}
+	}
+
+	return 0;
+}
+
+/*
  * For each segment in lv_where that uses a PV in pvl directly,
  * split the segment if it spans more than one underlying PV.
  */
lib/metadata/metadata-exported.h +1 -0
Index: LVM2/lib/metadata/metadata-exported.h
===================================================================
@@ -645,6 +645,7 @@ int lv_is_merging_cow(const struct logic
 int lv_is_visible(const struct logical_volume *lv);
 
 int pv_is_in_vg(struct volume_group *vg, struct physical_volume *pv);
+int pv_is_in_lv(struct logical_volume *lv, struct physical_volume *pv);
 
 struct lv_segment *find_merging_cow(const struct logical_volume *origin);
 
#3 lore raw

PATCH 1/1 LVM: New function - lv_is_on_pv

forgive the mistake. I had originally called the function lv_is_on_pv, but changed it to pv_is_in_lv to match the existing function pv_is_in_vg...

The header and subject should have said 'pv_is_in_lv'.
brassow

Quoted 91 lines · Jonathan Brassow

lv_is_on_pv - A useful function when devices are specified for removal from RAID

This function should also be useful for mirror down-converting.

Index: LVM2/lib/metadata/lv_manip.c
===================================================================

lib/metadata/lv_manip.c +55 -0
@@ -3513,6 +3513,61 @@ static int _match_seg_area_to_pe_range(s
 }
 
 /*
+ * pv_is_in_lv
+ * @lv:
+ * @pv:
+ *
+ * If any of the component devices of the LV are on the given PV, 1
+ * is returned; otherwise 0.  For example if one of the images of a mirror
+ * (or its log) is on the PV, 1 would be returned for the top-level LV.
+ * If you wish to check the images themselves, you should pass them.
+ */
+int pv_is_in_lv(struct logical_volume *lv, struct physical_volume *pv)
+{
+	uint32_t s;
+	struct physical_volume *pv2;
+	struct lv_segment *seg;
+
+	if (!lv)
+		return 0;
+
+	seg = first_seg(lv);
+	if (!seg)
+		return 0;
+
+	/* Check mirror log */
+	if (pv_is_in_lv(seg->log_lv, pv))
+		return 1;
+
+	/* Check stack of LVs */
+	dm_list_iterate_items(seg, &lv->segments) {
+		for (s = 0; s < seg->area_count; s++) {
+			if (seg_type(seg, s) == AREA_PV) {
+				pv2 = seg_pv(seg, s);
+				if (id_equal(&pv->id, &pv2->id))
+					return 1;
+				if (pv->dev && pv2->dev &&
+				    (pv->dev->dev == pv2->dev->dev))
+					return 1;
+			}
+
+			if ((seg_type(seg, s) == AREA_LV) &&
+			    pv_is_in_lv(seg_lv(seg, s), pv))
+				return 1;
+
+			if (!seg_is_raid(seg))
+				continue;
+
+			/* This is RAID, so we know the meta_area is AREA_LV */
+			if (pv_is_in_lv(seg_metalv(seg, s), pv))
+				return 1;
+		}
+	}
+
+	return 0;
+}
+
+/*
 * For each segment in lv_where that uses a PV in pvl directly,
 * split the segment if it spans more than one underlying PV.
 */

Index: LVM2/lib/metadata/metadata-exported.h
===================================================================

lib/metadata/metadata-exported.h +1 -1
@@ -645,6 +645,7 @@ int lv_is_merging_cow(const struct logic
 int lv_is_visible(const struct logical_volume *lv);
 
 int pv_is_in_vg(struct volume_group *vg, struct physical_volume *pv);
+int pv_is_in_lv(struct logical_volume *lv, struct physical_volume *pv);
 
 struct lv_segment *find_merging_cow(const struct logical_volume *origin);
 
 
 
 
--

lvm-devel mailing list
lvm-devel at redhat.com
https://www.redhat.com/mailman/listinfo/lvm-devel

#4 lore raw

PATCH 1/1 LVM RAID: New function - lv_raid_percent

In reply to Jonathan Brassow

Add function 'lv_raid_percent'

'lv_raid_percent' operates exactly the same as 'lv_mirror_percent', so it is simply a wrapper around that function.

lv_[snapshot|mirror|raid]_percent should be combined - perhaps at the dev_manager level while retaining distinct lv_*_percent calls. We will not be able to combine the snapshot percent function with the other types for the simple reason that we must account for the "-real" layer. Perhaps lv_snapshot_percent will become a wrapper around a more generic function - its only purpose being to flag that it wants the snapshot %'age and not an underlying LV's %'age.

Anyway, this simple wrapper will suit RAID's purposes for now.

lib/activate/activate.c +5 -0
Index: LVM2/lib/activate/activate.c
===================================================================
@@ -611,6 +611,11 @@ int lv_mirror_percent(struct cmd_context
 	return r;
 }
 
+int lv_raid_percent(const struct logical_volume *lv, percent_t *percent)
+{
+	return lv_mirror_percent(lv->vg->cmd, lv, 0, percent, NULL);
+}
+
 static int _lv_active(struct cmd_context *cmd, struct logical_volume *lv)
 {
 	struct lvinfo info;
lib/activate/activate.h +1 -0
Index: LVM2/lib/activate/activate.h
===================================================================
@@ -93,6 +93,7 @@ int lv_check_transient(struct logical_vo
 int lv_snapshot_percent(const struct logical_volume *lv, percent_t *percent);
 int lv_mirror_percent(struct cmd_context *cmd, const struct logical_volume *lv,
 		      int wait, percent_t *percent, uint32_t *event_nr);
+int lv_raid_percent(const struct logical_volume *lv, percent_t *percent);
 
 /*
  * Return number of LVs in the VG that are active.
#5 lore raw

PATCH 1/1 LVM RAID: Add down-convert support for RAID1

In reply to Jonathan Brassow
tools/lvconvert.c +75 -1
Index: LVM2/tools/lvconvert.c
===================================================================
@@ -39,7 +39,7 @@ struct lvconvert_params {
 	uint32_t stripes;
 	uint32_t stripe_size;
 
-	struct segment_type *segtype;
+	const struct segment_type *segtype;
 
 	alloc_policy_t alloc;
 
@@ -1366,6 +1366,62 @@ static int _lvconvert_mirrors(struct cmd
 	return 1;
 }
 
+static int is_valid_raid_conversion(const struct segment_type *from_segtype,
+				    const struct segment_type *to_segtype)
+{
+	if (from_segtype == to_segtype)
+		return 1;
+
+	if (!segtype_is_raid(from_segtype) && !segtype_is_raid(to_segtype))
+		return_0;  /* Not converting to or from RAID? */
+
+	return 0;
+}
+
+static int lvconvert_raid(struct logical_volume *lv, struct lvconvert_params *lp)
+{
+	int image_count;
+	struct cmd_context *cmd = lv->vg->cmd;
+	struct lv_segment *seg = first_seg(lv);
+
+	if (!arg_count(cmd, type_ARG))
+		lp->segtype = seg->segtype;
+
+	if (arg_count(cmd, mirrors_ARG) && !seg_is_mirrored(seg)) {
+		log_error("'--mirrors/-m' is not compatible with %s",
+			  seg->segtype->name);
+		return 0;
+	}
+
+	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->name, lp->segtype->name);
+		return 0;
+	}
+
+	/* Change number of RAID1 images */
+	if (arg_count(cmd, mirrors_ARG)) {
+		image_count = lv_raid_image_count(lv);
+		if (lp->mirrors_sign == SIGN_PLUS)
+			image_count += lp->mirrors;
+		else if (lp->mirrors_sign == SIGN_MINUS)
+			image_count -= lp->mirrors;
+		else
+			image_count = lp->mirrors + 1;
+
+		if (image_count < 1) {
+			log_error("Unable to reduce images by specified amount");
+			return 0;
+		}
+
+		return lv_raid_change_image_count(lv, image_count, lp->pvh);
+	}
+
+	log_error("Conversion operation not yet supported.");
+	return 0;
+}
+
 static int lvconvert_snapshot(struct cmd_context *cmd,
 			      struct logical_volume *lv,
 			      struct lvconvert_params *lp)
@@ -1580,6 +1636,24 @@ static int _lvconvert_single(struct cmd_
 			stack;
 			return ECMD_FAILED;
 		}
+	} else if (segtype_is_raid(lp->segtype) || (lv->status & RAID)) {
+		if (!archive(lv->vg)) {
+			stack;
+			return ECMD_FAILED;
+		}
+		if (!lvconvert_raid(lv, lp)) {
+			stack;
+			return ECMD_FAILED;
+		}
+
+		if (!(failed_pvs = _failed_pv_list(lv->vg))) {
+			stack;
+			return ECMD_FAILED;
+		}
+
+		/* If repairing and using policies, remove missing PVs from VG */
+		if (arg_count(cmd, repair_ARG) && arg_count(cmd, use_policies_ARG))
+			_remove_missing_empty_pv(lv->vg, failed_pvs);
 	} else if (arg_count(cmd, mirrors_ARG) ||
 		   arg_count(cmd, splitmirrors_ARG) ||
 		   (lv->status & MIRRORED)) {
lib/metadata/raid_manip.c new file +418 -0

418 lines not on this page · raw message

lib/Makefile.in +1 -0
Index: LVM2/lib/Makefile.in
===================================================================
@@ -85,6 +85,7 @@ SOURCES =\
 	metadata/pv.c \
 	metadata/pv_manip.c \
 	metadata/pv_map.c \
+	metadata/raid_manip.c \
 	metadata/replicator_manip.c \
 	metadata/segtype.c \
 	metadata/snapshot_manip.c \
lib/metadata/metadata-exported.h +7 -0
Index: LVM2/lib/metadata/metadata-exported.h
===================================================================
@@ -743,6 +743,13 @@ int lv_is_rlog(const struct logical_volu
 int lv_is_slog(const struct logical_volume *lv);
 struct logical_volume *first_replicator_dev(const struct logical_volume *lv);
 /* --  metadata/replicator_manip.c */
+
+/* ++  metadata/raid_manip.c */
+uint32_t lv_raid_image_count(const struct logical_volume *lv);
+int lv_raid_change_image_count(struct logical_volume *lv,
+			       uint32_t new_count, struct dm_list *pvs);
+/* --  metadata/raid_manip.c */
+
 struct cmd_vg *cmd_vg_add(struct dm_pool *mem, struct dm_list *cmd_vgs,
 			  const char *vg_name, const char *vgid,
 			  uint32_t flags);
#6 lore raw

PATCH 1/1 LVM RAID: Add '--splitmirrors' support for RAID1

In reply to Jonathan Brassow
lib/metadata/raid_manip.c +115 -12
Index: LVM2/lib/metadata/raid_manip.c
===================================================================
@@ -37,6 +37,22 @@ uint32_t lv_raid_image_count(const struc
 	return seg->area_count;
 }
 
+static int do_correct_activate(struct logical_volume *orig_lv,
+			       struct logical_volume *new_lv)
+{
+	struct cmd_context *cmd = orig_lv->vg->cmd;
+
+	/* If top RAID was EX, use EX */
+	if (lv_is_active_exclusive_locally(orig_lv)) {
+		if (!activate_lv_excl(cmd, new_lv))
+			return_0;
+	} else {
+		if (!activate_lv(cmd, new_lv))
+			return_0;
+	}
+	return 1;
+}
+
 static int lv_is_on_pvs(struct logical_volume *lv, struct dm_list *pvs)
 {
 	struct pv_list *pvl;
@@ -380,18 +396,9 @@ int lv_raid_change_image_count(struct lo
 	 * Bring extracted LVs into existance, so there are no
 	 * conflicts for the main RAID device's resume
 	 */
-	if (!dm_list_empty(&removal_list)) {
-		dm_list_iterate_items(lvl, &removal_list) {
-			/* If top RAID was EX, use EX */
-			if (lv_is_active_exclusive_locally(lv)) {
-				if (!activate_lv_excl(lv->vg->cmd, lvl->lv))
-					return_0;
-			} else {
-				if (!activate_lv(lv->vg->cmd, lvl->lv))
-					return_0;
-			}
-		}
-	}
+	dm_list_iterate_items(lvl, &removal_list)
+		if (!do_correct_activate(lv, lvl->lv))
+			return_0;
 
 	if (!resume_lv(lv->vg->cmd, lv)) {
 		log_error("Failed to resume %s/%s after committing changes",
@@ -416,3 +423,99 @@ int lv_raid_change_image_count(struct lo
 
 	return 1;
 }
+
+int lv_raid_split(struct logical_volume *lv, const char *split_name,
+		  uint32_t new_count, struct dm_list *splittable_pvs)
+{
+	int r;
+	struct lv_list *lvl;
+	struct dm_list meta_list, data_list;
+	uint32_t old_count = lv_raid_image_count(lv);
+
+	dm_list_init(&meta_list);
+	dm_list_init(&data_list);
+
+	if ((old_count - new_count) != 1) {
+		log_error("Unable to split more than one image from %s/%s",
+			  lv->vg->name, lv->name);
+		return 0;
+	}
+
+	if (!seg_is_mirrored(first_seg(lv))) {
+		log_error("Unable to split logical volume of segment type, %s",
+			  first_seg(lv)->segtype->name);
+		return 0;
+	}
+
+	if (find_lv_in_vg(lv->vg, split_name)) {
+		log_error("Logical Volume \"%s\" already exists in %s",
+			  split_name, lv->vg->name);
+		return 0;
+	}
+
+	if (!raid_in_sync(lv)) {
+		log_error("Unable to split %s/%s while it is not in-sync.",
+			  lv->vg->name, lv->name);
+		return 0;
+	}
+
+	r = raid_extract_images(lv, new_count, splittable_pvs, 1,
+				&meta_list, &data_list);
+	if (!r)
+		return 0;
+
+	/* Get first item */
+	dm_list_iterate_items(lvl, &data_list)
+		break;
+
+	lvl->lv->name = split_name;
+
+	if (!vg_write(lv->vg)) {
+		log_error("Failed to write changes to %s in %s",
+			  lv->name, lv->vg->name);
+		return 0;
+	}
+
+	if (!suspend_lv(lv->vg->cmd, lv)) {
+		log_error("Failed to suspend %s/%s before committing changes",
+			  lv->vg->name, lv->name);
+		return 0;
+	}
+
+	if (!vg_commit(lv->vg)) {
+		log_error("Failed to commit changes to %s in %s",
+			  lv->name, lv->vg->name);
+		return 0;
+	}
+
+	/*
+	 * Bring extracted LVs into existance, so there are no
+	 * conflicts for the main RAID device's resume
+	 */
+	dm_list_iterate_items(lvl, &meta_list)
+		if (!do_correct_activate(lv, lvl->lv))
+			return 0;
+	dm_list_iterate_items(lvl, &data_list)
+		if (!do_correct_activate(lv, lvl->lv))
+			return 0;
+
+	/* Resume original LV */
+	if (!resume_lv(lv->vg->cmd, lv)) {
+		log_error("Failed to resume %s/%s after committing changes",
+			  lv->vg->name, lv->name);
+		return 0;
+	}
+
+	/* Remove the meta LVs */
+	dm_list_iterate_items(lvl, &meta_list) {
+		if (!deactivate_lv(lv->vg->cmd, lvl->lv))
+			return_0;
+		if (!lv_remove(lvl->lv))
+			return_0;
+	}
+
+	if (!vg_write(lv->vg) || !vg_commit(lv->vg))
+		return_0;
+
+	return 1;
+}
tools/lvconvert.c +10 -3
Index: LVM2/tools/lvconvert.c
===================================================================
@@ -1401,7 +1401,7 @@ static int lvconvert_raid(struct logical
 	}
 
 	/* Change number of RAID1 images */
-	if (arg_count(cmd, mirrors_ARG)) {
+	if (arg_count(cmd, mirrors_ARG) || arg_count(cmd, splitmirrors_ARG)) {
 		image_count = lv_raid_image_count(lv);
 		if (lp->mirrors_sign == SIGN_PLUS)
 			image_count += lp->mirrors;
@@ -1411,11 +1411,18 @@ static int lvconvert_raid(struct logical
 			image_count = lp->mirrors + 1;
 
 		if (image_count < 1) {
-			log_error("Unable to reduce images by specified amount");
+			log_error("Unable to %s images by specified amount",
+				  arg_count(cmd, splitmirrors_ARG) ?
+				  "split" : "reduce");
 			return 0;
 		}
 
-		return lv_raid_change_image_count(lv, image_count, lp->pvh);
+		if (arg_count(cmd, splitmirrors_ARG))
+			return lv_raid_split(lv, lp->lv_split_name,
+					     image_count, lp->pvh);
+		else
+			return lv_raid_change_image_count(lv, image_count,
+							  lp->pvh);
 	}
 
 	log_error("Conversion operation not yet supported.");
lib/metadata/metadata-exported.h +3 -0
Index: LVM2/lib/metadata/metadata-exported.h
===================================================================
@@ -748,6 +748,9 @@ struct logical_volume *first_replicator_
 uint32_t lv_raid_image_count(const struct logical_volume *lv);
 int lv_raid_change_image_count(struct logical_volume *lv,
 			       uint32_t new_count, struct dm_list *pvs);
+int lv_raid_split(struct logical_volume *lv, const char *split_name,
+		  uint32_t new_count, struct dm_list *splittable_pvs);
+
 /* --  metadata/raid_manip.c */
 
 struct cmd_vg *cmd_vg_add(struct dm_pool *mem, struct dm_list *cmd_vgs,