Accepting request 1236106 from Virtualization

- update route parsing in kvp daemon
- reduce resource usage in hv_kvp_daemon (175c71c2)
- reduce resouce usage in hv_get_dns_info helper (a4d024fe)
- hv_kvp_daemon: Pass NIC name to hv_get_dns_info as well (07dfa6e8)
- terminate fcopy daemon if read from uio fails (a9640fcd)
- change permissions of NetworkManager configuration file (91ae69c7)
- Fix a complier warning in the fcopy uio daemon (cb1b78f1)
- remove obsolete kvptest.ps1.txt which failed since a decade
- remove obsolete rpm postinstall code for SLE11SP2

OBS-URL: https://build.opensuse.org/request/show/1236106
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/hyper-v?expand=0&rev=47
This commit is contained in:
Ana Guerrero 2025-01-09 14:05:51 +00:00 committed by Git OBS Bridge
commit b5f9af4b20
7 changed files with 157 additions and 110 deletions

View File

@ -1,3 +1,16 @@
-------------------------------------------------------------------
Wed Jan 1 01:01:01 UTC 2025 - ohering@suse.de
- update route parsing in kvp daemon
- reduce resource usage in hv_kvp_daemon (175c71c2)
- reduce resouce usage in hv_get_dns_info helper (a4d024fe)
- hv_kvp_daemon: Pass NIC name to hv_get_dns_info as well (07dfa6e8)
- terminate fcopy daemon if read from uio fails (a9640fcd)
- change permissions of NetworkManager configuration file (91ae69c7)
- Fix a complier warning in the fcopy uio daemon (cb1b78f1)
- remove obsolete kvptest.ps1.txt which failed since a decade
- remove obsolete rpm postinstall code for SLE11SP2
-------------------------------------------------------------------
Tue Oct 22 22:22:22 UTC 2024 - ohering@suse.de

View File

