: Add infrastructure for metadata balancing.
cover : Add infrastructure for metadata balancing.
This patchset is a second round of the metadata balancing support. It adds the infrastructure to set a bit inside the mda header on a per-PV basis, control it from pvchange, and display the number of mdas with this bit set on a particular PV or VG.
The disable/enable is implemented at the low level by taking advantage of the 'filler' field in the mda_header structure on disk. Normally this is written to 0, but I propose we change this 32-bit field to a 'flags' field and then define one flag that is a MDA disable. Much of the patchset deals with propagating the disable through the various LVM layers, and attempts to do this in a way that is true to the existing abstractions.
This code should now work for non-orphan PVs as well as orphans. Note that this patchset does not actually act on the bit to ignore mdas with the bit set. This should be fairly easy and will come in future patches.
Applies cleanly on upstream:
commit 5584f2ae4621b03dc890c6e1a9028eb8add259a1
Author: Jonathan Earl Brassow <[email protected]> Date: Wed Jan 27 22:28:05 2010 +0000
Was using dm_list_iterate_items when I should have been using *_safe. This had the effect of segfaulting the log daemon when converting a mirror from one log type to another.
PATCH 1/12 Add copy constructor for struct metadata_area.
Clean up cut&paste code with proper copy constructor.
--- lib/format_text/format-text.c | 74 ++++++++++++++++++++--------------------- 1 files changed, 36 insertions(+), 38 deletions(-)
lib/format_text/format-text.c +36 -38
@@ -1548,15 +1548,40 @@ static int _populate_pv_fields(struct lvmcache_info *info,return 1 ; } +/* +* Copy constructor for a metadata_area. +*/ +static struct metadata_area *_mda_copy (struct dm_pool *mem, +struct metadata_area *mda) +{ +struct metadata_area *mda_new; +struct mda_context *mdac, *mdac_new; + +if (!(mda_new =dm_pool_alloc (mem,sizeof (*mda_new)))) { +log_error ("metadata_area allocation failed" ); +return NULL ; + } +/* FIXME: this should be per-mda instance */ + mdac = (struct mda_context *) mda->metadata_locn; +if (!(mdac_new =dm_pool_alloc (mem,sizeof (*mdac_new)))) { +log_error ("metadata_area allocation failed" ); +return NULL ; + } +memcpy (mda_new, mda,sizeof (*mda)); +memcpy (mdac_new, mdac,sizeof (*mdac)); + mda_new->metadata_locn = mdac_new; +return mda_new; +} + +static int _text_pv_read (const struct format_type *fmt,const char *pv_name,struct physical_volume *pv,struct dm_list *mdas,int scan_label_only) { +struct metadata_area *mda, *mda_new;struct label *label;struct device *dev;struct lvmcache_info *info; -struct metadata_area *mda, *mda_new; -struct mda_context *mdac, *mdac_new;if (!(dev =dev_cache_get (pv_name, fmt->cmd->filter))) return_0;
@@ -1573,18 +1598,9 @@ static int _text_pv_read(const struct format_type *fmt, const char *pv_name,/* Add copy of mdas to supplied list */ dm_list_iterate_items(mda, &info->mdas) { - mdac = (struct mda_context *) mda->metadata_locn; -if (!(mda_new =dm_pool_alloc (fmt->cmd->mem,sizeof (*mda_new)))) { -log_error ("metadata_area allocation failed" ); -return 0 ; - } -if (!(mdac_new =dm_pool_alloc (fmt->cmd->mem,sizeof (*mdac_new)))) { -log_error ("metadata_area allocation failed" ); + mda_new =_mda_copy (fmt->cmd->mem, mda); +if (!mda_new)return 0 ; - } -memcpy (mda_new, mda,sizeof (*mda)); -memcpy (mdac_new, mdac,sizeof (*mdac)); - mda_new->metadata_locn = mdac_new;dm_list_add (mdas, &mda_new->list); }
@@ -1672,7 +1688,7 @@ static int _text_pv_setup(const struct format_type *fmt, struct physical_volume *pv, struct volume_group *vg) { struct metadata_area *mda, *mda_new, *mda2; -struct mda_context *mdac, *mdac_new, *mdac2; +struct mda_context *mdac, *mdac2;struct dm_list *pvmdas;struct lvmcache_info *info;int found;
@@ -1718,18 +1734,11 @@ static int _text_pv_setup(const struct format_type *fmt,if (found)continue ; -if (!(mda_new =dm_pool_alloc (fmt->cmd->mem, -sizeof (*mda_new)))) + mda_new =_mda_copy (fmt->cmd->mem, mda); +if (!mda_new) return_0; - -if (!(mdac_new =dm_pool_alloc (fmt->cmd->mem, -sizeof (*mdac_new)))) - return_0; -/* FIXME multiple dev_areas inside area */ -memcpy (mda_new, mda,sizeof (*mda)); -memcpy (mdac_new, mdac,sizeof (*mdac)); - mda_new->metadata_locn = mdac_new;dm_list_add (mdas, &mda_new->list); +/* FIXME multiple dev_areas inside area */ } }
@@ -1815,7 +1824,7 @@ static struct format_instance *_text_create_text_instance(const struct format_tystruct format_instance *fid;struct text_fid_context *fidtc;struct metadata_area *mda, *mda_new; -struct mda_context *mdac, *mdac_new; +struct mda_context *mdac;struct dir_list *dl;struct raw_list *rl;struct dm_list *dir_list, *raw_list, *mdas;
@@ -1892,21 +1901,10 @@ static struct format_instance *_text_create_text_instance(const struct format_ty dm_list_iterate_items(info, &vginfo->infos) { mdas = &info->mdas; dm_list_iterate_items(mda, mdas) { - mdac = - (struct mda_context *) mda->metadata_locn; -/* FIXME Check it holds this VG */ -if (!(mda_new =dm_pool_alloc (fmt->cmd->mem, -sizeof (*mda_new)))) - return_NULL; - -if (!(mdac_new =dm_pool_alloc (fmt->cmd->mem, -sizeof (*mdac_new)))) + mda_new =_mda_copy (fmt->cmd->mem, mda); +if (!mda_new) return_NULL; -/* FIXME multiple dev_areas inside area */ -memcpy (mda_new, mda,sizeof (*mda)); -memcpy (mdac_new, mdac,sizeof (*mdac)); - mda_new->metadata_locn = mdac_new;dm_list_add (&fid->metadata_areas, &mda_new->list); } }
Signature · 1 line
1.6.0.6
PATCH 2/12 Change 'filler' to 'flags' in on-disk 'raw_locn' structure.
Future patches will make use of a specific flag in the on-disk 'raw_locn' structure to enable/disable metadata areas, and facilitate metadata balancing.
Note that 'filler' is always set to '0' (see add_mda() - memset), so use of this area as a non-zero flags field is a safe way to provide future code features.
--- lib/format_text/layout.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
lib/format_text/layout.h +1 -1
@@ -51,7 +51,7 @@ struct raw_locn {uint64_t offset;/* Offset in bytes to start sector */ uint64_t size;/* Bytes */ uint32_t checksum; -uint32_t filler; +uint32_t flags; } __attribute__ ((packed));/* On disk */
Signature · 1 line
1.6.0.6
PATCH 3/12 Add text format specific 'rlocn' flag and access functions.
Adding a flag to the 'rlocn' structure in the mda header of the text format allows us to flip a bit to disable an mda via the text format specific mda_context structure. This patch defines the flag and access functions to manage the flag inside the mda_context structure. Other patches will manage the disable on a format-independent basis.
--- include/.symlinks.in | 1 + lib/format_text/format-text.c | 13 +++++++++++++ lib/format_text/format-text.h | 1 + lib/format_text/layout.h | 9 +++++++++ 4 files changed, 24 insertions(+), 0 deletions(-)
include/.symlinks.in +1 -0
@@ -26,6 +26,7 @@ @top_srcdir@/lib/format_text/format-text.h @top_srcdir@/lib/format_text/text_export.h @top_srcdir@/lib/format_text/text_import.h + at top_srcdir@/lib/format_text/layout.h @top_srcdir@/lib/label/label.h @top_srcdir@/lib/locking/locking.h @top_srcdir@/lib/log/log.h
lib/format_text/format-text.c +13 -0
@@ -66,6 +66,19 @@ struct text_context {char *desc;/* Description placed inside file */ }; +int mdac_is_disabled (const struct mda_context *mdac) +{ +return mdac->rlocn.flags &RAW_LOCN_FLAG_DISABLE ; +} + +void mdac_set_disabled (struct mda_context *mdac,int value) +{ +if (value) + mdac->rlocn.flags |=RAW_LOCN_FLAG_DISABLE ; +else + mdac->rlocn.flags &= ~RAW_LOCN_FLAG_DISABLE ; +} +/* * NOTE: Currently there can be only one vg per text file. */
lib/format_text/format-text.h +1 -0
@@ -17,6 +17,7 @@#define _LVM_FORMAT_TEXT_H#include "lvm-types.h" +#include "layout.h" #include "metadata.h" #define FMT_TEXT_NAME "lvm2"
lib/format_text/layout.h +9 -0
@@ -46,6 +46,13 @@ struct pv_header {struct disk_locn disk_areas_xl[0 ];/* Two lists */ } __attribute__ ((packed)); +/* +* Disable this raw location. This allows us to enable/disable +* metadata easily, and thus balance metadata across VGs with +* many PVs. +*/ +#define RAW_LOCN_FLAG_DISABLE 0x00000001 +/* On disk */ struct raw_locn {uint64_t offset;/* Offset in bytes to start sector */
@@ -78,6 +85,8 @@ struct mda_context {uint64_t free_sectors;struct raw_locn rlocn;/* Store inbetween write and commit */ }; +int mdac_is_disabled (const struct mda_context *mdac); +void mdac_set_disabled (struct mda_context *mdac,int value);/* FIXME Convert this at runtime */ #define FMTT_MAGIC "\040\114\126\115\062\040\170\133\065\101\045\162\060\116\052\076"
Signature · 1 line
1.6.0.6
PATCH 4/12 Add text format specific code to read and write 'rlocn' flags.
When we read the mda header, we read the rlocn and must save it in the mda_context structure to make sure we save the flags. Similarly, when writing out, make sure we copy the flags to be written to the new 'rlocn' flags area.
--- lib/format_text/format-text.c | 12 +++++++++++- lib/format_text/format-text.h | 1 + lib/format_text/text_label.c | 3 ++- 3 files changed, 14 insertions(+), 2 deletions(-)
lib/format_text/format-text.c +11 -1
@@ -687,6 +687,7 @@ static int _vg_commit_raw_rlocn(struct format_instance *fid, rlocn->offset = mdac->rlocn.offset; rlocn->size = mdac->rlocn.size; rlocn->checksum = mdac->rlocn.checksum; + rlocn->flags = mdac->rlocn.flags;log_debug ("%sCommitting %s metadata (%u) to %s header at %" PRIu64, precommit ?"Pre-" :"" , vg->name, vg->seqno,dev_name (mdac->area.dev), mdac->area.start);
@@ -777,6 +778,7 @@ static int _vg_remove_raw(struct format_instance *fid, struct volume_group *vg, rlocn->offset =0 ; rlocn->size =0 ; rlocn->checksum =0 ; + rlocn->flags =0 ;if (!_raw_write_mda_header (fid->fmt, mdac->area.dev, mdac->area.start, mdah)) {
@@ -1049,6 +1051,7 @@ static int _scan_file(const struct format_type *fmt) }const char *vgname_from_mda (const struct format_type *fmt, +struct mda_context *mdac,struct device_area *dev_area,struct id *vgid,uint64_t *vgstatus,char **creation_host,uint64_t *mda_free_sectors)
@@ -1074,6 +1077,11 @@ const char *vgname_from_mda(const struct format_type *fmt,/* FIXME Cope with returning a list */ rlocn = mdah->raw_locns; +/* Copy on-disk rlocn - needed to capture 'flags' field */ +if (mdac) + mdac->rlocn = *rlocn; +/* FIXME: Check for mda disable flag, and return here if set */ +/* * If no valid offset, do not try to search for vgname */
@@ -1168,7 +1176,8 @@ static int _scan_raw(const struct format_type *fmt) dm_list_iterate_items(rl, raw_list) {/* FIXME We're reading mdah twice here... */ -if ((vgname =vgname_from_mda (fmt, &rl->dev_area, &vgid, &vgstatus, +if ((vgname =vgname_from_mda (fmt,NULL , + &rl->dev_area, &vgid, &vgstatus,NULL ,NULL ))) {if ((vg =_vg_read_raw_area (&fid, vgname, &rl->dev_area,0 )))
@@ -1470,6 +1479,7 @@ static int _text_pv_write(const struct format_type *fmt, struct physical_volume mdac = mda->metadata_locn;memset (&buf,0 ,sizeof (buf)); mdah->size = mdac->area.size; + mdah->raw_locns[0 ].flags = mdac->rlocn.flags;if (!_raw_write_mda_header (fmt, mdac->area.dev, mdac->area.start, mdah)) {if (!dev_close (pv->dev))
lib/format_text/format-text.h +1 -0
@@ -61,6 +61,7 @@ int add_mda(const struct format_type *fmt, struct dm_pool *mem, struct dm_list *void del_mdas (struct dm_list *mdas);const char *vgname_from_mda (const struct format_type *fmt, +struct mda_context *mdac,struct device_area *dev_area,struct id *vgid,uint64_t *vgstatus,char **creation_host,uint64_t *mda_free_sectors);
lib/format_text/text_label.c +2 -1
@@ -298,7 +298,8 @@ static int _text_read(struct labeller *l, struct device *dev, void *buf, dm_list_iterate_items(mda, &info->mdas) { mdac = (struct mda_context *) mda->metadata_locn; - if ((vgname = vgname_from_mda(info->fmt, &mdac->area, + if ((vgname = vgname_from_mda(info->fmt, mdac, + &mdac->area, &vgid, &vgstatus, &creation_host, &mdac->free_sectors)) && !lvmcache_update_vgname_and_id(info, vgname,
Signature · 1 line
1.6.0.6
PATCH 5/12 Add flag and functions to disable mdas on a format independent basis.
First we add a 'flags' field to the format independent metadata_area structure, and a MDA_DISABLE flag. The mda_is_disabled and mda_set_disabled functions are added to manage the MDA_DISABLE flag. Adding the flag and functions gives a library interface to disable / enable metadata areas independent of the underlying format. The format-specific read/write functions must then handle any reading or writing of this flag to disk.
--- lib/format_text/text_label.c | 1 + lib/metadata/metadata.c | 13 +++++++++++++ lib/metadata/metadata.h | 6 ++++++ 3 files changed, 20 insertions(+), 0 deletions(-)
lib/format_text/text_label.c +1 -0
@@ -215,6 +215,7 @@ int add_mda(const struct format_type *fmt, struct dm_pool *mem, struct dm_list * mdal->ops = mda_lists->raw_ops; mdal->metadata_locn = mdac; + mdal->flags =0 ; mdac->area.dev = dev; mdac->area.start = start;
lib/metadata/metadata.c +13 -0
@@ -3626,6 +3626,19 @@ uint32_t pv_pe_alloc_count(const struct physical_volume *pv)return pv_field (pv, pe_alloc_count); } +int mda_is_disabled (struct metadata_area *mda) +{ +return (mda->flags &MDA_DISABLED ); +} + +void mda_set_disabled (struct metadata_area *mda,int value) +{ +if (value) + mda->flags |=MDA_DISABLED ; +else + mda->flags &= ~MDA_DISABLED ; +} +uint32_t pv_mda_count (const struct physical_volume *pv) {struct lvmcache_info *info;
lib/metadata/metadata.h +6 -0
@@ -158,12 +158,18 @@ struct metadata_area_ops { }; +#define MDA_DISABLED 0x00000001 +struct metadata_area {struct dm_list list;struct metadata_area_ops *ops;void *metadata_locn; +uint32_t flags; }; +int mda_is_disabled (struct metadata_area *mda); +void mda_set_disabled (struct metadata_area *mda,int value); +#define seg_pvseg (seg, s) (seg)->areas[(s)].u.pv.pvseg#define seg_dev (seg, s) (seg)->areas[(s)].u.pv.pvseg->pv->dev#define seg_pe (seg, s) (seg)->areas[(s)].u.pv.pvseg->pe
Signature · 1 line
1.6.0.6
PATCH 6/12 Make sure format independent mda disable matches format dependent.
After reading the label and peering into the text format to get the vgname and other things, we should set the format independent mda disable flag. Similarly, if we are writing the label, we must make sure the format independent flag sets/clears the format dependent flag.
--- lib/format_text/format-text.c | 2 ++ lib/format_text/text_label.c | 1 + 2 files changed, 3 insertions(+), 0 deletions(-)
lib/format_text/format-text.c +2 -0
@@ -557,6 +557,7 @@ static int _vg_write_raw(struct format_instance *fid, struct volume_group *vg, rlocn =_find_vg_rlocn (&mdac->area, mdah, vg->name, &noprecommit); mdac->rlocn.offset =_next_rlocn_offset (rlocn, mdah); +mdac_set_disabled (mdac,mda_is_disabled (mda)); if (!fidtc->raw_metadata_buf && !(fidtc->raw_metadata_buf_size =
@@ -1477,6 +1478,7 @@ static int _text_pv_write(const struct format_type *fmt, struct physical_volume dm_list_iterate_items(mda, &info->mdas) { mdac = mda->metadata_locn; +mdac_set_disabled (mdac,mda_is_disabled (mda));memset (&buf,0 ,sizeof (buf)); mdah->size = mdac->area.size; mdah->raw_locns[0 ].flags = mdac->rlocn.flags;
lib/format_text/text_label.c +1 -0
@@ -307,6 +307,7 @@ static int _text_read(struct labeller *l, struct device *dev, void *buf, (char *) &vgid, vgstatus, creation_host)) return_0; +mda_set_disabled (mda,mdac_is_disabled (mdac)); } info->status &= ~CACHE_INVALID ;
Signature · 1 line
1.6.0.6
PATCH 7/12 Add vg field to struct physical_volume and find_vg_by_pv().
Until now, the physical_volume struct contained only the vgname and vgid. However, this provides some difficulty when designing a proper API around pv handles and their properties. In particular, this patch is required if we want to enable/disable mdas for a particular PV with a nice PV-based interface.
For tools and operations such as pvchange, a clean API might look something like this:
pv = pv_open(pvname, mode);
value = pv_get_property(pv, propertyname);pv_set_property(pv, propertyname, newvalue);
The problem is today we have no way of really "opening" a PV for reading or writing, other than starting with a VG. This seems unduly restrictive to an application, since at times they may be starting with a device (pv) name and they may not know the vgname, nor do they really care if they are changing a device/pv property.
The possible pv_open() API above would implicitly call vg_read(), which would obtain the proper vg lock, and then return the pv handle. But then we'd have the problem of what happens to the vg handle obtained in the vg_read() call - do we leak it or store it somewhere? Thus, we introduce this small but important addition to struct physical_volume. Future patches will make use of this API to rework related areas of the code as well as enhance liblvm.
--- lib/format_text/import_vsn1.c | 1 + lib/metadata/metadata-exported.h | 2 ++ lib/metadata/metadata.c | 5 +++++ 3 files changed, 8 insertions(+), 0 deletions(-)
lib/format_text/import_vsn1.c +1 -0
@@ -268,6 +268,7 @@ static int _read_pv(struct format_instance *fid, struct dm_pool *mem, vg->pv_count++;dm_list_add (&vg->pvs, &pvl->list); + pv->vg = vg;return 1 ; }
lib/metadata/metadata-exported.h +2 -0
@@ -182,6 +182,7 @@ struct physical_volume {const struct format_type *fmt;const char *vg_name;struct id vgid; +struct volume_group *vg;uint64_t status;uint64_t size;
@@ -592,6 +593,7 @@ struct pv_list *find_pv_in_vg(const struct volume_group *vg, const char *pv_name);struct physical_volume *find_pv_in_vg_by_uuid (const struct volume_group *vg,const struct id *id); +struct volume_group *find_vg_by_pv (const struct physical_volume *pv);/* Find an LV within a given VG */ struct lv_list *find_lv_in_vg(const struct volume_group *vg,
lib/metadata/metadata.c +5 -0
@@ -1573,6 +1573,11 @@ static struct pv_list *_find_pv_in_vg(const struct volume_group *vg,return NULL ; } +struct volume_group *find_vg_by_pv (const struct physical_volume *pv) +{ +return pv->vg; +} +struct pv_list *find_pv_in_pv_list (const struct dm_list *pl,const struct physical_volume *pv) {
Signature · 1 line
1.6.0.6
PATCH 8/12 Add mda_locn_match() internal library function.
A metadata_area is defined independent of the location. One downside is that there is no obvious mapping from a pv to an mda. For a PV in a VG, we need a way to start with a PV and end up with an MDA, if we are to manage mdas. This function provides us a way to go down the list of PVs on a VG, and identify which ones match a particular PV.
I'm not entirely happy with this approach, but it does fit into the existing structures in a reasonable way.
A better solution might be to refactor the VG - PV interface such that mdas are a list tied to a PV. However, this seemed a bit tricky since a PV does not come into existence until after the list of mdas is constructed (see _vg_read() - we create a 'fid' and attach mdas to it, then we go through them and attach pvs).
--- lib/format_text/format-text.c | 15 +++++++++++++++ lib/metadata/metadata.c | 30 ++++++++++++++++++++++++++++++ lib/metadata/metadata.h | 7 +++++++ 3 files changed, 52 insertions(+), 0 deletions(-)
lib/format_text/format-text.c +15 -0
@@ -124,6 +124,20 @@ static int _mda_in_vg_raw(struct format_instance *fid __attribute((unused)),return 0 ; } +static int _mda_locn_match_raw (struct metadata_area *mda1, +struct metadata_area *mda2) +{ +struct mda_context *mda1c = (struct mda_context *) mda1->metadata_locn; +struct mda_context *mda2c = (struct mda_context *) mda2->metadata_locn; + +if ((mda1c->area.dev == mda2c->area.dev) && + (mda1c->area.start == mda2c->area.start) && + (mda1c->area.size == mda2c->area.size)) +return 1 ; + +return 0 ; +} +/* * For circular region between region_start and region_start + region_size, * back up one SECTOR_SIZE from 'region_ptr' and return the value.
@@ -1694,6 +1708,7 @@ static struct metadata_area_ops _metadata_text_raw_ops = { .mda_total_sectors = _mda_total_sectors_raw, .mda_in_vg = _mda_in_vg_raw, .pv_analyze_mda = _pv_analyze_mda_raw, + .mda_locn_match = _mda_locn_match_raw };/* pvmetadatasize in sectors */
lib/metadata/metadata.c +30 -0
@@ -3631,6 +3631,36 @@ uint32_t pv_pe_alloc_count(const struct physical_volume *pv)return pv_field (pv, pe_alloc_count); } +/* +* This function provides a way to answer the question on a format specific +* basis - does the format specfic context of these two metadata areas +* match? +* +* A metatdata_area is defined to be independent of the underlying context. +* This has the benefit that we can use the same abstraction to read disks +* (see _metadata_text_raw_ops) or files (see _metadata_text_file_ops). +* However, one downside is there is no format-independent way to determine +* whether a given metadata_area is attached to a specific device - in fact, +* it may not be attached to a device at all. +* +* Thus, LVM is structured such that an mda is not a member of struct +* physical_volume. The location of the mda depends on whether +* the PV is in a volume group. A PV not in a VG has an mda on the +* 'info->mda' list in lvmcache, while a PV in a VG has an mda on +* the vg->fid->metadata_areas list. For further details, see _vg_read(), +* and the sequence of creating the format_instance with fid->metadata_areas +* list, as well as the construction of the VG, with list of PVs (comes +* after the construction of the fid and list of mdas). +*/ +int mda_locn_match (struct metadata_area *mda1,struct metadata_area *mda2) +{ +if (!mda1->ops->mda_locn_match || !mda2->ops->mda_locn_match || + mda1->ops->mda_locn_match != mda2->ops->mda_locn_match) +return 0 ; + +return mda1->ops->mda_locn_match (mda1, mda2); +} +int mda_is_disabled (struct metadata_area *mda) {return (mda->flags &MDA_DISABLED );
lib/metadata/metadata.h +7 -0
@@ -156,6 +156,12 @@ struct metadata_area_ops {int (*pv_analyze_mda) (const struct format_type * fmt,struct metadata_area *mda); +/* +* Do these two metadata_areas match with respect to their underlying +* location? +*/ +int (*mda_locn_match)(struct metadata_area *mda1, +struct metadata_area *mda2); };#define MDA_DISABLED 0x00000001
@@ -169,6 +175,7 @@ struct metadata_area {int mda_is_disabled (struct metadata_area *mda);void mda_set_disabled (struct metadata_area *mda,int value); +int mda_locn_match (struct metadata_area *mda1,struct metadata_area *mda2);#define seg_pvseg (seg, s) (seg)->areas[(s)].u.pv.pvseg#define seg_dev (seg, s) (seg)->areas[(s)].u.pv.pvseg->pv->dev
Signature · 1 line
1.6.0.6
PATCH 9/12 Define new functions and vgs/pvs fields related to mda disable/enable.
Define a new pvs field, pv_mda_count_disabled, and a new vgs field, vg_mda_count_disabled to match the existing pv_mda_count and vg_mda_count. Also define various supporting functions to implement the counting as well as setting the disabled flag and determining if an mda is disabled. These high level functions call into the lower level format independent mda disable functions defined by earlier patches.
--- lib/metadata/metadata-exported.h | 4 ++ lib/metadata/metadata.c | 78 ++++++++++++++++++++++++++++++++++++++ lib/report/columns.h | 2 + lib/report/report.c | 25 ++++++++++++ 4 files changed, 109 insertions(+), 0 deletions(-)
lib/metadata/metadata-exported.h +4 -0
@@ -731,6 +731,9 @@ uint64_t pv_pe_start(const struct physical_volume *pv);uint32_t pv_pe_count (const struct physical_volume *pv);uint32_t pv_pe_alloc_count (const struct physical_volume *pv);uint32_t pv_mda_count (const struct physical_volume *pv); +uint32_t pv_mda_count_disabled (const struct physical_volume *pv); +uint32_t pv_mda_is_disabled (const struct physical_volume *pv); +void pv_mda_set_disabled (const struct physical_volume *pv,int value);uint64_t lv_size (const struct logical_volume *lv);
@@ -746,6 +749,7 @@ uint64_t vg_pv_count(const struct volume_group *vg);uint64_t vg_max_pv (const struct volume_group *vg);uint64_t vg_max_lv (const struct volume_group *vg);uint32_t vg_mda_count (const struct volume_group *vg); +uint32_t vg_mda_count_disabled (const struct volume_group *vg);int vg_check_write_mode (struct volume_group *vg);#define vg_is_clustered (vg) (vg_status((vg)) & CLUSTERED)#define vg_is_exported (vg) (vg_status((vg)) & EXPORTED_VG)
lib/metadata/metadata.c +78 -0
90 lines not on this page · raw message
lib/report/columns.h +2 -0
@@ -92,6 +92,7 @@ FIELD(PVS, pv, NUM, "PE", pe_count, 3, uint32, "pv_pe_count", "Total number of P FIELD(PVS, pv, NUM, "Alloc", pe_alloc_count, 5, uint32, "pv_pe_alloc_count", "Total number of allocated Physical Extents.") FIELD(PVS, pv, STR, "PV Tags", tags, 7, tags, "pv_tags", "Tags, if any.") FIELD(PVS, pv, NUM, "#PMda", id, 5, pvmdas, "pv_mda_count", "Number of metadata areas on this device.") +FIELD(PVS, pv, NUM, "#PMdaDis", id, 8, pvmdas_disabled, "pv_mda_count_disabled", "Number of metadata areas disabled on this device.") FIELD(VGS, vg, STR, "Fmt", cmd, 3, vgfmt, "vg_fmt", "Type of metadata.")FIELD (VGS , vg,STR ,"VG UUID" , id,38 , uuid,"vg_uuid" ,"Unique identifier." )
@@ -111,6 +112,7 @@ FIELD(VGS, vg, NUM, "#SN", cmd, 3, snapcount, "snap_count", "Number of snapshots FIELD(VGS, vg, NUM, "Seq", seqno, 3, uint32, "vg_seqno", "Revision number of internal metadata. Incremented whenever it changes.") FIELD(VGS, vg, STR, "VG Tags", tags, 7, tags, "vg_tags", "Tags, if any.") FIELD(VGS, vg, NUM, "#VMda", cmd, 5, vgmdas, "vg_mda_count", "Number of metadata areas in use by this VG.") +FIELD(VGS, vg, NUM, "#VMdaDis", cmd, 5, vgmdas_disabled, "vg_mda_count_disabled", "Number of metadata areas disabled in this VG.") FIELD(VGS, vg, NUM, "VMdaFree", cmd, 9, vgmdafree, "vg_mda_free", "Free metadata area space for this VG in current units.")FIELD (VGS , vg,NUM ,"VMdaSize" , cmd,9 , vgmdasize,"vg_mda_size" ,"Size of smallest metadata area for this VG in current units." )
lib/report/report.c +25 -0
@@ -861,6 +861,19 @@ static int _pvmdas_disp(struct dm_report *rh, struct dm_pool *mem,return _uint32_disp (rh, mem, field, &count, private); } +static int _pvmdas_disabled_disp (struct dm_report *rh,struct dm_pool *mem, +struct dm_report_field *field, +const void *data,void *private) +{ +uint32_t count; +const struct physical_volume *pv = + (const struct physical_volume *) data; + + count =pv_mda_count_disabled (pv); + +return _uint32_disp (rh, mem, field, &count, private); +} +static int _vgmdas_disp (struct dm_report *rh,struct dm_pool *mem,struct dm_report_field *field,const void *data,void *private)
@@ -873,6 +886,18 @@ static int _vgmdas_disp(struct dm_report *rh, struct dm_pool *mem,return _uint32_disp (rh, mem, field, &count, private); } +static int _vgmdas_disabled_disp (struct dm_report *rh,struct dm_pool *mem, +struct dm_report_field *field, +const void *data,void *private) +{ +const struct volume_group *vg = (const struct volume_group *) data; +uint32_t count; + + count =vg_mda_count_disabled (vg); + +return _uint32_disp (rh, mem, field, &count, private); +} +static int _pvmdafree_disp (struct dm_report *rh,struct dm_pool *mem,struct dm_report_field *field,const void *data,void *private)
Signature · 1 line
1.6.0.6
PATCH 10/12 Add --metadatadisable to pvchange, allowing for disabling of metadata areas.
This patch just modifies pvchange to call the underlying enable/disable functions for mdas.
--- tools/args.h | 1 + tools/commands.h | 3 ++- tools/pvchange.c | 28 +++++++++++++++++++++++++++- 3 files changed, 30 insertions(+), 2 deletions(-)
tools/args.h +1 -0
@@ -26,6 +26,7 @@ arg(nolocking_ARG, '\0', "nolocking", NULL, 0) arg(pvmetadatacopies_ARG, '\0', "pvmetadatacopies", int_arg, 0) arg(metadatacopies_ARG, '\0', "metadatacopies", int_arg, 0) arg(metadatasize_ARG, '\0', "metadatasize", size_mb_arg, 0) +arg(metadatadisable_ARG, '\0', "metadatadisable", yes_no_arg, 0) arg(restorefile_ARG, '\0', "restorefile", string_arg, 0) arg(labelsector_ARG, '\0', "labelsector", int_arg, 0)arg (driverloaded_ARG,'\0' ,"driverloaded" , yes_no_arg,0 )
tools/commands.h +2 -1
@@ -448,6 +448,7 @@ xx(pvchange,"\t[-t|--test]\n" "\t[-u|--uuid]\n" "\t[-x|--allocatable y|n]\n" +"\t[--metadatadisable y|n]\n" "\t[-v|--verbose]\n" "\t[--addtag Tag]\n" "\t[--deltag Tag]\n"
@@ -455,7 +456,7 @@ xx(pvchange, "\t[PhysicalVolumePath...]\n", all_ARG, allocatable_ARG, allocation_ARG, autobackup_ARG, deltag_ARG, - addtag_ARG, test_ARG, uuid_ARG) + addtag_ARG, metadatadisable_ARG, test_ARG, uuid_ARG) xx(pvresize, "Resize physical volume(s)",
tools/pvchange.c +27 -1
@@ -37,6 +37,7 @@ static int _pvchange_single(struct cmd_context *cmd, struct physical_volume *pv,int allocatable =0 ;int tagarg =0 ;int r =0 ; +int mda_disable =0 ;if (arg_count (cmd, addtag_ARG)) tagarg = addtag_ARG;
@@ -46,6 +47,9 @@ static int _pvchange_single(struct cmd_context *cmd, struct physical_volume *pv,if (arg_count (cmd, allocatable_ARG)) allocatable = !strcmp (arg_str_value (cmd, allocatable_ARG,"n" ),"y" ); +if (arg_count (cmd, metadatadisable_ARG)) + mda_disable = !strcmp (arg_str_value (cmd, metadatadisable_ARG,"n" ), +"y" );else if (tagarg && !(tag =arg_str_value (cmd, tagarg,NULL ))) {log_error ("Failed to get tag" );return 0 ;
@@ -149,6 +153,27 @@ static int _pvchange_single(struct cmd_context *cmd, struct physical_volume *pv, goto out; } } + }else if (arg_count (cmd, metadatadisable_ARG)) { +if (mda_disable &&pv_mda_is_disabled (pv)) { +log_error ("Physical volume \"%s\" mdas already " +"disabled" , pv_name); + r =1 ; + goto out; + } +if (!mda_disable && !pv_mda_is_disabled (pv)) { +log_error ("Physical volume \"%s\" mdas already " +"enabled" , pv_name); + r =1 ; + goto out; + } +if (mda_disable) { +log_verbose ("Setting physical volume \"%s\" " +"metadata disable" , pv_name); + }else { +log_verbose ("Setting physical volume \"%s\" NOT " +"metadata enable" , pv_name); + } +pv_mda_set_disabled (pv, mda_disable); }else {/* --uuid: Change PV ID randomly */ if (!id_create (&pv->id)) {
@@ -220,7 +245,8 @@ int pvchange(struct cmd_context *cmd, int argc, char **argv)struct dm_list mdas;if (arg_count (cmd, allocatable_ARG) +arg_count (cmd, addtag_ARG) + -arg_count (cmd, deltag_ARG) +arg_count (cmd, uuid_ARG) !=1 ) { +arg_count (cmd, deltag_ARG) +arg_count (cmd, uuid_ARG) + +arg_count (cmd, metadatadisable_ARG) !=1 ) {log_error ("Please give exactly one option of -x, -uuid, " "--addtag or --deltag" );return EINVALID_CMD_LINE ;
Signature · 1 line
1.6.0.6
PATCH 11/12 Update pvchange, pvs and vgs man pages for metadata disable.
Explain --metadatadisable argument to pvchange and new fields to pvs / vgs.
--- man/pvchange.8.in | 6 +++++- man/pvs.8.in | 3 ++- man/vgs.8.in | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-)
man/pvchange.8.in +5 -1
@@ -6,6 +6,7 @@ pvchange \- change attributes of a physical volume [\-\-addtag Tag] [\-A|\-\-autobackup y|n] [\-d|\-\-debug] [\-\-deltag Tag] +[\-\-metadatadisable y|n] [\-h|\-?|\-\-help] [\-t|\-\-test] [\-v|\-\-verbose] [\-a|\-\-all] [\-x|\-\-allocatable y|n]
@@ -25,10 +26,13 @@ Generate new random UUID for specified physical volumes. .TP .I \-x, \-\-allocatable y|n Enable or disable allocation of physical extents on this physical volume. +.TP +.I \-\-metadatadisable y|n +Disable or enable metadata areas on this physical volume. .SH Example "pvchange -x n /dev/sdk1" disallows the allocation of physical extents on this physical volume (possibly because of disk errors, or because it will be removed after freeing it. .SH SEE ALSO -.BR lvm (8), +.BR lvm (8), .BR pvcreate (8)
man/pvs.8.in +2 -1
@@ -54,7 +54,8 @@ Use \fb-o help\fP to view the full list of columns available. .IP Column names include: pv_fmt, pv_uuid, dev_size, pv_name, pv_mda_free, pv_mda_size, pe_start, pv_size, pv_free, pv_used, pv_attr, pv_pe_count, -pv_pe_alloc_count, pv_tags, pv_mda_count, pvseg_start, and pvseg_size. +pv_pe_alloc_count, pv_tags, pv_mda_count, pv_mda_count_disabled, +pvseg_start, and pvseg_size. .IP With --segments, any "pvseg_" prefixes are optional; otherwise any "pv_" prefixes are optional. Columns mentioned in \fBvgs (8)\fP can also
man/vgs.8.in +1 -1
@@ -49,7 +49,7 @@ Use \fb-o help\fP to view the full list of columns available. Column names include: vg_fmt, vg_uuid, vg_name, vg_attr, vg_size, vg_free, vg_sysid, vg_extent_size, vg_extent_count, vg_free_count, max_lv, max_pv, pv_count, lv_count, snap_count, vg_seqno, vg_tags, vg_mda_count, vg_mda_free, -and vg_mda_size. +and vg_mda_size, vg_mda_count_disabled. .IP Any "vg_" prefixes are optional. Columns mentioned in either \fBpvs (8)\fP or \fBlvs (8)\fP can also be chosen, but columns cannot be taken from both
Signature · 1 line
1.6.0.6
PATCH 12/12 Add tests for metadata balance - set/clear/display per-PV disable bit.
--- test/t-metadata-balance.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 41 insertions(+), 0 deletions(-) create mode 100755 test/t-metadata-balance.sh
test/t-metadata-balance.sh new file +41 -0
@@ -0,0 +1,41 @@ +# Copyright (C) 2008 Red Hat, Inc. All rights reserved. + +# This copyrighted material is made available to anyone wishing to use, +# modify, copy, or redistribute it subject to the terms and conditions +# of the GNU General Public License v.2. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +. ./test-utils.sh + +aux prepare_devs 5 + +# Make sure we can disable/enable mdas on a per-PV basis +for pv_in_vg in 1 0; do +for mdacp in 1 2; do + pvcreate --metadatacopies $mdacp $dev1 $dev2 + pvcreate --metadatacopies 0 $dev3 + if [ $pv_in_vg = 1 ]; then + vgcreate -c n "$vg" $dev1 $dev2 $dev3 + fi + pvchange --metadatadisable y $dev1 + check_pv_field_ $dev1 pv_mda_count $mdacp + check_pv_field_ $dev1 pv_mda_count_disabled $mdacp + check_pv_field_ $dev2 pv_mda_count $mdacp + check_pv_field_ $dev2 pv_mda_count_disabled 0 + if [ $pv_in_vg = 1 ]; then + check_vg_field_ $vg vg_mda_count $(($mdacp * 2)) + check_vg_field_ $vg vg_mda_count_disabled $mdacp + fi + pvchange --metadatadisable n $dev1 + check_pv_field_ $dev1 pv_mda_count $mdacp + check_pv_field_ $dev1 pv_mda_count_disabled 0 + if [ $pv_in_vg = 1 ]; then + check_vg_field_ $vg vg_mda_count $(($mdacp * 2)) + check_vg_field_ $vg vg_mda_count_disabled 0 + vgremove -f $vg + fi +done +done
Signature · 1 line
1.6.0.6