Staging: hv: move StorVscApi.h
[safe/jmp/linux-2.6] / drivers / staging / hv / blkvsc_drv.c
index 2f67981..9e0dbd5 100644 (file)
@@ -20,7 +20,6 @@
  *
  */
 
-
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/device.h>
 #include <scsi/scsi_eh.h>
 #include <scsi/scsi_dbg.h>
 
+#include "osd.h"
 #include "logging.h"
 #include "vmbus.h"
-
 #include "StorVscApi.h"
 
-//
-// #defines
-//
+
+/* #defines */
+
 #define BLKVSC_MINORS  64
 
-//
-// Data types
-//
+
+/* Data types */
+
 enum blkvsc_device_type {
        UNKNOWN_DEV_TYPE,
        HARDDISK_TYPE,
        DVD_TYPE,
 };
 
-// This request ties the struct request and struct blkvsc_request/STORVSC_REQUEST together
-// A struct request may be represented by 1 or more struct blkvsc_request
+/*
+ * This request ties the struct request and struct
+ * blkvsc_request/hv_storvsc_request together A struct request may be
+ * 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
+       struct list_head        blkvsc_req_list;        /* list of blkvsc_requests */
 };
 
 
 struct blkvsc_request {
-       struct list_head        req_entry;                      // blkvsc_request_group.blkvsc_req_list
+       struct list_head        req_entry;                      /* blkvsc_request_group.blkvsc_req_list */
 
-       struct list_head        pend_entry;                     // block_device_context.pending_list
+       struct list_head        pend_entry;                     /* block_device_context.pending_list */
 
-       struct request          *req;                           // This may be null if we generate a request internally
+       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
+       struct blkvsc_request_group     *group;         /* The group this request is part of. Maybe null */
 
        wait_queue_head_t       wevent;
        int cond;
@@ -83,14 +85,14 @@ struct blkvsc_request {
        unsigned char cmd_len;
        unsigned char cmnd[MAX_COMMAND_SIZE];
 
-       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;
+       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; */
 };
 
-// Per device structure
+/* Per device structure */
 struct block_device_context {
-       struct device_context   *device_ctx; // point back to our device context
+       struct device_context   *device_ctx; /* point back to our device context */
        struct kmem_cache       *request_pool;
        spinlock_t                              lock;
        struct gendisk                  *gd;
@@ -110,31 +112,31 @@ struct block_device_context {
        int                                             users;
 };
 
-// Per driver
+/* Per driver */
 struct blkvsc_driver_context {
-       // !! These must be the first 2 fields !!
+       /* !! These must be the first 2 fields !! */
        struct driver_context   drv_ctx;
-       STORVSC_DRIVER_OBJECT   drv_obj;
+       struct storvsc_driver_object drv_obj;
 };
 
-// Static decl
+/* Static decl */
 static int blkvsc_probe(struct device *dev);
 static int blkvsc_remove(struct device *device);
 static void blkvsc_shutdown(struct device *device);
 
-static int blkvsc_open(struct inode *inode, struct file *filep);
-static int blkvsc_release(struct inode *inode, struct file *filep);
+static int blkvsc_open(struct block_device *bdev,  fmode_t mode);
+static int blkvsc_release(struct gendisk *disk, fmode_t mode);
 static int blkvsc_media_changed(struct gendisk *gd);
 static int blkvsc_revalidate_disk(struct gendisk *gd);
 static int blkvsc_getgeo(struct block_device *bd, struct hd_geometry *hg);
-static int blkvsc_ioctl(struct inode *inode, struct file *filep, unsigned cmd, unsigned long arg);
-
+static int blkvsc_ioctl(struct block_device *bd, fmode_t mode,
+                       unsigned cmd, unsigned long argument);
 static void blkvsc_request(struct request_queue *queue);
-static void blkvsc_request_completion(STORVSC_REQUEST* request);
+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)(STORVSC_REQUEST*) );
+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(STORVSC_REQUEST* request);
+static void blkvsc_cmd_completion(struct hv_storvsc_request *request);
 static int blkvsc_do_inquiry(struct block_device_context *blkdev);
 static int blkvsc_do_read_capacity(struct block_device_context *blkdev);
 static int blkvsc_do_read_capacity16(struct block_device_context *blkdev);
@@ -145,7 +147,7 @@ static int blkvsc_do_pending_reqs(struct block_device_context *blkdev);
 
 static int blkvsc_ringbuffer_size = BLKVSC_RING_BUFFER_SIZE;
 
