1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

Display all filtered devices, not just PVs, with pvs -a.

This commit is contained in:
Alasdair Kergon 2004-06-19 19:27:00 +00:00
parent 01c263e9fe
commit c29d24650d
10 changed files with 89 additions and 27 deletions

View File

@ -1,5 +1,6 @@
Version 2.00.17 - Version 2.00.17 -
============================= =============================
Display all filtered devices, not just PVs, with pvs -a.
Fix sync_dir() when no / in filename Fix sync_dir() when no / in filename
vgcfgbackup -f accepts template with %s for VG name. vgcfgbackup -f accepts template with %s for VG name.
Extend hash functions to handle non-null-terminated data. Extend hash functions to handle non-null-terminated data.

View File

@ -39,7 +39,7 @@ static int _add_pv_to_vg(struct format_instance *fid, struct volume_group *vg,
} }
list_init(&mdas); 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", log_error("%s not identified as an existing physical volume",
pv_name); pv_name);
return 0; return 0;
@ -426,7 +426,7 @@ struct physical_volume *find_pv_by_name(struct cmd_context *cmd,
{ {
struct physical_volume *pv; 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); log_error("Physical volume %s not found", pv_name);
return NULL; return NULL;
} }
@ -605,7 +605,7 @@ static struct volume_group *_vg_read_orphans(struct cmd_context *cmd)
list_iterate(ih, &vginfo->infos) { list_iterate(ih, &vginfo->infos) {
dev = list_item(ih, struct lvmcache_info)->dev; 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; continue;
} }
if (!(pvl = pool_zalloc(cmd->mem, sizeof(*pvl)))) { 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 */ /* FIXME Use label functions instead of PV functions */
struct physical_volume *pv_read(struct cmd_context *cmd, const char *pv_name, 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 physical_volume *pv;
struct label *label; 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))) { 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; return 0;
} }

View File

@ -369,7 +369,8 @@ struct volume_group *vg_read(struct cmd_context *cmd, const char *vg_name,
int *consistent); int *consistent);
struct volume_group *vg_read_by_vgid(struct cmd_context *cmd, const char *vgid); 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 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); struct list *get_pvs(struct cmd_context *cmd);
/* Set full_scan to 1 to re-read every (filtered) device label */ /* Set full_scan to 1 to re-read every (filtered) device label */

View File

