From 718eed47e4c2eb740dc04a6729c8853424ac6965 Mon Sep 17 00:00:00 2001
From: ksrinivasan ksriniva...@novell.com
Date: Wed, 8 Dec 2010 14:10:35 -0700
This daemon gathers all the guest specific information needed to support the
HyperV KVP functionality. This daemon communicates with the kernel
component via a netlink channel.
Signed-off-by: ksrinivasan ksriniva...@novell.com
---
drivers/staging/hv/tools/hv_kvp_daemon.c | 470 ++
1 files changed, 470 insertions(+), 0 deletions(-)
create mode 100644 drivers/staging/hv/tools/hv_kvp_daemon.c
diff --git a/drivers/staging/hv/tools/hv_kvp_daemon.c
b/drivers/staging/hv/tools/hv_kvp_daemon.c
new file mode 100644
index 000..f5a2dd6
--- /dev/null
+++ b/drivers/staging/hv/tools/hv_kvp_daemon.c
@@ -0,0 +1,470 @@
+/*
+ * An implementation of key value pair (KVP) functionality for Linux.
+ *
+ *
+ * Copyright (C) 2010, Novell, Inc.
+ * Author : K. Y. Srinivasan ksriniva...@novell.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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+
+#include sys/types.h
+#include sys/socket.h
+#include sys/poll.h
+#include sys/utsname.h
+#include linux/types.h
+#include stdio.h
+#include stdlib.h
+#include unistd.h
+#include string.h
+#include errno.h
+#include arpa/inet.h
+#include linux/connector.h
+#include linux/netlink.h
+#include sys/socket.h
+#include ifaddrs.h
+#include netdb.h
+#include syslog.h
+
+/*
+ * KYS: TODO. Need to register these in the kernel.
+ *
+ * The following definitions are shared with the in-kernel component; do not
+ * change any of this without making the corresponding changes in
+ * the KVP kernel component.
+ */
+#define CN_KVP_IDX 0x9 /* MSFT KVP functionality */
+#define CN_KVP_VAL 0x1 /* This supports queries from the kernel */
+#define CN_KVP_USER_VAL0x2 /* This supports queries from the
user */
+
+/*
+ * KVP protocol: The user mode component first registers with the
+ * the kernel component. Subsequently, the kernel component requests, data
+ * for the specified keys. In response to this message the user mode component
+ * fills in the value corresponding to the specified key. We overload the
+ * sequence field in the cn_msg header to define our KVP message types.
+ *
+ * We use this infrastructure for also supporting queries from user mode
+ * application for state that may be maintained in the KVP kernel component.
+ *
+ * XXXKYS: Have a shared header file between the user and kernel (TODO)
+ */
+
+enum kvp_op {
+ KVP_REGISTER = 0, /* Register the user mode component*/
+ KVP_KERNEL_GET, /*Kernel is requesting the value for the specified key*/
+ KVP_KERNEL_SET, /*Kernel is providing the value for the specified key*/
+ KVP_USER_GET, /*User is requesting the value for the specified key*/
+ KVP_USER_SET /*User is providing the value for the specified key*/
+};
+
+#define HV_KVP_EXCHANGE_MAX_KEY_SIZE 512
+#define HV_KVP_EXCHANGE_MAX_VALUE_SIZE 2048
+
+struct hv_ku_msg {
+ __u32 kvp_index;
+ __u8 kvp_key[HV_KVP_EXCHANGE_MAX_KEY_SIZE]; /* Key name */
+ __u8 kvp_value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE]; /* Key value */
+};
+
+enum key_index {
+ FullyQualifiedDomainName = 0,
+ IntegrationServicesVersion, /*This key is serviced in the kernel*/
+ NetworkAddressIPv4,
+ NetworkAddressIPv6,
+ OSBuildNumber,
+ OSName,
+ OSMajorVersion,
+ OSMinorVersion,
+ OSVersion,
+ ProcessorArchitecture
+};
+
+/*
+ * End of shared definitions.
+ */
+
+static char kvp_send_buffer[4096];
+static char kvp_recv_buffer[4096];
+static struct sockaddr_nl addr;
+
+static char os_name[100];
+static char os_major[50];
+static char os_minor[50];
+static char processor_arch[50];
+static char os_build[100];
+static char *lic_version;
+
+void kvp_get_os_info(void)
+{
+ FILE*file;
+ char*eol;
+ struct utsname buf;
+
+ uname(buf);
+ strcpy(os_build, buf.release);
+ strcpy(processor_arch, buf.machine);
+
+ file = fopen(/etc/SuSE-release, r);
+ if (file != NULL)
+ goto kvp_osinfo_found;
+ file = fopen(/etc/redhat-release, r);
+ if (file != NULL)
+ goto kvp_osinfo_found;
+ /*
+* Add code for other supported platforms.
+*/
+
+ /*
+