From owner-svn-src-all@FreeBSD.ORG Sun Nov 2 17:29:49 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id E2405613; Sun, 2 Nov 2014 17:29:48 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::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 C355FCC2; Sun, 2 Nov 2014 17:29:48 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id sA2HTmbY028724; Sun, 2 Nov 2014 17:29:48 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id sA2HTm02028723; Sun, 2 Nov 2014 17:29:48 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201411021729.sA2HTm02028723@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Sun, 2 Nov 2014 17:29:48 +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: r273979 - stable/10/sys/cam/ctl X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 02 Nov 2014 17:29:49 -0000 Author: mav Date: Sun Nov 2 17:29:48 2014 New Revision: 273979 URL: https://svnweb.freebsd.org/changeset/base/273979 Log: MFC r273640: Add support for 12/16-byte EUI and 16-byte NAA IDs. Modified: stable/10/sys/cam/ctl/ctl.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/cam/ctl/ctl.c ============================================================================== --- stable/10/sys/cam/ctl/ctl.c Sun Nov 2 17:28:44 2014 (r273978) +++ stable/10/sys/cam/ctl/ctl.c Sun Nov 2 17:29:48 2014 (r273979) @@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -4351,6 +4352,36 @@ ctl_init_log_page_index(struct ctl_lun * return (CTL_RETVAL_COMPLETE); } +static int +hex2bin(const char *str, uint8_t *buf, int buf_size) +{ + int i; + u_char c; + + memset(buf, 0, buf_size); + while (isspace(str[0])) + str++; + if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) + str += 2; + buf_size *= 2; + for (i = 0; str[i] != 0 && i < buf_size; i++) { + c = str[i]; + if (isdigit(c)) + c -= '0'; + else if (isalpha(c)) + c -= isupper(c) ? 'A' - 10 : 'a' - 10; + else + break; + if (c >= 16) + break; + if ((i & 1) == 0) + buf[i / 2] |= (c << 4); + else + buf[i / 2] |= c; + } + return ((i + 1) / 2); +} + /* * LUN allocation. * @@ -4416,15 +4447,14 @@ ctl_alloc_lun(struct ctl_softc *ctl_soft } eui = ctl_get_opt(&be_lun->options, "eui"); if (eui != NULL) { - len += sizeof(struct scsi_vpd_id_descriptor) + 8; + len += sizeof(struct scsi_vpd_id_descriptor) + 16; } naa = ctl_get_opt(&be_lun->options, "naa"); if (naa != NULL) { - len += sizeof(struct scsi_vpd_id_descriptor) + 8; + len += sizeof(struct scsi_vpd_id_descriptor) + 16; } lun->lun_devid = malloc(sizeof(struct ctl_devid) + len, M_CTL, M_WAITOK | M_ZERO); - lun->lun_devid->len = len; desc = (struct scsi_vpd_id_descriptor *)lun->lun_devid->data; desc->proto_codeset = SVPD_ID_CODESET_ASCII; desc->id_type = SVPD_ID_PIV | SVPD_ID_ASSOC_LUN | SVPD_ID_TYPE_T10; @@ -4454,8 +4484,10 @@ ctl_alloc_lun(struct ctl_softc *ctl_soft desc->proto_codeset = SVPD_ID_CODESET_BINARY; desc->id_type = SVPD_ID_PIV | SVPD_ID_ASSOC_LUN | SVPD_ID_TYPE_EUI64; - desc->length = 8; - scsi_u64to8b(strtouq(eui, NULL, 0), desc->identifier); + desc->length = hex2bin(eui, desc->identifier, 16); + desc->length = desc->length > 12 ? 16 : + (desc->length > 8 ? 12 : 8); + len -= 16 - desc->length; } if (naa != NULL) { desc = (struct scsi_vpd_id_descriptor *)(&desc->identifier[0] + @@ -4463,9 +4495,11 @@ ctl_alloc_lun(struct ctl_softc *ctl_soft desc->proto_codeset = SVPD_ID_CODESET_BINARY; desc->id_type = SVPD_ID_PIV | SVPD_ID_ASSOC_LUN | SVPD_ID_TYPE_NAA; - desc->length = 8; - scsi_u64to8b(strtouq(naa, NULL, 0), desc->identifier); + desc->length = hex2bin(naa, desc->identifier, 16); + desc->length = desc->length > 8 ? 16 : 8; + len -= 16 - desc->length; } + lun->lun_devid->len = len; mtx_lock(&ctl_softc->ctl_lock); /*