svn commit: r349827 - stable/12/sys/cam
Alexander Motin
mav at FreeBSD.org
Sun Jul 7 18:50:24 UTC 2019
Author: mav
Date: Sun Jul 7 18:50:23 2019
New Revision: 349827
URL: https://svnweb.freebsd.org/changeset/base/349827
Log:
MFC r349243: Optimize xpt_getattr().
Do not allocate temporary buffer for attributes we are going to return
as-is, just make sure to NUL-terminate them. Do not zero temporary 64KB
buffer for CDAI_TYPE_SCSI_DEVID, XPT tells us how much data it filled
and there are also length fields inside the returned data also.
Modified:
stable/12/sys/cam/cam_xpt.c
Directory Properties:
stable/12/ (props changed)
Modified: stable/12/sys/cam/cam_xpt.c
==============================================================================
--- stable/12/sys/cam/cam_xpt.c Sun Jul 7 18:49:39 2019 (r349826)
+++ stable/12/sys/cam/cam_xpt.c Sun Jul 7 18:50:23 2019 (r349827)
@@ -1262,6 +1262,7 @@ xpt_getattr(char *buf, size_t len, const char *attr, s
cdai.ccb_h.func_code = XPT_DEV_ADVINFO;
cdai.flags = CDAI_FLAG_NONE;
cdai.bufsiz = len;
+ cdai.buf = buf;
if (!strcmp(attr, "GEOM::ident"))
cdai.buftype = CDAI_TYPE_SERIAL_NUM;
@@ -1271,14 +1272,14 @@ xpt_getattr(char *buf, size_t len, const char *attr, s
strcmp(attr, "GEOM::lunname") == 0) {
cdai.buftype = CDAI_TYPE_SCSI_DEVID;
cdai.bufsiz = CAM_SCSI_DEVID_MAXLEN;
+ cdai.buf = malloc(cdai.bufsiz, M_CAMXPT, M_NOWAIT);
+ if (cdai.buf == NULL) {
+ ret = ENOMEM;
+ goto out;
+ }
} else
goto out;
- cdai.buf = malloc(cdai.bufsiz, M_CAMXPT, M_NOWAIT|M_ZERO);
- if (cdai.buf == NULL) {
- ret = ENOMEM;
- goto out;
- }
xpt_action((union ccb *)&cdai); /* can only be synchronous */
if ((cdai.ccb_h.status & CAM_DEV_QFRZN) != 0)
cam_release_devq(cdai.ccb_h.path, 0, 0, 0, FALSE);
@@ -1343,13 +1344,15 @@ xpt_getattr(char *buf, size_t len, const char *attr, s
ret = EFAULT;
}
} else {
- ret = 0;
- if (strlcpy(buf, cdai.buf, len) >= len)
+ if (cdai.provsiz < len) {
+ cdai.buf[cdai.provsiz] = 0;
+ ret = 0;
+ } else
ret = EFAULT;
}
out:
- if (cdai.buf != NULL)
+ if ((char *)cdai.buf != buf)
free(cdai.buf, M_CAMXPT);
return ret;
}
More information about the svn-src-all
mailing list