Refactor xpt_getattr() to make it more readable. No outwardly

visible functional changes, though code flow was modified a bit
internally to lessen the need for goto jumps and chained if
conditionals.
This commit is contained in:
Scott Long 2019-06-21 23:40:26 +00:00
parent 7318fcb51d
commit 0feb46b0c6

View File

@ -1244,6 +1244,7 @@ xpt_getattr(char *buf, size_t len, const char *attr, struct cam_path *path)
{
int ret = -1, l, o;
struct ccb_dev_advinfo cdai;
struct scsi_vpd_device_id *did;
struct scsi_vpd_id_descriptor *idd;
xpt_path_assert(path, MA_OWNED);
@ -1276,31 +1277,36 @@ xpt_getattr(char *buf, size_t len, const char *attr, struct cam_path *path)
cam_release_devq(cdai.ccb_h.path, 0, 0, 0, FALSE);
if (cdai.provsiz == 0)
goto out;
if (cdai.buftype == CDAI_TYPE_SCSI_DEVID) {
switch(cdai.buftype) {
case CDAI_TYPE_SCSI_DEVID:
did = (struct scsi_vpd_device_id *)cdai.buf;
if (strcmp(attr, "GEOM::lunid") == 0) {
idd = scsi_get_devid((struct scsi_vpd_device_id *)cdai.buf,
cdai.provsiz, scsi_devid_is_lun_naa);
idd = scsi_get_devid(did, cdai.provsiz,
scsi_devid_is_lun_naa);
if (idd == NULL)
idd = scsi_get_devid((struct scsi_vpd_device_id *)cdai.buf,
cdai.provsiz, scsi_devid_is_lun_eui64);
idd = scsi_get_devid(did, cdai.provsiz,
scsi_devid_is_lun_eui64);
if (idd == NULL)
idd = scsi_get_devid((struct scsi_vpd_device_id *)cdai.buf,
cdai.provsiz, scsi_devid_is_lun_uuid);
idd = scsi_get_devid(did, cdai.provsiz,
scsi_devid_is_lun_uuid);
if (idd == NULL)
idd = scsi_get_devid((struct scsi_vpd_device_id *)cdai.buf,
cdai.provsiz, scsi_devid_is_lun_md5);
idd = scsi_get_devid(did, cdai.provsiz,
scsi_devid_is_lun_md5);
} else
idd = NULL;
if (idd == NULL)
idd = scsi_get_devid((struct scsi_vpd_device_id *)cdai.buf,
cdai.provsiz, scsi_devid_is_lun_t10);
idd = scsi_get_devid(did, cdai.provsiz,
scsi_devid_is_lun_t10);
if (idd == NULL)
idd = scsi_get_devid((struct scsi_vpd_device_id *)cdai.buf,
cdai.provsiz, scsi_devid_is_lun_name);
idd = scsi_get_devid(did, cdai.provsiz,
scsi_devid_is_lun_name);
if (idd == NULL)
goto out;
break;
ret = 0;
if ((idd->proto_codeset & SVPD_ID_CODESET_MASK) == SVPD_ID_CODESET_ASCII) {
if ((idd->proto_codeset & SVPD_ID_CODESET_MASK) ==
SVPD_ID_CODESET_ASCII) {
if (idd->length < len) {
for (l = 0; l < idd->length; l++)
buf[l] = idd->identifier[l] ?
@ -1308,38 +1314,46 @@ xpt_getattr(char *buf, size_t len, const char *attr, struct cam_path *path)
buf[l] = 0;
} else
ret = EFAULT;
} else if ((idd->proto_codeset & SVPD_ID_CODESET_MASK) == SVPD_ID_CODESET_UTF8) {
break;
}
if ((idd->proto_codeset & SVPD_ID_CODESET_MASK) ==
SVPD_ID_CODESET_UTF8) {
l = strnlen(idd->identifier, idd->length);
if (l < len) {
bcopy(idd->identifier, buf, l);
buf[l] = 0;
} else
ret = EFAULT;
} else if ((idd->id_type & SVPD_ID_TYPE_MASK) == SVPD_ID_TYPE_UUID
&& idd->identifier[0] == 0x10) {
if ((idd->length - 2) * 2 + 4 < len) {
for (l = 2, o = 0; l < idd->length; l++) {
if (l == 6 || l == 8 || l == 10 || l == 12)
o += sprintf(buf + o, "-");
o += sprintf(buf + o, "%02x",
idd->identifier[l]);
}
} else
ret = EFAULT;
} else {
if (idd->length * 2 < len) {
for (l = 0; l < idd->length; l++)
sprintf(buf + l * 2, "%02x",
idd->identifier[l]);
} else
ret = EFAULT;
break;
}
} else {
if ((idd->id_type & SVPD_ID_TYPE_MASK) ==
SVPD_ID_TYPE_UUID && idd->identifier[0] == 0x10) {
if ((idd->length - 2) * 2 + 4 >= len) {
ret = EFAULT;
break;
}
for (l = 2, o = 0; l < idd->length; l++) {
if (l == 6 || l == 8 || l == 10 || l == 12)
o += sprintf(buf + o, "-");
o += sprintf(buf + o, "%02x",
idd->identifier[l]);
}
break;
}
if (idd->length * 2 < len) {
for (l = 0; l < idd->length; l++)
sprintf(buf + l * 2, "%02x",
idd->identifier[l]);
} else
ret = EFAULT;
break;
default:
if (cdai.provsiz < len) {
cdai.buf[cdai.provsiz] = 0;
ret = 0;
} else
ret = EFAULT;
break;
}
out: