From patchwork Mon Aug 1 01:31:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Li X-Patchwork-Id: 12933302 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EA2C1C00140 for ; Mon, 1 Aug 2022 01:36:04 +0000 (UTC) Received: from localhost ([::1]:47446 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIKLj-0004sn-Ea for qemu-devel@archiver.kernel.org; Sun, 31 Jul 2022 21:36:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56042) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIKHs-0002ei-CG; Sun, 31 Jul 2022 21:32:04 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]:34768) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oIKHn-0000Tb-OD; Sun, 31 Jul 2022 21:32:04 -0400 Received: by mail-pl1-x631.google.com with SMTP id z19so9165257plb.1; Sun, 31 Jul 2022 18:31:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc; bh=ml9KuDp/EbRk0534Hyeav3hLJwJ/69H1x0qXo/Nx1gc=; b=HwebBxuJCurzOF7+HpUXIvaz3W3by0luKJZM84+r9tvkEr2H3g2oAXh8ZojE9NnJE8 /DShHf6pZE6+MEsEcQcEAp2cFXurXgjIy9QgkZQpaxObH3QhvyPS0+dgz0Az0F0VplbL 6yhjb3bOw1FCVGm9oBkVpL8/RYMUVdxO/Rt6ICCO6P57PofTDwsz5c7thIa1aBi6ricG ExX/WWA/jO9dCmt2ATRWTrWW++1z0ZbCMdw402ltSX4388RBhKqsRAwJnTsILtCGxvHy FSm7BaRp1jIhYxYiRj0Z98xmWEF1/fBL4UaZKs+UrpzOMrTEJQ0tKX46p6DdpCL9GWs6 NI8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=ml9KuDp/EbRk0534Hyeav3hLJwJ/69H1x0qXo/Nx1gc=; b=hivdTk3Wxq6ks9k4ZRcHuwSOOEZopd8+2D8RF9rooJEZ+M9dib0chzHuPJxmwKmlkY kwx3zRGVGnCUMPntidu303JhNCXUU0ogRDR8z6uwPEC+UOCctFuBb2XDsmn6p5bOUPVF CItZeWxmS3Qa1i7DWTleEi+BqaaCUFUE0MrkPragHV6LDmPv90PtHoF+oYyBbjaMImOz 1zAZZwD+NuT2zVqMaJSnjgwa1MRHxNpUgspHIhHKFkJ3vAbbLncRDv3cyYNPA/VjgtUt hZewU889YNSKn8tZZaWhUyLlyNOt/SyVXcDWnPKz5BsEBmFsRqCCBQXOdwVc9L7Vbors XtwQ== X-Gm-Message-State: ACgBeo1iGqio/DvJJt1g7/yxmaM0LEU2oMaynSZ+JV5ZMPD6a61fP+1C HYo4kPWcQ3+A2oxLB+ovwACdrIi7QO613VJV X-Google-Smtp-Source: AA6agR4nEjNOXW7VfKEJPguagTjIyzhNmDRL0eY3jWYwYLXniEVNlHfgE5E2jVUhyE3jRG1rvp88UQ== X-Received: by 2002:a17:902:da92:b0:16e:f2ee:b98a with SMTP id j18-20020a170902da9200b0016ef2eeb98amr1247390plx.154.1659317517709; Sun, 31 Jul 2022 18:31:57 -0700 (PDT) Received: from roots.. ([106.84.131.7]) by smtp.gmail.com with ESMTPSA id z14-20020a170902d54e00b0016edff78844sm2106716plf.277.2022.07.31.18.31.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Jul 2022 18:31:57 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: damien.lemoal@opensource.wdc.com, dmitry.fomichev@wdc.com, hare@suse.de, stefanha@redhat.com, mst@redhat.com, armbru@redhat.com, qemu-block@nongnu.org, fam@euphon.net, kwolf@redhat.com, hreitz@redhat.com, eblake@redhat.com, Sam Li Subject: [RFC v5 01/11] include: add zoned device structs Date: Mon, 1 Aug 2022 09:31:48 +0800 Message-Id: <20220801013148.10334-1-faithilikerun@gmail.com> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=faithilikerun@gmail.com; helo=mail-pl1-x631.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Sam Li Reviewed-by: Stefan Hajnoczi --- include/block/block-common.h | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/include/block/block-common.h b/include/block/block-common.h index fdb7306e78..c9d28b1c51 100644 --- a/include/block/block-common.h +++ b/include/block/block-common.h @@ -49,6 +49,49 @@ typedef struct BlockDriver BlockDriver; typedef struct BdrvChild BdrvChild; typedef struct BdrvChildClass BdrvChildClass; +typedef enum BlockZoneOp { + BLK_ZO_OPEN, + BLK_ZO_CLOSE, + BLK_ZO_FINISH, + BLK_ZO_RESET, +} BlockZoneOp; + +typedef enum BlockZoneModel { + BLK_Z_NONE = 0x0, /* Regular block device */ + BLK_Z_HM = 0x1, /* Host-aware zoned block device */ + BLK_Z_HA = 0x2, /* Host-managed zoned block device */ +} BlockZoneModel; + +typedef enum BlockZoneCondition { + BLK_ZS_NOT_WP = 0x0, + BLK_ZS_EMPTY = 0x1, + BLK_ZS_IOPEN = 0x2, + BLK_ZS_EOPEN = 0x3, + BLK_ZS_CLOSED = 0x4, + BLK_ZS_RDONLY = 0xD, + BLK_ZS_FULL = 0xE, + BLK_ZS_OFFLINE = 0xF, +} BlockZoneCondition; + +typedef enum BlockZoneType { + BLK_ZT_CONV = 0x1, + BLK_ZT_SWR = 0x2, + BLK_ZT_SWP = 0x3, +} BlockZoneType; + +/* + * Zone descriptor data structure. + * Provide information on a zone with all position and size values in bytes. + */ +typedef struct BlockZoneDescriptor { + uint64_t start; + uint64_t length; + uint64_t cap; + uint64_t wp; + BlockZoneType type; + BlockZoneCondition cond; +} BlockZoneDescriptor; + typedef struct BlockDriverInfo { /* in bytes, 0 if irrelevant */ int cluster_size; From patchwork Mon Aug 1 01:32:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Li X-Patchwork-Id: 12933303 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3048CC00140 for ; Mon, 1 Aug 2022 01:36:27 +0000 (UTC) Received: from localhost ([::1]:48302 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIKM6-0005SS-5f for qemu-devel@archiver.kernel.org; Sun, 31 Jul 2022 21:36:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56070) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIKI6-0002mT-1a; Sun, 31 Jul 2022 21:32:18 -0400 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]:33767) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oIKI4-0000U9-7l; Sun, 31 Jul 2022 21:32:17 -0400 Received: by mail-pg1-x536.google.com with SMTP id 206so4940437pgb.0; Sun, 31 Jul 2022 18:32:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc; bh=7r9o2/Lajx4dUVD8qjBdmsKEFctZywj1Bn7/2TsaI8A=; b=l2eYnqtHy5Da7EV8ndjULRoQoWSBUyBm1zqOmyPOw9MZdrXVnVjuPaMmurlZsTQIK2 sVdP2HGrV5agvaRmvIoAz28T2pd8+9pDQeCFPiOU5jII84zqt5Ua8QAZ5iMsJKDBns7p tsF2OSFFoXi5LRtxyPSAiiTMPqjGcX+V1NL1MGVlwBxrto5hN8GgrjFc791kLKfF6Mhg 9YF4U/RJAGh1/70YLg9xXkpiHx0cUvX/Y/BY8uQm+2+s80Mcb3cyqDhrK/jhTFAiKDbk ZMhnge3rm4C8Qw6cf5wiychHwYbYH35NRnO2+Ll0Qii0HAhLrYY4swG1YzYWWjYNseuN IL3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=7r9o2/Lajx4dUVD8qjBdmsKEFctZywj1Bn7/2TsaI8A=; b=Xm2qjvrnWVo+ogHRXeqIxzSZ9+qxxJ4uWbiN2mTeq9lbXB9PVGYv5rAhcPBUnIAvZH uyx/tfgC9oQBicWiUVysG9kjYHfcNuwoYI0GjUERD6jCh7e+fKnSSELtfIX/YqJUtvZ4 131QhEwcoqfaalePeDIiEML3utdHARht5LvzB6k34qkt950MyR8+i8hLTfytEYL3tIUP R/QTcAZvxjUMDBOHg48neriwkf/ZqIm3j+DD5z3245gj4tDwQW64CKd5zjcDw3TjFBOr sbfvzXT5NifTkYqPZROsMRHL1aITRmp3lmVkoB9WpcqNjkyAG8z728DNAA5EcnbRMH6U P+HA== X-Gm-Message-State: AJIora8+6VAdNE9e6kfJaT7FRfoCaEkwAX8noHZchz4Psv7SknTkokq4 5WX/81Ri5e9DK3jbw271/IL2fvwTbA61G1v2 X-Google-Smtp-Source: AGRyM1sz+IwJEqBMFRhvGsUUr7TVVbP6TRolcYcX71ld7g6lNM6NXTYNHosOPfpN3U8pWicejhR/jg== X-Received: by 2002:a63:5325:0:b0:41b:59f1:79d2 with SMTP id h37-20020a635325000000b0041b59f179d2mr11933827pgb.52.1659317534372; Sun, 31 Jul 2022 18:32:14 -0700 (PDT) Received: from roots.. ([106.84.131.7]) by smtp.gmail.com with ESMTPSA id v10-20020a1709028d8a00b0016bfbd99f64sm8069813plo.118.2022.07.31.18.32.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Jul 2022 18:32:14 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: damien.lemoal@opensource.wdc.com, dmitry.fomichev@wdc.com, hare@suse.de, stefanha@redhat.com, mst@redhat.com, armbru@redhat.com, qemu-block@nongnu.org, fam@euphon.net, kwolf@redhat.com, hreitz@redhat.com, eblake@redhat.com, Sam Li Subject: [RFC v5 02/11] include: import virtio_blk headers from linux with zoned storage support Date: Mon, 1 Aug 2022 09:32:05 +0800 Message-Id: <20220801013205.10371-1-faithilikerun@gmail.com> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::536; envelope-from=faithilikerun@gmail.com; helo=mail-pg1-x536.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Add file from Dmitry's "virtio-blk:add support for zoned block devices" linux patch using scripts/update-linux-headers.sh. There is a link for more information: https://github.com/dmitry-fomichev/virtblk-zbd Signed-off-by: Sam Li --- include/standard-headers/linux/virtio_blk.h | 118 ++++++++++++++++++++ 1 file changed, 118 insertions(+) diff --git a/include/standard-headers/linux/virtio_blk.h b/include/standard-headers/linux/virtio_blk.h index 2dcc90826a..5c6856aec3 100644 --- a/include/standard-headers/linux/virtio_blk.h +++ b/include/standard-headers/linux/virtio_blk.h @@ -40,6 +40,7 @@ #define VIRTIO_BLK_F_MQ 12 /* support more than one vq */ #define VIRTIO_BLK_F_DISCARD 13 /* DISCARD is supported */ #define VIRTIO_BLK_F_WRITE_ZEROES 14 /* WRITE ZEROES is supported */ +#define VIRTIO_BLK_F_ZONED 17 /* Zoned block device */ /* Legacy feature bits */ #ifndef VIRTIO_BLK_NO_LEGACY @@ -119,6 +120,20 @@ struct virtio_blk_config { uint8_t write_zeroes_may_unmap; uint8_t unused1[3]; + + /* Secure erase fields that are defined in the virtio spec */ + uint8_t sec_erase[12]; + + /* Zoned block device characteristics (if VIRTIO_BLK_F_ZONED) */ + struct virtio_blk_zoned_characteristics { + __virtio32 zone_sectors; + __virtio32 max_open_zones; + __virtio32 max_active_zones; + __virtio32 max_append_sectors; + __virtio32 write_granularity; + uint8_t model; + uint8_t unused2[3]; + } zoned; } QEMU_PACKED; /* @@ -153,6 +168,24 @@ struct virtio_blk_config { /* Write zeroes command */ #define VIRTIO_BLK_T_WRITE_ZEROES 13 +/* Zone append command */ +#define VIRTIO_BLK_T_ZONE_APPEND 15 + +/* Report zones command */ +#define VIRTIO_BLK_T_ZONE_REPORT 16 + +/* Open zone command */ +#define VIRTIO_BLK_T_ZONE_OPEN 18 + +/* Close zone command */ +#define VIRTIO_BLK_T_ZONE_CLOSE 20 + +/* Finish zone command */ +#define VIRTIO_BLK_T_ZONE_FINISH 22 + +/* Reset zone command */ +#define VIRTIO_BLK_T_ZONE_RESET 24 + #ifndef VIRTIO_BLK_NO_LEGACY /* Barrier before this op. */ #define VIRTIO_BLK_T_BARRIER 0x80000000 @@ -172,6 +205,84 @@ struct virtio_blk_outhdr { __virtio64 sector; }; +/* + * Supported zoned device models. + */ + +/* Regular block device */ +#define VIRTIO_BLK_Z_NONE 0 +/* Host-managed zoned device */ +#define VIRTIO_BLK_Z_HM 1 +/* Host-aware zoned device */ +#define VIRTIO_BLK_Z_HA 2 + +/* ZBD Management Out ALL flag */ +#define VIRTIO_BLK_ZONED_FLAG_ALL (1 << 0) + +/* + * Header for VIRTIO_BLK_T_ZONE_OPEN, VIRTIO_BLK_T_ZONE_CLOSE, + * VIRTIO_BLK_T_ZONE_RESET, VIRTIO_BLK_T_ZONE_FINISH requests. + */ +struct virtio_blk_zone_mgmt_outhdr { + /* Zoned request flags */ + __virtio32 flags; +}; + +/* + * Zone descriptor. A part of VIRTIO_BLK_T_ZONE_REPORT command reply. + */ +struct virtio_blk_zone_descriptor { + /* Zone capacity */ + __virtio64 z_cap; + /* The starting sector of the zone */ + __virtio64 z_start; + /* Zone write pointer position in sectors */ + __virtio64 z_wp; + /* Zone type */ + uint8_t z_type; + /* Zone state */ + uint8_t z_state; + uint8_t reserved[38]; +}; + +struct virtio_blk_zone_report { + __virtio64 nr_zones; + uint8_t reserved[56]; + struct virtio_blk_zone_descriptor zones[]; +}; + +/* + * Supported zone types. + */ + +/* Conventional zone */ +#define VIRTIO_BLK_ZT_CONV 1 +/* Sequential Write Required zone */ +#define VIRTIO_BLK_ZT_SWR 2 +/* Sequential Write Preferred zone */ +#define VIRTIO_BLK_ZT_SWP 3 + +/* + * Zone states that are available for zones of all types. + */ + +/* Not a write pointer (conventional zones only) */ +#define VIRTIO_BLK_ZS_NOT_WP 0 +/* Empty */ +#define VIRTIO_BLK_ZS_EMPTY 1 +/* Implicitly Open */ +#define VIRTIO_BLK_ZS_IOPEN 2 +/* Explicitly Open */ +#define VIRTIO_BLK_ZS_EOPEN 3 +/* Closed */ +#define VIRTIO_BLK_ZS_CLOSED 4 +/* Read-Only */ +#define VIRTIO_BLK_ZS_RDONLY 13 +/* Full */ +#define VIRTIO_BLK_ZS_FULL 14 +/* Offline */ +#define VIRTIO_BLK_ZS_OFFLINE 15 + /* Unmap this range (only valid for write zeroes command) */ #define VIRTIO_BLK_WRITE_ZEROES_FLAG_UNMAP 0x00000001 @@ -198,4 +309,11 @@ struct virtio_scsi_inhdr { #define VIRTIO_BLK_S_OK 0 #define VIRTIO_BLK_S_IOERR 1 #define VIRTIO_BLK_S_UNSUPP 2 + +/* Error codes that are specific to zoned block devices */ +#define VIRTIO_BLK_S_ZONE_INVALID_CMD 3 +#define VIRTIO_BLK_S_ZONE_UNALIGNED_WP 4 +#define VIRTIO_BLK_S_ZONE_OPEN_RESOURCE 5 +#define VIRTIO_BLK_S_ZONE_ACTIVE_RESOURCE 6 + #endif /* _LINUX_VIRTIO_BLK_H */ From patchwork Mon Aug 1 01:32:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Li X-Patchwork-Id: 12933307 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C26F9C00140 for ; Mon, 1 Aug 2022 01:40:24 +0000 (UTC) Received: from localhost ([::1]:57480 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIKPv-0003GX-Ry for qemu-devel@archiver.kernel.org; Sun, 31 Jul 2022 21:40:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56100) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIKIJ-0002qD-F7; Sun, 31 Jul 2022 21:32:31 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]:41912) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oIKIH-0000Uk-KF; Sun, 31 Jul 2022 21:32:31 -0400 Received: by mail-pl1-x630.google.com with SMTP id v18so9128116plo.8; Sun, 31 Jul 2022 18:32:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc; bh=H+3MOlJ49zk3LYKUyWss63wjcn3CnNQ+m/3YAsYv/dY=; b=IVpjQ3UO+b52dGP3F3pSzLMl2cTb0MAWaOhnpeJcGrZbG5Ulo7UFL4kJZEc/gUNxzB N27fEg+K5EubwZB9VKuKvGRfBbJA2tOtGzkHQ/HvJiV1JgMq6/tP+INlD3v3AmMvqzfj 5MBZfeuBKO/ksQBbweRap89qA5zRH/d+htCG4UbZHgiPBe5k+xziGCqt7wZ3uvaruB5G THrSJpZcxUTFHNwr1yL3bXZFxiURSaPTiqrcfYcdQoct8I4R/bS7+Ppcs5c/FC9MAL/c HCBlF6Xfj2V8IzzjZW7gzmY+OoIUSodEC0mRmf//4OfUqz2HfX3JYIdDdd57lWmPMyma xbJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=H+3MOlJ49zk3LYKUyWss63wjcn3CnNQ+m/3YAsYv/dY=; b=qrFvwxiOUtUg6nWrOudAO+gEHSdifBYftFbkaFbtOgzPUYist9iNCc+o+DI/qKgJm2 QNiLtSfqgndo9KvB/M7GqVeO5j/XGK2V25hNvODSt9A8IyoD5ybqA+iIRMrShIzPHKJl GCwSPhOURXqWIyWwgWVZa9dCDr1J95y1OBPsiNH2gW0AGfSJDR3EhApKopSjISC7SieD OcyA1PRs52ZDHBCtK9DuQ5SdnsWbIQpR5+Sy7WfEHg4Q3rwVDqpoWJiyvt+UJzpCBz+7 mz0fFZes5UoLC84AJe5Vgaypw0xIr4/4T9xqjQ6e3luql2E6gVlN0gjOXWAaL+PoVRcW TrwA== X-Gm-Message-State: ACgBeo1gcPYfaJqFXE7GrUeicSavn5Q70WV9w05xkeg5wC/4059jQAsz dMLhXORfnv13iDz9k0y/A4u9XXQAhizGkcPA X-Google-Smtp-Source: AA6agR79sCz+mzJZY3HKIWQL65VvvoPvpe7OoVHDUAJfNRgcbuTAo/OcQTOpoo11exsLMnbzoBWKgA== X-Received: by 2002:a17:902:f792:b0:168:e97b:3c05 with SMTP id q18-20020a170902f79200b00168e97b3c05mr14166857pln.94.1659317547570; Sun, 31 Jul 2022 18:32:27 -0700 (PDT) Received: from roots.. ([106.84.131.7]) by smtp.gmail.com with ESMTPSA id hi7-20020a17090b30c700b001f2fa09786asm7482755pjb.19.2022.07.31.18.32.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Jul 2022 18:32:27 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: damien.lemoal@opensource.wdc.com, dmitry.fomichev@wdc.com, hare@suse.de, stefanha@redhat.com, mst@redhat.com, armbru@redhat.com, qemu-block@nongnu.org, fam@euphon.net, kwolf@redhat.com, hreitz@redhat.com, eblake@redhat.com, Sam Li Subject: [RFC v5 03/11] file-posix: introduce get_sysfs_long_val for the long sysfs attribute Date: Mon, 1 Aug 2022 09:32:21 +0800 Message-Id: <20220801013221.10427-1-faithilikerun@gmail.com> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=faithilikerun@gmail.com; helo=mail-pl1-x630.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Use sysfs attribute files to get the long value of zoned device information. Signed-off-by: Sam Li --- block/file-posix.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 48cd096624..bcf898f0cb 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1210,15 +1210,19 @@ static int hdev_get_max_hw_transfer(int fd, struct stat *st) #endif } -static int hdev_get_max_segments(int fd, struct stat *st) -{ +/* + * Get zoned device information (chunk_sectors, zoned_append_max_bytes, + * max_open_zones, max_active_zones) through sysfs attribute files. + */ +static long get_sysfs_long_val(int fd, struct stat *st, + const char *attribute) { #ifdef CONFIG_LINUX char buf[32]; const char *end; char *sysfspath = NULL; int ret; int sysfd = -1; - long max_segments; + long val; if (S_ISCHR(st->st_mode)) { if (ioctl(fd, SG_GET_SG_TABLESIZE, &ret) == 0) { @@ -1231,8 +1235,9 @@ static int hdev_get_max_segments(int fd, struct stat *st) return -ENOTSUP; } - sysfspath = g_strdup_printf("/sys/dev/block/%u:%u/queue/max_segments", - major(st->st_rdev), minor(st->st_rdev)); + sysfspath = g_strdup_printf("/sys/dev/block/%u:%u/queue/%s", + major(st->st_rdev), minor(st->st_rdev), + attribute); sysfd = open(sysfspath, O_RDONLY); if (sysfd == -1) { ret = -errno; @@ -1250,9 +1255,9 @@ static int hdev_get_max_segments(int fd, struct stat *st) } buf[ret] = 0; /* The file is ended with '\n', pass 'end' to accept that. */ - ret = qemu_strtol(buf, &end, 10, &max_segments); + ret = qemu_strtol(buf, &end, 10, &val); if (ret == 0 && end && *end == '\n') { - ret = max_segments; + ret = val; } out: @@ -1266,6 +1271,10 @@ out: #endif } +static int hdev_get_max_segments(int fd, struct stat *st) { + return get_sysfs_long_val(fd, st, "max_segments"); +} + static void raw_refresh_limits(BlockDriverState *bs, Error **errp) { BDRVRawState *s = bs->opaque; From patchwork Mon Aug 1 01:32:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Li X-Patchwork-Id: 12933305 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6DD08C00140 for ; Mon, 1 Aug 2022 01:37:21 +0000 (UTC) Received: from localhost ([::1]:49294 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIKMy-0006CE-Gm for qemu-devel@archiver.kernel.org; Sun, 31 Jul 2022 21:37:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56166) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIKIq-0003Dm-OA; Sun, 31 Jul 2022 21:33:17 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]:36755) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oIKIn-0000c0-KP; Sun, 31 Jul 2022 21:33:03 -0400 Received: by mail-pl1-x635.google.com with SMTP id x10so8449556plb.3; Sun, 31 Jul 2022 18:32:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc; bh=i/cL+iZ/k30GZKkjoXM9xlnXK50965f4sgRoxMSddsU=; b=MKopE3Yap3lf88bmdU5peqyQ6GtxVI7tFEbBRE2m083idm4xzXms61l+B7XyxjiXhe MR3NAUEt5/jqI8CX0RKxr4K+PODLZ7Dn5/RrJoB5ZJgB1QdyboI0h/sa91D9v5lC24HE PFFnUBhwWS53foP8EZ2mk3KJEguO9qP8XonbrAtAAB9CmYqKDGGKaUtZO2IMfSQwKCY/ HkS3akGQzTvJAlCpr1mnZXMX528/3RdcL6UHEg1LfHsT5/CV70f1Vcu2USVIFBkTzrka kqZLCE7v0aQsjt5K1hYOATrENGDflg4IsK/speaA7JBElornhxaSWrbfK+g5q8QJGBQM 0GMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=i/cL+iZ/k30GZKkjoXM9xlnXK50965f4sgRoxMSddsU=; b=X6q01ud/v7KnHCP0sO+B+RjjAi+Ls0rvXayF7pmFE8F3sWloaGVsJM52LR7QtQuvcC UMBSHUuMKhyISHQfNOI3k+6Sak3dS9YgJy1P8WS/EQSqfEMuZIMRqwfz+x8VALZ0803i dx+8zMUyWotSdxFN2yojPuhueqUxD3gPRSHEW5tcCP/Zd5rjMFMfk4MREwnXqzj2RPuG maFKia76MG0SbisL6v6flSiZ+qbVEzbaJmLXybjKwJJtW7xntwg+DHgRqGbs/QcBh1KM xiR+qqeBSB7spQkQaSA0ZYFu71uX8reiC/CE8lrYsXJwzl+LfuxpCoLW6wA3NHGA4D3T NnTg== X-Gm-Message-State: ACgBeo2iYaNWo5hGfBflvVNsTrH4JlEQ3lUXOfPigTT+EdNJnmM/KiJb zcKTc5delCpj62bEpgR6S4i9EZrbd7O83tcT X-Google-Smtp-Source: AA6agR6vPYi6JwRQ17wQw2FgOLf4OaAvuWWUA/0M+vJ2zmjfbv7bYFOn9rFWWd19DAildGTQTYnTBQ== X-Received: by 2002:a17:902:d50e:b0:16d:6113:7666 with SMTP id b14-20020a170902d50e00b0016d61137666mr14373943plg.17.1659317578802; Sun, 31 Jul 2022 18:32:58 -0700 (PDT) Received: from roots.. ([106.84.131.7]) by smtp.gmail.com with ESMTPSA id e14-20020a17090301ce00b0016ef05d4110sm636470plh.108.2022.07.31.18.32.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Jul 2022 18:32:58 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: damien.lemoal@opensource.wdc.com, dmitry.fomichev@wdc.com, hare@suse.de, stefanha@redhat.com, mst@redhat.com, armbru@redhat.com, qemu-block@nongnu.org, fam@euphon.net, kwolf@redhat.com, hreitz@redhat.com, eblake@redhat.com, Sam Li Subject: [RFC v5 04/11] file-posix: introduce get_sysfs_str_val for device zoned model Date: Mon, 1 Aug 2022 09:32:48 +0800 Message-Id: <20220801013248.10468-1-faithilikerun@gmail.com> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=faithilikerun@gmail.com; helo=mail-pl1-x635.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Use sysfs attribute files to get the string value of device zoned model. Then get_sysfs_zoned_model can convert it to BlockZoneModel type in QEMU. Signed-off-by: Sam Li --- block/file-posix.c | 86 ++++++++++++++++++++++++++++++++ include/block/block_int-common.h | 3 ++ 2 files changed, 89 insertions(+) diff --git a/block/file-posix.c b/block/file-posix.c index bcf898f0cb..0d8b4acdc7 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1271,6 +1271,85 @@ out: #endif } +/* + * Convert the zoned attribute file in sysfs to internal value. + */ +static int get_sysfs_str_val(int fd, struct stat *st, + const char *attribute, + char **val) { +#ifdef CONFIG_LINUX + char buf[32]; + char *sysfspath = NULL; + int ret, offset; + int sysfd = -1; + + if (S_ISCHR(st->st_mode)) { + if (ioctl(fd, SG_GET_SG_TABLESIZE, &ret) == 0) { + return ret; + } + return -ENOTSUP; + } + + if (!S_ISBLK(st->st_mode)) { + return -ENOTSUP; + } + + sysfspath = g_strdup_printf("/sys/dev/block/%u:%u/queue/%s", + major(st->st_rdev), minor(st->st_rdev), + attribute); + sysfd = open(sysfspath, O_RDONLY); + if (sysfd == -1) { + ret = -errno; + goto out; + } + offset = 0; + do { + ret = read(sysfd, buf + offset, sizeof(buf) - 1 + offset); + if (ret > 0) { + offset += ret; + } + } while (ret == -1); + /* The file is ended with '\n' */ + if (buf[ret - 1] == '\n') { + buf[ret - 1] = '\0'; + } + + if (!strncpy(*val, buf, ret)) { + goto out; + } + +out: + if (sysfd != -1) { + close(sysfd); + } + g_free(sysfspath); + return ret; +#else + return -ENOTSUP; +#endif +} + +static int get_sysfs_zoned_model(int fd, struct stat *st, + BlockZoneModel *zoned) { + g_autofree char *val = NULL; + val = g_malloc(32); + get_sysfs_str_val(fd, st, "zoned", &val); + if (!val) { + return -ENOTSUP; + } + + if (strcmp(val, "host-managed") == 0) { + *zoned = BLK_Z_HM; + } else if (strcmp(val, "host-aware") == 0) { + *zoned = BLK_Z_HA; + } else if (strcmp(val, "none") == 0) { + *zoned = BLK_Z_NONE; + } else { + return -ENOTSUP; + } + return 0; +} + static int hdev_get_max_segments(int fd, struct stat *st) { return get_sysfs_long_val(fd, st, "max_segments"); } @@ -1279,6 +1358,8 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp) { BDRVRawState *s = bs->opaque; struct stat st; + int ret; + BlockZoneModel zoned; s->needs_alignment = raw_needs_alignment(bs); raw_probe_alignment(bs, s->fd, errp); @@ -1316,6 +1397,11 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp) bs->bl.max_hw_iov = ret; } } + + ret = get_sysfs_zoned_model(s->fd, &st, &zoned); + if (ret < 0) + zoned = BLK_Z_NONE; + bs->bl.zoned = zoned; } static int check_for_dasd(int fd) diff --git a/include/block/block_int-common.h b/include/block/block_int-common.h index 8947abab76..7f7863cc9e 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -825,6 +825,9 @@ typedef struct BlockLimits { /* maximum number of iovec elements */ int max_iov; + + /* device zone model */ + BlockZoneModel zoned; } BlockLimits; typedef struct BdrvOpBlocker BdrvOpBlocker; From patchwork Mon Aug 1 01:33:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Li X-Patchwork-Id: 12933306 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7352AC19F2C for ; Mon, 1 Aug 2022 01:37:22 +0000 (UTC) Received: from localhost ([::1]:49374 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIKMz-0006F5-75 for qemu-devel@archiver.kernel.org; Sun, 31 Jul 2022 21:37:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56206) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIKJ3-0003ER-4G; Sun, 31 Jul 2022 21:33:18 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]:46842) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oIKJ0-0000cU-3f; Sun, 31 Jul 2022 21:33:16 -0400 Received: by mail-pj1-x1035.google.com with SMTP id q7-20020a17090a7a8700b001f300db8677so10414482pjf.5; Sun, 31 Jul 2022 18:33:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc; bh=39NFgxRe6z1coXZ/1Fbp0crR/YDnPirHCBwYUNT8sBs=; b=TEBSsCuzrjtdWYneBjD3jURSwzSFw/XbrmkvuAvt9Q1WjhX+S29KGIs2i1oXqXkWjD tLvs5g0omX4lNYfGqtcRj1kJk0PNiBtaUbzTNEQuzz2HvOxluuditZhrE+gt43ixpdz4 x0ukJIWWktJ70iSsFxMH826A5F2ZHYtpGOvpYYKYSQWzLthB0DSy8bVwMu9/HIJxDTFo 6pqqemAN31/NTMd0LLMgkzn/cyefVFCVcnT2efoio+xWjffhrU6nAx573xkdvJoDo1JC HlxJdePynZTt9AKmAwzWA1LvBCVbllEssb0V0oTsFsU9u3w8sQjJ2+27oFF9smah/Zm7 aBPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=39NFgxRe6z1coXZ/1Fbp0crR/YDnPirHCBwYUNT8sBs=; b=3sP2foZMv6PDDBkN50uqjzBgD2wOvPnKVqbA6WSDIiMvJBu8kfcV+g9YYkiXhHWIom PTzo7JtiUymS4aAI0Dn1jAoGwuXY29jIwSIyzMbtVD2uOyZVVxbc+b4V4Yv1FR5jY1J4 fuuWM9+Ul6NnWcU1O5cY+A9G6y9OvqJ6YNJosuk8gDM/kZNnGv00jrk0mIx52ggqUZoC faBc2GtbGjJZF9kdlEWko9hY6SDl447kc+/J4MwuNsr5uGjAZH65/U62VfkI4AXJkGZw eSuOmMNf9Km0pxXnaateXycHiF3bfFR+1W6C+QIFsP7ow65wnO9BYuhd68CcuGsJlDVV /5cw== X-Gm-Message-State: ACgBeo3cNMYIP6rjEiMhoAEFoTfLKlYBSxTh4bIz8SJPV2vMZr4FFipq q81eXdue5pQFekENaRYaQX2mXwDCQaI3NDl/ X-Google-Smtp-Source: AA6agR70ERJ8LZnR1VLVJy5ZplC/ec6/+wpjluMAHioVHXwxQ4yFAXrbMH+CFs/2IHy2c+Pf8WJ19g== X-Received: by 2002:a17:90b:3849:b0:1f4:89bb:14dc with SMTP id nl9-20020a17090b384900b001f489bb14dcmr12560419pjb.144.1659317591914; Sun, 31 Jul 2022 18:33:11 -0700 (PDT) Received: from roots.. ([106.84.131.7]) by smtp.gmail.com with ESMTPSA id q11-20020a170902a3cb00b0016d4f05eb95sm8069478plb.272.2022.07.31.18.33.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Jul 2022 18:33:11 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: damien.lemoal@opensource.wdc.com, dmitry.fomichev@wdc.com, hare@suse.de, stefanha@redhat.com, mst@redhat.com, armbru@redhat.com, qemu-block@nongnu.org, fam@euphon.net, kwolf@redhat.com, hreitz@redhat.com, eblake@redhat.com, Sam Li Subject: [RFC v5 05/11] block: add block layer APIs resembling Linux ZonedBlockDevice ioctls Date: Mon, 1 Aug 2022 09:33:05 +0800 Message-Id: <20220801013305.10561-1-faithilikerun@gmail.com> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=faithilikerun@gmail.com; helo=mail-pj1-x1035.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" By adding zone management operations in BlockDriver, storage controller emulation can use the new block layer APIs including Report Zone and four zone management operations (open, close, finish, reset). BlockDriver can get zone information from null_blk device by refreshing BLockLimits. Signed-off-by: Sam Li --- block/block-backend.c | 47 ++++++ block/coroutines.h | 6 + block/file-posix.c | 272 ++++++++++++++++++++++++++++++- block/io.c | 57 +++++++ include/block/block-common.h | 1 - include/block/block-io.h | 13 ++ include/block/block_int-common.h | 22 ++- include/block/raw-aio.h | 6 +- meson.build | 1 + qapi/block-core.json | 7 +- 10 files changed, 426 insertions(+), 6 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index d4a5df2ac2..ef6a1f33d5 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1775,6 +1775,53 @@ int coroutine_fn blk_co_flush(BlockBackend *blk) return ret; } +/* + * Send a zone_report command. + * offset is a byte offset from the start of the device. No alignment + * required for offset. + * nr_zones represents IN maximum and OUT actual. + */ +int coroutine_fn blk_co_zone_report(BlockBackend *blk, int64_t offset, + unsigned int *nr_zones, + BlockZoneDescriptor *zones) +{ + int ret; + IO_CODE(); + + blk_inc_in_flight(blk); /* increase before waiting */ + blk_wait_while_drained(blk); + if (!blk_is_available(blk)) { + return -ENOMEDIUM; + } + ret = bdrv_co_zone_report(blk_bs(blk), offset, nr_zones, zones); + blk_dec_in_flight(blk); + return ret; +} + +/* + * Send a zone_management command. + * offset is the starting zone specified as a sector offset. + * len is the maximum number of sectors the command should operate on. + */ +int coroutine_fn blk_co_zone_mgmt(BlockBackend *blk, BlockZoneOp op, + int64_t offset, int64_t len) +{ + int ret; + IO_CODE(); + + ret = blk_check_byte_request(blk, offset, len); + if (ret < 0) + return ret; + blk_inc_in_flight(blk); + blk_wait_while_drained(blk); + if (!blk_is_available(blk)) { + return -ENOMEDIUM; + } + ret = bdrv_co_zone_mgmt(blk_bs(blk), op, offset, len); + blk_dec_in_flight(blk); + return ret; +} + void blk_drain(BlockBackend *blk) { BlockDriverState *bs = blk_bs(blk); diff --git a/block/coroutines.h b/block/coroutines.h index 3a2bad564f..e3f62d94e5 100644 --- a/block/coroutines.h +++ b/block/coroutines.h @@ -63,6 +63,12 @@ nbd_co_do_establish_connection(BlockDriverState *bs, bool blocking, Error **errp); +int coroutine_fn blk_co_zone_report(BlockBackend *blk, int64_t offset, + unsigned int *nr_zones, + BlockZoneDescriptor *zones); +int coroutine_fn blk_co_zone_mgmt(BlockBackend *blk, BlockZoneOp op, + int64_t offset, int64_t len); + /* * "I/O or GS" API functions. These functions can run without * the BQL, but only in one specific iothread/main loop. diff --git a/block/file-posix.c b/block/file-posix.c index 0d8b4acdc7..6c045eb6e8 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -67,6 +67,9 @@ #include #include #include +#if defined(CONFIG_BLKZONED) +#include +#endif #include #include #include @@ -216,6 +219,13 @@ typedef struct RawPosixAIOData { PreallocMode prealloc; Error **errp; } truncate; + struct { + unsigned int *nr_zones; + BlockZoneDescriptor *zones; + } zone_report; + struct { + BlockZoneOp op; + } zone_mgmt; }; } RawPosixAIOData; @@ -1386,7 +1396,7 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp) #endif if (bs->sg || S_ISBLK(st.st_mode)) { - int ret = hdev_get_max_hw_transfer(s->fd, &st); + ret = hdev_get_max_hw_transfer(s->fd, &st); if (ret > 0 && ret <= BDRV_REQUEST_MAX_BYTES) { bs->bl.max_hw_transfer = ret; @@ -1402,6 +1412,27 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp) if (ret < 0) zoned = BLK_Z_NONE; bs->bl.zoned = zoned; + if (zoned != BLK_Z_NONE) { + ret = get_sysfs_long_val(s->fd, &st, "chunk_sectors"); + if (ret > 0) { + bs->bl.zone_sectors = ret; + } + + ret = get_sysfs_long_val(s->fd, &st, "zone_append_max_bytes"); + if (ret > 0) { + bs->bl.zone_append_max_bytes = ret; + } + + ret = get_sysfs_long_val(s->fd, &st, "max_open_zones"); + if (ret > 0) { + bs->bl.max_open_zones = ret; + } + + ret = get_sysfs_long_val(s->fd, &st, "max_active_zones"); + if (ret > 0) { + bs->bl.max_active_zones = ret; + } + } } static int check_for_dasd(int fd) @@ -1896,6 +1927,131 @@ static off_t copy_file_range(int in_fd, off_t *in_off, int out_fd, } #endif +/* + * parse_zone - Fill a zone descriptor + */ +#if defined(CONFIG_BLKZONED) +static inline void parse_zone(struct BlockZoneDescriptor *zone, + struct blk_zone *blkz) { + zone->start = blkz->start; + zone->length = blkz->len; + zone->cap = blkz->capacity; + zone->wp = blkz->wp; + zone->type = blkz->type; + zone->cond = blkz->cond; +} + +static int handle_aiocb_zone_report(void *opaque) { + RawPosixAIOData *aiocb = opaque; + int fd = aiocb->aio_fildes; + unsigned int *nr_zones = aiocb->zone_report.nr_zones; + BlockZoneDescriptor *zones = aiocb->zone_report.zones; + int64_t sector = aiocb->aio_offset / 512; /* ZBDs use 512B sectors */ + + struct blk_zone *blkz; + int64_t rep_size; + unsigned int nrz; + int ret, n = 0, i = 0; + + nrz = *nr_zones; + rep_size = sizeof(struct blk_zone_report) + nrz * sizeof(struct blk_zone); + g_autofree struct blk_zone_report *rep = NULL; + rep = g_malloc(rep_size); + + blkz = (struct blk_zone *)(rep + 1); + while (n < nrz) { + memset(rep, 0, rep_size); + rep->sector = sector; + rep->nr_zones = nrz - n; + + ret = ioctl(fd, BLKREPORTZONE, rep); + if (ret != 0) { + error_report("%d: ioctl BLKREPORTZONE at %" PRId64 " failed %d", + fd, sector, errno); + return -errno; + } + + if (!rep->nr_zones) { + break; + } + + for (i = 0; i < rep->nr_zones; i++, n++) { + parse_zone(&zones[n], &blkz[i]); + /* The next report should start after the last zone reported */ + sector = blkz[i].start + blkz[i].len; + } + } + + *nr_zones = n; + return 0; +} + +static int handle_aiocb_zone_mgmt(void *opaque) { + RawPosixAIOData *aiocb = opaque; + BlockDriverState *bs = aiocb->bs; + int fd = aiocb->aio_fildes; + int64_t sector = aiocb->aio_offset; + int64_t nr_sectors = aiocb->aio_nbytes; + BlockZoneOp op = aiocb->zone_mgmt.op; + struct blk_zone_range range; + const char *ioctl_name; + unsigned long ioctl_op; + int64_t zone_sector, zone_sector_mask; + int ret; + + zone_sector = bs->bl.zone_sectors; + zone_sector_mask = zone_sector - 1; + if (sector & zone_sector_mask) { + error_report("offset %" PRId64 " is not aligned to zone size " + "%" PRId64 "", sector, zone_sector); + return -EINVAL; + } + + if (nr_sectors & zone_sector_mask) { + error_report("number of sectors %" PRId64 " is not aligned to zone size" + " %" PRId64 "", nr_sectors, zone_sector); + return -EINVAL; + } + + switch (op) { + case BLK_ZO_OPEN: + ioctl_name = "BLKOPENZONE"; + ioctl_op = BLKOPENZONE; + break; + case BLK_ZO_CLOSE: + ioctl_name = "BLKCLOSEZONE"; + ioctl_op = BLKCLOSEZONE; + break; + case BLK_ZO_FINISH: + ioctl_name = "BLKFINISHZONE"; + ioctl_op = BLKFINISHZONE; + break; + case BLK_ZO_RESET: + ioctl_name = "BLKRESETZONE"; + ioctl_op = BLKRESETZONE; + break; + default: + error_report("Invalid zone operation 0x%x", op); + return -EINVAL; + } + + /* Execute the operation */ + range.sector = sector; + range.nr_sectors = nr_sectors; + do { + ret = ioctl(fd, ioctl_op, &range); + } while (ret != 0 && errno == EINTR); + + if (ret != 0) { + error_report("ioctl %s failed %d", + ioctl_name, errno); + return -errno; + } + + return 0; +} +#endif + static int handle_aiocb_copy_range(void *opaque) { RawPosixAIOData *aiocb = opaque; @@ -3068,6 +3224,61 @@ static void raw_account_discard(BDRVRawState *s, uint64_t nbytes, int ret) } } +/* + * zone report - Get a zone block device's information in the form + * of an array of zone descriptors. + * + * @param bs: passing zone block device file descriptor + * @param zones: an array of zone descriptors to hold zone + * information on reply + * @param offset: offset can be any byte within the zone size. + * @param len: (not sure yet. + * @return 0 on success, -1 on failure + */ +#if defined(CONFIG_BLKZONED) +static int coroutine_fn raw_co_zone_report(BlockDriverState *bs, int64_t offset, + unsigned int *nr_zones, + BlockZoneDescriptor *zones) { + BDRVRawState *s = bs->opaque; + RawPosixAIOData acb; + + acb = (RawPosixAIOData) { + .bs = bs, + .aio_fildes = s->fd, + .aio_type = QEMU_AIO_ZONE_REPORT, + .aio_offset = offset, + .zone_report = { + .nr_zones = nr_zones, + .zones = zones, + }, + }; + + return raw_thread_pool_submit(bs, handle_aiocb_zone_report, &acb); +} + +/* + * zone management operations - Execute an operation on a zone + */ +static int coroutine_fn raw_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, + int64_t offset, int64_t len) { + BDRVRawState *s = bs->opaque; + RawPosixAIOData acb; + + acb = (RawPosixAIOData) { + .bs = bs, + .aio_fildes = s->fd, + .aio_type = QEMU_AIO_ZONE_MGMT, + .aio_offset = offset, + .aio_nbytes = len, + .zone_mgmt = { + .op = op, + }, + }; + + return raw_thread_pool_submit(bs, handle_aiocb_zone_mgmt, &acb); +} +#endif + static coroutine_fn int raw_do_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes, bool blkdev) @@ -3419,6 +3630,9 @@ BlockDriver bdrv_file = { .bdrv_abort_perm_update = raw_abort_perm_update, .create_opts = &raw_create_opts, .mutable_opts = mutable_opts, + + .bdrv_co_zone_report = raw_co_zone_report, + .bdrv_co_zone_mgmt = raw_co_zone_mgmt, }; /***********************************************/ @@ -3568,6 +3782,12 @@ static void hdev_parse_filename(const char *filename, QDict *options, bdrv_parse_filename_strip_prefix(filename, "host_device:", options); } +static void zoned_host_device_parse_filename(const char *filename, QDict *options, + Error **errp) +{ + bdrv_parse_filename_strip_prefix(filename, "zoned_host_device:", options); +} + static bool hdev_is_sg(BlockDriverState *bs) { @@ -3798,6 +4018,55 @@ static BlockDriver bdrv_host_device = { #endif }; +#if defined(CONFIG_BLKZONED) +static BlockDriver bdrv_zoned_host_device = { + .format_name = "zoned_host_device", + .protocol_name = "zoned_host_device", + .instance_size = sizeof(BDRVRawState), + .bdrv_needs_filename = true, + .bdrv_probe_device = hdev_probe_device, + .bdrv_parse_filename = zoned_host_device_parse_filename, + .bdrv_file_open = hdev_open, + .bdrv_close = raw_close, + .bdrv_reopen_prepare = raw_reopen_prepare, + .bdrv_reopen_commit = raw_reopen_commit, + .bdrv_reopen_abort = raw_reopen_abort, + .bdrv_co_create_opts = bdrv_co_create_opts_simple, + .create_opts = &bdrv_create_opts_simple, + .mutable_opts = mutable_opts, + .bdrv_co_invalidate_cache = raw_co_invalidate_cache, + .bdrv_co_pwrite_zeroes = hdev_co_pwrite_zeroes, + + .bdrv_co_preadv = raw_co_preadv, + .bdrv_co_pwritev = raw_co_pwritev, + .bdrv_co_flush_to_disk = raw_co_flush_to_disk, + .bdrv_co_pdiscard = hdev_co_pdiscard, + .bdrv_co_copy_range_from = raw_co_copy_range_from, + .bdrv_co_copy_range_to = raw_co_copy_range_to, + .bdrv_refresh_limits = raw_refresh_limits, + .bdrv_io_plug = raw_aio_plug, + .bdrv_io_unplug = raw_aio_unplug, + .bdrv_attach_aio_context = raw_aio_attach_aio_context, + + .bdrv_co_truncate = raw_co_truncate, + .bdrv_getlength = raw_getlength, + .bdrv_get_info = raw_get_info, + .bdrv_get_allocated_file_size + = raw_get_allocated_file_size, + .bdrv_get_specific_stats = hdev_get_specific_stats, + .bdrv_check_perm = raw_check_perm, + .bdrv_set_perm = raw_set_perm, + .bdrv_abort_perm_update = raw_abort_perm_update, + .bdrv_probe_blocksizes = hdev_probe_blocksizes, + .bdrv_probe_geometry = hdev_probe_geometry, + .bdrv_co_ioctl = hdev_co_ioctl, + + /* zone management operations */ + .bdrv_co_zone_report = raw_co_zone_report, + .bdrv_co_zone_mgmt = raw_co_zone_mgmt, +}; +#endif + #if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) static void cdrom_parse_filename(const char *filename, QDict *options, Error **errp) @@ -4059,6 +4328,7 @@ static void bdrv_file_init(void) #if defined(HAVE_HOST_BLOCK_DEVICE) bdrv_register(&bdrv_host_device); #ifdef __linux__ + bdrv_register(&bdrv_zoned_host_device); bdrv_register(&bdrv_host_cdrom); #endif #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) diff --git a/block/io.c b/block/io.c index 0a8cbefe86..a4625fb0e1 100644 --- a/block/io.c +++ b/block/io.c @@ -3198,6 +3198,63 @@ out: return co.ret; } +int bdrv_co_zone_report(BlockDriverState *bs, int64_t offset, + unsigned int *nr_zones, + BlockZoneDescriptor *zones) +{ + BlockDriver *drv = bs->drv; + CoroutineIOCompletion co = { + .coroutine = qemu_coroutine_self(), + }; + IO_CODE(); + + bdrv_inc_in_flight(bs); + if (!drv || (!drv->bdrv_co_zone_report)) { + co.ret = -ENOTSUP; + goto out; + } + + if (drv->bdrv_co_zone_report) { + co.ret = drv->bdrv_co_zone_report(bs, offset, nr_zones, zones); + } else { + co.ret = -ENOTSUP; + goto out; + qemu_coroutine_yield(); + } + +out: + bdrv_dec_in_flight(bs); + return co.ret; +} + +int bdrv_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, + int64_t offset, int64_t len) +{ + BlockDriver *drv = bs->drv; + CoroutineIOCompletion co = { + .coroutine = qemu_coroutine_self(), + }; + IO_CODE(); + + bdrv_inc_in_flight(bs); + if (!drv || (!drv->bdrv_co_zone_mgmt)) { + co.ret = -ENOTSUP; + goto out; + } + + if (drv->bdrv_co_zone_mgmt) { + co.ret = drv->bdrv_co_zone_mgmt(bs, op, offset, len); + } else { + co.ret = -ENOTSUP; + goto out; + qemu_coroutine_yield(); + } + +out: + bdrv_dec_in_flight(bs); + return co.ret; +} + void *qemu_blockalign(BlockDriverState *bs, size_t size) { IO_CODE(); diff --git a/include/block/block-common.h b/include/block/block-common.h index c9d28b1c51..19cf27cca9 100644 --- a/include/block/block-common.h +++ b/include/block/block-common.h @@ -23,7 +23,6 @@ */ #ifndef BLOCK_COMMON_H #define BLOCK_COMMON_H - #include "block/aio.h" #include "block/aio-wait.h" #include "qemu/iov.h" diff --git a/include/block/block-io.h b/include/block/block-io.h index fd25ffa9be..55ad261e16 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -88,6 +88,13 @@ int bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf); /* Ensure contents are flushed to disk. */ int coroutine_fn bdrv_co_flush(BlockDriverState *bs); +/* Report zone information of zone block device. */ +int coroutine_fn bdrv_co_zone_report(BlockDriverState *bs, int64_t offset, + unsigned int *nr_zones, + BlockZoneDescriptor *zones); +int coroutine_fn bdrv_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, + int64_t offset, int64_t len); + int bdrv_co_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes); bool bdrv_can_write_zeroes_with_unmap(BlockDriverState *bs); int bdrv_block_status(BlockDriverState *bs, int64_t offset, @@ -297,6 +304,12 @@ bdrv_readv_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos); int generated_co_wrapper bdrv_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos); +int generated_co_wrapper +blk_zone_report(BlockBackend *blk, int64_t offset, unsigned int *nr_zones, + BlockZoneDescriptor *zones); +int generated_co_wrapper +blk_zone_mgmt(BlockBackend *blk, BlockZoneOp op, int64_t offset, int64_t len); + /** * bdrv_parent_drained_begin_single: * diff --git a/include/block/block_int-common.h b/include/block/block_int-common.h index 7f7863cc9e..de44c7b6f4 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -94,7 +94,6 @@ typedef struct BdrvTrackedRequest { struct BdrvTrackedRequest *waiting_for; } BdrvTrackedRequest; - struct BlockDriver { /* * These fields are initialized when this object is created, @@ -691,6 +690,12 @@ struct BlockDriver { QEMUIOVector *qiov, int64_t pos); + int coroutine_fn (*bdrv_co_zone_report)(BlockDriverState *bs, + int64_t offset, unsigned int *nr_zones, + BlockZoneDescriptor *zones); + int coroutine_fn (*bdrv_co_zone_mgmt)(BlockDriverState *bs, BlockZoneOp op, + int64_t offset, int64_t len); + /* removable device specific */ bool (*bdrv_is_inserted)(BlockDriverState *bs); void (*bdrv_eject)(BlockDriverState *bs, bool eject_flag); @@ -828,6 +833,21 @@ typedef struct BlockLimits { /* device zone model */ BlockZoneModel zoned; + + /* zone size expressed in 512-byte sectors */ + uint32_t zone_sectors; + + /* total number of zones */ + unsigned int nr_zones; + + /* maximum size in bytes of a zone append write operation */ + int64_t zone_append_max_bytes; + + /* maximum number of open zones */ + int64_t max_open_zones; + + /* maximum number of active zones */ + int64_t max_active_zones; } BlockLimits; typedef struct BdrvOpBlocker BdrvOpBlocker; diff --git a/include/block/raw-aio.h b/include/block/raw-aio.h index 21fc10c4c9..3d26929cdd 100644 --- a/include/block/raw-aio.h +++ b/include/block/raw-aio.h @@ -29,6 +29,8 @@ #define QEMU_AIO_WRITE_ZEROES 0x0020 #define QEMU_AIO_COPY_RANGE 0x0040 #define QEMU_AIO_TRUNCATE 0x0080 +#define QEMU_AIO_ZONE_REPORT 0x0100 +#define QEMU_AIO_ZONE_MGMT 0x0200 #define QEMU_AIO_TYPE_MASK \ (QEMU_AIO_READ | \ QEMU_AIO_WRITE | \ @@ -37,7 +39,9 @@ QEMU_AIO_DISCARD | \ QEMU_AIO_WRITE_ZEROES | \ QEMU_AIO_COPY_RANGE | \ - QEMU_AIO_TRUNCATE) + QEMU_AIO_TRUNCATE | \ + QEMU_AIO_ZONE_REPORT | \ + QEMU_AIO_ZONE_MGMT) /* AIO flags */ #define QEMU_AIO_MISALIGNED 0x1000 diff --git a/meson.build b/meson.build index 75aaca8462..8c34516443 100644 --- a/meson.build +++ b/meson.build @@ -1883,6 +1883,7 @@ config_host_data.set('CONFIG_REPLICATION', get_option('live_block_migration').al # has_header config_host_data.set('CONFIG_EPOLL', cc.has_header('sys/epoll.h')) config_host_data.set('CONFIG_LINUX_MAGIC_H', cc.has_header('linux/magic.h')) +config_host_data.set('CONFIG_BLKZONED', cc.has_header('linux/blkzoned.h')) config_host_data.set('CONFIG_VALGRIND_H', cc.has_header('valgrind/valgrind.h')) config_host_data.set('HAVE_BTRFS_H', cc.has_header('linux/btrfs.h')) config_host_data.set('HAVE_DRM_H', cc.has_header('libdrm/drm.h')) diff --git a/qapi/block-core.json b/qapi/block-core.json index 2173e7734a..507f514ef9 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2955,7 +2955,8 @@ 'luks', 'nbd', 'nfs', 'null-aio', 'null-co', 'nvme', 'parallels', 'preallocate', 'qcow', 'qcow2', 'qed', 'quorum', 'raw', 'rbd', { 'name': 'replication', 'if': 'CONFIG_REPLICATION' }, - 'ssh', 'throttle', 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat' ] } + 'ssh', 'throttle', 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat', + { 'name': 'zoned_host_device', 'if': 'CONFIG_BLKZONED' } ] } ## # @BlockdevOptionsFile: @@ -4329,7 +4330,9 @@ 'vhdx': 'BlockdevOptionsGenericFormat', 'vmdk': 'BlockdevOptionsGenericCOWFormat', 'vpc': 'BlockdevOptionsGenericFormat', - 'vvfat': 'BlockdevOptionsVVFAT' + 'vvfat': 'BlockdevOptionsVVFAT', + 'zoned_host_device': { 'type': 'BlockdevOptionsFile', + 'if': 'CONFIG_BLKZONED' } } } ## From patchwork Mon Aug 1 01:33:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Li X-Patchwork-Id: 12933319 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ED92BC00140 for ; Mon, 1 Aug 2022 01:42:23 +0000 (UTC) Received: from localhost ([::1]:34340 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIKRr-0006jW-0z for qemu-devel@archiver.kernel.org; Sun, 31 Jul 2022 21:42:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56224) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIKJI-0003Ge-3N; Sun, 31 Jul 2022 21:33:34 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]:41676) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oIKJE-0000d5-Qv; Sun, 31 Jul 2022 21:33:30 -0400 Received: by mail-pj1-x102d.google.com with SMTP id t2-20020a17090a4e4200b001f21572f3a4so10472618pjl.0; Sun, 31 Jul 2022 18:33:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc; bh=rbTfjrlfp2f4Jk/H8zP36u4wj3Q7NZoPN3xcxEBsKtM=; b=mRqGa60nR917gKy4fvXB6TgcrZDyf3+aVsAvS0JXNFBSXP3ZbW086Nn9ZCm9JTPy/j K6w/kEAofqTHCsehOQpXnpAzdpScw9fEPK+hyKRnbVF9C+o6gprUqtrk556fCjyuNVVk 2yYj4tjtzAxQ67Ir/2EoqsG34CLJ/rBCzKJtmWM/gPzEhd9G9Q8UEXcBSaCxi/HOW843 35grT/0pWFPJirn7/ixjXWtQdOo7Q1GtzuQwLoPjXG8GqARY3SxyS+i/NDHiBD/tvcBZ RtnzTqAZ4iV7lBmPMUNzfo1gBi50jpRVp1Ze/yvqM1QHHCo2AApQiZLfq+k44v90IBms Ar5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=rbTfjrlfp2f4Jk/H8zP36u4wj3Q7NZoPN3xcxEBsKtM=; b=ATtono6sPVAfleRl+qWExq6AEts49aXG3sHkT0q3XRCzIbd9XnnN0l+RjJc64WUPJf JlzPZHVB2/NstvCx10ygQlkPkUwIbqGzQhOTZJK8KGRbw3Qy7e1YuotL6r3vSFG3Lrv0 7pMT1yvDrqYY+JbLaOp9Chv1x0I58tSzXbtlGqAUHp0x+UAECU6qKU4AO8vlCZDu6bd7 yXih93m8rwpfR8se95odcM9Ifvr7FeQwW1tnaP4hMy6+z99RDyDw211BKsJBFn8Wbydn Iq5z9LlkxL0S9+0uZMu8HOsxsHK2Cts9eOcJYWCXWFFukgPZ2jW25WcQizRg47OwzOGl n4mw== X-Gm-Message-State: ACgBeo0phPEQCNDUIJ1g2kRMzk8FhCNt00sG1lc80bHICiMGn5zNPGPb SeLvwVW3RNVhm2z1Dx2Ac4Cn09dxIIMutuF8 X-Google-Smtp-Source: AA6agR5HzLd1FEKVUQixZ8jHSWJ6rJ6pmL2JWosOs2XRX2p3yra83yXUwCzKNJUH1vG9QC7FxP0KWg== X-Received: by 2002:a17:903:244e:b0:16d:d5cd:c184 with SMTP id l14-20020a170903244e00b0016dd5cdc184mr12733134pls.44.1659317606873; Sun, 31 Jul 2022 18:33:26 -0700 (PDT) Received: from roots.. ([106.84.131.7]) by smtp.gmail.com with ESMTPSA id c136-20020a621c8e000000b0052ab54a4711sm4886017pfc.150.2022.07.31.18.33.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Jul 2022 18:33:26 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: damien.lemoal@opensource.wdc.com, dmitry.fomichev@wdc.com, hare@suse.de, stefanha@redhat.com, mst@redhat.com, armbru@redhat.com, qemu-block@nongnu.org, fam@euphon.net, kwolf@redhat.com, hreitz@redhat.com, eblake@redhat.com, Sam Li Subject: [RFC v5 06/11] raw-format: add zone operations to pass through requests Date: Mon, 1 Aug 2022 09:33:18 +0800 Message-Id: <20220801013318.10607-1-faithilikerun@gmail.com> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=faithilikerun@gmail.com; helo=mail-pj1-x102d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" raw-format driver usually sits on top of file-posix driver. It needs to pass through requests of zone commands. Signed-off-by: Sam Li Reviewed-by: Stefan Hajnoczi --- block/raw-format.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/block/raw-format.c b/block/raw-format.c index 69fd650eaf..6b20bd22ef 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -314,6 +314,17 @@ static int coroutine_fn raw_co_pdiscard(BlockDriverState *bs, return bdrv_co_pdiscard(bs->file, offset, bytes); } +static int coroutine_fn raw_co_zone_report(BlockDriverState *bs, int64_t offset, + unsigned int *nr_zones, + BlockZoneDescriptor *zones) { + return bdrv_co_zone_report(bs->file->bs, offset, nr_zones, zones); +} + +static int coroutine_fn raw_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, + int64_t offset, int64_t len) { + return bdrv_co_zone_mgmt(bs->file->bs, op, offset, len); +} + static int64_t raw_getlength(BlockDriverState *bs) { int64_t len; @@ -614,6 +625,8 @@ BlockDriver bdrv_raw = { .bdrv_co_pwritev = &raw_co_pwritev, .bdrv_co_pwrite_zeroes = &raw_co_pwrite_zeroes, .bdrv_co_pdiscard = &raw_co_pdiscard, + .bdrv_co_zone_report = &raw_co_zone_report, + .bdrv_co_zone_mgmt = &raw_co_zone_mgmt, .bdrv_co_block_status = &raw_co_block_status, .bdrv_co_copy_range_from = &raw_co_copy_range_from, .bdrv_co_copy_range_to = &raw_co_copy_range_to, From patchwork Mon Aug 1 01:33:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Li X-Patchwork-Id: 12933308 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 692FDC00140 for ; Mon, 1 Aug 2022 01:41:02 +0000 (UTC) Received: from localhost ([::1]:58524 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIKQX-0003yd-Fe for qemu-devel@archiver.kernel.org; Sun, 31 Jul 2022 21:41:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56252) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIKJV-0003Qk-6K; Sun, 31 Jul 2022 21:33:45 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]:35516) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oIKJT-0000dX-Ft; Sun, 31 Jul 2022 21:33:44 -0400 Received: by mail-pj1-x1032.google.com with SMTP id x2-20020a17090ab00200b001f4da5cdc9cso3523625pjq.0; Sun, 31 Jul 2022 18:33:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc; bh=GKVrcwEXCl2prSJ6/7KlSnZxGgo82D1bXh5Xv9PM7A0=; b=oLKUcU8qwFYLSm8ce+GuSPJD4lQOq+jxdy5DKngX1GiSMzZvUHiql5Q+xcxSSCHa6P 5bsXj6sCRD7h6TKRy8shvlJVU5aZMdBfYEGZtJWp2OlerJW27Vo2ci0LBdGIx5k/PCKb Dvqs+GtxCofEeXGYlTXyUwAldj7ggg/FK/t6mf9X+KCF101V38D/UravvTnk8YrVNO5L akC5+tbr6bEW23KI1xxZrsoVtf7Tn+lRV7ZdOXVatc3BTlQ2yRAn/6YaVy6J748/U56w UYO6FfZYbf7MLUbO24DN518pOve81tg0aoNiP1E7nNlejL6aG7Fa8gB+roEgnHSadnB4 xyhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=GKVrcwEXCl2prSJ6/7KlSnZxGgo82D1bXh5Xv9PM7A0=; b=zwtDBJGkWFH3TU+/LmD1QmO5nVVoybtL3eBCitYirLTfveemlGpxGJQRCkg38Ixwuu hQs74ZbQUZ+1PvIW/EACxVtqB1jeGAAccAvGOjoo2GSWJTTspAEVUqd6emW6YdnjVdgi tHv8v13zHdrJZfHoEFf2+0rYjg9jHu4IdbOk6NbYWyZOVc8UNwkLAzKgpUI8k0WYrv1v JVaYIzTxt27RjP1w9XTuumXwc0Km4qapp5v2uUCem5OiWjpH/1bfu5DHL6cpEpU70eqf CeQR5qBippzBAcWXD/0kQk5m6kFIP33umFN1wtfCoYXM3AKlfYUVCfuAe2NkQQJV7KJQ 5L3w== X-Gm-Message-State: ACgBeo3ZZy1lS+uFtW0eynnac09ER0cPFzM/IVU82/Ev0aguwIq307e7 4MKo14FI3KQtCGRRRY+xxqMbZD6IHlvUziwz X-Google-Smtp-Source: AA6agR4BVSUKf+vLgrcNwEJG7S5m1so1mRZzsD6fav/yyml4YFyA2/7PmPV4+v0QzmUdx5GKjV/DGQ== X-Received: by 2002:a17:903:40c7:b0:16e:e32d:259c with SMTP id t7-20020a17090340c700b0016ee32d259cmr4635424pld.67.1659317621217; Sun, 31 Jul 2022 18:33:41 -0700 (PDT) Received: from roots.. ([106.84.131.7]) by smtp.gmail.com with ESMTPSA id 63-20020a620642000000b00528c8ed356dsm7269625pfg.96.2022.07.31.18.33.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Jul 2022 18:33:41 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: damien.lemoal@opensource.wdc.com, dmitry.fomichev@wdc.com, hare@suse.de, stefanha@redhat.com, mst@redhat.com, armbru@redhat.com, qemu-block@nongnu.org, fam@euphon.net, kwolf@redhat.com, hreitz@redhat.com, eblake@redhat.com, Sam Li Subject: [RFC v5 07/11] config: add check to block layer Date: Mon, 1 Aug 2022 09:33:33 +0800 Message-Id: <20220801013333.10644-1-faithilikerun@gmail.com> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=faithilikerun@gmail.com; helo=mail-pj1-x1032.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Putting zoned/non-zoned BlockDrivers on top of each other is not allowed. Signed-off-by: Sam Li --- block.c | 13 +++++++++++++ block/file-posix.c | 2 ++ block/raw-format.c | 1 + include/block/block_int-common.h | 10 ++++++++++ 4 files changed, 26 insertions(+) diff --git a/block.c b/block.c index bc85f46eed..8a259b158c 100644 --- a/block.c +++ b/block.c @@ -7947,6 +7947,19 @@ void bdrv_add_child(BlockDriverState *parent_bs, BlockDriverState *child_bs, return; } + /* + * Non-zoned block drivers do not follow zoned storage constraints + * (i.e. sequential writes to zones). Refuse mixing zoned and non-zoned + * drivers in a graph. + */ + if (!parent_bs->drv->supports_zoned_children && child_bs->drv->is_zoned) { + error_setg(errp, "Cannot add a %s child to a %s parent", + child_bs->drv->is_zoned ? "zoned" : "non-zoned", + parent_bs->drv->supports_zoned_children ? + "support zoned children" : "not support zoned children"); + return; + } + if (!QLIST_EMPTY(&child_bs->parents)) { error_setg(errp, "The node %s already has a parent", child_bs->node_name); diff --git a/block/file-posix.c b/block/file-posix.c index 6c045eb6e8..8eb0b7bc9b 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -4023,6 +4023,8 @@ static BlockDriver bdrv_zoned_host_device = { .format_name = "zoned_host_device", .protocol_name = "zoned_host_device", .instance_size = sizeof(BDRVRawState), + .is_zoned = true, + .supports_zoned_children = true, .bdrv_needs_filename = true, .bdrv_probe_device = hdev_probe_device, .bdrv_parse_filename = zoned_host_device_parse_filename, diff --git a/block/raw-format.c b/block/raw-format.c index 6b20bd22ef..9441536819 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -614,6 +614,7 @@ static void raw_child_perm(BlockDriverState *bs, BdrvChild *c, BlockDriver bdrv_raw = { .format_name = "raw", .instance_size = sizeof(BDRVRawState), + .supports_zoned_children = true, .bdrv_probe = &raw_probe, .bdrv_reopen_prepare = &raw_reopen_prepare, .bdrv_reopen_commit = &raw_reopen_commit, diff --git a/include/block/block_int-common.h b/include/block/block_int-common.h index de44c7b6f4..0476cd0491 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -126,6 +126,16 @@ struct BlockDriver { */ bool is_format; + /* + * Set to true if the BlockDriver is a zoned block driver. + */ + bool is_zoned; + + /* + * Set to true if the BlockDriver supports zoned children. + */ + bool supports_zoned_children; + /* * Drivers not implementing bdrv_parse_filename nor bdrv_open should have * this field set to true, except ones that are defined only by their From patchwork Mon Aug 1 01:33:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Li X-Patchwork-Id: 12933322 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 462E1C00140 for ; Mon, 1 Aug 2022 01:44:30 +0000 (UTC) Received: from localhost ([::1]:41252 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIKTt-0002uj-CR for qemu-devel@archiver.kernel.org; Sun, 31 Jul 2022 21:44:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56280) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIKJh-0003sZ-PO; Sun, 31 Jul 2022 21:33:57 -0400 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]:50721) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oIKJf-0000fG-GD; Sun, 31 Jul 2022 21:33:57 -0400 Received: by mail-pj1-x1036.google.com with SMTP id f7so9604807pjp.0; Sun, 31 Jul 2022 18:33:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc; bh=FSjm4fpw1GFTKKny8ZQPXkRUdPSravta+3M2bQR2cdM=; b=IjRWKHc5XIC1K4U9vbfO5o6gWC+kjveRfCSq4HLbNe6fuSAa31I01elbYjo6U5sqhl +z6VEeZR+ciUzfcDotlYmrrifc8sVYpDxvmBBa6F8C9wBzfodGCc/EuZxn+/EDfdPKgC JfvdcIM9ZHg4IY973euagurjjbsA+tUqei4nXoAZXGYItpMIw6gFLfU8rSsHg3exR9Id xqnmc6DpL7WHscQS0tPU8fcL/uND6SGij0UsApMcjlpttvot0MCnP/hjjv4yfFXvzc7d s6TGnubLCYrVg7usLNHyEAe4J2lnDwSRC37z5VjOA6ALFRQrXJENZ5wnCij2tS3alB0Z KSBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=FSjm4fpw1GFTKKny8ZQPXkRUdPSravta+3M2bQR2cdM=; b=DR1nZQkxWlGu4mrt/2StY16r/k+rRzV5/bIy0yCRcOds4EfVGVvb2/8vCv54MaytCB Xpg8Ih7ltSKz+Lk/S4tDGA/CuUP/JdvoUaFYSzkF5Sfv/CSyyc6XjyRIwt/mVJmqbAzI cECzB6DjJjvUZC+HErqdejHZ/phTC1UUZN9cvqPLwouxASTYGlw+uaFRl4W9PDtiq119 pk6mYNmIPnO5xkg5fTskdBkZFT/ccQUkya+wbEtE+aE34Ddg6mY+8cDQ+FTrOSM/mfmB XsfjFM0TNdv52cZBsYEzBM/1EkN1P79/0Z3YJDJ38anDcKQYFerObQq3sy5Vlzemzja7 jhfg== X-Gm-Message-State: ACgBeo0NEtIOGAeXNzCmKQ5EzzxUEIQZRpJAIMwlDoiYG58dm8K3AOV3 kqWTKV8Qrml1aBM+AU7iR0+AmJtrqwSl39mn X-Google-Smtp-Source: AA6agR7WPCUB6a34JLl4Wrub22/C+kZAix4uKj5pkSgiijWt86mBSlCaq2iq+4yBqbdUk7KJDfnAXA== X-Received: by 2002:a17:90b:ec7:b0:1f2:fa08:44cd with SMTP id gz7-20020a17090b0ec700b001f2fa0844cdmr16305687pjb.183.1659317633705; Sun, 31 Jul 2022 18:33:53 -0700 (PDT) Received: from roots.. ([106.84.131.7]) by smtp.gmail.com with ESMTPSA id cp17-20020a17090afb9100b001ef9659d711sm7297302pjb.48.2022.07.31.18.33.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Jul 2022 18:33:53 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: damien.lemoal@opensource.wdc.com, dmitry.fomichev@wdc.com, hare@suse.de, stefanha@redhat.com, mst@redhat.com, armbru@redhat.com, qemu-block@nongnu.org, fam@euphon.net, kwolf@redhat.com, hreitz@redhat.com, eblake@redhat.com, Sam Li Subject: [RFC v5 08/11] virtio-blk: add zoned storage APIs for zoned devices Date: Mon, 1 Aug 2022 09:33:45 +0800 Message-Id: <20220801013345.10681-1-faithilikerun@gmail.com> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1036; envelope-from=faithilikerun@gmail.com; helo=mail-pj1-x1036.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" This patch extends virtio-blk emulation to handle zoned device commands by calling the new block layer APIs to perform zoned device I/O on behalf of the guest. It supports Report Zone, and four zone oparations (open, close, finish, reset). The virtio-blk zoned device command specifications is currently in the reviewing process. VIRTIO_BLK_F_ZONED will only be set if the host does support zoned block devices. The regular block device will not be set. The guest os having zoned device support can use blkzone(8) to test those commands. Signed-off-by: Sam Li --- block/block-backend.c | 92 ++++++++++++++++ hw/block/virtio-blk.c | 172 +++++++++++++++++++++++++++++- include/sysemu/block-backend-io.h | 6 ++ 3 files changed, 268 insertions(+), 2 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index ef6a1f33d5..8f2cfcbd9d 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1431,6 +1431,15 @@ typedef struct BlkRwCo { void *iobuf; int ret; BdrvRequestFlags flags; + union { + struct { + unsigned int *nr_zones; + BlockZoneDescriptor *zones; + } zone_report; + struct { + BlockZoneOp op; + } zone_mgmt; + }; } BlkRwCo; int blk_make_zero(BlockBackend *blk, BdrvRequestFlags flags) @@ -1775,6 +1784,89 @@ int coroutine_fn blk_co_flush(BlockBackend *blk) return ret; } +static void blk_aio_zone_report_entry(void *opaque) { + BlkAioEmAIOCB *acb = opaque; + BlkRwCo *rwco = &acb->rwco; + + rwco->ret = blk_co_zone_report(rwco->blk, rwco->offset, + rwco->zone_report.nr_zones, + rwco->zone_report.zones); + blk_aio_complete(acb); +} + +BlockAIOCB *blk_aio_zone_report(BlockBackend *blk, int64_t offset, + unsigned int *nr_zones, + BlockZoneDescriptor *zones, + BlockCompletionFunc *cb, void *opaque) +{ + BlkAioEmAIOCB *acb; + Coroutine *co; + + blk_inc_in_flight(blk); + acb = blk_aio_get(&blk_aio_em_aiocb_info, blk, cb, opaque); + acb->rwco = (BlkRwCo) { + .blk = blk, + .offset = offset, + .ret = NOT_DONE, + .zone_report = { + .zones = zones, + .nr_zones = nr_zones, + }, + }; + acb->has_returned = false; + + co = qemu_coroutine_create(blk_aio_zone_report_entry, acb); + bdrv_coroutine_enter(blk_bs(blk), co); + + acb->has_returned = true; + if (acb->rwco.ret != NOT_DONE) { + replay_bh_schedule_oneshot_event(blk_get_aio_context(blk), + blk_aio_complete_bh, acb); + } + + return &acb->common; +} + +static void blk_aio_zone_mgmt_entry(void *opaque) { + BlkAioEmAIOCB *acb = opaque; + BlkRwCo *rwco = &acb->rwco; + + rwco->ret = blk_co_zone_mgmt(rwco->blk, rwco->zone_mgmt.op, + rwco->offset, acb->bytes); + blk_aio_complete(acb); +} + +BlockAIOCB *blk_aio_zone_mgmt(BlockBackend *blk, BlockZoneOp op, + int64_t offset, int64_t len, + BlockCompletionFunc *cb, void *opaque) { + BlkAioEmAIOCB *acb; + Coroutine *co; + + blk_inc_in_flight(blk); + acb = blk_aio_get(&blk_aio_em_aiocb_info, blk, cb, opaque); + acb->rwco = (BlkRwCo) { + .blk = blk, + .offset = offset, + .ret = NOT_DONE, + .zone_mgmt = { + .op = op, + }, + }; + acb->bytes = len; + acb->has_returned = false; + + co = qemu_coroutine_create(blk_aio_zone_mgmt_entry, acb); + bdrv_coroutine_enter(blk_bs(blk), co); + + acb->has_returned = true; + if (acb->rwco.ret != NOT_DONE) { + replay_bh_schedule_oneshot_event(blk_get_aio_context(blk), + blk_aio_complete_bh, acb); + } + + return &acb->common; +} + /* * Send a zone_report command. * offset is a byte offset from the start of the device. No alignment diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index e9ba752f6b..9722f447a2 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -37,6 +37,7 @@ /* Config size before the discard support (hide associated config fields) */ #define VIRTIO_BLK_CFG_SIZE offsetof(struct virtio_blk_config, \ max_discard_sectors) + /* * Starting from the discard feature, we can use this array to properly * set the config size depending on the features enabled. @@ -46,6 +47,8 @@ static const VirtIOFeature feature_sizes[] = { .end = endof(struct virtio_blk_config, discard_sector_alignment)}, {.flags = 1ULL << VIRTIO_BLK_F_WRITE_ZEROES, .end = endof(struct virtio_blk_config, write_zeroes_may_unmap)}, + {.flags = 1ULL << VIRTIO_BLK_F_ZONED, + .end = endof(struct virtio_blk_config, zoned)}, {} }; @@ -514,6 +517,131 @@ static void virtio_blk_handle_flush(VirtIOBlockReq *req, MultiReqBuffer *mrb) blk_aio_flush(s->blk, virtio_blk_flush_complete, req); } +typedef struct ZoneReportData { + VirtIOBlockReq *req; + unsigned int nr_zones; + BlockZoneDescriptor zones[]; +} ZoneReportData; + +static void virtio_blk_zone_report_complete(void *opaque, int ret) +{ + ZoneReportData *data = opaque; + VirtIOBlockReq *req = data->req; + VirtIOBlock *s = req->dev; + VirtIODevice *vdev = VIRTIO_DEVICE(req->dev); + struct iovec *in_iov = req->elem.in_sg; + unsigned in_num = req->elem.in_num; + int64_t zrp_size, nz, offset, n, j; /* offset is of in_iov */ + + nz = data->nr_zones; + j = 0; + + struct virtio_blk_zone_report zrp_hdr = (struct virtio_blk_zone_report) { + .nr_zones = cpu_to_le64(nz), + }; + + zrp_size = sizeof(struct virtio_blk_zone_report) + + sizeof(struct virtio_blk_zone_descriptor) * nz; + offset = sizeof(zrp_hdr); + + memset(zrp_hdr.reserved, 0, 56); + aio_context_acquire(blk_get_aio_context(s->conf.conf.blk)); + n = iov_from_buf(in_iov, in_num, 0, &zrp_hdr, offset); + if (n != sizeof(zrp_hdr)) { + virtio_error(vdev, "Driver provided intput buffer that is too small!"); + return; + } + + for (size_t i = offset; i < zrp_size; i += sizeof(struct virtio_blk_zone_descriptor), ++j) { + struct virtio_blk_zone_descriptor desc = + (struct virtio_blk_zone_descriptor) { + .z_start = cpu_to_le64(data->zones[j].start), + .z_cap = cpu_to_le64(data->zones[j].cap), + .z_wp = cpu_to_le64(data->zones[j].wp), + .z_type = data->zones[j].type, + .z_state = data->zones[j].cond, + }; + memset(desc.reserved, 0, 38); + n = iov_from_buf(in_iov, in_num, i, &desc, sizeof(desc)); + if (n != sizeof(desc)) { + virtio_error(vdev, "Driver provided input buffer " + "for descriptors that is too small!"); + return; + } + } + g_free(data); + + virtio_blk_req_complete(req, VIRTIO_BLK_S_OK); + virtio_blk_free_request(req); + aio_context_release(blk_get_aio_context(s->conf.conf.blk)); +} + +static int virtio_blk_handle_zone_report(VirtIOBlockReq *req) { + VirtIOBlock *s = req->dev; + VirtIODevice *vdev = VIRTIO_DEVICE(s); + unsigned int nr_zones; + size_t data_size; + ZoneReportData *data; + int64_t offset; + + if (req->in_len <= sizeof(struct virtio_blk_inhdr)) { + virtio_error(vdev, "in buffer too small for zone report"); + return -1; + } + + /* start offset of the zone report */ + offset = virtio_ldq_p(vdev, &req->out.sector); + nr_zones = (req->in_len - sizeof(struct virtio_blk_inhdr) - + sizeof(struct virtio_blk_zone_report)) / + sizeof(struct virtio_blk_zone_descriptor); + data_size = sizeof(ZoneReportData) + + sizeof(BlockZoneDescriptor) * nr_zones; + data = g_malloc(data_size); + memset(data, 0, data_size); + data->nr_zones = nr_zones; + data->req = req; + + blk_aio_zone_report(s->blk, offset, &data->nr_zones, data->zones, + virtio_blk_zone_report_complete, data); + return 0; +} + +static void virtio_blk_zone_mgmt_complete(void *opaque, int ret) { + VirtIOBlockReq *req = opaque; + + virtio_blk_req_complete(req, VIRTIO_BLK_S_OK); + virtio_blk_free_request(req); +} + +static int virtio_blk_handle_zone_mgmt(VirtIOBlockReq *req, BlockZoneOp op) { + VirtIOBlock *s = req->dev; + VirtIODevice *vdev = VIRTIO_DEVICE(s); + int64_t offset = virtio_ldq_p(vdev, &req->out.sector); + struct iovec *out_iov =req->elem.out_sg; + unsigned out_num = req->elem.out_num; + BlockDriverState *state = blk_bs(s->blk); + struct virtio_blk_zone_mgmt_outhdr zm_hdr; + uint64_t len; + + if (unlikely(iov_to_buf(out_iov, out_num, 0, &zm_hdr, + sizeof(zm_hdr)) != sizeof(zm_hdr))){ + virtio_error(vdev, "virtio-blk request zone_mgmt_outhdr too short"); + return -1; + } + + if (zm_hdr.flags & VIRTIO_BLK_ZONED_FLAG_ALL) { + /* Entire drive capacity */ + offset = 0; + blk_get_geometry(s->blk, &len); + } else { + len = state->bl.zone_sectors; + } + + blk_aio_zone_mgmt(s->blk, op, offset, len, + virtio_blk_zone_mgmt_complete, req); + return 0; +} + static bool virtio_blk_sect_range_ok(VirtIOBlock *dev, uint64_t sector, size_t size) { @@ -700,6 +828,21 @@ static int virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *mrb) case VIRTIO_BLK_T_FLUSH: virtio_blk_handle_flush(req, mrb); break; + case VIRTIO_BLK_T_ZONE_REPORT: + virtio_blk_handle_zone_report(req); + break; + case VIRTIO_BLK_T_ZONE_OPEN: + virtio_blk_handle_zone_mgmt(req, BLK_ZO_OPEN); + break; + case VIRTIO_BLK_T_ZONE_CLOSE: + virtio_blk_handle_zone_mgmt(req, BLK_ZO_CLOSE); + break; + case VIRTIO_BLK_T_ZONE_RESET: + virtio_blk_handle_zone_mgmt(req, BLK_ZO_RESET); + break; + case VIRTIO_BLK_T_ZONE_FINISH: + virtio_blk_handle_zone_mgmt(req, BLK_ZO_FINISH); + break; case VIRTIO_BLK_T_SCSI_CMD: virtio_blk_handle_scsi(req); break; @@ -913,10 +1056,10 @@ static void virtio_blk_reset(VirtIODevice *vdev) /* coalesce internal state, copy to pci i/o region 0 */ -static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config) -{ +static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config) { VirtIOBlock *s = VIRTIO_BLK(vdev); BlockConf *conf = &s->conf.conf; + BlockDriverState *state = blk_bs(s->blk); struct virtio_blk_config blkcfg; uint64_t capacity; int64_t length; @@ -976,6 +1119,25 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config) blkcfg.write_zeroes_may_unmap = 1; virtio_stl_p(vdev, &blkcfg.max_write_zeroes_seg, 1); } +#ifdef CONFIG_BLKZONED + blkcfg.zoned.model = state->bl.zoned; + if (state->bl.zoned != BLK_Z_NONE) { + switch (state->bl.zoned) { + case BLK_Z_HM: + case BLK_Z_HA: + virtio_stl_p(vdev, &blkcfg.zoned.zone_sectors, state->bl.zone_sectors); + virtio_stl_p(vdev, &blkcfg.zoned.max_active_zones, state->bl.max_active_zones); + virtio_stl_p(vdev, &blkcfg.zoned.max_open_zones, state->bl.max_open_zones); + virtio_stl_p(vdev, &blkcfg.zoned.max_append_sectors, state->bl.zone_append_max_bytes); + virtio_stl_p(vdev, &blkcfg.zoned.write_granularity, blk_size); + break; + default: + virtio_error(vdev, "Invalid zoned model %x \n", (int)state->bl.zoned); + blkcfg.zoned.model = BLK_Z_NONE; + break; + } + } +#endif memcpy(config, &blkcfg, s->config_size); } @@ -995,6 +1157,7 @@ static uint64_t virtio_blk_get_features(VirtIODevice *vdev, uint64_t features, Error **errp) { VirtIOBlock *s = VIRTIO_BLK(vdev); + BlockDriverState *state = blk_bs(s->blk); /* Firstly sync all virtio-blk possible supported features */ features |= s->host_features; @@ -1003,6 +1166,8 @@ static uint64_t virtio_blk_get_features(VirtIODevice *vdev, uint64_t features, virtio_add_feature(&features, VIRTIO_BLK_F_GEOMETRY); virtio_add_feature(&features, VIRTIO_BLK_F_TOPOLOGY); virtio_add_feature(&features, VIRTIO_BLK_F_BLK_SIZE); + if (state->bl.zoned != BLK_Z_NONE) + virtio_add_feature(&s->host_features, VIRTIO_BLK_F_ZONED); if (virtio_has_feature(features, VIRTIO_F_VERSION_1)) { if (virtio_has_feature(s->host_features, VIRTIO_BLK_F_SCSI)) { error_setg(errp, "Please set scsi=off for virtio-blk devices in order to use virtio 1.0"); @@ -1286,6 +1451,9 @@ static Property virtio_blk_properties[] = { #ifdef __linux__ DEFINE_PROP_BIT64("scsi", VirtIOBlock, host_features, VIRTIO_BLK_F_SCSI, false), +#endif +#ifdef CONFIG_BLKZONED + DEFINE_PROP_BIT64("zoned", VirtIOBlock, host_features, VIRTIO_BLK_F_ZONED, true), #endif DEFINE_PROP_BIT("request-merging", VirtIOBlock, conf.request_merging, 0, true), diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h index 50f5aa2e07..6fe98bd1ed 100644 --- a/include/sysemu/block-backend-io.h +++ b/include/sysemu/block-backend-io.h @@ -45,6 +45,12 @@ BlockAIOCB *blk_aio_pwritev(BlockBackend *blk, int64_t offset, BlockCompletionFunc *cb, void *opaque); BlockAIOCB *blk_aio_flush(BlockBackend *blk, BlockCompletionFunc *cb, void *opaque); +BlockAIOCB *blk_aio_zone_report(BlockBackend *blk, int64_t offset, + unsigned int *nr_zones, BlockZoneDescriptor *zones, + BlockCompletionFunc *cb, void *opaque); +BlockAIOCB *blk_aio_zone_mgmt(BlockBackend *blk, BlockZoneOp op, + int64_t offset, int64_t len, + BlockCompletionFunc *cb, void *opaque); BlockAIOCB *blk_aio_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes, BlockCompletionFunc *cb, void *opaque); void blk_aio_cancel_async(BlockAIOCB *acb); From patchwork Mon Aug 1 01:33:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Li X-Patchwork-Id: 12933320 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5B7AEC00140 for ; Mon, 1 Aug 2022 01:43:51 +0000 (UTC) Received: from localhost ([::1]:38250 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIKTG-0000tj-8t for qemu-devel@archiver.kernel.org; Sun, 31 Jul 2022 21:43:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56300) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIKJv-0004BN-92; Sun, 31 Jul 2022 21:34:20 -0400 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]:43004) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oIKJt-0000fq-Ft; Sun, 31 Jul 2022 21:34:10 -0400 Received: by mail-pg1-x52c.google.com with SMTP id i71so2899474pge.9; Sun, 31 Jul 2022 18:34:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc; bh=STp8BitGJRh7BHonoM/wiLh8qdiBzBp/kI1Nm1IuscI=; b=UkMQZa+AsoeHAvbyx3YJF8klbEmAI2I0BXYdhyM0eRoNuNgc2ipfipt35DkrQb0RZG opvwyeVQTrpOOuJ4TbjFmZI6j3FsHt5XYTF28X1qDWvyNOKkLjfMByVcGS3OoTzt3JIg layLSu8+mG3So28lkU16WYU0x9cAkZQ9znv49ettD52ID0gb4pqOks1jZ/2pWK2emAu1 P/fxYIJvb66xtA7IYeN2hkxu8MfCH03sx0xOk/T7xPYmXLodKPHYyfLv7FXdqkJnkECW 7rRYnjYCJbdXPgZMRIeTo3hp6HNmVtWz3gtm94Hjz1pgz3/oN849dAHdprVh2JCAvS3j 1+Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=STp8BitGJRh7BHonoM/wiLh8qdiBzBp/kI1Nm1IuscI=; b=bqY7DVfeZrQZtvMy61ipUB6S02D1a7Q19oS13bYsSCzJt9JAZRSeDOOduPZgO8vUBn y7q5ku+xMVTZA3uL7TeHHHdcl3i516mQDEPS5OaHMzUfZ6s/Wu5JxGAdGkhHUDSnRZ9e jGl1QDnwTGaA939zXwTDMeoukD4fGI1bqwY69kIFvZH1U7XCWT2/g3wm7DdTocgaOnSD 3FEAvT0Y3fXh62kLaDBtfxwUXm3bBLgzETM/LKc4ryQv72bWGIe/WkVTlTBtUuXIJiPB VN6mx8YBG8a5qJDHX+rgI9rB9ef0ovSaRuB81IJikN2wfJ/SLbnnQftLJ1lTouVCXPKR 6caQ== X-Gm-Message-State: AJIora/JFK5lRR3kvKO03Jnf1sVEQ4TS8dI1Zb6BCH0p2icnON9x3yWK zF0rgBzAfA+DvA6qQpsHhRJ8rqiy/asjGjFT X-Google-Smtp-Source: AGRyM1vK/5A/bvqkvCgzKCwOYy5cJ9bDeOK51xZCMyeIo283ywvyo6Mr/a3pKzNPSECZ+VCFn9qlSA== X-Received: by 2002:a63:c04:0:b0:41a:ff05:a863 with SMTP id b4-20020a630c04000000b0041aff05a863mr11416607pgl.513.1659317646529; Sun, 31 Jul 2022 18:34:06 -0700 (PDT) Received: from roots.. ([106.84.131.7]) by smtp.gmail.com with ESMTPSA id l185-20020a6391c2000000b0041bf7924fc4sm1530970pge.13.2022.07.31.18.34.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Jul 2022 18:34:06 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: damien.lemoal@opensource.wdc.com, dmitry.fomichev@wdc.com, hare@suse.de, stefanha@redhat.com, mst@redhat.com, armbru@redhat.com, qemu-block@nongnu.org, fam@euphon.net, kwolf@redhat.com, hreitz@redhat.com, eblake@redhat.com, Sam Li Subject: [RFC v5 09/11] qemu-io: add zoned block device operations. Date: Mon, 1 Aug 2022 09:33:59 +0800 Message-Id: <20220801013359.10702-1-faithilikerun@gmail.com> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52c; envelope-from=faithilikerun@gmail.com; helo=mail-pg1-x52c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Add zoned storage commands of the device: zone_report(zrp), zone_open(zo), zone_close(zc), zone_reset(zrs), zone_finish(zf). For example, to test zone_report, use following command: $ ./build/qemu-io --image-opts driver=zoned_host_device, filename=/dev/nullb0 -c "zrp offset nr_zones" Signed-off-by: Sam Li Reviewed-by: Stefan Hajnoczi --- block/io.c | 24 ++------- qemu-io-cmds.c | 144 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+), 20 deletions(-) diff --git a/block/io.c b/block/io.c index a4625fb0e1..de9ec1d740 100644 --- a/block/io.c +++ b/block/io.c @@ -3209,19 +3209,11 @@ int bdrv_co_zone_report(BlockDriverState *bs, int64_t offset, IO_CODE(); bdrv_inc_in_flight(bs); - if (!drv || (!drv->bdrv_co_zone_report)) { + if (!drv || !drv->bdrv_co_zone_report) { co.ret = -ENOTSUP; goto out; } - - if (drv->bdrv_co_zone_report) { - co.ret = drv->bdrv_co_zone_report(bs, offset, nr_zones, zones); - } else { - co.ret = -ENOTSUP; - goto out; - qemu_coroutine_yield(); - } - + co.ret = drv->bdrv_co_zone_report(bs, offset, nr_zones, zones); out: bdrv_dec_in_flight(bs); return co.ret; @@ -3237,19 +3229,11 @@ int bdrv_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, IO_CODE(); bdrv_inc_in_flight(bs); - if (!drv || (!drv->bdrv_co_zone_mgmt)) { + if (!drv || !drv->bdrv_co_zone_mgmt) { co.ret = -ENOTSUP; goto out; } - - if (drv->bdrv_co_zone_mgmt) { - co.ret = drv->bdrv_co_zone_mgmt(bs, op, offset, len); - } else { - co.ret = -ENOTSUP; - goto out; - qemu_coroutine_yield(); - } - + co.ret = drv->bdrv_co_zone_mgmt(bs, op, offset, len); out: bdrv_dec_in_flight(bs); return co.ret; diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index 952dc940f1..5a215277c7 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -1712,6 +1712,145 @@ static const cmdinfo_t flush_cmd = { .oneline = "flush all in-core file state to disk", }; +static int zone_report_f(BlockBackend *blk, int argc, char **argv) +{ + int ret; + int64_t offset; + unsigned int nr_zones; + + ++optind; + offset = cvtnum(argv[optind]); + ++optind; + nr_zones = cvtnum(argv[optind]); + + g_autofree BlockZoneDescriptor *zones = NULL; + zones = g_new(BlockZoneDescriptor, nr_zones); + ret = blk_zone_report(blk, offset, &nr_zones, zones); + if (ret < 0) { + printf("zone report failed: %s\n", strerror(-ret)); + } else { + for (int i = 0; i < nr_zones; ++i) { + printf("start: 0x%" PRIx64 ", len 0x%" PRIx64 ", " + "cap"" 0x%" PRIx64 ",wptr 0x%" PRIx64 ", " + "zcond:%u, [type: %u]\n", + zones[i].start, zones[i].length, zones[i].cap, zones[i].wp, + zones[i].cond, zones[i].type); + } + } + return ret; +} + +static const cmdinfo_t zone_report_cmd = { + .name = "zone_report", + .altname = "zrp", + .cfunc = zone_report_f, + .argmin = 2, + .argmax = 2, + .args = "offset number", + .oneline = "report zone information", +}; + +static int zone_open_f(BlockBackend *blk, int argc, char **argv) +{ + int ret; + int64_t offset, len; + ++optind; + offset = cvtnum(argv[optind]); + ++optind; + len = cvtnum(argv[optind]); + ret = blk_zone_mgmt(blk, BLK_ZO_OPEN, offset, len); + if (ret < 0) { + printf("zone open failed: %s\n", strerror(-ret)); + } + return ret; +} + +static const cmdinfo_t zone_open_cmd = { + .name = "zone_open", + .altname = "zo", + .cfunc = zone_open_f, + .argmin = 2, + .argmax = 2, + .args = "offset len", + .oneline = "explicit open a range of zones in zone block device", +}; + +static int zone_close_f(BlockBackend *blk, int argc, char **argv) +{ + int ret; + int64_t offset, len; + ++optind; + offset = cvtnum(argv[optind]); + ++optind; + len = cvtnum(argv[optind]); + ret = blk_zone_mgmt(blk, BLK_ZO_CLOSE, offset, len); + if (ret < 0) { + printf("zone close failed: %s\n", strerror(-ret)); + } + return ret; +} + +static const cmdinfo_t zone_close_cmd = { + .name = "zone_close", + .altname = "zc", + .cfunc = zone_close_f, + .argmin = 2, + .argmax = 2, + .args = "offset len", + .oneline = "close a range of zones in zone block device", +}; + +static int zone_finish_f(BlockBackend *blk, int argc, char **argv) +{ + int ret; + int64_t offset, len; + ++optind; + offset = cvtnum(argv[optind]); + ++optind; + len = cvtnum(argv[optind]); + ret = blk_zone_mgmt(blk, BLK_ZO_FINISH, offset, len); + if (ret < 0) { + printf("zone finish failed: %s\n", strerror(-ret)); + } + return ret; +} + +static const cmdinfo_t zone_finish_cmd = { + .name = "zone_finish", + .altname = "zf", + .cfunc = zone_finish_f, + .argmin = 2, + .argmax = 2, + .args = "offset len", + .oneline = "finish a range of zones in zone block device", +}; + +static int zone_reset_f(BlockBackend *blk, int argc, char **argv) +{ + int ret; + int64_t offset, len; + ++optind; + offset = cvtnum(argv[optind]); + ++optind; + len = cvtnum(argv[optind]); + ret = blk_zone_mgmt(blk, BLK_ZO_RESET, offset, len); + if (ret < 0) { + printf("zone reset failed: %s\n", strerror(-ret)); + } + return ret; +} + +static const cmdinfo_t zone_reset_cmd = { + .name = "zone_reset", + .altname = "zrs", + .cfunc = zone_reset_f, + .argmin = 2, + .argmax = 2, + .args = "offset len", + .oneline = "reset a zone write pointer in zone block device", +}; + + static int truncate_f(BlockBackend *blk, int argc, char **argv); static const cmdinfo_t truncate_cmd = { .name = "truncate", @@ -2504,6 +2643,11 @@ static void __attribute((constructor)) init_qemuio_commands(void) qemuio_add_command(&aio_write_cmd); qemuio_add_command(&aio_flush_cmd); qemuio_add_command(&flush_cmd); + qemuio_add_command(&zone_report_cmd); + qemuio_add_command(&zone_open_cmd); + qemuio_add_command(&zone_close_cmd); + qemuio_add_command(&zone_finish_cmd); + qemuio_add_command(&zone_reset_cmd); qemuio_add_command(&truncate_cmd); qemuio_add_command(&length_cmd); qemuio_add_command(&info_cmd); From patchwork Mon Aug 1 01:34:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Li X-Patchwork-Id: 12933309 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4D9DFC00140 for ; Mon, 1 Aug 2022 01:41:05 +0000 (UTC) Received: from localhost ([::1]:58762 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIKQa-00048P-D3 for qemu-devel@archiver.kernel.org; Sun, 31 Jul 2022 21:41:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56370) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIKKA-0004KW-79; Sun, 31 Jul 2022 21:34:37 -0400 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]:37819) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oIKK8-0000gh-Eo; Sun, 31 Jul 2022 21:34:25 -0400 Received: by mail-pg1-x52f.google.com with SMTP id bh13so8438439pgb.4; Sun, 31 Jul 2022 18:34:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc; bh=Hrlr6S+WvZdp1hgKCfvKtMNgcntTY7LzWpVGjqF3Nv4=; b=c0riUX4U2ykMAsnLE8B+j5rIk0CHv/diMupF2mbYG5o/YGWIEXPCqWwmDTtvbzZ96M flLJv3/zmC/eyQ++Q0kARESsRVH9EPPc4tF5k7Lt7pnoUwBh4JEJ3D183uyq/zoJ8Jml I8rLCQ4bX1bSVZACen8KhUOpjqWOVV3FXlwZVV+2xFKTLlmpPPDfxtphhsHFCkEFLZZr D31eL9cAAYS58TUix71ViN0+Y6gWIqVjLLVFVb5seHoiTm04quCKy11w/oeXQZ5+inUy B+d71kuteKNz0zTfEQyRE63jZBPfrsCkEImKFKUIUJnelm92CEO/CtMQHmrvs/ZZzTs/ A1Kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=Hrlr6S+WvZdp1hgKCfvKtMNgcntTY7LzWpVGjqF3Nv4=; b=uotr3DLfsnLTVhj6EYmSrT2r/vWjmPRLuVDYBuPMoLJFwjntFfhsqG1DmAcAhICY3l /BwjSbuVZQzTg4fgYAPcuKxuJueDcZ0oaDLPif8pHBVIZzxtLHQacIF4VNYqQplck3cy djVxkp5Apgrmka855XVNDhV+FvpHDvhPtbgxmA87AN21/WOEtGn0CEMtHWbnmgwkH4Np 5dMzUwzWaD/qv1hQ9PAtWGK1hcQ0lzQDwkUeGjB/Eor+52CokqSuRIknPPgjTZXIOovN tc7H61QuTzpaS0ua+S7ifQ7BUHs+XZP2JIB0FmDfyX8td436/MrIcQu9aEXP1PEkDKEU ryQg== X-Gm-Message-State: ACgBeo0/7AuRpqxixkNV6VjmZfN23cRQBBN2BUJp0RV4JRYZxaGV71+0 gHmiZ/TgIsb9g7dUQ32R7cHhilZG5h3GRAFu X-Google-Smtp-Source: AA6agR7a6TXgOyiFfV1C0IIJqkmx945cTM1yoa5NbYzpA91T4cLD9yrywKBiMWp4z50/DF1D7U8/9A== X-Received: by 2002:aa7:960a:0:b0:52d:862b:55a7 with SMTP id q10-20020aa7960a000000b0052d862b55a7mr1808254pfg.19.1659317662723; Sun, 31 Jul 2022 18:34:22 -0700 (PDT) Received: from roots.. ([106.84.131.7]) by smtp.gmail.com with ESMTPSA id l1-20020a17090a384100b001f31e91200asm7941377pjf.44.2022.07.31.18.34.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Jul 2022 18:34:22 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: damien.lemoal@opensource.wdc.com, dmitry.fomichev@wdc.com, hare@suse.de, stefanha@redhat.com, mst@redhat.com, armbru@redhat.com, qemu-block@nongnu.org, fam@euphon.net, kwolf@redhat.com, hreitz@redhat.com, eblake@redhat.com, Sam Li Subject: [RFC v5 10/11] qemu-iotests: test new zone operations Date: Mon, 1 Aug 2022 09:34:16 +0800 Message-Id: <20220801013416.10786-1-faithilikerun@gmail.com> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52f; envelope-from=faithilikerun@gmail.com; helo=mail-pg1-x52f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" We have added new block layer APIs of zoned block devices. Test it with: Create a null_blk device, run each zone operation on it and see whether reporting right zone information. Signed-off-by: Sam Li Reviewed-by: Stefan Hajnoczi --- tests/qemu-iotests/tests/zoned.out | 53 ++++++++++++++++++ tests/qemu-iotests/tests/zoned.sh | 86 ++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 tests/qemu-iotests/tests/zoned.out create mode 100755 tests/qemu-iotests/tests/zoned.sh diff --git a/tests/qemu-iotests/tests/zoned.out b/tests/qemu-iotests/tests/zoned.out new file mode 100644 index 0000000000..d09be2ffcd --- /dev/null +++ b/tests/qemu-iotests/tests/zoned.out @@ -0,0 +1,53 @@ +QA output created by zoned.sh +Testing a null_blk device: +Simple cases: if the operations work +(1) report the first zone: +start: 0x0, len 0x80000, cap 0x80000,wptr 0x0, zcond:1, [type: 2] + +report the first 10 zones +start: 0x0, len 0x80000, cap 0x80000,wptr 0x0, zcond:1, [type: 2] +start: 0x80000, len 0x80000, cap 0x80000,wptr 0x80000, zcond:1, [type: 2] +start: 0x100000, len 0x80000, cap 0x80000,wptr 0x100000, zcond:1, [type: 2] +start: 0x180000, len 0x80000, cap 0x80000,wptr 0x180000, zcond:1, [type: 2] +start: 0x200000, len 0x80000, cap 0x80000,wptr 0x200000, zcond:1, [type: 2] +start: 0x280000, len 0x80000, cap 0x80000,wptr 0x280000, zcond:1, [type: 2] +start: 0x300000, len 0x80000, cap 0x80000,wptr 0x300000, zcond:1, [type: 2] +start: 0x380000, len 0x80000, cap 0x80000,wptr 0x380000, zcond:1, [type: 2] +start: 0x400000, len 0x80000, cap 0x80000,wptr 0x400000, zcond:1, [type: 2] +start: 0x480000, len 0x80000, cap 0x80000,wptr 0x480000, zcond:1, [type: 2] + +report the last zone: +start: 0x1f380000, len 0x80000, cap 0x80000,wptr 0x1f380000, zcond:1, [type: 2] + + +(2) opening the first zone +report after: +start: 0x0, len 0x80000, cap 0x80000,wptr 0x0, zcond:3, [type: 2] + +opening the second zone +report after: +start: 0x80000, len 0x80000, cap 0x80000,wptr 0x80000, zcond:3, [type: 2] + +opening the last zone +report after: +start: 0x1f380000, len 0x80000, cap 0x80000,wptr 0x1f380000, zcond:3, [type: 2] + + +(3) closing the first zone +report after: +start: 0x0, len 0x80000, cap 0x80000,wptr 0x0, zcond:1, [type: 2] + +closing the last zone +report after: +start: 0x1f380000, len 0x80000, cap 0x80000,wptr 0x1f380000, zcond:1, [type: 2] + + +(4) finishing the second zone +After finishing a zone: +start: 0x80000, len 0x80000, cap 0x80000,wptr 0x100000, zcond:14, [type: 2] + + +(5) resetting the second zone +After resetting a zone: +start: 0x80000, len 0x80000, cap 0x80000,wptr 0x80000, zcond:1, [type: 2] +*** done diff --git a/tests/qemu-iotests/tests/zoned.sh b/tests/qemu-iotests/tests/zoned.sh new file mode 100755 index 0000000000..db68aa88d4 --- /dev/null +++ b/tests/qemu-iotests/tests/zoned.sh @@ -0,0 +1,86 @@ +#!/usr/bin/env bash +# +# Test zone management operations. +# + +seq="$(basename $0)" +echo "QA output created by $seq" +status=1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img + sudo rmmod null_blk +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter +. ./common.qemu + +# This test only runs on Linux hosts with raw image files. +_supported_fmt raw +_supported_proto file +_supported_os Linux + +QEMU_IO="build/qemu-io" +IMG="--image-opts driver=zoned_host_device,filename=/dev/nullb0" +QEMU_IO_OPTIONS=$QEMU_IO_OPTIONS_NO_FMT + +echo "Testing a null_blk device:" +echo "Simple cases: if the operations work" +sudo modprobe null_blk nr_devices=1 zoned=1 + +echo "(1) report the first zone:" +sudo $QEMU_IO $IMG -c "zrp 0 1" +echo +echo "report the first 10 zones" +sudo $QEMU_IO $IMG -c "zrp 0 10" +echo +echo "report the last zone:" +sudo $QEMU_IO $IMG -c "zrp 0x3e70000000 2" +echo +echo +echo "(2) opening the first zone" +sudo $QEMU_IO $IMG -c "zo 0 0x80000" +echo "report after:" +sudo $QEMU_IO $IMG -c "zrp 0 1" +echo +echo "opening the second zone" +sudo $QEMU_IO $IMG -c "zo 524288 0x80000" # 524288 is the zone sector size +echo "report after:" +sudo $QEMU_IO $IMG -c "zrp 268435456 1" # 268435456 / 512 = 524288 +echo +echo "opening the last zone" +sudo $QEMU_IO $IMG -c "zo 0x1f380000 0x80000" +echo "report after:" +sudo $QEMU_IO $IMG -c "zrp 0x3e70000000 2" +echo +echo +echo "(3) closing the first zone" +sudo $QEMU_IO $IMG -c "zc 0 0x80000" +echo "report after:" +sudo $QEMU_IO $IMG -c "zrp 0 1" +echo +echo "closing the last zone" +sudo $QEMU_IO $IMG -c "zc 0x1f380000 0x80000" +echo "report after:" +sudo $QEMU_IO $IMG -c "zrp 0x3e70000000 2" +echo +echo +echo "(4) finishing the second zone" +sudo $QEMU_IO $IMG -c "zf 524288 0x80000" +echo "After finishing a zone:" +sudo $QEMU_IO $IMG -c "zrp 268435456 1" +echo +echo + +echo "(5) resetting the second zone" +sudo $QEMU_IO $IMG -c "zrs 524288 0x80000" +echo "After resetting a zone:" +sudo $QEMU_IO $IMG -c "zrp 268435456 1" +# success, all done +echo "*** done" +rm -f $seq.full +status=0 From patchwork Mon Aug 1 01:34:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Li X-Patchwork-Id: 12933321 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5DA17C19F2C for ; Mon, 1 Aug 2022 01:43:52 +0000 (UTC) Received: from localhost ([::1]:38434 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIKTH-00011U-AZ for qemu-devel@archiver.kernel.org; Sun, 31 Jul 2022 21:43:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56384) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIKKL-0004MR-QI; Sun, 31 Jul 2022 21:34:43 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]:37646) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oIKKJ-0000hJ-WE; Sun, 31 Jul 2022 21:34:37 -0400 Received: by mail-pf1-x434.google.com with SMTP id w185so9290484pfb.4; Sun, 31 Jul 2022 18:34:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc; bh=+Qqm7Xkah4rqyk9vUi8VDm/R3WQUM/ej4Fd0yJ5tItA=; b=XrezTm7MiJQZoAAZ6FOuchXs5Imt33Jh+u6MrrTwouUG7/pWf/x7PzR9Dn6eEOPFT9 nm0o2z2FF7neQ1ecmEteGWyQLULby25fb2f/pzvgodYyOJWiunTd1M8vN3XDwLWJU1Vn 4J4pwH0/Tgp47D2Bro5gOHOJP7eiqFuqV6QnkRyusAwvKY0ZdXUm0CiQr47TbGmtxVPd ijt66u4abIBR/s10s+4aZ4bRhMMYLbszY0mbwuMv1aWxX3O9Y3dMtRI52ZfLlBPNEAXW U+1UVJ6WNV9QeD2+9EqRrnBgdIsPfu9Q2mEkTXQTLNorrRqjtGAgJCP+vQf9JSnrl0XC cT7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=+Qqm7Xkah4rqyk9vUi8VDm/R3WQUM/ej4Fd0yJ5tItA=; b=Hu7mYpdjiKM7egvQNsA9d4UcVRvxO9vAAz1YQKcfouZmc0yibHx7DxsRU17IsONhTA DLJmy0ieLYHUsRw9RlHGTo8tbHzC7Pqaegnt3mF0A220n2+yL6vpivHuub1IcS1oVbbE m9hZthJtbOXxUbWMz4rozfsUV4syH0kRhPFi/4Uo5LZbgXyQLNUR65Z2ZjiCFLE0hqjk HptiXEWQJV5xcgy0v+H9uM85pFjiZbyKcRSP7IQTNP7TxfOYYh8b1//N2LHibvxXVG74 e40qJTsoXr+oE8hg+CzZ/BUh8INhSfIZE1k8B/zhHfTWR0B0pVb8yTF51mbhgaLGd8Fh HsHw== X-Gm-Message-State: AJIora/HuIm9UKBIVgu8kTMdb1y40RdVQcaUoyBdzRq/WX6ZGuJp733i XlhxEUSb5obMsdq3oaZVlVgCm3VPQZG4sPy6 X-Google-Smtp-Source: AGRyM1ui8ImMHbQSI2eXcBwdM3OyEqxwdNPprGtCsEAU7ZFtVacvb+IQo4lZWMqxP+cmIFavxKhOrA== X-Received: by 2002:a63:5653:0:b0:419:ffb6:3ec6 with SMTP id g19-20020a635653000000b00419ffb63ec6mr11477847pgm.149.1659317674145; Sun, 31 Jul 2022 18:34:34 -0700 (PDT) Received: from roots.. ([106.84.131.7]) by smtp.gmail.com with ESMTPSA id w196-20020a6282cd000000b0052d689fabbasm1183236pfd.121.2022.07.31.18.34.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Jul 2022 18:34:33 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: damien.lemoal@opensource.wdc.com, dmitry.fomichev@wdc.com, hare@suse.de, stefanha@redhat.com, mst@redhat.com, armbru@redhat.com, qemu-block@nongnu.org, fam@euphon.net, kwolf@redhat.com, hreitz@redhat.com, eblake@redhat.com, Sam Li Subject: [RFC v5 11/11] docs/zoned-storage: add zoned device documentation Date: Mon, 1 Aug 2022 09:34:27 +0800 Message-Id: <20220801013427.10811-1-faithilikerun@gmail.com> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::434; envelope-from=faithilikerun@gmail.com; helo=mail-pf1-x434.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Add the documentation about the zoned device support to virtio-blk emulation. Signed-off-by: Sam Li --- docs/devel/zoned-storage.rst | 68 ++++++++++++++++++++++++++ docs/system/qemu-block-drivers.rst.inc | 6 +++ 2 files changed, 74 insertions(+) create mode 100644 docs/devel/zoned-storage.rst diff --git a/docs/devel/zoned-storage.rst b/docs/devel/zoned-storage.rst new file mode 100644 index 0000000000..e62927dceb --- /dev/null +++ b/docs/devel/zoned-storage.rst @@ -0,0 +1,68 @@ +============= +zoned-storage +============= + +Zoned Block Devices (ZBDs) devide the LBA space to block regions called zones +that are larger than the LBA size. It can only allow sequential writes, which +reduces write amplification in SSD, leading to higher throughput and increased +capacity. More details about ZBDs can be found at: + +https://zonedstorage.io/docs/introduction/zoned-storage + +zone emulation +-------------- +In its current status, the virtio-blk device is not aware of ZBDs but the guest +sees host-managed drives as regular drive that will runs correctly under the +most common write workloads. + +The zoned device support aims to let guests (virtual machines) access zoned +storage devices on the host (hypervisor) through a virtio-blk device. This +involves extending QEMU's block layer and virtio-blk emulation code. + +If the host supports zoned block devices, it can set VIRTIO_BLK_F_ZONED. Then +in the guest side, it appears following situations: +1) If the guest virtio-blk driver sees the VIRTIO_BLK_F_ZONED bit set, then it +will assume that the zoned characteristics fields of the config space are valid. +2) If the guest virtio-blk driver sees a zoned model that is NONE, then it is +known that is a regular block device. +3) If the guest virtio-blk driver sees a zoned model that is HM(or HA), then it +is known that is a zoned block device and probes the other zone fields. + +On QEMU sides, +1) The DEFINE PROP BIT macro must be used to declare that the host supports +zones. +2) BlockDrivers can declare zoned device support once known the zoned model +for the block device is not NONE. + +zoned storage APIs +------------------ + +Zone emulation part extends the block layer APIs and virtio-blk emulation section +with the minimum set of zoned commands that are necessary to support zoned +devices. The commands are - Report Zones, four zone operations and Zone Append +(developing). + +testing +------- + +It can be tested on a null_blk device using qemu-io, qemu-iotests or blkzone(8) +command in the guest os. + +1. For example, the command line for zone report using qemu-io is: + +$ path/to/qemu-io --image-opts driver=zoned_host_device,filename=/dev/nullb0 -c +"zrp offset nr_zones" + +To enable zoned device in the guest os, the guest kernel must have the virtio-blk +driver with ZBDs support. The link to such patches for the kernel is: + +https://github.com/dmitry-fomichev/virtblk-zbd + +Then, add the following options to the QEMU command line: +-blockdev node-name=drive0,driver=zoned_host_device,filename=/dev/nullb0 + +After the guest os booting, use blkzone(8) to test zone operations: +blkzone report -o offset -c nr_zones /dev/vda + +2. We can also use the qemu-iotests in ./tests/qemu-iotests/tests/zoned.sh. + diff --git a/docs/system/qemu-block-drivers.rst.inc b/docs/system/qemu-block-drivers.rst.inc index dfe5d2293d..2a761a4b80 100644 --- a/docs/system/qemu-block-drivers.rst.inc +++ b/docs/system/qemu-block-drivers.rst.inc @@ -430,6 +430,12 @@ Hard disks you may corrupt your host data (use the ``-snapshot`` command line option or modify the device permissions accordingly). +Zoned block devices + Zoned block devices can passed through to the guest if the emulated storage + controller supports zoned storage. Use ``--blockdev zoned_host_device, + node-name=drive0,filename=/dev/nullb0`` to pass through ``/dev/nullb0`` + as ``drive0``. + Windows ^^^^^^^