From a5bf70018bb25415585c8d027729eb0ec4f186f6 Mon Sep 17 00:00:00 2001 From: Dave Wysochanski Date: Wed, 30 Jun 2010 12:17:24 +0000 Subject: [PATCH] Add --metadataignore to pvcreate. Allow metadataignore flag to be passed in to pvcreate. Ideally, more refactoring of the mda allocation / initialization is warranted, but for now, we just add another parameter to 'add_mda' to take an existing mda ignored flag. We need to do this or pv_write loses the state of the mda 'ignored' flag before copying and writing to disk. --- lib/config/defaults.h | 1 + lib/format_text/format-text.c | 6 +++--- lib/format_text/format-text.h | 2 +- lib/format_text/text_label.c | 6 ++++-- lib/metadata/metadata-exported.h | 1 + lib/metadata/metadata.c | 9 +++++++++ tools/commands.h | 4 ++-- tools/toollib.c | 12 ++++++++++++ 8 files changed, 33 insertions(+), 8 deletions(-) diff --git a/lib/config/defaults.h b/lib/config/defaults.h index 0d8cb9c35..9f48d1903 100644 --- a/lib/config/defaults.h +++ b/lib/config/defaults.h @@ -59,6 +59,7 @@ #define DEFAULT_FORMAT "lvm2" #define DEFAULT_STRIPESIZE 64 /* KB */ +#define DEFAULT_PVMETADATAIGNORE 0 #define DEFAULT_PVMETADATASIZE 255 #define DEFAULT_PVMETADATACOPIES 1 #define DEFAULT_VGMETADATACOPIES 0 diff --git a/lib/format_text/format-text.c b/lib/format_text/format-text.c index c551dea4e..f2959bb0e 100644 --- a/lib/format_text/format-text.c +++ b/lib/format_text/format-text.c @@ -1337,7 +1337,7 @@ static int _mda_setup(const struct format_type *fmt, /* FIXME If creating new mdas, wipe them! */ if (mda_size1) { if (!add_mda(fmt, fmt->cmd->mem, mdas, pv->dev, start1, - mda_size1)) + mda_size1, 0)) return 0; if (!dev_set((struct device *) pv->dev, start1, @@ -1384,7 +1384,7 @@ static int _mda_setup(const struct format_type *fmt, if (mda_size2) { if (!add_mda(fmt, fmt->cmd->mem, mdas, pv->dev, start2, - mda_size2)) return 0; + mda_size2, 0)) return 0; if (!dev_set(pv->dev, start2, (size_t) (mda_size1 > wipe_size ? : mda_size1), 0)) { @@ -1440,7 +1440,7 @@ static int _text_pv_write(const struct format_type *fmt, struct physical_volume mdac->area.start >> SECTOR_SHIFT, mdac->area.size >> SECTOR_SHIFT); add_mda(fmt, NULL, &info->mdas, mdac->area.dev, - mdac->area.start, mdac->area.size); + mdac->area.start, mdac->area.size, mda_is_ignored(mda)); } /* FIXME Temporary until mda creation supported by tools */ } else if (!info->mdas.n) { diff --git a/lib/format_text/format-text.h b/lib/format_text/format-text.h index eaf1e835c..79365eaf8 100644 --- a/lib/format_text/format-text.h +++ b/lib/format_text/format-text.h @@ -56,7 +56,7 @@ int add_da(struct dm_pool *mem, struct dm_list *das, void del_das(struct dm_list *das); 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); + struct device *dev, uint64_t start, uint64_t size, unsigned ignored); void del_mdas(struct dm_list *mdas); #endif diff --git a/lib/format_text/text_label.c b/lib/format_text/text_label.c index 38866894d..b108cd38b 100644 --- a/lib/format_text/text_label.c +++ b/lib/format_text/text_label.c @@ -182,8 +182,9 @@ void del_das(struct dm_list *das) } } +/* FIXME: refactor this function with other mda constructor code */ 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) + struct device *dev, uint64_t start, uint64_t size, unsigned ignored) { /* FIXME List size restricted by pv_header SECTOR_SIZE */ struct metadata_area *mdal; @@ -222,6 +223,7 @@ int add_mda(const struct format_type *fmt, struct dm_pool *mem, struct dm_list * mdac->area.size = size; mdac->free_sectors = UINT64_C(0); memset(&mdac->rlocn, 0, sizeof(mdac->rlocn)); + mda_set_ignored(mdal, ignored); dm_list_add(mdas, &mdal->list); return 1; @@ -294,7 +296,7 @@ static int _text_read(struct labeller *l, struct device *dev, void *buf, dlocn_xl++; while ((offset = xlate64(dlocn_xl->offset))) { add_mda(info->fmt, NULL, &info->mdas, dev, offset, - xlate64(dlocn_xl->size)); + xlate64(dlocn_xl->size), 0); dlocn_xl++; } diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h index e4f91e4fd..89a0f6a41 100644 --- a/lib/metadata/metadata-exported.h +++ b/lib/metadata/metadata-exported.h @@ -453,6 +453,7 @@ struct pvcreate_params { const char *restorefile; /* 0 if no --restorefile option */ force_t force; unsigned yes; + unsigned mda_ignore; }; struct physical_volume *pvcreate_single(struct cmd_context *cmd, diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c index 2832a0035..361ed2a1f 100644 --- a/lib/metadata/metadata.c +++ b/lib/metadata/metadata.c @@ -1580,6 +1580,7 @@ void pvcreate_params_set_defaults(struct pvcreate_params *pp) pp->restorefile = 0; pp->force = PROMPT; pp->yes = 0; + pp->mda_ignore = DEFAULT_PVMETADATAIGNORE; } /* @@ -1602,6 +1603,7 @@ struct physical_volume * pvcreate_single(struct cmd_context *cmd, struct dm_list mdas; struct pvcreate_params default_pp; char buffer[64] __attribute((aligned(8))); + struct metadata_area *mda; pvcreate_params_set_defaults(&default_pp); if (!pp) @@ -1667,6 +1669,13 @@ struct physical_volume * pvcreate_single(struct cmd_context *cmd, log_very_verbose("Writing physical volume data to disk \"%s\"", pv_name); + + if (pp->mda_ignore) { + dm_list_iterate_items(mda, &mdas) { + mda_set_ignored(mda, 1); + } + } + if (!(pv_write(cmd, pv, &mdas, pp->labelsector))) { log_error("Failed to write physical volume \"%s\"", pv_name); goto error; diff --git a/tools/commands.h b/tools/commands.h index aa012a749..f88b54abe 100644 --- a/tools/commands.h +++ b/tools/commands.h @@ -517,8 +517,8 @@ xx(pvcreate, dataalignment_ARG, dataalignmentoffset_ARG, force_ARG, test_ARG, labelsector_ARG, metadatatype_ARG, metadatacopies_ARG, pvmetadatacopies_ARG, - metadatasize_ARG, physicalvolumesize_ARG, restorefile_ARG, uuidstr_ARG, - yes_ARG, zero_ARG) + metadatasize_ARG, metadataignore_ARG, physicalvolumesize_ARG, + restorefile_ARG, uuidstr_ARG, yes_ARG, zero_ARG) xx(pvdata, "Display the on-disk metadata for physical volume(s)", diff --git a/tools/toollib.c b/tools/toollib.c index e56a3e583..1ba8cdd84 100644 --- a/tools/toollib.c +++ b/tools/toollib.c @@ -1377,6 +1377,18 @@ int pvcreate_params_validate(struct cmd_context *cmd, return 0; } + if (arg_count(cmd, metadataignore_ARG)) { + pp->mda_ignore = !strcmp(arg_str_value(cmd, + metadataignore_ARG, + "n"), "y"); + } + if (arg_count(cmd, pvmetadatacopies_ARG) && + !arg_int_value(cmd, pvmetadatacopies_ARG, -1) && + pp->mda_ignore) { + log_error("metadataignore only applies to metadatacopies > 0"); + return 0; + } + if (arg_count(cmd, zero_ARG)) pp->zero = strcmp(arg_str_value(cmd, zero_ARG, "y"), "n");