* Fri Jun 20 2025 Miroslav Rezanina <mrezanin@redhat.com> - 0-0.50.20220731git

- hpvd-tools-hv-Enable-debug-logs-for-hv_kvp_daemon.patch [RHEL-95811]
- Resolves: RHEL-95811
  ([RHEL-10]Backport tools: hv: Enable debug logs for hv_kvp_daemon for RHEL 10)
This commit is contained in:
Miroslav Rezanina 2025-06-20 01:52:11 -04:00
parent 711476e4cd
commit 0afd7bacd1
2 changed files with 211 additions and 1 deletions

View File

@ -0,0 +1,203 @@
From b8bb4a01a28d4c1861a953e41be02801a8236159 Mon Sep 17 00:00:00 2001
From: Shradha Gupta <shradhagupta@linux.microsoft.com>
Date: Tue, 15 Apr 2025 04:19:38 -0700
Subject: [PATCH] tools: hv: Enable debug logs for hv_kvp_daemon
RH-Author: Xuemin Li <None>
RH-MergeRequest: 12: tools: hv: Enable debug logs for hv_kvp_daemon
RH-Jira: RHEL-95811
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
RH-Commit: [1/1] 0f3b64c388a223a2306b67ea4804fb1b64fa8810
Allow the KVP daemon to log the KVP updates triggered in the VM
with a new debug flag(-d).
When the daemon is started with this flag, it logs updates and debug
information in syslog with loglevel LOG_DEBUG. This information comes
in handy for debugging issues where the key-value pairs for certain
pools show mismatch/incorrect values.
The distro-vendors can further consume these changes and modify the
respective service files to redirect the logs to specific files as
needed.
Signed-off-by: Shradha Gupta <shradhagupta@linux.microsoft.com>
Reviewed-by: Naman Jain <namjain@linux.microsoft.com>
Reviewed-by: Dexuan Cui <decui@microsoft.com>
Link: https://lore.kernel.org/r/1744715978-8185-1-git-send-email-shradhagupta@linux.microsoft.com
Signed-off-by: Wei Liu <wei.liu@kernel.org>
Message-ID: <1744715978-8185-1-git-send-email-shradhagupta@linux.microsoft.com>
(cherry picked from commit a9c0b33ef2306327dd2db02c6274107065ff9307)
Signed-off-by: Xuemin Li <xuli@redhat.com>
---
hv_kvp_daemon.c | 64 +++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 59 insertions(+), 5 deletions(-)
diff --git a/hv_kvp_daemon.c b/hv_kvp_daemon.c
index 931eb53..0775f9b 100644
--- a/hv_kvp_daemon.c
+++ b/hv_kvp_daemon.c
@@ -83,6 +83,7 @@ enum {
};
static int in_hand_shake;
+static int debug;
static char *os_name = "";
static char *os_major = "";
@@ -183,6 +184,20 @@ static void kvp_update_file(int pool)
kvp_release_lock(pool);
}
+static void kvp_dump_initial_pools(int pool)
+{
+ int i;
+
+ syslog(LOG_DEBUG, "===Start dumping the contents of pool %d ===\n",
+ pool);
+
+ for (i = 0; i < kvp_file_info[pool].num_records; i++)
+ syslog(LOG_DEBUG, "pool: %d, %d/%d key=%s val=%s\n",
+ pool, i + 1, kvp_file_info[pool].num_records,
+ kvp_file_info[pool].records[i].key,
+ kvp_file_info[pool].records[i].value);
+}
+
static void kvp_update_mem_state(int pool)
{
FILE *filep;
@@ -270,6 +285,8 @@ static int kvp_file_init(void)
return 1;
kvp_file_info[i].num_records = 0;
kvp_update_mem_state(i);
+ if (debug)
+ kvp_dump_initial_pools(i);
}
return 0;
@@ -297,6 +314,9 @@ static int kvp_key_delete(int pool, const __u8 *key, int key_size)
* Found a match; just move the remaining
* entries up.
*/
+ if (debug)
+ syslog(LOG_DEBUG, "%s: deleting the KVP: pool=%d key=%s val=%s",
+ __func__, pool, record[i].key, record[i].value);
if (i == (num_records - 1)) {
kvp_file_info[pool].num_records--;
kvp_update_file(pool);
@@ -315,20 +335,36 @@ static int kvp_key_delete(int pool, const __u8 *key, int key_size)
kvp_update_file(pool);
return 0;
}
+
+ if (debug)
+ syslog(LOG_DEBUG, "%s: could not delete KVP: pool=%d key=%s. Record not found",
+ __func__, pool, key);
+
return 1;
}
static int kvp_key_add_or_modify(int pool, const __u8 *key, int key_size,
const __u8 *value, int value_size)
{
- int i;
- int num_records;
struct kvp_record *record;
+ int num_records;
int num_blocks;
+ int i;
+
+ if (debug)
+ syslog(LOG_DEBUG, "%s: got a KVP: pool=%d key=%s val=%s",
+ __func__, pool, key, value);
if ((key_size > HV_KVP_EXCHANGE_MAX_KEY_SIZE) ||
- (value_size > HV_KVP_EXCHANGE_MAX_VALUE_SIZE))
+ (value_size > HV_KVP_EXCHANGE_MAX_VALUE_SIZE)) {
+ syslog(LOG_ERR, "%s: Too long key or value: key=%s, val=%s",
+ __func__, key, value);
+
+ if (debug)
+ syslog(LOG_DEBUG, "%s: Too long key or value: pool=%d, key=%s, val=%s",
+ __func__, pool, key, value);
return 1;
+ }
/*
* First update the in-memory state.
@@ -348,6 +384,9 @@ static int kvp_key_add_or_modify(int pool, const __u8 *key, int key_size,
*/
memcpy(record[i].value, value, value_size);
kvp_update_file(pool);
+ if (debug)
+ syslog(LOG_DEBUG, "%s: updated: pool=%d key=%s val=%s",
+ __func__, pool, key, value);
return 0;
}
@@ -359,8 +398,10 @@ static int kvp_key_add_or_modify(int pool, const __u8 *key, int key_size,
record = realloc(record, sizeof(struct kvp_record) *
ENTRIES_PER_BLOCK * (num_blocks + 1));
- if (record == NULL)
+ if (!record) {
+ syslog(LOG_ERR, "%s: Memory alloc failure", __func__);
return 1;
+ }
kvp_file_info[pool].num_blocks++;
}
@@ -368,6 +409,11 @@ static int kvp_key_add_or_modify(int pool, const __u8 *key, int key_size,
memcpy(record[i].key, key, key_size);
kvp_file_info[pool].records = record;
kvp_file_info[pool].num_records++;
+
+ if (debug)
+ syslog(LOG_DEBUG, "%s: added: pool=%d key=%s val=%s",
+ __func__, pool, key, value);
+
kvp_update_file(pool);
return 0;
}
@@ -1661,6 +1707,7 @@ void print_usage(char *argv[])
fprintf(stderr, "Usage: %s [options]\n"
"Options are:\n"
" -n, --no-daemon stay in foreground, don't daemonize\n"
+ " -d, --debug Enable debug logs(syslog debug by default)\n"
" -h, --help print this help\n", argv[0]);
}
@@ -1682,10 +1729,11 @@ int main(int argc, char *argv[])
static struct option long_options[] = {
{"help", no_argument, 0, 'h' },
{"no-daemon", no_argument, 0, 'n' },
+ {"debug", no_argument, 0, 'd' },
{0, 0, 0, 0 }
};
- while ((opt = getopt_long(argc, argv, "hn", long_options,
+ while ((opt = getopt_long(argc, argv, "hnd", long_options,
&long_index)) != -1) {
switch (opt) {
case 'n':
@@ -1694,6 +1742,9 @@ int main(int argc, char *argv[])
case 'h':
print_usage(argv);
exit(0);
+ case 'd':
+ debug = 1;
+ break;
default:
print_usage(argv);
exit(EXIT_FAILURE);
@@ -1716,6 +1767,9 @@ int main(int argc, char *argv[])
*/
kvp_get_domain_name(full_domain_name, sizeof(full_domain_name));
+ if (debug)
+ syslog(LOG_INFO, "Logging debug info in syslog(debug)");
+
if (kvp_file_init()) {
syslog(LOG_ERR, "Failed to initialize the pools");
exit(EXIT_FAILURE);
--
2.39.3

View File

@ -13,7 +13,7 @@
Name: hyperv-daemons Name: hyperv-daemons
Version: 0 Version: 0
Release: 0.49%{?snapver}%{?dist} Release: 0.50%{?snapver}%{?dist}
Summary: Hyper-V daemons suite Summary: Hyper-V daemons suite
License: GPL-2.0-only License: GPL-2.0-only
@ -85,6 +85,8 @@ Patch12: hpvd-Changes-for-adding-keyfile-support-in-RHEL-specific-.patch
Patch13: hpvd-Use-NetworkManager-information-to-report-DHCP-settin.patch Patch13: hpvd-Use-NetworkManager-information-to-report-DHCP-settin.patch
# For RHEL-65434 - [Hyper-V][RHEL-10]KVP daemon inspects /etc/sysconfig/network-scripts/ifcfg-* files to get DHCP information # For RHEL-65434 - [Hyper-V][RHEL-10]KVP daemon inspects /etc/sysconfig/network-scripts/ifcfg-* files to get DHCP information
Patch14: hpvd-Use-NetworkManager-information-to-report-DNS-setting.patch Patch14: hpvd-Use-NetworkManager-information-to-report-DNS-setting.patch
# For RHEL-95811 - [RHEL-10]Backport tools: hv: Enable debug logs for hv_kvp_daemon for RHEL 10
Patch15: hpvd-tools-hv-Enable-debug-logs-for-hv_kvp_daemon.patch
# Hyper-V is available only on x86 and aarch64 architectures # Hyper-V is available only on x86 and aarch64 architectures
# The base empty (a.k.a. virtual) package can not be noarch # The base empty (a.k.a. virtual) package can not be noarch
@ -316,6 +318,11 @@ fi
%{_sbindir}/vmbus_testing %{_sbindir}/vmbus_testing
%changelog %changelog
* Fri Jun 20 2025 Miroslav Rezanina <mrezanin@redhat.com> - 0-0.50.20220731git
- hpvd-tools-hv-Enable-debug-logs-for-hv_kvp_daemon.patch [RHEL-95811]
- Resolves: RHEL-95811
([RHEL-10]Backport tools: hv: Enable debug logs for hv_kvp_daemon for RHEL 10)
* Thu Nov 21 2024 Miroslav Rezanina <mrezanin@redhat.com> - 0-0.49.20220731git * Thu Nov 21 2024 Miroslav Rezanina <mrezanin@redhat.com> - 0-0.49.20220731git
- hpvd-Use-NetworkManager-information-to-report-DHCP-settin.patch [RHEL-65434] - hpvd-Use-NetworkManager-information-to-report-DHCP-settin.patch [RHEL-65434]
- hpvd-Use-NetworkManager-information-to-report-DNS-setting.patch [RHEL-65434] - hpvd-Use-NetworkManager-information-to-report-DNS-setting.patch [RHEL-65434]