master - log: use full buffer size for printf
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=20acc66a237429...
Commit: 20acc66a237429d81b699b56be57d4d043362098
Parent: 20483ead5bbc74b68126dfadec7b5f98f41b3400
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Dec 3 15:28:01 2015 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Dec 3 18:01:42 2015 +0100
log: use full buffer size for printf
Pass full buffer size to printf() function - no reason to make
buffer 1 char smaller.
Also rename locn buffer to message buffer directly since it's
not used for anything else.
TODO: we may use same buffer also for 'buf[]' since there is
no collision - so may safe 1K on stack usage.
---
WHATS_NEW | 1 +
lib/log/log.c | 24 +++++++++++++-----------
2 files changed, 14 insertions(+), 11 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 7ade066..c39eae4 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.137 -
=====================================
+ Cleaned logging code for buffer size usage.
Added internal id_read_format_try() function to check and read valid UUID.
Use dm_get_status_mirror() instead of individual parsers.
Add mem pool arg for check_transient_status() target function.
diff --git a/lib/log/log.c b/lib/log/log.c
index c44c3d4..fc52bdd 100644
--- a/lib/log/log.c
+++ b/lib/log/log.c
@@ -264,9 +264,8 @@ void print_log(int level, const char *file, int line, int dm_errno_or_class,
const char *format, ...)
{
va_list ap;
- char buf[1024], locn[4096];
+ char buf[1024], message[4096];
int bufused, n;
- const char *message;
const char *trformat; /* Translated format string */
char *newbuf;
int use_stderr = level & _LOG_STDERR;
@@ -315,17 +314,16 @@ void print_log(int level, const char *file, int line, int dm_errno_or_class,
(_store_errmsg && (level <= _LOG_ERR)) ||
log_once) {
va_start(ap, format);
- n = vsnprintf(locn, sizeof(locn) - 1, trformat, ap);
+ n = vsnprintf(message, sizeof(message), trformat, ap);
va_end(ap);
+ /* When newer glibc returns >= sizeof(locn), we will just log what
+ * has fit into buffer, it's '\0' terminated string */
if (n < 0) {
fprintf(stderr, _("vsnprintf failed: skipping external "
"logging function"));
goto log_it;
}
-
- locn[sizeof(locn) - 1] = '\0';
- message = locn;
}
/* FIXME Avoid pointless use of message buffer when it'll never be read! */
@@ -441,20 +439,24 @@ void print_log(int level, const char *file, int line, int dm_errno_or_class,
_already_logging = 1;
memset(&buf, ' ', sizeof(buf));
bufused = 0;
- if ((n = dm_snprintf(buf, sizeof(buf) - 1,
+ if ((n = dm_snprintf(buf, sizeof(buf),
"%s:%d %s%s", file, line, log_command_name(),
_msg_prefix)) == -1)
goto done;
- bufused += n;
+ bufused += n; /* n does not include '\0' */
va_start(ap, format);
- n = vsnprintf(buf + bufused - 1, sizeof(buf) - bufused - 1,
+ n = vsnprintf(buf + bufused, sizeof(buf) - bufused,
trformat, ap);
va_end(ap);
- bufused += n;
- buf[bufused - 1] = '\n';
+ if (n < 0)
+ goto done;
+
+ bufused += n;
+ if (n >= sizeof(buf))
+ bufused = sizeof(buf) - 1;
done:
buf[bufused] = '\n';
buf[sizeof(buf) - 1] = '\n';
8 years, 5 months
master - cleanup: use try_id_read_format
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=20483ead5bbc74...
Commit: 20483ead5bbc74b68126dfadec7b5f98f41b3400
Parent: c15c44a4924e07d96cea04672fbcd45c7d8aa7ab
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Dec 3 15:26:44 2015 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Dec 3 18:00:54 2015 +0100
cleanup: use try_id_read_format
Better then using log_suppress in this case.
---
tools/toollib.c | 7 ++-----
tools/vgrename.c | 4 +---
2 files changed, 3 insertions(+), 8 deletions(-)
diff --git a/tools/toollib.c b/tools/toollib.c
index 3980a88..e03aaf7 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -2101,11 +2101,8 @@ static void _choose_vgs_to_process(struct cmd_context *cmd,
* matches the UUID of a VG. (--select should generally
* be used to select a VG by uuid instead.)
*/
- if (!found && (cmd->command->flags & ALLOW_UUID_AS_NAME)) {
- log_suppress(2);
- arg_is_uuid = id_read_format(&id, sl->str);
- log_suppress(0);
- }
+ if (!found && (cmd->command->flags & ALLOW_UUID_AS_NAME))
+ arg_is_uuid = id_read_format_try(&id, sl->str);
if (!found && arg_is_uuid) {
dm_list_iterate_items_safe(vgnl, vgnl2, vgnameids_on_system) {
diff --git a/tools/vgrename.c b/tools/vgrename.c
index 07d992e..9e6beec 100644
--- a/tools/vgrename.c
+++ b/tools/vgrename.c
@@ -107,9 +107,7 @@ static int vg_rename_path(struct cmd_context *cmd, const char *old_vg_path,
}
}
- log_suppress(2);
- found_id = id_read_format(&id, vg_name_old);
- log_suppress(0);
+ found_id = id_read_format_try(&id, vg_name_old);
if (found_id && (vg_name = lvmcache_vgname_from_vgid(cmd->mem, (char *)id.uuid))) {
if (!strcmp(vg_name, vg_name_new)) {
8 years, 5 months
master - uuid: add id_read_format_try
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=c15c44a4924e07...
Commit: c15c44a4924e07d96cea04672fbcd45c7d8aa7ab
Parent: aec58c862064e2b9dd5b0ebb54473340ebd97f7f
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Dec 3 15:25:09 2015 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Dec 3 18:00:38 2015 +0100
uuid: add id_read_format_try
Provide id_read_format() functionality without log_error
when ID is not valid one - it will just return 0.
Does not need to use log_suppress() then.
---
WHATS_NEW | 1 +
lib/uuid/uuid.c | 33 ++++++++++++++++++++++++++-------
lib/uuid/uuid.h | 4 ++++
3 files changed, 31 insertions(+), 7 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index d9222bc..7ade066 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.137 -
=====================================
+ Added internal id_read_format_try() function to check and read valid UUID.
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/lib/uuid/uuid.c b/lib/uuid/uuid.c
index 67162dd..cfc58b0 100644
--- a/lib/uuid/uuid.c
+++ b/lib/uuid/uuid.c
@@ -132,7 +132,7 @@ 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 e)
{
int i;
@@ -140,13 +140,20 @@ int id_valid(struct id *id)
for (i = 0; i < ID_LEN; i++)
if (!_inverse_c[id->uuid[i]]) {
- log_error("UUID contains invalid character '%c'", id->uuid[i]);
+ if (e)
+ log_error("UUID contains invalid character '%c'", id->uuid[i]);
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 e)
{
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 (e)
+ log_error("Too many characters to be uuid.");
return 0;
}
@@ -200,12 +208,23 @@ 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 (e)
+ log_error("Couldn't read uuid: incorrect number of "
+ "characters.");
return 0;
}
- return id_valid(id);
+ return _id_valid(id, e);
+}
+
+int id_read_format(struct id *id, const char *buffer)
+{
+ return _id_read_format(id, buffer, 1);
+}
+
+int id_read_format_try(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 d87de73..8ca6352 100644
--- a/lib/uuid/uuid.h
+++ b/lib/uuid/uuid.h
@@ -56,6 +56,10 @@ int id_write_format(const struct id *id, char *buffer, size_t size);
* Reads a formatted uuid.
*/
int id_read_format(struct id *id, const char *buffer);
+/*
+ * Tries to read a formatted uuid without logging error for invalid ID
+ */
+int id_read_format_try(struct id *id, const char *buffer);
char *id_format_and_copy(struct dm_pool *mem, const struct id *id);
8 years, 5 months
master - lvconvert: Reinstate mirror to raid conversions.
by Alasdair Kergon
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=aec58c862064e2...
Commit: aec58c862064e2b9dd5b0ebb54473340ebd97f7f
Parent: 3bbf89e9ec92388cbfa722c0fbb6ff3fad0232aa
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Thu Dec 3 14:40:14 2015 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Thu Dec 3 14:40:14 2015 +0000
lvconvert: Reinstate mirror to raid conversions.
Reinstate conversions from mirror to raid stopped
by commit 46c8d6bb8ae91ee67c8633496cc6c3d92bb4f3ce
(lvconvert: Improve message for raid without -m).
---
tools/lvconvert.c | 9 +++++++--
1 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index b309b9e..82b804f 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -242,9 +242,9 @@ static int _check_conversion_type(struct cmd_context *cmd, const char *type_str)
if (!type_str || !*type_str)
return 1;
- if (!strcmp(type_str, "mirror") || !strncmp(type_str, "raid", 4)) {
+ if (!strcmp(type_str, "mirror")) {
if (!arg_count(cmd, mirrors_ARG)) {
- log_error("Mirror and raid conversions require -m/--mirrors");
+ log_error("Conversions to --type mirror require -m/--mirrors");
return 0;
}
return 1;
@@ -1734,6 +1734,11 @@ static int _lvconvert_raid(struct logical_volume *lv, struct lvconvert_params *l
return 0;
}
+ if (seg_is_linear(seg) && !arg_count(cmd, mirrors_ARG)) {
+ log_error("Raid conversions require -m/--mirrors");
+ return 0;
+ }
+
/* Change number of RAID1 images */
if (arg_count(cmd, mirrors_ARG) || arg_count(cmd, splitmirrors_ARG)) {
image_count = lv_raid_image_count(lv);
8 years, 5 months
master - man lvm: add section about unique VG names
by David Teigland
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=3bbf89e9ec9238...
Commit: 3bbf89e9ec92388cbfa722c0fbb6ff3fad0232aa
Parent: 61573bd1972702f1066c3df5543acc47e9e35da8
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Wed Dec 2 10:37:25 2015 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Wed Dec 2 10:37:25 2015 -0600
man lvm: add section about unique VG names
---
man/lvm.8.in | 22 ++++++++++++++++++++++
1 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/man/lvm.8.in b/man/lvm.8.in
index 31f7187..4e9e1dd 100644
--- a/man/lvm.8.in
+++ b/man/lvm.8.in
@@ -502,6 +502,28 @@ amendment when the software is updated. Should you need to process the node
names in /dev/mapper, you may use \fBdmsetup splitname\fP to separate out the
original VG, LV and internal layer names.
.
+.SH UNIQUE NAMES
+.
+
+VG names should be unique. vgcreate will produce an error if the
+specified VG name matches an existing VG name. However, there are cases
+where different VGs with the same name can appear to LVM, e.g. after
+moving disks or changing filters.
+
+When VGs with the same name exist, commands operating on all VGs will
+include all of the VGs with the same name. If the ambiguous VG name is
+specified on the command line, the command will produce an error. The
+error states that multiple VGs exist with the specified name. To process
+one of the VGs specifically, the --select option should be used with the
+UUID of the intended VG: '--select vg_uuid=<uuid>'.
+
+An exception is if all but one of the VGs with the shared name is foreign
+(see
+.BR lvmsystemid (7).)
+In this case, the one VG that is not foreign is assumed to be the intended
+VG and is processed.
+
+.
.SH ALLOCATION
.
When an operation needs to allocate Physical Extents for one or more
8 years, 5 months
master - toollib: only interpret vgname arg as uuid for vgrename
by David Teigland
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=61573bd1972702...
Commit: 61573bd1972702f1066c3df5543acc47e9e35da8
Parent: 166adf0e1fb01f0557a068086a73d9d40f9e5652
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Tue Dec 1 15:50:14 2015 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Tue Dec 1 15:50:14 2015 -0600
toollib: only interpret vgname arg as uuid for vgrename
In general, --select should be used to specify a VG by UUID,
but vgrename already allows a uuid to be substituted for
the name, so continue to allow it in that case.
---
tools/commands.h | 2 +-
tools/toollib.c | 11 ++++-------
tools/tools.h | 2 ++
3 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/tools/commands.h b/tools/commands.h
index 5770bf3..8c5162b 100644
--- a/tools/commands.h
+++ b/tools/commands.h
@@ -1323,7 +1323,7 @@ xx(vgremove,
xx(vgrename,
"Rename a volume group",
- 0,
+ ALLOW_UUID_AS_NAME,
"vgrename\n"
"\t[-A|--autobackup y|n]\n"
"\t[--commandprofile ProfileName]\n"
diff --git a/tools/toollib.c b/tools/toollib.c
index 8e4db5e..3980a88 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -2081,7 +2081,7 @@ static void _choose_vgs_to_process(struct cmd_context *cmd,
struct dm_str_list *sl, *sl2;
struct vgnameid_list *vgnl, *vgnl2;
struct id id;
- int arg_is_uuid;
+ int arg_is_uuid = 0;
int found;
dm_list_iterate_items_safe(sl, sl2, arg_vgnames) {
@@ -2098,13 +2098,10 @@ static void _choose_vgs_to_process(struct cmd_context *cmd,
/*
* If the VG name arg looks like a UUID, then check if it
- * matches the UUID of a VG.
- *
- * FIXME: Do we want to allow vgname args to be interpretted
- * as uuids for all commands or only some (e.g. vgrename)?
- * If only some, then use a cmd flag to enable this.
+ * matches the UUID of a VG. (--select should generally
+ * be used to select a VG by uuid instead.)
*/
- if (!found) {
+ if (!found && (cmd->command->flags & ALLOW_UUID_AS_NAME)) {
log_suppress(2);
arg_is_uuid = id_read_format(&id, sl->str);
log_suppress(0);
diff --git a/tools/tools.h b/tools/tools.h
index 27061fc..010fbf4 100644
--- a/tools/tools.h
+++ b/tools/tools.h
@@ -99,6 +99,8 @@ 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
+/* Command may try to interpret a vgname arg as a uuid. */
+#define ALLOW_UUID_AS_NAME 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. */
8 years, 5 months
master - toollib: allow VG UUID to be used in place of VG name
by David Teigland
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=166adf0e1fb01f...
Commit: 166adf0e1fb01f0557a068086a73d9d40f9e5652
Parent: 67763a9bec03415996903a97916b234252fb150d
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Tue Dec 1 12:00:57 2015 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Tue Dec 1 12:08:24 2015 -0600
toollib: allow VG UUID to be used in place of VG name
If the VG arg from the command line does not match the
name of any known VGs, then check if the arg looks like
a UUID. If it's a valid UUID, then compare it to the
UUID of known VGs. If it matches the UUID of a known VG,
then process that VG.
---
tools/toollib.c | 39 +++++++++++++++++++++++++++++++++++++++
1 files changed, 39 insertions(+), 0 deletions(-)
diff --git a/tools/toollib.c b/tools/toollib.c
index e49356f..8e4db5e 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -2077,8 +2077,11 @@ static void _choose_vgs_to_process(struct cmd_context *cmd,
struct dm_list *vgnameids_on_system,
struct dm_list *vgnameids_to_process)
{
+ char uuid[64] __attribute__((aligned(8)));
struct dm_str_list *sl, *sl2;
struct vgnameid_list *vgnl, *vgnl2;
+ struct id id;
+ int arg_is_uuid;
int found;
dm_list_iterate_items_safe(sl, sl2, arg_vgnames) {
@@ -2092,6 +2095,42 @@ static void _choose_vgs_to_process(struct cmd_context *cmd,
found = 1;
break;
}
+
+ /*
+ * If the VG name arg looks like a UUID, then check if it
+ * matches the UUID of a VG.
+ *
+ * FIXME: Do we want to allow vgname args to be interpretted
+ * as uuids for all commands or only some (e.g. vgrename)?
+ * If only some, then use a cmd flag to enable this.
+ */
+ if (!found) {
+ log_suppress(2);
+ arg_is_uuid = id_read_format(&id, sl->str);
+ log_suppress(0);
+ }
+
+ if (!found && arg_is_uuid) {
+ dm_list_iterate_items_safe(vgnl, vgnl2, vgnameids_on_system) {
+ if (!(id_write_format((const struct id*)vgnl->vgid, uuid, sizeof(uuid))))
+ continue;
+
+ if (strcmp(sl->str, uuid))
+ continue;
+
+ log_print("Processing VG %s because of matching UUID %s",
+ vgnl->vg_name, uuid);
+
+ dm_list_del(&vgnl->list);
+ dm_list_add(vgnameids_to_process, &vgnl->list);
+
+ /* Make the arg_vgnames entry use the actual VG name. */
+ sl->str = dm_pool_strdup(cmd->mem, vgnl->vg_name);
+
+ found = 1;
+ break;
+ }
+ }
/*
* If the name arg was not found in the list of all VGs, then
8 years, 5 months
master - lvresize: use process_each_vg
by David Teigland
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=67763a9bec0341...
Commit: 67763a9bec03415996903a97916b234252fb150d
Parent: 5bbbd37f414bdbf31776d09af1c937635205ab2d
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Tue Dec 1 11:01:26 2015 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Tue Dec 1 11:01:26 2015 -0600
lvresize: use process_each_vg
No functional change.
---
tools/lvresize.c | 63 +++++++++++++++++++++++++++++------------------------
1 files changed, 34 insertions(+), 29 deletions(-)
diff --git a/tools/lvresize.c b/tools/lvresize.c
index 3188f27..da97205 100644
--- a/tools/lvresize.c
+++ b/tools/lvresize.c
@@ -163,51 +163,56 @@ static int _lvresize_params(struct cmd_context *cmd, int argc, char **argv,
return 1;
}
-int lvresize(struct cmd_context *cmd, int argc, char **argv)
+static int _lvresize_single(struct cmd_context *cmd, const char *vg_name,
+ struct volume_group *vg, struct processing_handle *handle)
{
- struct lvresize_params lp = { 0 };
- struct volume_group *vg;
+ struct lvresize_params *lp = (struct lvresize_params *) handle->custom_handle;
struct dm_list *pvh = NULL;
struct logical_volume *lv;
- uint32_t lockd_state = 0;
- int r = ECMD_FAILED;
-
- if (!_lvresize_params(cmd, argc, argv, &lp))
- return EINVALID_CMD_LINE;
-
- if (!lockd_vg(cmd, lp.vg_name, "ex", 0, &lockd_state))
- return_ECMD_FAILED;
-
- log_verbose("Finding volume group %s", lp.vg_name);
- vg = vg_read_for_update(cmd, lp.vg_name, NULL, 0, lockd_state);
- if (vg_read_error(vg)) {
- release_vg(vg);
- return_ECMD_FAILED;
- }
+ int ret = ECMD_FAILED;
/* Does LV exist? */
- if (!(lv = find_lv(vg, lp.lv_name))) {
+ if (!(lv = find_lv(vg, lp->lv_name))) {
log_error("Logical volume %s not found in volume group %s",
- lp.lv_name, lp.vg_name);
+ lp->lv_name, lp->vg_name);
goto out;
}
- if (!(pvh = lp.argc ? create_pv_list(cmd->mem, vg, lp.argc,
- lp.argv, 1) : &vg->pvs))
+ if (!(pvh = lp->argc ? create_pv_list(cmd->mem, vg, lp->argc, lp->argv, 1) : &vg->pvs))
goto_out;
- if (!lv_resize_prepare(cmd, lv, &lp, pvh)) {
- r = EINVALID_CMD_LINE;
+ if (!lv_resize_prepare(cmd, lv, lp, pvh)) {
+ ret = EINVALID_CMD_LINE;
goto_out;
}
- if (!lv_resize(cmd, lv, &lp, pvh))
+ if (!lv_resize(cmd, lv, lp, pvh))
goto_out;
- r = ECMD_PROCESSED;
-
+ ret = ECMD_PROCESSED;
out:
- unlock_and_release_vg(cmd, vg, lp.vg_name);
+ return ret;
+}
+
+int lvresize(struct cmd_context *cmd, int argc, char **argv)
+{
+ struct processing_handle *handle = NULL;
+ struct lvresize_params lp = { 0 };
+ int ret = ECMD_FAILED;
+
+ if (!_lvresize_params(cmd, argc, argv, &lp))
+ return EINVALID_CMD_LINE;
+
+ if (!(handle = init_processing_handle(cmd))) {
+ log_error("Failed to initialize processing handle.");
+ return ECMD_FAILED;
+ }
+
+ handle->custom_handle = &lp;
+
+ ret = process_each_vg(cmd, 0, NULL, lp.vg_name, READ_FOR_UPDATE, handle,
+ &_lvresize_single);
- return r;
+ destroy_processing_handle(cmd, handle);
+ return ret;
}
8 years, 5 months
master - lvrename: use process_each_vg
by David Teigland
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=5bbbd37f414bdb...
Commit: 5bbbd37f414bdbf31776d09af1c937635205ab2d
Parent: f7571eb287ff3810d93485f6be7d5e1fad2bb250
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Tue Dec 1 09:54:33 2015 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Tue Dec 1 09:54:33 2015 -0600
lvrename: use process_each_vg
No functional change.
---
tools/lvrename.c | 93 +++++++++++++++++++++++++++++++++---------------------
1 files changed, 57 insertions(+), 36 deletions(-)
diff --git a/tools/lvrename.c b/tools/lvrename.c
index 7b0791a..18b02d2 100644
--- a/tools/lvrename.c
+++ b/tools/lvrename.c
@@ -15,20 +15,61 @@
#include "tools.h"
+struct lvrename_params {
+ const char *lv_name_old;
+ const char *lv_name_new;
+};
+
+static int _lvrename_single(struct cmd_context *cmd, const char *vg_name,
+ struct volume_group *vg, struct processing_handle *handle)
+{
+ struct lvrename_params *lp = (struct lvrename_params *) handle->custom_handle;
+ struct lv_list *lvl;
+ int ret = ECMD_FAILED;
+
+ if (!(lvl = find_lv_in_vg(vg, lp->lv_name_old))) {
+ log_error("Existing logical volume \"%s\" not found in "
+ "volume group \"%s\"", lp->lv_name_old, vg_name);
+ goto bad;
+ }
+
+ if (lv_is_raid_image(lvl->lv) || lv_is_raid_metadata(lvl->lv)) {
+ log_error("Cannot rename a RAID %s directly",
+ lv_is_raid_image(lvl->lv) ? "image" :
+ "metadata area");
+ goto bad;
+ }
+
+ if (lv_is_raid_with_tracking(lvl->lv)) {
+ log_error("Cannot rename %s while it is tracking a split image",
+ lvl->lv->name);
+ goto bad;
+ }
+
+ if (!lv_rename(cmd, lvl->lv, lp->lv_name_new))
+ goto_bad;
+
+ log_print_unless_silent("Renamed \"%s\" to \"%s\" in volume group \"%s\"",
+ lp->lv_name_old, lp->lv_name_new, vg_name);
+
+ ret = ECMD_PROCESSED;
+bad:
+ return ret;
+}
+
/*
* lvrename command implementation.
* Check arguments and call lv_rename() to execute the request.
*/
int lvrename(struct cmd_context *cmd, int argc, char **argv)
{
+ struct processing_handle *handle = NULL;
+ struct lvrename_params lp = { 0 };
size_t maxlen;
char *lv_name_old, *lv_name_new;
const char *vg_name, *vg_name_new, *vg_name_old;
char *st;
- struct volume_group *vg;
- struct lv_list *lvl;
- uint32_t lockd_state = 0;
- int r = ECMD_FAILED;
+ int ret = ECMD_FAILED;
if (argc == 3) {
vg_name = skip_dev_dir(cmd, argv[0], NULL);
@@ -99,43 +140,23 @@ int lvrename(struct cmd_context *cmd, int argc, char **argv)
return EINVALID_CMD_LINE;
}
- if (!lockd_vg(cmd, vg_name, "ex", 0, &lockd_state))
- return_ECMD_FAILED;
+ if (!(lp.lv_name_old = dm_pool_strdup(cmd->mem, lv_name_old)))
+ return ECMD_FAILED;
- log_verbose("Checking for existing volume group \"%s\"", vg_name);
- vg = vg_read_for_update(cmd, vg_name, NULL, 0, lockd_state);
- if (vg_read_error(vg)) {
- release_vg(vg);
- return_ECMD_FAILED;
- }
+ if (!(lp.lv_name_new = dm_pool_strdup(cmd->mem, lv_name_new)))
+ return ECMD_FAILED;
- if (!(lvl = find_lv_in_vg(vg, lv_name_old))) {
- log_error("Existing logical volume \"%s\" not found in "
- "volume group \"%s\"", lv_name_old, vg_name);
- goto bad;
+ if (!(handle = init_processing_handle(cmd))) {
+ log_error("Failed to initialize processing handle.");
+ return ECMD_FAILED;
}
- if (lv_is_raid_image(lvl->lv) || lv_is_raid_metadata(lvl->lv)) {
- log_error("Cannot rename a RAID %s directly",
- lv_is_raid_image(lvl->lv) ? "image" :
- "metadata area");
- goto bad;
- }
+ handle->custom_handle = &lp;
- if (lv_is_raid_with_tracking(lvl->lv)) {
- log_error("Cannot rename %s while it is tracking a split image",
- lvl->lv->name);
- goto bad;
- }
+ ret = process_each_vg(cmd, 0, NULL, vg_name, READ_FOR_UPDATE, handle,
+ _lvrename_single);
- if (!lv_rename(cmd, lvl->lv, lv_name_new))
- goto_bad;
+ destroy_processing_handle(cmd, handle);
+ return ret;
- log_print_unless_silent("Renamed \"%s\" to \"%s\" in volume group \"%s\"",
- lv_name_old, lv_name_new, vg_name);
-
- r = ECMD_PROCESSED;
-bad:
- unlock_and_release_vg(cmd, vg, vg_name);
- return r;
}
8 years, 5 months
master - lvcreate: use process_each_vg
by David Teigland
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=f7571eb287ff38...
Commit: f7571eb287ff3810d93485f6be7d5e1fad2bb250
Parent: ea74215fa1f76cc965efd4f4656ad74321827161
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Mon Nov 30 17:32:49 2015 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Tue Dec 1 09:36:52 2015 -0600
lvcreate: use process_each_vg
No functional change.
---
tools/lvcreate.c | 123 +++++++++++++++++++++++++++++++-----------------------
1 files changed, 71 insertions(+), 52 deletions(-)
diff --git a/tools/lvcreate.c b/tools/lvcreate.c
index 0debf40..e0d665b 100644
--- a/tools/lvcreate.c
+++ b/tools/lvcreate.c
@@ -25,6 +25,11 @@ struct lvcreate_cmdline_params {
uint32_t pv_count;
};
+struct processing_params {
+ struct lvcreate_params *lp;
+ struct lvcreate_cmdline_params *lcp;
+};
+
static int _set_vg_name(struct lvcreate_params *lp, const char *vg_name)
{
/* Can't do anything */
@@ -1445,74 +1450,51 @@ static void _destroy_lvcreate_params(struct lvcreate_params *lp)
}
}
-int lvcreate(struct cmd_context *cmd, int argc, char **argv)
+static int _lvcreate_single(struct cmd_context *cmd, const char *vg_name,
+ struct volume_group *vg, struct processing_handle *handle)
{
- int r = ECMD_FAILED;
- struct lvcreate_params lp = {
- .major = -1,
- .minor = -1,
- };
- struct lvcreate_cmdline_params lcp = { 0 };
- struct volume_group *vg;
- uint32_t lockd_state = 0;
-
- if (!_lvcreate_params(cmd, argc, argv, &lp, &lcp)) {
- stack;
- return EINVALID_CMD_LINE;
- }
-
- if (!_check_pool_parameters(cmd, NULL, &lp, &lcp)) {
- stack;
- return EINVALID_CMD_LINE;
- }
+ struct processing_params *pp = (struct processing_params *) handle->custom_handle;
+ struct lvcreate_params *lp = pp->lp;
+ struct lvcreate_cmdline_params *lcp = pp->lcp;
+ int ret = ECMD_FAILED;
- if (!lockd_vg(cmd, lp.vg_name, "ex", 0, &lockd_state))
- return_ECMD_FAILED;
-
- log_verbose("Finding volume group \"%s\"", lp.vg_name);
- vg = vg_read_for_update(cmd, lp.vg_name, NULL, 0, lockd_state);
- if (vg_read_error(vg)) {
- release_vg(vg);
- return_ECMD_FAILED;
- }
-
- if (!_read_activation_params(cmd, vg, &lp))
+ if (!_read_activation_params(cmd, vg, lp))
goto_out;
/* Resolve segment types with opened VG */
- if (lp.snapshot && lp.origin_name && !_determine_snapshot_type(vg, &lp, &lcp))
+ if (lp->snapshot && lp->origin_name && !_determine_snapshot_type(vg, lp, lcp))
goto_out;
- if (seg_is_cache(&lp) && !_determine_cache_argument(vg, &lp))
+ if (seg_is_cache(lp) && !_determine_cache_argument(vg, lp))
goto_out;
/* All types resolved at this point, now only validation steps */
- if (seg_is_raid(&lp) && !_check_raid_parameters(vg, &lp, &lcp))
+ if (seg_is_raid(lp) && !_check_raid_parameters(vg, lp, lcp))
goto_out;
- if (seg_is_thin(&lp) && !_check_thin_parameters(vg, &lp, &lcp))
+ if (seg_is_thin(lp) && !_check_thin_parameters(vg, lp, lcp))
goto_out;
- if (!_check_pool_parameters(cmd, vg, &lp, &lcp))
+ if (!_check_pool_parameters(cmd, vg, lp, lcp))
goto_out;
/* All types are checked */
- if (!_check_zero_parameters(cmd, &lp))
+ if (!_check_zero_parameters(cmd, lp))
return_0;
- if (!_update_extents_params(vg, &lp, &lcp))
+ if (!_update_extents_params(vg, lp, lcp))
goto_out;
- if (seg_is_thin(&lp) && !_validate_internal_thin_processing(&lp))
+ if (seg_is_thin(lp) && !_validate_internal_thin_processing(lp))
goto_out;
- if (lp.create_pool) {
- if (!handle_pool_metadata_spare(vg, lp.pool_metadata_extents,
- lp.pvh, lp.pool_metadata_spare))
+ if (lp->create_pool) {
+ if (!handle_pool_metadata_spare(vg, lp->pool_metadata_extents,
+ lp->pvh, lp->pool_metadata_spare))
goto_out;
log_verbose("Making pool %s in VG %s using segtype %s",
- lp.pool_name ? : "with generated name", lp.vg_name, lp.segtype->name);
+ lp->pool_name ? : "with generated name", lp->vg_name, lp->segtype->name);
}
if (vg->lock_type && !strcmp(vg->lock_type, "sanlock")) {
@@ -1522,22 +1504,59 @@ int lvcreate(struct cmd_context *cmd, int argc, char **argv)
}
}
- if (seg_is_thin_volume(&lp))
+ if (seg_is_thin_volume(lp))
log_verbose("Making thin LV %s in pool %s in VG %s%s%s using segtype %s",
- lp.lv_name ? : "with generated name",
- lp.pool_name ? : "with generated name", lp.vg_name,
- lp.snapshot ? " as snapshot of " : "",
- lp.snapshot ? lp.origin_name : "", lp.segtype->name);
+ lp->lv_name ? : "with generated name",
+ lp->pool_name ? : "with generated name", lp->vg_name,
+ lp->snapshot ? " as snapshot of " : "",
+ lp->snapshot ? lp->origin_name : "", lp->segtype->name);
if (is_lockd_type(vg->lock_type))
- lp.needs_lockd_init = 1;
+ lp->needs_lockd_init = 1;
- if (!lv_create_single(vg, &lp))
+ if (!lv_create_single(vg, lp))
goto_out;
- r = ECMD_PROCESSED;
+ ret = ECMD_PROCESSED;
out:
+ return ret;
+}
+
+int lvcreate(struct cmd_context *cmd, int argc, char **argv)
+{
+ struct processing_handle *handle = NULL;
+ struct processing_params pp;
+ struct lvcreate_params lp = {
+ .major = -1,
+ .minor = -1,
+ };
+ struct lvcreate_cmdline_params lcp = { 0 };
+ int ret;
+
+ if (!_lvcreate_params(cmd, argc, argv, &lp, &lcp)) {
+ stack;
+ return EINVALID_CMD_LINE;
+ }
+
+ if (!_check_pool_parameters(cmd, NULL, &lp, &lcp)) {
+ stack;
+ return EINVALID_CMD_LINE;
+ }
+
+ pp.lp = &lp;
+ pp.lcp = &lcp;
+
+ if (!(handle = init_processing_handle(cmd))) {
+ log_error("Failed to initialize processing handle.");
+ return ECMD_FAILED;
+ }
+
+ handle->custom_handle = &pp;
+
+ ret = process_each_vg(cmd, 0, NULL, lp.vg_name, READ_FOR_UPDATE, handle,
+ &_lvcreate_single);
+
_destroy_lvcreate_params(&lp);
- unlock_and_release_vg(cmd, vg, lp.vg_name);
- return r;
+ destroy_processing_handle(cmd, handle);
+ return ret;
}
8 years, 5 months