From nobody Fri May 10 01:51:43 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682685664; cv=none; d=zohomail.com; s=zohoarc; b=SUrbebbl+GhHa6xYd8yVFmPVAKMahBteS4irApWd16i0wSwuNPgcmKup+/Z3HCS1vixr1STd1DpquQQtWrQ+BpWm9r9pdmFRZ50GE0hXVQ6GZgpb5o0oe4DH11WTvM/no1tNdvDPI9QaAFZktD62vqQeiNphCt3hBjiW6N+XiJI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682685664; 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=73ZBgpVbuFH0LNfWMZ55Wa/XMwGt7KOps0s5hM6YTdw=; b=ma7b73lomxgwx9GzOW8uaXM3Zvh5qVu+gVeDjqKvi8nJYNCpCxMsPh9r8uxuGV36lGi/WWwEmLFPjDjQ2r9zgP+shgx6IbNvX09ed4F2ae3rSWJ5/DT2eHNkIreW8W/TMwiJanKD9wBS59gIo/wdghT0NIsQvx+mLDa2JwGfLbw= 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 1682685664656329.86547334993963; Fri, 28 Apr 2023 05:41:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1psNOc-0006k4-FT; Fri, 28 Apr 2023 08:40:18 -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 1psNOU-0006iM-1e for qemu-devel@nongnu.org; Fri, 28 Apr 2023 08:40:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1psNOP-0000S5-RI for qemu-devel@nongnu.org; Fri, 28 Apr 2023 08:40:08 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-172-rqzR32NANYietzTNwyAGqQ-1; Fri, 28 Apr 2023 08:40:00 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 73C7D185A7A2; Fri, 28 Apr 2023 12:39:59 +0000 (UTC) Received: from localhost (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id B7BA82027043; Fri, 28 Apr 2023 12:39:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682685604; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=73ZBgpVbuFH0LNfWMZ55Wa/XMwGt7KOps0s5hM6YTdw=; b=RPe7Bl9EAal014G3OuPhjGRLbD84uHgoduuGJl5OCLN3Uy2oxl8+OMpeGkJR1oHZP0lbmo OO3qugjwWVfZZBtX3I7u5Yuna9t4J/QniUchBngJLkJshZB/SsTnLYJ6B0iLoDpjIht/+A aLNSUDM9JawFAyQZCaPK6Bgxt+gEpdo= X-MC-Unique: rqzR32NANYietzTNwyAGqQ-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Raphael Norwitz , Julia Suvorova , Cornelia Huck , Eric Blake , Paolo Bonzini , Aarushi Mehta , Stefan Hajnoczi , Richard Henderson , Kevin Wolf , Markus Armbruster , Stefano Garzarella , qemu-block@nongnu.org, Hanna Reitz , Fam Zheng , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Michael S. Tsirkin" , kvm@vger.kernel.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sam Li , Damien Le Moal , Hannes Reinecke , Dmitry Fomichev Subject: [PULL 01/17] block/block-common: add zoned device structs Date: Fri, 28 Apr 2023 08:39:38 -0400 Message-Id: <20230428123954.179035-2-stefanha@redhat.com> In-Reply-To: <20230428123954.179035-1-stefanha@redhat.com> References: <20230428123954.179035-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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 @redhat.com) X-ZM-MESSAGEID: 1682685667216100005 From: Sam Li 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 Signed-off-by: Stefan Hajnoczi Message-id: 20230427172019.3345-2-faithilikerun@gmail.com 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 Fri May 10 01:51:43 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682685702; cv=none; d=zohomail.com; s=zohoarc; b=QwatuJsX8/ca1Hhw5RmcpjIPAz33a42fFG0smIIw30TY1wy4l8XDjsCTyJ+WnFXkjxhisDk0DvqvaoG0ensg+S0kJ0Vfj1TqBDThH7rQnQAyFWsoaJSkmCkse8K4lSOGY4DdrsbCGOC5QNiyhqYBUBfqJi7cgBKatzzynQyy41M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682685702; 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=W0udrCJv7r8lAynaFcJv3pPNEBbKHvfiYakeUszKD0Y=; b=VbOhYnYAF9bL3SfccRkhE6ReSkHH2VrsrB249z6FpjNp+0QSADi50A46NdRUG9ucaK6cW1oGfpNSb7PHeuK2ydKV++W9Z5gsim0l2qXzrN/fPDUH5GqhzGNGVys/B+YcvY6GCBE1pF5y5FwNWDb5qAnd6WGxlT2XYBsf+jqRl5Y= 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 1682685702500901.4732133175604; Fri, 28 Apr 2023 05:41:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1psNPW-0007VL-Lr; Fri, 28 Apr 2023 08:41:15 -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 1psNOr-0006pH-GU for qemu-devel@nongnu.org; Fri, 28 Apr 2023 08:40:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1psNOk-0000Un-3W for qemu-devel@nongnu.org; Fri, 28 Apr 2023 08:40:29 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-533-FO8xTO4SMsuocpXusj82lQ-1; Fri, 28 Apr 2023 08:40:04 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3C054887412; Fri, 28 Apr 2023 12:40:02 +0000 (UTC) Received: from localhost (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7301035443; Fri, 28 Apr 2023 12:40:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682685609; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=W0udrCJv7r8lAynaFcJv3pPNEBbKHvfiYakeUszKD0Y=; b=KlXkqMNlWhn9gGwr0cP8e/CgYqOr7lWZiiGonJ1oDzDfE1WC/FY7Jg0lo1OukvON+J7H06 sL5+yIVYmG+xv7SL2iMroU83knxxqGeDFkZL/uAuy8QeQSxgM5CHdSu8G5lxW804EbG9IO xoSAlvMTHT71m0uHpK86wGgTjQNL5Tc= X-MC-Unique: FO8xTO4SMsuocpXusj82lQ-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Raphael Norwitz , Julia Suvorova , Cornelia Huck , Eric Blake , Paolo Bonzini , Aarushi Mehta , Stefan Hajnoczi , Richard Henderson , Kevin Wolf , Markus Armbruster , Stefano Garzarella , qemu-block@nongnu.org, Hanna Reitz , Fam Zheng , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Michael S. Tsirkin" , kvm@vger.kernel.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sam Li , Hannes Reinecke , Damien Le Moal , Dmitry Fomichev Subject: [PULL 02/17] block/file-posix: introduce helper functions for sysfs attributes Date: Fri, 28 Apr 2023 08:39:39 -0400 Message-Id: <20230428123954.179035-3-stefanha@redhat.com> In-Reply-To: <20230428123954.179035-1-stefanha@redhat.com> References: <20230428123954.179035-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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 @redhat.com) X-ZM-MESSAGEID: 1682685703938100005 From: Sam Li 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 Signed-off-by: Stefan Hajnoczi Message-id: 20230427172019.3345-3-faithilikerun@gmail.com 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 --- include/block/block_int-common.h | 3 + block/file-posix.c | 139 ++++++++++++++++++++++--------- 2 files changed, 104 insertions(+), 38 deletions(-) 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; diff --git a/block/file-posix.c b/block/file-posix.c index c7b723368e..ba15b10eee 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1202,15 +1202,93 @@ static int hdev_get_max_hw_transfer(int fd, struct = stat *st) #endif } =20 -static int hdev_get_max_segments(int fd, struct stat *st) +/* + * Get a sysfs attribute value as character string. + */ +static int get_sysfs_str_val(struct stat *st, const char *attribute, + char **val) { +#ifdef CONFIG_LINUX + g_autofree char *sysfspath =3D NULL; + int ret; + size_t len; + + if (!S_ISBLK(st->st_mode)) { + return -ENOTSUP; + } + + sysfspath =3D g_strdup_printf("/sys/dev/block/%u:%u/queue/%s", + major(st->st_rdev), minor(st->st_rdev), + attribute); + ret =3D g_file_get_contents(sysfspath, val, &len, NULL); + if (ret =3D=3D -1) { + return -ENOENT; + } + + /* The file is ended with '\n' */ + char *p; + p =3D *val; + if (*(p + len - 1) =3D=3D '\n') { + *(p + len - 1) =3D '\0'; + } + return ret; +#else + return -ENOTSUP; +#endif +} + +static int get_sysfs_zoned_model(struct stat *st, BlockZoneModel *zoned) +{ + g_autofree char *val =3D NULL; + int ret; + + ret =3D get_sysfs_str_val(st, "zoned", &val); + if (ret < 0) { + return ret; + } + + 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; +} + +/* + * Get a sysfs attribute value as a long integer. + */ +static long get_sysfs_long_val(struct stat *st, const char *attribute) { #ifdef CONFIG_LINUX - char buf[32]; + g_autofree char *str =3D NULL; const char *end; - char *sysfspath =3D NULL; + 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; + } + return ret; +#else + return -ENOTSUP; +#endif +} + +static int hdev_get_max_segments(int fd, struct stat *st) +{ +#ifdef CONFIG_LINUX int ret; - int sysfd =3D -1; - long max_segments; =20 if (S_ISCHR(st->st_mode)) { if (ioctl(fd, SG_GET_SG_TABLESIZE, &ret) =3D=3D 0) { @@ -1218,44 +1296,27 @@ static int hdev_get_max_segments(int fd, struct sta= t *st) } return -ENOTSUP; } - - if (!S_ISBLK(st->st_mode)) { - return -ENOTSUP; - } - - 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; - } - ret =3D RETRY_ON_EINTR(read(sysfd, buf, sizeof(buf) - 1)); - if (ret < 0) { - ret =3D -errno; - goto out; - } else if (ret =3D=3D 0) { - ret =3D -EIO; - goto out; - } - 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; - } - -out: - if (sysfd !=3D -1) { - close(sysfd); - } - g_free(sysfspath); - return ret; + 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 +1358,8 @@ static void raw_refresh_limits(BlockDriverState *bs, = Error **errp) bs->bl.max_hw_iov =3D ret; } } + + raw_refresh_zoned_limits(bs, &st, errp); } =20 static int check_for_dasd(int fd) --=20 2.40.0 From nobody Fri May 10 01:51:43 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682685664; cv=none; d=zohomail.com; s=zohoarc; b=ij/FCEU0Cf5/K6KTAlnBXyf7Yb5wTBcQQi+ZtrmXc/J7unXPhsfFX/S5QOsL6jGTDAvZomU1Sr3g+dKYzyveWzVU5etZ1ulJG1VW+pal1rRDw7XbWzbJaYoJGuk+PZfrdyg1x/v47UYNdvmt3aDo9QsANHlrEsq3ZaCtarwUs+8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682685664; 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=fTMMUFVaws3/lkV6gm1enPvMf61Z6FU1r0Lld9+qWU4=; b=DS/XIjqzs6qJgqtcGVZXgFoJV5PgLwkkKnuxFp+qIAL9MiJUl5iZR7UrQg1F8ibzJrCkdeUykY+jCH8yfTvrSHt+3a+4C6RlGqgsetH8DPoErgqDFv8vALyp3dUGiTDHv4XGFF7Jv85QxnI1DHm+62WVuXrOTkkQToILr7AHZFA= 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 1682685664870632.2499148315941; Fri, 28 Apr 2023 05:41:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1psNP5-0006rS-SG; Fri, 28 Apr 2023 08:40:48 -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 1psNOq-0006n5-Ci for qemu-devel@nongnu.org; Fri, 28 Apr 2023 08:40:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1psNOj-0000Ul-IU for qemu-devel@nongnu.org; Fri, 28 Apr 2023 08:40:29 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-659-u8zWCYIvNbqk6PYr-tB3lg-1; Fri, 28 Apr 2023 08:40:05 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5064E887403; Fri, 28 Apr 2023 12:40:05 +0000 (UTC) Received: from localhost (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 10CF240C6EC4; Fri, 28 Apr 2023 12:40:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682685609; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fTMMUFVaws3/lkV6gm1enPvMf61Z6FU1r0Lld9+qWU4=; b=QzA7tZqCu9se3A2w0vV6xhZLXqRK3BO0zl3uLGYB2oZQcqLEA5v6HnzgLMCsl3eIwlGxzO fENDM53itflQ8lnSnH7Y11+yN0YJIYjb1a5cXD5IC8fhuBGxQimK8gpo3IY+JiBp7d0786 7+Op/2xH8IXfuqPQv+bzYxWJckRiSZA= X-MC-Unique: u8zWCYIvNbqk6PYr-tB3lg-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Raphael Norwitz , Julia Suvorova , Cornelia Huck , Eric Blake , Paolo Bonzini , Aarushi Mehta , Stefan Hajnoczi , Richard Henderson , Kevin Wolf , Markus Armbruster , Stefano Garzarella , qemu-block@nongnu.org, Hanna Reitz , Fam Zheng , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Michael S. Tsirkin" , kvm@vger.kernel.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sam Li , Hannes Reinecke , Dmitry Fomichev Subject: [PULL 03/17] block/block-backend: add block layer APIs resembling Linux ZonedBlockDevice ioctls Date: Fri, 28 Apr 2023 08:39:40 -0400 Message-Id: <20230428123954.179035-4-stefanha@redhat.com> In-Reply-To: <20230428123954.179035-1-stefanha@redhat.com> References: <20230428123954.179035-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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 @redhat.com) X-ZM-MESSAGEID: 1682685667279100007 From: Sam Li 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 Signed-off-by: Stefan Hajnoczi Message-id: 20230427172019.3345-4-faithilikerun@gmail.com 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 --- meson.build | 4 + 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 ++ block/block-backend.c | 137 +++++++++++++ block/file-posix.c | 313 +++++++++++++++++++++++++++++- block/io.c | 41 ++++ qemu-io-cmds.c | 149 ++++++++++++++ 9 files changed, 695 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index c44d05a13f..a1bc310114 100644 --- a/meson.build +++ b/meson.build @@ -1966,6 +1966,7 @@ config_host_data.set('CONFIG_REPLICATION', get_option= ('replication').allowed()) # has_header config_host_data.set('CONFIG_EPOLL', cc.has_header('sys/epoll.h')) config_host_data.set('CONFIG_LINUX_MAGIC_H', cc.has_header('linux/magic.h'= )) +config_host_data.set('CONFIG_BLKZONED', cc.has_header('linux/blkzoned.h')) config_host_data.set('CONFIG_VALGRIND_H', cc.has_header('valgrind/valgrind= .h')) config_host_data.set('HAVE_BTRFS_H', cc.has_header('linux/btrfs.h')) config_host_data.set('HAVE_DRM_H', cc.has_header('libdrm/drm.h')) @@ -2052,6 +2053,9 @@ config_host_data.set('HAVE_SIGEV_NOTIFY_THREAD_ID', config_host_data.set('HAVE_STRUCT_STAT_ST_ATIM', cc.has_member('struct stat', 'st_atim', prefix: '#include ')) +config_host_data.set('HAVE_BLK_ZONE_REP_CAPACITY', + cc.has_member('struct blk_zone', 'capacity', + prefix: '#include ')) =20 # has_type config_host_data.set('CONFIG_IOVEC', diff --git a/include/block/block-io.h b/include/block/block-io.h index 5dab88521d..58f415ab64 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -111,6 +111,15 @@ int coroutine_fn GRAPH_RDLOCK bdrv_co_flush(BlockDrive= rState *bs); int coroutine_fn GRAPH_RDLOCK bdrv_co_pdiscard(BdrvChild *child, int64_t o= ffset, int64_t bytes); =20 +/* Report zone information of zone block device. */ +int coroutine_fn GRAPH_RDLOCK bdrv_co_zone_report(BlockDriverState *bs, + int64_t offset, + unsigned int *nr_zones, + BlockZoneDescriptor *zon= es); +int coroutine_fn GRAPH_RDLOCK bdrv_co_zone_mgmt(BlockDriverState *bs, + BlockZoneOp op, + int64_t offset, int64_t le= n); + bool bdrv_can_write_zeroes_with_unmap(BlockDriverState *bs); int bdrv_block_status(BlockDriverState *bs, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map, diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 150dc6f68f..997d539890 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -712,6 +712,12 @@ struct BlockDriver { int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_load_vmstate)( BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos); =20 + int coroutine_fn (*bdrv_co_zone_report)(BlockDriverState *bs, + int64_t offset, unsigned int *nr_zones, + BlockZoneDescriptor *zones); + int coroutine_fn (*bdrv_co_zone_mgmt)(BlockDriverState *bs, BlockZoneO= p op, + int64_t offset, int64_t len); + /* removable device specific */ bool coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_is_inserted)( BlockDriverState *bs); @@ -864,6 +870,21 @@ typedef struct BlockLimits { =20 /* device zone model */ BlockZoneModel zoned; + + /* zone size expressed in bytes */ + uint32_t zone_size; + + /* total number of zones */ + uint32_t nr_zones; + + /* maximum sectors of a zone append write operation */ + int64_t max_append_sectors; + + /* maximum number of open zones */ + int64_t max_open_zones; + + /* maximum number of active zones */ + int64_t max_active_zones; } BlockLimits; =20 typedef struct BdrvOpBlocker BdrvOpBlocker; diff --git a/include/block/raw-aio.h b/include/block/raw-aio.h index e46a29c3f0..afb9bdf51b 100644 --- a/include/block/raw-aio.h +++ b/include/block/raw-aio.h @@ -28,6 +28,8 @@ #define QEMU_AIO_WRITE_ZEROES 0x0020 #define QEMU_AIO_COPY_RANGE 0x0040 #define QEMU_AIO_TRUNCATE 0x0080 +#define QEMU_AIO_ZONE_REPORT 0x0100 +#define QEMU_AIO_ZONE_MGMT 0x0200 #define QEMU_AIO_TYPE_MASK \ (QEMU_AIO_READ | \ QEMU_AIO_WRITE | \ @@ -36,7 +38,9 @@ QEMU_AIO_DISCARD | \ QEMU_AIO_WRITE_ZEROES | \ QEMU_AIO_COPY_RANGE | \ - QEMU_AIO_TRUNCATE) + QEMU_AIO_TRUNCATE | \ + QEMU_AIO_ZONE_REPORT | \ + QEMU_AIO_ZONE_MGMT) =20 /* AIO flags */ #define QEMU_AIO_MISALIGNED 0x1000 diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backe= nd-io.h index 851a44de96..eb1c1ebfec 100644 --- a/include/sysemu/block-backend-io.h +++ b/include/sysemu/block-backend-io.h @@ -46,6 +46,13 @@ BlockAIOCB *blk_aio_pwritev(BlockBackend *blk, int64_t o= ffset, BlockCompletionFunc *cb, void *opaque); BlockAIOCB *blk_aio_flush(BlockBackend *blk, BlockCompletionFunc *cb, void *opaque); +BlockAIOCB *blk_aio_zone_report(BlockBackend *blk, int64_t offset, + unsigned int *nr_zones, + BlockZoneDescriptor *zones, + BlockCompletionFunc *cb, void *opaque); +BlockAIOCB *blk_aio_zone_mgmt(BlockBackend *blk, BlockZoneOp op, + int64_t offset, int64_t len, + BlockCompletionFunc *cb, void *opaque); BlockAIOCB *blk_aio_pdiscard(BlockBackend *blk, int64_t offset, int64_t by= tes, BlockCompletionFunc *cb, void *opaque); void blk_aio_cancel_async(BlockAIOCB *acb); @@ -191,6 +198,17 @@ int co_wrapper_mixed blk_pwrite_zeroes(BlockBackend *b= lk, int64_t offset, int coroutine_fn blk_co_pwrite_zeroes(BlockBackend *blk, int64_t offset, int64_t bytes, BdrvRequestFlags flag= s); =20 +int coroutine_fn blk_co_zone_report(BlockBackend *blk, int64_t offset, + unsigned int *nr_zones, + BlockZoneDescriptor *zones); +int co_wrapper_mixed blk_zone_report(BlockBackend *blk, int64_t offset, + unsigned int *nr_zones, + BlockZoneDescriptor *zones); +int coroutine_fn blk_co_zone_mgmt(BlockBackend *blk, BlockZoneOp op, + int64_t offset, int64_t len); +int co_wrapper_mixed blk_zone_mgmt(BlockBackend *blk, BlockZoneOp op, + int64_t offset, int64_t len); + int co_wrapper_mixed blk_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes); int coroutine_fn blk_co_pdiscard(BlockBackend *blk, int64_t offset, diff --git a/block/block-backend.c b/block/block-backend.c index fc530ded6a..67722eb46d 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1845,6 +1845,143 @@ int coroutine_fn blk_co_flush(BlockBackend *blk) return ret; } =20 +static void coroutine_fn blk_aio_zone_report_entry(void *opaque) +{ + BlkAioEmAIOCB *acb =3D opaque; + BlkRwCo *rwco =3D &acb->rwco; + + rwco->ret =3D blk_co_zone_report(rwco->blk, rwco->offset, + (unsigned int*)(uintptr_t)acb->bytes, + rwco->iobuf); + blk_aio_complete(acb); +} + +BlockAIOCB *blk_aio_zone_report(BlockBackend *blk, int64_t offset, + unsigned int *nr_zones, + BlockZoneDescriptor *zones, + BlockCompletionFunc *cb, void *opaque) +{ + BlkAioEmAIOCB *acb; + Coroutine *co; + IO_CODE(); + + blk_inc_in_flight(blk); + acb =3D blk_aio_get(&blk_aio_em_aiocb_info, blk, cb, opaque); + acb->rwco =3D (BlkRwCo) { + .blk =3D blk, + .offset =3D offset, + .iobuf =3D zones, + .ret =3D NOT_DONE, + }; + acb->bytes =3D (int64_t)(uintptr_t)nr_zones, + acb->has_returned =3D false; + + co =3D qemu_coroutine_create(blk_aio_zone_report_entry, acb); + aio_co_enter(blk_get_aio_context(blk), co); + + acb->has_returned =3D true; + if (acb->rwco.ret !=3D NOT_DONE) { + replay_bh_schedule_oneshot_event(blk_get_aio_context(blk), + blk_aio_complete_bh, acb); + } + + return &acb->common; +} + +static void coroutine_fn blk_aio_zone_mgmt_entry(void *opaque) +{ + BlkAioEmAIOCB *acb =3D opaque; + BlkRwCo *rwco =3D &acb->rwco; + + rwco->ret =3D blk_co_zone_mgmt(rwco->blk, + (BlockZoneOp)(uintptr_t)rwco->iobuf, + rwco->offset, acb->bytes); + blk_aio_complete(acb); +} + +BlockAIOCB *blk_aio_zone_mgmt(BlockBackend *blk, BlockZoneOp op, + int64_t offset, int64_t len, + BlockCompletionFunc *cb, void *opaque) { + BlkAioEmAIOCB *acb; + Coroutine *co; + IO_CODE(); + + blk_inc_in_flight(blk); + acb =3D blk_aio_get(&blk_aio_em_aiocb_info, blk, cb, opaque); + acb->rwco =3D (BlkRwCo) { + .blk =3D blk, + .offset =3D offset, + .iobuf =3D (void *)(uintptr_t)op, + .ret =3D NOT_DONE, + }; + acb->bytes =3D len; + acb->has_returned =3D false; + + co =3D qemu_coroutine_create(blk_aio_zone_mgmt_entry, acb); + aio_co_enter(blk_get_aio_context(blk), co); + + acb->has_returned =3D true; + if (acb->rwco.ret !=3D NOT_DONE) { + replay_bh_schedule_oneshot_event(blk_get_aio_context(blk), + blk_aio_complete_bh, acb); + } + + return &acb->common; +} + +/* + * Send a zone_report command. + * offset is a byte offset from the start of the device. No alignment + * required for offset. + * nr_zones represents IN maximum and OUT actual. + */ +int coroutine_fn blk_co_zone_report(BlockBackend *blk, int64_t offset, + unsigned int *nr_zones, + BlockZoneDescriptor *zones) +{ + int ret; + IO_CODE(); + + blk_inc_in_flight(blk); /* increase before waiting */ + blk_wait_while_drained(blk); + GRAPH_RDLOCK_GUARD(); + if (!blk_is_available(blk)) { + blk_dec_in_flight(blk); + return -ENOMEDIUM; + } + ret =3D bdrv_co_zone_report(blk_bs(blk), offset, nr_zones, zones); + blk_dec_in_flight(blk); + return ret; +} + +/* + * Send a zone_management command. + * op is the zone operation; + * offset is the byte offset from the start of the zoned device; + * len is the maximum number of bytes the command should operate on. It + * should be aligned with the device zone size. + */ +int coroutine_fn blk_co_zone_mgmt(BlockBackend *blk, BlockZoneOp op, + int64_t offset, int64_t len) +{ + int ret; + IO_CODE(); + + blk_inc_in_flight(blk); + blk_wait_while_drained(blk); + GRAPH_RDLOCK_GUARD(); + + ret =3D blk_check_byte_request(blk, offset, len); + if (ret < 0) { + blk_dec_in_flight(blk); + return ret; + } + + ret =3D bdrv_co_zone_mgmt(blk_bs(blk), op, offset, len); + blk_dec_in_flight(blk); + return ret; +} + void blk_drain(BlockBackend *blk) { BlockDriverState *bs =3D blk_bs(blk); diff --git a/block/file-posix.c b/block/file-posix.c index ba15b10eee..3b6575d771 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -68,6 +68,9 @@ #include #include #include +#if defined(CONFIG_BLKZONED) +#include +#endif #include #include #include @@ -216,6 +219,13 @@ typedef struct RawPosixAIOData { PreallocMode prealloc; Error **errp; } truncate; + struct { + unsigned int *nr_zones; + BlockZoneDescriptor *zones; + } zone_report; + struct { + unsigned long op; + } zone_mgmt; }; } RawPosixAIOData; =20 @@ -1236,6 +1246,7 @@ static int get_sysfs_str_val(struct stat *st, const c= har *attribute, #endif } =20 +#if defined(CONFIG_BLKZONED) static int get_sysfs_zoned_model(struct stat *st, BlockZoneModel *zoned) { g_autofree char *val =3D NULL; @@ -1257,6 +1268,7 @@ static int get_sysfs_zoned_model(struct stat *st, Blo= ckZoneModel *zoned) } return 0; } +#endif /* defined(CONFIG_BLKZONED) */ =20 /* * Get a sysfs attribute value as a long integer. @@ -1302,6 +1314,7 @@ static int hdev_get_max_segments(int fd, struct stat = *st) #endif } =20 +#if defined(CONFIG_BLKZONED) static void raw_refresh_zoned_limits(BlockDriverState *bs, struct stat *st, Error **errp) { @@ -1315,7 +1328,54 @@ static void raw_refresh_zoned_limits(BlockDriverStat= e *bs, struct stat *st, return; } bs->bl.zoned =3D zoned; + + ret =3D get_sysfs_long_val(st, "max_open_zones"); + if (ret >=3D 0) { + bs->bl.max_open_zones =3D ret; + } + + ret =3D get_sysfs_long_val(st, "max_active_zones"); + if (ret >=3D 0) { + bs->bl.max_active_zones =3D ret; + } + + /* + * The zoned device must at least have zone size and nr_zones fields. + */ + ret =3D get_sysfs_long_val(st, "chunk_sectors"); + if (ret < 0) { + error_setg_errno(errp, -ret, "Unable to read chunk_sectors " + "sysfs attribute"); + return; + } else if (!ret) { + error_setg(errp, "Read 0 from chunk_sectors sysfs attribute"); + return; + } + bs->bl.zone_size =3D ret << BDRV_SECTOR_BITS; + + ret =3D get_sysfs_long_val(st, "nr_zones"); + if (ret < 0) { + error_setg_errno(errp, -ret, "Unable to read nr_zones " + "sysfs attribute"); + return; + } else if (!ret) { + error_setg(errp, "Read 0 from nr_zones sysfs attribute"); + return; + } + bs->bl.nr_zones =3D ret; + + ret =3D get_sysfs_long_val(st, "zone_append_max_bytes"); + if (ret > 0) { + bs->bl.max_append_sectors =3D ret >> BDRV_SECTOR_BITS; + } } +#else /* !defined(CONFIG_BLKZONED) */ +static void raw_refresh_zoned_limits(BlockDriverState *bs, struct stat *st, + Error **errp) +{ + bs->bl.zoned =3D BLK_Z_NONE; +} +#endif /* !defined(CONFIG_BLKZONED) */ =20 static void raw_refresh_limits(BlockDriverState *bs, Error **errp) { @@ -1383,9 +1443,12 @@ static int hdev_probe_blocksizes(BlockDriverState *b= s, BlockSizes *bsz) BDRVRawState *s =3D bs->opaque; int ret; =20 - /* If DASD, get blocksizes */ + /* If DASD or zoned devices, get blocksizes */ if (check_for_dasd(s->fd) < 0) { - return -ENOTSUP; + /* zoned devices are not DASD */ + if (bs->bl.zoned =3D=3D BLK_Z_NONE) { + return -ENOTSUP; + } } ret =3D probe_logical_blocksize(s->fd, &bsz->log); if (ret < 0) { @@ -1853,6 +1916,147 @@ static off_t copy_file_range(int in_fd, off_t *in_o= ff, int out_fd, } #endif =20 +/* + * parse_zone - Fill a zone descriptor + */ +#if defined(CONFIG_BLKZONED) +static inline int parse_zone(struct BlockZoneDescriptor *zone, + const struct blk_zone *blkz) { + zone->start =3D blkz->start << BDRV_SECTOR_BITS; + zone->length =3D blkz->len << BDRV_SECTOR_BITS; + zone->wp =3D blkz->wp << BDRV_SECTOR_BITS; + +#ifdef HAVE_BLK_ZONE_REP_CAPACITY + zone->cap =3D blkz->capacity << BDRV_SECTOR_BITS; +#else + zone->cap =3D blkz->len << BDRV_SECTOR_BITS; +#endif + + switch (blkz->type) { + case BLK_ZONE_TYPE_SEQWRITE_REQ: + zone->type =3D BLK_ZT_SWR; + break; + case BLK_ZONE_TYPE_SEQWRITE_PREF: + zone->type =3D BLK_ZT_SWP; + break; + case BLK_ZONE_TYPE_CONVENTIONAL: + zone->type =3D BLK_ZT_CONV; + break; + default: + error_report("Unsupported zone type: 0x%x", blkz->type); + return -ENOTSUP; + } + + switch (blkz->cond) { + case BLK_ZONE_COND_NOT_WP: + zone->state =3D BLK_ZS_NOT_WP; + break; + case BLK_ZONE_COND_EMPTY: + zone->state =3D BLK_ZS_EMPTY; + break; + case BLK_ZONE_COND_IMP_OPEN: + zone->state =3D BLK_ZS_IOPEN; + break; + case BLK_ZONE_COND_EXP_OPEN: + zone->state =3D BLK_ZS_EOPEN; + break; + case BLK_ZONE_COND_CLOSED: + zone->state =3D BLK_ZS_CLOSED; + break; + case BLK_ZONE_COND_READONLY: + zone->state =3D BLK_ZS_RDONLY; + break; + case BLK_ZONE_COND_FULL: + zone->state =3D BLK_ZS_FULL; + break; + case BLK_ZONE_COND_OFFLINE: + zone->state =3D BLK_ZS_OFFLINE; + break; + default: + error_report("Unsupported zone state: 0x%x", blkz->cond); + return -ENOTSUP; + } + return 0; +} +#endif + +#if defined(CONFIG_BLKZONED) +static int handle_aiocb_zone_report(void *opaque) +{ + RawPosixAIOData *aiocb =3D opaque; + int fd =3D aiocb->aio_fildes; + unsigned int *nr_zones =3D aiocb->zone_report.nr_zones; + BlockZoneDescriptor *zones =3D aiocb->zone_report.zones; + /* zoned block devices use 512-byte sectors */ + uint64_t sector =3D aiocb->aio_offset / 512; + + struct blk_zone *blkz; + size_t rep_size; + unsigned int nrz; + int ret; + unsigned int n =3D 0, i =3D 0; + + nrz =3D *nr_zones; + rep_size =3D sizeof(struct blk_zone_report) + nrz * sizeof(struct blk_= zone); + g_autofree struct blk_zone_report *rep =3D NULL; + rep =3D g_malloc(rep_size); + + blkz =3D (struct blk_zone *)(rep + 1); + while (n < nrz) { + memset(rep, 0, rep_size); + rep->sector =3D sector; + rep->nr_zones =3D nrz - n; + + do { + ret =3D ioctl(fd, BLKREPORTZONE, rep); + } while (ret !=3D 0 && errno =3D=3D EINTR); + if (ret !=3D 0) { + error_report("%d: ioctl BLKREPORTZONE at %" PRId64 " failed %d= ", + fd, sector, errno); + return -errno; + } + + if (!rep->nr_zones) { + break; + } + + for (i =3D 0; i < rep->nr_zones; i++, n++) { + ret =3D parse_zone(&zones[n], &blkz[i]); + if (ret !=3D 0) { + return ret; + } + + /* The next report should start after the last zone reported */ + sector =3D blkz[i].start + blkz[i].len; + } + } + + *nr_zones =3D n; + return 0; +} +#endif + +#if defined(CONFIG_BLKZONED) +static int handle_aiocb_zone_mgmt(void *opaque) +{ + RawPosixAIOData *aiocb =3D opaque; + int fd =3D aiocb->aio_fildes; + uint64_t sector =3D aiocb->aio_offset / 512; + int64_t nr_sectors =3D aiocb->aio_nbytes / 512; + struct blk_zone_range range; + int ret; + + /* Execute the operation */ + range.sector =3D sector; + range.nr_sectors =3D nr_sectors; + do { + ret =3D ioctl(fd, aiocb->zone_mgmt.op, &range); + } while (ret !=3D 0 && errno =3D=3D EINTR); + + return ret; +} +#endif + static int handle_aiocb_copy_range(void *opaque) { RawPosixAIOData *aiocb =3D opaque; @@ -3032,6 +3236,104 @@ static void raw_account_discard(BDRVRawState *s, ui= nt64_t nbytes, int ret) } } =20 +/* + * zone report - Get a zone block device's information in the form + * of an array of zone descriptors. + * zones is an array of zone descriptors to hold zone information on reply; + * offset can be any byte within the entire size of the device; + * nr_zones is the maxium number of sectors the command should operate on. + */ +#if defined(CONFIG_BLKZONED) +static int coroutine_fn raw_co_zone_report(BlockDriverState *bs, int64_t o= ffset, + unsigned int *nr_zones, + BlockZoneDescriptor *zones) { + BDRVRawState *s =3D bs->opaque; + RawPosixAIOData acb =3D (RawPosixAIOData) { + .bs =3D bs, + .aio_fildes =3D s->fd, + .aio_type =3D QEMU_AIO_ZONE_REPORT, + .aio_offset =3D offset, + .zone_report =3D { + .nr_zones =3D nr_zones, + .zones =3D zones, + }, + }; + + return raw_thread_pool_submit(handle_aiocb_zone_report, &acb); +} +#endif + +/* + * zone management operations - Execute an operation on a zone + */ +#if defined(CONFIG_BLKZONED) +static int coroutine_fn raw_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp= op, + int64_t offset, int64_t len) { + BDRVRawState *s =3D bs->opaque; + RawPosixAIOData acb; + int64_t zone_size, zone_size_mask; + const char *op_name; + unsigned long zo; + int ret; + int64_t capacity =3D bs->total_sectors << BDRV_SECTOR_BITS; + + zone_size =3D bs->bl.zone_size; + zone_size_mask =3D zone_size - 1; + if (offset & zone_size_mask) { + error_report("sector offset %" PRId64 " is not aligned to zone siz= e " + "%" PRId64 "", offset / 512, zone_size / 512); + return -EINVAL; + } + + if (((offset + len) < capacity && len & zone_size_mask) || + offset + len > capacity) { + error_report("number of sectors %" PRId64 " is not aligned to zone= size" + " %" PRId64 "", len / 512, zone_size / 512); + return -EINVAL; + } + + switch (op) { + case BLK_ZO_OPEN: + op_name =3D "BLKOPENZONE"; + zo =3D BLKOPENZONE; + break; + case BLK_ZO_CLOSE: + op_name =3D "BLKCLOSEZONE"; + zo =3D BLKCLOSEZONE; + break; + case BLK_ZO_FINISH: + op_name =3D "BLKFINISHZONE"; + zo =3D BLKFINISHZONE; + break; + case BLK_ZO_RESET: + op_name =3D "BLKRESETZONE"; + zo =3D BLKRESETZONE; + break; + default: + error_report("Unsupported zone op: 0x%x", op); + return -ENOTSUP; + } + + acb =3D (RawPosixAIOData) { + .bs =3D bs, + .aio_fildes =3D s->fd, + .aio_type =3D QEMU_AIO_ZONE_MGMT, + .aio_offset =3D offset, + .aio_nbytes =3D len, + .zone_mgmt =3D { + .op =3D zo, + }, + }; + + ret =3D raw_thread_pool_submit(handle_aiocb_zone_mgmt, &acb); + if (ret !=3D 0) { + error_report("ioctl %s failed %d", op_name, ret); + } + + return ret; +} +#endif + static coroutine_fn int raw_do_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes, bool blkdev) @@ -3787,6 +4089,13 @@ static BlockDriver bdrv_host_device =3D { #ifdef __linux__ .bdrv_co_ioctl =3D hdev_co_ioctl, #endif + + /* zoned device */ +#if defined(CONFIG_BLKZONED) + /* zone management operations */ + .bdrv_co_zone_report =3D raw_co_zone_report, + .bdrv_co_zone_mgmt =3D raw_co_zone_mgmt, +#endif }; =20 #if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel= __) diff --git a/block/io.c b/block/io.c index 6fa1993374..74bab69b0f 100644 --- a/block/io.c +++ b/block/io.c @@ -3115,6 +3115,47 @@ out: return co.ret; } =20 +int coroutine_fn bdrv_co_zone_report(BlockDriverState *bs, int64_t offset, + unsigned int *nr_zones, + BlockZoneDescriptor *zones) +{ + BlockDriver *drv =3D bs->drv; + CoroutineIOCompletion co =3D { + .coroutine =3D qemu_coroutine_self(), + }; + IO_CODE(); + + bdrv_inc_in_flight(bs); + if (!drv || !drv->bdrv_co_zone_report || bs->bl.zoned =3D=3D BLK_Z_NON= E) { + co.ret =3D -ENOTSUP; + goto out; + } + co.ret =3D drv->bdrv_co_zone_report(bs, offset, nr_zones, zones); +out: + bdrv_dec_in_flight(bs); + return co.ret; +} + +int coroutine_fn bdrv_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, + int64_t offset, int64_t len) +{ + BlockDriver *drv =3D bs->drv; + CoroutineIOCompletion co =3D { + .coroutine =3D qemu_coroutine_self(), + }; + IO_CODE(); + + bdrv_inc_in_flight(bs); + if (!drv || !drv->bdrv_co_zone_mgmt || bs->bl.zoned =3D=3D BLK_Z_NONE)= { + co.ret =3D -ENOTSUP; + goto out; + } + co.ret =3D drv->bdrv_co_zone_mgmt(bs, op, offset, len); +out: + bdrv_dec_in_flight(bs); + return co.ret; +} + void *qemu_blockalign(BlockDriverState *bs, size_t size) { IO_CODE(); diff --git a/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 Fri May 10 01:51:43 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682685702; cv=none; d=zohomail.com; s=zohoarc; b=SUs8iPeExKYc+a1WrOZyboYqEiT1THs9DawlSTKHgRNiCeDU3pc4VhV36VfbYB5fYvd0qxXBaqQuB+UKV5/3juT0LuB0g8/A2kB2hVQ3posK57JpjDvspWObt4TQF9pLW9pE+wLDtcOhwjrYFNMEfWmjSl+d+jZTBBqBBu3q+jE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682685702; 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=yeMdDfKzhdNutSfvOj4H62HA9JNU+Nd/HWAlu/9dPNI=; b=WxCXuJK05D117NnWqGmnfdIzxLsjvuH7n7MWkoIBwVs49v0C6iWLV0gVjiYzXI5dXiTFmQwX7V+x4rYOfqsGaQufIzrvwXAVxsXO01dWFgnu/sYAl2TZYD3bnfRegpqXXgMVhfpINFZMjOPvwdz4wkNBcu8S3VZt2fvxltNCSUE= 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 1682685702641264.6768627876131; Fri, 28 Apr 2023 05:41:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1psNPI-00078k-9v; Fri, 28 Apr 2023 08:41:01 -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 1psNOq-0006n6-HA for qemu-devel@nongnu.org; Fri, 28 Apr 2023 08:40:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1psNOj-0000VF-8m for qemu-devel@nongnu.org; Fri, 28 Apr 2023 08:40:26 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-637-1ZAzQ034NXCaeD3mxaj7Nw-1; Fri, 28 Apr 2023 08:40:08 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 151F42808E72; Fri, 28 Apr 2023 12:40:08 +0000 (UTC) Received: from localhost (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 53E0AC15BA0; Fri, 28 Apr 2023 12:40:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682685612; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yeMdDfKzhdNutSfvOj4H62HA9JNU+Nd/HWAlu/9dPNI=; b=X6N5tfFyoSiku5vaXttO+1qmQr22ozUk44RuzHldOaitB0sj48BYh/ZPic1hHRzBoh/grH tPJRVnFdJQe8f4sE+Vuf6UxpjFXXum5A24yempXmb/9z/gfgpx6pdTs+I36z5PoAySRqyh FMDxUDEx78k3WxQYdEzXVdBIwpdNRyA= X-MC-Unique: 1ZAzQ034NXCaeD3mxaj7Nw-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Raphael Norwitz , Julia Suvorova , Cornelia Huck , Eric Blake , Paolo Bonzini , Aarushi Mehta , Stefan Hajnoczi , Richard Henderson , Kevin Wolf , Markus Armbruster , Stefano Garzarella , qemu-block@nongnu.org, Hanna Reitz , Fam Zheng , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Michael S. Tsirkin" , kvm@vger.kernel.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sam Li , Damien Le Moal , Hannes Reinecke , Dmitry Fomichev Subject: [PULL 04/17] block/raw-format: add zone operations to pass through requests Date: Fri, 28 Apr 2023 08:39:41 -0400 Message-Id: <20230428123954.179035-5-stefanha@redhat.com> In-Reply-To: <20230428123954.179035-1-stefanha@redhat.com> References: <20230428123954.179035-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682685703694100002 From: Sam Li 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 Signed-off-by: Stefan Hajnoczi Message-id: 20230427172019.3345-5-faithilikerun@gmail.com 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 Fri May 10 01:51:43 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682685768; cv=none; d=zohomail.com; s=zohoarc; b=Cx9D6M6DaXplMrHSv2Zut0zsSHqOY1miNiUZzJoeSSdIVwxNV0OCk0Do9GV8ZcxHS3k3oiIdmXSMbfmt6uT8Cc7Nntiq5uFPIGcTQB2mc2D52JqerXgA1BYOJnzUo9Km8mV2JJ34s82B7j9Uolj7ht3AAGPr/dp4XdFN6IUE0PY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682685768; 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=V6/rjjxDXTwqzgBL9BI2gXN3wi8TqWGRROs8WPrhNrs=; b=IkbTeCGVABLjgIHo7pWjxV9Q2Orf3mDsyUUZm+je721M62h28Bp7aUCIv76R/qxzZkK+QeiR6ahs8rfOxE+oFwvWV50NhVcSrojWXTSeTiVH+swNdZausLSxXppcotpYKrDcwWfTNBvGfdyd3S6MkV9Yn7Nxri4hUtQ8OBEDe50= 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 1682685768193880.6478297830071; Fri, 28 Apr 2023 05:42:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1psNPA-0006w5-OD; Fri, 28 Apr 2023 08:40: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 1psNOq-0006n7-Hc for qemu-devel@nongnu.org; Fri, 28 Apr 2023 08:40:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1psNOj-0000VU-96 for qemu-devel@nongnu.org; Fri, 28 Apr 2023 08:40:28 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-166-2H-GjdQ2PE-Kplk-0dInZA-1; Fri, 28 Apr 2023 08:40:12 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9E80538237C8; Fri, 28 Apr 2023 12:40:10 +0000 (UTC) Received: from localhost (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0261E2166B4F; Fri, 28 Apr 2023 12:40:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682685615; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=V6/rjjxDXTwqzgBL9BI2gXN3wi8TqWGRROs8WPrhNrs=; b=UM7vy8equPoTjDr4dyGMDKJJKkoH3lOke/gkLXdBqyh+XL6JwZwaRlXbq5nauPUwMbGAfF 7WHu3Aj9PGcweZKliMBrNEm2zNbjzqUnZ2+IYs2IrAfjHmRhxRaCGqOD1U7x1x9hAQXyB/ +FewXgBb9OvtyimNEgGEVrRYkZ5L0Lg= X-MC-Unique: 2H-GjdQ2PE-Kplk-0dInZA-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Raphael Norwitz , Julia Suvorova , Cornelia Huck , Eric Blake , Paolo Bonzini , Aarushi Mehta , Stefan Hajnoczi , Richard Henderson , Kevin Wolf , Markus Armbruster , Stefano Garzarella , qemu-block@nongnu.org, Hanna Reitz , Fam Zheng , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Michael S. Tsirkin" , kvm@vger.kernel.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sam Li , Hannes Reinecke , Dmitry Fomichev Subject: [PULL 05/17] block: add zoned BlockDriver check to block layer Date: Fri, 28 Apr 2023 08:39:42 -0400 Message-Id: <20230428123954.179035-6-stefanha@redhat.com> In-Reply-To: <20230428123954.179035-1-stefanha@redhat.com> References: <20230428123954.179035-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682685769029100003 From: Sam Li 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 Signed-off-by: Stefan Hajnoczi Message-id: 20230427172019.3345-6-faithilikerun@gmail.com 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 --- include/block/block_int-common.h | 5 +++++ block.c | 19 +++++++++++++++++++ block/file-posix.c | 12 ++++++++++++ block/raw-format.c | 1 + 4 files changed, 37 insertions(+) diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 997d539890..3482cfa79e 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -137,6 +137,11 @@ struct BlockDriver { */ bool is_format; =20 + /* + * Set to true if the BlockDriver supports zoned children. + */ + bool supports_zoned_children; + /* * Drivers not implementing bdrv_parse_filename nor bdrv_open should h= ave * this field set to true, except ones that are defined only by their diff --git a/block.c b/block.c index 5ec1a3897e..f67317c2b9 100644 --- a/block.c +++ b/block.c @@ -7967,6 +7967,25 @@ void bdrv_add_child(BlockDriverState *parent_bs, Blo= ckDriverState *child_bs, return; } =20 + /* + * Non-zoned block drivers do not follow zoned storage constraints + * (i.e. sequential writes to zones). Refuse mixing zoned and non-zoned + * drivers in a graph. + */ + if (!parent_bs->drv->supports_zoned_children && + child_bs->bl.zoned =3D=3D BLK_Z_HM) { + /* + * The host-aware model allows zoned storage constraints and random + * write. Allow mixing host-aware and non-zoned drivers. Using + * host-aware device as a regular device. + */ + error_setg(errp, "Cannot add a %s child to a %s parent", + child_bs->bl.zoned =3D=3D BLK_Z_HM ? "zoned" : "non-zon= ed", + parent_bs->drv->supports_zoned_children ? + "support zoned children" : "not support zoned children"= ); + return; + } + if (!QLIST_EMPTY(&child_bs->parents)) { error_setg(errp, "The node %s already has a parent", child_bs->node_name); diff --git a/block/file-posix.c b/block/file-posix.c index 3b6575d771..67d4ec6ac5 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -776,6 +776,18 @@ static int raw_open_common(BlockDriverState *bs, QDict= *options, goto fail; } } +#ifdef CONFIG_BLKZONED + /* + * The kernel page cache does not reliably work for writes to SWR zones + * of zoned block device because it can not guarantee the order of wri= tes. + */ + if ((bs->bl.zoned !=3D BLK_Z_NONE) && + (!(s->open_flags & O_DIRECT))) { + error_setg(errp, "The driver supports zoned devices, and it requir= es " + "cache.direct=3Don, which was not specified."); + return -EINVAL; /* No host kernel page cache */ + } +#endif =20 if (S_ISBLK(st.st_mode)) { #ifdef __linux__ diff --git a/block/raw-format.c b/block/raw-format.c index f167448462..1a1dce8da4 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -623,6 +623,7 @@ static void raw_child_perm(BlockDriverState *bs, BdrvCh= ild *c, BlockDriver bdrv_raw =3D { .format_name =3D "raw", .instance_size =3D sizeof(BDRVRawState), + .supports_zoned_children =3D true, .bdrv_probe =3D &raw_probe, .bdrv_reopen_prepare =3D &raw_reopen_prepare, .bdrv_reopen_commit =3D &raw_reopen_commit, --=20 2.40.0 From nobody Fri May 10 01:51:43 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682685820; cv=none; d=zohomail.com; s=zohoarc; b=cww3lBVaJOKf1dOvcnrIpsqm+usUFvp7/BqgAnjuzQZ/9LoHyvQ8V2vYVb/cvMOCgt6ruhysQKyR1Lwj/JfKRvwqaVNzhexzJyY51J8dN+6N+z688Ut4gXvJAw7nJABPKMYyBKDSChsa1sKH9A9Uqf3tk8RBpDhp1wy/wLb24xs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682685820; 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=ASo/M27XEwJQrnB/OXsHap/SXpK8mavLaKAWB+uxFUs=; b=IQ7tKomOrIsR4SULPrKrci8bcVw57m33yr5RZd9UuIBh4w2sRwTDq/2NnZxC+1f4401x3auUXDKx6gqFgUjy1fhI8NMcYUuOFpxYhRwG2ac5zjGYn8T7YX7gGcqpOSQnTg1VcaoLSHIcbMHaE7bGuuodHGc1eFdSgJDExdh8zzk= 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 1682685820385317.87604814659824; Fri, 28 Apr 2023 05:43:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1psNPb-0007jO-JV; Fri, 28 Apr 2023 08:41:20 -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 1psNOr-0006pI-GU for qemu-devel@nongnu.org; Fri, 28 Apr 2023 08:40:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1psNOj-0000Vh-Bt for qemu-devel@nongnu.org; Fri, 28 Apr 2023 08:40:28 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-269-kklycAtNP5GuhxUKQEmhKw-1; Fri, 28 Apr 2023 08:40:14 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6569A800047; Fri, 28 Apr 2023 12:40:13 +0000 (UTC) Received: from localhost (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id BD44F2027043; Fri, 28 Apr 2023 12:40:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682685617; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ASo/M27XEwJQrnB/OXsHap/SXpK8mavLaKAWB+uxFUs=; b=EyeYKH/4FSlC7bHM4XL+f/w/2tlYgd78veAKe0iyVdktnUk/Kix4ebHwU8aH833EeyQ2sb G3GZaWwNSuguRAuUcncxbmVYE1ObIbhLgG8RLFrev2jGIqNC7dyUH1RvyqyTYfmM9KfTKG TIkVPZZDYWWiNEhYixSB9aQMVnQMHEI= X-MC-Unique: kklycAtNP5GuhxUKQEmhKw-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Raphael Norwitz , Julia Suvorova , Cornelia Huck , Eric Blake , Paolo Bonzini , Aarushi Mehta , Stefan Hajnoczi , Richard Henderson , Kevin Wolf , Markus Armbruster , Stefano Garzarella , qemu-block@nongnu.org, Hanna Reitz , Fam Zheng , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Michael S. Tsirkin" , kvm@vger.kernel.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sam Li Subject: [PULL 06/17] iotests: test new zone operations Date: Fri, 28 Apr 2023 08:39:43 -0400 Message-Id: <20230428123954.179035-7-stefanha@redhat.com> In-Reply-To: <20230428123954.179035-1-stefanha@redhat.com> References: <20230428123954.179035-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682685820644100005 From: Sam Li 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 Signed-off-by: Stefan Hajnoczi Message-id: 20230427172019.3345-7-faithilikerun@gmail.com 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 Fri May 10 01:51:43 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682685675; cv=none; d=zohomail.com; s=zohoarc; b=l/gvtMRy/zDP8Lr3rD772QKkL2sXWBeoHJfX12dhZyul0r+wXVwI9AWW8c9ezgDBHwlT+SiNQYaNf/bmV6Lrij8bH9H0iE+NL+4GGJQc//YH+pV7D+Y/5NamXQf8iV23eRSD/Fqsaeeo1IawtZIEWXtEL4ugOSZnqX6QXjqZUTs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682685675; 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=Or9qr1HLWkScxj5wpH0XQKCXfRV2RkdYmJOkEJYXowI=; b=Rp5uinXvYc1ll4xbYzDOsYFa914pRgG+C9RlWBHPSzrtRYklJ+GHVBu4+faTfhB51vtockdKRLqmLRWH06BssiD5gYHf/f7nsxIL1hTMuKdhp4ajey7OjPleI05YCQOG7AhaYoiJ+r318E/bs8FA0ILwK9c7cajRcJoSxjPLPdA= 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 1682685675549873.7019561105931; Fri, 28 Apr 2023 05:41:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1psNPQ-0007Aa-4M; Fri, 28 Apr 2023 08:41:09 -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 1psNOt-0006px-RZ for qemu-devel@nongnu.org; Fri, 28 Apr 2023 08:40:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1psNOk-0000Vm-4T for qemu-devel@nongnu.org; Fri, 28 Apr 2023 08:40:35 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-26-t754b5QUMd-jew8RkTwIrA-1; Fri, 28 Apr 2023 08:40:16 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9FF32887406; Fri, 28 Apr 2023 12:40:15 +0000 (UTC) Received: from localhost (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0714E35443; Fri, 28 Apr 2023 12:40:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682685617; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Or9qr1HLWkScxj5wpH0XQKCXfRV2RkdYmJOkEJYXowI=; b=S5BacjrVJJZ+dylxDfTVMFC7rq84O+CnEApZTW5xgvakXErYSjbnJxonzoo3SV/VP4jx0E IrQ9g5CyrOROdlZsSax59XwyTkbAS2gvF0P4jNXc4qFdGuf/i4n9yYqVw0n/x5tWFZw/gt +u1sM/RRhDEt7kreWGd+FI7KpK0AWgA= X-MC-Unique: t754b5QUMd-jew8RkTwIrA-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Raphael Norwitz , Julia Suvorova , Cornelia Huck , Eric Blake , Paolo Bonzini , Aarushi Mehta , Stefan Hajnoczi , Richard Henderson , Kevin Wolf , Markus Armbruster , Stefano Garzarella , qemu-block@nongnu.org, Hanna Reitz , Fam Zheng , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Michael S. Tsirkin" , kvm@vger.kernel.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sam Li , Dmitry Fomichev Subject: [PULL 07/17] block: add some trace events for new block layer APIs Date: Fri, 28 Apr 2023 08:39:44 -0400 Message-Id: <20230428123954.179035-8-stefanha@redhat.com> In-Reply-To: <20230428123954.179035-1-stefanha@redhat.com> References: <20230428123954.179035-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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 @redhat.com) X-ZM-MESSAGEID: 1682685676288100003 Content-Type: text/plain; charset="utf-8" From: Sam Li Signed-off-by: Sam Li Reviewed-by: Stefan Hajnoczi Reviewed-by: Dmitry Fomichev Acked-by: Kevin Wolf Signed-off-by: Stefan Hajnoczi Message-id: 20230427172019.3345-8-faithilikerun@gmail.com Message-id: 20230324090605.28361-8-faithilikerun@gmail.com Signed-off-by: Stefan Hajnoczi --- block/file-posix.c | 3 +++ block/trace-events | 2 ++ 2 files changed, 5 insertions(+) diff --git a/block/file-posix.c b/block/file-posix.c index 67d4ec6ac5..701acddbca 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -3271,6 +3271,7 @@ static int coroutine_fn raw_co_zone_report(BlockDrive= rState *bs, int64_t offset, }, }; =20 + trace_zbd_zone_report(bs, *nr_zones, offset >> BDRV_SECTOR_BITS); return raw_thread_pool_submit(handle_aiocb_zone_report, &acb); } #endif @@ -3337,6 +3338,8 @@ static int coroutine_fn raw_co_zone_mgmt(BlockDriverS= tate *bs, BlockZoneOp op, }, }; =20 + trace_zbd_zone_mgmt(bs, op_name, offset >> BDRV_SECTOR_BITS, + len >> BDRV_SECTOR_BITS); ret =3D raw_thread_pool_submit(handle_aiocb_zone_mgmt, &acb); if (ret !=3D 0) { error_report("ioctl %s failed %d", op_name, ret); diff --git a/block/trace-events b/block/trace-events index 48dbf10c66..3f4e1d088a 100644 --- a/block/trace-events +++ b/block/trace-events @@ -209,6 +209,8 @@ file_FindEjectableOpticalMedia(const char *media) "Matc= hing using %s" file_setup_cdrom(const char *partition) "Using %s as optical disc" file_hdev_is_sg(int type, int version) "SG device found: type=3D%d, versio= n=3D%d" file_flush_fdatasync_failed(int err) "errno %d" +zbd_zone_report(void *bs, unsigned int nr_zones, int64_t sector) "bs %p re= port %d zones starting at sector offset 0x%" PRIx64 "" +zbd_zone_mgmt(void *bs, const char *op_name, int64_t sector, int64_t len) = "bs %p %s starts at sector offset 0x%" PRIx64 " over a range of 0x%" PRIx64= " sectors" =20 # ssh.c sftp_error(const char *op, const char *ssh_err, int ssh_err_code, int sftp= _err_code) "%s failed: %s (libssh error code: %d, sftp error code: %d)" --=20 2.40.0 From nobody Fri May 10 01:51:43 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682685785; cv=none; d=zohomail.com; s=zohoarc; b=Ngswltvi1bBoYFYtoCYOtar0jgjFwu8wgJub1nwSz140Sj6+EuzGQ3JEYzgrfmuPdr4zZfEW7lQuBc3ci74AnVBRyfDGjJeU11m1KFCe/QjR99GwWl7ofiGSvlo+3a8CMq7PBgBt7YULcs4QJ/TmY0A9qsdzD96gYUDTbbkYNCI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682685785; 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=kNO7bUwm9cBK4+CqxMAaVkrctpqeObAqrTqFbWZjZlA=; b=AoE1hetRYSyyEu+dQWB0+J6Caw5fLSCg9JBljaDvbAwHzofOIyRUz+cQNG6ANKcC822Ap2XvcpKPi4m5OSkkytGxPZ2L8lAXSy4HZP8+XbETFc0ypvMbNeRuPB4umKE5m0abSyo8hdsI7cp/at3vk3S7159ssZbJRv3sRYtvoQg= 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 1682685785823659.1010018770595; Fri, 28 Apr 2023 05:43:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1psNPs-0008Ck-QA; Fri, 28 Apr 2023 08:41:36 -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 1psNOu-0006q5-Cb for qemu-devel@nongnu.org; Fri, 28 Apr 2023 08:40:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1psNOk-0000Wu-4Z for qemu-devel@nongnu.org; Fri, 28 Apr 2023 08:40:34 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-484-ThCvfjjsPyy0PXtlOH5dCA-1; Fri, 28 Apr 2023 08:40:19 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 083583C0E46C; Fri, 28 Apr 2023 12:40:18 +0000 (UTC) Received: from localhost (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 77E224021B9; Fri, 28 Apr 2023 12:40:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682685620; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kNO7bUwm9cBK4+CqxMAaVkrctpqeObAqrTqFbWZjZlA=; b=h5yqDlAhOgHtuCiGpB1Hl2LQTpMFeSuLM5DZEOFb19dVRP5Yl1UijxUd9RxWi+GmZ22iv9 v2iWyRXM9ZTYki75SoAI6Ezi8Ie1hoKYkYTmhxZeMafR/cJ9cgJhhFcrpox90I3+8u+x9j Wj/0JISqOOOBaxwCytng97wE03U4740= X-MC-Unique: ThCvfjjsPyy0PXtlOH5dCA-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Raphael Norwitz , Julia Suvorova , Cornelia Huck , Eric Blake , Paolo Bonzini , Aarushi Mehta , Stefan Hajnoczi , Richard Henderson , Kevin Wolf , Markus Armbruster , Stefano Garzarella , qemu-block@nongnu.org, Hanna Reitz , Fam Zheng , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Michael S. Tsirkin" , kvm@vger.kernel.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sam Li , Damien Le Moal , Dmitry Fomichev Subject: [PULL 08/17] docs/zoned-storage: add zoned device documentation Date: Fri, 28 Apr 2023 08:39:45 -0400 Message-Id: <20230428123954.179035-9-stefanha@redhat.com> In-Reply-To: <20230428123954.179035-1-stefanha@redhat.com> References: <20230428123954.179035-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 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=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682685786327100001 Content-Type: text/plain; charset="utf-8" From: Sam Li 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 Signed-off-by: Stefan Hajnoczi Message-id: 20230427172019.3345-9-faithilikerun@gmail.com 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 and fix pre-formatted command-line indentation. --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..da78db2783 --- /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/n= ullb0 -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 From nobody Fri May 10 01:51:43 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682685767; cv=none; d=zohomail.com; s=zohoarc; b=llj4s9E88/q7HbDyWqcTPeq4p3Bx+lvGCfuligdJrjbTenffvQfeJtHwdaGCL4zGX5emQMsq2zdh/S/8ClxQfdAkIWmv0Kgvx8VeQ/1YpVmoI/PwIwi+RnjPyQBEympbrkr4iZWordGsT4bZgFIbcm+SYsN+TpweEpi8aCEHIVA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682685767; 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=n9hx8swNthm3d9dHaInRN+HJ/JBUo8h7dHzzksYBthw=; b=kFj73NUB21GvzuWUWovGhb1meUHIYkW657k+Hwc9SbpJGoDc/W4StS6modCdxXfRkhsglluniimitjxpzK0vUE70KyAiufLvMt+cJUZ6oTdgNuLjoQyazX55ayIxQ+g4+1TheTjzuNaiTO2JYWSXK+ZIpDbgsGfuGpp0FGgdpOA= 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 1682685767821693.9742796996878; Fri, 28 Apr 2023 05:42:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1psNPy-0000cL-GF; Fri, 28 Apr 2023 08:41:42 -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 1psNOz-0006rU-3H for qemu-devel@nongnu.org; Fri, 28 Apr 2023 08:40:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1psNOq-0000jG-3e for qemu-devel@nongnu.org; Fri, 28 Apr 2023 08:40:40 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-636-dN8BKPE_O1W573ABrpvVdw-1; Fri, 28 Apr 2023 08:40:21 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 159253C0E44F; Fri, 28 Apr 2023 12:40:21 +0000 (UTC) Received: from localhost (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 248EF2027043; Fri, 28 Apr 2023 12:40:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682685626; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=n9hx8swNthm3d9dHaInRN+HJ/JBUo8h7dHzzksYBthw=; b=T9RMUkA1SYK7aErOU3NM+oRaPeEx9vVkrYSpYHPWLbHtsisr10zQEb9+KIoAmnpxbFcjwM 5vsn5eWfIlvuFaIfvCo4kpSnRLfcRGz4veDqdqdH3rVOU1/rfIY8qrFZ9FgmgbSL3bM7KG x6mpfYEKxQOWkHoJiJwbshFT/4l/8fo= X-MC-Unique: dN8BKPE_O1W573ABrpvVdw-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Raphael Norwitz , Julia Suvorova , Cornelia Huck , Eric Blake , Paolo Bonzini , Aarushi Mehta , Stefan Hajnoczi , Richard Henderson , Kevin Wolf , Markus Armbruster , Stefano Garzarella , qemu-block@nongnu.org, Hanna Reitz , Fam Zheng , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Michael S. Tsirkin" , kvm@vger.kernel.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sam Li Subject: [PULL 09/17] file-posix: add tracking of the zone write pointers Date: Fri, 28 Apr 2023 08:39:46 -0400 Message-Id: <20230428123954.179035-10-stefanha@redhat.com> In-Reply-To: <20230428123954.179035-1-stefanha@redhat.com> References: <20230428123954.179035-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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 @redhat.com) X-ZM-MESSAGEID: 1682685769920100005 Content-Type: text/plain; charset="utf-8" From: Sam Li Since Linux doesn't have a user API to issue zone append operations to zoned devices from user space, the file-posix driver is modified to add zone append emulation using regular writes. To do this, the file-posix driver tracks the wp location of all zones of the device. It uses an array of uint64_t. The most significant bit of each wp location indicates if the zone type is conventional zones. The zones wp can be changed due to the following operations issued: - zone reset: change the wp to the start offset of that zone - zone finish: change to the end location of that zone - write to a zone - zone append Signed-off-by: Sam Li Message-id: 20230427172339.3709-2-faithilikerun@gmail.com [Fix errno propagation from handle_aiocb_zone_mgmt() --Stefan] Signed-off-by: Stefan Hajnoczi --- include/block/block-common.h | 14 +++ include/block/block_int-common.h | 5 + block/file-posix.c | 178 ++++++++++++++++++++++++++++++- 3 files changed, 193 insertions(+), 4 deletions(-) diff --git a/include/block/block-common.h b/include/block/block-common.h index 1576fcf2ed..93196229ac 100644 --- a/include/block/block-common.h +++ b/include/block/block-common.h @@ -118,6 +118,14 @@ typedef struct BlockZoneDescriptor { BlockZoneState state; } BlockZoneDescriptor; =20 +/* + * Track write pointers of a zone in bytes. + */ +typedef struct BlockZoneWps { + CoMutex colock; + uint64_t wp[]; +} BlockZoneWps; + typedef struct BlockDriverInfo { /* in bytes, 0 if irrelevant */ int cluster_size; @@ -240,6 +248,12 @@ typedef enum { #define BDRV_SECTOR_BITS 9 #define BDRV_SECTOR_SIZE (1ULL << BDRV_SECTOR_BITS) =20 +/* + * Get the first most significant bit of wp. If it is zero, then + * the zone type is SWR. + */ +#define BDRV_ZT_IS_CONV(wp) (wp & (1ULL << 63)) + #define BDRV_REQUEST_MAX_SECTORS MIN_CONST(SIZE_MAX >> BDRV_SECTOR_BITS, \ INT_MAX >> BDRV_SECTOR_BITS) #define BDRV_REQUEST_MAX_BYTES (BDRV_REQUEST_MAX_SECTORS << BDRV_SECTOR_BI= TS) diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 3482cfa79e..d138a399c7 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -890,6 +890,8 @@ typedef struct BlockLimits { =20 /* maximum number of active zones */ int64_t max_active_zones; + + int64_t write_granularity; } BlockLimits; =20 typedef struct BdrvOpBlocker BdrvOpBlocker; @@ -1251,6 +1253,9 @@ struct BlockDriverState { CoMutex bsc_modify_lock; /* Always non-NULL, but must only be dereferenced under an RCU read gu= ard */ BdrvBlockStatusCache *block_status_cache; + + /* array of write pointers' location of each zone in the zoned device.= */ + BlockZoneWps *wps; }; =20 struct BlockBackendRootState { diff --git a/block/file-posix.c b/block/file-posix.c index 701acddbca..e7ad6bb4e7 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1327,9 +1327,93 @@ static int hdev_get_max_segments(int fd, struct stat= *st) } =20 #if defined(CONFIG_BLKZONED) +/* + * If the reset_all flag is true, then the wps of zone whose state is + * not readonly or offline should be all reset to the start sector. + * Else, take the real wp of the device. + */ +static int get_zones_wp(BlockDriverState *bs, int fd, int64_t offset, + unsigned int nrz, bool reset_all) +{ + struct blk_zone *blkz; + size_t rep_size; + uint64_t sector =3D offset >> BDRV_SECTOR_BITS; + BlockZoneWps *wps =3D bs->wps; + unsigned int j =3D offset / bs->bl.zone_size; + unsigned int n =3D 0, i =3D 0; + int ret; + 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, offset, errno); + return -errno; + } + + if (!rep->nr_zones) { + break; + } + + for (i =3D 0; i < rep->nr_zones; ++i, ++n, ++j) { + /* + * The wp tracking cares only about sequential writes required= and + * sequential write preferred zones so that the wp can advance= to + * the right location. + * Use the most significant bit of the wp location to indicate= the + * zone type: 0 for SWR/SWP zones and 1 for conventional zones. + */ + if (blkz[i].type =3D=3D BLK_ZONE_TYPE_CONVENTIONAL) { + wps->wp[j] |=3D 1ULL << 63; + } else { + switch(blkz[i].cond) { + case BLK_ZONE_COND_FULL: + case BLK_ZONE_COND_READONLY: + /* Zone not writable */ + wps->wp[j] =3D (blkz[i].start + blkz[i].len) << BDRV_S= ECTOR_BITS; + break; + case BLK_ZONE_COND_OFFLINE: + /* Zone not writable nor readable */ + wps->wp[j] =3D (blkz[i].start) << BDRV_SECTOR_BITS; + break; + default: + if (reset_all) { + wps->wp[j] =3D blkz[i].start << BDRV_SECTOR_BITS; + } else { + wps->wp[j] =3D blkz[i].wp << BDRV_SECTOR_BITS; + } + break; + } + } + } + sector =3D blkz[i - 1].start + blkz[i - 1].len; + } + + return 0; +} + +static void update_zones_wp(BlockDriverState *bs, int fd, int64_t offset, + unsigned int nrz) +{ + if (get_zones_wp(bs, fd, offset, nrz, 0) < 0) { + error_report("update zone wp failed"); + } +} + static void raw_refresh_zoned_limits(BlockDriverState *bs, struct stat *st, Error **errp) { + BDRVRawState *s =3D bs->opaque; BlockZoneModel zoned; int ret; =20 @@ -1380,6 +1464,23 @@ static void raw_refresh_zoned_limits(BlockDriverStat= e *bs, struct stat *st, if (ret > 0) { bs->bl.max_append_sectors =3D ret >> BDRV_SECTOR_BITS; } + + ret =3D get_sysfs_long_val(st, "physical_block_size"); + if (ret >=3D 0) { + bs->bl.write_granularity =3D ret; + } + + /* The refresh_limits() function can be called multiple times. */ + g_free(bs->wps); + bs->wps =3D g_malloc(sizeof(BlockZoneWps) + + sizeof(int64_t) * bs->bl.nr_zones); + ret =3D get_zones_wp(bs, s->fd, 0, bs->bl.nr_zones, 0); + if (ret < 0) { + error_setg_errno(errp, -ret, "report wps failed"); + bs->wps =3D NULL; + return; + } + qemu_co_mutex_init(&bs->wps->colock); } #else /* !defined(CONFIG_BLKZONED) */ static void raw_refresh_zoned_limits(BlockDriverState *bs, struct stat *st, @@ -2065,7 +2166,7 @@ static int handle_aiocb_zone_mgmt(void *opaque) ret =3D ioctl(fd, aiocb->zone_mgmt.op, &range); } while (ret !=3D 0 && errno =3D=3D EINTR); =20 - return ret; + return ret < 0 ? -errno : ret; } #endif =20 @@ -2351,9 +2452,15 @@ static int coroutine_fn raw_co_prw(BlockDriverState = *bs, uint64_t offset, { BDRVRawState *s =3D bs->opaque; RawPosixAIOData acb; + int ret; =20 if (fd_open(bs) < 0) return -EIO; +#if defined(CONFIG_BLKZONED) + if (type & QEMU_AIO_WRITE && bs->wps) { + qemu_co_mutex_lock(&bs->wps->colock); + } +#endif =20 /* * When using O_DIRECT, the request must be aligned to be able to use @@ -2366,12 +2473,15 @@ static int coroutine_fn raw_co_prw(BlockDriverState= *bs, uint64_t offset, #ifdef CONFIG_LINUX_IO_URING } else if (s->use_linux_io_uring) { assert(qiov->size =3D=3D bytes); - return luring_co_submit(bs, s->fd, offset, qiov, type); + ret =3D luring_co_submit(bs, s->fd, offset, qiov, type); + goto out; #endif #ifdef CONFIG_LINUX_AIO } else if (s->use_linux_aio) { assert(qiov->size =3D=3D bytes); - return laio_co_submit(s->fd, offset, qiov, type, s->aio_max_batch); + ret =3D laio_co_submit(s->fd, offset, qiov, type, + s->aio_max_batch); + goto out; #endif } =20 @@ -2388,7 +2498,35 @@ static int coroutine_fn raw_co_prw(BlockDriverState = *bs, uint64_t offset, }; =20 assert(qiov->size =3D=3D bytes); - return raw_thread_pool_submit(handle_aiocb_rw, &acb); + ret =3D raw_thread_pool_submit(handle_aiocb_rw, &acb); + goto out; /* Avoid the compiler err of unused label */ + +out: +#if defined(CONFIG_BLKZONED) +{ + BlockZoneWps *wps =3D bs->wps; + if (ret =3D=3D 0) { + if (type & QEMU_AIO_WRITE && wps && bs->bl.zone_size) { + uint64_t *wp =3D &wps->wp[offset / bs->bl.zone_size]; + if (!BDRV_ZT_IS_CONV(*wp)) { + /* Advance the wp if needed */ + if (offset + bytes > *wp) { + *wp =3D offset + bytes; + } + } + } + } else { + if (type & QEMU_AIO_WRITE) { + update_zones_wp(bs, s->fd, 0, 1); + } + } + + if (type & QEMU_AIO_WRITE && wps) { + qemu_co_mutex_unlock(&wps->colock); + } +} +#endif + return ret; } =20 static int coroutine_fn raw_co_preadv(BlockDriverState *bs, int64_t offset, @@ -2491,6 +2629,9 @@ static void raw_close(BlockDriverState *bs) BDRVRawState *s =3D bs->opaque; =20 if (s->fd >=3D 0) { +#if defined(CONFIG_BLKZONED) + g_free(bs->wps); +#endif qemu_close(s->fd); s->fd =3D -1; } @@ -3288,6 +3429,7 @@ static int coroutine_fn raw_co_zone_mgmt(BlockDriverS= tate *bs, BlockZoneOp op, const char *op_name; unsigned long zo; int ret; + BlockZoneWps *wps =3D bs->wps; int64_t capacity =3D bs->total_sectors << BDRV_SECTOR_BITS; =20 zone_size =3D bs->bl.zone_size; @@ -3305,6 +3447,14 @@ static int coroutine_fn raw_co_zone_mgmt(BlockDriver= State *bs, BlockZoneOp op, return -EINVAL; } =20 + uint32_t i =3D offset / bs->bl.zone_size; + uint32_t nrz =3D len / bs->bl.zone_size; + uint64_t *wp =3D &wps->wp[i]; + if (BDRV_ZT_IS_CONV(*wp) && len !=3D capacity) { + error_report("zone mgmt operations are not allowed for conventiona= l zones"); + return -EIO; + } + switch (op) { case BLK_ZO_OPEN: op_name =3D "BLKOPENZONE"; @@ -3342,7 +3492,27 @@ static int coroutine_fn raw_co_zone_mgmt(BlockDriver= State *bs, BlockZoneOp op, len >> BDRV_SECTOR_BITS); ret =3D raw_thread_pool_submit(handle_aiocb_zone_mgmt, &acb); if (ret !=3D 0) { + update_zones_wp(bs, s->fd, offset, i); error_report("ioctl %s failed %d", op_name, ret); + return ret; + } + + if (zo =3D=3D BLKRESETZONE && len =3D=3D capacity) { + ret =3D get_zones_wp(bs, s->fd, 0, bs->bl.nr_zones, 1); + if (ret < 0) { + error_report("reporting single wp failed"); + return ret; + } + } else if (zo =3D=3D BLKRESETZONE) { + for (unsigned int j =3D 0; j < nrz; ++j) { + wp[j] =3D offset + j * zone_size; + } + } else if (zo =3D=3D BLKFINISHZONE) { + for (unsigned int j =3D 0; j < nrz; ++j) { + /* The zoned device allows the last zone smaller that the + * zone size. */ + wp[j] =3D MIN(offset + (j + 1) * zone_size, offset + len); + } } =20 return ret; --=20 2.40.0 From nobody Fri May 10 01:51:43 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682685724; cv=none; d=zohomail.com; s=zohoarc; b=IHaTd8TR4uTip1bv0BpdgsZy8CrbmmPQUeJXAC5KQK9NgmoAG4117utPwzyY/wsQ/M83FLp5rJMxox++KY5ZhJVK1cud+FfTy34omTmsQ0FYooqu+UmVIssc4QdWN3uqNnsr33i1v9vS1+LLgHa0ByJ79QMACieFhEhr1vzVa9U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682685724; 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=UIhiZvhw4a5alv+XgMvVCIKlM42FanA9cKWfI6IFspk=; b=fTw0GiB60l8M0TfuPLrCzDAZU1MHmoY6trsHGdDGB+n+//aNboy9KXdZKO6M4KgWYpwt8tz9XjZ9TTXg3BP5cpR02v+ZX3CBTFEvh+FohSIQw9H8bNOOAsfiDEKzhHW+Ez7Q3zItAekoLOiVi2GuUI31I1p0Q0jLU+g/CU7tpP4= 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 1682685724571705.06807022549; Fri, 28 Apr 2023 05:42:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1psNQ0-0000kf-6s; Fri, 28 Apr 2023 08:41:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1psNP4-0006tk-Nl for qemu-devel@nongnu.org; Fri, 28 Apr 2023 08:40:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1psNOq-0000jg-3r for qemu-devel@nongnu.org; Fri, 28 Apr 2023 08:40:41 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-209-kV5JVlKZNiyytNhpAR1xAQ-1; Fri, 28 Apr 2023 08:40:24 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B91A8887404; Fri, 28 Apr 2023 12:40:23 +0000 (UTC) Received: from localhost (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id B75B114171FF; Fri, 28 Apr 2023 12:40:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682685627; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UIhiZvhw4a5alv+XgMvVCIKlM42FanA9cKWfI6IFspk=; b=jJnzCQu+lOf2mWMrIdBOyTJUJZUXllwU9+MBpSotHvS8yp7ctX80GOYjW3uRWaXnpSXSjq mXkwfSTw4JNCK0uOsdlkMipeVs/iWDz4kDlKdO+0XRAbCgz2AMq4F2OpiFrpTzMAsVJYd7 Mwtw8ILvhh7CVxw6M5SNL3diGR0klSE= X-MC-Unique: kV5JVlKZNiyytNhpAR1xAQ-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Raphael Norwitz , Julia Suvorova , Cornelia Huck , Eric Blake , Paolo Bonzini , Aarushi Mehta , Stefan Hajnoczi , Richard Henderson , Kevin Wolf , Markus Armbruster , Stefano Garzarella , qemu-block@nongnu.org, Hanna Reitz , Fam Zheng , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Michael S. Tsirkin" , kvm@vger.kernel.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sam Li , Dmitry Fomichev Subject: [PULL 10/17] block: introduce zone append write for zoned devices Date: Fri, 28 Apr 2023 08:39:47 -0400 Message-Id: <20230428123954.179035-11-stefanha@redhat.com> In-Reply-To: <20230428123954.179035-1-stefanha@redhat.com> References: <20230428123954.179035-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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 @redhat.com) X-ZM-MESSAGEID: 1682685724831100001 Content-Type: text/plain; charset="utf-8" From: Sam Li A zone append command is a write operation that specifies the first logical block of a zone as the write position. When writing to a zoned block device using zone append, the byte offset of the call may point at any position within the zone to which the data is being appended. Upon completion the device will respond with the position where the data has been written in the zone. Signed-off-by: Sam Li Reviewed-by: Dmitry Fomichev Reviewed-by: Stefan Hajnoczi Message-id: 20230427172339.3709-3-faithilikerun@gmail.com Signed-off-by: Stefan Hajnoczi --- include/block/block-io.h | 4 ++ include/block/block_int-common.h | 3 ++ include/block/raw-aio.h | 4 +- include/sysemu/block-backend-io.h | 9 +++++ block/block-backend.c | 61 +++++++++++++++++++++++++++++++ block/file-posix.c | 58 +++++++++++++++++++++++++---- block/io.c | 27 ++++++++++++++ block/io_uring.c | 4 ++ block/linux-aio.c | 3 ++ block/raw-format.c | 8 ++++ 10 files changed, 173 insertions(+), 8 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index 58f415ab64..f44e524a1c 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -119,6 +119,10 @@ int coroutine_fn GRAPH_RDLOCK bdrv_co_zone_report(Bloc= kDriverState *bs, int coroutine_fn GRAPH_RDLOCK bdrv_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, int64_t offset, int64_t le= n); +int coroutine_fn GRAPH_RDLOCK bdrv_co_zone_append(BlockDriverState *bs, + int64_t *offset, + QEMUIOVector *qiov, + BdrvRequestFlags flags); =20 bool bdrv_can_write_zeroes_with_unmap(BlockDriverState *bs); int bdrv_block_status(BlockDriverState *bs, int64_t offset, diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index d138a399c7..9a20ff1768 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -722,6 +722,9 @@ struct BlockDriver { BlockZoneDescriptor *zones); int coroutine_fn (*bdrv_co_zone_mgmt)(BlockDriverState *bs, BlockZoneO= p op, int64_t offset, int64_t len); + int coroutine_fn (*bdrv_co_zone_append)(BlockDriverState *bs, + int64_t *offset, QEMUIOVector *qiov, + BdrvRequestFlags flags); =20 /* removable device specific */ bool coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_is_inserted)( diff --git a/include/block/raw-aio.h b/include/block/raw-aio.h index afb9bdf51b..0fe85ade77 100644 --- a/include/block/raw-aio.h +++ b/include/block/raw-aio.h @@ -30,6 +30,7 @@ #define QEMU_AIO_TRUNCATE 0x0080 #define QEMU_AIO_ZONE_REPORT 0x0100 #define QEMU_AIO_ZONE_MGMT 0x0200 +#define QEMU_AIO_ZONE_APPEND 0x0400 #define QEMU_AIO_TYPE_MASK \ (QEMU_AIO_READ | \ QEMU_AIO_WRITE | \ @@ -40,7 +41,8 @@ QEMU_AIO_COPY_RANGE | \ QEMU_AIO_TRUNCATE | \ QEMU_AIO_ZONE_REPORT | \ - QEMU_AIO_ZONE_MGMT) + QEMU_AIO_ZONE_MGMT | \ + QEMU_AIO_ZONE_APPEND) =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 eb1c1ebfec..d62a7ee773 100644 --- a/include/sysemu/block-backend-io.h +++ b/include/sysemu/block-backend-io.h @@ -53,6 +53,9 @@ BlockAIOCB *blk_aio_zone_report(BlockBackend *blk, int64_= t offset, BlockAIOCB *blk_aio_zone_mgmt(BlockBackend *blk, BlockZoneOp op, int64_t offset, int64_t len, BlockCompletionFunc *cb, void *opaque); +BlockAIOCB *blk_aio_zone_append(BlockBackend *blk, int64_t *offset, + QEMUIOVector *qiov, BdrvRequestFlags flags, + 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); @@ -208,6 +211,12 @@ int coroutine_fn blk_co_zone_mgmt(BlockBackend *blk, B= lockZoneOp 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 coroutine_fn blk_co_zone_append(BlockBackend *blk, int64_t *offset, + QEMUIOVector *qiov, + BdrvRequestFlags flags); +int co_wrapper_mixed blk_zone_append(BlockBackend *blk, int64_t *offset, + QEMUIOVector *qiov, + BdrvRequestFlags flags); =20 int co_wrapper_mixed blk_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes); diff --git a/block/block-backend.c b/block/block-backend.c index 67722eb46d..aa8657e5c8 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1929,6 +1929,45 @@ BlockAIOCB *blk_aio_zone_mgmt(BlockBackend *blk, Blo= ckZoneOp op, return &acb->common; } =20 +static void coroutine_fn blk_aio_zone_append_entry(void *opaque) +{ + BlkAioEmAIOCB *acb =3D opaque; + BlkRwCo *rwco =3D &acb->rwco; + + rwco->ret =3D blk_co_zone_append(rwco->blk, (int64_t *)(uintptr_t)acb-= >bytes, + rwco->iobuf, rwco->flags); + blk_aio_complete(acb); +} + +BlockAIOCB *blk_aio_zone_append(BlockBackend *blk, int64_t *offset, + QEMUIOVector *qiov, BdrvRequestFlags flags, + 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, + .ret =3D NOT_DONE, + .flags =3D flags, + .iobuf =3D qiov, + }; + acb->bytes =3D (int64_t)(uintptr_t)offset; + acb->has_returned =3D false; + + co =3D qemu_coroutine_create(blk_aio_zone_append_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 @@ -1982,6 +2021,28 @@ int coroutine_fn blk_co_zone_mgmt(BlockBackend *blk,= BlockZoneOp op, return ret; } =20 +/* + * Send a zone_append command. + */ +int coroutine_fn blk_co_zone_append(BlockBackend *blk, int64_t *offset, + QEMUIOVector *qiov, BdrvRequestFlags flags) +{ + int ret; + IO_CODE(); + + blk_inc_in_flight(blk); + 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_append(blk_bs(blk), offset, qiov, flags); + 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 e7ad6bb4e7..8fca0eab7b 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -160,6 +160,7 @@ typedef struct BDRVRawState { bool has_write_zeroes:1; bool use_linux_aio:1; bool use_linux_io_uring:1; + int64_t *offset; /* offset of zone append operation */ int page_cache_inconsistent; /* errno from fdatasync failure */ bool has_fallocate; bool needs_alignment; @@ -1702,7 +1703,7 @@ static ssize_t handle_aiocb_rw_vector(RawPosixAIOData= *aiocb) ssize_t len; =20 len =3D RETRY_ON_EINTR( - (aiocb->aio_type & QEMU_AIO_WRITE) ? + (aiocb->aio_type & (QEMU_AIO_WRITE | QEMU_AIO_ZONE_APPEND)) ? qemu_pwritev(aiocb->aio_fildes, aiocb->io.iov, aiocb->io.niov, @@ -1731,7 +1732,7 @@ static ssize_t handle_aiocb_rw_linear(RawPosixAIOData= *aiocb, char *buf) ssize_t len; =20 while (offset < aiocb->aio_nbytes) { - if (aiocb->aio_type & QEMU_AIO_WRITE) { + if (aiocb->aio_type & (QEMU_AIO_WRITE | QEMU_AIO_ZONE_APPEND)) { len =3D pwrite(aiocb->aio_fildes, (const char *)buf + offset, aiocb->aio_nbytes - offset, @@ -1824,7 +1825,7 @@ static int handle_aiocb_rw(void *opaque) } =20 nbytes =3D handle_aiocb_rw_linear(aiocb, buf); - if (!(aiocb->aio_type & QEMU_AIO_WRITE)) { + if (!(aiocb->aio_type & (QEMU_AIO_WRITE | QEMU_AIO_ZONE_APPEND))) { char *p =3D buf; size_t count =3D aiocb->aio_nbytes, copy; int i; @@ -2457,8 +2458,12 @@ static int coroutine_fn raw_co_prw(BlockDriverState = *bs, uint64_t offset, if (fd_open(bs) < 0) return -EIO; #if defined(CONFIG_BLKZONED) - if (type & QEMU_AIO_WRITE && bs->wps) { + if ((type & (QEMU_AIO_WRITE | QEMU_AIO_ZONE_APPEND)) && bs->wps) { qemu_co_mutex_lock(&bs->wps->colock); + if (type & QEMU_AIO_ZONE_APPEND && bs->bl.zone_size) { + int index =3D offset / bs->bl.zone_size; + offset =3D bs->wps->wp[index]; + } } #endif =20 @@ -2506,9 +2511,13 @@ out: { BlockZoneWps *wps =3D bs->wps; if (ret =3D=3D 0) { - if (type & QEMU_AIO_WRITE && wps && bs->bl.zone_size) { + if ((type & (QEMU_AIO_WRITE | QEMU_AIO_ZONE_APPEND)) + && wps && bs->bl.zone_size) { uint64_t *wp =3D &wps->wp[offset / bs->bl.zone_size]; if (!BDRV_ZT_IS_CONV(*wp)) { + if (type & QEMU_AIO_ZONE_APPEND) { + *s->offset =3D *wp; + } /* Advance the wp if needed */ if (offset + bytes > *wp) { *wp =3D offset + bytes; @@ -2516,12 +2525,12 @@ out: } } } else { - if (type & QEMU_AIO_WRITE) { + if (type & (QEMU_AIO_WRITE | QEMU_AIO_ZONE_APPEND)) { update_zones_wp(bs, s->fd, 0, 1); } } =20 - if (type & QEMU_AIO_WRITE && wps) { + if ((type & (QEMU_AIO_WRITE | QEMU_AIO_ZONE_APPEND)) && wps) { qemu_co_mutex_unlock(&wps->colock); } } @@ -3519,6 +3528,40 @@ static int coroutine_fn raw_co_zone_mgmt(BlockDriver= State *bs, BlockZoneOp op, } #endif =20 +#if defined(CONFIG_BLKZONED) +static int coroutine_fn raw_co_zone_append(BlockDriverState *bs, + int64_t *offset, + QEMUIOVector *qiov, + BdrvRequestFlags flags) { + assert(flags =3D=3D 0); + int64_t zone_size_mask =3D bs->bl.zone_size - 1; + int64_t iov_len =3D 0; + int64_t len =3D 0; + BDRVRawState *s =3D bs->opaque; + s->offset =3D offset; + + if (*offset & zone_size_mask) { + error_report("sector offset %" PRId64 " is not aligned to zone siz= e " + "%" PRId32 "", *offset / 512, bs->bl.zone_size / 512); + return -EINVAL; + } + + int64_t wg =3D bs->bl.write_granularity; + int64_t wg_mask =3D wg - 1; + for (int i =3D 0; i < qiov->niov; i++) { + iov_len =3D qiov->iov[i].iov_len; + if (iov_len & wg_mask) { + error_report("len of IOVector[%d] %" PRId64 " is not aligned t= o " + "block size %" PRId64 "", i, iov_len, wg); + return -EINVAL; + } + len +=3D iov_len; + } + + return raw_co_prw(bs, *offset, len, qiov, QEMU_AIO_ZONE_APPEND); +} +#endif + static coroutine_fn int raw_do_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes, bool blkdev) @@ -4280,6 +4323,7 @@ static BlockDriver bdrv_host_device =3D { /* zone management operations */ .bdrv_co_zone_report =3D raw_co_zone_report, .bdrv_co_zone_mgmt =3D raw_co_zone_mgmt, + .bdrv_co_zone_append =3D raw_co_zone_append, #endif }; =20 diff --git a/block/io.c b/block/io.c index 74bab69b0f..20d1da8dc9 100644 --- a/block/io.c +++ b/block/io.c @@ -3156,6 +3156,33 @@ out: return co.ret; } =20 +int coroutine_fn bdrv_co_zone_append(BlockDriverState *bs, int64_t *offset, + QEMUIOVector *qiov, + BdrvRequestFlags flags) +{ + int ret; + BlockDriver *drv =3D bs->drv; + CoroutineIOCompletion co =3D { + .coroutine =3D qemu_coroutine_self(), + }; + IO_CODE(); + + ret =3D bdrv_check_qiov_request(*offset, qiov->size, qiov, 0, NULL); + if (ret < 0) { + return ret; + } + + bdrv_inc_in_flight(bs); + if (!drv || !drv->bdrv_co_zone_append || bs->bl.zoned =3D=3D BLK_Z_NON= E) { + co.ret =3D -ENOTSUP; + goto out; + } + co.ret =3D drv->bdrv_co_zone_append(bs, offset, qiov, flags); +out: + bdrv_dec_in_flight(bs); + return co.ret; +} + void *qemu_blockalign(BlockDriverState *bs, size_t size) { IO_CODE(); diff --git a/block/io_uring.c b/block/io_uring.c index 989f9a99ed..82cab6a5bd 100644 --- a/block/io_uring.c +++ b/block/io_uring.c @@ -350,6 +350,10 @@ static int luring_do_submit(int fd, LuringAIOCB *lurin= gcb, LuringState *s, io_uring_prep_writev(sqes, fd, luringcb->qiov->iov, luringcb->qiov->niov, offset); break; + case QEMU_AIO_ZONE_APPEND: + io_uring_prep_writev(sqes, fd, luringcb->qiov->iov, + luringcb->qiov->niov, offset); + break; case QEMU_AIO_READ: io_uring_prep_readv(sqes, fd, luringcb->qiov->iov, luringcb->qiov->niov, offset); diff --git a/block/linux-aio.c b/block/linux-aio.c index fc50cdd1bf..442c86209b 100644 --- a/block/linux-aio.c +++ b/block/linux-aio.c @@ -394,6 +394,9 @@ static int laio_do_submit(int fd, struct qemu_laiocb *l= aiocb, off_t offset, case QEMU_AIO_WRITE: io_prep_pwritev(iocbs, fd, qiov->iov, qiov->niov, offset); break; + case QEMU_AIO_ZONE_APPEND: + io_prep_pwritev(iocbs, fd, qiov->iov, qiov->niov, offset); + break; case QEMU_AIO_READ: io_prep_preadv(iocbs, fd, qiov->iov, qiov->niov, offset); break; diff --git a/block/raw-format.c b/block/raw-format.c index 1a1dce8da4..9816f1af80 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -332,6 +332,13 @@ raw_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, return bdrv_co_zone_mgmt(bs->file->bs, op, offset, len); } =20 +static int coroutine_fn GRAPH_RDLOCK +raw_co_zone_append(BlockDriverState *bs,int64_t *offset, QEMUIOVector *qio= v, + BdrvRequestFlags flags) +{ + return bdrv_co_zone_append(bs->file->bs, offset, qiov, flags); +} + static int64_t coroutine_fn GRAPH_RDLOCK raw_co_getlength(BlockDriverState *bs) { @@ -637,6 +644,7 @@ BlockDriver bdrv_raw =3D { .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_zone_append =3D &raw_co_zone_append, .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 Fri May 10 01:51:43 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682685714; cv=none; d=zohomail.com; s=zohoarc; b=fNUZdK/Mc1W4kMCtYrilz7CB2LXsLj0xPhSer8yIHYz6/+azRe9Mun8qLzkUprR8/jGk1qQFTCdPGADitOGDGjeXMz24s7cktPqDkdpNhfMw3IEHOYzetsrVLFiKuDbPcjD1AAcQUit1rvQT9x/7xVJZIkegVAfgZbgKO48ioz8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682685714; 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=LAmUYFTUCT3MRaxChcvc4BuynNCGSA2IqXd87VRazGQ=; b=mYon4ctU7iUaQlvUbypqSIZuG+VtuXx8XjRAJbRM9k42CFeUltnzh8EVZvwWpYEX13Yl21xtv848a+FXjfj+WVk7Sjr8FXXq0DhmvEcBQVIz/BObb2dBEla60B+c2LRgxhhz2XXQZ1Q17fA+eWrhJRbVNDBHJWuM4jO0QBPQFTo= 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 1682685713887771.8137075953939; Fri, 28 Apr 2023 05:41:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1psNPE-000719-1L; Fri, 28 Apr 2023 08:40: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 1psNOx-0006qj-3K for qemu-devel@nongnu.org; Fri, 28 Apr 2023 08:40:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1psNOq-0000kA-1o for qemu-devel@nongnu.org; Fri, 28 Apr 2023 08:40:38 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-145-nNGjHlWLOuuzHup0_xDyww-1; Fri, 28 Apr 2023 08:40:27 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8BD7B811E7B; Fri, 28 Apr 2023 12:40:26 +0000 (UTC) Received: from localhost (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id F055D4021B9; Fri, 28 Apr 2023 12:40:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682685630; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LAmUYFTUCT3MRaxChcvc4BuynNCGSA2IqXd87VRazGQ=; b=fxu2SQ8sozlbKUd5Vfs8LtG/dcFFpYeONwfMR2B+ol5JG9zWvSoGVlVq0iIJ7VbLST9Z55 dvFCsSFedf8t9rIJdEcbJiduDnQvKPbP6kVKSG368jx344EVBboqNjTib6nxLp0+nEBYsa DEyYVdSnNvLzWJ1DuC50dTT9rWL0GnE= X-MC-Unique: nNGjHlWLOuuzHup0_xDyww-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Raphael Norwitz , Julia Suvorova , Cornelia Huck , Eric Blake , Paolo Bonzini , Aarushi Mehta , Stefan Hajnoczi , Richard Henderson , Kevin Wolf , Markus Armbruster , Stefano Garzarella , qemu-block@nongnu.org, Hanna Reitz , Fam Zheng , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Michael S. Tsirkin" , kvm@vger.kernel.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sam Li Subject: [PULL 11/17] qemu-iotests: test zone append operation Date: Fri, 28 Apr 2023 08:39:48 -0400 Message-Id: <20230428123954.179035-12-stefanha@redhat.com> In-Reply-To: <20230428123954.179035-1-stefanha@redhat.com> References: <20230428123954.179035-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 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=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682685714617100001 Content-Type: text/plain; charset="utf-8" From: Sam Li The patch tests zone append writes by reporting the zone wp after the completion of the call. "zap -p" option can print the sector offset value after completion, which should be the start sector where the append write begins. Signed-off-by: Sam Li Reviewed-by: Stefan Hajnoczi Message-id: 20230427172339.3709-4-faithilikerun@gmail.com Signed-off-by: Stefan Hajnoczi --- qemu-io-cmds.c | 75 ++++++++++++++++++++++++++++++ tests/qemu-iotests/tests/zoned | 16 +++++++ tests/qemu-iotests/tests/zoned.out | 16 +++++++ 3 files changed, 107 insertions(+) diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index f35ea627d7..3f75d2f5a6 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -1874,6 +1874,80 @@ static const cmdinfo_t zone_reset_cmd =3D { .oneline =3D "reset a zone write pointer in zone block device", }; =20 +static int do_aio_zone_append(BlockBackend *blk, QEMUIOVector *qiov, + int64_t *offset, int flags, int *total) +{ + int async_ret =3D NOT_DONE; + + blk_aio_zone_append(blk, offset, qiov, flags, aio_rw_done, &async_ret); + while (async_ret =3D=3D NOT_DONE) { + main_loop_wait(false); + } + + *total =3D qiov->size; + return async_ret < 0 ? async_ret : 1; +} + +static int zone_append_f(BlockBackend *blk, int argc, char **argv) +{ + int ret; + bool pflag =3D false; + int flags =3D 0; + int total =3D 0; + int64_t offset; + char *buf; + int c, nr_iov; + int pattern =3D 0xcd; + QEMUIOVector qiov; + + if (optind > argc - 3) { + return -EINVAL; + } + + if ((c =3D getopt(argc, argv, "p")) !=3D -1) { + pflag =3D true; + } + + offset =3D cvtnum(argv[optind]); + if (offset < 0) { + print_cvtnum_err(offset, argv[optind]); + return offset; + } + optind++; + nr_iov =3D argc - optind; + buf =3D create_iovec(blk, &qiov, &argv[optind], nr_iov, pattern, + flags & BDRV_REQ_REGISTERED_BUF); + if (buf =3D=3D NULL) { + return -EINVAL; + } + ret =3D do_aio_zone_append(blk, &qiov, &offset, flags, &total); + if (ret < 0) { + printf("zone append failed: %s\n", strerror(-ret)); + goto out; + } + + if (pflag) { + printf("After zap done, the append sector is 0x%" PRIx64 "\n", + tosector(offset)); + } + +out: + qemu_io_free(blk, buf, qiov.size, + flags & BDRV_REQ_REGISTERED_BUF); + qemu_iovec_destroy(&qiov); + return ret; +} + +static const cmdinfo_t zone_append_cmd =3D { + .name =3D "zone_append", + .altname =3D "zap", + .cfunc =3D zone_append_f, + .argmin =3D 3, + .argmax =3D 4, + .args =3D "offset len [len..]", + .oneline =3D "append write a number of bytes at a specified offset", +}; + static int truncate_f(BlockBackend *blk, int argc, char **argv); static const cmdinfo_t truncate_cmd =3D { .name =3D "truncate", @@ -2672,6 +2746,7 @@ static void __attribute((constructor)) init_qemuio_co= mmands(void) qemuio_add_command(&zone_close_cmd); qemuio_add_command(&zone_finish_cmd); qemuio_add_command(&zone_reset_cmd); + qemuio_add_command(&zone_append_cmd); qemuio_add_command(&truncate_cmd); qemuio_add_command(&length_cmd); qemuio_add_command(&info_cmd); diff --git a/tests/qemu-iotests/tests/zoned b/tests/qemu-iotests/tests/zoned index 56f60616b5..3d23ce9cc1 100755 --- a/tests/qemu-iotests/tests/zoned +++ b/tests/qemu-iotests/tests/zoned @@ -82,6 +82,22 @@ 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" +echo +echo +echo "(6) append write" # the physical block size of the device is 4096 +$QEMU_IO $IMG -c "zrp 0 1" +$QEMU_IO $IMG -c "zap -p 0 0x1000 0x2000" +echo "After appending the first zone firstly:" +$QEMU_IO $IMG -c "zrp 0 1" +$QEMU_IO $IMG -c "zap -p 0 0x1000 0x2000" +echo "After appending the first zone secondly:" +$QEMU_IO $IMG -c "zrp 0 1" +$QEMU_IO $IMG -c "zap -p 268435456 0x1000 0x2000" +echo "After appending the second zone firstly:" +$QEMU_IO $IMG -c "zrp 268435456 1" +$QEMU_IO $IMG -c "zap -p 268435456 0x1000 0x2000" +echo "After appending the second zone secondly:" +$QEMU_IO $IMG -c "zrp 268435456 1" =20 # success, all done echo "*** done" diff --git a/tests/qemu-iotests/tests/zoned.out b/tests/qemu-iotests/tests/= zoned.out index b2d061da49..fe53ba4744 100644 --- a/tests/qemu-iotests/tests/zoned.out +++ b/tests/qemu-iotests/tests/zoned.out @@ -50,4 +50,20 @@ 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] + + +(6) append write +start: 0x0, len 0x80000, cap 0x80000, wptr 0x0, zcond:1, [type: 2] +After zap done, the append sector is 0x0 +After appending the first zone firstly: +start: 0x0, len 0x80000, cap 0x80000, wptr 0x18, zcond:2, [type: 2] +After zap done, the append sector is 0x18 +After appending the first zone secondly: +start: 0x0, len 0x80000, cap 0x80000, wptr 0x30, zcond:2, [type: 2] +After zap done, the append sector is 0x80000 +After appending the second zone firstly: +start: 0x80000, len 0x80000, cap 0x80000, wptr 0x80018, zcond:2, [type: 2] +After zap done, the append sector is 0x80018 +After appending the second zone secondly: +start: 0x80000, len 0x80000, cap 0x80000, wptr 0x80030, zcond:2, [type: 2] *** done --=20 2.40.0 From nobody Fri May 10 01:51:43 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682685912; cv=none; d=zohomail.com; s=zohoarc; b=OypwZFzmTqQaSV5iMgv/+iAJ5kdswHeXordspPLQNbH7LweoGzQTdzq4IU3rXI6GKwb3k9s5oKUiNEnulPwOHgZyIkjtxMhoMddkB5skCBDLgDsgMT1U6hA7l9ZSvGeHvRLA5zAZJ1s9+wVpD1i/8ipxtKWHuNU+h4/dhHktl/I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682685912; 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=dh7nqtTKz7RJ73ICCMHEvPvnB0LG2OqGywI2wyppfro=; b=YAtmLjLOjsvbg0Nk8ytDigVVO2cCU9JJ3uhTnRWumFxo212WM5Stp6uvIzrk6IXKGnQ0vRPhtikjzvg32UnoNHcivNFtxoL72WbB0d+QgwCkW4sbxyJ26FyhMes3NIgYJcVvyxHbOCBB+7Q9Fh3zoImeB8t3NtdLwMqGjP9m1uk= 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 1682685912878607.1436820269348; Fri, 28 Apr 2023 05:45:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1psNPu-0008RY-B1; Fri, 28 Apr 2023 08:41:38 -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 1psNOx-0006qk-3T for qemu-devel@nongnu.org; Fri, 28 Apr 2023 08:40:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1psNOq-0000kC-0x for qemu-devel@nongnu.org; Fri, 28 Apr 2023 08:40:38 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-381-wPXY4N5sMwe8vxg8zF5Fdg-1; Fri, 28 Apr 2023 08:40:29 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D46F8185A78B; Fri, 28 Apr 2023 12:40:28 +0000 (UTC) Received: from localhost (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 39DC12027045; Fri, 28 Apr 2023 12:40:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682685630; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dh7nqtTKz7RJ73ICCMHEvPvnB0LG2OqGywI2wyppfro=; b=YfCgoDTqiu+F3x8xI+zxMIgXgUZoypC9/XopVqS2EmV68fC0DMCi/Jrbu7acWrkoahXbsx zwHRvHzs3jvn6zwKg6nIOR2WTsoMCyU/Os9svpdQ7UWyzm5Hvxqr+uIyWrp+fziyLTdRsY ZPYLZrVInDBd/y5epbs5H01WR9MbOFY= X-MC-Unique: wPXY4N5sMwe8vxg8zF5Fdg-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Raphael Norwitz , Julia Suvorova , Cornelia Huck , Eric Blake , Paolo Bonzini , Aarushi Mehta , Stefan Hajnoczi , Richard Henderson , Kevin Wolf , Markus Armbruster , Stefano Garzarella , qemu-block@nongnu.org, Hanna Reitz , Fam Zheng , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Michael S. Tsirkin" , kvm@vger.kernel.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sam Li , Dmitry Fomichev Subject: [PULL 12/17] block: add some trace events for zone append Date: Fri, 28 Apr 2023 08:39:49 -0400 Message-Id: <20230428123954.179035-13-stefanha@redhat.com> In-Reply-To: <20230428123954.179035-1-stefanha@redhat.com> References: <20230428123954.179035-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682685913942100003 Content-Type: text/plain; charset="utf-8" From: Sam Li Signed-off-by: Sam Li Reviewed-by: Dmitry Fomichev Reviewed-by: Stefan Hajnoczi Message-id: 20230427172339.3709-5-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 8fca0eab7b..2d776efa71 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2517,6 +2517,8 @@ out: if (!BDRV_ZT_IS_CONV(*wp)) { if (type & QEMU_AIO_ZONE_APPEND) { *s->offset =3D *wp; + trace_zbd_zone_append_complete(bs, *s->offset + >> BDRV_SECTOR_BITS); } /* Advance the wp if needed */ if (offset + bytes > *wp) { @@ -3558,6 +3560,7 @@ static int coroutine_fn raw_co_zone_append(BlockDrive= rState *bs, len +=3D iov_len; } =20 + trace_zbd_zone_append(bs, *offset >> BDRV_SECTOR_BITS); return raw_co_prw(bs, *offset, len, qiov, QEMU_AIO_ZONE_APPEND); } #endif diff --git a/block/trace-events b/block/trace-events index 3f4e1d088a..32665158d6 100644 --- a/block/trace-events +++ b/block/trace-events @@ -211,6 +211,8 @@ file_hdev_is_sg(int type, int version) "SG device found= : type=3D%d, version=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" +zbd_zone_append(void *bs, int64_t sector) "bs %p append at sector offset 0= x%" PRIx64 "" +zbd_zone_append_complete(void *bs, int64_t sector) "bs %p returns append s= ector 0x%" PRIx64 "" =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 Fri May 10 01:51:43 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682685754; cv=none; d=zohomail.com; s=zohoarc; b=X7PKLi4w6Lwu04cTE45NPVYDCKoptoaA4Dc53mTMLld2xIOUuutUWdncDtXVt0LQXizUNp6x6iiFpEZ/oGfWl44L0z9q0WsgW7MqPCrBsihKMuIoSnlWX9zlt9hQdkSPGemXHycWPBxRynfyZ1avTICoETJNueE5dg1NQFLtMF8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682685754; 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=v3zJrehwEivkieUS3GfBQsYPXsnB/2FTm86lZ47Tb4A=; b=imQFM4oquwuSGzIOa5Hyj5IEBgOU+F9O+FPoLtoKKeq4/BgpmVQab8brq2Zmq5Uoxf8wfVTsDdmKcK7qz87J3yAyV+lwPuKUiedORU7E0/Lyw2GnpkVmW24Pl6NMCQkdsokg1rK3bZWEL/XMfSBXn/uuVxY8SefmIJ74hkG7oCQ= 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 1682685754463157.46635476966242; Fri, 28 Apr 2023 05:42:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1psNPw-0000LG-MF; Fri, 28 Apr 2023 08:41:40 -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 1psNP4-0006uD-RE for qemu-devel@nongnu.org; Fri, 28 Apr 2023 08:40:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1psNOu-0000o5-DB for qemu-devel@nongnu.org; Fri, 28 Apr 2023 08:40:43 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-491-qjiZvqBkMSi68tK9Me_s5Q-1; Fri, 28 Apr 2023 08:40:32 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 87B0E800047; Fri, 28 Apr 2023 12:40:31 +0000 (UTC) Received: from localhost (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id A8DD9C15BA0; Fri, 28 Apr 2023 12:40:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682685635; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=v3zJrehwEivkieUS3GfBQsYPXsnB/2FTm86lZ47Tb4A=; b=WplsK4eKFEeo09vVLXzs/FCaPldBZnaaJUMugC53BH1O4aWK33rX4mUuQSQx+jzjFtD3Wy GwST/TbhmHSL2XEpmOW9Z04mNfKIPc39XGyEnKA6hyNYcyGWkscABb7bgOI3OMMKpaaZVo vDKipZkZpNxO454NoigzjqosQSWYyn4= X-MC-Unique: qjiZvqBkMSi68tK9Me_s5Q-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Raphael Norwitz , Julia Suvorova , Cornelia Huck , Eric Blake , Paolo Bonzini , Aarushi Mehta , Stefan Hajnoczi , Richard Henderson , Kevin Wolf , Markus Armbruster , Stefano Garzarella , qemu-block@nongnu.org, Hanna Reitz , Fam Zheng , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Michael S. Tsirkin" , kvm@vger.kernel.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sam Li , Dmitry Fomichev Subject: [PULL 13/17] include: update virtio_blk headers to v6.3-rc1 Date: Fri, 28 Apr 2023 08:39:50 -0400 Message-Id: <20230428123954.179035-14-stefanha@redhat.com> In-Reply-To: <20230428123954.179035-1-stefanha@redhat.com> References: <20230428123954.179035-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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 @redhat.com) X-ZM-MESSAGEID: 1682685755492100001 Content-Type: text/plain; charset="utf-8" From: Sam Li Use scripts/update-linux-headers.sh to update headers to 6.3-rc1. Signed-off-by: Sam Li Reviewed-by: Stefan Hajnoczi Reviewed-by: Dmitry Fomichev Signed-off-by: Stefan Hajnoczi [Reran scripts/update-linux-headers.sh on Linux v6.3. The only change was the use of __virtioXX types instead of uintXX_t. --Stefan] Message-Id: <20230407082528.18841-2-faithilikerun@gmail.com> --- include/standard-headers/drm/drm_fourcc.h | 12 +++ include/standard-headers/linux/ethtool.h | 48 ++++++++- include/standard-headers/linux/fuse.h | 45 +++++++- include/standard-headers/linux/pci_regs.h | 1 + include/standard-headers/linux/vhost_types.h | 2 + include/standard-headers/linux/virtio_blk.h | 105 +++++++++++++++++++ linux-headers/asm-arm64/kvm.h | 1 + linux-headers/asm-x86/kvm.h | 34 +++++- linux-headers/linux/kvm.h | 9 ++ linux-headers/linux/vfio.h | 15 +-- linux-headers/linux/vhost.h | 8 ++ 11 files changed, 270 insertions(+), 10 deletions(-) diff --git a/include/standard-headers/drm/drm_fourcc.h b/include/standard-h= eaders/drm/drm_fourcc.h index 69cab17b38..dc3e6112c1 100644 --- a/include/standard-headers/drm/drm_fourcc.h +++ b/include/standard-headers/drm/drm_fourcc.h @@ -87,6 +87,18 @@ extern "C" { * * The authoritative list of format modifier codes is found in * `include/uapi/drm/drm_fourcc.h` + * + * Open Source User Waiver + * ----------------------- + * + * Because this is the authoritative source for pixel formats and modifiers + * referenced by GL, Vulkan extensions and other standards and hence used = both + * by open source and closed source driver stacks, the usual requirement f= or an + * upstream in-kernel or open source userspace user does not apply. + * + * To ensure, as much as feasible, compatibility across stacks and avoid + * confusion with incompatible enumerations stakeholders for all relevant = driver + * stacks should approve additions. */ =20 #define fourcc_code(a, b, c, d) ((uint32_t)(a) | ((uint32_t)(b) << 8) | \ diff --git a/include/standard-headers/linux/ethtool.h b/include/standard-he= aders/linux/ethtool.h index 87176ab075..99fcddf04f 100644 --- a/include/standard-headers/linux/ethtool.h +++ b/include/standard-headers/linux/ethtool.h @@ -711,6 +711,24 @@ enum ethtool_stringset { ETH_SS_COUNT }; =20 +/** + * enum ethtool_mac_stats_src - source of ethtool MAC statistics + * @ETHTOOL_MAC_STATS_SRC_AGGREGATE: + * if device supports a MAC merge layer, this retrieves the aggregate + * statistics of the eMAC and pMAC. Otherwise, it retrieves just the + * statistics of the single (express) MAC. + * @ETHTOOL_MAC_STATS_SRC_EMAC: + * if device supports a MM layer, this retrieves the eMAC statistics. + * Otherwise, it retrieves the statistics of the single (express) MAC. + * @ETHTOOL_MAC_STATS_SRC_PMAC: + * if device supports a MM layer, this retrieves the pMAC statistics. + */ +enum ethtool_mac_stats_src { + ETHTOOL_MAC_STATS_SRC_AGGREGATE, + ETHTOOL_MAC_STATS_SRC_EMAC, + ETHTOOL_MAC_STATS_SRC_PMAC, +}; + /** * enum ethtool_module_power_mode_policy - plug-in module power mode policy * @ETHTOOL_MODULE_POWER_MODE_POLICY_HIGH: Module is always in high power = mode. @@ -779,6 +797,31 @@ enum ethtool_podl_pse_pw_d_status { ETHTOOL_PODL_PSE_PW_D_STATUS_ERROR, }; =20 +/** + * enum ethtool_mm_verify_status - status of MAC Merge Verify function + * @ETHTOOL_MM_VERIFY_STATUS_UNKNOWN: + * verification status is unknown + * @ETHTOOL_MM_VERIFY_STATUS_INITIAL: + * the 802.3 Verify State diagram is in the state INIT_VERIFICATION + * @ETHTOOL_MM_VERIFY_STATUS_VERIFYING: + * the Verify State diagram is in the state VERIFICATION_IDLE, + * SEND_VERIFY or WAIT_FOR_RESPONSE + * @ETHTOOL_MM_VERIFY_STATUS_SUCCEEDED: + * indicates that the Verify State diagram is in the state VERIFIED + * @ETHTOOL_MM_VERIFY_STATUS_FAILED: + * the Verify State diagram is in the state VERIFY_FAIL + * @ETHTOOL_MM_VERIFY_STATUS_DISABLED: + * verification of preemption operation is disabled + */ +enum ethtool_mm_verify_status { + ETHTOOL_MM_VERIFY_STATUS_UNKNOWN, + ETHTOOL_MM_VERIFY_STATUS_INITIAL, + ETHTOOL_MM_VERIFY_STATUS_VERIFYING, + ETHTOOL_MM_VERIFY_STATUS_SUCCEEDED, + ETHTOOL_MM_VERIFY_STATUS_FAILED, + ETHTOOL_MM_VERIFY_STATUS_DISABLED, +}; + /** * struct ethtool_gstrings - string set for data tagging * @cmd: Command number =3D %ETHTOOL_GSTRINGS @@ -1183,7 +1226,7 @@ struct ethtool_rxnfc { uint32_t rule_cnt; uint32_t rss_context; }; - uint32_t rule_locs[0]; + uint32_t rule_locs[]; }; =20 =20 @@ -1741,6 +1784,9 @@ enum ethtool_link_mode_bit_indices { ETHTOOL_LINK_MODE_800000baseDR8_2_Full_BIT =3D 96, ETHTOOL_LINK_MODE_800000baseSR8_Full_BIT =3D 97, ETHTOOL_LINK_MODE_800000baseVR8_Full_BIT =3D 98, + ETHTOOL_LINK_MODE_10baseT1S_Full_BIT =3D 99, + ETHTOOL_LINK_MODE_10baseT1S_Half_BIT =3D 100, + ETHTOOL_LINK_MODE_10baseT1S_P2MP_Half_BIT =3D 101, =20 /* must be last entry */ __ETHTOOL_LINK_MODE_MASK_NBITS diff --git a/include/standard-headers/linux/fuse.h b/include/standard-heade= rs/linux/fuse.h index a1af78d989..35c131a107 100644 --- a/include/standard-headers/linux/fuse.h +++ b/include/standard-headers/linux/fuse.h @@ -201,6 +201,11 @@ * 7.38 * - add FUSE_EXPIRE_ONLY flag to fuse_notify_inval_entry * - add FOPEN_PARALLEL_DIRECT_WRITES + * - add total_extlen to fuse_in_header + * - add FUSE_MAX_NR_SECCTX + * - add extension header + * - add FUSE_EXT_GROUPS + * - add FUSE_CREATE_SUPP_GROUP */ =20 #ifndef _LINUX_FUSE_H @@ -358,6 +363,8 @@ struct fuse_file_lock { * FUSE_SECURITY_CTX: add security context to create, mkdir, symlink, and * mknod * FUSE_HAS_INODE_DAX: use per inode DAX + * FUSE_CREATE_SUPP_GROUP: add supplementary group info to create, mkdir, + * symlink and mknod (single group that matches parent) */ #define FUSE_ASYNC_READ (1 << 0) #define FUSE_POSIX_LOCKS (1 << 1) @@ -394,6 +401,7 @@ struct fuse_file_lock { /* bits 32..63 get shifted down 32 bits into the flags2 field */ #define FUSE_SECURITY_CTX (1ULL << 32) #define FUSE_HAS_INODE_DAX (1ULL << 33) +#define FUSE_CREATE_SUPP_GROUP (1ULL << 34) =20 /** * CUSE INIT request/reply flags @@ -499,6 +507,17 @@ struct fuse_file_lock { */ #define FUSE_EXPIRE_ONLY (1 << 0) =20 +/** + * extension type + * FUSE_MAX_NR_SECCTX: maximum value of &fuse_secctx_header.nr_secctx + * FUSE_EXT_GROUPS: &fuse_supp_groups extension + */ +enum fuse_ext_type { + /* Types 0..31 are reserved for fuse_secctx_header */ + FUSE_MAX_NR_SECCTX =3D 31, + FUSE_EXT_GROUPS =3D 32, +}; + enum fuse_opcode { FUSE_LOOKUP =3D 1, FUSE_FORGET =3D 2, /* no reply */ @@ -882,7 +901,8 @@ struct fuse_in_header { uint32_t uid; uint32_t gid; uint32_t pid; - uint32_t padding; + uint16_t total_extlen; /* length of extensions in 8byte units */ + uint16_t padding; }; =20 struct fuse_out_header { @@ -1043,4 +1063,27 @@ struct fuse_secctx_header { uint32_t nr_secctx; }; =20 +/** + * struct fuse_ext_header - extension header + * @size: total size of this extension including this header + * @type: type of extension + * + * This is made compatible with fuse_secctx_header by using type values > + * FUSE_MAX_NR_SECCTX + */ +struct fuse_ext_header { + uint32_t size; + uint32_t type; +}; + +/** + * struct fuse_supp_groups - Supplementary group extension + * @nr_groups: number of supplementary groups + * @groups: flexible array of group IDs + */ +struct fuse_supp_groups { + uint32_t nr_groups; + uint32_t groups[]; +}; + #endif /* _LINUX_FUSE_H */ diff --git a/include/standard-headers/linux/pci_regs.h b/include/standard-h= eaders/linux/pci_regs.h index 85ab127881..dc2000e0fe 100644 --- a/include/standard-headers/linux/pci_regs.h +++ b/include/standard-headers/linux/pci_regs.h @@ -693,6 +693,7 @@ #define PCI_EXP_LNKCTL2_TX_MARGIN 0x0380 /* Transmit Margin */ #define PCI_EXP_LNKCTL2_HASD 0x0020 /* HW Autonomous Speed Disable */ #define PCI_EXP_LNKSTA2 0x32 /* Link Status 2 */ +#define PCI_EXP_LNKSTA2_FLIT 0x0400 /* Flit Mode Status */ #define PCI_CAP_EXP_ENDPOINT_SIZEOF_V2 0x32 /* end of v2 EPs w/ link */ #define PCI_EXP_SLTCAP2 0x34 /* Slot Capabilities 2 */ #define PCI_EXP_SLTCAP2_IBPD 0x00000001 /* In-band PD Disable Supported */ diff --git a/include/standard-headers/linux/vhost_types.h b/include/standar= d-headers/linux/vhost_types.h index c41a73fe36..88600e2d9f 100644 --- a/include/standard-headers/linux/vhost_types.h +++ b/include/standard-headers/linux/vhost_types.h @@ -163,5 +163,7 @@ struct vhost_vdpa_iova_range { #define VHOST_BACKEND_F_IOTLB_ASID 0x3 /* Device can be suspended */ #define VHOST_BACKEND_F_SUSPEND 0x4 +/* Device can be resumed */ +#define VHOST_BACKEND_F_RESUME 0x5 =20 #endif diff --git a/include/standard-headers/linux/virtio_blk.h b/include/standard= -headers/linux/virtio_blk.h index e81715cd70..d7be3cf5e4 100644 --- a/include/standard-headers/linux/virtio_blk.h +++ b/include/standard-headers/linux/virtio_blk.h @@ -41,6 +41,7 @@ #define VIRTIO_BLK_F_DISCARD 13 /* DISCARD is supported */ #define VIRTIO_BLK_F_WRITE_ZEROES 14 /* WRITE ZEROES is supported */ #define VIRTIO_BLK_F_SECURE_ERASE 16 /* Secure Erase is supported */ +#define VIRTIO_BLK_F_ZONED 17 /* Zoned block device */ =20 /* Legacy feature bits */ #ifndef VIRTIO_BLK_NO_LEGACY @@ -135,6 +136,16 @@ struct virtio_blk_config { /* Secure erase commands must be aligned to this number of sectors. */ __virtio32 secure_erase_sector_alignment; =20 + /* Zoned block device characteristics (if VIRTIO_BLK_F_ZONED) */ + struct virtio_blk_zoned_characteristics { + __virtio32 zone_sectors; + __virtio32 max_open_zones; + __virtio32 max_active_zones; + __virtio32 max_append_sectors; + __virtio32 write_granularity; + uint8_t model; + uint8_t unused2[3]; + } zoned; } QEMU_PACKED; =20 /* @@ -172,6 +183,27 @@ struct virtio_blk_config { /* Secure erase command */ #define VIRTIO_BLK_T_SECURE_ERASE 14 =20 +/* Zone append command */ +#define VIRTIO_BLK_T_ZONE_APPEND 15 + +/* Report zones command */ +#define VIRTIO_BLK_T_ZONE_REPORT 16 + +/* Open zone command */ +#define VIRTIO_BLK_T_ZONE_OPEN 18 + +/* Close zone command */ +#define VIRTIO_BLK_T_ZONE_CLOSE 20 + +/* Finish zone command */ +#define VIRTIO_BLK_T_ZONE_FINISH 22 + +/* Reset zone command */ +#define VIRTIO_BLK_T_ZONE_RESET 24 + +/* Reset All zones command */ +#define VIRTIO_BLK_T_ZONE_RESET_ALL 26 + #ifndef VIRTIO_BLK_NO_LEGACY /* Barrier before this op. */ #define VIRTIO_BLK_T_BARRIER 0x80000000 @@ -191,6 +223,72 @@ struct virtio_blk_outhdr { __virtio64 sector; }; =20 +/* + * Supported zoned device models. + */ + +/* Regular block device */ +#define VIRTIO_BLK_Z_NONE 0 +/* Host-managed zoned device */ +#define VIRTIO_BLK_Z_HM 1 +/* Host-aware zoned device */ +#define VIRTIO_BLK_Z_HA 2 + +/* + * Zone descriptor. A part of VIRTIO_BLK_T_ZONE_REPORT command reply. + */ +struct virtio_blk_zone_descriptor { + /* Zone capacity */ + __virtio64 z_cap; + /* The starting sector of the zone */ + __virtio64 z_start; + /* Zone write pointer position in sectors */ + __virtio64 z_wp; + /* Zone type */ + uint8_t z_type; + /* Zone state */ + uint8_t z_state; + uint8_t reserved[38]; +}; + +struct virtio_blk_zone_report { + __virtio64 nr_zones; + uint8_t reserved[56]; + struct virtio_blk_zone_descriptor zones[]; +}; + +/* + * Supported zone types. + */ + +/* Conventional zone */ +#define VIRTIO_BLK_ZT_CONV 1 +/* Sequential Write Required zone */ +#define VIRTIO_BLK_ZT_SWR 2 +/* Sequential Write Preferred zone */ +#define VIRTIO_BLK_ZT_SWP 3 + +/* + * Zone states that are available for zones of all types. + */ + +/* Not a write pointer (conventional zones only) */ +#define VIRTIO_BLK_ZS_NOT_WP 0 +/* Empty */ +#define VIRTIO_BLK_ZS_EMPTY 1 +/* Implicitly Open */ +#define VIRTIO_BLK_ZS_IOPEN 2 +/* Explicitly Open */ +#define VIRTIO_BLK_ZS_EOPEN 3 +/* Closed */ +#define VIRTIO_BLK_ZS_CLOSED 4 +/* Read-Only */ +#define VIRTIO_BLK_ZS_RDONLY 13 +/* Full */ +#define VIRTIO_BLK_ZS_FULL 14 +/* Offline */ +#define VIRTIO_BLK_ZS_OFFLINE 15 + /* Unmap this range (only valid for write zeroes command) */ #define VIRTIO_BLK_WRITE_ZEROES_FLAG_UNMAP 0x00000001 =20 @@ -217,4 +315,11 @@ struct virtio_scsi_inhdr { #define VIRTIO_BLK_S_OK 0 #define VIRTIO_BLK_S_IOERR 1 #define VIRTIO_BLK_S_UNSUPP 2 + +/* Error codes that are specific to zoned block devices */ +#define VIRTIO_BLK_S_ZONE_INVALID_CMD 3 +#define VIRTIO_BLK_S_ZONE_UNALIGNED_WP 4 +#define VIRTIO_BLK_S_ZONE_OPEN_RESOURCE 5 +#define VIRTIO_BLK_S_ZONE_ACTIVE_RESOURCE 6 + #endif /* _LINUX_VIRTIO_BLK_H */ diff --git a/linux-headers/asm-arm64/kvm.h b/linux-headers/asm-arm64/kvm.h index a7cfefb3a8..d7e7bb885e 100644 --- a/linux-headers/asm-arm64/kvm.h +++ b/linux-headers/asm-arm64/kvm.h @@ -109,6 +109,7 @@ struct kvm_regs { #define KVM_ARM_VCPU_SVE 4 /* enable SVE for this CPU */ #define KVM_ARM_VCPU_PTRAUTH_ADDRESS 5 /* VCPU uses address authentication= */ #define KVM_ARM_VCPU_PTRAUTH_GENERIC 6 /* VCPU uses generic authentication= */ +#define KVM_ARM_VCPU_HAS_EL2 7 /* Support nested virtualization */ =20 struct kvm_vcpu_init { __u32 target; diff --git a/linux-headers/asm-x86/kvm.h b/linux-headers/asm-x86/kvm.h index 2747d2ce14..2937e7bf69 100644 --- a/linux-headers/asm-x86/kvm.h +++ b/linux-headers/asm-x86/kvm.h @@ -9,6 +9,7 @@ =20 #include #include +#include =20 #define KVM_PIO_PAGE_OFFSET 1 #define KVM_COALESCED_MMIO_PAGE_OFFSET 2 @@ -505,8 +506,8 @@ struct kvm_nested_state { * KVM_{GET,PUT}_NESTED_STATE ioctl values. */ union { - struct kvm_vmx_nested_state_data vmx[0]; - struct kvm_svm_nested_state_data svm[0]; + __DECLARE_FLEX_ARRAY(struct kvm_vmx_nested_state_data, vmx); + __DECLARE_FLEX_ARRAY(struct kvm_svm_nested_state_data, svm); } data; }; =20 @@ -523,6 +524,35 @@ struct kvm_pmu_event_filter { #define KVM_PMU_EVENT_ALLOW 0 #define KVM_PMU_EVENT_DENY 1 =20 +#define KVM_PMU_EVENT_FLAG_MASKED_EVENTS BIT(0) +#define KVM_PMU_EVENT_FLAGS_VALID_MASK (KVM_PMU_EVENT_FLAG_MASKED_EVENTS) + +/* + * Masked event layout. + * Bits Description + * ---- ----------- + * 7:0 event select (low bits) + * 15:8 umask match + * 31:16 unused + * 35:32 event select (high bits) + * 36:54 unused + * 55 exclude bit + * 63:56 umask mask + */ + +#define KVM_PMU_ENCODE_MASKED_ENTRY(event_select, mask, match, exclude) \ + (((event_select) & 0xFFULL) | (((event_select) & 0XF00ULL) << 24) | \ + (((mask) & 0xFFULL) << 56) | \ + (((match) & 0xFFULL) << 8) | \ + ((__u64)(!!(exclude)) << 55)) + +#define KVM_PMU_MASKED_ENTRY_EVENT_SELECT \ + (GENMASK_ULL(7, 0) | GENMASK_ULL(35, 32)) +#define KVM_PMU_MASKED_ENTRY_UMASK_MASK (GENMASK_ULL(63, 56)) +#define KVM_PMU_MASKED_ENTRY_UMASK_MATCH (GENMASK_ULL(15, 8)) +#define KVM_PMU_MASKED_ENTRY_EXCLUDE (BIT_ULL(55)) +#define KVM_PMU_MASKED_ENTRY_UMASK_MASK_SHIFT (56) + /* for KVM_{GET,SET,HAS}_DEVICE_ATTR */ #define KVM_VCPU_TSC_CTRL 0 /* control group for the timestamp counter (TS= C) */ #define KVM_VCPU_TSC_OFFSET 0 /* attribute for the TSC offset */ diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h index 1e2c16cfe3..599de3c6e3 100644 --- a/linux-headers/linux/kvm.h +++ b/linux-headers/linux/kvm.h @@ -581,6 +581,8 @@ struct kvm_s390_mem_op { struct { __u8 ar; /* the access register number */ __u8 key; /* access key, ignored if flag unset */ + __u8 pad1[6]; /* ignored */ + __u64 old_addr; /* ignored if cmpxchg flag unset */ }; __u32 sida_offset; /* offset into the sida */ __u8 reserved[32]; /* ignored */ @@ -593,11 +595,17 @@ struct kvm_s390_mem_op { #define KVM_S390_MEMOP_SIDA_WRITE 3 #define KVM_S390_MEMOP_ABSOLUTE_READ 4 #define KVM_S390_MEMOP_ABSOLUTE_WRITE 5 +#define KVM_S390_MEMOP_ABSOLUTE_CMPXCHG 6 + /* flags for kvm_s390_mem_op->flags */ #define KVM_S390_MEMOP_F_CHECK_ONLY (1ULL << 0) #define KVM_S390_MEMOP_F_INJECT_EXCEPTION (1ULL << 1) #define KVM_S390_MEMOP_F_SKEY_PROTECTION (1ULL << 2) =20 +/* flags specifying extension support via KVM_CAP_S390_MEM_OP_EXTENSION */ +#define KVM_S390_MEMOP_EXTENSION_CAP_BASE (1 << 0) +#define KVM_S390_MEMOP_EXTENSION_CAP_CMPXCHG (1 << 1) + /* for KVM_INTERRUPT */ struct kvm_interrupt { /* in */ @@ -1173,6 +1181,7 @@ struct kvm_ppc_resize_hpt { #define KVM_CAP_DIRTY_LOG_RING_ACQ_REL 223 #define KVM_CAP_S390_PROTECTED_ASYNC_DISABLE 224 #define KVM_CAP_DIRTY_LOG_RING_WITH_BITMAP 225 +#define KVM_CAP_PMU_EVENT_MASKED_EVENTS 226 =20 #ifdef KVM_CAP_IRQ_ROUTING =20 diff --git a/linux-headers/linux/vfio.h b/linux-headers/linux/vfio.h index c59692ce0b..4a534edbdc 100644 --- a/linux-headers/linux/vfio.h +++ b/linux-headers/linux/vfio.h @@ -49,7 +49,11 @@ /* Supports VFIO_DMA_UNMAP_FLAG_ALL */ #define VFIO_UNMAP_ALL 9 =20 -/* Supports the vaddr flag for DMA map and unmap */ +/* + * Supports the vaddr flag for DMA map and unmap. Not supported for media= ted + * devices, so this capability is subject to change as groups are added or + * removed. + */ #define VFIO_UPDATE_VADDR 10 =20 /* @@ -1343,8 +1347,7 @@ struct vfio_iommu_type1_info_dma_avail { * Map process virtual addresses to IO virtual addresses using the * provided struct vfio_dma_map. Caller sets argsz. READ &/ WRITE required. * - * If flags & VFIO_DMA_MAP_FLAG_VADDR, update the base vaddr for iova, and - * unblock translation of host virtual addresses in the iova range. The v= addr + * If flags & VFIO_DMA_MAP_FLAG_VADDR, update the base vaddr for iova. The= vaddr * must have previously been invalidated with VFIO_DMA_UNMAP_FLAG_VADDR. = To * maintain memory consistency within the user application, the updated va= ddr * must address the same memory object as originally mapped. Failure to d= o so @@ -1395,9 +1398,9 @@ struct vfio_bitmap { * must be 0. This cannot be combined with the get-dirty-bitmap flag. * * If flags & VFIO_DMA_UNMAP_FLAG_VADDR, do not unmap, but invalidate host - * virtual addresses in the iova range. Tasks that attempt to translate an - * iova's vaddr will block. DMA to already-mapped pages continues. This - * cannot be combined with the get-dirty-bitmap flag. + * virtual addresses in the iova range. DMA to already-mapped pages conti= nues. + * Groups may not be added to the container while any addresses are invali= d. + * This cannot be combined with the get-dirty-bitmap flag. */ struct vfio_iommu_type1_dma_unmap { __u32 argsz; diff --git a/linux-headers/linux/vhost.h b/linux-headers/linux/vhost.h index f9f115a7c7..92e1b700b5 100644 --- a/linux-headers/linux/vhost.h +++ b/linux-headers/linux/vhost.h @@ -180,4 +180,12 @@ */ #define VHOST_VDPA_SUSPEND _IO(VHOST_VIRTIO, 0x7D) =20 +/* Resume a device so it can resume processing virtqueue requests + * + * After the return of this ioctl the device will have restored all the + * necessary states and it is fully operational to continue processing the + * virtqueue descriptors. + */ +#define VHOST_VDPA_RESUME _IO(VHOST_VIRTIO, 0x7E) + #endif --=20 2.40.0 From nobody Fri May 10 01:51:43 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682685818; cv=none; d=zohomail.com; s=zohoarc; b=XNoTWD2Z1mQK4VS9KMIjqFtBzDZ+3VbDfTtDLhi6jH20QYL7YpC6p7nZQGGgm8qpzIGbh0+eTMjOu9MPlJsdW2tRbcHSpjYT4IjnEJlRyPRMXGyug0PGG5VCTUxxsw1rkspfkZvF7usEy5x9iMg1+RrlziTmnb6l8WvSw54uXEs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682685818; 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=w2jkI5wx67mNXdEuUMY+gMV22kgWZEzfWc7Hp2cqcOM=; b=W6lU9dtJY3C/vIfgwmWwXUCvD7RwIcby1lyKCyOQXjNkVNp7LtyCsWQ+ssAU8YVUAnC6xZqTzVNApOlV0HjFJ45J5Q/HfV8hPYl3tFF5eWN9YBsJsm+pJjjBvM1rdSuJCjo0AWrykj9ZUGowGCxSV3QoonIR0sujxBgE2KKh6uQ= 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 1682685818915599.1590939492243; Fri, 28 Apr 2023 05:43:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1psNPb-0007iC-76; Fri, 28 Apr 2023 08:41:19 -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 1psNP7-0006w4-4X for qemu-devel@nongnu.org; Fri, 28 Apr 2023 08:40:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1psNP4-0000qZ-1b for qemu-devel@nongnu.org; Fri, 28 Apr 2023 08:40:48 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-668-QkFFLBB6Oc-_-qh24IoVFQ-1; Fri, 28 Apr 2023 08:40:35 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1CE4A887404; Fri, 28 Apr 2023 12:40:35 +0000 (UTC) Received: from localhost (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 888FB4021B9; Fri, 28 Apr 2023 12:40:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682685640; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w2jkI5wx67mNXdEuUMY+gMV22kgWZEzfWc7Hp2cqcOM=; b=AXZzNQlMwXY2jFf56Llfchs0go3isrHKcdUB/Myg9ZPveqpeMVP8s4tHNiRhZnUF9Wemre 0dIvfCG5yrTV8fBJa7UDL2S6pBHIXK7Ue0TLWbKA1r+r9k+I21ggjJAjS15C3rQtQJdyAp scKtyJtzCU9ois4KB3p8VkRVoT63kn8= X-MC-Unique: QkFFLBB6Oc-_-qh24IoVFQ-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Raphael Norwitz , Julia Suvorova , Cornelia Huck , Eric Blake , Paolo Bonzini , Aarushi Mehta , Stefan Hajnoczi , Richard Henderson , Kevin Wolf , Markus Armbruster , Stefano Garzarella , qemu-block@nongnu.org, Hanna Reitz , Fam Zheng , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Michael S. Tsirkin" , kvm@vger.kernel.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sam Li Subject: [PULL 14/17] virtio-blk: add zoned storage emulation for zoned devices Date: Fri, 28 Apr 2023 08:39:51 -0400 Message-Id: <20230428123954.179035-15-stefanha@redhat.com> In-Reply-To: <20230428123954.179035-1-stefanha@redhat.com> References: <20230428123954.179035-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 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=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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 @redhat.com) X-ZM-MESSAGEID: 1682685820628100003 Content-Type: text/plain; charset="utf-8" From: Sam Li This patch extends virtio-blk emulation to handle zoned device commands by calling the new block layer APIs to perform zoned device I/O on behalf of the guest. It supports Report Zone, four zone oparations (open, close, finish, reset), and Append Zone. The VIRTIO_BLK_F_ZONED feature bit will only be set if the host does support zoned block devices. Regular block devices(conventional zones) will not be set. The guest os can use blktests, fio to test those commands on zoned devices. Furthermore, using zonefs to test zone append write is also supported. Signed-off-by: Sam Li Signed-off-by: Stefan Hajnoczi Message-Id: <20230407082528.18841-3-faithilikerun@gmail.com> --- hw/block/virtio-blk-common.c | 2 + hw/block/virtio-blk.c | 389 +++++++++++++++++++++++++++++++++++ hw/virtio/virtio-qmp.c | 2 + 3 files changed, 393 insertions(+) diff --git a/hw/block/virtio-blk-common.c b/hw/block/virtio-blk-common.c index ac52d7c176..e2f8e2f6da 100644 --- a/hw/block/virtio-blk-common.c +++ b/hw/block/virtio-blk-common.c @@ -29,6 +29,8 @@ static const VirtIOFeature feature_sizes[] =3D { .end =3D endof(struct virtio_blk_config, discard_sector_alignment)}, {.flags =3D 1ULL << VIRTIO_BLK_F_WRITE_ZEROES, .end =3D endof(struct virtio_blk_config, write_zeroes_may_unmap)}, + {.flags =3D 1ULL << VIRTIO_BLK_F_ZONED, + .end =3D endof(struct virtio_blk_config, zoned)}, {} }; =20 diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index cefca93b31..8b6030b1a5 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -17,6 +17,7 @@ #include "qemu/module.h" #include "qemu/error-report.h" #include "qemu/main-loop.h" +#include "block/block_int.h" #include "trace.h" #include "hw/block/block.h" #include "hw/qdev-properties.h" @@ -601,6 +602,335 @@ err: return err_status; } =20 +typedef struct ZoneCmdData { + VirtIOBlockReq *req; + struct iovec *in_iov; + unsigned in_num; + union { + struct { + unsigned int nr_zones; + BlockZoneDescriptor *zones; + } zone_report_data; + struct { + int64_t offset; + } zone_append_data; + }; +} ZoneCmdData; + +/* + * check zoned_request: error checking before issuing requests. If all che= cks + * passed, return true. + * append: true if only zone append requests issued. + */ +static bool check_zoned_request(VirtIOBlock *s, int64_t offset, int64_t le= n, + bool append, uint8_t *status) { + BlockDriverState *bs =3D blk_bs(s->blk); + int index; + + if (!virtio_has_feature(s->host_features, VIRTIO_BLK_F_ZONED)) { + *status =3D VIRTIO_BLK_S_UNSUPP; + return false; + } + + if (offset < 0 || len < 0 || len > (bs->total_sectors << BDRV_SECTOR_B= ITS) + || offset > (bs->total_sectors << BDRV_SECTOR_BITS) - len) { + *status =3D VIRTIO_BLK_S_ZONE_INVALID_CMD; + return false; + } + + if (append) { + if (bs->bl.write_granularity) { + if ((offset % bs->bl.write_granularity) !=3D 0) { + *status =3D VIRTIO_BLK_S_ZONE_UNALIGNED_WP; + return false; + } + } + + index =3D offset / bs->bl.zone_size; + if (BDRV_ZT_IS_CONV(bs->wps->wp[index])) { + *status =3D VIRTIO_BLK_S_ZONE_INVALID_CMD; + return false; + } + + if (len / 512 > bs->bl.max_append_sectors) { + if (bs->bl.max_append_sectors =3D=3D 0) { + *status =3D VIRTIO_BLK_S_UNSUPP; + } else { + *status =3D VIRTIO_BLK_S_ZONE_INVALID_CMD; + } + return false; + } + } + return true; +} + +static void virtio_blk_zone_report_complete(void *opaque, int ret) +{ + ZoneCmdData *data =3D opaque; + VirtIOBlockReq *req =3D data->req; + VirtIOBlock *s =3D req->dev; + VirtIODevice *vdev =3D VIRTIO_DEVICE(req->dev); + struct iovec *in_iov =3D data->in_iov; + unsigned in_num =3D data->in_num; + int64_t zrp_size, n, j =3D 0; + int64_t nz =3D data->zone_report_data.nr_zones; + int8_t err_status =3D VIRTIO_BLK_S_OK; + + if (ret) { + err_status =3D VIRTIO_BLK_S_ZONE_INVALID_CMD; + goto out; + } + + struct virtio_blk_zone_report zrp_hdr =3D (struct virtio_blk_zone_repo= rt) { + .nr_zones =3D cpu_to_le64(nz), + }; + zrp_size =3D sizeof(struct virtio_blk_zone_report) + + sizeof(struct virtio_blk_zone_descriptor) * nz; + n =3D iov_from_buf(in_iov, in_num, 0, &zrp_hdr, sizeof(zrp_hdr)); + if (n !=3D sizeof(zrp_hdr)) { + virtio_error(vdev, "Driver provided input buffer that is too small= !"); + err_status =3D VIRTIO_BLK_S_ZONE_INVALID_CMD; + goto out; + } + + for (size_t i =3D sizeof(zrp_hdr); i < zrp_size; + i +=3D sizeof(struct virtio_blk_zone_descriptor), ++j) { + struct virtio_blk_zone_descriptor desc =3D + (struct virtio_blk_zone_descriptor) { + .z_start =3D cpu_to_le64(data->zone_report_data.zones[j].s= tart + >> BDRV_SECTOR_BITS), + .z_cap =3D cpu_to_le64(data->zone_report_data.zones[j].cap + >> BDRV_SECTOR_BITS), + .z_wp =3D cpu_to_le64(data->zone_report_data.zones[j].wp + >> BDRV_SECTOR_BITS), + }; + + switch (data->zone_report_data.zones[j].type) { + case BLK_ZT_CONV: + desc.z_type =3D VIRTIO_BLK_ZT_CONV; + break; + case BLK_ZT_SWR: + desc.z_type =3D VIRTIO_BLK_ZT_SWR; + break; + case BLK_ZT_SWP: + desc.z_type =3D VIRTIO_BLK_ZT_SWP; + break; + default: + g_assert_not_reached(); + } + + switch (data->zone_report_data.zones[j].state) { + case BLK_ZS_RDONLY: + desc.z_state =3D VIRTIO_BLK_ZS_RDONLY; + break; + case BLK_ZS_OFFLINE: + desc.z_state =3D VIRTIO_BLK_ZS_OFFLINE; + break; + case BLK_ZS_EMPTY: + desc.z_state =3D VIRTIO_BLK_ZS_EMPTY; + break; + case BLK_ZS_CLOSED: + desc.z_state =3D VIRTIO_BLK_ZS_CLOSED; + break; + case BLK_ZS_FULL: + desc.z_state =3D VIRTIO_BLK_ZS_FULL; + break; + case BLK_ZS_EOPEN: + desc.z_state =3D VIRTIO_BLK_ZS_EOPEN; + break; + case BLK_ZS_IOPEN: + desc.z_state =3D VIRTIO_BLK_ZS_IOPEN; + break; + case BLK_ZS_NOT_WP: + desc.z_state =3D VIRTIO_BLK_ZS_NOT_WP; + break; + default: + g_assert_not_reached(); + } + + /* TODO: it takes O(n^2) time complexity. Optimizations required. = */ + n =3D iov_from_buf(in_iov, in_num, i, &desc, sizeof(desc)); + if (n !=3D sizeof(desc)) { + virtio_error(vdev, "Driver provided input buffer " + "for descriptors that is too small!"); + err_status =3D VIRTIO_BLK_S_ZONE_INVALID_CMD; + } + } + +out: + aio_context_acquire(blk_get_aio_context(s->conf.conf.blk)); + virtio_blk_req_complete(req, err_status); + virtio_blk_free_request(req); + aio_context_release(blk_get_aio_context(s->conf.conf.blk)); + g_free(data->zone_report_data.zones); + g_free(data); +} + +static void virtio_blk_handle_zone_report(VirtIOBlockReq *req, + struct iovec *in_iov, + unsigned in_num) +{ + VirtIOBlock *s =3D req->dev; + VirtIODevice *vdev =3D VIRTIO_DEVICE(s); + unsigned int nr_zones; + ZoneCmdData *data; + int64_t zone_size, offset; + uint8_t err_status; + + if (req->in_len < sizeof(struct virtio_blk_inhdr) + + sizeof(struct virtio_blk_zone_report) + + sizeof(struct virtio_blk_zone_descriptor)) { + virtio_error(vdev, "in buffer too small for zone report"); + return; + } + + /* start byte offset of the zone report */ + offset =3D virtio_ldq_p(vdev, &req->out.sector) << BDRV_SECTOR_BITS; + if (!check_zoned_request(s, offset, 0, false, &err_status)) { + goto out; + } + nr_zones =3D (req->in_len - sizeof(struct virtio_blk_inhdr) - + sizeof(struct virtio_blk_zone_report)) / + sizeof(struct virtio_blk_zone_descriptor); + + zone_size =3D sizeof(BlockZoneDescriptor) * nr_zones; + data =3D g_malloc(sizeof(ZoneCmdData)); + data->req =3D req; + data->in_iov =3D in_iov; + data->in_num =3D in_num; + data->zone_report_data.nr_zones =3D nr_zones; + data->zone_report_data.zones =3D g_malloc(zone_size), + + blk_aio_zone_report(s->blk, offset, &data->zone_report_data.nr_zones, + data->zone_report_data.zones, + virtio_blk_zone_report_complete, data); + return; +out: + virtio_blk_req_complete(req, err_status); + virtio_blk_free_request(req); +} + +static void virtio_blk_zone_mgmt_complete(void *opaque, int ret) +{ + VirtIOBlockReq *req =3D opaque; + VirtIOBlock *s =3D req->dev; + int8_t err_status =3D VIRTIO_BLK_S_OK; + + if (ret) { + err_status =3D VIRTIO_BLK_S_ZONE_INVALID_CMD; + } + + aio_context_acquire(blk_get_aio_context(s->conf.conf.blk)); + virtio_blk_req_complete(req, err_status); + virtio_blk_free_request(req); + aio_context_release(blk_get_aio_context(s->conf.conf.blk)); +} + +static int virtio_blk_handle_zone_mgmt(VirtIOBlockReq *req, BlockZoneOp op) +{ + VirtIOBlock *s =3D req->dev; + VirtIODevice *vdev =3D VIRTIO_DEVICE(s); + BlockDriverState *bs =3D blk_bs(s->blk); + int64_t offset =3D virtio_ldq_p(vdev, &req->out.sector) << BDRV_SECTOR= _BITS; + uint64_t len; + uint64_t capacity =3D bs->total_sectors << BDRV_SECTOR_BITS; + uint8_t err_status =3D VIRTIO_BLK_S_OK; + + uint32_t type =3D virtio_ldl_p(vdev, &req->out.type); + if (type =3D=3D VIRTIO_BLK_T_ZONE_RESET_ALL) { + /* Entire drive capacity */ + offset =3D 0; + len =3D capacity; + } else { + if (bs->bl.zone_size > capacity - offset) { + /* The zoned device allows the last smaller zone. */ + len =3D capacity - bs->bl.zone_size * (bs->bl.nr_zones - 1); + } else { + len =3D bs->bl.zone_size; + } + } + + if (!check_zoned_request(s, offset, len, false, &err_status)) { + goto out; + } + + blk_aio_zone_mgmt(s->blk, op, offset, len, + virtio_blk_zone_mgmt_complete, req); + + return 0; +out: + virtio_blk_req_complete(req, err_status); + virtio_blk_free_request(req); + return err_status; +} + +static void virtio_blk_zone_append_complete(void *opaque, int ret) +{ + ZoneCmdData *data =3D opaque; + VirtIOBlockReq *req =3D data->req; + VirtIOBlock *s =3D req->dev; + VirtIODevice *vdev =3D VIRTIO_DEVICE(req->dev); + int64_t append_sector, n; + uint8_t err_status =3D VIRTIO_BLK_S_OK; + + if (ret) { + err_status =3D VIRTIO_BLK_S_ZONE_INVALID_CMD; + goto out; + } + + virtio_stq_p(vdev, &append_sector, + data->zone_append_data.offset >> BDRV_SECTOR_BITS); + n =3D iov_from_buf(data->in_iov, data->in_num, 0, &append_sector, + sizeof(append_sector)); + if (n !=3D sizeof(append_sector)) { + virtio_error(vdev, "Driver provided input buffer less than size of= " + "append_sector"); + err_status =3D VIRTIO_BLK_S_ZONE_INVALID_CMD; + goto out; + } + +out: + aio_context_acquire(blk_get_aio_context(s->conf.conf.blk)); + virtio_blk_req_complete(req, err_status); + virtio_blk_free_request(req); + aio_context_release(blk_get_aio_context(s->conf.conf.blk)); + g_free(data); +} + +static int virtio_blk_handle_zone_append(VirtIOBlockReq *req, + struct iovec *out_iov, + struct iovec *in_iov, + uint64_t out_num, + unsigned in_num) { + VirtIOBlock *s =3D req->dev; + VirtIODevice *vdev =3D VIRTIO_DEVICE(s); + uint8_t err_status =3D VIRTIO_BLK_S_OK; + + int64_t offset =3D virtio_ldq_p(vdev, &req->out.sector) << BDRV_SECTOR= _BITS; + int64_t len =3D iov_size(out_iov, out_num); + + if (!check_zoned_request(s, offset, len, true, &err_status)) { + goto out; + } + + ZoneCmdData *data =3D g_malloc(sizeof(ZoneCmdData)); + data->req =3D req; + data->in_iov =3D in_iov; + data->in_num =3D in_num; + data->zone_append_data.offset =3D offset; + qemu_iovec_init_external(&req->qiov, out_iov, out_num); + blk_aio_zone_append(s->blk, &data->zone_append_data.offset, &req->qiov= , 0, + virtio_blk_zone_append_complete, data); + return 0; + +out: + aio_context_acquire(blk_get_aio_context(s->conf.conf.blk)); + virtio_blk_req_complete(req, err_status); + virtio_blk_free_request(req); + aio_context_release(blk_get_aio_context(s->conf.conf.blk)); + return err_status; +} + static int virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *= mrb) { uint32_t type; @@ -687,6 +1017,24 @@ static int virtio_blk_handle_request(VirtIOBlockReq *= req, MultiReqBuffer *mrb) case VIRTIO_BLK_T_FLUSH: virtio_blk_handle_flush(req, mrb); break; + case VIRTIO_BLK_T_ZONE_REPORT: + virtio_blk_handle_zone_report(req, in_iov, in_num); + break; + case VIRTIO_BLK_T_ZONE_OPEN: + virtio_blk_handle_zone_mgmt(req, BLK_ZO_OPEN); + break; + case VIRTIO_BLK_T_ZONE_CLOSE: + virtio_blk_handle_zone_mgmt(req, BLK_ZO_CLOSE); + break; + case VIRTIO_BLK_T_ZONE_FINISH: + virtio_blk_handle_zone_mgmt(req, BLK_ZO_FINISH); + break; + case VIRTIO_BLK_T_ZONE_RESET: + virtio_blk_handle_zone_mgmt(req, BLK_ZO_RESET); + break; + case VIRTIO_BLK_T_ZONE_RESET_ALL: + virtio_blk_handle_zone_mgmt(req, BLK_ZO_RESET); + break; case VIRTIO_BLK_T_SCSI_CMD: virtio_blk_handle_scsi(req); break; @@ -705,6 +1053,14 @@ static int virtio_blk_handle_request(VirtIOBlockReq *= req, MultiReqBuffer *mrb) virtio_blk_free_request(req); break; } + case VIRTIO_BLK_T_ZONE_APPEND & ~VIRTIO_BLK_T_OUT: + /* + * Passing out_iov/out_num and in_iov/in_num is not safe + * to access req->elem.out_sg directly because it may be + * modified by virtio_blk_handle_request(). + */ + virtio_blk_handle_zone_append(req, out_iov, in_iov, out_num, in_nu= m); + break; /* * VIRTIO_BLK_T_DISCARD and VIRTIO_BLK_T_WRITE_ZEROES are defined with * VIRTIO_BLK_T_OUT flag set. We masked this flag in the switch statem= ent, @@ -890,6 +1246,7 @@ static void virtio_blk_update_config(VirtIODevice *vde= v, uint8_t *config) { VirtIOBlock *s =3D VIRTIO_BLK(vdev); BlockConf *conf =3D &s->conf.conf; + BlockDriverState *bs =3D blk_bs(s->blk); struct virtio_blk_config blkcfg; uint64_t capacity; int64_t length; @@ -954,6 +1311,30 @@ static void virtio_blk_update_config(VirtIODevice *vd= ev, uint8_t *config) blkcfg.write_zeroes_may_unmap =3D 1; virtio_stl_p(vdev, &blkcfg.max_write_zeroes_seg, 1); } + if (bs->bl.zoned !=3D BLK_Z_NONE) { + switch (bs->bl.zoned) { + case BLK_Z_HM: + blkcfg.zoned.model =3D VIRTIO_BLK_Z_HM; + break; + case BLK_Z_HA: + blkcfg.zoned.model =3D VIRTIO_BLK_Z_HA; + break; + default: + g_assert_not_reached(); + } + + virtio_stl_p(vdev, &blkcfg.zoned.zone_sectors, + bs->bl.zone_size / 512); + virtio_stl_p(vdev, &blkcfg.zoned.max_active_zones, + bs->bl.max_active_zones); + virtio_stl_p(vdev, &blkcfg.zoned.max_open_zones, + bs->bl.max_open_zones); + virtio_stl_p(vdev, &blkcfg.zoned.write_granularity, blk_size); + virtio_stl_p(vdev, &blkcfg.zoned.max_append_sectors, + bs->bl.max_append_sectors); + } else { + blkcfg.zoned.model =3D VIRTIO_BLK_Z_NONE; + } memcpy(config, &blkcfg, s->config_size); } =20 @@ -1118,6 +1499,7 @@ static void virtio_blk_device_realize(DeviceState *de= v, Error **errp) VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); VirtIOBlock *s =3D VIRTIO_BLK(dev); VirtIOBlkConf *conf =3D &s->conf; + BlockDriverState *bs =3D blk_bs(conf->conf.blk); Error *err =3D NULL; unsigned i; =20 @@ -1163,6 +1545,13 @@ static void virtio_blk_device_realize(DeviceState *d= ev, Error **errp) return; } =20 + if (bs->bl.zoned !=3D BLK_Z_NONE) { + virtio_add_feature(&s->host_features, VIRTIO_BLK_F_ZONED); + if (bs->bl.zoned =3D=3D BLK_Z_HM) { + virtio_clear_feature(&s->host_features, VIRTIO_BLK_F_DISCARD); + } + } + if (virtio_has_feature(s->host_features, VIRTIO_BLK_F_DISCARD) && (!conf->max_discard_sectors || conf->max_discard_sectors > BDRV_REQUEST_MAX_SECTORS)) { diff --git a/hw/virtio/virtio-qmp.c b/hw/virtio/virtio-qmp.c index b70148aba9..e84316dcfd 100644 --- a/hw/virtio/virtio-qmp.c +++ b/hw/virtio/virtio-qmp.c @@ -176,6 +176,8 @@ static const qmp_virtio_feature_map_t virtio_blk_featur= e_map[] =3D { "VIRTIO_BLK_F_DISCARD: Discard command supported"), FEATURE_ENTRY(VIRTIO_BLK_F_WRITE_ZEROES, \ "VIRTIO_BLK_F_WRITE_ZEROES: Write zeroes command supported"), + FEATURE_ENTRY(VIRTIO_BLK_F_ZONED, \ + "VIRTIO_BLK_F_ZONED: Zoned block devices"), #ifndef VIRTIO_BLK_NO_LEGACY FEATURE_ENTRY(VIRTIO_BLK_F_BARRIER, \ "VIRTIO_BLK_F_BARRIER: Request barriers supported"), --=20 2.40.0 From nobody Fri May 10 01:51:43 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682685774; cv=none; d=zohomail.com; s=zohoarc; b=TkcVzzZls0GWfCWkhozpQEvk1Zk6jNaYp1NFo4Yrscg3Tp0QL71jVtucLAcfq5bmm/ZniDKx9kVg+zC8rBnlCUUJ1ULw+1WaXVJmvYJcRqLY7LD6p1P4SQd7WXkZ2fQSCnoMB2ySK/MZtbFrQiG5cEfmwHbPqfObaaMIOmyhlRY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682685774; 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=kV2zWPGuK8k4CzzrslCllCo66hc9AmkTXdFYc+wQU0A=; b=aR9XxjFY8u1imdMye8GnGVIsFIL3+tVp151DR5b0sEDsoO1InIFXPToU/srnOU8APlY+Lv+X0d34Hitfxv/uOU3i/pln4XaebRsXgV+il5MjX6rO1h5nf+c4oHX2ni33QMOX6/F9e4+L/FfoQufhEvJUNBmOJpAa6w0aItgkQlU= 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 1682685774530220.406039631196; Fri, 28 Apr 2023 05:42:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1psNQ1-0000pT-N0; Fri, 28 Apr 2023 08:41:45 -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 1psNP9-0006xs-OJ for qemu-devel@nongnu.org; Fri, 28 Apr 2023 08:40:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1psNP5-0000rV-AU for qemu-devel@nongnu.org; Fri, 28 Apr 2023 08:40:50 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-589-hcOszpRuOVK59f7GcLJfcQ-1; Fri, 28 Apr 2023 08:40:38 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A957238237CE; Fri, 28 Apr 2023 12:40:37 +0000 (UTC) Received: from localhost (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id CCE4D1121314; Fri, 28 Apr 2023 12:40:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682685645; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kV2zWPGuK8k4CzzrslCllCo66hc9AmkTXdFYc+wQU0A=; b=VCT6vCdt01wIqL8zh/b2/l0LFY5eVtvwMCeyUqRevKGDjY4vhukIkS/MK5/QEGgtWC6jV1 3uEZprzf1g62INSbCUfnPkKgB7DaNlghfAFPRjNyBeVUyiKHnktWdmHG6rUumb77us33TL FTcDvAWVfxwnquYgatDYLPPwBZRd83w= X-MC-Unique: hcOszpRuOVK59f7GcLJfcQ-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Raphael Norwitz , Julia Suvorova , Cornelia Huck , Eric Blake , Paolo Bonzini , Aarushi Mehta , Stefan Hajnoczi , Richard Henderson , Kevin Wolf , Markus Armbruster , Stefano Garzarella , qemu-block@nongnu.org, Hanna Reitz , Fam Zheng , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Michael S. Tsirkin" , kvm@vger.kernel.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sam Li Subject: [PULL 15/17] block: add accounting for zone append operation Date: Fri, 28 Apr 2023 08:39:52 -0400 Message-Id: <20230428123954.179035-16-stefanha@redhat.com> In-Reply-To: <20230428123954.179035-1-stefanha@redhat.com> References: <20230428123954.179035-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682685775968100001 Content-Type: text/plain; charset="utf-8" From: Sam Li Taking account of the new zone append write operation for zoned devices, BLOCK_ACCT_ZONE_APPEND enum is introduced as other I/O request type (read, write, flush). Signed-off-by: Sam Li Signed-off-by: Stefan Hajnoczi Message-Id: <20230407082528.18841-4-faithilikerun@gmail.com> --- qapi/block-core.json | 68 ++++++++++++++++++++++++++++++++------ qapi/block.json | 4 +++ include/block/accounting.h | 1 + block/qapi-sysemu.c | 11 ++++++ block/qapi.c | 18 ++++++++++ hw/block/virtio-blk.c | 4 +++ 6 files changed, 95 insertions(+), 11 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index c05ad0c07e..44a70aad21 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -849,6 +849,10 @@ # @min_wr_latency_ns: Minimum latency of write operations in the # defined interval, in nanoseconds. # +# @min_zone_append_latency_ns: Minimum latency of zone append operations +# in the defined interval, in nanoseconds +# (since 8.1) +# # @min_flush_latency_ns: Minimum latency of flush operations in the # defined interval, in nanoseconds. # @@ -858,6 +862,10 @@ # @max_wr_latency_ns: Maximum latency of write operations in the # defined interval, in nanoseconds. # +# @max_zone_append_latency_ns: Maximum latency of zone append operations +# in the defined interval, in nanoseconds +# (since 8.1) +# # @max_flush_latency_ns: Maximum latency of flush operations in the # defined interval, in nanoseconds. # @@ -867,6 +875,10 @@ # @avg_wr_latency_ns: Average latency of write operations in the # defined interval, in nanoseconds. # +# @avg_zone_append_latency_ns: Average latency of zone append operations +# in the defined interval, in nanoseconds +# (since 8.1) +# # @avg_flush_latency_ns: Average latency of flush operations in the # defined interval, in nanoseconds. # @@ -876,15 +888,23 @@ # @avg_wr_queue_depth: Average number of pending write operations # in the defined interval. # +# @avg_zone_append_queue_depth: Average number of pending zone append +# operations in the defined interval +# (since 8.1). +# # Since: 2.5 ## { 'struct': 'BlockDeviceTimedStats', 'data': { 'interval_length': 'int', 'min_rd_latency_ns': 'int', 'max_rd_latency_ns': 'int', 'avg_rd_latency_ns': 'int', 'min_wr_latency_ns': 'int', 'max_wr_latency_ns': 'int', - 'avg_wr_latency_ns': 'int', 'min_flush_latency_ns': 'int', - 'max_flush_latency_ns': 'int', 'avg_flush_latency_ns': 'int', - 'avg_rd_queue_depth': 'number', 'avg_wr_queue_depth': 'number'= } } + 'avg_wr_latency_ns': 'int', 'min_zone_append_latency_ns': 'int= ', + 'max_zone_append_latency_ns': 'int', + 'avg_zone_append_latency_ns': 'int', + 'min_flush_latency_ns': 'int', 'max_flush_latency_ns': 'int', + 'avg_flush_latency_ns': 'int', 'avg_rd_queue_depth': 'number', + 'avg_wr_queue_depth': 'number', + 'avg_zone_append_queue_depth': 'number' } } =20 ## # @BlockDeviceStats: @@ -895,12 +915,18 @@ # # @wr_bytes: The number of bytes written by the device. # +# @zone_append_bytes: The number of bytes appended by the zoned devices +# (since 8.1) +# # @unmap_bytes: The number of bytes unmapped by the device (Since 4.2) # # @rd_operations: The number of read operations performed by the device. # # @wr_operations: The number of write operations performed by the device. # +# @zone_append_operations: The number of zone append operations performed +# by the zoned devices (since 8.1) +# # @flush_operations: The number of cache flush operations performed by the # device (since 0.15) # @@ -911,6 +937,9 @@ # # @wr_total_time_ns: Total time spent on writes in nanoseconds (since 0.15= ). # +# @zone_append_total_time_ns: Total time spent on zone append writes +# in nanoseconds (since 8.1) +# # @flush_total_time_ns: Total time spent on cache flushes in nanoseconds # (since 0.15). # @@ -928,6 +957,9 @@ # @wr_merged: Number of write requests that have been merged into another # request (Since 2.3). # +# @zone_append_merged: Number of zone append requests that have been merged +# into another request (since 8.1) +# # @unmap_merged: Number of unmap requests that have been merged into anoth= er # request (Since 4.2) # @@ -941,6 +973,10 @@ # @failed_wr_operations: The number of failed write operations # performed by the device (Since 2.5) # +# @failed_zone_append_operations: The number of failed zone append write +# operations performed by the zoned devices +# (since 8.1) +# # @failed_flush_operations: The number of failed flush operations # performed by the device (Since 2.5) # @@ -953,6 +989,9 @@ # @invalid_wr_operations: The number of invalid write operations # performed by the device (Since 2.5) # +# @invalid_zone_append_operations: The number of invalid zone append opera= tions +# performed by the zoned device (since 8.= 1) +# # @invalid_flush_operations: The number of invalid flush operations # performed by the device (Since 2.5) # @@ -972,27 +1011,34 @@ # # @wr_latency_histogram: @BlockLatencyHistogramInfo. (Since 4.0) # +# @zone_append_latency_histogram: @BlockLatencyHistogramInfo. (since 8.1) +# # @flush_latency_histogram: @BlockLatencyHistogramInfo. (Since 4.0) # # Since: 0.14 ## { 'struct': 'BlockDeviceStats', - 'data': {'rd_bytes': 'int', 'wr_bytes': 'int', 'unmap_bytes' : 'int', - 'rd_operations': 'int', 'wr_operations': 'int', + 'data': {'rd_bytes': 'int', 'wr_bytes': 'int', 'zone_append_bytes': 'int= ', + 'unmap_bytes' : 'int', 'rd_operations': 'int', + 'wr_operations': 'int', 'zone_append_operations': 'int', 'flush_operations': 'int', 'unmap_operations': 'int', 'rd_total_time_ns': 'int', 'wr_total_time_ns': 'int', - 'flush_total_time_ns': 'int', 'unmap_total_time_ns': 'int', - 'wr_highest_offset': 'int', - 'rd_merged': 'int', 'wr_merged': 'int', 'unmap_merged': 'int', - '*idle_time_ns': 'int', + 'zone_append_total_time_ns': 'int', 'flush_total_time_ns': 'int= ', + 'unmap_total_time_ns': 'int', 'wr_highest_offset': 'int', + 'rd_merged': 'int', 'wr_merged': 'int', 'zone_append_merged': '= int', + 'unmap_merged': 'int', '*idle_time_ns': 'int', 'failed_rd_operations': 'int', 'failed_wr_operations': 'int', - 'failed_flush_operations': 'int', 'failed_unmap_operations': 'i= nt', - 'invalid_rd_operations': 'int', 'invalid_wr_operations': 'int', + 'failed_zone_append_operations': 'int', + 'failed_flush_operations': 'int', + 'failed_unmap_operations': 'int', 'invalid_rd_operations': 'int= ', + 'invalid_wr_operations': 'int', + 'invalid_zone_append_operations': 'int', 'invalid_flush_operations': 'int', 'invalid_unmap_operations': = 'int', 'account_invalid': 'bool', 'account_failed': 'bool', 'timed_stats': ['BlockDeviceTimedStats'], '*rd_latency_histogram': 'BlockLatencyHistogramInfo', '*wr_latency_histogram': 'BlockLatencyHistogramInfo', + '*zone_append_latency_histogram': 'BlockLatencyHistogramInfo', '*flush_latency_histogram': 'BlockLatencyHistogramInfo' } } =20 ## diff --git a/qapi/block.json b/qapi/block.json index 5fe068f903..5a57ef4a9f 100644 --- a/qapi/block.json +++ b/qapi/block.json @@ -525,6 +525,9 @@ # @boundaries-write: list of interval boundary values for write latency # histogram. # +# @boundaries-zap: list of interval boundary values for zone append write +# latency histogram. +# # @boundaries-flush: list of interval boundary values for flush latency # histogram. # @@ -573,5 +576,6 @@ '*boundaries': ['uint64'], '*boundaries-read': ['uint64'], '*boundaries-write': ['uint64'], + '*boundaries-zap': ['uint64'], '*boundaries-flush': ['uint64'] }, 'allow-preconfig': true } diff --git a/include/block/accounting.h b/include/block/accounting.h index b9caad60d5..a59e39f49d 100644 --- a/include/block/accounting.h +++ b/include/block/accounting.h @@ -37,6 +37,7 @@ enum BlockAcctType { BLOCK_ACCT_READ, BLOCK_ACCT_WRITE, BLOCK_ACCT_FLUSH, + BLOCK_ACCT_ZONE_APPEND, BLOCK_ACCT_UNMAP, BLOCK_MAX_IOTYPE, }; diff --git a/block/qapi-sysemu.c b/block/qapi-sysemu.c index 7bd7554150..cec3c1afb4 100644 --- a/block/qapi-sysemu.c +++ b/block/qapi-sysemu.c @@ -517,6 +517,7 @@ void qmp_block_latency_histogram_set( bool has_boundaries, uint64List *boundaries, bool has_boundaries_read, uint64List *boundaries_read, bool has_boundaries_write, uint64List *boundaries_write, + bool has_boundaries_append, uint64List *boundaries_append, bool has_boundaries_flush, uint64List *boundaries_flush, Error **errp) { @@ -557,6 +558,16 @@ void qmp_block_latency_histogram_set( } } =20 + if (has_boundaries || has_boundaries_append) { + ret =3D block_latency_histogram_set( + stats, BLOCK_ACCT_ZONE_APPEND, + has_boundaries_append ? boundaries_append : boundaries); + if (ret) { + error_setg(errp, "Device '%s' set append write boundaries fail= ", id); + return; + } + } + if (has_boundaries || has_boundaries_flush) { ret =3D block_latency_histogram_set( stats, BLOCK_ACCT_FLUSH, diff --git a/block/qapi.c b/block/qapi.c index c84147849d..2684484e9d 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -533,27 +533,36 @@ static void bdrv_query_blk_stats(BlockDeviceStats *ds= , BlockBackend *blk) =20 ds->rd_bytes =3D stats->nr_bytes[BLOCK_ACCT_READ]; ds->wr_bytes =3D stats->nr_bytes[BLOCK_ACCT_WRITE]; + ds->zone_append_bytes =3D stats->nr_bytes[BLOCK_ACCT_ZONE_APPEND]; ds->unmap_bytes =3D stats->nr_bytes[BLOCK_ACCT_UNMAP]; ds->rd_operations =3D stats->nr_ops[BLOCK_ACCT_READ]; ds->wr_operations =3D stats->nr_ops[BLOCK_ACCT_WRITE]; + ds->zone_append_operations =3D stats->nr_ops[BLOCK_ACCT_ZONE_APPEND]; ds->unmap_operations =3D stats->nr_ops[BLOCK_ACCT_UNMAP]; =20 ds->failed_rd_operations =3D stats->failed_ops[BLOCK_ACCT_READ]; ds->failed_wr_operations =3D stats->failed_ops[BLOCK_ACCT_WRITE]; + ds->failed_zone_append_operations =3D + stats->failed_ops[BLOCK_ACCT_ZONE_APPEND]; ds->failed_flush_operations =3D stats->failed_ops[BLOCK_ACCT_FLUSH]; ds->failed_unmap_operations =3D stats->failed_ops[BLOCK_ACCT_UNMAP]; =20 ds->invalid_rd_operations =3D stats->invalid_ops[BLOCK_ACCT_READ]; ds->invalid_wr_operations =3D stats->invalid_ops[BLOCK_ACCT_WRITE]; + ds->invalid_zone_append_operations =3D + stats->invalid_ops[BLOCK_ACCT_ZONE_APPEND]; ds->invalid_flush_operations =3D stats->invalid_ops[BLOCK_ACCT_FLUSH]; ds->invalid_unmap_operations =3D stats->invalid_ops[BLOCK_ACCT_UNMAP]; =20 ds->rd_merged =3D stats->merged[BLOCK_ACCT_READ]; ds->wr_merged =3D stats->merged[BLOCK_ACCT_WRITE]; + ds->zone_append_merged =3D stats->merged[BLOCK_ACCT_ZONE_APPEND]; ds->unmap_merged =3D stats->merged[BLOCK_ACCT_UNMAP]; ds->flush_operations =3D stats->nr_ops[BLOCK_ACCT_FLUSH]; ds->wr_total_time_ns =3D stats->total_time_ns[BLOCK_ACCT_WRITE]; + ds->zone_append_total_time_ns =3D + stats->total_time_ns[BLOCK_ACCT_ZONE_APPEND]; ds->rd_total_time_ns =3D stats->total_time_ns[BLOCK_ACCT_READ]; ds->flush_total_time_ns =3D stats->total_time_ns[BLOCK_ACCT_FLUSH]; ds->unmap_total_time_ns =3D stats->total_time_ns[BLOCK_ACCT_UNMAP]; @@ -571,6 +580,7 @@ static void bdrv_query_blk_stats(BlockDeviceStats *ds, = BlockBackend *blk) =20 TimedAverage *rd =3D &ts->latency[BLOCK_ACCT_READ]; TimedAverage *wr =3D &ts->latency[BLOCK_ACCT_WRITE]; + TimedAverage *zap =3D &ts->latency[BLOCK_ACCT_ZONE_APPEND]; TimedAverage *fl =3D &ts->latency[BLOCK_ACCT_FLUSH]; =20 dev_stats->interval_length =3D ts->interval_length; @@ -583,6 +593,10 @@ static void bdrv_query_blk_stats(BlockDeviceStats *ds,= BlockBackend *blk) dev_stats->max_wr_latency_ns =3D timed_average_max(wr); dev_stats->avg_wr_latency_ns =3D timed_average_avg(wr); =20 + dev_stats->min_zone_append_latency_ns =3D timed_average_min(zap); + dev_stats->max_zone_append_latency_ns =3D timed_average_max(zap); + dev_stats->avg_zone_append_latency_ns =3D timed_average_avg(zap); + dev_stats->min_flush_latency_ns =3D timed_average_min(fl); dev_stats->max_flush_latency_ns =3D timed_average_max(fl); dev_stats->avg_flush_latency_ns =3D timed_average_avg(fl); @@ -591,6 +605,8 @@ static void bdrv_query_blk_stats(BlockDeviceStats *ds, = BlockBackend *blk) block_acct_queue_depth(ts, BLOCK_ACCT_READ); dev_stats->avg_wr_queue_depth =3D block_acct_queue_depth(ts, BLOCK_ACCT_WRITE); + dev_stats->avg_zone_append_queue_depth =3D + block_acct_queue_depth(ts, BLOCK_ACCT_ZONE_APPEND); =20 QAPI_LIST_PREPEND(ds->timed_stats, dev_stats); } @@ -600,6 +616,8 @@ static void bdrv_query_blk_stats(BlockDeviceStats *ds, = BlockBackend *blk) =3D bdrv_latency_histogram_stats(&hgram[BLOCK_ACCT_READ]); ds->wr_latency_histogram =3D bdrv_latency_histogram_stats(&hgram[BLOCK_ACCT_WRITE]); + ds->zone_append_latency_histogram + =3D bdrv_latency_histogram_stats(&hgram[BLOCK_ACCT_ZONE_APPEND]); ds->flush_latency_histogram =3D bdrv_latency_histogram_stats(&hgram[BLOCK_ACCT_FLUSH]); } diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 8b6030b1a5..a9d3168770 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -919,6 +919,10 @@ static int virtio_blk_handle_zone_append(VirtIOBlockRe= q *req, data->in_num =3D in_num; data->zone_append_data.offset =3D offset; qemu_iovec_init_external(&req->qiov, out_iov, out_num); + + block_acct_start(blk_get_stats(s->blk), &req->acct, len, + BLOCK_ACCT_ZONE_APPEND); + blk_aio_zone_append(s->blk, &data->zone_append_data.offset, &req->qiov= , 0, virtio_blk_zone_append_complete, data); return 0; --=20 2.40.0 From nobody Fri May 10 01:51:43 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682685810; cv=none; d=zohomail.com; s=zohoarc; b=it3C+pIou7OVgbH0H7W9k9vjyKW2Bwc/biCrpA6nMqAF4ovrOPjaNVMi6eKp79IJAXAITTlFGd+QRC2MjLZkP0VKdadNAVlt8iQw/PyjUrQU0kuF6oPFoe1LwIkFXDGH1kGXiGIsf+PGPfeRzmwkCeC8exkZTmzLbB6HOlAgEr8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682685810; 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=54Tho65v8m23rzqAlACtxGOorCTnHWrQRKZ7YonfKxs=; b=F9L/5pDph7kmQauzbiEAeFCdwLDHXptgqsUQTvPzWdW9bmqqD//bPbm8PnFrPa/TyV0pQkLZI9VJke9HXajtcDP9DCxVWcgjybWK0rfX9kj2eJSy3l1sILCjMqsf7A8gA6HYrVCRefolIxGpKGp1fuzKshGH4nrpQEIrpHndZ98= 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 1682685810906967.1531854171691; Fri, 28 Apr 2023 05:43:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1psNPy-0000bX-6P; Fri, 28 Apr 2023 08:41:42 -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 1psNP9-0006xO-4d for qemu-devel@nongnu.org; Fri, 28 Apr 2023 08:40:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1psNP6-0000sG-H8 for qemu-devel@nongnu.org; Fri, 28 Apr 2023 08:40:50 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-326-KcNXBNcVO_i2IcwLkJlZiw-1; Fri, 28 Apr 2023 08:40:45 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 264D3A0F380; Fri, 28 Apr 2023 12:40:45 +0000 (UTC) Received: from localhost (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 65E08483EC4; Fri, 28 Apr 2023 12:40:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682685646; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=54Tho65v8m23rzqAlACtxGOorCTnHWrQRKZ7YonfKxs=; b=gP+0vncXI4EcTcd4iwWSRQQcoKbNDJ+zzMT7Oi5reV1wip7qbJjU2Xw5aoKrWLAsJb9cXO ipB2t6xd2qeoJv30hUeOkB5BxTT2B0YjW8kjKg9kPA4FNLVEKAfVLRinR3y3JrK3mt3XCy fEvpjxcToH5VqPIAOnwnjPGee5/vWbU= X-MC-Unique: KcNXBNcVO_i2IcwLkJlZiw-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Raphael Norwitz , Julia Suvorova , Cornelia Huck , Eric Blake , Paolo Bonzini , Aarushi Mehta , Stefan Hajnoczi , Richard Henderson , Kevin Wolf , Markus Armbruster , Stefano Garzarella , qemu-block@nongnu.org, Hanna Reitz , Fam Zheng , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Michael S. Tsirkin" , kvm@vger.kernel.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sam Li Subject: [PULL 16/17] virtio-blk: add some trace events for zoned emulation Date: Fri, 28 Apr 2023 08:39:53 -0400 Message-Id: <20230428123954.179035-17-stefanha@redhat.com> In-Reply-To: <20230428123954.179035-1-stefanha@redhat.com> References: <20230428123954.179035-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 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=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682685812536100003 Content-Type: text/plain; charset="utf-8" From: Sam Li Signed-off-by: Sam Li Reviewed-by: Stefan Hajnoczi Signed-off-by: Stefan Hajnoczi Message-Id: <20230407082528.18841-5-faithilikerun@gmail.com> --- hw/block/virtio-blk.c | 12 ++++++++++++ hw/block/trace-events | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index a9d3168770..7a66056c71 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -676,6 +676,7 @@ static void virtio_blk_zone_report_complete(void *opaqu= e, int ret) int64_t nz =3D data->zone_report_data.nr_zones; int8_t err_status =3D VIRTIO_BLK_S_OK; =20 + trace_virtio_blk_zone_report_complete(vdev, req, nz, ret); if (ret) { err_status =3D VIRTIO_BLK_S_ZONE_INVALID_CMD; goto out; @@ -792,6 +793,8 @@ static void virtio_blk_handle_zone_report(VirtIOBlockRe= q *req, nr_zones =3D (req->in_len - sizeof(struct virtio_blk_inhdr) - sizeof(struct virtio_blk_zone_report)) / sizeof(struct virtio_blk_zone_descriptor); + trace_virtio_blk_handle_zone_report(vdev, req, + offset >> BDRV_SECTOR_BITS, nr_zon= es); =20 zone_size =3D sizeof(BlockZoneDescriptor) * nr_zones; data =3D g_malloc(sizeof(ZoneCmdData)); @@ -814,7 +817,9 @@ static void virtio_blk_zone_mgmt_complete(void *opaque,= int ret) { VirtIOBlockReq *req =3D opaque; VirtIOBlock *s =3D req->dev; + VirtIODevice *vdev =3D VIRTIO_DEVICE(s); int8_t err_status =3D VIRTIO_BLK_S_OK; + trace_virtio_blk_zone_mgmt_complete(vdev, req,ret); =20 if (ret) { err_status =3D VIRTIO_BLK_S_ZONE_INVALID_CMD; @@ -841,6 +846,8 @@ static int virtio_blk_handle_zone_mgmt(VirtIOBlockReq *= req, BlockZoneOp op) /* Entire drive capacity */ offset =3D 0; len =3D capacity; + trace_virtio_blk_handle_zone_reset_all(vdev, req, 0, + bs->total_sectors); } else { if (bs->bl.zone_size > capacity - offset) { /* The zoned device allows the last smaller zone. */ @@ -848,6 +855,9 @@ static int virtio_blk_handle_zone_mgmt(VirtIOBlockReq *= req, BlockZoneOp op) } else { len =3D bs->bl.zone_size; } + trace_virtio_blk_handle_zone_mgmt(vdev, req, op, + offset >> BDRV_SECTOR_BITS, + len >> BDRV_SECTOR_BITS); } =20 if (!check_zoned_request(s, offset, len, false, &err_status)) { @@ -888,6 +898,7 @@ static void virtio_blk_zone_append_complete(void *opaqu= e, int ret) err_status =3D VIRTIO_BLK_S_ZONE_INVALID_CMD; goto out; } + trace_virtio_blk_zone_append_complete(vdev, req, append_sector, ret); =20 out: aio_context_acquire(blk_get_aio_context(s->conf.conf.blk)); @@ -909,6 +920,7 @@ static int virtio_blk_handle_zone_append(VirtIOBlockReq= *req, int64_t offset =3D virtio_ldq_p(vdev, &req->out.sector) << BDRV_SECTOR= _BITS; int64_t len =3D iov_size(out_iov, out_num); =20 + trace_virtio_blk_handle_zone_append(vdev, req, offset >> BDRV_SECTOR_B= ITS); if (!check_zoned_request(s, offset, len, true, &err_status)) { goto out; } diff --git a/hw/block/trace-events b/hw/block/trace-events index 2c45a62bd5..34be8b9135 100644 --- a/hw/block/trace-events +++ b/hw/block/trace-events @@ -44,9 +44,16 @@ pflash_write_unknown(const char *name, uint8_t cmd) "%s:= unknown command 0x%02x" # virtio-blk.c virtio_blk_req_complete(void *vdev, void *req, int status) "vdev %p req %p= status %d" virtio_blk_rw_complete(void *vdev, void *req, int ret) "vdev %p req %p ret= %d" +virtio_blk_zone_report_complete(void *vdev, void *req, unsigned int nr_zon= es, int ret) "vdev %p req %p nr_zones %u ret %d" +virtio_blk_zone_mgmt_complete(void *vdev, void *req, int ret) "vdev %p req= %p ret %d" +virtio_blk_zone_append_complete(void *vdev, void *req, int64_t sector, int= ret) "vdev %p req %p, append sector 0x%" PRIx64 " ret %d" virtio_blk_handle_write(void *vdev, void *req, uint64_t sector, size_t nse= ctors) "vdev %p req %p sector %"PRIu64" nsectors %zu" virtio_blk_handle_read(void *vdev, void *req, uint64_t sector, size_t nsec= tors) "vdev %p req %p sector %"PRIu64" nsectors %zu" virtio_blk_submit_multireq(void *vdev, void *mrb, int start, int num_reqs,= uint64_t offset, size_t size, bool is_write) "vdev %p mrb %p start %d num_= reqs %d offset %"PRIu64" size %zu is_write %d" +virtio_blk_handle_zone_report(void *vdev, void *req, int64_t sector, unsig= ned int nr_zones) "vdev %p req %p sector 0x%" PRIx64 " nr_zones %u" +virtio_blk_handle_zone_mgmt(void *vdev, void *req, uint8_t op, int64_t sec= tor, int64_t len) "vdev %p req %p op 0x%x sector 0x%" PRIx64 " len 0x%" PRI= x64 "" +virtio_blk_handle_zone_reset_all(void *vdev, void *req, int64_t sector, in= t64_t len) "vdev %p req %p sector 0x%" PRIx64 " cap 0x%" PRIx64 "" +virtio_blk_handle_zone_append(void *vdev, void *req, int64_t sector) "vdev= %p req %p, append sector 0x%" PRIx64 "" =20 # hd-geometry.c hd_geometry_lchs_guess(void *blk, int cyls, int heads, int secs) "blk %p L= CHS %d %d %d" --=20 2.40.0 From nobody Fri May 10 01:51:43 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682685931; cv=none; d=zohomail.com; s=zohoarc; b=W8tuE6B9F20tynXQZ4yakF+ZNC4Z+TgdxYruegSS6R0hURlx0k7sfYm9tAhzBvBtc9lXJ0cbgdFW2HQGPffT1mKv34Ixs7GwcRPWl07USbb4CpKDtcmjlOn3d6Yr/5KqMRzFt9GFbfPJcbv/8SpUCmVMyLjDX9c5ipItqSoXniI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682685931; 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=WiugCxsIb/whw5Nkr0rnohk1ss+BilENnp0eis8gAww=; b=fzLk+dzgRgwDNPTxajKYLz3HXZsgB+3fJ3y8dD1naGsVa5sfuw5M+WiWyS5n3DJALijkBvVqisCLS9sULrzTIieO1qh7ovUnTkSm4mAw4X56uLXzuocdqKDz+BDosbwG3pRbFf6jkVq1ONV6pVKVpWFW00ZLRhor3H8rSPp/7Ss= 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 168268593114386.66619040322291; Fri, 28 Apr 2023 05:45:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1psNPu-00006k-Uz; Fri, 28 Apr 2023 08:41:39 -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 1psNPB-0006zp-5y for qemu-devel@nongnu.org; Fri, 28 Apr 2023 08:40:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1psNP9-0000tM-6c for qemu-devel@nongnu.org; Fri, 28 Apr 2023 08:40:52 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-175-kHpOQMFhNzKzDLzQBifKbQ-1; Fri, 28 Apr 2023 08:40:48 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C4E14887402; Fri, 28 Apr 2023 12:40:47 +0000 (UTC) Received: from localhost (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2BE801121314; Fri, 28 Apr 2023 12:40:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682685650; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WiugCxsIb/whw5Nkr0rnohk1ss+BilENnp0eis8gAww=; b=OMGeO1ig7AydIRw3rYWReAdBptDzrigwSEwFNnm2irpjnKRF7TEM8qymUTzw53gxlLN7U8 kGhFfYx5ZNxZg6AWoFXdjV7THIpYr0Unbr6KjplAjeaG2F5RlKb4MUz10kCZkyXKKUEOvd xOS0fMJEpaFmf0C5+a6InK52xHXzQRI= X-MC-Unique: kHpOQMFhNzKzDLzQBifKbQ-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Raphael Norwitz , Julia Suvorova , Cornelia Huck , Eric Blake , Paolo Bonzini , Aarushi Mehta , Stefan Hajnoczi , Richard Henderson , Kevin Wolf , Markus Armbruster , Stefano Garzarella , qemu-block@nongnu.org, Hanna Reitz , Fam Zheng , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Michael S. Tsirkin" , kvm@vger.kernel.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sam Li Subject: [PULL 17/17] docs/zoned-storage:add zoned emulation use case Date: Fri, 28 Apr 2023 08:39:54 -0400 Message-Id: <20230428123954.179035-18-stefanha@redhat.com> In-Reply-To: <20230428123954.179035-1-stefanha@redhat.com> References: <20230428123954.179035-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682685932816100001 Content-Type: text/plain; charset="utf-8" From: Sam Li Add the documentation about the example of using virtio-blk driver to pass the zoned block devices through to the guest. Signed-off-by: Sam Li Signed-off-by: Stefan Hajnoczi [Fix rST syntax --Stefan] Message-Id: <20230407082528.18841-6-faithilikerun@gmail.com> --- docs/devel/zoned-storage.rst | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/docs/devel/zoned-storage.rst b/docs/devel/zoned-storage.rst index da78db2783..e02500c8a3 100644 --- a/docs/devel/zoned-storage.rst +++ b/docs/devel/zoned-storage.rst @@ -41,3 +41,22 @@ APIs for zoned storage emulation or testing. For example, to test zone_report on a null_blk device using qemu-io is:: =20 $ path/to/qemu-io --image-opts -n driver=3Dhost_device,filename=3D/dev/n= ullb0 -c "zrp offset nr_zones" + +To expose the host's zoned block device through virtio-blk, the command li= ne +can be (includes the -device parameter):: + + -blockdev node-name=3Ddrive0,driver=3Dhost_device,filename=3D/dev/nullb0= ,cache.direct=3Don \ + -device virtio-blk-pci,drive=3Ddrive0 + +Or only use the -drive parameter:: + + -driver driver=3Dhost_device,file=3D/dev/nullb0,if=3Dvirtio,cache.direct= =3Don + +Additionally, QEMU has several ways of supporting zoned storage, including: +(1) Using virtio-scsi: --device scsi-block allows for the passing through = of +SCSI ZBC devices, enabling the attachment of ZBC or ZAC HDDs to QEMU. +(2) PCI device pass-through: While NVMe ZNS emulation is available for tes= ting +purposes, it cannot yet pass through a zoned device from the host. To pass= on +the NVMe ZNS device to the guest, use VFIO PCI pass the entire NVMe PCI ad= apter +through to the guest. Likewise, an HDD HBA can be passed on to QEMU all HD= Ds +attached to the HBA. --=20 2.40.0