channel_mgmt.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. /*
  2. * Copyright (c) 2009, Microsoft Corporation.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along with
  14. * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  15. * Place - Suite 330, Boston, MA 02111-1307 USA.
  16. *
  17. * Authors:
  18. * Haiyang Zhang <haiyangz@microsoft.com>
  19. * Hank Janssen <hjanssen@microsoft.com>
  20. */
  21. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  22. #include <linux/kernel.h>
  23. #include <linux/sched.h>
  24. #include <linux/wait.h>
  25. #include <linux/mm.h>
  26. #include <linux/slab.h>
  27. #include <linux/list.h>
  28. #include <linux/module.h>
  29. #include <linux/completion.h>
  30. #include <linux/hyperv.h>
  31. #include "hyperv_vmbus.h"
  32. struct vmbus_channel_message_table_entry {
  33. enum vmbus_channel_message_type message_type;
  34. void (*message_handler)(struct vmbus_channel_message_header *msg);
  35. };
  36. #define MAX_MSG_TYPES 4
  37. #define MAX_NUM_DEVICE_CLASSES_SUPPORTED 8
  38. static const uuid_le
  39. supported_device_classes[MAX_NUM_DEVICE_CLASSES_SUPPORTED] = {
  40. /* {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f} */
  41. /* Storage - SCSI */
  42. {
  43. .b = {
  44. 0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d,
  45. 0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f
  46. }
  47. },
  48. /* {F8615163-DF3E-46c5-913F-F2D2F965ED0E} */
  49. /* Network */
  50. {
  51. .b = {
  52. 0x63, 0x51, 0x61, 0xF8, 0x3E, 0xDF, 0xc5, 0x46,
  53. 0x91, 0x3F, 0xF2, 0xD2, 0xF9, 0x65, 0xED, 0x0E
  54. }
  55. },
  56. /* {CFA8B69E-5B4A-4cc0-B98B-8BA1A1F3F95A} */
  57. /* Input */
  58. {
  59. .b = {
  60. 0x9E, 0xB6, 0xA8, 0xCF, 0x4A, 0x5B, 0xc0, 0x4c,
  61. 0xB9, 0x8B, 0x8B, 0xA1, 0xA1, 0xF3, 0xF9, 0x5A
  62. }
  63. },
  64. /* {32412632-86cb-44a2-9b5c-50d1417354f5} */
  65. /* IDE */
  66. {
  67. .b = {
  68. 0x32, 0x26, 0x41, 0x32, 0xcb, 0x86, 0xa2, 0x44,
  69. 0x9b, 0x5c, 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5
  70. }
  71. },
  72. /* 0E0B6031-5213-4934-818B-38D90CED39DB */
  73. /* Shutdown */
  74. {
  75. .b = {
  76. 0x31, 0x60, 0x0B, 0X0E, 0x13, 0x52, 0x34, 0x49,
  77. 0x81, 0x8B, 0x38, 0XD9, 0x0C, 0xED, 0x39, 0xDB
  78. }
  79. },
  80. /* {9527E630-D0AE-497b-ADCE-E80AB0175CAF} */
  81. /* TimeSync */
  82. {
  83. .b = {
  84. 0x30, 0xe6, 0x27, 0x95, 0xae, 0xd0, 0x7b, 0x49,
  85. 0xad, 0xce, 0xe8, 0x0a, 0xb0, 0x17, 0x5c, 0xaf
  86. }
  87. },
  88. /* {57164f39-9115-4e78-ab55-382f3bd5422d} */
  89. /* Heartbeat */
  90. {
  91. .b = {
  92. 0x39, 0x4f, 0x16, 0x57, 0x15, 0x91, 0x78, 0x4e,
  93. 0xab, 0x55, 0x38, 0x2f, 0x3b, 0xd5, 0x42, 0x2d
  94. }
  95. },
  96. /* {A9A0F4E7-5A45-4d96-B827-8A841E8C03E6} */
  97. /* KVP */
  98. {
  99. .b = {
  100. 0xe7, 0xf4, 0xa0, 0xa9, 0x45, 0x5a, 0x96, 0x4d,
  101. 0xb8, 0x27, 0x8a, 0x84, 0x1e, 0x8c, 0x3, 0xe6
  102. }
  103. },
  104. };
  105. /**
  106. * vmbus_prep_negotiate_resp() - Create default response for Hyper-V Negotiate message
  107. * @icmsghdrp: Pointer to msg header structure
  108. * @icmsg_negotiate: Pointer to negotiate message structure
  109. * @buf: Raw buffer channel data
  110. *
  111. * @icmsghdrp is of type &struct icmsg_hdr.
  112. * @negop is of type &struct icmsg_negotiate.
  113. * Set up and fill in default negotiate response message. This response can
  114. * come from both the vmbus driver and the hv_utils driver. The current api
  115. * will respond properly to both Windows 2008 and Windows 2008-R2 operating
  116. * systems.
  117. *
  118. * Mainly used by Hyper-V drivers.
  119. */
  120. void vmbus_prep_negotiate_resp(struct icmsg_hdr *icmsghdrp,
  121. struct icmsg_negotiate *negop, u8 *buf)
  122. {
  123. if (icmsghdrp->icmsgtype == ICMSGTYPE_NEGOTIATE) {
  124. icmsghdrp->icmsgsize = 0x10;
  125. negop = (struct icmsg_negotiate *)&buf[
  126. sizeof(struct vmbuspipe_hdr) +
  127. sizeof(struct icmsg_hdr)];
  128. if (negop->icframe_vercnt == 2 &&
  129. negop->icversion_data[1].major == 3) {
  130. negop->icversion_data[0].major = 3;
  131. negop->icversion_data[0].minor = 0;
  132. negop->icversion_data[1].major = 3;
  133. negop->icversion_data[1].minor = 0;
  134. } else {
  135. negop->icversion_data[0].major = 1;
  136. negop->icversion_data[0].minor = 0;
  137. negop->icversion_data[1].major = 1;
  138. negop->icversion_data[1].minor = 0;
  139. }
  140. negop->icframe_vercnt = 1;
  141. negop->icmsg_vercnt = 1;
  142. }
  143. }
  144. EXPORT_SYMBOL_GPL(vmbus_prep_negotiate_resp);
  145. /*
  146. * alloc_channel - Allocate and initialize a vmbus channel object
  147. */
  148. static struct vmbus_channel *alloc_channel(void)
  149. {
  150. struct vmbus_channel *channel;
  151. channel = kzalloc(sizeof(*channel), GFP_ATOMIC);
  152. if (!channel)
  153. return NULL;
  154. spin_lock_init(&channel->inbound_lock);
  155. channel->controlwq = create_workqueue("hv_vmbus_ctl");
  156. if (!channel->controlwq) {
  157. kfree(channel);
  158. return NULL;
  159. }
  160. return channel;
  161. }
  162. /*
  163. * release_hannel - Release the vmbus channel object itself
  164. */
  165. static void release_channel(struct work_struct *work)
  166. {
  167. struct vmbus_channel *channel = container_of(work,
  168. struct vmbus_channel,
  169. work);
  170. destroy_workqueue(channel->controlwq);
  171. kfree(channel);
  172. }
  173. /*
  174. * free_channel - Release the resources used by the vmbus channel object
  175. */
  176. static void free_channel(struct vmbus_channel *channel)
  177. {
  178. /*
  179. * We have to release the channel's workqueue/thread in the vmbus's
  180. * workqueue/thread context
  181. * ie we can't destroy ourselves.
  182. */
  183. INIT_WORK(&channel->work, release_channel);
  184. queue_work(vmbus_connection.work_queue, &channel->work);
  185. }
  186. /*
  187. * vmbus_process_rescind_offer -
  188. * Rescind the offer by initiating a device removal
  189. */
  190. static void vmbus_process_rescind_offer(struct work_struct *work)
  191. {
  192. struct vmbus_channel *channel = container_of(work,
  193. struct vmbus_channel,
  194. work);
  195. vmbus_device_unregister(channel->device_obj);
  196. }
  197. void vmbus_free_channels(void)
  198. {
  199. struct vmbus_channel *channel;
  200. list_for_each_entry(channel, &vmbus_connection.chn_list, listentry) {
  201. vmbus_device_unregister(channel->device_obj);
  202. kfree(channel->device_obj);
  203. free_channel(channel);
  204. }
  205. }
  206. /*
  207. * vmbus_process_offer - Process the offer by creating a channel/device
  208. * associated with this offer
  209. */
  210. static void vmbus_process_offer(struct work_struct *work)
  211. {
  212. struct vmbus_channel *newchannel = container_of(work,
  213. struct vmbus_channel,
  214. work);
  215. struct vmbus_channel *channel;
  216. bool fnew = true;
  217. int ret;
  218. unsigned long flags;
  219. /* The next possible work is rescind handling */
  220. INIT_WORK(&newchannel->work, vmbus_process_rescind_offer);
  221. /* Make sure this is a new offer */
  222. spin_lock_irqsave(&vmbus_connection.channel_lock, flags);
  223. list_for_each_entry(channel, &vmbus_connection.chn_list, listentry) {
  224. if (!uuid_le_cmp(channel->offermsg.offer.if_type,
  225. newchannel->offermsg.offer.if_type) &&
  226. !uuid_le_cmp(channel->offermsg.offer.if_instance,
  227. newchannel->offermsg.offer.if_instance)) {
  228. fnew = false;
  229. break;
  230. }
  231. }
  232. if (fnew)
  233. list_add_tail(&newchannel->listentry,
  234. &vmbus_connection.chn_list);
  235. spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags);
  236. if (!fnew) {
  237. free_channel(newchannel);
  238. return;
  239. }
  240. /*
  241. * Start the process of binding this offer to the driver
  242. * We need to set the DeviceObject field before calling
  243. * vmbus_child_dev_add()
  244. */
  245. newchannel->device_obj = vmbus_device_create(
  246. &newchannel->offermsg.offer.if_type,
  247. &newchannel->offermsg.offer.if_instance,
  248. newchannel);
  249. /*
  250. * Add the new device to the bus. This will kick off device-driver
  251. * binding which eventually invokes the device driver's AddDevice()
  252. * method.
  253. */
  254. ret = vmbus_device_register(newchannel->device_obj);
  255. if (ret != 0) {
  256. pr_err("unable to add child device object (relid %d)\n",
  257. newchannel->offermsg.child_relid);
  258. spin_lock_irqsave(&vmbus_connection.channel_lock, flags);
  259. list_del(&newchannel->listentry);
  260. spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags);
  261. kfree(newchannel->device_obj);
  262. free_channel(newchannel);
  263. } else {
  264. /*
  265. * This state is used to indicate a successful open
  266. * so that when we do close the channel normally, we
  267. * can cleanup properly
  268. */
  269. newchannel->state = CHANNEL_OPEN_STATE;
  270. }
  271. }
  272. /*
  273. * vmbus_onoffer - Handler for channel offers from vmbus in parent partition.
  274. *
  275. */
  276. static void vmbus_onoffer(struct vmbus_channel_message_header *hdr)
  277. {
  278. struct vmbus_channel_offer_channel *offer;
  279. struct vmbus_channel *newchannel;
  280. uuid_le *guidtype;
  281. uuid_le *guidinstance;
  282. int i;
  283. int fsupported = 0;
  284. offer = (struct vmbus_channel_offer_channel *)hdr;
  285. for (i = 0; i < MAX_NUM_DEVICE_CLASSES_SUPPORTED; i++) {
  286. if (!uuid_le_cmp(offer->offer.if_type,
  287. supported_device_classes[i])) {
  288. fsupported = 1;
  289. break;
  290. }
  291. }
  292. if (!fsupported)
  293. return;
  294. guidtype = &offer->offer.if_type;
  295. guidinstance = &offer->offer.if_instance;
  296. /* Allocate the channel object and save this offer. */
  297. newchannel = alloc_channel();
  298. if (!newchannel) {
  299. pr_err("Unable to allocate channel object\n");
  300. return;
  301. }
  302. memcpy(&newchannel->offermsg, offer,
  303. sizeof(struct vmbus_channel_offer_channel));
  304. newchannel->monitor_grp = (u8)offer->monitorid / 32;
  305. newchannel->monitor_bit = (u8)offer->monitorid % 32;
  306. INIT_WORK(&newchannel->work, vmbus_process_offer);
  307. queue_work(newchannel->controlwq, &newchannel->work);
  308. }
  309. /*
  310. * vmbus_onoffer_rescind - Rescind offer handler.
  311. *
  312. * We queue a work item to process this offer synchronously
  313. */
  314. static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr)
  315. {
  316. struct vmbus_channel_rescind_offer *rescind;
  317. struct vmbus_channel *channel;
  318. rescind = (struct vmbus_channel_rescind_offer *)hdr;
  319. channel = relid2channel(rescind->child_relid);
  320. if (channel == NULL)
  321. /* Just return here, no channel found */
  322. return;
  323. /* work is initialized for vmbus_process_rescind_offer() from
  324. * vmbus_process_offer() where the channel got created */
  325. queue_work(channel->controlwq, &channel->work);
  326. }
  327. /*
  328. * vmbus_onoffers_delivered -
  329. * This is invoked when all offers have been delivered.
  330. *
  331. * Nothing to do here.
  332. */
  333. static void vmbus_onoffers_delivered(
  334. struct vmbus_channel_message_header *hdr)
  335. {
  336. }
  337. /*
  338. * vmbus_onopen_result - Open result handler.
  339. *
  340. * This is invoked when we received a response to our channel open request.
  341. * Find the matching request, copy the response and signal the requesting
  342. * thread.
  343. */
  344. static void vmbus_onopen_result(struct vmbus_channel_message_header *hdr)
  345. {
  346. struct vmbus_channel_open_result *result;
  347. struct vmbus_channel_msginfo *msginfo;
  348. struct vmbus_channel_message_header *requestheader;
  349. struct vmbus_channel_open_channel *openmsg;
  350. unsigned long flags;
  351. result = (struct vmbus_channel_open_result *)hdr;
  352. /*
  353. * Find the open msg, copy the result and signal/unblock the wait event
  354. */
  355. spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags);
  356. list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list,
  357. msglistentry) {
  358. requestheader =
  359. (struct vmbus_channel_message_header *)msginfo->msg;
  360. if (requestheader->msgtype == CHANNELMSG_OPENCHANNEL) {
  361. openmsg =
  362. (struct vmbus_channel_open_channel *)msginfo->msg;
  363. if (openmsg->child_relid == result->child_relid &&
  364. openmsg->openid == result->openid) {
  365. memcpy(&msginfo->response.open_result,
  366. result,
  367. sizeof(
  368. struct vmbus_channel_open_result));
  369. complete(&msginfo->waitevent);
  370. break;
  371. }
  372. }
  373. }
  374. spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags);
  375. }
  376. /*
  377. * vmbus_ongpadl_created - GPADL created handler.
  378. *
  379. * This is invoked when we received a response to our gpadl create request.
  380. * Find the matching request, copy the response and signal the requesting
  381. * thread.
  382. */
  383. static void vmbus_ongpadl_created(struct vmbus_channel_message_header *hdr)
  384. {
  385. struct vmbus_channel_gpadl_created *gpadlcreated;
  386. struct vmbus_channel_msginfo *msginfo;
  387. struct vmbus_channel_message_header *requestheader;
  388. struct vmbus_channel_gpadl_header *gpadlheader;
  389. unsigned long flags;
  390. gpadlcreated = (struct vmbus_channel_gpadl_created *)hdr;
  391. /*
  392. * Find the establish msg, copy the result and signal/unblock the wait
  393. * event
  394. */
  395. spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags);
  396. list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list,
  397. msglistentry) {
  398. requestheader =
  399. (struct vmbus_channel_message_header *)msginfo->msg;
  400. if (requestheader->msgtype == CHANNELMSG_GPADL_HEADER) {
  401. gpadlheader =
  402. (struct vmbus_channel_gpadl_header *)requestheader;
  403. if ((gpadlcreated->child_relid ==
  404. gpadlheader->child_relid) &&
  405. (gpadlcreated->gpadl == gpadlheader->gpadl)) {
  406. memcpy(&msginfo->response.gpadl_created,
  407. gpadlcreated,
  408. sizeof(
  409. struct vmbus_channel_gpadl_created));
  410. complete(&msginfo->waitevent);
  411. break;
  412. }
  413. }
  414. }
  415. spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags);
  416. }
  417. /*
  418. * vmbus_ongpadl_torndown - GPADL torndown handler.
  419. *
  420. * This is invoked when we received a response to our gpadl teardown request.
  421. * Find the matching request, copy the response and signal the requesting
  422. * thread.
  423. */
  424. static void vmbus_ongpadl_torndown(
  425. struct vmbus_channel_message_header *hdr)
  426. {
  427. struct vmbus_channel_gpadl_torndown *gpadl_torndown;
  428. struct vmbus_channel_msginfo *msginfo;
  429. struct vmbus_channel_message_header *requestheader;
  430. struct vmbus_channel_gpadl_teardown *gpadl_teardown;
  431. unsigned long flags;
  432. gpadl_torndown = (struct vmbus_channel_gpadl_torndown *)hdr;
  433. /*
  434. * Find the open msg, copy the result and signal/unblock the wait event
  435. */
  436. spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags);
  437. list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list,
  438. msglistentry) {
  439. requestheader =
  440. (struct vmbus_channel_message_header *)msginfo->msg;
  441. if (requestheader->msgtype == CHANNELMSG_GPADL_TEARDOWN) {
  442. gpadl_teardown =
  443. (struct vmbus_channel_gpadl_teardown *)requestheader;
  444. if (gpadl_torndown->gpadl == gpadl_teardown->gpadl) {
  445. memcpy(&msginfo->response.gpadl_torndown,
  446. gpadl_torndown,
  447. sizeof(
  448. struct vmbus_channel_gpadl_torndown));
  449. complete(&msginfo->waitevent);
  450. break;
  451. }
  452. }
  453. }
  454. spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags);
  455. }
  456. /*
  457. * vmbus_onversion_response - Version response handler
  458. *
  459. * This is invoked when we received a response to our initiate contact request.
  460. * Find the matching request, copy the response and signal the requesting
  461. * thread.
  462. */
  463. static void vmbus_onversion_response(
  464. struct vmbus_channel_message_header *hdr)
  465. {
  466. struct vmbus_channel_msginfo *msginfo;
  467. struct vmbus_channel_message_header *requestheader;
  468. struct vmbus_channel_initiate_contact *initiate;
  469. struct vmbus_channel_version_response *version_response;
  470. unsigned long flags;
  471. version_response = (struct vmbus_channel_version_response *)hdr;
  472. spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags);
  473. list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list,
  474. msglistentry) {
  475. requestheader =
  476. (struct vmbus_channel_message_header *)msginfo->msg;
  477. if (requestheader->msgtype ==
  478. CHANNELMSG_INITIATE_CONTACT) {
  479. initiate =
  480. (struct vmbus_channel_initiate_contact *)requestheader;
  481. memcpy(&msginfo->response.version_response,
  482. version_response,
  483. sizeof(struct vmbus_channel_version_response));
  484. complete(&msginfo->waitevent);
  485. }
  486. }
  487. spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags);
  488. }
  489. /* Channel message dispatch table */
  490. static struct vmbus_channel_message_table_entry
  491. channel_message_table[CHANNELMSG_COUNT] = {
  492. {CHANNELMSG_INVALID, NULL},
  493. {CHANNELMSG_OFFERCHANNEL, vmbus_onoffer},
  494. {CHANNELMSG_RESCIND_CHANNELOFFER, vmbus_onoffer_rescind},
  495. {CHANNELMSG_REQUESTOFFERS, NULL},
  496. {CHANNELMSG_ALLOFFERS_DELIVERED, vmbus_onoffers_delivered},
  497. {CHANNELMSG_OPENCHANNEL, NULL},
  498. {CHANNELMSG_OPENCHANNEL_RESULT, vmbus_onopen_result},
  499. {CHANNELMSG_CLOSECHANNEL, NULL},
  500. {CHANNELMSG_GPADL_HEADER, NULL},
  501. {CHANNELMSG_GPADL_BODY, NULL},
  502. {CHANNELMSG_GPADL_CREATED, vmbus_ongpadl_created},
  503. {CHANNELMSG_GPADL_TEARDOWN, NULL},
  504. {CHANNELMSG_GPADL_TORNDOWN, vmbus_ongpadl_torndown},
  505. {CHANNELMSG_RELID_RELEASED, NULL},
  506. {CHANNELMSG_INITIATE_CONTACT, NULL},
  507. {CHANNELMSG_VERSION_RESPONSE, vmbus_onversion_response},
  508. {CHANNELMSG_UNLOAD, NULL},
  509. };
  510. /*
  511. * vmbus_onmessage - Handler for channel protocol messages.
  512. *
  513. * This is invoked in the vmbus worker thread context.
  514. */
  515. void vmbus_onmessage(void *context)
  516. {
  517. struct hv_message *msg = context;
  518. struct vmbus_channel_message_header *hdr;
  519. int size;
  520. hdr = (struct vmbus_channel_message_header *)msg->u.payload;
  521. size = msg->header.payload_size;
  522. if (hdr->msgtype >= CHANNELMSG_COUNT) {
  523. pr_err("Received invalid channel message type %d size %d\n",
  524. hdr->msgtype, size);
  525. print_hex_dump_bytes("", DUMP_PREFIX_NONE,
  526. (unsigned char *)msg->u.payload, size);
  527. return;
  528. }
  529. if (channel_message_table[hdr->msgtype].message_handler)
  530. channel_message_table[hdr->msgtype].message_handler(hdr);
  531. else
  532. pr_err("Unhandled channel message type %d\n", hdr->msgtype);
  533. }
  534. /*
  535. * vmbus_request_offers - Send a request to get all our pending offers.
  536. */
  537. int vmbus_request_offers(void)
  538. {
  539. struct vmbus_channel_message_header *msg;
  540. struct vmbus_channel_msginfo *msginfo;
  541. int ret, t;
  542. msginfo = kmalloc(sizeof(*msginfo) +
  543. sizeof(struct vmbus_channel_message_header),
  544. GFP_KERNEL);
  545. if (!msginfo)
  546. return -ENOMEM;
  547. init_completion(&msginfo->waitevent);
  548. msg = (struct vmbus_channel_message_header *)msginfo->msg;
  549. msg->msgtype = CHANNELMSG_REQUESTOFFERS;
  550. ret = vmbus_post_msg(msg,
  551. sizeof(struct vmbus_channel_message_header));
  552. if (ret != 0) {
  553. pr_err("Unable to request offers - %d\n", ret);
  554. goto cleanup;
  555. }
  556. t = wait_for_completion_timeout(&msginfo->waitevent, 5*HZ);
  557. if (t == 0) {
  558. ret = -ETIMEDOUT;
  559. goto cleanup;
  560. }
  561. cleanup:
  562. kfree(msginfo);
  563. return ret;
  564. }
  565. /* eof */