From nobody Mon Feb 9 05:40:39 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