From f4a69472aa70b2079fc9e26c1dd5d10658ad8f2f Mon Sep 17 00:00:00 2001 From: David Teigland Date: Wed, 23 Apr 2014 13:44:54 -0500 Subject: logging: use flags to enable warnings The "warnings" arg was used to enable logging of warnings when reading a pv. This arg is turned into a set of flags with the WARN_PV_READ flag matching the existing behavior. A new flag WARN_INCONSISTENT is added that will cause vg_read_internal() to log the "vg is not consistent" warning, and the various callers do not need to log this warning themselves. --- daemons/clvmd/lvm-functions.c | 2 +- lib/metadata/metadata-exported.h | 8 +++- lib/metadata/metadata.c | 80 +++++++++++++++++++--------------------- 3 files changed, 45 insertions(+), 45 deletions(-) diff --git a/daemons/clvmd/lvm-functions.c b/daemons/clvmd/lvm-functions.c index 2ecf7d73e..5c2cf5b15 100644 --- a/daemons/clvmd/lvm-functions.c +++ b/daemons/clvmd/lvm-functions.c @@ -843,7 +843,7 @@ void lvm_do_backup(const char *vgname) pthread_mutex_lock(&lvm_lock); - vg = vg_read_internal(cmd, vgname, NULL /*vgid*/, 1, &consistent); + vg = vg_read_internal(cmd, vgname, NULL /*vgid*/, WARN_PV_READ, &consistent); if (vg && consistent) check_current_backup(vg); diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h index 6f97564bb..2fd37e094 100644 --- a/lib/metadata/metadata-exported.h +++ b/lib/metadata/metadata-exported.h @@ -519,6 +519,10 @@ int pvcreate_single(struct cmd_context *cmd, const char *pv_name, struct pvcreate_params *pp); void pvcreate_params_set_defaults(struct pvcreate_params *pp); +/* log_flags */ +#define WARN_PV_READ 0x00000001 +#define WARN_INCONSISTENT 0x00000002 + /* * Utility functions */ @@ -526,7 +530,7 @@ int vg_write(struct volume_group *vg); int vg_commit(struct volume_group *vg); void vg_revert(struct volume_group *vg); struct volume_group *vg_read_internal(struct cmd_context *cmd, const char *vg_name, - const char *vgid, int warnings, int *consistent); + const char *vgid, uint32_t log_flags, int *consistent); #define get_pvs( cmd ) get_pvs_internal((cmd), NULL, NULL) #define get_pvs_perserve_vg( cmd, pv_list, vg_list ) get_pvs_internal((cmd), (pv_list), (vg_list)) @@ -544,7 +548,7 @@ void lv_set_hidden(struct logical_volume *lv); struct dm_list *get_vgnames(struct cmd_context *cmd, int include_internal); struct dm_list *get_vgids(struct cmd_context *cmd, int include_internal); -int scan_vgs_for_pvs(struct cmd_context *cmd, int warnings); +int scan_vgs_for_pvs(struct cmd_context *cmd, uint32_t log_flags); int pv_write(struct cmd_context *cmd, struct physical_volume *pv, int allow_non_orphan); int move_pv(struct volume_group *vg_from, struct volume_group *vg_to, diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c index 6bc7e3ae0..756fe0a77 100644 --- a/lib/metadata/metadata.c +++ b/lib/metadata/metadata.c @@ -38,7 +38,7 @@ static struct physical_volume *_pv_read(struct cmd_context *cmd, struct dm_pool *pvmem, const char *pv_name, struct format_instance *fid, - int warnings, int scan_label_only); + uint32_t log_flags, int scan_label_only); static uint32_t _vg_bad_status_bits(const struct volume_group *vg, uint64_t status); @@ -332,18 +332,15 @@ int get_pv_from_vg_by_id(const struct format_type *fmt, const char *vg_name, { struct volume_group *vg; struct pv_list *pvl; + uint32_t log_flags = WARN_PV_READ | WARN_INCONSISTENT; int r = 0, consistent = 0; - if (!(vg = vg_read_internal(fmt->cmd, vg_name, vgid, 1, &consistent))) { + if (!(vg = vg_read_internal(fmt->cmd, vg_name, vgid, log_flags, &consistent))) { log_error("get_pv_from_vg_by_id: vg_read_internal failed to read VG %s", vg_name); return 0; } - if (!consistent) - log_warn("WARNING: Volume group %s is not consistent", - vg_name); - dm_list_iterate_items(pvl, &vg->pvs) { if (id_equal(&pvl->pv->id, (const struct id *) pvid)) { if (!_copy_pv(fmt->cmd->mem, pv, pvl->pv)) { @@ -986,7 +983,7 @@ struct volume_group *vg_create(struct cmd_context *cmd, const char *vg_name) /* FIXME: Is this vg_read_internal necessary? Move it inside vg_lock_newname? */ /* is this vg name already in use ? */ - if ((vg = vg_read_internal(cmd, vg_name, NULL, 1, &consistent))) { + if ((vg = vg_read_internal(cmd, vg_name, NULL, WARN_PV_READ, &consistent))) { log_error("A volume group called '%s' already exists.", vg_name); unlock_and_release_vg(cmd, vg, vg_name); return _vg_make_handle(cmd, NULL, FAILED_EXIST); @@ -2813,7 +2810,7 @@ void vg_revert(struct volume_group *vg) struct _vg_read_orphan_baton { struct volume_group *vg; - int warnings; + uint32_t log_flags; }; static int _vg_read_orphan_pv(struct lvmcache_info *info, void *baton) @@ -2823,7 +2820,7 @@ static int _vg_read_orphan_pv(struct lvmcache_info *info, void *baton) struct pv_list *pvl; if (!(pv = _pv_read(b->vg->cmd, b->vg->vgmem, dev_name(lvmcache_device(info)), - b->vg->fid, b->warnings, 0))) { + b->vg->fid, b->log_flags, 0))) { stack; return 1; } @@ -2840,7 +2837,7 @@ static int _vg_read_orphan_pv(struct lvmcache_info *info, void *baton) /* Make orphan PVs look like a VG. */ static struct volume_group *_vg_read_orphans(struct cmd_context *cmd, - int warnings, + uint32_t log_flags, const char *orphan_vgname) { const struct format_type *fmt; @@ -2873,7 +2870,7 @@ static struct volume_group *_vg_read_orphans(struct cmd_context *cmd, vg->extent_count = 0; vg->free_count = 0; - baton.warnings = warnings; + baton.log_flags = log_flags; baton.vg = vg; while ((pvl = (struct pv_list *) dm_list_first(&head.list))) { @@ -3022,7 +3019,7 @@ static int _check_mda_in_use(struct metadata_area *mda, void *_in_use) static struct volume_group *_vg_read(struct cmd_context *cmd, const char *vgname, const char *vgid, - int warnings, + uint32_t log_flags, int *consistent, unsigned precommitted) { struct format_instance *fid = NULL; @@ -3051,7 +3048,7 @@ static struct volume_group *_vg_read(struct cmd_context *cmd, return NULL; } *consistent = 1; - return _vg_read_orphans(cmd, warnings, vgname); + return _vg_read_orphans(cmd, log_flags, vgname); } if (lvmetad_active() && !use_precommitted) { @@ -3488,12 +3485,12 @@ static struct volume_group *_vg_read(struct cmd_context *cmd, } struct volume_group *vg_read_internal(struct cmd_context *cmd, const char *vgname, - const char *vgid, int warnings, int *consistent) + const char *vgid, uint32_t log_flags, int *consistent) { struct volume_group *vg; struct lv_list *lvl; - if (!(vg = _vg_read(cmd, vgname, vgid, warnings, consistent, 0))) + if (!(vg = _vg_read(cmd, vgname, vgid, log_flags, consistent, 0))) return NULL; if (!check_pv_segments(vg)) { @@ -3524,6 +3521,9 @@ struct volume_group *vg_read_internal(struct cmd_context *cmd, const char *vgnam } } + if (log_flags & WARN_INCONSISTENT) + log_warn("WARNING: Volume Group %s is not consistent", vgname); + return vg; } @@ -3547,16 +3547,13 @@ static struct volume_group *_vg_read_by_vgid(struct cmd_context *cmd, struct dm_list *vgnames; struct volume_group *vg; struct str_list *strl; + uint32_t log_flags = WARN_PV_READ | WARN_INCONSISTENT; int consistent = 0; /* Is corresponding vgname already cached? */ if (lvmcache_vgid_is_cached(vgid)) { - if ((vg = _vg_read(cmd, NULL, vgid, 1, - &consistent, precommitted)) && + if ((vg = _vg_read(cmd, NULL, vgid, log_flags, &consistent, precommitted)) && id_equal(&vg->id, (const struct id *)vgid)) { - if (!consistent) - log_error("Volume group %s metadata is " - "inconsistent", vg->name); return vg; } release_vg(vg); @@ -3582,12 +3579,9 @@ static struct volume_group *_vg_read_by_vgid(struct cmd_context *cmd, if (!vgname) continue; // FIXME Unnecessary? consistent = 0; - if ((vg = _vg_read(cmd, vgname, vgid, 1, &consistent, - precommitted)) && + if ((vg = _vg_read(cmd, vgname, vgid, log_flags, &consistent, precommitted)) && id_equal(&vg->id, (const struct id *)vgid)) { if (!consistent) { - log_error("Volume group %s metadata is " - "inconsistent", vgname); release_vg(vg); return NULL; } @@ -3651,7 +3645,7 @@ const char *find_vgname_from_pvid(struct cmd_context *cmd, * every PV on the system. */ if (lvmcache_uncertain_ownership(info)) { - if (!scan_vgs_for_pvs(cmd, 1)) { + if (!scan_vgs_for_pvs(cmd, WARN_PV_READ)) { log_error("Rescan for PVs without " "metadata areas failed."); return NULL; @@ -3685,7 +3679,7 @@ static struct physical_volume *_pv_read(struct cmd_context *cmd, struct dm_pool *pvmem, const char *pv_name, struct format_instance *fid, - int warnings, int scan_label_only) + uint32_t log_flags, int scan_label_only) { struct physical_volume *pv; struct label *label; @@ -3703,13 +3697,13 @@ static struct physical_volume *_pv_read(struct cmd_context *cmd, if (!lvmetad_pv_lookup_by_dev(cmd, dev, &found)) return_NULL; if (!found) { - if (warnings) + if (log_flags & WARN_PV_READ) log_error("No physical volume found in lvmetad cache for %s", pv_name); return NULL; } if (!(info = lvmcache_info_from_pvid(dev->pvid, 0))) { - if (warnings) + if (log_flags & WARN_PV_READ) log_error("No cache info in lvmetad cache for %s.", pv_name); return NULL; @@ -3718,7 +3712,7 @@ static struct physical_volume *_pv_read(struct cmd_context *cmd, label = lvmcache_get_label(info); } else { if (!(label_read(dev, &label, UINT64_C(0)))) { - if (warnings) + if (log_flags & WARN_PV_READ) log_error("No physical volume label read from %s", pv_name); return NULL; @@ -3774,7 +3768,7 @@ struct dm_list *get_vgids(struct cmd_context *cmd, int include_internal) return lvmcache_get_vgids(cmd, include_internal); } -static int _get_pvs(struct cmd_context *cmd, int warnings, +static int _get_pvs(struct cmd_context *cmd, uint32_t log_flags, struct dm_list *pvslist, struct dm_list *vgslist) { struct str_list *strl; @@ -3817,13 +3811,13 @@ static int _get_pvs(struct cmd_context *cmd, int warnings, * vgid will be NULL. * FIXME Remove this hack. */ - if (!(vg = vg_read_internal(cmd, vgname, (!vgslist) ? vgid : NULL, warnings, &consistent))) { + + log_flags |= WARN_INCONSISTENT; + + if (!(vg = vg_read_internal(cmd, vgname, (!vgslist) ? vgid : NULL, log_flags, &consistent))) { stack; continue; } - if (!consistent) - log_warn("WARNING: Volume Group %s is not consistent", - vgname); /* Move PVs onto results list */ if (pvslist) @@ -3905,7 +3899,7 @@ struct dm_list *get_pvs_internal(struct cmd_context *cmd, dm_list_init(results); } - if (!_get_pvs(cmd, 1, results, vgslist)) { + if (!_get_pvs(cmd, WARN_PV_READ, results, vgslist)) { if (!pvslist) dm_pool_free(cmd->mem, results); return NULL; @@ -3913,9 +3907,9 @@ struct dm_list *get_pvs_internal(struct cmd_context *cmd, return results; } -int scan_vgs_for_pvs(struct cmd_context *cmd, int warnings) +int scan_vgs_for_pvs(struct cmd_context *cmd, uint32_t log_flags) { - return _get_pvs(cmd, warnings, NULL, NULL); + return _get_pvs(cmd, log_flags, NULL, NULL); } int pv_write(struct cmd_context *cmd __attribute__((unused)), @@ -4121,7 +4115,7 @@ static struct volume_group *_recover_vg(struct cmd_context *cmd, if (!lock_vol(cmd, vg_name, LCK_VG_WRITE, NULL)) return_NULL; - if (!(vg = vg_read_internal(cmd, vg_name, vgid, 1, &consistent))) { + if (!(vg = vg_read_internal(cmd, vg_name, vgid, WARN_PV_READ, &consistent))) { unlock_vg(cmd, vg_name); return_NULL; } @@ -4154,6 +4148,7 @@ static struct volume_group *_vg_lock_and_read(struct cmd_context *cmd, const cha int consistent = 1; int consistent_in; uint32_t failure = 0; + uint32_t log_flags = 0; int already_locked; if (misc_flags & READ_ALLOW_INCONSISTENT || lock_flags != LCK_VG_WRITE) @@ -4178,16 +4173,17 @@ static struct volume_group *_vg_lock_and_read(struct cmd_context *cmd, const cha consistent_in = consistent; + log_flags = WARN_PV_READ; + if (consistent) + log_flags |= WARN_INCONSISTENT; + /* If consistent == 1, we get NULL here if correction fails. */ - if (!(vg = vg_read_internal(cmd, vg_name, vgid, 1, &consistent))) { + if (!(vg = vg_read_internal(cmd, vg_name, vgid, log_flags, &consistent))) { if (consistent_in && !consistent) { - log_error("Volume group \"%s\" inconsistent.", vg_name); failure |= FAILED_INCONSISTENT; goto bad; } - log_error("Volume group \"%s\" not found", vg_name); - failure |= FAILED_NOTFOUND; goto bad; } -- cgit v1.2.1