From owner-svn-src-all@freebsd.org Mon Oct 5 09:25:05 2015 Return-Path: Delivered-To: svn-src-all@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 45319A101FA; Mon, 5 Oct 2015 09:25:05 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org (repo.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 1CA1DB96; Mon, 5 Oct 2015 09:25:05 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t959P4V4043077; Mon, 5 Oct 2015 09:25:04 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t959P4aO043076; Mon, 5 Oct 2015 09:25:04 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201510050925.t959P4aO043076@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Mon, 5 Oct 2015 09:25:04 +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: r288763 - 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.20 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: Mon, 05 Oct 2015 09:25:05 -0000 Author: mav Date: Mon Oct 5 09:25:04 2015 New Revision: 288763 URL: https://svnweb.freebsd.org/changeset/base/288763 Log: MFC r287868: Make COMPARE AND WRITE report offset of difference. Modified: stable/10/sys/cam/ctl/ctl_backend_block.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/cam/ctl/ctl_backend_block.c ============================================================================== --- stable/10/sys/cam/ctl/ctl_backend_block.c Mon Oct 5 09:24:08 2015 (r288762) +++ stable/10/sys/cam/ctl/ctl_backend_block.c Mon Oct 5 09:25:04 2015 (r288763) @@ -354,6 +354,48 @@ ctl_complete_beio(struct ctl_be_block_io } } +static size_t +cmp(uint8_t *a, uint8_t *b, size_t size) +{ + size_t i; + + for (i = 0; i < size; i++) { + if (a[i] != b[i]) + break; + } + return (i); +} + +static void +ctl_be_block_compare(union ctl_io *io) +{ + struct ctl_be_block_io *beio; + uint64_t off, res; + int i; + uint8_t info[8]; + + beio = (struct ctl_be_block_io *)PRIV(io)->ptr; + off = 0; + for (i = 0; i < beio->num_segs; i++) { + res = cmp(beio->sg_segs[i].addr, + beio->sg_segs[i + CTLBLK_HALF_SEGS].addr, + beio->sg_segs[i].len); + off += res; + if (res < beio->sg_segs[i].len) + break; + } + if (i < beio->num_segs) { + scsi_u64to8b(off, info); + ctl_set_sense(&io->scsiio, /*current_error*/ 1, + /*sense_key*/ SSD_KEY_MISCOMPARE, + /*asc*/ 0x1D, /*ascq*/ 0x00, + /*type*/ SSD_ELEM_INFO, + /*size*/ sizeof(info), /*data*/ &info, + /*type*/ SSD_ELEM_NONE); + } else + ctl_set_success(&io->scsiio); +} + static int ctl_be_block_move_done(union ctl_io *io) { @@ -363,7 +405,6 @@ ctl_be_block_move_done(union ctl_io *io) #ifdef CTL_TIME_IO struct bintime cur_bt; #endif - int i; beio = (struct ctl_be_block_io *)PRIV(io)->ptr; be_lun = beio->lun; @@ -391,21 +432,7 @@ ctl_be_block_move_done(union ctl_io *io) ctl_set_success(&io->scsiio); } else if (lbalen->flags & CTL_LLF_COMPARE) { /* We have two data blocks ready for comparison. */ - for (i = 0; i < beio->num_segs; i++) { - if (memcmp(beio->sg_segs[i].addr, - beio->sg_segs[i + CTLBLK_HALF_SEGS].addr, - beio->sg_segs[i].len) != 0) - break; - } - if (i < beio->num_segs) - ctl_set_sense(&io->scsiio, - /*current_error*/ 1, - /*sense_key*/ SSD_KEY_MISCOMPARE, - /*asc*/ 0x1D, - /*ascq*/ 0x00, - SSD_ELEM_NONE); - else - ctl_set_success(&io->scsiio); + ctl_be_block_compare(io); } } else if ((io->io_hdr.port_status != 0) && ((io->io_hdr.status & CTL_STATUS_MASK) == CTL_STATUS_NONE ||