Commit 11bc3a5f authored by Vitaly Kuznetsov's avatar Vitaly Kuznetsov Committed by Greg Kroah-Hartman

Drivers: hv: kvp: convert to hv_utils_transport

Convert to hv_utils_transport to support both netlink and /dev/vmbus/hv_kvp communication methods.
Signed-off-by: default avatarVitaly Kuznetsov <vkuznets@redhat.com>
Tested-by: default avatarAlex Ng <alexng@microsoft.com>
Signed-off-by: default avatarK. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent c7e490fc
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <linux/hyperv.h> #include <linux/hyperv.h>
#include "hyperv_vmbus.h" #include "hyperv_vmbus.h"
#include "hv_utils_transport.h"
/* /*
* Pre win8 version numbers used in ws2008 and ws 2008 r2 (win7) * Pre win8 version numbers used in ws2008 and ws 2008 r2 (win7)
...@@ -83,9 +84,9 @@ static void kvp_register(int); ...@@ -83,9 +84,9 @@ static void kvp_register(int);
static DECLARE_DELAYED_WORK(kvp_timeout_work, kvp_timeout_func); static DECLARE_DELAYED_WORK(kvp_timeout_work, kvp_timeout_func);
static DECLARE_WORK(kvp_sendkey_work, kvp_send_key); static DECLARE_WORK(kvp_sendkey_work, kvp_send_key);
static struct cb_id kvp_id = { CN_KVP_IDX, CN_KVP_VAL }; static const char kvp_devname[] = "vmbus/hv_kvp";
static const char kvp_name[] = "kvp_kernel_module";
static u8 *recv_buffer; static u8 *recv_buffer;
static struct hvutil_transport *hvt;
/* /*
* Register the kernel component with the user-level daemon. * Register the kernel component with the user-level daemon.
* As part of this registration, pass the LIC version number. * As part of this registration, pass the LIC version number.
...@@ -97,23 +98,18 @@ static void ...@@ -97,23 +98,18 @@ static void
kvp_register(int reg_value) kvp_register(int reg_value)
{ {
struct cn_msg *msg;
struct hv_kvp_msg *kvp_msg; struct hv_kvp_msg *kvp_msg;
char *version; char *version;
msg = kzalloc(sizeof(*msg) + sizeof(struct hv_kvp_msg), GFP_ATOMIC); kvp_msg = kzalloc(sizeof(*kvp_msg), GFP_KERNEL);
if (msg) { if (kvp_msg) {
kvp_msg = (struct hv_kvp_msg *)msg->data;
version = kvp_msg->body.kvp_register.version; version = kvp_msg->body.kvp_register.version;
msg->id.idx = CN_KVP_IDX;
msg->id.val = CN_KVP_VAL;
kvp_msg->kvp_hdr.operation = reg_value; kvp_msg->kvp_hdr.operation = reg_value;
strcpy(version, HV_DRV_VERSION); strcpy(version, HV_DRV_VERSION);
msg->len = sizeof(struct hv_kvp_msg);
cn_netlink_send(msg, 0, 0, GFP_ATOMIC); hvutil_transport_send(hvt, kvp_msg, sizeof(*kvp_msg));
kfree(msg); kfree(kvp_msg);
} }
} }
...@@ -135,8 +131,6 @@ static void kvp_timeout_func(struct work_struct *dummy) ...@@ -135,8 +131,6 @@ static void kvp_timeout_func(struct work_struct *dummy)
static int kvp_handle_handshake(struct hv_kvp_msg *msg) static int kvp_handle_handshake(struct hv_kvp_msg *msg)
{ {
int ret = 1;
switch (msg->kvp_hdr.operation) { switch (msg->kvp_hdr.operation) {
case KVP_OP_REGISTER: case KVP_OP_REGISTER:
dm_reg_value = KVP_OP_REGISTER; dm_reg_value = KVP_OP_REGISTER;
...@@ -150,18 +144,17 @@ static int kvp_handle_handshake(struct hv_kvp_msg *msg) ...@@ -150,18 +144,17 @@ static int kvp_handle_handshake(struct hv_kvp_msg *msg)
pr_info("KVP: incompatible daemon\n"); pr_info("KVP: incompatible daemon\n");
pr_info("KVP: KVP version: %d, Daemon version: %d\n", pr_info("KVP: KVP version: %d, Daemon version: %d\n",
KVP_OP_REGISTER1, msg->kvp_hdr.operation); KVP_OP_REGISTER1, msg->kvp_hdr.operation);
ret = 0; return -EINVAL;
} }
if (ret) { /*
/* * We have a compatible daemon; complete the handshake.
* We have a compatible daemon; complete the handshake. */
*/ pr_info("KVP: user-mode registering done.\n");
pr_info("KVP: user-mode registering done.\n"); kvp_register(dm_reg_value);
kvp_register(dm_reg_value); kvp_transaction.state = HVUTIL_READY;
kvp_transaction.state = HVUTIL_READY;
} return 0;
return ret;
} }
...@@ -169,14 +162,14 @@ static int kvp_handle_handshake(struct hv_kvp_msg *msg) ...@@ -169,14 +162,14 @@ static int kvp_handle_handshake(struct hv_kvp_msg *msg)
* Callback when data is received from user mode. * Callback when data is received from user mode.
*/ */
static void static int kvp_on_msg(void *msg, int len)
kvp_cn_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp)
{ {
struct hv_kvp_msg *message; struct hv_kvp_msg *message = (struct hv_kvp_msg *)msg;
struct hv_kvp_msg_enumerate *data; struct hv_kvp_msg_enumerate *data;
int error = 0; int error = 0;
message = (struct hv_kvp_msg *)msg->data; if (len < sizeof(*message))
return -EINVAL;
/* /*
* If we are negotiating the version information * If we are negotiating the version information
...@@ -184,13 +177,13 @@ kvp_cn_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp) ...@@ -184,13 +177,13 @@ kvp_cn_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp)
*/ */
if (kvp_transaction.state < HVUTIL_READY) { if (kvp_transaction.state < HVUTIL_READY) {
kvp_handle_handshake(message); return kvp_handle_handshake(message);
return;
} }
/* We didn't send anything to userspace so the reply is spurious */ /* We didn't send anything to userspace so the reply is spurious */
if (kvp_transaction.state < HVUTIL_USERSPACE_REQ) if (kvp_transaction.state < HVUTIL_USERSPACE_REQ)
return; return -EINVAL;
kvp_transaction.state = HVUTIL_USERSPACE_RECV; kvp_transaction.state = HVUTIL_USERSPACE_RECV;
/* /*
...@@ -228,6 +221,8 @@ kvp_cn_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp) ...@@ -228,6 +221,8 @@ kvp_cn_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp)
hv_poll_channel(kvp_transaction.kvp_context, hv_poll_channel(kvp_transaction.kvp_context,
hv_kvp_onchannelcallback); hv_kvp_onchannelcallback);
} }
return 0;
} }
...@@ -344,7 +339,6 @@ static void process_ib_ipinfo(void *in_msg, void *out_msg, int op) ...@@ -344,7 +339,6 @@ static void process_ib_ipinfo(void *in_msg, void *out_msg, int op)
static void static void
kvp_send_key(struct work_struct *dummy) kvp_send_key(struct work_struct *dummy)
{ {
struct cn_msg *msg;
struct hv_kvp_msg *message; struct hv_kvp_msg *message;
struct hv_kvp_msg *in_msg; struct hv_kvp_msg *in_msg;
__u8 operation = kvp_transaction.kvp_msg->kvp_hdr.operation; __u8 operation = kvp_transaction.kvp_msg->kvp_hdr.operation;
...@@ -357,14 +351,7 @@ kvp_send_key(struct work_struct *dummy) ...@@ -357,14 +351,7 @@ kvp_send_key(struct work_struct *dummy)
if (kvp_transaction.state != HVUTIL_HOSTMSG_RECEIVED) if (kvp_transaction.state != HVUTIL_HOSTMSG_RECEIVED)
return; return;
msg = kzalloc(sizeof(*msg) + sizeof(struct hv_kvp_msg) , GFP_ATOMIC); message = kzalloc(sizeof(*message), GFP_KERNEL);
if (!msg)
return;
msg->id.idx = CN_KVP_IDX;
msg->id.val = CN_KVP_VAL;
message = (struct hv_kvp_msg *)msg->data;
message->kvp_hdr.operation = operation; message->kvp_hdr.operation = operation;
message->kvp_hdr.pool = pool; message->kvp_hdr.pool = pool;
in_msg = kvp_transaction.kvp_msg; in_msg = kvp_transaction.kvp_msg;
...@@ -451,9 +438,8 @@ kvp_send_key(struct work_struct *dummy) ...@@ -451,9 +438,8 @@ kvp_send_key(struct work_struct *dummy)
break; break;
} }
msg->len = sizeof(struct hv_kvp_msg);
kvp_transaction.state = HVUTIL_USERSPACE_REQ; kvp_transaction.state = HVUTIL_USERSPACE_REQ;
rc = cn_netlink_send(msg, 0, 0, GFP_ATOMIC); rc = hvutil_transport_send(hvt, message, sizeof(*message));
if (rc) { if (rc) {
pr_debug("KVP: failed to communicate to the daemon: %d\n", rc); pr_debug("KVP: failed to communicate to the daemon: %d\n", rc);
if (cancel_delayed_work_sync(&kvp_timeout_work)) { if (cancel_delayed_work_sync(&kvp_timeout_work)) {
...@@ -462,7 +448,7 @@ kvp_send_key(struct work_struct *dummy) ...@@ -462,7 +448,7 @@ kvp_send_key(struct work_struct *dummy)
} }
} }
kfree(msg); kfree(message);
return; return;
} }
...@@ -694,14 +680,16 @@ void hv_kvp_onchannelcallback(void *context) ...@@ -694,14 +680,16 @@ void hv_kvp_onchannelcallback(void *context)
} }
static void kvp_on_reset(void)
{
if (cancel_delayed_work_sync(&kvp_timeout_work))
kvp_respond_to_host(NULL, HV_E_FAIL);
kvp_transaction.state = HVUTIL_DEVICE_INIT;
}
int int
hv_kvp_init(struct hv_util_service *srv) hv_kvp_init(struct hv_util_service *srv)
{ {
int err;
err = cn_add_callback(&kvp_id, kvp_name, kvp_cn_callback);
if (err)
return err;
recv_buffer = srv->recv_buffer; recv_buffer = srv->recv_buffer;
/* /*
...@@ -712,13 +700,18 @@ hv_kvp_init(struct hv_util_service *srv) ...@@ -712,13 +700,18 @@ hv_kvp_init(struct hv_util_service *srv)
*/ */
kvp_transaction.state = HVUTIL_DEVICE_INIT; kvp_transaction.state = HVUTIL_DEVICE_INIT;
hvt = hvutil_transport_init(kvp_devname, CN_KVP_IDX, CN_KVP_VAL,
kvp_on_msg, kvp_on_reset);
if (!hvt)
return -EFAULT;
return 0; return 0;
} }
void hv_kvp_deinit(void) void hv_kvp_deinit(void)
{ {
kvp_transaction.state = HVUTIL_DEVICE_DYING; kvp_transaction.state = HVUTIL_DEVICE_DYING;
cn_del_callback(&kvp_id);
cancel_delayed_work_sync(&kvp_timeout_work); cancel_delayed_work_sync(&kvp_timeout_work);
cancel_work_sync(&kvp_sendkey_work); cancel_work_sync(&kvp_sendkey_work);
hvutil_transport_destroy(hvt);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment