Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=0eebd9d7802c724ee71b6…
Commit: 0eebd9d7802c724ee71b6ebb80940ea6007f9c7a
Parent: 3c49a2e43ccfbad720a3134484c7870a14b1135b
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Tue Aug 30 14:40:48 2022 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Tue Aug 30 14:52:00 2022 -0500
vgimportdevices: fix locking when creating devices file
Take the devices file lock before creating a new devices file.
(Was missed by the change to preemptively create the devices
file prior to setup_devices(), which was done to improve the
error path.)
---
lib/device/dev-cache.c | 7 +++----
lib/device/device_id.c | 1 +
tools/vgimportdevices.c | 10 ++++++++--
3 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c
index 193eb7585..85f9b499a 100644
--- a/lib/device/dev-cache.c
+++ b/lib/device/dev-cache.c
@@ -1937,10 +1937,9 @@ int setup_devices(struct cmd_context *cmd)
if (!file_exists) {
/*
- * pvcreate/vgcreate/vgimportdevices/lvmdevices-add create
- * a new devices file here if it doesn't exist.
- * They have the create_edit_devices_file flag set.
- * First they create/lock-ex the devices file lockfile.
+ * pvcreate/vgcreate create a new devices file here if it
+ * doesn't exist. They have create_edit_devices_file=1.
+ * First create/lock-ex the devices file lockfile.
* Other commands will not use a devices file if none exists.
*/
lock_mode = LOCK_EX;
diff --git a/lib/device/device_id.c b/lib/device/device_id.c
index 6c70f110c..a0a626533 100644
--- a/lib/device/device_id.c
+++ b/lib/device/device_id.c
@@ -2468,6 +2468,7 @@ static int _lock_devices_file(struct cmd_context *cmd, int mode, int nonblock, i
if (_devices_file_locked == mode) {
/* can happen when a command holds an ex lock and does an update in device_ids_validate */
+ /* can happen when vgimportdevices calls this directly, followed later by setup_devices */
if (held)
*held = 1;
return 1;
diff --git a/tools/vgimportdevices.c b/tools/vgimportdevices.c
index 9ade1b9e4..23c2718ff 100644
--- a/tools/vgimportdevices.c
+++ b/tools/vgimportdevices.c
@@ -132,8 +132,10 @@ int vgimportdevices(struct cmd_context *cmd, int argc, char **argv)
return ECMD_FAILED;
/*
- * Prepare devices file preemptively because the error path for this
- * case from process_each is not as clean.
+ * Prepare/create devices file preemptively because the error path for
+ * this case from process_each/setup_devices is not as clean.
+ * This means that when setup_devices is called, it the devices
+ * file steps will be redundant, and need to handle being repeated.
*/
if (!setup_devices_file(cmd)) {
log_error("Failed to set up devices file.");
@@ -143,6 +145,10 @@ int vgimportdevices(struct cmd_context *cmd, int argc, char **argv)
log_error("Devices file not enabled.");
return ECMD_FAILED;
}
+ if (!lock_devices_file(cmd, LOCK_EX)) {
+ log_error("Failed to lock the devices file.");
+ return ECMD_FAILED;
+ }
if (!devices_file_exists(cmd)) {
if (!devices_file_touch(cmd)) {
log_error("Failed to create devices file.");
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=b553bf6fa817a38474f48…
Commit: b553bf6fa817a38474f48816fc520d178cb48229
Parent: 8370d117d7ef8a472c95315a3cd085696c90b3be
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Aug 30 13:48:18 2022 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Aug 30 13:56:16 2022 +0200
mm: use mallinfo2 when available
Switch to mallinfo2() from a deprecated mallinfo() glibc call
since struct size members where to small for 64b CPUs.
---
WHATS_NEW | 1 +
lib/mm/memlock.c | 13 ++++++++++---
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 9e7cd1f0c..293c034af 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.03.17 -
===============================
+ Switch to use mallinfo2 and use it only with glibc.
Error out in lvm shell if using a cmd argument not supported in the shell.
Fix lvm shell's lastlog command to report previous pre-command failures.
Extend VDO and VDOPOOL without flushing and locking fs.
diff --git a/lib/mm/memlock.c b/lib/mm/memlock.c
index 4a202866a..ad69f6474 100644
--- a/lib/mm/memlock.c
+++ b/lib/mm/memlock.c
@@ -167,7 +167,8 @@ static void _allocate_memory(void)
*/
void *stack_mem;
struct rlimit limit;
- int i, area = 0, missing = _size_malloc_tmp, max_areas = 32, hblks;
+ int i, area = 0, missing = _size_malloc_tmp, max_areas = 32;
+ size_t hblks;
char *areas[max_areas];
/* Check if we could preallocate requested stack */
@@ -180,6 +181,12 @@ static void _allocate_memory(void)
}
/* FIXME else warn user setting got ignored */
+#ifdef HAVE_MALLINFO2
+ /* Prefer mallinfo2 call when avaialble with newer glibc */
+#define MALLINFO mallinfo2
+#else
+#define MALLINFO mallinfo
+#endif
/*
* When a brk() fails due to fragmented address space (which sometimes
* happens when we try to grab 8M or so), glibc will make a new
@@ -191,13 +198,13 @@ static void _allocate_memory(void)
* memory on free(), this is good enough for our purposes.
*/
while (missing > 0) {
- struct mallinfo inf = mallinfo();
+ struct MALLINFO inf = MALLINFO();
hblks = inf.hblks;
if ((areas[area] = malloc(_size_malloc_tmp)))
_touch_memory(areas[area], _size_malloc_tmp);
- inf = mallinfo();
+ inf = MALLINFO();
if (hblks < inf.hblks) {
/* malloc cheated and used mmap, even though we told it
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=8d70cfe6005165e173643…
Commit: 8d70cfe6005165e173643954e6cd9eff745e4aa4
Parent: e6b6a09f90f53a5cea3a712b2b84af57f4514a02
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Fri Aug 26 14:51:31 2022 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Fri Aug 26 15:08:33 2022 +0200
report: values: add note about self-decriptive values to report
---
lib/report/report.c | 27 +++++++++++++++++++++++++++
lib/report/values.h | 27 +++++++++++++++++++++++++++
2 files changed, 54 insertions(+)
diff --git a/lib/report/report.c b/lib/report/report.c
index 8a5122ff9..f666ca842 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -29,6 +29,33 @@
#include <float.h> /* DBL_MAX */
#include <time.h>
+/*
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ * IMPORTANT NOTE ABOUT ADDING A NEW VALUE FOR REPORTING
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ *
+ * When adding a new string value to report, try to keep it
+ * self-descriptive so when it's printed even without the header,
+ * we can still deduce what it is actually reporting.
+ *
+ * If you need more than one descriptive string to mean the same value,
+ * please define them as reserved values in values.h.
+ *
+ * The first reserved value is the one that is printed in reports (unless
+ * it's a binary value and we have report/binary_values_as_numeric=1 config
+ * option used OR --binary command line option is used OR we're using an
+ * output format which must always print binary values in numeric way,
+ * like json_std output format.
+ *
+ * All the other (2nd and further) listed reserved names are synonyms which
+ * may be also used in selection (-S|--select).
+ *
+ * Also, always use proper *_disp functions to display each type of value
+ * properly. For example, in case of binary values, you should use
+ * _binary_disp so that we can always switch between numerical (0/1/-1) and
+ * string representation while reporting the value.
+ */
+
struct lvm_report_object {
struct volume_group *vg;
struct lv_with_info_and_seg_status *lvdm;
diff --git a/lib/report/values.h b/lib/report/values.h
index 9b98c229e..71175fa6e 100644
--- a/lib/report/values.h
+++ b/lib/report/values.h
@@ -45,6 +45,33 @@
/* *INDENT-OFF* */
+/*
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ * IMPORTANT NOTE ABOUT ADDING A NEW VALUE FOR REPORTING
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ *
+ * When adding a new string value to report, try to keep it
+ * self-descriptive so when it's printed even without the header,
+ * we can still deduce what it is actually reporting.
+ *
+ * If you need more than one descriptive string to mean the same value,
+ * please define them as reserved values in values.h.
+ *
+ * The first reserved value is the one that is printed in reports (unless
+ * it's a binary value and we have report/binary_values_as_numeric=1 config
+ * option used OR --binary command line option is used OR we're using an
+ * output format which must always print binary values in numeric way,
+ * like json_std output format.
+ *
+ * All the other (2nd and further) listed reserved names are synonyms which
+ * may be also used in selection (-S|--select).
+ *
+ * Also, always use proper *_disp functions to display each type of value
+ * properly. For example, in case of binary values, you should use
+ * _binary_disp so that we can always switch between numerical (0/1/-1) and
+ * string representation while reporting the value.
+ */
+
/* Per-type reserved values usable for all fields of certain type. */
TYPE_RESERVED_VALUE(NUM, NOFLAG, num_undef_64, "Reserved value for undefined numeric value.", UINT64_C(-1), "-1", "unknown", "undefined", "undef")
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=e6b6a09f90f53a5cea3a7…
Commit: e6b6a09f90f53a5cea3a712b2b84af57f4514a02
Parent: 800436d2affd4142b9d4b405112c4c30f1d31b5b
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Fri Aug 26 12:17:45 2022 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Fri Aug 26 12:17:50 2022 +0200
args: add ARG_NONINTERACTIVE for cmds not supported in lvm shell
Certain args can't be used in lvm shell ("interactive mode") because
they are not supported there. Add ARG_NONINTERACTIVE flag to mark
such args and error out if we're in interactive mode and at the same
time we detect use of such argument.
Currently, this is the case for --reportformat arg - we don't support
changing the format per command in lvm shell. The whole shell is running
under a reportformat chosen at shell's start.
---
WHATS_NEW | 1 +
tools/args.h | 2 +-
tools/command.c | 1 +
tools/lvmcmdline.c | 9 +++++++++
tools/tools.h | 1 +
5 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 90dd417b1..9e7cd1f0c 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.03.17 -
===============================
+ Error out in lvm shell if using a cmd argument not supported in the shell.
Fix lvm shell's lastlog command to report previous pre-command failures.
Extend VDO and VDOPOOL without flushing and locking fs.
Add --valuesonly option to lvmconfig to print only values without keys.
diff --git a/tools/args.h b/tools/args.h
index bdeefca7d..85dd11aeb 100644
--- a/tools/args.h
+++ b/tools/args.h
@@ -671,7 +671,7 @@ arg(replace_ARG, '\0', "replace", pv_VAL, ARG_GROUPABLE, 0,
"Multiple PVs can be replaced by repeating this option.\n"
"See \\fBlvmraid\\fP(7) for more information.\n")
-arg(reportformat_ARG, '\0', "reportformat", reportformat_VAL, 0, 0,
+arg(reportformat_ARG, '\0', "reportformat", reportformat_VAL, ARG_NONINTERACTIVE, 0,
"Overrides current output format for reports which is defined globally by\n"
"the report/output_format setting in \\fBlvm.conf\\fP(5).\n"
"\\fBbasic\\fP is the original format with columns and rows.\n"
diff --git a/tools/command.c b/tools/command.c
index 8de8825e4..5da511530 100644
--- a/tools/command.c
+++ b/tools/command.c
@@ -78,6 +78,7 @@ static void *dm_pool_alloc(void *p, size_t size)
/* needed to include args.h */
#define ARG_COUNTABLE 0x00000001
#define ARG_GROUPABLE 0x00000002
+#define ARG_NONINTERACTIVE 0x00000004
struct cmd_context;
struct arg_values;
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index 4fb21074f..ba3ca220b 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -2261,6 +2261,15 @@ static int _process_command_line(struct cmd_context *cmd, int *argc, char ***arg
av = &cmd->opt_arg_values[arg_enum];
+ if (a->flags & ARG_NONINTERACTIVE && cmd->is_interactive) {
+ log_error("Argument%s%c%s%s cannot be used in interactive mode.",
+ a->short_opt ? " -" : "",
+ a->short_opt ? : ' ',
+ (a->short_opt && a->long_opt) ?
+ "/" : "", a->long_opt ? : "");
+ return 0;
+ }
+
if (a->flags & ARG_GROUPABLE) {
/*
* Start a new group of arguments:
diff --git a/tools/tools.h b/tools/tools.h
index cd89e1692..2636c22da 100644
--- a/tools/tools.h
+++ b/tools/tools.h
@@ -96,6 +96,7 @@ enum {
#define ARG_COUNTABLE 0x00000001 /* E.g. -vvvv */
#define ARG_GROUPABLE 0x00000002 /* E.g. --addtag */
+#define ARG_NONINTERACTIVE 0x00000004 /* only for use in noninteractive mode */
struct arg_values {
unsigned count;
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=800436d2affd4142b9d4b…
Commit: 800436d2affd4142b9d4b405112c4c30f1d31b5b
Parent: 508782a9135acf13b39b47605e675a5678495c58
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Aug 24 12:08:51 2022 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Aug 24 12:10:10 2022 +0200
libdm: report: fix escaping of JSON quote char in reported fields
Commit 73ec3c954b21522352b6f5cce9a700d6bf30ccf4 added a way to print
only a part of the report string (repstr) to support decoding individual
string list items out of repstr.
The repstr is normally printed through _safe_repstr_output so that any
JSON_QUOTE character ('"') found within the repstr is escaped to not
interfere with value quoting in JSON format.
However, the commit 73ec3c954b21522352b6f5cce9a700d6bf30ccf4 missed
checking the 'len' argument passed to _safe_repstr_output function when
adding the rest of the repstr after all previous JSON_QUOTE characters
were escaped (when calling the last dm_pool_grow_object). When 'len'
is 0, we need to calculate the 'len' ourselves in the function by
simply calling strlen. This is because 'len' is passed to the function
only if we're taking a part of repstr, not as a whole.
---
device_mapper/libdm-report.c | 11 +++--------
libdm/libdm-report.c | 11 +++--------
2 files changed, 6 insertions(+), 16 deletions(-)
diff --git a/device_mapper/libdm-report.c b/device_mapper/libdm-report.c
index d4cd06002..2d4c8883b 100644
--- a/device_mapper/libdm-report.c
+++ b/device_mapper/libdm-report.c
@@ -4572,17 +4572,12 @@ bad:
static int _safe_repstr_output(struct dm_report *rh, const char *repstr, size_t len)
{
const char *p_repstr;
- const char *repstr_end = repstr + len;
+ const char *repstr_end = len ? repstr + len : repstr + strlen(repstr);
/* Escape any JSON_QUOTE that may appear in reported string. */
while (1) {
- if (len) {
- if (!(p_repstr = memchr(repstr, JSON_QUOTE[0], repstr_end - repstr)))
- break;
- } else {
- if (!(p_repstr = strstr(repstr, JSON_QUOTE)))
- break;
- }
+ if (!(p_repstr = memchr(repstr, JSON_QUOTE[0], repstr_end - repstr)))
+ break;
if (p_repstr > repstr) {
if (!dm_pool_grow_object(rh->mem, repstr, p_repstr - repstr)) {
diff --git a/libdm/libdm-report.c b/libdm/libdm-report.c
index fc71ca5df..8eaf5896e 100644
--- a/libdm/libdm-report.c
+++ b/libdm/libdm-report.c
@@ -4571,17 +4571,12 @@ bad:
static int _safe_repstr_output(struct dm_report *rh, const char *repstr, size_t len)
{
const char *p_repstr;
- const char *repstr_end = repstr + len;
+ const char *repstr_end = len ? repstr + len : repstr + strlen(repstr);
/* Escape any JSON_QUOTE that may appear in reported string. */
while (1) {
- if (len) {
- if (!(p_repstr = memchr(repstr, JSON_QUOTE[0], repstr_end - repstr)))
- break;
- } else {
- if (!(p_repstr = strstr(repstr, JSON_QUOTE)))
- break;
- }
+ if (!(p_repstr = memchr(repstr, JSON_QUOTE[0], repstr_end - repstr)))
+ break;
if (p_repstr > repstr) {
if (!dm_pool_grow_object(rh->mem, repstr, p_repstr - repstr)) {