From nobody Thu Apr 25 18:48:42 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1659686539; cv=none; d=zohomail.com; s=zohoarc; b=OQBi1NIjELViuQZUjygmFI9yV/iCNRAdpbv51ejS3lT8vqFU7RCNVysj3rZ+wd/BVTap9IBLGMrMDkK1FYoKV07xevBwZtXY33cuTlbTyfFDhLHqT6qvy3aOIaFu/c1dtTIlmYQyoUo3P1mcObAECdkP8urQzOpBnkY/rmIP9bA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659686539; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/uxSNMtOiF3YH3Q+juusUgjtziotSgDrNrvuRHofnb4=; b=dJ10EBZa14jm+FM8AiwYRB0LIt2p5R2gzUTAWuMwk6AV5MlmR+wFpFOn8eIA2y6ZoTTSkYICXd8+hx5qPgI+2TEIYGieav0MZx6txHvfVBH6XCjFZa5+WgCUHoFY3JjZjs3ATkQEtl6pN2+q8h6xEn1+KFYKH0uPKq1JRD1pTy0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1659686539440960.3152502110363; Fri, 5 Aug 2022 01:02:19 -0700 (PDT) Received: from localhost ([::1]:50900 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJsHi-0005Ey-4Z for importer@patchew.org; Fri, 05 Aug 2022 04:02:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60398) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJsDg-0002pG-QW; Fri, 05 Aug 2022 03:58:08 -0400 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]:40589) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oJsDf-0001v8-AI; Fri, 05 Aug 2022 03:58:08 -0400 Received: by mail-pg1-x52b.google.com with SMTP id f11so2036001pgj.7; Fri, 05 Aug 2022 00:58:06 -0700 (PDT) Received: from roots.. ([106.84.130.246]) by smtp.gmail.com with ESMTPSA id z15-20020a170903018f00b0016ee708350bsm2418564plg.14.2022.08.05.00.58.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Aug 2022 00:58:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=/uxSNMtOiF3YH3Q+juusUgjtziotSgDrNrvuRHofnb4=; b=bgbcajtxBExDi2i6IUq3tzOyho4Cc28LAo7XcC2ahfpUzTF0YYYNdMkBSC0/iKuuda Y8sfZG3CNq2cizw/2IZdfv79z3FxstltIVNG9hj+hqrU/9gKM9zPW+amUdwqkcqjz6RL XqlUYrJOj0dWjsf2jKYEp32rDhU3Pd5EzMiW+QzecD9lImLIhtWDmtsehhqhdHGA5jQ5 T8js7anXngRHNQwxVI0pHTxpeDPeYLufKqSvuSp3CC8wuDf8dMSv42ksvWDiKVBmHN0/ Q2I6bH4S7Q8FFgi3HeQQDsrtlnQWryMIx29mFEL8PB+e5tdZFJ3NFDM4x3DJmYwdkxDr N7qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=/uxSNMtOiF3YH3Q+juusUgjtziotSgDrNrvuRHofnb4=; b=Hm9pEpOvAgG/9KKhgN8qdJm1sxYZFze9QNRaUPF77TKNdogE42bEBdiJ28USEa0T0E 79yZNfOu1S/hd49Os29ovpCzak/UXwqMLlftWxusMYrQjSIq5guuvHo8+hrAmHu+8nWp z5+rLevicgQhhSdabUc5mIvwUhsMGXXILa0UEV7Y68K1WFnCknLoA5ElkJg381qMF8pi 74uYIG6BVHeQk1FwiGjgoUtT8a84YkJdBPZjtYqkQuDP8Y8AYOXeFsIiitlc0lS0wdZm PPl15IIkWcSGnpGNAuTKowWB4i//cw/nUHKlkb53+oXeO3j+o+fFH+HSzBOVL8b663cO mIGw== X-Gm-Message-State: ACgBeo3EQrm4QxqwMizL3Cm3owFqyZJkaR70+C/cpsrw5hEDg5+H5D/w +YJCOwAFFVIC+XAJpwZTQBwOi5qfueLKtA== X-Google-Smtp-Source: AA6agR4efXrnVMt7r0jugaJ2n42RoTTCYTeQysAWC2mji+ND1x4qD3BQm12Ss+PCKJPG0QV0jU5tWA== X-Received: by 2002:a63:1726:0:b0:41d:b30:46d4 with SMTP id x38-20020a631726000000b0041d0b3046d4mr1033346pgl.27.1659686285581; Fri, 05 Aug 2022 00:58:05 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, hare@suse.de, Stefan Hajnoczi , dmitry.fomichev@wdc.com, Kevin Wolf , damien.lemoal@opensource.wdc.com, Eric Blake , Fam Zheng , Markus Armbruster , Hanna Reitz , Sam Li Subject: [PATCH v6 1/8] include: add zoned device structs Date: Fri, 5 Aug 2022 15:57:44 +0800 Message-Id: <20220805075751.77499-2-faithilikerun@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220805075751.77499-1-faithilikerun@gmail.com> References: <20220805075751.77499-1-faithilikerun@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::52b; envelope-from=faithilikerun@gmail.com; helo=mail-pg1-x52b.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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1659686540808100001 Content-Type: text/plain; charset="utf-8" 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..36bd0e480e 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; =20 +typedef enum BlockZoneOp { + BLK_ZO_OPEN, + BLK_ZO_CLOSE, + BLK_ZO_FINISH, + BLK_ZO_RESET, +} BlockZoneOp; + +typedef enum BlockZoneModel { + BLK_Z_NONE =3D 0x0, /* Regular block device */ + BLK_Z_HM =3D 0x1, /* Host-managed zoned block device */ + BLK_Z_HA =3D 0x2, /* Host-aware zoned block device */ +} BlockZoneModel; + +typedef enum BlockZoneCondition { + BLK_ZS_NOT_WP =3D 0x0, + BLK_ZS_EMPTY =3D 0x1, + BLK_ZS_IOPEN =3D 0x2, + BLK_ZS_EOPEN =3D 0x3, + BLK_ZS_CLOSED =3D 0x4, + BLK_ZS_RDONLY =3D 0xD, + BLK_ZS_FULL =3D 0xE, + BLK_ZS_OFFLINE =3D 0xF, +} BlockZoneCondition; + +typedef enum BlockZoneType { + BLK_ZT_CONV =3D 0x1, /* Conventional random writes supported */ + BLK_ZT_SWR =3D 0x2, /* Sequential writes required */ + BLK_ZT_SWP =3D 0x3, /* Sequential writes preferred */ +} BlockZoneType; + +/* + * Zone descriptor data structure. + * Provides information on a zone with all position and size values in byt= es. + */ +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; --=20 2.37.1 From nobody Thu Apr 25 18:48:42 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1659686525; cv=none; d=zohomail.com; s=zohoarc; b=eNKwwI532th1v5bInkUiGuN70MDiusNJZv8CnmPc93RhI7T3rSUz9wGiUD2ieW7vDfQcXlqiVAnbfjT0GMQVEW8T5ATHFucFnahEaIoTouwnYqi9im107lwJMmql+g85baZ25Ar3TPil9kMByKqOvq84Misvv23SQULNpF8GtwE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659686525; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=CmKuBcw8ARJwBYjuXzUoGFsoFdqkxX9OVMWD9ZCDqJ0=; b=it3Bm9wyYRUPsDTra115LOJaSK1TzFVAix669uhW4oGtyIdGTkrHMK8m6bXlSdFwiGqgu8HBk8Tyr8oqW48rYrsEuMGX1gyPgT9KktBcjBBLDEiqKoaXAyDTro54HTgafvxEojNVqsBfKaBSXtklPhiuErvmxKU+DwJyjzlD7M4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 165968652504748.80436422286289; Fri, 5 Aug 2022 01:02:05 -0700 (PDT) Received: from localhost ([::1]:50820 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJsHT-0005CB-8M for importer@patchew.org; Fri, 05 Aug 2022 04:02:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60412) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJsDl-0002rE-QS; Fri, 05 Aug 2022 03:58:13 -0400 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]:38790) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oJsDk-0001vY-7B; Fri, 05 Aug 2022 03:58:13 -0400 Received: by mail-pj1-x1030.google.com with SMTP id q9-20020a17090a2dc900b001f58bcaca95so756506pjm.3; Fri, 05 Aug 2022 00:58:11 -0700 (PDT) Received: from roots.. ([106.84.130.246]) by smtp.gmail.com with ESMTPSA id z15-20020a170903018f00b0016ee708350bsm2418564plg.14.2022.08.05.00.58.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Aug 2022 00:58:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=CmKuBcw8ARJwBYjuXzUoGFsoFdqkxX9OVMWD9ZCDqJ0=; b=BSL5nBvxLHHdphXbYJOYMDuaMHZPJgeFTjbGx/Q9CnI2Sk8Q0dz9CIGp5ixdEliEwQ YPsatZbdc9QCan7I2XZmZ4xOFI7SgmflEYjyQLg1KTrdnlRUIRt+VuFLVjjwANLi5O9y Zm0nqSfTdaH9fovdVvd+fSmOvNYT6XisF5+UNRMXzES65f7GDWdoJutnIVPqTUuFg78Q Ooj9yWHC+ld60ID8gQFkJtBUBP3dzbRT1rGFDqI1jz24wcJRNt76qQh821uVlWM6m0HK wImLY6yNSaSsczC1cm+VidNC/NblwUdjKd1P4Q/vpVpOCFSRVptwizway/cZnokYl1Jp CYGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=CmKuBcw8ARJwBYjuXzUoGFsoFdqkxX9OVMWD9ZCDqJ0=; b=Fqj5ayOwQ1b/X5U5nz6TXNdM03QtGRxNXHbL48ik9HXOhZgkYkU/rBCdezuQkKldgK Sg9+9hDEoEeF7+C0WmXU6A8iHEpwvuHHK4j196cBFf8t+Doz69CQhS1vFkDQRndZ2siR t14iPXDKAZOpVFaC3ZQ/xpvIOXR/YfvU/vf+j/ZTIRwJd7yj/OLnYfYWx5SXaNE7Egsm PpwcGMhJYAKCL5UpDWf3CwfZT1xEpk/PMRCCx12vivIy9mjuwMPAtw+Yi8hrJCLyY83+ KjLAWYmV7hbzr4dCjg5v7DfVy0dbWCW7RliSnFHbkEesW9U1SI4kiRqT6AFZYlRMJ5sP sd3Q== X-Gm-Message-State: ACgBeo3OswpHB5G9DeurFsmClnINl2W72x1yW2BtleJGNtbJ9wamr9s8 PNtD3Y1f7QJQnLOUN0QljIex12hNCIiAOg== X-Google-Smtp-Source: AA6agR6Yv5ywlZL2tbhvAEK9FSkbuV3ADYvz1pBrFxHDGsscF0B1lNbHX+1S9VBEj7M3lJuZ+9b7Zw== X-Received: by 2002:a17:902:e848:b0:16f:8f:9027 with SMTP id t8-20020a170902e84800b0016f008f9027mr5756015plg.66.1659686290363; Fri, 05 Aug 2022 00:58:10 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, hare@suse.de, Stefan Hajnoczi , dmitry.fomichev@wdc.com, Kevin Wolf , damien.lemoal@opensource.wdc.com, Eric Blake , Fam Zheng , Markus Armbruster , Hanna Reitz , Sam Li Subject: [PATCH v6 2/8] file-posix: introduce get_sysfs_long_val for the long sysfs attribute Date: Fri, 5 Aug 2022 15:57:45 +0800 Message-Id: <20220805075751.77499-3-faithilikerun@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220805075751.77499-1-faithilikerun@gmail.com> References: <20220805075751.77499-1-faithilikerun@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1030; envelope-from=faithilikerun@gmail.com; helo=mail-pj1-x1030.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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1659686527005100001 Content-Type: text/plain; charset="utf-8" Use sysfs attribute files to get the long value of zoned device information. Signed-off-by: Sam Li Reviewed-by: Hannes Reinecke Reviewed-by: Stefan Hajnoczi --- block/file-posix.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 48cd096624..a40eab64a2 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1210,29 +1210,27 @@ static int hdev_get_max_hw_transfer(int fd, struct = stat *st) #endif } =20 -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 =3D NULL; int ret; int sysfd =3D -1; - long max_segments; - - if (S_ISCHR(st->st_mode)) { - if (ioctl(fd, SG_GET_SG_TABLESIZE, &ret) =3D=3D 0) { - return ret; - } - return -ENOTSUP; - } + long val; =20 if (!S_ISBLK(st->st_mode)) { return -ENOTSUP; } =20 - sysfspath =3D g_strdup_printf("/sys/dev/block/%u:%u/queue/max_segments= ", - major(st->st_rdev), minor(st->st_rdev)); + sysfspath =3D g_strdup_printf("/sys/dev/block/%u:%u/queue/%s", + major(st->st_rdev), minor(st->st_rdev), + attribute); sysfd =3D open(sysfspath, O_RDONLY); if (sysfd =3D=3D -1) { ret =3D -errno; @@ -1250,9 +1248,9 @@ static int hdev_get_max_segments(int fd, struct stat = *st) } buf[ret] =3D 0; /* The file is ended with '\n', pass 'end' to accept that. */ - ret =3D qemu_strtol(buf, &end, 10, &max_segments); + ret =3D qemu_strtol(buf, &end, 10, &val); if (ret =3D=3D 0 && end && *end =3D=3D '\n') { - ret =3D max_segments; + ret =3D val; } =20 out: @@ -1266,6 +1264,17 @@ out: #endif } =20 +static int hdev_get_max_segments(int fd, struct stat *st) { + int ret; + if (S_ISCHR(st->st_mode)) { + if (ioctl(fd, SG_GET_SG_TABLESIZE, &ret) =3D=3D 0) { + return ret; + } + return -ENOTSUP; + } + return get_sysfs_long_val(fd, st, "max_segments"); +} + static void raw_refresh_limits(BlockDriverState *bs, Error **errp) { BDRVRawState *s =3D bs->opaque; --=20 2.37.1 From nobody Thu Apr 25 18:48:42 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1659686595; cv=none; d=zohomail.com; s=zohoarc; b=WK256CGJv7a5oAS3Rl7t3Nn8iror8HVx/UsAmcwzTMSM/+rj+QlpHD2HWp+WFzL+HgL9garB4n5UBXSAewdHJ2O6u+iumUq0xB8KlesGVu4jlB07hKPjl8sa8Vkz+wwzBvk853jHzeaMlV3PSZL6utxpmHw06cU3L/9F67ZyGy0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659686595; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=bDPuAiP4ePtzz22qpEVMqEcyzCUbID81bXO+GFqczYY=; b=MhnQ4fmvfoiziVE4LL6IiYXbqwDAC0cDLNgk4UUKGiTITsKRJjUtKWGaqkKb2zsg5GkxU0f2DUJcP7wrRg56GmQKC+vNN08jp+/jkypdkqxWFY++FCC17Rh54Jtfr2KfYBnj7GTx12fkGiJHhnvTjhoddXQE3yQ94YhGfkWVDXk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1659686595099625.4096952800356; Fri, 5 Aug 2022 01:03:15 -0700 (PDT) Received: from localhost ([::1]:52378 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJsIc-0006PA-13 for importer@patchew.org; Fri, 05 Aug 2022 04:03:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60442) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJsDs-0002xH-Ih; Fri, 05 Aug 2022 03:58:21 -0400 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]:33558) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oJsDq-0001vv-T8; Fri, 05 Aug 2022 03:58:20 -0400 Received: by mail-pj1-x1031.google.com with SMTP id f11-20020a17090a4a8b00b001f2f7e32d03so7332143pjh.0; Fri, 05 Aug 2022 00:58:16 -0700 (PDT) Received: from roots.. ([106.84.130.246]) by smtp.gmail.com with ESMTPSA id z15-20020a170903018f00b0016ee708350bsm2418564plg.14.2022.08.05.00.58.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Aug 2022 00:58:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=bDPuAiP4ePtzz22qpEVMqEcyzCUbID81bXO+GFqczYY=; b=h02+qrcRoxXZgOwTormWYVqwmKyqquWg9hzyvMjkPLWXbhbtPoowSSDrgtPJmGye/+ kywORMHHPVL1n9rxq8NSup+bgGTqh7/DBgWrVL7vJhasxVGVV9SIy8hweD0xVnneH4ym pSuW6xUHmfRlNCH7i6O74DS1qyhV0PInX31sigStmOpX1+dmM4qzTh4PElcV3TYwIJGq YcNbTxwqZzOWRWzh4shq643eB4tFK4g6wF1TQH3SeSgYRKTgbHstFEXuTqBeI8UNpOaH 2dZ+0d0HsegeRmZJla5i1phiUkJkMlud8v7IbNu9WC08L529o1e2Hoe+ComHqWK2fCpa UZ/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=bDPuAiP4ePtzz22qpEVMqEcyzCUbID81bXO+GFqczYY=; b=PbonOOq0q8lriUJazLHw8I52UEqaHfSOJGmQJYkx87Nq+vldmGw7AItuKddSVWplZD cKvEr41opENpsWlESmbHV7otIGBlfEs0H07RYCKmfNo9FN8DhFMw8CvvXeLi0RuaHQwh Y8VURflo8LXHAW+bSFBNtyCioESDLGmtG4yuyhgCn7BV46IioDnJsF8tgTEKCrFbp2xk WuGFph7KvUgS077yFHA3YglbD5lL+ZXZjUzee/CnZ1ltDmbftHtzP7eY7Aogkzh19URk 6C+idvawiZ1fQBK0hrpxXWrhXzy8X0iThS7f4q4q+5guOhhyDA+gnSqOjLy9Awr4U+N8 //AQ== X-Gm-Message-State: ACgBeo0r0+snH0JWtb+pf0i47ZxcjaeiMitghaFZWm6+PMUqvcBnIS4q LyRXOw6Eu6/x5OGIQoylzH+/1YE0r/Vmzw== X-Google-Smtp-Source: AA6agR7qR2fa3U3vSWsqPwKBKSScGRKnBpIuh6Rlr9FuRwx1HAaYPeKAOWwCVtdTYFEM5PGQHuUOjw== X-Received: by 2002:a17:90b:1e11:b0:1f4:ee94:6236 with SMTP id pg17-20020a17090b1e1100b001f4ee946236mr6458422pjb.63.1659686295654; Fri, 05 Aug 2022 00:58:15 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, hare@suse.de, Stefan Hajnoczi , dmitry.fomichev@wdc.com, Kevin Wolf , damien.lemoal@opensource.wdc.com, Eric Blake , Fam Zheng , Markus Armbruster , Hanna Reitz , Sam Li Subject: [PATCH v6 3/8] file-posix: introduce get_sysfs_str_val for device zoned model Date: Fri, 5 Aug 2022 15:57:46 +0800 Message-Id: <20220805075751.77499-4-faithilikerun@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220805075751.77499-1-faithilikerun@gmail.com> References: <20220805075751.77499-1-faithilikerun@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1031; envelope-from=faithilikerun@gmail.com; helo=mail-pj1-x1031.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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1659686597175100001 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Hannes Reinecke --- block/file-posix.c | 70 ++++++++++++++++++++++++++++++++ include/block/block_int-common.h | 3 ++ 2 files changed, 73 insertions(+) diff --git a/block/file-posix.c b/block/file-posix.c index a40eab64a2..4785203eea 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1264,6 +1264,68 @@ out: #endif } =20 +/* + * 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 =3D NULL; + g_autofree char *sysfspath =3D NULL; + int ret; + size_t len; + + if (!S_ISBLK(st->st_mode)) { + return -ENOTSUP; + } + + sysfspath =3D g_strdup_printf("/sys/dev/block/%u:%u/queue/%s", + major(st->st_rdev), minor(st->st_rdev), + attribute); + ret =3D g_file_get_contents(sysfspath, &buf, &len, NULL); + if (ret =3D=3D -1) { + ret =3D -errno; + return ret; + } + + /* The file is ended with '\n' */ + if (buf[len - 1] =3D=3D '\n') { + buf[len - 1] =3D '\0'; + } + + if (!strncpy(*val, buf, len)) { + ret =3D -errno; + return ret; + } + g_free(buf); + return 0; +#else + return -ENOTSUP; +#endif +} + +static int get_sysfs_zoned_model(int fd, struct stat *st, + BlockZoneModel *zoned) { + g_autofree char *val =3D NULL; + val =3D g_malloc(32); + get_sysfs_str_val(fd, st, "zoned", &val); + if (!val) { + return -ENOTSUP; + } + + if (strcmp(val, "host-managed") =3D=3D 0) { + *zoned =3D BLK_Z_HM; + } else if (strcmp(val, "host-aware") =3D=3D 0) { + *zoned =3D BLK_Z_HA; + } else if (strcmp(val, "none") =3D=3D 0) { + *zoned =3D BLK_Z_NONE; + } else { + return -ENOTSUP; + } + return 0; +} + static int hdev_get_max_segments(int fd, struct stat *st) { int ret; if (S_ISCHR(st->st_mode)) { @@ -1279,6 +1341,8 @@ static void raw_refresh_limits(BlockDriverState *bs, = Error **errp) { BDRVRawState *s =3D bs->opaque; struct stat st; + int ret; + BlockZoneModel zoned; =20 s->needs_alignment =3D raw_needs_alignment(bs); raw_probe_alignment(bs, s->fd, errp); @@ -1316,6 +1380,12 @@ static void raw_refresh_limits(BlockDriverState *bs,= Error **errp) bs->bl.max_hw_iov =3D ret; } } + + ret =3D get_sysfs_zoned_model(s->fd, &st, &zoned); + if (ret < 0) { + zoned =3D BLK_Z_NONE; + } + bs->bl.zoned =3D zoned; } =20 static int check_for_dasd(int fd) diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.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 { =20 /* maximum number of iovec elements */ int max_iov; + + /* device zone model */ + BlockZoneModel zoned; } BlockLimits; =20 typedef struct BdrvOpBlocker BdrvOpBlocker; --=20 2.37.1 From nobody Thu Apr 25 18:48:42 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1659687067; cv=none; d=zohomail.com; s=zohoarc; b=bh3X9L1Pq4gA0moXFlE1840T/DUxRH6xbllgGkW8fgfqxC6IF1bq5NNhLINYBjuSvchaN5jvRqUsgUNM5Q6+6PuD/MI4+MbyMcrfRVr436KZSmZzxnvPHKtlZEvoVPJqcjCHkSKjYBD7+Uwm7A7tB5nyPp/e7nHCcj9sFrZs6yg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659687067; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=MGXk85DZqoZqhRKVF8kEswqZ1+VuXM8ng3MQZ5+NxMo=; b=JFuvddgqdx9n97zLGvOL77ZnBcmhGZx1UTYT/GWARMJ8LnI2sVJIayExafw9Bnkic/EWbJEvI3TT97AUvfpnvXxf+R3sjTnX+CDgDojUkSjL9ApYASsErCjdGeXYQ9+r9DaH7vSWQVG5uJ8g7Dfn1ZyNP8xllzjIGox4fG5Fcwo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1659687067818598.4150988069249; Fri, 5 Aug 2022 01:11:07 -0700 (PDT) Received: from localhost ([::1]:59274 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJsQE-0003FR-O6 for importer@patchew.org; Fri, 05 Aug 2022 04:11:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60476) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJsDz-0003AZ-55; Fri, 05 Aug 2022 03:58:27 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]:46744) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oJsDw-0001wR-1a; Fri, 05 Aug 2022 03:58:26 -0400 Received: by mail-pf1-x430.google.com with SMTP id 130so1568126pfv.13; Fri, 05 Aug 2022 00:58:22 -0700 (PDT) Received: from roots.. ([106.84.130.246]) by smtp.gmail.com with ESMTPSA id z15-20020a170903018f00b0016ee708350bsm2418564plg.14.2022.08.05.00.58.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Aug 2022 00:58:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=MGXk85DZqoZqhRKVF8kEswqZ1+VuXM8ng3MQZ5+NxMo=; b=UTKdsI6Yl7ngaG5wpRAdhT16bIWobqkN8YmxoEJ/a+4UxkPIWwmS+vKSzh8BF9cZnq +2F13H3iLFqtvMn7k+RSI6u2UifmL6TCsfUwRWiEQN5JqzGTI9HvKFvBEDWWz2cnp/Uz OdHCGLKmUXJOeQxhhv7a21wt9vRGNpmj+iYAsk7D8b2NJGHZjF1B9XAUjeVpKl5/zs5y OVH0v2oIJJ90q31X51ulnIF8tNSS/dJF37C8gotfaveINUhqbhmMgWV7cEDAnZnsKgMR CGR7LOKuoN5EfCyB9u+451b6rot0o174nNmTXmbAqLxf5Sj+dEAZ31V/UdgllFvdLUQf ZPTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=MGXk85DZqoZqhRKVF8kEswqZ1+VuXM8ng3MQZ5+NxMo=; b=FGxNV+O0pAKy1bgqZRzvi9HZO8EoX/YB38CvbqXGGY4H3ehb48ldoj+MdU8BiRoQE0 8y61/uI32nS7p2L7iP46u6GpK+xDqm4N/0lltxy1ylfUdmpyvyBD4oElyY50aHmtlymR nSO+PWu8bIbwjBt+gKrgnz0euZrFpONS8EVCamyHWSZIFsTaqrvateubm6OChsRh5uw0 ka5HT4CLaaevNUS2P0qrGQ0icUdCXenfbdsUu0v3Wh5wktArxlH3yTbNVkDu6sZnfhsq HwqlfZniTA4SPtrujVt4mAQWBcx6g5Oh0f49WWYDedcw5pu3xo2Qs5j9QLChJjF1DNoc 8GPw== X-Gm-Message-State: ACgBeo0FsDh6TfSj7hNG1KrxdzpPA+jj0/zI0UnEmu/2+6qneFP61qFt 8rTA1otDIQqzdlUQ7JYFg035I4n+yd+ncw== X-Google-Smtp-Source: AA6agR4wTgJuKuA8aYxqa/kKBw+Ln1m49JKFrOBxhWlECk4PxDpS72jOD2rhnt1FQt+bwirv8AxIQw== X-Received: by 2002:a05:6a00:ac1:b0:52b:5db8:f362 with SMTP id c1-20020a056a000ac100b0052b5db8f362mr5665772pfl.80.1659686301378; Fri, 05 Aug 2022 00:58:21 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, hare@suse.de, Stefan Hajnoczi , dmitry.fomichev@wdc.com, Kevin Wolf , damien.lemoal@opensource.wdc.com, Eric Blake , Fam Zheng , Markus Armbruster , Hanna Reitz , Sam Li Subject: [PATCH v6 4/8] block: add block layer APIs resembling Linux ZonedBlockDevice ioctls Date: Fri, 5 Aug 2022 15:57:47 +0800 Message-Id: <20220805075751.77499-5-faithilikerun@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220805075751.77499-1-faithilikerun@gmail.com> References: <20220805075751.77499-1-faithilikerun@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::430; envelope-from=faithilikerun@gmail.com; helo=mail-pf1-x430.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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1659687068633100001 Content-Type: text/plain; charset="utf-8" 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). 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=3Dzoned_host_device, filename=3D/dev/= nullb0 -c "zrp offset nr_zones" Signed-off-by: Sam Li Reviewed-by: Hannes Reinecke --- block/block-backend.c | 50 +++++ block/coroutines.h | 6 + block/file-posix.c | 315 ++++++++++++++++++++++++++++++- block/io.c | 41 ++++ 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 | 8 +- qemu-io-cmds.c | 144 ++++++++++++++ 11 files changed, 601 insertions(+), 6 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index d4a5df2ac2..fc639b0cd7 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1775,6 +1775,56 @@ int coroutine_fn blk_co_flush(BlockBackend *blk) return ret; } =20 +/* + * 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)) { + blk_dec_in_flight(blk); + return -ENOMEDIUM; + } + ret =3D 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 =3D 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)) { + blk_dec_in_flight(blk); + return -ENOMEDIUM; + } + ret =3D bdrv_co_zone_mgmt(blk_bs(blk), op, offset, len); + blk_dec_in_flight(blk); + return ret; +} + void blk_drain(BlockBackend *blk) { BlockDriverState *bs =3D 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, boo= l blocking, Error **errp); =20 =20 +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 4785203eea..2627431581 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; =20 @@ -1369,7 +1379,7 @@ static void raw_refresh_limits(BlockDriverState *bs, = Error **errp) #endif =20 if (bs->sg || S_ISBLK(st.st_mode)) { - int ret =3D hdev_get_max_hw_transfer(s->fd, &st); + ret =3D hdev_get_max_hw_transfer(s->fd, &st); =20 if (ret > 0 && ret <=3D BDRV_REQUEST_MAX_BYTES) { bs->bl.max_hw_transfer =3D ret; @@ -1386,6 +1396,27 @@ static void raw_refresh_limits(BlockDriverState *bs,= Error **errp) zoned =3D BLK_Z_NONE; } bs->bl.zoned =3D zoned; + if (zoned !=3D BLK_Z_NONE) { + ret =3D get_sysfs_long_val(s->fd, &st, "chunk_sectors"); + if (ret > 0) { + bs->bl.zone_sectors =3D ret; + } + + ret =3D get_sysfs_long_val(s->fd, &st, "zone_append_max_bytes"); + if (ret > 0) { + bs->bl.zone_append_max_bytes =3D ret; + } + + ret =3D get_sysfs_long_val(s->fd, &st, "max_open_zones"); + if (ret > 0) { + bs->bl.max_open_zones =3D ret; + } + + ret =3D get_sysfs_long_val(s->fd, &st, "max_active_zones"); + if (ret > 0) { + bs->bl.max_active_zones =3D ret; + } + } } =20 static int check_for_dasd(int fd) @@ -1880,6 +1911,167 @@ static off_t copy_file_range(int in_fd, off_t *in_o= ff, int out_fd, } #endif =20 +/* + * parse_zone - Fill a zone descriptor + */ +#if defined(CONFIG_BLKZONED) +static inline void parse_zone(struct BlockZoneDescriptor *zone, + struct blk_zone *blkz) { + zone->start =3D blkz->start; + zone->length =3D blkz->len; + zone->cap =3D blkz->capacity; + zone->wp =3D blkz->wp; + zone->type =3D blkz->type; + + switch (blkz->cond) { + case BLK_ZONE_COND_NOT_WP: + blkz->cond =3D BLK_ZS_NOT_WP; + break; + case BLK_ZONE_COND_EMPTY: + blkz->cond =3D BLK_ZS_EMPTY; + break; + case BLK_ZONE_COND_IMP_OPEN: + blkz->cond =3DBLK_ZS_IOPEN; + break; + case BLK_ZONE_COND_EXP_OPEN: + blkz->cond =3D BLK_ZS_EOPEN; + break; + case BLK_ZONE_COND_CLOSED: + blkz->cond =3D BLK_ZS_CLOSED; + break; + case BLK_ZONE_COND_READONLY: + blkz->cond =3D BLK_ZS_RDONLY; + break; + case BLK_ZONE_COND_FULL: + blkz->cond =3D BLK_ZS_FULL; + break; + case BLK_ZONE_COND_OFFLINE: + blkz->cond =3D BLK_ZS_OFFLINE; + break; + default: + error_report("Invalid zone condition 0x%x", blkz->cond); + } +} +#endif + +static int handle_aiocb_zone_report(void *opaque) { +#if defined(CONFIG_BLKZONED) + RawPosixAIOData *aiocb =3D opaque; + int fd =3D aiocb->aio_fildes; + unsigned int *nr_zones =3D aiocb->zone_report.nr_zones; + BlockZoneDescriptor *zones =3D aiocb->zone_report.zones; + int64_t sector =3D aiocb->aio_offset / 512; /* ZBDs use 512B sectors */ + + struct blk_zone *blkz; + int64_t rep_size; + unsigned int nrz; + int ret, n =3D 0, i =3D 0; + + nrz =3D *nr_zones; + rep_size =3D sizeof(struct blk_zone_report) + nrz * sizeof(struct blk_= zone); + g_autofree struct blk_zone_report *rep =3D NULL; + rep =3D g_malloc(rep_size); + + blkz =3D (struct blk_zone *)(rep + 1); + while (n < nrz) { + memset(rep, 0, rep_size); + rep->sector =3D sector; + rep->nr_zones =3D nrz - n; + + ret =3D ioctl(fd, BLKREPORTZONE, rep); + if (ret !=3D 0) { + error_report("%d: ioctl BLKREPORTZONE at %" PRId64 " failed %d= ", + fd, sector, errno); + return -errno; + } + + if (!rep->nr_zones) { + break; + } + + for (i =3D 0; i < rep->nr_zones; i++, n++) { + parse_zone(&zones[n], &blkz[i]); + /* The next report should start after the last zone reported */ + sector =3D blkz[i].start + blkz[i].len; + } + } + + *nr_zones =3D n; + return 0; +#else + return -ENOTSUP; +#endif +} + +static int handle_aiocb_zone_mgmt(void *opaque) { +#if defined(CONFIG_BLKZONED) + RawPosixAIOData *aiocb =3D opaque; + BlockDriverState *bs =3D aiocb->bs; + int fd =3D aiocb->aio_fildes; + int64_t sector =3D aiocb->aio_offset; + int64_t nr_sectors =3D aiocb->aio_nbytes; + BlockZoneOp op =3D 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 =3D bs->bl.zone_sectors; + zone_sector_mask =3D 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 =3D "BLKOPENZONE"; + ioctl_op =3D BLKOPENZONE; + break; + case BLK_ZO_CLOSE: + ioctl_name =3D "BLKCLOSEZONE"; + ioctl_op =3D BLKCLOSEZONE; + break; + case BLK_ZO_FINISH: + ioctl_name =3D "BLKFINISHZONE"; + ioctl_op =3D BLKFINISHZONE; + break; + case BLK_ZO_RESET: + ioctl_name =3D "BLKRESETZONE"; + ioctl_op =3D BLKRESETZONE; + break; + default: + error_report("Invalid zone operation 0x%x", op); + return -EINVAL; + } + + /* Execute the operation */ + range.sector =3D sector; + range.nr_sectors =3D nr_sectors; + do { + ret =3D ioctl(fd, ioctl_op, &range); + } while (ret !=3D 0 && errno =3D=3D EINTR); + + if (ret !=3D 0) { + error_report("ioctl %s failed %d", + ioctl_name, errno); + return -errno; + } + + return 0; +#else + return -ENOTSUP; +#endif +} + static int handle_aiocb_copy_range(void *opaque) { RawPosixAIOData *aiocb =3D opaque; @@ -3052,6 +3244,67 @@ static void raw_account_discard(BDRVRawState *s, uin= t64_t nbytes, int ret) } } =20 +/* + * 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 + */ +static int coroutine_fn raw_co_zone_report(BlockDriverState *bs, int64_t o= ffset, + unsigned int *nr_zones, + BlockZoneDescriptor *zones) { +#if defined(CONFIG_BLKZONED) + BDRVRawState *s =3D bs->opaque; + RawPosixAIOData acb; + + acb =3D (RawPosixAIOData) { + .bs =3D bs, + .aio_fildes =3D s->fd, + .aio_type =3D QEMU_AIO_ZONE_REPORT, + .aio_offset =3D offset, + .zone_report =3D { + .nr_zones =3D nr_zones, + .zones =3D zones, + }, + }; + + return raw_thread_pool_submit(bs, handle_aiocb_zone_report, &acb); +#else + return -ENOTSUP; +#endif +} + +/* + * 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) { +#if defined(CONFIG_BLKZONED) + BDRVRawState *s =3D bs->opaque; + RawPosixAIOData acb; + + acb =3D (RawPosixAIOData) { + .bs =3D bs, + .aio_fildes =3D s->fd, + .aio_type =3D QEMU_AIO_ZONE_MGMT, + .aio_offset =3D offset, + .aio_nbytes =3D len, + .zone_mgmt =3D { + .op =3D op, + }, + }; + + return raw_thread_pool_submit(bs, handle_aiocb_zone_mgmt, &acb); +#else + return -ENOTSUP; +#endif +} + static coroutine_fn int raw_do_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes, bool blkdev) @@ -3552,6 +3805,14 @@ static void hdev_parse_filename(const char *filename= , QDict *options, bdrv_parse_filename_strip_prefix(filename, "host_device:", options); } =20 +#if defined(CONFIG_BLKZONED) +static void zoned_host_device_parse_filename(const char *filename, QDict *= options, + Error **errp) +{ + bdrv_parse_filename_strip_prefix(filename, "zoned_host_device:", optio= ns); +} +#endif + static bool hdev_is_sg(BlockDriverState *bs) { =20 @@ -3782,6 +4043,55 @@ static BlockDriver bdrv_host_device =3D { #endif }; =20 +#if defined(CONFIG_BLKZONED) +static BlockDriver bdrv_zoned_host_device =3D { + .format_name =3D "zoned_host_device", + .protocol_name =3D "zoned_host_device", + .instance_size =3D sizeof(BDRVRawState), + .bdrv_needs_filename =3D true, + .bdrv_probe_device =3D hdev_probe_device, + .bdrv_parse_filename =3D zoned_host_device_parse_filename, + .bdrv_file_open =3D hdev_open, + .bdrv_close =3D raw_close, + .bdrv_reopen_prepare =3D raw_reopen_prepare, + .bdrv_reopen_commit =3D raw_reopen_commit, + .bdrv_reopen_abort =3D raw_reopen_abort, + .bdrv_co_create_opts =3D bdrv_co_create_opts_simple, + .create_opts =3D &bdrv_create_opts_simple, + .mutable_opts =3D mutable_opts, + .bdrv_co_invalidate_cache =3D raw_co_invalidate_cache, + .bdrv_co_pwrite_zeroes =3D hdev_co_pwrite_zeroes, + + .bdrv_co_preadv =3D raw_co_preadv, + .bdrv_co_pwritev =3D raw_co_pwritev, + .bdrv_co_flush_to_disk =3D raw_co_flush_to_disk, + .bdrv_co_pdiscard =3D hdev_co_pdiscard, + .bdrv_co_copy_range_from =3D raw_co_copy_range_from, + .bdrv_co_copy_range_to =3D raw_co_copy_range_to, + .bdrv_refresh_limits =3D raw_refresh_limits, + .bdrv_io_plug =3D raw_aio_plug, + .bdrv_io_unplug =3D raw_aio_unplug, + .bdrv_attach_aio_context =3D raw_aio_attach_aio_context, + + .bdrv_co_truncate =3D raw_co_truncate, + .bdrv_getlength =3D raw_getlength, + .bdrv_get_info =3D raw_get_info, + .bdrv_get_allocated_file_size + =3D raw_get_allocated_file_size, + .bdrv_get_specific_stats =3D hdev_get_specific_stats, + .bdrv_check_perm =3D raw_check_perm, + .bdrv_set_perm =3D raw_set_perm, + .bdrv_abort_perm_update =3D raw_abort_perm_update, + .bdrv_probe_blocksizes =3D hdev_probe_blocksizes, + .bdrv_probe_geometry =3D hdev_probe_geometry, + .bdrv_co_ioctl =3D hdev_co_ioctl, + + /* zone management operations */ + .bdrv_co_zone_report =3D raw_co_zone_report, + .bdrv_co_zone_mgmt =3D 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) @@ -4042,6 +4352,9 @@ static void bdrv_file_init(void) bdrv_register(&bdrv_file); #if defined(HAVE_HOST_BLOCK_DEVICE) bdrv_register(&bdrv_host_device); +#if defined(CONFIG_BLKZONED) + bdrv_register(&bdrv_zoned_host_device); +#endif #ifdef __linux__ bdrv_register(&bdrv_host_cdrom); #endif diff --git a/block/io.c b/block/io.c index 0a8cbefe86..de9ec1d740 100644 --- a/block/io.c +++ b/block/io.c @@ -3198,6 +3198,47 @@ out: return co.ret; } =20 +int bdrv_co_zone_report(BlockDriverState *bs, int64_t offset, + unsigned int *nr_zones, + BlockZoneDescriptor *zones) +{ + BlockDriver *drv =3D bs->drv; + CoroutineIOCompletion co =3D { + .coroutine =3D qemu_coroutine_self(), + }; + IO_CODE(); + + bdrv_inc_in_flight(bs); + if (!drv || !drv->bdrv_co_zone_report) { + co.ret =3D -ENOTSUP; + goto out; + } + co.ret =3D drv->bdrv_co_zone_report(bs, offset, nr_zones, zones); +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 =3D bs->drv; + CoroutineIOCompletion co =3D { + .coroutine =3D qemu_coroutine_self(), + }; + IO_CODE(); + + bdrv_inc_in_flight(bs); + if (!drv || !drv->bdrv_co_zone_mgmt) { + co.ret =3D -ENOTSUP; + goto out; + } + co.ret =3D drv->bdrv_co_zone_mgmt(bs, op, offset, len); +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 36bd0e480e..5102fa6858 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 *b= uf); /* Ensure contents are flushed to disk. */ int coroutine_fn bdrv_co_flush(BlockDriverState *bs); =20 +/* 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); =20 +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 l= en); + /** * bdrv_parent_drained_begin_single: * diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.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; =20 - struct BlockDriver { /* * These fields are initialized when this object is created, @@ -691,6 +690,12 @@ struct BlockDriver { QEMUIOVector *qiov, int64_t pos); =20 + 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, BlockZoneO= p 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 { =20 /* 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; =20 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) =20 /* 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..c6bbb7a037 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2942,6 +2942,7 @@ # @compress: Since 5.0 # @copy-before-write: Since 6.2 # @snapshot-access: Since 7.0 +# @zoned_host_device: Since 7.2 # # Since: 2.9 ## @@ -2955,7 +2956,8 @@ 'luks', 'nbd', 'nfs', 'null-aio', 'null-co', 'nvme', 'parallel= s', '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' } ] } =20 ## # @BlockdevOptionsFile: @@ -4329,7 +4331,9 @@ 'vhdx': 'BlockdevOptionsGenericFormat', 'vmdk': 'BlockdevOptionsGenericCOWFormat', 'vpc': 'BlockdevOptionsGenericFormat', - 'vvfat': 'BlockdevOptionsVVFAT' + 'vvfat': 'BlockdevOptionsVVFAT', + 'zoned_host_device': { 'type': 'BlockdevOptionsFile', + 'if': 'CONFIG_BLKZONED' } } } =20 ## 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 =3D { .oneline =3D "flush all in-core file state to disk", }; =20 +static int zone_report_f(BlockBackend *blk, int argc, char **argv) +{ + int ret; + int64_t offset; + unsigned int nr_zones; + + ++optind; + offset =3D cvtnum(argv[optind]); + ++optind; + nr_zones =3D cvtnum(argv[optind]); + + g_autofree BlockZoneDescriptor *zones =3D NULL; + zones =3D g_new(BlockZoneDescriptor, nr_zones); + ret =3D blk_zone_report(blk, offset, &nr_zones, zones); + if (ret < 0) { + printf("zone report failed: %s\n", strerror(-ret)); + } else { + for (int i =3D 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 =3D { + .name =3D "zone_report", + .altname =3D "zrp", + .cfunc =3D zone_report_f, + .argmin =3D 2, + .argmax =3D 2, + .args =3D "offset number", + .oneline =3D "report zone information", +}; + +static int zone_open_f(BlockBackend *blk, int argc, char **argv) +{ + int ret; + int64_t offset, len; + ++optind; + offset =3D cvtnum(argv[optind]); + ++optind; + len =3D cvtnum(argv[optind]); + ret =3D 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 =3D { + .name =3D "zone_open", + .altname =3D "zo", + .cfunc =3D zone_open_f, + .argmin =3D 2, + .argmax =3D 2, + .args =3D "offset len", + .oneline =3D "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 =3D cvtnum(argv[optind]); + ++optind; + len =3D cvtnum(argv[optind]); + ret =3D 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 =3D { + .name =3D "zone_close", + .altname =3D "zc", + .cfunc =3D zone_close_f, + .argmin =3D 2, + .argmax =3D 2, + .args =3D "offset len", + .oneline =3D "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 =3D cvtnum(argv[optind]); + ++optind; + len =3D cvtnum(argv[optind]); + ret =3D 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 =3D { + .name =3D "zone_finish", + .altname =3D "zf", + .cfunc =3D zone_finish_f, + .argmin =3D 2, + .argmax =3D 2, + .args =3D "offset len", + .oneline =3D "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 =3D cvtnum(argv[optind]); + ++optind; + len =3D cvtnum(argv[optind]); + ret =3D 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 =3D { + .name =3D "zone_reset", + .altname =3D "zrs", + .cfunc =3D zone_reset_f, + .argmin =3D 2, + .argmax =3D 2, + .args =3D "offset len", + .oneline =3D "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 =3D { .name =3D "truncate", @@ -2504,6 +2643,11 @@ static void __attribute((constructor)) init_qemuio_c= ommands(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); --=20 2.37.1 From nobody Thu Apr 25 18:48:42 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1659687359; cv=none; d=zohomail.com; s=zohoarc; b=Om7KqJXWt+/gsJHZt2RmRRwVuU0BbWviR3PvFRS2YNUqjbCXh4qiqy3jfk3IenH3wI1lx0J21l32URUmM9YNWazxL4yz7iIYAESIxSlko9+LJKWnRFMXDnpJnkK376+sq8CKimODN4QjR8tsd8lkuDPvCn1bhZuftV7FCKnPt38= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659687359; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WgTioHR22IT5Y1Gxy5Cwuruw+nplwJ4ECOjTCIRKC8o=; b=XpGKNDhoQja4dUmX7OoCuklUFp1tlgv5ra/5D1lnaFSrIfrPr2MmBgbuL1VCH5jLzC074J0dPiu1TuCFr629JaJUTGii2VQTVRSdAxMS25C/+hVtqPuyy1Grok5BrUvzEyjMQsT4CfuiNvBgtigU+AJrfpBp9Q5jgHMJ1Biur5g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1659687359969885.0257677186075; Fri, 5 Aug 2022 01:15:59 -0700 (PDT) Received: from localhost ([::1]:39256 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJsUw-0000hq-Mw for importer@patchew.org; Fri, 05 Aug 2022 04:15:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60514) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJsE4-0003Ja-8I; Fri, 05 Aug 2022 03:58:32 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]:39865) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oJsDz-0001y2-Vz; Fri, 05 Aug 2022 03:58:30 -0400 Received: by mail-pj1-x1032.google.com with SMTP id h21-20020a17090aa89500b001f31a61b91dso7536156pjq.4; Fri, 05 Aug 2022 00:58:27 -0700 (PDT) Received: from roots.. ([106.84.130.246]) by smtp.gmail.com with ESMTPSA id z15-20020a170903018f00b0016ee708350bsm2418564plg.14.2022.08.05.00.58.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Aug 2022 00:58:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=WgTioHR22IT5Y1Gxy5Cwuruw+nplwJ4ECOjTCIRKC8o=; b=TgompkQWNMgL2oMrfZtIdIGhhbjlZPaPlCeZHxLiiD1oTnya+nJFeN+SN1sAgErckC YU5kJr6zyl6blhzNkT+ccTy3sUsUwCYLHGYzIG4VV6pwJ1q8FzECgVXxY0oezC5DtBtI DcGd8gxja9ZLi0LBQY610weZ2HEETmHUSNTdFX/JuEtYLBefgAvCB1vGm1eVzvrZGX78 Jy3FcdqoAsvVYpsHEjsZokfI9I1EL4dlXLkOhdv9cZZ6QxyNbP1wRo383mhiwMU2019d VKrcKAxN6ILtMBR8ueuTRduiFkwLj6qOg77I7/G2m02qM7SWBwA9yYgIL8zk1ntivZS1 fCEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=WgTioHR22IT5Y1Gxy5Cwuruw+nplwJ4ECOjTCIRKC8o=; b=hEGEPDScuJY32d1wWv2B1qiOCPhD4JbSa/7yqEIHW4vVR+0OYRhRMyE51yA1CZGuSn bSjiomfriTl8fa2r3ChSr9TRa6vdpBUMeWw3AeITJow8sh3U90GyaCu4Uh3h57ZFS8Dy MtOjkeW2S+sfz4FrtR56kuVnMGrxyDYjK6VdbFoZTjemetHucjn4gqDkbjyZRoObK4ru SCYydeNbPZNFK4eqBpg45rBxKAHu8RX/yknRO7pm7krLBCK4bPIgKQtVzEIseD87oGn6 zEJmWKtyYX2Ny1n8aAyjV4pfreFHhIw93/v8G0fsWcShb2asXHQkDqo5dNPhcbY8F63J khbw== X-Gm-Message-State: ACgBeo1PzfN4qvJOb6ELxlykQJkRUTvKA3+tmJLrot7hIqlagKWebP79 mwriMBULntIVcbZfNVuFuvKJMabQASANPg== X-Google-Smtp-Source: AA6agR4g5Mjqr8dE07MiyFxjrGGOdYtym+CFPZggKIrA5KfwiHTx5OLFCDV+TQ7MnYhLzY3aES3bjA== X-Received: by 2002:a17:90b:4b8a:b0:1f5:942:dcc6 with SMTP id lr10-20020a17090b4b8a00b001f50942dcc6mr6440961pjb.78.1659686306071; Fri, 05 Aug 2022 00:58:26 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, hare@suse.de, Stefan Hajnoczi , dmitry.fomichev@wdc.com, Kevin Wolf , damien.lemoal@opensource.wdc.com, Eric Blake , Fam Zheng , Markus Armbruster , Hanna Reitz , Sam Li Subject: [PATCH v6 5/8] raw-format: add zone operations to pass through requests Date: Fri, 5 Aug 2022 15:57:48 +0800 Message-Id: <20220805075751.77499-6-faithilikerun@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220805075751.77499-1-faithilikerun@gmail.com> References: <20220805075751.77499-1-faithilikerun@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1659687361474100001 Content-Type: text/plain; charset="utf-8" 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(BlockDriverSta= te *bs, return bdrv_co_pdiscard(bs->file, offset, bytes); } =20 +static int coroutine_fn raw_co_zone_report(BlockDriverState *bs, int64_t o= ffset, + 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 =3D { .bdrv_co_pwritev =3D &raw_co_pwritev, .bdrv_co_pwrite_zeroes =3D &raw_co_pwrite_zeroes, .bdrv_co_pdiscard =3D &raw_co_pdiscard, + .bdrv_co_zone_report =3D &raw_co_zone_report, + .bdrv_co_zone_mgmt =3D &raw_co_zone_mgmt, .bdrv_co_block_status =3D &raw_co_block_status, .bdrv_co_copy_range_from =3D &raw_co_copy_range_from, .bdrv_co_copy_range_to =3D &raw_co_copy_range_to, --=20 2.37.1 From nobody Thu Apr 25 18:48:42 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1659687818; cv=none; d=zohomail.com; s=zohoarc; b=DsX+7BsGYps8IpIOl7bihyZG+pS9fdxhXOOGT345McetwYhGW6zGTNoCt0vpanvPGCiYibjgYExImyE+RWu5Jy9e5/5FiyS31DHJZouErSrpdSpn/rSCEzGM3yczd9Ys6NRw8iRfks1mVvduSJOg8PpnEH8GLMFbl6PGwolP5QI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659687818; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0bfoHoSanZtQiV7SoIqqkoxtM2o34+5XyFcXpFu8r9A=; b=gdxTTk8Q8PJr4felx0fxIrK17DKBtJr0egjig1r8MEUGA66Ae8sVA14AFhZ+4IAp9JpwVA0dOAY5nxFP07CpTFU5XqsCIqS9JJGLBtjGKYURpekIkUYTO8f8HeaBAd/yKjUCJPLsbpXA4rtxRnur9hBrIG36XK/xoaEmdZF2U/A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1659687818863432.1459700259393; Fri, 5 Aug 2022 01:23:38 -0700 (PDT) Received: from localhost ([::1]:46778 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJscL-0006Lz-R8 for importer@patchew.org; Fri, 05 Aug 2022 04:23:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60528) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJsE6-0003NV-Cv; Fri, 05 Aug 2022 03:58:34 -0400 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]:44974) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oJsE4-0001yZ-Oz; Fri, 05 Aug 2022 03:58:34 -0400 Received: by mail-pf1-x433.google.com with SMTP id h28so1581963pfq.11; Fri, 05 Aug 2022 00:58:32 -0700 (PDT) Received: from roots.. ([106.84.130.246]) by smtp.gmail.com with ESMTPSA id z15-20020a170903018f00b0016ee708350bsm2418564plg.14.2022.08.05.00.58.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Aug 2022 00:58:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=0bfoHoSanZtQiV7SoIqqkoxtM2o34+5XyFcXpFu8r9A=; b=fUQFgtGURTl0NzcoP52VBrgAdjzGTrIWl/s4qAGC3+HU4JmAZTZ0lvk7QhH3sKTK5W uBRQ61rfmX0u5qapnwM1E1a87W6iLtpHohNUdsep2CiE5Mx8qR+YRv0zuhxzOqrNAKm+ wTj4vKuVRoenYTI4eUb0COmzkWQgDHzg+iJHiXIArmkAM8KgUz5DNrNmjq19VzKyyb8B bc3veWlZLE5cmRgsDOhl6eR+XLXDbds3bKtWW0JvtL2uRtwdIr1dWAOetHNDqYVkRMZM gPE9P/l1qwIEF9QCb/7lXKI1/GhHlV9akPHHHv5kZY5ipCoQoCJ9tVvDx7pcUkxV5GGV MivA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=0bfoHoSanZtQiV7SoIqqkoxtM2o34+5XyFcXpFu8r9A=; b=7TBEJCtIB0nuVyTvQ+ekvAI/FL7atcMO8PLxD1Xd5XZRxIwpRONLNO80Rt3jOwCKyk ajbTzdIiH7bqxLbwB50sGxf840M5gVAqZKpylmZDaScm/ikP1vKpbPJ3WSakcm4q28md j6Y6aXvNJibptUBDYdjo40VDXXjsxjBZ0FuZG8jLoRwQV2uAtzxMo2beGCm7IrtwOZEp tyfP5C6q4aaOtR4yGY0LZWVJ9x/gF2pkyuM1BBcdhRfXOJk76iOALqYvZ1TS7s6lqAKT utk7G2xP2pv/rGhVT8pCiJKwQsUkc2y/yi+A+0hAwyqLTWTtedwUFKTURJNEt38+hGFr jDUw== X-Gm-Message-State: ACgBeo1D82pdF17lNl7dgY1ZHvGYahCl5reReGWEL9jxKkB5WUuCoRvH GdOi4pND2qxbigaEZWygGit8XvPzo9SUOQ== X-Google-Smtp-Source: AA6agR7XMF5JA0sSkKJEw7j2RVggNf8mylJs4pkxPCkgWSypzTjJForxO82WbpmlX6a/7To4OBmJNQ== X-Received: by 2002:a05:6a00:1641:b0:52d:3dde:73c5 with SMTP id m1-20020a056a00164100b0052d3dde73c5mr5535112pfc.24.1659686310905; Fri, 05 Aug 2022 00:58:30 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, hare@suse.de, Stefan Hajnoczi , dmitry.fomichev@wdc.com, Kevin Wolf , damien.lemoal@opensource.wdc.com, Eric Blake , Fam Zheng , Markus Armbruster , Hanna Reitz , Sam Li Subject: [PATCH v6 6/8] config: add check to block layer Date: Fri, 5 Aug 2022 15:57:49 +0800 Message-Id: <20220805075751.77499-7-faithilikerun@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220805075751.77499-1-faithilikerun@gmail.com> References: <20220805075751.77499-1-faithilikerun@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::433; envelope-from=faithilikerun@gmail.com; helo=mail-pf1-x433.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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1659687819540100001 Content-Type: text/plain; charset="utf-8" Putting zoned/non-zoned BlockDrivers on top of each other is not allowed. Signed-off-by: Sam Li Reviewed-by: Stefan Hajnoczi --- block.c | 13 +++++++++++++ block/file-posix.c | 1 + block/raw-format.c | 1 + include/block/block_int-common.h | 10 ++++++++++ 4 files changed, 25 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, Blo= ckDriverState *child_bs, return; } =20 + /* + * 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_zone= d) { + 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 2627431581..7ab39eb291 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -4048,6 +4048,7 @@ static BlockDriver bdrv_zoned_host_device =3D { .format_name =3D "zoned_host_device", .protocol_name =3D "zoned_host_device", .instance_size =3D sizeof(BDRVRawState), + .is_zoned =3D true, .bdrv_needs_filename =3D true, .bdrv_probe_device =3D hdev_probe_device, .bdrv_parse_filename =3D 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, BdrvCh= ild *c, BlockDriver bdrv_raw =3D { .format_name =3D "raw", .instance_size =3D sizeof(BDRVRawState), + .supports_zoned_children =3D true, .bdrv_probe =3D &raw_probe, .bdrv_reopen_prepare =3D &raw_reopen_prepare, .bdrv_reopen_commit =3D &raw_reopen_commit, diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.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; =20 + /* + * 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 h= ave * this field set to true, except ones that are defined only by their --=20 2.37.1 From nobody Thu Apr 25 18:48:42 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1659688083; cv=none; d=zohomail.com; s=zohoarc; b=W61EQ4ecvUHtRtSsG2pRjlliRTu3mCLI98+Z6jvG4YGBHp0OhVisy+QiwVHlhUCmyESGK0F1zvVGneQAedEUYcTVZPKCXhVtUDHCQoLL4pvlrPeuoDJcXBVZ2ItqbuBwGFAiei/K3Pv5OWVXWY+MnfvNKIV9FbmJnEhzGLnUpgo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659688083; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=c6dPTlYyPvubG8TXDDFuABwGKU2xBmZWlbheVh8goN4=; b=gnK/NcI8f0LsJ5dUHTuIM5V2heGV1QduakKxmCfmZiSV7pL59ZyOH/IPXBKAw2FlHuZdVL7SNnba2XSlwpD2oQ0yX1Xv+Dg21+giNRUmSeuxUHCAbz7xbhclKU3Hn24Jf9zt3l8vYcvWXweLKAKBK/zoae8Dkfs8/8FteHnDrbE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1659688083054212.54837405806097; Fri, 5 Aug 2022 01:28:03 -0700 (PDT) Received: from localhost ([::1]:51536 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJsga-0001Lm-V7 for importer@patchew.org; Fri, 05 Aug 2022 04:28:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60578) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJsEC-0003bK-Ju; Fri, 05 Aug 2022 03:58:40 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]:33780) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oJsE9-0001z1-BC; Fri, 05 Aug 2022 03:58:40 -0400 Received: by mail-pf1-x42a.google.com with SMTP id 17so1647056pfy.0; Fri, 05 Aug 2022 00:58:36 -0700 (PDT) Received: from roots.. ([106.84.130.246]) by smtp.gmail.com with ESMTPSA id z15-20020a170903018f00b0016ee708350bsm2418564plg.14.2022.08.05.00.58.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Aug 2022 00:58:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=c6dPTlYyPvubG8TXDDFuABwGKU2xBmZWlbheVh8goN4=; b=R9ghnCu40uRtCESpO4mp7PqFJcA3TVOEdixGk/lNgoZFNNkAL6qa18dulgGKls4VoU 7226iy56fVqMr71htIjJKOX2iWftbNb/NKvDorFb7//JJ8Z8u5EZAwKTFcrC+iuYmwRy XH2nZTJtz65TUPrLC1TYOUAqDdaKROexehR59LF+RMLeEFLQSFiiQlKMyQy9uvcPxitV 2m5ML0vpXx0lXb+JqI7hlaHrpxkJNadHe7aYvAvidtaccIY1OslEn1H7M71tZ7rEGBl7 vfWVZfQPqs85ke/LPaWxcIJSmNHNmg/5tMTw6PRdUwaVHxagjVLstqYTk1UuWechMZkm sxrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=c6dPTlYyPvubG8TXDDFuABwGKU2xBmZWlbheVh8goN4=; b=EIwpEOSS0/jAwaKlhg3mZdfP7k7MlwJ53C6yWC7H6ndNiytYTUKpo17EkwVdZBYjlj uEnNtaR7R6zDPYXj1Zeddv9s2s7YF4cZ8HxM5zodGfJfLrNQCJnm4Cuh24iHDxw6iTwK ZTey0xrUDEeXAaW4SbVHYAqiVjCM0BOxmUyxVF0delhdZh1gr6CFmK6ApMRKPtvbCmAy gOQ7s1zjd4V1pNPyiRIJaJicVVnWFYy/H+JTRzBa3N9bh1ALM7JLYtFH4jzL7VXv9T/0 69q4jf0e6ZPB+kbc/cKtODwNRUV2Z8+nMKCwYNldg51hQB9i5vxoi0pbnSm/ymIFBhbA 8FQQ== X-Gm-Message-State: ACgBeo2qffmbBwneuwOgiEuJPURSeMuxW1HGcloybQsDUlA//3l4kU3k Quev++onRRnfS0xstdRvyaCUIZ80Y8ZFsw== X-Google-Smtp-Source: AA6agR6gLdZMpMGCaVBbSbzOftpp/UrLX+WUWdzPoVeZtxjwZkpdfjLXx8rgYiQEXahJbHRnjJBZWA== X-Received: by 2002:a63:d90b:0:b0:41a:ff05:4808 with SMTP id r11-20020a63d90b000000b0041aff054808mr4918827pgg.159.1659686315563; Fri, 05 Aug 2022 00:58:35 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, hare@suse.de, Stefan Hajnoczi , dmitry.fomichev@wdc.com, Kevin Wolf , damien.lemoal@opensource.wdc.com, Eric Blake , Fam Zheng , Markus Armbruster , Hanna Reitz , Sam Li Subject: [PATCH v6 7/8] qemu-iotests: test new zone operations Date: Fri, 5 Aug 2022 15:57:50 +0800 Message-Id: <20220805075751.77499-8-faithilikerun@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220805075751.77499-1-faithilikerun@gmail.com> References: <20220805075751.77499-1-faithilikerun@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42a; envelope-from=faithilikerun@gmail.com; helo=mail-pf1-x42a.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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1659688084566100001 Content-Type: text/plain; charset="utf-8" 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, [typ= e: 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, [typ= e: 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, [typ= e: 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/z= oned.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=3D"$(basename $0)" +echo "QA output created by $seq" +status=3D1 # 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=3D"build/qemu-io" +IMG=3D"--image-opts driver=3Dzoned_host_device,filename=3D/dev/nullb0" +QEMU_IO_OPTIONS=3D$QEMU_IO_OPTIONS_NO_FMT + +echo "Testing a null_blk device:" +echo "Simple cases: if the operations work" +sudo modprobe null_blk nr_devices=3D1 zoned=3D1 + +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 =3D 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=3D0 --=20 2.37.1 From nobody Thu Apr 25 18:48:42 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1659688216; cv=none; d=zohomail.com; s=zohoarc; b=Uhc0e/ba8zaZsVNsbkI0E2p8L1+LDa4VeFXYGR25kJ2Ykk4Kbo70pLi8sP8lMqu0QnlWwOrc4g7ClNn34BqNKAstINMFW1ntU3QX7UsEYT+G+QBGZ+Qxs7U+OCoqyLUkavPDq0sk9hSGhCjcznvBmrh78rq/shCLtm8qpRymRkI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659688216; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=y37nrXKQuzvNQncPc/5KLvokW86ReypQKlztAtxsyvs=; b=GmavC8/nxvZNRFA/RFfvjCHKuL4yE68Ln12qKDTzUuaM6LgIO7ZhBAgAhCYBzda+DhkURhi0H4tvxPP0oxbfu3Ev3kM5dt0y68ejkFR7MION0Yfl0nC8jrW8Xtur3/cbnUIHxh7If3Pc6MAjcuXamAvw5W/agP136ZxNZIaapLU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16596882161101004.7941730037012; Fri, 5 Aug 2022 01:30:16 -0700 (PDT) Received: from localhost ([::1]:56750 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJsik-0004en-LI for importer@patchew.org; Fri, 05 Aug 2022 04:30:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60620) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJsEG-0003nn-1Z; Fri, 05 Aug 2022 03:58:44 -0400 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]:40457) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oJsEE-0001zk-6u; Fri, 05 Aug 2022 03:58:43 -0400 Received: by mail-pj1-x102f.google.com with SMTP id s5-20020a17090a13c500b001f4da9ffe5fso7539526pjf.5; Fri, 05 Aug 2022 00:58:41 -0700 (PDT) Received: from roots.. ([106.84.130.246]) by smtp.gmail.com with ESMTPSA id z15-20020a170903018f00b0016ee708350bsm2418564plg.14.2022.08.05.00.58.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Aug 2022 00:58:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=y37nrXKQuzvNQncPc/5KLvokW86ReypQKlztAtxsyvs=; b=l+zKIWq5O0/N4rmUVb/VL5vcJPAFBMzkT4gcRmJ0nTQiM5ytQwytpsjmAlUc6algLr /JypLxXAg+vCzjiQEEEg5oh1G2YCJB1s//rKal62YEZY4Qa290xsOjTYfeLK/93QA2EG xbgsHl88B3N0iwKos27PIatDXU/zlHYgNB6DTDZEmNzvbXbq1TjNjoZ2xDrAqontsUtF iYfGluOn+/CFPUwuTpj++DXax1WY6kafGtB/vFQ6bKbO9labOnvapK2ixz98n85kN/2u Qw4B7+DxC9qY7bQNizAEEHdMYng/EGrHMA+TtPGzAdomKN1NH9w91VQK7NsLc/3H65vg swcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=y37nrXKQuzvNQncPc/5KLvokW86ReypQKlztAtxsyvs=; b=s0oyuzp87SNzNUrOluyQqm7nJeUTFMa/i7k8hT4Vg1xohFjAQ1MvfnrJyCK/7BQN31 CbKbLU3dqRSt9hQi+fJsihjQubq3Fw1FqF+VVFN8VCh6n0ydpXptHuHwldnvuC6oagkc rfr7aLAQTG7O7l3CiXqCVRCVKk4rSL4cISipZdhu8RQRmhGSsl4n3JCx09gYoP14n6SS I1eXYOPflsGNyoTmUk3/8ZzUntBYbCK8NUd92Rc4Q4i6gJQNYMj+ICxOAW3hLCJ9iTQU TsBjOa4q6gOBpd/MyP43l8JelQzSxLXusxtVZnp7IEQBbtZjo6miOx1OJ73ZmUym50DZ Un2A== X-Gm-Message-State: ACgBeo31T/YpNPrDzg4YUs+ZwsMXuPGT6Bt/OMpdLD7ozQUP8MN6/wRv tmu/ZSTyj73EmE37IZS8Wk3JifoKVHvVPQ== X-Google-Smtp-Source: AA6agR7aSZT5IX0ReFc2sDTh4eZsm0Rzv4bMqhpSauXFwmXtviOASKAN7V53zlLXVWUgkEOkyrlQTg== X-Received: by 2002:a17:90b:3144:b0:1f5:829e:cd49 with SMTP id ip4-20020a17090b314400b001f5829ecd49mr3634814pjb.80.1659686320404; Fri, 05 Aug 2022 00:58:40 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, hare@suse.de, Stefan Hajnoczi , dmitry.fomichev@wdc.com, Kevin Wolf , damien.lemoal@opensource.wdc.com, Eric Blake , Fam Zheng , Markus Armbruster , Hanna Reitz , Sam Li Subject: [PATCH v6 8/8] docs/zoned-storage: add zoned device documentation Date: Fri, 5 Aug 2022 15:57:51 +0800 Message-Id: <20220805075751.77499-9-faithilikerun@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220805075751.77499-1-faithilikerun@gmail.com> References: <20220805075751.77499-1-faithilikerun@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=faithilikerun@gmail.com; helo=mail-pj1-x102f.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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1659688217208100001 Content-Type: text/plain; charset="utf-8" Add the documentation about the zoned device support to virtio-blk emulation. Signed-off-by: Sam Li Reviewed-by: Stefan Hajnoczi --- docs/devel/zoned-storage.rst | 41 ++++++++++++++++++++++++++ docs/system/qemu-block-drivers.rst.inc | 6 ++++ 2 files changed, 47 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..c3f1e477ac --- /dev/null +++ b/docs/devel/zoned-storage.rst @@ -0,0 +1,41 @@ +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +zoned-storage +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Zoned Block Devices (ZBDs) devide the LBA space into block regions called = zones +that are larger than the LBA size. It can only allow sequential writes, wh= ich +reduces write amplification in SSDs, leading to higher throughput and incr= eased +capacity. More details about ZBDs can be found at: + +https://zonedstorage.io/docs/introduction/zoned-storage + +1. Block layer APIs for zoned storage +------------------------------------- +QEMU block layer has three zoned storage model: +- BLK_Z_HM: This model only allows sequential writes access. It supports a= set +of ZBD-specific I/O request that used by the host to manage device zones. +- BLK_Z_HA: It deals with both sequential writes and random writes access. +- BLK_Z_NONE: Regular block devices and drive-managed ZBDs are treated as +non-zoned devices. + +The block device information is resided inside BlockDriverState. QEMU uses +BlockLimits struct(BlockDriverState::bl) that is continuously accessed by = the +block layer while processing I/O requests. A BlockBackend has a root point= er to +a BlockDriverState graph(for example, raw format on top of file-posix). The +zoned storage information can be propagated from the leaf BlockDriverState= all +the way up to the BlockBackend. If the zoned storage model in file-posix is +set to BLK_Z_HM, then block drivers will declare support for zoned host de= vice. + +The block layer APIs support commands needed for zoned storage devices, +including report zones, four zone operations, and zone append. + +2. Emulating zoned storage controllers +-------------------------------------- +When the BlockBackend's BlockLimits model reports a zoned storage device, = users +like the virtio-blk emulation or the qemu-io-cmds.c utility can use block = layer +APIs for zoned storage emulation or testing. + +For example, the command line for zone report testing a null_blk device of +qemu-io-cmds.c is: +$ path/to/qemu-io --image-opts driver=3Dzoned_host_device,filename=3D/dev/= nullb0 -c +"zrp offset nr_zones" diff --git a/docs/system/qemu-block-drivers.rst.inc b/docs/system/qemu-bloc= k-drivers.rst.inc index dfe5d2293d..0b97227fd9 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). =20 +Zoned block devices + Zoned block devices can be passed through to the guest if the emulated s= torage + controller supports zoned storage. Use ``--blockdev zoned_host_device, + node-name=3Ddrive0,filename=3D/dev/nullb0`` to pass through ``/dev/nullb= 0`` + as ``drive0``. + Windows ^^^^^^^ =20 --=20 2.37.1