-// The one and only one
+/* The one and only one */
 static struct blkvsc_driver_context g_blkvsc_drv;
 
 
@@ -167,10 +169,10 @@ Name:     blkvsc_drv_init()
 Desc:  BlkVsc driver initialization.
 
 --*/
-int blkvsc_drv_init(PFN_DRIVERINITIALIZE pfn_drv_init)
+static int blkvsc_drv_init(PFN_DRIVERINITIALIZE pfn_drv_init)
 {
        int ret=0;
-       STORVSC_DRIVER_OBJECT *storvsc_drv_obj=&g_blkvsc_drv.drv_obj;
+       struct storvsc_driver_object *storvsc_drv_obj = &g_blkvsc_drv.drv_obj;
        struct driver_context *drv_ctx=&g_blkvsc_drv.drv_ctx;
 
        DPRINT_ENTER(BLKVSC_DRV);
@@ -179,23 +181,18 @@ int blkvsc_drv_init(PFN_DRIVERINITIALIZE pfn_drv_init)
 
        storvsc_drv_obj->RingBufferSize = blkvsc_ringbuffer_size;
 
-       // Callback to client driver to complete the initialization
+       /* Callback to client driver to complete the initialization */
        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(GUID));
+       memcpy(&drv_ctx->class_id, &storvsc_drv_obj->Base.deviceType, sizeof(struct hv_guid));
 
-#if defined(KERNEL_2_6_5) || defined(KERNEL_2_6_9)
-       drv_ctx->driver.probe = blkvsc_probe;
-       drv_ctx->driver.remove = blkvsc_remove;
-#else
        drv_ctx->probe = blkvsc_probe;
        drv_ctx->remove = blkvsc_remove;
        drv_ctx->shutdown = blkvsc_shutdown;
-#endif
 
-       // The driver belongs to vmbus
-       vmbus_child_driver_register(drv_ctx);
+       /* The driver belongs to vmbus */
+       ret = vmbus_child_driver_register(drv_ctx);
 
        DPRINT_EXIT(BLKVSC_DRV);
 
@@ -207,7 +204,7 @@ static int blkvsc_drv_exit_cb(struct device *dev, void *data)
 {
        struct device **curr = (struct device **)data;
        *curr = dev;
-       return 1; // stop iterating
+       return 1; /* stop iterating */
 }
 
 /*++
@@ -217,22 +214,12 @@ Name:     blkvsc_drv_exit()
 Desc:
 
 --*/
