LVM RAID: Add ability to convert linear to RAID1
PATCH 1/1 LVM RAID: Add ability to convert linear to RAID1
Add the ability to convert linear LVs to RAID1
Example:
~> lvconvert --type raid1 -m 1 vg/lv
The following steps are performed to convert linear to RAID1:
1) Allocate a metadata device from the same PV as the linear device to provide the metadata/data LV pair required for all RAID components.
2) Allocate the required number of metadata/data LV pairs for the remaining additional images.
3) Clear the metadata LVs. This performs a LVM metadata update.
4) Create the top-level RAID LV and add the component devices.
We want to make any failure easy to unwind. This is why we don't create the top-level LV and add the components until the last step. Should anything happen before that, the user could simply remove the unnecessary images. Also, we want to ensure that the metadata LVs are cleared before forming the array to prevent stale information from polluting the new array.
A new macro 'seg_is_linear' was added to allow us to distinguish linear LVs from striped LVs.
The ability to reserve LV names was added to prevent generate_lv_name from choosing a name which we want to use in the future. The need for this comes from the required order of steps when converting linear LVs to RAID1, and the following constraints:
1) We want the linear LV to occupy the first position in the array (*_rimage_0)
2) We must allocate the new metadata/data LVs in pairs to allow the allocator to group them together on the same device cleanly.
3) The linear LV does not aquire its sub-lv name until insert_layer_for_lv is called.
'generate_lv_name' is used in all the above cases to create names for the rimage and rmeta LVs. If we can't reserve the *_rimage_0 name, then the rmeta and rimage LV pair names would not match, nor would the converting LV's rimage name be correct.
lib/metadata/lv_manip.c +38 -0
@@ -2866,10 +2866,40 @@ out:return r; } +int reserve_lv_name (struct volume_group *vg,const char *name) +{ +struct str_list *strl; +struct lv_list *lvl; + + dm_list_iterate_items(lvl, &vg->lvs) +if (!strcmp (lvl->lv->name, name)) { +log_error ("Unable to reserve existing LV name, %s" , + name); +return 0 ; + } + +if (!(strl =dm_pool_zalloc (vg->vgmem,sizeof (*strl)))) + goto fail; + +if (!(strl->str =dm_pool_strdup (vg->vgmem, name))) + goto fail; + +dm_list_add (&vg->reserved_lv_names, &strl->list); +log_debug ("Reserving logical volume name, %s in volume group %s" , + name, vg->name); + +return 1 ; + +fail: +log_error ("Unable to reserve LV name, %s: Out of memory" , name); +return 0 ; +} +char *generate_lv_name (struct volume_group *vg,const char *format,char *buffer,size_t len) {struct lv_list *lvl; +struct str_list *strl;int high =-1 , i; dm_list_iterate_items(lvl, &vg->lvs) {
@@ -2880,6 +2910,14 @@ char *generate_lv_name(struct volume_gro high = i; } + dm_list_iterate_items(strl, &vg->reserved_lv_names) { +if (sscanf (strl->str, format, &i) !=1 ) +continue ; + +if (i > high) + high = i; + } +if (dm_snprintf (buffer, len, format, high +1 ) <0 )return NULL ;
lib/metadata/metadata-exported.h +1 -0
@@ -801,6 +801,7 @@ struct dm_list *lvs_using_lv(struct cmd_ struct logical_volume *lv);uint32_t find_free_lvnum (struct logical_volume *lv); +int reserve_lv_name (struct volume_group *vg,const char *name);char *generate_lv_name (struct volume_group *vg,const char *format,char *buffer,size_t len);
lib/metadata/raid_manip.c +153 -13
244 lines not on this page · raw message
lib/metadata/segtype.h +1 -0
@@ -47,6 +47,7 @@ struct dev_manager;#define seg_is_replicator (seg) ((seg)->segtype->flags & SEG_REPLICATOR ? 1 : 0)#define seg_is_replicator_dev (seg) ((seg)->segtype->flags & SEG_REPLICATOR_DEV ? 1 : 0)#define seg_is_striped (seg) ((seg)->segtype->flags & SEG_AREAS_STRIPED ? 1 : 0) +#define seg_is_linear (seg) (seg_is_striped(seg) && !(seg)->stripe_size)#define seg_is_snapshot (seg) ((seg)->segtype->flags & SEG_SNAPSHOT ? 1 : 0)#define seg_is_virtual (seg) ((seg)->segtype->flags & SEG_VIRTUAL ? 1 : 0)#define seg_is_raid (seg) ((seg)->segtype->flags & SEG_RAID ? 1 : 0)
lib/metadata/vg.c +1 -0
@@ -48,6 +48,7 @@ struct volume_group *alloc_vg(const chardm_list_init (&vg->pvs_to_create);dm_list_init (&vg->lvs);dm_list_init (&vg->tags); +dm_list_init (&vg->reserved_lv_names);dm_list_init (&vg->removed_pvs);log_debug ("Allocated VG %s at %p." , vg->name, vg);
lib/metadata/vg.h +8 -0
@@ -91,6 +91,14 @@ struct volume_group {struct dm_list tags;/* +* The 'reserved_lv_names' list is used by the +* [generate|reserve]_lv_name functions. 'generate_lv_name' will not +* generate an LV name that exists or has been reserved by +* 'reserve_lv_name'. +*/ +struct dm_list reserved_lv_names; + +/* * FIXME: Move the next fields into a different struct? */
tools/commands.h +2 -1
@@ -98,6 +98,7 @@ xx(lvconvert,0 ,"lvconvert " "[-m|--mirrors Mirrors [{--mirrorlog {disk|core|mirrored}|--corelog}]]\n" +"\t[--type SegmentType]\n" "\t[--repair [--use-policies]]\n" "\t[-R|--regionsize MirrorLogRegionSize]\n" "\t[--alloc AllocationPolicy]\n"
@@ -141,7 +142,7 @@ xx(lvconvert, alloc_ARG, background_ARG, chunksize_ARG, corelog_ARG, interval_ARG, merge_ARG, mirrorlog_ARG, mirrors_ARG, name_ARG, noudevsync_ARG, regionsize_ARG, repair_ARG, snapshot_ARG, splitmirrors_ARG, trackchanges_ARG, - stripes_long_ARG, stripesize_ARG, test_ARG, + type_ARG, stripes_long_ARG, stripesize_ARG, test_ARG, use_policies_ARG, yes_ARG, force_ARG, zero_ARG) xx(lvcreate,
tools/lvconvert.c +6 -3
@@ -304,7 +304,8 @@ static int _read_params(struct lvconvertreturn 0 ; } -if (!(lp->segtype =get_segtype_from_string (cmd,"mirror" ))) + lp->segtype =get_segtype_from_string (cmd,arg_str_value (cmd, type_ARG,"mirror" )); +if (!lp->segtype) return_0; }
@@ -1393,7 +1394,7 @@ static int is_valid_raid_conversion(consif (!segtype_is_raid (from_segtype) && !segtype_is_raid (to_segtype)) return_0;/* Not converting to or from RAID? */ -return 0 ; +return 1 ; }static int lvconvert_raid (struct logical_volume *lv,struct lvconvert_params *lp)
@@ -1405,7 +1406,9 @@ static int lvconvert_raid(struct logicalif (!arg_count (cmd, type_ARG)) lp->segtype = seg->segtype; -if (arg_count (cmd, mirrors_ARG) && !seg_is_mirrored (seg)) { +/* Can only change image count for raid1 and linear */ +if (arg_count (cmd, mirrors_ARG) && + !seg_is_mirrored (seg) && !seg_is_linear (seg)) {log_error ("'--mirrors/-m' is not compatible with %s" , seg->segtype->name);return 0 ;
PATCH 1/1 LVM RAID: Add ability to convert linear to RAID1
Quoted 5 lines · Jonathan Brassow
The ability to reserve LV names was added to prevent
generate_lv_namefrom choosing a name which we want to use in the future. The need for this comes from the required order of steps when converting linear LVs to RAID1, and the following constraints:
1) We want the linear LV to occupy the first position in the array (*_rimage_0)
Quoted 8 lines
2) We must allocate the new metadata/data LVs in pairs to allow the allocator to group them together on the same device cleanly.
3) The linear LV does not aquire its sub-lv name untilinsert_layer_for_lvis called.
'generate_lv_name' is used in all the above cases to create names for the rimage and rmeta LVs. If we can't reserve the*_rimage_0name, then the rmeta and rimage LV pair names would not match, nor would the converting LV's rimage name be correct.
To address some confusion on what it means to 'reserve' a name...
A reserved name is not somehow logged in the LVM metadata. It is not reserved across commands.
When converting from linear to RAID1, new data images need to be allocated and new metadata images need to be allocated. (Remember, a new metadata image will be needed as a counterpart to the current linear LV as well.) For a 3-way RAID1, that would mean allocating 3 metadata areas and 2 data areas. The convert from linear to a 3-way RAID1 happens in the following way:
1) Start out with a linear LV, "lv"
2) Reserve the name "lv_rimage_0", so that it isn't taken when generate_lv_name is used to allocate the new data images
3) allocate the metadata area that will pair with the current linear LV
4) allocate the metadata/data pairs that will make up the additional images of the RAID1 array.
*) Now we have "lv", "lv_rmeta_[012]", "lv_rimage_[12]", and a in-core reserved name "lv_rimage_0" which isn't yet used. If we hadn't reserved "lv_rimage_0", the data LVs allocated would have been "lv_rimage_[01]", which would conflict with the name we want for the linear LV that we are going to call 'insert_layer_for_lv' on later.
5) We COMMIT THE METADATA for the sole purpose of allowing us to activate the metadata LVs and clear them
6) clear metadata LVs
7) Create the RAID layer with 'insert_layer_for_lv'. We specify the reserved name here ("lv_rimage_0") as the name desired for the sub-LV that will result from this function call.
8) Add the metadata and data LVs allocated above to the RAID1 array
9) COMMIT THE METADATA to instantiate the array.
We must not build the RAID before clearing the metadata. That means not calling 'insert_layer_for_lv' before creating the other images. That means we must reserve the "lv_rimage_0" name to allow for proper names to be given by 'generate_lv_name' to the new images before using this reserved name in 'insert_layer_for_lv'.
There are three methods to solving this naming problem. They are:
1) Allow a name to be avoided by generate_lv_name. This is the method described above.
2) Reorder all the name pointers before committing the final metadata. This means the intermediate stage will have the wrong names for the data images and they will not match their metadata counterpart.
3) Create a dummy LV with the name "lv_rimage_0" for the sole purpose of reserving the name and deleting it before forming the RAID. This is essentially the same as #1, but doing it with existing functions and in a much more shitty way.
I'm willing to do #2 if I have to, but I'd prefer #1.
brassow
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/lvm-devel/attachments/20111006/e2f273a7/attachment.htm>