Add interface to support adding and removing metadata areas on demand
cover Add interface to support adding and removing metadata areas on demand
This patchset provides a possibility to add new metadata areas on demand as well as removing them. Now, we can add a new metadata area independently of the PV initialisation so if there's a place we can even add metadata area additionally. The same applies for metadata removal functionality. This is only internal interface for now, but we should be able to provide external hooks in lvm2 commands if desired.
The patchset also tries to cleanup existing pv_setup/pv_write code. It also uses the new interface to allow resizing a PV with more copies of metadata areas on disk which was not allowed before because of missing metadata handling part in the interface.
(This patchset should be applicable to 4f2136c6545532afe149657f923fb982d2660415. There's still one thing that is failing which I need to inspect - it's lvm1 format handling and failing t-pv-create-usage.sh: "PV segment pe_count mismatch: 33 != 32". But anyway, here it is... I'll provide an update if I find anything.)
Peter Rajnoha (11):
Add mda_slots field for PV info in the cache.
Add pe_start_locked flag in struct physical_volume to retain
pe_start.
Add pv_add_metadata_area to format_handler interface. Add pv_remove_metadata_area to format_handler interface. Add pv_initialise to format_handler interface.
Refactor pv_setup to not include the initialisation only code. Remove unused _mda_setup.
Cleanup pv_write to use recent changes in metadata handling
interface.
Remove useless mdas parameter in code creating new PVs. Make existing lvmcache_update_pvid public.
Use new metadata interface to provide better support for PV resize.
lib/cache/lvmcache.c | 18 +- lib/cache/lvmcache.h | 3 + lib/format1/disk-rep.c | 7 + lib/format1/disk-rep.h | 1 + lib/format1/format1.c | 64 ++- lib/format1/format1.h | 1 + lib/format1/lvm1-label.c | 5 + lib/format_pool/disk_rep.c | 4 + lib/format_pool/disk_rep.h | 1 + lib/format_pool/format_pool.c | 22 +- lib/format_pool/format_pool.h | 1 + lib/format_text/archiver.c | 5 +- lib/format_text/format-text.c | 912 ++++++++++++++++++++++---------------- lib/format_text/format-text.h | 11 +- lib/format_text/text_label.c | 26 +- lib/metadata/metadata-exported.h | 12 +- lib/metadata/metadata.c | 80 ++-- lib/metadata/metadata.h | 49 ++- lib/metadata/pv.h | 1 + lib/metadata/pv_manip.c | 70 +++- tools/pvchange.c | 10 +- tools/pvresize.c | 57 +--- tools/vgconvert.c | 12 +- tools/vgreduce.c | 2 +- 24 files changed, 803 insertions(+), 571 deletions(-)
Signature · 1 line
1.7.3.2
PATCH 1/11 Add mda_slots field for PV info in the cache.
The code further needs to access the information about metadata areas directly quite often without checking the relative position to other metadata areas or data areas. IOW, we need to know directly whether there is any metadata area at the start of the disk or at the end of the disk or any other position we can think of in the future. This way, I know exactly which slots are free, which are occupied and I know the relative position to other metadata areas without checking any offsets etc.
Using the original list would be quite painful here - either I'd need to store the position somewhere or I'll just use this array which seems better. Though, the list itself is still there - this is something I'd like to discuss... (So I haven't tried to remove the mda_list completely yet).
--- lib/cache/lvmcache.c | 1 + lib/cache/lvmcache.h | 2 ++ 2 files changed, 3 insertions(+), 0 deletions(-)
lib/cache/lvmcache.c +1 -0
@@ -1357,6 +1357,7 @@ static void _lvmcache_destroy_entry(struct lvmcache_info *info)_vginfo_detach_info (info);strcpy (info->dev->pvid,"" );label_destroy (info->label); +dm_free (info->mda_slots);dm_free (info); }
lib/cache/lvmcache.h +2 -0
@@ -33,6 +33,7 @@struct cmd_context ;struct format_type ;struct volume_group ; +struct metadata_area ;/* One per VG */ struct lvmcache_vginfo {
@@ -53,6 +54,7 @@ struct lvmcache_vginfo {struct lvmcache_info {struct dm_list list;/* Join VG members together */ struct dm_list mdas;/* list head for metadata areas */ +void **mda_slots;/* Direct indexed access for metadata areas */ struct dm_list das;/* list head for data areas */ struct lvmcache_vginfo *vginfo;/* NULL == unknown */ struct label *label;
Signature · 1 line
1.7.3.2
PATCH 1/11 Add mda_slots field for PV info in the cache.
Dne 18.11.2010 22:32, Peter Rajnoha napsal(a):
Quoted 38 lines
The code further needs to access the information about metadata areas directly quite often without checking the relative position to other metadata areas or data areas. IOW, we need to know directly whether there is any metadata area at the start of the disk or at the end of the disk or any other position we can think of in the future. This way, I know exactly which slots are free, which are occupied and I know the relative position to other metadata areas without checking any offsets etc.
Using the original list would be quite painful here - either I'd need to store the position somewhere or I'll just use this array which seems better. Though, the list itself is still there - this is something I'd like to discuss... (So I haven't tried to remove the
mda_listcompletely yet).Signed-off-by Peter Rajnoha <[email protected]>--- lib/cache/lvmcache.c | 1 + lib/cache/lvmcache.h | 2 ++ 2 files changed, 3 insertions(+), 0 deletions(-)lib/cache/lvmcache.c +1
-0@@ -1357,6 +1357,7 @@ static void _lvmcache_destroy_entry(struct lvmcache_info *info)_vginfo_detach_info (info);strcpy (info->dev->pvid,"" );label_destroy (info->label); +dm_free (info->mda_slots);dm_free (info); }lib/cache/lvmcache.h +0
-0
lib/cache/lvmcache.h line 36
Quoted 4 lines
lib/cache/lvmcache.h +1
-0@@ -33,6 +33,7 @@struct cmd_context ;struct format_type ;struct volume_group ; +struct metadata_area ;
I'm not really sure where we are heading with out lvmcache.
I'd like to see rather complete removal of this part of code - once we will start work on thing like Petr's lvmetad - which would probably completely eliminate need of any cache.
I think we should keep our lvmcache as simple as we can only to skip repeated open & read from device - everything else should be kept in higher level. That could make future removal of this code much easier.
I guess we already break this concept in few place - but we should rather fix those areas instead of add more hardwired functionality into cache level.
Zdenek
PATCH 1/11 Add mda_slots field for PV info in the cache.
Quoted 1 line · Zdenek Kabelac
Quoted 1 line
+struct
metadata_area;
(ah, this line slipped from the older version of this patch, this line is not needed anymore at this place, but that's a detail...)
Quoted 6 lines
I'm not really sure where we are heading with out lvmcache.
I'd like to see rather complete removal of this part of code - once we will start work on thing like Petr's lvmetad - which would probably completely eliminate need of any cache.
Yes, that's a very good question - where are we heading with our cache? As I read the lvmetad concept, it seemed to me that the daemon will just replace the actual scanning phase and the code will ask the daemon to provide any info it has already cached instead of firing the scan. Otherwise, everything would stay as we have today (so the concept seems to be fine - to do as less surgery as possible). Which is not a bad idea - since all this existing cache machinery is quite a complex. So we need to do those changes in steps (iow, I don't think that removing the cache as it is today completely and replacing it with totally different scheme is something that we can do in a short time).
Quoted 5 lines
I think we should keep our lvmcache as simple as we can only to skip repeated open & read from device - everything else should be kept in higher level. That could make future removal of this code much easier.
What I've done here is that I used the cache to keep a few info that I need (and since I haven't seen any rules as to how the cache should be used :)), I sticked to that. Well, I just did the same what the older code did, but I moved the update of the cache a little bit sooner in time... That's all.
Of course, I can avoid using the cache this way, but that would mean far more changes to be done (for this interface to work). At least, it would mean consolidating the use of "format instance" and change the structure and its use throughout the code.
The logic of this patches would stay of course, what I need to decide (with respect to this patchset, not the cache itself) is where to store this information, how to 'package' the info and how to handle it internally so I can access it easily.
So we would have structures for the cached information that would be only read, not edited nor touched in any way. If there are any changes done, we throw away the cache completely and read it again from the raw disk - we need to state the policy clearly and follow it!
For now, I reused the cache structure. But sure, I can add something else so we can avoid using the cache this way (it's just about replacing the carrier
of the information). We would have a "working copy" of the cache. Though that would mean copying part of the information we already have in cache structures. This happens already for the internal "format_instance". Unluckily, this structure is not suitable for this patchset, so I would need to change it considerably, I think.
But yes, it could be done, but including far far more changes...
Quoted 2 lines
I guess we already break this concept in few place - but we should rather fix those areas instead of add more hardwired functionality into cache level.
As I said above, let's state the policy and the rules for the cache use and let's follow it ;)
Peter
PATCH 1/11 Add mda_slots field for PV info in the cache.
Quoted 4 lines · Peter Rajnoha
Of course, I can avoid using the cache this way, but that would mean far more changes to be done (for this interface to work). At least, it would mean consolidating the use of "format instance" and change the structure and its use throughout the code.
..I'd like to avoid making another copy of the cache. It's not about performance right now, but it's more about keeping the code readable - having N copies of the same structures around the code will bring confusion and bugs...
Peter
PATCH 2/11 Add pe_start_locked flag in struct physical_volume to retain pe_start.
In reply to Peter RajnohaNormally, pe_start value is changing throughout the calculation of the alignment and/or adding and removing metadata areas. But sometimes we really need to retain the old pe_start value, not trying to change it. When this flag is set, the code will try to fit new metadata areas within this limit and it will adjust the calculation so that the pe_start value is not changed at all if possible (so for example, we don't overwrite any existing data areas - a restore from backups etc.).
--- lib/format_text/format-text.c | 6 ++++-- lib/metadata/pv.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-)
lib/format_text/format-text.c +4 -2
@@ -1854,8 +1854,10 @@ static int _text_pv_setup(const struct format_type *fmt,/* FIXME Default from config file? vgextend cmdline flag? */ pv->status |=ALLOCATABLE_PV ; }else { -if (pe_start) +if (pe_start) { + pv->pe_start_locked =1 ; pv->pe_start = pe_start; + }if (!data_alignment) data_alignment = find_config_tree_int(pv->fmt->cmd,
@@ -1894,7 +1896,7 @@ static int _text_pv_setup(const struct format_type *fmt,* - Without this you get actual != expected pe_start * failures in the testsuite. */ -if (!pe_start && pv->pe_start < pv->pe_align) +if (!pv->pe_start_locked && pv->pe_start < pv->pe_align) pv->pe_start = pv->pe_align;if (extent_count)
lib/metadata/pv.h +1 -0
@@ -44,6 +44,7 @@ struct physical_volume {/* physical extents */ uint32_t pe_size;uint64_t pe_start; +int pe_start_locked;/* If set, try to retain the PE start value. */ uint32_t pe_count;uint32_t pe_alloc_count;unsigned long pe_align;
Signature · 1 line
1.7.3.2
PATCH 3/11 Add pv_add_metadata_area to format_handler interface.
In reply to Peter RajnohaThis provides a way to add new metadata area for a PV on demand. Adding any new metadata area will update the cache directly (just as it is in the situation while scanning and reading existing PVs). Why cache? Because when I add a new metadata area, I need to know about other metadata areas (together with any newly add metadata areas!) So I had two choices - either I copy the list of existing metadata areas to my own list and proceed with this one (adding/removing other mdas as needed) or I can use the cache directly (which we update anyway). Now, we update it a little bit earlier than we did before.
So there's a question probably - what is our cache policy?
- read info from disk, cache it, use it and if anything changes, throw the cache away immediately and read new info from the disk again,
- read info from disk, cache it, use it, modify it together with any modifications we're just doing, use the new cache later on, don't read from the disk again (unless really necessary),
- read info form disk, cache it, use it, modify it only at certain points where it is allowed.
The thing is that I really want to avoid making *another* copy of the mda_list. We already have one in the format_instance, one in the cache, of course... Another one just for mda add/remove interface? No. So if this cache modification is no-go, I'd lean to changing the format_instance itself so it could be used for this mda add/remove interface as well (but that would require much more changes, I think).
But here's the solution with the cache... It's doing its job so it's just about the question what's our policy when working with the cache.
--- lib/format_text/format-text.c | 249 +++++++++++++++++++++++++++++++++++++++++ lib/format_text/format-text.h | 7 + lib/metadata/metadata.h | 10 ++ 3 files changed, 266 insertions(+), 0 deletions(-)
lib/format_text/format-text.c +249 -0
@@ -1909,6 +1909,254 @@ static int _text_pv_setup(const struct format_type *fmt,return 1 ; } +int add_metadata_area_to_cache (struct lvmcache_info *info, +unsigned mda_index, +uint64_t mda_start, +uint64_t mda_size, +unsigned mda_ignored) +{ +struct metadata_area *mda; +struct mda_context *mdac; +struct mda_lists *mda_lists = (struct mda_lists *) info->fmt->private; + +if (mda_index >=FMT_TEXT_MAX_MDAS_PER_PV ) { +log_error (INTERNAL_ERROR "can't add metadata with index %u to" +"cache for PV %s. Metadata layout " +"not supported by %s format." , + mda_index,dev_name (info->dev), + info->fmt->name); + } + +if (!(mda =dm_malloc (sizeof (struct metadata_area )))) { +log_error ("struct metadata_area allocation failed" ); +return 0 ; + } + +if (!(mdac =dm_malloc (sizeof (struct mda_context )))) { +log_error ("struct mda_context allocation failed" ); +dm_free (mda); +return 0 ; + } + + mda->ops = mda_lists->raw_ops; + mda->metadata_locn = mdac; + mda->status =0 ; + + mdac->area.dev = info->dev; + mdac->area.start = mda_start; + mdac->area.size = mda_size; + mdac->free_sectors =UINT64_C (0 ); +memset (&mdac->rlocn,0 ,sizeof (mdac->rlocn)); +mda_set_ignored (mda, mda_ignored); + +dm_list_add (&info->mdas, &mda->list); + info->mda_slots[mda_index] = mda; + +return 1 ; +} + +static int _text_pv_add_metadata_area (const struct format_type *fmt, +struct physical_volume *pv, +unsigned mda_index, +uint64_t mda_size, +unsigned mda_ignored) +{ +uint64_t pe_start, pe_end; +uint64_t alignment, alignment_offset; +uint64_t disk_size; +uint64_t mda_start; +uint64_t adjustment, limit; +uint64_t wipe_size =8 <<SECTOR_SHIFT ; +size_t page_size =lvm_getpagesize (); +struct lvmcache_info *info; +struct metadata_area *mda; +struct mda_context *mdac; + +if (mda_index >=FMT_TEXT_MAX_MDAS_PER_PV ) { +log_error (INTERNAL_ERROR "invalid index of value %u used " +"while trying to add metadata area on PV %s. " +"Metadata layout not supported by %s format." , + mda_index,pv_dev_name (pv), fmt->name); +return 0 ; + } + + pe_start = pv->pe_start <<SECTOR_SHIFT ; + alignment = pv->pe_align <<SECTOR_SHIFT ; + alignment_offset = pv->pe_align_offset <<SECTOR_SHIFT ; + disk_size = pv->size <<SECTOR_SHIFT ; + mda_size = mda_size <<SECTOR_SHIFT ; + +if (!(info =info_from_pvid (pv->dev->pvid,0 ))) + return_0; + +if (info->mda_slots[mda_index]) { +log_error (INTERNAL_ERROR "metadata area with index %u already " +"exists on PV %s." , mda_index,pv_dev_name (pv)); +return 0 ; + } + +/* First metadata area at the start of the device. */ +if (mda_index ==0 ) { +/* +* Try to fit MDA0 end within given pe_start limit if its value +* is locked. If it's not locked, count with any existing MDA1. +* If there's no MDA1, just use disk size as the limit. +*/ +if (pv->pe_start_locked) + limit = pe_start; +else if ((mda = (struct metadata_area *) info->mda_slots[1 ]) && + (mdac = mda->metadata_locn)) + limit = mdac->area.start; +else + limit = disk_size; + +if (limit > disk_size) + goto bad; + + mda_start =LABEL_SCAN_SIZE ; + +/* Align MDA0 start with page size if possible. */ +if (limit - mda_start >=MDA_SIZE_MIN ) { +if ((adjustment = mda_start % page_size)) + mda_start += (page_size - adjustment); + } + +/* Align MDA0 end position with given alignment if possible. */ +if (alignment) { +if ((adjustment = (mda_start + mda_size) % alignment)) { + mda_size += (alignment - adjustment); +if (mda_start + mda_size > limit) + mda_size -= (alignment - adjustment); + } + } + +/* Align MDA0 end position with given alignment offset if possible. */ +if (alignment_offset && + (((mda_start + mda_size) % alignment) ==0 )) { + mda_size += alignment_offset; +if (mda_start + mda_size > limit) + mda_size -= alignment_offset; + } + +if (mda_start + mda_size > limit) { +log_warn ("WARNING: metadata area size outreaches " +"a limit on PV %s specified by its %s. " +"Trying to adjust metadata area size." , +pv_dev_name (pv), + pv->pe_start_locked ?"PE start" + :"disk size" ); + +/* +* Try to decrease the MDA0 size with twice the +* alignment and then align with given alignment. +* If pe_start is locked, skip this type of +* alignment since it would be useless. +* Check first whether we can apply that! +*/ +if (!pv->pe_start_locked && + ((limit - mda_start) > alignment *2 )) { + mda_size = limit - mda_start - alignment *2 ; + +if ((adjustment = (mda_start + mda_size) % alignment)) + mda_size += (alignment - adjustment); + +/* Still too much? Then there's nothing else to do. */ +if (mda_start + mda_size > limit) + goto bad; + } +/* Otherwise, give up and take any usable space. */ +/* FIXME: We should probably check for some minimum MDA size here. */ +else + mda_size = limit - mda_start; + } + +/* +* If PV's pe_start is not locked, update pe_start value with the +* start of the area that follows the MDA0 we've just calculated. +*/ +if (!pv->pe_start_locked) { + pe_start = mda_start + mda_size; + pv->pe_start = pe_start >>SECTOR_SHIFT ; + } + } +/* Second metadata area at the end of the device. */ +else { +/* +* Try to fit MDA1 start within given pe_end or pe_start limit +* if it's locked. If pe_start and pe_end are not defined yet, +* count with any existing MDA0 and pe_start. If MDA0 does not +* exist, just use LABEL_SCAN_SIZE. +*/ + pe_end = pv->pe_count ? (pv->pe_start + + pv->pe_count * pv->pe_size -1 ) <<SECTOR_SHIFT + :0 ; +if (pv->pe_start_locked) + limit = pe_end ? pe_end : pe_start; +else if (pe_start) + limit = pe_start; +/* +* Normally MDA0's start + size should be pe_start. +* The statemet here is probably useless since the +* situation is covered by previous statement. +*/ +else if ((mda = (struct metadata_area *) info->mda_slots[0 ]) && + (mdac = mda->metadata_locn)) + limit = mdac->area.start + mdac->area.size; +else + limit =LABEL_SCAN_SIZE ; + +if (limit > disk_size || mda_size > disk_size) + goto bad; + + mda_start = disk_size - mda_size; + +if (alignment) { + adjustment = mda_start % alignment; +if (adjustment) + mda_size += adjustment; + } + +/* FIXME: mda_size should be sanity-checked somewhere before. +* I'm not sure whether it really is --> !(mda_size > disk_size). */ +if (disk_size - mda_size < limit) + mda_size = disk_size - limit; + +/* +* If PV's pe_end not set yet, set it to the end of the +* area that precedes the MDA1 we've just calculated. +* FIXME: do we need to set this? Isn't it always set before? +*/ +/*if (!pe_end) { +pe_end = mda_start; +pv->pe_end = pe_end >> SECTOR_SHIFT; +}*/ + } + +if (mda_size) { +/* Wipe metadata area with zeroes. */ +if (!dev_set ((struct device *) pv->dev, mda_start, + (size_t ) (mda_size > wipe_size ? : mda_size),0 )) { +log_error ("Failed to wipe new metadata area " +"at the %s of the %s" , + mda_index ?"end" :"start" , +pv_dev_name (pv)); +return 0 ; + } + +/* Finally, add new metadata area to cache. */ +if (!add_metadata_area_to_cache (info, mda_index, + mda_start, mda_size, mda_ignored)) + return_0; + } + +return 1 ; + +bad: +log_error ("Not enough space available for metadata area " +"with index %u on PV %s." , mda_index,pv_dev_name (pv)); +return 0 ; +} +/* 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 char *vgname,
@@ -2049,6 +2297,7 @@ static struct format_handler _text_handler = { .scan = _text_scan, .pv_read = _text_pv_read, .pv_setup = _text_pv_setup, + .pv_add_metadata_area = _text_pv_add_metadata_area, .pv_write = _text_pv_write, .vg_setup = _text_vg_setup, .lv_setup = _text_lv_setup,
lib/format_text/format-text.h +7 -0
@@ -22,6 +22,7 @@#define FMT_TEXT_NAME "lvm2"#define FMT_TEXT_ALIAS "text"#define FMT_TEXT_ORPHAN_VG_NAME ORPHAN_VG_NAME(FMT_TEXT_NAME) +#define FMT_TEXT_MAX_MDAS_PER_PV 2/* * Archives a vg config. 'retain_days' is the minimum number of
@@ -55,6 +56,12 @@ int add_da(struct dm_pool *mem, struct dm_list *das, uint64_t start, uint64_t size);void del_das (struct dm_list *das); +int add_metadata_area_to_cache (struct lvmcache_info *info, +unsigned mda_index, +uint64_t mda_start, +uint64_t mda_size, +unsigned mda_ignored); +int add_mda (const struct format_type *fmt,struct dm_pool *mem,struct dm_list *mdas,struct device *dev,uint64_t start,uint64_t size,unsigned ignored);void del_mdas (struct dm_list *mdas);
lib/metadata/metadata.h +10 -0
@@ -23,6 +23,7 @@#include "ctype.h" #include "dev-cache.h" +#include "lvmcache.h" #include "lvm-string.h" #include "metadata-exported.h"
@@ -249,6 +250,15 @@ struct format_handler { struct physical_volume * pv, struct volume_group * vg);/* +* Add metadata area to a PV. Changes will take effect on pv_write. +*/ +int (*pv_add_metadata_area) (const struct format_type * fmt, +struct physical_volume * pv, +unsigned metadata_index, +uint64_t metadata_size, +unsigned metadata_ignored); + +/* * 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 */
Signature · 1 line
1.7.3.2
PATCH 4/11 Add pv_remove_metadata_area to format_handler interface.
In reply to Peter RajnohaThe same as for pv_add_metadata_area, but removing...
--- lib/format_text/format-text.c | 50 +++++++++++++++++++++++++++++++++++++++++ lib/format_text/format-text.h | 3 ++ lib/metadata/metadata.h | 7 +++++ 3 files changed, 60 insertions(+), 0 deletions(-)
lib/format_text/format-text.c +50 -0
@@ -2157,6 +2157,55 @@ bad:return 0 ; } +int remove_metadata_area_from_cache (struct lvmcache_info *info, +unsigned mda_index) +{ +struct metadata_area *mda; + +if (mda_index >=FMT_TEXT_MAX_MDAS_PER_PV ) { +log_error (INTERNAL_ERROR "can't remove metadata with index %u " +"from cache for PV %s. Metadata layout " +"not supported by %s format." , + mda_index,dev_name (info->dev), + info->fmt->name); +return 0 ; + } + + mda = info->mda_slots[mda_index]; + +dm_list_del (&mda->list); + info->mda_slots[mda_index] =NULL ; +dm_free (mda->metadata_locn); +dm_free (mda); + +return 1 ; +} + +static int _text_pv_remove_metadata_area (const struct format_type *fmt, +struct physical_volume *pv, +unsigned mda_index) +{ +struct lvmcache_info *info; + +if (mda_index >=FMT_TEXT_MAX_MDAS_PER_PV ) { +log_error (INTERNAL_ERROR "invalid index of value %u used " +"while trying to remove metadata area on PV %s. " +"Metadata layout not supported by %s format." , + mda_index,pv_dev_name (pv), fmt->name); +return 0 ; + } + +if (!(info =info_from_pvid (pv->dev->pvid,0 ))) + return_0; + +/* FIXME: Also wipe the mda area with zeroes? */ + +if (!remove_metadata_area_from_cache (info, mda_index)) + return_0; + +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 char *vgname,
@@ -2298,6 +2347,7 @@ static struct format_handler _text_handler = { .pv_read = _text_pv_read, .pv_setup = _text_pv_setup, .pv_add_metadata_area = _text_pv_add_metadata_area, + .pv_remove_metadata_area = _text_pv_remove_metadata_area, .pv_write = _text_pv_write, .vg_setup = _text_vg_setup, .lv_setup = _text_lv_setup,
lib/format_text/format-text.h +3 -0
@@ -62,6 +62,9 @@ int add_metadata_area_to_cache(struct lvmcache_info *info,uint64_t mda_size, unsigned mda_ignored); +int remove_metadata_area_from_cache (struct lvmcache_info *info, +unsigned mda_index); +int add_mda (const struct format_type *fmt,struct dm_pool *mem,struct dm_list *mdas,struct device *dev,uint64_t start,uint64_t size,unsigned ignored);void del_mdas (struct dm_list *mdas);
lib/metadata/metadata.h +7 -0
@@ -259,6 +259,13 @@ struct format_handler { unsigned metadata_ignored);/* +* Remove metadata area from a PV. Changes will take effect on pv_write. +*/ +int (*pv_remove_metadata_area) (const struct format_type *fmt, +struct physical_volume *pv, +unsigned metadata_index); + +/* * 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 */
Signature · 1 line
1.7.3.2
PATCH 4/11 Add pv_remove_metadata_area to format_handler interface.
Dne 18.11.2010 22:32, Peter Rajnoha napsal(a):
Quoted 18 lines
The same as for
pv_add_metadata_area, but removing...Signed-off-by Peter Rajnoha <[email protected]>--- lib/format_text/format-text.c | 50 +++++++++++++++++++++++++++++++++++++++++ lib/format_text/format-text.h | 3 ++ lib/metadata/metadata.h | 7 +++++ 3 files changed, 60 insertions(+), 0 deletions(-)lib/format_text/format-text.c +1
-0@@ -2157,6 +2157,55 @@ bad:return 0 ; } +int remove_metadata_area_from_cache(struct lvmcache_info *info,
lib/format_text/format-text.c bad: · line 2170
Quoted 10 lines
lib/format_text/format-text.c +10
-0+ unsigned mda_index) +{ +struct metadata_area *mda; + +if (mda_index >=FMT_TEXT_MAX_MDAS_PER_PV ) { +log_error (INTERNAL_ERROR "can't remove metadata with index %u " +"from cache for PV %s. Metadata layout " +"not supported by %s format." , + mda_index,dev_name (info->dev), + info->fmt->name);
align text on '(' - no reason to keep INTERNAL_ERROR as extra indent level.
Zdenek
PATCH 5/11 Add pv_initialise to format_handler interface.
In reply to Peter RajnohaThis is a split-off from the original pv_setup code, a simple refactor. It makes the code easier to read and cleans up the interface a bit. So now we will call pv_initialise when we only initialise a PV, creating a brand new PV.
This patch also adjusts the code reading a PV to fill the mda_slots with existing mdas so it's prepared for use in new mda add/removal interface. We allocate the mda_slots based on the value of the maximum allowed metadata areas for each format which is defined by FMT_<format>_MAX_MDAS_PER_PV.
--- lib/format1/disk-rep.c | 7 +++ lib/format1/disk-rep.h | 1 + lib/format1/format1.c | 57 +++++++++++++++++++++----- lib/format1/format1.h | 1 + lib/format1/lvm1-label.c | 5 ++ lib/format_pool/disk_rep.c | 4 ++ lib/format_pool/disk_rep.h | 1 + lib/format_pool/format_pool.c | 13 ++++++ lib/format_pool/format_pool.h | 1 + lib/format_text/format-text.c | 91 +++++++++++++++++++++++++++++++++++++++++ lib/format_text/format-text.h | 1 - lib/format_text/text_label.c | 26 +++++------- lib/metadata/metadata.c | 14 ++++++ lib/metadata/metadata.h | 13 ++++++ 14 files changed, 209 insertions(+), 26 deletions(-)
lib/format1/disk-rep.c +7 -0
@@ -337,6 +337,13 @@ static void __update_lvmcache(const struct format_type *fmt, info->device_size =xlate32 (dl->pvd.pv_size) <<SECTOR_SHIFT ;dm_list_init (&info->mdas); +if (info->mda_slots) +dm_free (info->mda_slots); +if (!(info->mda_slots =dm_zalloc (FMT_LVM1_MAX_MDAS_PER_PV *sizeof (struct metadata_area *)))) { +/* FIXME: Add revert of cache info! */ + stack; +return ; + } info->status &= ~CACHE_INVALID ; }
lib/format1/disk-rep.h +1 -0
@@ -18,6 +18,7 @@#include "lvm-types.h" #include "metadata.h" +#include "format1.h" #include "toolcontext.h" #define MAX_PV 256
lib/format1/format1.c +47 -10
79 lines not on this page · raw message
lib/format1/format1.h +1 -0
@@ -21,6 +21,7 @@#define FMT_LVM1_NAME "lvm1"#define FMT_LVM1_ORPHAN_VG_NAME ORPHAN_VG_NAME(FMT_LVM1_NAME) +#define FMT_LVM1_MAX_MDAS_PER_PV 1#ifdef LVM1_INTERNAL struct format_type *init_lvm1_format (struct cmd_context *cmd);
lib/format1/lvm1-label.c +5 -0
@@ -82,6 +82,11 @@ static int _lvm1_read(struct labeller *l, struct device *dev, void *buf, info->device_size =xlate32 (pvd->pv_size) <<SECTOR_SHIFT ;dm_list_init (&info->mdas); +if (!(info->mda_slots =dm_zalloc (FMT_LVM1_MAX_MDAS_PER_PV *sizeof (struct metadata_area *)))) { +/* FIXME: Add revert of cache info! */ +return 0 ; + } + info->status &= ~CACHE_INVALID ;return 1 ;
lib/format_pool/disk_rep.c +4 -0
@@ -105,6 +105,10 @@ int read_pool_label(struct pool_list *pl, struct labeller *l, info->device_size =xlate32_be (pd->pl_blocks) <<SECTOR_SHIFT ;dm_list_init (&info->mdas); +if (!(info->mda_slots =dm_zalloc (FMT_POOL_MAX_MDAS_PER_PV *sizeof (struct metadata_area *)))) { +/* FIXME: Add revert of cache info! */ +return 0 ; + } info->status &= ~CACHE_INVALID ;
lib/format_pool/disk_rep.h +1 -0
@@ -18,6 +18,7 @@#include "label.h" #include "metadata.h" +#include "format_pool.h" #define MINOR_OFFSET 65536
lib/format_pool/format_pool.c +13 -0
@@ -188,6 +188,18 @@ out:return NULL ; } +static int _pool_pv_initialise (const struct format_type *fmt __attribute__((unused)), +int64_t label_sector __attribute__((unused)), +uint64_t pe_start __attribute__((unused)), +uint32_t extent_count __attribute__((unused)), +uint32_t extent_size __attribute__((unused)), +unsigned long data_alignment __attribute__((unused)), +unsigned long data_alignment_offset __attribute__((unused)), +struct physical_volume *pv __attribute__((unused))) +{ +return 1 ; +} + static int _pool_pv_setup(const struct format_type *fmt __attribute__((unused)), uint64_t pe_start __attribute__((unused)), uint32_t extent_count __attribute__((unused)),
@@ -294,6 +306,7 @@ static void _pool_destroy(const struct format_type *fmt)/* *INDENT-OFF* */ static struct format_handler _format_pool_ops = { .pv_read = _pool_pv_read, + .pv_initialise = _pool_pv_initialise, .pv_setup = _pool_pv_setup, .create_instance = _pool_create_instance, .destroy_instance = _pool_destroy_instance,
lib/format_pool/format_pool.h +1 -0
@@ -20,6 +20,7 @@#define FMT_POOL_NAME "pool"#define FMT_POOL_ORPHAN_VG_NAME ORPHAN_VG_NAME(FMT_POOL_NAME) +#define FMT_POOL_MAX_MDAS_PER_PV 1#ifdef POOL_INTERNAL struct format_type *init_pool_format (struct cmd_context *cmd);
lib/format_text/format-text.c +91 -0
103 lines not on this page · raw message
lib/format_text/format-text.h +0 -1
@@ -67,6 +67,5 @@ int remove_metadata_area_from_cache(struct lvmcache_info *info,int add_mda (const struct format_type *fmt,struct dm_pool *mem,struct dm_list *mdas,struct device *dev,uint64_t start,uint64_t size,unsigned ignored); -void del_mdas (struct dm_list *mdas);#endif
lib/format_text/text_label.c +11 -15
@@ -229,19 +229,6 @@ int add_mda(const struct format_type *fmt, struct dm_pool *mem, struct dm_list *return 1 ; } -void del_mdas (struct dm_list *mdas) -{ -struct dm_list *mdah, *tmp; -struct metadata_area *mda; - - dm_list_iterate_safe(mdah, tmp, mdas) { - mda = dm_list_item(mdah, struct metadata_area); -dm_free (mda->metadata_locn); -dm_list_del (&mda->list); -dm_free (mda); - } -} -static int _text_initialise_label (struct labeller *l __attribute__((unused)),struct label *label) {
@@ -257,6 +244,7 @@ static int _text_read(struct labeller *l, struct device *dev, void *buf,struct pv_header *pvhdr;struct lvmcache_info *info;struct disk_locn *dlocn_xl; +unsigned dlocn_index =0 ;uint64_t offset;struct metadata_area *mda;struct id vgid;
@@ -284,6 +272,11 @@ static int _text_read(struct labeller *l, struct device *dev, void *buf,del_mdas (&info->mdas);dm_list_init (&info->mdas); +if (!(info->mda_slots =dm_zalloc (FMT_TEXT_MAX_MDAS_PER_PV *sizeof (struct metadata_area *)))) { +/* FIXME: Add revert of cache info! */ +return 0 ; + } +/* Data areas holding the PEs */ dlocn_xl = pvhdr->disk_areas_xl;while ((offset =xlate64 (dlocn_xl->offset))) {
@@ -295,9 +288,12 @@ static int _text_read(struct labeller *l, struct device *dev, void *buf,/* Metadata area headers */ dlocn_xl++;while ((offset =xlate64 (dlocn_xl->offset))) { -add_mda (info->fmt,NULL , &info->mdas, dev, offset, -xlate64 (dlocn_xl->size),0 ); +/* FIXME: Check order! We could possibly have mda at the end only! */ +/* E.g. check relative position to data area etc. */ +add_metadata_area_to_cache (info, dlocn_index, offset, +xlate64 (dlocn_xl->size),0 ); dlocn_xl++; + dlocn_index++; } dm_list_iterate_items(mda, &info->mdas) {
lib/metadata/metadata.c +14 -0
@@ -3855,6 +3855,20 @@ struct metadata_area *mda_copy(struct dm_pool *mem,return mda_new; } + +void del_mdas (struct dm_list *mdas) +{ +struct dm_list *mdah, *tmp; +struct metadata_area *mda; + + dm_list_iterate_safe(mdah, tmp, mdas) { + mda = dm_list_item(mdah, struct metadata_area); +dm_free (mda->metadata_locn); +dm_list_del (&mda->list); +dm_free (mda); + } +} +/* * This function provides a way to answer the question on a format specific * basis - does the format specfic context of these two metadata areas
lib/metadata/metadata.h +13 -0
@@ -187,6 +187,7 @@ struct metadata_area { };struct metadata_area *mda_copy (struct dm_pool *mem,struct metadata_area *mda); +void del_mdas (struct dm_list *mdas);unsigned mda_is_ignored (struct metadata_area *mda);void mda_set_ignored (struct metadata_area *mda,unsigned ignored);
@@ -238,6 +239,18 @@ struct format_handler { int scan_label_only);/* +* Initialise a new PV. +*/ +int (*pv_initialise) (const struct format_type * fmt, +int64_t label_sector, +uint64_t pe_start, +uint32_t extent_count, +uint32_t extent_size, +unsigned long data_alignment, +unsigned long data_alignment_offset, +struct physical_volume * pv); + +/* * Tweak an already filled out a pv ready for importing into a * vg. eg. pe_count is format specific. */
Signature · 1 line
1.7.3.2
PATCH 5/11 Add pv_initialise to format_handler interface.
Dne 18.11.2010 22:32, Peter Rajnoha napsal(a):
lib/format1/disk-rep.c static void __update_lvmcache(const struct format_type *fmt, · line 337
Quoted 6 lines
lib/format1/disk-rep.c +0
-0@@ -337,6 +337,13 @@ static void __update_lvmcache(const struct format_type *fmt,
Interesting - we should not use '__' as prefix in our code - though not directly related to our code.
lib/format1/disk-rep.c static void __update_lvmcache(const struct format_type *fmt, · line 345
Quoted 8 lines
lib/format1/disk-rep.c +6
-0info->device_size =xlate32 (dl->pvd.pv_size) <<SECTOR_SHIFT ;dm_list_init (&info->mdas); +if (info->mda_slots) +dm_free (info->mda_slots); +if (!(info->mda_slots =dm_zalloc (FMT_LVM1_MAX_MDAS_PER_PV *sizeof (struct metadata_area *)))) { +/* FIXME: Add revert of cache info! */ + stack; +return ;
This is yet another reason why we should not play with cache internally - we may introduce internal consistency problem and may get into the moment when our cache will represent different data than does we would read from disk.
lib/format1/disk-rep.c static void __update_lvmcache(const struct format_type *fmt, · line 348
Quoted 3 lines
lib/format1/disk-rep.c +3
-0+ +if (!(info->mda_slots =dm_zalloc (FMT_TEXT_MAX_MDAS_PER_PV *sizeof (struct metadata_area *)))) { +/* FIXME: Add revert of cache info! */
again quite important case...
lib/format1/disk-rep.c static void __update_lvmcache(const struct format_type *fmt,
Quoted 9 lines
lib/format1/disk-rep.c +6
-0+return 0 ; + } + +return 1 ; +} +static void _text_destroy_instance (struct format_instance *fid __attribute__((unused))) { }
Zdenek
PATCH 6/11 Refactor pv_setup to not include the initialisation only code.
In reply to Peter RajnohaWe'll use new pv_initialise to initialise a PV. For any other use where we need to recalculate the parameters for an existing PV that is part of a VG, we'll use pv_setup code.
Also, since we're using the cache now to hold any metadata changes, remove the mdas parameter from pv_setup/pv_write.
This patch also uses new pv_add_metadata_area interface when creating a new PV.
--- lib/format1/format1.c | 11 +-- lib/format_pool/format_pool.c | 9 -- lib/format_text/archiver.c | 5 +- lib/format_text/format-text.c | 219 ++++++++++++++++---------------------- lib/metadata/metadata-exported.h | 7 +- lib/metadata/metadata.c | 53 ++++----- lib/metadata/metadata.h | 8 +- tools/vgconvert.c | 6 +- 8 files changed, 127 insertions(+), 191 deletions(-)
lib/format1/format1.c +2 -9
@@ -424,15 +424,8 @@ static int _format1_pv_initialise(const struct format_type * fmt, }static int _format1_pv_setup (const struct format_type *fmt, -uint64_t pe_start,uint32_t extent_count, -uint32_t extent_size, -unsigned long data_alignment __attribute__((unused)), -unsigned long data_alignment_offset __attribute__((unused)), -int pvmetadatacopies __attribute__((unused)), -uint64_t pvmetadatasize __attribute__((unused)), -unsigned metadataignore __attribute__((unused)), -struct dm_list *mdas __attribute__((unused)), -struct physical_volume *pv,struct volume_group *vg __attribute__((unused))) +struct physical_volume *pv, +struct volume_group *vg __attribute__((unused))) {return _format1_pv_initialise (fmt,-1 ,0 ,0 , vg->extent_size,0 ,0 , pv); }
lib/format_pool/format_pool.c +0 -9
@@ -201,15 +201,6 @@ static int _pool_pv_initialise(const struct format_type *fmt __attribute__((unus }static int _pool_pv_setup (const struct format_type *fmt __attribute__((unused)), -uint64_t pe_start __attribute__((unused)), -uint32_t extent_count __attribute__((unused)), -uint32_t extent_size __attribute__((unused)), -unsigned long data_alignment __attribute__((unused)), -unsigned long data_alignment_offset __attribute__((unused)), -int pvmetadatacopies __attribute__((unused)), -uint64_t pvmetadatasize __attribute__((unused)), -unsigned metadataignore __attribute__((unused)), -struct dm_list *mdas __attribute__((unused)),struct physical_volume *pv __attribute__((unused)),struct volume_group *vg __attribute__((unused))) {
lib/format_text/archiver.c +1 -4
@@ -329,10 +329,7 @@ int backup_restore_vg(struct cmd_context *cmd, struct volume_group *vg) pv_dev_name(pv), info->fmt->name);return 0 ; } -if (!vg->fid->fmt->ops-> -pv_setup (vg->fid->fmt,UINT64_C (0 ),0 ,0 ,0 ,0 ,0UL , -UINT64_C (0 ),0 , - &vg->fid->metadata_areas_in_use, pv, vg)) { +if (!vg->fid->fmt->ops->pv_setup (vg->fid->fmt, pv, vg)) {log_error ("Format-specific setup for %s failed" ,pv_dev_name (pv));return 0 ;
lib/format_text/format-text.c +91 -128
244 lines not on this page · raw message
lib/metadata/metadata-exported.h +4 -3
@@ -398,9 +398,10 @@ struct physical_volume *pv_create(const struct cmd_context *cmd,uint64_t pe_start, uint32_t existing_extent_count, uint32_t existing_extent_size, - int pvmetadatacopies, uint64_t pvmetadatasize, - unsigned metadataignore, - struct dm_list *mdas); + uint64_t label_sector, + int pvmetadatacopies, + uint64_t pvmetadatasize, + unsigned metadataignore);int pv_resize (struct physical_volume *pv,struct volume_group *vg,uint32_t new_pe_count); int pv_analyze(struct cmd_context *cmd, const char *pv_name,
lib/metadata/metadata.c +23 -30
90 lines not on this page · raw message
lib/metadata/metadata.h +2 -6
@@ -255,12 +255,8 @@ struct format_handler {* vg. eg. pe_count is format specific. */ int (*pv_setup) (const struct format_type * fmt, -uint64_t pe_start,uint32_t extent_count, -uint32_t extent_size,unsigned long data_alignment, -unsigned long data_alignment_offset, -int pvmetadatacopies,uint64_t pvmetadatasize, -unsigned metadataignore,struct dm_list * mdas, -struct physical_volume * pv,struct volume_group * vg); +struct physical_volume * pv, +struct volume_group * vg);/* * Add metadata area to a PV. Changes will take effect on pv_write.
tools/vgconvert.c +4 -2
@@ -126,8 +126,10 @@ static int vgconvert_single(struct cmd_context *cmd, const char *vg_name,if (!(pv =pv_create (cmd,pv_dev (existing_pv), &existing_pv->id, size,0 ,0 , pe_start,pv_pe_count (existing_pv), -pv_pe_size (existing_pv), pvmetadatacopies, - pvmetadatasize,0 , &mdas))) { +pv_pe_size (existing_pv), +arg_int64_value (cmd, labelsector_ARG, +DEFAULT_LABELSECTOR ), + pvmetadatacopies, pvmetadatasize,0 ))) {log_error ("Failed to setup physical volume \"%s\"" ,pv_dev_name (existing_pv));if (change_made)
Signature · 1 line
1.7.3.2
PATCH 7/11 Remove unused _mda_setup.
In reply to Peter RajnohaThe functionality of former _mda_setup is now in new pv_add_metadata_area fn (though it's changed considerably).
--- lib/format_text/format-text.c | 153 ----------------------------------------- 1 files changed, 0 insertions(+), 153 deletions(-)
lib/format_text/format-text.c +0 -153
@@ -1246,159 +1246,6 @@ static int _text_scan(const struct format_type *fmt)return (_scan_file (fmt) &_scan_raw (fmt)); } -/* For orphan, creates new mdas according to policy. -Always have an mda between end-of-label and pe_align() boundary */ -static int _mda_setup (const struct format_type *fmt, -uint64_t pe_start,uint64_t pe_end, -int pvmetadatacopies,uint64_t pvmetadatasize, -unsigned metadataignore,struct dm_list *mdas, -struct physical_volume *pv, -struct volume_group *vg __attribute__((unused))) -{ -uint64_t mda_adjustment, disk_size, alignment, alignment_offset; -uint64_t start1, mda_size1;/* First area - start of disk */ -uint64_t start2, mda_size2;/* Second area - end of disk */ -uint64_t wipe_size =8 <<SECTOR_SHIFT ; -size_t pagesize =lvm_getpagesize (); - -if (!pvmetadatacopies) -return 1 ; - - alignment = pv->pe_align <<SECTOR_SHIFT ; - alignment_offset = pv->pe_align_offset <<SECTOR_SHIFT ; - disk_size = pv->size <<SECTOR_SHIFT ; - pe_start <<=SECTOR_SHIFT ; - pe_end <<=SECTOR_SHIFT ; - -if (pe_end > disk_size) { -log_error ("Physical extents end beyond end of device %s!" , -pv_dev_name (pv)); -return 0 ; - } - -/* Requested metadatasize */ - mda_size1 = pvmetadatasize <<SECTOR_SHIFT ; - -/* Place mda straight after label area@start of disk */ - start1 =LABEL_SCAN_SIZE ; - -/* Unless the space available is tiny, round to PAGE_SIZE boundary */ -if ((!pe_start && !pe_end) || - ((pe_start > start1) && (pe_start - start1 >=MDA_SIZE_MIN ))) { - mda_adjustment = start1 % pagesize; -if (mda_adjustment) - start1 += (pagesize - mda_adjustment); - } - -/* Round up to pe_align boundary */ - mda_adjustment = (mda_size1 + start1) % alignment; -if (mda_adjustment) { - mda_size1 += (alignment - mda_adjustment); -/* Revert if it's now too large */ -if (start1 + mda_size1 > disk_size) - mda_size1 -= (alignment - mda_adjustment); - } - -/* Add pe_align_offset if on pe_align boundary */ -if (alignment_offset && - (((start1 + mda_size1) % alignment) ==0 )) { - mda_size1 += alignment_offset; -/* Revert if it's now too large */ -if (start1 + mda_size1 > disk_size) - mda_size1 -= alignment_offset; - } - -/* Ensure it's not going to be bigger than the disk! */ -if (start1 + mda_size1 > disk_size) { -log_warn ("WARNING: metadata area fills disk leaving no " -"space for data on %s." ,pv_dev_name (pv)); -/* Leave some free space for rounding */ -/* Avoid empty data area as could cause tools problems */ - mda_size1 = disk_size - start1 - alignment *2 ; -if (start1 + mda_size1 > disk_size) { -log_error ("Insufficient space for first mda on %s" , -pv_dev_name (pv)); -return 0 ; - } -/* Round up to pe_align boundary */ - mda_adjustment = (mda_size1 + start1) % alignment; -if (mda_adjustment) - mda_size1 += (alignment - mda_adjustment); -/* Only have 1 mda in this case */ - pvmetadatacopies =1 ; - } - -/* If we already have PEs, avoid overlap */ -if (pe_start || pe_end) { -if (pe_start <= start1) - mda_size1 =0 ; -else if (start1 + mda_size1 > pe_start) - mda_size1 = pe_start - start1; - } - -/* FIXME If creating new mdas, wipe them! */ -if (mda_size1) { -if (!add_mda (fmt, fmt->cmd->mem, mdas, pv->dev, start1, - mda_size1, metadataignore)) -return 0 ; - -if (!dev_set ((struct device *) pv->dev, start1, - (size_t ) (mda_size1 > - wipe_size ? : mda_size1),0 )) { -log_error ("Failed to wipe new metadata area" ); -return 0 ; - } - -if (pvmetadatacopies ==1 ) -return 1 ; - }else - start1 =0 ; - -/* A second copy at end of disk */ - mda_size2 = pvmetadatasize <<SECTOR_SHIFT ; - -/* Ensure it's not going to be bigger than the disk! */ -if (mda_size2 > disk_size) - mda_size2 = disk_size - start1 - mda_size1; - - mda_adjustment = (disk_size - mda_size2) % alignment; -if (mda_adjustment) - mda_size2 += mda_adjustment; - - start2 = disk_size - mda_size2; - -/* If we already have PEs, avoid overlap */ -if (pe_start || pe_end) { -if (start2 < pe_end) { - mda_size2 -= (pe_end - start2); - start2 = pe_end; - } - } - -/* If we already have a first mda, avoid overlap */ -if (mda_size1) { -if (start2 < start1 + mda_size1) { - mda_size2 -= (start1 + mda_size1 - start2); - start2 = start1 + mda_size1; - } -/* No room for any PEs here now! */ - } - -if (mda_size2) { -if (!add_mda (fmt, fmt->cmd->mem, mdas, pv->dev, start2, - mda_size2, metadataignore))return 0 ; -if (!dev_set (pv->dev, start2, - (size_t ) (mda_size1 > - wipe_size ? : mda_size1),0 )) { -log_error ("Failed to wipe new metadata area" ); -return 0 ; - } - }else -return 0 ; - -return 1 ; -} -/* Only for orphans */ /* Set label_sector to -1 if rewriting existing label into same sector */ /* If mdas is supplied it overwrites existing mdas e.g. used with pvcreate */
Signature · 1 line
1.7.3.2
PATCH 8/11 Cleanup pv_write to use recent changes in metadata handling interface.
In reply to Peter RajnohaWell, pv_write is now quite short and clean when using all the changes and I hope (maybe 'pray' is a better word :)) I haven't removed anything important. Also, I hope that everything that should be calculated was calculated in the code before and eveything is in its place.
Please, double-check me, triple-check me, ... :)
--- lib/format1/format1.c | 14 +---- lib/format_text/format-text.c | 114 +------------------------------------ lib/metadata/metadata-exported.h | 3 +- lib/metadata/metadata.c | 11 ++-- lib/metadata/metadata.h | 3 +- tools/pvchange.c | 4 +- tools/pvresize.c | 2 +- tools/vgconvert.c | 4 +- tools/vgreduce.c | 2 +- 9 files changed, 17 insertions(+), 140 deletions(-)
lib/format1/format1.c +1 -13
@@ -451,23 +451,11 @@ static int _format1_lv_setup(struct format_instance *fid, struct logical_volumereturn 1 ; } -static int _format1_pv_write (const struct format_type *fmt,struct physical_volume *pv, -struct dm_list *mdas __attribute__((unused)),int64_t sector __attribute__((unused))) +static int _format1_pv_write (const struct format_type *fmt,struct physical_volume *pv) {struct dm_pool *mem;struct disk_list *dl;struct dm_list pvs; -struct label *label; -struct lvmcache_info *info; - -if (!(info =lvmcache_add (fmt->labeller, (char *) &pv->id, pv->dev, - pv->vg_name,NULL ,0 ))) - return_0; - label = info->label; - info->device_size = pv->size <<SECTOR_SHIFT ; - info->fmt = fmt; - -dm_list_init (&info->mdas);dm_list_init (&pvs);
lib/format_text/format-text.c +4 -110
140 lines not on this page · raw message
lib/metadata/metadata-exported.h +1 -2
@@ -359,8 +359,7 @@ struct dm_list *get_vgnames(struct cmd_context *cmd, int include_internal);struct dm_list *get_vgids (struct cmd_context *cmd,int include_internal);int scan_vgs_for_pvs (struct cmd_context *cmd); -int pv_write (struct cmd_context *cmd,struct physical_volume *pv, -struct dm_list *mdas,int64_t label_sector); +int pv_write (struct cmd_context *cmd,struct physical_volume *pv);int move_pv (struct volume_group *vg_from,struct volume_group *vg_to,const char *pv_name); int move_pvs_used_by_lv(struct volume_group *vg_from,
lib/metadata/metadata.c +5 -6
@@ -585,7 +585,7 @@ int vg_remove(struct volume_group *vg) }/* FIXME Write to same sector label was read from */ -if (!pv_write (vg->cmd, pv,NULL ,INT64_C (-1 ))) { +if (!pv_write (vg->cmd, pv)) {log_error ("Failed to remove physical volume \"%s\"" " from volume group \"%s\"" ,pv_dev_name (pv), vg->name);
@@ -1503,7 +1503,7 @@ struct physical_volume * pvcreate_single(struct cmd_context *cmd,log_very_verbose ("Writing physical volume data to disk \"%s\"" , pv_name); -if (!(pv_write (cmd, pv, &mdas, pp->labelsector))) { +if (!(pv_write (cmd, pv))) {log_error ("Failed to write physical volume \"%s\"" , pv_name); goto error; }
@@ -3403,8 +3403,7 @@ int scan_vgs_for_pvs(struct cmd_context *cmd) }int pv_write (struct cmd_context *cmd __attribute__((unused)), -struct physical_volume *pv, -struct dm_list *mdas,int64_t label_sector) +struct physical_volume *pv) {if (!pv->fmt->ops->pv_write) {log_error ("Format does not support writing physical volumes" );
@@ -3417,7 +3416,7 @@ int pv_write(struct cmd_context *cmd __attribute__((unused)),return 0 ; } -if (!pv->fmt->ops->pv_write (pv->fmt, pv, mdas, label_sector)) +if (!pv->fmt->ops->pv_write (pv->fmt, pv)) return_0;return 1 ;
@@ -3436,7 +3435,7 @@ int pv_write_orphan(struct cmd_context *cmd, struct physical_volume *pv)return 0 ; } -if (!pv_write (cmd, pv,NULL ,INT64_C (-1 ))) { +if (!pv_write (cmd, pv)) {log_error ("Failed to clear metadata from physical " "volume \"%s\" after removal from \"%s\"" ,pv_dev_name (pv), old_vg_name);
lib/metadata/metadata.h +1 -2
@@ -279,8 +279,7 @@ struct format_handler {* pv->vg_name must be a valid orphan VG name */ int (*pv_write) (const struct format_type * fmt, -struct physical_volume * pv,struct dm_list * mdas, -int64_t label_sector); +struct physical_volume * pv);/* * Tweak an already filled out a lv eg, check there
tools/pvchange.c +2 -2
@@ -160,7 +160,7 @@ static int _pvchange_single(struct cmd_context *cmd, struct volume_group *vg, pv->vg_name = pv->fmt->orphan_vg_name; pv->pe_alloc_count =0 ; -if (!(pv_write (cmd, pv,NULL ,INT64_C (-1 )))) { +if (!(pv_write (cmd, pv))) {log_error ("pv_write with new uuid failed " "for %s." , pv_name); goto out;
@@ -182,7 +182,7 @@ static int _pvchange_single(struct cmd_context *cmd, struct volume_group *vg, goto out; }backup (vg); - }else if (!(pv_write (cmd, pv,NULL ,INT64_C (-1 )))) { + }else if (!(pv_write (cmd, pv))) {log_error ("Failed to store physical volume \"%s\"" , pv_name); goto out;
tools/pvresize.c +1 -1
@@ -152,7 +152,7 @@ static int _pv_resize_single(struct cmd_context *cmd, goto out; }backup (vg); - }else if (!(pv_write (cmd, pv,NULL ,INT64_C (-1 )))) { + }else if (!(pv_write (cmd, pv))) {log_error ("Failed to store physical volume \"%s\"" , pv_name); goto out;
tools/vgconvert.c +1 -3
@@ -155,9 +155,7 @@ static int vgconvert_single(struct cmd_context *cmd, const char *vg_name,log_very_verbose ("Writing physical volume data to disk \"%s\"" ,pv_dev_name (pv)); -if (!(pv_write (cmd, pv, &mdas, -arg_int64_value (cmd, labelsector_ARG, -DEFAULT_LABELSECTOR )))) { +if (!(pv_write (cmd, pv))) {log_error ("Failed to write physical volume \"%s\"" ,pv_dev_name (pv)); log_error("Use pvcreate and vgcfgrestore to repair "
tools/vgreduce.c +1 -1
@@ -438,7 +438,7 @@ static int _vgreduce_single(struct cmd_context *cmd, struct volume_group *vg, goto bad; } -if (!pv_write (cmd, pv,NULL ,INT64_C (-1 ))) { +if (!pv_write (cmd, pv)) {log_error ("Failed to clear metadata from physical " "volume \"%s\" " "after removal from \"%s\"" , name, vg->name);
Signature · 1 line
1.7.3.2
PATCH 9/11 Remove useless mdas parameter in code creating new PVs.
In reply to Peter Rajnoha--- lib/metadata/metadata.c | 2 -- tools/vgconvert.c | 2 -- 2 files changed, 0 insertions(+), 4 deletions(-)
lib/metadata/metadata.c +0 -2
@@ -1434,7 +1434,6 @@ struct physical_volume * pvcreate_single(struct cmd_context *cmd, {struct physical_volume *pv;struct device *dev; -struct dm_list mdas;struct pvcreate_params default_pp; char buffer[64] __attribute__((aligned(8)));
@@ -1466,7 +1465,6 @@ struct physical_volume * pvcreate_single(struct cmd_context *cmd, goto error; } -dm_list_init (&mdas); if (!(pv = pv_create(cmd, dev, pp->idp, pp->size, pp->data_alignment, pp->data_alignment_offset, pp->pe_start, pp->extent_count, pp->extent_size,
tools/vgconvert.c +0 -2
@@ -23,7 +23,6 @@ static int vgconvert_single(struct cmd_context *cmd, const char *vg_name,struct logical_volume *lv;struct lv_list *lvl;uint64_t size =0 ; -struct dm_list mdas;int pvmetadatacopies =0 ;uint64_t pvmetadatasize =0 ;uint64_t pe_end =0 , pe_start =0 ;
@@ -122,7 +121,6 @@ static int vgconvert_single(struct cmd_context *cmd, const char *vg_name, pe_end =pv_pe_count (existing_pv) *pv_pe_size (existing_pv) + pe_start -1 ; -dm_list_init (&mdas); if (!(pv = pv_create(cmd, pv_dev(existing_pv), &existing_pv->id, size, 0, 0, pe_start, pv_pe_count(existing_pv),
Signature · 1 line
1.7.3.2
PATCH 10/11 Make existing lvmcache_update_pvid public.
In reply to Peter RajnohaWhen changing PV uuid (and the UUID which is important since the cache hash is based on its value), we need to update the cache. This is important for subsequent pv_write which tries to find the new PV with that new UUID in the cache...
--- lib/cache/lvmcache.c | 17 +++++++++++------ lib/cache/lvmcache.h | 1 + tools/pvchange.c | 6 ++++++ 3 files changed, 18 insertions(+), 6 deletions(-)
lib/cache/lvmcache.c +11 -6
@@ -872,19 +872,24 @@ void lvmcache_del(struct lvmcache_info *info)return; } */ -static int _lvmcache_update_pvid (struct lvmcache_info *info,const char *pvid) +int lvmcache_update_pvid (struct lvmcache_info *info,const char *pvid) { + char pvid_s[ID_LEN + 1] __attribute__((aligned(8))); + +strncpy (pvid_s, pvid,sizeof (pvid_s)); + pvid_s[sizeof (pvid_s) -1 ] ='\0' ; +/* * Nothing to do if already stored with same pvid. */ -if (((dm_hash_lookup (_pvid_hash, pvid)) == info) && +if (((dm_hash_lookup (_pvid_hash, pvid_s)) == info) && !strcmp (info->dev->pvid, pvid))return 1 ;if (*info->dev->pvid)dm_hash_remove (_pvid_hash, info->dev->pvid); -strncpy (info->dev->pvid, pvid,sizeof (info->dev->pvid)); -if (!dm_hash_insert (_pvid_hash, pvid, info)) { -log_error ("_lvmcache_update: pvid insertion failed: %s" , pvid); +strncpy (info->dev->pvid, pvid_s,sizeof (info->dev->pvid)); +if (!dm_hash_insert (_pvid_hash, pvid_s, info)) { +log_error ("_lvmcache_update: pvid insertion failed: %s" , pvid_s);return 0 ; }
@@ -1331,7 +1336,7 @@ struct lvmcache_info *lvmcache_add(struct labeller *labeller, const char *pvid, info->fmt = (const struct format_type *) labeller->private; info->status |=CACHE_INVALID ; -if (!_lvmcache_update_pvid (info, pvid_s)) { +if (!lvmcache_update_pvid (info, pvid_s)) {if (!existing) {dm_free (info);label_destroy (label);
lib/cache/lvmcache.h +1 -0
@@ -80,6 +80,7 @@ int lvmcache_add_orphan_vginfo(const char *vgname, struct format_type *fmt);void lvmcache_del (struct lvmcache_info *info);/* Update things */ +int lvmcache_update_pvid (struct lvmcache_info *info,const char *pvid);int lvmcache_update_vgname_and_id (struct lvmcache_info *info,const char *vgname,const char *vgid,uint32_t vgstatus,const char *hostname);
tools/pvchange.c +6 -0
@@ -21,6 +21,8 @@ static int _pvchange_single(struct cmd_context *cmd, struct volume_group *vg,struct physical_volume *pv, void *handle __attribute__((unused))) { +struct lvmcache_info *info; +uint32_t orig_pe_alloc_count;/* FIXME Next three only required for format1. */ uint32_t orig_pe_count, orig_pe_size;
@@ -141,6 +143,9 @@ static int _pvchange_single(struct cmd_context *cmd, struct volume_group *vg, goto out; }else {/* --uuid: Change PV ID randomly */ +if (!(info =info_from_pvid ((char *) &pv->id,0 ))) + goto_out; +if (!id_create (&pv->id)) {log_error ("Failed to generate new random UUID for %s." , pv_name);
@@ -149,6 +154,7 @@ static int _pvchange_single(struct cmd_context *cmd, struct volume_group *vg,if (!id_write_format (&pv->id, uuid,sizeof (uuid))) goto_out;log_verbose ("Changing uuid of %s to %s." , pv_name, uuid); +if (!(lvmcache_update_pvid (info, (char *) &pv->id)));if (!is_orphan (pv)) { orig_vg_name =pv_vg_name (pv); orig_pe_alloc_count =pv_pe_alloc_count (pv);
Signature · 1 line
1.7.3.2
PATCH 11/11 Use new metadata interface to provide better support for PV resize.
In reply to Peter Rajnoha(rhbz #477891)
Finally, we can achieve this! Now, it's simple - when resizing a PV which contains 2nd metadata area at the end of the disk, we'll just remove the mda, resize and add a new mda.
We also need a format-specific resize part of the code to be called so the format_handler interface now includes the pv_resize fn (metadata location is format-specific as well as the number of supported metadata area and the metadata layout itself).
The patch moves some parts of the PV resize code a bit to fit the changes better.
--- lib/format_text/format-text.c | 52 ++++++++++++++++++++++++++++ lib/metadata/metadata-exported.h | 2 +- lib/metadata/metadata.h | 8 ++++ lib/metadata/pv_manip.c | 70 +++++++++++++++++++++++++++++--------- tools/pvresize.c | 55 ++---------------------------- 5 files changed, 118 insertions(+), 69 deletions(-)
lib/format_text/format-text.c +52 -0
@@ -2000,6 +2000,57 @@ static int _text_pv_remove_metadata_area(const struct format_type *fmt,return 1 ; } +static int _text_pv_resize (const struct format_type *fmt, +struct physical_volume *pv, +struct volume_group *vg, +uint64_t size) +{ +struct lvmcache_info *info; +struct metadata_area *mda; +struct mda_context *mdac; +uint64_t size_reduction; +uint64_t mda_size; +unsigned mda_ignored; + +if (!(info =info_from_pvid (pv->dev->pvid,0 ))) + return_0; + +/* +* 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 ; + info->device_size = size <<SECTOR_SHIFT ; + +/* If there's an mda@the end, move it to a new position. */ +if ((mda = info->mda_slots[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 , 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 = info->mda_slots[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 char *vgname,
@@ -2143,6 +2194,7 @@ static struct format_handler _text_handler = { .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
@@ -402,7 +402,7 @@ struct physical_volume *pv_create(const struct cmd_context *cmd,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
@@ -275,6 +275,14 @@ struct format_handler { 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 +54 -16
94 lines not on this page · raw message
tools/pvresize.c +3 -52
92 lines not on this page · raw message
Signature · 1 line
1.7.3.2