Re: [PATCH] virtio_blk: decrement index when blockdevice is removed

2011-04-06 Thread Jens Axboe
On 2011-04-05 06:49, Takuma Umeya wrote:
 When virtio block device is removed, index does not get decremented. When 
 another virtio disk is attached it uses the next device letter to the 
 one that is suppose to be available. 
 
 Signed-off-by: Takuma Umeya tum...@redhat.com
 
 diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
 index 6ecf89c..730e7af 100644
 --- a/drivers/block/virtio_blk.c
 +++ b/drivers/block/virtio_blk.c
 @@ -489,6 +489,7 @@ static void __devexit virtblk_remove(struct virtio_device 
 *vdev)
 mempool_destroy(vblk-pool);
 vdev-config-del_vqs(vdev);
 kfree(vblk);
 +   index--;
  }
  
  static const struct virtio_device_id id_table[] = {

What happens when you delete a device that isn't the last one?

-- 
Jens Axboe

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


KVM Forum 2011 - Save the Date

2011-04-06 Thread KVM Forum 2011 Program Committee
KVM Forum 2011 - Save the Date

Conference: August 15 - 16, 2011
Location: Hyatt Regency Vancouver - Vancouver, Canada

KVM is an industry leading open source hypervisor that provides an ideal
platform for datacenter virtualization, virtual desktop infrastructure,
and cloud computing.  Once again, it's time to bring together the
community of developers and users that define the KVM ecosystem for
our annual technical conference.  We will discuss the current state of
affairs and plan for the future of KVM, its surrounding infrastructure,
and management tools.  So mark your calendar and join us in advancing KVM.

We are colocated with The Linux Foundation's LinuxCon again this year.

Details regarding registration and proposal submission will be coming
later this week.

Thanks,
your KVM Forum 2011 Program Commitee
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


Re: [PATCH] virtio_blk: decrement index when blockdevice is removed

2011-04-06 Thread Jens Axboe
On 2011-04-06 03:32, Rusty Russell wrote:
 On Tue, 05 Apr 2011 07:08:12 +0200, Jens Axboe jax...@fusionio.com wrote:
 On 2011-04-05 06:49, Takuma Umeya wrote:
 When virtio block device is removed, index does not get decremented. When 
 another virtio disk is attached it uses the next device letter to the 
 one that is suppose to be available. 

 Signed-off-by: Takuma Umeya tum...@redhat.com

 diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
 index 6ecf89c..730e7af 100644
 --- a/drivers/block/virtio_blk.c
 +++ b/drivers/block/virtio_blk.c
 @@ -489,6 +489,7 @@ static void __devexit virtblk_remove(struct 
 virtio_device *vdev)
 mempool_destroy(vblk-pool);
 vdev-config-del_vqs(vdev);
 kfree(vblk);
 +   index--;
  }
  
  static const struct virtio_device_id id_table[] = {

 What happens when you delete a device that isn't the last one?
 
 Obviously we should do something cleverer for assigning drives.
 
 It might be a cute if genhd gave us a function to get the next free
 index for a given major number, and format it for us, like so:
 
   /* Return the next available minor for a given @major, at least
* @spacing after the previous and, and append appropriate letters
* to @name if it's not NULL.  -ve errno on fail (-ENOSPC?). */
   int disk_next_minor(int major, unsigned spacing, char *name);
 
 A trivial optimization would be to remember the last major and max minor
 (resetting that if any disks are removed).
 
 This could clean up other code, too.

Something like idr would be a good fit for this. But yes, adding some
helpers for this might not hurt...

-- 
Jens Axboe
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


[PATCH 2/2] Staging: hv: Zero out the request structure on allocation

2011-04-06 Thread K. Y. Srinivasan
As part of the cleanup of the I/O request structure, allocate them zeroed
out. This fixes a bug that was introduced in the patch-set titled:
Staging: hv: Cleanup-storage-drivers-phase-II.
A corrected version of this patch-set was sent out earlier, however
the earlier (buggy) version of this patch-set was already applied.
This patch fixes the problem.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/storvsc_drv.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/staging/hv/storvsc_drv.c b/drivers/staging/hv/storvsc_drv.c
index 6128ffd..ae61735 100644
--- a/drivers/staging/hv/storvsc_drv.c
+++ b/drivers/staging/hv/storvsc_drv.c
@@ -738,7 +738,7 @@ static int storvsc_queuecommand_lck(struct scsi_cmnd *scmnd,
 
request_size = sizeof(struct storvsc_cmd_request);
 
-   cmd_request = kmem_cache_alloc(host_device_ctx-request_pool,
+   cmd_request = kmem_cache_zalloc(host_device_ctx-request_pool,
   GFP_ATOMIC);
if (!cmd_request) {
DPRINT_ERR(STORVSC_DRV, scmnd (%p) - unable to allocate 
-- 
1.7.4.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


[PATCH 1/2] Staging: hv: Properly capture the error state

2011-04-06 Thread K. Y. Srinivasan
Properly capture the error state after the completion of I/O. This fixes a bug
that was introduced in the patch-set titled:
Staging: hv: Cleanup-storage-drivers-phase-II.
A corrected version of this patch-set was sent out earlier, however
the earlier (buggy) version of this patch-set was already applied.
This patch fixes the problem.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/storvsc.c |   13 +++--
 1 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/hv/storvsc.c b/drivers/staging/hv/storvsc.c
index 55865fa..d7ce393 100644
--- a/drivers/staging/hv/storvsc.c
+++ b/drivers/staging/hv/storvsc.c
@@ -279,6 +279,7 @@ static void stor_vsc_on_io_completion(struct hv_device 
*device,
  struct hv_storvsc_request *request)
 {
struct storvsc_device *stor_device;
+   struct vstor_packet *stor_pkt;
 
stor_device = must_get_stor_device(device);
if (!stor_device) {
@@ -287,19 +288,24 @@ static void stor_vsc_on_io_completion(struct hv_device 
*device,
return;
}
 
-   DPRINT_DBG(STORVSC, IO_COMPLETE_OPERATION - request  %p 
+   DPRINT_DBG(STORVSC, IO_COMPLETE_OPERATION - request %p 
   completed bytes xfer %u, request,
   vstor_packet-vm_srb.data_transfer_length);
 
+   stor_pkt = request-vstor_packet;
 
 
/* Copy over the status...etc */
+   stor_pkt-vm_srb.scsi_status = vstor_packet-vm_srb.scsi_status;
+   stor_pkt-vm_srb.srb_status = vstor_packet-vm_srb.srb_status;
+   stor_pkt-vm_srb.sense_info_length =
+   vstor_packet-vm_srb.sense_info_length;
 
if (vstor_packet-vm_srb.scsi_status != 0 ||
vstor_packet-vm_srb.srb_status != 1) {
DPRINT_WARN(STORVSC,
cmd 0x%x scsi status 0x%x srb status 0x%x\n,
-   vstor_packet-vm_srb.cdb[0],
+   stor_pkt-vm_srb.cdb[0],
vstor_packet-vm_srb.scsi_status,
vstor_packet-vm_srb.srb_status);
}
@@ -319,6 +325,8 @@ static void stor_vsc_on_io_completion(struct hv_device 
*device,
}
}
 
+   stor_pkt-vm_srb.data_transfer_length =
+   vstor_packet-vm_srb.data_transfer_length;
 
request-on_io_completion(request);
 
@@ -535,6 +543,7 @@ int stor_vsc_on_io_request(struct hv_device *device,
 
request-device  = device;
 
+
vstor_packet-flags |= REQUEST_COMPLETION_FLAG;
 
vstor_packet-vm_srb.length = sizeof(struct vmscsi_request);
-- 
1.7.4.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


[PATCH 0/2] Staging: hv: Fixup Phase II storage driver cleanup

2011-04-06 Thread K. Y. Srinivasan
This fixes a couple of bugs  that was introduced in the patch-set titled:

Staging: hv: Cleanup storage drivers phase II.

A corrected version of this patch-set was sent out earlier, however
the earlier (buggy) version of this patch-set was already applied.
This patch set  fixes this problem..


Regards,

K. Y
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


Re: [PATCH] virtio_blk: decrement index when blockdevice is removed

2011-04-06 Thread Ryan Harper
* Takuma Umeya tum...@redhat.com [2011-04-05 00:00]:
 When virtio block device is removed, index does not get decremented. When 
 another virtio disk is attached it uses the next device letter to the 
 one that is suppose to be available. 
 
 Signed-off-by: Takuma Umeya tum...@redhat.com
 
 diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
 index 6ecf89c..730e7af 100644
 --- a/drivers/block/virtio_blk.c
 +++ b/drivers/block/virtio_blk.c
 @@ -489,6 +489,7 @@ static void __devexit virtblk_remove(struct virtio_device 
 *vdev)
 mempool_destroy(vblk-pool);
 vdev-config-del_vqs(vdev);
 kfree(vblk);
 +   index--;
  }

What about referencing /dev/disk/by-id  and using drive serial numbers?
How much do we care about re-using minor numbers?  IIRC, virtio-blk can
go out to vdxxx; that's a lot of disks or add/removes.

 
  static const struct virtio_device_id id_table[] = {
 
 -- 
 Umeya, Takuma
 Technical Account Manager
 Red Hat GSS APAC
 +81.3.5798.8584 (direct)
 tum...@redhat.com
 ___
 Virtualization mailing list
 Virtualization@lists.linux-foundation.org
 https://lists.linux-foundation.org/mailman/listinfo/virtualization

-- 
Ryan Harper
Software Engineer; Linux Technology Center
IBM Corp., Austin, Tx
ry...@us.ibm.com
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


[RESEND] [PATCH 00/22] Staging: hv: Cleanup-storage-drivers-phase-III

2011-04-06 Thread K. Y. Srinivasan
The latest upstream merge changed struct block_device_operations:
This merge got rid of blkvsc_media_changed and introduced the
function blkvsc_check_events. This broke all the patches that
were sent after the tree was closed the last time. This is a resend of
this patch-set to account for this change in the kernel.

This patch-set deals with some of the style isues in blkvsc_drv.c. We also
get rid most of the dead code in this file:

1) Get rid of most of the forward declarations in this file.
   The only remaining forward declarations are to deal with 
   circular dependencies.

2) Get rid of most of the dead code in the file. Some of
   the functions in this file are place holders - they are not
   fuly implementedi yet (blkvsc_ioctl(), blkvsc_media_changed(). 
   We have retained some comments/dead code, to help us in the
   final implementation.

Regads,

K. Y 


___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


[PATCH 11/22] Staging: hv: Get rid of the forward declaration of blkvsc_shutdown()

2011-04-06 Thread K. Y. Srinivasan
Get rid of the forward declaration of blkvsc_shutdown() by moving the
code around.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Abhishek Kane v-abk...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |   70 +++
 1 files changed, 34 insertions(+), 36 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index a98ed8f..1fb68b7 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -645,10 +645,42 @@ static int blkvsc_remove(struct device *device)
return ret;
 }
 
+static void blkvsc_shutdown(struct device *device)
+{
+   struct block_device_context *blkdev = dev_get_drvdata(device);
+   unsigned long flags;
+
+   if (!blkdev)
+   return;
+
+   DPRINT_DBG(BLKVSC_DRV, blkvsc_shutdown - users %d disk %s\n,
+  blkdev-users, blkdev-gd-disk_name);
+
+   spin_lock_irqsave(blkdev-lock, flags);
+
+   blkdev-shutting_down = 1;
+
+   blk_stop_queue(blkdev-gd-queue);
+
+   spin_unlock_irqrestore(blkdev-lock, flags);
+
+   while (blkdev-num_outstanding_reqs) {
+   DPRINT_INFO(STORVSC, waiting for %d requests to complete...,
+   blkdev-num_outstanding_reqs);
+   udelay(100);
+   }
+
+   blkvsc_do_flush(blkdev);
+
+   spin_lock_irqsave(blkdev-lock, flags);
+
+   blkvsc_cancel_pending_reqs(blkdev);
+
+   spin_unlock_irqrestore(blkdev-lock, flags);
+}
+
 /* Static decl */
 static int blkvsc_probe(struct device *dev);
-static void blkvsc_shutdown(struct device *device);
-
 static int blkvsc_release(struct gendisk *disk, fmode_t mode);
 static int blkvsc_revalidate_disk(struct gendisk *gd);
 static void blkvsc_request(struct request_queue *queue);
@@ -913,40 +945,6 @@ Cleanup:
return ret;
 }
 
-static void blkvsc_shutdown(struct device *device)
-{
-   struct block_device_context *blkdev = dev_get_drvdata(device);
-   unsigned long flags;
-
-   if (!blkdev)
-   return;
-
-   DPRINT_DBG(BLKVSC_DRV, blkvsc_shutdown - users %d disk %s\n,
-  blkdev-users, blkdev-gd-disk_name);
-
-   spin_lock_irqsave(blkdev-lock, flags);
-
-   blkdev-shutting_down = 1;
-
-   blk_stop_queue(blkdev-gd-queue);
-
-   spin_unlock_irqrestore(blkdev-lock, flags);
-
-   while (blkdev-num_outstanding_reqs) {
-   DPRINT_INFO(STORVSC, waiting for %d requests to complete...,
-   blkdev-num_outstanding_reqs);
-   udelay(100);
-   }
-
-   blkvsc_do_flush(blkdev);
-
-   spin_lock_irqsave(blkdev-lock, flags);
-
-   blkvsc_cancel_pending_reqs(blkdev);
-
-   spin_unlock_irqrestore(blkdev-lock, flags);
-}
-
 /* 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)
 {
-- 
1.7.4.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


[PATCH 05/22] Staging: hv: Get rid of the forward declaration of blkvsc_init_rw()

2011-04-06 Thread K. Y. Srinivasan
Get rid of the forward declaration of blkvsc_init_rw() by moving the
code around.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Abhishek Kane v-abk...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |  117 ---
 1 files changed, 59 insertions(+), 58 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index 69048e3..5f14bb6 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -356,6 +356,65 @@ static int blkvsc_getgeo(struct block_device *bd, struct 
hd_geometry *hg)
return 0;
 }
 
+
+static void blkvsc_init_rw(struct blkvsc_request *blkvsc_req)
+{
+   /* ASSERT(blkvsc_req-req); */
+   /* ASSERT(blkvsc_req-sector_count =
+  (MAX_MULTIPAGE_BUFFER_COUNT*8)); */
+
+   blkvsc_req-cmd_len = 16;
+
+   if (blkvsc_req-sector_start  0x) {
+   if (rq_data_dir(blkvsc_req-req)) {
+   blkvsc_req-write = 1;
+   blkvsc_req-cmnd[0] = WRITE_16;
+   } else {
+   blkvsc_req-write = 0;
+   blkvsc_req-cmnd[0] = READ_16;
+   }
+
+   blkvsc_req-cmnd[1] |=
+   (blkvsc_req-req-cmd_flags  REQ_FUA) ? 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  0x1f)) {
+   if (rq_data_dir(blkvsc_req-req)) {
+   blkvsc_req-write = 1;
+   blkvsc_req-cmnd[0] = WRITE_10;
+   } else {
+   blkvsc_req-write = 0;
+   blkvsc_req-cmnd[0] = READ_10;
+   }
+
+   blkvsc_req-cmnd[1] |=
+   (blkvsc_req-req-cmd_flags  REQ_FUA) ? 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)) {
+   blkvsc_req-write = 1;
+   blkvsc_req-cmnd[0] = WRITE_6;
+   } 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;
+   blkvsc_req-cmnd[1] = 0x1f;
+   blkvsc_req-cmnd[4] = (unsigned char)blkvsc_req-sector_count;
+   }
+}
+
+
 /* Static decl */
 static int blkvsc_probe(struct device *dev);
 static int blkvsc_remove(struct device *device);
@@ -369,7 +428,6 @@ 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 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);
 static int blkvsc_do_read_capacity(struct block_device_context *blkdev);