@ -1,5 +1,131 @@
--- a/hyper-v.tools.hv.hv_kvp_daemon.c
+++ b/hyper-v.tools.hv.hv_kvp_daemon.c
@@ -24,6 +24,7 @@
#include <sys/poll.h>
#include <sys/utsname.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -677,6 +678,83 @@ static void kvp_process_ipconfig_file(ch
pclose(file);
}
+static bool kvp_verify_ip_address(void *address_string)
+{
+ char verify_buf[sizeof(struct in6_addr)];
+
+ if (inet_pton(AF_INET, address_string, verify_buf) == 1)
+ return true;
+ if (inet_pton(AF_INET6, address_string, verify_buf) == 1)
+ return true;
+ return false;
+}
+
+static void kvp_extract_routes(void **output, size_t *output_len, char *line)
+{
+ static const char needle[] = "via ";
+ char *match, *haystack = line;
+
+ while ((match = strstr(haystack, needle))) {
+ char *address, *end;
+
+ /* Address starts after needle. */
+ address = match + strlen(needle);
+
+ /* The char following address is a space or end of line. */
+ end = strpbrk(address, " \t\\");
+ if (!end)
+ end = address + strlen(address) + 1;
+
+ /* Enough room for address and semicolon. */
+ if (*output_len >= (end - address) + 1) {
+ memcpy(*output, address, end - address);
+ /* Terminate string for verification. */
+ memcpy(*output + (end - address), "", 1);
+ if (kvp_verify_ip_address(*output)) {
+ /* Advance output buffer. */
+ *output += end - address;
+ *output_len -= end - address;
+
+ /* Each address needs a trailing semicolon. */
+ memcpy(*output, ";", 1);
+ *output += 1;
+ *output_len -= 1;
+ }
+ }
+ haystack = end;
+ }
+}
+
+static void kvp_get_gateway(void *buffer, size_t buffer_len)
+{
+ static const char needle[] = "default ";
+ FILE *f;
+ void *output = buffer;
+ char *line = NULL;
+ size_t alloc_size = 0, output_len = buffer_len - 1;
+ ssize_t num_chars;
+
+ /* Show route information in a single line, for each address family */
+ f = popen("ip --oneline -4 route show;exec ip --oneline -6 route show", "r");
+ while ((num_chars = getline(&line, &alloc_size, f)) > 0) {
+ /* Skip short lines. */
+ if (num_chars <= strlen(needle))
+ continue;
+ /* Skip lines without default route. */
+ if (memcmp(line, needle, strlen(needle)))
+ continue;
+ /* Remove trailing newline to simplify further parsing. */
+ if (line[num_chars - 1] == '\n')
+ line[num_chars - 1] = '\0';
+ /* Search routes after match. */
+ kvp_extract_routes(&output, &output_len, line + strlen(needle));
+ }
+ /* Convert buffer into C-String. */
+ memcpy(output, "", 1);
+ free(line);
+ pclose(f);
+}
+
static void kvp_get_ipconfig_info(char *if_name,
struct hv_kvp_ipaddr_value *buffer)
{
@@ -684,32 +762,7 @@ static void kvp_get_ipconfig_info(char *
char dhcp_info[128];
char *p;
FILE *file;
-
- /*
- * Get the address of default gateway (ipv4).
- */
- sprintf(cmd, "%s %s", "ip route show dev", if_name);
- strcat(cmd, " | awk '/default/ {print $3 }'");
-
- /*
- * Execute the command to gather gateway info.
- */
- kvp_process_ipconfig_file(cmd, (char *)buffer->gate_way,
- (MAX_GATEWAY_SIZE * 2), INET_ADDRSTRLEN, 0);
-
- /*
- * Get the address of default gateway (ipv6).
- */
- sprintf(cmd, "%s %s", "ip -f inet6 route show dev", if_name);
- strcat(cmd, " | awk '/default/ {print $3 }'");
-
- /*
- * Execute the command to gather gateway info (ipv6).
- */
- kvp_process_ipconfig_file(cmd, (char *)buffer->gate_way,
- (MAX_GATEWAY_SIZE * 2), INET6_ADDRSTRLEN, 1);
-
-
+ kvp_get_gateway(buffer->gate_way, sizeof(buffer->gate_way));
/*
* Gather the DNS state.
* Since there is no standard way to get this information
@@ -1335,6 +1335,7 @@ kvp_get_domain_name(char *buffer, int le
struct addrinfo hints, *info ;
int error = 0;

View File

@ -1,49 +0,0 @@
# Windows PowerShell script to test Key Value Pair functionality
#
# http://blogs.msdn.com/b/virtual_pc_guy/archive/2008/11/18/hyper-v-script-looking-at-kvp-guestintrinsicexchangeitems.aspx
#
# Per default execution of scripts is disabled.
# http://technet.microsoft.com/en-us/library/ee176949.aspx
# The command 'Set-ExecutionPolicy RemoteSigned' will enable it.
#
# Filter for parsing XML data
filter Import-CimXml
{
# Create new XML object from input
$CimXml = [Xml]$_
$CimObj = New-Object -TypeName System.Object
# Iterate over the data and pull out just the value name and data for each entry
foreach ($CimProperty in $CimXml.SelectNodes("/INSTANCE/PROPERTY[@NAME='Name']"))
{
$CimObj | Add-Member -MemberType NoteProperty -Name $CimProperty.NAME -Value $CimProperty.VALUE
}
foreach ($CimProperty in $CimXml.SelectNodes("/INSTANCE/PROPERTY[@NAME='Data']"))
{
$CimObj | Add-Member -MemberType NoteProperty -Name $CimProperty.NAME -Value $CimProperty.VALUE
}
# Display output
$CimObj
}
# Prompt for the Hyper-V Server to use
$HyperVServer = Read-Host "Specify the Hyper-V Server to use (enter '.' for the local computer)"
# Prompt for the virtual machine to use
$VMName = Read-Host "Specify the name of the virtual machine"
# Get the virtual machine object
$query = "Select * From Msvm_ComputerSystem Where ElementName='" + $VMName + "'"
$Vm = gwmi -namespace root\virtualization -query $query -computername $HyperVServer
# Get the KVP Object
$query = "Associators of {$Vm} Where AssocClass=Msvm_SystemDevice ResultClass=Msvm_KvpExchangeComponent"
$Kvp = gwmi -namespace root\virtualization -query $query -computername $HyperVServer
Write-Host
Write-Host "Guest KVP information for" $VMName
# Filter the results
$Kvp.GuestIntrinsicExchangeItems | Import-CimXml

View File

@ -43,7 +43,6 @@ URL: http://www.kernel.org
Version: 9
Release: 0
Source0: hyper-v.lsvmbus.py
Source5: hyper-v.kvptest.ps1.txt
Source7: hyper-v.compare-with-upstream.sh
Source8: hyper-v.tools.hv.vmbus_bufring.h
Source9: hyper-v.include.linux.hyperv.h
@ -63,7 +62,6 @@ This package contains the Microsoft Hyper-V tools.
%prep
%setup -Tc
cp -avL %{S:5} kvptest.ps1.txt
cp -vL %{S:8} %vmbus_bufring.h
cp -vL %{S:9} %include_uapi_linux_hyperv.h
cp -vL %{S:10} .
@ -263,58 +261,15 @@ chmod 755 %buildroot${bindir}/${helper}
%?python3_fix_shebang
%files
%doc kvptest.ps1.txt
%_unitdir/*
%_udevrulesdir/*
%_sbindir/*
%helper_dir
%pre
# hv_kvp_daemon in SLES11 SP2 stored temporary state files in /var/opt
# move them to /var/lib and remove old directory, if possible.
if test -d /var/opt/hyperv
then
if mkdir -p -v -m 0755 /var/lib/hyperv
then
cd /var/lib/hyperv
for oldfile in /var/opt/hyperv/ifcfg-* /var/opt/hyperv/.kvp_pool_*
do
if test -e "${oldfile}"
then
mv -vfb "${oldfile}" . || :
fi
done
cd - >/dev/null
fi
rmdir -v /var/opt/hyperv || :
fi
: nothing to do in case of systemd
# the relevant part is systemctl daemon-reload, due to udev triggers
%post
board_vendor=
product_name=
if cd /sys/class/dmi/id 2>/dev/null
then
if test -r board_vendor
then
board_vendor="`cat board_vendor`"
fi
if test -r product_name
then
product_name="`cat product_name`"
fi
cd - >/dev/null
fi
if test "${board_vendor}" = "Microsoft Corporation" -a "${product_name}" = "Virtual Machine"
then
: nothing to do in case of systemd
fi
%preun
: nothing to do in case of systemd
%service_add_post %hv_kvp_daemon %hv_vss_daemon %hv_fcopy_daemon %hv_fcopy_uio_daemon
%postun
# no restart on update because the daemon can not be restarted
: nothing to do in case of systemd
%service_del_postun_without_restart %hv_kvp_daemon %hv_vss_daemon %hv_fcopy_daemon %hv_fcopy_uio_daemon
%changelog

View File

@ -35,8 +35,6 @@
#define WIN8_SRV_MINOR 1
#define WIN8_SRV_VERSION (WIN8_SRV_MAJOR << 16 | WIN8_SRV_MINOR)
#define MAX_FOLDER_NAME 15
#define MAX_PATH_LEN 15
#define FCOPY_UIO "/sys/bus/vmbus/devices/eb765408-105f-49b6-b4aa-c123b64d17d4/uio"
#define FCOPY_VER_COUNT 1
@ -51,7 +49,7 @@ static const int fw_versions[] = {
#define HV_RING_SIZE 0x4000 /* 16KB ring buffer size */
unsigned char desc[HV_RING_SIZE];
static unsigned char desc[HV_RING_SIZE];
static int target_fd;
static char target_fname[PATH_MAX];
@ -409,8 +407,8 @@ int main(int argc, char *argv[])
struct vmbus_br txbr, rxbr;
void *ring;
uint32_t len = HV_RING_SIZE;
char uio_name[MAX_FOLDER_NAME] = {0};
char uio_dev_path[MAX_PATH_LEN] = {0};
char uio_name[NAME_MAX] = {0};
char uio_dev_path[PATH_MAX] = {0};
static struct option long_options[] = {
{"help", no_argument, 0, 'h' },
@ -468,8 +466,10 @@ int main(int argc, char *argv[])
*/
ret = pread(fcopy_fd, &tmp, sizeof(int), 0);
if (ret < 0) {
if (errno == EINTR || errno == EAGAIN)
continue;
syslog(LOG_ERR, "pread failed: %s", strerror(errno));
continue;
goto close;
}
len = HV_RING_SIZE;

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
# This script parses /etc/resolv.conf to retrive DNS information.
# In the interest of keeping the KVP daemon code free of distro specific
@ -10,7 +10,8 @@
# this script can be based on the Network Manager APIs for retrieving DNS
# entries.
if test -r /etc/resolv.conf
if test -f /etc/resolv.conf
then
awk -- '/^nameserver/ { print $2 }' /etc/resolv.conf
exec awk -- '/^nameserver/ { print $2 }' /etc/resolv.conf
fi
exit 0

View File

@ -725,7 +725,7 @@ static void kvp_get_ipconfig_info(char *if_name,
* .
*/
sprintf(cmd, KVP_SCRIPTS_PATH "%s", "hv_get_dns_info");
sprintf(cmd, "exec %s %s", KVP_SCRIPTS_PATH "hv_get_dns_info", if_name);
/*
* Execute the command to gather DNS info.
@ -742,7 +742,7 @@ static void kvp_get_ipconfig_info(char *if_name,
* Enabled: DHCP enabled.
*/
sprintf(cmd, KVP_SCRIPTS_PATH "%s %s", "hv_get_dhcp_info", if_name);
sprintf(cmd, "exec %s %s", KVP_SCRIPTS_PATH "hv_get_dhcp_info", if_name);
file = popen(cmd, "r");
if (file == NULL)
@ -1606,8 +1606,9 @@ static int kvp_set_ip_info(char *if_name, struct hv_kvp_ipaddr_value *new_val)
* invoke the external script to do its magic.
*/
str_len = snprintf(cmd, sizeof(cmd), KVP_SCRIPTS_PATH "%s %s %s",
"hv_set_ifconfig", if_filename, nm_filename);
str_len = snprintf(cmd, sizeof(cmd), "exec %s %s %s",
KVP_SCRIPTS_PATH "hv_set_ifconfig",
if_filename, nm_filename);
/*
* This is a little overcautious, but it's necessary to suppress some
* false warnings from gcc 8.0.1.