From nobody Tue Feb 10 07:42:32 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1573205912; cv=none; d=zoho.com; s=zohoarc; b=G7p6nv3J8gS+wIC6lRArO1BhKMPTKpTv9/qSwi1FMXchSwIsxYoqwcL+000KzqApDYgIesGIyfV3rhKGgjr/GxC3fOLPQJANcuFrTZ74Q1CUR/M07xTHmmZDCVb7HtAi/Y/KPSVLBt97Sd8MGWpn8TeshosOcldMPSxl4+IrAxs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573205912; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=r5zdx6/A4HZL3Yk8sLfwRt/KT7Mpao2ycRNSnyCbXJU=; b=dxg8XzRH//iUSBIalEmfArYelLKtBDFfJJbFNSm23HAz41KEWeUJufE7EmYZc1Mjsz0Co22xQETqJpzhse9iWy+NPVFCma5TN6haMLI9XwzshA0S11VTiEBjedpl7sPBLdN4H7JRSOt2Y47sp2Zk0U36u23giekscYwj6qhLzYQ= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1573205912340901.5571567057239; Fri, 8 Nov 2019 01:38:32 -0800 (PST) Received: from localhost ([::1]:51104 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iT0is-00054o-94 for importer@patchew.org; Fri, 08 Nov 2019 04:38:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37739) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iT0hB-0003F7-Fw for qemu-devel@nongnu.org; Fri, 08 Nov 2019 04:36:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iT0h9-0002UL-Hi for qemu-devel@nongnu.org; Fri, 08 Nov 2019 04:36:45 -0500 Received: from cmccmta2.chinamobile.com ([221.176.66.80]:4899) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1iT0h4-0002LD-80; Fri, 08 Nov 2019 04:36:39 -0500 Received: from spf.mail.chinamobile.com (unknown[172.16.121.3]) by rmmx-syy-dmz-app06-12006 (RichMail) with SMTP id 2ee65dc536d6057-8550e; Fri, 08 Nov 2019 17:35:18 +0800 (CST) Received: from localhost.novalocal (unknown[112.25.65.41]) by rmsmtp-syy-appsvr02-12002 (RichMail) with SMTP id 2ee25dc536d2c26-16e3e; Fri, 08 Nov 2019 17:35:17 +0800 (CST) X-RM-TRANSID: 2ee65dc536d6057-8550e X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 X-RM-TRANSID: 2ee25dc536d2c26-16e3e From: Yaowei Bai To: pbonzini@redhat.com, fam@euphon.net, dillaman@redhat.com, kwolf@redhat.com, mreitz@redhat.com Subject: [PATCH 1/4 V2] block: add SCSI COMPARE_AND_WRITE support Date: Fri, 8 Nov 2019 17:35:38 +0800 Message-Id: <1573205741-2094-2-git-send-email-baiyaowei@cmss.chinamobile.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1573205741-2094-1-git-send-email-baiyaowei@cmss.chinamobile.com> References: <1573205741-2094-1-git-send-email-baiyaowei@cmss.chinamobile.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 221.176.66.80 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: baiyaowei@cmss.chinamobile.com, yangjun@cmss.chinamobile.com, qemu-devel@nongnu.org, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Some storages(i.e. librbd) already have interfaces to handle some SCSI commands directly. This patch adds COMPARE_AND_WRITE command support through the write path in the block io layer by introducing a new element BDRV_REQ_COMPARE_AND_WRITE into BdrvRequestFlags which indicates a COMPARE_AND_WRITE request. In this way we could easily extend to other SCSI commands support like WRITE_SAME in the future. Signed-off-by: Yaowei Bai --- block/io.c | 20 ++++++++++++++++++++ include/block/block.h | 5 +++-- include/block/block_int.h | 3 +++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/block/io.c b/block/io.c index f75777f..3507d71 100644 --- a/block/io.c +++ b/block/io.c @@ -1186,6 +1186,26 @@ static int coroutine_fn bdrv_driver_pwritev(BlockDri= verState *bs, goto emulate_flags; } =20 + if (drv->bdrv_aio_compare_and_write && + (flags & BDRV_REQ_COMPARE_AND_WRITE)) { + BlockAIOCB *acb; + CoroutineIOCompletion co =3D { + .coroutine =3D qemu_coroutine_self(), + }; + + acb =3D drv->bdrv_aio_compare_and_write(bs, offset, bytes, qiov, + flags & bs->supported_write_flags, + bdrv_co_io_em_complete, &co); + flags &=3D ~bs->supported_write_flags; + if (acb =3D=3D NULL) { + ret =3D -EIO; + } else { + qemu_coroutine_yield(); + ret =3D co.ret; + } + goto emulate_flags; + } + if (drv->bdrv_aio_pwritev) { BlockAIOCB *acb; CoroutineIOCompletion co =3D { diff --git a/include/block/block.h b/include/block/block.h index 1df9848..f71aa4f 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -92,9 +92,10 @@ typedef enum { * on read request and means that caller doesn't really need data to be * written to qiov parameter which may be NULL. */ - BDRV_REQ_PREFETCH =3D 0x200, + BDRV_REQ_PREFETCH =3D 0x200, + BDRV_REQ_COMPARE_AND_WRITE =3D 0x400, /* Mask of valid flags */ - BDRV_REQ_MASK =3D 0x3ff, + BDRV_REQ_MASK =3D 0x7ff, } BdrvRequestFlags; =20 typedef struct BlockSizes { diff --git a/include/block/block_int.h b/include/block/block_int.h index dd033d0..96096e0 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -189,6 +189,9 @@ struct BlockDriver { BlockAIOCB *(*bdrv_aio_pdiscard)(BlockDriverState *bs, int64_t offset, int bytes, BlockCompletionFunc *cb, void *opaque); + BlockAIOCB *(*bdrv_aio_compare_and_write)(BlockDriverState *bs, + uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int flags, + BlockCompletionFunc *cb, void *opaque); =20 int coroutine_fn (*bdrv_co_readv)(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov); --=20 1.8.3.1