@@ -1000,63 +1058,6 @@ static int blkvsc_remove(struct device *device)
return ret;
 }
 
-static void blkvsc_init_rw(struct blkvsc_request *blkvsc_req)
-{
-   /* ASSERT(blkvsc_req-req); */
-   /* ASSERT(blkvsc_req-sector_count = (MAX_MULTIPAGE_BUFFER_COUNT*8)); 
*/
-
-   blkvsc_req-cmd_len = 16;
-
-   if (blkvsc_req-sector_start  0x) {
-   if (rq_data_dir(blkvsc_req-req)) {
-   blkvsc_req-write = 1;
-   blkvsc_req-cmnd[0] = WRITE_16;
-   } else {
-   blkvsc_req-write = 0;
-   blkvsc_req-cmnd[0] = READ_16;
-   }
-
-   blkvsc_req-cmnd[1] |=
-   (blkvsc_req-req-cmd_flags  REQ_FUA) ? 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  0x1f)) {
-   if (rq_data_dir(blkvsc_req-req)) {
-   blkvsc_req-write = 1;
-   blkvsc_req-cmnd[0] = WRITE_10;
-  

[PATCH 15/22] Staging: hv: Get rid of the forward declaration of blkvsc_revalidate_disk()

2011-04-06 Thread K. Y. Srinivasan
Get rid of the forward declaration of blkvsc_revalidate_disk() by moving
the code around.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Abhishek Kane v-abk...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |   31 +++
 1 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index 49caad7..35dacf0 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -861,9 +861,23 @@ static int blkvsc_do_read_capacity16(struct 
block_device_context *blkdev)
return 0;
 }
 
+static int blkvsc_revalidate_disk(struct gendisk *gd)
+{
+   struct block_device_context *blkdev = gd-private_data;
+
+   DPRINT_DBG(BLKVSC_DRV, - enter\n);
+
+   if (blkdev-device_type == DVD_TYPE) {
+   blkvsc_do_read_capacity(blkdev);
+   set_capacity(blkdev-gd, blkdev-capacity *
+   (blkdev-sector_size/512));
+   blk_queue_logical_block_size(gd-queue, blkdev-sector_size);
+   }
+   return 0;
+}
+
 /* Static decl */
 static int blkvsc_probe(struct device *dev);
-static int blkvsc_revalidate_disk(struct gendisk *gd);
 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,
@@ -1513,21 +1527,6 @@ static void blkvsc_request(struct request_queue *queue)
}
 }
 
-static int blkvsc_revalidate_disk(struct gendisk *gd)
-{
-   struct block_device_context *blkdev = gd-private_data;
-
-   DPRINT_DBG(BLKVSC_DRV, - enter\n);
-
-   if (blkdev-device_type == DVD_TYPE) {
-   blkvsc_do_read_capacity(blkdev);
-   set_capacity(blkdev-gd, blkdev-capacity *
-   (blkdev-sector_size/512));
-   blk_queue_logical_block_size(gd-queue, blkdev-sector_size);
-   }
-   return 0;
-}
-
 static int __init blkvsc_init(void)
 {
int ret;
-- 
1.7.4.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


[PATCH 18/22] Staging: hv: Get rid of the forward declaration for blkvsc_do_pending_reqs()

2011-04-06 Thread K. Y. Srinivasan
Get rid of the forward declaration for blkvsc_do_pending_reqs() by moving
the code around.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Abhishek Kane v-abk...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |   45 +++
 1 files changed, 22 insertions(+), 23 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index 9d4fcbd..66590f6 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -1148,10 +1148,31 @@ static int blkvsc_do_request(struct 
block_device_context *blkdev,
return pending;
 }
 
+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 */
+   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);
+   if (ret != 0)
+   break;
+   else
+   list_del(pend_req-pend_entry);
+   }
+
+   return ret;
+}
+
 /* Static decl */
 static int blkvsc_probe(struct device *dev);
 static void blkvsc_request(struct request_queue *queue);
-static int blkvsc_do_pending_reqs(struct block_device_context *blkdev);
 
 static int blkvsc_ringbuffer_size = BLKVSC_RING_BUFFER_SIZE;
 module_param(blkvsc_ringbuffer_size, int, S_IRUGO);
@@ -1479,28 +1500,6 @@ static void blkvsc_request_completion(struct 
hv_storvsc_request *request)
spin_unlock_irqrestore(blkdev-lock, flags);
 }
 
-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 */
-   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);
-   if (ret != 0)
-   break;
-   else
-   list_del(pend_req-pend_entry);
-   }
-
-   return ret;
-}
-
 static void blkvsc_request(struct request_queue *queue)
 {
struct block_device_context *blkdev = NULL;
-- 
1.7.4.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


[PATCH 03/22] Staging: hv: Get rid of the forward declaration of blkvsc_open()

2011-04-06 Thread K. Y. Srinivasan
Get rid of the forward declaration of blkvsc_open() by moving the code around.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Abhishek Kane v-abk...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |   49 +++
 1 files changed, 24 insertions(+), 25 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index 4452700..173abe3 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -106,6 +106,7 @@ struct block_device_context {
int users;
 };
 
+static DEFINE_MUTEX(blkvsc_mutex);
 
 static const char *g_blk_driver_name = blkvsc;
 
@@ -251,13 +252,34 @@ static unsigned int blkvsc_check_events(struct gendisk 
*gd,
 }
 
 
+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);
+
+   mutex_lock(blkvsc_mutex);
+   spin_lock(blkdev-lock);
+
+   if (!blkdev-users  blkdev-device_type == DVD_TYPE) {
+   spin_unlock(blkdev-lock);
+   check_disk_change(bdev);
+   spin_lock(blkdev-lock);
+   }
+
+   blkdev-users++;
+
+   spin_unlock(blkdev-lock);
+   mutex_unlock(blkvsc_mutex);
+   return 0;
+}
+
 /* Static decl */
-static DEFINE_MUTEX(blkvsc_mutex);
 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 block_device *bdev,  fmode_t mode);
 static int blkvsc_release(struct gendisk *disk, fmode_t mode);
 static int blkvsc_revalidate_disk(struct gendisk *gd);
 static int blkvsc_getgeo(struct block_device *bd, struct hd_geometry *hg);
@@ -1368,29 +1390,6 @@ static void blkvsc_request(struct request_queue *queue)
}
 }
 
-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);
-
-   mutex_lock(blkvsc_mutex);
-   spin_lock(blkdev-lock);
-
-   if (!blkdev-users  blkdev-device_type == DVD_TYPE) {
-   spin_unlock(blkdev-lock);
-   check_disk_change(bdev);
-   spin_lock(blkdev-lock);
-   }
-
-   blkdev-users++;
-
-   spin_unlock(blkdev-lock);
-   mutex_unlock(blkvsc_mutex);
-   return 0;
-}
-
 static int blkvsc_release(struct gendisk *disk, fmode_t mode)
 {
struct block_device_context *blkdev = disk-private_data;
-- 
1.7.4.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


[PATCH 09/22] Staging: hv: Get rid of the forward declaration of blkvsc_cancel_pending_reqs()

2011-04-06 Thread K. Y. Srinivasan
Get rid of the forward declaration of blkvsc_cancel_pending_reqs() by moving
the code around.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Abhishek Kane v-abk...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |  159 +++
 1 files changed, 79 insertions(+), 80 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index 94f090e..2829266 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -501,6 +501,85 @@ static int blkvsc_do_flush(struct block_device_context 
*blkdev)
 }
 
 
+static int blkvsc_cancel_pending_reqs(struct block_device_context *blkdev)
+{
+   struct blkvsc_request *pend_req, *tmp;
+   struct blkvsc_request *comp_req, *tmp2;
+   struct vmscsi_request *vm_srb;
+
+   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) {
+   /*
+* 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);
+
+   if (comp_req == pend_req)
+   break;
+
+   list_del(comp_req-req_entry);
+
+   if (comp_req-req) {
+   vm_srb =
+   comp_req-request.vstor_packet.
+   vm_srb;
+   ret = __blk_end_request(comp_req-req,
+   (!vm_srb-scsi_status ? 0 : -EIO),
+   comp_req-sector_count *
+   blkdev-sector_size);
+
+   /* FIXME: shouldn't this do more than return? */
+   if (ret)
+   goto out;
+   }
+
+   kmem_cache_free(blkdev-request_pool, comp_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);
+   }
+   }
+
+   kmem_cache_free(blkdev-request_pool, pend_req);
+   }
+
+out:
+   return ret;
+}
+
 /* Static decl */
 static int blkvsc_probe(struct device *dev);
 static int blkvsc_remove(struct device *device);
@@ -515,7 +594,6 @@ static int blkvsc_do_request(struct block_device_context 
*blkdev,
 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);
-static int blkvsc_cancel_pending_reqs(struct block_device_context *blkdev);
 static int blkvsc_do_pending_reqs(struct block_device_context *blkdev);
 
 static int blkvsc_ringbuffer_size = BLKVSC_RING_BUFFER_SIZE;
@@ -1352,85 +1430,6 @@ static void blkvsc_request_completion(struct 
hv_storvsc_request *request)
spin_unlock_irqrestore(blkdev-lock, flags);
 }
 
-static int blkvsc_cancel_pending_reqs(struct block_device_context *blkdev)
-{
-   struct blkvsc_request *pend_req, *tmp;
-   struct blkvsc_request *comp_req, *tmp2;
-   struct vmscsi_request *vm_srb;
-
-   int ret = 0;
-
-   

[PATCH 20/22] Staging: hv: Move some definitions/declarations to be earlier in the file

2011-04-06 Thread K. Y. Srinivasan
Move some definitions/declarations to be earlier in the file.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Abhishek Kane v-abk...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |   11 ---
 1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index 55ba9de..865b4dc 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -124,6 +124,14 @@ static const struct hv_guid g_blk_device_type = {
  */
 static void blkvsc_request_completion(struct hv_storvsc_request *request);
 
+static int blkvsc_ringbuffer_size = BLKVSC_RING_BUFFER_SIZE;
+
+/*
+ * There is a circular dependency involving blkvsc_probe()
+ * and block_ops.
+ */
+static int blkvsc_probe(struct device *dev);
+
 static int blk_vsc_on_device_add(struct hv_device *device,
void *additional_info)
 {
@@ -1213,10 +1221,7 @@ static void blkvsc_request(struct request_queue *queue)
}
 }
 
-/* Static decl */
-static int blkvsc_probe(struct device *dev);
 
-static int blkvsc_ringbuffer_size = BLKVSC_RING_BUFFER_SIZE;
 module_param(blkvsc_ringbuffer_size, int, S_IRUGO);
 MODULE_PARM_DESC(ring_size, Ring buffer size (in bytes));
 
-- 
1.7.4.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


[PATCH 08/22] Staging: hv: Get rid of the forward declaration of blkvsc_do_flush()

2011-04-06 Thread K. Y. Srinivasan
Get rid of the forward declaration of blkvsc_do_flush() by moving the code
around.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Abhishek Kane v-abk...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |   71 +++
 1 files changed, 35 insertions(+), 36 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index 068daee..94f090e 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -465,6 +465,41 @@ static void blkvsc_cmd_completion(struct 
hv_storvsc_request *request)
complete(blkvsc_req-request.wait_event);
 }
 
+static int blkvsc_do_flush(struct block_device_context *blkdev)
+{
+   struct blkvsc_request *blkvsc_req;
+
+   DPRINT_DBG(BLKVSC_DRV, blkvsc_do_flush()\n);
+
+   if (blkdev-device_type != HARDDISK_TYPE)
+   return 0;
+
+   blkvsc_req = kmem_cache_zalloc(blkdev-request_pool, GFP_KERNEL);
+   if (!blkvsc_req)
+   return -ENOMEM;
+
+   memset(blkvsc_req, 0, sizeof(struct blkvsc_request));
+   init_completion(blkvsc_req-request.wait_event);
+   blkvsc_req-dev = blkdev;
+   blkvsc_req-req = NULL;
+   blkvsc_req-write = 0;
+
+   blkvsc_req-request.data_buffer.pfn_array[0] = 0;
+   blkvsc_req-request.data_buffer.offset = 0;
+   blkvsc_req-request.data_buffer.len = 0;
+
+   blkvsc_req-cmnd[0] = SYNCHRONIZE_CACHE;
+   blkvsc_req-cmd_len = 10;
+
+   blkvsc_submit_request(blkvsc_req, blkvsc_cmd_completion);
+
+   wait_for_completion_interruptible(blkvsc_req-request.wait_event);
+
+   kmem_cache_free(blkvsc_req-dev-request_pool, blkvsc_req);
+
+   return 0;
+}
+
 
 /* Static decl */
 static int blkvsc_probe(struct device *dev);
@@ -480,7 +515,6 @@ static int blkvsc_do_request(struct block_device_context 
*blkdev,
 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);
-static int blkvsc_do_flush(struct block_device_context *blkdev);
 static int blkvsc_cancel_pending_reqs(struct block_device_context *blkdev);
 static int blkvsc_do_pending_reqs(struct block_device_context *blkdev);
 
@@ -771,41 +805,6 @@ static void blkvsc_shutdown(struct device *device)
spin_unlock_irqrestore(blkdev-lock, flags);
 }
 
