REPORT LUNS
Hi,
Wile trying to figure out how to ignore non-existing LUNs on RAID devices, I have fallen across an error in scsilun_to_int() where it doesn't behave as the comment suggests and a problematic piece of code in scsi_report_lun_scan().
Patch is included.
Signature · 3 lines
Josef Möllers (Pinguinpfleger bei FSC) If failure had no penalty success would not be a prize -- T. Pratchett
drivers/scsi/scsi_scan.c +8 -3
@@ -884,8 +884,8 @@ lun =0 ;for (i =0 ; i <sizeof (lun); i +=2 ) - lun = lun | (((scsilun->scsi_lun[i] <<8 ) | - scsilun->scsi_lun[i +1 ]) << (i *8 )); + lun = lun | (((scsilun->scsi_lun[i] &0x3f ) << (i *8 +1 )) | + ((scsilun->scsi_lun[i +1 ]) << (i *8 )));return lun; }
@@ -1027,13 +1027,18 @@* the header, so start at 1 and go up to and including num_luns. */ for (lunp = &lun_data[1 ]; lunp <= &lun_data[num_luns]; lunp++) { +int j; + lun =scsilun_to_int (lunp);/* * Check if the unused part of lunp is non-zero, and so * does not fit in lun. */ -if (memcmp (&lunp->scsi_lun[sizeof (lun)],"\0\0\0\0" ,4 )) { +for (j =sizeof (lun); j <sizeof (struct scsi_lun ); j++) +if (lunp->scsi_lun[j] !=0 ) +break ; +if (j <sizeof (struct scsi_lun )) {int i;/*
Quoted 8 lines · Josef Möllers
Hi,
Wile trying to figure out how to ignore non-existing LUNs on RAID devices, I have fallen across an error in
scsilun_to_int()where it doesn't behave as the comment suggests and a problematic piece of code inscsi_report_lun_scan().Patch is included.
If we clear the upper bits (address method, per SAM-3), someone has to eventually set them again, and this is not handled today in linux scsi core.
What adapter and driver are you using? AFAIK the Emulex driver figures out the address method (high two bits) and ors it with each LUN sent down.
I don't recall what happens with the qlogic driver, I thought it had some special code to handle these, but can't find it.
For SPI it seems OK to ignore the upper bits since they are truncated. Maybe some devices work OK this way - they set an address method of 10b or 01b, and then don't care that the LUN comes in without the high bits set.
So the change might work for some adapters, but break on others.
We are probably broken for anyone using the 11b extended logical unit addressing method (with or without your patch).
Can you change your RAID device to use the peripheral device addressing method - address method of 00b - instead?
In any case we should do what actually works, given that we are translating an 8 byte LUN to a (host ordered) int, and later converting that back to an 8 or 1 byte LUN (for qlogic, to a 2 byte LUN that is then converted to an 8 byte LUN).
Quoted 10 lines
drivers/scsi/scsi_scan.c +2
-0@@ -1027,13 +1027,18 @@* the header, so start at 1 and go up to and including num_luns. */ for (lunp = &lun_data[1 ]; lunp <= &lun_data[num_luns]; lunp++) { +int j; + lun =scsilun_to_int (lunp);/* * Check if the unused part of lunp is non-zero, and so
drivers/scsi/scsi_scan.c line 1044
Quoted 10 lines
drivers/scsi/scsi_scan.c +4
-1* does not fit in lun. */ -if (memcmp (&lunp->scsi_lun[sizeof (lun)],"\0\0\0\0" ,4 )) { +for (j =sizeof (lun); j <sizeof (struct scsi_lun ); j++) +if (lunp->scsi_lun[j] !=0 ) +break ; +if (j <sizeof (struct scsi_lun )) {int i;/*
What does the above patch fix? It looks like they both check if the last four bytes are 0.
PS: Going offline really soon now for about a week.
-- Patrick Mansfield
-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 9 lines · Patrick Mansfield
Quoted 7 lines · Josef Möllers
Hi,
Wile trying to figure out how to ignore non-existing LUNs on RAID devices, I have fallen across an error in
scsilun_to_int()where it doesn't behave as the comment suggests and a problematic piece of code inscsi_report_lun_scan().
Quoted 5 lines
Quoted 1 line
Patch is included.
If we clear the upper bits (address method, per SAM-3), someone has to eventually set them again, and this is not handled today in linux scsi core.
The comment said that the upper two bits were ignored which they were not in the original code, so, apart from fixing the shifts, I also added the mask to keep the code in sync with the comment. I haven't yet followed the use of the value thus created.
Quoted 19 lines
Quoted 19 lines
drivers/scsi/scsi_scan.c +6
-1@@ -1027,13 +1027,18 @@* the header, so start at 1 and go up to and including num_luns. */ for (lunp = &lun_data[1 ]; lunp <= &lun_data[num_luns]; lunp++) { +int j; + lun =scsilun_to_int (lunp);/* * Check if the unused part of lunp is non-zero, and so * does not fit in lun. */ -if (memcmp (&lunp->scsi_lun[sizeof (lun)],"\0\0\0\0" ,4 )) { +for (j =sizeof (lun); j <sizeof (struct scsi_lun ); j++) +if (lunp->scsi_lun[j] !=0 ) +break ; +if (j <sizeof (struct scsi_lun )) {int i;
Quoted 4 lines
Review line 1044
Quoted 1 line
(quoted diff) +0
-0/*What does the above patch fix? It looks like they both check if the last four bytes are 0.
It does so, iff sizeof(lun) is 4 and sizeof(struct scsi_lun) is 8. Perhaps it was more a question of personal taste to change the code so that it also works for 64 bit ints.
Signature · 7 lines
Josef Möllers (Pinguinpfleger bei FSC) If failure had no penalty success would not be a prize -- T. Pratchett - To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 12 lines · Josef Möllers
Quoted 11 lines · Patrick Mansfield
Quoted 8 lines · Josef Möllers
Hi,
Wile trying to figure out how to ignore non-existing LUNs on RAID devices, I have fallen across an error in
scsilun_to_int()where it doesn't behave as the comment suggests and a problematic piece of code inscsi_report_lun_scan().Patch is included.
Quoted 8 lines
Quoted 3 lines
If we clear the upper bits (address method, per SAM-3), someone has to eventually set them again, and this is not handled today in linux scsi core.
The comment said that the upper two bits were ignored which they were not in the original code, so, apart from fixing the shifts, I also added the mask to keep the code in sync with the comment. I haven't yet followed the use of the value thus created.
Ignored meaning "does nothing with it", when we should probably do something - proper conversion, an error or warning output. The current code might work (with high bits set), if we did not exceed the host->max_lun. We might need an 8 byte lun everywhere to make it work right for all cases.
Can you give more details of the problem you are seeing, and software (adapter driver) and hardware in use?
I did not notice your shift changes - I don't see how they work or what it fixes.
If scsi_lun was: 0x1 0x2 0x3 0x4 0 0 0 0
Current code:
First loop in scsilun_to_int, with i = 0:
lun = 0 | ( (0x1 << 8 | 0x2) << 0) = 0x0102
Second loop i = 2:
lun = 0x0102 | ( (0x3 << 8 | 0x4) << 16) = 0x03040102
Your patch would give:
First loop i = 0:
lun = 0 | ((0x1 & 0x3f) << 1) | (0x2 << 0) = 0x02
Second loop i = 2:
lun = 0x02 | ( ((0x3 & 0x3f) << 17) | (0x4 << 16) = 0x00060002
-- Patrick Mansfield
-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 23 lines · Patrick Mansfield
Quoted 12 lines · Josef Möllers
Quoted 11 lines · Patrick Mansfield
Quoted 8 lines · Josef Möllers
Hi,
Wile trying to figure out how to ignore non-existing LUNs on RAID devices, I have fallen across an error in
scsilun_to_int()where it doesn't behave as the comment suggests and a problematic piece of code inscsi_report_lun_scan().Patch is included.
Quoted 8 lines
Quoted 3 lines
If we clear the upper bits (address method, per SAM-3), someone has to eventually set them again, and this is not handled today in linux scsi core.
The comment said that the upper two bits were ignored which they were not in the original code, so, apart from fixing the shifts, I also added the mask to keep the code in sync with the comment. I haven't yet followed the use of the value thus created.
Quoted 5 lines
Ignored meaning "does nothing with it", when we should probably do something - proper conversion, an error or warning output. The current code might work (with high bits set), if we did not exceed the
host->max_lun. We might need an 8 byte lun everywhere to make it work right for all cases.
OK.
Quoted 2 lines
Can you give more details of the problem you are seeing, and software (adapter driver) and hardware in use?
The main problem we have is with current 2.4 kernels that some RAID systems report SCSI-2 but allow for more than 8 LUNs, so rather than put each box into the device_list[] (BLIST_SPARSELUN), I was investigating how this problem could be solved in an orderly fashion: either by using REPORT LUNS or by examining the Peripheral Qualifier in the INQUIRY data (which would require BLIST_SPARSELUN, nonetheless).
I looked at the 2.5 code and found that REPORT LUNS was implemented but stumbled across the comment. I couln't really make sense out of SCSI-3 and a manual I have for EMC RAID subsystems on the data returned by the REPORT LUNS command. I then looked at the code, got confused about the shifts and broke the code with my patch.
Quoted 2 lines
I did not notice your shift changes - I don't see how they work or what it fixes.
Looking at it fresh in the morning: no, it doesn't fix anything, it breaks code which is OK. I learnt my lesson to be more careful.
Quoted 14 lines
If
scsi_lunwas:0x10x20x30x40 0 0 0Current code:
First loop in
scsilun_to_int, with i = 0:lun = 0 | ( (0x1 << 8 | 0x2) << 0) = 0x0102Second loop i = 2:
lun = 0x0102 | ( (0x3 << 8 | 0x4) << 16) = 0x03040102Your patch would give:
Quoted 7 lines
First loop i = 0:
lun = 0 | ((0x1 & 0x3f) << 1) | (0x2 << 0) = 0x02Second loop i = 2:
lun = 0x02 | ( ((0x3 & 0x3f) << 17) | (0x4 << 16) = 0x00060002
You're absolutely right. If i needed an excuse (other than not having been careful enough), I'd attribute it to the heat.
I'll test my patches more thoroughly in the future.
Sorry,
Josef
Signature · 7 lines
Josef Möllers (Pinguinpfleger bei FSC) If failure had no penalty success would not be a prize -- T. Pratchett - To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html