summaryrefslogtreecommitdiffstats
path: root/lib/metadata/raid_manip.c
diff options
context:
space:
mode:
authorJonathan Earl Brassow <jbrassow@redhat.com>2011-08-18 19:34:18 +0000
committerJonathan Earl Brassow <jbrassow@redhat.com>2011-08-18 19:34:18 +0000
commita324baf6a13cb84f46dda81b6f3c7e795820c35d (patch)
tree5e96c34b9ce8a8647c4c17e0f7ef56c6757c6b77 /lib/metadata/raid_manip.c
parent63d32fb6a6e2d77d74967c7874595b0fe0e2dd0b (diff)
downloadlvm2-a324baf6a13cb84f46dda81b6f3c7e795820c35d.tar.gz
lvm2-a324baf6a13cb84f46dda81b6f3c7e795820c35d.tar.xz
lvm2-a324baf6a13cb84f46dda81b6f3c7e795820c35d.zip
Add --splitmirrors support for RAID1 (1 image only)
Users already have the ability to split an image from an LV of "mirror" segtype. This patch extends that ability to LVs of "raid1" segtype. This patch only allows a single image to be split off, however. (The "mirror" segtype allows an arbitrary number of images to be split off. e.g. 4-way => 3-way/linear, 2-way/2-way, linear,3-way)
Diffstat (limited to 'lib/metadata/raid_manip.c')
-rw-r--r--lib/metadata/raid_manip.c108
1 files changed, 108 insertions, 0 deletions
diff --git a/lib/metadata/raid_manip.c b/lib/metadata/raid_manip.c
index 4a00820e..c48d9e06 100644
--- a/lib/metadata/raid_manip.c
+++ b/lib/metadata/raid_manip.c
@@ -515,3 +515,111 @@ int lv_raid_change_image_count(struct logical_volume *lv,
return 1;
}
+
+int lv_raid_split(struct logical_volume *lv, const char *split_name,
+ uint32_t new_count, struct dm_list *splittable_pvs)
+{
+ const char *old_name;
+ struct lv_list *lvl;
+ struct dm_list removal_list, data_list;
+ struct cmd_context *cmd = lv->vg->cmd;
+ uint32_t old_count = lv_raid_image_count(lv);
+
+ dm_list_init(&removal_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;
+ }
+
+ if (!raid_extract_images(lv, new_count, splittable_pvs, 1,
+ &removal_list, &data_list)) {
+ log_error("Failed to extract images from %s/%s",
+ lv->vg->name, lv->name);
+ return 0;
+ }
+
+ /* Convert to linear? */
+ if ((new_count == 1) && !raid_remove_top_layer(lv, &removal_list)) {
+ log_error("Failed to remove RAID layer after linear conversion");
+ return 0;
+ }
+
+ /* Get first item */
+ dm_list_iterate_items(lvl, &data_list)
+ break;
+
+ old_name = lvl->lv->name;
+ 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(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;
+ }
+
+ /*
+ * Resume original LV
+ * This also resumes all other sub-lvs (including the extracted)
+ */
+ if (!resume_lv(cmd, lv)) {
+ log_error("Failed to resume %s/%s after committing changes",
+ lv->vg->name, lv->name);
+ return 0;
+ }
+
+ /* Recycle newly split LV so it is properly renamed */
+ if (!suspend_lv(cmd, lvl->lv) || !resume_lv(cmd, lvl->lv)) {
+ log_error("Failed to rename %s to %s after committing changes",
+ old_name, split_name);
+ return 0;
+ }
+
+ /*
+ * Eliminate the residual LVs
+ */
+ dm_list_iterate_items(lvl, &removal_list) {
+ if (!deactivate_lv(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;
+}