channel_mgmt.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  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. /*
  198. * vmbus_process_offer - Process the offer by creating a channel/device
  199. * associated with this offer
  200. */
  201. static void vmbus_process_offer(struct work_struct *work)
  202. {
  203. struct vmbus_channel *newchannel = container_of(work,
  204. struct vmbus_channel,
  205. work);
  206. struct vmbus_channel *channel;
  207. bool fnew = true;
  208. int ret;
  209. unsigned long flags;
  210. /* The next possible work is rescind handling */
  211. INIT_WORK(&newchannel->work, vmbus_process_rescind_offer);
  212. /* Make sure this is a new offer */
  213. spin_lock_irqsave(&vmbus_connection.channel_lock, flags);
  214. list_for_each_entry(channel, &vmbus_connection.chn_list, listentry) {
  215. if (!uuid_le_cmp(channel->offermsg.offer.if_type,
  216. newchannel->offermsg.offer.if_type) &&
  217. !uuid_le_cmp(channel->offermsg.offer.if_instance,
  218. newchannel->offermsg.offer.if_instance)) {
  219. fnew = false;
  220. break;
  221. }
  222. }
  223. if (fnew)
  224. list_add_tail(&newchannel->listentry,
  225. &vmbus_connection.chn_list);
  226. spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags);
  227. if (!fnew) {
  228. free_channel(newchannel);
  229. return;
  230. }
  231. /*
  232. * Start the process of binding this offer to the driver
  233. * We need to set the DeviceObject field before calling
  234. * vmbus_child_dev_add()
  235. */
  236. newchannel->device_obj = vmbus_device_create(
  237. &newchannel->offermsg.offer.if_type,
  238. &newchannel->offermsg.offer.if_instance,
  239. newchannel);
  240. /*
  241. * Add the new device to the bus. This will kick off device-driver
  242. * binding which eventually invokes the device driver's AddDevice()
  243. * method.
  244. */
  245. ret = vmbus_device_register(newchannel->device_obj);
  246. if (ret != 0) {
  247. pr_err("unable to add child device object (relid %d)\n",
  248. newchannel->offermsg.child_relid);
  249. spin_lock_irqsave(&vmbus_connection.channel_lock, flags);
  250. list_del(&newchannel->listentry);
  251. spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags);
  252. kfree(newchannel->device_obj);
  253. free_channel(newchannel);
  254. } else {
  255. /*
  256. * This state is used to indicate a successful open
  257. * so that when we do close the channel normally, we
  258. * can cleanup properly
  259. */
  260. newchannel->state = CHANNEL_OPEN_STATE;
  261. }
  262. }
  263. /*
  264. * vmbus_onoffer - Handler for channel offers from vmbus in parent partition.
  265. *
  266. */
  267. static void vmbus_onoffer(struct vmbus_channel_message_header *hdr)
  268. {
  269. struct vmbus_channel_offer_channel *offer;
  270. struct vmbus_channel *newchannel;
  271. uuid_le *guidtype;
  272. uuid_le *guidinstance;
  273. int i;
  274. int fsupported = 0;
  275. offer = (struct vmbus_channel_offer_channel *)hdr;
  276. for (i = 0; i < MAX_NUM_DEVICE_CLASSES_SUPPORTED; i++) {
  277. if (!uuid_le_cmp(offer->offer.if_type,
  278. supported_device_classes[i])) {
  279. fsupported = 1;
  280. break;
  281. }
  282. }
  283. if (!fsupported)
  284. return;
  285. guidtype = &offer->offer.if_type;
  286. guidinstance = &offer->offer.if_instance;
  287. /* Allocate the channel object and save this offer. */
  288. newchannel = alloc_channel();
  289. if (!newchannel) {
  290. pr_err("Unable to allocate channel object\n");
  291. return;
  292. }
  293. memcpy(&newchannel->offermsg, offer,
  294. sizeof(struct vmbus_channel_offer_channel));
  295. newchannel->monitor_grp = (u8)offer->monitorid / 32;
  296. newchannel->monitor_bit = (u8)offer->monitorid % 32;
  297. INIT_WORK(&newchannel->work, vmbus_process_offer);
  298. queue_work(newchannel->controlwq, &newchannel->work);
  299. }
  300. /*
  301. * vmbus_onoffer_rescind - Rescind offer handler.
  302. *
  303. * We queue a work item to process this offer synchronously
  304. */
  305. static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr)
  306. {
  307. struct vmbus_channel_rescind_offer *rescind;
  308. struct vmbus_channel *channel;
  309. rescind = (struct vmbus_channel_rescind_offer *)hdr;
  310. channel = relid2channel(rescind->child_relid);
  311. if (channel == NULL)
  312. /* Just return here, no channel found */
  313. return;
  314. /* work is initialized for vmbus_process_rescind_offer() from
  315. * vmbus_process_offer() where the channel got created */
  316. queue_work(channel->controlwq, &channel->work);
  317. }
  318. /*
  319. * vmbus_onoffers_delivered -
  320. * This is invoked when all offers have been delivered.
  321. *
  322. * Nothing to do here.
  323. */
  324. static void vmbus_onoffers_delivered(
  325. struct vmbus_channel_message_header *hdr)
  326. {
  327. }
  328. /*
  329. * vmbus_onopen_result - Open result handler.
  330. *
  331. * This is invoked when we received a response to our channel open request.
  332. * Find the matching request, copy the response and signal the requesting
  333. * thread.
  334. */
  335. static void vmbus_onopen_result(struct vmbus_channel_message_header *hdr)
  336. {
  337. struct vmbus_channel_open_result *result;
  338. struct vmbus_channel_msginfo *msginfo;
  339. struct vmbus_channel_message_header *requestheader;
  340. struct vmbus_channel_open_channel *openmsg;
  341. unsigned long flags;
  342. result = (struct vmbus_channel_open_result *)hdr;
  343. /*
  344. * Find the open msg, copy the result and signal/unblock the wait event
  345. */
  346. spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags);
  347. list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list,
  348. msglistentry) {
  349. requestheader =
  350. (struct vmbus_channel_message_header *)msginfo->msg;
  351. if (requestheader->msgtype == CHANNELMSG_OPENCHANNEL) {
  352. openmsg =
  353. (struct vmbus_channel_open_channel *)msginfo->msg;
  354. if (openmsg->child_relid == result->child_relid &&
  355. openmsg->openid == result->openid) {
  356. memcpy(&msginfo->response.open_result,
  357. result,
  358. sizeof(
  359. struct vmbus_channel_open_result));
  360. complete(&msginfo->waitevent);
  361. break;
  362. }
  363. }
  364. }
  365. spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags);
  366. }
  367. /*
  368. * vmbus_ongpadl_created - GPADL created handler.
  369. *
  370. * This is invoked when we received a response to our gpadl create request.
  371. * Find the matching request, copy the response and signal the requesting
  372. * thread.
  373. */
  374. static void vmbus_ongpadl_created(struct vmbus_channel_message_header *hdr)
  375. {
  376. struct vmbus_channel_gpadl_created *gpadlcreated;
  377. struct vmbus_channel_msginfo *msginfo;
  378. struct vmbus_channel_message_header *requestheader;
  379. struct vmbus_channel_gpadl_header *gpadlheader;
  380. unsigned long flags;
  381. gpadlcreated = (struct vmbus_channel_gpadl_created *)hdr;
  382. /*
  383. * Find the establish msg, copy the result and signal/unblock the wait
  384. * event
  385. */
  386. spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags);
  387. list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list,
  388. msglistentry) {
  389. requestheader =
  390. (struct vmbus_channel_message_header *)msginfo->msg;
  391. if (requestheader->msgtype == CHANNELMSG_GPADL_HEADER) {
  392. gpadlheader =
  393. (struct vmbus_channel_gpadl_header *)requestheader;
  394. if ((gpadlcreated->child_relid ==
  395. gpadlheader->child_relid) &&
  396. (gpadlcreated->gpadl == gpadlheader->gpadl)) {
  397. memcpy(&msginfo->response.gpadl_created,
  398. gpadlcreated,
  399. sizeof(
  400. struct vmbus_channel_gpadl_created));
  401. complete(&msginfo->waitevent);
  402. break;
  403. }
  404. }
  405. }
  406. spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags);
  407. }
  408. /*
  409. * vmbus_ongpadl_torndown - GPADL torndown handler.
  410. *
  411. * This is invoked when we received a response to our gpadl teardown request.
  412. * Find the matching request, copy the response and signal the requesting
  413. * thread.
  414. */
  415. static void vmbus_ongpadl_torndown(
  416. struct vmbus_channel_message_header *hdr)
  417. {
  418. struct vmbus_channel_gpadl_torndown *gpadl_torndown;
  419. struct vmbus_channel_msginfo *msginfo;
  420. struct vmbus_channel_message_header *requestheader;
  421. struct vmbus_channel_gpadl_teardown *gpadl_teardown;
  422. unsigned long flags;
  423. gpadl_torndown = (struct vmbus_channel_gpadl_torndown *)hdr;
  424. /*
  425. * Find the open msg, copy the result and signal/unblock the wait event
  426. */
  427. spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags);
  428. list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list,
  429. msglistentry) {
  430. requestheader =
  431. (struct vmbus_channel_message_header *)msginfo->msg;
  432. if (requestheader->msgtype == CHANNELMSG_GPADL_TEARDOWN) {
  433. gpadl_teardown =
  434. (struct vmbus_channel_gpadl_teardown *)requestheader;
  435. if (gpadl_torndown->gpadl == gpadl_teardown->gpadl) {
  436. memcpy(&msginfo->response.gpadl_torndown,
  437. gpadl_torndown,
  438. sizeof(
  439. struct vmbus_channel_gpadl_torndown));
  440. complete(&msginfo->waitevent);
  441. break;
  442. }
  443. }
  444. }
  445. spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags);
  446. }
  447. /*
  448. * vmbus_onversion_response - Version response handler
  449. *
  450. * This is invoked when we received a response to our initiate contact request.
  451. * Find the matching request, copy the response and signal the requesting
  452. * thread.
  453. */
  454. static void vmbus_onversion_response(
  455. struct vmbus_channel_message_header *hdr)
  456. {
  457. struct vmbus_channel_msginfo *msginfo;
  458. struct vmbus_channel_message_header *requestheader;
  459. struct vmbus_channel_initiate_contact *initiate;
  460. struct vmbus_channel_version_response *version_response;
  461. unsigned long flags;
  462. version_response = (struct vmbus_channel_version_response *)hdr;
  463. spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags);
  464. list_for_each_entry(msginfo, &vmbus_connection.chn_msg_list,
  465. msglistentry) {
  466. requestheader =
  467. (struct vmbus_channel_message_header *)msginfo->msg;
  468. if (requestheader->msgtype ==
  469. CHANNELMSG_INITIATE_CONTACT) {
  470. initiate =
  471. (struct vmbus_channel_initiate_contact *)requestheader;
  472. memcpy(&msginfo->response.version_response,
  473. version_response,
  474. sizeof(struct vmbus_channel_version_response));
  475. complete(&msginfo->waitevent);
  476. }
  477. }
  478. spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags);
  479. }
  480. /* Channel message dispatch table */
  481. static struct vmbus_channel_message_table_entry
  482. channel_message_table[CHANNELMSG_COUNT] = {
  483. {CHANNELMSG_INVALID, NULL},
  484. {CHANNELMSG_OFFERCHANNEL, vmbus_onoffer},
  485. {CHANNELMSG_RESCIND_CHANNELOFFER, vmbus_onoffer_rescind},
  486. {CHANNELMSG_REQUESTOFFERS, NULL},
  487. {CHANNELMSG_ALLOFFERS_DELIVERED, vmbus_onoffers_delivered},
  488. {CHANNELMSG_OPENCHANNEL, NULL},
  489. {CHANNELMSG_OPENCHANNEL_RESULT, vmbus_onopen_result},
  490. {CHANNELMSG_CLOSECHANNEL, NULL},
  491. {CHANNELMSG_GPADL_HEADER, NULL},
  492. {CHANNELMSG_GPADL_BODY, NULL},
  493. {CHANNELMSG_GPADL_CREATED, vmbus_ongpadl_created},
  494. {CHANNELMSG_GPADL_TEARDOWN, NULL},
  495. {CHANNELMSG_GPADL_TORNDOWN, vmbus_ongpadl_torndown},
  496. {CHANNELMSG_RELID_RELEASED, NULL},
  497. {CHANNELMSG_INITIATE_CONTACT, NULL},
  498. {CHANNELMSG_VERSION_RESPONSE, vmbus_onversion_response},
  499. {CHANNELMSG_UNLOAD, NULL},
  500. };
  501. /*
  502. * vmbus_onmessage - Handler for channel protocol messages.
  503. *
  504. * This is invoked in the vmbus worker thread context.
  505. */
  506. void vmbus_onmessage(void *context)
  507. {
  508. struct hv_message *msg = context;
  509. struct vmbus_channel_message_header *hdr;
  510. int size;
  511. hdr = (struct vmbus_channel_message_header *)msg->u.payload;
  512. size = msg->header.payload_size;
  513. if (hdr->msgtype >= CHANNELMSG_COUNT) {
  514. pr_err("Received invalid channel message type %d size %d\n",
  515. hdr->msgtype, size);
  516. print_hex_dump_bytes("", DUMP_PREFIX_NONE,
  517. (unsigned char *)msg->u.payload, size);
  518. return;
  519. }
  520. if (channel_message_table[hdr->msgtype].message_handler)
  521. channel_message_table[hdr->msgtype].message_handler(hdr);
  522. else
  523. pr_err("Unhandled channel message type %d\n", hdr->msgtype);
  524. }
  525. /*
  526. * vmbus_request_offers - Send a request to get all our pending offers.
  527. */
  528. int vmbus_request_offers(void)
  529. {
  530. struct vmbus_channel_message_header *msg;
  531. struct vmbus_channel_msginfo *msginfo;
  532. int ret, t;
  533. msginfo = kmalloc(sizeof(*msginfo) +
  534. sizeof(struct vmbus_channel_message_header),
  535. GFP_KERNEL);
  536. if (!msginfo)
  537. return -ENOMEM;
  538. init_completion(&msginfo->waitevent);
  539. msg = (struct vmbus_channel_message_header *)msginfo->msg;
  540. msg->msgtype = CHANNELMSG_REQUESTOFFERS;
  541. ret = vmbus_post_msg(msg,
  542. sizeof(struct vmbus_channel_message_header));
  543. if (ret != 0) {
  544. pr_err("Unable to request offers - %d\n", ret);
  545. goto cleanup;
  546. }
  547. t = wait_for_completion_timeout(&msginfo->waitevent, 5*HZ);
  548. if (t == 0) {
  549. ret = -ETIMEDOUT;
  550. goto cleanup;
  551. }
  552. cleanup:
  553. kfree(msginfo);
  554. return ret;
  555. }
  556. /* eof */