-void blkvsc_drv_exit(void)
+static void blkvsc_drv_exit(void)
 {
-       STORVSC_DRIVER_OBJECT *storvsc_drv_obj=&g_blkvsc_drv.drv_obj;
+       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;
-
-#if defined(KERNEL_2_6_5) || defined(KERNEL_2_6_9)
-#define driver_for_each_device(drv, start, data, fn) \
-       struct list_head *ptr, *n; \
-       list_for_each_safe(ptr, n, &((drv)->devices)) {\
-               struct device *curr_dev;\
-               curr_dev = list_entry(ptr, struct device, driver_list);\
-               fn(curr_dev, data);\
-       }
-#endif // KERNEL_2_6_9
+       int ret;
 
        DPRINT_ENTER(BLKVSC_DRV);
 
@@ -240,13 +227,20 @@ void blkvsc_drv_exit(void)
        {
                current_dev = NULL;
 
-               // Get the device
-               driver_for_each_device(&drv_ctx->driver, NULL, (void*)&current_dev, blkvsc_drv_exit_cb);
+               /* Get the device */
+               ret = driver_for_each_device(&drv_ctx->driver, NULL,
+                                            (void *) &current_dev,
+                                            blkvsc_drv_exit_cb);
+
+               if (ret)
+                       DPRINT_WARN(BLKVSC_DRV,
+                                   "driver_for_each_device returned %d", ret);
+
 
                if (current_dev == NULL)
                        break;
 
-               // Initiate removal from the top-down
+               /* Initiate removal from the top-down */
                device_unregister(current_dev);
        }
 
@@ -273,13 +267,13 @@ static int blkvsc_probe(struct device *device)
 
        struct driver_context *driver_ctx = driver_to_driver_context(device->driver);
        struct blkvsc_driver_context *blkvsc_drv_ctx = (struct blkvsc_driver_context*)driver_ctx;
-       STORVSC_DRIVER_OBJECT* storvsc_drv_obj = &blkvsc_drv_ctx->drv_obj;
+       struct storvsc_driver_object *storvsc_drv_obj = &blkvsc_drv_ctx->drv_obj;
 
        struct device_context *device_ctx = device_to_device_context(device);
-       DEVICE_OBJECT* device_obj = &device_ctx->device_obj;
+       struct hv_device *device_obj = &device_ctx->device_obj;
 
        struct block_device_context *blkdev=NULL;
-       STORVSC_DEVICE_INFO device_info;
+       struct storvsc_device_info device_info;
        int major=0;
        int devnum=0;
 
@@ -307,20 +301,14 @@ static int blkvsc_probe(struct device *device)
 
        INIT_LIST_HEAD(&blkdev->pending_list);
 
-       // Initialize what we can here
+       /* Initialize what we can here */
        spin_lock_init(&blkdev->lock);
 
        ASSERT(sizeof(struct blkvsc_request_group) <= sizeof(struct blkvsc_request));
 
-#ifdef KERNEL_2_6_27
-        blkdev->request_pool = kmem_cache_create(device_ctx->device.bus_id,
-                sizeof(struct blkvsc_request) + storvsc_drv_obj->RequestExtSize, 0,
-                SLAB_HWCACHE_ALIGN, NULL);
-#else
-       blkdev->request_pool = kmem_cache_create(device_ctx->device.bus_id,
+       blkdev->request_pool = kmem_cache_create(dev_name(&device_ctx->device),
                sizeof(struct blkvsc_request) + storvsc_drv_obj->RequestExtSize, 0,
-               SLAB_HWCACHE_ALIGN, NULL, NULL);
-#endif
+               SLAB_HWCACHE_ALIGN, NULL);
        if (!blkdev->request_pool)
        {
                ret = -ENOMEM;
@@ -328,7 +316,7 @@ static int blkvsc_probe(struct device *device)
        }
 
 
-       // Call to the vsc driver to add the device
+       /* Call to the vsc driver to add the device */
        ret = storvsc_drv_obj->Base.OnDeviceAdd(device_obj, &device_info);
        if (ret != 0)
        {
@@ -337,16 +325,16 @@ static int blkvsc_probe(struct device *device)
        }
 
        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
+       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 */
 
-       device->driver_data = blkdev;
+       dev_set_drvdata(device, blkdev);
 
-       // Calculate the major and device num
+       /* Calculate the major and device num */
        if (blkdev->path == 0)
        {
                major = IDE0_MAJOR;
-               devnum = blkdev->path + blkdev->target;         // 0 or 1
+               devnum = blkdev->path + blkdev->target;         /* 0 or 1 */
 
                if (!ide0_registered)
                {
@@ -363,7 +351,7 @@ static int blkvsc_probe(struct device *device)
        else if (blkdev->path == 1)
        {
                major = IDE1_MAJOR;
-               devnum = blkdev->path + blkdev->target + 1; // 2 or 3
+               devnum = blkdev->path + blkdev->target + 1; /* 2 or 3 */
 
                if (!ide1_registered)
                {
@@ -426,11 +414,11 @@ static int blkvsc_probe(struct device *device)
        }
 
        set_capacity(blkdev->gd, blkdev->capacity * (blkdev->sector_size/512));
-       blk_queue_hardsect_size(blkdev->gd->queue, blkdev->sector_size);
-       // go!
+       blk_queue_logical_block_size(blkdev->gd->queue, blkdev->sector_size);
+       /* go! */
        add_disk(blkdev->gd);
 
-       DPRINT_INFO(BLKVSC_DRV, "%s added!! capacity %llu sector_size %d", blkdev->gd->disk_name, 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;
 
@@ -456,7 +444,7 @@ Cleanup:
 
 static void blkvsc_shutdown(struct device *device)
 {
-       struct block_device_context *blkdev = (struct block_device_context*)device->driver_data;
+       struct block_device_context *blkdev = dev_get_drvdata(device);
        unsigned long flags;
 
        if (!blkdev)
@@ -516,7 +504,7 @@ static int blkvsc_do_flush(struct block_device_context *blkdev)
        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
+       /* 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);
 
@@ -527,7 +515,7 @@ static int blkvsc_do_flush(struct block_device_context *blkdev)
        return 0;
 }
 
-// Do a scsi INQUIRY cmd here to get the device type (ie disk or dvd)
+/* 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;
@@ -561,12 +549,12 @@ static int blkvsc_do_inquiry(struct block_device_context *blkdev)
        blkvsc_req->request.DataBuffer.Length = 64;
 
        blkvsc_req->cmnd[0] = INQUIRY;
-       blkvsc_req->cmnd[1] = 0x1;              // Get product data
-       blkvsc_req->cmnd[2] = 0x83;             // mode page 83
+       blkvsc_req->cmnd[1] = 0x1;              /* Get product data */
+       blkvsc_req->cmnd[2] = 0x83;             /* mode page 83 */
        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
+       /* 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);
@@ -577,8 +565,8 @@ static int blkvsc_do_inquiry(struct block_device_context *blkdev)
 
        buf = kmap(page_buf);
 
-       //PrintBytes(buf, 64);
-       // be to le
+       /* print_hex_dump_bytes("", DUMP_PREFIX_NONE, buf, 64); */
+       /* be to le */
        device_type = buf[0] & 0x1F;
 
        if (device_type == 0x0)
@@ -591,7 +579,7 @@ static int blkvsc_do_inquiry(struct block_device_context *blkdev)
        }
        else
        {
-               // TODO: this is currently unsupported device type
+               /* TODO: this is currently unsupported device type */
                blkdev->device_type = UNKNOWN_DEV_TYPE;
        }
 
@@ -602,7 +590,8 @@ static int blkvsc_do_inquiry(struct block_device_context *blkdev)
                blkdev->device_id_len = 64;
 
        memcpy(blkdev->device_id, &buf[8], blkdev->device_id_len);
-       //PrintBytes(blkdev->device_id, blkdev->device_id_len);
+       /* printk_hex_dump_bytes("", DUMP_PREFIX_NONE, blkdev->device_id,
+        * blkdev->device_id_len); */
 
        kunmap(page_buf);
 
@@ -613,7 +602,7 @@ static int blkvsc_do_inquiry(struct block_device_context *blkdev)
        return 0;
 }
 
-// Do a scsi READ_CAPACITY cmd here to get the size of the disk
+/* 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;
@@ -625,7 +614,7 @@ static int blkvsc_do_read_capacity(struct block_device_context *blkdev)
 
        blkdev->sector_size = 0;
        blkdev->capacity = 0;
-       blkdev->media_not_present = 0; // assume a disk is present
+       blkdev->media_not_present = 0; /* assume a disk is present */
 
        blkvsc_req = kmem_cache_alloc(blkdev->request_pool, GFP_KERNEL);
        if (!blkvsc_req)
@@ -653,7 +642,10 @@ static int blkvsc_do_read_capacity(struct block_device_context *blkdev)
        blkvsc_req->cmnd[0] = READ_CAPACITY;
        blkvsc_req->cmd_len = 16;
 
-       // Set this here since the completion routine may be invoked and completed before we return
+       /*
+        * 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);
@@ -662,12 +654,12 @@ static int blkvsc_do_read_capacity(struct block_device_context *blkdev)
 
        wait_event_interruptible(blkvsc_req->wevent, blkvsc_req->cond);
 
-       // check error
+       /* 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 (sense_hdr.asc == 0x3A) /* Medium not present */
                {
                        blkdev->media_not_present = 1;
                }
@@ -676,7 +668,7 @@ static int blkvsc_do_read_capacity(struct block_device_context *blkdev)
        }
        buf = kmap(page_buf);
 
-       // be to le
+       /* 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];
 
@@ -701,7 +693,7 @@ static int blkvsc_do_read_capacity16(struct block_device_context *blkdev)
 
        blkdev->sector_size = 0;
        blkdev->capacity = 0;
-       blkdev->media_not_present = 0; // assume a disk is present
+       blkdev->media_not_present = 0; /* assume a disk is present */
 
        blkvsc_req = kmem_cache_alloc(blkdev->request_pool, GFP_KERNEL);
        if (!blkvsc_req)
@@ -726,10 +718,13 @@ static int blkvsc_do_read_capacity16(struct block_device_context *blkdev)
        blkvsc_req->request.DataBuffer.Offset = 0;
        blkvsc_req->request.DataBuffer.Length = 12;
 
-       blkvsc_req->cmnd[0] = 0x9E; //READ_CAPACITY16;
+       blkvsc_req->cmnd[0] = 0x9E; /* READ_CAPACITY16; */
        blkvsc_req->cmd_len = 16;
 
-       // Set this here since the completion routine may be invoked and completed before we return
+       /*
+        * 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);
@@ -738,12 +733,12 @@ static int blkvsc_do_read_capacity16(struct block_device_context *blkdev)
 
        wait_event_interruptible(blkvsc_req->wevent, blkvsc_req->cond);
 
-       // check error
+       /* 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 (sense_hdr.asc == 0x3A) /* Medium not present */
                {
                        blkdev->media_not_present = 1;
                }
@@ -752,12 +747,12 @@ static int blkvsc_do_read_capacity16(struct block_device_context *blkdev)
        }
        buf = kmap(page_buf);
 
-       // be to le
+       /* 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 = ((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);
 
@@ -781,11 +776,11 @@ static int blkvsc_remove(struct device *device)
 
        struct driver_context *driver_ctx = driver_to_driver_context(device->driver);
        struct blkvsc_driver_context *blkvsc_drv_ctx = (struct blkvsc_driver_context*)driver_ctx;
-       STORVSC_DRIVER_OBJECT* storvsc_drv_obj = &blkvsc_drv_ctx->drv_obj;
+       struct storvsc_driver_object *storvsc_drv_obj = &blkvsc_drv_ctx->drv_obj;
 
        struct device_context *device_ctx = device_to_device_context(device);
-       DEVICE_OBJECT* device_obj = &device_ctx->device_obj;
-       struct block_device_context *blkdev = (struct block_device_context*)device->driver_data;
+       struct hv_device *device_obj = &device_ctx->device_obj;
+       struct block_device_context *blkdev = dev_get_drvdata(device);
        unsigned long flags;
 
        DPRINT_ENTER(BLKVSC_DRV);
@@ -798,15 +793,15 @@ static int blkvsc_remove(struct device *device)
                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)
        {
-               // TODO:
+               /* TODO: */
                DPRINT_ERR(BLKVSC_DRV, "unable to remove blkvsc device (ret %d)", ret);
        }
 
-       // Get to a known state
+       /* Get to a known state */
        spin_lock_irqsave(&blkdev->lock, flags);
 
        blkdev->shutting_down = 1;
@@ -905,21 +900,21 @@ static void blkvsc_init_rw(struct blkvsc_request *blkvsc_req)
        }
 }
 