-static int blkvsc_do_flush(struct block_device_context *blkdev)
-{
-   struct blkvsc_request *blkvsc_req;
-
-   DPRINT_DBG(BLKVSC_DRV, blkvsc_do_flush()\n);
-
-   if (blkdev-device_type != HARDDISK_TYPE)
-   return 0;
-
-   blkvsc_req = kmem_cache_zalloc(blkdev-request_pool, GFP_KERNEL);
-   if (!blkvsc_req)
-   return -ENOMEM;
-
-   memset(blkvsc_req, 0, sizeof(struct blkvsc_request));
-   init_completion(blkvsc_req-request.wait_event);
-   blkvsc_req-dev = blkdev;
-   blkvsc_req-req = NULL;
-   blkvsc_req-write = 0;
-
-   blkvsc_req-request.data_buffer.pfn_array[0] = 0;
-   blkvsc_req-request.data_buffer.offset = 0;
-   blkvsc_req-request.data_buffer.len = 0;
-
-   blkvsc_req-cmnd[0] = SYNCHRONIZE_CACHE;
-   blkvsc_req-cmd_len = 10;
-
-   blkvsc_submit_request(blkvsc_req, blkvsc_cmd_completion);
-
-   wait_for_completion_interruptible(blkvsc_req-request.wait_event);
-
-   kmem_cache_free(blkvsc_req-dev-request_pool, blkvsc_req);
-
-   return 0;
-}
-
 /* 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)
 {
-- 
1.7.4.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


[PATCH 01/22] Staging: hv: Get rid of the forward declaration of blkvsc_submit_request()

2011-04-06 Thread K. Y. Srinivasan
Get rid of the forward declaration of  blkvsc_submit_request() by moving the
code around.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Abhishek Kane v-abk...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |  117 ---
 1 files changed, 59 insertions(+), 58 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index d1ecd60..efcc916 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -184,6 +184,65 @@ static int blk_vsc_initialize(struct hv_driver *driver)
return ret;
 }
 
+
+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 hv_device *device_ctx = blkdev-device_ctx;
+   struct hv_driver *drv =
+   drv_to_hv_drv(device_ctx-device.driver);
+   struct storvsc_driver_object *storvsc_drv_obj =
+   drv-priv;
+   struct hv_storvsc_request *storvsc_req;
+   struct vmscsi_request *vm_srb;
+   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.data_buffer.offset,
+  blkvsc_req-request.data_buffer.len);
+#if 0
+   for (i = 0; i  (blkvsc_req-request.data_buffer.len  12); i++) {
+   DPRINT_DBG(BLKVSC_DRV, blkvsc_submit_request() - 
+  req %p pfn[%d] %llx\n,
+  blkvsc_req, i,
+  blkvsc_req-request.data_buffer.pfn_array[i]);
+   }
+#endif
+
+   storvsc_req = blkvsc_req-request;
+   vm_srb = storvsc_req-vstor_packet.vm_srb;
+
+   vm_srb-data_in = blkvsc_req-write ? WRITE_TYPE : READ_TYPE;
+
+   storvsc_req-on_io_completion = request_completion;
+   storvsc_req-context = blkvsc_req;
+
+   vm_srb-port_number = blkdev-port;
+   vm_srb-path_id = blkdev-path;
+   vm_srb-target_id = blkdev-target;
+   vm_srb-lun = 0; /* this is not really used at all */
+
+   vm_srb-cdb_length = blkvsc_req-cmd_len;
+
+   memcpy(vm_srb-cdb, blkvsc_req-cmnd, vm_srb-cdb_length);
+
+   storvsc_req-sense_buffer = blkvsc_req-sense_buffer;
+
+   ret = storvsc_drv_obj-on_io_request(blkdev-device_ctx,
+  blkvsc_req-request);
+   if (ret == 0)
+   blkdev-num_outstanding_reqs++;
+
+   return ret;
+}
+
+
 /* Static decl */
 static DEFINE_MUTEX(blkvsc_mutex);
 static int blkvsc_probe(struct device *dev);
@@ -202,8 +261,6 @@ 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 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);
@@ -891,62 +948,6 @@ static void blkvsc_init_rw(struct blkvsc_request 
*blkvsc_req)
}
 }
 
-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 hv_device *device_ctx = blkdev-device_ctx;
-   struct hv_driver *drv =
-   drv_to_hv_drv(device_ctx-device.driver);
-   struct storvsc_driver_object *storvsc_drv_obj =
-   drv-priv;
-   struct hv_storvsc_request *storvsc_req;
-   struct vmscsi_request *vm_srb;
-   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.data_buffer.offset,
-  blkvsc_req-request.data_buffer.len);
-#if 0
-   for (i = 0; i  (blkvsc_req-request.data_buffer.len  12); i++) {
-   DPRINT_DBG(BLKVSC_DRV, blkvsc_submit_request() - 
-  req %p pfn[%d] %llx\n,
-  blkvsc_req, i,
- 

[PATCH 22/22] Staging: hv: Get rid of some dead code in blkvsc_drv.c

2011-04-06 Thread K. Y. Srinivasan
Get rid of some dead code in blkvsc_drv.c.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Abhishek Kane v-abk...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |   26 --
 1 files changed, 0 insertions(+), 26 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index 6ad1cad..0b85995 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -172,7 +172,6 @@ static int blk_vsc_initialize(struct hv_driver *driver)
stor_driver = hvdr_to_stordr(driver);
 
/* Make sure we are at least 2 pages since 1 page is used for control */
-   /* ASSERT(stor_driver-RingBufferSize = (PAGE_SIZE  1)); */
 
driver-name = g_blk_driver_name;
memcpy(driver-dev_type, g_blk_device_type, sizeof(struct hv_guid));
@@ -224,14 +223,6 @@ static int blkvsc_submit_request(struct blkvsc_request 
*blkvsc_req,
   blkvsc_req-sector_count,
   blkvsc_req-request.data_buffer.offset,
   blkvsc_req-request.data_buffer.len);
-#if 0
-   for (i = 0; i  (blkvsc_req-request.data_buffer.len  12); i++) {
-   DPRINT_DBG(BLKVSC_DRV, blkvsc_submit_request() - 
-  req %p pfn[%d] %llx\n,
-  blkvsc_req, i,
-  blkvsc_req-request.data_buffer.pfn_array[i]);
-   }
-#endif
 
storvsc_req = blkvsc_req-request;
vm_srb = storvsc_req-vstor_packet.vm_srb;
@@ -376,9 +367,6 @@ static int blkvsc_getgeo(struct block_device *bd, struct 
hd_geometry *hg)
 
 static void blkvsc_init_rw(struct blkvsc_request *blkvsc_req)
 {
-   /* ASSERT(blkvsc_req-req); */
-   /* ASSERT(blkvsc_req-sector_count =
-  (MAX_MULTIPAGE_BUFFER_COUNT*8)); */
 
blkvsc_req-cmd_len = 16;
 
@@ -435,7 +423,6 @@ static void blkvsc_init_rw(struct blkvsc_request 
*blkvsc_req)
 static int blkvsc_ioctl(struct block_device *bd, fmode_t mode,
unsigned cmd, unsigned long argument)
 {
-/* struct block_device_context *blkdev = bd-bd_disk-private_data; */
int ret;
 
switch (cmd) {
@@ -862,13 +849,6 @@ static int blkvsc_do_read_capacity16(struct 
block_device_context *blkdev)
blkdev-capacity = be64_to_cpu(*(unsigned long long *) buf[0]) + 1;
blkdev-sector_size = be32_to_cpu(*(unsigned int *)buf[8]);
 
-#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);
 
__free_page(page_buf);
@@ -940,7 +920,6 @@ static int blkvsc_do_inquiry(struct block_device_context 
*blkdev)
 
buf = kmap(page_buf);
 
-   /* print_hex_dump_bytes(, DUMP_PREFIX_NONE, buf, 64); */
/* be to le */
device_type = buf[0]  0x1F;
 
@@ -960,8 +939,6 @@ 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);
-   /* printk_hex_dump_bytes(, DUMP_PREFIX_NONE, blkdev-device_id,
-* blkdev-device_id_len); */
 
kunmap(page_buf);
 
@@ -1346,8 +1323,6 @@ static int blkvsc_probe(struct device *device)
/* Initialize what we can here */
spin_lock_init(blkdev-lock);
 
-   /* ASSERT(sizeof(struct blkvsc_request_group) = */
-   /*  sizeof(struct blkvsc_request)); */
 
blkdev-request_pool = kmem_cache_create(dev_name(device_obj-device),
sizeof(struct blkvsc_request), 0,
@@ -1484,7 +1459,6 @@ static void blkvsc_request_completion(struct 
hv_storvsc_request *request)
struct blkvsc_request *comp_req, *tmp;
struct vmscsi_request *vm_srb;
 
-   /* 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 
-- 
1.7.4.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


[PATCH 16/22] Staging: hv: Get rid of the forward declaration for blkvsc_do_inquiry()

2011-04-06 Thread K. Y. Srinivasan
Get rid of the forward declaration for blkvsc_do_inquiry() by moving the code
around.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Abhishek Kane v-abk...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |  158 +++---
 1 files changed, 79 insertions(+), 79 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index 35dacf0..f7bf42f 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -876,13 +876,91 @@ static int blkvsc_revalidate_disk(struct gendisk *gd)
return 0;
 }
 
+
+/* 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;
+   struct page *page_buf;
+   unsigned char *buf;
+   unsigned char device_type;
+
+   DPRINT_DBG(BLKVSC_DRV, blkvsc_do_inquiry()\n);
+
+   blkvsc_req = kmem_cache_zalloc(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) {
+   kmem_cache_free(blkvsc_req-dev-request_pool, blkvsc_req);
+   return -ENOMEM;
+   }
+
+   init_completion(blkvsc_req-request.wait_event);
+   blkvsc_req-dev = blkdev;
+   blkvsc_req-req = NULL;
+   blkvsc_req-write = 0;
+
+   blkvsc_req-request.data_buffer.pfn_array[0] =
+   page_to_pfn(page_buf);
+   blkvsc_req-request.data_buffer.offset = 0;
+   blkvsc_req-request.data_buffer.len = 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[4] = 64;
+   blkvsc_req-cmd_len = 6;
+
+   blkvsc_submit_request(blkvsc_req, blkvsc_cmd_completion);
+
+   DPRINT_DBG(BLKVSC_DRV, waiting %p to complete\n,
+  blkvsc_req);
+
+   wait_for_completion_interruptible(blkvsc_req-request.wait_event);
+
+   buf = kmap(page_buf);
+
+   /* print_hex_dump_bytes(, DUMP_PREFIX_NONE, buf, 64); */
+   /* be to le */
+   device_type = buf[0]  0x1F;
+
+   if (device_type == 0x0) {
+   blkdev-device_type = HARDDISK_TYPE;
+   } else if (device_type == 0x5) {
+   blkdev-device_type = DVD_TYPE;
+   } else {
+   /* TODO: this is currently unsupported device type */
+   blkdev-device_type = UNKNOWN_DEV_TYPE;
+   }
+
+   DPRINT_DBG(BLKVSC_DRV, device type %d\n, device_type);
+
+   blkdev-device_id_len = buf[7];
+   if (blkdev-device_id_len  64)
+   blkdev-device_id_len = 64;
+
+   memcpy(blkdev-device_id, buf[8], blkdev-device_id_len);
+   /* printk_hex_dump_bytes(, DUMP_PREFIX_NONE, blkdev-device_id,
+* blkdev-device_id_len); */
+
+   kunmap(page_buf);
+
+   __free_page(page_buf);
+
+   kmem_cache_free(blkvsc_req-dev-request_pool, blkvsc_req);
+
+   return 0;
+}
+
 /* Static decl */
 static int blkvsc_probe(struct device *dev);
 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_do_inquiry(struct block_device_context *blkdev);
 static int blkvsc_do_pending_reqs(struct block_device_context *blkdev);
 
 static int blkvsc_ringbuffer_size = BLKVSC_RING_BUFFER_SIZE;
@@ -1138,84 +1216,6 @@ Cleanup:
return ret;
 }
 
-/* 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;
-   struct page *page_buf;
-   unsigned char *buf;
-   unsigned char device_type;
-
-   DPRINT_DBG(BLKVSC_DRV, blkvsc_do_inquiry()\n);
-
-   blkvsc_req = kmem_cache_zalloc(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) {
-   kmem_cache_free(blkvsc_req-dev-request_pool, blkvsc_req);
-   return -ENOMEM;
-   }
-
-   init_completion(blkvsc_req-request.wait_event);
-   blkvsc_req-dev = blkdev;
-   blkvsc_req-req = NULL;
-   blkvsc_req-write = 0;
-
-   blkvsc_req-request.data_buffer.pfn_array[0] =
-   page_to_pfn(page_buf);
-   blkvsc_req-request.data_buffer.offset = 0;
-   blkvsc_req-request.data_buffer.len = 64;
-
-   blkvsc_req-cmnd[0] = INQUIRY;
-   blkvsc_req-cmnd[1] = 0x1;  /* Get product data */
-   

[PATCH 02/22] Staging: hv: Get rid of the forward declaration of blkvsc_check_events()

2011-04-06 Thread K. Y. Srinivasan
Get rid of the forward declaration of  blkvsc_check_events()  
by moving the code around.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Abhishek Kane v-abk...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |   17 -
 1 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index efcc916..4452700 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -243,6 +243,14 @@ static int blkvsc_submit_request(struct blkvsc_request 
*blkvsc_req,
 }
 
 
+static unsigned int blkvsc_check_events(struct gendisk *gd,
+   unsigned int clearing)
+{
+   DPRINT_DBG(BLKVSC_DRV, - enter\n);
+   return DISK_EVENT_MEDIA_CHANGE;
+}
+
+
 /* Static decl */
 static DEFINE_MUTEX(blkvsc_mutex);
 static int blkvsc_probe(struct device *dev);
@@ -251,8 +259,6 @@ static void blkvsc_shutdown(struct device *device);
 
 static int blkvsc_open(struct block_device *bdev,  fmode_t mode);
 static int blkvsc_release(struct gendisk *disk, fmode_t mode);
-static unsigned int blkvsc_check_events(struct gendisk *gd,
-   unsigned int clearing);
 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 block_device *bd, fmode_t mode,
@@ -1407,13 +1413,6 @@ static int blkvsc_release(struct gendisk *disk, fmode_t 
mode)
return 0;
 }
 
-static unsigned int blkvsc_check_events(struct gendisk *gd,
-   unsigned int clearing)
-{
-   DPRINT_DBG(BLKVSC_DRV, - enter\n);
-   return DISK_EVENT_MEDIA_CHANGE;
-}
-
 static int blkvsc_revalidate_disk(struct gendisk *gd)
 {
struct block_device_context *blkdev = gd-private_data;
-- 
1.7.4.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


[PATCH 14/22] Staging: hv: Get rid of the forward declaration of blkvsc_do_read_capacity16()

2011-04-06 Thread K. Y. Srinivasan
Get rid of the forward declaration of blkvsc_do_read_capacity16() by moving
the code around.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Abhishek Kane v-abk...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |  168 +++---
 1 files changed, 84 insertions(+), 84 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index dedb5a36..49caad7 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -777,6 +777,90 @@ static int blkvsc_do_read_capacity(struct 
block_device_context *blkdev)
return 0;
 }
 
+
+static int blkvsc_do_read_capacity16(struct block_device_context *blkdev)
+{
+   struct blkvsc_request *blkvsc_req;
+   struct page *page_buf;
+   unsigned char *buf;
+   struct scsi_sense_hdr sense_hdr;
+   struct vmscsi_request *vm_srb;
+
+   DPRINT_DBG(BLKVSC_DRV, blkvsc_do_read_capacity16()\n);
+
+   blkdev-sector_size = 0;
+   blkdev-capacity = 0;
+   blkdev-media_not_present = 0; /* assume a disk is present */
+
+   blkvsc_req = kmem_cache_zalloc(blkdev-request_pool, GFP_KERNEL);
+   if (!blkvsc_req)
+   return -ENOMEM;
+
+   memset(blkvsc_req, 0, sizeof(struct blkvsc_request));
+   vm_srb = blkvsc_req-request.vstor_packet.vm_srb;
+   page_buf = alloc_page(GFP_KERNEL);
+   if (!page_buf) {
+   kmem_cache_free(blkvsc_req-dev-request_pool, blkvsc_req);
+   return -ENOMEM;
+   }
+
+   init_completion(blkvsc_req-request.wait_event);
+   blkvsc_req-dev = blkdev;
+   blkvsc_req-req = NULL;
+   blkvsc_req-write = 0;
+
+   blkvsc_req-request.data_buffer.pfn_array[0] =
+   page_to_pfn(page_buf);
+   blkvsc_req-request.data_buffer.offset = 0;
+   blkvsc_req-request.data_buffer.len = 12;
+
+   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
+*/
+
+   blkvsc_submit_request(blkvsc_req, blkvsc_cmd_completion);
+
+   DPRINT_DBG(BLKVSC_DRV, waiting %p to complete\n,
+  blkvsc_req);
+
+   wait_for_completion_interruptible(blkvsc_req-request.wait_event);
+
+   /* check error */
+   if (vm_srb-scsi_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]);
+
+#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);
+
+   __free_page(page_buf);
+
+   kmem_cache_free(blkvsc_req-dev-request_pool, blkvsc_req);
+
+   return 0;
+}
+
 /* Static decl */
 static int blkvsc_probe(struct device *dev);
 static int blkvsc_revalidate_disk(struct gendisk *gd);
@@ -785,7 +869,6 @@ 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_do_inquiry(struct block_device_context *blkdev);
-static int blkvsc_do_read_capacity16(struct block_device_context *blkdev);
 static int blkvsc_do_pending_reqs(struct block_device_context *blkdev);
 
 static int blkvsc_ringbuffer_size = BLKVSC_RING_BUFFER_SIZE;
@@ -1119,89 +1202,6 @@ static int blkvsc_do_inquiry(struct block_device_context 
*blkdev)
return 0;
 }
 
