- async name resolution in kvp_daemon (bsc#1100758)

- kvp: eliminate 'may be used uninitialized' warning (89eb4d8d)
- fix typos in toolchain (2d35c660)
- fixed Python pep8/flake8 warnings for lsvmbus (5912e791)
- Replace GPLv2 boilerplate/reference with SPDX (43aa3132)
- Fix a warning of buffer overflow with gcc 8.0.1 (4fcba780)

OBS-URL: https://build.opensuse.org/package/show/Virtualization/hyper-v?expand=0&rev=139
This commit is contained in:
Olaf Hering 2019-11-27 09:32:29 +00:00 committed by Git OBS Bridge
parent b932f55fe9
commit 21b02eaa39
7 changed files with 147 additions and 86 deletions

View File

@ -1,3 +1,13 @@
-------------------------------------------------------------------
Wed Nov 27 09:08:07 UTC 2019 - ohering@suse.de
- async name resolution in kvp_daemon (bsc#1100758)
- kvp: eliminate 'may be used uninitialized' warning (89eb4d8d)
- fix typos in toolchain (2d35c660)
- fixed Python pep8/flake8 warnings for lsvmbus (5912e791)
- Replace GPLv2 boilerplate/reference with SPDX (43aa3132)
- Fix a warning of buffer overflow with gcc 8.0.1 (4fcba780)
------------------------------------------------------------------- -------------------------------------------------------------------
Tue Oct 9 09:27:45 UTC 2018 - ohering@suse.de Tue Oct 9 09:27:45 UTC 2018 - ohering@suse.de

View File

@ -4,10 +4,10 @@
import os import os
from optparse import OptionParser from optparse import OptionParser
help_msg = "print verbose messages. Try -vv, -vvv for more verbose messages"
parser = OptionParser() parser = OptionParser()
parser.add_option("-v", "--verbose", dest="verbose", parser.add_option(
help="print verbose messages. Try -vv, -vvv for \ "-v", "--verbose", dest="verbose", help=help_msg, action="count")
more verbose messages", action="count")
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
@ -42,6 +42,7 @@ vmbus_dev_dict = {
'{3375baf4-9e15-4b30-b765-67acb10d607b}': '[Reserved system device]', '{3375baf4-9e15-4b30-b765-67acb10d607b}': '[Reserved system device]',
} }
def get_vmbus_dev_attr(dev_name, attr): def get_vmbus_dev_attr(dev_name, attr):
try: try:
f = open('%s/%s/%s' % (vmbus_sys_path, dev_name, attr), 'r') f = open('%s/%s/%s' % (vmbus_sys_path, dev_name, attr), 'r')
@ -52,6 +53,7 @@ def get_vmbus_dev_attr(dev_name, attr):
return lines return lines
class VMBus_Dev: class VMBus_Dev:
pass pass
@ -66,12 +68,13 @@ for f in os.listdir(vmbus_sys_path):
chn_vp_mapping = get_vmbus_dev_attr(f, 'channel_vp_mapping') chn_vp_mapping = get_vmbus_dev_attr(f, 'channel_vp_mapping')
chn_vp_mapping = [c.strip() for c in chn_vp_mapping] chn_vp_mapping = [c.strip() for c in chn_vp_mapping]
chn_vp_mapping = sorted(chn_vp_mapping, chn_vp_mapping = sorted(
key = lambda c : int(c.split(':')[0])) chn_vp_mapping, key=lambda c: int(c.split(':')[0]))
chn_vp_mapping = ['\tRel_ID=%s, target_cpu=%s' % chn_vp_mapping = [
(c.split(':')[0], c.split(':')[1]) '\tRel_ID=%s, target_cpu=%s' %
for c in chn_vp_mapping] (c.split(':')[0], c.split(':')[1]) for c in chn_vp_mapping
]
d = VMBus_Dev() d = VMBus_Dev()
d.sysfs_path = '%s/%s' % (vmbus_sys_path, f) d.sysfs_path = '%s/%s' % (vmbus_sys_path, f)
d.vmbus_id = vmbus_id d.vmbus_id = vmbus_id
@ -95,9 +98,15 @@ for d in vmbus_dev_list:
if verbose == 0: if verbose == 0:
print(('VMBUS ID ' + format0) % (d.vmbus_id, d.dev_desc)) print(('VMBUS ID ' + format0) % (d.vmbus_id, d.dev_desc))
elif verbose == 1: elif verbose == 1:
print (('VMBUS ID ' + format1) % \ print(
(d.vmbus_id, d.class_id, d.dev_desc, d.chn_vp_mapping)) ('VMBUS ID ' + format1) %
(d.vmbus_id, d.class_id, d.dev_desc, d.chn_vp_mapping)
)
else: else:
print (('VMBUS ID ' + format2) % \ print(
(d.vmbus_id, d.class_id, d.dev_desc, \ ('VMBUS ID ' + format2) %
d.device_id, d.sysfs_path, d.chn_vp_mapping)) (
d.vmbus_id, d.class_id, d.dev_desc,
d.device_id, d.sysfs_path, d.chn_vp_mapping
)
)

View File

@ -89,6 +89,7 @@ gcc \
-DCN_KVP_IDX=0x9 \ -DCN_KVP_IDX=0x9 \
-DCN_KVP_VAL=0x1 \ -DCN_KVP_VAL=0x1 \
-DKVP_SCRIPTS_PATH= \ -DKVP_SCRIPTS_PATH= \
-pthread \
-o %{hv_kvp_daemon} -o %{hv_kvp_daemon}
gcc \ gcc \
$RPM_OPT_FLAGS \ $RPM_OPT_FLAGS \

View File

@ -1,19 +1,10 @@
// SPDX-License-Identifier: GPL-2.0-only
/* /*
* An implementation of host to guest copy functionality for Linux. * An implementation of host to guest copy functionality for Linux.
* *
* Copyright (C) 2014, Microsoft, Inc. * Copyright (C) 2014, Microsoft, Inc.
* *
* Author : K. Y. Srinivasan <kys@microsoft.com> * Author : K. Y. Srinivasan <kys@microsoft.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
* NON INFRINGEMENT. See the GNU General Public License for more
* details.
*/ */

View File

@ -12,7 +12,7 @@
# the script prints the string "Disabled" to stdout. # the script prints the string "Disabled" to stdout.
# #
# Each Distro is expected to implement this script in a distro specific # Each Distro is expected to implement this script in a distro specific
# fashion. For instance on Distros that ship with Network Manager enabled, # fashion. For instance, on Distros that ship with Network Manager enabled,
# this script can be based on the Network Manager APIs for retrieving DHCP # this script can be based on the Network Manager APIs for retrieving DHCP
# information. # information.

View File

@ -41,6 +41,7 @@
#include <net/if.h> #include <net/if.h>
#include <limits.h> #include <limits.h>
#include <getopt.h> #include <getopt.h>
#include <pthread.h>
/* /*
* KVP protocol: The user mode component first registers with the * KVP protocol: The user mode component first registers with the
@ -85,7 +86,7 @@ static char *processor_arch;
static char *os_build; static char *os_build;
static char *os_version; static char *os_version;
static char *lic_version = "Unknown version"; static char *lic_version = "Unknown version";
static char full_domain_name[HV_KVP_EXCHANGE_MAX_VALUE_SIZE]; static char *full_domain_name;
static struct utsname uts_buf; static struct utsname uts_buf;
/* /*
@ -809,7 +810,7 @@ kvp_get_ip_info(int family, char *if_name, int op,
int sn_offset = 0; int sn_offset = 0;
int error = 0; int error = 0;
char *buffer; char *buffer;
struct hv_kvp_ipaddr_value *ip_buffer; struct hv_kvp_ipaddr_value *ip_buffer = NULL;
char cidr_mask[5]; /* /xyz */ char cidr_mask[5]; /* /xyz */
int weight; int weight;
int i; int i;
@ -1051,7 +1052,7 @@ static int parse_ip_val_buffer(char *in_buf, int *offset,
char *start; char *start;
/* /*
* in_buf has sequence of characters that are seperated by * in_buf has sequence of characters that are separated by
* the character ';'. The last sequence does not have the * the character ';'. The last sequence does not have the
* terminating ";" character. * terminating ";" character.
*/ */
@ -1178,6 +1179,7 @@ static int kvp_set_ip_info(char *if_name, struct hv_kvp_ipaddr_value *new_val)
FILE *file; FILE *file;
char cmd[PATH_MAX]; char cmd[PATH_MAX];
char *mac_addr; char *mac_addr;
int str_len;
/* /*
* Set the configuration for the specified interface with * Set the configuration for the specified interface with
@ -1301,8 +1303,18 @@ static int kvp_set_ip_info(char *if_name, struct hv_kvp_ipaddr_value *new_val)
* invoke the external script to do its magic. * invoke the external script to do its magic.
*/ */
snprintf(cmd, sizeof(cmd), KVP_SCRIPTS_PATH "%s %s", str_len = snprintf(cmd, sizeof(cmd), KVP_SCRIPTS_PATH "%s %s",
"hv_set_ifconfig", if_file); "hv_set_ifconfig", if_file);
/*
* This is a little overcautious, but it's necessary to suppress some
* false warnings from gcc 8.0.1.
*/
if (str_len <= 0 || (unsigned int)str_len >= sizeof(cmd)) {
syslog(LOG_ERR, "Cmd '%s' (len=%d) may be too long",
cmd, str_len);
return HV_E_FAIL;
}
if (system(cmd)) { if (system(cmd)) {
syslog(LOG_ERR, "Failed to execute cmd '%s'; error: %d %s", syslog(LOG_ERR, "Failed to execute cmd '%s'; error: %d %s",
cmd, errno, strerror(errno)); cmd, errno, strerror(errno));
@ -1317,27 +1329,76 @@ setval_error:
return error; return error;
} }
/*
static void * Async retrival of Fully Qualified Domain Name because getaddrinfo takes an
kvp_get_domain_name(char *buffer, int length) * unpredictable amount of time to finish.
*/
static void *kvp_getaddrinfo(void *p)
{ {
struct addrinfo hints, *info ; char *tmp, **str_ptr = (char **)p;
int error = 0; char hostname[HOST_NAME_MAX + 1];
struct addrinfo *info, hints = {
.ai_family = AF_INET, /* Get only ipv4 addrinfo. */
.ai_socktype = SOCK_STREAM,
.ai_flags = AI_CANONNAME,
};
int ret;
int prev_ret = 0, cnt = 5;
gethostname(buffer, length); do {
memset(&hints, 0, sizeof(hints)); if (gethostname(hostname, sizeof(hostname) - 1) < 0)
hints.ai_family = AF_INET; /*Get only ipv4 addrinfo. */ goto out;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_CANONNAME;
error = getaddrinfo(buffer, NULL, &hints, &info); ret = getaddrinfo(hostname, NULL, &hints, &info);
if (error != 0) { switch (ret) {
snprintf(buffer, length, "getaddrinfo failed: 0x%x %s", case 0:
error, gai_strerror(error)); break;
case EAI_BADFLAGS:
case EAI_MEMORY:
case EAI_OVERFLOW:
case EAI_SOCKTYPE:
case EAI_SYSTEM:
/* Permanent failure */
syslog(LOG_ERR, "getaddrinfo failed: %d %s",
ret, gai_strerror(ret));
goto out;
default:
/* runtime debug */
if (cnt) {
if (prev_ret != ret) {
prev_ret = ret;
syslog(LOG_ERR, "getaddrinfo warning: %d %s", ret, gai_strerror(ret));
cnt--;
}
}
/* Temporary failure, aim for success. */
sleep(5);
}
} while (ret);
ret = asprintf(&tmp, "%s", info->ai_canonname);
freeaddrinfo(info);
if (ret <= 0)
goto out;
if (ret > HV_KVP_EXCHANGE_MAX_VALUE_SIZE)
tmp[HV_KVP_EXCHANGE_MAX_VALUE_SIZE - 1] = '\0';
*str_ptr = tmp;
out:
pthread_exit(NULL);
}
static void kvp_obtain_domain_name(char **str_ptr)
{
pthread_t t;
if (pthread_create(&t, NULL, kvp_getaddrinfo, str_ptr)) {
syslog(LOG_ERR, "pthread_create failed; error: %d %s",
errno, strerror(errno));
return; return;
} }
snprintf(buffer, length, "%s", info->ai_canonname); pthread_detach(t);
freeaddrinfo(info);
} }
void print_usage(char *argv[]) void print_usage(char *argv[])
@ -1376,6 +1437,8 @@ int main(int argc, char *argv[])
daemonize = 0; daemonize = 0;
break; break;
case 'h': case 'h':
print_usage(argv);
exit(0);
default: default:
print_usage(argv); print_usage(argv);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -1400,11 +1463,7 @@ int main(int argc, char *argv[])
* Retrieve OS release information. * Retrieve OS release information.
*/ */
kvp_get_os_info(); kvp_get_os_info();
/* kvp_obtain_domain_name(&full_domain_name);
* Cache Fully Qualified Domain Name because getaddrinfo takes an
* unpredictable amount of time to finish.
*/
kvp_get_domain_name(full_domain_name, sizeof(full_domain_name));
if (kvp_file_init()) { if (kvp_file_init()) {
syslog(LOG_ERR, "Failed to initialize the pools"); syslog(LOG_ERR, "Failed to initialize the pools");
@ -1559,7 +1618,7 @@ int main(int argc, char *argv[])
switch (hv_msg->body.kvp_enum_data.index) { switch (hv_msg->body.kvp_enum_data.index) {
case FullyQualifiedDomainName: case FullyQualifiedDomainName:
strcpy(key_value, full_domain_name); strcpy(key_value, full_domain_name ? : "");
strcpy(key_name, "FullyQualifiedDomainName"); strcpy(key_name, "FullyQualifiedDomainName");
break; break;
case IntegrationServicesVersion: case IntegrationServicesVersion:

View File

@ -1,20 +1,9 @@
// SPDX-License-Identifier: GPL-2.0-only
/* /*
* An implementation of the host initiated guest snapshot for Hyper-V. * An implementation of the host initiated guest snapshot for Hyper-V.
* *
*
* Copyright (C) 2013, Microsoft, Inc. * Copyright (C) 2013, Microsoft, Inc.
* Author : K. Y. Srinivasan <kys@microsoft.com> * Author : K. Y. Srinivasan <kys@microsoft.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
* NON INFRINGEMENT. See the GNU General Public License for more
* details.
*
*/ */
@ -53,7 +42,7 @@ static int vss_do_freeze(char *dir, unsigned int cmd)
* If a partition is mounted more than once, only the first * If a partition is mounted more than once, only the first
* FREEZE/THAW can succeed and the later ones will get * FREEZE/THAW can succeed and the later ones will get
* EBUSY/EINVAL respectively: there could be 2 cases: * EBUSY/EINVAL respectively: there could be 2 cases:
* 1) a user may mount the same partition to differnt directories * 1) a user may mount the same partition to different directories
* by mistake or on purpose; * by mistake or on purpose;
* 2) The subvolume of btrfs appears to have the same partition * 2) The subvolume of btrfs appears to have the same partition
* mounted more than once. * mounted more than once.
@ -229,6 +218,8 @@ int main(int argc, char *argv[])
daemonize = 0; daemonize = 0;
break; break;
case 'h': case 'h':
print_usage(argv);
exit(0);
default: default:
print_usage(argv); print_usage(argv);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);