Skip to contentSkip to conversation

- export scsilun_to_int

PATCH Eric Moore 3 participants 3 messages Jan 31, 2007 – Feb 1, 2007

Subsystems (2)
lore
Share & tools
lore

Eric Moore

author
#0 lore raw
Quoted 7 lines · James Bottomley

Yes, I missed that. However, the mf (SCSIIORequest_t) comes back with the 8 byte luns, couldn't you just run vdevice->lun through int_to_scsilun and compare on that?

I'm really reluctant to export the lun to int lossy transform because it
will encourage bad uses.

I've removed usage of scsilun_to_int.
Now I use int_to_scsilun to convert vdevice->lun, then added a new function
mptscsih_cmp_scsilun which compares the two luns. This applies over all the
previous patchs I posted this week.

drivers/message/fusion/mptscsih.c +27 -5
diff -uarpN b/drivers/message/fusion/mptscsih.c a/drivers/message/fusion/mptscsih.c
@@ -996,6 +996,26 @@ mptscsih_flush_running_cmds(MPT_SCSI_HOS
 }
 
 /*
+ *	mptscsih_cmp_scsilun - compare two luns, lun1 and lun2
+ *	@lun1: 1st lun
+ *	@lun2: 2nd lun
+ *
+ *	Returns: zero, if they compare, or 1 when it doesn't
+ *
+ */
+static int
+mptscsih_cmp_scsilun(struct scsi_lun * lun1, struct scsi_lun * lun2)
+{
+	int i;
+
+	for (i = 0; i < 8 ; i++)
+		if (lun1->scsi_lun[i] != lun2->scsi_lun[i])
+			return 1;
+
+	return 0;
+}
+
+/*
  *	mptscsih_search_running_cmds - Delete any commands associated
  *		with the specified target and lun. Function called only
  *		when a lun is disable by mid-layer.
@@ -1016,7 +1036,7 @@ mptscsih_search_running_cmds(MPT_SCSI_HO
 	int		 ii;
 	int		 max = hd->ioc->req_depth;
 	struct scsi_cmnd *sc;
-	int		 lun;
+	struct scsi_lun  lun;
 
 	dsprintk((KERN_INFO MYNAM ": search_running channel %d id %d lun %d max %d\n",
 	    vdevice->vtarget->channel, vdevice->vtarget->id, vdevice->lun, max));
@@ -1027,13 +1047,15 @@ mptscsih_search_running_cmds(MPT_SCSI_HO
 			mf = (SCSIIORequest_t *)MPT_INDEX_2_MFPTR(hd->ioc, ii);
 			if (mf == NULL)
 				continue;
-			lun = scsilun_to_int((struct scsi_lun *)mf->LUN);
-			dsprintk(( "search_running: found (sc=%p, mf = %p) chanel %d id %d, lun %d \n",
-			    hd->ScsiLookup[ii], mf, mf->Bus, mf->TargetID, lun));
+			int_to_scsilun(vdevice->lun, &lun);
 			if ((mf->Bus != vdevice->vtarget->channel) ||
 			    (mf->TargetID != vdevice->vtarget->id) ||
-			    (lun != vdevice->lun))
+			    mptscsih_cmp_scsilun(&lun,
+				(struct scsi_lun *)mf->LUN))
 				continue;
+			dsprintk(( "search_running: found (sc=%p, mf = %p) "
+			    "channel %d id %d, lun %d \n", hd->ScsiLookup[ii],
+			    mf, mf->Bus, mf->TargetID, vdevice->lun));
 
 			/* Cleanup
 			 */
#1 lore raw

drivers/message/fusion/mptscsih.c mptscsih_flush_running_cmds(MPT_SCSI_HOS · line 1016

Quoted 11 lines · Eric Moore

static int

drivers/message/fusion/mptscsih.c +10 -0
+mptscsih_cmp_scsilun(struct scsi_lun * lun1, struct scsi_lun * lun2)
+{
+       int i;
+
+       for (i = 0; i < 8 ; i++)
+               if (lun1->scsi_lun[i] != lun2->scsi_lun[i])
+                       return 1;
+
+       return 0;
+}

what's wrong with

memcmp(lun1->scsi_lun, lun2->scsi_lun, 8)

rather than introducing a wrapper? The compiler can even optimise memcmp for a fixed size nicely.

James

#2 lore raw
Quoted 15 lines · James Bottomley

drivers/message/fusion/mptscsih.c mptscsih_flush_running_cmds(MPT_SCSI_HOS · line 1016

Quoted 11 lines · Eric Moore

static int

drivers/message/fusion/mptscsih.c +10 -0
+mptscsih_cmp_scsilun(struct scsi_lun * lun1, struct scsi_lun * lun2)
+{
+       int i;
+
+       for (i = 0; i < 8 ; i++)
+               if (lun1->scsi_lun[i] != lun2->scsi_lun[i])
+                       return 1;
+
+       return 0;
+}

what's wrong with

Quoted 4 lines

memcmp(lun1->scsi_lun, lun2->scsi_lun, 8)

rather than introducing a wrapper? The compiler can even optimise memcmp for a fixed size nicely.

I would rather introduce a wrapper that calls memcmp()

That's why I have done in my scsilun tree (jgarzik/scsilun-2.6.git, branches submit1, submit1 and hacking)

Jeff