-static int blkvsc_do_read_capacity16(struct block_device_context *blkdev)
-{
-   struct blkvsc_request *blkvsc_req;
-   struct page *page_buf;
-   unsigned char *buf;
-   struct scsi_sense_hdr sense_hdr;
-   struct vmscsi_request *vm_srb;
-
-   DPRINT_DBG(BLKVSC_DRV, blkvsc_do_read_capacity16()\n);
-
-   blkdev-sector_size = 0;
-   blkdev-capacity = 0;
-   blkdev-media_not_present = 0; /* assume a disk is present */
-
-   blkvsc_req = kmem_cache_zalloc(blkdev-request_pool, GFP_KERNEL);
-   if (!blkvsc_req)
-   return -ENOMEM;
-
-   memset(blkvsc_req, 0, sizeof(struct blkvsc_request));
-   vm_srb = blkvsc_req-request.vstor_packet.vm_srb;
-   page_buf = alloc_page(GFP_KERNEL);
-   if (!page_buf) {
-   kmem_cache_free(blkvsc_req-dev-request_pool, 

Re: Signed bit field; int have_hotplug_status_watch:1

2011-04-06 Thread David Miller
From: Ian Campbell ian.campb...@eu.citrix.com
Date: Mon, 4 Apr 2011 09:26:24 +0100

 Subject: [PATCH] xen: netback: use unsigned type for one-bit bitfield.
 
 Fixes error from sparse:
   CHECK   drivers/net/xen-netback/xenbus.c
 drivers/net/xen-netback/xenbus.c:29:40: error: dubious one-bit signed bitfield
 
 int have_hotplug_status_watch:1;
 
 Reported-by: Dr. David Alan Gilbert li...@treblig.org
 Signed-off-by: Ian Campbell ian.campb...@citrix.com

Applied to net-next-2.6, thanks.
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


Re: [PATCH] xen: drop anti-dependency on X86_VISWS

2011-04-06 Thread David Miller
From: Ian Campbell ian.campb...@eu.citrix.com
Date: Mon, 4 Apr 2011 10:55:55 +0100

 You mean the !X86_VISWS I presume? It doesn't make sense to me either.

No, I think 32-bit x86 allmodconfig elides XEN because of it's X86_TSC 
dependency.

And, well, you could type make allmodconfig on your tree and see for
yourself instead of asking me :-)
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


[PATCH 12/22] Staging: hv: Get rid of the forward declaration for blkvsc_release()

2011-04-06 Thread K. Y. Srinivasan
Get rid of the forward declaration for blkvsc_release() by moving the code
around.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Abhishek Kane v-abk...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |   45 +++
 1 files changed, 22 insertions(+), 23 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index 1fb68b7..799f5ad 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -679,9 +679,30 @@ static void blkvsc_shutdown(struct device *device)
spin_unlock_irqrestore(blkdev-lock, flags);
 }
 
+static int blkvsc_release(struct gendisk *disk, fmode_t mode)
+{
+   struct block_device_context *blkdev = disk-private_data;
+
+   DPRINT_DBG(BLKVSC_DRV, - users %d disk %s\n, blkdev-users,
+  blkdev-gd-disk_name);
+
+   mutex_lock(blkvsc_mutex);
+   spin_lock(blkdev-lock);
+   if (blkdev-users == 1) {
+   spin_unlock(blkdev-lock);
+   blkvsc_do_flush(blkdev);
+   spin_lock(blkdev-lock);
+   }
+
+   blkdev-users--;
+
+   spin_unlock(blkdev-lock);
+   mutex_unlock(blkvsc_mutex);
+   return 0;
+}
+
 /* Static decl */
 static int blkvsc_probe(struct device *dev);
-static int blkvsc_release(struct gendisk *disk, fmode_t mode);
 static int blkvsc_revalidate_disk(struct gendisk *gd);
 static void blkvsc_request(struct request_queue *queue);
 static void blkvsc_request_completion(struct hv_storvsc_request *request);
@@ -1492,28 +1513,6 @@ static void blkvsc_request(struct request_queue *queue)
}
 }
 
-static int blkvsc_release(struct gendisk *disk, fmode_t mode)
-{
-   struct block_device_context *blkdev = disk-private_data;
-
-   DPRINT_DBG(BLKVSC_DRV, - users %d disk %s\n, blkdev-users,
-  blkdev-gd-disk_name);
-
-   mutex_lock(blkvsc_mutex);
-   spin_lock(blkdev-lock);
-   if (blkdev-users == 1) {
-   spin_unlock(blkdev-lock);
-   blkvsc_do_flush(blkdev);
-   spin_lock(blkdev-lock);
-   }
-
-   blkdev-users--;
-
-   spin_unlock(blkdev-lock);
-   mutex_unlock(blkvsc_mutex);
-   return 0;
-}
-
 static int blkvsc_revalidate_disk(struct gendisk *gd)
 {
struct block_device_context *blkdev = gd-private_data;
-- 
1.7.4.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


[PATCH 04/22] Staging: hv: Get rid of the forward declaration of blkvsc_getgeo()

2011-04-06 Thread K. Y. Srinivasan
Get rid of the forward declaration of blkvsc_getgeo() by moving the code around.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Abhishek Kane v-abk...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |  162 +++---
 1 files changed, 81 insertions(+), 81 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index 173abe3..69048e3 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -275,6 +275,87 @@ static int blkvsc_open(struct block_device *bdev, fmode_t 
mode)
return 0;
 }
 
+
+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;
+
+   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;
+   /* 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;
+   /* sector_div stores the quotient in cylinder_times_heads */
+   rem = sector_div(cylinder_times_heads, sectors_per_track);
+
+   temp = cylinder_times_heads + 1023;
+   /* sector_div stores the quotient in temp */
+   rem = sector_div(temp, 1024);
+
+   heads = temp;
+
+   if (heads  4)
+   heads = 4;
+
+
+   if (cylinder_times_heads = (heads * 1024) || (heads  16)) {
+   sectors_per_track = 31;
+   heads = 16;
+
+   cylinder_times_heads = total_sectors;
+   /*
+* 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;
+
+   cylinder_times_heads = total_sectors;
+   /*
+* sector_div stores the quotient in
+* cylinder_times_heads
+*/
+   rem = sector_div(cylinder_times_heads,
+sectors_per_track);
+   }
+   }
+
+   temp = cylinder_times_heads;
+   /* 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;
+
+   DPRINT_INFO(BLKVSC_DRV, CHS (%d, %d, %d), cylinders, heads,
+   sectors_per_track);
+
+   return 0;
+}
+
 /* Static decl */
 static int blkvsc_probe(struct device *dev);
 static int blkvsc_remove(struct device *device);
@@ -282,7 +363,6 @@ static void blkvsc_shutdown(struct device *device);
 
 static int blkvsc_release(struct gendisk *disk, fmode_t mode);
 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 block_device *bd, fmode_t mode,
unsigned cmd, unsigned long argument);
 static void blkvsc_request(struct request_queue *queue);
@@ -1427,86 +1507,6 @@ static int blkvsc_revalidate_disk(struct gendisk *gd)
return 0;
 }
 
-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;
-
-   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;
-   /* 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;
-   /* 

[PATCH 06/22] Staging: hv: Get rid of the forward declaration of blkvsc_ioctl()

2011-04-06 Thread K. Y. Srinivasan
Get rid of the forward declaration of blkvsc_ioctl() by moving the code around.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Abhishek Kane v-abk...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |   56 ++
 1 files changed, 27 insertions(+), 29 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index 5f14bb6..a16f38c 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -415,6 +415,33 @@ static void blkvsc_init_rw(struct blkvsc_request 
*blkvsc_req)
 }
 
 
+static int blkvsc_ioctl(struct block_device *bd, fmode_t mode,
+   unsigned cmd, unsigned long argument)
+{
+/* struct block_device_context *blkdev = bd-bd_disk-private_data; */
+   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.
+*/
+#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))
+   ret = -EFAULT;
+   break;
+#endif
+   default:
+   ret = -EINVAL;
+   break;
+   }
+
+   return ret;
+}
+
 /* Static decl */
 static int blkvsc_probe(struct device *dev);
 static int blkvsc_remove(struct device *device);
@@ -422,8 +449,6 @@ static void blkvsc_shutdown(struct device *device);
 
 static int blkvsc_release(struct gendisk *disk, fmode_t mode);
 static int blkvsc_revalidate_disk(struct gendisk *gd);
-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(struct hv_storvsc_request *request);
 static int blkvsc_do_request(struct block_device_context *blkdev,
@@ -1508,33 +1533,6 @@ static int blkvsc_revalidate_disk(struct gendisk *gd)
return 0;
 }
 
-static int blkvsc_ioctl(struct block_device *bd, fmode_t mode,
-   unsigned cmd, unsigned long argument)
-{
-/* struct block_device_context *blkdev = bd-bd_disk-private_data; */
-   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.
-*/
-#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))
-   ret = -EFAULT;
-   break;
-#endif
-   default:
-   ret = -EINVAL;
-   break;
-   }
-
-   return ret;
-}
-
 static int __init blkvsc_init(void)
 {
int ret;
-- 
1.7.4.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


[PATCH 19/22] Staging: hv: Get rid of the forward declaration for blkvsc_request()

2011-04-06 Thread K. Y. Srinivasan
Get rid of the forward declaration for blkvsc_request() by moving the code
around.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Abhishek Kane v-abk...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |   86 +++---
 1 files changed, 43 insertions(+), 43 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index 66590f6..55ba9de 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -1170,9 +1170,51 @@ static int blkvsc_do_pending_reqs(struct 
block_device_context *blkdev)
return ret;
 }
 
+
+static void blkvsc_request(struct request_queue *queue)
+{
+   struct block_device_context *blkdev = NULL;
+   struct request *req;
+   int ret = 0;
+
+   DPRINT_DBG(BLKVSC_DRV, - enter\n);
+   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 || req-cmd_type != REQ_TYPE_FS ||
+   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);
+   blk_stop_queue(queue);
+   break;
+   }
+
+   blk_start_request(req);
+
+   ret = blkvsc_do_request(blkdev, req);
+   if (ret  0) {
+   DPRINT_DBG(BLKVSC_DRV, - stop queue - no room\n);
+   blk_stop_queue(queue);
+   break;
+   } else if (ret  0) {
+   DPRINT_DBG(BLKVSC_DRV, - stop queue - no mem\n);
+   blk_requeue_request(queue, req);
+   blk_stop_queue(queue);
+   break;
+   }
+   }
+}
+
 /* Static decl */
 static int blkvsc_probe(struct device *dev);
-static void blkvsc_request(struct request_queue *queue);
 
 static int blkvsc_ringbuffer_size = BLKVSC_RING_BUFFER_SIZE;
 module_param(blkvsc_ringbuffer_size, int, S_IRUGO);
@@ -1500,48 +1542,6 @@ static void blkvsc_request_completion(struct 
hv_storvsc_request *request)
spin_unlock_irqrestore(blkdev-lock, flags);
 }
 
