Skip to contentSkip to conversation

pvSCSI: Sanity check for REPORT_LUN emulation

PATCH In review Jun Kamada 2 participants 4 messages Jul 16, 2008 – Jul 28, 2008

Subsystems (2)
lore
Share & tools
lore

Jun Kamada

author
#0 lore raw

PATCH 1/1 pvSCSI: Sanity check for REPORT_LUN emulation

Hi Steven-san and all,

I will attach a patch in order to provide following.

- Sanity check for REPORT_LUN emulation.
- Return "residual" value from backend to frontend. The residual value is used to represent difference between request size the frontend requested and size backend actually responded.

Best regards,

-----
Jun Kamada

# HG changeset patch
# User [email protected]
# Date 1216166587 -32400
# Node ID 3a30c5a939439e722056f3ef72ccb1c6a2ebcffb # Parent a2dd9df157678bfb73684e7c97d79b9a5c4408d8
pvscsi: add residual_len in response

drivers/xen/scsiback/common.h +2 -1
diff -r a2dd9df15767 -r 3a30c5a93943 drivers/xen/scsiback/common.h
@@ -124,6 +124,7 @@ typedef struct {
 	grant_ref_t gref[VSCSIIF_SG_TABLESIZE];
 
 	int32_t rslt;
+	uint32_t resid;
 	uint8_t sense_buffer[VSCSIIF_SENSE_BUFFERSIZE];
 
 	struct list_head free_list;
@@ -169,7 +170,7 @@ void scsiback_release_translation_entry(
 
 void scsiback_cmd_exec(pending_req_t *pending_req);
 void scsiback_do_resp_with_sense(char *sense_buffer, int32_t result,
-				pending_req_t *pending_req);
+			uint32_t resid, pending_req_t *pending_req);
 void scsiback_fast_flush_area(pending_req_t *req);
 
 void scsiback_rsp_emulation(pending_req_t *pending_req);
drivers/xen/scsiback/emulate.c +60 -23

145 lines not on this page · raw message

drivers/xen/scsiback/scsiback.c +10 -6
diff -r a2dd9df15767 -r 3a30c5a93943 drivers/xen/scsiback/scsiback.c
@@ -142,7 +142,7 @@ static void scsiback_notify_work(struct 
 }
 
 void scsiback_do_resp_with_sense(char *sense_buffer, int32_t result,
-				pending_req_t *pending_req)
+			uint32_t resid, pending_req_t *pending_req)
 {
 	vscsiif_response_t *ring_res;
 	struct vscsibk_info *info = pending_req->info;
@@ -167,6 +167,8 @@ void scsiback_do_resp_with_sense(char *s
 	} else {
 		ring_res->sense_len = 0;
 	}
+
+	ring_res->residual_len = resid;
 
 	RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&info->ring, notify);
 	if (info->ring.rsp_prod_pvt == info->ring.req_cons) {
@@ -209,8 +211,10 @@ static void scsiback_cmd_done(struct req
 {
 	pending_req_t *pending_req = req->end_io_data;
 	unsigned char *sense_buffer;
+	unsigned int resid;
 
 	sense_buffer = req->sense;
+	resid        = req->data_len;
 
 	if (errors != 0) {
 		if (log_print_stat)
@@ -220,7 +224,7 @@ static void scsiback_cmd_done(struct req
 	scsiback_rsp_emulation(pending_req);
 
 	scsiback_fast_flush_area(pending_req);
-	scsiback_do_resp_with_sense(sense_buffer, errors, pending_req);
+	scsiback_do_resp_with_sense(sense_buffer, errors, resid, pending_req);
 	scsiback_put(pending_req->info);
 
 	__blk_put_request(req->q, req);
@@ -473,7 +477,7 @@ static void scsiback_device_reset_exec(p
 	scsiback_get(info);
 	err = scsi_reset_provider(sdev, SCSI_TRY_RESET_DEVICE);
 
-	scsiback_do_resp_with_sense(NULL, err, pending_req);
+	scsiback_do_resp_with_sense(NULL, err, 0, pending_req);
 	scsiback_put(info);
 
 	return;
@@ -592,11 +596,11 @@ static int scsiback_do_cmd_fn(struct vsc
 						pending_req);
 		if (err == -EINVAL) {
 			scsiback_do_resp_with_sense(NULL, (DRIVER_ERROR << 24),
-				pending_req);
+				0, pending_req);
 			continue;
 		} else if (err == -ENODEV) {
 			scsiback_do_resp_with_sense(NULL, (DID_NO_CONNECT << 16),
-				pending_req);
+				0, pending_req);
 			continue;
 		}
 
@@ -607,7 +611,7 @@ static int scsiback_do_cmd_fn(struct vsc
 		} else {
 			printk(KERN_ERR "scsiback: invalid parameter for request\n");
 			scsiback_do_resp_with_sense(NULL, (DRIVER_ERROR << 24),
-				pending_req);
+				0, pending_req);
 			continue;
 		}
 	}
drivers/xen/scsifront/scsifront.c +1 -1
diff -r a2dd9df15767 -r 3a30c5a93943 drivers/xen/scsifront/scsifront.c
@@ -147,7 +147,7 @@ static void scsifront_cdb_cmd_done(struc
 	add_id_to_freelist(info, id);
 
 	sc->result = ring_res->rslt;
-	sc->resid  = 0;
+	sc->resid  = ring_res->residual_len;
 
 	if (ring_res->sense_len > VSCSIIF_SENSE_BUFFERSIZE)
 		sense_len = VSCSIIF_SENSE_BUFFERSIZE;
include/xen/interface/io/vscsiif.h +3 -1
diff -r a2dd9df15767 -r 3a30c5a93943 include/xen/interface/io/vscsiif.h
@@ -84,7 +84,9 @@ struct vscsiif_response {
     uint8_t sense_len;
     uint8_t sense_buffer[VSCSIIF_SENSE_BUFFERSIZE];
     int32_t rslt;
-    uint32_t reserved[37];
+    uint32_t residual_len;     /* request bufflen - 
+                                  return the value from physical device */
+    uint32_t reserved[36];
 };
 typedef struct vscsiif_response vscsiif_response_t;
 

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 3 lines

I will attach a patch in order to provide following.

- Sanity check for REPORT_LUN emulation.

Thank you, that's much better.

I have one slight issue with the new approach: if a REPORT_LUNS command races with a LUN hot-add on the backend, you tell the frontend that the command failed. Might it be better to instead retry the command on the backend?

It's pretty unlikely that anyone would actually hit this race, and the current behaviour isn't completely unreasonable, but it seems like retrying in the backend would be a bit more robust. What do you think?

Steven.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

author
#2 lore raw

Hi Steven-san,

Sorry for delay.

Quoted 10 lines · On Fri, 18 Jul 2008 14:58:41 +0100 Steven Smith <[email protected]> wrote:
Quoted 3 lines

I will attach a patch in order to provide following.

- Sanity check for REPORT_LUN emulation.

Thank you, that's much better.

I have one slight issue with the new approach: if a REPORT_LUNS command races with a LUN hot-add on the backend, you tell the frontend that the command failed. Might it be better to instead retry the command on the backend?

Quoted 4 lines

It's pretty unlikely that anyone would actually hit this race, and the current behaviour isn't completely unreasonable, but it seems like retrying in the backend would be a bit more robust. What do you think?

Yes, I consider retrying is a right way, because we can expect few times retrying will certainly succeed in this case.
I will attach a patch with the number of retry is three. How do you think three times retry is appropriate?

Best regards,

-----
Jun Kamada

# HG changeset patch
# User [email protected]
# Date 1216719296 -32400
# Node ID d14b91e5361b3109e77c38ed49a294e574f515aa # Parent 2c80783731a23f4718089761a0f4e4a8e635c035
pvscsi: add retry in REPORT_LUN emulation

drivers/xen/scsiback/emulate.c +19 -4
diff -r 2c80783731a2 -r d14b91e5361b drivers/xen/scsiback/emulate.c
@@ -73,8 +73,6 @@
 #define VSCSI_MAX_SCSI_OP_CODE		256
 static unsigned char bitmap[VSCSI_MAX_SCSI_OP_CODE];
 
-/* REPORT LUNS Header*/
-#define VSCSI_REPORT_LUNS_HEADER	8
 
 
 /*
@@ -200,6 +198,11 @@ static int __nr_luns_under_host(struct v
 
 	return (lun_cnt);
 }
+
+
+/* REPORT LUNS Define*/
+#define VSCSI_REPORT_LUNS_HEADER	8
+#define VSCSI_REPORT_LUNS_RETRY		3
 
 /* quoted scsi_debug.c/resp_report_luns() */
 static void __report_luns(pending_req_t *pending_req, void *data)
@@ -215,6 +218,7 @@ static void __report_luns(pending_req_t 
 	unsigned int alloc_luns = 0;
 	unsigned int req_bufflen = 0;
 	unsigned int actual_len = 0;
+	unsigned int retry_cnt = 0;
 	int select_report = (int)cmd[2];
 	int i, lun_cnt = 0, lun, upper, err = 0;
 	
@@ -231,7 +235,7 @@ static void __report_luns(pending_req_t 
 	alloc_luns = __nr_luns_under_host(info);
 	alloc_len  = sizeof(struct scsi_lun) * alloc_luns
 				+ VSCSI_REPORT_LUNS_HEADER;
-
+retry:
 	if ((buff = kmalloc(alloc_len, GFP_KERNEL)) == NULL) {
 		printk(KERN_ERR "scsiback:%s kmalloc err\n", __FUNCTION__);
 		goto fail;
@@ -246,8 +250,19 @@ static void __report_luns(pending_req_t 
 		    (entry->v.tgt == target)) {
 			
 			/* check overflow */
-			if (lun_cnt >= alloc_luns)
+			if (lun_cnt >= alloc_luns) {
+				spin_unlock_irqrestore(&info->v2p_lock,
+							flags);
+
+				if (retry_cnt < VSCSI_REPORT_LUNS_RETRY) {
+					retry_cnt++;
+					if (buff)
+						kfree(buff);
+					goto retry;
+				}
+
 				goto fail;
+			}
 
 			lun = entry->v.lun;
 			upper = (lun >> 8) & 0x3f;

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#3 lore raw
Quoted 1 line

Sorry for delay.

Don't worry about it; I'm just as bad.

Quoted 10 lines
Quoted 10 lines
Quoted 3 lines

I will attach a patch in order to provide following.

- Sanity check for REPORT_LUN emulation.

Thank you, that's much better.

I have one slight issue with the new approach: if a REPORT_LUNS command races with a LUN hot-add on the backend, you tell the frontend that the command failed. Might it be better to instead retry the command on the backend?

Quoted 8 lines
Quoted 4 lines

It's pretty unlikely that anyone would actually hit this race, and the current behaviour isn't completely unreasonable, but it seems like retrying in the backend would be a bit more robust. What do you think?

Yes, I consider retrying is a right way, because we can expect few times retrying will certainly succeed in this case.
I will attach a patch with the number of retry is three. How do you think three times retry is appropriate?

The patch looks fine. Three retries sounds pretty reasonable; failing once is unlikely, so failing four times in a row shouldn't really happen unless there's something else wrong.

(Famous last words :)).

Steven.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel