From owner-svn-src-stable@freebsd.org Sat Apr 16 02:47:48 2016 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 233F4B0E450; Sat, 16 Apr 2016 02:47:48 +0000 (UTC) (envelope-from scottl@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id F1FB81AC0; Sat, 16 Apr 2016 02:47:47 +0000 (UTC) (envelope-from scottl@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u3G2llPR089991; Sat, 16 Apr 2016 02:47:47 GMT (envelope-from scottl@FreeBSD.org) Received: (from scottl@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u3G2llUF089989; Sat, 16 Apr 2016 02:47:47 GMT (envelope-from scottl@FreeBSD.org) Message-Id: <201604160247.u3G2llUF089989@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: scottl set sender to scottl@FreeBSD.org using -f From: Scott Long Date: Sat, 16 Apr 2016 02:47:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r298093 - stable/10/sys/cam/scsi X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 16 Apr 2016 02:47:48 -0000 Author: scottl Date: Sat Apr 16 02:47:46 2016 New Revision: 298093 URL: https://svnweb.freebsd.org/changeset/base/298093 Log: MFC r297925, r297926: Add scsi_cdb_sbuf() for handling CDB strings. Reimplement scsi_cdb_string() in terms of it. Use scsi_cdb_sbuf() inside of scsi_command_string now that the temporary string storage is no longer needed. Sponsored by: Netflix Modified: stable/10/sys/cam/scsi/scsi_all.c stable/10/sys/cam/scsi/scsi_all.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/cam/scsi/scsi_all.c ============================================================================== --- stable/10/sys/cam/scsi/scsi_all.c Sat Apr 16 02:32:12 2016 (r298092) +++ stable/10/sys/cam/scsi/scsi_all.c Sat Apr 16 02:47:46 2016 (r298093) @@ -3464,14 +3464,32 @@ scsi_error_action(struct ccb_scsiio *csi char * scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string, size_t len) { + struct sbuf sb; + int error; + + if (len == 0) + return (""); + + sbuf_new(&sb, cdb_string, len, SBUF_FIXEDLEN); + + scsi_cdb_sbuf(cdb_ptr, &sb); + + /* ENOMEM just means that the fixed buffer is full, OK to ignore */ + error = sbuf_finish(&sb); + if (error != 0 && error != ENOMEM) + return (""); + + return(sbuf_data(&sb)); +} + +void +scsi_cdb_sbuf(u_int8_t *cdb_ptr, struct sbuf *sb) +{ u_int8_t cdb_len; int i; if (cdb_ptr == NULL) - return(""); - - /* Silence warnings */ - cdb_len = 0; + return; /* * This is taken from the SCSI-3 draft spec. @@ -3508,12 +3526,11 @@ scsi_cdb_string(u_int8_t *cdb_ptr, char cdb_len = 12; break; } - *cdb_string = '\0'; + for (i = 0; i < cdb_len; i++) - snprintf(cdb_string + strlen(cdb_string), - len - strlen(cdb_string), "%02hhx ", cdb_ptr[i]); + sbuf_printf(sb, "%02hhx ", cdb_ptr[i]); - return(cdb_string); + return; } const char * @@ -3562,7 +3579,6 @@ scsi_command_string(struct cam_device *d #endif /* _KERNEL/!_KERNEL */ { struct scsi_inquiry_data *inq_data; - char cdb_str[(SCSI_MAX_CDBLEN * 3) + 1]; #ifdef _KERNEL struct ccb_getdev *cgd; #endif /* _KERNEL */ @@ -3595,15 +3611,13 @@ scsi_command_string(struct cam_device *d #endif /* _KERNEL/!_KERNEL */ if ((csio->ccb_h.flags & CAM_CDB_POINTER) != 0) { - sbuf_printf(sb, "%s. CDB: %s", - scsi_op_desc(csio->cdb_io.cdb_ptr[0], inq_data), - scsi_cdb_string(csio->cdb_io.cdb_ptr, cdb_str, - sizeof(cdb_str))); + sbuf_printf(sb, "%s. CDB: ", + scsi_op_desc(csio->cdb_io.cdb_ptr[0], inq_data)); + scsi_cdb_sbuf(csio->cdb_io.cdb_ptr, sb); } else { - sbuf_printf(sb, "%s. CDB: %s", - scsi_op_desc(csio->cdb_io.cdb_bytes[0], inq_data), - scsi_cdb_string(csio->cdb_io.cdb_bytes, cdb_str, - sizeof(cdb_str))); + sbuf_printf(sb, "%s. CDB: ", + scsi_op_desc(csio->cdb_io.cdb_bytes[0], inq_data)); + scsi_cdb_sbuf(csio->cdb_io.cdb_bytes, sb); } #ifdef _KERNEL Modified: stable/10/sys/cam/scsi/scsi_all.h ============================================================================== --- stable/10/sys/cam/scsi/scsi_all.h Sat Apr 16 02:32:12 2016 (r298092) +++ stable/10/sys/cam/scsi/scsi_all.h Sat Apr 16 02:47:46 2016 (r298093) @@ -3644,6 +3644,7 @@ const char * scsi_op_desc(u_int16_t opco struct scsi_inquiry_data *inq_data); char * scsi_cdb_string(u_int8_t *cdb_ptr, char *cdb_string, size_t len); +void scsi_cdb_sbuf(u_int8_t *cdb_ptr, struct sbuf *sb); void scsi_print_inquiry(struct scsi_inquiry_data *inq_data); void scsi_print_inquiry_short(struct scsi_inquiry_data *inq_data);