-static void blkvsc_request(struct request_queue *queue)
-{
-   struct block_device_context *blkdev = NULL;
-   struct request *req;
-   int ret = 0;
-
-   DPRINT_DBG(BLKVSC_DRV, - enter\n);
-   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 || req-cmd_type != REQ_TYPE_FS ||
-   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);
-   blk_stop_queue(queue);
-   break;
-   }
-
-   blk_start_request(req);
-
-   ret = blkvsc_do_request(blkdev, req);
-   if (ret  0) {
-   DPRINT_DBG(BLKVSC_DRV, - stop queue - no room\n);
-   blk_stop_queue(queue);
-   break;
-   } else if (ret  0) {
-   DPRINT_DBG(BLKVSC_DRV, - stop queue - no mem\n);
-   blk_requeue_request(queue, req);
-   blk_stop_queue(queue);
-   break;
-   }
-   }
-}
-
 static int __init blkvsc_init(void)
 {
int ret;
-- 
1.7.4.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


[PATCH 07/22] Staging: hv: Get rid of the forward declaration of blkvsc_cmd_completion()

2011-04-06 Thread K. Y. Srinivasan
Get rid of the forward declaration of blkvsc_cmd_completion() by moving the
code  around.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Abhishek Kane v-abk...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |   48 +++---
 1 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index a16f38c..068daee 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -442,6 +442,30 @@ static int blkvsc_ioctl(struct block_device *bd, fmode_t 
mode,
return ret;
 }
 
+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 scsi_sense_hdr sense_hdr;
+   struct vmscsi_request *vm_srb;
+
+   DPRINT_DBG(BLKVSC_DRV, blkvsc_cmd_completion() - req %p\n,
+  blkvsc_req);
+
+   vm_srb = blkvsc_req-request.vstor_packet.vm_srb;
+   blkdev-num_outstanding_reqs--;
+
+   if (vm_srb-scsi_status)
+   if (scsi_normalize_sense(blkvsc_req-sense_buffer,
+SCSI_SENSE_BUFFERSIZE, sense_hdr))
+   scsi_print_sense_hdr(blkvsc, sense_hdr);
+
+   complete(blkvsc_req-request.wait_event);
+}
+
+
 /* Static decl */
 static int blkvsc_probe(struct device *dev);
 static int blkvsc_remove(struct device *device);
@@ -453,7 +477,6 @@ 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 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);
@@ -1257,29 +1280,6 @@ static int blkvsc_do_request(struct block_device_context 
*blkdev,
return pending;
 }
 
-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 scsi_sense_hdr sense_hdr;
-   struct vmscsi_request *vm_srb;
-
-   DPRINT_DBG(BLKVSC_DRV, blkvsc_cmd_completion() - req %p\n,
-  blkvsc_req);
-
-   vm_srb = blkvsc_req-request.vstor_packet.vm_srb;
-   blkdev-num_outstanding_reqs--;
-
-   if (vm_srb-scsi_status)
-   if (scsi_normalize_sense(blkvsc_req-sense_buffer,
-SCSI_SENSE_BUFFERSIZE, sense_hdr))
-   scsi_print_sense_hdr(blkvsc, sense_hdr);
-
-   complete(blkvsc_req-request.wait_event);
-}
-
 static void blkvsc_request_completion(struct hv_storvsc_request *request)
 {
struct blkvsc_request *blkvsc_req =
-- 
1.7.4.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


[PATCH 10/22] Staging: hv: Get rid of the forward declaration of blkvsc_remove()

2011-04-06 Thread K. Y. Srinivasan
Get rid of the forward declaration of blkvsc_remove() by moving the code around.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Abhishek Kane v-abk...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |  130 +++---
 1 files changed, 65 insertions(+), 65 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index 2829266..a98ed8f 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -580,9 +580,73 @@ out:
return ret;
 }
 
+
+/*
+ * blkvsc_remove() - Callback when our device is removed
+ */
+static int blkvsc_remove(struct device *device)
+{
+   struct hv_driver *drv =
+   drv_to_hv_drv(device-driver);
+   struct storvsc_driver_object *storvsc_drv_obj =
+   drv-priv;
+   struct hv_device *device_obj = device_to_hv_device(device);
+   struct block_device_context *blkdev = dev_get_drvdata(device);
+   unsigned long flags;
+   int ret;
+
+   DPRINT_DBG(BLKVSC_DRV, blkvsc_remove()\n);
+
+   if (!storvsc_drv_obj-base.dev_rm)
+   return -1;
+
+   /*
+* Call to the vsc driver to let it know that the device is being
+* removed
+*/
+   ret = storvsc_drv_obj-base.dev_rm(device_obj);
+   if (ret != 0) {
+   /* TODO: */
+   DPRINT_ERR(BLKVSC_DRV,
+  unable to remove blkvsc device (ret %d), ret);
+   }
+
+   /* Get to a known state */
+   spin_lock_irqsave(blkdev-lock, flags);
+
+   blkdev-shutting_down = 1;
+
+   blk_stop_queue(blkdev-gd-queue);
+
+   spin_unlock_irqrestore(blkdev-lock, flags);
+
+   while (blkdev-num_outstanding_reqs) {
+   DPRINT_INFO(STORVSC, waiting for %d requests to complete...,
+   blkdev-num_outstanding_reqs);
+   udelay(100);
+   }
+
+   blkvsc_do_flush(blkdev);
+
+   spin_lock_irqsave(blkdev-lock, flags);
+
+   blkvsc_cancel_pending_reqs(blkdev);
+
+   spin_unlock_irqrestore(blkdev-lock, flags);
+
+   blk_cleanup_queue(blkdev-gd-queue);
+
+   del_gendisk(blkdev-gd);
+
+   kmem_cache_destroy(blkdev-request_pool);
+
+   kfree(blkdev);
+
+   return ret;
+}
+
 /* 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_release(struct gendisk *disk, fmode_t mode);
@@ -1120,70 +1184,6 @@ static int blkvsc_do_read_capacity16(struct 
block_device_context *blkdev)
 }
 
 /*
- * blkvsc_remove() - Callback when our device is removed
- */
-static int blkvsc_remove(struct device *device)
-{
-   struct hv_driver *drv =
-   drv_to_hv_drv(device-driver);
-   struct storvsc_driver_object *storvsc_drv_obj =
-   drv-priv;
-   struct hv_device *device_obj = device_to_hv_device(device);
-   struct block_device_context *blkdev = dev_get_drvdata(device);
-   unsigned long flags;
-   int ret;
-
-   DPRINT_DBG(BLKVSC_DRV, blkvsc_remove()\n);
-
-   if (!storvsc_drv_obj-base.dev_rm)
-   return -1;
-
-   /*
-* Call to the vsc driver to let it know that the device is being
-* removed
-*/
-   ret = storvsc_drv_obj-base.dev_rm(device_obj);
-   if (ret != 0) {
-   /* TODO: */
-   DPRINT_ERR(BLKVSC_DRV,
-  unable to remove blkvsc device (ret %d), ret);
-   }
-
-   /* Get to a known state */
-   spin_lock_irqsave(blkdev-lock, flags);
-
-   blkdev-shutting_down = 1;
-
-   blk_stop_queue(blkdev-gd-queue);
-
-   spin_unlock_irqrestore(blkdev-lock, flags);
-
-   while (blkdev-num_outstanding_reqs) {
-   DPRINT_INFO(STORVSC, waiting for %d requests to complete...,
-   blkdev-num_outstanding_reqs);
-   udelay(100);
-   }
-
-   blkvsc_do_flush(blkdev);
-
-   spin_lock_irqsave(blkdev-lock, flags);
-
-   blkvsc_cancel_pending_reqs(blkdev);
-
-   spin_unlock_irqrestore(blkdev-lock, flags);
-
-   blk_cleanup_queue(blkdev-gd-queue);
-
-   del_gendisk(blkdev-gd);
-
-   kmem_cache_destroy(blkdev-request_pool);
-
-   kfree(blkdev);
-
-   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.
-- 
1.7.4.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


[PATCH 13/22] Staging: hv: Get rid of the forward declaration for blkvsc_do_read_capacity()

2011-04-06 Thread K. Y. Srinivasan
Get rid of the forward declaration for blkvsc_do_read_capacity() by moving
the code around.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Abhishek Kane v-abk...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |  152 +++---
 1 files changed, 76 insertions(+), 76 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index 799f5ad..dedb5a36 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -701,6 +701,82 @@ static int blkvsc_release(struct gendisk *disk, fmode_t 
mode)
return 0;
 }
 
+
+/* 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;
+   struct page *page_buf;
+   unsigned char *buf;
+   struct scsi_sense_hdr sense_hdr;
+   struct vmscsi_request *vm_srb;
+
+   DPRINT_DBG(BLKVSC_DRV, blkvsc_do_read_capacity()\n);
+
+   blkdev-sector_size = 0;
+   blkdev-capacity = 0;
+   blkdev-media_not_present = 0; /* assume a disk is present */
+
+   blkvsc_req = kmem_cache_zalloc(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) {
+   kmem_cache_free(blkvsc_req-dev-request_pool, blkvsc_req);
+   return -ENOMEM;
+   }
+
+   vm_srb = blkvsc_req-request.vstor_packet.vm_srb;
+   init_completion(blkvsc_req-request.wait_event);
+   blkvsc_req-dev = blkdev;
+   blkvsc_req-req = NULL;
+   blkvsc_req-write = 0;
+
+   blkvsc_req-request.data_buffer.pfn_array[0] =
+   page_to_pfn(page_buf);
+   blkvsc_req-request.data_buffer.offset = 0;
+   blkvsc_req-request.data_buffer.len = 8;
+
+   blkvsc_req-cmnd[0] = READ_CAPACITY;
+   blkvsc_req-cmd_len = 16;
+
+   blkvsc_submit_request(blkvsc_req, blkvsc_cmd_completion);
+
+   DPRINT_DBG(BLKVSC_DRV, waiting %p to complete\n,
+  blkvsc_req);
+
+   wait_for_completion_interruptible(blkvsc_req-request.wait_event);
+
+   /* check error */
+   if (vm_srb-scsi_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 = ((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);
+
+   __free_page(page_buf);
+
+   kmem_cache_free(blkvsc_req-dev-request_pool, blkvsc_req);
+
+   return 0;
+}
+
 /* Static decl */
 static int blkvsc_probe(struct device *dev);
 static int blkvsc_revalidate_disk(struct gendisk *gd);
@@ -709,7 +785,6 @@ 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_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);
 static int blkvsc_do_pending_reqs(struct block_device_context *blkdev);
 
@@ -1044,81 +1119,6 @@ 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 */
-static int blkvsc_do_read_capacity(struct block_device_context *blkdev)
-{
-   struct blkvsc_request *blkvsc_req;
-   struct page *page_buf;
-   unsigned char *buf;
-   struct scsi_sense_hdr sense_hdr;
-   struct vmscsi_request *vm_srb;
-
-   DPRINT_DBG(BLKVSC_DRV, blkvsc_do_read_capacity()\n);
-
-   blkdev-sector_size = 0;
-   blkdev-capacity = 0;
-   blkdev-media_not_present = 0; /* assume a disk is present */
-
-   blkvsc_req = kmem_cache_zalloc(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) {
-   kmem_cache_free(blkvsc_req-dev-request_pool, blkvsc_req);
-   return -ENOMEM;
-   }
-
-   vm_srb = blkvsc_req-request.vstor_packet.vm_srb;
-   init_completion(blkvsc_req-request.wait_event);
-   blkvsc_req-dev = blkdev;
-   blkvsc_req-req = NULL;
- 

[PATCH 17/22] Staging: hv: Get rid of the forward declaration for blkvsc_do_request()

2011-04-06 Thread K. Y. Srinivasan
Get rid of the forward declaration for blkvsc_do_request() by moving the
code around.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Abhishek Kane v-abk...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |  370 ---
 1 files changed, 193 insertions(+), 177 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index f7bf42f..9d4fcbd 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -118,6 +118,12 @@ static const struct hv_guid g_blk_device_type = {
}
 };
 
+/*
+ * There is a circular dependency involving blkvsc_request_completion()
+ * and blkvsc_do_request().
+ */
+static void blkvsc_request_completion(struct hv_storvsc_request *request);
+
 static int blk_vsc_on_device_add(struct hv_device *device,
void *additional_info)
 {
@@ -955,12 +961,196 @@ static int blkvsc_do_inquiry(struct block_device_context 
*blkdev)
return 0;
 }
 
+
+/*
+ * 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;
+   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;
+   sector_t start_sector;
+   unsigned long num_sectors = 0;
+   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));
+
+   /* Create a group to tie req to list of blkvsc_reqs */
+   group = kmem_cache_zalloc(blkdev-request_pool, GFP_ATOMIC);
+   if (!group)
+   return -ENOMEM;
+
+   INIT_LIST_HEAD(group-blkvsc_req_list);
+   group-outstanding = group-status = 0;
+
+   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 */
+   /* 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_init_rw(blkvsc_req);
+   }
+
+   /*
+* Create new blkvsc_req to represent
+* the current bvec
+*/
+   blkvsc_req =
+   kmem_cache_zalloc(
+   blkdev-request_pool, GFP_ATOMIC);
+   if (!blkvsc_req) {
+   /* free up everything */
+   list_for_each_entry_safe(
+   blkvsc_req, tmp,

[RESEND][PATCH 00/22] Staging: hv: Cleanup storage drivers - Phase IV

2011-04-06 Thread K. Y. Srinivasan
The latest upstream merge changed struct block_device_operations:
This merge got rid of blkvsc_media_changed and introduced the
function blkvsc_check_events. This broke all the patches that
were sent after the tree was closed the last time. This is a resend of
this patch-set to account for this change in the kernel.


More cleanup. In this patch-set we deal with the following issues:

1) While a Linux guest on Hyper-V can be assigned removable media
   devices (DVD, floppy etc), these devices are not handled by the
   Hyper-V block driver. So, we cleanup all the dead code
   dealing with removable media devices.

2) There were multiple functions to retrieve information about 
   the device. Since much of the code in these functions were
   identical, we have consolidated these functions into a single
   function.

3) Enable the ioctl code for handling HDIO_GET_IDENTITY

4) Cleanup the code for getting the geometry.

5) Cleanup code for retreiving device capacity; this has also fixed
   a bug with regards to presenting physical disks to the guest
   as an IDE disk.

6) General cleanup: simplify blkvsc_init_rw(), get rid of 
   unnecessary DPRINT*() calls, get rid of unnecessary code,
   cleanup blkvsc_open().

7) Remove all IDE details from blkvsc_drv.c.

Regards,

K. Y
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


RE: [PATCH 00/22] Staging: hv: Cleanup-storage-drivers-phase-III

2011-04-06 Thread KY Srinivasan


 -Original Message-
 From: Greg KH [mailto:g...@kroah.com]
 Sent: Tuesday, April 05, 2011 11:11 AM
 To: KY Srinivasan
 Cc: gre...@suse.de; linux-ker...@vger.kernel.org;
 de...@linuxdriverproject.org; virtualizat...@lists.osdl.org
 Subject: Re: [PATCH 00/22] Staging: hv: Cleanup-storage-drivers-phase-III
 
 
 A: No.
 Q: Should I include quotations after my reply?
 
 http://daringfireball.net/2007/07/on_top
 
 
 On Tue, Apr 05, 2011 at 01:58:37PM +, KY Srinivasan wrote:
  Sorry for the confusion Greg. I reworked some patches in Phase-II
  cleanup and I was meaning to resend them before you began applying the
  patches, That is the reason for the problem you are encountering.
 
 Huh?  I applied them in the order you sent them to me, how would that
 cause a patch to fail to apply properly?
 
  I
  just resent the Phase II series. If you can back out the phase II that
  you have applied and apply the ones I resent, everything should apply
  cleanly. Once again, I sorry for creating additional work for you.
 
 I can't back out anything, sorry.  I'll drop any pending patches you
 have sent me now.  Please resync with my staging git tree and resend
 them to properly apply and work.

