From c29d24650dfb303e1e314f43095a907e0cdad498 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Sat, 19 Jun 2004 19:27:00 +0000 Subject: [PATCH] Display all filtered devices, not just PVs, with pvs -a. --- WHATS_NEW | 1 + lib/metadata/metadata.c | 13 +++++++----- lib/metadata/metadata.h | 3 ++- lib/report/report.c | 12 ++++++++++- tools/commands.h | 7 ++++--- tools/pvchange.c | 9 ++++----- tools/pvcreate.c | 2 +- tools/pvremove.c | 2 +- tools/reporter.c | 22 +++++++++++--------- tools/toollib.c | 45 ++++++++++++++++++++++++++++++++++++++++- 10 files changed, 89 insertions(+), 27 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index 5b5b08893..0a5aa1283 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.00.17 - ============================= + Display all filtered devices, not just PVs, with pvs -a. Fix sync_dir() when no / in filename vgcfgbackup -f accepts template with %s for VG name. Extend hash functions to handle non-null-terminated data. diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c index 2f7175ecf..75464b12d 100644 --- a/lib/metadata/metadata.c +++ b/lib/metadata/metadata.c @@ -39,7 +39,7 @@ static int _add_pv_to_vg(struct format_instance *fid, struct volume_group *vg, } list_init(&mdas); - if (!(pv = pv_read(fid->fmt->cmd, pv_name, &mdas, NULL))) { + if (!(pv = pv_read(fid->fmt->cmd, pv_name, &mdas, NULL, 1))) { log_error("%s not identified as an existing physical volume", pv_name); return 0; @@ -426,7 +426,7 @@ struct physical_volume *find_pv_by_name(struct cmd_context *cmd, { struct physical_volume *pv; - if (!(pv = pv_read(cmd, pv_name, NULL, NULL))) { + if (!(pv = pv_read(cmd, pv_name, NULL, NULL, 1))) { log_error("Physical volume %s not found", pv_name); return NULL; } @@ -605,7 +605,7 @@ static struct volume_group *_vg_read_orphans(struct cmd_context *cmd) list_iterate(ih, &vginfo->infos) { dev = list_item(ih, struct lvmcache_info)->dev; - if (!(pv = pv_read(cmd, dev_name(dev), NULL, NULL))) { + if (!(pv = pv_read(cmd, dev_name(dev), NULL, NULL, 1))) { continue; } if (!(pvl = pool_zalloc(cmd->mem, sizeof(*pvl)))) { @@ -814,7 +814,8 @@ struct logical_volume *lv_from_lvid(struct cmd_context *cmd, const char *lvid_s) /* FIXME Use label functions instead of PV functions */ struct physical_volume *pv_read(struct cmd_context *cmd, const char *pv_name, - struct list *mdas, uint64_t *label_sector) + struct list *mdas, uint64_t *label_sector, + int warnings) { struct physical_volume *pv; struct label *label; @@ -827,7 +828,9 @@ struct physical_volume *pv_read(struct cmd_context *cmd, const char *pv_name, } if (!(label_read(dev, &label))) { - log_error("No physical volume label read from %s", pv_name); + if (warnings) + log_error("No physical volume label read from %s", + pv_name); return 0; } diff --git a/lib/metadata/metadata.h b/lib/metadata/metadata.h index 0fb27c9c3..3d57c6398 100644 --- a/lib/metadata/metadata.h +++ b/lib/metadata/metadata.h @@ -369,7 +369,8 @@ struct volume_group *vg_read(struct cmd_context *cmd, const char *vg_name, int *consistent); struct volume_group *vg_read_by_vgid(struct cmd_context *cmd, const char *vgid); struct physical_volume *pv_read(struct cmd_context *cmd, const char *pv_name, - struct list *mdas, uint64_t *label_sector); + struct list *mdas, uint64_t *label_sector, + int warnings); struct list *get_pvs(struct cmd_context *cmd); /* Set full_scan to 1 to re-read every (filtered) device label */ diff --git a/lib/report/report.c b/lib/report/report.c index edf319569..5db54db03 100644 --- a/lib/report/report.c +++ b/lib/report/report.c @@ -1063,6 +1063,7 @@ int report_object(void *handle, struct volume_group *vg, struct row *row; struct field *field; void *data = NULL; + int skip; if (lv && pv) { log_error("report_object: One of *lv and *pv must be NULL!"); @@ -1090,6 +1091,8 @@ int report_object(void *handle, struct volume_group *vg, list_iterate(fh, &rh->field_props) { fp = list_item(fh, struct field_properties); + skip = 0; + if (!(field = pool_zalloc(rh->mem, sizeof(*field)))) { log_error("struct field allocation failed"); return 0; @@ -1101,6 +1104,10 @@ int report_object(void *handle, struct volume_group *vg, data = (void *) lv + _fields[fp->field_num].offset; break; case VGS: + if (!vg) { + skip = 1; + break; + } data = (void *) vg + _fields[fp->field_num].offset; break; case PVS: @@ -1110,7 +1117,10 @@ int report_object(void *handle, struct volume_group *vg, data = (void *) seg + _fields[fp->field_num].offset; } - if (!_fields[fp->field_num].report_fn(rh, field, data)) { + if (skip) { + field->report_string = ""; + field->sort_value = (const void *) field->report_string; + } else if (!_fields[fp->field_num].report_fn(rh, field, data)) { log_error("report function failed for field %s", _fields[fp->field_num].id); return 0; diff --git a/tools/commands.h b/tools/commands.h index 980034207..140c34651 100644 --- a/tools/commands.h +++ b/tools/commands.h @@ -479,6 +479,7 @@ xx(pvs, "Display information about physical volumes", "pvs" "\n" "\t[--aligned]\n" + "\t[-a|--all]\n" "\t[-d|--debug]" "\n" "\t[-h|-?|--help] " "\n" "\t[--noheadings]\n" @@ -493,9 +494,9 @@ xx(pvs, "\t[--version]\n" "\t[PhysicalVolume [PhysicalVolume...]]\n", - aligned_ARG, ignorelockingfailure_ARG, noheadings_ARG, nolocking_ARG, - nosuffix_ARG, options_ARG, separator_ARG, sort_ARG, unbuffered_ARG, - units_ARG) + aligned_ARG, all_ARG, ignorelockingfailure_ARG, noheadings_ARG, + nolocking_ARG, nosuffix_ARG, options_ARG, separator_ARG, sort_ARG, + unbuffered_ARG, units_ARG) xx(pvscan, "List all physical volumes", diff --git a/tools/pvchange.c b/tools/pvchange.c index 1056300f5..71b9992be 100644 --- a/tools/pvchange.c +++ b/tools/pvchange.c @@ -107,7 +107,7 @@ static int _pvchange_single(struct cmd_context *cmd, struct physical_volume *pv, return 0; } - if (!(pv = pv_read(cmd, pv_name, &mdas, §or))) { + if (!(pv = pv_read(cmd, pv_name, &mdas, §or, 1))) { unlock_vg(cmd, ORPHAN); log_error("Unable to read PV \"%s\"", pv_name); return 0; @@ -236,10 +236,9 @@ int pvchange(struct cmd_context *cmd, int argc, char **argv) for (; opt < argc; opt++) { pv_name = argv[opt]; /* FIXME Read VG instead - pv_read will fail */ - if (!(pv = pv_read(cmd, pv_name, &mdas, NULL))) { - log_error - ("Failed to read physical volume \"%s\"", - pv_name); + if (!(pv = pv_read(cmd, pv_name, &mdas, NULL, 1))) { + log_error("Failed to read physical volume %s", + pv_name); continue; } total++; diff --git a/tools/pvcreate.c b/tools/pvcreate.c index a2ea2df67..162faaed8 100644 --- a/tools/pvcreate.c +++ b/tools/pvcreate.c @@ -35,7 +35,7 @@ static int pvcreate_check(struct cmd_context *cmd, const char *name) /* is there a pv here already */ /* FIXME Use partial mode here? */ - if (!(pv = pv_read(cmd, name, NULL, NULL))) + if (!(pv = pv_read(cmd, name, NULL, NULL, 0))) return 1; /* orphan ? */ diff --git a/tools/pvremove.c b/tools/pvremove.c index f5d675e9c..4ca855034 100644 --- a/tools/pvremove.c +++ b/tools/pvremove.c @@ -34,7 +34,7 @@ static int pvremove_check(struct cmd_context *cmd, const char *name) } /* is there a pv here already */ - if (!(pv = pv_read(cmd, name, NULL, NULL))) + if (!(pv = pv_read(cmd, name, NULL, NULL, 1))) return 1; /* orphan ? */ diff --git a/tools/reporter.c b/tools/reporter.c index e45574baf..bbf002b84 100644 --- a/tools/reporter.c +++ b/tools/reporter.c @@ -60,21 +60,25 @@ static int _pvs_single(struct cmd_context *cmd, struct volume_group *vg, int consistent = 0; int ret = ECMD_PROCESSED; - if (!lock_vol(cmd, pv->vg_name, LCK_VG_READ)) { - log_error("Can't lock %s: skipping", pv->vg_name); - return ECMD_FAILED; - } + if (pv->vg_name) { + if (!lock_vol(cmd, pv->vg_name, LCK_VG_READ)) { + log_error("Can't lock %s: skipping", pv->vg_name); + return ECMD_FAILED; + } - if (!(vg = vg_read(cmd, pv->vg_name, &consistent))) { - log_error("Can't read %s: skipping", pv->vg_name); - unlock_vg(cmd, pv->vg_name); - return ECMD_FAILED; + if (!(vg = vg_read(cmd, pv->vg_name, &consistent))) { + log_error("Can't read %s: skipping", pv->vg_name); + unlock_vg(cmd, pv->vg_name); + return ECMD_FAILED; + } } if (!report_object(handle, vg, NULL, pv, NULL)) ret = ECMD_FAILED; - unlock_vg(cmd, pv->vg_name); + if (pv->vg_name) + unlock_vg(cmd, pv->vg_name); + return ret; } diff --git a/tools/toollib.c b/tools/toollib.c index 67b17e75b..75649928e 100644 --- a/tools/toollib.c +++ b/tools/toollib.c @@ -463,6 +463,44 @@ int process_each_pv_in_vg(struct cmd_context *cmd, struct volume_group *vg, return ret_max; } +static int _process_all_devs(struct cmd_context *cmd, void *handle, + int (*process_single) (struct cmd_context * cmd, + struct volume_group * vg, + struct physical_volume * pv, + void *handle)) +{ + struct physical_volume *pv; + struct physical_volume pv_dummy; + struct dev_iter *iter; + struct device *dev; + + int ret_max = 0; + int ret = 0; + + if (!(iter = dev_iter_create(cmd->filter))) { + log_error("dev_iter creation failed"); + return ECMD_FAILED; + } + + while ((dev = dev_iter_get(iter))) { + if (!(pv = pv_read(cmd, dev_name(dev), NULL, NULL, 0))) { + memset(&pv_dummy, 0, sizeof(pv_dummy)); + list_init(&pv_dummy.segments); + list_init(&pv_dummy.tags); + pv_dummy.dev = dev; + pv_dummy.fmt = NULL; + pv = &pv_dummy; + } + ret = process_single(cmd, NULL, pv, handle); + if (ret > ret_max) + ret_max = ret; + } + + dev_iter_destroy(iter); + + return ret_max; +} + int process_each_pv(struct cmd_context *cmd, int argc, char **argv, struct volume_group *vg, void *handle, int (*process_single) (struct cmd_context * cmd, @@ -516,7 +554,8 @@ int process_each_pv(struct cmd_context *cmd, int argc, char **argv, } pv = pvl->pv; } else { - if (!(pv = pv_read(cmd, argv[opt], NULL, NULL))) { + if (!(pv = pv_read(cmd, argv[opt], NULL, + NULL, 1))) { log_error("Failed to read physical " "volume \"%s\"", argv[opt]); ret_max = ECMD_FAILED; @@ -549,6 +588,10 @@ int process_each_pv(struct cmd_context *cmd, int argc, char **argv, process_single); if (ret > ret_max) ret_max = ret; + } else if (arg_count(cmd, all_ARG)) { + ret = _process_all_devs(cmd, handle, process_single); + if (ret > ret_max) + ret_max = ret; } else { log_verbose("Scanning for physical volume names"); if (!(pvslist = get_pvs(cmd)))