Staging: hv: storvsc: Move the storage driver out of the staging area
Subsystems (3)
PATCH RESEND 1/1 Staging: hv: storvsc: Move the storage driver out of the staging area
The storage driver (storvsc_drv.c) handles all block storage devices assigned to Linux guests hosted on Hyper-V. This driver has been in the staging tree for a while and this patch moves it out of the staging area. As per Greg's recommendation, this patch makes no changes to the staging/hv directory. Once the driver moves out of staging, we will cleanup the staging/hv directory.
This patch includes all the patches that I have sent against the staging/hv tree to address the comments I have gotten to date on this storage driver. Greg has already applied all these patches to the staging tree.
--- drivers/scsi/Kconfig | 7 + drivers/scsi/Makefile | 3 + drivers/scsi/storvsc_drv.c | 1586 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1596 insertions(+), 0 deletions(-) create mode 100644 drivers/scsi/storvsc_drv.c
drivers/scsi/Kconfig +7 -0
@@ -662,6 +662,13 @@ config VMWARE_PVSCSI To compile this driver as a module, choose M here: the module will be called vmw_pvscsi. +config HYPERV_STORAGE + tristate "Microsoft Hyper-V virtual storage driver" + depends on SCSI && HYPERV + default HYPERV + help + Select this option to enable the Hyper-V virtual storage driver. + config LIBFC tristate "LibFC module" select SCSI_FC_ATTRS
drivers/scsi/Makefile +3 -0
@@ -142,6 +142,7 @@ obj-$(CONFIG_SCSI_BNX2_ISCSI) += libiscsi.o bnx2i/ obj-$(CONFIG_BE2ISCSI) += libiscsi.o be2iscsi/ obj-$(CONFIG_SCSI_PMCRAID) += pmcraid.o obj-$(CONFIG_VMWARE_PVSCSI) += vmw_pvscsi.o +obj-$(CONFIG_HYPERV_STORAGE) += hv_storvsc.o obj-$(CONFIG_ARM) += arm/
@@ -170,6 +171,8 @@ scsi_mod-$(CONFIG_SCSI_PROC_FS) += scsi_proc.o scsi_mod-y += scsi_trace.o scsi_mod-$(CONFIG_PM) += scsi_pm.o +hv_storvsc-y := storvsc_drv.o + scsi_tgt-y += scsi_tgt_lib.o scsi_tgt_if.o sd_mod-objs := sd.o
drivers/scsi/storvsc_drv.c new file +1586 -0
1,586 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Quoted 1 line
+#define
STORVSC_MIN_BUF_NR64
What about a comment explaining what this is for?
drivers/scsi/storvsc_drv.c line 48
Quoted 2 lines
drivers/scsi/storvsc_drv.c new file +2
-0+#define STORVSC_RING_BUFFER_SIZE (20*PAGE_SIZE) +static int storvsc_ringbuffer_size =STORVSC_RING_BUFFER_SIZE ;
I don't think you need the #define here.
Quoted 8 lines
drivers/scsi/storvsc_drv.c new file +8
-0+/* to alert the user that structure sizes may be mismatched even though the */ +/* protocol versions match. */ + + +#define REVISION_STRING (REVISION_ ) #REVISION_ +#define FILL_VMSTOR_REVISION (RESULT_LVALUE_ ) \ + do { \ + char *revision_string \
drivers/scsi/storvsc_drv.c line 70
Quoted 10 lines
drivers/scsi/storvsc_drv.c new file +10
-0+ = REVISION_STRING($Rev : 6 $) + 6; \ +RESULT_LVALUE_ =0 ; \ +while (*revision_string >='0' \ + && *revision_string <='9' ) { \ +RESULT_LVALUE_ *=10 ; \ +RESULT_LVALUE_ += *revision_string -'0' ; \ + revision_string++; \ + } \ + }while (0 ) +
How can these macros work? I don't think git ever expans $Rev, and in either case I really don't get how this is supposed to work.
drivers/scsi/storvsc_drv.c line 72
Quoted 2 lines
drivers/scsi/storvsc_drv.c new file +2
-0+/* Major/minor macros. Minor version is in LSB, meaning that earlier flat */ +/* version numbers will be interpreted as "0.x" (i.e., 1 becomes 0.1). */
Please use comment formats like this:
/*
* Blah ....
* .....
*/
(this also applies to a few other places).
drivers/scsi/storvsc_drv.c line 76
Quoted 4 lines
drivers/scsi/storvsc_drv.c new file +4
-0+#define VMSTOR_PROTOCOL_MAJOR (VERSION_ ) (((VERSION_) >> 8) & 0xff) +#define VMSTOR_PROTOCOL_MINOR (VERSION_ ) (((VERSION_)) & 0xff) +#define VMSTOR_PROTOCOL_VERSION (MAJOR_ ,MINOR_ ) ((((MAJOR_) & 0xff) << 8) | \ + (((MINOR_) & 0xff)))
All these should be inline functions.
Quoted 1 line
+#define
VMSTOR_INVALID_PROTOCOL_VERSION(-1)
Not used.
drivers/scsi/storvsc_drv.c line 124
Quoted 11 lines
+ * Platform neutral description of a scsi request -
+ * this remains the same across the write regardless of 32/64 bit
+ * note: it's patterned off theSCSI_PASS_THROUGHstructure
+ */drivers/scsi/storvsc_drv.c new file +7
-0+#define CDB16GENERIC_LENGTH 0x10 + +#ifndef SENSE_BUFFER_SIZE +#define SENSE_BUFFER_SIZE 0x12 +#endif + +#define MAX_DATA_BUF_LEN_WITH_PADDING 0x14
Please don't conditionally re-use the SCSI-layer SENSE_BUFFER_SIZE for your on the wire packets, but define your own. Please also give all theses constants a VMSCSI_ or similar prefix.
Quoted 13 lines
drivers/scsi/storvsc_drv.c new file +13
-0+struct vmscsi_request { +unsigned short length; +unsigned char srb_status; +unsigned char scsi_status; + +unsigned char port_number; +unsigned char path_id; +unsigned char target_id; +unsigned char lun; + +unsigned char cdb_length; +unsigned char sense_info_length; +unsigned char data_in;
drivers/scsi/storvsc_drv.c line 148
Quoted 10 lines
drivers/scsi/storvsc_drv.c new file +10
-0+unsigned char reserved; + +unsigned int data_transfer_length; + +union { +unsigned char cdb[CDB16GENERIC_LENGTH ]; +unsigned char sense_data[SENSE_BUFFER_SIZE ]; +unsigned char reserved_array[MAX_DATA_BUF_LEN_WITH_PADDING ]; + }; +} __attribute((packed));
Please use fixed size u8/16/32/etc types for all the on-wire defintions.
I'd also really recommend splitting the actual protocol defintion in a header separate from the driver implementation to make it clear what is part of the protocol and what's internal to the driver.
drivers/scsi/storvsc_drv.c line 222
Quoted 2 lines
drivers/scsi/storvsc_drv.c new file +2
-0+/* This is the set of flags that the vsc can set in any packets it sends */ +#define VSC_LEGAL_FLAGS (REQUEST_COMPLETION_FLAG)
unused.
Quoted 1 line
+#define
STORVSC_MAX_CMD_LEN16
This seems to duplicate the CDB16GENERIC_LENGTH define used above, please make sure you only have one #define for this constant.
drivers/scsi/storvsc_drv.c line 245
Quoted 7 lines
drivers/scsi/storvsc_drv.c new file +7
-0+ +/* Matches Windows-end */ +enum storvsc_request_type { +WRITE_TYPE , +READ_TYPE , +UNKNOWN_TYPE , +};
For enums specifying the protocol please always use explicit values.
drivers/scsi/storvsc_drv.c line 255
Quoted 8 lines
drivers/scsi/storvsc_drv.c new file +8
-0+struct hv_storvsc_request { +struct hv_device *device; + +/* Synchronize the request/response if needed */ +struct completion wait_event; + +unsigned char *sense_buffer; +void *context;
This always is a struct storvsc_cmd_request, and should be typed as such.
drivers/scsi/storvsc_drv.c line 256
Quoted 1 line
drivers/scsi/storvsc_drv.c new file +1
-0+void (*on_io_completion)(struct hv_storvsc_request *request);
This always points to storvsc_command_completion, so please remove the indirect call and use it directly.
drivers/scsi/storvsc_drv.c line 260
Quoted 4 lines
drivers/scsi/storvsc_drv.c new file +4
-0+struct hv_multipage_buffer data_buffer; + +struct vstor_packet vstor_packet; +};
Btw, what is the reason that storvsc_cmd_request and hv_storvsc_request are separate structures and not merged into one? This wastes a tiny amount of memory for the init/reset requests, but keeps the code a lot simpler.
drivers/scsi/storvsc_drv.c line 378
Quoted 5 lines
drivers/scsi/storvsc_drv.c new file +4
-0+static inline struct storvsc_device *get_out_stor_device( + struct hv_device *device) +static inline struct storvsc_device *get_in_stor_device( +struct hv_device *device)
I'm pretty sure you defended this odd reference counting scheme last time the discussion came up, but please write up a long comment in the code explaning it so that the question doesn't come up again all the time.
drivers/scsi/storvsc_drv.c line 549
Quoted 13 lines
drivers/scsi/storvsc_drv.c new file +13
-0+/* +* The current SCSI handling on the host side does +* not correctly handle: +* INQUIRY command with page code parameter set to 0x80 +* MODE_SENSE command with cmd[2] == 0x1c +* +* Setup srb and scsi status so this won't be fatal. +* We do this so we can distinguish truly fatal failues +* (srb status == 0x4) and off-line the device in that case. +*/ + +if ((stor_pkt->vm_srb.cdb[0 ] ==INQUIRY ) || + (stor_pkt->vm_srb.cdb[0 ] ==MODE_SENSE )) {
This should be:
if (stor_pkt->vm_srb.cdb[0] == INQUIRY ||
stor_pkt->vm_srb.cdb[0] == MODE_SENSE) {or even better use a switch statement to clarify what's going on.
drivers/scsi/storvsc_drv.c line 1088
Quoted 13 lines
drivers/scsi/storvsc_drv.c new file +13
-0+static int storvsc_remove (struct hv_device *dev) +{ +struct storvsc_device *stor_device =hv_get_drvdata (dev); +struct Scsi_Host *host = stor_device->host; + +scsi_remove_host (host); + +scsi_host_put (host); + +storvsc_dev_remove (dev); + +return 0 ; +}
Why isn't this near storvcs_probe at the end of the file given that they logically belong together? Also please only do the scsi_host_put once you are fully done with it, that is after storvsc_dev_remove.
drivers/scsi/storvsc_drv.c line 1166
Quoted 10 lines
drivers/scsi/storvsc_drv.c new file +10
-0+/* +* storvsc_host_reset_handler - Reset the scsi HBA +*/ +static int storvsc_host_reset_handler (struct scsi_cmnd *scmnd) +{ +struct hv_host_device *host_dev =shost_priv (scmnd->device->host); +struct hv_device *dev = host_dev->dev; + +return storvsc_host_reset (dev); +}
Why is storvsc_host_reset split from this function? Also the comment really doesn't tell us anything, I'd rather leave it away.
drivers/scsi/storvsc_drv.c line 1172
Quoted 4 lines
drivers/scsi/storvsc_drv.c new file +4
-0+/* +* storvsc_command_completion - Command completion processing +*/ +static void storvsc_command_completion (struct hv_storvsc_request *request)
I really don't see how this comment adds any value over the pure function name.
drivers/scsi/storvsc_drv.c line 1208
Quoted 3 lines
drivers/scsi/storvsc_drv.c new file +2
-0+if (vm_srb->srb_status ==0x4 ) +if (vm_srb->srb_status ==0x20 ) {
Please add defines for the vm_srb->srb_status values.
Quoted 1 line
+static bool
storvsc_check_scsi_cmd(struct scsi_cmnd *scmnd)
Please call this storvsc_ignore_command or similar to make the use more obvious.
drivers/scsi/storvsc_drv.c line 1294
Quoted 8 lines
drivers/scsi/storvsc_drv.c new file +8
-0+/* If retrying, no need to prep the cmd */ +if (scmnd->host_scribble) { + + cmd_request = + (struct storvsc_cmd_request *)scmnd->host_scribble; + + goto retry_request; + }
I don't think this can ever happen given that you make sure to always clear ->host_scribble when returning SCSI_MLQUEUE_*_BUSY.
drivers/scsi/storvsc_drv.c line 1301
Quoted 6 lines
drivers/scsi/storvsc_drv.c new file +6
-0+ request_size =sizeof (struct storvsc_cmd_request ); + + cmd_request =mempool_alloc (memp->request_mempool, +GFP_ATOMIC ); +if (!cmd_request) +return SCSI_MLQUEUE_DEVICE_BUSY ;
The point of the mempool allocator is that it will never return NULL.
drivers/scsi/storvsc_drv.c line 1308
Quoted 7 lines
drivers/scsi/storvsc_drv.c new file +7
-0+ +memset (cmd_request,0 ,sizeof (struct storvsc_cmd_request )); + +/* Setup the cmd request */ + cmd_request->bounce_sgl_count =0 ; + cmd_request->bounce_sgl =NULL ; + cmd_request->cmd = scmnd;
Either use memset for the whole structure, or set the fields that need it to 0 explicitly, but not both. I doubt it's more efficient to only initialise the fields that need it.
Quoted 9 lines
drivers/scsi/storvsc_drv.c new file +7
-0+if (!cmd_request->bounce_sgl) { + scmnd->host_scribble =NULL ; +mempool_free (cmd_request, + memp->request_mempool); + +return SCSI_MLQUEUE_HOST_BUSY ; + }
drivers/scsi/storvsc_drv.c line 1404
Quoted 10 lines
drivers/scsi/storvsc_drv.c new file +9
-0+if (cmd_request->bounce_sgl_count) +destroy_bounce_buffer (cmd_request->bounce_sgl, + cmd_request->bounce_sgl_count); + +mempool_free (cmd_request, memp->request_mempool); + + scmnd->host_scribble =NULL ; + + ret =SCSI_MLQUEUE_DEVICE_BUSY ;
Please use goto labels and a single error exit for unwindining on failure.
Quoted 1 line
+/* Scsi driver */
Not a useful comment, just remove it.
Quoted 3 lines
+/*
+ *storvsc_probe- Add a new device for this driver
+ */
Not a very useful comment, just remove it.
drivers/scsi/storvsc_drv.c line 1497
Quoted 2 lines
drivers/scsi/storvsc_drv.c new file +2
-0+if (dev_is_ide) +storvsc_get_ide_info (device, &target, &path);
path is never used, so drop that argument from storvsc_get_ide_info please. Target is only used in the next dev_is_ide block, so please move this call to it.
drivers/scsi/storvsc_drv.c line 1509
Quoted 8 lines
drivers/scsi/storvsc_drv.c new file +8
-0+/* max # of devices per target */ + host->max_lun =STORVSC_MAX_LUNS_PER_TARGET ; +/* max # of targets per channel */ + host->max_id =STORVSC_MAX_TARGETS ; +/* max # of channels */ + host->max_channel =STORVSC_MAX_CHANNELS -1 ; +/* max cmd length */ + host->max_cmd_len =STORVSC_MAX_CMD_LEN ;
Any reason these aren't set directly in the host template?
drivers/scsi/storvsc_drv.c line 1525
Quoted 10 lines
drivers/scsi/storvsc_drv.c new file +10
-0+if (!dev_is_ide) { +scsi_scan_host (host); +return 0 ; + } + ret =scsi_add_device (host,0 , target,0 ); +if (ret) { +scsi_remove_host (host); + goto err_out2; + } +return 0 ;
I'd write this as an if/else block to be be more clear.
Quoted 1 line
+/* The one and only one */
this isn't an overly useful comment.
Christoph,
Let me begin by first thanking you for your detailed review. I have addressed all the issues you have identified - the code looks much better now; thank you! I am currently testing this code and I will post the patches soon - individual patches against the current code in the staging tree as well as a patch to move the driver out of staging (as I have done in the past). Please find my responses to your comments in-line.
Regards,
K. Y
Quoted 12 lines
-----Original Message-----
From: Christoph Hellwig [mailto:[email protected]]
Sent: Wednesday, January 11, 2012 5:37 AM
To: KY Srinivasan
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]
Subject: Re: [PATCH 1/1][RESEND] Staging: hv: storvsc: Move the storage driver out of the staging area
Quoted 3 lines
I'd also really recommend splitting the actual protocol defintion in a header separate from the driver implementation to make it clear what is part of the protocol and what's internal to the driver.
I have consolidated all of the protocol defines at the start of the file and these are properly commented. The decision to not have a separate header file was based on the comments I got from the community a while ago. Hopefully, this consolidation will address all the concerns.
Quoted 11 lines
drivers/scsi/storvsc_drv.c line 378
Quoted 6 lines
drivers/scsi/storvsc_drv.c new file +4
-0+static inline struct storvsc_device *get_out_stor_device( + struct hv_device *device) +static inline struct storvsc_device *get_in_stor_device( +struct hv_device *device)I'm pretty sure you defended this odd reference counting scheme last time the discussion came up, but please write up a long comment in the code explaning it so that the question doesn't come up again all the time.
I don't have any reference counting anymore. I have added a comment explaining the protocol for managing the life-cycle.
Quoted 9 lines
drivers/scsi/storvsc_drv.c line 1301
Quoted 7 lines
drivers/scsi/storvsc_drv.c new file +6
-0+ request_size =sizeof (struct storvsc_cmd_request ); + + cmd_request =mempool_alloc (memp->request_mempool, +GFP_ATOMIC ); +if (!cmd_request) +return SCSI_MLQUEUE_DEVICE_BUSY ;The point of the mempool allocator is that it will never return NULL.
With GFP_ATOMIC flag, the allocation I think can fail. At least that is what mempool_alloc() comment says.
Quoted 11 lines
drivers/scsi/storvsc_drv.c line 1509
Quoted 9 lines
drivers/scsi/storvsc_drv.c new file +8
-0+/* max # of devices per target */ + host->max_lun =STORVSC_MAX_LUNS_PER_TARGET ; +/* max # of targets per channel */ + host->max_id =STORVSC_MAX_TARGETS ; +/* max # of channels */ + host->max_channel =STORVSC_MAX_CHANNELS -1 ; +/* max cmd length */ + host->max_cmd_len =STORVSC_MAX_CMD_LEN ;Any reason these aren't set directly in the host template?
This state is not in the scsi_host_template. What am I missing here.