From nobody Tue May 14 12:38:52 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=1682616085; cv=none; d=zohomail.com; s=zohoarc; b=C6/C6Z8p7X+11fPclFeYJLsROy4PrwfVvnflLzU0nvrRN2KBH891cN7cRTTvgAof5S6dUdpBJrjavG25SKi4lKGuJpujsd2IkFUGXg5QO85zKoxd0DzpkU5gEf6V8gu9LDsJpw8JpoeETe7RhCu6NQ1HmsUhe9+3piG33pcnOTk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682616085; h=Content-Type: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=w9iJ0TtvzUwBpKUP/uL1GmcFj9lAgNDwrL1rkCpsmvw=; b=ZQV6hwOivb6TtgI2T2qucRVfFUfmwTtnqjiTWOdQtWKCIE1iRxdSYcwU23D/hO3gIP5pBQfhXCnoO8owRKOXG1zcy2B2au18AjHe1opVf4fSTOI/D3C/rF0XR+fnCB8szHCIifjx8fPK8YyLNeSQanhr9zWCq2v9hA3+bSL6CGM= 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 1682616085465268.34014776380195; Thu, 27 Apr 2023 10:21:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ps5IV-0006KR-8P; Thu, 27 Apr 2023 13:20:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ps5IU-0006Jg-9O; Thu, 27 Apr 2023 13:20:46 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ps5IO-0007KZ-W4; Thu, 27 Apr 2023 13:20:46 -0400 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1a66888cb89so68086665ad.3; Thu, 27 Apr 2023 10:20:40 -0700 (PDT) Received: from fedlinux.. ([106.84.128.101]) by smtp.gmail.com with ESMTPSA id p1-20020a170902a40100b001a95c7742bbsm8878578plq.9.2023.04.27.10.20.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 10:20:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682616039; x=1685208039; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=w9iJ0TtvzUwBpKUP/uL1GmcFj9lAgNDwrL1rkCpsmvw=; b=BorAWrGyFZwg3ZkHNq9yphJxFyqdPuDGLQQpGPeNCqhsv021WcMJIdUs3d4JolFuqE rn2P55zxrSnXvrlkJv2aq8ZI2A1jKrNAqs7h40zezJ9eg2TgesUaIu3p8Az/I9Lc3gC0 ARSRHdYAzvERbY1AfRjZ5vPFx6Eo/B3iJFmWj9uF20nVHAXs10OjFANNReANnMj7ucj0 1eCD00y8bq20TlW0RKDdS/SySDPb/lvs2IN3mP/6SnRLRTdix3U6PM1G3QN4IENxBCAs zIyRaMRDSOE3wwEfQEogOhcSqmH5xY2SrXKEfKTSIlW/1z3CEvCImcbvGeq3eTOWzIql 5vSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682616039; x=1685208039; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=w9iJ0TtvzUwBpKUP/uL1GmcFj9lAgNDwrL1rkCpsmvw=; b=crNJtl8ET7znWanrrsG2RYNEXZfc4IA2hhal2eJ5wbfW+MGNiiaIV0KAWaPjvu1Wi4 Pfq7EXeRlcrPrTV3x3cJy9/uPGFwdbPK+EsbT+/1D5mhdiy5ZzkZwRSey/aGWHak1doZ QdYEskxdlySTVZ0WRQUnVOHCGLGV613Te4GkbDp01DTGfboOk53lubsRRqaRjrqqg1VV VjipIVH9C18Uhsr3bDM8xSkVCVy31qDk1/bzg8P+A7TN+YnumD6I3rvlf0CL8d+G9iIp dqSgASI0a1vZC1JZYz4mfG+dUZArXkbSplQAz79rPV3cxQdln9EcPfLcACMXs7ZPNVr7 Eq/A== X-Gm-Message-State: AC+VfDy478b4cbgkvED3xByRjTQ8qZYWMF5ZJFmTHUiOgat8CuuU9iaS wQl/3VhYOFGtXraJFvsSqCHvRZLTK6QuGzPmqoI= X-Google-Smtp-Source: ACHHUZ4/sru7bLllRSwbw8pQxC82u8dxzVH8DGbUScmVq/yh41AeAP3ntYTkHBbUpUFGYqre5wYntQ== X-Received: by 2002:a17:902:f20a:b0:1a6:c110:9029 with SMTP id m10-20020a170902f20a00b001a6c1109029mr2149932plc.59.1682616038504; Thu, 27 Apr 2023 10:20:38 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Kevin Wolf , Fam Zheng , Paolo Bonzini , dlemoal@kernel.org, hare@suse.de, Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , stefanha@redhat.com, dmitry.fomichev@wdc.com, qemu-block@nongnu.org, Sam Li , Damien Le Moal Subject: [PATCH v19 1/8] block/block-common: add zoned device structs Date: Fri, 28 Apr 2023 01:20:12 +0800 Message-Id: <20230427172019.3345-2-faithilikerun@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230427172019.3345-1-faithilikerun@gmail.com> References: <20230427172019.3345-1-faithilikerun@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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::634; envelope-from=faithilikerun@gmail.com; helo=mail-pl1-x634.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.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, FREEMAIL_REPLY=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1682616087626100001 Signed-off-by: Sam Li Reviewed-by: Stefan Hajnoczi Reviewed-by: Damien Le Moal Reviewed-by: Hannes Reinecke Reviewed-by: Dmitry Fomichev Acked-by: Kevin Wolf Message-id: 20230324090605.28361-2-faithilikerun@gmail.com [Adjust commit message prefix as suggested by Philippe Mathieu-Daud=C3=A9 . --Stefan] Signed-off-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 b5122ef8ab..1576fcf2ed 100644 --- a/include/block/block-common.h +++ b/include/block/block-common.h @@ -75,6 +75,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 BlockZoneState { + 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, +} BlockZoneState; + +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; + BlockZoneState state; +} BlockZoneDescriptor; + typedef struct BlockDriverInfo { /* in bytes, 0 if irrelevant */ int cluster_size; --=20 2.40.0 From nobody Tue May 14 12:38:52 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=1682616170; cv=none; d=zohomail.com; s=zohoarc; b=GbN0Rbb89m76muAlytUFzPLiflOBDm1K2GF0vlvCqqpOo0in6uVGAXt8FGeLh/xupGSNGdvHND4Uchau9YkxkxdFqwN+P8K97tUMEXxUJMnYoqPUqhS8FE6sh5YYzJYE0Mkixc22gzhO3Dp9ft6PRdOMG7eua6iS7ZggTdbgT2s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682616170; h=Content-Type: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=onSu0Ke/vEcZki4o3PulYUE8aFRZwU69Hc3w/Cte9mM=; b=i3YoqLXECcnMF9xKX+96YRWKZ4IOkfh5uBg4mhpJaMKUjQku8y9sLae9yAiyBk5lk9D39I9Zco9J+p8WXNE/T7Nxq2dWsC7JFcTVnlX5FTqz9jELfyoSX92/1VOSWJ2OqkMvEXIqB+VS3S5P22uga1YOXWBo9rrDG6oBpGaehJA= 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 16826161708351010.6664566892537; Thu, 27 Apr 2023 10:22:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ps5Ia-0006aR-U3; Thu, 27 Apr 2023 13:20:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ps5IY-0006TR-LS; Thu, 27 Apr 2023 13:20:50 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ps5IW-0007LR-W8; Thu, 27 Apr 2023 13:20:50 -0400 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1a920d484bdso68664045ad.1; Thu, 27 Apr 2023 10:20:48 -0700 (PDT) Received: from fedlinux.. ([106.84.128.101]) by smtp.gmail.com with ESMTPSA id p1-20020a170902a40100b001a95c7742bbsm8878578plq.9.2023.04.27.10.20.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 10:20:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682616047; x=1685208047; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=onSu0Ke/vEcZki4o3PulYUE8aFRZwU69Hc3w/Cte9mM=; b=UqyUVE/Jopsdt3CAyUE+JKznF9akwMG3nZGMbybqZyMvcHvfOW5+EORaeU1iTNvqck 08HAeDKLbcwOLPxAvPyQPl8YRNH4FQJI9B/EmDkAAVqFHG8fNSVhVF/2SEimGdbDw9YB t1LR99wukXcya7c5eRBGmeknSYcuDp61bXxh8wvEwXha1TZj+OSIW0vOT3SSnMUGMCBW VGcT+1P36VnzO4lGunogJG5RN0H1kLxmd5Mx57Su03QOAyycLhZHYAOXGXHWvjBFEKl2 oPRo129MQ9UBZ/AGv/nhQLD0He4D6u5Vnc7+UP012UM8oqFweUIoLgQQrtRD5CtizQMX uzYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682616047; x=1685208047; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=onSu0Ke/vEcZki4o3PulYUE8aFRZwU69Hc3w/Cte9mM=; b=QBL4SES5dULLkGXuMTGJbVQBQ7l0RUyv8C8uxfTaVndN/FvYFWj0tSwy+K5or9qyo7 OTVxAdJZHAUUyXv6cFR8kmjXtNBPHD8E+69qFbXYA2kQxeveq56kD9cKp5ywTc1ssxz3 1HKewLGWMGURLi20jVF1xmRI1O7ZJMLtJjWfStHY8qaQ53ry3u3dLxk1Hf1mgqhmp6gM 6/ONg8/ZU2G8kciAhk1b5FNxUE3nw0gbTP8rfoEYnJ7p8m6XJTnyTJFHlwkbwCx6zakW Ops1y4yPu8YaR7uSu8xtka6eOEgQVP9lKLG+EwvGcHFuOjOV8w+Dgj/tuLO+uDR6ywBS XLng== X-Gm-Message-State: AC+VfDy2l21h7H0Zmnwpc2sGK3BfTSZibllZvCUPx22QKPtr3UQ/HToa lSqdprZGQpe+qllnRahUuQuf0go9DO7lRa/nZSU= X-Google-Smtp-Source: ACHHUZ6t35ZlODB0GpOKCd8k4WbVRdgxU6H9YMyzSl8f3by67/GqJYYTqJIOQ2JlDYUif1Xm+dPa/w== X-Received: by 2002:a17:903:120f:b0:1a8:13fc:a654 with SMTP id l15-20020a170903120f00b001a813fca654mr2495517plh.25.1682616046444; Thu, 27 Apr 2023 10:20:46 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Kevin Wolf , Fam Zheng , Paolo Bonzini , dlemoal@kernel.org, hare@suse.de, Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , stefanha@redhat.com, dmitry.fomichev@wdc.com, qemu-block@nongnu.org, Sam Li , Damien Le Moal Subject: [PATCH v19 2/8] block/file-posix: introduce helper functions for sysfs attributes Date: Fri, 28 Apr 2023 01:20:13 +0800 Message-Id: <20230427172019.3345-3-faithilikerun@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230427172019.3345-1-faithilikerun@gmail.com> References: <20230427172019.3345-1-faithilikerun@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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::633; envelope-from=faithilikerun@gmail.com; helo=mail-pl1-x633.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.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, FREEMAIL_REPLY=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1682616171766100002 Use get_sysfs_str_val() to get the string value of device zoned model. Then get_sysfs_zoned_model() can convert it to BlockZoneModel type of QEMU. Use get_sysfs_long_val() to get the long value of zoned device information. Signed-off-by: Sam Li Reviewed-by: Hannes Reinecke Reviewed-by: Stefan Hajnoczi Reviewed-by: Damien Le Moal Reviewed-by: Dmitry Fomichev Acked-by: Kevin Wolf Message-id: 20230324090605.28361-3-faithilikerun@gmail.com [Adjust commit message prefix as suggested by Philippe Mathieu-Daud=C3=A9 . --Stefan] Signed-off-by: Stefan Hajnoczi --- block/file-posix.c | 131 +++++++++++++++++++++++-------- include/block/block_int-common.h | 3 + 2 files changed, 100 insertions(+), 34 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index c7b723368e..ba15b10eee 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1202,60 +1202,121 @@ 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 a sysfs attribute value as character string. + */ +static int get_sysfs_str_val(struct stat *st, const char *attribute, + char **val) { #ifdef CONFIG_LINUX - char buf[32]; - const char *end; - char *sysfspath =3D NULL; + g_autofree char *sysfspath =3D NULL; int ret; - int sysfd =3D -1; - long max_segments; + size_t len; =20 - if (S_ISCHR(st->st_mode)) { - if (ioctl(fd, SG_GET_SG_TABLESIZE, &ret) =3D=3D 0) { - return ret; - } + if (!S_ISBLK(st->st_mode)) { return -ENOTSUP; } =20 - 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, val, &len, NULL); + if (ret =3D=3D -1) { + return -ENOENT; } =20 - sysfspath =3D g_strdup_printf("/sys/dev/block/%u:%u/queue/max_segments= ", - major(st->st_rdev), minor(st->st_rdev)); - sysfd =3D open(sysfspath, O_RDONLY); - if (sysfd =3D=3D -1) { - ret =3D -errno; - goto out; + /* The file is ended with '\n' */ + char *p; + p =3D *val; + if (*(p + len - 1) =3D=3D '\n') { + *(p + len - 1) =3D '\0'; } - ret =3D RETRY_ON_EINTR(read(sysfd, buf, sizeof(buf) - 1)); + return ret; +#else + return -ENOTSUP; +#endif +} + +static int get_sysfs_zoned_model(struct stat *st, BlockZoneModel *zoned) +{ + g_autofree char *val =3D NULL; + int ret; + + ret =3D get_sysfs_str_val(st, "zoned", &val); if (ret < 0) { - ret =3D -errno; - goto out; - } else if (ret =3D=3D 0) { - ret =3D -EIO; - goto out; + return ret; } - buf[ret] =3D 0; - /* The file is ended with '\n', pass 'end' to accept that. */ - ret =3D qemu_strtol(buf, &end, 10, &max_segments); - if (ret =3D=3D 0 && end && *end =3D=3D '\n') { - ret =3D max_segments; + + 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; +} =20 -out: - if (sysfd !=3D -1) { - close(sysfd); +/* + * Get a sysfs attribute value as a long integer. + */ +static long get_sysfs_long_val(struct stat *st, const char *attribute) +{ +#ifdef CONFIG_LINUX + g_autofree char *str =3D NULL; + const char *end; + long val; + int ret; + + ret =3D get_sysfs_str_val(st, attribute, &str); + if (ret < 0) { + return ret; + } + + /* The file is ended with '\n', pass 'end' to accept that. */ + ret =3D qemu_strtol(str, &end, 10, &val); + if (ret =3D=3D 0 && end && *end =3D=3D '\0') { + ret =3D val; } - g_free(sysfspath); return ret; #else return -ENOTSUP; #endif } =20 +static int hdev_get_max_segments(int fd, struct stat *st) +{ +#ifdef CONFIG_LINUX + 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(st, "max_segments"); +#else + return -ENOTSUP; +#endif +} + +static void raw_refresh_zoned_limits(BlockDriverState *bs, struct stat *st, + Error **errp) +{ + BlockZoneModel zoned; + int ret; + + bs->bl.zoned =3D BLK_Z_NONE; + + ret =3D get_sysfs_zoned_model(st, &zoned); + if (ret < 0 || zoned =3D=3D BLK_Z_NONE) { + return; + } + bs->bl.zoned =3D zoned; +} + static void raw_refresh_limits(BlockDriverState *bs, Error **errp) { BDRVRawState *s =3D bs->opaque; @@ -1297,6 +1358,8 @@ static void raw_refresh_limits(BlockDriverState *bs, = Error **errp) bs->bl.max_hw_iov =3D ret; } } + + raw_refresh_zoned_limits(bs, &st, errp); } =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 013d419444..150dc6f68f 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -861,6 +861,9 @@ typedef struct BlockLimits { * an explicit monitor command to load the disk inside the guest). */ bool has_variable_length; + + /* device zone model */ + BlockZoneModel zoned; } BlockLimits; =20 typedef struct BdrvOpBlocker BdrvOpBlocker; --=20 2.40.0 From nobody Tue May 14 12:38:52 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=1682616144; cv=none; d=zohomail.com; s=zohoarc; b=No2wdbMo0qXRyRIjQCtzzjjY1plN2y+4bCMU50/JXahS246nldhOxsyQ6HwHhcUi1WNl/31ozQpoS6KVP7oIIpacC/ZUouqKtMLgG2LZMcsUzyA8CVUF2C7BvitwiXxXnUPohDjSMrJZmxSyhqWap2xWJ95+HZ8FDteEydlxaSg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682616144; h=Content-Type: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=tNvYKQDbPL0AhS3kFpupNbmMEgv53zkIcH8M+V8p+nw=; b=WBqN5IiluIDhAik1BkCJQPiro83DyZT0TUIdYnTQE27Eoz966DGJbUDWzzEvQhq9KO8xZHGcO94GDOHFh4ip83ZDWsrnLAtenkxqdtSiQqyRasvv7b+xgFu6oC82VKPaPYjANdKx6vsnGuKLlFwmQXKHpPB0jkgFesqNy6ZsrL4= 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 1682616144635898.1664344673617; Thu, 27 Apr 2023 10:22:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ps5Im-0006mS-3E; Thu, 27 Apr 2023 13:21:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ps5Ik-0006iT-H1; Thu, 27 Apr 2023 13:21:02 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ps5Ig-0007M7-AK; Thu, 27 Apr 2023 13:21:02 -0400 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1a8097c1ccfso89912645ad.1; Thu, 27 Apr 2023 10:20:57 -0700 (PDT) Received: from fedlinux.. ([106.84.128.101]) by smtp.gmail.com with ESMTPSA id p1-20020a170902a40100b001a95c7742bbsm8878578plq.9.2023.04.27.10.20.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 10:20:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682616056; x=1685208056; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tNvYKQDbPL0AhS3kFpupNbmMEgv53zkIcH8M+V8p+nw=; b=mVYGQJEpMlZtfQHL+YB0I8PAlqy819ZT7tZDUJnFFpeNZeBoEHe394O7cLnPsF0Q37 JA3MvRebWjgMZ7eUQdnGCaGyEwYPULJy6eu63CY+GBun/hA5om2iPjJzKv2OhAeTy/oE bEAizKuvqMMsOzCl4OSQvWU0jwHMCYjZOvsd6L3HX/8InQnft5pMO7VpKRNEy1fDGc9S c4cjGyd5sxm2pGSlJ6hYbyt+hdX13lT8LFOphN1s6zJqjrnlARYgAFj77wMYQnQiNh7a lqvpg+SGHfHVWbV3W3Lc3niWROM1IJ8xKHULTd3YA3uUT1Re/Y8CA8TKzd+JVW1KSfAs B+TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682616056; x=1685208056; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tNvYKQDbPL0AhS3kFpupNbmMEgv53zkIcH8M+V8p+nw=; b=NHkkwXnNPh5BE4nkKk16ByY99QDjlvVoCI2WGn7937MErpwaRaIRusN3hk9qSLO8xN FXCPeAaRYPJovc/gkwXKHQZgIiMHQ0Yi9/j+xw8WNqzbtWNLSaTP8Y965Cb94poHOkIv KTYaYE6DxglsMdaHs/wc2BL4CfYTJkv580dSGhj0EWA/Wvll8nHawcU5TF0A+QKZfs2p 7GQCl5V6dkrG3pKF9G8uDoKBjgrtI6f4Z+EYM9woD+GKVZQdo3p1IRx/T0/IFqEZRP6E CVq7ILk5IYlhjSwp1aECJUnT9etq6X1ux8nJ+upbHYV66voUO9SUff3sN52prTTreuoH cHmw== X-Gm-Message-State: AC+VfDyz/86hPnv7j34RHRiJ5ctAs1YGDEs5L8pXMRU69QQ6cn8FcTgj /KSLB48osTpY7SVXupxLFjg0dmSbV6ESdibjbNE= X-Google-Smtp-Source: ACHHUZ5kqdpRsgKsLNYUS4BwR8k1sd1zmKvk903BZFV7Szey/UgKHF+oqBG+goASfhAtAB5CArOVuA== X-Received: by 2002:a17:902:b205:b0:1a9:7e44:17 with SMTP id t5-20020a170902b20500b001a97e440017mr2031534plr.17.1682616055752; Thu, 27 Apr 2023 10:20:55 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Kevin Wolf , Fam Zheng , Paolo Bonzini , dlemoal@kernel.org, hare@suse.de, Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , stefanha@redhat.com, dmitry.fomichev@wdc.com, qemu-block@nongnu.org, Sam Li Subject: [PATCH v19 3/8] block/block-backend: add block layer APIs resembling Linux ZonedBlockDevice ioctls Date: Fri, 28 Apr 2023 01:20:14 +0800 Message-Id: <20230427172019.3345-4-faithilikerun@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230427172019.3345-1-faithilikerun@gmail.com> References: <20230427172019.3345-1-faithilikerun@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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::62e; envelope-from=faithilikerun@gmail.com; helo=mail-pl1-x62e.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.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, FREEMAIL_REPLY=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1682616145409100005 Add zoned device option to host_device BlockDriver. It will be presented on= ly for zoned host block devices. By adding zone management operations to the host_block_device BlockDriver, users can use the new block layer APIs including Report Zone and four zone management operations (open, close, finish, reset, reset_all). Qemu-io uses the new APIs to perform 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 -n driver=3Dhost_device, filename=3D/dev/nul= lb0 -c "zrp offset nr_zones" Signed-off-by: Sam Li Reviewed-by: Hannes Reinecke Reviewed-by: Stefan Hajnoczi Reviewed-by: Dmitry Fomichev Acked-by: Kevin Wolf Message-id: 20230324090605.28361-4-faithilikerun@gmail.com [Adjust commit message prefix as suggested by Philippe Mathieu-Daud=C3=A9 and remove spurious ret =3D -errno in raw_co_zone_mgmt(). --Stefan] Signed-off-by: Stefan Hajnoczi --- block/block-backend.c | 137 +++++++++++++ block/file-posix.c | 313 +++++++++++++++++++++++++++++- block/io.c | 41 ++++ include/block/block-io.h | 9 + include/block/block_int-common.h | 21 ++ include/block/raw-aio.h | 6 +- include/sysemu/block-backend-io.h | 18 ++ meson.build | 4 + qemu-io-cmds.c | 149 ++++++++++++++ 9 files changed, 695 insertions(+), 3 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index fc530ded6a..67722eb46d 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1845,6 +1845,143 @@ int coroutine_fn blk_co_flush(BlockBackend *blk) return ret; } =20 +static void coroutine_fn blk_aio_zone_report_entry(void *opaque) +{ + BlkAioEmAIOCB *acb =3D opaque; + BlkRwCo *rwco =3D &acb->rwco; + + rwco->ret =3D blk_co_zone_report(rwco->blk, rwco->offset, + (unsigned int*)(uintptr_t)acb->bytes, + rwco->iobuf); + 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; + IO_CODE(); + + blk_inc_in_flight(blk); + acb =3D blk_aio_get(&blk_aio_em_aiocb_info, blk, cb, opaque); + acb->rwco =3D (BlkRwCo) { + .blk =3D blk, + .offset =3D offset, + .iobuf =3D zones, + .ret =3D NOT_DONE, + }; + acb->bytes =3D (int64_t)(uintptr_t)nr_zones, + acb->has_returned =3D false; + + co =3D qemu_coroutine_create(blk_aio_zone_report_entry, acb); + aio_co_enter(blk_get_aio_context(blk), co); + + acb->has_returned =3D true; + if (acb->rwco.ret !=3D NOT_DONE) { + replay_bh_schedule_oneshot_event(blk_get_aio_context(blk), + blk_aio_complete_bh, acb); + } + + return &acb->common; +} + +static void coroutine_fn blk_aio_zone_mgmt_entry(void *opaque) +{ + BlkAioEmAIOCB *acb =3D opaque; + BlkRwCo *rwco =3D &acb->rwco; + + rwco->ret =3D blk_co_zone_mgmt(rwco->blk, + (BlockZoneOp)(uintptr_t)rwco->iobuf, + 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; + IO_CODE(); + + blk_inc_in_flight(blk); + acb =3D blk_aio_get(&blk_aio_em_aiocb_info, blk, cb, opaque); + acb->rwco =3D (BlkRwCo) { + .blk =3D blk, + .offset =3D offset, + .iobuf =3D (void *)(uintptr_t)op, + .ret =3D NOT_DONE, + }; + acb->bytes =3D len; + acb->has_returned =3D false; + + co =3D qemu_coroutine_create(blk_aio_zone_mgmt_entry, acb); + aio_co_enter(blk_get_aio_context(blk), co); + + acb->has_returned =3D true; + if (acb->rwco.ret !=3D 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 + * 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); + GRAPH_RDLOCK_GUARD(); + 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. + * op is the zone operation; + * offset is the byte offset from the start of the zoned device; + * len is the maximum number of bytes the command should operate on. It + * should be aligned with the device zone size. + */ +int coroutine_fn blk_co_zone_mgmt(BlockBackend *blk, BlockZoneOp op, + int64_t offset, int64_t len) +{ + int ret; + IO_CODE(); + + blk_inc_in_flight(blk); + blk_wait_while_drained(blk); + GRAPH_RDLOCK_GUARD(); + + ret =3D blk_check_byte_request(blk, offset, len); + if (ret < 0) { + blk_dec_in_flight(blk); + return ret; + } + + 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/file-posix.c b/block/file-posix.c index ba15b10eee..3b6575d771 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -68,6 +68,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 { + unsigned long op; + } zone_mgmt; }; } RawPosixAIOData; =20 @@ -1236,6 +1246,7 @@ static int get_sysfs_str_val(struct stat *st, const c= har *attribute, #endif } =20 +#if defined(CONFIG_BLKZONED) static int get_sysfs_zoned_model(struct stat *st, BlockZoneModel *zoned) { g_autofree char *val =3D NULL; @@ -1257,6 +1268,7 @@ static int get_sysfs_zoned_model(struct stat *st, Blo= ckZoneModel *zoned) } return 0; } +#endif /* defined(CONFIG_BLKZONED) */ =20 /* * Get a sysfs attribute value as a long integer. @@ -1302,6 +1314,7 @@ static int hdev_get_max_segments(int fd, struct stat = *st) #endif } =20 +#if defined(CONFIG_BLKZONED) static void raw_refresh_zoned_limits(BlockDriverState *bs, struct stat *st, Error **errp) { @@ -1315,7 +1328,54 @@ static void raw_refresh_zoned_limits(BlockDriverStat= e *bs, struct stat *st, return; } bs->bl.zoned =3D zoned; + + ret =3D get_sysfs_long_val(st, "max_open_zones"); + if (ret >=3D 0) { + bs->bl.max_open_zones =3D ret; + } + + ret =3D get_sysfs_long_val(st, "max_active_zones"); + if (ret >=3D 0) { + bs->bl.max_active_zones =3D ret; + } + + /* + * The zoned device must at least have zone size and nr_zones fields. + */ + ret =3D get_sysfs_long_val(st, "chunk_sectors"); + if (ret < 0) { + error_setg_errno(errp, -ret, "Unable to read chunk_sectors " + "sysfs attribute"); + return; + } else if (!ret) { + error_setg(errp, "Read 0 from chunk_sectors sysfs attribute"); + return; + } + bs->bl.zone_size =3D ret << BDRV_SECTOR_BITS; + + ret =3D get_sysfs_long_val(st, "nr_zones"); + if (ret < 0) { + error_setg_errno(errp, -ret, "Unable to read nr_zones " + "sysfs attribute"); + return; + } else if (!ret) { + error_setg(errp, "Read 0 from nr_zones sysfs attribute"); + return; + } + bs->bl.nr_zones =3D ret; + + ret =3D get_sysfs_long_val(st, "zone_append_max_bytes"); + if (ret > 0) { + bs->bl.max_append_sectors =3D ret >> BDRV_SECTOR_BITS; + } +} +#else /* !defined(CONFIG_BLKZONED) */ +static void raw_refresh_zoned_limits(BlockDriverState *bs, struct stat *st, + Error **errp) +{ + bs->bl.zoned =3D BLK_Z_NONE; } +#endif /* !defined(CONFIG_BLKZONED) */ =20 static void raw_refresh_limits(BlockDriverState *bs, Error **errp) { @@ -1383,9 +1443,12 @@ static int hdev_probe_blocksizes(BlockDriverState *b= s, BlockSizes *bsz) BDRVRawState *s =3D bs->opaque; int ret; =20 - /* If DASD, get blocksizes */ + /* If DASD or zoned devices, get blocksizes */ if (check_for_dasd(s->fd) < 0) { - return -ENOTSUP; + /* zoned devices are not DASD */ + if (bs->bl.zoned =3D=3D BLK_Z_NONE) { + return -ENOTSUP; + } } ret =3D probe_logical_blocksize(s->fd, &bsz->log); if (ret < 0) { @@ -1853,6 +1916,147 @@ 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 int parse_zone(struct BlockZoneDescriptor *zone, + const struct blk_zone *blkz) { + zone->start =3D blkz->start << BDRV_SECTOR_BITS; + zone->length =3D blkz->len << BDRV_SECTOR_BITS; + zone->wp =3D blkz->wp << BDRV_SECTOR_BITS; + +#ifdef HAVE_BLK_ZONE_REP_CAPACITY + zone->cap =3D blkz->capacity << BDRV_SECTOR_BITS; +#else + zone->cap =3D blkz->len << BDRV_SECTOR_BITS; +#endif + + switch (blkz->type) { + case BLK_ZONE_TYPE_SEQWRITE_REQ: + zone->type =3D BLK_ZT_SWR; + break; + case BLK_ZONE_TYPE_SEQWRITE_PREF: + zone->type =3D BLK_ZT_SWP; + break; + case BLK_ZONE_TYPE_CONVENTIONAL: + zone->type =3D BLK_ZT_CONV; + break; + default: + error_report("Unsupported zone type: 0x%x", blkz->type); + return -ENOTSUP; + } + + switch (blkz->cond) { + case BLK_ZONE_COND_NOT_WP: + zone->state =3D BLK_ZS_NOT_WP; + break; + case BLK_ZONE_COND_EMPTY: + zone->state =3D BLK_ZS_EMPTY; + break; + case BLK_ZONE_COND_IMP_OPEN: + zone->state =3D BLK_ZS_IOPEN; + break; + case BLK_ZONE_COND_EXP_OPEN: + zone->state =3D BLK_ZS_EOPEN; + break; + case BLK_ZONE_COND_CLOSED: + zone->state =3D BLK_ZS_CLOSED; + break; + case BLK_ZONE_COND_READONLY: + zone->state =3D BLK_ZS_RDONLY; + break; + case BLK_ZONE_COND_FULL: + zone->state =3D BLK_ZS_FULL; + break; + case BLK_ZONE_COND_OFFLINE: + zone->state =3D BLK_ZS_OFFLINE; + break; + default: + error_report("Unsupported zone state: 0x%x", blkz->cond); + return -ENOTSUP; + } + return 0; +} +#endif + +#if defined(CONFIG_BLKZONED) +static int handle_aiocb_zone_report(void *opaque) +{ + 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; + /* zoned block devices use 512-byte sectors */ + uint64_t sector =3D aiocb->aio_offset / 512; + + struct blk_zone *blkz; + size_t rep_size; + unsigned int nrz; + int ret; + unsigned int 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; + + do { + ret =3D ioctl(fd, BLKREPORTZONE, rep); + } while (ret !=3D 0 && errno =3D=3D EINTR); + 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++) { + ret =3D parse_zone(&zones[n], &blkz[i]); + if (ret !=3D 0) { + return ret; + } + + /* The next report should start after the last zone reported */ + sector =3D blkz[i].start + blkz[i].len; + } + } + + *nr_zones =3D n; + return 0; +} +#endif + +#if defined(CONFIG_BLKZONED) +static int handle_aiocb_zone_mgmt(void *opaque) +{ + RawPosixAIOData *aiocb =3D opaque; + int fd =3D aiocb->aio_fildes; + uint64_t sector =3D aiocb->aio_offset / 512; + int64_t nr_sectors =3D aiocb->aio_nbytes / 512; + struct blk_zone_range range; + int ret; + + /* Execute the operation */ + range.sector =3D sector; + range.nr_sectors =3D nr_sectors; + do { + ret =3D ioctl(fd, aiocb->zone_mgmt.op, &range); + } while (ret !=3D 0 && errno =3D=3D EINTR); + + return ret; +} +#endif + static int handle_aiocb_copy_range(void *opaque) { RawPosixAIOData *aiocb =3D opaque; @@ -3032,6 +3236,104 @@ static void raw_account_discard(BDRVRawState *s, ui= nt64_t nbytes, int ret) } } =20 +/* + * zone report - Get a zone block device's information in the form + * of an array of zone descriptors. + * zones is an array of zone descriptors to hold zone information on reply; + * offset can be any byte within the entire size of the device; + * nr_zones is the maxium number of sectors the command should operate on. + */ +#if defined(CONFIG_BLKZONED) +static int coroutine_fn raw_co_zone_report(BlockDriverState *bs, int64_t o= ffset, + unsigned int *nr_zones, + BlockZoneDescriptor *zones) { + BDRVRawState *s =3D bs->opaque; + RawPosixAIOData 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(handle_aiocb_zone_report, &acb); +} +#endif + +/* + * zone management operations - Execute an operation on a zone + */ +#if defined(CONFIG_BLKZONED) +static int coroutine_fn raw_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp= op, + int64_t offset, int64_t len) { + BDRVRawState *s =3D bs->opaque; + RawPosixAIOData acb; + int64_t zone_size, zone_size_mask; + const char *op_name; + unsigned long zo; + int ret; + int64_t capacity =3D bs->total_sectors << BDRV_SECTOR_BITS; + + zone_size =3D bs->bl.zone_size; + zone_size_mask =3D zone_size - 1; + if (offset & zone_size_mask) { + error_report("sector offset %" PRId64 " is not aligned to zone siz= e " + "%" PRId64 "", offset / 512, zone_size / 512); + return -EINVAL; + } + + if (((offset + len) < capacity && len & zone_size_mask) || + offset + len > capacity) { + error_report("number of sectors %" PRId64 " is not aligned to zone= size" + " %" PRId64 "", len / 512, zone_size / 512); + return -EINVAL; + } + + switch (op) { + case BLK_ZO_OPEN: + op_name =3D "BLKOPENZONE"; + zo =3D BLKOPENZONE; + break; + case BLK_ZO_CLOSE: + op_name =3D "BLKCLOSEZONE"; + zo =3D BLKCLOSEZONE; + break; + case BLK_ZO_FINISH: + op_name =3D "BLKFINISHZONE"; + zo =3D BLKFINISHZONE; + break; + case BLK_ZO_RESET: + op_name =3D "BLKRESETZONE"; + zo =3D BLKRESETZONE; + break; + default: + error_report("Unsupported zone op: 0x%x", op); + return -ENOTSUP; + } + + 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 zo, + }, + }; + + ret =3D raw_thread_pool_submit(handle_aiocb_zone_mgmt, &acb); + if (ret !=3D 0) { + error_report("ioctl %s failed %d", op_name, ret); + } + + return ret; +} +#endif + static coroutine_fn int raw_do_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes, bool blkdev) @@ -3787,6 +4089,13 @@ static BlockDriver bdrv_host_device =3D { #ifdef __linux__ .bdrv_co_ioctl =3D hdev_co_ioctl, #endif + + /* zoned device */ +#if defined(CONFIG_BLKZONED) + /* zone management operations */ + .bdrv_co_zone_report =3D raw_co_zone_report, + .bdrv_co_zone_mgmt =3D raw_co_zone_mgmt, +#endif }; =20 #if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel= __) diff --git a/block/io.c b/block/io.c index 6fa1993374..74bab69b0f 100644 --- a/block/io.c +++ b/block/io.c @@ -3115,6 +3115,47 @@ out: return co.ret; } =20 +int coroutine_fn 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 || bs->bl.zoned =3D=3D BLK_Z_NON= E) { + 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 coroutine_fn 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 || bs->bl.zoned =3D=3D BLK_Z_NONE)= { + 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-io.h b/include/block/block-io.h index 5dab88521d..58f415ab64 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -111,6 +111,15 @@ int coroutine_fn GRAPH_RDLOCK bdrv_co_flush(BlockDrive= rState *bs); int coroutine_fn GRAPH_RDLOCK bdrv_co_pdiscard(BdrvChild *child, int64_t o= ffset, int64_t bytes); =20 +/* Report zone information of zone block device. */ +int coroutine_fn GRAPH_RDLOCK bdrv_co_zone_report(BlockDriverState *bs, + int64_t offset, + unsigned int *nr_zones, + BlockZoneDescriptor *zon= es); +int coroutine_fn GRAPH_RDLOCK bdrv_co_zone_mgmt(BlockDriverState *bs, + BlockZoneOp op, + int64_t offset, int64_t le= n); + bool bdrv_can_write_zeroes_with_unmap(BlockDriverState *bs); int bdrv_block_status(BlockDriverState *bs, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map, diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 150dc6f68f..997d539890 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -712,6 +712,12 @@ struct BlockDriver { int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_load_vmstate)( BlockDriverState *bs, 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 coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_is_inserted)( BlockDriverState *bs); @@ -864,6 +870,21 @@ typedef struct BlockLimits { =20 /* device zone model */ BlockZoneModel zoned; + + /* zone size expressed in bytes */ + uint32_t zone_size; + + /* total number of zones */ + uint32_t nr_zones; + + /* maximum sectors of a zone append write operation */ + int64_t max_append_sectors; + + /* 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 e46a29c3f0..afb9bdf51b 100644 --- a/include/block/raw-aio.h +++ b/include/block/raw-aio.h @@ -28,6 +28,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 | \ @@ -36,7 +38,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/include/sysemu/block-backend-io.h b/include/sysemu/block-backe= nd-io.h index 851a44de96..eb1c1ebfec 100644 --- a/include/sysemu/block-backend-io.h +++ b/include/sysemu/block-backend-io.h @@ -46,6 +46,13 @@ BlockAIOCB *blk_aio_pwritev(BlockBackend *blk, int64_t o= ffset, 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 by= tes, BlockCompletionFunc *cb, void *opaque); void blk_aio_cancel_async(BlockAIOCB *acb); @@ -191,6 +198,17 @@ int co_wrapper_mixed blk_pwrite_zeroes(BlockBackend *b= lk, int64_t offset, int coroutine_fn blk_co_pwrite_zeroes(BlockBackend *blk, int64_t offset, int64_t bytes, BdrvRequestFlags flag= s); =20 +int coroutine_fn blk_co_zone_report(BlockBackend *blk, int64_t offset, + unsigned int *nr_zones, + BlockZoneDescriptor *zones); +int co_wrapper_mixed blk_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); +int co_wrapper_mixed blk_zone_mgmt(BlockBackend *blk, BlockZoneOp op, + int64_t offset, int64_t len); + int co_wrapper_mixed blk_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes); int coroutine_fn blk_co_pdiscard(BlockBackend *blk, int64_t offset, diff --git a/meson.build b/meson.build index c44d05a13f..a1bc310114 100644 --- a/meson.build +++ b/meson.build @@ -1966,6 +1966,7 @@ config_host_data.set('CONFIG_REPLICATION', get_option= ('replication').allowed()) # 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')) @@ -2052,6 +2053,9 @@ config_host_data.set('HAVE_SIGEV_NOTIFY_THREAD_ID', config_host_data.set('HAVE_STRUCT_STAT_ST_ATIM', cc.has_member('struct stat', 'st_atim', prefix: '#include ')) +config_host_data.set('HAVE_BLK_ZONE_REP_CAPACITY', + cc.has_member('struct blk_zone', 'capacity', + prefix: '#include ')) =20 # has_type config_host_data.set('CONFIG_IOVEC', diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index e7a02f5b99..f35ea627d7 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -1730,6 +1730,150 @@ static const cmdinfo_t flush_cmd =3D { .oneline =3D "flush all in-core file state to disk", }; =20 +static inline int64_t tosector(int64_t bytes) +{ + return bytes >> BDRV_SECTOR_BITS; +} + +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", + tosector(zones[i].start), tosector(zones[i].length), + tosector(zones[i].cap), tosector(zones[i].wp), + zones[i].state, 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", @@ -2523,6 +2667,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.40.0 From nobody Tue May 14 12:38:52 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=1682616114; cv=none; d=zohomail.com; s=zohoarc; b=JVBdzy9Yk97ZMy+hSyCCsfMaC5SEai/9a0b/AkZLcHKNbw5FDPQf1bWWexVOnrKtZzWGhfgXOlKfhSNrsIE84Ub2xhee4Miq6wt1S3M2c/bBu4JYsysYJqSpoqFWrbI7EX3tReBz7/0pU2kTHLuKRiiiRaJBzAKx5dSot+90+mA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682616114; h=Content-Type: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=ThsgU5dxftQSrGWB8lAXUWGk9tQClLWkofAITVagcVg=; b=ZT/eXUNo8m0cbWSC0Mi4VdDfNLqErRk+4/aF+/E86Y+LWYLIxwosBdP/hYPZy8b4vdXb3xLDZ8TYb95VjyshFwj6tGOWqPEVANTvXGo92BEgnMIG+5HUROljQVTKvDAchW+SrxSyoyzhJbn73g+PgdktGI50LXkGoNjGDW//dRY= 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 1682616114429293.7891173203209; Thu, 27 Apr 2023 10:21:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ps5Is-0006ru-1G; Thu, 27 Apr 2023 13:21:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ps5Iq-0006p9-07; Thu, 27 Apr 2023 13:21:08 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ps5Io-0007NX-CG; Thu, 27 Apr 2023 13:21:07 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-63b5465fb99so7258066b3a.1; Thu, 27 Apr 2023 10:21:05 -0700 (PDT) Received: from fedlinux.. ([106.84.128.101]) by smtp.gmail.com with ESMTPSA id p1-20020a170902a40100b001a95c7742bbsm8878578plq.9.2023.04.27.10.20.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 10:21:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682616064; x=1685208064; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ThsgU5dxftQSrGWB8lAXUWGk9tQClLWkofAITVagcVg=; b=WrW5NWPkyhijadMPqA8BFyLH3d3lx4DwdYz2tPNwWVRxfE7gf3+slyl1aPkeCfBFH4 nmJ5ViSM2AP4kdVF0nShmIlKL2tUa3m+mBxoASOrr6Pt2V313XIC/N6Cw6pL/F1NiOy5 TPWrmHUHV95FRc6U5fnBwQ3Ut9rNDbyId3maUdxAYfKxvI2OtC1SAJLVPDuq0PjYzczL U9ksrt6aEMWKCeTL0k4H0V6Yi8HGkIqmPa3JdWo4tGCkig+FyzFCDcglkr80JuhZpx5T kpPMfpsjQhJXfwjh+5z9b3I5U9V4WOW0/J0NcvFwTOlETkYKMJXJmcabw92wzmAC/yAK zaKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682616064; x=1685208064; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ThsgU5dxftQSrGWB8lAXUWGk9tQClLWkofAITVagcVg=; b=j7jgkUHbM7rY9KXFjBsxvp6sbuLuXG1KExdIf4ZLWtgyysqiK8i8gjUVryAWvB9Xx5 KWJIQsePIm9ixRcDb3Zwr5hPlfQE3sQ63azaF0yyLr3ag2gAZP//rUJSpV7cSojA14rm +nkq/X/xyOHJNGV9Kw98It1pXuSNqTqdoi6g+aNb61fQvyhfBpNVnQo3+g/3kPVmlm9X S7TqdOrxthCkjNGCzpYYZ3svN7ltHXE3mO532eXXeQ3buG3AqlW9kUKp1m0KMKkNPq9p E4Vpi0NYKp4t4VayNWDb6BwM9+RumMCj4LuIwNerqIE+Ep8FOT99RHafACEkzyH8jQax bXbg== X-Gm-Message-State: AC+VfDwm9cdOd/u3rL9pg3R/ftOUc5Q9MqtNv5WzW9zEvSg0eqahuYYc byA85Ng4ZwWGqa9xvP+NcarPuwIuPAWIcGd+ux4= X-Google-Smtp-Source: ACHHUZ4UuAobScOR45gdyoikjNFY1+aaoPlAkQm7RbzUUeSxs4Bq8LRUj/Grcg+rV02kJt0g/KxmhA== X-Received: by 2002:a05:6a21:7884:b0:ec:88e1:1452 with SMTP id bf4-20020a056a21788400b000ec88e11452mr2804678pzc.62.1682616063696; Thu, 27 Apr 2023 10:21:03 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Kevin Wolf , Fam Zheng , Paolo Bonzini , dlemoal@kernel.org, hare@suse.de, Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , stefanha@redhat.com, dmitry.fomichev@wdc.com, qemu-block@nongnu.org, Sam Li , Damien Le Moal Subject: [PATCH v19 4/8] block/raw-format: add zone operations to pass through requests Date: Fri, 28 Apr 2023 01:20:15 +0800 Message-Id: <20230427172019.3345-5-faithilikerun@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230427172019.3345-1-faithilikerun@gmail.com> References: <20230427172019.3345-1-faithilikerun@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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::42d; envelope-from=faithilikerun@gmail.com; helo=mail-pf1-x42d.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.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, FREEMAIL_REPLY=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1682616115194100001 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 Reviewed-by: Damien Le Moal Reviewed-by: Hannes Reinecke Reviewed-by: Dmitry Fomichev Acked-by: Kevin Wolf Message-id: 20230324090605.28361-5-faithilikerun@gmail.com [Adjust commit message prefix as suggested by Philippe Mathieu-Daud=C3=A9 . --Stefan] Signed-off-by: Stefan Hajnoczi --- block/raw-format.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/block/raw-format.c b/block/raw-format.c index 06b8030d9d..f167448462 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -317,6 +317,21 @@ raw_co_pdiscard(BlockDriverState *bs, int64_t offset, = int64_t bytes) return bdrv_co_pdiscard(bs->file, offset, bytes); } =20 +static int coroutine_fn GRAPH_RDLOCK +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 GRAPH_RDLOCK +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 coroutine_fn GRAPH_RDLOCK raw_co_getlength(BlockDriverState *bs) { @@ -619,6 +634,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.40.0 From nobody Tue May 14 12:38:52 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=1682616116; cv=none; d=zohomail.com; s=zohoarc; b=ij3GBBUx+LEgHEbocW+ZPIIJo8jry23mEqmtLhdMzDU1+onXu1pK5JOXqKfXsL5MjwZu6tGY1jFIDqLI7UD+RIlIHXWUCMxc/CBygdhveLNMvYl4B8FauZCJ4ZCgeNCIxyOBzYdgULGVEgZSoUpov9tzioa8Y4WFajsHUk+0X/w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682616116; h=Content-Type: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=Gc/4qUImTJaRhWCgN51Hl/t4Sfw1zZk3NoffPVKB18k=; b=B6yNu7H3eXfyXmRu72pLmgjnjOg6o+xdsF1t+njrYHoJfjTKt5ga+m0STwy3f+LA/YdRzpPbRDnHMKRx0bZZ6MsDo6XYreybwwWcJ8RCrpRLjldysDmByprvGcWozDLzGr4axJNLeSap3ZDEn+jWhrGFw67NORWrTXbS73msJPU= 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 1682616116296488.80063849724957; Thu, 27 Apr 2023 10:21:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ps5Iz-0006zy-SI; Thu, 27 Apr 2023 13:21:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ps5Iy-0006za-MD; Thu, 27 Apr 2023 13:21:16 -0400 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ps5Iv-0007OT-Ks; Thu, 27 Apr 2023 13:21:16 -0400 Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-518d325b8a2so8582089a12.0; Thu, 27 Apr 2023 10:21:12 -0700 (PDT) Received: from fedlinux.. ([106.84.128.101]) by smtp.gmail.com with ESMTPSA id p1-20020a170902a40100b001a95c7742bbsm8878578plq.9.2023.04.27.10.21.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 10:21:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682616071; x=1685208071; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Gc/4qUImTJaRhWCgN51Hl/t4Sfw1zZk3NoffPVKB18k=; b=rUKCUNIkpF3yt35NzsWzhY9nX2lXHATjWoconCcyXFCisXsmi8w+mmE9nZ3qOzf3NI f2t67SGWCqdmBi5NuAevY7QAINXjgN2Uvqfi5fa4Ae2l2K123ekus6NzxzJ6083F0sV4 Ps/Z3SJQ39aNn0s0hJQ4R7qAF+vEofVzTkbdmyUQjwRXSfEWdflt2UuuNoAMYU8pJmcH 9cqjwXqynNFYOQvcVY5EH6uE9p5kEfpQrFtl6BpFlSmk7up2LtF9rSSxQcDVNehGMDoh +kmSabYvxPTxx471o+/F8AgB1FWZgz3Bz96mgyEEPcAkGdn1BheoFMnwy7LZ1vA32O/1 +4mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682616071; x=1685208071; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Gc/4qUImTJaRhWCgN51Hl/t4Sfw1zZk3NoffPVKB18k=; b=KSIu5jpeliJb1co2ebwH6yyXcsrwaYaDCL3VqXco2EkBxfgXinYTykgXcsmQ2QOlpu ObLm8SFj9UggT8uDcGT3v5Ik47+D4j5qpMIdqCLsiPF+V7wVYrnQP8QT+a4+Vcs4iroC G7qo7ru9p7vtkAPr/kGoCsgiZUCCnODxn8oyQ7HvRMeD0HVz+0BZtL+swVCVb0uh0pOQ 6khZwjI6lpTWiPZKnh0eE+saZm6aAUuFIOwcBfzDVZbVKJ7/IsHyHfAvfLUXGaoTj2iR VVbIFp7+Fg/5AWPowLdBU0FV9Hz2mvFeGYwpILfHVyF9X9tNY1ObVMwBW5Czjbeey/Fy atVQ== X-Gm-Message-State: AC+VfDxYP4szDg2rMd2BasBhzOKtpDqzjRharqOgHHSkb4RyFBF3jjhF 7qkjB2b+s2iyzIlGtBQXjKK4sjLROrggFpHfiEg= X-Google-Smtp-Source: ACHHUZ5pg684E+xApEHo3Y63sLK+Vu6ynI0YQ7bHlkUUMEacfLkDoANJTm7Pr9vuqJBb8WvJ5Xj/fg== X-Received: by 2002:a17:902:e883:b0:1a9:9b92:bd84 with SMTP id w3-20020a170902e88300b001a99b92bd84mr2941867plg.31.1682616071123; Thu, 27 Apr 2023 10:21:11 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Kevin Wolf , Fam Zheng , Paolo Bonzini , dlemoal@kernel.org, hare@suse.de, Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , stefanha@redhat.com, dmitry.fomichev@wdc.com, qemu-block@nongnu.org, Sam Li Subject: [PATCH v19 5/8] block: add zoned BlockDriver check to block layer Date: Fri, 28 Apr 2023 01:20:16 +0800 Message-Id: <20230427172019.3345-6-faithilikerun@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230427172019.3345-1-faithilikerun@gmail.com> References: <20230427172019.3345-1-faithilikerun@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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::531; envelope-from=faithilikerun@gmail.com; helo=mail-pg1-x531.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.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, FREEMAIL_REPLY=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1682616117825100001 Putting zoned/non-zoned BlockDrivers on top of each other is not allowed. Signed-off-by: Sam Li Reviewed-by: Stefan Hajnoczi Reviewed-by: Hannes Reinecke Reviewed-by: Dmitry Fomichev Acked-by: Kevin Wolf Message-id: 20230324090605.28361-6-faithilikerun@gmail.com [Adjust commit message prefix as suggested by Philippe Mathieu-Daud=C3=A9 and clarify that the check is about zoned BlockDrivers. --Stefan] Signed-off-by: Stefan Hajnoczi --- block.c | 19 +++++++++++++++++++ block/file-posix.c | 12 ++++++++++++ block/raw-format.c | 1 + include/block/block_int-common.h | 5 +++++ 4 files changed, 37 insertions(+) diff --git a/block.c b/block.c index 5ec1a3897e..f67317c2b9 100644 --- a/block.c +++ b/block.c @@ -7967,6 +7967,25 @@ 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->bl.zoned =3D=3D BLK_Z_HM) { + /* + * The host-aware model allows zoned storage constraints and random + * write. Allow mixing host-aware and non-zoned drivers. Using + * host-aware device as a regular device. + */ + error_setg(errp, "Cannot add a %s child to a %s parent", + child_bs->bl.zoned =3D=3D BLK_Z_HM ? "zoned" : "non-zon= ed", + 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 3b6575d771..67d4ec6ac5 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -776,6 +776,18 @@ static int raw_open_common(BlockDriverState *bs, QDict= *options, goto fail; } } +#ifdef CONFIG_BLKZONED + /* + * The kernel page cache does not reliably work for writes to SWR zones + * of zoned block device because it can not guarantee the order of wri= tes. + */ + if ((bs->bl.zoned !=3D BLK_Z_NONE) && + (!(s->open_flags & O_DIRECT))) { + error_setg(errp, "The driver supports zoned devices, and it requir= es " + "cache.direct=3Don, which was not specified."); + return -EINVAL; /* No host kernel page cache */ + } +#endif =20 if (S_ISBLK(st.st_mode)) { #ifdef __linux__ diff --git a/block/raw-format.c b/block/raw-format.c index f167448462..1a1dce8da4 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -623,6 +623,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 997d539890..3482cfa79e 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -137,6 +137,11 @@ struct BlockDriver { */ bool is_format; =20 + /* + * 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.40.0 From nobody Tue May 14 12:38:52 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=1682616141; cv=none; d=zohomail.com; s=zohoarc; b=h9b2esWXZru+kJYOqJITudJ65fPyz1ZXNmITe5q8VguDCh9TAtLGNcuzbCe+9IDbX51QtzBeAF+ckC6ZURc5Lh052LJZwLqK2GPJUuWT3P/lmaX9B0KHQyFVCpQukMIETx9Cqkrk3viyAftujVskI2IDuVpyRQmBSOerluWKUtg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682616141; h=Content-Type: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=JwSvm8h+wUZyKdwpWuwbWauyBmol2X4X5Cr48k6rmec=; b=FafUSr/MnV5g9u9a529KcPWA91qGBB3LKfZ6a0CNJzU5ARRlr0pTsZ2mHbISY0yT2tDQM3vAdW3qDk7cO75698fTELdE4mKPYv1eexyGgOFZX2RJgO86buZH30EH/JwC/Ip27iTrafX369HhpoZTE2mjRqluZekz/jcrM7zOY2Q= 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 1682616141517720.4088175674977; Thu, 27 Apr 2023 10:22:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ps5J6-00079N-VH; Thu, 27 Apr 2023 13:21:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ps5J4-00076u-On; Thu, 27 Apr 2023 13:21:22 -0400 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ps5J2-0007PJ-Uj; Thu, 27 Apr 2023 13:21:22 -0400 Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-51b6d0b9430so6577168a12.2; Thu, 27 Apr 2023 10:21:20 -0700 (PDT) Received: from fedlinux.. ([106.84.128.101]) by smtp.gmail.com with ESMTPSA id p1-20020a170902a40100b001a95c7742bbsm8878578plq.9.2023.04.27.10.21.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 10:21:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682616079; x=1685208079; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JwSvm8h+wUZyKdwpWuwbWauyBmol2X4X5Cr48k6rmec=; b=UQQX1LEdZVntjooiY5d+CC2PjIOR7mXVz4ZQnq+a2He9Pz2qKt/krvrMrARbwwWbjA mQwW5j9ALmqAnOmGB18YVdWgrxT4KXcxzigiEZ2DJfnZ85bvbeLkyZnVWuwESEIiEo+X AaTPK/0TeWj6fjCv56zi5ewx1mMe9q6icwySApjCRLuX18SqRkrbJkGQ8ijSB/LuE35Y UHaBAIGmDtfqZthIO4I6daSHlBJ4wEO8RdRLCI9dtnspeQrxRVb05AIdbyNeoNrAK7Ab 2YzunGs6CFgD/garOGqhdsKGKJPp4r8nLyy+hwEODlbxP/+GnHL9uyQ0vnLnKBBYAK+e il8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682616079; x=1685208079; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JwSvm8h+wUZyKdwpWuwbWauyBmol2X4X5Cr48k6rmec=; b=gWgDXgIMtS/9jzEavfhR4dsLwuL3lP3zLeLshJvMR1z00oM662em+0E2JfqVM050aq Xppq6fZ0FdFaavy+chbzoTUNFYJxuI9AbWPhNH/bSvLKAQgzA1DrCnOnVFPplOIf5YVK FD5M5Yl7v+/Pc6Tb2FgJ4vmJO/Ce60lGQ7rG+tgjfdwY+MO9C/7ezBeiRkhiL6/SwuMA +Gd1hRsOxjPTm1ik+hsvrGfp64nUKWIUcLr+JdkwwROIHh9BhEnVhQpCa8F0ZXXFkcSK zjO5oRC3hEohCMvLVHhBF75gpBRt4GufFDjmPAmP4ibeTSXhOZFZBdc/0ZxyzWSLMUxE qSGQ== X-Gm-Message-State: AC+VfDzOYjnkLHorfaFYHGXVa1o8285dt8PmxGfRUru1hieW+zheXVUi KXMps7Hz6kFF7gu4l52YEyAt4A0breWas7wzItI= X-Google-Smtp-Source: ACHHUZ7q0kPjm+53tE336aSOxFBp2fC12E6msNd+/j9hvZDjikw5Sf+OEtMQoxjcXjrZ19q+A7+03Q== X-Received: by 2002:a17:902:c712:b0:1a5:2621:34cd with SMTP id p18-20020a170902c71200b001a5262134cdmr1811362plp.39.1682616078298; Thu, 27 Apr 2023 10:21:18 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Kevin Wolf , Fam Zheng , Paolo Bonzini , dlemoal@kernel.org, hare@suse.de, Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , stefanha@redhat.com, dmitry.fomichev@wdc.com, qemu-block@nongnu.org, Sam Li Subject: [PATCH v19 6/8] iotests: test new zone operations Date: Fri, 28 Apr 2023 01:20:17 +0800 Message-Id: <20230427172019.3345-7-faithilikerun@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230427172019.3345-1-faithilikerun@gmail.com> References: <20230427172019.3345-1-faithilikerun@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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::52a; envelope-from=faithilikerun@gmail.com; helo=mail-pg1-x52a.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.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, FREEMAIL_REPLY=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1682616143728100002 The new block layer APIs of zoned block devices can be tested by: $ tests/qemu-iotests/check zoned Run each zone operation on a newly created null_blk device and see whether it outputs the same zone information. Signed-off-by: Sam Li Reviewed-by: Stefan Hajnoczi Acked-by: Kevin Wolf Message-id: 20230324090605.28361-7-faithilikerun@gmail.com [Adjust commit message prefix as suggested by Philippe Mathieu-Daud=C3=A9 . --Stefan] Signed-off-by: Stefan Hajnoczi --- tests/qemu-iotests/tests/zoned | 89 ++++++++++++++++++++++++++++++ tests/qemu-iotests/tests/zoned.out | 53 ++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100755 tests/qemu-iotests/tests/zoned create mode 100644 tests/qemu-iotests/tests/zoned.out diff --git a/tests/qemu-iotests/tests/zoned b/tests/qemu-iotests/tests/zoned new file mode 100755 index 0000000000..56f60616b5 --- /dev/null +++ b/tests/qemu-iotests/tests/zoned @@ -0,0 +1,89 @@ +#!/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 -n 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 + +sudo -n true || \ + _notrun 'Password-less sudo required' + +IMG=3D"--image-opts -n driver=3Dhost_device,filename=3D/dev/nullb0" +QEMU_IO_OPTIONS=3D$QEMU_IO_OPTIONS_NO_FMT + +echo "Testing a null_blk device:" +echo "case 1: if the operations work" +sudo -n modprobe null_blk nr_devices=3D1 zoned=3D1 +sudo -n chmod 0666 /dev/nullb0 + +echo "(1) report the first zone:" +$QEMU_IO $IMG -c "zrp 0 1" +echo +echo "report the first 10 zones" +$QEMU_IO $IMG -c "zrp 0 10" +echo +echo "report the last zone:" +$QEMU_IO $IMG -c "zrp 0x3e70000000 2" # 0x3e70000000 / 512 =3D 0x1f380000 +echo +echo +echo "(2) opening the first zone" +$QEMU_IO $IMG -c "zo 0 268435456" # 268435456 / 512 =3D 524288 +echo "report after:" +$QEMU_IO $IMG -c "zrp 0 1" +echo +echo "opening the second zone" +$QEMU_IO $IMG -c "zo 268435456 268435456" # +echo "report after:" +$QEMU_IO $IMG -c "zrp 268435456 1" +echo +echo "opening the last zone" +$QEMU_IO $IMG -c "zo 0x3e70000000 268435456" +echo "report after:" +$QEMU_IO $IMG -c "zrp 0x3e70000000 2" +echo +echo +echo "(3) closing the first zone" +$QEMU_IO $IMG -c "zc 0 268435456" +echo "report after:" +$QEMU_IO $IMG -c "zrp 0 1" +echo +echo "closing the last zone" +$QEMU_IO $IMG -c "zc 0x3e70000000 268435456" +echo "report after:" +$QEMU_IO $IMG -c "zrp 0x3e70000000 2" +echo +echo +echo "(4) finishing the second zone" +$QEMU_IO $IMG -c "zf 268435456 268435456" +echo "After finishing a zone:" +$QEMU_IO $IMG -c "zrp 268435456 1" +echo +echo +echo "(5) resetting the second zone" +$QEMU_IO $IMG -c "zrs 268435456 268435456" +echo "After resetting a zone:" +$QEMU_IO $IMG -c "zrp 268435456 1" + +# success, all done +echo "*** done" +rm -f $seq.full +status=3D0 diff --git a/tests/qemu-iotests/tests/zoned.out b/tests/qemu-iotests/tests/= zoned.out new file mode 100644 index 0000000000..b2d061da49 --- /dev/null +++ b/tests/qemu-iotests/tests/zoned.out @@ -0,0 +1,53 @@ +QA output created by zoned +Testing a null_blk device: +case 1: 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, [ty= pe: 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, [ty= pe: 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, [ty= pe: 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 --=20 2.40.0 From nobody Tue May 14 12:38:52 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=1682616157; cv=none; d=zohomail.com; s=zohoarc; b=RHslYxiB8ZXOi8Vw5hVAb/n1HgEYZXD8tqwu82bWgnkPO8zkGyHh3UHNVkz4rgDnu2/MxfH2EWH6Ig/6WAyOv1AccHTFFy9kRF6sM2/R1j5YL7ngaIFpQjY39FiR/9htXH4OlTnJGOqq/UgDMiD6npFwqXyp2hxWVw9PDI0JUq8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682616157; 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=up0Aat6c1cxPVKLFJNe82cGl0KC/DnBejeUsU/iTVQg=; b=MT0KeQM/y1ipZUGzDC/5MaIKnxyiXsu+tYI+9RJPRAMiYm3UqTc1+lxRfFew4ylUi/icaYw43TF+ZxE6e31GvMaqWnUIQaOFUQjfmoThHGeF8SotXg+kbuHvi/GL1K0oEvPxR4Qn9wsW15i38LUg4kkHJMvE/4orISI5YRZqYHE= 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 1682616156596914.199793607118; Thu, 27 Apr 2023 10:22:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ps5JD-0007oY-Kv; Thu, 27 Apr 2023 13:21:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ps5JC-0007kW-IJ; Thu, 27 Apr 2023 13:21:30 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ps5JA-0007RT-VG; Thu, 27 Apr 2023 13:21:30 -0400 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1a9253d4551so68386295ad.0; Thu, 27 Apr 2023 10:21:28 -0700 (PDT) Received: from fedlinux.. ([106.84.128.101]) by smtp.gmail.com with ESMTPSA id p1-20020a170902a40100b001a95c7742bbsm8878578plq.9.2023.04.27.10.21.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 10:21:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682616087; x=1685208087; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=up0Aat6c1cxPVKLFJNe82cGl0KC/DnBejeUsU/iTVQg=; b=gmaG6OPYRke/elocQbjhbcbY08x0sdtqj6lSVUuM3pf70UZJasVclFg0i+KZVR9Y+V dBJjYQuMtIuveBCBBlS57tcvTRfol2MgOfNvLF77ZjTnhxAjG4lJF8aqp3FcQjvsyitF wWiltgbTprmYksLApVeFh3vEaw8RTFkT47boSco2DReIHvT2Qijz7ONvGspe+pbptHXx zwYcQs2dyhaWgOdiGB7UjaYcg/nTTeKpXsQL/8y3WstfmrL5enZDLczEEB8O832LV9UK i9NL4pXpvIxNqfxNeVoypJ269wSIh8NGL+Zd2N/MMtcPi2Kzq1m3nGog2cKX+8l4GytK FgFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682616087; x=1685208087; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=up0Aat6c1cxPVKLFJNe82cGl0KC/DnBejeUsU/iTVQg=; b=hlrfk4Hu7ISwjNfynQe3zp7IvwgVTqX43S7r8tnuRQkyyVtJkhziXirqbvD4qJZP8y 5fGcc7PFufyVBfcUdq24m/7pvZgG0dm2OBw+CGWT+/e/ekG9Vu+RwQr13yLgXhHwaRGx nEwe0glnPBMkbSP2GZOOjoKAH5DlvGT7qwwc0/JPJeB9GxAPQ7FMpMLmGwRWEznQEqYw cJI71hCdHQTzcTNDmhaD07/r/CN8zQ424gSnE7AEbej6/ngVBmkOxgASBA8hz2oTEk13 A5m3ex7+1AykmYyNKWbNzIk/SZhtw/66j9hM+VgDlww8j2L+uGEMhwbPoOz4SFW0dYsO AI5g== X-Gm-Message-State: AC+VfDxbPrfnJbMZmUqQdUMGJhyJGhKE1udhaL4Uw69/FtQR9IC5T6Ix 3//8PJblSbHSdYoRUz0GPFVIIuTMfiBhUcqw8dY= X-Google-Smtp-Source: ACHHUZ6E3V5o5/oH9lXmwM08xUG90NJa2xeRtwF7mRfJv4cgFtYsyVx+Qka9oIYBQzb4ZQWqsWXY1g== X-Received: by 2002:a17:902:ce89:b0:1a5:2db2:2bb with SMTP id f9-20020a170902ce8900b001a52db202bbmr2887145plg.15.1682616086518; Thu, 27 Apr 2023 10:21:26 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Kevin Wolf , Fam Zheng , Paolo Bonzini , dlemoal@kernel.org, hare@suse.de, Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , stefanha@redhat.com, dmitry.fomichev@wdc.com, qemu-block@nongnu.org, Sam Li Subject: [PATCH v19 7/8] block: add some trace events for new block layer APIs Date: Fri, 28 Apr 2023 01:20:18 +0800 Message-Id: <20230427172019.3345-8-faithilikerun@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230427172019.3345-1-faithilikerun@gmail.com> References: <20230427172019.3345-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::62e; envelope-from=faithilikerun@gmail.com; helo=mail-pl1-x62e.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.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, FREEMAIL_REPLY=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1682616157758100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Sam Li Reviewed-by: Stefan Hajnoczi Reviewed-by: Dmitry Fomichev Acked-by: Kevin Wolf Message-id: 20230324090605.28361-8-faithilikerun@gmail.com Signed-off-by: Stefan Hajnoczi --- block/file-posix.c | 3 +++ block/trace-events | 2 ++ 2 files changed, 5 insertions(+) diff --git a/block/file-posix.c b/block/file-posix.c index 67d4ec6ac5..701acddbca 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -3271,6 +3271,7 @@ static int coroutine_fn raw_co_zone_report(BlockDrive= rState *bs, int64_t offset, }, }; =20 + trace_zbd_zone_report(bs, *nr_zones, offset >> BDRV_SECTOR_BITS); return raw_thread_pool_submit(handle_aiocb_zone_report, &acb); } #endif @@ -3337,6 +3338,8 @@ static int coroutine_fn raw_co_zone_mgmt(BlockDriverS= tate *bs, BlockZoneOp op, }, }; =20 + trace_zbd_zone_mgmt(bs, op_name, offset >> BDRV_SECTOR_BITS, + len >> BDRV_SECTOR_BITS); ret =3D raw_thread_pool_submit(handle_aiocb_zone_mgmt, &acb); if (ret !=3D 0) { error_report("ioctl %s failed %d", op_name, ret); diff --git a/block/trace-events b/block/trace-events index 48dbf10c66..3f4e1d088a 100644 --- a/block/trace-events +++ b/block/trace-events @@ -209,6 +209,8 @@ file_FindEjectableOpticalMedia(const char *media) "Matc= hing using %s" file_setup_cdrom(const char *partition) "Using %s as optical disc" file_hdev_is_sg(int type, int version) "SG device found: type=3D%d, versio= n=3D%d" file_flush_fdatasync_failed(int err) "errno %d" +zbd_zone_report(void *bs, unsigned int nr_zones, int64_t sector) "bs %p re= port %d zones starting at sector offset 0x%" PRIx64 "" +zbd_zone_mgmt(void *bs, const char *op_name, int64_t sector, int64_t len) = "bs %p %s starts at sector offset 0x%" PRIx64 " over a range of 0x%" PRIx64= " sectors" =20 # ssh.c sftp_error(const char *op, const char *ssh_err, int ssh_err_code, int sftp= _err_code) "%s failed: %s (libssh error code: %d, sftp error code: %d)" --=20 2.40.0 From nobody Tue May 14 12:38:52 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=1682616171; cv=none; d=zohomail.com; s=zohoarc; b=Kv6f8eW++MTqqqrj+w0QxHue9cOV17cHMPUco7lDuLFyczRDfph0lYO002bcn7rfSEywf60ZJRmFhKlBpT44L1hc1JeGHN6b+x28p3Elcccu2OA4y9Nwz4NERGDxIvXGGSvGMV5657YMa2XJmXSbT/Wf145uAI9ILG3bO9I2ma0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682616171; 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=c1c0sfqfBQALkwLl03dvFSnDNE5/8ZWsJGfmKl5eHJY=; b=D/E8mHSOKxmiqvE9DZteALwIggkVh5BcCSer4aNZOc3ErpUGq77WEfeBEhXKKIbT7DEAG1aS0DfFNn9HaM/1JgaBjN+mDLmxbJPrqRbWyBI12lPOVCMkEo6wHr/EbK2ozoF0EzSI0XZ1gsx1c19QbQYxgHycZtjGFsmXFr6obZk= 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 168261617116869.30974415075923; Thu, 27 Apr 2023 10:22:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ps5JQ-0007zE-Ql; Thu, 27 Apr 2023 13:21:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ps5JO-0007ys-UR; Thu, 27 Apr 2023 13:21:43 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ps5JJ-0007SJ-NT; Thu, 27 Apr 2023 13:21:42 -0400 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1a920d484bdso68669855ad.1; Thu, 27 Apr 2023 10:21:36 -0700 (PDT) Received: from fedlinux.. ([106.84.128.101]) by smtp.gmail.com with ESMTPSA id p1-20020a170902a40100b001a95c7742bbsm8878578plq.9.2023.04.27.10.21.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 10:21:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682616095; x=1685208095; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=c1c0sfqfBQALkwLl03dvFSnDNE5/8ZWsJGfmKl5eHJY=; b=ekLgshXtRMhvbKiBIJvvghALEzekVLJr0x++GHVNahlIBxv8u957ByJiRyIVhTy2Wz FHZxpDqslMJZjKAWZx02dJOAiDTSPKqx2P2jv6u6qkPwhge+TjNke7JGRHGBxDkm6nxz 3gkzgLZeIDlhq2bg5RkI4SOou/2vwJDOWC1TxjD0kqaH/bLSClR1FWC5v6KJa3+y3tBd EiZEoIkIJKuzc4BwD+smvPfIX9IGog+eYsZ3aLUY6TmA9ULLsSgFGNCUCo/wqePxaFyt epDInIthOx9Wfr6giyUW51g6vgG1EXD/G2c7ZQKN4S6ZW/716eNahGD/cl3Xsi2O5IC9 Wcgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682616095; x=1685208095; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c1c0sfqfBQALkwLl03dvFSnDNE5/8ZWsJGfmKl5eHJY=; b=R+2Zp2o+Sbap/c9GCRLJ7DyBv/JAkQqPwSLFPC0fN55ki2URRh75kfdduIasVE1oQQ uYHOwHTT9EzkPkiiJ83A+2VM7J/RHDhWQObJUQF3QvgBv6pW7FTemQlPIfWJaiqd1qIg uCXU4HOgNXQ016Z++KbRCizS7NI50pRTzPXrn1fNUFwXvc8LZP2Vl6u5bsJStNgAacLW WZVDvIpFI3n9D8Eg4aNHDHNsvxkogU9moG8smByjh3k+X9tNdMoiAVH09Fn4zwaXJhLv GDqopSMayOq5R/kQbqywej0HysJKFWDHUNveBPmNjZddp+3JyfHj1vRNeXeIBOznj/dY b2hQ== X-Gm-Message-State: AC+VfDwxsswLCOZ6/+7lmg+oqcKMc/kx9yo2X1cwE4TfIZAon1nTuPT0 6MsgmMfzllX2hvWvSFF+R1yqEasva7foNVoYEX8= X-Google-Smtp-Source: ACHHUZ6hDNIsnj0OoPm+vYUxrTDz1Mwju6fVdiOrOfntFg2WRFpWi6NRap2Uil8k5omlYHRSJDJ4UA== X-Received: by 2002:a17:903:200c:b0:1a9:8ddd:8215 with SMTP id s12-20020a170903200c00b001a98ddd8215mr1766773pla.4.1682616094210; Thu, 27 Apr 2023 10:21:34 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Kevin Wolf , Fam Zheng , Paolo Bonzini , dlemoal@kernel.org, hare@suse.de, Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , stefanha@redhat.com, dmitry.fomichev@wdc.com, qemu-block@nongnu.org, Sam Li , Damien Le Moal Subject: [PATCH v19 8/8] docs/zoned-storage: add zoned device documentation Date: Fri, 28 Apr 2023 01:20:19 +0800 Message-Id: <20230427172019.3345-9-faithilikerun@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230427172019.3345-1-faithilikerun@gmail.com> References: <20230427172019.3345-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::635; envelope-from=faithilikerun@gmail.com; helo=mail-pl1-x635.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.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, FREEMAIL_REPLY=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1682616171807100004 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 Reviewed-by: Damien Le Moal Reviewed-by: Dmitry Fomichev Acked-by: Kevin Wolf Message-id: 20230324090605.28361-9-faithilikerun@gmail.com [Add index-api.rst to fix "zoned-storage.rst:document isn't included in any toctree" error. --Stefan] Signed-off-by: Stefan Hajnoczi --- docs/devel/index-api.rst | 1 + docs/devel/zoned-storage.rst | 43 ++++++++++++++++++++++++++ docs/system/qemu-block-drivers.rst.inc | 6 ++++ 3 files changed, 50 insertions(+) create mode 100644 docs/devel/zoned-storage.rst diff --git a/docs/devel/index-api.rst b/docs/devel/index-api.rst index 60c0d7459d..7108821746 100644 --- a/docs/devel/index-api.rst +++ b/docs/devel/index-api.rst @@ -12,3 +12,4 @@ generated from in-code annotations to function prototypes. memory modules ui + zoned-storage diff --git a/docs/devel/zoned-storage.rst b/docs/devel/zoned-storage.rst new file mode 100644 index 0000000000..6a36133e51 --- /dev/null +++ b/docs/devel/zoned-storage.rst @@ -0,0 +1,43 @@ +=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) divide the LBA space into block regions called = zones +that are larger than the LBA size. They can only allow sequential writes, = which +can reduce write amplification in SSDs, and potentially lead to higher +throughput and increased 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 supports three zoned storage models: +- BLK_Z_HM: The host-managed zoned model only allows sequential writes acc= ess +to zones. It supports ZBD-specific I/O commands that can be used by a host= to +manage the zones of a device. +- BLK_Z_HA: The host-aware zoned model allows random write operations in +zones, making it backward compatible with regular block devices. +- BLK_Z_NONE: The non-zoned model has no zones support. It includes both +regular and drive-managed ZBD devices. ZBD-specific I/O commands are not +supported. + +The block device information resides 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, to test zone_report on a null_blk device using qemu-io is: +$ path/to/qemu-io --image-opts -n driver=3Dhost_device,filename=3D/dev/nul= lb0 +-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..105cb9679c 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 host_device, + node-name=3Ddrive0,filename=3D/dev/nullb0,cache.direct=3Don`` to pass th= rough + ``/dev/nullb0`` as ``drive0``. + Windows ^^^^^^^ =20 --=20 2.40.0