From d7934cfd12ada441faf658f952530a4a99aadb7c Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Sat, 19 Oct 2024 21:51:34 +0200 Subject: [PATCH] export size --- lib/format_text/export.c | 11 ++++------- lib/format_text/format-text.c | 2 +- libdaemon/client/config-util.c | 4 ++-- libdaemon/client/config-util.h | 2 +- libdaemon/client/daemon-client.c | 2 +- libdaemon/server/daemon-server.c | 2 +- 6 files changed, 10 insertions(+), 13 deletions(-) diff --git a/lib/format_text/export.c b/lib/format_text/export.c index 6164b71dc..4ab23bfe8 100644 --- a/lib/format_text/export.c +++ b/lib/format_text/export.c @@ -1059,22 +1059,19 @@ size_t text_vg_export_raw(struct volume_group *vg, const char *desc, char **buf, return r; } -static size_t _export_vg_to_buffer(struct volume_group *vg, char **buf) -{ - return text_vg_export_raw(vg, "", buf, NULL); -} - struct dm_config_tree *export_vg_to_config_tree(struct volume_group *vg) { char *buf = NULL; + uint32_t buf_size = 0; struct dm_config_tree *vg_cft; - if (!_export_vg_to_buffer(vg, &buf)) { + /* export vg to bufffer */ + if (!text_vg_export_raw(vg, "", &buf, &buf_size)) { log_error("Could not format metadata for VG %s.", vg->name); return NULL; } - if (!(vg_cft = config_tree_from_string_without_dup_node_check(buf))) { + if (!(vg_cft = config_tree_from_string_without_dup_node_check(buf, buf_size))) { log_error("Error parsing metadata for VG %s.", vg->name); free(buf); return NULL; diff --git a/lib/format_text/format-text.c b/lib/format_text/format-text.c index d2c99f6bb..b52319805 100644 --- a/lib/format_text/format-text.c +++ b/lib/format_text/format-text.c @@ -647,7 +647,7 @@ static int _vg_write_raw(struct format_instance *fid, struct volume_group *vg, * * 'Lazy' creation of such VG might improve performance, but we * lose important validation that written metadata can be parsed. */ - if (!(cft = config_tree_from_string_without_dup_node_check(write_buf))) { + if (!(cft = config_tree_from_string_without_dup_node_check(write_buf, new_size - 1))) { log_error("Error parsing metadata for VG %s.", vg->name); goto out; } diff --git a/libdaemon/client/config-util.c b/libdaemon/client/config-util.c index b0813f176..3e821f56f 100644 --- a/libdaemon/client/config-util.c +++ b/libdaemon/client/config-util.c @@ -159,14 +159,14 @@ void chain_node(struct dm_config_node *cn, } -struct dm_config_tree *config_tree_from_string_without_dup_node_check(const char *config_settings) +struct dm_config_tree *config_tree_from_string_without_dup_node_check(const char *config_settings, size_t len) { struct dm_config_tree *cft; if (!(cft = dm_config_create())) return_NULL; - if (!dm_config_parse_without_dup_node_check(cft, config_settings, config_settings + strlen(config_settings))) { + if (!dm_config_parse_without_dup_node_check(cft, config_settings, config_settings + len)) { dm_config_destroy(cft); return_NULL; } diff --git a/libdaemon/client/config-util.h b/libdaemon/client/config-util.h index 485161f7b..36ca2c073 100644 --- a/libdaemon/client/config-util.h +++ b/libdaemon/client/config-util.h @@ -66,6 +66,6 @@ struct dm_config_node *config_make_nodes(struct dm_config_tree *cft, struct dm_config_node *pre_sib, ...); -struct dm_config_tree *config_tree_from_string_without_dup_node_check(const char *config_settings); +struct dm_config_tree *config_tree_from_string_without_dup_node_check(const char *config_settings, size_t len); #endif /* _LVM_DAEMON_CONFIG_UTIL_H */ diff --git a/libdaemon/client/daemon-client.c b/libdaemon/client/daemon-client.c index bb8be30e3..538d41d5e 100644 --- a/libdaemon/client/daemon-client.c +++ b/libdaemon/client/daemon-client.c @@ -118,7 +118,7 @@ daemon_reply daemon_send(daemon_handle h, daemon_request rq) reply.error = errno; if (buffer_read(h.socket_fd, &reply.buffer)) { - reply.cft = config_tree_from_string_without_dup_node_check(reply.buffer.mem); + reply.cft = config_tree_from_string_without_dup_node_check(reply.buffer.mem, reply.buffer.used); if (!reply.cft) reply.error = EPROTO; } else diff --git a/libdaemon/server/daemon-server.c b/libdaemon/server/daemon-server.c index bb52857ce..0be31ac8c 100644 --- a/libdaemon/server/daemon-server.c +++ b/libdaemon/server/daemon-server.c @@ -450,7 +450,7 @@ static void *_client_thread(void *state) if (!buffer_read(ts->client.socket_fd, &req.buffer)) goto fail; - req.cft = config_tree_from_string_without_dup_node_check(req.buffer.mem); + req.cft = config_tree_from_string_without_dup_node_check(req.buffer.mem, req.buffer.used); if (!req.cft) fprintf(stderr, "error parsing request:\n %s\n", req.buffer.mem);