Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 885490 Details for
Bug 1070381
LVM: Allow the use of VGUUID in place of the vgname
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
patch
0001-toollib-handle-vg-uuid-args-in-process_each_vg.patch (text/plain), 9.78 KB, created by
David Teigland
on 2014-04-11 16:41:10 UTC
(
hide
)
Description:
patch
Filename:
MIME Type:
Creator:
David Teigland
Created:
2014-04-11 16:41:10 UTC
Size:
9.78 KB
patch
obsolete
>From e3f3a3939baacedb8fdb4c845c7386bdfe4c1238 Mon Sep 17 00:00:00 2001 >From: David Teigland <teigland@redhat.com> >Date: Mon, 10 Mar 2014 12:25:50 -0500 >Subject: [PATCH 1/3] toollib: handle vg uuid args in process_each_vg > >VG uuids can be used in place of VG names as command >args for commands using process_each_vg. The command >line uuid format includes dashes. > >As with tags, processing vg uuid args requires >process_each_vg to read all vgs to match their >uuid against the uuid args. > >If a command line uuid arg matches one vg's name >and another vg's uuid, the vg with matching name >will be selected. >--- > lib/uuid/uuid.c | 34 ++++++++++--- > lib/uuid/uuid.h | 5 ++ > tools/toollib.c | 151 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- > 3 files changed, 178 insertions(+), 12 deletions(-) > >diff --git a/lib/uuid/uuid.c b/lib/uuid/uuid.c >index c85b822d7db2..bb5736770de7 100644 >--- a/lib/uuid/uuid.c >+++ b/lib/uuid/uuid.c >@@ -132,21 +132,28 @@ static void _build_inverse(void) > _inverse_c[(int) *ptr] = (char) 0x1; > } > >-int id_valid(struct id *id) >+static int _id_valid(struct id *id, int with_err) > { > int i; > > _build_inverse(); > >- for (i = 0; i < ID_LEN; i++) >+ for (i = 0; i < ID_LEN; i++) { > if (!_inverse_c[id->uuid[i]]) { >- log_error("UUID contains invalid character"); >+ if (with_err) >+ log_error("UUID contains invalid character"); > return 0; > } >+ } > > return 1; > } > >+int id_valid(struct id *id) >+{ >+ return _id_valid(id, 1); >+} >+ > int id_equal(const struct id *lhs, const struct id *rhs) > { > return !memcmp(lhs->uuid, rhs->uuid, sizeof(lhs->uuid)); >@@ -179,7 +186,7 @@ int id_write_format(const struct id *id, char *buffer, size_t size) > return 1; > } > >-int id_read_format(struct id *id, const char *buffer) >+static int _id_read_format(struct id *id, const char *buffer, int with_err) > { > int out = 0; > >@@ -192,7 +199,8 @@ int id_read_format(struct id *id, const char *buffer) > } > > if (out >= ID_LEN) { >- log_error("Too many characters to be uuid."); >+ if (with_err) >+ log_error("Too many characters to be uuid."); > return 0; > } > >@@ -200,12 +208,22 @@ int id_read_format(struct id *id, const char *buffer) > } > > if (out != ID_LEN) { >- log_error("Couldn't read uuid: incorrect number of " >- "characters."); >+ if (with_err) >+ log_error("Couldn't read uuid: incorrect number of characters."); > return 0; > } > >- return id_valid(id); >+ return _id_valid(id, with_err); >+} >+ >+int id_read_format(struct id *id, const char *buffer) >+{ >+ return _id_read_format(id, buffer, 1); >+} >+ >+int id_test_format(struct id *id, const char *buffer) >+{ >+ return _id_read_format(id, buffer, 0); > } > > char *id_format_and_copy(struct dm_pool *mem, const struct id *id) >diff --git a/lib/uuid/uuid.h b/lib/uuid/uuid.h >index d39ad88245e6..6713a7abdac2 100644 >--- a/lib/uuid/uuid.h >+++ b/lib/uuid/uuid.h >@@ -58,6 +58,11 @@ int id_write_format(const struct id *id, char *buffer, size_t size); > */ > int id_read_format(struct id *id, const char *buffer); > >+/* >+ * id_read_format without reporting errors. >+ */ >+int id_test_format(struct id *id, const char *buffer); >+ > char *id_format_and_copy(struct dm_pool *mem, const struct id *id); > > #endif >diff --git a/tools/toollib.c b/tools/toollib.c >index dab663afa8bc..951337114f0e 100644 >--- a/tools/toollib.c >+++ b/tools/toollib.c >@@ -1211,6 +1211,29 @@ struct name_id_list { > const char *uuid; > }; > >+static int name_id_list_match_uuid(const struct dm_list *nll, >+ const struct id *uuid) >+{ >+ struct name_id_list *nl; >+ >+ dm_list_iterate_items(nl, nll) { >+ if (nl->uuid && id_equal((const struct id *)nl->uuid, uuid)) >+ return 1; >+ } >+ return 0; >+} >+ >+static void name_id_list_del_uuid(const struct dm_list *nll, >+ const struct id *uuid) >+{ >+ struct name_id_list *nl, *nl_safe; >+ >+ dm_list_iterate_items_safe(nl, nl_safe, nll) { >+ if (nl->uuid && id_equal((const struct id *)nl->uuid, uuid)) >+ dm_list_del(&nl->list); >+ } >+} >+ > static int get_arg_vgnames(struct cmd_context *cmd, > int argc, char **argv, > struct dm_list *arg_vgnames, >@@ -1306,12 +1329,17 @@ out: > static int process_vg_name_list(struct cmd_context *cmd, uint32_t flags, > struct dm_list *use_vgnames, > struct dm_list *arg_vgnames, >+ struct dm_list *arg_vguuids, > struct dm_list *arg_tags, > void *handle, > process_single_vg_fn_t process_single_vg) > { >- struct volume_group *vg; >+ char uuid[64] __attribute__((aligned(8))); >+ struct id id_vg_name; >+ struct dm_list use_tmp; > struct name_id_list *nl; >+ struct name_id_list *nl_safe; >+ struct volume_group *vg; > const char *vg_name; > const char *vg_uuid; > int ret_max = ECMD_PROCESSED; >@@ -1319,9 +1347,37 @@ static int process_vg_name_list(struct cmd_context *cmd, uint32_t flags, > int process_all = 0; > int process_vg; > >- if (dm_list_empty(arg_vgnames) && dm_list_empty(arg_tags)) >+ if (dm_list_empty(arg_vgnames) && >+ dm_list_empty(arg_vguuids) && >+ dm_list_empty(arg_tags)) > process_all = 1; > >+ if (!process_all && !dm_list_empty(arg_vguuids)) { >+ /* >+ * Priority is to match arg_vguuid items with vg names >+ * before vg uuids. This requires sorting use_vgnames so >+ * items matching arg_vguuids are at the front of the list >+ * so they are matched first. >+ */ >+ dm_list_init(&use_tmp); >+ >+ dm_list_iterate_items_safe(nl, nl_safe, use_vgnames) { >+ if (!id_test_format(&id_vg_name, nl->name)) >+ continue; >+ >+ if (!name_id_list_match_uuid(arg_vguuids, &id_vg_name)) >+ continue; >+ >+ dm_list_del(&nl->list); >+ dm_list_add(&use_tmp, &nl->list); >+ } >+ >+ dm_list_iterate_items_safe(nl, nl_safe, &use_tmp) { >+ dm_list_del(&nl->list); >+ dm_list_add_h(use_vgnames, &nl->list); >+ } >+ } >+ > dm_list_iterate_items(nl, use_vgnames) { > vg_name = nl->name; > vg_uuid = nl->uuid; >@@ -1349,6 +1405,21 @@ static int process_vg_name_list(struct cmd_context *cmd, uint32_t flags, > str_list_match_list(arg_tags, &vg->tags, NULL)) > process_vg = 1; > >+ if (!process_vg && !dm_list_empty(arg_vguuids)) { >+ if (!id_test_format(&id_vg_name, vg_name)) >+ memset(&id_vg_name, 0, sizeof(id_vg_name)); >+ >+ if (id_vg_name.uuid[0] && >+ name_id_list_match_uuid(arg_vguuids, &id_vg_name)) { >+ process_vg = 1; >+ name_id_list_del_uuid(arg_vguuids, &id_vg_name); >+ >+ } else if (name_id_list_match_uuid(arg_vguuids, &vg->id)) { >+ process_vg = 1; >+ name_id_list_del_uuid(arg_vguuids, &vg->id); >+ } >+ } >+ > if (process_vg) > ret = process_single_vg(cmd, vg_name, vg, handle); > >@@ -1363,6 +1434,15 @@ static int process_vg_name_list(struct cmd_context *cmd, uint32_t flags, > break; > } > >+ dm_list_iterate_items(nl, arg_vguuids) { >+ if (!nl->uuid) >+ continue; >+ if (!id_write_format((const struct id *)nl->uuid, uuid, sizeof(uuid))) >+ continue; >+ log_error("Volume group \"%s\" not found", uuid); >+ ret_max = ECMD_FAILED; >+ } >+ > return ret_max; > } > >@@ -1391,6 +1471,52 @@ static int copy_str_to_name_list(struct cmd_context *cmd, > return ECMD_PROCESSED; > } > >+/* >+ * If the vg name (from command args) is a valid uuid, then >+ * remove it from arg_vgnames, and add it to arg_vguuids. >+ * >+ * arg_vgnames is a str_list, arg_vguuids is a name_id_list >+ * >+ * The vg name which resembles a uuid is saved in nl->uuid. >+ * >+ * The format of the uuid arg contains dashes, but internal >+ * uuid strings do not. >+ */ >+ >+static int get_arg_vguuids(struct cmd_context *cmd, >+ struct dm_list *arg_vgnames, >+ struct dm_list *arg_vguuids) >+{ >+ const char *name; >+ struct str_list *sl, *sl_safe; >+ struct name_id_list *nl; >+ struct id uuid; >+ >+ /* TODO: check a config option to enable this behavior? */ >+ >+ dm_list_iterate_items_safe(sl, sl_safe, arg_vgnames) { >+ name = sl->str; >+ >+ /* does not copy "-" chars from name to uuid */ >+ if (!id_test_format(&uuid, name)) >+ continue; >+ >+ dm_list_del(&sl->list); >+ >+ nl = dm_pool_alloc(cmd->mem, sizeof(struct name_id_list)); >+ if (!nl) { >+ log_error("name_id_list allocation failed"); >+ return ECMD_FAILED; >+ } >+ >+ nl->name = NULL; >+ nl->uuid = dm_pool_strdup(cmd->mem, (char *)uuid.uuid); >+ >+ dm_list_add(arg_vguuids, &nl->list); >+ } >+ return ECMD_PROCESSED; >+} >+ > int process_each_vg(struct cmd_context *cmd, > int argc, char **argv, uint32_t flags, > void *handle, >@@ -1398,6 +1524,7 @@ int process_each_vg(struct cmd_context *cmd, > { > struct dm_list arg_tags; /* str_list */ > struct dm_list arg_vgnames; /* str_list */ >+ struct dm_list arg_vguuids; /* name_id_list */ > struct dm_list all_vgnames; /* name_id_list */ > struct dm_list use_vgnames; /* name_id_list */ > int enable_all_vgs = (cmd->command->flags & ENABLE_ALL_VGS); >@@ -1405,6 +1532,7 @@ int process_each_vg(struct cmd_context *cmd, > > dm_list_init(&arg_tags); > dm_list_init(&arg_vgnames); >+ dm_list_init(&arg_vguuids); > dm_list_init(&all_vgnames); > dm_list_init(&use_vgnames); > >@@ -1412,8 +1540,23 @@ int process_each_vg(struct cmd_context *cmd, > if (ret != ECMD_PROCESSED) > return ret; > >+ ret = get_arg_vguuids(cmd, &arg_vgnames, &arg_vguuids); >+ if (ret != ECMD_PROCESSED) >+ return ret; >+ >+ /* >+ * Cases were all vg names are needed: >+ * - There are no vg names specified and the command >+ * wants to process all when none are named. >+ * - There are tags specified, which means all vgs must >+ * be read and checked to see if they have a matching tag. >+ * - There are vg uuids specified, which means all vgs must >+ * be read and checked to see if they have a matching uuid. >+ */ >+ > if ((dm_list_empty(&arg_vgnames) && enable_all_vgs) || >- !dm_list_empty(&arg_tags)) { >+ !dm_list_empty(&arg_tags) || >+ !dm_list_empty(&arg_vguuids)) { > ret = get_all_vgnames(cmd, &all_vgnames, 0); > if (ret != ECMD_PROCESSED) > return ret; >@@ -1433,7 +1576,7 @@ int process_each_vg(struct cmd_context *cmd, > } > > ret = process_vg_name_list(cmd, flags, &use_vgnames, >- &arg_vgnames, &arg_tags, >+ &arg_vgnames, &arg_vguuids, &arg_tags, > handle, process_single_vg); > return ret; > } >-- >1.8.3.1 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 1070381
: 885490 |
885491