public inbox for lvm2-cvs@sourceware.org
help / color / mirror / Atom feed
* LVM2/lib metadata/raid_manip.c raid/raid.c
@ 2011-08-13 4:28 jbrassow
0 siblings, 0 replies; 2+ messages in thread
From: jbrassow @ 2011-08-13 4:28 UTC (permalink / raw)
To: lvm-devel, lvm2-cvs
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: jbrassow@sourceware.org 2011-08-13 04:28:34
Modified files:
lib/metadata : raid_manip.c
lib/raid : raid.c
Log message:
Compiler warning fixes, better error messaging, and cosmetic changes.
1) add new function 'raid_remove_top_layer' which will be useful
to other conversion functions later (also cleans up code)
2) Add error messages if raid_[extract|add]_images fails
3) Add function prototypes to prevent compiler warnings when
compiling with '--with-raid=shared'
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/raid_manip.c.diff?cvsroot=lvm2&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/raid/raid.c.diff?cvsroot=lvm2&r1=1.5&r2=1.6
--- LVM2/lib/metadata/raid_manip.c 2011/08/11 21:32:18 1.3
+++ LVM2/lib/metadata/raid_manip.c 2011/08/13 04:28:34 1.4
@@ -123,6 +123,63 @@
}
/*
+ * raid_remove_top_layer
+ * @lv
+ * @removal_list
+ *
+ * Remove top layer of RAID LV in order to convert to linear.
+ * This function makes no on-disk changes. The residual LVs
+ * returned in 'removal_list' must be freed by the caller.
+ *
+ * Returns: 1 on succes, 0 on failure
+ */
+static int raid_remove_top_layer(struct logical_volume *lv,
+ struct dm_list *removal_list)
+{
+ struct lv_list *lvl_array, *lvl;
+ struct lv_segment *seg = first_seg(lv);
+
+ if (!seg_is_mirrored(seg)) {
+ log_error(INTERNAL_ERROR
+ "Unable to remove RAID layer from segment type %s",
+ seg->segtype->name);
+ return 0;
+ }
+
+ if (seg->area_count != 1) {
+ log_error(INTERNAL_ERROR
+ "Unable to remove RAID layer when there"
+ " is more than one sub-lv");
+ return 0;
+ }
+
+ lvl_array = dm_pool_alloc(lv->vg->vgmem, 2 * sizeof(*lvl));
+ if (!lvl_array) {
+ log_error("Memory allocation failed.");
+ return 0;
+ }
+
+ /* Add last metadata area to removal_list */
+ lvl_array[0].lv = seg_metalv(seg, 0);
+ lv_set_visible(seg_metalv(seg, 0));
+ remove_seg_from_segs_using_this_lv(seg_metalv(seg, 0), seg);
+ seg_metatype(seg, 0) = AREA_UNASSIGNED;
+ dm_list_add(removal_list, &(lvl_array[0].list));
+
+ /* Remove RAID layer and add residual LV to removal_list*/
+ seg_lv(seg, 0)->status &= ~RAID_IMAGE;
+ lv_set_visible(seg_lv(seg, 0));
+ lvl_array[1].lv = seg_lv(seg, 0);
+ dm_list_add(removal_list, &(lvl_array[1].list));
+
+ if (!remove_layer_from_lv(lv, seg_lv(seg, 0)))
+ return_0;
+
+ lv->status &= ~(MIRRORED | RAID);
+ return 1;
+}
+
+/*
* _shift_and_rename_image_components
* @seg: Top-level RAID segment
*
@@ -373,11 +430,10 @@
int lv_raid_change_image_count(struct logical_volume *lv,
uint32_t new_count, struct dm_list *pvs)
{
- int r;
uint32_t old_count = lv_raid_image_count(lv);
struct lv_segment *seg = first_seg(lv);
struct dm_list removal_list;
- struct lv_list *lvl_array, *lvl;
+ struct lv_list *lvl;
dm_list_init(&removal_list);
@@ -392,34 +448,25 @@
return 1;
}
- if (old_count > new_count)
- r = raid_extract_images(lv, new_count, pvs, 1,
- &removal_list, &removal_list);
- else
- r = raid_add_images(lv, new_count, pvs);
- if (!r)
- return 0;
+ if (old_count > new_count) {
+ if (!raid_extract_images(lv, new_count, pvs, 1,
+ &removal_list, &removal_list)) {
+ log_error("Failed to extract images from %s/%s",
+ lv->vg->name, lv->name);
+ return 0;
+ }
+ } else {
+ if (!raid_add_images(lv, new_count, pvs)) {
+ log_error("Failed to add images to %s/%s",
+ lv->vg->name, lv->name);
+ return 0;
+ }
+ }
/* Convert to linear? */
- if (new_count == 1) {
- /* Add last metadata area to removal_list */
- lvl_array = dm_pool_alloc(lv->vg->cmd->mem, 2 * sizeof(*lvl));
- if (!lvl_array)
- return_0;
- lvl_array[0].lv = seg_metalv(seg, 0);
- remove_seg_from_segs_using_this_lv(seg_metalv(seg, 0), seg);
- seg_metatype(seg, 0) = AREA_UNASSIGNED;
- dm_list_add(&removal_list, &(lvl_array[0].list));
-
- /* Remove RAID layer */
- seg_lv(seg, 0)->status &= ~RAID_IMAGE;
- lv_set_visible(seg_lv(seg, 0));
- lvl_array[1].lv = seg_lv(seg, 0);
- dm_list_add(&removal_list, &(lvl_array[1].list));
-
- if (!remove_layer_from_lv(lv, seg_lv(seg, 0)))
- return_0;
- lv->status &= ~(MIRRORED | RAID);
+ if ((new_count == 1) && !raid_remove_top_layer(lv, &removal_list)) {
+ log_error("Failed to remove RAID layer after linear conversion");
+ return 0;
}
if (!vg_write(lv->vg)) {
--- LVM2/lib/raid/raid.c 2011/08/11 21:32:19 1.5
+++ LVM2/lib/raid/raid.c 2011/08/13 04:28:34 1.6
@@ -349,6 +349,20 @@
return segtype;
}
+#ifndef RAID_INTERNAL /* Shared */
+struct segment_type *init_raid1_segtype(struct cmd_context *cmd);
+struct segment_type *init_raid4_segtype(struct cmd_context *cmd);
+struct segment_type *init_raid5_segtype(struct cmd_context *cmd);
+struct segment_type *init_raid5_la_segtype(struct cmd_context *cmd);
+struct segment_type *init_raid5_ra_segtype(struct cmd_context *cmd);
+struct segment_type *init_raid5_ls_segtype(struct cmd_context *cmd);
+struct segment_type *init_raid5_rs_segtype(struct cmd_context *cmd);
+struct segment_type *init_raid6_segtype(struct cmd_context *cmd);
+struct segment_type *init_raid6_zr_segtype(struct cmd_context *cmd);
+struct segment_type *init_raid6_nr_segtype(struct cmd_context *cmd);
+struct segment_type *init_raid6_nc_segtype(struct cmd_context *cmd);
+#endif
+
struct segment_type *init_raid1_segtype(struct cmd_context *cmd)
{
struct segment_type *segtype;
^ permalink raw reply [flat|nested] 2+ messages in thread
* LVM2/lib metadata/raid_manip.c raid/raid.c
@ 2011-08-11 21:32 jbrassow
0 siblings, 0 replies; 2+ messages in thread
From: jbrassow @ 2011-08-11 21:32 UTC (permalink / raw)
To: lvm-devel, lvm2-cvs
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: jbrassow@sourceware.org 2011-08-11 21:32:19
Modified files:
lib/metadata : raid_manip.c
lib/raid : raid.c
Log message:
Various code clean-ups (s/malloc/zalloc/, new msgs, etc)
Fix a couple more issues that kabi found.
- Add some error messages in failure cases
- s/malloc/zalloc/
- use vg->vgmem for lv names instead of vg->cmd->mem
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/raid_manip.c.diff?cvsroot=lvm2&r1=1.2&r2=1.3
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/raid/raid.c.diff?cvsroot=lvm2&r1=1.4&r2=1.5
--- LVM2/lib/metadata/raid_manip.c 2011/08/11 19:17:10 1.2
+++ LVM2/lib/metadata/raid_manip.c 2011/08/11 21:32:18 1.3
@@ -242,7 +242,7 @@
{
int len;
char *tmp_name;
- struct cmd_context *cmd = seg->lv->vg->cmd;
+ struct volume_group *vg = seg->lv->vg;
struct logical_volume *data_lv = seg_lv(seg, idx);
struct logical_volume *meta_lv = seg_metalv(seg, idx);
@@ -262,14 +262,14 @@
seg_metatype(seg, idx) = AREA_UNASSIGNED;
len = strlen(meta_lv->name) + strlen("_extracted") + 1;
- tmp_name = dm_pool_alloc(cmd->mem, len);
+ tmp_name = dm_pool_alloc(vg->vgmem, len);
if (!tmp_name)
return_0;
sprintf(tmp_name, "%s_extracted", meta_lv->name);
meta_lv->name = tmp_name;
len = strlen(data_lv->name) + strlen("_extracted") + 1;
- tmp_name = dm_pool_alloc(cmd->mem, len);
+ tmp_name = dm_pool_alloc(vg->vgmem, len);
if (!tmp_name)
return_0;
sprintf(tmp_name, "%s_extracted", data_lv->name);
--- LVM2/lib/raid/raid.c 2011/08/11 14:00:58 1.4
+++ LVM2/lib/raid/raid.c 2011/08/11 21:32:19 1.5
@@ -321,11 +321,13 @@
static struct segment_type *init_raid_segtype(struct cmd_context *cmd,
const char *raid_type)
{
- struct segment_type *segtype = dm_malloc(sizeof(*segtype));
+ struct segment_type *segtype = dm_zalloc(sizeof(*segtype));
- if (!segtype)
+ if (!segtype) {
+ log_error("Failed to allocate memory for %s segtype",
+ raid_type);
return_NULL;
-
+ }
segtype->cmd = cmd;
segtype->flags = SEG_RAID;
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-08-13 4:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-13 4:28 LVM2/lib metadata/raid_manip.c raid/raid.c jbrassow
-- strict thread matches above, loose matches on Subject: below --
2011-08-11 21:32 jbrassow
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).