From nobody Thu May 9 02:22:50 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=1683521839; cv=none; d=zohomail.com; s=zohoarc; b=Ofn3jYtJTKfhz7MRPWIN6EV+shuLPLoO/2DWRfZfV5OPxh+SV9s7NE1vU/nN94R0sC8xSByMfhVlhnVV/DcVprkkSIwFIHmFCkJXogmY6tAOGZWROf0NP1YXdTFgV0eN/A2OWH7Rz/L+uKJxnePo6ceFLVc5tmfWFKWLdXa+5ro= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683521839; 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=CpysJ3NtTUDo6s+rpYHfL1DLIMlkvrG+sQvllgoW10qyLMXbSD0rpj4mw5/PS921imyjervpRX87MSfsOsa+FQ/F2XgHQix/g3yQiwQz15QRv6UFYweFs7asVsj3qqwnDwYQQpXcOXi41DsF0AdzlkxYWol2e9FQT1EbyFUXquc= 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 1683521839117112.33785115617252; Sun, 7 May 2023 21:57:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pvsue-00017k-DL; Mon, 08 May 2023 00:55: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 1pvsuc-00015D-PG; Mon, 08 May 2023 00:55:50 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pvsub-0005Sh-5n; Mon, 08 May 2023 00:55:50 -0400 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1aaed87d8bdso27665675ad.3; Sun, 07 May 2023 21:55:48 -0700 (PDT) Received: from fedlinux.. ([106.84.128.239]) by smtp.gmail.com with ESMTPSA id bg12-20020a1709028e8c00b0019ef86c2574sm6007112plb.270.2023.05.07.21.55.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 May 2023 21:55:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683521747; x=1686113747; 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=N3I+a2J9v2mbzObGHYJbJ17RnQpzUA997dNUvxRv4Uo6bb1Jy1vv4BpyqF2+tGcN9K 37NQmHCNmjKeQT917wg8K2qfsp0KRXfVQ13FaAfL8joakpuyAKQsPFRLqxS9Qs4awMv1 NgUagzypDAlcArbM/qm4cz1kMv+qE7WG45n65++ZfjVkv4bbv+EjIMIdo1FbhVlHd0wg uZbkvt/+ENItukcB0F/mzkSSKwYdt1Dv1kl38AxK1D29ANoRDCH7mLBtYwHz/4ZOLAe0 mv4pqGwgo1BNd6nhxmVXy+X4TRWAkwkP47ZbldlAUHDzlyR2XVzjksKiCVpbCY8aCMG4 Kkig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683521747; x=1686113747; 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=jFcXCiCmyuA9z9KPivOWssu8uMHNiflFOiqt9oUiQ7+yHah6nUmlsWiDB/G9+0hnQP iNA4URbrOl0QXEgpcgwXjN/LGIR5Bv2GNCYI8NuZpz3UWn0zgNrJhmW0codilSJw1kFA l8QOXH3/BC7FyDTyUGbPro/wuU51uz2D9Ury1Ana7njvK0N95ZBF8a2vvtTDCzk2gszA aV59pJVycK0WIK7wI/uCb0QEmI8gLnhWnwKSJ2AthPf49a3alkWH9FS+7v+KXWQyJfMq ghuId0Pnif7QX5/B60q+IEsKTyirzi9ZNjPJlWr8vgUyVv/HCSr+/wv8ZzM57u6Wl7cE uKZw== X-Gm-Message-State: AC+VfDwa6+pcKJrlmhN63pKo6KpV1jQbPBJsb9v9JkwM5upMsdvmhBcU +FJ5tfj5ibgXiNby/cH2j7jjwfp060ZrYPM+ X-Google-Smtp-Source: ACHHUZ7ULhghDvE7TxeiWyxPo98We1NtsknussT6AUWnVBjlu27ZOlu5rYEDg0v3YtmuzWfWxb2a2A== X-Received: by 2002:a17:902:c115:b0:1a0:4ebd:15d5 with SMTP id 21-20020a170902c11500b001a04ebd15d5mr8862789pli.67.1683521746659; Sun, 07 May 2023 21:55:46 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , qemu-block@nongnu.org, Hanna Reitz , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , dmitry.fomichev@wdc.com, Fam Zheng , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Kevin Wolf , Thomas Huth , dlemoal@kernel.org, hare@suse.de, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Sam Li , Damien Le Moal Subject: [PATCH v20 1/8] block/block-common: add zoned device structs Date: Mon, 8 May 2023 12:55:26 +0800 Message-Id: <20230508045533.175575-2-faithilikerun@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230508045533.175575-1-faithilikerun@gmail.com> References: <20230508045533.175575-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::630; envelope-from=faithilikerun@gmail.com; helo=mail-pl1-x630.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: 1683521839546100001 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 Thu May 9 02:22:50 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=1683521808; cv=none; d=zohomail.com; s=zohoarc; b=gJsWMzufY53Jdi+WPqwJFpgyzgk+ZsunG34TtC6KhVE8Cs6/cW7PnjpcbsaCST0Q6FA1pYDJor7ftxuBSsqWJ0QQC0hu2e1L2+Lg6zhNo372mx3bG+iNTWF50Ct+JBIdE7oVEWKBVbsB4mf7hDzF73s2qYbmnjiKgfc58VJDFT4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683521808; 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=vLJHiZfMCqd1hJDFnNOvsbwumv03fXU04zOtqhLQfSk=; b=e2awKDLjF3SnSLD2wSuqNqjSkajeOqs3n3EWp+fPZOx+qOS0+wMLimC4T6UFI5n2hcD2XcG9HjAfvuGvPKHPVKBrU2BQqlLEqQ7JvLFYZkqdhCgko7HbRp8QlbigBtcwIIYKmaLA9/sIwzziCEPKrLIy/sDCANKgUwCjRP45+zM= 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 1683521808387358.87897787215206; Sun, 7 May 2023 21:56:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pvsuj-00018c-Ki; Mon, 08 May 2023 00:55:57 -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 1pvsui-00017t-2v; Mon, 08 May 2023 00:55:56 -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 1pvsug-0005VU-B5; Mon, 08 May 2023 00:55:55 -0400 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1aae46e62e9so28395825ad.2; Sun, 07 May 2023 21:55:53 -0700 (PDT) Received: from fedlinux.. ([106.84.128.239]) by smtp.gmail.com with ESMTPSA id bg12-20020a1709028e8c00b0019ef86c2574sm6007112plb.270.2023.05.07.21.55.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 May 2023 21:55:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683521752; x=1686113752; 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=vLJHiZfMCqd1hJDFnNOvsbwumv03fXU04zOtqhLQfSk=; b=LMQ9o5QY+aqSw5aqvZamY4eRfUVhj2KPP7ul0Vivi4B/wrDeHJqQmu8k5WzvjVIIul rFyP/bpQuHM60Mxb6AuRqkbz4cSJBsDb3ehCl4IH1MLFowNtL5AUdTuQ/dR6kL5dLJ5m x8HXGECAbfbrG4RlIO1VY8eY8KdC4djiaOAci5RMg/XNX4sIN4kH9d460lnvEDGDjY8Q xk6/jkmK53toO2ki5Zbj5kbxbmn8ToJ22mh509baAKTuVaTZnIq5x/v5Ud6Ou41VJHzr ewE68TEcYxD5eUedKy1S/oHSXUgfGqwOE8qTY7gMX7gI+htAoZaiRQV3MNmudbEOe0TK oL5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683521752; x=1686113752; 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=vLJHiZfMCqd1hJDFnNOvsbwumv03fXU04zOtqhLQfSk=; b=jHGYBY/y1lQZXQS5+HohUg9ifw45R05V0Z7ay3o73voAlvUieWT2gQ0BzEwuL7Gz5V aO+Kdh4llms6EXrlC6hyLGZzKwMb5vaQzO4Zd13P0jsZDiP2esXzVcnlA4J1CBXeWfzz vuj2h4SjNvhV1RNGOnyj8wjQbDMvUxIMnxUyucPkoEDMVKseBbV9z28BAL5S7+xoGG7g GuASy6jBM0PYZKJwRn78D01Nwl2eOkfXGbprWNPchQa1eYDWlDuMtmSJCvfkqMpRawvY L6iUevV34ivS4UMqJu4jPd9fhFAeGLURnpmUS0UGA3+Z+YpYB2KgzA5RmU8aekBkQ8Br I3Xg== X-Gm-Message-State: AC+VfDwisHUdwUkCHURAm5vjmPC3tTNpSelawDAKNG0KFw+/mm9w0XUH xM3gYA8K77jvY8GhZoXN4tZkKt7wQU2vl8fS X-Google-Smtp-Source: ACHHUZ47ZdXuVhkFR8XoR5+KJNsBeuOsGN+C8acS0P/DfMjXgONvN1/9T9S5iOVl/RsZpYPgec/t9A== X-Received: by 2002:a17:902:c40b:b0:1aa:fd48:f5e2 with SMTP id k11-20020a170902c40b00b001aafd48f5e2mr12298739plk.32.1683521751836; Sun, 07 May 2023 21:55:51 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , qemu-block@nongnu.org, Hanna Reitz , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , dmitry.fomichev@wdc.com, Fam Zheng , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Kevin Wolf , Thomas Huth , dlemoal@kernel.org, hare@suse.de, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Sam Li , Damien Le Moal Subject: [PATCH v20 2/8] block/file-posix: introduce helper functions for sysfs attributes Date: Mon, 8 May 2023 12:55:27 +0800 Message-Id: <20230508045533.175575-3-faithilikerun@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230508045533.175575-1-faithilikerun@gmail.com> References: <20230508045533.175575-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::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: 1683521809090100005 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 | 127 ++++++++++++++++++++++--------- include/block/block_int-common.h | 3 + 2 files changed, 96 insertions(+), 34 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index c7b723368e..97c597a2a0 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1202,60 +1202,117 @@ 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. + */ #ifdef CONFIG_LINUX - char buf[32]; - const char *end; - char *sysfspath =3D NULL; +static int get_sysfs_str_val(struct stat *st, const char *attribute, + char **val) { + 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; +} +#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. + */ +#ifdef CONFIG_LINUX +static long get_sysfs_long_val(struct stat *st, const char *attribute) +{ + 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; +} +#endif + +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 } =20 +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 +1354,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 Thu May 9 02:22:50 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=1683521856; cv=none; d=zohomail.com; s=zohoarc; b=TWpGbxlL0x2a2BQhlPf1xCneRnoOMLp1ulQ23SBDDPe72oYEo9fy+AgPSDGpxo65wbhqwXbssv7WGjPSfZrth7eCakRq6S7ueccHcpABz8InDT+jMKW1egH026W7K8R5aSUNzGlvy2bEs1WKVfGSJUJ7LR274P4kTtR23KGrz7Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683521856; 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=MKvHEqz9uiUJSDMEfC7SpVSVGWRYt+mG7nz3EA552mg=; b=Uv6fIyaU7iiwE0VO6HKUer5wQPmoaJqkrjZiM7ENwi0Kf72iM8KzEpAVDCy1HXXbA3oHPS0CId8/STwlZRvik/XJdZDxdWAGs72MoGmmmvZy7LaP2IdNne7wK/+BdTS3S6yfOGqve/RmWlWexTH8nOJeBRPyYzB8aGfP29bGdmQ= 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 1683521856962683.8355805852303; Sun, 7 May 2023 21:57:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pvsuq-000198-Eg; Mon, 08 May 2023 00:56: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 1pvsuo-00018o-Bw; Mon, 08 May 2023 00:56:02 -0400 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pvsul-0005Wf-Cq; Mon, 08 May 2023 00:56:02 -0400 Received: by mail-pg1-x52f.google.com with SMTP id 41be03b00d2f7-51b661097bfso2789925a12.0; Sun, 07 May 2023 21:55:58 -0700 (PDT) Received: from fedlinux.. ([106.84.128.239]) by smtp.gmail.com with ESMTPSA id bg12-20020a1709028e8c00b0019ef86c2574sm6007112plb.270.2023.05.07.21.55.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 May 2023 21:55:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683521757; x=1686113757; 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=MKvHEqz9uiUJSDMEfC7SpVSVGWRYt+mG7nz3EA552mg=; b=d2Mv504pLj0yzZ+8a5rRIewiVcAHRtuk+sBPLSkT/kFP63ROOI1omVZ4vLpdrTxaV1 6e8OeNiB4G+acVD0qsMtl2vpXIXSapMCGdtOm/y2dRbvULudZgc2Mk1NxonQ0gvMh+EZ eiSJjD2ikUINMQtdqER+Omj1CV94e/B33VNqeGmOfg3YIkNAXxiS84ED0/2OOlM3T1v5 KXfq1g83m3aWbV7cnOY0o/JuYO3IwD89igc7v0koaNfHc5da8fKVhEhjFcyULCGrWQSW moxdTySWWZ6ES7OOgN6E+Po6fEKOBPHD+EyTunxRyACymh1WmpjrR8FioJZtmfWkV93F NVRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683521757; x=1686113757; 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=MKvHEqz9uiUJSDMEfC7SpVSVGWRYt+mG7nz3EA552mg=; b=R58Cvc8ek4TLiKNKX3CjcVIzwnTO1deAhH+hZ/srjwYJN2lPU7xonY6otld9G+R9Kl NFNWspefr/a9ITs2BceK8WKmpolJvycpIeJUK2kmRo3VhJb7QmIGbRr8ItRG/jiXLHeT 3sUPEHiVZtjMwpS2QDy+lxNMcpjJPzvPkJBl62UivUIzhqbaDO2hXcr8m8REwC1mXzaf UTDIv9eE+wkoSJX+pX4vM9rhXp/5LHf5CtOa0v9jWJJaEDUMmN5Utj1H5oiwQ2wnCkZL xQwwieoc9NhSj2pdpC8V2mG6vjGJqXlVmUMNgDcOkDPiwB2DGwg2AFIH8x4ixgSpkVoQ Jzmg== X-Gm-Message-State: AC+VfDxRC2Sne3nMTm/wkFgjTE08sJLmNHXALdQATxfR2l254U87pwxt bbwbjROrNwEYvUHT8tx1D2JDSZ9Dk2eeuAn9 X-Google-Smtp-Source: ACHHUZ5D6QIetSL+aQiuC65BegQ0jvb4iQ8w38yakOcAwTx0wGnMwNOh/9EliG1ZjgqidtlhbZvMgQ== X-Received: by 2002:a17:903:2344:b0:1ac:6a6f:2dc3 with SMTP id c4-20020a170903234400b001ac6a6f2dc3mr4385365plh.20.1683521756566; Sun, 07 May 2023 21:55:56 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , qemu-block@nongnu.org, Hanna Reitz , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , dmitry.fomichev@wdc.com, Fam Zheng , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Kevin Wolf , Thomas Huth , dlemoal@kernel.org, hare@suse.de, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Sam Li Subject: [PATCH v20 3/8] block/block-backend: add block layer APIs resembling Linux ZonedBlockDevice ioctls Date: Mon, 8 May 2023 12:55:28 +0800 Message-Id: <20230508045533.175575-4-faithilikerun@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230508045533.175575-1-faithilikerun@gmail.com> References: <20230508045533.175575-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::52f; envelope-from=faithilikerun@gmail.com; helo=mail-pg1-x52f.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: 1683521858146100007 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 | 5 + qemu-io-cmds.c | 149 ++++++++++++++ 9 files changed, 696 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 97c597a2a0..11eaa780df 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 @@ -1234,6 +1244,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; @@ -1255,6 +1266,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. @@ -1298,6 +1310,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) { @@ -1311,7 +1324,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) { @@ -1379,9 +1439,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) { @@ -1849,6 +1912,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; @@ -3028,6 +3232,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) @@ -3783,6 +4085,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..e580ea8e38 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 */ + uint32_t max_append_sectors; + + /* maximum number of open zones */ + uint32_t max_open_zones; + + /* maximum number of active zones */ + uint32_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 229eb585f7..56b749c08c 100644 --- a/meson.build +++ b/meson.build @@ -2024,6 +2024,8 @@ if rdma.found() endif =20 # has_header_symbol +config_host_data.set('CONFIG_BLKZONED', + cc.has_header_symbol('linux/blkzoned.h', 'BLKOPENZONE= ')) config_host_data.set('CONFIG_EPOLL_CREATE1', cc.has_header_symbol('sys/epoll.h', 'epoll_create1')) config_host_data.set('CONFIG_FALLOCATE_PUNCH_HOLE', @@ -2059,6 +2061,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 Thu May 9 02:22:50 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=1683521880; cv=none; d=zohomail.com; s=zohoarc; b=UtdbUTiYq/h7Xshi6MVE4Z3Ss8zXNhu7+t+H7ByRx8NzbVrlk7UpHDylMq0stCMP2OomCipO+uiYDRymBZdC4AwJgkw1IHMtyt3MQ8WyLGU+Qe6bRcOd2aussCOfdSgSx6gHjqMGmRzmQspMOhXXbz3GD6UK3Fcr63KFz8GdyrY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683521880; 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=d+7DeyG7kFsjcHEYpy/YmKVKcmNQeM7zOK+9h4cLal9FCH9yXj1np3+0voO9VxXGK0j7Y7zbyU+azUSi4O31DcTXV7lKvdnQQKxAy4yJt632vo8cfkZ9MIaQ9joMBv6HGUYYLrk6hvoWJQ8L2c2Z2d3WL60kjUO6Ek8zEDZUqb0= 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 1683521880659495.42674909959965; Sun, 7 May 2023 21:58:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pvsuu-0001BE-4g; Mon, 08 May 2023 00:56:08 -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 1pvsus-0001AC-6h; Mon, 08 May 2023 00:56:06 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pvsuq-0005Xb-K1; Mon, 08 May 2023 00:56:05 -0400 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1aad55244b7so30214135ad.2; Sun, 07 May 2023 21:56:03 -0700 (PDT) Received: from fedlinux.. ([106.84.128.239]) by smtp.gmail.com with ESMTPSA id bg12-20020a1709028e8c00b0019ef86c2574sm6007112plb.270.2023.05.07.21.55.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 May 2023 21:56:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683521762; x=1686113762; 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=Nuw/HfubR0mWeId8elllokgzcaMqRlx1XFrbcwRkRFhkkSidsnDHsqhsyh6aFInT5H det1cAJtGDGu6V6Z67Q0LxjYgf0xNSW+PvmnAX0QiGo0GyhjL8moCKRO1bupb0yObi/w Sw111j6wujIZTG0gDJc7CCGGpovH4DlzBHVRZcSmo9mlF3cksasYvmWU64ZWeoTdbbNj HFLN3PJ/8KonR0OoCJElj5j+MWv/T2KPznhvYtFKgDi9qD5b3wGiNxI/1iInYvS1nIag iVBDfOcBQaAxT98GAqMsK5DIXgBlC7r/daVMNRNr90sOidAPT1XYtab74Jn1hePrdqxg DetA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683521762; x=1686113762; 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=QI+gnyxffRkhS3U8PvoeTaaGfSioTAqiimKcYBlbuYoJDTWSmM3vi4wAIw20wAc0Qq fRSmpwmJEgaVtnWU+eC8h3mWvnzPN3VETS7HyOpPnI7w8ip+6WBrq6PNMQARi0aRi7hV 3LIjWV1PFpG3HxAWAmYD1px2dEAiTTVaqXnocWa3hlOeLYVBqiAo+p0CczZ3BS0pUNRo YbFChXQxCo8owSFHMXkrwXKFl0FH4jS4nYRhNRF17Lupm/Cbf8r9mHM6fu/Mii5Fj5j+ CZeCQaEdcPDHr7z6DBziDzLawWSGQyYxaQPpYutH+E5LEhf7lkcWsCu1t9KNepyP/5Xj r/LQ== X-Gm-Message-State: AC+VfDzemtnnnSiXvTGruQoDMzPlgcKmY7sK4qX/kAlR0ekgutgEu0Do HhrmKhfV+fZZinwvecY7fmPhfGCarIK/X8Me X-Google-Smtp-Source: ACHHUZ4IGmSF3OEepaMcC1FStkrMZQZ12x91PADU+dfli5ccqSBmFRMivUNc9YGKUHMJGm1gKDm44A== X-Received: by 2002:a17:903:2448:b0:1ac:3642:bff3 with SMTP id l8-20020a170903244800b001ac3642bff3mr11945819pls.38.1683521762051; Sun, 07 May 2023 21:56:02 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , qemu-block@nongnu.org, Hanna Reitz , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , dmitry.fomichev@wdc.com, Fam Zheng , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Kevin Wolf , Thomas Huth , dlemoal@kernel.org, hare@suse.de, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Sam Li , Damien Le Moal Subject: [PATCH v20 4/8] block/raw-format: add zone operations to pass through requests Date: Mon, 8 May 2023 12:55:29 +0800 Message-Id: <20230508045533.175575-5-faithilikerun@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230508045533.175575-1-faithilikerun@gmail.com> References: <20230508045533.175575-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::62b; envelope-from=faithilikerun@gmail.com; helo=mail-pl1-x62b.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: 1683521881102100001 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 Thu May 9 02:22:50 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=1683521859; cv=none; d=zohomail.com; s=zohoarc; b=IJzTmSgZZ5gK+yUMKTNPmGxGzukR1aXbxR98LQYXTTan+GWJCEVnn2FOg3bDyZqes93hk/5XebPkaleJHFMIIsEEmOhQtRQosIfwNOi8atQM7bzfczdKDCX9XLgrDpFn5KuaTMIfttlKWoJS6UHFUqdXfl9EuqsLUoiXmloK5cQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683521859; 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=fAlJNERF8vxfdTc16P44twHaiCwg1Cgz55PMysdlzmA=; b=WJ40IFpcnd8CoSHqNzwi73XbAmG7zckuZKbWND/H7M89eEvM5hemy9YD0rdIlnjnnc9lyEdZ/gPu2ArpR0M1scKccJe9c80zZmIhXsQwhCANF8oRdxxsMjKUoADYTZQHQIID3PxNBcflkc0SR98kiCc+oBPra3lLNZ406u+dpaE= 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 1683521859756539.6121661939264; Sun, 7 May 2023 21:57:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pvsuy-0001C6-Rr; Mon, 08 May 2023 00:56:12 -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 1pvsux-0001BO-06; Mon, 08 May 2023 00:56:11 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pvsuv-0005YN-2K; Mon, 08 May 2023 00:56:10 -0400 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1aaea3909d1so38092325ad.2; Sun, 07 May 2023 21:56:08 -0700 (PDT) Received: from fedlinux.. ([106.84.128.239]) by smtp.gmail.com with ESMTPSA id bg12-20020a1709028e8c00b0019ef86c2574sm6007112plb.270.2023.05.07.21.56.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 May 2023 21:56:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683521767; x=1686113767; 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=fAlJNERF8vxfdTc16P44twHaiCwg1Cgz55PMysdlzmA=; b=kWiVqsDQGctnDJfyQZh3VYNetbjxC1UZ9F2S8bb8+MjEMEY8fIoWajKDE0R+6JnN0v KZxNnPx6OsBsQ75Mal5Ao5TTOSRA8021P4utdpXAKM2JAZOD0NkQ/TDxxF0ZkF9MhXKs uorinC4iU8zy8lE0qE9L1DLIqKkPrLAVxgs/cLyX2WhKL3TXZzuJXa1dCglakoaiR6Vr tHPlN0aIEjX6wotIMc+qWVkw+XWN0XlstXeKnBk/8xuAth+jNnzrXNX7rkifz+WjdJGK FR8+xt6vz35OURhIcbBTcjSbLBnuz84SCBO32lpzgQqu+tEw/XTQyNab7jOdzUjom2OQ W8TQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683521767; x=1686113767; 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=fAlJNERF8vxfdTc16P44twHaiCwg1Cgz55PMysdlzmA=; b=XZX76lrKgKaqoRnYtBZJZqtISMkcsYHWShTw491pqB7TKGZ5SKc679/a7/yN6iUhXf 4YfclWZaYDE2ocjDSDxHplZfEJHIqHywBdoT4XwyDJ6TmxWxkT1QpDLclJplUSgtp67d 0TBvEI7YqxTmqgenLoa42OyPWIRlpVSQwBBQiTbabdyhXSLc0tf4QWXgysFJEBUmejrO WdoLVFpc1XrYl113IwGpEJ1izn1QZn7eNPKeYyyu7pfC8/SulvuBOgyYw1KAlglwwUK6 //izi/1nZtYajP45HG68P5xb/QfVKdkdPBNLGV0Wmx4lYy7U8ybTBD22dkMo59ddHdko tI9w== X-Gm-Message-State: AC+VfDy2bDmgm9omQQPmwzvl2ALPDAm0VqvYcbGyjjhgH7mv67JUTbaB 3KxXC0N/ZFT7BK4HD8ye6kaIuMsgG2XzJNzz X-Google-Smtp-Source: ACHHUZ4ccTnPU4zRR3Y+dqeHDrgt3bYjDmHLkCdahm7uKJEGk8Izqi3VzY8qMD0iDiVeJEx615w6TQ== X-Received: by 2002:a17:902:d4c2:b0:1ac:813b:bfc0 with SMTP id o2-20020a170902d4c200b001ac813bbfc0mr1360482plg.18.1683521766638; Sun, 07 May 2023 21:56:06 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , qemu-block@nongnu.org, Hanna Reitz , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , dmitry.fomichev@wdc.com, Fam Zheng , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Kevin Wolf , Thomas Huth , dlemoal@kernel.org, hare@suse.de, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Sam Li Subject: [PATCH v20 5/8] block: add zoned BlockDriver check to block layer Date: Mon, 8 May 2023 12:55:30 +0800 Message-Id: <20230508045533.175575-6-faithilikerun@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230508045533.175575-1-faithilikerun@gmail.com> References: <20230508045533.175575-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::632; envelope-from=faithilikerun@gmail.com; helo=mail-pl1-x632.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: 1683521860280100001 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 11eaa780df..9a52ad4c65 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 e580ea8e38..06816a6fed 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 Thu May 9 02:22:50 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=1683521865; cv=none; d=zohomail.com; s=zohoarc; b=Q8famm4iKk4NM/PgEO2fpp8h/O20Yv4/VUcyUdwemcbKu1g1cknz+T9iCo1eqQqEcK66Mz7IwAK2WHgCCAwi/FiQzZwMDkmmxbL1gPWi1lpGxTLu46ZUlRw0Yohogg0ZbTbe7RNidYrdi9gWqr7sA6fDrrJO03sfY0rZZzBzvOY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683521865; 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=KjE7d4Sa+QKWJ+4O51mQ57Gu6fM4b6QFPxJtUaqubDFOVjuqwIeVlf/gxsvfrpeBw010T4VnLUPJIpPYv0dLpTDP0eK7/gfOh1M2PVNGOVaF0ZeH0agSfTIXZLvyZYC+ui3FbJ6iLfFLXY0+kPadcWbmkAZlLQPmkteKOLdHgbo= 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 1683521865150175.0888523156899; Sun, 7 May 2023 21:57:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pvsv3-0001DF-C4; Mon, 08 May 2023 00:56: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 1pvsv2-0001D1-2d; Mon, 08 May 2023 00:56:16 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pvsv0-0005aD-AQ; Mon, 08 May 2023 00:56:15 -0400 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1ab01bf474aso30249185ad.1; Sun, 07 May 2023 21:56:13 -0700 (PDT) Received: from fedlinux.. ([106.84.128.239]) by smtp.gmail.com with ESMTPSA id bg12-20020a1709028e8c00b0019ef86c2574sm6007112plb.270.2023.05.07.21.56.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 May 2023 21:56:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683521772; x=1686113772; 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=e3dEXF6Bt/zDlbvdN9XZs2d4AuStOnpdjRs9Xx3OBHFndcVGe4lsJkYKdzr/Dpwd/l c8wKzFv5GrckDws8eJgv0TOW9I6g3ekTepOkxsSnPyj6GaSHkAb8y5Qgp3NzYLPVI5Vz 7kAp+H8JoDTOoWHCZtqi0wZZzdQMkQH/lB3ybtAJnxPzaDk1ONID4zL6kQnIj0ckuKVr xI65Y68/MHTgfkPihJGg6wJzb0dikzGZ55kNZCtF0TxQRaIp8gBrGvk+0fXz2H3L3uxy XS2OaeAEPbwOta5JWA11MBCO6uzGTPTEyfVrXRWNyvQDhttzTBD3Uoex1PP44ihgteJZ sUkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683521772; x=1686113772; 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=Psw+m7O9et0jjyFVyoTNzVt/5JDuLE7aG6+mHbieI1XKCDa4ViN9dfbSSSkZHz7wYL tokXCrJ6g2LHYZbZFSKDzWygcBL2ZB/DwJrRtII1zqlypWTARxqyBCdOsoFKcuY6pbGU Wd+FCqcV0wEPKwo9JPewXAWNe5H95tyD03YkWUZlPSeLAkaZzfu1Zrz2CZz1ybxXizen a0BeFpVSw4HIZ/Bkvgr7Hd8sgwhDw7o/gNupuHUaRPF0G+37JLkOJjvcKWx/dUpwz+aw slTGjGdtZCUZbg6uL7brtCNE5YeEyNebjSCLaN46ZQQwTLmG+bQMJ3y0cBPa9aiclhId 070A== X-Gm-Message-State: AC+VfDwN14wwO3DKalwmc7BHCWKK16W7v6yKf6KXDdRdHdhjt6bERBEI tjYWSGwKCwg7facfLPRNVeq4HtpvlSbg6s99 X-Google-Smtp-Source: ACHHUZ5FR2ojiLN7JGOFrKxMzdzNDPTzHqwo84tN2VIxREXNx4tO5/SMKHt0/IGbMd7Z3WDHvQ36YA== X-Received: by 2002:a17:903:248:b0:1aa:e631:9f7f with SMTP id j8-20020a170903024800b001aae6319f7fmr10252543plh.41.1683521771547; Sun, 07 May 2023 21:56:11 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , qemu-block@nongnu.org, Hanna Reitz , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , dmitry.fomichev@wdc.com, Fam Zheng , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Kevin Wolf , Thomas Huth , dlemoal@kernel.org, hare@suse.de, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Sam Li Subject: [PATCH v20 6/8] iotests: test new zone operations Date: Mon, 8 May 2023 12:55:31 +0800 Message-Id: <20230508045533.175575-7-faithilikerun@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230508045533.175575-1-faithilikerun@gmail.com> References: <20230508045533.175575-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::62f; envelope-from=faithilikerun@gmail.com; helo=mail-pl1-x62f.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: 1683521867119100002 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 Thu May 9 02:22:50 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=1683521855; cv=none; d=zohomail.com; s=zohoarc; b=nYHAgj8ef4dHYv+RyRjmG65Q/fYVkf99cHQqyCr1Tn1Agor27qDKISliU1b4Q7KIw6QouUp15QUUwox/tB2L3yDTxhxEArbrL1yj0lEh02b+APg39ZkXaJIXWbM86F78WMOz7AX6Lgku79O6L9oDN5KJkhfHKKGi37DNF6pceH0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683521855; 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=96krboaY65tjRC/hxvTfm8jhMVKSj3WQaI78UbKnhlo=; b=AUE2to+UvksLt/fmRDhyOIf4s5Eaw4RgStiEhGtL6zUI4jcEhR5+/mvCvH78HWv4MdWuJhFPEPrZb0OM1CoBcIJdx44163RXh48YePWQfyu9BXwvLNJBmpkCbqI2KlbhpNzRlCfYqOP7j9ar1VKAxxkxCCwyC5hV8sOaaiA/gB0= 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 1683521855560127.89647878325354; Sun, 7 May 2023 21:57:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pvsv8-0001EA-2h; Mon, 08 May 2023 00:56:22 -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 1pvsv6-0001Dl-BK; Mon, 08 May 2023 00:56:20 -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 1pvsv4-0005c4-Rc; Mon, 08 May 2023 00:56:20 -0400 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1ab14cb3aaeso28020285ad.2; Sun, 07 May 2023 21:56:18 -0700 (PDT) Received: from fedlinux.. ([106.84.128.239]) by smtp.gmail.com with ESMTPSA id bg12-20020a1709028e8c00b0019ef86c2574sm6007112plb.270.2023.05.07.21.56.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 May 2023 21:56:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683521777; x=1686113777; 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=96krboaY65tjRC/hxvTfm8jhMVKSj3WQaI78UbKnhlo=; b=iPWLSq5YsyFyr9VOuzgHq6elqb+9oOkQAH41aJXOOAijSHJh5xl1S7Ub3w6X/+lfcC exu1dv++NUadjlqDv+gNi90fsySa5NjGUnwcDo2PX3V3qm6pOVqFPfC8p2WUSfP5/Dwt gZo77NeJwrMYyvHW23H3z8K7zf4jbZniZub32LLxr9/xsF54BCaZ2G7dLwblm4Y98FMe Oz1VGJ8KUIcs7pfoMuchexfbxZu5Muh59atQmwkPXmo2jDKi8XJNr8nE2yxjA4qe9Q1G u6SCPqxMtAkdPVpDM30f6pFoqVyRMtrl0L/A3IepX2blQr6DMrogK1KFTlEyTuC2fIoj 5QUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683521777; x=1686113777; 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=96krboaY65tjRC/hxvTfm8jhMVKSj3WQaI78UbKnhlo=; b=T7442qPBgIkWTkBuNcvqmJPG7Iq//o2aK5OJBHk5fi2kr4zApKL65TB7ar9LFJaA2g iJzfYY2qjNoC634DGT7oonHDOec7MVRwWZglkBRRSFrbiHhxVPMc4+a2m9P0x+9L3qUx 8pe0VcMxetZAZPZHi9v6X0rLLddzRTXOdfZLgiBX/l6IqFYpE0VobX3OdWeFprkHXtcn LtSNcIFGayzSpLnMath576g3KsjE3cHM6l4BW5BrFMkEQMFrmDcSGcSiC3W+zfrD4lFJ HKudH3IfqtEMHPSJnFgDUhZRcepieS9lZDiC9LdtUN21r8X5hQqJ+fL1KSfvMwCi67mP Z3Mg== X-Gm-Message-State: AC+VfDyQdTLqHNPll10wb6vfhUV380yaLFz9bwM+OsZ5Pl1aU15mP6v7 TiR9LF4dOTksrq1s9SjGvmPak/9sWRiAIhii X-Google-Smtp-Source: ACHHUZ7t6eDP/6SB5MeWdNIM8CN0eYv1lQIeWZW4ocwugDF/bqUch/8OQ6NYqgQaX0yyicfikT7wjQ== X-Received: by 2002:a17:902:eb46:b0:1a6:5487:3f97 with SMTP id i6-20020a170902eb4600b001a654873f97mr8614477pli.64.1683521776233; Sun, 07 May 2023 21:56:16 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , qemu-block@nongnu.org, Hanna Reitz , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , dmitry.fomichev@wdc.com, Fam Zheng , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Kevin Wolf , Thomas Huth , dlemoal@kernel.org, hare@suse.de, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Sam Li Subject: [PATCH v20 7/8] block: add some trace events for new block layer APIs Date: Mon, 8 May 2023 12:55:32 +0800 Message-Id: <20230508045533.175575-8-faithilikerun@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230508045533.175575-1-faithilikerun@gmail.com> References: <20230508045533.175575-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::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: 1683521856978100002 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 9a52ad4c65..e143de8217 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -3267,6 +3267,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 @@ -3333,6 +3334,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 Thu May 9 02:22:50 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=1683521808; cv=none; d=zohomail.com; s=zohoarc; b=kmhEJJEf3+3Q36zltvEsMdOgB7jcJMuwOmYBggvzd6ZRcQTtHAhIXiUAqr1xZo8raSD+fUfm7NDUFVQ0IzBJ2mO1TyluOKdpbyRQ2+NUwyxjnm0DHgfBaa+JbYMZ9ct+iYJJkj4cvkaeBiXu9g4hka6StZYqXCx+hzmKyTj9E74= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683521808; 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=KpLZHxQAbb5BQoKDFNie8F7N8lg1Ou7QkiDNVtQ40vgHcNXNMdryYI0eS3+5NIZ/53s5+w4LvXmHgJrZWFDV4s3V97MkqFkWXvGfGJfl3YdZvblFm8BwxVJP6uAKFcsSvTXtb9QWRWjW6wsTlIBEBYhpLzN+17ApV4SRBrF36So= 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 1683521808350983.755616408443; Sun, 7 May 2023 21:56:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pvsvD-0001FJ-IW; Mon, 08 May 2023 00:56:27 -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 1pvsvB-0001El-Kw; Mon, 08 May 2023 00:56:25 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pvsv9-0005dL-Nm; Mon, 08 May 2023 00:56:25 -0400 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1aaec6f189cso27015365ad.3; Sun, 07 May 2023 21:56:22 -0700 (PDT) Received: from fedlinux.. ([106.84.128.239]) by smtp.gmail.com with ESMTPSA id bg12-20020a1709028e8c00b0019ef86c2574sm6007112plb.270.2023.05.07.21.56.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 May 2023 21:56:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683521781; x=1686113781; 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=RAc+TsH87GSfr7w/nXlbpaB8mvBDUd6zEBDm84Ll8L7ZtWSMfzExotaoObF8QhDbPL iXcbjVoo6iwSr/U585m9bFgJv56ecCwUg/deSpNn3/qEy8WtIThVpIyPsDE/oJdw4I6V fc29h/sh5QNiObZH6TZb0HoCeaM+amEN9eLhTivnpB/zsJYlSB007cANMYtgcTomCb9y dOds6uJa8/E9Tb5Z1vmk8K4IRYXUr69I7eqZHGQ2mu8el31FQK32uxNgkRQ8I2Piovhb utMXlfT6GjjcynfZJ8vy6dPqbsIJp43bO4iPA9Iq6706tLV+Y1Lsp2LaGomiL2ri+Np9 6ENg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683521781; x=1686113781; 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=VP/Prns3kEz5mH7dP307UurnOXXjiTLD8XX6nZWi7OK6/enm1Ydm8FWQJikPw4vl6v iR15DkYh6ZKF7C8kn217VFxv1YUF0GJXCSshtXiJOzbAUYk8q/e91V74L2L0RDzueBLz /j2aVgKd33/zjCUspqU7EIUT7eo9YI0VEZQwTIFsS65Uyqb1h3uylSiq8Ct8LwnkYJdO RIzZthtgeAtzH6hK8l11EeWh8msPGUOb+BRbb9zlRAyHEgtuJKNqe1dk+xRiafzPt14i 3okd09eqwuQF9sIndJem6/XJ5Snk/myFOpwrj8sqkIAtyrlGGEscHGsPRewh9A/bHRVS 97xA== X-Gm-Message-State: AC+VfDwOXjszu1ENC2aVEVVVJlZA+S4E31yDCRznKpRb2VtaMaBZUWdW JD44bueFDQBIQVijBpKYcBzXer7reuMq8Bvb X-Google-Smtp-Source: ACHHUZ5E14dOCkWJHohL9DAxZ5B+AZo81it/f9PimGNClj3aECMMqI9y+WWU5bLrbHwf18nr5TZJHA== X-Received: by 2002:a17:902:e786:b0:1ac:7543:bcdf with SMTP id cp6-20020a170902e78600b001ac7543bcdfmr2606871plb.31.1683521781245; Sun, 07 May 2023 21:56:21 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , qemu-block@nongnu.org, Hanna Reitz , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , dmitry.fomichev@wdc.com, Fam Zheng , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Kevin Wolf , Thomas Huth , dlemoal@kernel.org, hare@suse.de, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Sam Li , Damien Le Moal Subject: [PATCH v20 8/8] docs/zoned-storage: add zoned device documentation Date: Mon, 8 May 2023 12:55:33 +0800 Message-Id: <20230508045533.175575-9-faithilikerun@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230508045533.175575-1-faithilikerun@gmail.com> References: <20230508045533.175575-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::62f; envelope-from=faithilikerun@gmail.com; helo=mail-pl1-x62f.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: 1683521808984100001 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