-static int blkvsc_submit_request(struct blkvsc_request *blkvsc_req, void (*request_completion)(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;
-       STORVSC_DRIVER_OBJECT* storvsc_drv_obj = &blkvsc_drv_ctx->drv_obj;
+       struct storvsc_driver_object *storvsc_drv_obj = &blkvsc_drv_ctx->drv_obj;
        int ret =0;
 
-       STORVSC_REQUEST *storvsc_req;
+       struct hv_storvsc_request *storvsc_req;
 
-       DPRINT_DBG(BLKVSC_DRV, "blkvsc_submit_request() - req %p type %s start_sector %llu count %d offset %d len %d\n",
+       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",
-               blkvsc_req->sector_start,
+               (unsigned long) blkvsc_req->sector_start,
                blkvsc_req->sector_count,
                blkvsc_req->request.DataBuffer.Offset,
                blkvsc_req->request.DataBuffer.Length);
@@ -943,7 +938,7 @@ static int blkvsc_submit_request(struct blkvsc_request *blkvsc_req, void (*reque
        storvsc_req->Host = blkdev->port;
        storvsc_req->Bus = blkdev->path;
        storvsc_req->TargetId = blkdev->target;
-       storvsc_req->LunId = 0;  // this is not really used at all
+       storvsc_req->LunId = 0;  /* this is not really used at all */
 
        storvsc_req->CdbLen = blkvsc_req->cmd_len;
        storvsc_req->Cdb = blkvsc_req->cmnd;
@@ -960,11 +955,13 @@ static int blkvsc_submit_request(struct blkvsc_request *blkvsc_req, void (*reque
        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.
-//
+
+/*
+ * 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)
 {
        struct bio *bio=NULL;
@@ -982,9 +979,9 @@ static int blkvsc_do_request(struct block_device_context *blkdev, struct request
        int pending=0;
        struct blkvsc_request_group *group=NULL;
 
-       DPRINT_DBG(BLKVSC_DRV, "blkdev %p req %p sect %llu \n", blkdev, req, req->sector);
+       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
+       /* Create a group to tie req to list of blkvsc_reqs */
        group = (struct blkvsc_request_group*)kmem_cache_alloc(blkdev->request_pool, GFP_ATOMIC);
        if (!group)
        {
@@ -994,25 +991,25 @@ static int blkvsc_do_request(struct block_device_context *blkdev, struct request
        INIT_LIST_HEAD(&group->blkvsc_req_list);
        group->outstanding = group->status = 0;
 
-       start_sector = req->sector;
+       start_sector = blk_rq_pos(req);
 
-       // foreach bio in the request
+       /* 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
+               /* 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
+                       /* 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
+                                (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
+                               /* submit the prev one */
                                if (blkvsc_req)
                                {
                                        blkvsc_req->sector_start = start_sector;
@@ -1023,11 +1020,11 @@ static int blkvsc_do_request(struct block_device_context *blkdev, struct request
                                        blkvsc_init_rw(blkvsc_req);
                                }
 
-                               // Create new blkvsc_req to represent the current bvec
+                               /* 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
+                                       /* free up everything */
                                        list_for_each_entry_safe(blkvsc_req, tmp, &group->blkvsc_req_list, req_entry)
                                        {
                                                list_del(&blkvsc_req->req_entry);
@@ -1045,7 +1042,7 @@ static int blkvsc_do_request(struct block_device_context *blkdev, struct request
                                blkvsc_req->request.DataBuffer.Offset = bvec->bv_offset;
                                blkvsc_req->request.DataBuffer.Length = 0;
 
-                               // Add to the group
+                               /* 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);
@@ -1055,7 +1052,7 @@ static int blkvsc_do_request(struct block_device_context *blkdev, struct request
                                databuf_idx = 0;
                        }
 
-                       // Add the curr bvec/segment to the curr blkvsc_req
+                       /* 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;
 
@@ -1064,11 +1061,11 @@ static int blkvsc_do_request(struct block_device_context *blkdev, struct request
                        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
+       /* 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);
@@ -1085,8 +1082,8 @@ static int blkvsc_do_request(struct block_device_context *blkdev, struct request
        {
                if (pending)
                {
-                       DPRINT_DBG(BLKVSC_DRV, "adding blkvsc_req to pending_list - blkvsc_req %p start_sect %llu sect_count %d (%llu %d)\n",
-                               blkvsc_req, blkvsc_req->sector_start, blkvsc_req->sector_count, start_sector, num_sectors);
+                       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);
                }
@@ -1099,15 +1096,15 @@ static int blkvsc_do_request(struct block_device_context *blkdev, struct request
                                list_add_tail(&blkvsc_req->pend_entry, &blkdev->pending_list);
                        }
 
-                       DPRINT_DBG(BLKVSC_DRV, "submitted blkvsc_req %p start_sect %llu sect_count %d (%llu %d) ret %d\n",
-                               blkvsc_req, blkvsc_req->sector_start, blkvsc_req->sector_count, 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);
                }
        }
 
        return pending;
 }
 
-static void blkvsc_cmd_completion(STORVSC_REQUEST* request)
+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;
@@ -1130,7 +1127,7 @@ static void blkvsc_cmd_completion(STORVSC_REQUEST* request)
        wake_up_interruptible(&blkvsc_req->wevent);
 }
 
-static void blkvsc_request_completion(STORVSC_REQUEST* request)
+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;
@@ -1139,12 +1136,12 @@ static void blkvsc_request_completion(STORVSC_REQUEST* request)
 
        ASSERT(blkvsc_req->group);
 
-       DPRINT_DBG(BLKVSC_DRV, "blkdev %p blkvsc_req %p group %p type %s sect_start %llu sect_count %d len %d group outstd %d total outstd %d\n",
+       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",
-               blkvsc_req->sector_start,
+               (unsigned long) blkvsc_req->sector_start,
                blkvsc_req->sector_count,
                blkvsc_req->request.DataBuffer.Length,
                blkvsc_req->group->outstanding,
@@ -1155,40 +1152,31 @@ static void blkvsc_request_completion(STORVSC_REQUEST* request)
        blkdev->num_outstanding_reqs--;
        blkvsc_req->group->outstanding--;
 
-       // Only start processing when all the blkvsc_reqs are completed. This guarantees no out-of-order
-       // blkvsc_req completion when calling end_that_request_first()
+       /*
+        * Only start processing when all the blkvsc_reqs are
+        * 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 %llu sect_count %d \n",
+                       DPRINT_DBG(BLKVSC_DRV, "completing blkvsc_req %p sect_start %lu sect_count %ld \n",
                                comp_req,
-                               comp_req->sector_start,
+                               (unsigned long) comp_req->sector_start,
                                comp_req->sector_count);
 
                        list_del(&comp_req->req_entry);
 
-#ifdef KERNEL_2_6_27
                        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
+                               /* 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);
                        }
-#else
-                       if (!end_that_request_first(comp_req->req, !comp_req->request.Status,  (comp_req->sector_count * (blkdev->sector_size >> 9))))
-                       {
-                               //All the sectors have been xferred ie the request is done
-                               DPRINT_DBG(BLKVSC_DRV, "req %p COMPLETED\n", comp_req->req);
-
-                               end_that_request_last(comp_req->req, !comp_req->request.Status);
-
-                               kmem_cache_free(blkdev->request_pool, comp_req->group);
-                       }
-#endif
 
                        kmem_cache_free(blkdev->request_pool, comp_req);
                }
@@ -1213,16 +1201,19 @@ static int blkvsc_cancel_pending_reqs(struct block_device_context *blkdev)
 
        DPRINT_DBG(BLKVSC_DRV, "blkvsc_cancel_pending_reqs()");
 
-       // Flush the pending list first
+       /* Flush the pending list first */
        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
+               /*
+                * 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 %llu sect_count %d \n",
+                       DPRINT_DBG(BLKVSC_DRV, "completing blkvsc_req %p sect_start %lu sect_count %ld \n",
                                comp_req,
-                               comp_req->sector_start,
+                               (unsigned long) comp_req->sector_start,
                                comp_req->sector_count);
 
                        if (comp_req == pend_req)
@@ -1232,14 +1223,10 @@ static int blkvsc_cancel_pending_reqs(struct block_device_context *blkdev)
 
                        if (comp_req->req)
                        {
-#ifdef KERNEL_2_6_27
                        ret = __blk_end_request(
                            comp_req->req,
                            (!comp_req->request.Status ? 0 : -EIO),
                            comp_req->sector_count * blkdev->sector_size);
-#else
-                       ret = end_that_request_first(comp_req->req, !comp_req->request.Status,  (comp_req->sector_count * (blkdev->sector_size >> 9)));
-#endif
                        ASSERT(ret != 0);
                        }
 
@@ -1254,27 +1241,15 @@ static int blkvsc_cancel_pending_reqs(struct block_device_context *blkdev)
 
                if (comp_req->req)
                {
-#ifdef KERNEL_2_6_27
                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
+                       /* 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);
                }
-#else
-               if (!end_that_request_first(pend_req->req, 0,  (pend_req->sector_count * (blkdev->sector_size >> 9))))
-               {
-                       //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);
-
-                       end_that_request_last(pend_req->req, 0);
-
-                       kmem_cache_free(blkdev->request_pool, pend_req->group);
-               }
-#endif
                }
 
                kmem_cache_free(blkdev->request_pool, pend_req);
@@ -1288,7 +1263,7 @@ static int blkvsc_do_pending_reqs(struct block_device_context *blkdev)
        struct blkvsc_request *pend_req, *tmp;
        int ret=0;
 
-       // Flush the pending list first
+       /* 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);
@@ -1314,13 +1289,13 @@ static void blkvsc_request(struct request_queue *queue)
        int ret=0;
 
        DPRINT_DBG(BLKVSC_DRV, "- enter \n");
-       while ((req = elv_next_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) {
-                       end_request(req, 0);
+                       __blk_end_request_cur(req, 0);
                        continue;
                }
 
@@ -1333,7 +1308,7 @@ static void blkvsc_request(struct request_queue *queue)
                        break;
                }
 
-               blkdev_dequeue_request(req);
+               blk_start_request(req);
 
                ret = blkvsc_do_request(blkdev, req);
                if (ret > 0)
@@ -1352,9 +1327,9 @@ static void blkvsc_request(struct request_queue *queue)
        }
 }
 
-static int blkvsc_open(struct inode *inode, struct file *filep)
+static int blkvsc_open(struct block_device *bdev,  fmode_t mode)
 {
-       struct block_device_context *blkdev = inode->i_bdev->bd_disk->private_data;
+       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);
 
@@ -1363,7 +1338,7 @@ static int blkvsc_open(struct inode *inode, struct file *filep)
        if (!blkdev->users && blkdev->device_type == DVD_TYPE)
        {
                spin_unlock(&blkdev->lock);
-               check_disk_change(inode->i_bdev);
+               check_disk_change(bdev);
                spin_lock(&blkdev->lock);
        }
 
@@ -1373,9 +1348,9 @@ static int blkvsc_open(struct inode *inode, struct file *filep)
        return 0;
 }
 
-static int blkvsc_release(struct inode *inode, struct file *filep)
+static int blkvsc_release(struct gendisk *disk, fmode_t mode)
 {
-       struct block_device_context *blkdev = inode->i_bdev->bd_disk->private_data;
+       struct block_device_context *blkdev = disk->private_data;
 
        DPRINT_DBG(BLKVSC_DRV, "- users %d disk %s\n", blkdev->users, blkdev->gd->disk_name);
 
@@ -1410,12 +1385,12 @@ static int blkvsc_revalidate_disk(struct gendisk *gd)
        {
                blkvsc_do_read_capacity(blkdev);
                set_capacity(blkdev->gd, blkdev->capacity * (blkdev->sector_size/512));
-               blk_queue_hardsect_size(gd->queue, blkdev->sector_size);
+               blk_queue_logical_block_size(gd->queue, blkdev->sector_size);
        }
        return 0;
 }
 
-int blkvsc_getgeo(struct block_device *bd, struct hd_geometry *hg)
+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;
@@ -1427,51 +1402,51 @@ int blkvsc_getgeo(struct block_device *bd, struct hd_geometry *hg)
        int rem=0;
 
     if (total_sectors > (65535 * 16 * 255)) {
-        total_sectors = (65535 * 16 * 255);
+       total_sectors = (65535 * 16 * 255);
     }
 
     if (total_sectors >= (65535 * 16 * 63)) {
-        sectors_per_track = 255;
-        heads = 16;
+       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
+               rem = sector_div(cylinder_times_heads, sectors_per_track); /* sector_div stores the quotient in cylinder_times_heads */
     }
        else
        {
-        sectors_per_track = 17;
+       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
+       rem = sector_div(cylinder_times_heads, sectors_per_track);      /* sector_div stores the quotient in cylinder_times_heads */
 
                temp = cylinder_times_heads + 1023;
-               rem = sector_div(temp, 1024);   // sector_div stores the quotient in temp
+               rem = sector_div(temp, 1024);   /* sector_div stores the quotient in temp */
 
                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
-        }
+           rem = sector_div(cylinder_times_heads, sectors_per_track); /* sector_div stores the quotient in cylinder_times_heads */
+       }
 
-        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
-        }
+           rem = sector_div(cylinder_times_heads, sectors_per_track); /* sector_div stores the quotient in cylinder_times_heads */
+       }
     }
 
        temp = cylinder_times_heads;
-    rem = sector_div(temp, heads); // sector_div stores the quotient in temp
+    rem = sector_div(temp, heads); /* sector_div stores the quotient in temp */
        cylinders = temp;
 
        hg->heads = heads;
@@ -1483,16 +1458,16 @@ int blkvsc_getgeo(struct block_device *bd, struct hd_geometry *hg)
     return 0;
 }
 
-static int blkvsc_ioctl(struct inode *inode, struct file *filep, unsigned cmd, unsigned long arg)
+static int blkvsc_ioctl(struct block_device *bd, fmode_t mode,
+                       unsigned cmd, unsigned long argument)
 {
-       struct block_device *bd = inode->i_bdev;
-       struct block_device_context *blkdev = bd->bd_disk->private_data;
+/*     struct block_device_context *blkdev = bd->bd_disk->private_data; */
        int ret=0;
 
        switch (cmd)
        {
-       // TODO: I think there is certain format for HDIO_GET_IDENTITY rather than just
-       // a GUID. Commented it out for now.
+       /* 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:
                DPRINT_INFO(BLKVSC_DRV, "HDIO_GET_IDENTITY\n");
 
@@ -1517,7 +1492,7 @@ static int __init blkvsc_init(void)
 {
        int ret;
 
-       ASSERT(sizeof(sector_t) == 8); // Make sure CONFIG_LBD is set
+       ASSERT(sizeof(sector_t) == 8); /* Make sure CONFIG_LBD is set */
 
        DPRINT_ENTER(BLKVSC_DRV);
 
@@ -1544,4 +1519,4 @@ module_param(blkvsc_ringbuffer_size, int, S_IRUGO);
 module_init(blkvsc_init);
 module_exit(blkvsc_exit);
 
-// eof
+/* eof */