Staging: hv: make Channel->InboundLock a real spinlock
authorGreg Kroah-Hartman <gregkh@suse.de>
Wed, 15 Jul 2009 21:48:32 +0000 (14:48 -0700)
committerGreg Kroah-Hartman <gregkh@suse.de>
Tue, 15 Sep 2009 19:01:48 +0000 (12:01 -0700)
Don't use the wrapper functions for this lock, make it a real
lock so that we know what is going on.

I don't think we really want to be doing a irqsave for this code, but I
left it alone to preserve the original codepath.  It should be reviewed
later.

Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/staging/hv/Channel.c
drivers/staging/hv/ChannelMgmt.c
drivers/staging/hv/ChannelMgmt.h

index de6d2cfa82483a96f7d3cf29fa7e1c1b600c519d..757aba60fd6f92308f307009f97b44057b07c522 100644 (file)
@@ -991,18 +991,19 @@ VmbusChannelRecvPacket(
        u32 packetLen;
        u32 userLen;
        int ret;
+       unsigned long flags;
 
        DPRINT_ENTER(VMBUS);
 
        *BufferActualLen = 0;
        *RequestId = 0;
 
-       SpinlockAcquire(Channel->InboundLock);
+       spin_lock_irqsave(&Channel->inbound_lock, flags);
 
        ret = RingBufferPeek(&Channel->Inbound, &desc, sizeof(VMPACKET_DESCRIPTOR));
        if (ret != 0)
        {
-               SpinlockRelease(Channel->InboundLock);
+               spin_unlock_irqrestore(&Channel->inbound_lock, flags);
 
                //DPRINT_DBG(VMBUS, "nothing to read!!");
                DPRINT_EXIT(VMBUS);
@@ -1026,7 +1027,7 @@ VmbusChannelRecvPacket(
 
        if (userLen > BufferLen)
        {
-               SpinlockRelease(Channel->InboundLock);
+               spin_unlock_irqrestore(&Channel->inbound_lock, flags);
 
                DPRINT_ERR(VMBUS, "buffer too small - got %d needs %d", BufferLen, userLen);
                DPRINT_EXIT(VMBUS);
@@ -1039,7 +1040,7 @@ VmbusChannelRecvPacket(
        // Copy over the packet to the user buffer
        ret = RingBufferRead(&Channel->Inbound, Buffer, userLen, (desc.DataOffset8 << 3));
 
-       SpinlockRelease(Channel->InboundLock);
+       spin_unlock_irqrestore(&Channel->inbound_lock, flags);
 
        DPRINT_EXIT(VMBUS);
 
@@ -1068,18 +1069,19 @@ VmbusChannelRecvPacketRaw(
        u32 packetLen;
        u32 userLen;
        int ret;
+       unsigned long flags;
 
        DPRINT_ENTER(VMBUS);
 
        *BufferActualLen = 0;
        *RequestId = 0;
 
-       SpinlockAcquire(Channel->InboundLock);
+       spin_lock_irqsave(&Channel->inbound_lock, flags);
 
        ret = RingBufferPeek(&Channel->Inbound, &desc, sizeof(VMPACKET_DESCRIPTOR));
        if (ret != 0)
        {
-               SpinlockRelease(Channel->InboundLock);
+               spin_unlock_irqrestore(&Channel->inbound_lock, flags);
 
                //DPRINT_DBG(VMBUS, "nothing to read!!");
                DPRINT_EXIT(VMBUS);
@@ -1102,7 +1104,7 @@ VmbusChannelRecvPacketRaw(
 
        if (packetLen > BufferLen)
        {
-               SpinlockRelease(Channel->InboundLock);
+               spin_unlock_irqrestore(&Channel->inbound_lock, flags);
 
                DPRINT_ERR(VMBUS, "buffer too small - needed %d bytes but got space for only %d bytes", packetLen, BufferLen);
                DPRINT_EXIT(VMBUS);
@@ -1114,7 +1116,7 @@ VmbusChannelRecvPacketRaw(
        // Copy over the entire packet to the user buffer
        ret = RingBufferRead(&Channel->Inbound, Buffer, packetLen, 0);
 
-       SpinlockRelease(Channel->InboundLock);
+       spin_unlock_irqrestore(&Channel->inbound_lock, flags);
 
        DPRINT_EXIT(VMBUS);
 
index a19ff89f03e592b21769726d0c49c9ff23148655..7a0fd099477378f0756a86c306b651b7677b3de4 100644 (file)
@@ -149,17 +149,11 @@ VMBUS_CHANNEL* AllocVmbusChannel(void)
                return NULL;
        }
 
-       channel->InboundLock = SpinlockCreate();
-       if (!channel->InboundLock)
-       {
-               kfree(channel);
-               return NULL;
-       }
+       spin_lock_init(&channel->inbound_lock);
 
        channel->PollTimer = TimerCreate(VmbusChannelOnTimer, channel);
        if (!channel->PollTimer)
        {
-               SpinlockClose(channel->InboundLock);
                kfree(channel);
                return NULL;
        }
@@ -169,7 +163,6 @@ VMBUS_CHANNEL* AllocVmbusChannel(void)
        if (!channel->ControlWQ)
        {
                TimerClose(channel->PollTimer);
-               SpinlockClose(channel->InboundLock);
                kfree(channel);
                return NULL;
        }
@@ -212,7 +205,6 @@ Description:
 --*/
 void FreeVmbusChannel(VMBUS_CHANNEL* Channel)
 {
-       SpinlockClose(Channel->InboundLock);
        TimerClose(Channel->PollTimer);
 
        // We have to release the channel's workqueue/thread in the vmbus's workqueue/thread context
index b1ea2fc280c2d8671a92072edbd715a542643cb4..b7afecad04596442761d9f83851689aafe202766 100644 (file)
@@ -63,7 +63,7 @@ typedef struct _VMBUS_CHANNEL {
        u32                                             RingBufferPageCount;
        RING_BUFFER_INFO                        Outbound;       // send to parent
        RING_BUFFER_INFO                        Inbound;        // receive from parent
-       HANDLE                                          InboundLock;
+       spinlock_t inbound_lock;
        HANDLE                                          ControlWQ;
 
        // Channel callback are invoked in this workqueue context