LVM2 lib/format_text/format-text.c lib/metadat ...
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: prajnoha at sourceware.org 2011-02-21 12:27:26
Modified files:
lib/format_text: format-text.c
lib/metadata : metadata-exported.h metadata.h pv_manip.c
tools : pvresize.c
Log message:
Change pvresize code to work with new metadata handling interface and allow resizing a PV with two metadata areas.
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/format_text/format-text.c.diff?cvsroot=lvm2&r1=1.164&r2=1.165
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata-exported.h.diff?cvsroot=lvm2&r1=1.180&r2=1.181
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata.h.diff?cvsroot=lvm2&r1=1.238&r2=1.239
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/pv_manip.c.diff?cvsroot=lvm2&r1=1.25&r2=1.26
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/pvresize.c.diff?cvsroot=lvm2&r1=1.40&r2=1.41
lib/format_text/format-text.c +50 -0
@@ -2093,6 +2093,55 @@return remove_metadata_area_from_pv (pv, mda_index); } +static int _text_pv_resize (const struct format_type *fmt, +struct physical_volume *pv, +struct volume_group *vg, +uint64_t size) +{ +struct format_instance *fid = pv->fid; +const char *pvid = (const char *) &pv->id; +struct metadata_area *mda; +struct mda_context *mdac; +uint64_t size_reduction; +uint64_t mda_size; +unsigned mda_ignored; + +/* +* First, set the new size and update the cache and reset pe_count. +* (pe_count must be reset otherwise it would be considered as +* a limiting factor while moving the mda!) +*/ + pv->size = size; + pv->pe_count =0 ; + +/* If there's an mda at the end, move it to a new position. */ +if ((mda =fid_get_mda_indexed (fid, pvid,ID_LEN ,1 )) && + (mdac = mda->metadata_locn)) { +/* FIXME: Maybe MDA0 size would be better? */ + mda_size = mdac->area.size >>SECTOR_SHIFT ; + mda_ignored =mda_is_ignored (mda); + +if (!_text_pv_remove_metadata_area (fmt, pv,1 ) || + !_text_pv_add_metadata_area (fmt, pv,1 ,1 , mda_size, + mda_ignored)) { +log_error ("Failed to move metadata area with index 1 " +"while resizing PV %s." ,pv_dev_name (pv)); +return 0 ; + } + } + +/* If there's a VG, reduce size by counting in pe_start and metadata areas. */ +if (vg) { + size_reduction =pv_pe_start (pv); +if ((mda =fid_get_mda_indexed (fid, pvid,ID_LEN ,1 )) && + (mdac = mda->metadata_locn)) + size_reduction += mdac->area.size >>SECTOR_SHIFT ; + pv->size -= size_reduction; + } + +return 1 ; +} +/* NULL vgname means use only the supplied context e.g. an archive file */ static struct format_instance *_text_create_text_instance (const struct format_type *fmt,const struct format_instance_ctx *fic)
@@ -2170,6 +2219,7 @@ .pv_setup = _text_pv_setup, .pv_add_metadata_area = _text_pv_add_metadata_area, .pv_remove_metadata_area = _text_pv_remove_metadata_area, + .pv_resize = _text_pv_resize, .pv_write = _text_pv_write, .vg_setup = _text_vg_setup, .lv_setup = _text_lv_setup,
lib/metadata/metadata-exported.h +1 -1
@@ -428,7 +428,7 @@uint64_t pvmetadatasize, unsigned metadataignore);int pv_resize (struct physical_volume *pv,struct volume_group *vg, -uint32_t new_pe_count); +uint64_t size);int pv_analyze (struct cmd_context *cmd,const char *pv_name,uint64_t label_sector);
lib/metadata/metadata.h +8 -0
@@ -293,6 +293,14 @@ unsigned metadata_index);/* +* Recalculate the PV size taking into account any existing metadata areas. +*/ +int (*pv_resize) (const struct format_type *fmt, +struct physical_volume *pv, +struct volume_group *vg, +uint64_t size); + +/* * Write a PV structure to disk. Fails if the PV is in a VG ie * pv->vg_name must be a valid orphan VG name */
lib/metadata/pv_manip.c +55 -17
95 lines not on this page · raw message
tools/pvresize.c +3 -50
87 lines not on this page · raw message