From dabb54859f44e321b00eaa35e7dbb40e9b120078 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Thu, 28 Jan 2016 10:37:08 -0600 Subject: toollib: keep PV args in the same order --- tools/toollib.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tools/toollib.c b/tools/toollib.c index 9486bc92c..90de9879c 100644 --- a/tools/toollib.c +++ b/tools/toollib.c @@ -3659,6 +3659,18 @@ static struct pvcreate_device *_pvcreate_list_find_dev(struct dm_list *devices, return NULL; } +static struct pvcreate_device *_pvcreate_list_find_name(struct dm_list *devices, const char *name) +{ + struct pvcreate_device *pd; + + dm_list_iterate_items(pd, devices) { + if (!strcmp(pd->name, name)) + return pd; + } + + return NULL; +} + /* * If this function decides that a arg_devices entry cannot be used, but the * command might be able to continue without it, then it moves that entry from @@ -4047,6 +4059,7 @@ int pvcreate_each_device(struct cmd_context *cmd, struct pvcreate_prompt *prompt, *prompt2; struct physical_volume *pv; struct volume_group *orphan_vg; + struct dm_list arg_sort; struct pv_list *pvl; struct pv_list *vgpvl; const char *pv_name; @@ -4055,6 +4068,8 @@ int pvcreate_each_device(struct cmd_context *cmd, int found; int i; + dm_list_init(&arg_sort); + handle->custom_handle = pp; /* @@ -4274,6 +4289,15 @@ int pvcreate_each_device(struct cmd_context *cmd, do_command: + /* + * Reorder arg_process entries to match the original order of args. + */ + dm_list_splice(&arg_sort, &pp->arg_process); + for (i = 0; i < pp->pv_count; i++) { + if ((pd = _pvcreate_list_find_name(&arg_sort, pp->pv_names[i]))) + dm_list_move(&pp->arg_process, &pd->list); + } + if (pp->is_remove) dm_list_splice(&pp->arg_remove, &pp->arg_process); else -- cgit v1.2.1