: RFC - Add infrastructure for metadata balancing.
cover : RFC - Add infrastructure for metadata balancing.
This patchset is a start towards metadata balancing by introducing --metadatadisable to pvchange as well as new fields to vgs and pvs to count the number of disabled mdas.
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.
This code works for orphan pvs but not yet for pvs in vgs (see FIXME in the code). I am somewhat undecided about possible refactorings in this regard.
Applies cleanly and tested on top of latest upstream:
commit 8e44e884a2b5430097c33641fd155fdf3ff4213c
Author: Alasdair Kergon <[email protected]> Date: Fri Jan 22 01:09:09 2010 +0000
post-release
PATCH 1/5 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 2/5 Add mda_is_disabled and mda_set_disabled to metadata_area_ops.
Implementing metadata balancing requires we have a way to enable/disable metadata areas, so we add these functions to metadata_area_ops.
--- include/.symlinks.in | 1 + lib/format_text/format-text.c | 42 +++++++++++++++++++++++++++++++++++++++- lib/format_text/format-text.h | 2 + lib/format_text/layout.h | 7 ++++++ lib/format_text/text_label.c | 4 ++- lib/metadata/metadata.h | 2 + 6 files changed, 55 insertions(+), 3 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 +40 -2
84 lines not on this page · raw message
lib/format_text/format-text.h +2 -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"
@@ -60,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/layout.h +7 -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 */
lib/format_text/text_label.c +3 -1
@@ -291,6 +291,7 @@ static int _text_read(struct labeller *l, struct device *dev, void *buf,/* Metadata area headers */ dlocn_xl++;while ((offset =xlate64 (dlocn_xl->offset))) { +/* NOTE: mda header not read from disk until later */ add_mda (info->fmt,NULL , &info->mdas, dev, offset,xlate64 (dlocn_xl->size)); dlocn_xl++;
@@ -298,7 +299,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,
lib/metadata/metadata.h +2 -0
@@ -156,6 +156,8 @@ struct metadata_area_ops {int (*pv_analyze_mda) (const struct format_type * fmt,struct metadata_area *mda); +int (*mda_is_disabled) (const struct metadata_area *mda); +void (*mda_set_disabled) (const struct metadata_area *mda,int value); };struct metadata_area {
Signature · 1 line
1.6.0.6
PATCH 3/5 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.
--- lib/metadata/metadata-exported.h | 4 +++ lib/metadata/metadata.c | 54 ++++++++++++++++++++++++++++++++++++++ lib/report/columns.h | 2 + lib/report/report.c | 25 +++++++++++++++++ 4 files changed, 85 insertions(+), 0 deletions(-)
lib/metadata/metadata-exported.h +4 -0
@@ -729,6 +729,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);
@@ -744,6 +747,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 +54 -0
66 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 4/5 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 5/5 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