From nobody Sun Feb 8 13:38:37 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.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=1592389728; cv=none; d=zohomail.com; s=zohoarc; b=UmcfoT9yMMx7xTDNk2S1sAsqOTHpRLOHhyLajYwA7k35EmrGGef59FmoAAa2u63bMYoOJwVE3c5a/IEoYawETBJdSVQFmrtKFRWaWg+5WJj7Lpzir4Oq4mdEAtmRaD87XaHVCF/1uTyJvdDdekSe9bxxoHt/EQAHKuwUW9gLDYQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592389728; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=LjgdY45G2B/P1e9HyyJEIYGlVAq8rMncFu9MNoqpXrg=; b=gcO23rWAiRLQxjxeid7NHdPpmpTpVoqiQI4TFEXj3uxxfCjIF+trK/0jlZklJ+o9XIsEkbUxz6okybEgCC6TI/NvXtKV1wcCeVlQugN/UoEn9Zm4eoWCSMsBDjDF3Lxqts7YhVSbAxE77p3Rf+nWfvlsZcYJvbQNgOAuAZEpHsU= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.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 1592389728528282.0749163228278; Wed, 17 Jun 2020 03:28:48 -0700 (PDT) Received: from localhost ([::1]:60708 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jlVJH-00079O-Ax for importer@patchew.org; Wed, 17 Jun 2020 06:28:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54406) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jlVGq-0004GS-77; Wed, 17 Jun 2020 06:26:16 -0400 Received: from [114.255.249.163] (port=49827 helo=localhost) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jlVGo-0007Ok-EB; Wed, 17 Jun 2020 06:26:15 -0400 Received: by localhost (Postfix, from userid 0) id 16553140E50; Wed, 17 Jun 2020 18:20:24 +0800 (CST) From: Lin Ma To: qemu-block@nongnu.org Subject: [PATCH v2 1/3] block: Add bdrv_co_get_lba_status Date: Wed, 17 Jun 2020 18:20:17 +0800 Message-Id: <20200617102019.29652-2-lma@suse.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200617102019.29652-1-lma@suse.com> References: <20200617102019.29652-1-lma@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 114.255.249.163 (failed) Received-SPF: pass (zohomail.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; Received-SPF: none client-ip=114.255.249.163; envelope-from=root@localhost; helo=localhost X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/17 06:20:25 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: 68 X-Spam_score: 6.8 X-Spam_bar: ++++++ X-Spam_report: (6.8 / 5.0 requ) BAYES_00=-1.9, FSL_HELO_NON_FQDN_1=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, HELO_LOCALHOST=3.828, RCVD_IN_MSPIKE_BL=0.01, RCVD_IN_MSPIKE_ZBI=2.7, RCVD_IN_XBL=0.375, RDNS_NONE=0.793, SPF_NONE=0.001 autolearn=_AUTOLEARN X-Spam_action: reject 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: fam@euphon.net, kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, Lin Ma , pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The get lba status wrapper based on the bdrv_block_status. The following patches will add GET LBA STATUS 16 support for scsi emulation layer. Signed-off-by: Lin Ma --- block/io.c | 43 +++++++++++++++++++++++++++++++++++++++ include/block/block_int.h | 5 +++++ 2 files changed, 48 insertions(+) diff --git a/block/io.c b/block/io.c index df8f2a98d4..2064016b19 100644 --- a/block/io.c +++ b/block/io.c @@ -2208,6 +2208,49 @@ int coroutine_fn bdrv_co_pwrite_zeroes(BdrvChild *ch= ild, int64_t offset, BDRV_REQ_ZERO_WRITE | flags); } =20 +int coroutine_fn +bdrv_co_get_lba_status(BdrvChild *child, int64_t offset, int64_t bytes, + uint32_t *num_blocks, uint32_t *is_deallocated) +{ + BlockDriverState *bs =3D child->bs; + int ret =3D 0; + int64_t target_size, count =3D 0; + bool first =3D true; + uint8_t wanted_bit1 =3D 0; + + target_size =3D bdrv_getlength(bs); + if (target_size < 0) { + return -EIO; + } + + if (offset < 0 || bytes < 0) { + return -EIO; + } + + for ( ; offset <=3D target_size - bytes; offset +=3D count) { + ret =3D bdrv_block_status(bs, offset, bytes, &count, NULL, NULL); + if (ret < 0) { + goto out; + } + if (first) { + if (ret & BDRV_BLOCK_ZERO) { + wanted_bit1 =3D BDRV_BLOCK_ZERO >> 1; + *is_deallocated =3D 1; + } else { + wanted_bit1 =3D 0; + } + first =3D false; + } + if ((ret & BDRV_BLOCK_ZERO) >> 1 =3D=3D wanted_bit1) { + (*num_blocks)++; + } else { + break; + } + } +out: + return ret; +} + /* * Flush ALL BDSes regardless of if they are reachable via a BlkBackend or= not. */ diff --git a/include/block/block_int.h b/include/block/block_int.h index 791de6a59c..43f90591b9 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -1296,6 +1296,11 @@ int coroutine_fn bdrv_co_block_status_from_backing(B= lockDriverState *bs, int64_t *pnum, int64_t *map, BlockDriverState **file= ); +int coroutine_fn bdrv_co_get_lba_status(BdrvChild *child, + int64_t offset, + int64_t bytes, + uint32_t *num_blocks, + uint32_t *is_deallocated); const char *bdrv_get_parent_name(const BlockDriverState *bs); void blk_dev_change_media_cb(BlockBackend *blk, bool load, Error **errp); bool blk_dev_has_removable_media(BlockBackend *blk); --=20 2.26.0 From nobody Sun Feb 8 13:38:37 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.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=1592389688; cv=none; d=zohomail.com; s=zohoarc; b=R2bBZYDSylOrP0/zY0qss7T/8IXlYVDAafFwOvx9Shjw5Y0dqoyhcDINt6OqAYTaJCb71TMBv3aq5RIYzTqEyOJycULzjSSZx8pBOHL1UlkmQGPJFCO5TNSDQ+5l46zrUC72HHcAR4QUXZdQ+yamUcblf+gkF28Rn8OeFSVRdfY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592389688; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=w7gMfFneSO/Ae8TX5Q3DAdZgAzg15N6pZkYHdPwFk3Y=; b=PflMbJ1rbdpP0d3ERG/AyM+hCNdYIKIjNF6sUNHQoxTyBTyb4VSiiZ+i4EhIkjqSbS6w/aoE61y4WSKJSNWP7APxbiXU6+q1bi3uG78Mv/wjVM1JHmx1qffxK7rrfFPEa3S/3QV0xCUJt19XRAu7WX6cRMySepq4gAcX2Bcg3c0= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.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 1592389688165173.79605101407162; Wed, 17 Jun 2020 03:28:08 -0700 (PDT) Received: from localhost ([::1]:58458 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jlVIc-0006BO-SD for importer@patchew.org; Wed, 17 Jun 2020 06:28:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54434) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jlVGr-0004Hz-Ah; Wed, 17 Jun 2020 06:26:17 -0400 Received: from [114.255.249.163] (port=49820 helo=localhost) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jlVGo-0007Oh-G5; Wed, 17 Jun 2020 06:26:17 -0400 Received: by localhost (Postfix, from userid 0) id 1939F1415E5; Wed, 17 Jun 2020 18:20:24 +0800 (CST) From: Lin Ma To: qemu-block@nongnu.org Subject: [PATCH v2 2/3] block: Add GET LBA STATUS support Date: Wed, 17 Jun 2020 18:20:18 +0800 Message-Id: <20200617102019.29652-3-lma@suse.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200617102019.29652-1-lma@suse.com> References: <20200617102019.29652-1-lma@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 114.255.249.163 (failed) Received-SPF: pass (zohomail.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; Received-SPF: none client-ip=114.255.249.163; envelope-from=root@localhost; helo=localhost X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/17 06:20:25 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: 68 X-Spam_score: 6.8 X-Spam_bar: ++++++ X-Spam_report: (6.8 / 5.0 requ) BAYES_00=-1.9, FSL_HELO_NON_FQDN_1=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, HELO_LOCALHOST=3.828, RCVD_IN_MSPIKE_BL=0.01, RCVD_IN_MSPIKE_ZBI=2.7, RCVD_IN_XBL=0.375, RDNS_NONE=0.793, SPF_NONE=0.001 autolearn=_AUTOLEARN X-Spam_action: reject 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: fam@euphon.net, kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, Lin Ma , pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Lin Ma --- block/block-backend.c | 38 ++++++++++++++++++++++++++++++++++ include/sysemu/block-backend.h | 2 ++ 2 files changed, 40 insertions(+) diff --git a/block/block-backend.c b/block/block-backend.c index 6936b25c83..6d08dd5e0d 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1650,6 +1650,44 @@ int blk_pdiscard(BlockBackend *blk, int64_t offset, = int bytes) return blk_prw(blk, offset, NULL, bytes, blk_pdiscard_entry, 0); } =20 +static int coroutine_fn +blk_do_get_lba_status(BlockBackend *blk, int64_t offset, int bytes, + uint32_t *num_blocks, uint32_t *is_deallocated) +{ + int ret; + + blk_wait_while_drained(blk); + + ret =3D blk_check_byte_request(blk, offset, bytes); + if (ret < 0) { + return ret; + } + + return bdrv_co_get_lba_status(blk->root, offset, bytes, num_blocks, + is_deallocated); +} + +static void blk_aio_get_lba_status_entry(void *opaque) +{ + BlkAioEmAIOCB *acb =3D opaque; + BlkRwCo *rwco =3D &acb->rwco; + + void *data =3D acb->common.opaque; + uint32_t *num_blocks =3D (uint32_t *)data; + uint32_t *is_deallocated =3D (uint32_t *)(data + sizeof(uint32_t)); + + rwco->ret =3D blk_do_get_lba_status(rwco->blk, rwco->offset, acb->byte= s, + num_blocks, is_deallocated); + blk_aio_complete(acb); +} + +BlockAIOCB *blk_aio_get_lba_status(BlockBackend *blk, int64_t offset, int = bytes, + BlockCompletionFunc *cb, void *opaque) +{ + return blk_aio_prwv(blk, offset, bytes, NULL, blk_aio_get_lba_status_e= ntry, + 0, cb, opaque); +} + /* To be called between exactly one pair of blk_inc/dec_in_flight() */ static int coroutine_fn blk_do_flush(BlockBackend *blk) { diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 8203d7f6f9..cd527ec0c9 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -171,6 +171,8 @@ BlockAIOCB *blk_aio_flush(BlockBackend *blk, BlockCompletionFunc *cb, void *opaque); BlockAIOCB *blk_aio_pdiscard(BlockBackend *blk, int64_t offset, int bytes, BlockCompletionFunc *cb, void *opaque); +BlockAIOCB *blk_aio_get_lba_status(BlockBackend *blk, int64_t offset, int = bytes, + BlockCompletionFunc *cb, void *opaque); void blk_aio_cancel(BlockAIOCB *acb); void blk_aio_cancel_async(BlockAIOCB *acb); int blk_ioctl(BlockBackend *blk, unsigned long int req, void *buf); --=20 2.26.0 From nobody Sun Feb 8 13:38:37 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.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=1592389801; cv=none; d=zohomail.com; s=zohoarc; b=RmrQtUpedTLpXrUx7IzheKjJzsuJtmHyYW+JPduyo70LqCag4O6DbNPuv9LJSkjAPk2Nojp+6Aotfi1zVai6z9rfOyet6j5WALzkQmAVrigk8TIxbBDb6ku8oykCPkfU+qiHxqkLvK7wFE/VDYX+fp5zp1ogvHOamQt0tmWvRzE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592389801; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=nUKfX9FVfthy2w7tRAPEyZ1a9rIxVPHgzXPclsOOFbo=; b=Wz9jaFF/d+j/OG0ldL3wFZnkntHXE6dvTgSARL2LWAdTKzr20ZJnYqi4RCSu9D2wCOY7kaOjc5kxqbLTayP8xoFhxNadWFvYQvwmtOfOYC9aevseMFrU2lQnvWLKizhP5gfEhrVX+wojcfMu1gtUqVA/e5/9g2vcDUDwsk/lyX0= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.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 1592389801802429.1170991312001; Wed, 17 Jun 2020 03:30:01 -0700 (PDT) Received: from localhost ([::1]:37080 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jlVKS-0000bG-Ac for importer@patchew.org; Wed, 17 Jun 2020 06:30:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54412) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jlVGq-0004Ge-D8; Wed, 17 Jun 2020 06:26:16 -0400 Received: from [114.255.249.163] (port=23486 helo=localhost) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jlVGo-0007Og-Fm; Wed, 17 Jun 2020 06:26:16 -0400 Received: by localhost (Postfix, from userid 0) id 1F7BA1415FB; Wed, 17 Jun 2020 18:20:24 +0800 (CST) From: Lin Ma To: qemu-block@nongnu.org Subject: [PATCH v2 3/3] scsi-disk: Add support for the GET LBA STATUS 16 command Date: Wed, 17 Jun 2020 18:20:19 +0800 Message-Id: <20200617102019.29652-4-lma@suse.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200617102019.29652-1-lma@suse.com> References: <20200617102019.29652-1-lma@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 114.255.249.163 (failed) Received-SPF: pass (zohomail.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; Received-SPF: none client-ip=114.255.249.163; envelope-from=root@localhost; helo=localhost X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/17 06:20:25 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: 68 X-Spam_score: 6.8 X-Spam_bar: ++++++ X-Spam_report: (6.8 / 5.0 requ) BAYES_00=-1.9, FSL_HELO_NON_FQDN_1=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, HELO_LOCALHOST=3.828, RCVD_IN_MSPIKE_BL=0.01, RCVD_IN_MSPIKE_ZBI=2.7, RCVD_IN_XBL=0.375, RDNS_NONE=0.793, SPF_NONE=0.001 autolearn=_AUTOLEARN X-Spam_action: reject 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: fam@euphon.net, kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, Lin Ma , pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Lin Ma --- hw/scsi/scsi-disk.c | 90 ++++++++++++++++++++++++++++++++++++++ include/block/accounting.h | 1 + include/scsi/constants.h | 1 + 3 files changed, 92 insertions(+) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index 387503e11b..9e3002ddaf 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -1866,6 +1866,89 @@ static void scsi_disk_emulate_write_data(SCSIRequest= *req) } } =20 +typedef struct GetLbaStatusCBData { + uint32_t num_blocks; + uint32_t is_deallocated; + SCSIDiskReq *r; +} GetLbaStatusCBData; + +static void scsi_get_lba_status_complete(void *opaque, int ret); + +static void scsi_get_lba_status_complete_noio(GetLbaStatusCBData *data, in= t ret) +{ + SCSIDiskReq *r =3D data->r; + SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, r->req.dev); + + assert(r->req.aiocb =3D=3D NULL); + + block_acct_start(blk_get_stats(s->qdev.conf.blk), &r->acct, + s->qdev.blocksize, BLOCK_ACCT_GET_LBA_STATUS); + + r->req.aiocb =3D blk_aio_get_lba_status(s->qdev.conf.blk, + r->req.cmd.lba * s->qdev.blocksi= ze, + s->qdev.blocksize, + scsi_get_lba_status_complete, da= ta); +} + +static void scsi_get_lba_status_complete(void *opaque, int ret) +{ + GetLbaStatusCBData *data =3D opaque; + SCSIDiskReq *r =3D data->r; + SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, r->req.dev); + + assert(r->req.aiocb !=3D NULL); + r->req.aiocb =3D NULL; + + aio_context_acquire(blk_get_aio_context(s->qdev.conf.blk)); + if (scsi_disk_req_check_error(r, ret, true)) { + g_free(data); + goto done; + } + + block_acct_done(blk_get_stats(s->qdev.conf.blk), &r->acct); + scsi_req_unref(&r->req); + g_free(data); + +done: + aio_context_release(blk_get_aio_context(s->qdev.conf.blk)); +} + +static void scsi_disk_emulate_get_lba_status(SCSIRequest *req, uint8_t *ou= tbuf) +{ + SCSIDiskReq *r =3D DO_UPCAST(SCSIDiskReq, req, req); + GetLbaStatusCBData *data; + uint32_t *num_blocks; + uint32_t *is_deallocated; + + data =3D g_new0(GetLbaStatusCBData, 1); + data->r =3D r; + num_blocks =3D &(data->num_blocks); + is_deallocated =3D &(data->is_deallocated); + + scsi_req_ref(&r->req); + scsi_get_lba_status_complete_noio(data, 0); + + /* + * 8 + 16 is the length in bytes of response header and + * one LBA status descriptor + */ + memset(outbuf, 0, 8 + 16); + outbuf[3] =3D 20; + outbuf[8] =3D (req->cmd.lba >> 56) & 0xff; + outbuf[9] =3D (req->cmd.lba >> 48) & 0xff; + outbuf[10] =3D (req->cmd.lba >> 40) & 0xff; + outbuf[11] =3D (req->cmd.lba >> 32) & 0xff; + outbuf[12] =3D (req->cmd.lba >> 24) & 0xff; + outbuf[13] =3D (req->cmd.lba >> 16) & 0xff; + outbuf[14] =3D (req->cmd.lba >> 8) & 0xff; + outbuf[15] =3D req->cmd.lba & 0xff; + outbuf[16] =3D (*num_blocks >> 24) & 0xff; + outbuf[17] =3D (*num_blocks >> 16) & 0xff; + outbuf[18] =3D (*num_blocks >> 8) & 0xff; + outbuf[19] =3D *num_blocks & 0xff; + outbuf[20] =3D *is_deallocated ? 1 : 0; +} + static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf) { SCSIDiskReq *r =3D DO_UPCAST(SCSIDiskReq, req, req); @@ -2076,6 +2159,13 @@ static int32_t scsi_disk_emulate_command(SCSIRequest= *req, uint8_t *buf) =20 /* Protection, exponent and lowest lba field left blank. */ break; + } else if ((req->cmd.buf[1] & 31) =3D=3D SAI_GET_LBA_STATUS) { + if (req->cmd.lba > s->qdev.max_lba) { + goto illegal_lba; + } + scsi_disk_emulate_get_lba_status(req, outbuf); + r->iov.iov_len =3D req->cmd.xfer; + return r->iov.iov_len; } trace_scsi_disk_emulate_command_SAI_unsupported(); goto illegal_request; diff --git a/include/block/accounting.h b/include/block/accounting.h index 878b4c3581..645014fb0b 100644 --- a/include/block/accounting.h +++ b/include/block/accounting.h @@ -38,6 +38,7 @@ enum BlockAcctType { BLOCK_ACCT_WRITE, BLOCK_ACCT_FLUSH, BLOCK_ACCT_UNMAP, + BLOCK_ACCT_GET_LBA_STATUS, BLOCK_MAX_IOTYPE, }; =20 diff --git a/include/scsi/constants.h b/include/scsi/constants.h index 874176019e..b18377b214 100644 --- a/include/scsi/constants.h +++ b/include/scsi/constants.h @@ -154,6 +154,7 @@ * SERVICE ACTION IN subcodes */ #define SAI_READ_CAPACITY_16 0x10 +#define SAI_GET_LBA_STATUS 0x12 =20 /* * READ POSITION service action codes --=20 2.26.0