Greg,

An upstream merge that occurred after the last tree closure was the cause of 
some of my patches not applying. I have fixed up all the patches and resent 
them for your consideration.

Regards,

K. Y

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


[PATCH 10/22] Staging: hv: Simplify blkvsc_init_rw()

2011-04-06 Thread K. Y. Srinivasan
Simplyfify blkvsc_init_rw() by using a single scsi command independent of
the start sector.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |   58 +--
 1 files changed, 13 insertions(+), 45 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index b2cd04a..5cf82f0 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -305,53 +305,21 @@ static void blkvsc_init_rw(struct blkvsc_request 
*blkvsc_req)
 
blkvsc_req-cmd_len = 16;
 
-   if (blkvsc_req-sector_start  0x) {
-   if (rq_data_dir(blkvsc_req-req)) {
-   blkvsc_req-write = 1;
-   blkvsc_req-cmnd[0] = WRITE_16;
-   } else {
-   blkvsc_req-write = 0;
-   blkvsc_req-cmnd[0] = READ_16;
-   }
-
-   blkvsc_req-cmnd[1] |=
-   (blkvsc_req-req-cmd_flags  REQ_FUA) ? 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  0x1f)) {
-   if (rq_data_dir(blkvsc_req-req)) {
-   blkvsc_req-write = 1;
-   blkvsc_req-cmnd[0] = WRITE_10;
-   } else {
-   blkvsc_req-write = 0;
-   blkvsc_req-cmnd[0] = READ_10;
-   }
-
-   blkvsc_req-cmnd[1] |=
-   (blkvsc_req-req-cmd_flags  REQ_FUA) ? 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);
+   if (rq_data_dir(blkvsc_req-req)) {
+   blkvsc_req-write = 1;
+   blkvsc_req-cmnd[0] = WRITE_16;
} else {
-   if (rq_data_dir(blkvsc_req-req)) {
-   blkvsc_req-write = 1;
-   blkvsc_req-cmnd[0] = WRITE_6;
-   } 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;
-   blkvsc_req-cmnd[1] = 0x1f;
-   blkvsc_req-cmnd[4] = (unsigned char)blkvsc_req-sector_count;
+   blkvsc_req-write = 0;
+   blkvsc_req-cmnd[0] = READ_16;
}
+
+   blkvsc_req-cmnd[1] |=
+   (blkvsc_req-req-cmd_flags  REQ_FUA) ? 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);
 }
 
 
-- 
1.7.4.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


[PATCH 07/22] Staging: hv: Get rid of the function blkvsc_do_flush()

2011-04-06 Thread K. Y. Srinivasan
Get rid of the function blkvsc_do_flush() and instead use the common function
to force a device flush.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |   52 ++
 1 files changed, 14 insertions(+), 38 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index 7fab3c7..a7ae437 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -49,6 +49,7 @@ enum blkvsc_device_type {
 enum blkvsc_op_type {
DO_INQUIRY,
DO_CAPACITY,
+   DO_FLUSH,
 };
 
 /*
@@ -451,6 +452,13 @@ static int blkvsc_do_operation(struct block_device_context 
*blkdev,
blkvsc_req-cmd_len = 16;
blkvsc_req-request.data_buffer.len = 8;
break;
+
+   case DO_FLUSH:
+   blkvsc_req-cmnd[0] = SYNCHRONIZE_CACHE;
+   blkvsc_req-cmd_len = 10;
+   blkvsc_req-request.data_buffer.pfn_array[0] = 0;
+   blkvsc_req-request.data_buffer.len = 0;
+   break;
default:
ret = -EINVAL;
goto cleanup;
@@ -502,6 +510,9 @@ static int blkvsc_do_operation(struct block_device_context 
*blkdev,
(buf[4]  24) | (buf[5]  16) |
(buf[6]  8) | buf[7];
break;
+   default:
+   break;
+
}
 
 cleanup:
@@ -515,41 +526,6 @@ cleanup:
return ret;
 }
 
-static int blkvsc_do_flush(struct block_device_context *blkdev)
-{
-   struct blkvsc_request *blkvsc_req;
-
-   DPRINT_DBG(BLKVSC_DRV, blkvsc_do_flush()\n);
-
-   if (blkdev-device_type != HARDDISK_TYPE)
-   return 0;
-
-   blkvsc_req = kmem_cache_zalloc(blkdev-request_pool, GFP_KERNEL);
-   if (!blkvsc_req)
-   return -ENOMEM;
-
-   memset(blkvsc_req, 0, sizeof(struct blkvsc_request));
-   init_completion(blkvsc_req-request.wait_event);
-   blkvsc_req-dev = blkdev;
-   blkvsc_req-req = NULL;
-   blkvsc_req-write = 0;
-
-   blkvsc_req-request.data_buffer.pfn_array[0] = 0;
-   blkvsc_req-request.data_buffer.offset = 0;
-   blkvsc_req-request.data_buffer.len = 0;
-
-   blkvsc_req-cmnd[0] = SYNCHRONIZE_CACHE;
-   blkvsc_req-cmd_len = 10;
-
-   blkvsc_submit_request(blkvsc_req, blkvsc_cmd_completion);
-
-   wait_for_completion_interruptible(blkvsc_req-request.wait_event);
-
-   kmem_cache_free(blkvsc_req-dev-request_pool, blkvsc_req);
-
-   return 0;
-}
-
 
 static int blkvsc_cancel_pending_reqs(struct block_device_context *blkdev)
 {
@@ -676,7 +652,7 @@ static int blkvsc_remove(struct device *device)
udelay(100);
}
 
-   blkvsc_do_flush(blkdev);
+   blkvsc_do_operation(blkdev, DO_FLUSH);
 
spin_lock_irqsave(blkdev-lock, flags);
 
@@ -720,7 +696,7 @@ static void blkvsc_shutdown(struct device *device)
udelay(100);
}
 
-   blkvsc_do_flush(blkdev);
+   blkvsc_do_operation(blkdev, DO_FLUSH);
 
spin_lock_irqsave(blkdev-lock, flags);
 
@@ -740,7 +716,7 @@ static int blkvsc_release(struct gendisk *disk, fmode_t 
mode)
spin_lock(blkdev-lock);
if (blkdev-users == 1) {
spin_unlock(blkdev-lock);
-   blkvsc_do_flush(blkdev);
+   blkvsc_do_operation(blkdev, DO_FLUSH);
spin_lock(blkdev-lock);
}
 
-- 
1.7.4.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


[PATCH 14/22] Staging: hv: Cleanup storvsc_remove()

2011-04-06 Thread K. Y. Srinivasan
storvsc_remove() cannot fail, clean it up accordingly.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/storvsc_drv.c |   14 ++
 1 files changed, 2 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/hv/storvsc_drv.c b/drivers/staging/hv/storvsc_drv.c
index ae61735..f819c6a 100644
--- a/drivers/staging/hv/storvsc_drv.c
+++ b/drivers/staging/hv/storvsc_drv.c
@@ -404,7 +404,6 @@ static int storvsc_probe(struct device *device)
  */
 static int storvsc_remove(struct device *device)
 {
-   int ret;
struct hv_driver *drv =
drv_to_hv_drv(device-driver);
struct storvsc_driver_object *storvsc_drv_obj = drv-priv;
@@ -413,20 +412,11 @@ static int storvsc_remove(struct device *device)
struct host_device_context *host_device_ctx =
(struct host_device_context *)host-hostdata;
 
-
-   if (!storvsc_drv_obj-base.dev_rm)
-   return -1;
-
/*
 * Call to the vsc driver to let it know that the device is being
 * removed
 */
-   ret = storvsc_drv_obj-base.dev_rm(device_obj);
-   if (ret != 0) {
-   /* TODO: */
-   DPRINT_ERR(STORVSC, unable to remove vsc device (ret %d),
-  ret);
-   }
+   storvsc_drv_obj-base.dev_rm(device_obj);
 
if (host_device_ctx-request_pool) {
kmem_cache_destroy(host_device_ctx-request_pool);
@@ -438,7 +428,7 @@ static int storvsc_remove(struct device *device)
 
DPRINT_INFO(STORVSC, releasing host adapter (%p)..., host);
scsi_host_put(host);
-   return ret;
+   return 0;
 }
 
 /*
-- 
1.7.4.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


[PATCH 03/22] Staging: hv: Simplify the code for blkvsc_getgeo()

2011-04-06 Thread K. Y. Srinivasan
We are making up the geometry anyway, keep it simple.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |   84 +-
 1 files changed, 11 insertions(+), 73 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index 3b47495..f5cc522 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -278,82 +278,20 @@ static int blkvsc_open(struct block_device *bdev, fmode_t 
mode)
 
 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 nsect = get_capacity(bd-bd_disk);
+   sector_t cylinders = nsect;
 
-   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;
-   /* 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;
-   /* sector_div stores the quotient in cylinder_times_heads */
-   rem = sector_div(cylinder_times_heads, sectors_per_track);
-
-   temp = cylinder_times_heads + 1023;
-   /* sector_div stores the quotient in temp */
-   rem = sector_div(temp, 1024);
-
-   heads = temp;
-
-   if (heads  4)
-   heads = 4;
-
-
-   if (cylinder_times_heads = (heads * 1024) || (heads  16)) {
-   sectors_per_track = 31;
-   heads = 16;
-
-   cylinder_times_heads = total_sectors;
-   /*
-* 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;
-
-   cylinder_times_heads = total_sectors;
-   /*
-* sector_div stores the quotient in
-* cylinder_times_heads
-*/
-   rem = sector_div(cylinder_times_heads,
-sectors_per_track);
-   }
-   }
-
-   temp = cylinder_times_heads;
-   /* sector_div stores the quotient in temp */
-   rem = sector_div(temp, heads);
-   cylinders = temp;
-
-   hg-heads = heads;
-   hg-sectors = sectors_per_track;
+   /*
+* We are making up these values; let us keep it simple.
+*/
+   hg-heads = 0xff;
+   hg-sectors = 0x3f;
+   sector_div(cylinders, hg-heads * hg-sectors);
hg-cylinders = cylinders;
-
-   DPRINT_INFO(BLKVSC_DRV, CHS (%d, %d, %d), cylinders, heads,
-   sectors_per_track);
-
+   if ((sector_t)(hg-cylinders + 1) * hg-heads * hg-sectors  nsect)
+   hg-cylinders = 0x;
return 0;
+
 }
 
 
-- 
1.7.4.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


[PATCH 08/22] Staging: hv: Get rid of the state media_not_present

