From d64924508d11db59fdbfbd7c3d25d62c445ca0ba8379b3b773429e926a15ed3b Mon Sep 17 00:00:00 2001 From: Olaf Hering Date: Mon, 12 Jan 2015 09:44:54 +0000 Subject: [PATCH] - Check return value of setsockopt call - Improve error logging in VSS daemon. - Check return value of poll call - Properly pack the data for file copy functionality - make struct hv_do_fcopy match Hyper-V host messages OBS-URL: https://build.opensuse.org/package/show/Virtualization/hyper-v?expand=0&rev=107 --- hyper-v.changes | 9 +++++++++ hyper-v.include.linux.hyperv.h | 3 ++- hyper-v.spec | 2 +- hyper-v.tools.hv.hv_fcopy_daemon.c | 2 +- hyper-v.tools.hv.hv_kvp_daemon.c | 2 +- hyper-v.tools.hv.hv_vss_daemon.c | 27 +++++++++++++++++++++------ 6 files changed, 35 insertions(+), 10 deletions(-) diff --git a/hyper-v.changes b/hyper-v.changes index efa5e6d..48e3ccf 100644 --- a/hyper-v.changes +++ b/hyper-v.changes @@ -1,3 +1,12 @@ +------------------------------------------------------------------- +Mon Jan 12 09:37:40 UTC 2015 - ohering@suse.de + +- Check return value of setsockopt call +- Improve error logging in VSS daemon. +- Check return value of poll call +- Properly pack the data for file copy functionality +- make struct hv_do_fcopy match Hyper-V host messages + ------------------------------------------------------------------- Wed Dec 17 09:06:33 UTC 2014 - ohering@suse.de diff --git a/hyper-v.include.linux.hyperv.h b/hyper-v.include.linux.hyperv.h index 29f83dd..fe56441 100644 --- a/hyper-v.include.linux.hyperv.h +++ b/hyper-v.include.linux.hyperv.h @@ -128,10 +128,11 @@ struct hv_start_fcopy { struct hv_do_fcopy { struct hv_fcopy_hdr hdr; + __u32 pad; __u64 offset; __u32 size; __u8 data[DATA_FRAGMENT]; -}; +} __attribute__((packed)); /* diff --git a/hyper-v.spec b/hyper-v.spec index 85c5d51..3bfb8d8 100644 --- a/hyper-v.spec +++ b/hyper-v.spec @@ -1,7 +1,7 @@ # # spec file for package hyper-v # -# Copyright (c) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany. +# Copyright (c) 2015 SUSE LINUX Products GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed diff --git a/hyper-v.tools.hv.hv_fcopy_daemon.c b/hyper-v.tools.hv.hv_fcopy_daemon.c index e48eebf..b819c0e 100644 --- a/hyper-v.tools.hv.hv_fcopy_daemon.c +++ b/hyper-v.tools.hv.hv_fcopy_daemon.c @@ -174,7 +174,7 @@ int main(int argc, char *argv[]) fcopy_fd = open("/dev/vmbus/hv_fcopy", O_RDWR); if (fcopy_fd < 0) { - syslog(LOG_ERR, "open /dev/hv_fcopy failed; error: %d %s", + syslog(LOG_ERR, "open /dev/vmbus/hv_fcopy failed; error: %d %s", errno, strerror(errno)); exit(EXIT_FAILURE); } diff --git a/hyper-v.tools.hv.hv_kvp_daemon.c b/hyper-v.tools.hv.hv_kvp_daemon.c index 7f70579..d020f06 100644 --- a/hyper-v.tools.hv.hv_kvp_daemon.c +++ b/hyper-v.tools.hv.hv_kvp_daemon.c @@ -1485,7 +1485,7 @@ int main(int argc, char *argv[]) kvp_get_os_info(); /* * Cache Fully Qualified Domain Name because getaddrinfo takes an - * unpredicatable amount of time to finish. + * unpredictable amount of time to finish. */ kvp_get_domain_name(full_domain_name, sizeof(full_domain_name)); diff --git a/hyper-v.tools.hv.hv_vss_daemon.c b/hyper-v.tools.hv.hv_vss_daemon.c index fe380c7..e1567ae 100644 --- a/hyper-v.tools.hv.hv_vss_daemon.c +++ b/hyper-v.tools.hv.hv_vss_daemon.c @@ -221,7 +221,8 @@ int main(int argc, char *argv[]) fd = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_CONNECTOR); if (fd < 0) { - syslog(LOG_ERR, "netlink socket creation failed; error:%d", fd); + syslog(LOG_ERR, "netlink socket creation failed; error:%d %s", + errno, strerror(errno)); exit(EXIT_FAILURE); } addr.nl_family = AF_NETLINK; @@ -232,12 +233,16 @@ int main(int argc, char *argv[]) error = bind(fd, (struct sockaddr *)&addr, sizeof(addr)); if (error < 0) { - syslog(LOG_ERR, "bind failed; error:%d", error); + syslog(LOG_ERR, "bind failed; error:%d %s", errno, strerror(errno)); close(fd); exit(EXIT_FAILURE); } nl_group = CN_VSS_IDX; - setsockopt(fd, SOL_NETLINK, NETLINK_ADD_MEMBERSHIP, &nl_group, sizeof(nl_group)); + if (setsockopt(fd, SOL_NETLINK, NETLINK_ADD_MEMBERSHIP, &nl_group, sizeof(nl_group)) < 0) { + syslog(LOG_ERR, "setsockopt failed; error:%d %s", errno, strerror(errno)); + close(fd); + exit(EXIT_FAILURE); + } /* * Register ourselves with the kernel. */ @@ -252,7 +257,7 @@ int main(int argc, char *argv[]) len = netlink_send(fd, message); if (len < 0) { - syslog(LOG_ERR, "netlink_send failed; error:%d", len); + syslog(LOG_ERR, "netlink_send failed; error:%d %s", errno, strerror(errno)); close(fd); exit(EXIT_FAILURE); } @@ -264,7 +269,16 @@ int main(int argc, char *argv[]) socklen_t addr_l = sizeof(addr); pfd.events = POLLIN; pfd.revents = 0; - poll(&pfd, 1, -1); + + if (poll(&pfd, 1, -1) < 0) { + syslog(LOG_ERR, "poll failed; error:%d %s", errno, strerror(errno)); + if (errno == EINVAL) { + close(fd); + exit(EXIT_FAILURE); + } + else + continue; + } len = recvfrom(fd, vss_recv_buffer, vss_recv_buffer_len, 0, addr_p, &addr_l); @@ -314,7 +328,8 @@ int main(int argc, char *argv[]) vss_msg->error = error; len = netlink_send(fd, incoming_cn_msg); if (len < 0) { - syslog(LOG_ERR, "net_link send failed; error:%d", len); + syslog(LOG_ERR, "net_link send failed; error:%d %s", + errno, strerror(errno)); exit(EXIT_FAILURE); } }