Re: [PATCH scsi-misc-2.6] allow REPORT LUN scanning even for LUN 0 PQ of 3

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Sep 22, 2005 at 08:33:28PM -0500, James Bottomley wrote:
> On Wed, 2005-09-21 at 17:10 -0700, Patrick Mansfield wrote:
> > I removed the bad "!" on !scsi_device_get(), and the "insmod ./scsi_debug.ko
> > max_luns=3' found 2 sd's as expected.
> 
> Fixed it.
> 
> > But, scsi_debug module count is still at 1. Removing (via delete attr) the
> > 2 scsi_debug devices, and module count is still at 1. So probably still a
> > missing scsi_device_put(). I'm trying to debug a bit more.
> 
> Found it and fixed that too ... missing a put after the find_device.

OK, works fine now ...

> +static inline void scsi_destroy_sdev(struct scsi_device *sdev)
> +{
> +	if (sdev->host->hostt->slave_destroy)
> +		sdev->host->hostt->slave_destroy(sdev);
> +	transport_destroy_device(&sdev->sdev_gendev);
> +	put_device(&sdev->sdev_gendev);

One nit ... get rid of the inline, as the code path is not performance
critical.

Also, note that most devices won't behave as scsi_debug configured as
previosly patched: it had PQ !=0 for LUN 0, but then put LUN 0 in REPORT
LUN output.

So, we hit the already existing sdev case in James' patch. 

But it was a good test case :)

For the record, here's a scsi_debug patch to not have LUN 0 show up, and
not have it in REPORT LUNS output.

--- linux-2.6.14-rc2-git1/drivers/scsi/scsi_debug.c	2005-08-28 17:51:48.000000000 -0700
+++ jamesb-lun0-replun/drivers/scsi/scsi_debug.c	2005-09-23 15:33:51.000000000 -0700
@@ -619,7 +619,10 @@ static int resp_inquiry(struct scsi_cmnd
 
 	alloc_len = (cmd[3] << 8) + cmd[4];
 	memset(arr, 0, SDEBUG_MAX_INQ_ARR_SZ);
-	pq_pdt = (scsi_debug_ptype & 0x1f);
+	if (devip->lun == 0)
+		pq_pdt = 0x7f; /* XXX hack no LUN 0 */
+	else
+		pq_pdt = (scsi_debug_ptype & 0x1f);
 	arr[0] = pq_pdt;
 	if (0x2 & cmd[1]) {  /* CMDDT bit set */
 		mk_sense_buffer(devip, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB,
@@ -946,7 +949,7 @@ static int resp_report_luns(struct scsi_
 			    struct sdebug_dev_info * devip)
 {
 	unsigned int alloc_len;
-	int lun_cnt, i, upper;
+	int lun_cnt, i, upper, lun;
 	unsigned char *cmd = (unsigned char *)scp->cmnd;
 	int select_report = (int)cmd[2];
 	struct scsi_lun *one_lun;
@@ -960,18 +963,18 @@ static int resp_report_luns(struct scsi_
 	}
 	/* can produce response with up to 16k luns (lun 0 to lun 16383) */
 	memset(arr, 0, SDEBUG_RLUN_ARR_SZ);
-	lun_cnt = scsi_debug_max_luns;
+	lun_cnt = scsi_debug_max_luns - 1;
 	arr[2] = ((sizeof(struct scsi_lun) * lun_cnt) >> 8) & 0xff;
 	arr[3] = (sizeof(struct scsi_lun) * lun_cnt) & 0xff;
 	lun_cnt = min((int)((SDEBUG_RLUN_ARR_SZ - 8) /
 			    sizeof(struct scsi_lun)), lun_cnt);
 	one_lun = (struct scsi_lun *) &arr[8];
-	for (i = 0; i < lun_cnt; i++) {
-		upper = (i >> 8) & 0x3f;
+	for (i = 0, lun = 1; i < lun_cnt; i++, lun++) {
+		upper = (lun >> 8) & 0x3f;
 		if (upper)
 			one_lun[i].scsi_lun[0] =
 			    (upper | (SAM2_LUN_ADDRESS_METHOD << 6));
-		one_lun[i].scsi_lun[1] = i & 0xff;
+		one_lun[i].scsi_lun[1] = lun & 0xff;
 	}
 	return fill_from_dev_buffer(scp, arr,
 				    min((int)alloc_len, SDEBUG_RLUN_ARR_SZ));

-- Patrick Mansfield
-
: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]
  Powered by Linux