2011-04-06 Thread K. Y. Srinivasan
The block driver in Hyper-V does not handle removable media, get rid of the
media_not_present state.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |9 +
 1 files changed, 1 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index a7ae437..4c248b7 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -103,7 +103,6 @@ struct block_device_context {
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;
@@ -446,7 +445,6 @@ static int blkvsc_do_operation(struct block_device_context 
*blkdev,
case DO_CAPACITY:
blkdev-sector_size = 0;
blkdev-capacity = 0;
-   blkdev-media_not_present = 0; /* assume a disk is present */
 
blkvsc_req-cmnd[0] = READ_CAPACITY;
blkvsc_req-cmd_len = 16;
@@ -473,10 +471,6 @@ static int blkvsc_do_operation(struct block_device_context 
*blkdev,
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;
}
 
@@ -964,8 +958,7 @@ static void blkvsc_request(struct request_queue *queue)
DPRINT_DBG(BLKVSC_DRV, - req %p\n, req);
 
blkdev = req-rq_disk-private_data;
-   if (blkdev-shutting_down || req-cmd_type != REQ_TYPE_FS ||
-   blkdev-media_not_present) {
+   if (blkdev-shutting_down || req-cmd_type != REQ_TYPE_FS) {
__blk_end_request_cur(req, 0);
continue;
}
-- 
1.7.4.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


[PATCH 16/22] Staging: hv: Get rid of some DPRINT_ERR() calls

2011-04-06 Thread K. Y. Srinivasan
Get rid of some DPRINT_ERR() calls.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |9 +++--
 1 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index 92614d5..35ad3d5 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -17,6 +17,8 @@
  * Authors:
  *   Haiyang Zhang haiya...@microsoft.com
  *   Hank Janssen  hjans...@microsoft.com
+ *
+ * 4/3/2011: K. Y. Srinivasan - Significant restructuring and cleanup.
  */
 #include linux/init.h
 #include linux/module.h
@@ -967,7 +969,6 @@ static int blkvsc_probe(struct device *device)
 
 
if (!storvsc_drv_obj-base.dev_add) {
-   DPRINT_ERR(BLKVSC_DRV, OnDeviceAdd() not set);
ret = -1;
goto Cleanup;
}
@@ -995,10 +996,8 @@ static int blkvsc_probe(struct device *device)
 
/* Call to the vsc driver to add the device */
ret = storvsc_drv_obj-base.dev_add(device_obj, device_info);
-   if (ret != 0) {
-   DPRINT_ERR(BLKVSC_DRV, unable to add blkvsc device);
+   if (ret != 0)
goto Cleanup;
-   }
 
blkdev-device_ctx = device_obj;
/* this identified the device 0 or 1 */
@@ -1040,7 +1039,6 @@ static int blkvsc_probe(struct device *device)
ide1_registered = 1;
}
} else {
-   DPRINT_ERR(BLKVSC_DRV, invalid pathid);
ret = -1;
goto Cleanup;
}
@@ -1049,7 +1047,6 @@ static int blkvsc_probe(struct device *device)
 
blkdev-gd = alloc_disk(BLKVSC_MINORS);
if (!blkdev-gd) {
-   DPRINT_ERR(BLKVSC_DRV, register_blkdev() failed! ret %d, ret);
ret = -1;
goto Cleanup;
}
-- 
1.7.4.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


[PATCH 04/22] Staging: hv: Introduce a common function for issuing commands to the device

2011-04-06 Thread K. Y. Srinivasan
There are multiple functions to either get info about the device
(INQUIRY, CAPACITY etc) or to FLUSH the device cache. The majority of the
code for these functions is identical. Introduce a common function for
doing all these operations.


Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |  163 --
 1 files changed, 86 insertions(+), 77 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index f5cc522..9dbba3c 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -46,6 +46,10 @@ enum blkvsc_device_type {
DVD_TYPE,
 };
 
+enum blkvsc_op_type {
+   DO_INQUIRY,
+};
+
 /*
  * This request ties the struct request and struct
  * blkvsc_request/hv_storvsc_request together A struct request may be
@@ -394,6 +398,86 @@ static void blkvsc_cmd_completion(struct 
hv_storvsc_request *request)
complete(blkvsc_req-request.wait_event);
 }
 
+
+static int blkvsc_do_operation(struct block_device_context *blkdev,
+   enum blkvsc_op_type op)
+{
+   struct blkvsc_request *blkvsc_req;
+   struct page *page_buf;
+   unsigned char *buf;
+   unsigned char device_type;
+   int ret = 0;
+
+   blkvsc_req = kmem_cache_zalloc(blkdev-request_pool, GFP_KERNEL);
+   if (!blkvsc_req)
+   return -ENOMEM;
+
+   page_buf = alloc_page(GFP_KERNEL);
+   if (!page_buf) {
+   kmem_cache_free(blkvsc_req-dev-request_pool, blkvsc_req);
+   return -ENOMEM;
+   }
+
+   init_completion(blkvsc_req-request.wait_event);
+   blkvsc_req-dev = blkdev;
+   blkvsc_req-req = NULL;
+   blkvsc_req-write = 0;
+
+   blkvsc_req-request.data_buffer.pfn_array[0] =
+   page_to_pfn(page_buf);
+   blkvsc_req-request.data_buffer.offset = 0;
+
+   switch (op) {
+   case DO_INQUIRY:
+   blkvsc_req-cmnd[0] = INQUIRY;
+   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;
+   blkvsc_req-request.data_buffer.len = 64;
+   break;
+
+   default:
+   ret = -EINVAL;
+   goto cleanup;
+   }
+
+   blkvsc_submit_request(blkvsc_req, blkvsc_cmd_completion);
+
+   wait_for_completion_interruptible(blkvsc_req-request.wait_event);
+
+   buf = kmap(page_buf);
+
+   switch (op) {
+   case DO_INQUIRY:
+   device_type = buf[0]  0x1F;
+
+   if (device_type == 0x0)
+   blkdev-device_type = HARDDISK_TYPE;
+else if (device_type == 0x5)
+   blkdev-device_type = DVD_TYPE;
+else
+   blkdev-device_type = UNKNOWN_DEV_TYPE;
+
+   blkdev-device_id_len = buf[7];
+   if (blkdev-device_id_len  64)
+   blkdev-device_id_len = 64;
+
+   memcpy(blkdev-device_id, buf[8], blkdev-device_id_len);
+   break;
+   }
+
+cleanup:
+
+   kunmap(page_buf);
+
+   __free_page(page_buf);
+
+   kmem_cache_free(blkvsc_req-dev-request_pool, blkvsc_req);
+
+   return ret;
+}
+
 static int blkvsc_do_flush(struct block_device_context *blkdev)
 {
struct blkvsc_request *blkvsc_req;
@@ -799,82 +883,6 @@ static int blkvsc_revalidate_disk(struct gendisk *gd)
 }
 
 
-/* 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;
-   struct page *page_buf;
-   unsigned char *buf;
-   unsigned char device_type;
-
-   DPRINT_DBG(BLKVSC_DRV, blkvsc_do_inquiry()\n);
-
-   blkvsc_req = kmem_cache_zalloc(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) {
-   kmem_cache_free(blkvsc_req-dev-request_pool, blkvsc_req);
-   return -ENOMEM;
-   }
-
-   init_completion(blkvsc_req-request.wait_event);
-   blkvsc_req-dev = blkdev;
-   blkvsc_req-req = NULL;
-   blkvsc_req-write = 0;
-
-   blkvsc_req-request.data_buffer.pfn_array[0] =
-   page_to_pfn(page_buf);
-   blkvsc_req-request.data_buffer.offset = 0;
-   blkvsc_req-request.data_buffer.len = 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[4] = 64;
-   blkvsc_req-cmd_len = 6;
-
-   

[PATCH 02/22] Staging: hv: Enable blkvsc_ioctl()

2011-04-06 Thread K. Y. Srinivasan
We can support HDIO_GET_IDENTITY ioctl, enable blkvsc_ioctl().

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |   11 +++
 1 files changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index 3a344d2..3b47495 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -413,23 +413,18 @@ static void blkvsc_init_rw(struct blkvsc_request 
*blkvsc_req)
 
 
 static int blkvsc_ioctl(struct block_device *bd, fmode_t mode,
-   unsigned cmd, unsigned long argument)
+   unsigned cmd, unsigned long arg)
 {
-   int ret;
+   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.
-*/
-#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))
ret = -EFAULT;
break;
-#endif
default:
ret = -EINVAL;
break;
-- 
1.7.4.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


[PATCH 19/22] Staging: hv: Fix a jump label (Cleanup) in blkvsc_drv

2011-04-06 Thread K. Y. Srinivasan
One of the goto labels was named Cleanup; change it to cleanup.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |   12 ++--
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index bf8647e..a47581c 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -963,7 +963,7 @@ static int blkvsc_probe(struct device *device)
blkdev = kzalloc(sizeof(struct block_device_context), GFP_KERNEL);
if (!blkdev) {
ret = -ENOMEM;
-   goto Cleanup;
+   goto cleanup;
}
 
INIT_LIST_HEAD(blkdev-pending_list);
@@ -977,14 +977,14 @@ static int blkvsc_probe(struct device *device)
SLAB_HWCACHE_ALIGN, NULL);
if (!blkdev-request_pool) {
ret = -ENOMEM;
-   goto Cleanup;
+   goto cleanup;
}
 
 
/* Call to the vsc driver to add the device */
ret = storvsc_drv_obj-base.dev_add(device_obj, device_info);
if (ret != 0)
-   goto Cleanup;
+   goto cleanup;
 
blkdev-device_ctx = device_obj;
/* this identified the device 0 or 1 */
@@ -1027,7 +1027,7 @@ static int blkvsc_probe(struct device *device)
}
} else {
ret = -1;
-   goto Cleanup;
+   goto cleanup;
}
 
DPRINT_INFO(BLKVSC_DRV, blkvsc registered for major %d!!, major);
@@ -1035,7 +1035,7 @@ static int blkvsc_probe(struct device *device)
blkdev-gd = alloc_disk(BLKVSC_MINORS);
if (!blkdev-gd) {
ret = -1;
-   goto Cleanup;
+   goto cleanup;
}
 
blkdev-gd-queue = blk_init_queue(blkvsc_request, blkdev-lock);
@@ -1074,7 +1074,7 @@ static int blkvsc_probe(struct device *device)
 Remove:
storvsc_drv_obj-base.dev_rm(device_obj);
 
