master - vgextend: pass single vgname as process_each_vg arg
by David Teigland
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=ea74215fa1f76c...
Commit: ea74215fa1f76cc965efd4f4656ad74321827161
Parent: 3bcdf5d14b930ba71c4dc5b03fcde0b19a5c8515
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Mon Nov 30 17:00:26 2015 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Tue Dec 1 09:36:45 2015 -0600
vgextend: pass single vgname as process_each_vg arg
Pass the single vgname as a new process_each_vg arg
instead of setting a cmd flag to tell process_each_vg
to take only the first vgname arg from argv.
Other commands with different argv formats will be
able to use it this way.
---
tools/commands.h | 2 +-
tools/polldaemon.c | 4 ++--
tools/reporter.c | 6 +++---
tools/toollib.c | 31 ++++++++++++++++---------------
tools/toollib.h | 3 ++-
tools/tools.h | 2 --
tools/vgcfgbackup.c | 2 +-
tools/vgchange.c | 2 +-
tools/vgck.c | 2 +-
tools/vgconvert.c | 2 +-
tools/vgdisplay.c | 2 +-
tools/vgexport.c | 2 +-
tools/vgextend.c | 5 ++++-
tools/vgimport.c | 2 +-
tools/vgremove.c | 2 +-
tools/vgscan.c | 2 +-
16 files changed, 37 insertions(+), 34 deletions(-)
diff --git a/tools/commands.h b/tools/commands.h
index b232a7d..5770bf3 100644
--- a/tools/commands.h
+++ b/tools/commands.h
@@ -1214,7 +1214,7 @@ xx(vgexport,
xx(vgextend,
"Add physical volumes to a volume group",
- ONE_VGNAME_ARG,
+ 0,
"vgextend\n"
"\t[-A|--autobackup y|n]\n"
"\t[--restoremissing]\n"
diff --git a/tools/polldaemon.c b/tools/polldaemon.c
index ccfaa7d..9172d71 100644
--- a/tools/polldaemon.c
+++ b/tools/polldaemon.c
@@ -364,7 +364,7 @@ static void _poll_for_all_vgs(struct cmd_context *cmd,
while (1) {
parms->outstanding_count = 0;
- process_each_vg(cmd, 0, NULL, READ_FOR_UPDATE, handle, _poll_vg);
+ process_each_vg(cmd, 0, NULL, NULL, READ_FOR_UPDATE, handle, _poll_vg);
if (!parms->outstanding_count)
break;
if (parms->interval)
@@ -508,7 +508,7 @@ static void _lvmpolld_poll_for_all_vgs(struct cmd_context *cmd,
handle->custom_handle = &lpdp;
- process_each_vg(cmd, 0, NULL, 0, handle, _lvmpolld_init_poll_vg);
+ process_each_vg(cmd, 0, NULL, NULL, 0, handle, _lvmpolld_init_poll_vg);
first = dm_list_first(&lpdp.idls);
diff --git a/tools/reporter.c b/tools/reporter.c
index 71f20a3..88025ec 100644
--- a/tools/reporter.c
+++ b/tools/reporter.c
@@ -884,7 +884,7 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
&_lvs_single);
break;
case VGS:
- r = process_each_vg(cmd, argc, argv, 0,
+ r = process_each_vg(cmd, argc, argv, NULL, 0,
&handle, &_vgs_single);
break;
case LABEL:
@@ -896,7 +896,7 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
r = process_each_pv(cmd, argc, argv, NULL, 0,
&handle, &_pvs_single);
else
- r = process_each_vg(cmd, argc, argv, 0,
+ r = process_each_vg(cmd, argc, argv, NULL, 0,
&handle, &_pvs_in_vg);
break;
case SEGSSTATUS:
@@ -917,7 +917,7 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
lv_info_needed && lv_segment_status_needed ? &_pvsegs_with_lv_info_and_status_single :
&_pvsegs_single);
else
- r = process_each_vg(cmd, argc, argv, 0,
+ r = process_each_vg(cmd, argc, argv, NULL, 0,
&handle, &_pvsegs_in_vg);
break;
}
diff --git a/tools/toollib.c b/tools/toollib.c
index f979475..e49356f 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1729,7 +1729,7 @@ int validate_restricted_lvname_param(struct cmd_context *cmd, const char **vg_na
*/
static int _get_arg_vgnames(struct cmd_context *cmd,
int argc, char **argv,
- unsigned one_vgname_arg,
+ const char *one_vgname,
struct dm_list *arg_vgnames,
struct dm_list *arg_tags)
{
@@ -1739,15 +1739,19 @@ static int _get_arg_vgnames(struct cmd_context *cmd,
log_verbose("Using volume group(s) on command line.");
+ if (one_vgname) {
+ if (!str_list_add(cmd->mem, arg_vgnames,
+ dm_pool_strdup(cmd->mem, one_vgname))) {
+ log_error("strlist allocation failed.");
+ return ECMD_FAILED;
+ }
+ return ret_max;
+ }
+
for (; opt < argc; opt++) {
vg_name = argv[opt];
if (*vg_name == '@') {
- if (one_vgname_arg) {
- log_error("This command does not yet support a tag to identify a Volume Group.");
- return EINVALID_CMD_LINE;
- }
-
if (!validate_tag(vg_name + 1)) {
log_error("Skipping invalid tag: %s", vg_name);
if (ret_max < EINVALID_CMD_LINE)
@@ -1769,8 +1773,6 @@ static int _get_arg_vgnames(struct cmd_context *cmd,
log_error("Invalid volume group name %s.", vg_name);
if (ret_max < EINVALID_CMD_LINE)
ret_max = EINVALID_CMD_LINE;
- if (one_vgname_arg)
- break;
continue;
}
@@ -1779,9 +1781,6 @@ static int _get_arg_vgnames(struct cmd_context *cmd,
log_error("strlist allocation failed.");
return ECMD_FAILED;
}
-
- if (one_vgname_arg)
- break;
}
return ret_max;
@@ -1937,7 +1936,7 @@ static int _process_vgnameid_list(struct cmd_context *cmd, uint32_t read_flags,
process_all = 1;
/*
- * FIXME If one_vgname_arg, only proceed if exactly one VG matches tags or selection.
+ * FIXME If one_vgname, only proceed if exactly one VG matches tags or selection.
*/
dm_list_iterate_items(vgnl, vgnameids_to_process) {
if (sigint_caught())
@@ -2120,9 +2119,12 @@ static void _choose_vgs_to_process(struct cmd_context *cmd,
/*
* Call process_single_vg() for each VG selected by the command line arguments.
+ * If one_vgname is set, process only that VG and ignore argc/argv (which should be 0/NULL)..
+ * If one_vgname is not set, get VG names to process from argc/argv.
*/
int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
- uint32_t read_flags, struct processing_handle *handle,
+ const char *one_vgname, uint32_t read_flags,
+ struct processing_handle *handle,
process_single_vg_fn_t process_single_vg)
{
int handle_supplied = handle != NULL;
@@ -2131,7 +2133,6 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
struct dm_list vgnameids_on_system; /* vgnameid_list */
struct dm_list vgnameids_to_process; /* vgnameid_list */
int enable_all_vgs = (cmd->command->flags & ALL_VGS_IS_DEFAULT);
- int one_vgname_arg = (cmd->command->flags & ONE_VGNAME_ARG);
int process_all_vgs_on_system = 0;
int ret_max = ECMD_PROCESSED;
int ret;
@@ -2147,7 +2148,7 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
/*
* Find any VGs or tags explicitly provided on the command line.
*/
- if ((ret = _get_arg_vgnames(cmd, argc, argv, one_vgname_arg, &arg_vgnames, &arg_tags)) != ECMD_PROCESSED) {
+ if ((ret = _get_arg_vgnames(cmd, argc, argv, one_vgname, &arg_vgnames, &arg_tags)) != ECMD_PROCESSED) {
ret_max = ret;
goto_out;
}
diff --git a/tools/toollib.h b/tools/toollib.h
index 2dc5ad7..400bac5 100644
--- a/tools/toollib.h
+++ b/tools/toollib.h
@@ -97,7 +97,8 @@ typedef int (*process_single_pvseg_fn_t) (struct cmd_context * cmd,
struct processing_handle *handle);
int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
- uint32_t flags, struct processing_handle *handle,
+ const char *one_vgname, uint32_t flags,
+ struct processing_handle *handle,
process_single_vg_fn_t process_single_vg);
int process_each_pv(struct cmd_context *cmd, int argc, char **argv,
diff --git a/tools/tools.h b/tools/tools.h
index 4ed893f..27061fc 100644
--- a/tools/tools.h
+++ b/tools/tools.h
@@ -99,8 +99,6 @@ struct arg_value_group_list {
#define ALL_VGS_IS_DEFAULT 0x00000004
/* Process all devices with --all if none are specified on the command line. */
#define ENABLE_ALL_DEVS 0x00000008
-/* Exactly one VG name argument required. */
-#define ONE_VGNAME_ARG 0x00000010
/* Command needs a shared lock on a VG; it only reads the VG. */
#define LOCKD_VG_SH 0x00000020
/* Command does not process any metadata. */
diff --git a/tools/vgcfgbackup.c b/tools/vgcfgbackup.c
index 5e80c80..be4dbb0 100644
--- a/tools/vgcfgbackup.c
+++ b/tools/vgcfgbackup.c
@@ -94,7 +94,7 @@ int vgcfgbackup(struct cmd_context *cmd, int argc, char **argv)
init_pvmove(1);
- ret = process_each_vg(cmd, argc, argv, READ_ALLOW_INCONSISTENT,
+ ret = process_each_vg(cmd, argc, argv, NULL, READ_ALLOW_INCONSISTENT,
handle, &vg_backup_single);
dm_free(last_filename);
diff --git a/tools/vgchange.c b/tools/vgchange.c
index 81e4bf3..9e1b09e 100644
--- a/tools/vgchange.c
+++ b/tools/vgchange.c
@@ -1227,7 +1227,7 @@ int vgchange(struct cmd_context *cmd, int argc, char **argv)
if (arg_is_set(cmd, lockstart_ARG) || arg_is_set(cmd, lockstop_ARG))
flags |= READ_ALLOW_EXPORTED;
- ret = process_each_vg(cmd, argc, argv, flags, NULL, &vgchange_single);
+ ret = process_each_vg(cmd, argc, argv, NULL, flags, NULL, &vgchange_single);
/* Wait for lock-start ops that were initiated in vgchange_lockstart. */
diff --git a/tools/vgck.c b/tools/vgck.c
index 1631289..b73544b 100644
--- a/tools/vgck.c
+++ b/tools/vgck.c
@@ -38,6 +38,6 @@ static int vgck_single(struct cmd_context *cmd __attribute__((unused)),
int vgck(struct cmd_context *cmd, int argc, char **argv)
{
lvmetad_set_active(cmd, 0);
- return process_each_vg(cmd, argc, argv, 0, NULL,
+ return process_each_vg(cmd, argc, argv, NULL, 0, NULL,
&vgck_single);
}
diff --git a/tools/vgconvert.c b/tools/vgconvert.c
index c4bb37a..9e6cb57 100644
--- a/tools/vgconvert.c
+++ b/tools/vgconvert.c
@@ -249,6 +249,6 @@ int vgconvert(struct cmd_context *cmd, int argc, char **argv)
return EINVALID_CMD_LINE;
}
- return process_each_vg(cmd, argc, argv, READ_FOR_UPDATE, NULL,
+ return process_each_vg(cmd, argc, argv, NULL, READ_FOR_UPDATE, NULL,
&vgconvert_single);
}
diff --git a/tools/vgdisplay.c b/tools/vgdisplay.c
index 1acb3ec..f232a83 100644
--- a/tools/vgdisplay.c
+++ b/tools/vgdisplay.c
@@ -89,7 +89,7 @@ int vgdisplay(struct cmd_context *cmd, int argc, char **argv)
}
**********/
- return process_each_vg(cmd, argc, argv, 0, NULL,
+ return process_each_vg(cmd, argc, argv, NULL, 0, NULL,
vgdisplay_single);
/******** FIXME Need to count number processed
diff --git a/tools/vgexport.c b/tools/vgexport.c
index 566cc96..59ad123 100644
--- a/tools/vgexport.c
+++ b/tools/vgexport.c
@@ -80,6 +80,6 @@ int vgexport(struct cmd_context *cmd, int argc, char **argv)
return EINVALID_CMD_LINE;
}
- return process_each_vg(cmd, argc, argv, READ_FOR_UPDATE, NULL,
+ return process_each_vg(cmd, argc, argv, NULL, READ_FOR_UPDATE, NULL,
&vgexport_single);
}
diff --git a/tools/vgextend.c b/tools/vgextend.c
index bddc22f..a747113 100644
--- a/tools/vgextend.c
+++ b/tools/vgextend.c
@@ -129,6 +129,7 @@ int vgextend(struct cmd_context *cmd, int argc, char **argv)
struct vgextend_params vp;
unsigned restoremissing = arg_is_set(cmd, restoremissing_ARG);
struct processing_handle *handle;
+ const char *one_vgname;
int ret;
if (!argc) {
@@ -137,6 +138,8 @@ int vgextend(struct cmd_context *cmd, int argc, char **argv)
return EINVALID_CMD_LINE;
}
+ one_vgname = skip_dev_dir(cmd, argv[0], NULL);
+
if (arg_count(cmd, metadatacopies_ARG)) {
log_error("Invalid option --metadatacopies, "
"use --pvmetadatacopies instead.");
@@ -169,7 +172,7 @@ int vgextend(struct cmd_context *cmd, int argc, char **argv)
if (!lockd_gl(cmd, "ex", 0))
return_ECMD_FAILED;
- ret = process_each_vg(cmd, argc, argv,
+ ret = process_each_vg(cmd, 0, NULL, one_vgname,
READ_FOR_UPDATE, handle,
restoremissing ? &_vgextend_restoremissing : &_vgextend_single);
diff --git a/tools/vgimport.c b/tools/vgimport.c
index 04a59dc..9e27ca3 100644
--- a/tools/vgimport.c
+++ b/tools/vgimport.c
@@ -98,7 +98,7 @@ int vgimport(struct cmd_context *cmd, int argc, char **argv)
return ECMD_FAILED;
}
- return process_each_vg(cmd, argc, argv,
+ return process_each_vg(cmd, argc, argv, NULL,
READ_FOR_UPDATE | READ_ALLOW_EXPORTED,
NULL,
&vgimport_single);
diff --git a/tools/vgremove.c b/tools/vgremove.c
index 219149e..3bf2b70 100644
--- a/tools/vgremove.c
+++ b/tools/vgremove.c
@@ -109,7 +109,7 @@ int vgremove(struct cmd_context *cmd, int argc, char **argv)
cmd->lockd_gl_disable = 1;
cmd->handles_missing_pvs = 1;
- ret = process_each_vg(cmd, argc, argv,
+ ret = process_each_vg(cmd, argc, argv, NULL,
READ_FOR_UPDATE,
NULL, &vgremove_single);
diff --git a/tools/vgscan.c b/tools/vgscan.c
index 7328a09..45841ec 100644
--- a/tools/vgscan.c
+++ b/tools/vgscan.c
@@ -62,7 +62,7 @@ int vgscan(struct cmd_context *cmd, int argc, char **argv)
log_print_unless_silent("Reading all physical volumes. This may take a while...");
- maxret = process_each_vg(cmd, argc, argv, 0, NULL,
+ maxret = process_each_vg(cmd, argc, argv, NULL, 0, NULL,
&vgscan_single);
if (arg_count(cmd, mknodes_ARG)) {
8 years, 4 months
master - lvmcache: change duplicate VG name warnings to verbose
by David Teigland
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=3bcdf5d14b930b...
Commit: 3bcdf5d14b930ba71c4dc5b03fcde0b19a5c8515
Parent: 88cef47b18cd8b03b090b4b17220b1ddf45aba03
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Mon Nov 30 15:28:22 2015 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Tue Dec 1 09:30:23 2015 -0600
lvmcache: change duplicate VG name warnings to verbose
When two different VGs with the same name exist,
they are both stored in lvmcache using the vginfo->next
list. Previously, the code would print warnings (sometimes)
when adding VGs to this list. Now the duplicate VG names
are handled by higher level code, so this list no longer
needs to print warnings about duplicate VG names being found.
---
lib/cache/lvmcache.c | 53 +++++++++++++++++++++++++++++++------------------
1 files changed, 33 insertions(+), 20 deletions(-)
diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c
index e375388..799de6f 100644
--- a/lib/cache/lvmcache.c
+++ b/lib/cache/lvmcache.c
@@ -1259,6 +1259,15 @@ static int _insert_vginfo(struct lvmcache_vginfo *new_vginfo, const char *vgid,
return_0;
/*
+ * vginfo is kept for each VG with the same name.
+ * They are saved with the vginfo->next list.
+ * These checks just decide the ordering of
+ * that list.
+ *
+ * FIXME: it should no longer matter what order
+ * the vginfo's are kept in, so we can probably
+ * remove these comparisons and reordering entirely.
+ *
* If Primary not exported, new exported => keep
* Else Primary exported, new not exported => change
* Else Primary has hostname for this machine => keep
@@ -1268,38 +1277,42 @@ static int _insert_vginfo(struct lvmcache_vginfo *new_vginfo, const char *vgid,
*/
if (!(primary_vginfo->status & EXPORTED_VG) &&
(vgstatus & EXPORTED_VG))
- log_warn("WARNING: Duplicate VG name %s: "
- "Existing %s takes precedence over "
- "exported %s", new_vginfo->vgname,
- uuid_primary, uuid_new);
+ log_verbose("Cache: Duplicate VG name %s: "
+ "Existing %s takes precedence over "
+ "exported %s", new_vginfo->vgname,
+ uuid_primary, uuid_new);
else if ((primary_vginfo->status & EXPORTED_VG) &&
!(vgstatus & EXPORTED_VG)) {
- log_warn("WARNING: Duplicate VG name %s: "
- "%s takes precedence over exported %s",
- new_vginfo->vgname, uuid_new,
- uuid_primary);
+ log_verbose("Cache: Duplicate VG name %s: "
+ "%s takes precedence over exported %s",
+ new_vginfo->vgname, uuid_new,
+ uuid_primary);
use_new = 1;
} else if (primary_vginfo->creation_host &&
!strcmp(primary_vginfo->creation_host,
primary_vginfo->fmt->cmd->hostname))
- log_warn("WARNING: Duplicate VG name %s: "
- "Existing %s (created here) takes precedence "
- "over %s", new_vginfo->vgname, uuid_primary,
- uuid_new);
+ log_verbose("Cache: Duplicate VG name %s: "
+ "Existing %s (created here) takes precedence "
+ "over %s", new_vginfo->vgname, uuid_primary,
+ uuid_new);
else if (!primary_vginfo->creation_host && creation_host) {
- log_warn("WARNING: Duplicate VG name %s: "
- "%s (with creation_host) takes precedence over %s",
- new_vginfo->vgname, uuid_new,
- uuid_primary);
+ log_verbose("Cache: Duplicate VG name %s: "
+ "%s (with creation_host) takes precedence over %s",
+ new_vginfo->vgname, uuid_new,
+ uuid_primary);
use_new = 1;
} else if (creation_host &&
!strcmp(creation_host,
primary_vginfo->fmt->cmd->hostname)) {
- log_warn("WARNING: Duplicate VG name %s: "
- "%s (created here) takes precedence over %s",
- new_vginfo->vgname, uuid_new,
- uuid_primary);
+ log_verbose("Cache: Duplicate VG name %s: "
+ "%s (created here) takes precedence over %s",
+ new_vginfo->vgname, uuid_new,
+ uuid_primary);
use_new = 1;
+ } else {
+ log_verbose("Cache: Duplicate VG name %s: "
+ "Prefer existing %s vs new %s",
+ new_vginfo->vgname, uuid_primary, uuid_new);
}
if (!use_new) {
8 years, 4 months
master - vg_read: look up vgid from name
by David Teigland
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=88cef47b18cd8b...
Commit: 88cef47b18cd8b03b090b4b17220b1ddf45aba03
Parent: 1e43ec15ce0a34ac29c82f232f21a2b0ea7f3a26
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Mon Nov 30 15:12:01 2015 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Tue Dec 1 09:18:48 2015 -0600
vg_read: look up vgid from name
After recent changes to process_each, vg_read() is usually
given both the vgname and vgid for the intended VG.
However, in some cases vg_read() is given a vgid with
no vgname, or is given a vgname with no vgid.
When given a vgid with no vgname, vg_read() uses lvmcache
to look up the vgname using the vgid. If the vgname is
not found, vg_read() fails.
When given a vgname with no vgid, vg_read() should also
use lvmcache to look up the vgid using the vgname.
If the vgid is not found, vg_read() fails.
If the lvmcache lookup finds multiple vgids for the
vgname, then the lookup fails, causing vg_read() to fail
because the intended VG is uncertain.
Usually, both vgname and vgid for the intended VG are passed
to vg_read(), which means the lvmcache translations
between vgname and vgid are not done.
---
lib/cache/lvmcache.c | 17 +++++++++++++++++
lib/cache/lvmcache.h | 1 +
lib/metadata/metadata.c | 10 +++++++++-
3 files changed, 27 insertions(+), 1 deletions(-)
diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c
index 985ff43..e375388 100644
--- a/lib/cache/lvmcache.c
+++ b/lib/cache/lvmcache.c
@@ -614,6 +614,23 @@ const char *lvmcache_vgname_from_vgid(struct dm_pool *mem, const char *vgid)
return vgname;
}
+const char *lvmcache_vgid_from_vgname(struct cmd_context *cmd, const char *vgname)
+{
+ struct lvmcache_vginfo *vginfo;
+
+ if (!(vginfo = dm_hash_lookup(_vgname_hash, vgname)))
+ return_NULL;
+
+ if (!vginfo->next)
+ return dm_pool_strdup(cmd->mem, vginfo->vgid);
+
+ /*
+ * There are multiple VGs with this name to choose from.
+ * Return an error because we don't know which VG is intended.
+ */
+ return NULL;
+}
+
static int _info_is_valid(struct lvmcache_info *info)
{
if (info->status & CACHE_INVALID)
diff --git a/lib/cache/lvmcache.h b/lib/cache/lvmcache.h
index b968a12..509cfd6 100644
--- a/lib/cache/lvmcache.h
+++ b/lib/cache/lvmcache.h
@@ -99,6 +99,7 @@ struct lvmcache_vginfo *lvmcache_vginfo_from_vgname(const char *vgname,
struct lvmcache_vginfo *lvmcache_vginfo_from_vgid(const char *vgid);
struct lvmcache_info *lvmcache_info_from_pvid(const char *pvid, int valid_only);
const char *lvmcache_vgname_from_vgid(struct dm_pool *mem, const char *vgid);
+const char *lvmcache_vgid_from_vgname(struct cmd_context *cmd, const char *vgname);
struct device *lvmcache_device_from_pvid(struct cmd_context *cmd, const struct id *pvid,
unsigned *scan_done_once, uint64_t *label_sector);
const char *lvmcache_pvid_from_devname(struct cmd_context *cmd,
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index bf030d3..ec645ae 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -3617,8 +3617,16 @@ static struct volume_group *_vg_read(struct cmd_context *cmd,
}
/* Now determine the correct vgname if none was supplied */
- if (!vgname && !(vgname = lvmcache_vgname_from_vgid(cmd->mem, vgid)))
+ if (!vgname && !(vgname = lvmcache_vgname_from_vgid(cmd->mem, vgid))) {
+ log_debug_metadata("Cache did not find VG name from vgid %.32s", vgid);
return_NULL;
+ }
+
+ /* Determine the correct vgid if none was supplied */
+ if (!vgid && !(vgid = lvmcache_vgid_from_vgname(cmd, vgname))) {
+ log_debug_metadata("Cache did not find VG vgid from name %s", vgname);
+ return_NULL;
+ }
if (use_precommitted && !(fmt->features & FMT_PRECOMMIT))
use_precommitted = 0;
8 years, 4 months
master - toollib: remove unused function
by David Teigland
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=1e43ec15ce0a34...
Commit: 1e43ec15ce0a34ac29c82f232f21a2b0ea7f3a26
Parent: aa4932674aa6c7e1f2526781caaa98a1920fd72a
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Mon Nov 30 14:17:33 2015 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Tue Dec 1 09:10:01 2015 -0600
toollib: remove unused function
---
tools/toollib.c | 29 -----------------------------
1 files changed, 0 insertions(+), 29 deletions(-)
diff --git a/tools/toollib.c b/tools/toollib.c
index ce1cdda..f979475 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1997,35 +1997,6 @@ endvg:
}
/*
- * Copy the contents of a str_list of VG names to a name list, filling
- * in the vgid with NULL (unknown).
- */
-static int _copy_str_to_vgnameid_list(struct cmd_context *cmd, struct dm_list *sll,
- struct dm_list *vgnll)
-{
- const char *vgname;
- struct dm_str_list *sl;
- struct vgnameid_list *vgnl;
-
- dm_list_iterate_items(sl, sll) {
- vgname = sl->str;
-
- vgnl = dm_pool_alloc(cmd->mem, sizeof(*vgnl));
- if (!vgnl) {
- log_error("vgnameid_list allocation failed.");
- return ECMD_FAILED;
- }
-
- vgnl->vgid = NULL;
- vgnl->vg_name = dm_pool_strdup(cmd->mem, vgname);
-
- dm_list_add(vgnll, &vgnl->list);
- }
-
- return ECMD_PROCESSED;
-}
-
-/*
* Check if a command line VG name is ambiguous, i.e. there are multiple VGs on
* the system that have the given name. If *one* VG with the given name is
* local and the rest are foreign, then use the local VG (removing foreign VGs
8 years, 4 months
master - process_each: resolve duplicate VG names
by David Teigland
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=aa4932674aa6c7...
Commit: aa4932674aa6c7e1f2526781caaa98a1920fd72a
Parent: 4ff2583dc5ffb87ad4265d7f0d9063c482cbc3a7
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Mon Nov 30 12:11:01 2015 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Tue Dec 1 09:09:55 2015 -0600
process_each: resolve duplicate VG names
If two different VGs with the same name exist on the system,
a command that just specifies that ambiguous name will fail
with a new error:
$ vgs -o name,uuid
...
foo qyUS65-vn32-TuKs-a8yF-wfeQ-7DkF-Fds0uf
foo vfhKCP-mpc7-KLLL-Uh08-4xPG-zLNR-4cnxJX
$ lvs foo
Multiple VGs found with the same name: foo
Use the --select option with VG UUID (vg_uuid).
$ vgremove foo
Multiple VGs found with the same name: foo
Use the --select option with VG UUID (vg_uuid).
$ lvs -S vg_uuid=qyUS65-vn32-TuKs-a8yF-wfeQ-7DkF-Fds0uf
lv1 foo ...
This is implemented for process_each_vg/lv, and works
with or without lvmetad. It does not work for commands
that do not use process_each.
This change includes one exception to the behavior shown
above. If one of the VGs is foreign, and the other is not,
then the command assumes that the intended VG is the local
one and uses it.
---
tools/toollib.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 93 insertions(+), 0 deletions(-)
diff --git a/tools/toollib.c b/tools/toollib.c
index 889bbb0..ce1cdda 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -2026,6 +2026,77 @@ static int _copy_str_to_vgnameid_list(struct cmd_context *cmd, struct dm_list *s
}
/*
+ * Check if a command line VG name is ambiguous, i.e. there are multiple VGs on
+ * the system that have the given name. If *one* VG with the given name is
+ * local and the rest are foreign, then use the local VG (removing foreign VGs
+ * with the same name from the vgnameids_on_system list). If multiple VGs with
+ * the given name are local, we don't know which VG is intended, so remove the
+ * ambiguous name from the list of args.
+ */
+static int _resolve_duplicate_vgnames(struct cmd_context *cmd,
+ struct dm_list *arg_vgnames,
+ struct dm_list *vgnameids_on_system)
+{
+ struct dm_str_list *sl, *sl2;
+ struct vgnameid_list *vgnl, *vgnl2;
+ char uuid[64] __attribute__((aligned(8)));
+ int found;
+ int ret = ECMD_PROCESSED;
+
+ dm_list_iterate_items_safe(sl, sl2, arg_vgnames) {
+ found = 0;
+ dm_list_iterate_items(vgnl, vgnameids_on_system) {
+ if (strcmp(sl->str, vgnl->vg_name))
+ continue;
+ found++;
+ }
+
+ if (found < 2)
+ continue;
+
+ /*
+ * More than one VG match the given name.
+ * If only one is local, use that one.
+ */
+
+ found = 0;
+ dm_list_iterate_items_safe(vgnl, vgnl2, vgnameids_on_system) {
+ if (strcmp(sl->str, vgnl->vg_name))
+ continue;
+
+ /*
+ * Without lvmetad, a label scan has already populated
+ * lvmcache vginfo with this information.
+ * With lvmetad, this function does vg_lookup on this
+ * name/vgid and checks system_id in the metadata.
+ */
+ if (lvmcache_vg_is_foreign(cmd, vgnl->vg_name, vgnl->vgid)) {
+ id_write_format((const struct id*)vgnl->vgid, uuid, sizeof(uuid));
+ log_warn("WARNING: Ignoring foreign VG with matching name %s UUID %s.",
+ vgnl->vg_name, uuid);
+ dm_list_del(&vgnl->list);
+ } else {
+ found++;
+ }
+ }
+
+ if (found < 2)
+ continue;
+
+ /*
+ * More than one VG with this name is local so the intended VG
+ * is unknown.
+ */
+ log_error("Multiple VGs found with the same name: skipping %s", sl->str);
+ log_error("Use the VG UUID with --select vg_uuid=<uuid>");
+ dm_list_del(&sl->list);
+ ret = ECMD_FAILED;
+ }
+
+ return ret;
+}
+
+/*
* For each arg_vgname, move the corresponding entry from
* vgnameids_on_system to vgnameids_to_process. If an
* item in arg_vgnames doesn't exist in vgnameids_on_system,
@@ -2141,6 +2212,17 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
goto_out;
}
+ if (!dm_list_empty(&arg_vgnames)) {
+ /* This may remove entries from arg_vgnames or vgnameids_on_system. */
+ ret = _resolve_duplicate_vgnames(cmd, &arg_vgnames, &vgnameids_on_system);
+ if (ret > ret_max)
+ ret_max = ret;
+ if (dm_list_empty(&arg_vgnames) && dm_list_empty(&arg_tags)) {
+ ret_max = ECMD_FAILED;
+ goto out;
+ }
+ }
+
if (dm_list_empty(&arg_vgnames) && dm_list_empty(&vgnameids_on_system)) {
/* FIXME Should be log_print, but suppressed for reporting cmds */
log_verbose("No volume groups found.");
@@ -2646,6 +2728,17 @@ int process_each_lv(struct cmd_context *cmd, int argc, char **argv, uint32_t rea
goto_out;
}
+ if (!dm_list_empty(&arg_vgnames)) {
+ /* This may remove entries from arg_vgnames or vgnameids_on_system. */
+ ret = _resolve_duplicate_vgnames(cmd, &arg_vgnames, &vgnameids_on_system);
+ if (ret > ret_max)
+ ret_max = ret;
+ if (dm_list_empty(&arg_vgnames) && dm_list_empty(&arg_tags)) {
+ ret_max = ECMD_FAILED;
+ goto out;
+ }
+ }
+
if (dm_list_empty(&arg_vgnames) && dm_list_empty(&vgnameids_on_system)) {
/* FIXME Should be log_print, but suppressed for reporting cmds */
log_verbose("No volume groups found.");
8 years, 4 months
master - process_each: always use list of vgnames on system
by David Teigland
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=4ff2583dc5ffb8...
Commit: 4ff2583dc5ffb87ad4265d7f0d9063c482cbc3a7
Parent: 68e2ea11a35b3c204aede9dce23ab99cdedcba32
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Mon Nov 30 12:51:44 2015 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Tue Dec 1 09:09:49 2015 -0600
process_each: always use list of vgnames on system
This makes process_each_vg/lv always use the list of
vgnames on the system. When specific VGs are named on
the command line, the corresponding entries from
vgnameids_on_system are moved to vgnameids_to_process.
Previously, when specific VGs were named on the command
line, the vgnameids_on_system list was not created, and
vgnameids_to_process was created from the arg_vgnames
list (which is only names, without vgids).
Now, vgnameids_on_system is always created, and entries
are moved from that list to vgnameids_to_process -- either
some (when arg_vgnames specifies only some), or all (when
the command is processing all VGs, or needs to look at
all VGs for checking tags/selection).
This change adds one new lvmetad lookup (vg_list) to a
command that specifies VG names. It adds no new work
for other commands, e.g. non-lvmetad commands, or
commands that look at all VGs.
When using lvmetad, 'lvs foo' previously sent one
request to lvmetad: 'vg_lookup foo'.
Now, 'lvs foo' sends two requests to lvmetad:
'vg_list' and 'vg_lookup foo <uuid>'.
(The lookup can now always include the uuid in the request
because the initial vg_list contains name/vgid pairs.)
---
tools/toollib.c | 219 ++++++++++++++++++++++++++++++++++++++++++-------------
1 files changed, 169 insertions(+), 50 deletions(-)
diff --git a/tools/toollib.c b/tools/toollib.c
index a52252e..889bbb0 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1916,6 +1916,7 @@ static int _process_vgnameid_list(struct cmd_context *cmd, uint32_t read_flags,
struct processing_handle *handle,
process_single_vg_fn_t process_single_vg)
{
+ char uuid[64] __attribute__((aligned(8)));
struct volume_group *vg;
struct vgnameid_list *vgnl;
const char *vg_name;
@@ -1947,6 +1948,11 @@ static int _process_vgnameid_list(struct cmd_context *cmd, uint32_t read_flags,
skip = 0;
notfound = 0;
+ if (vg_uuid)
+ id_write_format((const struct id*)vg_uuid, uuid, sizeof(uuid));
+
+ log_very_verbose("Processing VG %s %s", vg_name, vg_uuid ? uuid : "");
+
if (!lockd_vg(cmd, vg_name, NULL, 0, &lockd_state)) {
ret_max = ECMD_FAILED;
continue;
@@ -1966,6 +1972,9 @@ static int _process_vgnameid_list(struct cmd_context *cmd, uint32_t read_flags,
(!dm_list_empty(arg_vgnames) && str_list_match_item(arg_vgnames, vg_name)) ||
(!dm_list_empty(arg_tags) && str_list_match_list(arg_tags, &vg->tags, NULL))) &&
select_match_vg(cmd, handle, vg, &selected) && selected) {
+
+ log_very_verbose("Process single VG %s", vg_name);
+
ret = process_single_vg(cmd, vg_name, vg, handle);
_update_selection_result(handle, &whole_selected);
if (ret != ECMD_PROCESSED)
@@ -2017,6 +2026,57 @@ static int _copy_str_to_vgnameid_list(struct cmd_context *cmd, struct dm_list *s
}
/*
+ * For each arg_vgname, move the corresponding entry from
+ * vgnameids_on_system to vgnameids_to_process. If an
+ * item in arg_vgnames doesn't exist in vgnameids_on_system,
+ * then add a new entry for it to vgnameids_to_process.
+ */
+static void _choose_vgs_to_process(struct cmd_context *cmd,
+ struct dm_list *arg_vgnames,
+ struct dm_list *vgnameids_on_system,
+ struct dm_list *vgnameids_to_process)
+{
+ struct dm_str_list *sl, *sl2;
+ struct vgnameid_list *vgnl, *vgnl2;
+ int found;
+
+ dm_list_iterate_items_safe(sl, sl2, arg_vgnames) {
+ found = 0;
+ dm_list_iterate_items_safe(vgnl, vgnl2, vgnameids_on_system) {
+ if (strcmp(sl->str, vgnl->vg_name))
+ continue;
+
+ dm_list_del(&vgnl->list);
+ dm_list_add(vgnameids_to_process, &vgnl->list);
+ found = 1;
+ break;
+ }
+
+ /*
+ * If the name arg was not found in the list of all VGs, then
+ * it probably doesn't exist, but we want the "VG not found"
+ * failure to be handled by the existing vg_read() code for
+ * that error. So, create an entry with just the VG name so
+ * that the processing loop will attempt to process it and use
+ * the vg_read() error path.
+ */
+ if (!found) {
+ log_verbose("VG name on command line not found in list of VGs: %s", sl->str);
+
+ if (!(vgnl = dm_pool_alloc(cmd->mem, sizeof(*vgnl))))
+ continue;
+
+ vgnl->vgid = NULL;
+
+ if (!(vgnl->vg_name = dm_pool_strdup(cmd->mem, sl->str)))
+ continue;
+
+ dm_list_add(vgnameids_to_process, &vgnl->list);
+ }
+ }
+}
+
+/*
* Call process_single_vg() for each VG selected by the command line arguments.
*/
int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
@@ -2028,9 +2088,10 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
struct dm_list arg_vgnames; /* str_list */
struct dm_list vgnameids_on_system; /* vgnameid_list */
struct dm_list vgnameids_to_process; /* vgnameid_list */
-
int enable_all_vgs = (cmd->command->flags & ALL_VGS_IS_DEFAULT);
int one_vgname_arg = (cmd->command->flags & ONE_VGNAME_ARG);
+ int process_all_vgs_on_system = 0;
+ int ret_max = ECMD_PROCESSED;
int ret;
/* Disable error in vg_read so we can print it from ignore_vg. */
@@ -2044,29 +2105,46 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
/*
* Find any VGs or tags explicitly provided on the command line.
*/
- if ((ret = _get_arg_vgnames(cmd, argc, argv, one_vgname_arg, &arg_vgnames, &arg_tags)) != ECMD_PROCESSED)
+ if ((ret = _get_arg_vgnames(cmd, argc, argv, one_vgname_arg, &arg_vgnames, &arg_tags)) != ECMD_PROCESSED) {
+ ret_max = ret;
goto_out;
+ }
/*
- * Obtain the complete list of VGs present on the system if it is needed because:
- * any tags were supplied and need resolving; or
- * no VG names were given and the command defaults to processing all VGs.
+ * Process all VGs on the system when:
+ * . tags are specified and all VGs need to be read to
+ * look for matching tags.
+ * . no VG names are specified and the command defaults
+ * to processing all VGs when none are specified.
*/
- if ((dm_list_empty(&arg_vgnames) && enable_all_vgs) || !dm_list_empty(&arg_tags)) {
- /* Needed for a current listing of the global VG namespace. */
- if (!lockd_gl(cmd, "sh", 0)) {
- ret = ECMD_FAILED;
- goto_out;
- }
+ if ((dm_list_empty(&arg_vgnames) && enable_all_vgs) || !dm_list_empty(&arg_tags))
+ process_all_vgs_on_system = 1;
- if (!get_vgnameids(cmd, &vgnameids_on_system, NULL, 0))
- goto_out;
+ /*
+ * Needed for a current listing of the global VG namespace.
+ */
+ if (process_all_vgs_on_system && !lockd_gl(cmd, "sh", 0)) {
+ ret_max = ECMD_FAILED;
+ goto_out;
+ }
+
+ /*
+ * A list of all VGs on the system is needed when:
+ * . processing all VGs on the system
+ * . A VG name is specified which may refer to one
+ * of multiple VGs on the system with that name.
+ */
+ log_very_verbose("Get list of VGs on system");
+
+ if (!get_vgnameids(cmd, &vgnameids_on_system, NULL, 0)) {
+ ret_max = ECMD_FAILED;
+ goto_out;
}
if (dm_list_empty(&arg_vgnames) && dm_list_empty(&vgnameids_on_system)) {
/* FIXME Should be log_print, but suppressed for reporting cmds */
log_verbose("No volume groups found.");
- ret = ECMD_PROCESSED;
+ ret_max = ECMD_PROCESSED;
goto out;
}
@@ -2074,28 +2152,37 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
read_flags |= READ_OK_NOTFOUND;
/*
- * If we obtained a full list of VGs on the system, we need to work through them all;
- * otherwise we can merely work through the VG names provided.
+ * When processing all VGs, vgnameids_on_system simply becomes
+ * vgnameids_to_process.
+ * When processing only specified VGs, then for each item in
+ * arg_vgnames, move the corresponding entry from
+ * vgnameids_on_system to vgnameids_to_process.
*/
- if (!dm_list_empty(&vgnameids_on_system))
+ if (process_all_vgs_on_system)
dm_list_splice(&vgnameids_to_process, &vgnameids_on_system);
- else if ((ret = _copy_str_to_vgnameid_list(cmd, &arg_vgnames, &vgnameids_to_process)) != ECMD_PROCESSED)
- goto_out;
+ else
+ _choose_vgs_to_process(cmd, &arg_vgnames, &vgnameids_on_system, &vgnameids_to_process);
- if (!handle && !(handle = init_processing_handle(cmd)))
+ if (!handle && !(handle = init_processing_handle(cmd))) {
+ ret_max = ECMD_FAILED;
goto_out;
+ }
if (handle->internal_report_for_select && !handle->selection_handle &&
- !init_selection_handle(cmd, handle, VGS))
+ !init_selection_handle(cmd, handle, VGS)) {
+ ret_max = ECMD_FAILED;
goto_out;
+ }
ret = _process_vgnameid_list(cmd, read_flags, &vgnameids_to_process,
&arg_vgnames, &arg_tags, handle, process_single_vg);
+ if (ret > ret_max)
+ ret_max = ret;
out:
if (!handle_supplied)
destroy_processing_handle(cmd, handle);
- return ret;
+ return ret_max;
}
int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
@@ -2386,6 +2473,7 @@ static int _process_lv_vgnameid_list(struct cmd_context *cmd, uint32_t read_flag
struct processing_handle *handle,
process_single_lv_fn_t process_single_lv)
{
+ char uuid[64] __attribute__((aligned(8)));
struct volume_group *vg;
struct vgnameid_list *vgnl;
struct dm_str_list *sl;
@@ -2440,6 +2528,11 @@ static int _process_lv_vgnameid_list(struct cmd_context *cmd, uint32_t read_flag
}
}
+ if (vg_uuid)
+ id_write_format((const struct id*)vg_uuid, uuid, sizeof(uuid));
+
+ log_very_verbose("Processing VG %s %s", vg_name, vg_uuid ? uuid : "");
+
if (!lockd_vg(cmd, vg_name, NULL, 0, &lockd_state)) {
ret_max = ECMD_FAILED;
continue;
@@ -2483,9 +2576,9 @@ int process_each_lv(struct cmd_context *cmd, int argc, char **argv, uint32_t rea
struct dm_list arg_lvnames; /* str_list */
struct dm_list vgnameids_on_system; /* vgnameid_list */
struct dm_list vgnameids_to_process; /* vgnameid_list */
-
int enable_all_vgs = (cmd->command->flags & ALL_VGS_IS_DEFAULT);
- int need_vgnameids = 0;
+ int process_all_vgs_on_system = 0;
+ int ret_max = ECMD_PROCESSED;
int ret;
/* Disable error in vg_read so we can print it from ignore_vg. */
@@ -2500,44 +2593,63 @@ int process_each_lv(struct cmd_context *cmd, int argc, char **argv, uint32_t rea
/*
* Find any LVs, VGs or tags explicitly provided on the command line.
*/
- if ((ret = _get_arg_lvnames(cmd, argc, argv, &arg_vgnames, &arg_lvnames, &arg_tags) != ECMD_PROCESSED))
+ if ((ret = _get_arg_lvnames(cmd, argc, argv, &arg_vgnames, &arg_lvnames, &arg_tags) != ECMD_PROCESSED)) {
+ ret_max = ret;
goto_out;
+ }
- if (!handle && !(handle = init_processing_handle(cmd)))
+ if (!handle && !(handle = init_processing_handle(cmd))) {
+ ret_max = ECMD_FAILED;
goto_out;
+ }
if (handle->internal_report_for_select && !handle->selection_handle &&
- !init_selection_handle(cmd, handle, LVS))
+ !init_selection_handle(cmd, handle, LVS)) {
+ ret_max = ECMD_FAILED;
goto_out;
+ }
/*
- * Obtain the complete list of VGs present on the system if it is needed because:
- * any tags were supplied and need resolving; or
- * no VG names were given and the select option needs resolving; or
- * no VG names were given and the command defaults to processing all VGs.
- */
+ * Process all VGs on the system when:
+ * . tags are specified and all VGs need to be read to
+ * look for matching tags.
+ * . no VG names are specified and the command defaults
+ * to processing all VGs when none are specified.
+ * . no VG names are specified and the select option needs
+ * resolving.
+ */
if (!dm_list_empty(&arg_tags))
- need_vgnameids = 1;
+ process_all_vgs_on_system = 1;
else if (dm_list_empty(&arg_vgnames) && enable_all_vgs)
- need_vgnameids = 1;
+ process_all_vgs_on_system = 1;
else if (dm_list_empty(&arg_vgnames) && handle->internal_report_for_select)
- need_vgnameids = 1;
+ process_all_vgs_on_system = 1;
- if (need_vgnameids) {
- /* Needed for a current listing of the global VG namespace. */
- if (!lockd_gl(cmd, "sh", 0)) {
- ret = ECMD_FAILED;
- goto_out;
- }
+ /*
+ * Needed for a current listing of the global VG namespace.
+ */
+ if (process_all_vgs_on_system && !lockd_gl(cmd, "sh", 0)) {
+ ret_max = ECMD_FAILED;
+ goto_out;
+ }
- if (!get_vgnameids(cmd, &vgnameids_on_system, NULL, 0))
- goto_out;
+ /*
+ * A list of all VGs on the system is needed when:
+ * . processing all VGs on the system
+ * . A VG name is specified which may refer to one
+ * of multiple VGs on the system with that name.
+ */
+ log_very_verbose("Get list of VGs on system");
+
+ if (!get_vgnameids(cmd, &vgnameids_on_system, NULL, 0)) {
+ ret_max = ECMD_FAILED;
+ goto_out;
}
if (dm_list_empty(&arg_vgnames) && dm_list_empty(&vgnameids_on_system)) {
/* FIXME Should be log_print, but suppressed for reporting cmds */
log_verbose("No volume groups found.");
- ret = ECMD_PROCESSED;
+ ret_max = ECMD_PROCESSED;
goto out;
}
@@ -2545,20 +2657,27 @@ int process_each_lv(struct cmd_context *cmd, int argc, char **argv, uint32_t rea
read_flags |= READ_OK_NOTFOUND;
/*
- * If we obtained a full list of VGs on the system, we need to work through them all;
- * otherwise we can merely work through the VG names provided.
+ * When processing all VGs, vgnameids_on_system simply becomes
+ * vgnameids_to_process.
+ * When processing only specified VGs, then for each item in
+ * arg_vgnames, move the corresponding entry from
+ * vgnameids_on_system to vgnameids_to_process.
*/
- if (!dm_list_empty(&vgnameids_on_system))
+ if (process_all_vgs_on_system)
dm_list_splice(&vgnameids_to_process, &vgnameids_on_system);
- else if ((ret = _copy_str_to_vgnameid_list(cmd, &arg_vgnames, &vgnameids_to_process)) != ECMD_PROCESSED)
- goto_out;
+ else
+ _choose_vgs_to_process(cmd, &arg_vgnames, &vgnameids_on_system, &vgnameids_to_process);
ret = _process_lv_vgnameid_list(cmd, read_flags, &vgnameids_to_process, &arg_vgnames, &arg_lvnames,
&arg_tags, handle, process_single_lv);
+
+ if (ret > ret_max)
+ ret_max = ret;
out:
if (!handle_supplied)
destroy_processing_handle(cmd, handle);
- return ret;
+
+ return ret_max;
}
static int _get_arg_pvnames(struct cmd_context *cmd,
8 years, 4 months
master - mirror: fix condition
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=68e2ea11a35b3c...
Commit: 68e2ea11a35b3c204aede9dce23ab99cdedcba32
Parent: 86e7894ecceede2e4977cb9d8f39f5fa53e6f5ea
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Dec 1 13:59:20 2015 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Dec 1 13:59:20 2015 +0100
mirror: fix condition
Recent patch tested wrong condition for error
---
daemons/dmeventd/plugins/mirror/dmeventd_mirror.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c b/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c
index 68fe728..f3abb67 100644
--- a/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c
+++ b/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c
@@ -73,7 +73,7 @@ static int _get_mirror_event(struct dso_state *state, char *params)
unsigned i;
struct dm_status_mirror *ms;
- if (dm_get_status_mirror(state->mem, params, &ms))
+ if (!dm_get_status_mirror(state->mem, params, &ms))
goto_out;
/* Check for bad mirror devices */
8 years, 4 months
master - cleanup: use dm_get_status_mirror
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=86e7894ecceede...
Commit: 86e7894ecceede2e4977cb9d8f39f5fa53e6f5ea
Parent: 6336ef98d41b8c5b1435de08855aa66c8fd527c2
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Nov 30 21:17:25 2015 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Dec 1 13:03:16 2015 +0100
cleanup: use dm_get_status_mirror
Use libdm function to parse mirror status report.
---
WHATS_NEW | 1 +
WHATS_NEW_DM | 1 +
daemons/dmeventd/plugins/mirror/dmeventd_mirror.c | 121 ++++++---------
lib/activate/dev_manager.c | 108 +++-----------
lib/mirror/mirrored.c | 167 +++++++--------------
5 files changed, 118 insertions(+), 280 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index dcd2b22..d9222bc 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.137 -
=====================================
+ Use dm_get_status_mirror() instead of individual parsers.
Add mem pool arg for check_transient_status() target function.
Avoid misleading error with -m is omitted with lvconvert to raid types.
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index 689fe43..3357cec 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,5 +1,6 @@
Version 1.02.113 -
=====================================
+ Mirror plugin in dmeventd uses dm_get_status_mirror().
Add dm_get_status_mirror() for parsing mirror status line.
Version 1.02.112 - 28th November 2015
diff --git a/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c b/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c
index e20b249..68fe728 100644
--- a/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c
+++ b/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c
@@ -31,8 +31,9 @@ struct dso_state {
DM_EVENT_LOG_FN("mirr")
-static int _process_status_code(const char status_code, const char *dev_name,
- const char *dev_type, int r)
+static void _process_status_code(dm_status_mirror_health_t health,
+ uint32_t major, uint32_t minor,
+ const char *dev_type, int *r)
{
/*
* A => Alive - No failures
@@ -42,90 +43,60 @@ static int _process_status_code(const char status_code, const char *dev_name,
* R => Read - A read failure occurred, mirror data unaffected
* U => Unclassified failure (bug)
*/
- if (status_code == 'F') {
- log_error("%s device %s flush failed.", dev_type, dev_name);
- r = ME_FAILURE;
- } else if (status_code == 'S')
- log_error("%s device %s sync failed.", dev_type, dev_name);
- else if (status_code == 'R')
- log_error("%s device %s read failed.", dev_type, dev_name);
- else if (status_code != 'A') {
- log_error("%s device %s has failed (%c).",
- dev_type, dev_name, status_code);
- r = ME_FAILURE;
+ switch (health) {
+ case DM_STATUS_MIRROR_ALIVE:
+ return;
+ case DM_STATUS_MIRROR_FLUSH_FAILED:
+ log_error("%s device %u:%u flush failed.",
+ dev_type, major, minor);
+ *r = ME_FAILURE;
+ break;
+ case DM_STATUS_MIRROR_SYNC_FAILED:
+ log_error("%s device %u:%u sync failed.",
+ dev_type, major, minor);
+ break;
+ case DM_STATUS_MIRROR_READ_FAILED:
+ log_error("%s device %u:%u read failed.",
+ dev_type, major, minor);
+ break;
+ default:
+ log_error("%s device %u:%u has failed (%c).",
+ dev_type, major, minor, (char)health);
+ *r = ME_FAILURE;
+ break;
}
-
- return r;
}
-static int _get_mirror_event(char *params)
+static int _get_mirror_event(struct dso_state *state, char *params)
{
- int i, r = ME_INSYNC;
- char **args = NULL;
- char *dev_status_str;
- char *log_status_str;
- char *sync_str;
- char *p = NULL;
- int log_argc, num_devs;
+ int r = ME_INSYNC;
+ unsigned i;
+ struct dm_status_mirror *ms;
- /*
- * dm core parms: 0 409600 mirror
- * Mirror core parms: 2 253:4 253:5 400/400
- * New-style failure params: 1 AA
- * New-style log params: 3 cluster 253:3 A
- * or 3 disk 253:3 A
- * or 1 core
- */
-
- /* number of devices */
- if (!dm_split_words(params, 1, 0, &p))
- goto out_parse;
-
- if (!(num_devs = atoi(p)) ||
- (num_devs > DEFAULT_MIRROR_MAX_IMAGES) || (num_devs < 0))
- goto out_parse;
- p += strlen(p) + 1;
-
- /* devices names + "400/400" + "1 AA" + 1 or 3 log parms + NULL */
- args = dm_malloc((num_devs + 7) * sizeof(char *));
- if (!args || dm_split_words(p, num_devs + 7, 0, args) < num_devs + 5)
- goto out_parse;
-
- /* FIXME: Code differs from lib/mirror/mirrored.c */
- dev_status_str = args[2 + num_devs];
- log_argc = atoi(args[3 + num_devs]);
- log_status_str = args[3 + num_devs + log_argc];
- sync_str = args[num_devs];
+ if (dm_get_status_mirror(state->mem, params, &ms))
+ goto_out;
/* Check for bad mirror devices */
- for (i = 0; i < num_devs; i++)
- r = _process_status_code(dev_status_str[i], args[i],
- i ? "Secondary mirror" : "Primary mirror", r);
+ for (i = 0; i < ms->dev_count; ++i)
+ _process_status_code(ms->devs[i].health,
+ ms->devs[i].major, ms->devs[i].minor,
+ i ? "Secondary mirror" : "Primary mirror", &r);
/* Check for bad disk log device */
- if (log_argc > 1)
- r = _process_status_code(log_status_str[0],
- args[2 + num_devs + log_argc],
- "Log", r);
-
- if (r == ME_FAILURE)
- goto out;
-
- p = strstr(sync_str, "/");
- if (p) {
- p[0] = '\0';
- if (strcmp(sync_str, p+1))
- r = ME_IGNORE;
- p[0] = '/';
- } else
- goto out_parse;
+ for (i = 0; i < ms->log_count; ++i)
+ _process_status_code(ms->logs[i].health,
+ ms->logs[i].major, ms->logs[i].minor,
+ "Log", &r);
+
+ /* Ignore if not in-sync */
+ if ((r == ME_INSYNC) && (ms->insync_regions != ms->total_regions))
+ r = ME_IGNORE;
+
+ dm_pool_free(state->mem, ms);
-out:
- dm_free(args);
return r;
-out_parse:
- dm_free(args);
+out:
log_error("Unable to parse mirror status string.");
return ME_IGNORE;
@@ -172,7 +143,7 @@ void process_event(struct dm_task *dmt,
continue;
}
- switch(_get_mirror_event(params)) {
+ switch(_get_mirror_event(state, params)) {
case ME_INSYNC:
/* FIXME: all we really know is that this
_part_ of the device is in sync
diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c
index 4eff5cb..4d0b4d8 100644
--- a/lib/activate/dev_manager.c
+++ b/lib/activate/dev_manager.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2002-2004 Sistina Software, Inc. All rights reserved.
- * Copyright (C) 2004-2014 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2004-2015 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
@@ -247,79 +247,6 @@ static int _info_run(info_type_t type, const char *name, const char *dlid,
}
/*
- * _parse_mirror_status
- * @mirror_status_string
- * @image_health: return for allocated copy of image health characters
- * @log_device: return for 'dev_t' of log device
- * @log_health: NULL if corelog, otherwise dm_malloc'ed log health char which
- * the caller must free
- *
- * This function takes the mirror status string, breaks it up and returns
- * its components. For now, we only return the health characters. This
- * is an internal function. If there are more things we want to return
- * later, we can do that then.
- *
- * Returns: 1 on success, 0 on failure
- */
-static int _parse_mirror_status(char *mirror_status_str,
- char **images_health,
- dev_t *log_dev, char **log_health)
-{
- int major, minor;
- char *p = NULL;
- char **args, **log_args;
- unsigned num_devs, log_argc;
-
- *images_health = NULL;
- *log_health = NULL;
- *log_dev = 0;
-
- if (!dm_split_words(mirror_status_str, 1, 0, &p) ||
- !(num_devs = (unsigned) atoi(p)))
- /* On errors, we must assume the mirror is to be avoided */
- return_0;
-
- p += strlen(p) + 1;
- args = alloca((num_devs + 5) * sizeof(char *));
-
- if ((unsigned)dm_split_words(p, num_devs + 4, 0, args) < num_devs + 4)
- return_0;
-
- log_argc = (unsigned) atoi(args[3 + num_devs]);
- log_args = alloca(log_argc * sizeof(char *));
-
- if ((unsigned)dm_split_words(args[3 + num_devs] + strlen(args[3 + num_devs]) + 1,
- log_argc, 0, log_args) < log_argc)
- return_0;
-
- if (!strcmp(log_args[0], "disk")) {
- if (!(*log_health = dm_strdup(log_args[2]))) {
- log_error("Allocation of log string failed.");
- return 0;
- }
- if (sscanf(log_args[1], "%d:%d", &major, &minor) != 2) {
- log_error("Failed to parse log's device number from %s.", log_args[1]);
- goto out;
- }
- *log_dev = MKDEV((dev_t)major, minor);
- }
-
- if (!(*images_health = dm_strdup(args[2 + num_devs]))) {
- log_error("Allocation of images string failed.");
- goto out;
- }
-
- return 1;
-
-out:
- dm_free(*log_health);
- *log_health = NULL;
- *log_dev = 0;
-
- return 0;
-}
-
-/*
* ignore_blocked_mirror_devices
* @dev
* @start
@@ -349,44 +276,45 @@ static int _ignore_blocked_mirror_devices(struct device *dev,
uint64_t start, uint64_t length,
char *mirror_status_str)
{
+ struct dm_pool *mem;
+ struct dm_status_mirror *sm;
unsigned i, check_for_blocking = 0;
- dev_t log_dev;
- char *images_health, *log_health;
uint64_t s,l;
char *p, *params, *target_type = NULL;
void *next = NULL;
struct dm_task *dmt = NULL;
int r = 0;
+ struct device *tmp_dev;
+ char buf[16];
- if (!_parse_mirror_status(mirror_status_str,
- &images_health, &log_dev, &log_health))
+ if (!(mem = dm_pool_create("blocked_mirrors", 128)))
return_0;
- for (i = 0; images_health[i]; i++)
- if (images_health[i] != 'A') {
+ if (!dm_get_status_mirror(mem, mirror_status_str, &sm))
+ goto_out;
+
+ for (i = 0; i < sm->dev_count; ++i)
+ if (sm->devs[i].health != DM_STATUS_MIRROR_ALIVE) {
log_debug_activation("%s: Mirror image %d marked as failed",
dev_name(dev), i);
check_for_blocking = 1;
}
- if (!check_for_blocking && log_dev) {
- if (log_health[0] != 'A') {
+ if (!check_for_blocking && sm->log_count) {
+ if (sm->logs[0].health != DM_STATUS_MIRROR_ALIVE) {
log_debug_activation("%s: Mirror log device marked as failed",
dev_name(dev));
check_for_blocking = 1;
} else {
- struct device *tmp_dev;
- char buf[16];
- if (dm_snprintf(buf, sizeof(buf), "%d:%d",
- (int)MAJOR(log_dev),
- (int)MINOR(log_dev)) < 0)
+ if (dm_snprintf(buf, sizeof(buf), "%u:%u",
+ sm->logs[0].major, sm->logs[0].minor) < 0)
goto_out;
if (!(tmp_dev = dev_create_file(buf, NULL, NULL, 0)))
goto_out;
- tmp_dev->dev = log_dev;
+ tmp_dev->dev = MKDEV((dev_t)sm->logs[0].major, sm->logs[0].minor);
if (device_is_usable(tmp_dev, (struct dev_usable_check_params)
{ .check_empty = 1,
.check_blocked = 1,
@@ -440,8 +368,8 @@ static int _ignore_blocked_mirror_devices(struct device *dev,
out:
if (dmt)
dm_task_destroy(dmt);
- dm_free(log_health);
- dm_free(images_health);
+
+ dm_pool_destroy(mem);
return r;
}
diff --git a/lib/mirror/mirrored.c b/lib/mirror/mirrored.c
index b810c70..371718d 100644
--- a/lib/mirror/mirrored.c
+++ b/lib/mirror/mirrored.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2003-2004 Sistina Software, Inc. All rights reserved.
- * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2004-2015 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
@@ -168,161 +168,94 @@ static int _mirrored_target_percent(void **target_state,
uint64_t *total_numerator,
uint64_t *total_denominator)
{
- uint64_t numerator, denominator;
- unsigned mirror_count, m;
- int used;
- char *pos = params;
+ struct dm_status_mirror *sm;
if (!*target_state)
*target_state = _mirrored_init_target(mem, cmd);
- /* Status line: <#mirrors> (maj:min)+ <synced>/<total_regions> */
- log_debug_activation("Mirror status: %s", params);
-
- if (sscanf(pos, "%u %n", &mirror_count, &used) != 1) {
- log_error("Failure parsing mirror status mirror count: %s",
- params);
- return 0;
- }
- pos += used;
-
- for (m = 0; m < mirror_count; m++) {
- if (sscanf(pos, "%*x:%*x %n", &used) != 0) {
- log_error("Failure parsing mirror status devices: %s",
- params);
- return 0;
- }
- pos += used;
- }
-
- if (sscanf(pos, FMTu64 "/" FMTu64 "%n", &numerator, &denominator,
- &used) != 2) {
- log_error("Failure parsing mirror status fraction: %s", params);
- return 0;
- }
- pos += used;
+ if (!dm_get_status_mirror(mem, params, &sm))
+ return_0;
- *total_numerator += numerator;
- *total_denominator += denominator;
+ *total_numerator += sm->insync_regions;
+ *total_denominator += sm->total_regions;
if (seg)
- seg->extents_copied = seg->area_len * numerator / denominator;
+ seg->extents_copied = seg->area_len * sm->insync_regions / sm->total_regions;
+
+ *percent = dm_make_percent(sm->insync_regions, sm->total_regions);
- *percent = dm_make_percent(numerator, denominator);
+ dm_pool_free(mem, sm);
return 1;
}
static int _mirrored_transient_status(struct dm_pool *mem, struct lv_segment *seg, char *params)
{
- unsigned i, j;
+ struct dm_status_mirror *sm;
+ struct logical_volume *log;
struct logical_volume *lv = seg->lv;
+ int failed = 0, r = 0;
+ unsigned i, j;
struct lvinfo info;
- char *p = NULL;
- char **args, **log_args;
- struct logical_volume **images;
- struct logical_volume *log;
- unsigned num_devs, log_argc;
- int failed = 0;
- char *status;
log_very_verbose("Mirrored transient status: \"%s\"", params);
- /* number of devices */
- if (!dm_split_words(params, 1, 0, &p))
- return_0;
-
- if (!(num_devs = (unsigned) atoi(p)))
- return_0;
-
- p += strlen(p) + 1;
-
- if (num_devs > DEFAULT_MIRROR_MAX_IMAGES) {
- log_error("Unexpectedly many (%d) mirror images in %s.",
- num_devs, lv->name);
- return 0;
- }
-
- args = alloca((num_devs + 5) * sizeof(char *));
- images = alloca(num_devs * sizeof(struct logical_volume *));
-
- /* FIXME: dm_split_words() should return unsigned */
- if ((unsigned)dm_split_words(p, num_devs + 4, 0, args) < num_devs + 4)
- return_0;
-
- log_argc = (unsigned) atoi(args[3 + num_devs]);
-
- if (log_argc > 16) {
- log_error("Unexpectedly many (%d) log arguments in %s.",
- log_argc, lv->name);
- return 0;
- }
-
- log_args = alloca(log_argc * sizeof(char *));
-
- if ((unsigned)dm_split_words(args[3 + num_devs] + strlen(args[3 + num_devs]) + 1,
- log_argc, 0, log_args) < log_argc)
+ if (!dm_get_status_mirror(mem, params, &sm))
return_0;
- if (num_devs != seg->area_count) {
+ if (sm->dev_count != seg->area_count) {
log_error("Active mirror has a wrong number of mirror images!");
- log_error("Metadata says %d, kernel says %d.", seg->area_count, num_devs);
- return 0;
+ log_error("Metadata says %u, kernel says %u.",
+ seg->area_count, sm->dev_count);
+ goto out;
}
- if (!strcmp(log_args[0], "disk")) {
- char buf[32];
+ if (!strcmp(sm->log_type, "disk")) {
log = first_seg(lv)->log_lv;
if (!lv_info(lv->vg->cmd, log, 0, &info, 0, 0)) {
log_error("Check for existence of mirror log %s failed.",
- log->name);
- return 0;
+ display_lvname(log));
+ goto out;
}
log_debug_activation("Found mirror log at %d:%d", info.major, info.minor);
- sprintf(buf, "%d:%d", info.major, info.minor);
- if (strcmp(buf, log_args[1])) {
- log_error("Mirror log mismatch. Metadata says %s, kernel says %s.",
- buf, log_args[1]);
- return 0;
+ if (info.major != (int)sm->logs[0].major ||
+ info.minor != (int)sm->logs[0].minor) {
+ log_error("Mirror log mismatch. Metadata says %d:%d, kernel says %u:%u.",
+ info.major, info.minor,
+ sm->logs[0].major, sm->logs[0].minor);
+ goto out;
}
- log_very_verbose("Status of log (%s): %s", buf, log_args[2]);
- if (log_args[2][0] != 'A') {
+ log_very_verbose("Status of log (%d:%d): %c.",
+ info.major, info.minor,
+ sm->logs[0].health);
+ if (sm->logs[0].health != DM_STATUS_MIRROR_ALIVE) {
log->status |= PARTIAL_LV;
++failed;
}
}
- for (i = 0; i < num_devs; ++i)
- images[i] = NULL;
-
for (i = 0; i < seg->area_count; ++i) {
- char buf[32];
if (!lv_info(lv->vg->cmd, seg_lv(seg, i), 0, &info, 0, 0)) {
log_error("Check for existence of mirror image %s failed.",
seg_lv(seg, i)->name);
- return 0;
+ goto out;
}
log_debug_activation("Found mirror image at %d:%d", info.major, info.minor);
- sprintf(buf, "%d:%d", info.major, info.minor);
- for (j = 0; j < num_devs; ++j) {
- if (!strcmp(buf, args[j])) {
- log_debug_activation("Match: metadata image %d matches kernel image %d", i, j);
- images[j] = seg_lv(seg, i);
+ for (j = 0; j < sm->dev_count; ++j)
+ if (info.major == (int)sm->devs[j].major &&
+ info.minor == (int)sm->devs[j].minor) {
+ log_very_verbose("Status of image %d: %c.",
+ i, sm->devs[j].health);
+ if (sm->devs[j].health != DM_STATUS_MIRROR_ALIVE) {
+ seg_lv(seg, i)->status |= PARTIAL_LV;
+ ++failed;
+ }
+ break;
}
- }
- }
-
- status = args[2 + num_devs];
-
- for (i = 0; i < num_devs; ++i) {
- if (!images[i]) {
- log_error("Failed to find image %d (%s).", i, args[i]);
- return 0;
- }
- log_very_verbose("Status of image %d: %c", i, status[i]);
- if (status[i] != 'A') {
- images[i]->status |= PARTIAL_LV;
- ++failed;
+ if (j == sm->dev_count) {
+ log_error("Failed to find image %d (%d:%d).",
+ i, info.major, info.minor);
+ goto out;
}
}
@@ -330,7 +263,11 @@ static int _mirrored_transient_status(struct dm_pool *mem, struct lv_segment *se
if (failed)
vg_mark_partial_lvs(lv->vg, 0);
- return 1;
+ r = 1;
+out:
+ dm_pool_free(mem, sm);
+
+ return r;
}
static int _add_log(struct dm_pool *mem, struct lv_segment *seg,
8 years, 4 months
master - lib: pass mem pool to check_transient_status
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=6336ef98d41b8c...
Commit: 6336ef98d41b8c5b1435de08855aa66c8fd527c2
Parent: c717ea5fc0b5096a1655313017611b4305e883d3
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Nov 30 21:24:31 2015 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Dec 1 13:01:28 2015 +0100
lib: pass mem pool to check_transient_status
check_transient_status() may need to allocate some memory,
so pass in already existing mem pool.
---
WHATS_NEW | 1 +
lib/activate/dev_manager.c | 2 +-
lib/metadata/segtype.h | 3 ++-
lib/mirror/mirrored.c | 2 +-
4 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index d2bdb58..dcd2b22 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.137 -
=====================================
+ Add mem pool arg for check_transient_status() target function.
Avoid misleading error with -m is omitted with lvconvert to raid types.
Version 2.02.136 - 28th November 2015
diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c
index 4b37845..4eff5cb 100644
--- a/lib/activate/dev_manager.c
+++ b/lib/activate/dev_manager.c
@@ -1114,7 +1114,7 @@ int dev_manager_transient(struct dev_manager *dm, const struct logical_volume *l
}
if (seg->segtype->ops->check_transient_status &&
- !seg->segtype->ops->check_transient_status(seg, params))
+ !seg->segtype->ops->check_transient_status(dm->mem, seg, params))
goto_out;
} while (next);
diff --git a/lib/metadata/segtype.h b/lib/metadata/segtype.h
index 72c64f9..41adf92 100644
--- a/lib/metadata/segtype.h
+++ b/lib/metadata/segtype.h
@@ -192,7 +192,8 @@ struct segtype_handler {
struct dm_tree_node *node, uint64_t len,
uint32_t *pvmove_mirror_count);
int (*target_status_compatible) (const char *type);
- int (*check_transient_status) (struct lv_segment *seg, char *params);
+ int (*check_transient_status) (struct dm_pool *mem,
+ struct lv_segment *seg, char *params);
int (*target_percent) (void **target_state,
dm_percent_t *percent,
struct dm_pool * mem,
diff --git a/lib/mirror/mirrored.c b/lib/mirror/mirrored.c
index 6e189b2..b810c70 100644
--- a/lib/mirror/mirrored.c
+++ b/lib/mirror/mirrored.c
@@ -213,7 +213,7 @@ static int _mirrored_target_percent(void **target_state,
return 1;
}
-static int _mirrored_transient_status(struct lv_segment *seg, char *params)
+static int _mirrored_transient_status(struct dm_pool *mem, struct lv_segment *seg, char *params)
{
unsigned i, j;
struct logical_volume *lv = seg->lv;
8 years, 4 months
master - tests: unit test for mirror status
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=c717ea5fc0b509...
Commit: c717ea5fc0b5096a1655313017611b4305e883d3
Parent: fa87979004a0bbce2e4e3eacaeab0c4e0e0827eb
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Nov 30 20:54:52 2015 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Dec 1 13:00:52 2015 +0100
tests: unit test for mirror status
---
test/unit/Makefile.in | 5 ++-
test/unit/dmstatus_t.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++
test/unit/run.c | 1 +
test/unit/units.h | 1 +
4 files changed, 77 insertions(+), 2 deletions(-)
diff --git a/test/unit/Makefile.in b/test/unit/Makefile.in
index 13d2f3c..87eaf2b 100644
--- a/test/unit/Makefile.in
+++ b/test/unit/Makefile.in
@@ -1,4 +1,4 @@
-# Copyright (C) 2011-2013 Red Hat, Inc. All rights reserved.
+# Copyright (C) 2011-2015 Red Hat, Inc. All rights reserved.
#
# This file is part of LVM2.
#
@@ -19,6 +19,7 @@ UNITS = \
bitset_t.c\
config_t.c\
dmlist_t.c\
+ dmstatus_t.c\
matcher_t.c\
string_t.c\
run.c
@@ -40,7 +41,7 @@ CFLAGS += @CUNIT_CFLAGS@
check: unit
-$(TARGETS): $(OBJECTS)
+$(TARGETS): $(OBJECTS) $(top_builddir)/libdm/libdevmapper.$(LIB_SUFFIX)
unit: $(TARGETS)
@echo Running unit tests
diff --git a/test/unit/dmstatus_t.c b/test/unit/dmstatus_t.c
new file mode 100644
index 0000000..de6defa
--- /dev/null
+++ b/test/unit/dmstatus_t.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2015 Red Hat, Inc. All rights reserved.
+ *
+ * This file is part of LVM2.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU General Public License v.2.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "units.h"
+
+static struct dm_pool *_mem;
+
+int dmstatus_init(void)
+{
+ _mem = dm_pool_create("dmstatus test", 1024);
+ return (_mem == NULL);
+}
+
+int dmstatus_fini(void)
+{
+ dm_pool_destroy(_mem);
+ return 0;
+}
+
+static void _test_mirror_status(void)
+{
+ struct dm_status_mirror *s = NULL;
+
+ CU_ASSERT(dm_get_status_mirror(_mem,
+ "2 253:1 253:2 80/81 1 AD 3 disk 253:0 A",
+ &s));
+ if (s) {
+ CU_ASSERT_EQUAL(s->total_regions, 81);
+ CU_ASSERT_EQUAL(s->insync_regions, 80);
+ CU_ASSERT_EQUAL(s->dev_count, 2);
+ CU_ASSERT_EQUAL(s->devs[0].health, 'A');
+ CU_ASSERT_EQUAL(s->devs[0].major, 253);
+ CU_ASSERT_EQUAL(s->devs[0].minor, 1);
+ CU_ASSERT_EQUAL(s->devs[1].health, 'D');
+ CU_ASSERT_EQUAL(s->devs[1].major, 253);
+ CU_ASSERT_EQUAL(s->devs[1].minor, 2);
+ CU_ASSERT_EQUAL(s->log_count, 1);
+ CU_ASSERT_EQUAL(s->logs[0].major, 253);
+ CU_ASSERT_EQUAL(s->logs[0].minor, 0);
+ CU_ASSERT_EQUAL(s->logs[0].health, 'A');
+ CU_ASSERT(!strcmp(s->log_type, "disk"));
+ }
+
+ CU_ASSERT(dm_get_status_mirror(_mem,
+ "4 253:1 253:2 253:3 253:4 10/10 1 ADFF 1 core",
+ &s));
+ if (s) {
+ CU_ASSERT_EQUAL(s->total_regions, 10);
+ CU_ASSERT_EQUAL(s->insync_regions, 10);
+ CU_ASSERT_EQUAL(s->dev_count, 4);
+ CU_ASSERT_EQUAL(s->devs[3].minor, 4);
+ CU_ASSERT_EQUAL(s->devs[3].health, 'F');
+ CU_ASSERT_EQUAL(s->log_count, 0);
+ CU_ASSERT(!strcmp(s->log_type, "core"));
+ }
+}
+
+CU_TestInfo dmstatus_list[] = {
+ { (char*)"mirror_status", _test_mirror_status },
+ CU_TEST_INFO_NULL
+};
diff --git a/test/unit/run.c b/test/unit/run.c
index c46266d..5364107 100644
--- a/test/unit/run.c
+++ b/test/unit/run.c
@@ -16,6 +16,7 @@ CU_SuiteInfo suites[] = {
USE(bitset),
USE(config),
USE(dmlist),
+ USE(dmstatus),
USE(regex),
USE(string),
CU_SUITE_INFO_NULL
diff --git a/test/unit/units.h b/test/unit/units.h
index 4ae66b9..5eed535 100644
--- a/test/unit/units.h
+++ b/test/unit/units.h
@@ -26,6 +26,7 @@
DECL(bitset);
DECL(config);
DECL(dmlist);
+DECL(dmstatus);
DECL(regex);
DECL(string);
8 years, 4 months