From nobody Thu May 2 22:47:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520524387865597.3310384831144; Thu, 8 Mar 2018 07:53:07 -0800 (PST) Received: from localhost ([::1]:39837 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etxqi-0007M6-Be for importer@patchew.org; Thu, 08 Mar 2018 10:52:56 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59195) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etxpe-00071H-VV for qemu-devel@nongnu.org; Thu, 08 Mar 2018 10:51:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1etxpb-0002cC-Tm for qemu-devel@nongnu.org; Thu, 08 Mar 2018 10:51:51 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:43164 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1etxpb-0002bS-Px for qemu-devel@nongnu.org; Thu, 08 Mar 2018 10:51:47 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3EDAE76FB9 for ; Thu, 8 Mar 2018 15:51:47 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-37.ams2.redhat.com [10.36.117.37]) by smtp.corp.redhat.com (Postfix) with ESMTP id 997E3215CDA7; Thu, 8 Mar 2018 15:51:46 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 8 Mar 2018 16:51:45 +0100 Message-Id: <20180308155145.19315-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Thu, 08 Mar 2018 15:51:47 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Thu, 08 Mar 2018 15:51:47 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'pbonzini@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH] scsi: support NDOB (no data-out buffer) for WRITE SAME commands X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: famz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" A NDOB bit set to one specifies that the disk shall not transfer data from the data-out buffer and shall process the command as if the data-out buffer contained user data set to all zeroes. Signed-off-by: Paolo Bonzini --- hw/scsi/scsi-bus.c | 2 +- hw/scsi/scsi-disk.c | 2 +- tests/virtio-scsi-test.c | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c index 1eaeffc830..9646743a7d 100644 --- a/hw/scsi/scsi-bus.c +++ b/hw/scsi/scsi-bus.c @@ -944,7 +944,7 @@ static int scsi_req_xfer(SCSICommand *cmd, SCSIDevice *= dev, uint8_t *buf) break; case WRITE_SAME_10: case WRITE_SAME_16: - cmd->xfer =3D dev->blocksize; + cmd->xfer =3D buf[1] & 1 ? 0 : dev->blocksize; break; case READ_CAPACITY_10: cmd->xfer =3D 8; diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index c65c1ce56d..5b7a48f5a5 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -1807,7 +1807,7 @@ static void scsi_disk_emulate_write_same(SCSIDiskReq = *r, uint8_t *inbuf) return; } =20 - if (buffer_is_zero(inbuf, s->qdev.blocksize)) { + if ((req->cmd.buf[1] & 0x1) || buffer_is_zero(inbuf, s->qdev.blocksize= )) { int flags =3D (req->cmd.buf[1] & 0x8) ? BDRV_REQ_MAY_UNMAP : 0; =20 /* The request is used as the AIO opaque value, so add a ref. */ diff --git a/tests/virtio-scsi-test.c b/tests/virtio-scsi-test.c index 7393d69bb2..037872bb98 100644 --- a/tests/virtio-scsi-test.c +++ b/tests/virtio-scsi-test.c @@ -216,6 +216,9 @@ static void test_unaligned_write_same(void) const uint8_t write_same_cdb_2[VIRTIO_SCSI_CDB_SIZE] =3D { 0x41, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x33, 0x00, 0x00 }; + const uint8_t write_same_cdb_ndob[VIRTIO_SCSI_CDB_SIZE] =3D { + 0x41, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x33, 0x00, 0x00 + }; =20 vs =3D qvirtio_scsi_pci_init(PCI_SLOT); =20 @@ -225,6 +228,9 @@ static void test_unaligned_write_same(void) g_assert_cmphex(0, =3D=3D, virtio_scsi_do_command(vs, write_same_cdb_2, NULL, 0, buf2, 512, N= ULL)); =20 + g_assert_cmphex(0, =3D=3D, + virtio_scsi_do_command(vs, write_same_cdb_ndob, NULL, 0, NULL, 0, = NULL)); + qvirtio_scsi_pci_free(vs); } =20 --=20 2.14.3