-Cleanup:
+cleanup:
if (blkdev) {
if (blkdev-request_pool) {
kmem_cache_destroy(blkdev-request_pool);
-- 
1.7.4.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


[PATCH 01/22] Staging: hv: Get rid of blkvsc_check_events()

2011-04-06 Thread K. Y. Srinivasan
We don't support removable media in Hyper-V block driver.
Get rid of blkvsc_check_events() as it is efectively dead code.


Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |9 -
 1 files changed, 0 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index 0b85995..3a344d2 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -252,14 +252,6 @@ static int blkvsc_submit_request(struct blkvsc_request 
*blkvsc_req,
 }
 
 
-static unsigned int blkvsc_check_events(struct gendisk *gd,
-   unsigned int clearing)
-{
-   DPRINT_DBG(BLKVSC_DRV, - enter\n);
-   return DISK_EVENT_MEDIA_CHANGE;
-}
-
-
 static int blkvsc_open(struct block_device *bdev, fmode_t mode)
 {
struct block_device_context *blkdev = bdev-bd_disk-private_data;
@@ -1209,7 +1201,6 @@ static const struct block_device_operations block_ops = {
.owner = THIS_MODULE,
.open = blkvsc_open,
.release = blkvsc_release,
-   .check_events = blkvsc_check_events,
.revalidate_disk = blkvsc_revalidate_disk,
.getgeo = blkvsc_getgeo,
.ioctl  = blkvsc_ioctl,
-- 
1.7.4.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


[PATCH 13/22] Staging: hv: Cleanup blkvsc_remove()

2011-04-06 Thread K. Y. Srinivasan
blkvsc_remove() cannot fail. Clean it up accordingly.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |   15 +++
 1 files changed, 3 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index 58d4a2d..7974e6c 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -556,22 +556,12 @@ static int blkvsc_remove(struct device *device)
struct hv_device *device_obj = device_to_hv_device(device);
struct block_device_context *blkdev = dev_get_drvdata(device);
unsigned long flags;
-   int ret;
-
-
-   if (!storvsc_drv_obj-base.dev_rm)
-   return -1;
 
/*
 * Call to the vsc driver to let it know that the device is being
 * removed
 */
-   ret = storvsc_drv_obj-base.dev_rm(device_obj);
-   if (ret != 0) {
-   /* TODO: */
-   DPRINT_ERR(BLKVSC_DRV,
-  unable to remove blkvsc device (ret %d), ret);
-   }
+   storvsc_drv_obj-base.dev_rm(device_obj);
 
/* Get to a known state */
spin_lock_irqsave(blkdev-lock, flags);
@@ -604,7 +594,8 @@ static int blkvsc_remove(struct device *device)
 
kfree(blkdev);
 
-   return ret;
+   return 0;
+
 }
 
 static void blkvsc_shutdown(struct device *device)
-- 
1.7.4.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


[PATCH 09/22] Staging: hv: Get rid of the function blkvsc_revalidate_disk()

2011-04-06 Thread K. Y. Srinivasan
The block driver in Hyper-V does not support removable media, get rid of the
blkvsc_revalidate_disk().

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |   17 -
 1 files changed, 0 insertions(+), 17 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index 4c248b7..b2cd04a 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -722,22 +722,6 @@ static int blkvsc_release(struct gendisk *disk, fmode_t 
mode)
 }
 
 
-static int blkvsc_revalidate_disk(struct gendisk *gd)
-{
-   struct block_device_context *blkdev = gd-private_data;
-
-   DPRINT_DBG(BLKVSC_DRV, - enter\n);
-
-   if (blkdev-device_type == DVD_TYPE) {
-   blkvsc_do_operation(blkdev, DO_CAPACITY);
-   set_capacity(blkdev-gd, blkdev-capacity *
-   (blkdev-sector_size/512));
-   blk_queue_logical_block_size(gd-queue, blkdev-sector_size);
-   }
-   return 0;
-}
-
-
 /*
  * We break the request into 1 or more blkvsc_requests and submit
  * them.  If we cant submit them all, we put them on the
@@ -997,7 +981,6 @@ static const struct block_device_operations block_ops = {
.owner = THIS_MODULE,
.open = blkvsc_open,
.release = blkvsc_release,
-   .revalidate_disk = blkvsc_revalidate_disk,
.getgeo = blkvsc_getgeo,
.ioctl  = blkvsc_ioctl,
 };
-- 
1.7.4.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


[PATCH 22/22] Staging: hv: Get rid of IDE details from blkvsc_drv.c

2011-04-06 Thread K. Y. Srinivasan
Now get rid of IDE details from blkvsc_drv.c.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |   55 +++---
 drivers/staging/hv/storvsc.c|   18 ++--
 2 files changed, 25 insertions(+), 48 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index 3229ebc..acc5435 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -953,11 +953,8 @@ static int blkvsc_probe(struct device *device)
 
struct block_device_context *blkdev = NULL;
struct storvsc_device_info device_info;
-   int major = 0;
-   int devnum = 0;
+   struct storvsc_major_info major_info;
int ret = 0;
-   static int ide0_registered;
-   static int ide1_registered;
 
 
blkdev = kzalloc(sizeof(struct block_device_context), GFP_KERNEL);
@@ -994,43 +991,23 @@ static int blkvsc_probe(struct device *device)
 
dev_set_drvdata(device, blkdev);
 
-   /* Calculate the major and device num */
-   if (blkdev-path == 0) {
-   major = IDE0_MAJOR;
-   devnum = blkdev-path + blkdev-target; /* 0 or 1 */
-
-   if (!ide0_registered) {
-   ret = register_blkdev(major, ide);
-   if (ret != 0) {
-   DPRINT_ERR(BLKVSC_DRV,
-  register_blkdev() failed! ret %d,
-  ret);
-   goto remove;
-   }
+   ret = stor_vsc_get_major_info(device_info, major_info);
 
-   ide0_registered = 1;
-   }
-   } else if (blkdev-path == 1) {
-   major = IDE1_MAJOR;
-   devnum = blkdev-path + blkdev-target + 1; /* 2 or 3 */
-
-   if (!ide1_registered) {
-   ret = register_blkdev(major, ide);
-   if (ret != 0) {
-   DPRINT_ERR(BLKVSC_DRV,
-  register_blkdev() failed! ret %d,
-  ret);
-   goto remove;
-   }
+   if (ret)
+   goto cleanup;
+
+   if (major_info.do_register) {
+   ret = register_blkdev(major_info.major, major_info.devname);
 
-   ide1_registered = 1;
+   if (ret != 0) {
+   DPRINT_ERR(BLKVSC_DRV,
+  register_blkdev() failed! ret %d, ret);
+   goto remove;
}
-   } else {
-   ret = -1;
-   goto cleanup;
}
 
-   DPRINT_INFO(BLKVSC_DRV, blkvsc registered for major %d!!, major);
+   DPRINT_INFO(BLKVSC_DRV, blkvsc registered for major %d!!,
+   major_info.major);
 
blkdev-gd = alloc_disk(BLKVSC_MINORS);
if (!blkdev-gd) {
@@ -1046,8 +1023,8 @@ static int blkvsc_probe(struct device *device)
blk_queue_bounce_limit(blkdev-gd-queue, BLK_BOUNCE_ANY);
blk_queue_dma_alignment(blkdev-gd-queue, 511);
 
-   blkdev-gd-major = major;
-   if (devnum == 1 || devnum == 3)
+   blkdev-gd-major = major_info.major;
+   if (major_info.index == 1 || major_info.index == 3)
blkdev-gd-first_minor = BLKVSC_MINORS;
else
blkdev-gd-first_minor = 0;
@@ -1055,7 +1032,7 @@ static int blkvsc_probe(struct device *device)
blkdev-gd-events = DISK_EVENT_MEDIA_CHANGE;
blkdev-gd-private_data = blkdev;
blkdev-gd-driverfs_dev = (blkdev-device_ctx-device);
-   sprintf(blkdev-gd-disk_name, hd%c, 'a' + devnum);
+   sprintf(blkdev-gd-disk_name, hd%c, 'a' + major_info.index);
 
blkvsc_do_operation(blkdev, DO_INQUIRY);
blkvsc_do_operation(blkdev, DO_CAPACITY);
diff --git a/drivers/staging/hv/storvsc.c b/drivers/staging/hv/storvsc.c
index e2b3410..85bae5a 100644
--- a/drivers/staging/hv/storvsc.c
+++ b/drivers/staging/hv/storvsc.c
@@ -629,26 +629,26 @@ int stor_vsc_get_major_info(struct storvsc_device_info 
*device_info,
 
if (device_info-path_id) {
major_info-major = 22;
-   if (!ide1_registered)
+   if (!ide1_registered) {
major_info-do_register = true;
-   else {
-   major_info-do_register = false;
ide1_registered = true;
-   }
+   } else
+   major_info-do_register = false;
+
if (device_info-target_id)
major_info-index = 3;
-else
+   else
major_info-index = 2;
 
return 0;
} else {
   

[PATCH 20/22] Staging: hv: Fix a jump label (Remove) in blkvsc_drv.c

2011-04-06 Thread K. Y. Srinivasan
One of the jump labels was named Remove; change it to remove.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index a47581c..3229ebc 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -1005,7 +1005,7 @@ static int blkvsc_probe(struct device *device)
DPRINT_ERR(BLKVSC_DRV,
   register_blkdev() failed! ret %d,
   ret);
-   goto Remove;
+   goto remove;
}
 
ide0_registered = 1;
@@ -1020,7 +1020,7 @@ static int blkvsc_probe(struct device *device)
DPRINT_ERR(BLKVSC_DRV,
   register_blkdev() failed! ret %d,
   ret);
-   goto Remove;
+   goto remove;
}
 
ide1_registered = 1;
@@ -1071,7 +1071,7 @@ static int blkvsc_probe(struct device *device)
 
return ret;
 
-Remove:
+remove:
storvsc_drv_obj-base.dev_rm(device_obj);
 
 cleanup:
-- 
1.7.4.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


[PATCH 05/22] Staging: hv: Get rid of blkvsc_do_read_capacity()

2011-04-06 Thread K. Y. Srinivasan
Now that we have a common function for some of the operations on the device,
use that and get rid of the function blkvsc_do_read_capacity().

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |  117 +--
 1 files changed, 39 insertions(+), 78 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index 9dbba3c..b2d149d 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -48,6 +48,7 @@ enum blkvsc_device_type {
 
 enum blkvsc_op_type {
DO_INQUIRY,
+   DO_CAPACITY,
 };
 
 /*
@@ -406,6 +407,9 @@ static int blkvsc_do_operation(struct block_device_context 
*blkdev,
struct page *page_buf;
unsigned char *buf;
unsigned char device_type;
+   struct scsi_sense_hdr sense_hdr;
+   struct vmscsi_request *vm_srb;
+
int ret = 0;
 
blkvsc_req = kmem_cache_zalloc(blkdev-request_pool, GFP_KERNEL);
@@ -418,6 +422,7 @@ static int blkvsc_do_operation(struct block_device_context 
*blkdev,
return -ENOMEM;
}
 
+   vm_srb = blkvsc_req-request.vstor_packet.vm_srb;
init_completion(blkvsc_req-request.wait_event);
blkvsc_req-dev = blkdev;
blkvsc_req-req = NULL;
@@ -437,6 +442,15 @@ static int blkvsc_do_operation(struct block_device_context 
*blkdev,
blkvsc_req-request.data_buffer.len = 64;
break;
 
+   case DO_CAPACITY:
+   blkdev-sector_size = 0;
+   blkdev-capacity = 0;
+   blkdev-media_not_present = 0; /* assume a disk is present */
+
+   blkvsc_req-cmnd[0] = READ_CAPACITY;
+   blkvsc_req-cmd_len = 16;
+   blkvsc_req-request.data_buffer.len = 8;
+   break;
default:
ret = -EINVAL;
goto cleanup;
@@ -446,6 +460,18 @@ static int blkvsc_do_operation(struct block_device_context 
*blkdev,
 
wait_for_completion_interruptible(blkvsc_req-request.wait_event);
 
+   /* check error */
+   if (vm_srb-scsi_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);
 
switch (op) {
@@ -465,6 +491,17 @@ static int blkvsc_do_operation(struct block_device_context 
*blkdev,
 
memcpy(blkdev-device_id, buf[8], blkdev-device_id_len);
break;
+
+   case DO_CAPACITY:
+   /* 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];
+   break;
}
 
 cleanup:
@@ -715,82 +752,6 @@ static int blkvsc_release(struct gendisk *disk, fmode_t 
mode)
 }
 
 
-/* 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;
-   struct page *page_buf;
-   unsigned char *buf;
-   struct scsi_sense_hdr sense_hdr;
-   struct vmscsi_request *vm_srb;
-
-   DPRINT_DBG(BLKVSC_DRV, blkvsc_do_read_capacity()\n);
-
-   blkdev-sector_size = 0;
-   blkdev-capacity = 0;
-   blkdev-media_not_present = 0; /* assume a disk is present */
-
-   blkvsc_req = kmem_cache_zalloc(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) {
-   kmem_cache_free(blkvsc_req-dev-request_pool, blkvsc_req);
-   return -ENOMEM;
-   }
-
-   vm_srb = blkvsc_req-request.vstor_packet.vm_srb;
-   init_completion(blkvsc_req-request.wait_event);
-   blkvsc_req-dev = blkdev;
-   blkvsc_req-req = NULL;
-   blkvsc_req-write = 0;
-
-   blkvsc_req-request.data_buffer.pfn_array[0] =
-   page_to_pfn(page_buf);
-   blkvsc_req-request.data_buffer.offset = 0;
-   blkvsc_req-request.data_buffer.len = 8;
-
-   blkvsc_req-cmnd[0] = READ_CAPACITY;
-   blkvsc_req-cmd_len = 16;
-
-   blkvsc_submit_request(blkvsc_req, blkvsc_cmd_completion);
-
-   DPRINT_DBG(BLKVSC_DRV, waiting %p to complete\n,
-  blkvsc_req);
-
-   wait_for_completion_interruptible(blkvsc_req-request.wait_event);
-
-   /* check error */
-   if (vm_srb-scsi_status) {
-   scsi_normalize_sense(blkvsc_req-sense_buffer,
-  

[PATCH 17/22] Staging: hv: Get rid of an unnecessary check in blkvsc_probe()

2011-04-06 Thread K. Y. Srinivasan
It is never the case that the dev_add function pointer will not be set
(we set it in this code!). Get rid of this meaningless check.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |5 -
 1 files changed, 0 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index 35ad3d5..3060bab 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -968,11 +968,6 @@ static int blkvsc_probe(struct device *device)
static int ide1_registered;
 
 
-   if (!storvsc_drv_obj-base.dev_add) {
-   ret = -1;
-   goto Cleanup;
-   }
-
blkdev = kzalloc(sizeof(struct block_device_context), GFP_KERNEL);
if (!blkdev) {
ret = -ENOMEM;
-- 
1.7.4.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


[PATCH 21/22] Staging: hv: Introduce a function to map channel properties onto block device info

2011-04-06 Thread K. Y. Srinivasan
In preparation for removing the IDE details from the block driver, implement
a function that maps channel properties to block device information.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/storvsc.c |   68 ++
 drivers/staging/hv/storvsc_api.h |   10 +
 2 files changed, 78 insertions(+), 0 deletions(-)

diff --git a/drivers/staging/hv/storvsc.c b/drivers/staging/hv/storvsc.c
index d7ce393..e2b3410 100644
--- a/drivers/staging/hv/storvsc.c
+++ b/drivers/staging/hv/storvsc.c
@@ -17,6 +17,8 @@
  * Authors:
  *   Haiyang Zhang haiya...@microsoft.com
  *   Hank Janssen  hjans...@microsoft.com
+ *
+ * 4/3/2011: K. Y. Srinivasan - Significant restructuring and cleanup.
  */
 #include linux/kernel.h
 #include linux/sched.h
@@ -593,6 +595,72 @@ int stor_vsc_on_io_request(struct hv_device *device,
 }
 
 /*
+ * The channel properties uniquely specify how the device is to be
+ * presented to the guest. Map this information for use by the block
+ * driver. For Linux guests on Hyper-V, we emulate a scsi HBA in the guest
+ * (storvsc_drv) and so scsi devices in the guest  are handled by
+ * native upper level Linux drivers. Consequently, Hyper-V
+ * block driver, while being a generic block driver, presently does not
+ * deal with anything other than devices that would need to be presented
+ * to the guest as an IDE disk.
+ *
+ * This function maps the channel properties as embedded in the input
+ * parameter device_info onto information necessary to register the
+ * corresponding block device.
+ *
+ * Currently, there is no way to stop the emulation of the block device
+ * on the host side. And so, to prevent the native IDE drivers in Linux
+ * from taking over these devices (to be managedby Hyper-V block
+ * driver), we will take over if need be the major of the IDE controllers.
+ *
+ */
+
+int stor_vsc_get_major_info(struct storvsc_device_info *device_info,
+   struct storvsc_major_info *major_info)
+{
+   static bool ide0_registered;
+   static bool ide1_registered;
+
+   /*
+* For now we only support IDE disks.
+*/
+   major_info-devname = ide;
+   major_info-diskname = hd;
+
+   if (device_info-path_id) {
+   major_info-major = 22;
+   if (!ide1_registered)
+   major_info-do_register = true;
+   else {
+   major_info-do_register = false;
+   ide1_registered = true;
+   }
+   if (device_info-target_id)
+   major_info-index = 3;
+else
+   major_info-index = 2;
+
+   return 0;
+   } else {
+   major_info-major = 3;
+   if (!ide0_registered)
+   major_info-do_register = true;
+   else {
+   major_info-do_register = false;
+   ide0_registered = true;
+   }
+   if (device_info-target_id)
+   major_info-index = 1;
+   else
+   major_info-index = 0;
+
+   return 0;
+   }
+
+   return -ENODEV;
+}
+
+/*
  * stor_vsc_on_cleanup - Perform any cleanup when the driver is removed
  */
 void stor_vsc_on_cleanup(struct hv_driver *driver)
diff --git a/drivers/staging/hv/storvsc_api.h b/drivers/staging/hv/storvsc_api.h
index d7db949..c98139c 100644
--- a/drivers/staging/hv/storvsc_api.h
+++ b/drivers/staging/hv/storvsc_api.h
@@ -92,6 +92,14 @@ struct storvsc_device_info {
unsigned char target_id;
 };
 
+struct storvsc_major_info {
+   int major;
+   int index;
+   bool do_register;
+   char *devname;
+   char *diskname;
+};
+
 /* A storvsc device is a device object that contains a vmbus channel */
 struct storvsc_device {
struct hv_device *device;
@@ -155,5 +163,7 @@ int stor_vsc_on_io_request(struct hv_device *device,
struct hv_storvsc_request *request);
 void stor_vsc_on_cleanup(struct hv_driver *driver);
 
+int stor_vsc_get_major_info(struct storvsc_device_info *device_info,
+   struct storvsc_major_info *major_info);
 
 #endif /* _STORVSC_API_H_ */
-- 
1.7.4.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


[PATCH 11/22] Staging: hv: Get rid of some DPRINT_INFO() statements

2011-04-06 Thread K. Y. Srinivasan
Get rid of some of the DPRINT_INFO() statements.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index 5cf82f0..09633cc 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -331,7 +331,6 @@ static int blkvsc_ioctl(struct block_device *bd, fmode_t 
mode,
 
switch (cmd) {
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))
ret = -EFAULT;
@@ -1264,8 +1263,6 @@ static int __init blkvsc_init(void)
 
BUILD_BUG_ON(sizeof(sector_t) != 8);
 
-   DPRINT_INFO(BLKVSC_DRV, Blkvsc initializing);
-
ret = blkvsc_drv_init();
 
return ret;
-- 
1.7.4.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization


[PATCH 06/22] Staging: hv: Get rid of blkvsc_do_read_capacity16()

2011-04-06 Thread K. Y. Srinivasan
Get rid of blkvsc_do_read_capacity16() and instead use the common function
for retrieving capacity.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Signed-off-by: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Hank Janssen hjans...@microsoft.com
---
 drivers/staging/hv/blkvsc_drv.c |   81 +--
 1 files changed, 2 insertions(+), 79 deletions(-)

diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index b2d149d..7fab3c7 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -752,82 +752,6 @@ static int blkvsc_release(struct gendisk *disk, fmode_t 
mode)
 }
 
 
-static int blkvsc_do_read_capacity16(struct block_device_context *blkdev)
-{
-   struct blkvsc_request *blkvsc_req;
-   struct page *page_buf;
-   unsigned char *buf;
-   struct scsi_sense_hdr sense_hdr;
-   struct vmscsi_request *vm_srb;
-
-   DPRINT_DBG(BLKVSC_DRV, blkvsc_do_read_capacity16()\n);
-
-   blkdev-sector_size = 0;
-   blkdev-capacity = 0;
-   blkdev-media_not_present = 0; /* assume a disk is present */
-
-   blkvsc_req = kmem_cache_zalloc(blkdev-request_pool, GFP_KERNEL);
-   if (!blkvsc_req)
-   return -ENOMEM;
-
-   memset(blkvsc_req, 0, sizeof(struct blkvsc_request));
-   vm_srb = blkvsc_req-request.vstor_packet.vm_srb;
-   page_buf = alloc_page(GFP_KERNEL);
-   if (!page_buf) {
-   kmem_cache_free(blkvsc_req-dev-request_pool, blkvsc_req);
-   return -ENOMEM;
-   }
-
-   init_completion(blkvsc_req-request.wait_event);
-   blkvsc_req-dev = blkdev;
-   blkvsc_req-req = NULL;
-   blkvsc_req-write = 0;
-
-   blkvsc_req-request.data_buffer.pfn_array[0] =
-   page_to_pfn(page_buf);
-   blkvsc_req-request.data_buffer.offset = 0;
-   blkvsc_req-request.data_buffer.len = 12;
-
-   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
-*/
-
-   blkvsc_submit_request(blkvsc_req, blkvsc_cmd_completion);
-
-   DPRINT_DBG(BLKVSC_DRV, waiting %p to complete\n,
-  blkvsc_req);
-
-   wait_for_completion_interruptible(blkvsc_req-request.wait_event);
-
-   /* check error */
-   if (vm_srb-scsi_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]);
-
-   kunmap(page_buf);
-
-   __free_page(page_buf);
-
-   kmem_cache_free(blkvsc_req-dev-request_pool, blkvsc_req);
-
-   return 0;
-}
-
 static int blkvsc_revalidate_disk(struct gendisk *gd)
 {
struct block_device_context *blkdev = gd-private_data;
@@ -1312,9 +1236,8 @@ static int blkvsc_probe(struct device *device)
set_disk_ro(blkdev-gd, 1);
blkdev-gd-flags |= GENHD_FL_REMOVABLE;
blkvsc_do_operation(blkdev, DO_CAPACITY);
-   } else {
-   blkvsc_do_read_capacity16(blkdev);
-   }
+   } else
+   blkvsc_do_operation(blkdev, DO_CAPACITY);
 
set_capacity(blkdev-gd, blkdev-capacity * (blkdev-sector_size/512));
blk_queue_logical_block_size(blkdev-gd-queue, blkdev-sector_size);
-- 
1.7.4.1

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization