summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2014-04-23 13:44:54 -0500
committerDavid Teigland <teigland@redhat.com>2014-04-23 14:13:51 -0500
commit676a5fc760464a6b052ade08f6be8047995fc706 (patch)
treef91b9e997979c3e5e59f423220d00d935fafb633
parentf9e07daff75803968d78255ace5e0aafa10ea7e4 (diff)
downloadlvm2-dev-dct-process-v14.tar.gz
logging: use flags to enable warningsdev-dct-process-v14
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. A new vg_read flag READ_WARN_INCONSISTENT is used from reporting to enable the WARN_INCONSISTENT flag in vg_read_internal.
-rw-r--r--daemons/clvmd/lvm-functions.c2
-rw-r--r--lib/metadata/metadata-exported.h9
-rw-r--r--lib/metadata/metadata.c80
-rw-r--r--tools/toollib.c2
4 files changed, 47 insertions, 46 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..abcc438ed 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -139,6 +139,7 @@
#define READ_ALLOW_INCONSISTENT 0x00010000U
#define READ_ALLOW_EXPORTED 0x00020000U
#define READ_WITHOUT_LOCK 0x00040000U
+#define READ_WARN_INCONSISTENT 0x00080000U
/* A meta-flag, useful with toollib for_each_* functions. */
#define READ_FOR_UPDATE 0x00100000U
@@ -519,6 +520,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);
+/* warn_flags */
+#define WARN_PV_READ 0x00000001
+#define WARN_INCONSISTENT 0x00000002
+
/*
* Utility functions
*/
@@ -526,7 +531,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 warn_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 +549,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 warn_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..29d4a0c5d 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 warn_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 warn_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, warn_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 warn_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->warn_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 warn_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.warn_flags = warn_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 warn_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, warn_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 warn_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, warn_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 (!*consistent && (warn_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 warn_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, warn_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, warn_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 warn_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 (warn_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 (warn_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 (warn_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 warn_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))) {
+
+ warn_flags |= WARN_INCONSISTENT;
+
+ if (!(vg = vg_read_internal(cmd, vgname, (!vgslist) ? vgid : NULL, warn_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 warn_flags)
{
- return _get_pvs(cmd, warnings, NULL, NULL);
+ return _get_pvs(cmd, warn_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 warn_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;
+ warn_flags = WARN_PV_READ;
+ if (consistent || (misc_flags & READ_WARN_INCONSISTENT))
+ warn_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, warn_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;
}
diff --git a/tools/toollib.c b/tools/toollib.c
index 0f5acadff..7400292ba 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -2000,7 +2000,7 @@ static int process_pvs_in_vgs(struct cmd_context *cmd, uint32_t flags,
vg_uuid = nl->uuid;
ret = 0;
- vg = vg_read(cmd, vg_name, vg_uuid, flags);
+ vg = vg_read(cmd, vg_name, vg_uuid, flags | READ_WARN_INCONSISTENT);
if (ignore_vg(vg, vg_name, flags & READ_ALLOW_INCONSISTENT, &ret)) {
if (ret > ret_max)
ret_max = ret;