Skip to content

Commit

Permalink
Tools: hv: cache FQDN in kvp_daemon to avoid timeouts
Browse files Browse the repository at this point in the history
kvp_daemon does some operations which take an unpredicable amount of
time. In addition the kernel driver gives the kvp_daemon a 5 second
timeout to respond to message from the host. If an operation such as
getaddrinfo takes a long time and the timeout triggers then netlink
errors occour. As a result of such errors the daemon just terminates and
the service becomes unavailable.

Idendifying and fixing these shortcomings in the kernel-userland
communication protocol will be done in separate patches. This change
fixes just one obvious timeout bug.

Update kvp_get_domain_name to not return a value, better diagnostic for
the consumer of the hostname string, remove trailing newline in error
case, use snprintf to not overrun output buffer, get hostname only once
and return the cached result.

Signed-off-by: Olaf Hering <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
olafhering authored and gregkh committed Sep 26, 2013
1 parent d667566 commit 5812521
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions tools/hv/hv_kvp_daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ static char *processor_arch;
static char *os_build;
static char *os_version;
static char *lic_version = "Unknown version";
static char full_domain_name[HV_KVP_EXCHANGE_MAX_VALUE_SIZE];
static struct utsname uts_buf;

/*
Expand Down Expand Up @@ -1367,7 +1368,7 @@ static int kvp_set_ip_info(char *if_name, struct hv_kvp_ipaddr_value *new_val)
}


static int
static void
kvp_get_domain_name(char *buffer, int length)
{
struct addrinfo hints, *info ;
Expand All @@ -1381,12 +1382,12 @@ kvp_get_domain_name(char *buffer, int length)

error = getaddrinfo(buffer, NULL, &hints, &info);
if (error != 0) {
strcpy(buffer, "getaddrinfo failed\n");
return error;
snprintf(buffer, length, "getaddrinfo failed: 0x%x %s",
error, gai_strerror(error));
return;
}
strcpy(buffer, info->ai_canonname);
snprintf(buffer, length, "%s", info->ai_canonname);
freeaddrinfo(info);
return error;
}

static int
Expand Down Expand Up @@ -1453,6 +1454,11 @@ int main(void)
* Retrieve OS release information.
*/
kvp_get_os_info();
/*
* 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()) {
syslog(LOG_ERR, "Failed to initialize the pools");
Expand Down Expand Up @@ -1671,8 +1677,7 @@ int main(void)

switch (hv_msg->body.kvp_enum_data.index) {
case FullyQualifiedDomainName:
kvp_get_domain_name(key_value,
HV_KVP_EXCHANGE_MAX_VALUE_SIZE);
strcpy(key_value, full_domain_name);
strcpy(key_name, "FullyQualifiedDomainName");
break;
case IntegrationServicesVersion:
Expand Down

0 comments on commit 5812521

Please sign in to comment.