ID:394 - plugins/usb: Fix probe for SCSI devices

The current USB plugin doesn't find my IPMI channel:

  # ipmitool -I usb mc info
  Error in USB session setup

  Unable to setup interface usb
  Error loading interface usb

This is beacuse I have more than 8 scsi-generic devices that identify
as AMI:

  # grep -c ^AMI /proc/scsi/sg/device_strs
  13

So we end up hitting the max in FindG2CDROM, and abort without finding
the actual IPMI endpoint (on my system, this is /dev/sg11).

This change bumps that maximum up to 16.

However, that means we hit another bug in scsiProbeNew, where if
we hit the end of the file without completely filling the array,
we return with an error. This change handles the EOF condition
gracefully instead.

Also, fp is never going to become NULL; we don't need to check for that
condition.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
This commit is contained in:
Jeremy Kerr 2015-10-15 17:40:34 +08:00 committed by Zdenek Styblik
parent 999cd0ad91
commit 607cfe6f47

View File

@ -131,11 +131,7 @@ scsiProbeNew(int *num_ami_devices, int *sg_nos)
while (1) { while (1) {
/* Read line by line and search for "AMI" */ /* Read line by line and search for "AMI" */
if (fgets(linebuf, 80, fp) == NULL) { if (fgets(linebuf, 80, fp) == NULL) {
if (fp != NULL) { break;
fclose(fp);
}
/* Return 1 on error */
return 1;
} }
if (sscanf(linebuf, "%s", vendor) == 1) { if (sscanf(linebuf, "%s", vendor) == 1) {
@ -151,9 +147,7 @@ scsiProbeNew(int *num_ami_devices, int *sg_nos)
} }
*num_ami_devices = numdevfound; *num_ami_devices = numdevfound;
if (fp != NULL) {
fclose(fp); fclose(fp);
}
return 0; return 0;
} }
@ -268,8 +262,8 @@ FindG2CDROM(struct ipmi_intf *intf)
{ {
int err = 0; int err = 0;
char device[256]; char device[256];
int devarray[8]; int devarray[16];
int numdev = 8; int numdev = 16;
int iter; int iter;
err = scsiProbeNew(&numdev, devarray); err = scsiProbeNew(&numdev, devarray);