@ -1063,6 +1063,7 @@ int report_object(void *handle, struct volume_group *vg,
struct row *row; struct row *row;
struct field *field; struct field *field;
void *data = NULL; void *data = NULL;
int skip;
if (lv && pv) { if (lv && pv) {
log_error("report_object: One of *lv and *pv must be NULL!"); 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) { list_iterate(fh, &rh->field_props) {
fp = list_item(fh, struct field_properties); fp = list_item(fh, struct field_properties);
skip = 0;
if (!(field = pool_zalloc(rh->mem, sizeof(*field)))) { if (!(field = pool_zalloc(rh->mem, sizeof(*field)))) {
log_error("struct field allocation failed"); log_error("struct field allocation failed");
return 0; return 0;
@ -1101,6 +1104,10 @@ int report_object(void *handle, struct volume_group *vg,
data = (void *) lv + _fields[fp->field_num].offset; data = (void *) lv + _fields[fp->field_num].offset;
break; break;
case VGS: case VGS:
if (!vg) {
skip = 1;
break;
}
data = (void *) vg + _fields[fp->field_num].offset; data = (void *) vg + _fields[fp->field_num].offset;
break; break;
case PVS: case PVS:
@ -1110,7 +1117,10 @@ int report_object(void *handle, struct volume_group *vg,
data = (void *) seg + _fields[fp->field_num].offset; 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", log_error("report function failed for field %s",
_fields[fp->field_num].id); _fields[fp->field_num].id);
return 0; return 0;

View File

@ -479,6 +479,7 @@ xx(pvs,
"Display information about physical volumes", "Display information about physical volumes",
"pvs" "\n" "pvs" "\n"
"\t[--aligned]\n" "\t[--aligned]\n"
"\t[-a|--all]\n"
"\t[-d|--debug]" "\n" "\t[-d|--debug]" "\n"
"\t[-h|-?|--help] " "\n" "\t[-h|-?|--help] " "\n"
"\t[--noheadings]\n" "\t[--noheadings]\n"
@ -493,9 +494,9 @@ xx(pvs,
"\t[--version]\n" "\t[--version]\n"
"\t[PhysicalVolume [PhysicalVolume...]]\n", "\t[PhysicalVolume [PhysicalVolume...]]\n",
aligned_ARG, ignorelockingfailure_ARG, noheadings_ARG, nolocking_ARG, aligned_ARG, all_ARG, ignorelockingfailure_ARG, noheadings_ARG,
nosuffix_ARG, options_ARG, separator_ARG, sort_ARG, unbuffered_ARG, nolocking_ARG, nosuffix_ARG, options_ARG, separator_ARG, sort_ARG,
units_ARG) unbuffered_ARG, units_ARG)
xx(pvscan, xx(pvscan,
"List all physical volumes", "List all physical volumes",

View File

@ -107,7 +107,7 @@ static int _pvchange_single(struct cmd_context *cmd, struct physical_volume *pv,
return 0; return 0;
} }
if (!(pv = pv_read(cmd, pv_name, &mdas, &sector))) { if (!(pv = pv_read(cmd, pv_name, &mdas, &sector, 1))) {
unlock_vg(cmd, ORPHAN); unlock_vg(cmd, ORPHAN);
log_error("Unable to read PV \"%s\"", pv_name); log_error("Unable to read PV \"%s\"", pv_name);
return 0; return 0;
@ -236,9 +236,8 @@ int pvchange(struct cmd_context *cmd, int argc, char **argv)
for (; opt < argc; opt++) { for (; opt < argc; opt++) {
pv_name = argv[opt]; pv_name = argv[opt];
/* FIXME Read VG instead - pv_read will fail */ /* FIXME Read VG instead - pv_read will fail */
if (!(pv = pv_read(cmd, pv_name, &mdas, NULL))) { if (!(pv = pv_read(cmd, pv_name, &mdas, NULL, 1))) {
log_error log_error("Failed to read physical volume %s",
("Failed to read physical volume \"%s\"",
pv_name); pv_name);
continue; continue;
} }

View File

@ -35,7 +35,7 @@ static int pvcreate_check(struct cmd_context *cmd, const char *name)
/* is there a pv here already */ /* is there a pv here already */
/* FIXME Use partial mode here? */ /* FIXME Use partial mode here? */
if (!(pv = pv_read(cmd, name, NULL, NULL))) if (!(pv = pv_read(cmd, name, NULL, NULL, 0)))
return 1; return 1;
/* orphan ? */ /* orphan ? */

View File

@ -34,7 +34,7 @@ static int pvremove_check(struct cmd_context *cmd, const char *name)
} }
/* is there a pv here already */ /* 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; return 1;
/* orphan ? */ /* orphan ? */

View File

@ -60,6 +60,7 @@ static int _pvs_single(struct cmd_context *cmd, struct volume_group *vg,
int consistent = 0; int consistent = 0;
int ret = ECMD_PROCESSED; int ret = ECMD_PROCESSED;
if (pv->vg_name) {
if (!lock_vol(cmd, pv->vg_name, LCK_VG_READ)) { if (!lock_vol(cmd, pv->vg_name, LCK_VG_READ)) {
log_error("Can't lock %s: skipping", pv->vg_name); log_error("Can't lock %s: skipping", pv->vg_name);
return ECMD_FAILED; return ECMD_FAILED;
@ -70,11 +71,14 @@ static int _pvs_single(struct cmd_context *cmd, struct volume_group *vg,
unlock_vg(cmd, pv->vg_name); unlock_vg(cmd, pv->vg_name);
return ECMD_FAILED; return ECMD_FAILED;
} }
}
if (!report_object(handle, vg, NULL, pv, NULL)) if (!report_object(handle, vg, NULL, pv, NULL))
ret = ECMD_FAILED; ret = ECMD_FAILED;
if (pv->vg_name)
unlock_vg(cmd, pv->vg_name); unlock_vg(cmd, pv->vg_name);
return ret; return ret;
} }

View File

@ -463,6 +463,44 @@ int process_each_pv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
return ret_max; 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, int process_each_pv(struct cmd_context *cmd, int argc, char **argv,
struct volume_group *vg, void *handle, struct volume_group *vg, void *handle,
int (*process_single) (struct cmd_context * cmd, 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; pv = pvl->pv;
} else { } 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 " log_error("Failed to read physical "
"volume \"%s\"", argv[opt]); "volume \"%s\"", argv[opt]);
ret_max = ECMD_FAILED; ret_max = ECMD_FAILED;
@ -549,6 +588,10 @@ int process_each_pv(struct cmd_context *cmd, int argc, char **argv,
process_single); process_single);
if (ret > ret_max) if (ret > ret_max)
ret_max = ret; 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 { } else {
log_verbose("Scanning for physical volume names"); log_verbose("Scanning for physical volume names");
if (!(pvslist = get_pvs(cmd))) if (!(pvslist = get_pvs(cmd)))