main - shell: add pre-cmd log report object type and enable lastlog for it
by Peter Rajnoha
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=508782a9135acf13b39...
Commit: 508782a9135acf13b39b47605e675a5678495c58
Parent: 8c3cfc75c72696ae8b620555fcc4f815b0c1d6b6
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Mon Aug 22 13:59:08 2022 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Mon Aug 22 14:06:34 2022 +0200
shell: add pre-cmd log report object type and enable lastlog for it
If we failed or logged anything before we actually execute given command
in lvm shell, we couldn't report the log using lastlog command after.
This patch adds specific 'pre-cmd' log report object type to identify
such log messages and enables lastlog to report even this log.
---
WHATS_NEW | 1 +
lib/log/log.c | 1 +
lib/log/lvm-logging.h | 1 +
tools/lvm.c | 11 +++++++----
4 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index fac295336..90dd417b1 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.03.17 -
===============================
+ 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.
Updates configure with recent autoconf tooling.
diff --git a/lib/log/log.c b/lib/log/log.c
index 5771a1d01..118a3ba42 100644
--- a/lib/log/log.c
+++ b/lib/log/log.c
@@ -446,6 +446,7 @@ const char *log_get_report_context_name(log_report_context_t context)
const char *log_get_report_object_type_name(log_report_object_type_t object_type)
{
static const char *log_object_type_names[LOG_REPORT_OBJECT_TYPE_COUNT] = {[LOG_REPORT_OBJECT_TYPE_NULL] = "",
+ [LOG_REPORT_OBJECT_TYPE_PRE_CMD] = "pre-cmd",
[LOG_REPORT_OBJECT_TYPE_CMD] = "cmd",
[LOG_REPORT_OBJECT_TYPE_ORPHAN] = "orphan",
[LOG_REPORT_OBJECT_TYPE_PV] = "pv",
diff --git a/lib/log/lvm-logging.h b/lib/log/lvm-logging.h
index 5b975a6b8..f5a4277a8 100644
--- a/lib/log/lvm-logging.h
+++ b/lib/log/lvm-logging.h
@@ -91,6 +91,7 @@ typedef enum {
typedef enum {
LOG_REPORT_OBJECT_TYPE_NULL,
+ LOG_REPORT_OBJECT_TYPE_PRE_CMD,
LOG_REPORT_OBJECT_TYPE_CMD,
LOG_REPORT_OBJECT_TYPE_ORPHAN,
LOG_REPORT_OBJECT_TYPE_PV,
diff --git a/tools/lvm.c b/tools/lvm.c
index 756328f3f..370dc49e3 100644
--- a/tools/lvm.c
+++ b/tools/lvm.c
@@ -231,7 +231,7 @@ int lvm_shell(struct cmd_context *cmd, struct cmdline_context *cmdline)
orig_command_log_selection = dm_pool_strdup(cmd->libmem, find_config_tree_str(cmd, log_command_log_selection_CFG, NULL));
log_set_report_context(LOG_REPORT_CONTEXT_SHELL);
- log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_CMD);
+ log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_PRE_CMD);
while (1) {
/*
@@ -255,6 +255,7 @@ int lvm_shell(struct cmd_context *cmd, struct cmdline_context *cmdline)
log_error("Failed to reset log report selection.");
}
+ log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_PRE_CMD);
log_set_report(cmd->cmd_report.log_rh);
log_set_report_object_name_and_id(NULL, NULL);
@@ -275,6 +276,8 @@ int lvm_shell(struct cmd_context *cmd, struct cmdline_context *cmdline)
continue;
}
+ log_set_report_object_name_and_id(input, NULL);
+
add_history(input);
for (i = 0; i < MAX_ARGS; i++)
@@ -285,8 +288,7 @@ int lvm_shell(struct cmd_context *cmd, struct cmdline_context *cmdline)
if (lvm_split(input, &argc, argv, MAX_ARGS) == MAX_ARGS) {
_discard_log_report_content(cmd);
log_error("Too many arguments, sorry.");
- dm_report_group_output_and_pop_all(cmd->cmd_report.report_group);
- continue;
+ goto report_log;
}
if (!argc) {
@@ -304,6 +306,7 @@ int lvm_shell(struct cmd_context *cmd, struct cmdline_context *cmdline)
continue;
}
+ log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_CMD);
log_set_report_object_name_and_id(argv[0], NULL);
is_lastlog_cmd = !strcmp(argv[0], "lastlog");
@@ -331,7 +334,7 @@ int lvm_shell(struct cmd_context *cmd, struct cmdline_context *cmdline)
if (!is_lastlog_cmd)
_log_shell_command_status(cmd, ret);
-
+report_log:
log_set_report(NULL);
dm_report_group_output_and_pop_all(cmd->cmd_report.report_group);
1 year, 8 months
main - devices file: fix pvcreate --uuid matching pvid entry with no device id
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=8c3cfc75c72696ae8b6...
Commit: 8c3cfc75c72696ae8b620555fcc4f815b0c1d6b6
Parent: 1a981e9b6efb0bbc0881f5ed1f17900e9c669f48
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Fri Aug 19 13:31:22 2022 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Aug 19 13:34:36 2022 -0500
devices file: fix pvcreate --uuid matching pvid entry with no device id
pvcreate with --uuid would segfault if a devices file entry matched
the specified pvid, but the devices file entry had no device_id, which
could happen if the entry has a devname idtype.
---
lib/device/device_id.c | 7 ++++---
test/shell/devicesfile-devname.sh | 13 +++++++++++++
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/lib/device/device_id.c b/lib/device/device_id.c
index 9dec9f884..6c70f110c 100644
--- a/lib/device/device_id.c
+++ b/lib/device/device_id.c
@@ -1168,8 +1168,9 @@ id_done:
du_devname->devname);
if (du_pvid && (du_pvid->dev != dev))
- log_warn("WARNING: adding device %s with PVID %s which is already used for %s.",
- dev_name(dev), pvid, du_pvid->dev ? dev_name(du_pvid->dev) : "missing device");
+ log_warn("WARNING: adding device %s with PVID %s which is already used for %s device_id %s.",
+ dev_name(dev), pvid, du_pvid->dev ? dev_name(du_pvid->dev) : "missing device",
+ du_pvid->idname ?: "none");
if (du_devid && (du_devid->dev != dev)) {
if (!du_devid->dev) {
@@ -1215,7 +1216,7 @@ id_done:
else
check_idname = device_id_system_read(cmd, dev, du_pvid->idtype);
- if (check_idname && !strcmp(check_idname, du_pvid->idname)) {
+ if (!du_pvid->idname || (check_idname && !strcmp(check_idname, du_pvid->idname))) {
update_du = du_pvid;
dm_list_del(&update_du->list);
update_matching_kind = "PVID";
diff --git a/test/shell/devicesfile-devname.sh b/test/shell/devicesfile-devname.sh
index 338637275..211f4dbed 100644
--- a/test/shell/devicesfile-devname.sh
+++ b/test/shell/devicesfile-devname.sh
@@ -550,6 +550,19 @@ vgchange -an $vg2
vgremove -ff $vg1
vgremove -ff $vg2
+# bz 2119473
+
+aux lvmconf "devices/search_for_devnames = \"none\""
+sed -e "s|DEVNAME=$dev1|DEVNAME=.|" "$ORIG" > tmp1.devices
+sed -e "s|IDNAME=$dev1|IDNAME=.|" tmp1.devices > "$DF"
+pvs
+lvmdevices
+pvcreate -ff --yes --uuid "$PVID1" --norestorefile $dev1
+grep "$PVID1" "$DF" |tee out
+grep "DEVNAME=$dev1" out
+grep "IDNAME=$dev1" out
+aux lvmconf "devices/search_for_devnames = \"auto\""
+
# devnames change so the new devname now refers to a filtered device,
# e.g. an mpath or md component, which is not scanned
1 year, 8 months
main - devices: drop double // from sysfs path
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=1a981e9b6efb0bbc088...
Commit: 1a981e9b6efb0bbc0881f5ed1f17900e9c669f48
Parent: 718e38d5faf3a3ca23690d2f4203df1df65eba77
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Wed Aug 10 15:09:34 2022 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Aug 19 14:56:57 2022 +0200
devices: drop double // from sysfs path
dm_sysfs_dir() comes internally as /sys/.
---
lib/device/dev-mpath.c | 4 ++--
lib/device/dev-type.c | 8 ++++----
lib/metadata/vdo_manip.c | 2 +-
3 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/lib/device/dev-mpath.c b/lib/device/dev-mpath.c
index 27b0f41a6..2040edac3 100644
--- a/lib/device/dev-mpath.c
+++ b/lib/device/dev-mpath.c
@@ -815,7 +815,7 @@ const char *dev_mpath_component_wwid(struct cmd_context *cmd, struct device *dev
/* /sys/dev/block/253:7/slaves/sda/device/wwid */
- if (dm_snprintf(slaves_path, sizeof(slaves_path), "%s/dev/block/%d:%d/slaves",
+ if (dm_snprintf(slaves_path, sizeof(slaves_path), "%sdev/block/%d:%d/slaves",
dm_sysfs_dir(), (int)MAJOR(dev->dev), (int)MINOR(dev->dev)) < 0) {
log_warn("Sysfs path to check mpath components is too long.");
return NULL;
@@ -845,7 +845,7 @@ const char *dev_mpath_component_wwid(struct cmd_context *cmd, struct device *dev
/* read /sys/block/sda/device/wwid */
- if (dm_snprintf(wwid_path, sizeof(wwid_path), "%s/block/%s/device/wwid",
+ if (dm_snprintf(wwid_path, sizeof(wwid_path), "%sblock/%s/device/wwid",
dm_sysfs_dir(), slave_name) < 0) {
log_warn("Failed to create sysfs wwid path for %s", slave_name);
continue;
diff --git a/lib/device/dev-type.c b/lib/device/dev-type.c
index 939eb4aeb..1dc895b54 100644
--- a/lib/device/dev-type.c
+++ b/lib/device/dev-type.c
@@ -548,7 +548,7 @@ static int _has_sys_partition(struct device *dev)
int minor = (int) MINOR(dev->dev);
/* check if dev is a partition */
- if (dm_snprintf(path, sizeof(path), "%s/dev/block/%d:%d/partition",
+ if (dm_snprintf(path, sizeof(path), "%sdev/block/%d:%d/partition",
dm_sysfs_dir(), major, minor) < 0) {
log_warn("WARNING: %s: partition path is too long.", dev_name(dev));
return 0;
@@ -775,7 +775,7 @@ int dev_get_primary_dev(struct dev_types *dt, struct device *dev, dev_t *result)
* - basename ../../block/md0/md0 = md0
* Parent's 'dev' sysfs attribute = /sys/block/md0/dev
*/
- if (dm_snprintf(path, sizeof(path), "%s/dev/block/%d:%d",
+ if (dm_snprintf(path, sizeof(path), "%sdev/block/%d:%d",
dm_sysfs_dir(), major, minor) < 0) {
log_warn("WARNING: %s: major:minor sysfs path is too long.", dev_name(dev));
return 0;
@@ -787,7 +787,7 @@ int dev_get_primary_dev(struct dev_types *dt, struct device *dev, dev_t *result)
temp_path[size] = '\0';
- if (dm_snprintf(path, sizeof(path), "%s/block/%s/dev",
+ if (dm_snprintf(path, sizeof(path), "%sblock/%s/dev",
dm_sysfs_dir(), basename(dirname(temp_path))) < 0) {
log_warn("WARNING: sysfs path for %s is too long.",
basename(dirname(temp_path)));
@@ -1095,7 +1095,7 @@ int wipe_known_signatures(struct cmd_context *cmd, struct device *dev,
static int _snprintf_attr(char *buf, size_t buf_size, const char *sysfs_dir,
const char *attribute, dev_t dev)
{
- if (dm_snprintf(buf, buf_size, "%s/dev/block/%d:%d/%s", sysfs_dir,
+ if (dm_snprintf(buf, buf_size, "%sdev/block/%d:%d/%s", sysfs_dir,
(int)MAJOR(dev), (int)MINOR(dev),
attribute) < 0) {
log_warn("WARNING: sysfs path for %s attribute is too long.", attribute);
diff --git a/lib/metadata/vdo_manip.c b/lib/metadata/vdo_manip.c
index 0db401537..779883d03 100644
--- a/lib/metadata/vdo_manip.c
+++ b/lib/metadata/vdo_manip.c
@@ -148,7 +148,7 @@ static int _sysfs_get_kvdo_value(const char *dm_name, const struct dm_info *dmin
char temp[64];
int fd, size, r = 0;
- if (dm_snprintf(path, sizeof(path), "%s/block/dm-%d/vdo/%s",
+ if (dm_snprintf(path, sizeof(path), "%sblock/dm-%d/vdo/%s",
dm_sysfs_dir(), dminfo->minor, vdo_param) < 0) {
log_debug("Failed to build kvdo path.");
return 0;
1 year, 8 months
main - dmsetup: check also for ouf of range value
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=718e38d5faf3a3ca236...
Commit: 718e38d5faf3a3ca23690d2f4203df1df65eba77
Parent: a3eb6ba425773224076c41aabc3c490a6a016ee6
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Aug 18 13:56:03 2022 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Aug 19 14:56:57 2022 +0200
dmsetup: check also for ouf of range value
Check errno result from strtoull().
---
libdm/dm-tools/dmsetup.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libdm/dm-tools/dmsetup.c b/libdm/dm-tools/dmsetup.c
index 8502d9adc..42eeead68 100644
--- a/libdm/dm-tools/dmsetup.c
+++ b/libdm/dm-tools/dmsetup.c
@@ -5106,8 +5106,9 @@ static int _size_from_string(char *argptr, uint64_t *size, const char *name)
if (!argptr)
return_0;
+ errno = 0;
*size = strtoull(argptr, &endptr, 10);
- if (endptr == argptr) {
+ if (errno || endptr == argptr) {
*size = 0;
log_error("Invalid %s argument: \"%s\"",
name, (*argptr) ? argptr : "");
1 year, 8 months
main - mm: remove libaio from being skipped
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=a3eb6ba425773224076...
Commit: a3eb6ba425773224076c41aabc3c490a6a016ee6
Parent: e26c21cb8d5841141dcfdfc77f46da1108a81255
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Aug 18 14:31:27 2022 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Aug 19 14:56:57 2022 +0200
mm: remove libaio from being skipped
Since libaio is now used also in critical section,
keep the libaio locked in memory.
---
lib/mm/memlock.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/lib/mm/memlock.c b/lib/mm/memlock.c
index 3d1a3927c..f43bacdcd 100644
--- a/lib/mm/memlock.c
+++ b/lib/mm/memlock.c
@@ -105,7 +105,6 @@ static const char * const _blacklist_maps[] = {
"/LC_MESSAGES/",
"gconv/gconv-modules.cache",
"/ld-2.", /* not using dlopen,dlsym during mlock */
- "/libaio.so.", /* not using aio during mlock */
"/libattr.so.", /* not using during mlock (udev) */
"/libblkid.so.", /* not using blkid during mlock (udev) */
"/libbz2.so.", /* not using during mlock (udev) */
1 year, 8 months
main - vdo: extend volume and pool without flush
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=e26c21cb8d5841141dc...
Commit: e26c21cb8d5841141dcfdfc77f46da1108a81255
Parent: 309df239e3ee474f3a5337f8fa3c0a1f7b0a89e5
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Aug 19 14:48:01 2022 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Aug 19 14:56:55 2022 +0200
vdo: extend volume and pool without flush
When the volume size is extended, there is no need to flush
IO operations (nothing can be targeting new space yet).
VDO target is supported as target that can safely work with
this condition.
Such support is also needed, when extending VDOPOOL size
while the pool is reaching its capacity - since this allows
to continue working without reaching 'out-of-space' condition
due to flushing of all in flight IO.
---
WHATS_NEW | 1 +
lib/activate/activate.c | 6 +++++-
lib/activate/dev_manager.c | 2 ++
3 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 6e9a3fa1d..fac295336 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.03.17 -
===============================
+ Extend VDO and VDOPOOL without flushing and locking fs.
Add --valuesonly option to lvmconfig to print only values without keys.
Updates configure with recent autoconf tooling.
Fix lvconvert --test --type vdo-pool execution.
diff --git a/lib/activate/activate.c b/lib/activate/activate.c
index db5f08b11..a92fbb8e1 100644
--- a/lib/activate/activate.c
+++ b/lib/activate/activate.c
@@ -2141,7 +2141,11 @@ static int _lv_suspend(struct cmd_context *cmd, const char *lvid_s,
* TODO: Relax this limiting condition further */
if (!flush_required &&
(lv_is_pvmove(lv) || pvmove_lv ||
- (!lv_is_mirror(lv) && !lv_is_thin_pool(lv) && !lv_is_thin_volume(lv)))) {
+ (!lv_is_mirror(lv) &&
+ !lv_is_thin_volume(lv) &&
+ !lv_is_thin_pool(lv) &&
+ !lv_is_vdo(lv) &&
+ !lv_is_vdo_pool(lv)))) {
log_debug("Requiring flush for LV %s.", display_lvname(lv));
flush_required = 1;
}
diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c
index 8cb31008e..2bfd275fd 100644
--- a/lib/activate/dev_manager.c
+++ b/lib/activate/dev_manager.c
@@ -3908,6 +3908,8 @@ static int _tree_action(struct dev_manager *dm, const struct logical_volume *lv,
* non 'thin pool/volume' and size increase */
else if (!lv_is_thin_volume(lv) &&
!lv_is_thin_pool(lv) &&
+ !lv_is_vdo(lv) &&
+ !lv_is_vdo_pool(lv) &&
dm_tree_node_size_changed(root))
dm->flush_required = 1;
1 year, 8 months
main - vdo: reset errno before strtoull
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=309df239e3ee474f3a5...
Commit: 309df239e3ee474f3a5337f8fa3c0a1f7b0a89e5
Parent: ac2c78544fa60490f9506f4ea0cd7d74d2395b28
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Aug 18 13:55:29 2022 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Aug 19 14:55:47 2022 +0200
vdo: reset errno before strtoull
Missed errno reset in commit ebad057579aeff0980a1b8af7eaacd56e62ed0c9.
---
lib/metadata/vdo_manip.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/lib/metadata/vdo_manip.c b/lib/metadata/vdo_manip.c
index 637fd1e5d..0db401537 100644
--- a/lib/metadata/vdo_manip.c
+++ b/lib/metadata/vdo_manip.c
@@ -618,6 +618,7 @@ static int _get_memory_info(uint64_t *total_mb, uint64_t *available_mb)
if (!found)
continue; // not interesting
+ errno = 0;
*(found->value) = (uint64_t) strtoull(e, &tail, 10);
if ((e == tail) || errno)
1 year, 8 months
main - config: check for possible mempool errors in _out_line_fn
by Peter Rajnoha
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=ac2c78544fa60490f95...
Commit: ac2c78544fa60490f9506f4ea0cd7d74d2395b28
Parent: 8a23683a59835d967eff193bf1f82cc4ee5a6fdf
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Aug 17 12:51:42 2022 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Aug 17 12:52:02 2022 +0200
config: check for possible mempool errors in _out_line_fn
---
lib/config/config.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/lib/config/config.c b/lib/config/config.c
index db8f3c2c1..230ec3225 100644
--- a/lib/config/config.c
+++ b/lib/config/config.c
@@ -1872,9 +1872,15 @@ static int _out_line_fn(const struct dm_config_node *cn, const char *line, void
p = line + space_prefix_len;
/* copy space_prefix, skip key and '=', copy value */
- dm_pool_begin_object(out->mem, len);
- dm_pool_grow_object(out->mem, line, space_prefix_len);
- dm_pool_grow_object(out->mem, p + strcspn(p, "=") + 1, len + 1);
+ if (!dm_pool_begin_object(out->mem, len))
+ return_0;
+
+ if (!dm_pool_grow_object(out->mem, line, space_prefix_len) ||
+ !dm_pool_grow_object(out->mem, p + strcspn(p, "=") + 1, len + 1)) {
+ dm_pool_abandon_object(out->mem);
+ return_0;
+ }
+
line = dm_pool_end_object(out->mem);
} else
line = strchr(line, '=') + 1;
1 year, 8 months
main - config: remove unnecessary copy of config line's space prefix before printing
by Peter Rajnoha
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=8a23683a59835d967ef...
Commit: 8a23683a59835d967eff193bf1f82cc4ee5a6fdf
Parent: b4cc28c2ef72ee022c1a03819927e31775c18676
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Aug 17 10:11:05 2022 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Aug 17 10:47:43 2022 +0200
config: remove unnecessary copy of config line's space prefix before printing
When we wanted to insert '#' before a config line (to comment it out),
we used dm_pool_strndup to temporarily copy the space prefix first so
we can assemble the final line with:
"<space_prefix># <key>=<value>":
out of original:
"<space_prefix><key>=<value>".
The space_prefix copy is not necessary, we can just use fprintf's
precision modifier "%.*s" to print the exact part if we alrady
know space_prefix length.
---
lib/config/config.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/lib/config/config.c b/lib/config/config.c
index 1142ed345..db8f3c2c1 100644
--- a/lib/config/config.c
+++ b/lib/config/config.c
@@ -1831,7 +1831,6 @@ static int _out_line_fn(const struct dm_config_node *cn, const char *line, void
char version[9];
int pos = 0;
int space_prefix_len;
- char *space_prefix;
const char *p;
size_t len;
@@ -1888,10 +1887,9 @@ static int _out_line_fn(const struct dm_config_node *cn, const char *line, void
(cfg_def->flags & (CFG_DEFAULT_UNDEFINED | CFG_DEFAULT_COMMENTED))) {
/* print with # at the front to comment out the line */
if (_should_print_cfg_with_undef_def_val(out, cfg_def, cn)) {
- space_prefix = ((len = strspn(line, "\t "))) ? dm_pool_strndup(out->mem, line, len) : NULL;
- fprintf(out->fp, "%s%s%s\n", space_prefix ? : "", "# ", line + len);
- if (space_prefix)
- dm_pool_free(out->mem, space_prefix);
+ space_prefix_len = strspn(line, "\t ");
+ fprintf(out->fp, "%.*s%s%s\n", space_prefix_len, line, "# ",
+ line + space_prefix_len);
}
return 1;
}
1 year, 8 months
main - lvmconfig: add --valuesonly option
by Peter Rajnoha
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=b4cc28c2ef72ee022c1...
Commit: b4cc28c2ef72ee022c1a03819927e31775c18676
Parent: 81839cc4ebf566ea9f3e6d819c7338b98cdec374
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue Aug 16 16:56:06 2022 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Aug 17 10:47:24 2022 +0200
lvmconfig: add --valuesonly option
The new --valuesonly option causes the lvmconfig output to contain only
values without keys for each config node. This is practical mainly in
case where we use lvmconfig in scripts and we want to assign the value
to a different custom key or simply output the value itself without the
key.
For example:
# lvmconfig --type full activation/raid_fault_policy
raid_fault_policy="warn"
# lvmconfig --type full activation/raid_fault_policy --valuesonly
"warn"
# my_var=$(lvmconfig --type full activation/raid_fault_policy --valuesonly)
# echo $my_var
"warn"
---
WHATS_NEW | 1 +
lib/config/config.c | 22 +++++++++++++++++++++-
lib/config/config.h | 1 +
man/lvmconfig.8_pregen | 7 +++++++
tools/args.h | 3 +++
tools/command-lines.in | 5 +++--
tools/dumpconfig.c | 7 +++++++
7 files changed, 43 insertions(+), 3 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 6cd53553b..6e9a3fa1d 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.03.17 -
===============================
+ Add --valuesonly option to lvmconfig to print only values without keys.
Updates configure with recent autoconf tooling.
Fix lvconvert --test --type vdo-pool execution.
Add json_std output format for more JSON standard compliant version of output.
diff --git a/lib/config/config.c b/lib/config/config.c
index f9614779a..1142ed345 100644
--- a/lib/config/config.c
+++ b/lib/config/config.c
@@ -1830,8 +1830,10 @@ static int _out_line_fn(const struct dm_config_node *cn, const char *line, void
char summary[MAX_COMMENT_LINE+1];
char version[9];
int pos = 0;
- size_t len;
+ int space_prefix_len;
char *space_prefix;
+ const char *p;
+ size_t len;
if ((out->tree_spec->type == CFG_DEF_TREE_DIFF) &&
(!(out->tree_spec->check_status[cn->id] & CFG_DIFF)))
@@ -1865,9 +1867,24 @@ static int _out_line_fn(const struct dm_config_node *cn, const char *line, void
/* Usual tree view with nodes and their values. */
+ if (out->tree_spec->valuesonly && !(cfg_def->type & CFG_TYPE_SECTION)) {
+ if ((space_prefix_len = strspn(line, "\t "))) {
+ len = strlen(line);
+ p = line + space_prefix_len;
+
+ /* copy space_prefix, skip key and '=', copy value */
+ dm_pool_begin_object(out->mem, len);
+ dm_pool_grow_object(out->mem, line, space_prefix_len);
+ dm_pool_grow_object(out->mem, p + strcspn(p, "=") + 1, len + 1);
+ line = dm_pool_end_object(out->mem);
+ } else
+ line = strchr(line, '=') + 1;
+ }
+
if ((out->tree_spec->type != CFG_DEF_TREE_CURRENT) &&
(out->tree_spec->type != CFG_DEF_TREE_DIFF) &&
(out->tree_spec->type != CFG_DEF_TREE_FULL) &&
+ !out->tree_spec->valuesonly &&
(cfg_def->flags & (CFG_DEFAULT_UNDEFINED | CFG_DEFAULT_COMMENTED))) {
/* print with # at the front to comment out the line */
if (_should_print_cfg_with_undef_def_val(out, cfg_def, cn)) {
@@ -1883,6 +1900,9 @@ static int _out_line_fn(const struct dm_config_node *cn, const char *line, void
if (_should_print_cfg_with_undef_def_val(out, cfg_def, cn))
fprintf(out->fp, "%s\n", line);
+ if (out->tree_spec->valuesonly && !(cfg_def->type & CFG_TYPE_SECTION) && space_prefix_len)
+ dm_pool_free(out->mem, (char *) line);
+
return 1;
}
diff --git a/lib/config/config.h b/lib/config/config.h
index c62ea20a5..3926b12f5 100644
--- a/lib/config/config.h
+++ b/lib/config/config.h
@@ -176,6 +176,7 @@ struct config_def_tree_spec {
unsigned unconfigured:1; /* use unconfigured path strings */
unsigned withgeneralpreamble:1; /* include preamble for a general config file */
unsigned withlocalpreamble:1; /* include preamble for a local config file */
+ unsigned valuesonly:1; /* print only values without keys */
uint8_t *check_status; /* status of last tree check (currently needed for CFG_DEF_TREE_MISSING only) */
};
diff --git a/man/lvmconfig.8_pregen b/man/lvmconfig.8_pregen
index a29255cf4..5279fa4dc 100644
--- a/man/lvmconfig.8_pregen
+++ b/man/lvmconfig.8_pregen
@@ -56,6 +56,8 @@ line settings from --config.
.br
[ \fB--validate\fP ]
.br
+[ \fB--valuesonly\fP ]
+.br
[ \fB--withsummary\fP ]
.br
[ \fB--withcomments\fP ]
@@ -369,6 +371,11 @@ merged configuration tree, also use --mergedconfig.
The validation is done even if \fBlvm.conf\fP(5) \fBconfig/checks\fP is disabled.
.
.HP
+\fB--valuesonly\fP
+.br
+When printing config settings, print only values without keys.
+.
+.HP
\fB-v\fP|\fB--verbose\fP ...
.br
Set verbose level. Repeat from 1 to 4 times to increase the detail
diff --git a/tools/args.h b/tools/args.h
index 9229b8764..bdeefca7d 100644
--- a/tools/args.h
+++ b/tools/args.h
@@ -905,6 +905,9 @@ arg(validate_ARG, '\0', "validate", 0, 0, 0,
"merged configuration tree, also use --mergedconfig.\n"
"The validation is done even if \\fBlvm.conf\\fP(5) \\fBconfig/checks\\fP is disabled.\n")
+arg(valuesonly_ARG, '\0', "valuesonly", 0, 0, 0,
+ "When printing config settings, print only values without keys.\n")
+
arg(vdo_ARG, '\0', "vdo", 0, 0, 0,
"Specifies the command is handling VDO LV.\n"
"See --type vdo.\n"
diff --git a/tools/command-lines.in b/tools/command-lines.in
index b6a03d158..6e9e7bdea 100644
--- a/tools/command-lines.in
+++ b/tools/command-lines.in
@@ -221,8 +221,9 @@ OO_REPORT: --aligned, --all, --binary, --configreport ConfigReport, --foreign,
#
OO_CONFIG: --atversion String, --typeconfig ConfigType, --file String, --ignoreadvanced,
--ignoreunsupported, --ignorelocal, --list, --mergedconfig, --metadataprofile String,
---sinceversion String, --showdeprecated, --showunsupported, --validate, --withsummary,
---withcomments, --withgeneralpreamble, --withlocalpreamble, --withspaces, --unconfigured, --withversions
+--sinceversion String, --showdeprecated, --showunsupported, --validate, --valuesonly,
+--withsummary, --withcomments, --withgeneralpreamble, --withlocalpreamble, --withspaces,
+--unconfigured, --withversions
---
diff --git a/tools/dumpconfig.c b/tools/dumpconfig.c
index 9e4408e16..4a0f193c4 100644
--- a/tools/dumpconfig.c
+++ b/tools/dumpconfig.c
@@ -242,6 +242,10 @@ int dumpconfig(struct cmd_context *cmd, int argc, char **argv)
log_error("--withgeneralpreamble has no effect with --type list");
return EINVALID_CMD_LINE;
}
+ if (arg_is_set(cmd, valuesonly_ARG)) {
+ log_err("--valuesonly has no effect with --type list");
+ return EINVALID_CMD_LINE;
+ }
/* list type does not require status check */
} else if (!strcmp(type, "full")) {
tree_spec.type = CFG_DEF_TREE_FULL;
@@ -320,6 +324,9 @@ int dumpconfig(struct cmd_context *cmd, int argc, char **argv)
if (arg_is_set(cmd, withspaces_ARG))
tree_spec.withspaces = 1;
+ if (arg_is_set(cmd, valuesonly_ARG))
+ tree_spec.valuesonly = 1;
+
if (cft_check_handle)
tree_spec.check_status = cft_check_handle->status;
1 year, 8 months