hv_kvp.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. /*
  2. * An implementation of key value pair (KVP) functionality for Linux.
  3. *
  4. *
  5. * Copyright (C) 2010, Novell, Inc.
  6. * Author : K. Y. Srinivasan <ksrinivasan@novell.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License version 2 as published
  10. * by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  15. * NON INFRINGEMENT. See the GNU General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21. *
  22. */
  23. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  24. #include <linux/net.h>
  25. #include <linux/nls.h>
  26. #include <linux/connector.h>
  27. #include <linux/workqueue.h>
  28. #include <linux/hyperv.h>
  29. /*
  30. * Pre win8 version numbers used in ws2008 and ws 2008 r2 (win7)
  31. */
  32. #define WIN7_SRV_MAJOR 3
  33. #define WIN7_SRV_MINOR 0
  34. #define WIN7_SRV_MAJOR_MINOR (WIN7_SRV_MAJOR << 16 | WIN7_SRV_MINOR)
  35. #define WIN8_SRV_MAJOR 4
  36. #define WIN8_SRV_MINOR 0
  37. #define WIN8_SRV_MAJOR_MINOR (WIN8_SRV_MAJOR << 16 | WIN8_SRV_MINOR)
  38. /*
  39. * Global state maintained for transaction that is being processed.
  40. * Note that only one transaction can be active at any point in time.
  41. *
  42. * This state is set when we receive a request from the host; we
  43. * cleanup this state when the transaction is completed - when we respond
  44. * to the host with the key value.
  45. */
  46. static struct {
  47. bool active; /* transaction status - active or not */
  48. int recv_len; /* number of bytes received. */
  49. struct hv_kvp_msg *kvp_msg; /* current message */
  50. struct vmbus_channel *recv_channel; /* chn we got the request */
  51. u64 recv_req_id; /* request ID. */
  52. void *kvp_context; /* for the channel callback */
  53. } kvp_transaction;
  54. /*
  55. * Before we can accept KVP messages from the host, we need
  56. * to handshake with the user level daemon. This state tracks
  57. * if we are in the handshake phase.
  58. */
  59. static bool in_hand_shake = true;
  60. /*
  61. * This state maintains the version number registered by the daemon.
  62. */
  63. static int dm_reg_value;
  64. static void kvp_send_key(struct work_struct *dummy);
  65. static void kvp_respond_to_host(struct hv_kvp_msg *msg, int error);
  66. static void kvp_work_func(struct work_struct *dummy);
  67. static void kvp_register(int);
  68. static DECLARE_DELAYED_WORK(kvp_work, kvp_work_func);
  69. static DECLARE_WORK(kvp_sendkey_work, kvp_send_key);
  70. static struct cb_id kvp_id = { CN_KVP_IDX, CN_KVP_VAL };
  71. static const char kvp_name[] = "kvp_kernel_module";
  72. static u8 *recv_buffer;
  73. /*
  74. * Register the kernel component with the user-level daemon.
  75. * As part of this registration, pass the LIC version number.
  76. */
  77. static void
  78. kvp_register(int reg_value)
  79. {
  80. struct cn_msg *msg;
  81. struct hv_kvp_msg *kvp_msg;
  82. char *version;
  83. msg = kzalloc(sizeof(*msg) + sizeof(struct hv_kvp_msg), GFP_ATOMIC);
  84. if (msg) {
  85. kvp_msg = (struct hv_kvp_msg *)msg->data;
  86. version = kvp_msg->body.kvp_register.version;
  87. msg->id.idx = CN_KVP_IDX;
  88. msg->id.val = CN_KVP_VAL;
  89. kvp_msg->kvp_hdr.operation = reg_value;
  90. strcpy(version, HV_DRV_VERSION);
  91. msg->len = sizeof(struct hv_kvp_msg);
  92. cn_netlink_send(msg, 0, GFP_ATOMIC);
  93. kfree(msg);
  94. }
  95. }
  96. static void
  97. kvp_work_func(struct work_struct *dummy)
  98. {
  99. /*
  100. * If the timer fires, the user-mode component has not responded;
  101. * process the pending transaction.
  102. */
  103. kvp_respond_to_host(NULL, HV_E_FAIL);
  104. }
  105. static int kvp_handle_handshake(struct hv_kvp_msg *msg)
  106. {
  107. int ret = 1;
  108. switch (msg->kvp_hdr.operation) {
  109. case KVP_OP_REGISTER:
  110. dm_reg_value = KVP_OP_REGISTER;
  111. pr_info("KVP: IP injection functionality not available\n");
  112. pr_info("KVP: Upgrade the KVP daemon\n");
  113. break;
  114. case KVP_OP_REGISTER1:
  115. dm_reg_value = KVP_OP_REGISTER1;
  116. break;
  117. default:
  118. pr_info("KVP: incompatible daemon\n");
  119. pr_info("KVP: KVP version: %d, Daemon version: %d\n",
  120. KVP_OP_REGISTER1, msg->kvp_hdr.operation);
  121. ret = 0;
  122. }
  123. if (ret) {
  124. /*
  125. * We have a compatible daemon; complete the handshake.
  126. */
  127. pr_info("KVP: user-mode registering done.\n");
  128. kvp_register(dm_reg_value);
  129. kvp_transaction.active = false;
  130. if (kvp_transaction.kvp_context)
  131. hv_kvp_onchannelcallback(kvp_transaction.kvp_context);
  132. }
  133. return ret;
  134. }
  135. /*
  136. * Callback when data is received from user mode.
  137. */
  138. static void
  139. kvp_cn_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp)
  140. {
  141. struct hv_kvp_msg *message;
  142. struct hv_kvp_msg_enumerate *data;
  143. int error = 0;
  144. message = (struct hv_kvp_msg *)msg->data;
  145. /*
  146. * If we are negotiating the version information
  147. * with the daemon; handle that first.
  148. */
  149. if (in_hand_shake) {
  150. if (kvp_handle_handshake(message))
  151. in_hand_shake = false;
  152. return;
  153. }
  154. /*
  155. * Based on the version of the daemon, we propagate errors from the
  156. * daemon differently.
  157. */
  158. data = &message->body.kvp_enum_data;
  159. switch (dm_reg_value) {
  160. case KVP_OP_REGISTER:
  161. /*
  162. * Null string is used to pass back error condition.
  163. */
  164. if (data->data.key[0] == 0)
  165. error = HV_S_CONT;
  166. break;
  167. case KVP_OP_REGISTER1:
  168. /*
  169. * We use the message header information from
  170. * the user level daemon to transmit errors.
  171. */
  172. error = message->error;
  173. break;
  174. }
  175. /*
  176. * Complete the transaction by forwarding the key value
  177. * to the host. But first, cancel the timeout.
  178. */
  179. if (cancel_delayed_work_sync(&kvp_work))
  180. kvp_respond_to_host(message, error);
  181. }
  182. static int process_ob_ipinfo(void *in_msg, void *out_msg, int op)
  183. {
  184. struct hv_kvp_msg *in = in_msg;
  185. struct hv_kvp_ip_msg *out = out_msg;
  186. int len;
  187. switch (op) {
  188. case KVP_OP_GET_IP_INFO:
  189. /*
  190. * Transform all parameters into utf16 encoding.
  191. */
  192. len = utf8s_to_utf16s((char *)in->body.kvp_ip_val.ip_addr,
  193. strlen((char *)in->body.kvp_ip_val.ip_addr),
  194. UTF16_HOST_ENDIAN,
  195. (wchar_t *)out->kvp_ip_val.ip_addr,
  196. MAX_IP_ADDR_SIZE);
  197. if (len < 0)
  198. return len;
  199. len = utf8s_to_utf16s((char *)in->body.kvp_ip_val.sub_net,
  200. strlen((char *)in->body.kvp_ip_val.sub_net),
  201. UTF16_HOST_ENDIAN,
  202. (wchar_t *)out->kvp_ip_val.sub_net,
  203. MAX_IP_ADDR_SIZE);
  204. if (len < 0)
  205. return len;
  206. len = utf8s_to_utf16s((char *)in->body.kvp_ip_val.gate_way,
  207. strlen((char *)in->body.kvp_ip_val.gate_way),
  208. UTF16_HOST_ENDIAN,
  209. (wchar_t *)out->kvp_ip_val.gate_way,
  210. MAX_GATEWAY_SIZE);
  211. if (len < 0)
  212. return len;
  213. len = utf8s_to_utf16s((char *)in->body.kvp_ip_val.dns_addr,
  214. strlen((char *)in->body.kvp_ip_val.dns_addr),
  215. UTF16_HOST_ENDIAN,
  216. (wchar_t *)out->kvp_ip_val.dns_addr,
  217. MAX_IP_ADDR_SIZE);
  218. if (len < 0)
  219. return len;
  220. len = utf8s_to_utf16s((char *)in->body.kvp_ip_val.adapter_id,
  221. strlen((char *)in->body.kvp_ip_val.adapter_id),
  222. UTF16_HOST_ENDIAN,
  223. (wchar_t *)out->kvp_ip_val.adapter_id,
  224. MAX_IP_ADDR_SIZE);
  225. if (len < 0)
  226. return len;
  227. out->kvp_ip_val.dhcp_enabled =
  228. in->body.kvp_ip_val.dhcp_enabled;
  229. out->kvp_ip_val.addr_family =
  230. in->body.kvp_ip_val.addr_family;
  231. }
  232. return 0;
  233. }
  234. static void process_ib_ipinfo(void *in_msg, void *out_msg, int op)
  235. {
  236. struct hv_kvp_ip_msg *in = in_msg;
  237. struct hv_kvp_msg *out = out_msg;
  238. switch (op) {
  239. case KVP_OP_SET_IP_INFO:
  240. /*
  241. * Transform all parameters into utf8 encoding.
  242. */
  243. utf16s_to_utf8s((wchar_t *)in->kvp_ip_val.ip_addr,
  244. MAX_IP_ADDR_SIZE,
  245. UTF16_LITTLE_ENDIAN,
  246. (__u8 *)out->body.kvp_ip_val.ip_addr,
  247. MAX_IP_ADDR_SIZE);
  248. utf16s_to_utf8s((wchar_t *)in->kvp_ip_val.sub_net,
  249. MAX_IP_ADDR_SIZE,
  250. UTF16_LITTLE_ENDIAN,
  251. (__u8 *)out->body.kvp_ip_val.sub_net,
  252. MAX_IP_ADDR_SIZE);
  253. utf16s_to_utf8s((wchar_t *)in->kvp_ip_val.gate_way,
  254. MAX_GATEWAY_SIZE,
  255. UTF16_LITTLE_ENDIAN,
  256. (__u8 *)out->body.kvp_ip_val.gate_way,
  257. MAX_GATEWAY_SIZE);
  258. utf16s_to_utf8s((wchar_t *)in->kvp_ip_val.dns_addr,
  259. MAX_IP_ADDR_SIZE,
  260. UTF16_LITTLE_ENDIAN,
  261. (__u8 *)out->body.kvp_ip_val.dns_addr,
  262. MAX_IP_ADDR_SIZE);
  263. out->body.kvp_ip_val.dhcp_enabled = in->kvp_ip_val.dhcp_enabled;
  264. default:
  265. utf16s_to_utf8s((wchar_t *)in->kvp_ip_val.adapter_id,
  266. MAX_ADAPTER_ID_SIZE,
  267. UTF16_LITTLE_ENDIAN,
  268. (__u8 *)out->body.kvp_ip_val.adapter_id,
  269. MAX_ADAPTER_ID_SIZE);
  270. out->body.kvp_ip_val.addr_family = in->kvp_ip_val.addr_family;
  271. }
  272. }
  273. static void
  274. kvp_send_key(struct work_struct *dummy)
  275. {
  276. struct cn_msg *msg;
  277. struct hv_kvp_msg *message;
  278. struct hv_kvp_msg *in_msg;
  279. __u8 operation = kvp_transaction.kvp_msg->kvp_hdr.operation;
  280. __u8 pool = kvp_transaction.kvp_msg->kvp_hdr.pool;
  281. __u32 val32;
  282. __u64 val64;
  283. msg = kzalloc(sizeof(*msg) + sizeof(struct hv_kvp_msg) , GFP_ATOMIC);
  284. if (!msg)
  285. return;
  286. msg->id.idx = CN_KVP_IDX;
  287. msg->id.val = CN_KVP_VAL;
  288. message = (struct hv_kvp_msg *)msg->data;
  289. message->kvp_hdr.operation = operation;
  290. message->kvp_hdr.pool = pool;
  291. in_msg = kvp_transaction.kvp_msg;
  292. /*
  293. * The key/value strings sent from the host are encoded in
  294. * in utf16; convert it to utf8 strings.
  295. * The host assures us that the utf16 strings will not exceed
  296. * the max lengths specified. We will however, reserve room
  297. * for the string terminating character - in the utf16s_utf8s()
  298. * function we limit the size of the buffer where the converted
  299. * string is placed to HV_KVP_EXCHANGE_MAX_*_SIZE -1 to gaurantee
  300. * that the strings can be properly terminated!
  301. */
  302. switch (message->kvp_hdr.operation) {
  303. case KVP_OP_SET_IP_INFO:
  304. process_ib_ipinfo(in_msg, message, KVP_OP_SET_IP_INFO);
  305. break;
  306. case KVP_OP_GET_IP_INFO:
  307. process_ib_ipinfo(in_msg, message, KVP_OP_GET_IP_INFO);
  308. break;
  309. case KVP_OP_SET:
  310. switch (in_msg->body.kvp_set.data.value_type) {
  311. case REG_SZ:
  312. /*
  313. * The value is a string - utf16 encoding.
  314. */
  315. message->body.kvp_set.data.value_size =
  316. utf16s_to_utf8s(
  317. (wchar_t *)in_msg->body.kvp_set.data.value,
  318. in_msg->body.kvp_set.data.value_size,
  319. UTF16_LITTLE_ENDIAN,
  320. message->body.kvp_set.data.value,
  321. HV_KVP_EXCHANGE_MAX_VALUE_SIZE - 1) + 1;
  322. break;
  323. case REG_U32:
  324. /*
  325. * The value is a 32 bit scalar.
  326. * We save this as a utf8 string.
  327. */
  328. val32 = in_msg->body.kvp_set.data.value_u32;
  329. message->body.kvp_set.data.value_size =
  330. sprintf(message->body.kvp_set.data.value,
  331. "%d", val32) + 1;
  332. break;
  333. case REG_U64:
  334. /*
  335. * The value is a 64 bit scalar.
  336. * We save this as a utf8 string.
  337. */
  338. val64 = in_msg->body.kvp_set.data.value_u64;
  339. message->body.kvp_set.data.value_size =
  340. sprintf(message->body.kvp_set.data.value,
  341. "%llu", val64) + 1;
  342. break;
  343. }
  344. case KVP_OP_GET:
  345. message->body.kvp_set.data.key_size =
  346. utf16s_to_utf8s(
  347. (wchar_t *)in_msg->body.kvp_set.data.key,
  348. in_msg->body.kvp_set.data.key_size,
  349. UTF16_LITTLE_ENDIAN,
  350. message->body.kvp_set.data.key,
  351. HV_KVP_EXCHANGE_MAX_KEY_SIZE - 1) + 1;
  352. break;
  353. case KVP_OP_DELETE:
  354. message->body.kvp_delete.key_size =
  355. utf16s_to_utf8s(
  356. (wchar_t *)in_msg->body.kvp_delete.key,
  357. in_msg->body.kvp_delete.key_size,
  358. UTF16_LITTLE_ENDIAN,
  359. message->body.kvp_delete.key,
  360. HV_KVP_EXCHANGE_MAX_KEY_SIZE - 1) + 1;
  361. break;
  362. case KVP_OP_ENUMERATE:
  363. message->body.kvp_enum_data.index =
  364. in_msg->body.kvp_enum_data.index;
  365. break;
  366. }
  367. msg->len = sizeof(struct hv_kvp_msg);
  368. cn_netlink_send(msg, 0, GFP_ATOMIC);
  369. kfree(msg);
  370. return;
  371. }
  372. /*
  373. * Send a response back to the host.
  374. */
  375. static void
  376. kvp_respond_to_host(struct hv_kvp_msg *msg_to_host, int error)
  377. {
  378. struct hv_kvp_msg *kvp_msg;
  379. struct hv_kvp_exchg_msg_value *kvp_data;
  380. char *key_name;
  381. char *value;
  382. struct icmsg_hdr *icmsghdrp;
  383. int keylen = 0;
  384. int valuelen = 0;
  385. u32 buf_len;
  386. struct vmbus_channel *channel;
  387. u64 req_id;
  388. int ret;
  389. /*
  390. * If a transaction is not active; log and return.
  391. */
  392. if (!kvp_transaction.active) {
  393. /*
  394. * This is a spurious call!
  395. */
  396. pr_warn("KVP: Transaction not active\n");
  397. return;
  398. }
  399. /*
  400. * Copy the global state for completing the transaction. Note that
  401. * only one transaction can be active at a time.
  402. */
  403. buf_len = kvp_transaction.recv_len;
  404. channel = kvp_transaction.recv_channel;
  405. req_id = kvp_transaction.recv_req_id;
  406. kvp_transaction.active = false;
  407. icmsghdrp = (struct icmsg_hdr *)
  408. &recv_buffer[sizeof(struct vmbuspipe_hdr)];
  409. if (channel->onchannel_callback == NULL)
  410. /*
  411. * We have raced with util driver being unloaded;
  412. * silently return.
  413. */
  414. return;
  415. icmsghdrp->status = error;
  416. /*
  417. * If the error parameter is set, terminate the host's enumeration
  418. * on this pool.
  419. */
  420. if (error) {
  421. /*
  422. * Something failed or we have timedout;
  423. * terminate the current host-side iteration.
  424. */
  425. goto response_done;
  426. }
  427. kvp_msg = (struct hv_kvp_msg *)
  428. &recv_buffer[sizeof(struct vmbuspipe_hdr) +
  429. sizeof(struct icmsg_hdr)];
  430. switch (kvp_transaction.kvp_msg->kvp_hdr.operation) {
  431. case KVP_OP_GET_IP_INFO:
  432. ret = process_ob_ipinfo(msg_to_host,
  433. (struct hv_kvp_ip_msg *)kvp_msg,
  434. KVP_OP_GET_IP_INFO);
  435. if (ret < 0)
  436. icmsghdrp->status = HV_E_FAIL;
  437. goto response_done;
  438. case KVP_OP_SET_IP_INFO:
  439. goto response_done;
  440. case KVP_OP_GET:
  441. kvp_data = &kvp_msg->body.kvp_get.data;
  442. goto copy_value;
  443. case KVP_OP_SET:
  444. case KVP_OP_DELETE:
  445. goto response_done;
  446. default:
  447. break;
  448. }
  449. kvp_data = &kvp_msg->body.kvp_enum_data.data;
  450. key_name = msg_to_host->body.kvp_enum_data.data.key;
  451. /*
  452. * The windows host expects the key/value pair to be encoded
  453. * in utf16. Ensure that the key/value size reported to the host
  454. * will be less than or equal to the MAX size (including the
  455. * terminating character).
  456. */
  457. keylen = utf8s_to_utf16s(key_name, strlen(key_name), UTF16_HOST_ENDIAN,
  458. (wchar_t *) kvp_data->key,
  459. (HV_KVP_EXCHANGE_MAX_KEY_SIZE / 2) - 2);
  460. kvp_data->key_size = 2*(keylen + 1); /* utf16 encoding */
  461. copy_value:
  462. value = msg_to_host->body.kvp_enum_data.data.value;
  463. valuelen = utf8s_to_utf16s(value, strlen(value), UTF16_HOST_ENDIAN,
  464. (wchar_t *) kvp_data->value,
  465. (HV_KVP_EXCHANGE_MAX_VALUE_SIZE / 2) - 2);
  466. kvp_data->value_size = 2*(valuelen + 1); /* utf16 encoding */
  467. /*
  468. * If the utf8s to utf16s conversion failed; notify host
  469. * of the error.
  470. */
  471. if ((keylen < 0) || (valuelen < 0))
  472. icmsghdrp->status = HV_E_FAIL;
  473. kvp_data->value_type = REG_SZ; /* all our values are strings */
  474. response_done:
  475. icmsghdrp->icflags = ICMSGHDRFLAG_TRANSACTION | ICMSGHDRFLAG_RESPONSE;
  476. vmbus_sendpacket(channel, recv_buffer, buf_len, req_id,
  477. VM_PKT_DATA_INBAND, 0);
  478. }
  479. /*
  480. * This callback is invoked when we get a KVP message from the host.
  481. * The host ensures that only one KVP transaction can be active at a time.
  482. * KVP implementation in Linux needs to forward the key to a user-mde
  483. * component to retrive the corresponding value. Consequently, we cannot
  484. * respond to the host in the conext of this callback. Since the host
  485. * guarantees that at most only one transaction can be active at a time,
  486. * we stash away the transaction state in a set of global variables.
  487. */
  488. void hv_kvp_onchannelcallback(void *context)
  489. {
  490. struct vmbus_channel *channel = context;
  491. u32 recvlen;
  492. u64 requestid;
  493. struct hv_kvp_msg *kvp_msg;
  494. struct icmsg_hdr *icmsghdrp;
  495. struct icmsg_negotiate *negop = NULL;
  496. if (kvp_transaction.active) {
  497. /*
  498. * We will defer processing this callback once
  499. * the current transaction is complete.
  500. */
  501. kvp_transaction.kvp_context = context;
  502. return;
  503. }
  504. vmbus_recvpacket(channel, recv_buffer, PAGE_SIZE * 2, &recvlen,
  505. &requestid);
  506. if (recvlen > 0) {
  507. icmsghdrp = (struct icmsg_hdr *)&recv_buffer[
  508. sizeof(struct vmbuspipe_hdr)];
  509. if (icmsghdrp->icmsgtype == ICMSGTYPE_NEGOTIATE) {
  510. /*
  511. * We start with win8 version and if the host cannot
  512. * support that we use the previous version.
  513. */
  514. if (vmbus_prep_negotiate_resp(icmsghdrp, negop,
  515. recv_buffer, UTIL_FW_MAJOR_MINOR,
  516. WIN8_SRV_MAJOR_MINOR))
  517. goto done;
  518. vmbus_prep_negotiate_resp(icmsghdrp, negop,
  519. recv_buffer, UTIL_FW_MAJOR_MINOR,
  520. WIN7_SRV_MAJOR_MINOR);
  521. } else {
  522. kvp_msg = (struct hv_kvp_msg *)&recv_buffer[
  523. sizeof(struct vmbuspipe_hdr) +
  524. sizeof(struct icmsg_hdr)];
  525. /*
  526. * Stash away this global state for completing the
  527. * transaction; note transactions are serialized.
  528. */
  529. kvp_transaction.recv_len = recvlen;
  530. kvp_transaction.recv_channel = channel;
  531. kvp_transaction.recv_req_id = requestid;
  532. kvp_transaction.active = true;
  533. kvp_transaction.kvp_msg = kvp_msg;
  534. /*
  535. * Get the information from the
  536. * user-mode component.
  537. * component. This transaction will be
  538. * completed when we get the value from
  539. * the user-mode component.
  540. * Set a timeout to deal with
  541. * user-mode not responding.
  542. */
  543. schedule_work(&kvp_sendkey_work);
  544. schedule_delayed_work(&kvp_work, 5*HZ);
  545. return;
  546. }
  547. done:
  548. icmsghdrp->icflags = ICMSGHDRFLAG_TRANSACTION
  549. | ICMSGHDRFLAG_RESPONSE;
  550. vmbus_sendpacket(channel, recv_buffer,
  551. recvlen, requestid,
  552. VM_PKT_DATA_INBAND, 0);
  553. }
  554. }
  555. int
  556. hv_kvp_init(struct hv_util_service *srv)
  557. {
  558. int err;
  559. err = cn_add_callback(&kvp_id, kvp_name, kvp_cn_callback);
  560. if (err)
  561. return err;
  562. recv_buffer = srv->recv_buffer;
  563. /*
  564. * When this driver loads, the user level daemon that
  565. * processes the host requests may not yet be running.
  566. * Defer processing channel callbacks until the daemon
  567. * has registered.
  568. */
  569. kvp_transaction.active = true;
  570. return 0;
  571. }
  572. void hv_kvp_deinit(void)
  573. {
  574. cn_del_callback(&kvp_id);
  575. cancel_delayed_work_sync(&kvp_work);
  576. cancel_work_sync(&kvp_sendkey_work);
  577. }