Commit 9568a193 authored by K. Y. Srinivasan's avatar K. Y. Srinivasan Committed by Greg Kroah-Hartman

Staging: hv: Use completion abstraction to synchronize in vmbus_channel_msginfo

Use completion abstraction to synchronize in vmbus_channel_msginfo.
Signed-off-by: default avatarK. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: default avatarHaiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: default avatarAbhishek Kane <v-abkane@microsoft.com>
Signed-off-by: default avatarHank Janssen <hjanssen@microsoft.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent b7c6b02f
...@@ -177,7 +177,7 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, ...@@ -177,7 +177,7 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size,
struct vmbus_channel_msginfo *openInfo = NULL; struct vmbus_channel_msginfo *openInfo = NULL;
void *in, *out; void *in, *out;
unsigned long flags; unsigned long flags;
int ret, err = 0; int ret, t, err = 0;
/* Aligned to page size */ /* Aligned to page size */
/* ASSERT(!(SendRingBufferSize & (PAGE_SIZE - 1))); */ /* ASSERT(!(SendRingBufferSize & (PAGE_SIZE - 1))); */
...@@ -240,7 +240,7 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, ...@@ -240,7 +240,7 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size,
goto errorout; goto errorout;
} }
init_waitqueue_head(&openInfo->waitevent); init_completion(&openInfo->waitevent);
openMsg = (struct vmbus_channel_open_channel *)openInfo->msg; openMsg = (struct vmbus_channel_open_channel *)openInfo->msg;
openMsg->header.msgtype = CHANNELMSG_OPENCHANNEL; openMsg->header.msgtype = CHANNELMSG_OPENCHANNEL;
...@@ -270,11 +270,8 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, ...@@ -270,11 +270,8 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size,
if (ret != 0) if (ret != 0)
goto Cleanup; goto Cleanup;
openInfo->wait_condition = 0; t = wait_for_completion_timeout(&openInfo->waitevent, HZ);
wait_event_timeout(openInfo->waitevent, if (t == 0) {
openInfo->wait_condition,
msecs_to_jiffies(1000));
if (openInfo->wait_condition == 0) {
err = -ETIMEDOUT; err = -ETIMEDOUT;
goto errorout; goto errorout;
} }
...@@ -495,6 +492,7 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer, ...@@ -495,6 +492,7 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
u32 next_gpadl_handle; u32 next_gpadl_handle;
unsigned long flags; unsigned long flags;
int ret = 0; int ret = 0;
int t;
next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle); next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
atomic_inc(&vmbus_connection.next_gpadl_handle); atomic_inc(&vmbus_connection.next_gpadl_handle);
...@@ -503,7 +501,7 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer, ...@@ -503,7 +501,7 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
if (ret) if (ret)
return ret; return ret;
init_waitqueue_head(&msginfo->waitevent); init_completion(&msginfo->waitevent);
gpadlmsg = (struct vmbus_channel_gpadl_header *)msginfo->msg; gpadlmsg = (struct vmbus_channel_gpadl_header *)msginfo->msg;
gpadlmsg->header.msgtype = CHANNELMSG_GPADL_HEADER; gpadlmsg->header.msgtype = CHANNELMSG_GPADL_HEADER;
...@@ -518,7 +516,6 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer, ...@@ -518,7 +516,6 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags);
msginfo->wait_condition = 0;
ret = vmbus_post_msg(gpadlmsg, msginfo->msgsize - ret = vmbus_post_msg(gpadlmsg, msginfo->msgsize -
sizeof(*msginfo)); sizeof(*msginfo));
if (ret != 0) if (ret != 0)
...@@ -546,10 +543,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer, ...@@ -546,10 +543,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
} }
} }
wait_event_timeout(msginfo->waitevent, t = wait_for_completion_timeout(&msginfo->waitevent, HZ);
msginfo->wait_condition, BUG_ON(t == 0);
msecs_to_jiffies(1000));
BUG_ON(msginfo->wait_condition == 0);
/* At this point, we received the gpadl created msg */ /* At this point, we received the gpadl created msg */
...@@ -573,7 +568,7 @@ int vmbus_teardown_gpadl(struct vmbus_channel *channel, u32 gpadl_handle) ...@@ -573,7 +568,7 @@ int vmbus_teardown_gpadl(struct vmbus_channel *channel, u32 gpadl_handle)
struct vmbus_channel_gpadl_teardown *msg; struct vmbus_channel_gpadl_teardown *msg;
struct vmbus_channel_msginfo *info; struct vmbus_channel_msginfo *info;
unsigned long flags; unsigned long flags;
int ret; int ret, t;
/* ASSERT(gpadl_handle != 0); */ /* ASSERT(gpadl_handle != 0); */
...@@ -582,7 +577,7 @@ int vmbus_teardown_gpadl(struct vmbus_channel *channel, u32 gpadl_handle) ...@@ -582,7 +577,7 @@ int vmbus_teardown_gpadl(struct vmbus_channel *channel, u32 gpadl_handle)
if (!info) if (!info)
return -ENOMEM; return -ENOMEM;
init_waitqueue_head(&info->waitevent); init_completion(&info->waitevent);
msg = (struct vmbus_channel_gpadl_teardown *)info->msg; msg = (struct vmbus_channel_gpadl_teardown *)info->msg;
...@@ -594,14 +589,12 @@ int vmbus_teardown_gpadl(struct vmbus_channel *channel, u32 gpadl_handle) ...@@ -594,14 +589,12 @@ int vmbus_teardown_gpadl(struct vmbus_channel *channel, u32 gpadl_handle)
list_add_tail(&info->msglistentry, list_add_tail(&info->msglistentry,
&vmbus_connection.chn_msg_list); &vmbus_connection.chn_msg_list);
spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags);
info->wait_condition = 0;
ret = vmbus_post_msg(msg, ret = vmbus_post_msg(msg,
sizeof(struct vmbus_channel_gpadl_teardown)); sizeof(struct vmbus_channel_gpadl_teardown));
BUG_ON(ret != 0); BUG_ON(ret != 0);
wait_event_timeout(info->waitevent, t = wait_for_completion_timeout(&info->waitevent, HZ);
info->wait_condition, msecs_to_jiffies(1000)); BUG_ON(t == 0);
BUG_ON(info->wait_condition == 0);
/* Received a torndown response */ /* Received a torndown response */
spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags);
......
...@@ -556,9 +556,9 @@ static void vmbus_onopen_result(struct vmbus_channel_message_header *hdr) ...@@ -556,9 +556,9 @@ static void vmbus_onopen_result(struct vmbus_channel_message_header *hdr)
openmsg->openid == result->openid) { openmsg->openid == result->openid) {
memcpy(&msginfo->response.open_result, memcpy(&msginfo->response.open_result,
result, result,
sizeof(struct vmbus_channel_open_result)); sizeof(
msginfo->wait_condition = 1; struct vmbus_channel_open_result));
wake_up(&msginfo->waitevent); complete(&msginfo->waitevent);
break; break;
} }
} }
...@@ -603,9 +603,9 @@ static void vmbus_ongpadl_created(struct vmbus_channel_message_header *hdr) ...@@ -603,9 +603,9 @@ static void vmbus_ongpadl_created(struct vmbus_channel_message_header *hdr)
(gpadlcreated->gpadl == gpadlheader->gpadl)) { (gpadlcreated->gpadl == gpadlheader->gpadl)) {
memcpy(&msginfo->response.gpadl_created, memcpy(&msginfo->response.gpadl_created,
gpadlcreated, gpadlcreated,
sizeof(struct vmbus_channel_gpadl_created)); sizeof(
msginfo->wait_condition = 1; struct vmbus_channel_gpadl_created));
wake_up(&msginfo->waitevent); complete(&msginfo->waitevent);
break; break;
} }
} }
...@@ -648,9 +648,9 @@ static void vmbus_ongpadl_torndown( ...@@ -648,9 +648,9 @@ static void vmbus_ongpadl_torndown(
if (gpadl_torndown->gpadl == gpadl_teardown->gpadl) { if (gpadl_torndown->gpadl == gpadl_teardown->gpadl) {
memcpy(&msginfo->response.gpadl_torndown, memcpy(&msginfo->response.gpadl_torndown,
gpadl_torndown, gpadl_torndown,
sizeof(struct vmbus_channel_gpadl_torndown)); sizeof(
msginfo->wait_condition = 1; struct vmbus_channel_gpadl_torndown));
wake_up(&msginfo->waitevent); complete(&msginfo->waitevent);
break; break;
} }
} }
...@@ -689,8 +689,7 @@ static void vmbus_onversion_response( ...@@ -689,8 +689,7 @@ static void vmbus_onversion_response(
memcpy(&msginfo->response.version_response, memcpy(&msginfo->response.version_response,
version_response, version_response,
sizeof(struct vmbus_channel_version_response)); sizeof(struct vmbus_channel_version_response));
msginfo->wait_condition = 1; complete(&msginfo->waitevent);
wake_up(&msginfo->waitevent);
} }
} }
spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags);
...@@ -753,7 +752,7 @@ int vmbus_request_offers(void) ...@@ -753,7 +752,7 @@ int vmbus_request_offers(void)
{ {
struct vmbus_channel_message_header *msg; struct vmbus_channel_message_header *msg;
struct vmbus_channel_msginfo *msginfo; struct vmbus_channel_msginfo *msginfo;
int ret; int ret, t;
msginfo = kmalloc(sizeof(*msginfo) + msginfo = kmalloc(sizeof(*msginfo) +
sizeof(struct vmbus_channel_message_header), sizeof(struct vmbus_channel_message_header),
...@@ -761,7 +760,7 @@ int vmbus_request_offers(void) ...@@ -761,7 +760,7 @@ int vmbus_request_offers(void)
if (!msginfo) if (!msginfo)
return -ENOMEM; return -ENOMEM;
init_waitqueue_head(&msginfo->waitevent); init_completion(&msginfo->waitevent);
msg = (struct vmbus_channel_message_header *)msginfo->msg; msg = (struct vmbus_channel_message_header *)msginfo->msg;
...@@ -776,10 +775,8 @@ int vmbus_request_offers(void) ...@@ -776,10 +775,8 @@ int vmbus_request_offers(void)
goto cleanup; goto cleanup;
} }
msginfo->wait_condition = 0; t = wait_for_completion_timeout(&msginfo->waitevent, HZ);
wait_event_timeout(msginfo->waitevent, msginfo->wait_condition, if (t == 0) {
msecs_to_jiffies(1000));
if (msginfo->wait_condition == 0) {
ret = -ETIMEDOUT; ret = -ETIMEDOUT;
goto cleanup; goto cleanup;
} }
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <linux/list.h> #include <linux/list.h>
#include <linux/timer.h> #include <linux/timer.h>
#include <linux/workqueue.h> #include <linux/workqueue.h>
#include <linux/completion.h>
#include "ring_buffer.h" #include "ring_buffer.h"
#include "vmbus_channel_interface.h" #include "vmbus_channel_interface.h"
#include "vmbus_packet_format.h" #include "vmbus_packet_format.h"
...@@ -290,8 +291,7 @@ struct vmbus_channel_msginfo { ...@@ -290,8 +291,7 @@ struct vmbus_channel_msginfo {
struct list_head submsglist; struct list_head submsglist;
/* Synchronize the request/response if needed */ /* Synchronize the request/response if needed */
int wait_condition; struct completion waitevent;
wait_queue_head_t waitevent;
union { union {
struct vmbus_channel_version_supported version_supported; struct vmbus_channel_version_supported version_supported;
struct vmbus_channel_open_result open_result; struct vmbus_channel_open_result open_result;
......
...@@ -44,6 +44,7 @@ struct vmbus_connection vmbus_connection = { ...@@ -44,6 +44,7 @@ struct vmbus_connection vmbus_connection = {
int vmbus_connect(void) int vmbus_connect(void)
{ {
int ret = 0; int ret = 0;
int t;
struct vmbus_channel_msginfo *msginfo = NULL; struct vmbus_channel_msginfo *msginfo = NULL;
struct vmbus_channel_initiate_contact *msg; struct vmbus_channel_initiate_contact *msg;
unsigned long flags; unsigned long flags;
...@@ -101,7 +102,7 @@ int vmbus_connect(void) ...@@ -101,7 +102,7 @@ int vmbus_connect(void)
goto Cleanup; goto Cleanup;
} }
init_waitqueue_head(&msginfo->waitevent); init_completion(&msginfo->waitevent);
msg = (struct vmbus_channel_initiate_contact *)msginfo->msg; msg = (struct vmbus_channel_initiate_contact *)msginfo->msg;
...@@ -134,10 +135,8 @@ int vmbus_connect(void) ...@@ -134,10 +135,8 @@ int vmbus_connect(void)
} }
/* Wait for the connection response */ /* Wait for the connection response */
msginfo->wait_condition = 0; t = wait_for_completion_timeout(&msginfo->waitevent, HZ);
wait_event_timeout(msginfo->waitevent, msginfo->wait_condition, if (t == 0) {
msecs_to_jiffies(1000));
if (msginfo->wait_condition == 0) {
spin_lock_irqsave(&vmbus_connection.channelmsg_lock, spin_lock_irqsave(&vmbus_connection.channelmsg_lock,
flags); flags);
list_del(&msginfo->msglistentry); list_del(&msginfo->msglistentry);
......
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