aboutsummaryrefslogtreecommitdiffstats
diff options
authorGreg Kroah-Hartman <gregkh@suse.de>2009-09-01 20:19:13 -0700
committerGreg Kroah-Hartman <gregkh@suse.de>2009-09-01 20:19:13 -0700
commitcef16096f51a9ff4909f4f5ef5b66310cce15a8b (patch)
tree695e3f791b6dbca07dd3fbe7fb6395962b3c9a6d
parent438da86ccf7b13af517aaa2bf4ff7ddd97debd25 (diff)
downloadpatches-cef16096f51a9ff4909f4f5ef5b66310cce15a8b.tar.gz
more hv patches
-rw-r--r--f3.patch283
-rw-r--r--series5
-rw-r--r--staging/staging-hv-coding-style-cleanup-for-channel.c.patch1393
-rw-r--r--staging/staging-hv-coding-style-fixes-for-blkvsc_drv.c.patch1788
-rw-r--r--staging/staging-hv-warn-the-world-of-a-bug-in-the-release-function.patch33
5 files changed, 3502 insertions, 0 deletions
diff --git a/f3.patch b/f3.patch
new file mode 100644
index 00000000000000..f7c6d7c77ff741
--- /dev/null
+++ b/f3.patch
@@ -0,0 +1,283 @@
+---
+ drivers/staging/hv/vmbus_drv.c | 139 +++++++++++------------------------------
+ 1 file changed, 38 insertions(+), 101 deletions(-)
+
+--- a/drivers/staging/hv/vmbus_drv.c
++++ b/drivers/staging/hv/vmbus_drv.c
+@@ -1,5 +1,4 @@
+ /*
+- *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+@@ -18,10 +17,7 @@
+ * Authors:
+ * Haiyang Zhang <haiyangz@microsoft.com>
+ * Hank Janssen <hjanssen@microsoft.com>
+- *
+ */
+-
+-
+ #include <linux/init.h>
+ #include <linux/module.h>
+ #include <linux/device.h>
+@@ -33,35 +29,27 @@
+ #include "vmbus.h"
+
+
+-/* Defines */
+-
+-
+ /* FIXME! We need to do this dynamically for PIC and APIC system */
+-#define VMBUS_IRQ 0x5
+-#define VMBUS_IRQ_VECTOR IRQ5_VECTOR
+-
+-/* Data types */
+-
++#define VMBUS_IRQ 0x5
++#define VMBUS_IRQ_VECTOR IRQ5_VECTOR
+
+ /* Main vmbus driver data structure */
+ struct vmbus_driver_context {
+ /* !! These must be the first 2 fields !! */
++ /* FIXME, this is a bug */
+ /* The driver field is not used in here. Instead, the bus field is */
+ /* used to represent the driver */
+- struct driver_context drv_ctx;
++ struct driver_context drv_ctx;
+ struct vmbus_driver drv_obj;
+
+- struct bus_type bus;
+- struct tasklet_struct msg_dpc;
+- struct tasklet_struct event_dpc;
++ struct bus_type bus;
++ struct tasklet_struct msg_dpc;
++ struct tasklet_struct event_dpc;
+
+ /* The bus root device */
+- struct device_context device_ctx;
++ struct device_context device_ctx;
+ };
+
+-
+-/* Static decl */
+-
+ static int vmbus_match(struct device *device, struct device_driver *driver);
+ static int vmbus_probe(struct device *device);
+ static int vmbus_remove(struct device *device);
+@@ -914,9 +902,8 @@ static int vmbus_remove(struct device *c
+ return 0;
+ }
+
+-/*++
+-
+-Name: vmbus_shutdown()
++/**
++ * vmbus_shutdown
+
+ Desc: Shutdown a vmbus device
+
+@@ -928,16 +915,17 @@ static void vmbus_shutdown(struct device
+ DPRINT_ENTER(VMBUS_DRV);
+
+ /* Special case root bus device */
+- if (child_device->parent == NULL)
+- {
+- /* No-op since it is statically defined and handle in vmbus_bus_exit() */
++ if (child_device->parent == NULL) {
++ /*
++ * No-op since it is statically defined and handle in
++ * vmbus_bus_exit()
++ */
+ DPRINT_EXIT(VMBUS_DRV);
+ return;
+ }
+
+ /* The device may not be attached yet */
+- if (!child_device->driver)
+- {
++ if (!child_device->driver) {
+ DPRINT_EXIT(VMBUS_DRV);
+ return;
+ }
+@@ -955,13 +943,9 @@ static void vmbus_shutdown(struct device
+ return;
+ }
+
+-/*++
+-
+-Name: vmbus_bus_release()
+-
+-Desc: Final callback release of the vmbus root device
+-
+---*/
++/**
++ * vmbus_bus_release - Final callback release of the vmbus root device
++ */
+ static void vmbus_bus_release(struct device *device)
+ {
+ DPRINT_ENTER(VMBUS_DRV);
+@@ -973,13 +957,9 @@ static void vmbus_bus_release(struct dev
+ DPRINT_EXIT(VMBUS_DRV);
+ }
+
+-/*++
+-
+-Name: vmbus_device_release()
+-
+-Desc: Final callback release of the vmbus child device
+-
+---*/
++/**
++ * vmbus_device_release - Final callback release of the vmbus child device
++ */
+ static void vmbus_device_release(struct device *device)
+ {
+ struct device_context *device_ctx = device_to_device_context(device);
+@@ -990,19 +970,14 @@ static void vmbus_device_release(struct
+ kfree(device_ctx);
+
+ /* !!DO NOT REFERENCE device_ctx anymore at this point!! */
+-
+ DPRINT_EXIT(VMBUS_DRV);
+
+ return;
+ }
+
+-/*++
+-
+-Name: vmbus_msg_dpc()
+-
+-Desc: Tasklet routine to handle hypervisor messages
+-
+---*/
++/**
++ * vmbus_msg_dpc - Tasklet routine to handle hypervisor messages
++ */
+ static void vmbus_msg_dpc(unsigned long data)
+ {
+ struct vmbus_driver *vmbus_drv_obj = (struct vmbus_driver *)data;
+@@ -1017,13 +992,9 @@ static void vmbus_msg_dpc(unsigned long
+ DPRINT_EXIT(VMBUS_DRV);
+ }
+
+-/*++
+-
+-Name: vmbus_msg_dpc()
+-
+-Desc: Tasklet routine to handle hypervisor events
+-
+---*/
++/**
++ * vmbus_msg_dpc - Tasklet routine to handle hypervisor events
++ */
+ static void vmbus_event_dpc(unsigned long data)
+ {
+ struct vmbus_driver *vmbus_drv_obj = (struct vmbus_driver *)data;
+@@ -1038,17 +1009,10 @@ static void vmbus_event_dpc(unsigned lon
+ DPRINT_EXIT(VMBUS_DRV);
+ }
+
+-/*++
+-
+-Name: vmbus_msg_dpc()
+-
+-Desc: ISR routine
+-
+---*/
+-static irqreturn_t vmbus_isr(int irq, void* dev_id)
++static irqreturn_t vmbus_isr(int irq, void *dev_id)
+ {
+- int ret=0;
+ struct vmbus_driver *vmbus_driver_obj = &g_vmbus_drv.drv_obj;
++ int ret;
+
+ DPRINT_ENTER(VMBUS_DRV);
+
+@@ -1058,48 +1022,31 @@ static irqreturn_t vmbus_isr(int irq, vo
+ ret = vmbus_driver_obj->OnIsr(&vmbus_driver_obj->Base);
+
+ /* Schedules a dpc if necessary */
+- if (ret > 0)
+- {
+- if (test_bit(0, (unsigned long*)&ret))
+- {
++ if (ret > 0) {
++ if (test_bit(0, (unsigned long *)&ret))
+ tasklet_schedule(&g_vmbus_drv.msg_dpc);
+- }
+
+- if (test_bit(1, (unsigned long*)&ret))
+- {
++ if (test_bit(1, (unsigned long *)&ret))
+ tasklet_schedule(&g_vmbus_drv.event_dpc);
+- }
+
+ DPRINT_EXIT(VMBUS_DRV);
+ return IRQ_HANDLED;
+- }
+- else
+- {
++ } else {
+ DPRINT_EXIT(VMBUS_DRV);
+ return IRQ_NONE;
+ }
+ }
+
+-MODULE_LICENSE("GPL");
+-
+-
+-/*++
+-
+-Name: vmbus_init()
+-
+-Desc: Main vmbus driver entry routine
+-
+---*/
+ static int __init vmbus_init(void)
+ {
+- int ret=0;
++ int ret = 0;
+
+ DPRINT_ENTER(VMBUS_DRV);
+
+ DPRINT_INFO(VMBUS_DRV,
+ "Vmbus initializing.... current log level 0x%x (%x,%x)",
+ vmbus_loglevel, HIWORD(vmbus_loglevel), LOWORD(vmbus_loglevel));
+-/* Todo: it is used for loglevel, to be ported to new kernel. */
++ /* Todo: it is used for loglevel, to be ported to new kernel. */
+
+ ret = vmbus_bus_init(VmbusInitialize);
+
+@@ -1107,29 +1054,19 @@ static int __init vmbus_init(void)
+ return ret;
+ }
+
+-
+-
+-/*++
+-
+-Name: vmbus_init()
+-
+-Desc: Main vmbus driver exit routine
+-
+---*/
+ static void __exit vmbus_exit(void)
+ {
+ DPRINT_ENTER(VMBUS_DRV);
+
+ vmbus_bus_exit();
+-/* Todo: it is used for loglevel, to be ported to new kernel. */
++ /* Todo: it is used for loglevel, to be ported to new kernel. */
+ DPRINT_EXIT(VMBUS_DRV);
+-
+ return;
+ }
+
++MODULE_LICENSE("GPL");
+ module_param(vmbus_irq, int, S_IRUGO);
+ module_param(vmbus_loglevel, int, S_IRUGO);
+
+ module_init(vmbus_init);
+ module_exit(vmbus_exit);
+-/* eof */
diff --git a/series b/series
index 5c83c7905e6b21..ecdf08c28f78a5 100644
--- a/series
+++ b/series
@@ -601,6 +601,9 @@ staging/staging-hv-reorg-channelmgmt-a-bit.patch
staging/staging-hv-todo-add-some-more-items.patch
staging/staging-hv-coding-style-cleanups-for-storvsc.c.patch
staging/staging-hv-reorg-storvsc.c.patch
+staging/staging-hv-coding-style-fixes-for-blkvsc_drv.c.patch
+staging/staging-hv-coding-style-cleanup-for-channel.c.patch
+staging/staging-hv-warn-the-world-of-a-bug-in-the-release-function.patch
staging/staging-htc-dream-limit-kconfig-for-only-msm-platforms.patch
staging/staging-htc-dream-touchscreen-driver-for-staging.patch
@@ -893,3 +896,5 @@ led_classdev.sysfs-name.patch
#tty.work/serial-core-port-wait
#tty.work/serial-f81216-helper
+
+f3.patch
diff --git a/staging/staging-hv-coding-style-cleanup-for-channel.c.patch b/staging/staging-hv-coding-style-cleanup-for-channel.c.patch
new file mode 100644
index 00000000000000..600f7187187384
--- /dev/null
+++ b/staging/staging-hv-coding-style-cleanup-for-channel.c.patch
@@ -0,0 +1,1393 @@
+From foo@baz Tue Sep 1 17:24:57 PDT 2009
+Date: Tue, 01 Sep 2009 17:24:57 -0700
+To: Greg KH <greg@kroah.com>
+From: Greg Kroah-Hartman <gregkh@suse.de>
+Subject: Staging: hv: coding style cleanup for Channel.c
+
+All clean now.
+
+Cc: Hank Janssen <hjanssen@microsoft.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
+
+---
+ drivers/staging/hv/Channel.c | 826 ++++++++++++++++++-------------------------
+ 1 file changed, 346 insertions(+), 480 deletions(-)
+
+--- a/drivers/staging/hv/Channel.c
++++ b/drivers/staging/hv/Channel.c
+@@ -1,5 +1,4 @@
+ /*
+- *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+@@ -18,9 +17,7 @@
+ * Authors:
+ * Haiyang Zhang <haiyangz@microsoft.com>
+ * Hank Janssen <hjanssen@microsoft.com>
+- *
+ */
+-
+ #include <linux/kernel.h>
+ #include <linux/mm.h>
+ #include "osd.h"
+@@ -29,81 +26,67 @@
+
+ /* Internal routines */
+ static int VmbusChannelCreateGpadlHeader(
+- void * Kbuffer, /* must be phys and virt contiguous */
+- u32 Size, /* page-size multiple */
++ void *Kbuffer, /* must be phys and virt contiguous */
++ u32 Size, /* page-size multiple */
+ struct vmbus_channel_msginfo **msgInfo,
+- u32 *MessageCount
+- );
++ u32 *MessageCount);
+ static void DumpVmbusChannel(struct vmbus_channel *channel);
+ static void VmbusChannelSetEvent(struct vmbus_channel *channel);
+
+
+ #if 0
+-static void
+-DumpMonitorPage(
+- struct hv_monitor_page *MonitorPage
+- )
++static void DumpMonitorPage(struct hv_monitor_page *MonitorPage)
+ {
+- int i=0;
+- int j=0;
+-
+- DPRINT_DBG(VMBUS, "monitorPage - %p, trigger state - %d", MonitorPage, MonitorPage->TriggerState);
++ int i = 0;
++ int j = 0;
+
+- for (i=0; i<4; i++)
+- {
+- DPRINT_DBG(VMBUS, "trigger group (%d) - %llx", i, MonitorPage->TriggerGroup[i].AsUINT64);
+- }
++ DPRINT_DBG(VMBUS, "monitorPage - %p, trigger state - %d",
++ MonitorPage, MonitorPage->TriggerState);
+
+- for (i=0; i<4; i++)
+- {
+- for (j=0; j<32; j++)
+- {
+- DPRINT_DBG(VMBUS, "latency (%d)(%d) - %llx", i, j, MonitorPage->Latency[i][j]);
++ for (i = 0; i < 4; i++)
++ DPRINT_DBG(VMBUS, "trigger group (%d) - %llx", i,
++ MonitorPage->TriggerGroup[i].AsUINT64);
++
++ for (i = 0; i < 4; i++) {
++ for (j = 0; j < 32; j++) {
++ DPRINT_DBG(VMBUS, "latency (%d)(%d) - %llx", i, j,
++ MonitorPage->Latency[i][j]);
+ }
+ }
+- for (i=0; i<4; i++)
+- {
+- for (j=0; j<32; j++)
+- {
+- DPRINT_DBG(VMBUS, "param-conn id (%d)(%d) - %d", i, j, MonitorPage->Parameter[i][j].ConnectionId.Asu32);
+- DPRINT_DBG(VMBUS, "param-flag (%d)(%d) - %d", i, j, MonitorPage->Parameter[i][j].FlagNumber);
+-
++ for (i = 0; i < 4; i++) {
++ for (j = 0; j < 32; j++) {
++ DPRINT_DBG(VMBUS, "param-conn id (%d)(%d) - %d", i, j,
++ MonitorPage->Parameter[i][j].ConnectionId.Asu32);
++ DPRINT_DBG(VMBUS, "param-flag (%d)(%d) - %d", i, j,
++ MonitorPage->Parameter[i][j].FlagNumber);
+ }
+ }
+ }
+ #endif
+
+-/*++
+-
+-Name:
+- VmbusChannelSetEvent()
+-
+-Description:
+- Trigger an event notification on the specified channel.
+-
+---*/
++/**
++ * VmbusChannelSetEvent - Trigger an event notification on the specified channel.
++ */
+ static void VmbusChannelSetEvent(struct vmbus_channel *Channel)
+ {
+ struct hv_monitor_page *monitorPage;
+
+ DPRINT_ENTER(VMBUS);
+
+- if (Channel->OfferMsg.MonitorAllocated)
+- {
++ if (Channel->OfferMsg.MonitorAllocated) {
+ /* Each u32 represents 32 channels */
+ set_bit(Channel->OfferMsg.ChildRelId & 31,
+ (unsigned long *) gVmbusConnection.SendInterruptPage +
+- (Channel->OfferMsg.ChildRelId >> 5) );
++ (Channel->OfferMsg.ChildRelId >> 5));
+
+- monitorPage = (struct hv_monitor_page *)gVmbusConnection.MonitorPages;
++ monitorPage = gVmbusConnection.MonitorPages;
+ monitorPage++; /* Get the child to parent monitor page */
+
+ set_bit(Channel->MonitorBit,
+- (unsigned long *) &monitorPage->TriggerGroup[Channel->MonitorGroup].Pending);
++ (unsigned long *)&monitorPage->TriggerGroup
++ [Channel->MonitorGroup].Pending);
+
+- }
+- else
+- {
++ } else {
+ VmbusSetEvent(Channel->OfferMsg.ChildRelId);
+ }
+
+@@ -117,162 +100,162 @@ static void VmbusChannelClearEvent(struc
+
+ DPRINT_ENTER(VMBUS);
+
+- if (Channel->OfferMsg.MonitorAllocated)
+- {
++ if (Channel->OfferMsg.MonitorAllocated) {
+ /* Each u32 represents 32 channels */
+ clear_bit(Channel->OfferMsg.ChildRelId & 31,
+- (unsigned long *) gVmbusConnection.SendInterruptPage + (Channel->OfferMsg.ChildRelId >> 5));
++ (unsigned long *)gVmbusConnection.SendInterruptPage +
++ (Channel->OfferMsg.ChildRelId >> 5));
+
+- monitorPage = (struct hv_monitor_page *)gVmbusConnection.MonitorPages;
++ monitorPage =
++ (struct hv_monitor_page *)gVmbusConnection.MonitorPages;
+ monitorPage++; /* Get the child to parent monitor page */
+
+ clear_bit(Channel->MonitorBit,
+- (unsigned long *) &monitorPage->TriggerGroup[Channel->MonitorGroup].Pending);
++ (unsigned long *)&monitorPage->TriggerGroup
++ [Channel->MonitorGroup].Pending);
+ }
+
+ DPRINT_EXIT(VMBUS);
+ }
+
+ #endif
+-/*++;
+-
+-Name:
+- VmbusChannelGetDebugInfo()
+-
+-Description:
+- Retrieve various channel debug info
+-
+---*/
++/**
++ * VmbusChannelGetDebugInfo -Retrieve various channel debug info
++ */
+ void VmbusChannelGetDebugInfo(struct vmbus_channel *Channel,
+ struct vmbus_channel_debug_info *DebugInfo)
+ {
+ struct hv_monitor_page *monitorPage;
+- u8 monitorGroup = (u8)Channel->OfferMsg.MonitorId / 32;
+- u8 monitorOffset = (u8)Channel->OfferMsg.MonitorId % 32;
++ u8 monitorGroup = (u8)Channel->OfferMsg.MonitorId / 32;
++ u8 monitorOffset = (u8)Channel->OfferMsg.MonitorId % 32;
+ /* u32 monitorBit = 1 << monitorOffset; */
+
+ DebugInfo->RelId = Channel->OfferMsg.ChildRelId;
+ DebugInfo->State = Channel->State;
+- memcpy(&DebugInfo->InterfaceType, &Channel->OfferMsg.Offer.InterfaceType, sizeof(struct hv_guid));
+- memcpy(&DebugInfo->InterfaceInstance, &Channel->OfferMsg.Offer.InterfaceInstance, sizeof(struct hv_guid));
++ memcpy(&DebugInfo->InterfaceType,
++ &Channel->OfferMsg.Offer.InterfaceType, sizeof(struct hv_guid));
++ memcpy(&DebugInfo->InterfaceInstance,
++ &Channel->OfferMsg.Offer.InterfaceInstance,
++ sizeof(struct hv_guid));
+
+ monitorPage = (struct hv_monitor_page *)gVmbusConnection.MonitorPages;
+
+ DebugInfo->MonitorId = Channel->OfferMsg.MonitorId;
+
+- DebugInfo->ServerMonitorPending = monitorPage->TriggerGroup[monitorGroup].Pending;
+- DebugInfo->ServerMonitorLatency = monitorPage->Latency[monitorGroup][ monitorOffset];
+- DebugInfo->ServerMonitorConnectionId = monitorPage->Parameter[monitorGroup][ monitorOffset].ConnectionId.u.Id;
++ DebugInfo->ServerMonitorPending =
++ monitorPage->TriggerGroup[monitorGroup].Pending;
++ DebugInfo->ServerMonitorLatency =
++ monitorPage->Latency[monitorGroup][monitorOffset];
++ DebugInfo->ServerMonitorConnectionId =
++ monitorPage->Parameter[monitorGroup]
++ [monitorOffset].ConnectionId.u.Id;
+
+ monitorPage++;
+
+- DebugInfo->ClientMonitorPending = monitorPage->TriggerGroup[monitorGroup].Pending;
+- DebugInfo->ClientMonitorLatency = monitorPage->Latency[monitorGroup][ monitorOffset];
+- DebugInfo->ClientMonitorConnectionId = monitorPage->Parameter[monitorGroup][ monitorOffset].ConnectionId.u.Id;
++ DebugInfo->ClientMonitorPending =
++ monitorPage->TriggerGroup[monitorGroup].Pending;
++ DebugInfo->ClientMonitorLatency =
++ monitorPage->Latency[monitorGroup][monitorOffset];
++ DebugInfo->ClientMonitorConnectionId =
++ monitorPage->Parameter[monitorGroup]
++ [monitorOffset].ConnectionId.u.Id;
+
+ RingBufferGetDebugInfo(&Channel->Inbound, &DebugInfo->Inbound);
+ RingBufferGetDebugInfo(&Channel->Outbound, &DebugInfo->Outbound);
+ }
+
+-
+-/*++;
+-
+-Name:
+- VmbusChannelOpen()
+-
+-Description:
+- Open the specified channel.
+-
+---*/
+-int VmbusChannelOpen(struct vmbus_channel *NewChannel,
+- u32 SendRingBufferSize,
+- u32 RecvRingBufferSize,
+- void * UserData,
+- u32 UserDataLen,
+- PFN_CHANNEL_CALLBACK pfnOnChannelCallback,
+- void * Context
+- )
++/**
++ * VmbusChannelOpen - Open the specified channel.
++ */
++int VmbusChannelOpen(struct vmbus_channel *NewChannel, u32 SendRingBufferSize,
++ u32 RecvRingBufferSize, void *UserData, u32 UserDataLen,
++ PFN_CHANNEL_CALLBACK pfnOnChannelCallback, void *Context)
+ {
+- int ret=0;
+ struct vmbus_channel_open_channel *openMsg;
+ struct vmbus_channel_msginfo *openInfo;
+ void *in, *out;
+ unsigned long flags;
++ int ret;
+
+ DPRINT_ENTER(VMBUS);
+
+ /* Aligned to page size */
+- ASSERT(!(SendRingBufferSize & (PAGE_SIZE -1)));
+- ASSERT(!(RecvRingBufferSize & (PAGE_SIZE -1)));
++ ASSERT(!(SendRingBufferSize & (PAGE_SIZE - 1)));
++ ASSERT(!(RecvRingBufferSize & (PAGE_SIZE - 1)));
+
+ NewChannel->OnChannelCallback = pfnOnChannelCallback;
+ NewChannel->ChannelCallbackContext = Context;
+
+ /* Allocate the ring buffer */
+- out = osd_PageAlloc((SendRingBufferSize + RecvRingBufferSize) >> PAGE_SHIFT);
+- /* out = kzalloc(sendRingBufferSize + recvRingBufferSize, GFP_KERNEL); */
++ out = osd_PageAlloc((SendRingBufferSize + RecvRingBufferSize)
++ >> PAGE_SHIFT);
+ ASSERT(out);
+ ASSERT(((unsigned long)out & (PAGE_SIZE-1)) == 0);
+
+- in = (void*)((unsigned long)out + SendRingBufferSize);
++ in = (void *)((unsigned long)out + SendRingBufferSize);
+
+ NewChannel->RingBufferPages = out;
+- NewChannel->RingBufferPageCount = (SendRingBufferSize + RecvRingBufferSize) >> PAGE_SHIFT;
++ NewChannel->RingBufferPageCount = (SendRingBufferSize +
++ RecvRingBufferSize) >> PAGE_SHIFT;
+
+ RingBufferInit(&NewChannel->Outbound, out, SendRingBufferSize);
+
+ RingBufferInit(&NewChannel->Inbound, in, RecvRingBufferSize);
+
+ /* Establish the gpadl for the ring buffer */
+- DPRINT_DBG(VMBUS, "Establishing ring buffer's gpadl for channel %p...", NewChannel);
++ DPRINT_DBG(VMBUS, "Establishing ring buffer's gpadl for channel %p...",
++ NewChannel);
+
+ NewChannel->RingBufferGpadlHandle = 0;
+
+ ret = VmbusChannelEstablishGpadl(NewChannel,
+- NewChannel->Outbound.RingBuffer,
+- SendRingBufferSize + RecvRingBufferSize,
+- &NewChannel->RingBufferGpadlHandle);
+-
+- DPRINT_DBG(VMBUS, "channel %p <relid %d gpadl 0x%x send ring %p size %d recv ring %p size %d, downstreamoffset %d>",
+- NewChannel,
+- NewChannel->OfferMsg.ChildRelId,
+- NewChannel->RingBufferGpadlHandle,
+- NewChannel->Outbound.RingBuffer,
+- NewChannel->Outbound.RingSize,
+- NewChannel->Inbound.RingBuffer,
+- NewChannel->Inbound.RingSize,
+- SendRingBufferSize);
++ NewChannel->Outbound.RingBuffer,
++ SendRingBufferSize +
++ RecvRingBufferSize,
++ &NewChannel->RingBufferGpadlHandle);
++
++ DPRINT_DBG(VMBUS, "channel %p <relid %d gpadl 0x%x send ring %p "
++ "size %d recv ring %p size %d, downstreamoffset %d>",
++ NewChannel, NewChannel->OfferMsg.ChildRelId,
++ NewChannel->RingBufferGpadlHandle,
++ NewChannel->Outbound.RingBuffer,
++ NewChannel->Outbound.RingSize,
++ NewChannel->Inbound.RingBuffer,
++ NewChannel->Inbound.RingSize,
++ SendRingBufferSize);
+
+ /* Create and init the channel open message */
+- openInfo = kmalloc(sizeof(*openInfo) + sizeof(struct vmbus_channel_open_channel), GFP_KERNEL);
++ openInfo = kmalloc(sizeof(*openInfo) +
++ sizeof(struct vmbus_channel_open_channel),
++ GFP_KERNEL);
+ ASSERT(openInfo != NULL);
+
+ openInfo->WaitEvent = osd_WaitEventCreate();
+
+ openMsg = (struct vmbus_channel_open_channel *)openInfo->Msg;
+- openMsg->Header.MessageType = ChannelMessageOpenChannel;
+- openMsg->OpenId = NewChannel->OfferMsg.ChildRelId; /* FIXME */
+- openMsg->ChildRelId = NewChannel->OfferMsg.ChildRelId;
+- openMsg->RingBufferGpadlHandle = NewChannel->RingBufferGpadlHandle;
+- ASSERT(openMsg->RingBufferGpadlHandle);
+- openMsg->DownstreamRingBufferPageOffset = SendRingBufferSize >> PAGE_SHIFT;
+- openMsg->ServerContextAreaGpadlHandle = 0; /* TODO */
++ openMsg->Header.MessageType = ChannelMessageOpenChannel;
++ openMsg->OpenId = NewChannel->OfferMsg.ChildRelId; /* FIXME */
++ openMsg->ChildRelId = NewChannel->OfferMsg.ChildRelId;
++ openMsg->RingBufferGpadlHandle = NewChannel->RingBufferGpadlHandle;
++ ASSERT(openMsg->RingBufferGpadlHandle);
++ openMsg->DownstreamRingBufferPageOffset = SendRingBufferSize >>
++ PAGE_SHIFT;
++ openMsg->ServerContextAreaGpadlHandle = 0; /* TODO */
+
+ ASSERT(UserDataLen <= MAX_USER_DEFINED_BYTES);
+ if (UserDataLen)
+- {
+ memcpy(openMsg->UserData, UserData, UserDataLen);
+- }
+
+ spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
+- INSERT_TAIL_LIST(&gVmbusConnection.ChannelMsgList, &openInfo->MsgListEntry);
++ INSERT_TAIL_LIST(&gVmbusConnection.ChannelMsgList,
++ &openInfo->MsgListEntry);
+ spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
+
+ DPRINT_DBG(VMBUS, "Sending channel open msg...");
+
+- ret = VmbusPostMessage(openMsg, sizeof(struct vmbus_channel_open_channel));
+- if (ret != 0)
+- {
++ ret = VmbusPostMessage(openMsg,
++ sizeof(struct vmbus_channel_open_channel));
++ if (ret != 0) {
+ DPRINT_ERR(VMBUS, "unable to open channel - %d", ret);
+ goto Cleanup;
+ }
+@@ -281,13 +264,10 @@ int VmbusChannelOpen(struct vmbus_channe
+ osd_WaitEventWait(openInfo->WaitEvent);
+
+ if (openInfo->Response.OpenResult.Status == 0)
+- {
+ DPRINT_INFO(VMBUS, "channel <%p> open success!!", NewChannel);
+- }
+ else
+- {
+- DPRINT_INFO(VMBUS, "channel <%p> open failed - %d!!", NewChannel, openInfo->Response.OpenResult.Status);
+- }
++ DPRINT_INFO(VMBUS, "channel <%p> open failed - %d!!",
++ NewChannel, openInfo->Response.OpenResult.Status);
+
+ Cleanup:
+ spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
+@@ -302,119 +282,97 @@ Cleanup:
+ return 0;
+ }
+
+-/*++;
+-
+-Name:
+- DumpGpadlBody()
+-
+-Description:
+- Dump the gpadl body message to the console for debugging purposes.
+-
+---*/
++/**
++ * DumpGpadlBody - Dump the gpadl body message to the console for debugging purposes.
++ */
+ static void DumpGpadlBody(struct vmbus_channel_gpadl_body *Gpadl, u32 Len)
+ {
+- int i=0;
+- int pfnCount=0;
++ int i;
++ int pfnCount;
+
+- pfnCount = (Len - sizeof(struct vmbus_channel_gpadl_body))/ sizeof(u64);
++ pfnCount = (Len - sizeof(struct vmbus_channel_gpadl_body)) /
++ sizeof(u64);
+ DPRINT_DBG(VMBUS, "gpadl body - len %d pfn count %d", Len, pfnCount);
+
+- for (i=0; i< pfnCount; i++)
+- {
+- DPRINT_DBG(VMBUS, "gpadl body - %d) pfn %llu", i, Gpadl->Pfn[i]);
+- }
++ for (i = 0; i < pfnCount; i++)
++ DPRINT_DBG(VMBUS, "gpadl body - %d) pfn %llu",
++ i, Gpadl->Pfn[i]);
+ }
+
+-
+-/*++;
+-
+-Name:
+- DumpGpadlHeader()
+-
+-Description:
+- Dump the gpadl header message to the console for debugging purposes.
+-
+---*/
++/**
++ * DumpGpadlHeader - Dump the gpadl header message to the console for debugging purposes.
++ */
+ static void DumpGpadlHeader(struct vmbus_channel_gpadl_header *Gpadl)
+ {
+- int i=0,j=0;
+- int pageCount=0;
+-
++ int i, j;
++ int pageCount;
+
+- DPRINT_DBG(VMBUS, "gpadl header - relid %d, range count %d, range buflen %d",
+- Gpadl->ChildRelId,
+- Gpadl->RangeCount,
+- Gpadl->RangeBufLen);
+- for (i=0; i< Gpadl->RangeCount; i++)
+- {
++ DPRINT_DBG(VMBUS,
++ "gpadl header - relid %d, range count %d, range buflen %d",
++ Gpadl->ChildRelId, Gpadl->RangeCount, Gpadl->RangeBufLen);
++ for (i = 0; i < Gpadl->RangeCount; i++) {
+ pageCount = Gpadl->Range[i].ByteCount >> PAGE_SHIFT;
+- pageCount = (pageCount > 26)? 26 : pageCount;
++ pageCount = (pageCount > 26) ? 26 : pageCount;
+
+- DPRINT_DBG(VMBUS, "gpadl range %d - len %d offset %d page count %d",
+- i, Gpadl->Range[i].ByteCount, Gpadl->Range[i].ByteOffset, pageCount);
++ DPRINT_DBG(VMBUS, "gpadl range %d - len %d offset %d "
++ "page count %d", i, Gpadl->Range[i].ByteCount,
++ Gpadl->Range[i].ByteOffset, pageCount);
+
+- for (j=0; j< pageCount; j++)
+- {
+- DPRINT_DBG(VMBUS, "%d) pfn %llu", j, Gpadl->Range[i].PfnArray[j]);
+- }
++ for (j = 0; j < pageCount; j++)
++ DPRINT_DBG(VMBUS, "%d) pfn %llu", j,
++ Gpadl->Range[i].PfnArray[j]);
+ }
+ }
+
+-/*++;
+-
+-Name:
+- VmbusChannelCreateGpadlHeader()
+-
+-Description:
+- Creates a gpadl for the specified buffer
+-
+---*/
+-static int
+-VmbusChannelCreateGpadlHeader(
+- void * Kbuffer, /* from kmalloc() */
+- u32 Size, /* page-size multiple */
+- struct vmbus_channel_msginfo **MsgInfo,
+- u32 *MessageCount)
++/**
++ * VmbusChannelCreateGpadlHeader - Creates a gpadl for the specified buffer
++ */
++static int VmbusChannelCreateGpadlHeader(void *Kbuffer, u32 Size,
++ struct vmbus_channel_msginfo **MsgInfo,
++ u32 *MessageCount)
+ {
+ int i;
+ int pageCount;
+- unsigned long long pfn;
++ unsigned long long pfn;
+ struct vmbus_channel_gpadl_header *gpaHeader;
+ struct vmbus_channel_gpadl_body *gpadlBody;
+ struct vmbus_channel_msginfo *msgHeader;
+ struct vmbus_channel_msginfo *msgBody;
+- u32 msgSize;
++ u32 msgSize;
+
+ int pfnSum, pfnCount, pfnLeft, pfnCurr, pfnSize;
+
+- /* ASSERT( (kbuffer & (PAGE_SIZE-1)) == 0); */
+- ASSERT( (Size & (PAGE_SIZE-1)) == 0);
++ /* ASSERT((kbuffer & (PAGE_SIZE-1)) == 0); */
++ ASSERT((Size & (PAGE_SIZE-1)) == 0);
+
+ pageCount = Size >> PAGE_SHIFT;
+ pfn = virt_to_phys(Kbuffer) >> PAGE_SHIFT;
+
+ /* do we need a gpadl body msg */
+- pfnSize = MAX_SIZE_CHANNEL_MESSAGE - sizeof(struct vmbus_channel_gpadl_header) - sizeof(struct gpa_range);
++ pfnSize = MAX_SIZE_CHANNEL_MESSAGE -
++ sizeof(struct vmbus_channel_gpadl_header) -
++ sizeof(struct gpa_range);
+ pfnCount = pfnSize / sizeof(u64);
+
+- if (pageCount > pfnCount) /* we need a gpadl body */
+- {
++ if (pageCount > pfnCount) {
++ /* we need a gpadl body */
+ /* fill in the header */
+- msgSize = sizeof(struct vmbus_channel_msginfo) + sizeof(struct vmbus_channel_gpadl_header) + sizeof(struct gpa_range) + pfnCount*sizeof(u64);
++ msgSize = sizeof(struct vmbus_channel_msginfo) +
++ sizeof(struct vmbus_channel_gpadl_header) +
++ sizeof(struct gpa_range) + pfnCount * sizeof(u64);
+ msgHeader = kzalloc(msgSize, GFP_KERNEL);
+
+ INITIALIZE_LIST_HEAD(&msgHeader->SubMsgList);
+- msgHeader->MessageSize=msgSize;
++ msgHeader->MessageSize = msgSize;
+
+ gpaHeader = (struct vmbus_channel_gpadl_header *)msgHeader->Msg;
+ gpaHeader->RangeCount = 1;
+- gpaHeader->RangeBufLen = sizeof(struct gpa_range) + pageCount*sizeof(u64);
++ gpaHeader->RangeBufLen = sizeof(struct gpa_range) +
++ pageCount * sizeof(u64);
+ gpaHeader->Range[0].ByteOffset = 0;
+ gpaHeader->Range[0].ByteCount = Size;
+- for (i=0; i<pfnCount; i++)
+- {
++ for (i = 0; i < pfnCount; i++)
+ gpaHeader->Range[0].PfnArray[i] = pfn+i;
+- }
+ *MsgInfo = msgHeader;
+ *MessageCount = 1;
+
+@@ -422,57 +380,58 @@ VmbusChannelCreateGpadlHeader(
+ pfnLeft = pageCount - pfnCount;
+
+ /* how many pfns can we fit */
+- pfnSize = MAX_SIZE_CHANNEL_MESSAGE - sizeof(struct vmbus_channel_gpadl_body);
++ pfnSize = MAX_SIZE_CHANNEL_MESSAGE -
++ sizeof(struct vmbus_channel_gpadl_body);
+ pfnCount = pfnSize / sizeof(u64);
+
+ /* fill in the body */
+- while (pfnLeft)
+- {
++ while (pfnLeft) {
+ if (pfnLeft > pfnCount)
+- {
+ pfnCurr = pfnCount;
+- }
+ else
+- {
+ pfnCurr = pfnLeft;
+- }
+
+- msgSize = sizeof(struct vmbus_channel_msginfo) + sizeof(struct vmbus_channel_gpadl_body) + pfnCurr*sizeof(u64);
++ msgSize = sizeof(struct vmbus_channel_msginfo) +
++ sizeof(struct vmbus_channel_gpadl_body) +
++ pfnCurr * sizeof(u64);
+ msgBody = kzalloc(msgSize, GFP_KERNEL);
+ ASSERT(msgBody);
+ msgBody->MessageSize = msgSize;
+ (*MessageCount)++;
+- gpadlBody = (struct vmbus_channel_gpadl_body *)msgBody->Msg;
++ gpadlBody =
++ (struct vmbus_channel_gpadl_body *)msgBody->Msg;
+
+- /* FIXME: Gpadl is u32 and we are using a pointer which could be 64-bit */
++ /*
++ * FIXME:
++ * Gpadl is u32 and we are using a pointer which could
++ * be 64-bit
++ */
+ /* gpadlBody->Gpadl = kbuffer; */
+- for (i=0; i<pfnCurr; i++)
+- {
++ for (i = 0; i < pfnCurr; i++)
+ gpadlBody->Pfn[i] = pfn + pfnSum + i;
+- }
+
+ /* add to msg header */
+- INSERT_TAIL_LIST(&msgHeader->SubMsgList, &msgBody->MsgListEntry);
++ INSERT_TAIL_LIST(&msgHeader->SubMsgList,
++ &msgBody->MsgListEntry);
+ pfnSum += pfnCurr;
+ pfnLeft -= pfnCurr;
+ }
+- }
+- else
+- {
++ } else {
+ /* everything fits in a header */
+- msgSize = sizeof(struct vmbus_channel_msginfo) + sizeof(struct vmbus_channel_gpadl_header) + sizeof(struct gpa_range) + pageCount*sizeof(u64);
++ msgSize = sizeof(struct vmbus_channel_msginfo) +
++ sizeof(struct vmbus_channel_gpadl_header) +
++ sizeof(struct gpa_range) + pageCount * sizeof(u64);
+ msgHeader = kzalloc(msgSize, GFP_KERNEL);
+- msgHeader->MessageSize=msgSize;
++ msgHeader->MessageSize = msgSize;
+
+ gpaHeader = (struct vmbus_channel_gpadl_header *)msgHeader->Msg;
+ gpaHeader->RangeCount = 1;
+- gpaHeader->RangeBufLen = sizeof(struct gpa_range) + pageCount*sizeof(u64);
++ gpaHeader->RangeBufLen = sizeof(struct gpa_range) +
++ pageCount * sizeof(u64);
+ gpaHeader->Range[0].ByteOffset = 0;
+ gpaHeader->Range[0].ByteCount = Size;
+- for (i=0; i<pageCount; i++)
+- {
++ for (i = 0; i < pageCount; i++)
+ gpaHeader->Range[0].PfnArray[i] = pfn+i;
+- }
+
+ *MsgInfo = msgHeader;
+ *MessageCount = 1;
+@@ -481,35 +440,28 @@ VmbusChannelCreateGpadlHeader(
+ return 0;
+ }
+
+-
+-/*++;
+-
+-Name:
+- VmbusChannelEstablishGpadl()
+-
+-Description:
+- Estabish a GPADL for the specified buffer
+-
+---*/
+-int VmbusChannelEstablishGpadl(struct vmbus_channel *Channel,
+- void * Kbuffer, /* from kmalloc() */
+- u32 Size, /* page-size multiple */
+- u32 *GpadlHandle
+- )
++/**
++ * VmbusChannelEstablishGpadl - Estabish a GPADL for the specified buffer
++ *
++ * @Channel: a channel
++ * @Kbuffer: from kmalloc
++ * @Size: page-size multiple
++ * @GpadlHandle: some funky thing
++ */
++int VmbusChannelEstablishGpadl(struct vmbus_channel *Channel, void *Kbuffer,
++ u32 Size, u32 *GpadlHandle)
+ {
+- int ret=0;
+ struct vmbus_channel_gpadl_header *gpadlMsg;
+ struct vmbus_channel_gpadl_body *gpadlBody;
+ /* struct vmbus_channel_gpadl_created *gpadlCreated; */
+-
+ struct vmbus_channel_msginfo *msgInfo;
+ struct vmbus_channel_msginfo *subMsgInfo;
+-
+ u32 msgCount;
+- LIST_ENTRY* anchor;
+- LIST_ENTRY* curr;
++ LIST_ENTRY *anchor;
++ LIST_ENTRY *curr;
+ u32 nextGpadlHandle;
+ unsigned long flags;
++ int ret;
+
+ DPRINT_ENTER(VMBUS);
+
+@@ -518,7 +470,7 @@ int VmbusChannelEstablishGpadl(struct vm
+
+ VmbusChannelCreateGpadlHeader(Kbuffer, Size, &msgInfo, &msgCount);
+ ASSERT(msgInfo != NULL);
+- ASSERT(msgCount >0);
++ ASSERT(msgCount > 0);
+
+ msgInfo->WaitEvent = osd_WaitEventCreate();
+ gpadlMsg = (struct vmbus_channel_gpadl_header *)msgInfo->Msg;
+@@ -529,44 +481,52 @@ int VmbusChannelEstablishGpadl(struct vm
+ DumpGpadlHeader(gpadlMsg);
+
+ spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
+- INSERT_TAIL_LIST(&gVmbusConnection.ChannelMsgList, &msgInfo->MsgListEntry);
++ INSERT_TAIL_LIST(&gVmbusConnection.ChannelMsgList,
++ &msgInfo->MsgListEntry);
+ spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
+
+- DPRINT_DBG(VMBUS, "buffer %p, size %d msg cnt %d", Kbuffer, Size, msgCount);
++ DPRINT_DBG(VMBUS, "buffer %p, size %d msg cnt %d",
++ Kbuffer, Size, msgCount);
+
+- DPRINT_DBG(VMBUS, "Sending GPADL Header - len %zd", msgInfo->MessageSize - sizeof(*msgInfo));
++ DPRINT_DBG(VMBUS, "Sending GPADL Header - len %zd",
++ msgInfo->MessageSize - sizeof(*msgInfo));
+
+- ret = VmbusPostMessage(gpadlMsg, msgInfo->MessageSize - sizeof(*msgInfo));
+- if (ret != 0)
+- {
++ ret = VmbusPostMessage(gpadlMsg, msgInfo->MessageSize -
++ sizeof(*msgInfo));
++ if (ret != 0) {
+ DPRINT_ERR(VMBUS, "Unable to open channel - %d", ret);
+ goto Cleanup;
+ }
+
+- if (msgCount>1)
+- {
+- ITERATE_LIST_ENTRIES(anchor, curr, &msgInfo->SubMsgList)
+- {
++ if (msgCount > 1) {
++ ITERATE_LIST_ENTRIES(anchor, curr, &msgInfo->SubMsgList) {
+ subMsgInfo = (struct vmbus_channel_msginfo *)curr;
+- gpadlBody = (struct vmbus_channel_gpadl_body *)subMsgInfo->Msg;
++ gpadlBody =
++ (struct vmbus_channel_gpadl_body *)subMsgInfo->Msg;
+
+ gpadlBody->Header.MessageType = ChannelMessageGpadlBody;
+ gpadlBody->Gpadl = nextGpadlHandle;
+
+- DPRINT_DBG(VMBUS, "Sending GPADL Body - len %zd", subMsgInfo->MessageSize - sizeof(*subMsgInfo));
+-
+- DumpGpadlBody(gpadlBody, subMsgInfo->MessageSize - sizeof(*subMsgInfo));
+- ret = VmbusPostMessage(gpadlBody, subMsgInfo->MessageSize - sizeof(*subMsgInfo));
++ DPRINT_DBG(VMBUS, "Sending GPADL Body - len %zd",
++ subMsgInfo->MessageSize -
++ sizeof(*subMsgInfo));
++
++ DumpGpadlBody(gpadlBody, subMsgInfo->MessageSize -
++ sizeof(*subMsgInfo));
++ ret = VmbusPostMessage(gpadlBody,
++ subMsgInfo->MessageSize -
++ sizeof(*subMsgInfo));
+ ASSERT(ret == 0);
+ }
+ }
+ osd_WaitEventWait(msgInfo->WaitEvent);
+
+ /* At this point, we received the gpadl created msg */
+- DPRINT_DBG(VMBUS, "Received GPADL created (relid %d, status %d handle %x)",
+- Channel->OfferMsg.ChildRelId,
+- msgInfo->Response.GpadlCreated.CreationStatus,
+- gpadlMsg->Gpadl);
++ DPRINT_DBG(VMBUS, "Received GPADL created "
++ "(relid %d, status %d handle %x)",
++ Channel->OfferMsg.ChildRelId,
++ msgInfo->Response.GpadlCreated.CreationStatus,
++ gpadlMsg->Gpadl);
+
+ *GpadlHandle = gpadlMsg->Gpadl;
+
+@@ -583,29 +543,22 @@ Cleanup:
+ return ret;
+ }
+
+-
+-
+-/*++;
+-
+-Name:
+- VmbusChannelTeardownGpadl()
+-
+-Description:
+- Teardown the specified GPADL handle
+-
+---*/
++/**
++ * VmbusChannelTeardownGpadl -Teardown the specified GPADL handle
++ */
+ int VmbusChannelTeardownGpadl(struct vmbus_channel *Channel, u32 GpadlHandle)
+ {
+- int ret=0;
+ struct vmbus_channel_gpadl_teardown *msg;
+ struct vmbus_channel_msginfo *info;
+ unsigned long flags;
++ int ret;
+
+ DPRINT_ENTER(VMBUS);
+
+ ASSERT(GpadlHandle != 0);
+
+- info = kmalloc(sizeof(*info) + sizeof(struct vmbus_channel_gpadl_teardown), GFP_KERNEL);
++ info = kmalloc(sizeof(*info) +
++ sizeof(struct vmbus_channel_gpadl_teardown), GFP_KERNEL);
+ ASSERT(info != NULL);
+
+ info->WaitEvent = osd_WaitEventCreate();
+@@ -613,17 +566,18 @@ int VmbusChannelTeardownGpadl(struct vmb
+ msg = (struct vmbus_channel_gpadl_teardown *)info->Msg;
+
+ msg->Header.MessageType = ChannelMessageGpadlTeardown;
+- msg->ChildRelId = Channel->OfferMsg.ChildRelId;
+- msg->Gpadl = GpadlHandle;
++ msg->ChildRelId = Channel->OfferMsg.ChildRelId;
++ msg->Gpadl = GpadlHandle;
+
+ spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
+ INSERT_TAIL_LIST(&gVmbusConnection.ChannelMsgList, &info->MsgListEntry);
+ spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
+
+- ret = VmbusPostMessage(msg, sizeof(struct vmbus_channel_gpadl_teardown));
+- if (ret != 0)
+- {
++ ret = VmbusPostMessage(msg,
++ sizeof(struct vmbus_channel_gpadl_teardown));
++ if (ret != 0) {
+ /* TODO: */
++ /* something... */
+ }
+
+ osd_WaitEventWait(info->WaitEvent);
+@@ -641,22 +595,15 @@ int VmbusChannelTeardownGpadl(struct vmb
+ return ret;
+ }
+
+-
+-/*++
+-
+-Name:
+- VmbusChannelClose()
+-
+-Description:
+- Close the specified channel
+-
+---*/
++/**
++ * VmbusChannelClose - Close the specified channel
++ */
+ void VmbusChannelClose(struct vmbus_channel *Channel)
+ {
+- int ret=0;
+ struct vmbus_channel_close_channel *msg;
+ struct vmbus_channel_msginfo *info;
+ unsigned long flags;
++ int ret;
+
+ DPRINT_ENTER(VMBUS);
+
+@@ -665,26 +612,26 @@ void VmbusChannelClose(struct vmbus_chan
+ del_timer(&Channel->poll_timer);
+
+ /* Send a closing message */
+- info = kmalloc(sizeof(*info) + sizeof(struct vmbus_channel_close_channel), GFP_KERNEL);
++ info = kmalloc(sizeof(*info) +
++ sizeof(struct vmbus_channel_close_channel), GFP_KERNEL);
+ ASSERT(info != NULL);
+
+ /* info->waitEvent = osd_WaitEventCreate(); */
+
+ msg = (struct vmbus_channel_close_channel *)info->Msg;
+- msg->Header.MessageType = ChannelMessageCloseChannel;
+- msg->ChildRelId = Channel->OfferMsg.ChildRelId;
++ msg->Header.MessageType = ChannelMessageCloseChannel;
++ msg->ChildRelId = Channel->OfferMsg.ChildRelId;
+
+ ret = VmbusPostMessage(msg, sizeof(struct vmbus_channel_close_channel));
+- if (ret != 0)
+- {
++ if (ret != 0) {
+ /* TODO: */
++ /* something... */
+ }
+
+ /* Tear down the gpadl for the channel's ring buffer */
+ if (Channel->RingBufferGpadlHandle)
+- {
+- VmbusChannelTeardownGpadl(Channel, Channel->RingBufferGpadlHandle);
+- }
++ VmbusChannelTeardownGpadl(Channel,
++ Channel->RingBufferGpadlHandle);
+
+ /* TODO: Send a msg to release the childRelId */
+
+@@ -696,15 +643,13 @@ void VmbusChannelClose(struct vmbus_chan
+
+ kfree(info);
+
+-
+ /*
+ * If we are closing the channel during an error path in
+ * opening the channel, don't free the channel since the
+ * caller will free the channel
+ */
+
+- if (Channel->State == CHANNEL_OPEN_STATE)
+- {
++ if (Channel->State == CHANNEL_OPEN_STATE) {
+ spin_lock_irqsave(&gVmbusConnection.channel_lock, flags);
+ REMOVE_ENTRY_LIST(&Channel->ListEntry);
+ spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags);
+@@ -715,33 +660,23 @@ void VmbusChannelClose(struct vmbus_chan
+ DPRINT_EXIT(VMBUS);
+ }
+
+-
+-/*++
+-
+-Name:
+- VmbusChannelSendPacket()
+-
+-Description:
+- Send the specified buffer on the given channel
+-
+---*/
+-int VmbusChannelSendPacket(struct vmbus_channel *Channel,
+- const void * Buffer,
+- u32 BufferLen,
+- u64 RequestId,
+- enum vmbus_packet_type Type,
+- u32 Flags
+-)
++/**
++ * VmbusChannelSendPacket - Send the specified buffer on the given channel
++ */
++int VmbusChannelSendPacket(struct vmbus_channel *Channel, const void *Buffer,
++ u32 BufferLen, u64 RequestId,
++ enum vmbus_packet_type Type, u32 Flags)
+ {
+- int ret=0;
+ struct vmpacket_descriptor desc;
+ u32 packetLen = sizeof(struct vmpacket_descriptor) + BufferLen;
+ u32 packetLenAligned = ALIGN_UP(packetLen, sizeof(u64));
+ struct scatterlist bufferList[3];
+- u64 alignedData=0;
++ u64 alignedData = 0;
++ int ret;
+
+ DPRINT_ENTER(VMBUS);
+- DPRINT_DBG(VMBUS, "channel %p buffer %p len %d", Channel, Buffer, BufferLen);
++ DPRINT_DBG(VMBUS, "channel %p buffer %p len %d",
++ Channel, Buffer, BufferLen);
+
+ DumpVmbusChannel(Channel);
+
+@@ -750,57 +685,43 @@ int VmbusChannelSendPacket(struct vmbus_
+ /* Setup the descriptor */
+ desc.Type = Type; /* VmbusPacketTypeDataInBand; */
+ desc.Flags = Flags; /* VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED; */
+- desc.DataOffset8 = sizeof(struct vmpacket_descriptor) >> 3; /* in 8-bytes granularity */
++ /* in 8-bytes granularity */
++ desc.DataOffset8 = sizeof(struct vmpacket_descriptor) >> 3;
+ desc.Length8 = (u16)(packetLenAligned >> 3);
+ desc.TransactionId = RequestId;
+
+- sg_init_table(bufferList,3);
++ sg_init_table(bufferList, 3);
+ sg_set_buf(&bufferList[0], &desc, sizeof(struct vmpacket_descriptor));
+ sg_set_buf(&bufferList[1], Buffer, BufferLen);
+ sg_set_buf(&bufferList[2], &alignedData, packetLenAligned - packetLen);
+
+- ret = RingBufferWrite(
+- &Channel->Outbound,
+- bufferList,
+- 3);
++ ret = RingBufferWrite(&Channel->Outbound, bufferList, 3);
+
+ /* TODO: We should determine if this is optional */
+ if (ret == 0 && !GetRingBufferInterruptMask(&Channel->Outbound))
+- {
+ VmbusChannelSetEvent(Channel);
+- }
+
+ DPRINT_EXIT(VMBUS);
+
+ return ret;
+ }
+
+-
+-/*++
+-
+-Name:
+- VmbusChannelSendPacketPageBuffer()
+-
+-Description:
+- Send a range of single-page buffer packets using a GPADL Direct packet type.
+-
+---*/
++/**
++ * VmbusChannelSendPacketPageBuffer - Send a range of single-page buffer packets using a GPADL Direct packet type.
++ */
+ int VmbusChannelSendPacketPageBuffer(struct vmbus_channel *Channel,
+- struct hv_page_buffer PageBuffers[],
+- u32 PageCount,
+- void * Buffer,
+- u32 BufferLen,
+- u64 RequestId
+-)
++ struct hv_page_buffer PageBuffers[],
++ u32 PageCount, void *Buffer, u32 BufferLen,
++ u64 RequestId)
+ {
+- int ret=0;
+- int i=0;
++ int ret;
++ int i;
+ struct VMBUS_CHANNEL_PACKET_PAGE_BUFFER desc;
+ u32 descSize;
+ u32 packetLen;
+ u32 packetLenAligned;
+ struct scatterlist bufferList[3];
+- u64 alignedData=0;
++ u64 alignedData = 0;
+
+ DPRINT_ENTER(VMBUS);
+
+@@ -808,8 +729,13 @@ int VmbusChannelSendPacketPageBuffer(str
+
+ DumpVmbusChannel(Channel);
+
+- /* Adjust the size down since VMBUS_CHANNEL_PACKET_PAGE_BUFFER is the largest size we support */
+- descSize = sizeof(struct VMBUS_CHANNEL_PACKET_PAGE_BUFFER) - ((MAX_PAGE_BUFFER_COUNT - PageCount)*sizeof(struct hv_page_buffer));
++ /*
++ * Adjust the size down since VMBUS_CHANNEL_PACKET_PAGE_BUFFER is the
++ * largest size we support
++ */
++ descSize = sizeof(struct VMBUS_CHANNEL_PACKET_PAGE_BUFFER) -
++ ((MAX_PAGE_BUFFER_COUNT - PageCount) *
++ sizeof(struct hv_page_buffer));
+ packetLen = descSize + BufferLen;
+ packetLenAligned = ALIGN_UP(packetLen, sizeof(u64));
+
+@@ -823,72 +749,62 @@ int VmbusChannelSendPacketPageBuffer(str
+ desc.TransactionId = RequestId;
+ desc.RangeCount = PageCount;
+
+- for (i=0; i<PageCount; i++)
+- {
++ for (i = 0; i < PageCount; i++) {
+ desc.Range[i].Length = PageBuffers[i].Length;
+ desc.Range[i].Offset = PageBuffers[i].Offset;
+ desc.Range[i].Pfn = PageBuffers[i].Pfn;
+ }
+
+- sg_init_table(bufferList,3);
++ sg_init_table(bufferList, 3);
+ sg_set_buf(&bufferList[0], &desc, descSize);
+ sg_set_buf(&bufferList[1], Buffer, BufferLen);
+ sg_set_buf(&bufferList[2], &alignedData, packetLenAligned - packetLen);
+
+- ret = RingBufferWrite(
+- &Channel->Outbound,
+- bufferList,
+- 3);
++ ret = RingBufferWrite(&Channel->Outbound, bufferList, 3);
+
+ /* TODO: We should determine if this is optional */
+ if (ret == 0 && !GetRingBufferInterruptMask(&Channel->Outbound))
+- {
+ VmbusChannelSetEvent(Channel);
+- }
+
+ DPRINT_EXIT(VMBUS);
+
+ return ret;
+ }
+
+-
+-
+-/*++
+-
+-Name:
+- VmbusChannelSendPacketMultiPageBuffer()
+-
+-Description:
+- Send a multi-page buffer packet using a GPADL Direct packet type.
+-
+---*/
++/**
++ * VmbusChannelSendPacketMultiPageBuffer - Send a multi-page buffer packet using a GPADL Direct packet type.
++ */
+ int VmbusChannelSendPacketMultiPageBuffer(struct vmbus_channel *Channel,
+- struct hv_multipage_buffer *MultiPageBuffer,
+- void * Buffer,
+- u32 BufferLen,
+- u64 RequestId
+-)
++ struct hv_multipage_buffer *MultiPageBuffer,
++ void *Buffer, u32 BufferLen, u64 RequestId)
+ {
+- int ret=0;
++ int ret;
+ struct VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER desc;
+ u32 descSize;
+ u32 packetLen;
+ u32 packetLenAligned;
+ struct scatterlist bufferList[3];
+- u64 alignedData=0;
+- u32 PfnCount = NUM_PAGES_SPANNED(MultiPageBuffer->Offset, MultiPageBuffer->Length);
++ u64 alignedData = 0;
++ u32 PfnCount = NUM_PAGES_SPANNED(MultiPageBuffer->Offset,
++ MultiPageBuffer->Length);
+
+ DPRINT_ENTER(VMBUS);
+
+ DumpVmbusChannel(Channel);
+
+- DPRINT_DBG(VMBUS, "data buffer - offset %u len %u pfn count %u", MultiPageBuffer->Offset, MultiPageBuffer->Length, PfnCount);
++ DPRINT_DBG(VMBUS, "data buffer - offset %u len %u pfn count %u",
++ MultiPageBuffer->Offset, MultiPageBuffer->Length, PfnCount);
+
+ ASSERT(PfnCount > 0);
+ ASSERT(PfnCount <= MAX_MULTIPAGE_BUFFER_COUNT);
+
+- /* Adjust the size down since VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER is the largest size we support */
+- descSize = sizeof(struct VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER) - ((MAX_MULTIPAGE_BUFFER_COUNT - PfnCount)*sizeof(u64));
++ /*
++ * Adjust the size down since VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER is
++ * the largest size we support
++ */
++ descSize = sizeof(struct VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER) -
++ ((MAX_MULTIPAGE_BUFFER_COUNT - PfnCount) *
++ sizeof(u64));
+ packetLen = descSize + BufferLen;
+ packetLenAligned = ALIGN_UP(packetLen, sizeof(u64));
+
+@@ -905,45 +821,31 @@ int VmbusChannelSendPacketMultiPageBuffe
+ desc.Range.Length = MultiPageBuffer->Length;
+ desc.Range.Offset = MultiPageBuffer->Offset;
+
+- memcpy(desc.Range.PfnArray, MultiPageBuffer->PfnArray, PfnCount*sizeof(u64));
++ memcpy(desc.Range.PfnArray, MultiPageBuffer->PfnArray,
++ PfnCount * sizeof(u64));
+
+- sg_init_table(bufferList,3);
++ sg_init_table(bufferList, 3);
+ sg_set_buf(&bufferList[0], &desc, descSize);
+ sg_set_buf(&bufferList[1], Buffer, BufferLen);
+ sg_set_buf(&bufferList[2], &alignedData, packetLenAligned - packetLen);
+
+- ret = RingBufferWrite(
+- &Channel->Outbound,
+- bufferList,
+- 3);
++ ret = RingBufferWrite(&Channel->Outbound, bufferList, 3);
+
+ /* TODO: We should determine if this is optional */
+ if (ret == 0 && !GetRingBufferInterruptMask(&Channel->Outbound))
+- {
+ VmbusChannelSetEvent(Channel);
+- }
+
+ DPRINT_EXIT(VMBUS);
+
+ return ret;
+ }
+
+-
+-/*++
+-
+-Name:
+- VmbusChannelRecvPacket()
+-
+-Description:
+- Retrieve the user packet on the specified channel
+-
+---*/
++/**
++ * VmbusChannelRecvPacket - Retrieve the user packet on the specified channel
++ */
+ /* TODO: Do we ever receive a gpa direct packet other than the ones we send ? */
+-int VmbusChannelRecvPacket(struct vmbus_channel *Channel,
+- void *Buffer,
+- u32 BufferLen,
+- u32 *BufferActualLen,
+- u64 *RequestId)
++int VmbusChannelRecvPacket(struct vmbus_channel *Channel, void *Buffer,
++ u32 BufferLen, u32 *BufferActualLen, u64 *RequestId)
+ {
+ struct vmpacket_descriptor desc;
+ u32 packetLen;
+@@ -958,9 +860,9 @@ int VmbusChannelRecvPacket(struct vmbus_
+
+ spin_lock_irqsave(&Channel->inbound_lock, flags);
+
+- ret = RingBufferPeek(&Channel->Inbound, &desc, sizeof(struct vmpacket_descriptor));
+- if (ret != 0)
+- {
++ ret = RingBufferPeek(&Channel->Inbound, &desc,
++ sizeof(struct vmpacket_descriptor));
++ if (ret != 0) {
+ spin_unlock_irqrestore(&Channel->inbound_lock, flags);
+
+ /* DPRINT_DBG(VMBUS, "nothing to read!!"); */
+@@ -974,20 +876,18 @@ int VmbusChannelRecvPacket(struct vmbus_
+ userLen = packetLen - (desc.DataOffset8 << 3);
+ /* ASSERT(userLen > 0); */
+
+- DPRINT_DBG(VMBUS, "packet received on channel %p relid %d <type %d flag %d tid %llx pktlen %d datalen %d> ",
+- Channel,
+- Channel->OfferMsg.ChildRelId,
+- desc.Type,
+- desc.Flags,
+- desc.TransactionId, packetLen, userLen);
++ DPRINT_DBG(VMBUS, "packet received on channel %p relid %d <type %d "
++ "flag %d tid %llx pktlen %d datalen %d> ",
++ Channel, Channel->OfferMsg.ChildRelId, desc.Type,
++ desc.Flags, desc.TransactionId, packetLen, userLen);
+
+ *BufferActualLen = userLen;
+
+- if (userLen > BufferLen)
+- {
++ if (userLen > BufferLen) {
+ spin_unlock_irqrestore(&Channel->inbound_lock, flags);
+
+- DPRINT_ERR(VMBUS, "buffer too small - got %d needs %d", BufferLen, userLen);
++ DPRINT_ERR(VMBUS, "buffer too small - got %d needs %d",
++ BufferLen, userLen);
+ DPRINT_EXIT(VMBUS);
+
+ return -1;
+@@ -996,7 +896,8 @@ int VmbusChannelRecvPacket(struct vmbus_
+ *RequestId = desc.TransactionId;
+
+ /* Copy over the packet to the user buffer */
+- ret = RingBufferRead(&Channel->Inbound, Buffer, userLen, (desc.DataOffset8 << 3));
++ ret = RingBufferRead(&Channel->Inbound, Buffer, userLen,
++ (desc.DataOffset8 << 3));
+
+ spin_unlock_irqrestore(&Channel->inbound_lock, flags);
+
+@@ -1005,21 +906,12 @@ int VmbusChannelRecvPacket(struct vmbus_
+ return 0;
+ }
+
+-/*++
+-
+-Name:
+- VmbusChannelRecvPacketRaw()
+-
+-Description:
+- Retrieve the raw packet on the specified channel
+-
+---*/
+-int VmbusChannelRecvPacketRaw(struct vmbus_channel *Channel,
+- void * Buffer,
+- u32 BufferLen,
+- u32* BufferActualLen,
+- u64* RequestId
+- )
++/**
++ * VmbusChannelRecvPacketRaw - Retrieve the raw packet on the specified channel
++ */
++int VmbusChannelRecvPacketRaw(struct vmbus_channel *Channel, void *Buffer,
++ u32 BufferLen, u32 *BufferActualLen,
++ u64 *RequestId)
+ {
+ struct vmpacket_descriptor desc;
+ u32 packetLen;
+@@ -1034,9 +926,9 @@ int VmbusChannelRecvPacketRaw(struct vmb
+
+ spin_lock_irqsave(&Channel->inbound_lock, flags);
+
+- ret = RingBufferPeek(&Channel->Inbound, &desc, sizeof(struct vmpacket_descriptor));
+- if (ret != 0)
+- {
++ ret = RingBufferPeek(&Channel->Inbound, &desc,
++ sizeof(struct vmpacket_descriptor));
++ if (ret != 0) {
+ spin_unlock_irqrestore(&Channel->inbound_lock, flags);
+
+ /* DPRINT_DBG(VMBUS, "nothing to read!!"); */
+@@ -1049,20 +941,18 @@ int VmbusChannelRecvPacketRaw(struct vmb
+ packetLen = desc.Length8 << 3;
+ userLen = packetLen - (desc.DataOffset8 << 3);
+
+- DPRINT_DBG(VMBUS, "packet received on channel %p relid %d <type %d flag %d tid %llx pktlen %d datalen %d> ",
+- Channel,
+- Channel->OfferMsg.ChildRelId,
+- desc.Type,
+- desc.Flags,
+- desc.TransactionId, packetLen, userLen);
++ DPRINT_DBG(VMBUS, "packet received on channel %p relid %d <type %d "
++ "flag %d tid %llx pktlen %d datalen %d> ",
++ Channel, Channel->OfferMsg.ChildRelId, desc.Type,
++ desc.Flags, desc.TransactionId, packetLen, userLen);
+
+ *BufferActualLen = packetLen;
+
+- if (packetLen > BufferLen)
+- {
++ if (packetLen > BufferLen) {
+ 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_ERR(VMBUS, "buffer too small - needed %d bytes but "
++ "got space for only %d bytes", packetLen, BufferLen);
+ DPRINT_EXIT(VMBUS);
+ return -2;
+ }
+@@ -1079,16 +969,9 @@ int VmbusChannelRecvPacketRaw(struct vmb
+ return 0;
+ }
+
+-
+-/*++
+-
+-Name:
+- VmbusChannelOnChannelEvent()
+-
+-Description:
+- Channel event callback
+-
+---*/
++/**
++ * VmbusChannelOnChannelEvent - Channel event callback
++ */
+ void VmbusChannelOnChannelEvent(struct vmbus_channel *Channel)
+ {
+ DumpVmbusChannel(Channel);
+@@ -1103,21 +986,14 @@ void VmbusChannelOnChannelEvent(struct v
+ #endif
+ }
+
+-/*++
+-
+-Name:
+- VmbusChannelOnTimer()
+-
+-Description:
+- Timer event callback
+-
+---*/
++/**
++ * VmbusChannelOnTimer - Timer event callback
++ */
+ void VmbusChannelOnTimer(unsigned long data)
+ {
+ struct vmbus_channel *channel = (struct vmbus_channel *)data;
+
+- if (channel->OnChannelCallback)
+- {
++ if (channel->OnChannelCallback) {
+ channel->OnChannelCallback(channel->ChannelCallbackContext);
+ #ifdef ENABLE_POLLING
+ channel->poll_timer.expires(jiffies + usecs_to_jiffies(100);
+@@ -1126,22 +1002,12 @@ void VmbusChannelOnTimer(unsigned long d
+ }
+ }
+
+-
+-/*++
+-
+-Name:
+- DumpVmbusChannel()
+-
+-Description:
+- Dump vmbus channel info to the console
+-
+---*/
++/**
++ * DumpVmbusChannel - Dump vmbus channel info to the console
++ */
+ static void DumpVmbusChannel(struct vmbus_channel *Channel)
+ {
+ DPRINT_DBG(VMBUS, "Channel (%d)", Channel->OfferMsg.ChildRelId);
+ DumpRingInfo(&Channel->Outbound, "Outbound ");
+ DumpRingInfo(&Channel->Inbound, "Inbound ");
+ }
+-
+-
+-/* eof */
diff --git a/staging/staging-hv-coding-style-fixes-for-blkvsc_drv.c.patch b/staging/staging-hv-coding-style-fixes-for-blkvsc_drv.c.patch
new file mode 100644
index 00000000000000..c1b513a0c8c12e
--- /dev/null
+++ b/staging/staging-hv-coding-style-fixes-for-blkvsc_drv.c.patch
@@ -0,0 +1,1788 @@
+From foo@baz Tue Sep 1 16:34:56 PDT 2009
+Date: Tue, 01 Sep 2009 16:34:56 -0700
+To: Greg KH <greg@kroah.com>
+From: Greg Kroah-Hartman <gregkh@suse.de>
+Subject: Staging: hv: coding style fixes for blkvsc_drv.c
+
+There are still some very long lines, someone needs to unwind the
+logic there to resolve that.
+
+Cc: Hank Janssen <hjanssen@microsoft.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
+
+---
+ drivers/staging/hv/blkvsc_drv.c | 1055 +++++++++++++++++++---------------------
+ 1 file changed, 522 insertions(+), 533 deletions(-)
+
+--- a/drivers/staging/hv/blkvsc_drv.c
++++ b/drivers/staging/hv/blkvsc_drv.c
+@@ -1,5 +1,4 @@
+ /*
+- *
+ * Copyright (c) 2009, Microsoft Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+@@ -17,9 +16,7 @@
+ *
+ * Authors:
+ * Hank Janssen <hjanssen@microsoft.com>
+- *
+ */
+-
+ #include <linux/init.h>
+ #include <linux/module.h>
+ #include <linux/device.h>
+@@ -27,25 +24,18 @@
+ #include <linux/major.h>
+ #include <linux/delay.h>
+ #include <linux/hdreg.h>
+-
+ #include <scsi/scsi.h>
+ #include <scsi/scsi_cmnd.h>
+ #include <scsi/scsi_eh.h>
+ #include <scsi/scsi_dbg.h>
+-
+ #include "osd.h"
+ #include "logging.h"
+ #include "vmbus.h"
+ #include "StorVscApi.h"
+
+
+-/* #defines */
+-
+ #define BLKVSC_MINORS 64
+
+-
+-/* Data types */
+-
+ enum blkvsc_device_type {
+ UNKNOWN_DEV_TYPE,
+ HARDDISK_TYPE,
+@@ -58,64 +48,74 @@ enum blkvsc_device_type {
+ * represented by 1 or more struct blkvsc_request
+ */
+ struct blkvsc_request_group {
+- int outstanding;
+- int status;
+-
+- struct list_head blkvsc_req_list; /* list of blkvsc_requests */
++ int outstanding;
++ int status;
++ struct list_head blkvsc_req_list; /* list of blkvsc_requests */
+ };
+
+-
+ struct blkvsc_request {
+- struct list_head req_entry; /* blkvsc_request_group.blkvsc_req_list */
++ /* blkvsc_request_group.blkvsc_req_list */
++ struct list_head req_entry;
++
++ /* block_device_context.pending_list */
++ struct list_head pend_entry;
++
++ /* This may be null if we generate a request internally */
++ struct request *req;
+
+- struct list_head pend_entry; /* block_device_context.pending_list */
++ struct block_device_context *dev;
+
+- struct request *req; /* This may be null if we generate a request internally */
+- struct block_device_context *dev;
+- struct blkvsc_request_group *group; /* The group this request is part of. Maybe null */
++ /* The group this request is part of. Maybe null */
++ struct blkvsc_request_group *group;
+
+- wait_queue_head_t wevent;
++ wait_queue_head_t wevent;
+ int cond;
+
+- int write;
+- sector_t sector_start;
+- unsigned long sector_count;
++ int write;
++ sector_t sector_start;
++ unsigned long sector_count;
+
+ unsigned char sense_buffer[SCSI_SENSE_BUFFERSIZE];
+ unsigned char cmd_len;
+ unsigned char cmnd[MAX_COMMAND_SIZE];
+
+ struct hv_storvsc_request request;
+- /* !!!DO NOT ADD ANYTHING BELOW HERE!!! Otherwise, memory can overlap, because - */
+- /* The extension buffer falls right here and is pointed to by request.Extension; */
++ /*
++ * !!!DO NOT ADD ANYTHING BELOW HERE!!! Otherwise, memory can overlap,
++ * because - The extension buffer falls right here and is pointed to by
++ * request.Extension;
++ * Which sounds like a horrible idea, who designed this?
++ */
+ };
+
+ /* Per device structure */
+ struct block_device_context {
+- struct device_context *device_ctx; /* point back to our device context */
+- struct kmem_cache *request_pool;
+- spinlock_t lock;
+- struct gendisk *gd;
++ /* point back to our device context */
++ struct device_context *device_ctx;
++ struct kmem_cache *request_pool;
++ spinlock_t lock;
++ struct gendisk *gd;
+ enum blkvsc_device_type device_type;
+- struct list_head pending_list;
++ struct list_head pending_list;
+
+- unsigned char device_id[64];
+- unsigned int device_id_len;
+- int num_outstanding_reqs;
+- int shutting_down;
+- int media_not_present;
+- unsigned int sector_size;
+- sector_t capacity;
+- unsigned int port;
+- unsigned char path;
+- unsigned char target;
+- int users;
++ unsigned char device_id[64];
++ unsigned int device_id_len;
++ int num_outstanding_reqs;
++ int shutting_down;
++ int media_not_present;
++ unsigned int sector_size;
++ sector_t capacity;
++ unsigned int port;
++ unsigned char path;
++ unsigned char target;
++ int users;
+ };
+
+ /* Per driver */
+ struct blkvsc_driver_context {
+ /* !! These must be the first 2 fields !! */
+- struct driver_context drv_ctx;
++ /* FIXME this is a bug! */
++ struct driver_context drv_ctx;
+ struct storvsc_driver_object drv_obj;
+ };
+
+@@ -133,8 +133,10 @@ static int blkvsc_ioctl(struct block_dev
+ unsigned cmd, unsigned long argument);
+ static void blkvsc_request(struct request_queue *queue);
+ static void blkvsc_request_completion(struct hv_storvsc_request *request);
+-static int blkvsc_do_request(struct block_device_context *blkdev, struct request *req);
+-static int blkvsc_submit_request(struct blkvsc_request *blkvsc_req, void (*request_completion)(struct hv_storvsc_request*) );
++static int blkvsc_do_request(struct block_device_context *blkdev,
++ struct request *req);
++static int blkvsc_submit_request(struct blkvsc_request *blkvsc_req,
++ void (*request_completion)(struct hv_storvsc_request *));
+ static void blkvsc_init_rw(struct blkvsc_request *blkvsc_req);
+ static void blkvsc_cmd_completion(struct hv_storvsc_request *request);
+ static int blkvsc_do_inquiry(struct block_device_context *blkdev);
+@@ -150,9 +152,7 @@ static int blkvsc_ringbuffer_size = BLKV
+ /* The one and only one */
+ static struct blkvsc_driver_context g_blkvsc_drv;
+
+-
+-static struct block_device_operations block_ops =
+-{
++static struct block_device_operations block_ops = {
+ .owner = THIS_MODULE,
+ .open = blkvsc_open,
+ .release = blkvsc_release,
+@@ -162,18 +162,14 @@ static struct block_device_operations bl
+ .ioctl = blkvsc_ioctl,
+ };
+
+-/*++
+-
+-Name: blkvsc_drv_init()
+-
+-Desc: BlkVsc driver initialization.
+-
+---*/
++/**
++ * blkvsc_drv_init - BlkVsc driver initialization.
++ */
+ static int blkvsc_drv_init(PFN_DRIVERINITIALIZE pfn_drv_init)
+ {
+- int ret=0;
+ struct storvsc_driver_object *storvsc_drv_obj = &g_blkvsc_drv.drv_obj;
+- struct driver_context *drv_ctx=&g_blkvsc_drv.drv_ctx;
++ struct driver_context *drv_ctx = &g_blkvsc_drv.drv_ctx;
++ int ret;
+
+ DPRINT_ENTER(BLKVSC_DRV);
+
+@@ -185,7 +181,8 @@ static int blkvsc_drv_init(PFN_DRIVERINI
+ pfn_drv_init(&storvsc_drv_obj->Base);
+
+ drv_ctx->driver.name = storvsc_drv_obj->Base.name;
+- memcpy(&drv_ctx->class_id, &storvsc_drv_obj->Base.deviceType, sizeof(struct hv_guid));
++ memcpy(&drv_ctx->class_id, &storvsc_drv_obj->Base.deviceType,
++ sizeof(struct hv_guid));
+
+ drv_ctx->probe = blkvsc_probe;
+ drv_ctx->remove = blkvsc_remove;
+@@ -199,7 +196,6 @@ static int blkvsc_drv_init(PFN_DRIVERINI
+ return ret;
+ }
+
+-
+ static int blkvsc_drv_exit_cb(struct device *dev, void *data)
+ {
+ struct device **curr = (struct device **)data;
+@@ -207,24 +203,16 @@ static int blkvsc_drv_exit_cb(struct dev
+ return 1; /* stop iterating */
+ }
+
+-/*++
+-
+-Name: blkvsc_drv_exit()
+-
+-Desc:
+-
+---*/
+ static void blkvsc_drv_exit(void)
+ {
+ struct storvsc_driver_object *storvsc_drv_obj = &g_blkvsc_drv.drv_obj;
+- struct driver_context *drv_ctx=&g_blkvsc_drv.drv_ctx;
+- struct device *current_dev=NULL;
++ struct driver_context *drv_ctx = &g_blkvsc_drv.drv_ctx;
++ struct device *current_dev;
+ int ret;
+
+ DPRINT_ENTER(BLKVSC_DRV);
+
+- while (1)
+- {
++ while (1) {
+ current_dev = NULL;
+
+ /* Get the device */
+@@ -254,47 +242,40 @@ static void blkvsc_drv_exit(void)
+ return;
+ }
+
+-/*++
+-
+-Name: blkvsc_probe()
+-
+-Desc: Add a new device for this driver
+-
+---*/
++/**
++ * blkvsc_probe - Add a new device for this driver
++ */
+ static int blkvsc_probe(struct device *device)
+ {
+- int ret=0;
+-
+- struct driver_context *driver_ctx = driver_to_driver_context(device->driver);
+- struct blkvsc_driver_context *blkvsc_drv_ctx = (struct blkvsc_driver_context*)driver_ctx;
+- struct storvsc_driver_object *storvsc_drv_obj = &blkvsc_drv_ctx->drv_obj;
+-
++ struct driver_context *driver_ctx =
++ driver_to_driver_context(device->driver);
++ struct blkvsc_driver_context *blkvsc_drv_ctx =
++ (struct blkvsc_driver_context *)driver_ctx;
++ struct storvsc_driver_object *storvsc_drv_obj =
++ &blkvsc_drv_ctx->drv_obj;
+ struct device_context *device_ctx = device_to_device_context(device);
+ struct hv_device *device_obj = &device_ctx->device_obj;
+
+- struct block_device_context *blkdev=NULL;
++ struct block_device_context *blkdev = NULL;
+ struct storvsc_device_info device_info;
+- int major=0;
+- int devnum=0;
+-
+- static int ide0_registered=0;
+- static int ide1_registered=0;
++ int major = 0;
++ int devnum = 0;
++ int ret = 0;
++ static int ide0_registered;
++ static int ide1_registered;
+
+ DPRINT_ENTER(BLKVSC_DRV);
+
+ DPRINT_DBG(BLKVSC_DRV, "blkvsc_probe - enter");
+
+- if (!storvsc_drv_obj->Base.OnDeviceAdd)
+- {
++ if (!storvsc_drv_obj->Base.OnDeviceAdd) {
+ DPRINT_ERR(BLKVSC_DRV, "OnDeviceAdd() not set");
+-
+ ret = -1;
+ goto Cleanup;
+ }
+
+ blkdev = kzalloc(sizeof(struct block_device_context), GFP_KERNEL);
+- if (!blkdev)
+- {
++ if (!blkdev) {
+ ret = -ENOMEM;
+ goto Cleanup;
+ }
+@@ -304,13 +285,14 @@ static int blkvsc_probe(struct device *d
+ /* Initialize what we can here */
+ spin_lock_init(&blkdev->lock);
+
+- ASSERT(sizeof(struct blkvsc_request_group) <= sizeof(struct blkvsc_request));
++ ASSERT(sizeof(struct blkvsc_request_group) <=
++ sizeof(struct blkvsc_request));
+
+ blkdev->request_pool = kmem_cache_create(dev_name(&device_ctx->device),
+- sizeof(struct blkvsc_request) + storvsc_drv_obj->RequestExtSize, 0,
+- SLAB_HWCACHE_ALIGN, NULL);
+- if (!blkdev->request_pool)
+- {
++ sizeof(struct blkvsc_request) +
++ storvsc_drv_obj->RequestExtSize, 0,
++ SLAB_HWCACHE_ALIGN, NULL);
++ if (!blkdev->request_pool) {
+ ret = -ENOMEM;
+ goto Cleanup;
+ }
+@@ -318,56 +300,51 @@ static int blkvsc_probe(struct device *d
+
+ /* Call to the vsc driver to add the device */
+ ret = storvsc_drv_obj->Base.OnDeviceAdd(device_obj, &device_info);
+- if (ret != 0)
+- {
++ if (ret != 0) {
+ DPRINT_ERR(BLKVSC_DRV, "unable to add blkvsc device");
+ goto Cleanup;
+ }
+
+ blkdev->device_ctx = device_ctx;
+- blkdev->target = device_info.TargetId; /* this identified the device 0 or 1 */
+- blkdev->path = device_info.PathId; /* this identified the ide ctrl 0 or 1 */
++ /* this identified the device 0 or 1 */
++ blkdev->target = device_info.TargetId;
++ /* this identified the ide ctrl 0 or 1 */
++ blkdev->path = device_info.PathId;
+
+ dev_set_drvdata(device, blkdev);
+
+ /* Calculate the major and device num */
+- if (blkdev->path == 0)
+- {
++ if (blkdev->path == 0) {
+ major = IDE0_MAJOR;
+ devnum = blkdev->path + blkdev->target; /* 0 or 1 */
+
+- if (!ide0_registered)
+- {
++ if (!ide0_registered) {
+ ret = register_blkdev(major, "ide");
+- if (ret != 0)
+- {
+- DPRINT_ERR(BLKVSC_DRV, "register_blkdev() failed! ret %d", ret);
++ if (ret != 0) {
++ DPRINT_ERR(BLKVSC_DRV,
++ "register_blkdev() failed! ret %d",
++ ret);
+ goto Remove;
+ }
+
+ ide0_registered = 1;
+ }
+- }
+- else if (blkdev->path == 1)
+- {
++ } else if (blkdev->path == 1) {
+ major = IDE1_MAJOR;
+ devnum = blkdev->path + blkdev->target + 1; /* 2 or 3 */
+
+- if (!ide1_registered)
+- {
++ if (!ide1_registered) {
+ ret = register_blkdev(major, "ide");
+- if (ret != 0)
+- {
+- DPRINT_ERR(BLKVSC_DRV, "register_blkdev() failed! ret %d", ret);
++ if (ret != 0) {
++ DPRINT_ERR(BLKVSC_DRV,
++ "register_blkdev() failed! ret %d",
++ ret);
+ goto Remove;
+ }
+
+ ide1_registered = 1;
+ }
+-
+- }
+- else
+- {
++ } else {
+ DPRINT_ERR(BLKVSC_DRV, "invalid pathid");
+ ret = -1;
+ goto Cleanup;
+@@ -376,8 +353,7 @@ static int blkvsc_probe(struct device *d
+ DPRINT_INFO(BLKVSC_DRV, "blkvsc registered for major %d!!", major);
+
+ blkdev->gd = alloc_disk(BLKVSC_MINORS);
+- if (!blkdev->gd)
+- {
++ if (!blkdev->gd) {
+ DPRINT_ERR(BLKVSC_DRV, "register_blkdev() failed! ret %d", ret);
+ ret = -1;
+ goto Cleanup;
+@@ -386,8 +362,10 @@ static int blkvsc_probe(struct device *d
+ blkdev->gd->queue = blk_init_queue(blkvsc_request, &blkdev->lock);
+
+ blk_queue_max_segment_size(blkdev->gd->queue, PAGE_SIZE);
+- blk_queue_max_phys_segments(blkdev->gd->queue, MAX_MULTIPAGE_BUFFER_COUNT);
+- blk_queue_max_hw_segments(blkdev->gd->queue, MAX_MULTIPAGE_BUFFER_COUNT);
++ blk_queue_max_phys_segments(blkdev->gd->queue,
++ MAX_MULTIPAGE_BUFFER_COUNT);
++ blk_queue_max_hw_segments(blkdev->gd->queue,
++ MAX_MULTIPAGE_BUFFER_COUNT);
+ blk_queue_segment_boundary(blkdev->gd->queue, PAGE_SIZE-1);
+ blk_queue_bounce_limit(blkdev->gd->queue, BLK_BOUNCE_ANY);
+ blk_queue_dma_alignment(blkdev->gd->queue, 511);
+@@ -399,17 +377,14 @@ static int blkvsc_probe(struct device *d
+ blkdev->gd->first_minor = 0;
+ blkdev->gd->fops = &block_ops;
+ blkdev->gd->private_data = blkdev;
+- sprintf(blkdev->gd->disk_name, "hd%c", 'a'+ devnum);
++ sprintf(blkdev->gd->disk_name, "hd%c", 'a' + devnum);
+
+ blkvsc_do_inquiry(blkdev);
+- if (blkdev->device_type == DVD_TYPE)
+- {
++ if (blkdev->device_type == DVD_TYPE) {
+ set_disk_ro(blkdev->gd, 1);
+ blkdev->gd->flags |= GENHD_FL_REMOVABLE;
+ blkvsc_do_read_capacity(blkdev);
+- }
+- else
+- {
++ } else {
+ blkvsc_do_read_capacity16(blkdev);
+ }
+
+@@ -418,7 +393,9 @@ static int blkvsc_probe(struct device *d
+ /* go! */
+ add_disk(blkdev->gd);
+
+- DPRINT_INFO(BLKVSC_DRV, "%s added!! capacity %lu sector_size %d", blkdev->gd->disk_name, (unsigned long) blkdev->capacity, blkdev->sector_size);
++ DPRINT_INFO(BLKVSC_DRV, "%s added!! capacity %lu sector_size %d",
++ blkdev->gd->disk_name, (unsigned long)blkdev->capacity,
++ blkdev->sector_size);
+
+ return ret;
+
+@@ -426,10 +403,8 @@ Remove:
+ storvsc_drv_obj->Base.OnDeviceRemove(device_obj);
+
+ Cleanup:
+- if (blkdev)
+- {
+- if (blkdev->request_pool)
+- {
++ if (blkdev) {
++ if (blkdev->request_pool) {
+ kmem_cache_destroy(blkdev->request_pool);
+ blkdev->request_pool = NULL;
+ }
+@@ -450,7 +425,8 @@ static void blkvsc_shutdown(struct devic
+ if (!blkdev)
+ return;
+
+- DPRINT_DBG(BLKVSC_DRV, "blkvsc_shutdown - users %d disk %s\n", blkdev->users, blkdev->gd->disk_name);
++ DPRINT_DBG(BLKVSC_DRV, "blkvsc_shutdown - users %d disk %s\n",
++ blkdev->users, blkdev->gd->disk_name);
+
+ spin_lock_irqsave(&blkdev->lock, flags);
+
+@@ -460,10 +436,9 @@ static void blkvsc_shutdown(struct devic
+
+ spin_unlock_irqrestore(&blkdev->lock, flags);
+
+- while (blkdev->num_outstanding_reqs)
+- {
+- DPRINT_INFO(STORVSC, "waiting for %d requests to complete...", blkdev->num_outstanding_reqs);
+-
++ while (blkdev->num_outstanding_reqs) {
++ DPRINT_INFO(STORVSC, "waiting for %d requests to complete...",
++ blkdev->num_outstanding_reqs);
+ udelay(100);
+ }
+
+@@ -478,7 +453,7 @@ static void blkvsc_shutdown(struct devic
+
+ static int blkvsc_do_flush(struct block_device_context *blkdev)
+ {
+- struct blkvsc_request *blkvsc_req=NULL;
++ struct blkvsc_request *blkvsc_req;
+
+ DPRINT_DBG(BLKVSC_DRV, "blkvsc_do_flush()\n");
+
+@@ -487,9 +462,7 @@ static int blkvsc_do_flush(struct block_
+
+ blkvsc_req = kmem_cache_alloc(blkdev->request_pool, GFP_KERNEL);
+ if (!blkvsc_req)
+- {
+ return -ENOMEM;
+- }
+
+ memset(blkvsc_req, 0, sizeof(struct blkvsc_request));
+ init_waitqueue_head(&blkvsc_req->wevent);
+@@ -504,8 +477,11 @@ static int blkvsc_do_flush(struct block_
+ blkvsc_req->cmnd[0] = SYNCHRONIZE_CACHE;
+ blkvsc_req->cmd_len = 10;
+
+- /* Set this here since the completion routine may be invoked and completed before we return */
+- blkvsc_req->cond =0;
++ /*
++ * Set this here since the completion routine may be invoked and
++ * completed before we return
++ */
++ blkvsc_req->cond = 0;
+ blkvsc_submit_request(blkvsc_req, blkvsc_cmd_completion);
+
+ wait_event_interruptible(blkvsc_req->wevent, blkvsc_req->cond);
+@@ -518,7 +494,7 @@ static int blkvsc_do_flush(struct block_
+ /* Do a scsi INQUIRY cmd here to get the device type (ie disk or dvd) */
+ static int blkvsc_do_inquiry(struct block_device_context *blkdev)
+ {
+- struct blkvsc_request *blkvsc_req=NULL;
++ struct blkvsc_request *blkvsc_req;
+ struct page *page_buf;
+ unsigned char *buf;
+ unsigned char device_type;
+@@ -527,14 +503,11 @@ static int blkvsc_do_inquiry(struct bloc
+
+ blkvsc_req = kmem_cache_alloc(blkdev->request_pool, GFP_KERNEL);
+ if (!blkvsc_req)
+- {
+ return -ENOMEM;
+- }
+
+ memset(blkvsc_req, 0, sizeof(struct blkvsc_request));
+ page_buf = alloc_page(GFP_KERNEL);
+- if (!page_buf)
+- {
++ if (!page_buf) {
+ kmem_cache_free(blkvsc_req->dev->request_pool, blkvsc_req);
+ return -ENOMEM;
+ }
+@@ -554,12 +527,16 @@ static int blkvsc_do_inquiry(struct bloc
+ blkvsc_req->cmnd[4] = 64;
+ blkvsc_req->cmd_len = 6;
+
+- /* Set this here since the completion routine may be invoked and completed before we return */
+- blkvsc_req->cond =0;
++ /*
++ * Set this here since the completion routine may be invoked and
++ * completed before we return
++ */
++ blkvsc_req->cond = 0;
+
+ blkvsc_submit_request(blkvsc_req, blkvsc_cmd_completion);
+
+- DPRINT_DBG(BLKVSC_DRV, "waiting %p to complete - cond %d\n", blkvsc_req, blkvsc_req->cond);
++ DPRINT_DBG(BLKVSC_DRV, "waiting %p to complete - cond %d\n",
++ blkvsc_req, blkvsc_req->cond);
+
+ wait_event_interruptible(blkvsc_req->wevent, blkvsc_req->cond);
+
+@@ -569,16 +546,11 @@ static int blkvsc_do_inquiry(struct bloc
+ /* be to le */
+ device_type = buf[0] & 0x1F;
+
+- if (device_type == 0x0)
+- {
++ if (device_type == 0x0) {
+ blkdev->device_type = HARDDISK_TYPE;
+- }
+- else if (device_type == 0x5)
+- {
++ } else if (device_type == 0x5) {
+ blkdev->device_type = DVD_TYPE;
+- }
+- else
+- {
++ } else {
+ /* TODO: this is currently unsupported device type */
+ blkdev->device_type = UNKNOWN_DEV_TYPE;
+ }
+@@ -605,7 +577,7 @@ static int blkvsc_do_inquiry(struct bloc
+ /* Do a scsi READ_CAPACITY cmd here to get the size of the disk */
+ static int blkvsc_do_read_capacity(struct block_device_context *blkdev)
+ {
+- struct blkvsc_request *blkvsc_req=NULL;
++ struct blkvsc_request *blkvsc_req;
+ struct page *page_buf;
+ unsigned char *buf;
+ struct scsi_sense_hdr sense_hdr;
+@@ -618,14 +590,11 @@ static int blkvsc_do_read_capacity(struc
+
+ blkvsc_req = kmem_cache_alloc(blkdev->request_pool, GFP_KERNEL);
+ if (!blkvsc_req)
+- {
+ return -ENOMEM;
+- }
+
+ memset(blkvsc_req, 0, sizeof(struct blkvsc_request));
+ page_buf = alloc_page(GFP_KERNEL);
+- if (!page_buf)
+- {
++ if (!page_buf) {
+ kmem_cache_free(blkvsc_req->dev->request_pool, blkvsc_req);
+ return -ENOMEM;
+ }
+@@ -646,31 +615,33 @@ static int blkvsc_do_read_capacity(struc
+ * Set this here since the completion routine may be invoked
+ * and completed before we return
+ */
+- blkvsc_req->cond =0;
++ blkvsc_req->cond = 0;
+
+ blkvsc_submit_request(blkvsc_req, blkvsc_cmd_completion);
+
+- DPRINT_DBG(BLKVSC_DRV, "waiting %p to complete - cond %d\n", blkvsc_req, blkvsc_req->cond);
++ DPRINT_DBG(BLKVSC_DRV, "waiting %p to complete - cond %d\n",
++ blkvsc_req, blkvsc_req->cond);
+
+ wait_event_interruptible(blkvsc_req->wevent, blkvsc_req->cond);
+
+ /* check error */
+- if (blkvsc_req->request.Status)
+- {
+- scsi_normalize_sense(blkvsc_req->sense_buffer, SCSI_SENSE_BUFFERSIZE, &sense_hdr);
++ if (blkvsc_req->request.Status) {
++ scsi_normalize_sense(blkvsc_req->sense_buffer,
++ SCSI_SENSE_BUFFERSIZE, &sense_hdr);
+
+- if (sense_hdr.asc == 0x3A) /* Medium not present */
+- {
++ if (sense_hdr.asc == 0x3A) {
++ /* Medium not present */
+ blkdev->media_not_present = 1;
+ }
+-
+ return 0;
+ }
+ buf = kmap(page_buf);
+
+ /* be to le */
+- blkdev->capacity = ((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]) + 1;
+- blkdev->sector_size = (buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7];
++ blkdev->capacity = ((buf[0] << 24) | (buf[1] << 16) |
++ (buf[2] << 8) | buf[3]) + 1;
++ blkdev->sector_size = (buf[4] << 24) | (buf[5] << 16) |
++ (buf[6] << 8) | buf[7];
+
+ kunmap(page_buf);
+
+@@ -681,10 +652,9 @@ static int blkvsc_do_read_capacity(struc
+ return 0;
+ }
+
+-
+ static int blkvsc_do_read_capacity16(struct block_device_context *blkdev)
+ {
+- struct blkvsc_request *blkvsc_req=NULL;
++ struct blkvsc_request *blkvsc_req;
+ struct page *page_buf;
+ unsigned char *buf;
+ struct scsi_sense_hdr sense_hdr;
+@@ -697,14 +667,11 @@ static int blkvsc_do_read_capacity16(str
+
+ blkvsc_req = kmem_cache_alloc(blkdev->request_pool, GFP_KERNEL);
+ if (!blkvsc_req)
+- {
+ return -ENOMEM;
+- }
+
+ memset(blkvsc_req, 0, sizeof(struct blkvsc_request));
+ page_buf = alloc_page(GFP_KERNEL);
+- if (!page_buf)
+- {
++ if (!page_buf) {
+ kmem_cache_free(blkvsc_req->dev->request_pool, blkvsc_req);
+ return -ENOMEM;
+ }
+@@ -725,34 +692,37 @@ static int blkvsc_do_read_capacity16(str
+ * Set this here since the completion routine may be invoked
+ * and completed before we return
+ */
+- blkvsc_req->cond =0;
++ blkvsc_req->cond = 0;
+
+ blkvsc_submit_request(blkvsc_req, blkvsc_cmd_completion);
+
+- DPRINT_DBG(BLKVSC_DRV, "waiting %p to complete - cond %d\n", blkvsc_req, blkvsc_req->cond);
++ DPRINT_DBG(BLKVSC_DRV, "waiting %p to complete - cond %d\n",
++ blkvsc_req, blkvsc_req->cond);
+
+ wait_event_interruptible(blkvsc_req->wevent, blkvsc_req->cond);
+
+ /* check error */
+- if (blkvsc_req->request.Status)
+- {
+- scsi_normalize_sense(blkvsc_req->sense_buffer, SCSI_SENSE_BUFFERSIZE, &sense_hdr);
+-
+- if (sense_hdr.asc == 0x3A) /* Medium not present */
+- {
++ if (blkvsc_req->request.Status) {
++ scsi_normalize_sense(blkvsc_req->sense_buffer,
++ SCSI_SENSE_BUFFERSIZE, &sense_hdr);
++ if (sense_hdr.asc == 0x3A) {
++ /* Medium not present */
+ blkdev->media_not_present = 1;
+ }
+-
+ return 0;
+ }
+ buf = kmap(page_buf);
+
+ /* be to le */
+- blkdev->capacity = be64_to_cpu(*(unsigned long long*) &buf[0]) + 1;
+- blkdev->sector_size = be32_to_cpu(*(unsigned int*)&buf[8]);
++ blkdev->capacity = be64_to_cpu(*(unsigned long long *) &buf[0]) + 1;
++ blkdev->sector_size = be32_to_cpu(*(unsigned int *)&buf[8]);
+
+- /* blkdev->capacity = ((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]) + 1; */
+- /* blkdev->sector_size = (buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7]; */
++#if 0
++ blkdev->capacity = ((buf[0] << 24) | (buf[1] << 16) |
++ (buf[2] << 8) | buf[3]) + 1;
++ blkdev->sector_size = (buf[4] << 24) | (buf[5] << 16) |
++ (buf[6] << 8) | buf[7];
++#endif
+
+ kunmap(page_buf);
+
+@@ -763,42 +733,41 @@ static int blkvsc_do_read_capacity16(str
+ return 0;
+ }
+
+-/*++
+-
+-Name: blkvsc_remove()
+-
+-Desc: Callback when our device is removed
+-
+---*/
++/**
++ * blkvsc_remove() - Callback when our device is removed
++ */
+ static int blkvsc_remove(struct device *device)
+ {
+- int ret=0;
+-
+- struct driver_context *driver_ctx = driver_to_driver_context(device->driver);
+- struct blkvsc_driver_context *blkvsc_drv_ctx = (struct blkvsc_driver_context*)driver_ctx;
+- struct storvsc_driver_object *storvsc_drv_obj = &blkvsc_drv_ctx->drv_obj;
+-
++ struct driver_context *driver_ctx =
++ driver_to_driver_context(device->driver);
++ struct blkvsc_driver_context *blkvsc_drv_ctx =
++ (struct blkvsc_driver_context *)driver_ctx;
++ struct storvsc_driver_object *storvsc_drv_obj =
++ &blkvsc_drv_ctx->drv_obj;
+ struct device_context *device_ctx = device_to_device_context(device);
+ struct hv_device *device_obj = &device_ctx->device_obj;
+ struct block_device_context *blkdev = dev_get_drvdata(device);
+ unsigned long flags;
++ int ret;
+
+ DPRINT_ENTER(BLKVSC_DRV);
+
+ DPRINT_DBG(BLKVSC_DRV, "blkvsc_remove()\n");
+
+- if (!storvsc_drv_obj->Base.OnDeviceRemove)
+- {
++ if (!storvsc_drv_obj->Base.OnDeviceRemove) {
+ DPRINT_EXIT(BLKVSC_DRV);
+ return -1;
+ }
+
+- /* Call to the vsc driver to let it know that the device is being removed */
++ /*
++ * Call to the vsc driver to let it know that the device is being
++ * removed
++ */
+ ret = storvsc_drv_obj->Base.OnDeviceRemove(device_obj);
+- if (ret != 0)
+- {
++ if (ret != 0) {
+ /* TODO: */
+- DPRINT_ERR(BLKVSC_DRV, "unable to remove blkvsc device (ret %d)", ret);
++ DPRINT_ERR(BLKVSC_DRV,
++ "unable to remove blkvsc device (ret %d)", ret);
+ }
+
+ /* Get to a known state */
+@@ -810,10 +779,9 @@ static int blkvsc_remove(struct device *
+
+ spin_unlock_irqrestore(&blkdev->lock, flags);
+
+- while (blkdev->num_outstanding_reqs)
+- {
+- DPRINT_INFO(STORVSC, "waiting for %d requests to complete...", blkdev->num_outstanding_reqs);
+-
++ while (blkdev->num_outstanding_reqs) {
++ DPRINT_INFO(STORVSC, "waiting for %d requests to complete...",
++ blkdev->num_outstanding_reqs);
+ udelay(100);
+ }
+
+@@ -845,92 +813,89 @@ static void blkvsc_init_rw(struct blkvsc
+
+ blkvsc_req->cmd_len = 16;
+
+- if (blkvsc_req->sector_start > 0xffffffff)
+- {
+- if (rq_data_dir(blkvsc_req->req))
+- {
++ if (blkvsc_req->sector_start > 0xffffffff) {
++ if (rq_data_dir(blkvsc_req->req)) {
+ blkvsc_req->write = 1;
+ blkvsc_req->cmnd[0] = WRITE_16;
+- }
+- else
+- {
++ } else {
+ blkvsc_req->write = 0;
+ blkvsc_req->cmnd[0] = READ_16;
+ }
+
+ blkvsc_req->cmnd[1] |= blk_fua_rq(blkvsc_req->req) ? 0x8 : 0;
+
+- *(unsigned long long*)&blkvsc_req->cmnd[2] = cpu_to_be64(blkvsc_req->sector_start);
+- *(unsigned int*)&blkvsc_req->cmnd[10] = cpu_to_be32(blkvsc_req->sector_count);
+- }
+- else if ((blkvsc_req->sector_count > 0xff) || (blkvsc_req->sector_start > 0x1fffff))
+- {
+- if (rq_data_dir(blkvsc_req->req))
+- {
++ *(unsigned long long *)&blkvsc_req->cmnd[2] =
++ cpu_to_be64(blkvsc_req->sector_start);
++ *(unsigned int *)&blkvsc_req->cmnd[10] =
++ cpu_to_be32(blkvsc_req->sector_count);
++ } else if ((blkvsc_req->sector_count > 0xff) ||
++ (blkvsc_req->sector_start > 0x1fffff)) {
++ if (rq_data_dir(blkvsc_req->req)) {
+ blkvsc_req->write = 1;
+ blkvsc_req->cmnd[0] = WRITE_10;
+- }
+- else
+- {
++ } else {
+ blkvsc_req->write = 0;
+ blkvsc_req->cmnd[0] = READ_10;
+ }
+
+ blkvsc_req->cmnd[1] |= blk_fua_rq(blkvsc_req->req) ? 0x8 : 0;
+
+- *(unsigned int *)&blkvsc_req->cmnd[2] = cpu_to_be32(blkvsc_req->sector_start);
+- *(unsigned short*)&blkvsc_req->cmnd[7] = cpu_to_be16(blkvsc_req->sector_count);
+- }
+- else
+- {
+- if (rq_data_dir(blkvsc_req->req))
+- {
++ *(unsigned int *)&blkvsc_req->cmnd[2] =
++ cpu_to_be32(blkvsc_req->sector_start);
++ *(unsigned short *)&blkvsc_req->cmnd[7] =
++ cpu_to_be16(blkvsc_req->sector_count);
++ } else {
++ if (rq_data_dir(blkvsc_req->req)) {
+ blkvsc_req->write = 1;
+ blkvsc_req->cmnd[0] = WRITE_6;
+- }
+- else
+- {
++ } else {
+ blkvsc_req->write = 0;
+ blkvsc_req->cmnd[0] = READ_6;
+ }
+
+- *(unsigned int *)&blkvsc_req->cmnd[1] = cpu_to_be32(blkvsc_req->sector_start) >> 8;
++ *(unsigned int *)&blkvsc_req->cmnd[1] =
++ cpu_to_be32(blkvsc_req->sector_start) >> 8;
+ blkvsc_req->cmnd[1] &= 0x1f;
+- blkvsc_req->cmnd[4] = (unsigned char) blkvsc_req->sector_count;
++ blkvsc_req->cmnd[4] = (unsigned char)blkvsc_req->sector_count;
+ }
+ }
+
+-static int blkvsc_submit_request(struct blkvsc_request *blkvsc_req, void (*request_completion)(struct hv_storvsc_request*) )
++static int blkvsc_submit_request(struct blkvsc_request *blkvsc_req,
++ void (*request_completion)(struct hv_storvsc_request *))
+ {
+ struct block_device_context *blkdev = blkvsc_req->dev;
+- struct device_context *device_ctx=blkdev->device_ctx;
+- struct driver_context *driver_ctx = driver_to_driver_context(device_ctx->device.driver);
+- struct blkvsc_driver_context *blkvsc_drv_ctx = (struct blkvsc_driver_context*)driver_ctx;
+- struct storvsc_driver_object *storvsc_drv_obj = &blkvsc_drv_ctx->drv_obj;
+- int ret =0;
+-
++ struct device_context *device_ctx = blkdev->device_ctx;
++ struct driver_context *driver_ctx =
++ driver_to_driver_context(device_ctx->device.driver);
++ struct blkvsc_driver_context *blkvsc_drv_ctx =
++ (struct blkvsc_driver_context *)driver_ctx;
++ struct storvsc_driver_object *storvsc_drv_obj =
++ &blkvsc_drv_ctx->drv_obj;
+ struct hv_storvsc_request *storvsc_req;
++ int ret;
+
+- DPRINT_DBG(BLKVSC_DRV, "blkvsc_submit_request() - req %p type %s start_sector %lu count %ld offset %d len %d\n",
+- blkvsc_req,
+- (blkvsc_req->write)?"WRITE":"READ",
+- (unsigned long) blkvsc_req->sector_start,
+- blkvsc_req->sector_count,
+- blkvsc_req->request.DataBuffer.Offset,
+- blkvsc_req->request.DataBuffer.Length);
+-
+- /*for (i=0; i < (blkvsc_req->request.DataBuffer.Length >> 12); i++)
+- {
+- DPRINT_DBG(BLKVSC_DRV, "blkvsc_submit_request() - req %p pfn[%d] %llx\n",
+- blkvsc_req,
+- i,
+- blkvsc_req->request.DataBuffer.PfnArray[i]);
+- }*/
++ DPRINT_DBG(BLKVSC_DRV, "blkvsc_submit_request() - "
++ "req %p type %s start_sector %lu count %ld offset %d "
++ "len %d\n", blkvsc_req,
++ (blkvsc_req->write) ? "WRITE" : "READ",
++ (unsigned long) blkvsc_req->sector_start,
++ blkvsc_req->sector_count,
++ blkvsc_req->request.DataBuffer.Offset,
++ blkvsc_req->request.DataBuffer.Length);
++#if 0
++ for (i = 0; i < (blkvsc_req->request.DataBuffer.Length >> 12); i++) {
++ DPRINT_DBG(BLKVSC_DRV, "blkvsc_submit_request() - "
++ "req %p pfn[%d] %llx\n",
++ blkvsc_req, i,
++ blkvsc_req->request.DataBuffer.PfnArray[i]);
++ }
++#endif
+
+ storvsc_req = &blkvsc_req->request;
+- storvsc_req->Extension = (void*)((unsigned long)blkvsc_req + sizeof(struct blkvsc_request));
++ storvsc_req->Extension = (void *)((unsigned long)blkvsc_req +
++ sizeof(struct blkvsc_request));
+
+- storvsc_req->Type = blkvsc_req->write? WRITE_TYPE : READ_TYPE;
++ storvsc_req->Type = blkvsc_req->write ? WRITE_TYPE : READ_TYPE;
+
+ storvsc_req->OnIOCompletion = request_completion;
+ storvsc_req->Context = blkvsc_req;
+@@ -946,47 +911,42 @@ static int blkvsc_submit_request(struct
+ storvsc_req->SenseBuffer = blkvsc_req->sense_buffer;
+ storvsc_req->SenseBufferSize = SCSI_SENSE_BUFFERSIZE;
+
+- ret = storvsc_drv_obj->OnIORequest(&blkdev->device_ctx->device_obj, &blkvsc_req->request);
++ ret = storvsc_drv_obj->OnIORequest(&blkdev->device_ctx->device_obj,
++ &blkvsc_req->request);
+ if (ret == 0)
+- {
+ blkdev->num_outstanding_reqs++;
+- }
+
+ return ret;
+ }
+
+-
+ /*
+ * We break the request into 1 or more blkvsc_requests and submit
+ * them. If we cant submit them all, we put them on the
+ * pending_list. The blkvsc_request() will work on the pending_list.
+ */
+-
+-static int blkvsc_do_request(struct block_device_context *blkdev, struct request *req)
++static int blkvsc_do_request(struct block_device_context *blkdev,
++ struct request *req)
+ {
+- struct bio *bio=NULL;
+- struct bio_vec *bvec=NULL;
+- struct bio_vec *prev_bvec=NULL;
+-
+- struct blkvsc_request *blkvsc_req=NULL;
++ struct bio *bio = NULL;
++ struct bio_vec *bvec = NULL;
++ struct bio_vec *prev_bvec = NULL;
++ struct blkvsc_request *blkvsc_req = NULL;
+ struct blkvsc_request *tmp;
+- int databuf_idx=0;
+- int seg_idx=0;
+-
++ int databuf_idx = 0;
++ int seg_idx = 0;
+ sector_t start_sector;
+ unsigned long num_sectors = 0;
+- int ret=0;
+- int pending=0;
+- struct blkvsc_request_group *group=NULL;
++ int ret = 0;
++ int pending = 0;
++ struct blkvsc_request_group *group = NULL;
+
+- DPRINT_DBG(BLKVSC_DRV, "blkdev %p req %p sect %lu \n", blkdev, req, (unsigned long) blk_rq_pos(req));
++ DPRINT_DBG(BLKVSC_DRV, "blkdev %p req %p sect %lu \n", blkdev, req,
++ (unsigned long)blk_rq_pos(req));
+
+ /* Create a group to tie req to list of blkvsc_reqs */
+- group = (struct blkvsc_request_group*)kmem_cache_alloc(blkdev->request_pool, GFP_ATOMIC);
++ group = kmem_cache_alloc(blkdev->request_pool, GFP_ATOMIC);
+ if (!group)
+- {
+ return -ENOMEM;
+- }
+
+ INIT_LIST_HEAD(&group->blkvsc_req_list);
+ group->outstanding = group->status = 0;
+@@ -994,110 +954,131 @@ static int blkvsc_do_request(struct bloc
+ start_sector = blk_rq_pos(req);
+
+ /* foreach bio in the request */
+- if (req->bio)
+- for (bio = req->bio; bio; bio = bio->bi_next)
+- {
+- /* Map this bio into an existing or new storvsc request */
+- bio_for_each_segment (bvec, bio, seg_idx)
+- {
+- DPRINT_DBG(BLKVSC_DRV, "bio_for_each_segment() - req %p bio %p bvec %p seg_idx %d databuf_idx %d\n",
+- req, bio, bvec, seg_idx, databuf_idx);
+-
+- /* Get a new storvsc request */
+- if ( (!blkvsc_req) || /* 1st-time */
+- (databuf_idx >= MAX_MULTIPAGE_BUFFER_COUNT) ||
+- (bvec->bv_offset != 0) || /* hole at the begin of page */
+- (prev_bvec && (prev_bvec->bv_len != PAGE_SIZE)) ) /* hold at the end of page */
+- {
+- /* submit the prev one */
+- if (blkvsc_req)
+- {
+- blkvsc_req->sector_start = start_sector;
+- sector_div(blkvsc_req->sector_start, (blkdev->sector_size >> 9));
++ if (req->bio) {
++ for (bio = req->bio; bio; bio = bio->bi_next) {
++ /*
++ * Map this bio into an existing or new storvsc request
++ */
++ bio_for_each_segment(bvec, bio, seg_idx) {
++ DPRINT_DBG(BLKVSC_DRV, "bio_for_each_segment() "
++ "- req %p bio %p bvec %p seg_idx %d "
++ "databuf_idx %d\n", req, bio, bvec,
++ seg_idx, databuf_idx);
++
++ /* Get a new storvsc request */
++ /* 1st-time */
++ if ((!blkvsc_req) ||
++ (databuf_idx >= MAX_MULTIPAGE_BUFFER_COUNT)
++ /* hole at the begin of page */
++ || (bvec->bv_offset != 0) ||
++ /* hold at the end of page */
++ (prev_bvec &&
++ (prev_bvec->bv_len != PAGE_SIZE))) {
++ /* submit the prev one */
++ if (blkvsc_req) {
++ blkvsc_req->sector_start = start_sector;
++ sector_div(blkvsc_req->sector_start, (blkdev->sector_size >> 9));
+
+- blkvsc_req->sector_count = num_sectors / (blkdev->sector_size >> 9);
++ blkvsc_req->sector_count = num_sectors / (blkdev->sector_size >> 9);
++ blkvsc_init_rw(blkvsc_req);
++ }
+
+- blkvsc_init_rw(blkvsc_req);
+- }
++ /*
++ * Create new blkvsc_req to represent
++ * the current bvec
++ */
++ blkvsc_req = kmem_cache_alloc(blkdev->request_pool, GFP_ATOMIC);
++ if (!blkvsc_req) {
++ /* free up everything */
++ list_for_each_entry_safe(
++ blkvsc_req, tmp,
++ &group->blkvsc_req_list,
++ req_entry) {
++ list_del(&blkvsc_req->req_entry);
++ kmem_cache_free(blkdev->request_pool, blkvsc_req);
++ }
+
+- /* Create new blkvsc_req to represent the current bvec */
+- blkvsc_req = kmem_cache_alloc(blkdev->request_pool, GFP_ATOMIC);
+- if (!blkvsc_req)
+- {
+- /* free up everything */
+- list_for_each_entry_safe(blkvsc_req, tmp, &group->blkvsc_req_list, req_entry)
+- {
+- list_del(&blkvsc_req->req_entry);
+- kmem_cache_free(blkdev->request_pool, blkvsc_req);
++ kmem_cache_free(blkdev->request_pool, group);
++ return -ENOMEM;
+ }
+
+- kmem_cache_free(blkdev->request_pool, group);
+- return -ENOMEM;
+- }
+-
+- memset(blkvsc_req, 0, sizeof(struct blkvsc_request));
++ memset(blkvsc_req, 0,
++ sizeof(struct blkvsc_request));
+
+- blkvsc_req->dev = blkdev;
+- blkvsc_req->req = req;
+- blkvsc_req->request.DataBuffer.Offset = bvec->bv_offset;
+- blkvsc_req->request.DataBuffer.Length = 0;
+-
+- /* Add to the group */
+- blkvsc_req->group = group;
+- blkvsc_req->group->outstanding++;
+- list_add_tail(&blkvsc_req->req_entry, &blkvsc_req->group->blkvsc_req_list);
+-
+- start_sector += num_sectors;
+- num_sectors = 0;
+- databuf_idx = 0;
+- }
++ blkvsc_req->dev = blkdev;
++ blkvsc_req->req = req;
++ blkvsc_req->request.DataBuffer.Offset = bvec->bv_offset;
++ blkvsc_req->request.DataBuffer.Length = 0;
++
++ /* Add to the group */
++ blkvsc_req->group = group;
++ blkvsc_req->group->outstanding++;
++ list_add_tail(&blkvsc_req->req_entry,
++ &blkvsc_req->group->blkvsc_req_list);
++
++ start_sector += num_sectors;
++ num_sectors = 0;
++ databuf_idx = 0;
++ }
+
+- /* Add the curr bvec/segment to the curr blkvsc_req */
+- blkvsc_req->request.DataBuffer.PfnArray[databuf_idx] = page_to_pfn(bvec->bv_page);
+- blkvsc_req->request.DataBuffer.Length += bvec->bv_len;
++ /* Add the curr bvec/segment to the curr blkvsc_req */
++ blkvsc_req->request.DataBuffer.PfnArray[databuf_idx] = page_to_pfn(bvec->bv_page);
++ blkvsc_req->request.DataBuffer.Length += bvec->bv_len;
+
+- prev_bvec = bvec;
++ prev_bvec = bvec;
+
+- databuf_idx++;
+- num_sectors += bvec->bv_len >> 9;
++ databuf_idx++;
++ num_sectors += bvec->bv_len >> 9;
+
+- } /* bio_for_each_segment */
++ } /* bio_for_each_segment */
+
+- } /* rq_for_each_bio */
++ } /* rq_for_each_bio */
++ }
+
+ /* Handle the last one */
+- if (blkvsc_req)
+- {
+- DPRINT_DBG(BLKVSC_DRV, "blkdev %p req %p group %p count %d\n", blkdev, req, blkvsc_req->group, blkvsc_req->group->outstanding);
++ if (blkvsc_req) {
++ DPRINT_DBG(BLKVSC_DRV, "blkdev %p req %p group %p count %d\n",
++ blkdev, req, blkvsc_req->group,
++ blkvsc_req->group->outstanding);
+
+ blkvsc_req->sector_start = start_sector;
+- sector_div(blkvsc_req->sector_start, (blkdev->sector_size >> 9));
++ sector_div(blkvsc_req->sector_start,
++ (blkdev->sector_size >> 9));
+
+- blkvsc_req->sector_count = num_sectors / (blkdev->sector_size >> 9);
++ blkvsc_req->sector_count = num_sectors /
++ (blkdev->sector_size >> 9);
+
+ blkvsc_init_rw(blkvsc_req);
+ }
+
+- list_for_each_entry(blkvsc_req, &group->blkvsc_req_list, req_entry)
+- {
+- if (pending)
+- {
+- DPRINT_DBG(BLKVSC_DRV, "adding blkvsc_req to pending_list - blkvsc_req %p start_sect %lu sect_count %ld (%lu %ld)\n",
+- blkvsc_req, (unsigned long)blkvsc_req->sector_start, blkvsc_req->sector_count, (unsigned long) start_sector, (unsigned long) num_sectors);
+-
+- list_add_tail(&blkvsc_req->pend_entry, &blkdev->pending_list);
+- }
+- else
+- {
+- ret = blkvsc_submit_request(blkvsc_req, blkvsc_request_completion);
+- if (ret == -1)
+- {
++ list_for_each_entry(blkvsc_req, &group->blkvsc_req_list, req_entry) {
++ if (pending) {
++ DPRINT_DBG(BLKVSC_DRV, "adding blkvsc_req to "
++ "pending_list - blkvsc_req %p start_sect %lu"
++ " sect_count %ld (%lu %ld)\n", blkvsc_req,
++ (unsigned long)blkvsc_req->sector_start,
++ blkvsc_req->sector_count,
++ (unsigned long)start_sector,
++ (unsigned long)num_sectors);
++
++ list_add_tail(&blkvsc_req->pend_entry,
++ &blkdev->pending_list);
++ } else {
++ ret = blkvsc_submit_request(blkvsc_req,
++ blkvsc_request_completion);
++ if (ret == -1) {
+ pending = 1;
+- list_add_tail(&blkvsc_req->pend_entry, &blkdev->pending_list);
++ list_add_tail(&blkvsc_req->pend_entry,
++ &blkdev->pending_list);
+ }
+
+- DPRINT_DBG(BLKVSC_DRV, "submitted blkvsc_req %p start_sect %lu sect_count %ld (%lu %ld) ret %d\n",
+- blkvsc_req, (unsigned long) blkvsc_req->sector_start, blkvsc_req->sector_count, (unsigned long) start_sector, num_sectors, ret);
++ DPRINT_DBG(BLKVSC_DRV, "submitted blkvsc_req %p "
++ "start_sect %lu sect_count %ld (%lu %ld) "
++ "ret %d\n", blkvsc_req,
++ (unsigned long)blkvsc_req->sector_start,
++ blkvsc_req->sector_count,
++ (unsigned long)start_sector,
++ num_sectors, ret);
+ }
+ }
+
+@@ -1106,46 +1087,47 @@ static int blkvsc_do_request(struct bloc
+
+ static void blkvsc_cmd_completion(struct hv_storvsc_request *request)
+ {
+- struct blkvsc_request *blkvsc_req=(struct blkvsc_request*)request->Context;
+- struct block_device_context *blkdev = (struct block_device_context*)blkvsc_req->dev;
+-
++ struct blkvsc_request *blkvsc_req =
++ (struct blkvsc_request *)request->Context;
++ struct block_device_context *blkdev =
++ (struct block_device_context *)blkvsc_req->dev;
+ struct scsi_sense_hdr sense_hdr;
+
+- DPRINT_DBG(BLKVSC_DRV, "blkvsc_cmd_completion() - req %p\n", blkvsc_req);
++ DPRINT_DBG(BLKVSC_DRV, "blkvsc_cmd_completion() - req %p\n",
++ blkvsc_req);
+
+ blkdev->num_outstanding_reqs--;
+
+ if (blkvsc_req->request.Status)
+- {
+- if (scsi_normalize_sense(blkvsc_req->sense_buffer, SCSI_SENSE_BUFFERSIZE, &sense_hdr))
+- {
++ if (scsi_normalize_sense(blkvsc_req->sense_buffer,
++ SCSI_SENSE_BUFFERSIZE, &sense_hdr))
+ scsi_print_sense_hdr("blkvsc", &sense_hdr);
+- }
+- }
+
+- blkvsc_req->cond =1;
++ blkvsc_req->cond = 1;
+ wake_up_interruptible(&blkvsc_req->wevent);
+ }
+
+ static void blkvsc_request_completion(struct hv_storvsc_request *request)
+ {
+- struct blkvsc_request *blkvsc_req=(struct blkvsc_request*)request->Context;
+- struct block_device_context *blkdev = (struct block_device_context*)blkvsc_req->dev;
++ struct blkvsc_request *blkvsc_req =
++ (struct blkvsc_request *)request->Context;
++ struct block_device_context *blkdev =
++ (struct block_device_context *)blkvsc_req->dev;
+ unsigned long flags;
+ struct blkvsc_request *comp_req, *tmp;
+
+ ASSERT(blkvsc_req->group);
+
+- DPRINT_DBG(BLKVSC_DRV, "blkdev %p blkvsc_req %p group %p type %s sect_start %lu sect_count %ld len %d group outstd %d total outstd %d\n",
+- blkdev,
+- blkvsc_req,
+- blkvsc_req->group,
+- (blkvsc_req->write)?"WRITE":"READ",
+- (unsigned long) blkvsc_req->sector_start,
+- blkvsc_req->sector_count,
+- blkvsc_req->request.DataBuffer.Length,
+- blkvsc_req->group->outstanding,
+- blkdev->num_outstanding_reqs);
++ DPRINT_DBG(BLKVSC_DRV, "blkdev %p blkvsc_req %p group %p type %s "
++ "sect_start %lu sect_count %ld len %d group outstd %d "
++ "total outstd %d\n",
++ blkdev, blkvsc_req, blkvsc_req->group,
++ (blkvsc_req->write) ? "WRITE" : "READ",
++ (unsigned long)blkvsc_req->sector_start,
++ blkvsc_req->sector_count,
++ blkvsc_req->request.DataBuffer.Length,
++ blkvsc_req->group->outstanding,
++ blkdev->num_outstanding_reqs);
+
+ spin_lock_irqsave(&blkdev->lock, flags);
+
+@@ -1157,32 +1139,35 @@ static void blkvsc_request_completion(st
+ * completed. This guarantees no out-of-order blkvsc_req
+ * completion when calling end_that_request_first()
+ */
+- if (blkvsc_req->group->outstanding == 0)
+- {
+- list_for_each_entry_safe(comp_req, tmp, &blkvsc_req->group->blkvsc_req_list, req_entry)
+- {
+- DPRINT_DBG(BLKVSC_DRV, "completing blkvsc_req %p sect_start %lu sect_count %ld \n",
+- comp_req,
+- (unsigned long) comp_req->sector_start,
+- comp_req->sector_count);
++ if (blkvsc_req->group->outstanding == 0) {
++ list_for_each_entry_safe(comp_req, tmp,
++ &blkvsc_req->group->blkvsc_req_list,
++ req_entry) {
++ DPRINT_DBG(BLKVSC_DRV, "completing blkvsc_req %p "
++ "sect_start %lu sect_count %ld \n",
++ comp_req,
++ (unsigned long)comp_req->sector_start,
++ comp_req->sector_count);
+
+ list_del(&comp_req->req_entry);
+
+- if (!__blk_end_request(
+- comp_req->req,
+- (!comp_req->request.Status ? 0: -EIO),
+- comp_req->sector_count * blkdev->sector_size))
+- {
+- /* All the sectors have been xferred ie the request is done */
+- DPRINT_DBG(BLKVSC_DRV, "req %p COMPLETED\n", comp_req->req);
+- kmem_cache_free(blkdev->request_pool, comp_req->group);
++ if (!__blk_end_request(comp_req->req,
++ (!comp_req->request.Status ? 0 : -EIO),
++ comp_req->sector_count * blkdev->sector_size)) {
++ /*
++ * All the sectors have been xferred ie the
++ * request is done
++ */
++ DPRINT_DBG(BLKVSC_DRV, "req %p COMPLETED\n",
++ comp_req->req);
++ kmem_cache_free(blkdev->request_pool,
++ comp_req->group);
+ }
+
+ kmem_cache_free(blkdev->request_pool, comp_req);
+ }
+
+- if (!blkdev->shutting_down)
+- {
++ if (!blkdev->shutting_down) {
+ blkvsc_do_pending_reqs(blkdev);
+ blk_start_queue(blkdev->gd->queue);
+ blkvsc_request(blkdev->gd->queue);
+@@ -1197,59 +1182,64 @@ static int blkvsc_cancel_pending_reqs(st
+ struct blkvsc_request *pend_req, *tmp;
+ struct blkvsc_request *comp_req, *tmp2;
+
+- int ret=0;
++ int ret = 0;
+
+ DPRINT_DBG(BLKVSC_DRV, "blkvsc_cancel_pending_reqs()");
+
+ /* Flush the pending list first */
+- list_for_each_entry_safe(pend_req, tmp, &blkdev->pending_list, pend_entry)
+- {
++ list_for_each_entry_safe(pend_req, tmp, &blkdev->pending_list,
++ pend_entry) {
+ /*
+ * The pend_req could be part of a partially completed
+ * request. If so, complete those req first until we
+ * hit the pend_req
+ */
+- list_for_each_entry_safe(comp_req, tmp2, &pend_req->group->blkvsc_req_list, req_entry)
+- {
+- DPRINT_DBG(BLKVSC_DRV, "completing blkvsc_req %p sect_start %lu sect_count %ld \n",
+- comp_req,
+- (unsigned long) comp_req->sector_start,
+- comp_req->sector_count);
++ list_for_each_entry_safe(comp_req, tmp2,
++ &pend_req->group->blkvsc_req_list,
++ req_entry) {
++ DPRINT_DBG(BLKVSC_DRV, "completing blkvsc_req %p "
++ "sect_start %lu sect_count %ld \n",
++ comp_req,
++ (unsigned long) comp_req->sector_start,
++ comp_req->sector_count);
+
+ if (comp_req == pend_req)
+ break;
+
+ list_del(&comp_req->req_entry);
+
+- if (comp_req->req)
+- {
+- ret = __blk_end_request(
+- comp_req->req,
+- (!comp_req->request.Status ? 0 : -EIO),
+- comp_req->sector_count * blkdev->sector_size);
+- ASSERT(ret != 0);
++ if (comp_req->req) {
++ ret = __blk_end_request(comp_req->req,
++ (!comp_req->request.Status ? 0 : -EIO),
++ comp_req->sector_count *
++ blkdev->sector_size);
++ ASSERT(ret != 0);
+ }
+
+ kmem_cache_free(blkdev->request_pool, comp_req);
+ }
+
+- DPRINT_DBG(BLKVSC_DRV, "cancelling pending request - %p\n", pend_req);
++ DPRINT_DBG(BLKVSC_DRV, "cancelling pending request - %p\n",
++ pend_req);
+
+ list_del(&pend_req->pend_entry);
+
+ list_del(&pend_req->req_entry);
+
+- if (comp_req->req)
+- {
+- if (!__blk_end_request(
+- pend_req->req,
+- -EIO,
+- pend_req->sector_count * blkdev->sector_size))
+- {
+- /* All the sectors have been xferred ie the request is done */
+- DPRINT_DBG(BLKVSC_DRV, "blkvsc_cancel_pending_reqs() - req %p COMPLETED\n", pend_req->req);
+- kmem_cache_free(blkdev->request_pool, pend_req->group);
+- }
++ if (comp_req->req) {
++ if (!__blk_end_request(pend_req->req, -EIO,
++ pend_req->sector_count *
++ blkdev->sector_size)) {
++ /*
++ * All the sectors have been xferred ie the
++ * request is done
++ */
++ DPRINT_DBG(BLKVSC_DRV,
++ "blkvsc_cancel_pending_reqs() - "
++ "req %p COMPLETED\n", pend_req->req);
++ kmem_cache_free(blkdev->request_pool,
++ pend_req->group);
++ }
+ }
+
+ kmem_cache_free(blkdev->request_pool, pend_req);
+@@ -1261,22 +1251,20 @@ static int blkvsc_cancel_pending_reqs(st
+ static int blkvsc_do_pending_reqs(struct block_device_context *blkdev)
+ {
+ struct blkvsc_request *pend_req, *tmp;
+- int ret=0;
++ int ret = 0;
+
+ /* Flush the pending list first */
+- list_for_each_entry_safe(pend_req, tmp, &blkdev->pending_list, pend_entry)
+- {
+- DPRINT_DBG(BLKVSC_DRV, "working off pending_list - %p\n", pend_req);
++ list_for_each_entry_safe(pend_req, tmp, &blkdev->pending_list,
++ pend_entry) {
++ DPRINT_DBG(BLKVSC_DRV, "working off pending_list - %p\n",
++ pend_req);
+
+- ret = blkvsc_submit_request(pend_req, blkvsc_request_completion);
++ ret = blkvsc_submit_request(pend_req,
++ blkvsc_request_completion);
+ if (ret != 0)
+- {
+ break;
+- }
+ else
+- {
+ list_del(&pend_req->pend_entry);
+- }
+ }
+
+ return ret;
+@@ -1286,24 +1274,24 @@ static void blkvsc_request(struct reques
+ {
+ struct block_device_context *blkdev = NULL;
+ struct request *req;
+- int ret=0;
++ int ret = 0;
+
+ DPRINT_DBG(BLKVSC_DRV, "- enter \n");
+- while ((req = blk_peek_request(queue)) != NULL)
+- {
++ while ((req = blk_peek_request(queue)) != NULL) {
+ DPRINT_DBG(BLKVSC_DRV, "- req %p\n", req);
+
+ blkdev = req->rq_disk->private_data;
+- if (blkdev->shutting_down || !blk_fs_request(req) || blkdev->media_not_present) {
++ if (blkdev->shutting_down || !blk_fs_request(req) ||
++ blkdev->media_not_present) {
+ __blk_end_request_cur(req, 0);
+ continue;
+ }
+
+ ret = blkvsc_do_pending_reqs(blkdev);
+
+- if (ret != 0)
+- {
+- DPRINT_DBG(BLKVSC_DRV, "- stop queue - pending_list not empty\n");
++ if (ret != 0) {
++ DPRINT_DBG(BLKVSC_DRV,
++ "- stop queue - pending_list not empty\n");
+ blk_stop_queue(queue);
+ break;
+ }
+@@ -1311,14 +1299,11 @@ static void blkvsc_request(struct reques
+ blk_start_request(req);
+
+ ret = blkvsc_do_request(blkdev, req);
+- if (ret > 0)
+- {
++ if (ret > 0) {
+ DPRINT_DBG(BLKVSC_DRV, "- stop queue - no room\n");
+ blk_stop_queue(queue);
+ break;
+- }
+- else if (ret < 0)
+- {
++ } else if (ret < 0) {
+ DPRINT_DBG(BLKVSC_DRV, "- stop queue - no mem\n");
+ blk_requeue_request(queue, req);
+ blk_stop_queue(queue);
+@@ -1327,16 +1312,16 @@ static void blkvsc_request(struct reques
+ }
+ }
+
+-static int blkvsc_open(struct block_device *bdev, fmode_t mode)
++static int blkvsc_open(struct block_device *bdev, fmode_t mode)
+ {
+ struct block_device_context *blkdev = bdev->bd_disk->private_data;
+
+- DPRINT_DBG(BLKVSC_DRV, "- users %d disk %s\n", blkdev->users, blkdev->gd->disk_name);
++ DPRINT_DBG(BLKVSC_DRV, "- users %d disk %s\n", blkdev->users,
++ blkdev->gd->disk_name);
+
+ spin_lock(&blkdev->lock);
+
+- if (!blkdev->users && blkdev->device_type == DVD_TYPE)
+- {
++ if (!blkdev->users && blkdev->device_type == DVD_TYPE) {
+ spin_unlock(&blkdev->lock);
+ check_disk_change(bdev);
+ spin_lock(&blkdev->lock);
+@@ -1352,11 +1337,11 @@ static int blkvsc_release(struct gendisk
+ {
+ struct block_device_context *blkdev = disk->private_data;
+
+- DPRINT_DBG(BLKVSC_DRV, "- users %d disk %s\n", blkdev->users, blkdev->gd->disk_name);
++ DPRINT_DBG(BLKVSC_DRV, "- users %d disk %s\n", blkdev->users,
++ blkdev->gd->disk_name);
+
+ spin_lock(&blkdev->lock);
+- if (blkdev->users == 1)
+- {
++ if (blkdev->users == 1) {
+ spin_unlock(&blkdev->lock);
+ blkvsc_do_flush(blkdev);
+ spin_lock(&blkdev->lock);
+@@ -1371,7 +1356,6 @@ static int blkvsc_release(struct gendisk
+ static int blkvsc_media_changed(struct gendisk *gd)
+ {
+ DPRINT_DBG(BLKVSC_DRV, "- enter\n");
+-
+ return 1;
+ }
+
+@@ -1381,10 +1365,10 @@ static int blkvsc_revalidate_disk(struct
+
+ DPRINT_DBG(BLKVSC_DRV, "- enter\n");
+
+- if (blkdev->device_type == DVD_TYPE)
+- {
++ if (blkdev->device_type == DVD_TYPE) {
+ blkvsc_do_read_capacity(blkdev);
+- set_capacity(blkdev->gd, blkdev->capacity * (blkdev->sector_size/512));
++ set_capacity(blkdev->gd, blkdev->capacity *
++ (blkdev->sector_size/512));
+ blk_queue_logical_block_size(gd->queue, blkdev->sector_size);
+ }
+ return 0;
+@@ -1393,67 +1377,79 @@ static int blkvsc_revalidate_disk(struct
+ static int blkvsc_getgeo(struct block_device *bd, struct hd_geometry *hg)
+ {
+ sector_t total_sectors = get_capacity(bd->bd_disk);
+- sector_t cylinder_times_heads=0;
+- sector_t temp=0;
++ sector_t cylinder_times_heads = 0;
++ sector_t temp = 0;
+
+- int sectors_per_track=0;
+- int heads=0;
+- int cylinders=0;
+- int rem=0;
+-
+- if (total_sectors > (65535 * 16 * 255)) {
+- total_sectors = (65535 * 16 * 255);
+- }
+-
+- if (total_sectors >= (65535 * 16 * 63)) {
+- sectors_per_track = 255;
+- heads = 16;
++ int sectors_per_track = 0;
++ int heads = 0;
++ int cylinders = 0;
++ int rem = 0;
++
++ if (total_sectors > (65535 * 16 * 255))
++ total_sectors = (65535 * 16 * 255);
++
++ if (total_sectors >= (65535 * 16 * 63)) {
++ sectors_per_track = 255;
++ heads = 16;
+
+ cylinder_times_heads = total_sectors;
+- rem = sector_div(cylinder_times_heads, sectors_per_track); /* sector_div stores the quotient in cylinder_times_heads */
+- }
+- else
+- {
+- sectors_per_track = 17;
++ /* sector_div stores the quotient in cylinder_times_heads */
++ rem = sector_div(cylinder_times_heads, sectors_per_track);
++ } else {
++ sectors_per_track = 17;
+
+ cylinder_times_heads = total_sectors;
+- rem = sector_div(cylinder_times_heads, sectors_per_track); /* sector_div stores the quotient in cylinder_times_heads */
++ /* sector_div stores the quotient in cylinder_times_heads */
++ rem = sector_div(cylinder_times_heads, sectors_per_track);
+
+ temp = cylinder_times_heads + 1023;
+- rem = sector_div(temp, 1024); /* sector_div stores the quotient in temp */
++ /* sector_div stores the quotient in temp */
++ rem = sector_div(temp, 1024);
+
+ heads = temp;
+
+- if (heads < 4) {
+- heads = 4;
+- }
++ if (heads < 4)
++ heads = 4;
++
+
+- if (cylinder_times_heads >= (heads * 1024) || (heads > 16)) {
+- sectors_per_track = 31;
+- heads = 16;
++ if (cylinder_times_heads >= (heads * 1024) || (heads > 16)) {
++ sectors_per_track = 31;
++ heads = 16;
+
+ cylinder_times_heads = total_sectors;
+- rem = sector_div(cylinder_times_heads, sectors_per_track); /* sector_div stores the quotient in cylinder_times_heads */
+- }
++ /*
++ * sector_div stores the quotient in
++ * cylinder_times_heads
++ */
++ rem = sector_div(cylinder_times_heads,
++ sectors_per_track);
++ }
+
+- if (cylinder_times_heads >= (heads * 1024)) {
+- sectors_per_track = 63;
+- heads = 16;
++ if (cylinder_times_heads >= (heads * 1024)) {
++ sectors_per_track = 63;
++ heads = 16;
+
+ cylinder_times_heads = total_sectors;
+- rem = sector_div(cylinder_times_heads, sectors_per_track); /* sector_div stores the quotient in cylinder_times_heads */
++ /*
++ * sector_div stores the quotient in
++ * cylinder_times_heads
++ */
++ rem = sector_div(cylinder_times_heads,
++ sectors_per_track);
++ }
+ }
+- }
+
+ temp = cylinder_times_heads;
+- rem = sector_div(temp, heads); /* sector_div stores the quotient in temp */
++ /* sector_div stores the quotient in temp */
++ rem = sector_div(temp, heads);
+ cylinders = temp;
+
+ hg->heads = heads;
+- hg->sectors = sectors_per_track;
+- hg->cylinders = cylinders;
++ hg->sectors = sectors_per_track;
++ hg->cylinders = cylinders;
+
+- DPRINT_INFO(BLKVSC_DRV, "CHS (%d, %d, %d)", cylinders, heads, sectors_per_track);
++ DPRINT_INFO(BLKVSC_DRV, "CHS (%d, %d, %d)", cylinders, heads,
++ sectors_per_track);
+
+ return 0;
+ }
+@@ -1462,21 +1458,21 @@ static int blkvsc_ioctl(struct block_dev
+ unsigned cmd, unsigned long argument)
+ {
+ /* struct block_device_context *blkdev = bd->bd_disk->private_data; */
+- int ret=0;
++ int ret;
+
+- switch (cmd)
+- {
+- /* TODO: I think there is certain format for HDIO_GET_IDENTITY rather than just */
+- /* a GUID. Commented it out for now. */
+- /*case HDIO_GET_IDENTITY:
++ switch (cmd) {
++ /*
++ * TODO: I think there is certain format for HDIO_GET_IDENTITY rather
++ * than just a GUID. Commented it out for now.
++ */
++#if 0
++ case HDIO_GET_IDENTITY:
+ DPRINT_INFO(BLKVSC_DRV, "HDIO_GET_IDENTITY\n");
+-
+- if (copy_to_user((void __user *)arg, blkdev->device_id, blkdev->device_id_len))
+- {
++ if (copy_to_user((void __user *)arg, blkdev->device_id,
++ blkdev->device_id_len))
+ ret = -EFAULT;
+- }
+-
+- break;*/
++ break;
++#endif
+ default:
+ ret = -EINVAL;
+ break;
+@@ -1485,9 +1481,6 @@ static int blkvsc_ioctl(struct block_dev
+ return ret;
+ }
+
+-
+-MODULE_LICENSE("GPL");
+-
+ static int __init blkvsc_init(void)
+ {
+ int ret;
+@@ -1508,15 +1501,11 @@ static int __init blkvsc_init(void)
+ static void __exit blkvsc_exit(void)
+ {
+ DPRINT_ENTER(BLKVSC_DRV);
+-
+ blkvsc_drv_exit();
+-
+ DPRINT_ENTER(BLKVSC_DRV);
+ }
+
++MODULE_LICENSE("GPL");
+ module_param(blkvsc_ringbuffer_size, int, S_IRUGO);
+-
+ module_init(blkvsc_init);
+ module_exit(blkvsc_exit);
+-
+-/* eof */
diff --git a/staging/staging-hv-warn-the-world-of-a-bug-in-the-release-function.patch b/staging/staging-hv-warn-the-world-of-a-bug-in-the-release-function.patch
new file mode 100644
index 00000000000000..3c05bf5b6caac0
--- /dev/null
+++ b/staging/staging-hv-warn-the-world-of-a-bug-in-the-release-function.patch
@@ -0,0 +1,33 @@
+From foo@baz Tue Sep 1 20:12:58 PDT 2009
+Date: Tue, 01 Sep 2009 20:12:58 -0700
+To: Greg KH <greg@kroah.com>
+From: Greg Kroah-Hartman <gregkh@suse.de>
+Subject: Staging: hv: warn the world of a bug in the release function
+
+All device release functions need to do something, if not, it's a bug.
+By merely providing an "empty" release function, it gets the kernel to
+shut up, but that's not solving the problem at all. Stick a big fat
+WARN_ON(1); in there to get people's attention.
+
+
+Cc: Hank Janssen <hjanssen@microsoft.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
+
+---
+ drivers/staging/hv/vmbus_drv.c | 5 +++++
+ 1 file changed, 5 insertions(+)
+
+--- a/drivers/staging/hv/vmbus_drv.c
++++ b/drivers/staging/hv/vmbus_drv.c
+@@ -965,6 +965,11 @@ Desc: Final callback release of the vmbu
+ static void vmbus_bus_release(struct device *device)
+ {
+ DPRINT_ENTER(VMBUS_DRV);
++ /* FIXME */
++ /* Empty release functions are a bug, or a major sign
++ * of a problem design, this MUST BE FIXED! */
++ dev_err(device, "%s needs to be fixed!\n", __func__);
++ WARN_ON(1);
+ DPRINT_EXIT(VMBUS_DRV);
+ }
+