From nobody Thu May 9 00:06:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1660631713; cv=none; d=zohomail.com; s=zohoarc; b=eRGjW2Q6YgIO067uTVVWCgLv4JBuKBaXxgEmD50+5xwBAwFHe4Jih0nIAcjjoJP8ECIDn7kLtuy/l2MFMY/9xX6hz4Qj/vMEoR8u/qopV4zGa5kdGaiXS0EES7bmpiNdlDCSJ4z3MvCrQW5EXKPfZiwsMTFNcc++v/efk+8NZoE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660631713; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/uxSNMtOiF3YH3Q+juusUgjtziotSgDrNrvuRHofnb4=; b=nnqa6i0e2Lug+IWwQWnAN/xf/VFLemVpvHV7AZ3a5WgIL7XiaCamB1sf9jGN09CTB47V6/THD8yrgz2KBAWoNjAS1w84/wlOFZ4ze8ndXi9Ld0awXBaTT8znuIE1i3/k+LFRJNjQ/wpeGe8OZVyqMHq4VwdfQj6Ol9Fi4Ak/8TE= 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 1660631713306299.26234429993497; Mon, 15 Aug 2022 23:35:13 -0700 (PDT) Received: from localhost ([::1]:38454 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oNqAS-0002el-A4 for importer@patchew.org; Tue, 16 Aug 2022 02:35:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60422) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oNq1A-0005ad-7G; Tue, 16 Aug 2022 02:25:36 -0400 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]:45603) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oNq18-0003Yn-Im; Tue, 16 Aug 2022 02:25:35 -0400 Received: by mail-pj1-x102c.google.com with SMTP id p14-20020a17090a74ce00b001f4d04492faso8730817pjl.4; Mon, 15 Aug 2022 23:25:33 -0700 (PDT) Received: from roots.. ([106.84.129.185]) by smtp.gmail.com with ESMTPSA id e15-20020a170902784f00b0016f1c1f50f4sm8082868pln.235.2022.08.15.23.25.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Aug 2022 23:25:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=/uxSNMtOiF3YH3Q+juusUgjtziotSgDrNrvuRHofnb4=; b=UPoEa1K5yB61j6YdbAJLSS1u1cRzpfDcg81cgG70w8B4vM7oqL3ngfgNtjCm5dlMPs Y9BmBx9HFfmvfIBu4nyY4Z4zSrvDShlmqIK8bUjecdgFuQiEbVjIrxwJalkhcQtQmma0 66AMj7snsHpSN1QV70GTfzJyS0WWcSHLAQgluz5UiuGTzHGEcSkqqlCZT+aOZd9UUYeX IcwfGmQQJAIzQZNhNqwpktYQKVdedgyNxBxzWsHW7u33Z+jMI1QaEsEzxaSygREpBdB0 gh5N84vW13vgHMzI9oFWK8aqDrAUIVE4I6El15vv/GnVCBC0Yf2QQQuS0InvtA93oI9d qwFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=/uxSNMtOiF3YH3Q+juusUgjtziotSgDrNrvuRHofnb4=; b=JQR/dbBDfNMVS1RyDeOKe74EPmkQ9cKnJl+foPgE9ySllRIoe9rbEPqFcLFfrqkpZ2 c/nRz6pa5sWtSAPMPpNAXJgl2S2yGA1evFByTKn4UYzQORNSXfZ684nCs7xJY3uHBD7T dnKqaQZowlU+aCkng5pv1klgz1Vwg5Xwgev9cRoNhdPqNRE/y0CHj7QZZ2twvYWlTWkf GQvzD/TDd/RwNpZha8dlF+WLS7pPVFd85SYCTMWLuEJ7gPt9KXJ0lDnqq9cJpvjz59MJ Je/xBhs9kxtcvix2WiIYy+ETxqGlkEsuS63YodFMte87GBn4mCp8Mx91PmGk3QI0qasa gF7g== X-Gm-Message-State: ACgBeo3AtHEr2We0J125gRAdMhLXhIQPI/C/b0fdgF5jt2E/4AE+x0+4 DCHkPTT+sJBcDmHARHtY7ASk1C67NcA7ag== X-Google-Smtp-Source: AA6agR5fIuzetMyMA7Ym0MIpR8D01ghKSDOBTg482V9QXujgbqVueXhL6HpGEMoXE0NVJjABAv7UYg== X-Received: by 2002:a17:90a:4d8d:b0:1fa:9cc6:3408 with SMTP id m13-20020a17090a4d8d00b001fa9cc63408mr722797pjh.245.1660631132668; Mon, 15 Aug 2022 23:25:32 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: hare@suse.de, Fam Zheng , Kevin Wolf , Eric Blake , Markus Armbruster , stefanha@redhat.com, Hanna Reitz , dmitry.fomichev@wdc.com, qemu-block@nongnu.org, damien.lemoal@opensource.wdc.com, Sam Li Subject: [PATCH v7 1/8] include: add zoned device structs Date: Tue, 16 Aug 2022 14:25:15 +0800 Message-Id: <20220816062522.85714-2-faithilikerun@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220816062522.85714-1-faithilikerun@gmail.com> References: <20220816062522.85714-1-faithilikerun@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=faithilikerun@gmail.com; helo=mail-pj1-x102c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1660631714262100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Sam Li Reviewed-by: Stefan Hajnoczi Reviewed-by: Damien Le Moal --- include/block/block-common.h | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/include/block/block-common.h b/include/block/block-common.h index fdb7306e78..36bd0e480e 100644 --- a/include/block/block-common.h +++ b/include/block/block-common.h @@ -49,6 +49,49 @@ typedef struct BlockDriver BlockDriver; typedef struct BdrvChild BdrvChild; typedef struct BdrvChildClass BdrvChildClass; =20 +typedef enum BlockZoneOp { + BLK_ZO_OPEN, + BLK_ZO_CLOSE, + BLK_ZO_FINISH, + BLK_ZO_RESET, +} BlockZoneOp; + +typedef enum BlockZoneModel { + BLK_Z_NONE =3D 0x0, /* Regular block device */ + BLK_Z_HM =3D 0x1, /* Host-managed zoned block device */ + BLK_Z_HA =3D 0x2, /* Host-aware zoned block device */ +} BlockZoneModel; + +typedef enum BlockZoneCondition { + BLK_ZS_NOT_WP =3D 0x0, + BLK_ZS_EMPTY =3D 0x1, + BLK_ZS_IOPEN =3D 0x2, + BLK_ZS_EOPEN =3D 0x3, + BLK_ZS_CLOSED =3D 0x4, + BLK_ZS_RDONLY =3D 0xD, + BLK_ZS_FULL =3D 0xE, + BLK_ZS_OFFLINE =3D 0xF, +} BlockZoneCondition; + +typedef enum BlockZoneType { + BLK_ZT_CONV =3D 0x1, /* Conventional random writes supported */ + BLK_ZT_SWR =3D 0x2, /* Sequential writes required */ + BLK_ZT_SWP =3D 0x3, /* Sequential writes preferred */ +} BlockZoneType; + +/* + * Zone descriptor data structure. + * Provides information on a zone with all position and size values in byt= es. + */ +typedef struct BlockZoneDescriptor { + uint64_t start; + uint64_t length; + uint64_t cap; + uint64_t wp; + BlockZoneType type; + BlockZoneCondition cond; +} BlockZoneDescriptor; + typedef struct BlockDriverInfo { /* in bytes, 0 if irrelevant */ int cluster_size; --=20 2.37.1 From nobody Thu May 9 00:06:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1660632120; cv=none; d=zohomail.com; s=zohoarc; b=CyIXDw63lWg7sIYJfPOSNHZeSoD4iQFbv90+qLXMaF2xumWlqrOPPyAG3+RHdjsfP/utIL9ySejPTAcvCRI/2Jp9TlDnEjPdq5dDSfQodJEK0YaN0YY3u+KufKNuopK/eyzuec+AYnuwEuhoDx3hDVGuCF+JuyzR2XRlW5H8jKU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660632120; 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=oBur3qKGiJGHF0aic5DCV+9mWyAk9SD7xII096cvZUM=; b=W6ncemJvlWJqTcIC5n8H6hhV7IVA9vRlVo88vImf6SoIe7MCmhjG8AzKQZWJ0+9yvTiu5zFcvR6cVZALwoCDtWuMTESM/lcI3lZOlVcyJ0p1qKZSuhPlL4/XaF7VG+dL8Vx+OUWFYpc+Zzxzu6NLXYQaMWYamSMELz3Xq65453M= 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 1660632120301721.9272609969577; Mon, 15 Aug 2022 23:42:00 -0700 (PDT) Received: from localhost ([::1]:38194 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oNqH0-0000QR-9H for importer@patchew.org; Tue, 16 Aug 2022 02:41:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60464) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oNq1E-0005dV-1G; Tue, 16 Aug 2022 02:25:40 -0400 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]:40731) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oNq1C-0003ZG-BW; Tue, 16 Aug 2022 02:25:39 -0400 Received: by mail-pg1-x533.google.com with SMTP id 24so8446580pgr.7; Mon, 15 Aug 2022 23:25:37 -0700 (PDT) Received: from roots.. ([106.84.129.185]) by smtp.gmail.com with ESMTPSA id e15-20020a170902784f00b0016f1c1f50f4sm8082868pln.235.2022.08.15.23.25.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Aug 2022 23:25:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=oBur3qKGiJGHF0aic5DCV+9mWyAk9SD7xII096cvZUM=; b=aZwfcFwBruJtWpTCpvKkKunKtvTRxRv6mKYQrJ77A2pcJ66IGVCqnG9mE4SM/3lymQ m81yLmXKDFHk2j2ZFhzQEKxkKGNZ+eCWaVouAyg0gSa0eEvzgEkseJzEOq0fFO+MYBTD Bf3JpPZmRbJjxP46t4odruPItHVqd9L5QE6Jyiy6OZ9TLiUtkwid0Ugy0encamwemmu0 0nyhhLGsFcCXVFgGFk7U7LmYeNXi5s4pJBZ5JVE1aB88WZlvoD6sx6X2OLbZDiSveTQd gUuvGPRYwFRKbQghsNgRDXFPi+v3Ek74IODewHaOuC4CkxK2RJqBg5ONU+8fbJHJFmZA 5lPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=oBur3qKGiJGHF0aic5DCV+9mWyAk9SD7xII096cvZUM=; b=GnDYdW86ycgKC/QNHIL/rB/9ptfyI9qTmblk0WRwzRrHcwDgTkxvHX6eVvJDBJqiHe 9MJcVxRq5UD3UGXKiFcEb5Pe7Jn931o8qQlmqvJE6uOKk5WiCverHijrOoQPvIEyW2s2 fyAHE1I0EAb2tq8EfQVXtHnNfuijyhPIaVur0fGeacEJczkWMi9vaY9O2TUMWNRSqfY1 OMbof4oPkNX+8eCCCI9O5LoMKYVIJrkQsOMIx5QrULUGiGh8VkngDlZpTi3qjY5XQ4Eh WW74rFq40fABBvJTdSpoXEZ53fQOuSzGrS6dgXSS+0d6+6wvaA6ghTcZrhHrUycm4h2S pTUw== X-Gm-Message-State: ACgBeo37WZrjLxtIr2sDuv3KnEjdLWoVHlmOCbkiWzhTgidLOcnCRdIv Lrii5wBf2dI7/I31XH1v1ofxSTbLnUUcew== X-Google-Smtp-Source: AA6agR5i4Tpc3S9IZ/IXAGQrYITdn1osWoi81d0XAVn/idNCepKCGjQn57lMS/xiMadKq4euPH1Tgw== X-Received: by 2002:a63:e901:0:b0:422:4d27:5814 with SMTP id i1-20020a63e901000000b004224d275814mr15580089pgh.317.1660631136247; Mon, 15 Aug 2022 23:25:36 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: hare@suse.de, Fam Zheng , Kevin Wolf , Eric Blake , Markus Armbruster , stefanha@redhat.com, Hanna Reitz , dmitry.fomichev@wdc.com, qemu-block@nongnu.org, damien.lemoal@opensource.wdc.com, Sam Li Subject: [PATCH v7 2/8] file-posix: introduce get_sysfs_str_val for device zoned model Date: Tue, 16 Aug 2022 14:25:16 +0800 Message-Id: <20220816062522.85714-3-faithilikerun@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220816062522.85714-1-faithilikerun@gmail.com> References: <20220816062522.85714-1-faithilikerun@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::533; envelope-from=faithilikerun@gmail.com; helo=mail-pg1-x533.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1660632121099100001 Content-Type: text/plain; charset="utf-8" Use sysfs attribute files to get the string value of device zoned model. Then get_sysfs_zoned_model can convert it to BlockZoneModel type in QEMU. Signed-off-by: Sam Li Reviewed-by: Hannes Reinecke --- block/file-posix.c | 93 ++++++++++++++++++-------------- include/block/block_int-common.h | 3 ++ 2 files changed, 55 insertions(+), 41 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 48cd096624..c07ac4c697 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1210,66 +1210,71 @@ 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) -{ +/* + * Convert the zoned attribute file in sysfs to internal value. + */ +static int get_sysfs_str_val(struct stat *st, const char *attribute, + char **val) { #ifdef CONFIG_LINUX - char buf[32]; - const char *end; - char *sysfspath =3D NULL; + g_autofree char *sysfspath =3D NULL; int ret; - int sysfd =3D -1; - long max_segments; - - if (S_ISCHR(st->st_mode)) { - if (ioctl(fd, SG_GET_SG_TABLESIZE, &ret) =3D=3D 0) { - return ret; - } - return -ENOTSUP; - } + size_t len; =20 if (!S_ISBLK(st->st_mode)) { return -ENOTSUP; } =20 - sysfspath =3D g_strdup_printf("/sys/dev/block/%u:%u/queue/max_segments= ", - major(st->st_rdev), minor(st->st_rdev)); - sysfd =3D open(sysfspath, O_RDONLY); - if (sysfd =3D=3D -1) { - ret =3D -errno; - goto out; + 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; } - do { - ret =3D read(sysfd, buf, sizeof(buf) - 1); - } while (ret =3D=3D -1 && errno =3D=3D EINTR); + return ret; +#else + return -ENOTSUP; +#endif +} + +static int get_sysfs_zoned_model(struct stat *st, BlockZoneModel *zoned) { + g_autofree char *val =3D NULL; + int ret; + + ret =3D get_sysfs_str_val(st, "zoned", &val); if (ret < 0) { - ret =3D -errno; - goto out; - } else if (ret =3D=3D 0) { - ret =3D -EIO; - goto out; + return ret; } - buf[ret] =3D 0; - /* The file is ended with '\n', pass 'end' to accept that. */ - ret =3D qemu_strtol(buf, &end, 10, &max_segments); - if (ret =3D=3D 0 && end && *end =3D=3D '\n') { - ret =3D max_segments; + + if (strcmp(val, "host-managed") =3D=3D 0) { + *zoned =3D BLK_Z_HM; + } else if (strcmp(val, "host-aware") =3D=3D 0) { + *zoned =3D BLK_Z_HA; + } else if (strcmp(val, "none") =3D=3D 0) { + *zoned =3D BLK_Z_NONE; + } else { + return -ENOTSUP; } + return 0; +} =20 -out: - if (sysfd !=3D -1) { - close(sysfd); +static int hdev_get_max_segments(int fd, struct stat *st) { + int ret; + if (S_ISCHR(st->st_mode)) { + if (ioctl(fd, SG_GET_SG_TABLESIZE, &ret) =3D=3D 0) { + return ret; + } + return -ENOTSUP; } - g_free(sysfspath); - return ret; -#else - return -ENOTSUP; -#endif + return get_sysfs_long_val(st, "max_segments"); } =20 static void raw_refresh_limits(BlockDriverState *bs, Error **errp) { BDRVRawState *s =3D bs->opaque; struct stat st; + int ret; + BlockZoneModel zoned; =20 s->needs_alignment =3D raw_needs_alignment(bs); raw_probe_alignment(bs, s->fd, errp); @@ -1307,6 +1312,12 @@ static void raw_refresh_limits(BlockDriverState *bs,= Error **errp) bs->bl.max_hw_iov =3D ret; } } + + ret =3D get_sysfs_zoned_model(s->fd, &st, &zoned); + if (ret < 0) { + zoned =3D BLK_Z_NONE; + } + bs->bl.zoned =3D zoned; } =20 static int check_for_dasd(int fd) diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 8947abab76..7f7863cc9e 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -825,6 +825,9 @@ typedef struct BlockLimits { =20 /* maximum number of iovec elements */ int max_iov; + + /* device zone model */ + BlockZoneModel zoned; } BlockLimits; =20 typedef struct BdrvOpBlocker BdrvOpBlocker; --=20 2.37.1 From nobody Thu May 9 00:06:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1660631556; cv=none; d=zohomail.com; s=zohoarc; b=VDlGoS0J8OTyUARzFmwlVSE15JDk0fIpP70jOp33kRELfjubpTpm/D1NDTTrOHBIZm5ChGVklu8nzmEYna0MQTdLrxgstT3LlwaSNFIWiiP1V70NyoIT5YuoROuWBM/QU+O511Khhgf4YBfhERGYjlhNgJlRH5/tpclmtqj//DA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660631556; 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=AbM7fTPtWik1gu6NNQf85lKrMmeb7WBh151vruFR3Dw=; b=Ca+4WtbAus7zS0whfJOrKyRpMV3Scz6HDRIilsi2kBIPKaRR8yz/1saxTc0LqPGrBNmPObGP8a3jUPGF6OiF0w/A6GFmuuLlmdciytpEw5LLp3ubTL0pqmH4x6Ih1pWU0JmpJry9P+z4gXkHvcB3os/drct9BZC4ZAvb4EM3P2o= 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 1660631556072123.5747183314378; Mon, 15 Aug 2022 23:32:36 -0700 (PDT) Received: from localhost ([::1]:34922 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oNq7r-0001mj-6y for importer@patchew.org; Tue, 16 Aug 2022 02:32:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60494) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oNq1J-0005kt-1E; Tue, 16 Aug 2022 02:25:45 -0400 Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]:33678) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oNq1F-0003Zf-HA; Tue, 16 Aug 2022 02:25:43 -0400 Received: by mail-pg1-x534.google.com with SMTP id l64so8471383pge.0; Mon, 15 Aug 2022 23:25:40 -0700 (PDT) Received: from roots.. ([106.84.129.185]) by smtp.gmail.com with ESMTPSA id e15-20020a170902784f00b0016f1c1f50f4sm8082868pln.235.2022.08.15.23.25.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Aug 2022 23:25:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=AbM7fTPtWik1gu6NNQf85lKrMmeb7WBh151vruFR3Dw=; b=DxYKwD3DOFDrOdDzdDHuN8XjiD1P7f6dWVBK3jWGMrcvWf2hlrgzdUymHaBoWa2fT9 AsJM3WoZeKzyVIWgR2TIhkvo/n+8tgAa+Wfvz5CrBUXyfmf0dqZkj/conCqSBv1ls7xc Ani81p5EvtWcciwEgK0BNXfsM/UowXyTKfwZNJ6A0YM6+Wwjppg6jdifwB2XhIze+V/X m3KVcLV3D882ZWZ0vPdKDoGRmJmKnjzsOBarje1giB27RCdLzLTv0h2EHNmD3WNvb/L4 7bmsQBHYzz1FNl3+hZ2ZKQivsf4cwgFAgsT5tDiuq/0vBAYNi2fzPJyqqoHEifDen+4I GjBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=AbM7fTPtWik1gu6NNQf85lKrMmeb7WBh151vruFR3Dw=; b=Jvm3sPLWzLl4ELyU2JOomyfb4FnS6WWma0IdO47pFCw7wwLM50URKIHebo9ctAeQO5 dYfjgW+gN2HjJpf/Cmmv3u+gBq5tIBMIRM+oT7lPd1Dqmzcv7IUDc5BbgNAf0NVMSIrk 0/KJIY6zg0sPbXwgHx8v8xUC+tXTZXsT3cl+TeBQpmYGbpDSkqhmF9+tfFvgK4u83dSc W0xATft8oEJGykONbIvwI0iCryS3JOdoZ/sZzNgCvDuSHPKxn0aQLKVsmLQdyCvDzezV 6lgE09vQro06e1rJgoGbw/H93qBiVLx807Z6/dRVuLYmuBD+9lrYl7Y2VEFgJma7XI6X HtUw== X-Gm-Message-State: ACgBeo0aAx66tFArRQ2035ycbKUUSHE2vQ40ftyTcGNebwn1/SQQcMta utNuW/1Ji8ox1LN7CFRm+sfEj92MBXJGaQ== X-Google-Smtp-Source: AA6agR5Ukse/QXtua2NSiz5+LhoVJ+B9sRI6mBGHnZbgh6F6LL1Qc8JSgu1lOr12TgIpp3V/hM3ddQ== X-Received: by 2002:a63:8c47:0:b0:40d:2d4:e3a2 with SMTP id q7-20020a638c47000000b0040d02d4e3a2mr17163429pgn.2.1660631139772; Mon, 15 Aug 2022 23:25:39 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: hare@suse.de, Fam Zheng , Kevin Wolf , Eric Blake , Markus Armbruster , stefanha@redhat.com, Hanna Reitz , dmitry.fomichev@wdc.com, qemu-block@nongnu.org, damien.lemoal@opensource.wdc.com, Sam Li Subject: [PATCH v7 3/8] file-posix: introduce get_sysfs_long_val for the long sysfs attribute Date: Tue, 16 Aug 2022 14:25:17 +0800 Message-Id: <20220816062522.85714-4-faithilikerun@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220816062522.85714-1-faithilikerun@gmail.com> References: <20220816062522.85714-1-faithilikerun@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::534; envelope-from=faithilikerun@gmail.com; helo=mail-pg1-x534.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1660631558413100001 Content-Type: text/plain; charset="utf-8" Use sysfs attribute files to get the long value of zoned device information. Signed-off-by: Sam Li Reviewed-by: Hannes Reinecke Reviewed-by: Stefan Hajnoczi --- block/file-posix.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/block/file-posix.c b/block/file-posix.c index c07ac4c697..727389488c 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1258,6 +1258,33 @@ static int get_sysfs_zoned_model(struct stat *st, Bl= ockZoneModel *zoned) { return 0; } =20 +/* + * Get zoned device information (chunk_sectors, zoned_append_max_bytes, + * max_open_zones, max_active_zones) through sysfs attribute files. + */ +static long get_sysfs_long_val(struct stat *st, const char *attribute) { +#ifdef CONFIG_LINUX + g_autofree char *str =3D NULL; + const char *end; + long val; + int ret; + + ret =3D get_sysfs_str_val(st, attribute, &str); + if (ret < 0) { + return ret; + } + + /* The file is ended with '\n', pass 'end' to accept that. */ + ret =3D qemu_strtol(str, &end, 10, &val); + if (ret =3D=3D 0 && end && *end =3D=3D '\n') { + ret =3D val; + } + return ret; +#else + return -ENOTSUP; +#endif +} + static int hdev_get_max_segments(int fd, struct stat *st) { int ret; if (S_ISCHR(st->st_mode)) { --=20 2.37.1 From nobody Thu May 9 00:06:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1660632043; cv=none; d=zohomail.com; s=zohoarc; b=lP/S3jOQrVGcDNV3f5sWZip6s2O8e/8n44WOWQ88CCvQnmmBvXglYhiB9DTL8EWoogPO7uo8gBi/QrREsHHI8tw2AlKQG6NptC93a7CvVU/GsjsguQOyGWeupKjPnBv3yJpySybFKGmseME9fo0ij6BezJVn0wfV3FZVR0Sgkj0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660632043; 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=ZJFVk+/6iteeN9kgARtDibutBO823LrGrcmjZNLORTA=; b=EIPzMb5KTuFx2CmrHgZWFsw4cy7IPK+SbGsLG5NXLfB2zzNDuxp13rtK3ZQmUhnTjYC5Cfk0DUBT5yjYNZNoXjtXCNgixZjYatWGkZxmbrCXfqp8qUvAjkwhdzecDY2wjNLD831Vkjy40y2bXfpjH8SdhJBjTv0+dHLPZuvLeT8= 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 16606320432084.911279898847852; Mon, 15 Aug 2022 23:40:43 -0700 (PDT) Received: from localhost ([::1]:59908 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oNqFl-0006Rk-0J for importer@patchew.org; Tue, 16 Aug 2022 02:40:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60510) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oNq1M-0005qz-De; Tue, 16 Aug 2022 02:25:48 -0400 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]:40731) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oNq1J-0003ZG-DS; Tue, 16 Aug 2022 02:25:48 -0400 Received: by mail-pg1-x533.google.com with SMTP id 24so8446814pgr.7; Mon, 15 Aug 2022 23:25:44 -0700 (PDT) Received: from roots.. ([106.84.129.185]) by smtp.gmail.com with ESMTPSA id e15-20020a170902784f00b0016f1c1f50f4sm8082868pln.235.2022.08.15.23.25.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Aug 2022 23:25:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=ZJFVk+/6iteeN9kgARtDibutBO823LrGrcmjZNLORTA=; b=q14oFUoKdzvhrh/WFtdQyuBq3wS93koL6hj2eHzG8lqdCQOqm32B2B7Ny7AgW0Qehb ieEoVMngJHkk7DaesGilafhobg02NCTiut+JEmBtxCq7VUDfJZBzJPC4ywK56QXWPU5w a0ZwZThwRv9+LsCBnB3juRPzL+9GKB6gjml8vObYpj/8Ud8EiMe/TKrPFcYatwCFIsNy Eby7f6e8fCd/1D9b2vJ3nH2z+y9CK3tHiahIBodyKPUjVcaJFahayWGWlfk4djlnWkYI i/abbxjXykVp9g/MZcRkNkIkhxYrc3kUrZpcrhAYNh9XEXXbZVU5I3VBIQHepowRgI78 clSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=ZJFVk+/6iteeN9kgARtDibutBO823LrGrcmjZNLORTA=; b=pDQ8PhHJQvpOunWO6TSYcubUOmVuyHs/wL8eVsUZ9l8Ny8YrcSOqdx7OXhVe2gdwc3 GvLk6eAmfWTdRFh70GGgxtpqA9vuKwoqgd3kZkz/lsVn/FHsyp/fpH6jOke+3a/Uqdfv DiqjNHQzQPxmAW4g2MXRD8x7EftqL5kBUneW8RBKw91Z4dq9tvrB4HrD5ZbOb461CcmE cZ0OmHQAFb0i/WgppwpdYtuXgdI9GkkUf2Kc5gJhQFMikqUOZQ9xtOYJNvZs19bu574L dAuALMLSprT0/MbSdRTM8JOsDpBSuS39h7Qp/tqyx0Qpvmv6E7B/xtBcu2Uw9wiENFaA tvmg== X-Gm-Message-State: ACgBeo2RYAvhNMKzy1fb+3WJv1ZyPwmXOXIeEtNOjXXuiK9nM5oSkhV7 0eKqLGKU6KvA4Nj6LVnOCvURcUzR4lxu7Q== X-Google-Smtp-Source: AA6agR7nga0tbd1yElJ1g22v3sRLhOTxnPU2QDnZLCroFE9bw7+PobsuSx3lsgtda9rz9cXLF207Ag== X-Received: by 2002:a63:e410:0:b0:422:45b3:837 with SMTP id a16-20020a63e410000000b0042245b30837mr15264580pgi.175.1660631143675; Mon, 15 Aug 2022 23:25:43 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: hare@suse.de, Fam Zheng , Kevin Wolf , Eric Blake , Markus Armbruster , stefanha@redhat.com, Hanna Reitz , dmitry.fomichev@wdc.com, qemu-block@nongnu.org, damien.lemoal@opensource.wdc.com, Sam Li Subject: [PATCH v7 4/8] block: add block layer APIs resembling Linux ZonedBlockDevice ioctls Date: Tue, 16 Aug 2022 14:25:18 +0800 Message-Id: <20220816062522.85714-5-faithilikerun@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220816062522.85714-1-faithilikerun@gmail.com> References: <20220816062522.85714-1-faithilikerun@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::533; envelope-from=faithilikerun@gmail.com; helo=mail-pg1-x533.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1660632044838100001 Content-Type: text/plain; charset="utf-8" By adding zone management operations in BlockDriver, storage controller emulation can use the new block layer APIs including Report Zone and four zone management operations (open, close, finish, reset). Add zoned storage commands of the device: zone_report(zrp), zone_open(zo), zone_close(zc), zone_reset(zrs), zone_finish(zf). For example, to test zone_report, use following command: $ ./build/qemu-io --image-opts driver=3Dzoned_host_device, filename=3D/dev/= nullb0 -c "zrp offset nr_zones" Signed-off-by: Sam Li Reviewed-by: Hannes Reinecke --- block/block-backend.c | 50 +++++ block/file-posix.c | 341 +++++++++++++++++++++++++++++- block/io.c | 41 ++++ include/block/block-common.h | 1 - include/block/block-io.h | 13 ++ include/block/block_int-common.h | 22 +- include/block/raw-aio.h | 6 +- include/sysemu/block-backend-io.h | 6 + meson.build | 1 + qapi/block-core.json | 8 +- qemu-io-cmds.c | 143 +++++++++++++ 11 files changed, 625 insertions(+), 7 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index d4a5df2ac2..fc639b0cd7 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1775,6 +1775,56 @@ int coroutine_fn blk_co_flush(BlockBackend *blk) return ret; } =20 +/* + * Send a zone_report command. + * offset is a byte offset from the start of the device. No alignment + * required for offset. + * nr_zones represents IN maximum and OUT actual. + */ +int coroutine_fn blk_co_zone_report(BlockBackend *blk, int64_t offset, + unsigned int *nr_zones, + BlockZoneDescriptor *zones) +{ + int ret; + IO_CODE(); + + blk_inc_in_flight(blk); /* increase before waiting */ + blk_wait_while_drained(blk); + if (!blk_is_available(blk)) { + blk_dec_in_flight(blk); + return -ENOMEDIUM; + } + ret =3D bdrv_co_zone_report(blk_bs(blk), offset, nr_zones, zones); + blk_dec_in_flight(blk); + return ret; +} + +/* + * Send a zone_management command. + * offset is the starting zone specified as a sector offset. + * len is the maximum number of sectors the command should operate on. + */ +int coroutine_fn blk_co_zone_mgmt(BlockBackend *blk, BlockZoneOp op, + int64_t offset, int64_t len) +{ + int ret; + IO_CODE(); + + ret =3D blk_check_byte_request(blk, offset, len); + if (ret < 0) { + return ret; + } + blk_inc_in_flight(blk); + blk_wait_while_drained(blk); + if (!blk_is_available(blk)) { + blk_dec_in_flight(blk); + return -ENOMEDIUM; + } + ret =3D bdrv_co_zone_mgmt(blk_bs(blk), op, offset, len); + blk_dec_in_flight(blk); + return ret; +} + void blk_drain(BlockBackend *blk) { BlockDriverState *bs =3D blk_bs(blk); diff --git a/block/file-posix.c b/block/file-posix.c index 727389488c..29f67082d9 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -67,6 +67,9 @@ #include #include #include +#if defined(CONFIG_BLKZONED) +#include +#endif #include #include #include @@ -216,6 +219,13 @@ typedef struct RawPosixAIOData { PreallocMode prealloc; Error **errp; } truncate; + struct { + unsigned int *nr_zones; + BlockZoneDescriptor *zones; + } zone_report; + struct { + unsigned long ioctl_op; + } zone_mgmt; }; } RawPosixAIOData; =20 @@ -1328,7 +1338,7 @@ static void raw_refresh_limits(BlockDriverState *bs, = Error **errp) #endif =20 if (bs->sg || S_ISBLK(st.st_mode)) { - int ret =3D hdev_get_max_hw_transfer(s->fd, &st); + ret =3D hdev_get_max_hw_transfer(s->fd, &st); =20 if (ret > 0 && ret <=3D BDRV_REQUEST_MAX_BYTES) { bs->bl.max_hw_transfer =3D ret; @@ -1340,11 +1350,32 @@ static void raw_refresh_limits(BlockDriverState *bs= , Error **errp) } } =20 - ret =3D get_sysfs_zoned_model(s->fd, &st, &zoned); + ret =3D get_sysfs_zoned_model(&st, &zoned); if (ret < 0) { zoned =3D BLK_Z_NONE; } bs->bl.zoned =3D zoned; + if (zoned !=3D BLK_Z_NONE) { + ret =3D get_sysfs_long_val(&st, "chunk_sectors"); + if (ret > 0) { + bs->bl.zone_sectors =3D ret; + } + + ret =3D get_sysfs_long_val(&st, "zone_append_max_bytes"); + if (ret > 0) { + bs->bl.zone_append_max_bytes =3D ret; + } + + ret =3D get_sysfs_long_val(&st, "max_open_zones"); + if (ret > 0) { + bs->bl.max_open_zones =3D ret; + } + + ret =3D get_sysfs_long_val(&st, "max_active_zones"); + if (ret > 0) { + bs->bl.max_active_zones =3D ret; + } + } } =20 static int check_for_dasd(int fd) @@ -1839,6 +1870,134 @@ static off_t copy_file_range(int in_fd, off_t *in_o= ff, int out_fd, } #endif =20 +/* + * parse_zone - Fill a zone descriptor + */ +#if defined(CONFIG_BLKZONED) +static inline void parse_zone(struct BlockZoneDescriptor *zone, + struct blk_zone *blkz) { + zone->start =3D blkz->start; + zone->length =3D blkz->len; + zone->cap =3D blkz->capacity; + zone->wp =3D blkz->wp; + + 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("Invalid zone type: 0x%x", blkz->type); + } + + switch (blkz->cond) { + case BLK_ZONE_COND_NOT_WP: + zone->cond =3D BLK_ZS_NOT_WP; + break; + case BLK_ZONE_COND_EMPTY: + zone->cond =3D BLK_ZS_EMPTY; + break; + case BLK_ZONE_COND_IMP_OPEN: + zone->cond =3DBLK_ZS_IOPEN; + break; + case BLK_ZONE_COND_EXP_OPEN: + zone->cond =3D BLK_ZS_EOPEN; + break; + case BLK_ZONE_COND_CLOSED: + zone->cond =3D BLK_ZS_CLOSED; + break; + case BLK_ZONE_COND_READONLY: + zone->cond =3D BLK_ZS_RDONLY; + break; + case BLK_ZONE_COND_FULL: + zone->cond =3D BLK_ZS_FULL; + break; + case BLK_ZONE_COND_OFFLINE: + zone->cond =3D BLK_ZS_OFFLINE; + break; + default: + error_report("Invalid zone condition 0x%x", blkz->cond); + } +} +#endif + +static int handle_aiocb_zone_report(void *opaque) { +#if defined(CONFIG_BLKZONED) + RawPosixAIOData *aiocb =3D opaque; + int fd =3D aiocb->aio_fildes; + unsigned int *nr_zones =3D aiocb->zone_report.nr_zones; + BlockZoneDescriptor *zones =3D aiocb->zone_report.zones; + int64_t sector =3D aiocb->aio_offset; + + struct blk_zone *blkz; + int64_t rep_size; + unsigned int nrz; + int ret, n =3D 0, i =3D 0; + + nrz =3D *nr_zones; + rep_size =3D sizeof(struct blk_zone_report) + nrz * sizeof(struct blk_= zone); + g_autofree struct blk_zone_report *rep =3D NULL; + rep =3D g_malloc(rep_size); + + blkz =3D (struct blk_zone *)(rep + 1); + while (n < nrz) { + memset(rep, 0, rep_size); + rep->sector =3D sector; + rep->nr_zones =3D nrz - n; + + ret =3D ioctl(fd, BLKREPORTZONE, rep); + if (ret !=3D 0) { + error_report("%d: ioctl BLKREPORTZONE at %" PRId64 " failed %d= ", + fd, sector, errno); + return -errno; + } + + if (!rep->nr_zones) { + break; + } + + for (i =3D 0; i < rep->nr_zones; i++, n++) { + parse_zone(&zones[n], &blkz[i]); + /* The next report should start after the last zone reported */ + sector =3D blkz[i].start + blkz[i].len; + } + } + + *nr_zones =3D n; + return 0; +#else + return -ENOTSUP; +#endif +} + +static int handle_aiocb_zone_mgmt(void *opaque) { +#if defined(CONFIG_BLKZONED) + RawPosixAIOData *aiocb =3D opaque; + int fd =3D aiocb->aio_fildes; + int64_t sector =3D aiocb->aio_offset; + int64_t nr_sectors =3D aiocb->aio_nbytes; + unsigned long ioctl_op =3D aiocb->zone_mgmt.ioctl_op; + 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, ioctl_op, &range); + } while (ret !=3D 0 && errno =3D=3D EINTR); + + return ret; +#else + return -ENOTSUP; +#endif +} + static int handle_aiocb_copy_range(void *opaque) { RawPosixAIOData *aiocb =3D opaque; @@ -3011,6 +3170,124 @@ 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. + * + * @param bs: passing zone block device file descriptor + * @param zones: an array of zone descriptors to hold zone + * information on reply + * @param offset: offset can be any byte within the zone size. + * @param len: (not sure yet. + * @return 0 on success, -1 on failure + */ +static int coroutine_fn raw_co_zone_report(BlockDriverState *bs, int64_t o= ffset, + unsigned int *nr_zones, + BlockZoneDescriptor *zones) { +#if defined(CONFIG_BLKZONED) + BDRVRawState *s =3D bs->opaque; + RawPosixAIOData acb; + + acb =3D (RawPosixAIOData) { + .bs =3D bs, + .aio_fildes =3D s->fd, + .aio_type =3D QEMU_AIO_ZONE_REPORT, + /* zoned block devices use 512-byte sectors */ + .aio_offset =3D offset / 512, + .zone_report =3D { + .nr_zones =3D nr_zones, + .zones =3D zones, + }, + }; + + return raw_thread_pool_submit(bs, handle_aiocb_zone_report, &acb); +#else + return -ENOTSUP; +#endif +} + +/* + * zone management operations - Execute an operation on a zone + */ +static int coroutine_fn raw_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp= op, + int64_t offset, int64_t len) { +#if defined(CONFIG_BLKZONED) + BDRVRawState *s =3D bs->opaque; + RawPosixAIOData acb; + int64_t zone_sector, zone_sector_mask; + const char *ioctl_name; + unsigned long ioctl_op; + int ret; + + struct stat st; + if (fstat(s->fd, &st) < 0) { + ret =3D -errno; + return ret; + } + zone_sector =3D get_sysfs_long_val(&st, "chunk_sectors"); + if (zone_sector < 0) { + error_report("invalid zone sector size %" PRId64 "", zone_sector); + return -EINVAL; + } + + zone_sector_mask =3D zone_sector - 1; + if (offset & zone_sector_mask) { + error_report("sector offset %" PRId64 " is not aligned to zone siz= e " + "%" PRId64 "", offset, zone_sector); + return -EINVAL; + } + + if (len & zone_sector_mask) { + error_report("number of sectors %" PRId64 " is not aligned to zone= size" + " %" PRId64 "", len, zone_sector); + return -EINVAL; + } + + switch (op) { + case BLK_ZO_OPEN: + ioctl_name =3D "BLKOPENZONE"; + ioctl_op =3D BLKOPENZONE; + break; + case BLK_ZO_CLOSE: + ioctl_name =3D "BLKCLOSEZONE"; + ioctl_op =3D BLKCLOSEZONE; + break; + case BLK_ZO_FINISH: + ioctl_name =3D "BLKFINISHZONE"; + ioctl_op =3D BLKFINISHZONE; + break; + case BLK_ZO_RESET: + ioctl_name =3D "BLKRESETZONE"; + ioctl_op =3D BLKRESETZONE; + break; + default: + error_report("Invalid zone operation 0x%x", op); + return -EINVAL; + } + + 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 { + .ioctl_op =3D ioctl_op, + }, + }; + + ret =3D raw_thread_pool_submit(bs, handle_aiocb_zone_mgmt, &acb); + if (ret !=3D 0) { + error_report("ioctl %s failed %d", ioctl_name, errno); + return -errno; + } + + return ret; +#else + return -ENOTSUP; +#endif +} + static coroutine_fn int raw_do_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes, bool blkdev) @@ -3511,6 +3788,14 @@ static void hdev_parse_filename(const char *filename= , QDict *options, bdrv_parse_filename_strip_prefix(filename, "host_device:", options); } =20 +#if defined(CONFIG_BLKZONED) +static void zoned_host_device_parse_filename(const char *filename, QDict *= options, + Error **errp) +{ + bdrv_parse_filename_strip_prefix(filename, "zoned_host_device:", optio= ns); +} +#endif + static bool hdev_is_sg(BlockDriverState *bs) { =20 @@ -3741,6 +4026,55 @@ static BlockDriver bdrv_host_device =3D { #endif }; =20 +#if defined(CONFIG_BLKZONED) +static BlockDriver bdrv_zoned_host_device =3D { + .format_name =3D "zoned_host_device", + .protocol_name =3D "zoned_host_device", + .instance_size =3D sizeof(BDRVRawState), + .bdrv_needs_filename =3D true, + .bdrv_probe_device =3D hdev_probe_device, + .bdrv_parse_filename =3D zoned_host_device_parse_filename, + .bdrv_file_open =3D hdev_open, + .bdrv_close =3D raw_close, + .bdrv_reopen_prepare =3D raw_reopen_prepare, + .bdrv_reopen_commit =3D raw_reopen_commit, + .bdrv_reopen_abort =3D raw_reopen_abort, + .bdrv_co_create_opts =3D bdrv_co_create_opts_simple, + .create_opts =3D &bdrv_create_opts_simple, + .mutable_opts =3D mutable_opts, + .bdrv_co_invalidate_cache =3D raw_co_invalidate_cache, + .bdrv_co_pwrite_zeroes =3D hdev_co_pwrite_zeroes, + + .bdrv_co_preadv =3D raw_co_preadv, + .bdrv_co_pwritev =3D raw_co_pwritev, + .bdrv_co_flush_to_disk =3D raw_co_flush_to_disk, + .bdrv_co_pdiscard =3D hdev_co_pdiscard, + .bdrv_co_copy_range_from =3D raw_co_copy_range_from, + .bdrv_co_copy_range_to =3D raw_co_copy_range_to, + .bdrv_refresh_limits =3D raw_refresh_limits, + .bdrv_io_plug =3D raw_aio_plug, + .bdrv_io_unplug =3D raw_aio_unplug, + .bdrv_attach_aio_context =3D raw_aio_attach_aio_context, + + .bdrv_co_truncate =3D raw_co_truncate, + .bdrv_getlength =3D raw_getlength, + .bdrv_get_info =3D raw_get_info, + .bdrv_get_allocated_file_size + =3D raw_get_allocated_file_size, + .bdrv_get_specific_stats =3D hdev_get_specific_stats, + .bdrv_check_perm =3D raw_check_perm, + .bdrv_set_perm =3D raw_set_perm, + .bdrv_abort_perm_update =3D raw_abort_perm_update, + .bdrv_probe_blocksizes =3D hdev_probe_blocksizes, + .bdrv_probe_geometry =3D hdev_probe_geometry, + .bdrv_co_ioctl =3D hdev_co_ioctl, + + /* zone management operations */ + .bdrv_co_zone_report =3D raw_co_zone_report, + .bdrv_co_zone_mgmt =3D raw_co_zone_mgmt, +}; +#endif + #if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel= __) static void cdrom_parse_filename(const char *filename, QDict *options, Error **errp) @@ -4001,6 +4335,9 @@ static void bdrv_file_init(void) bdrv_register(&bdrv_file); #if defined(HAVE_HOST_BLOCK_DEVICE) bdrv_register(&bdrv_host_device); +#if defined(CONFIG_BLKZONED) + bdrv_register(&bdrv_zoned_host_device); +#endif #ifdef __linux__ bdrv_register(&bdrv_host_cdrom); #endif diff --git a/block/io.c b/block/io.c index 0a8cbefe86..de9ec1d740 100644 --- a/block/io.c +++ b/block/io.c @@ -3198,6 +3198,47 @@ out: return co.ret; } =20 +int bdrv_co_zone_report(BlockDriverState *bs, int64_t offset, + unsigned int *nr_zones, + BlockZoneDescriptor *zones) +{ + BlockDriver *drv =3D bs->drv; + CoroutineIOCompletion co =3D { + .coroutine =3D qemu_coroutine_self(), + }; + IO_CODE(); + + bdrv_inc_in_flight(bs); + if (!drv || !drv->bdrv_co_zone_report) { + co.ret =3D -ENOTSUP; + goto out; + } + co.ret =3D drv->bdrv_co_zone_report(bs, offset, nr_zones, zones); +out: + bdrv_dec_in_flight(bs); + return co.ret; +} + +int bdrv_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, + int64_t offset, int64_t len) +{ + BlockDriver *drv =3D bs->drv; + CoroutineIOCompletion co =3D { + .coroutine =3D qemu_coroutine_self(), + }; + IO_CODE(); + + bdrv_inc_in_flight(bs); + if (!drv || !drv->bdrv_co_zone_mgmt) { + co.ret =3D -ENOTSUP; + goto out; + } + co.ret =3D drv->bdrv_co_zone_mgmt(bs, op, offset, len); +out: + bdrv_dec_in_flight(bs); + return co.ret; +} + void *qemu_blockalign(BlockDriverState *bs, size_t size) { IO_CODE(); diff --git a/include/block/block-common.h b/include/block/block-common.h index 36bd0e480e..5102fa6858 100644 --- a/include/block/block-common.h +++ b/include/block/block-common.h @@ -23,7 +23,6 @@ */ #ifndef BLOCK_COMMON_H #define BLOCK_COMMON_H - #include "block/aio.h" #include "block/aio-wait.h" #include "qemu/iov.h" diff --git a/include/block/block-io.h b/include/block/block-io.h index fd25ffa9be..55ad261e16 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -88,6 +88,13 @@ int bdrv_co_ioctl(BlockDriverState *bs, int req, void *b= uf); /* Ensure contents are flushed to disk. */ int coroutine_fn bdrv_co_flush(BlockDriverState *bs); =20 +/* Report zone information of zone block device. */ +int coroutine_fn bdrv_co_zone_report(BlockDriverState *bs, int64_t offset, + unsigned int *nr_zones, + BlockZoneDescriptor *zones); +int coroutine_fn bdrv_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, + int64_t offset, int64_t len); + int bdrv_co_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes); bool bdrv_can_write_zeroes_with_unmap(BlockDriverState *bs); int bdrv_block_status(BlockDriverState *bs, int64_t offset, @@ -297,6 +304,12 @@ bdrv_readv_vmstate(BlockDriverState *bs, QEMUIOVector = *qiov, int64_t pos); int generated_co_wrapper bdrv_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos); =20 +int generated_co_wrapper +blk_zone_report(BlockBackend *blk, int64_t offset, unsigned int *nr_zones, + BlockZoneDescriptor *zones); +int generated_co_wrapper +blk_zone_mgmt(BlockBackend *blk, BlockZoneOp op, int64_t offset, int64_t l= en); + /** * bdrv_parent_drained_begin_single: * diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 7f7863cc9e..de44c7b6f4 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -94,7 +94,6 @@ typedef struct BdrvTrackedRequest { struct BdrvTrackedRequest *waiting_for; } BdrvTrackedRequest; =20 - struct BlockDriver { /* * These fields are initialized when this object is created, @@ -691,6 +690,12 @@ struct BlockDriver { QEMUIOVector *qiov, int64_t pos); =20 + int coroutine_fn (*bdrv_co_zone_report)(BlockDriverState *bs, + int64_t offset, unsigned int *nr_zones, + BlockZoneDescriptor *zones); + int coroutine_fn (*bdrv_co_zone_mgmt)(BlockDriverState *bs, BlockZoneO= p op, + int64_t offset, int64_t len); + /* removable device specific */ bool (*bdrv_is_inserted)(BlockDriverState *bs); void (*bdrv_eject)(BlockDriverState *bs, bool eject_flag); @@ -828,6 +833,21 @@ typedef struct BlockLimits { =20 /* device zone model */ BlockZoneModel zoned; + + /* zone size expressed in 512-byte sectors */ + uint32_t zone_sectors; + + /* total number of zones */ + unsigned int nr_zones; + + /* maximum size in bytes of a zone append write operation */ + int64_t zone_append_max_bytes; + + /* maximum number of open zones */ + int64_t max_open_zones; + + /* maximum number of active zones */ + int64_t max_active_zones; } BlockLimits; =20 typedef struct BdrvOpBlocker BdrvOpBlocker; diff --git a/include/block/raw-aio.h b/include/block/raw-aio.h index 21fc10c4c9..3d26929cdd 100644 --- a/include/block/raw-aio.h +++ b/include/block/raw-aio.h @@ -29,6 +29,8 @@ #define QEMU_AIO_WRITE_ZEROES 0x0020 #define QEMU_AIO_COPY_RANGE 0x0040 #define QEMU_AIO_TRUNCATE 0x0080 +#define QEMU_AIO_ZONE_REPORT 0x0100 +#define QEMU_AIO_ZONE_MGMT 0x0200 #define QEMU_AIO_TYPE_MASK \ (QEMU_AIO_READ | \ QEMU_AIO_WRITE | \ @@ -37,7 +39,9 @@ QEMU_AIO_DISCARD | \ QEMU_AIO_WRITE_ZEROES | \ QEMU_AIO_COPY_RANGE | \ - QEMU_AIO_TRUNCATE) + QEMU_AIO_TRUNCATE | \ + QEMU_AIO_ZONE_REPORT | \ + QEMU_AIO_ZONE_MGMT) =20 /* AIO flags */ #define QEMU_AIO_MISALIGNED 0x1000 diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backe= nd-io.h index 50f5aa2e07..6e7df1d93b 100644 --- a/include/sysemu/block-backend-io.h +++ b/include/sysemu/block-backend-io.h @@ -156,6 +156,12 @@ int generated_co_wrapper blk_pwrite_zeroes(BlockBacken= d *blk, 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 coroutine_fn blk_co_zone_mgmt(BlockBackend *blk, BlockZoneOp op, + int64_t offset, int64_t len); + int generated_co_wrapper blk_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes); int coroutine_fn blk_co_pdiscard(BlockBackend *blk, int64_t offset, diff --git a/meson.build b/meson.build index 294e9a8f32..c3219b0e87 100644 --- a/meson.build +++ b/meson.build @@ -1883,6 +1883,7 @@ config_host_data.set('CONFIG_REPLICATION', get_option= ('live_block_migration').al # has_header config_host_data.set('CONFIG_EPOLL', cc.has_header('sys/epoll.h')) config_host_data.set('CONFIG_LINUX_MAGIC_H', cc.has_header('linux/magic.h'= )) +config_host_data.set('CONFIG_BLKZONED', cc.has_header('linux/blkzoned.h')) config_host_data.set('CONFIG_VALGRIND_H', cc.has_header('valgrind/valgrind= .h')) config_host_data.set('HAVE_BTRFS_H', cc.has_header('linux/btrfs.h')) config_host_data.set('HAVE_DRM_H', cc.has_header('libdrm/drm.h')) diff --git a/qapi/block-core.json b/qapi/block-core.json index 2173e7734a..c6bbb7a037 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2942,6 +2942,7 @@ # @compress: Since 5.0 # @copy-before-write: Since 6.2 # @snapshot-access: Since 7.0 +# @zoned_host_device: Since 7.2 # # Since: 2.9 ## @@ -2955,7 +2956,8 @@ 'luks', 'nbd', 'nfs', 'null-aio', 'null-co', 'nvme', 'parallel= s', 'preallocate', 'qcow', 'qcow2', 'qed', 'quorum', 'raw', 'rbd', { 'name': 'replication', 'if': 'CONFIG_REPLICATION' }, - 'ssh', 'throttle', 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat' ] } + 'ssh', 'throttle', 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat', + { 'name': 'zoned_host_device', 'if': 'CONFIG_BLKZONED' } ] } =20 ## # @BlockdevOptionsFile: @@ -4329,7 +4331,9 @@ 'vhdx': 'BlockdevOptionsGenericFormat', 'vmdk': 'BlockdevOptionsGenericCOWFormat', 'vpc': 'BlockdevOptionsGenericFormat', - 'vvfat': 'BlockdevOptionsVVFAT' + 'vvfat': 'BlockdevOptionsVVFAT', + 'zoned_host_device': { 'type': 'BlockdevOptionsFile', + 'if': 'CONFIG_BLKZONED' } } } =20 ## diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index 952dc940f1..687c3a624c 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -1712,6 +1712,144 @@ static const cmdinfo_t flush_cmd =3D { .oneline =3D "flush all in-core file state to disk", }; =20 +static int zone_report_f(BlockBackend *blk, int argc, char **argv) +{ + int ret; + int64_t offset; + unsigned int nr_zones; + + ++optind; + offset =3D cvtnum(argv[optind]); + ++optind; + nr_zones =3D cvtnum(argv[optind]); + + g_autofree BlockZoneDescriptor *zones =3D NULL; + zones =3D g_new(BlockZoneDescriptor, nr_zones); + ret =3D blk_zone_report(blk, offset, &nr_zones, zones); + if (ret < 0) { + printf("zone report failed: %s\n", strerror(-ret)); + } else { + for (int i =3D 0; i < nr_zones; ++i) { + printf("start: 0x%" PRIx64 ", len 0x%" PRIx64 ", " + "cap"" 0x%" PRIx64 ",wptr 0x%" PRIx64 ", " + "zcond:%u, [type: %u]\n", + zones[i].start, zones[i].length, zones[i].cap, zones[i]= .wp, + zones[i].cond, zones[i].type); + } + } + return ret; +} + +static const cmdinfo_t zone_report_cmd =3D { + .name =3D "zone_report", + .altname =3D "zrp", + .cfunc =3D zone_report_f, + .argmin =3D 2, + .argmax =3D 2, + .args =3D "offset number", + .oneline =3D "report zone information", +}; + +static int zone_open_f(BlockBackend *blk, int argc, char **argv) +{ + int ret; + int64_t offset, len; + ++optind; + offset =3D cvtnum(argv[optind]); + ++optind; + len =3D cvtnum(argv[optind]); + ret =3D blk_zone_mgmt(blk, BLK_ZO_OPEN, offset, len); + if (ret < 0) { + printf("zone open failed: %s\n", strerror(-ret)); + } + return ret; +} + +static const cmdinfo_t zone_open_cmd =3D { + .name =3D "zone_open", + .altname =3D "zo", + .cfunc =3D zone_open_f, + .argmin =3D 2, + .argmax =3D 2, + .args =3D "offset len", + .oneline =3D "explicit open a range of zones in zone block device", +}; + +static int zone_close_f(BlockBackend *blk, int argc, char **argv) +{ + int ret; + int64_t offset, len; + ++optind; + offset =3D cvtnum(argv[optind]); + ++optind; + len =3D cvtnum(argv[optind]); + ret =3D blk_zone_mgmt(blk, BLK_ZO_CLOSE, offset, len); + if (ret < 0) { + printf("zone close failed: %s\n", strerror(-ret)); + } + return ret; +} + +static const cmdinfo_t zone_close_cmd =3D { + .name =3D "zone_close", + .altname =3D "zc", + .cfunc =3D zone_close_f, + .argmin =3D 2, + .argmax =3D 2, + .args =3D "offset len", + .oneline =3D "close a range of zones in zone block device", +}; + +static int zone_finish_f(BlockBackend *blk, int argc, char **argv) +{ + int ret; + int64_t offset, len; + ++optind; + offset =3D cvtnum(argv[optind]); + ++optind; + len =3D cvtnum(argv[optind]); + ret =3D blk_zone_mgmt(blk, BLK_ZO_FINISH, offset, len); + if (ret < 0) { + printf("zone finish failed: %s\n", strerror(-ret)); + } + return ret; +} + +static const cmdinfo_t zone_finish_cmd =3D { + .name =3D "zone_finish", + .altname =3D "zf", + .cfunc =3D zone_finish_f, + .argmin =3D 2, + .argmax =3D 2, + .args =3D "offset len", + .oneline =3D "finish a range of zones in zone block device", +}; + +static int zone_reset_f(BlockBackend *blk, int argc, char **argv) +{ + int ret; + int64_t offset, len; + ++optind; + offset =3D cvtnum(argv[optind]); + ++optind; + len =3D cvtnum(argv[optind]); + ret =3D blk_zone_mgmt(blk, BLK_ZO_RESET, offset, len); + if (ret < 0) { + printf("zone reset failed: %s\n", strerror(-ret)); + } + return ret; +} + +static const cmdinfo_t zone_reset_cmd =3D { + .name =3D "zone_reset", + .altname =3D "zrs", + .cfunc =3D zone_reset_f, + .argmin =3D 2, + .argmax =3D 2, + .args =3D "offset len", + .oneline =3D "reset a zone write pointer in zone block device", +}; + static int truncate_f(BlockBackend *blk, int argc, char **argv); static const cmdinfo_t truncate_cmd =3D { .name =3D "truncate", @@ -2504,6 +2642,11 @@ static void __attribute((constructor)) init_qemuio_c= ommands(void) qemuio_add_command(&aio_write_cmd); qemuio_add_command(&aio_flush_cmd); qemuio_add_command(&flush_cmd); + qemuio_add_command(&zone_report_cmd); + qemuio_add_command(&zone_open_cmd); + qemuio_add_command(&zone_close_cmd); + qemuio_add_command(&zone_finish_cmd); + qemuio_add_command(&zone_reset_cmd); qemuio_add_command(&truncate_cmd); qemuio_add_command(&length_cmd); qemuio_add_command(&info_cmd); --=20 2.37.1 From nobody Thu May 9 00:06:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1660632097; cv=none; d=zohomail.com; s=zohoarc; b=BKv4DF5Oi3sTul62eDPwj7p/wp2Okytk5uYC54wPz46dI5Ly7IqBHGrFFb7T81Tpsiu33btuRHHolDFLyMbxpIDBUOS9kSmczGH7K73WvVWhHhG2WxLIRaD+y513YUCf2fO5x5DlXoF5OQDP0DOUJZnGfQHsTUw2cH+lgXeXnyg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660632097; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WgTioHR22IT5Y1Gxy5Cwuruw+nplwJ4ECOjTCIRKC8o=; b=fWoVRx+cc6Dw6RpigkJDOVJn4meeSrFg6H4X4SlolK2NkQZ3tMMnLiKXc6OHzaRw87yYuk1UfpzguKwv15FDzlc0piWUyWXoUs+vlFsAB+zFKSydM2lzlB+2jyAw3EJx8lWXkqtzzKwnUffVfBWJjhQhP/6RVGVYay+/h6p1mUA= 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 1660632097747658.4432730420866; Mon, 15 Aug 2022 23:41:37 -0700 (PDT) Received: from localhost ([::1]:45740 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oNqGe-00087Q-LD for importer@patchew.org; Tue, 16 Aug 2022 02:41:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60538) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oNq1O-0005vH-AM; Tue, 16 Aug 2022 02:25:50 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]:41664) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oNq1M-0003aC-R1; Tue, 16 Aug 2022 02:25:50 -0400 Received: by mail-pl1-x632.google.com with SMTP id p18so8338113plr.8; Mon, 15 Aug 2022 23:25:48 -0700 (PDT) Received: from roots.. ([106.84.129.185]) by smtp.gmail.com with ESMTPSA id e15-20020a170902784f00b0016f1c1f50f4sm8082868pln.235.2022.08.15.23.25.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Aug 2022 23:25:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=WgTioHR22IT5Y1Gxy5Cwuruw+nplwJ4ECOjTCIRKC8o=; b=QfLlPzxVqd1bqi9080PlqcbKSukQuLrWPRvvBNjkGdjiBbNAyeeUl/bhleyASaVo4+ lRZEUTWNhF8uShqI9w6bJdXopu823MRIbCR3n3jG92AYv+9wO1FchKGH7YHuw6YOuD4q 0LOnxlzbdIlCgh6GW8N9g8cOiCyT/Nz5hdxFOl4e2Y/vd2YjJvsVQRb3Gf6JbMP4ODRD QU8uOVJUAWBTUTBcIDjwyLEF4lpR98iVfczohhSdqqvW8IYTtTulO5y9va8t+bVikTI3 B4ljaI9WdZSwE4956TGbWBVyTNEalGJr7H8kIDUurVLJiWo4/IsATBMbItNuJEhTD541 oTxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=WgTioHR22IT5Y1Gxy5Cwuruw+nplwJ4ECOjTCIRKC8o=; b=7LcuOZZHPks1wZ+GP3eohe7/gcBcYbV3N63ZSAzQrvvwsKwi1iX+lUomZh4NBkQxNw IJ8o8chEuqANMksuaFAUWIQ9bRw/cuOqqBiUD+cgCl2MB2Uw/a4ue1xq52rlOk1xDgK8 FkijGtQNr1idy5QZSJHi3ZUObgy2sIFrW8bQwDS9S1rQCrNogV0qg8odCSgTNkYB2ejf FpOXz2+LyE3yDyxcQaYz5P+/W/g5MKH+6XJE1zD7culCkZXysN+VnyH4AOseBDgRHdg8 Z9NK52OUtUbZ5KPQx/8DATD0A6cC/Pxe+lS+UYlWoqbNrLQMbQO4VVKSYd0/bCZEF9qC jF7g== X-Gm-Message-State: ACgBeo3iAUZ/AQIyqQnjkpbgvkW+TIDFPs3DTdxZaGPBg/kPaYw7NUfp yT/Hcf5f1HaysfX7ZPJWF/udp2AOciIaXw== X-Google-Smtp-Source: AA6agR76SCQCPbZ3ex2gSY4qP8N213Q7VdA56JoKkYzmUEr/JCvTjIdEvErgp+eE8M85094wSzNCTw== X-Received: by 2002:a17:90b:3502:b0:1f3:550:5f6f with SMTP id ls2-20020a17090b350200b001f305505f6fmr22422513pjb.49.1660631147149; Mon, 15 Aug 2022 23:25:47 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: hare@suse.de, Fam Zheng , Kevin Wolf , Eric Blake , Markus Armbruster , stefanha@redhat.com, Hanna Reitz , dmitry.fomichev@wdc.com, qemu-block@nongnu.org, damien.lemoal@opensource.wdc.com, Sam Li Subject: [PATCH v7 5/8] raw-format: add zone operations to pass through requests Date: Tue, 16 Aug 2022 14:25:19 +0800 Message-Id: <20220816062522.85714-6-faithilikerun@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220816062522.85714-1-faithilikerun@gmail.com> References: <20220816062522.85714-1-faithilikerun@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=faithilikerun@gmail.com; helo=mail-pl1-x632.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1660632098893100003 Content-Type: text/plain; charset="utf-8" raw-format driver usually sits on top of file-posix driver. It needs to pass through requests of zone commands. Signed-off-by: Sam Li Reviewed-by: Stefan Hajnoczi --- block/raw-format.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/block/raw-format.c b/block/raw-format.c index 69fd650eaf..6b20bd22ef 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -314,6 +314,17 @@ static int coroutine_fn raw_co_pdiscard(BlockDriverSta= te *bs, return bdrv_co_pdiscard(bs->file, offset, bytes); } =20 +static int coroutine_fn raw_co_zone_report(BlockDriverState *bs, int64_t o= ffset, + unsigned int *nr_zones, + BlockZoneDescriptor *zones) { + return bdrv_co_zone_report(bs->file->bs, offset, nr_zones, zones); +} + +static int coroutine_fn raw_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp= op, + int64_t offset, int64_t len) { + return bdrv_co_zone_mgmt(bs->file->bs, op, offset, len); +} + static int64_t raw_getlength(BlockDriverState *bs) { int64_t len; @@ -614,6 +625,8 @@ BlockDriver bdrv_raw =3D { .bdrv_co_pwritev =3D &raw_co_pwritev, .bdrv_co_pwrite_zeroes =3D &raw_co_pwrite_zeroes, .bdrv_co_pdiscard =3D &raw_co_pdiscard, + .bdrv_co_zone_report =3D &raw_co_zone_report, + .bdrv_co_zone_mgmt =3D &raw_co_zone_mgmt, .bdrv_co_block_status =3D &raw_co_block_status, .bdrv_co_copy_range_from =3D &raw_co_copy_range_from, .bdrv_co_copy_range_to =3D &raw_co_copy_range_to, --=20 2.37.1 From nobody Thu May 9 00:06:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1660631518; cv=none; d=zohomail.com; s=zohoarc; b=ARVFGsSuX9ULkxKjc+dYmbhhQg91+aBRdhpnMENX/A0nisiNxmfp8XiL81KtAb9tZ8KHZT6yPamZNEFTf2+lReCvR7FFOynvKYAvrfIT8E11zCjN3Rp2rzb0j2H/iVJEt1kzoYivg9SK9Js3QcEmA4Q5vSpPHIuUya9oNnSWdu0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660631518; 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=yMqYS1x2K+YOxm8GuxGhnoarBMz1ltJDvihoD3vL5Bo=; b=kFMW4THsDENHwuSW99JsNE4ONvAPPB0QdRsBTLfFfeJ5mql693gdwB13zm2ccyjRxmT1CtTevb7R8OhoKXZ8E7VjtJCP9fXpr9NzBMJB++EpCoTlAFv2howeU8NRIe1rswIiU5UIYI2kLvsNFmPlzFl81HMKvtY04peIoqj82ns= 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 1660631518745374.56675440618426; Mon, 15 Aug 2022 23:31:58 -0700 (PDT) Received: from localhost ([::1]:56562 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oNq7J-0000ow-Ia for importer@patchew.org; Tue, 16 Aug 2022 02:31:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60554) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oNq1R-00064f-QS; Tue, 16 Aug 2022 02:25:53 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]:46735) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oNq1Q-0003ap-8Q; Tue, 16 Aug 2022 02:25:53 -0400 Received: by mail-pl1-x62c.google.com with SMTP id jm11so6118530plb.13; Mon, 15 Aug 2022 23:25:51 -0700 (PDT) Received: from roots.. ([106.84.129.185]) by smtp.gmail.com with ESMTPSA id e15-20020a170902784f00b0016f1c1f50f4sm8082868pln.235.2022.08.15.23.25.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Aug 2022 23:25:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=yMqYS1x2K+YOxm8GuxGhnoarBMz1ltJDvihoD3vL5Bo=; b=qdPLK86+huZpooMmnOdh/EXw/m/iM4c/f0FhBr5r/CNDx8zoJ/mJXQw8Yp2EPkjwsn oG+Pdjv6OAZyy8iYzr8LHaTnIFfTgeSmQ0N9atnG9AFGhu84JKG9dCq6MtPC1AlxmZV8 DX1p7xJhkUKHruLpv+XxzVKHeLp4e5Wta7hwi+vaQIr5rtRICBN5QXbxepuZWHvfJAIU LjJyL5dkGVybJ9f2tU8wDjNBrpk816m2a/W34KMTEwu8GEmGkJvA9SIBqnZUXax814T5 w2dWP3MeeO4l63Us/7MLYnWjdKZWrsqEMwUr9LLDZNC7ZwPxAX39msMLORrIEBGXXMjC GzNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=yMqYS1x2K+YOxm8GuxGhnoarBMz1ltJDvihoD3vL5Bo=; b=WhOXaRrCYxKMa73uYZ/W1wmm9QlAZ/cTb2Sude7AVGdysF4+dGQgM5jMei3if02Wma YaIWOdegabrZboi1dtYtmVQmHvUeFDh9/4hwOakoEXeloKOg9jgQK4rlU+L1DEozxQuE /akRXEFA0pDGd14XdzZ9Y1mtmlRaOdd3MaR73gZoz+iKwSNjWwdP5Q6JSPMe3Ctc0unf 4SRrfFp2Fp9M7hLSkvRjI8lpqbn+67SePcynw0NxP26N9343rWnZprEY00c2lWLQlN3Q cAY7YdYi7s51zwSs5NS//l5egPjKA2LDbW7mg94wANwZeaobBcGSpLQkSOwKs9VpnO5J 3f3w== X-Gm-Message-State: ACgBeo38PsgLdymRI8qoHidpohcZ83oOkDdSIaEx9H8y79wRiE16OqOW BXOdBPsbNbKsk4gQqeO5m48RRoWFJoqwQQ== X-Google-Smtp-Source: AA6agR4g9aw6McAT7dxJUf2xLrPZePW3E/jyydl9L4EjrhcHSIS9CjRP04SFxt5p0rd+cxzONVF6bQ== X-Received: by 2002:a17:90b:4c89:b0:1f5:3aee:79d1 with SMTP id my9-20020a17090b4c8900b001f53aee79d1mr31709685pjb.195.1660631150481; Mon, 15 Aug 2022 23:25:50 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: hare@suse.de, Fam Zheng , Kevin Wolf , Eric Blake , Markus Armbruster , stefanha@redhat.com, Hanna Reitz , dmitry.fomichev@wdc.com, qemu-block@nongnu.org, damien.lemoal@opensource.wdc.com, Sam Li Subject: [PATCH v7 6/8] config: add check to block layer Date: Tue, 16 Aug 2022 14:25:20 +0800 Message-Id: <20220816062522.85714-7-faithilikerun@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220816062522.85714-1-faithilikerun@gmail.com> References: <20220816062522.85714-1-faithilikerun@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=faithilikerun@gmail.com; helo=mail-pl1-x62c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1660631520095100003 Content-Type: text/plain; charset="utf-8" Putting zoned/non-zoned BlockDrivers on top of each other is not allowed. Signed-off-by: Sam Li Reviewed-by: Stefan Hajnoczi --- block.c | 14 ++++++++++++++ block/raw-format.c | 1 + include/block/block_int-common.h | 5 +++++ 3 files changed, 20 insertions(+) diff --git a/block.c b/block.c index bc85f46eed..affe6c597e 100644 --- a/block.c +++ b/block.c @@ -7947,6 +7947,20 @@ 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 BLK_Z_HM) { + 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/raw-format.c b/block/raw-format.c index 6b20bd22ef..9441536819 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -614,6 +614,7 @@ static void raw_child_perm(BlockDriverState *bs, BdrvCh= ild *c, BlockDriver bdrv_raw =3D { .format_name =3D "raw", .instance_size =3D sizeof(BDRVRawState), + .supports_zoned_children =3D true, .bdrv_probe =3D &raw_probe, .bdrv_reopen_prepare =3D &raw_reopen_prepare, .bdrv_reopen_commit =3D &raw_reopen_commit, diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index de44c7b6f4..4c44592b59 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -126,6 +126,11 @@ struct BlockDriver { */ bool is_format; =20 + /* + * Set to true if the BlockDriver supports zoned children. + */ + bool supports_zoned_children; + /* * Drivers not implementing bdrv_parse_filename nor bdrv_open should h= ave * this field set to true, except ones that are defined only by their --=20 2.37.1 From nobody Thu May 9 00:06:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1660632078; cv=none; d=zohomail.com; s=zohoarc; b=EdwCwgtKVN8QHvPCb2KFkVeU3WuSFLgh7X0+RuZS5BNT729Z0GkUNniOPKs7dWZLdyzPIgmb/5xJAdNZzVK+8n2OQ7lJI6/EqKTqIeyIzycRi55MiBWD1txvk5YmzHR1If5BUl2C6luTvXglV+w6jrwJuvEI9rpw7eCAeqcEy1o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660632078; 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=HkCINVDbvDchmHTdjxm4Q8iHfT9y8wRtOSDQPuoOMZU=; b=VIaSA1Mw+s9357fMwr1s4EdpXaKH0pOYx7T9h66RxYO7TSaU5FI0iuZ3cC5elrbUud3EBecfNN8bAmFICw3yBLoW/yfTQYxrgftzKBa+s5t3ttAOrNn//ykPzFEbhLYbTe+zvVwhLOMP8/rOIJQIqSfZ2MXzQONyTZUu5ZwM3Wo= 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 1660632078993953.8257369518614; Mon, 15 Aug 2022 23:41:18 -0700 (PDT) Received: from localhost ([::1]:46802 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oNqGL-0007SU-SU for importer@patchew.org; Tue, 16 Aug 2022 02:41:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60574) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oNq1W-0006CJ-OX; Tue, 16 Aug 2022 02:25:58 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]:45730) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oNq1T-0003c9-UW; Tue, 16 Aug 2022 02:25:58 -0400 Received: by mail-pf1-x430.google.com with SMTP id z187so8522718pfb.12; Mon, 15 Aug 2022 23:25:55 -0700 (PDT) Received: from roots.. ([106.84.129.185]) by smtp.gmail.com with ESMTPSA id e15-20020a170902784f00b0016f1c1f50f4sm8082868pln.235.2022.08.15.23.25.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Aug 2022 23:25:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=HkCINVDbvDchmHTdjxm4Q8iHfT9y8wRtOSDQPuoOMZU=; b=d8fhH26L6gw+vwFZE3WMxeEYPjOzFBcOjANvEygUAW1RMqc4PKecoyv4brifkFhfiF rTf23+HtDuSYwjgsiQEeeKxCR5h6idBVVMHpnqLmxQaJfJ/LYEXi+JDWt9GHCRXlNvrO k3yPEbG1IlCJhis2TaodSoig8YdfysuYl67x4I7PKkh6TmfcEoLgYFQrQIQzqcDO1g7Q 4W/El6lxEsgY6gJaszcWVRjZNYhgxazVBE0oq+Ixw8UUUA1Hqua+HO4YWIA9B5FSdNA+ FosM3UaDnnSMhfrwGR6ABZA515c06cNxxmL+mt6lOaoW0PgP1JZ9mXpH7ButLviEiOox gHIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=HkCINVDbvDchmHTdjxm4Q8iHfT9y8wRtOSDQPuoOMZU=; b=PX3/QeDmFlb6cM140gY7q2inQUE2/62Gj/odezBcCN9xOah+Yket97r/9gUXkAk9Wc 5ojdtmNfKVfN7ILH7/5WBAvFmGMQM8PPS3iU3OASZHhObNdP5qxq2qmNhBYeLN1iMXAN cFiDp7mhpdX5BSrK8QVry8yy5+OhTwsrUPjeQTdwinuQ8SU492JamSUOlwjIte1iLKiP XY85NZr5hMglT1Wax2TQPPkSxcBN6nxq4/19ok9xjzj5ZSDi6mW4T2kpsHBcPQTHfl4W /V5aZrgF2bmfqXBpPdHvcNPnY2inTZOqqE5hl6pwW7m3VzspzJ9k039YnxaIVI73Gm8T Kxpw== X-Gm-Message-State: ACgBeo13ItsesVAkmVj+rBUm1jjX6Wxr9hcsXiYs3s0G/UPkoeNErzmD 1UjdYPq5/Z6D4bYpRgsgC/4HZE3hiSjscg== X-Google-Smtp-Source: AA6agR6d7vR9pAqFYy4qpA5NYui/QhE8cxEf3A/llq+YLVg1FM8qMg4SqT0C9IZVOlzy5xK3Z1z44g== X-Received: by 2002:a63:ec15:0:b0:41c:2669:1e54 with SMTP id j21-20020a63ec15000000b0041c26691e54mr17176258pgh.253.1660631154083; Mon, 15 Aug 2022 23:25:54 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: hare@suse.de, Fam Zheng , Kevin Wolf , Eric Blake , Markus Armbruster , stefanha@redhat.com, Hanna Reitz , dmitry.fomichev@wdc.com, qemu-block@nongnu.org, damien.lemoal@opensource.wdc.com, Sam Li Subject: [PATCH v7 7/8] qemu-iotests: test new zone operations Date: Tue, 16 Aug 2022 14:25:21 +0800 Message-Id: <20220816062522.85714-8-faithilikerun@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220816062522.85714-1-faithilikerun@gmail.com> References: <20220816062522.85714-1-faithilikerun@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::430; envelope-from=faithilikerun@gmail.com; helo=mail-pf1-x430.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1660632080813100001 Content-Type: text/plain; charset="utf-8" We have added new block layer APIs of zoned block devices. Test it with: Create a null_blk device, run each zone operation on it and see whether reporting right zone information. Signed-off-by: Sam Li Reviewed-by: Stefan Hajnoczi --- tests/qemu-iotests/tests/zoned.out | 53 ++++++++++++++++++ tests/qemu-iotests/tests/zoned.sh | 86 ++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 tests/qemu-iotests/tests/zoned.out create mode 100755 tests/qemu-iotests/tests/zoned.sh diff --git a/tests/qemu-iotests/tests/zoned.out b/tests/qemu-iotests/tests/= zoned.out new file mode 100644 index 0000000000..d09be2ffcd --- /dev/null +++ b/tests/qemu-iotests/tests/zoned.out @@ -0,0 +1,53 @@ +QA output created by zoned.sh +Testing a null_blk device: +Simple cases: if the operations work +(1) report the first zone: +start: 0x0, len 0x80000, cap 0x80000,wptr 0x0, zcond:1, [type: 2] + +report the first 10 zones +start: 0x0, len 0x80000, cap 0x80000,wptr 0x0, zcond:1, [type: 2] +start: 0x80000, len 0x80000, cap 0x80000,wptr 0x80000, zcond:1, [type: 2] +start: 0x100000, len 0x80000, cap 0x80000,wptr 0x100000, zcond:1, [type: 2] +start: 0x180000, len 0x80000, cap 0x80000,wptr 0x180000, zcond:1, [type: 2] +start: 0x200000, len 0x80000, cap 0x80000,wptr 0x200000, zcond:1, [type: 2] +start: 0x280000, len 0x80000, cap 0x80000,wptr 0x280000, zcond:1, [type: 2] +start: 0x300000, len 0x80000, cap 0x80000,wptr 0x300000, zcond:1, [type: 2] +start: 0x380000, len 0x80000, cap 0x80000,wptr 0x380000, zcond:1, [type: 2] +start: 0x400000, len 0x80000, cap 0x80000,wptr 0x400000, zcond:1, [type: 2] +start: 0x480000, len 0x80000, cap 0x80000,wptr 0x480000, zcond:1, [type: 2] + +report the last zone: +start: 0x1f380000, len 0x80000, cap 0x80000,wptr 0x1f380000, zcond:1, [typ= e: 2] + + +(2) opening the first zone +report after: +start: 0x0, len 0x80000, cap 0x80000,wptr 0x0, zcond:3, [type: 2] + +opening the second zone +report after: +start: 0x80000, len 0x80000, cap 0x80000,wptr 0x80000, zcond:3, [type: 2] + +opening the last zone +report after: +start: 0x1f380000, len 0x80000, cap 0x80000,wptr 0x1f380000, zcond:3, [typ= e: 2] + + +(3) closing the first zone +report after: +start: 0x0, len 0x80000, cap 0x80000,wptr 0x0, zcond:1, [type: 2] + +closing the last zone +report after: +start: 0x1f380000, len 0x80000, cap 0x80000,wptr 0x1f380000, zcond:1, [typ= e: 2] + + +(4) finishing the second zone +After finishing a zone: +start: 0x80000, len 0x80000, cap 0x80000,wptr 0x100000, zcond:14, [type: 2] + + +(5) resetting the second zone +After resetting a zone: +start: 0x80000, len 0x80000, cap 0x80000,wptr 0x80000, zcond:1, [type: 2] +*** done diff --git a/tests/qemu-iotests/tests/zoned.sh b/tests/qemu-iotests/tests/z= oned.sh new file mode 100755 index 0000000000..d158db09c8 --- /dev/null +++ b/tests/qemu-iotests/tests/zoned.sh @@ -0,0 +1,86 @@ +#!/usr/bin/env bash +# +# Test zone management operations. +# + +seq=3D"$(basename $0)" +echo "QA output created by $seq" +status=3D1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img + sudo rmmod null_blk +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter +. ./common.qemu + +# This test only runs on Linux hosts with raw image files. +_supported_fmt raw +_supported_proto file +_supported_os Linux + +QEMU_IO=3D"build/qemu-io" +IMG=3D"--image-opts -n driver=3Dzoned_host_device,filename=3D/dev/nullb0" +QEMU_IO_OPTIONS=3D$QEMU_IO_OPTIONS_NO_FMT + +echo "Testing a null_blk device:" +echo "Simple cases: if the operations work" +sudo modprobe null_blk nr_devices=3D1 zoned=3D1 + +echo "(1) report the first zone:" +sudo $QEMU_IO $IMG -c "zrp 0 1" +echo +echo "report the first 10 zones" +sudo $QEMU_IO $IMG -c "zrp 0 10" +echo +echo "report the last zone:" +sudo $QEMU_IO $IMG -c "zrp 0x3e70000000 2" +echo +echo +echo "(2) opening the first zone" +sudo $QEMU_IO $IMG -c "zo 0 0x80000" +echo "report after:" +sudo $QEMU_IO $IMG -c "zrp 0 1" +echo +echo "opening the second zone" +sudo $QEMU_IO $IMG -c "zo 524288 0x80000" # 524288 is the zone sector size +echo "report after:" +sudo $QEMU_IO $IMG -c "zrp 268435456 1" # 268435456 / 512 =3D 524288 +echo +echo "opening the last zone" +sudo $QEMU_IO $IMG -c "zo 0x1f380000 0x80000" +echo "report after:" +sudo $QEMU_IO $IMG -c "zrp 0x3e70000000 2" +echo +echo +echo "(3) closing the first zone" +sudo $QEMU_IO $IMG -c "zc 0 0x80000" +echo "report after:" +sudo $QEMU_IO $IMG -c "zrp 0 1" +echo +echo "closing the last zone" +sudo $QEMU_IO $IMG -c "zc 0x1f380000 0x80000" +echo "report after:" +sudo $QEMU_IO $IMG -c "zrp 0x3e70000000 2" +echo +echo +echo "(4) finishing the second zone" +sudo $QEMU_IO $IMG -c "zf 524288 0x80000" +echo "After finishing a zone:" +sudo $QEMU_IO $IMG -c "zrp 268435456 1" +echo +echo + +echo "(5) resetting the second zone" +sudo $QEMU_IO $IMG -c "zrs 524288 0x80000" +echo "After resetting a zone:" +sudo $QEMU_IO $IMG -c "zrp 268435456 1" +# success, all done +echo "*** done" +rm -f $seq.full +status=3D0 --=20 2.37.1 From nobody Thu May 9 00:06:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1660632356; cv=none; d=zohomail.com; s=zohoarc; b=TxfuD4diIwIN3lMRa8s0SduIijT5PMxW5+pKTvtJ4qSDAN2Cot06CjwpoU35xU9FAukFG1h637lHtxoTvkEAXFcasTogfoDpS2aL7Ao4MDeOI/k2RPJygibgG0bn55gfkCw5sORDw8aWO7NcJD3VBLfx532LQAIeAFIykYECo/E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660632356; 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=LR986ojhUARUop8jfo7ruxBtsc8WmLIQeeugiixceKA=; b=b6VyMxPh38AmDF8/MYgpmH7IwmIO1hRPAPxQsNRLbeWljnQy++dwfzN5Axwditm/V/bLG0KbwmDgkwbyJqN2Tvg3LTWUD0AxapPpCZFUZlIqXekWuNxYmVEYIEzL/aFVwUwD5VHivBaHWwL9j/swr//ENJkhyJer1qNynH3LTgo= 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 1660632356513840.1812242712845; Mon, 15 Aug 2022 23:45:56 -0700 (PDT) Received: from localhost ([::1]:41580 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oNqKm-0004Kx-Ss for importer@patchew.org; Tue, 16 Aug 2022 02:45:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60588) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oNq1Z-0006Ez-C9; Tue, 16 Aug 2022 02:26:01 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]:35661) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oNq1X-0003dm-Cr; Tue, 16 Aug 2022 02:26:00 -0400 Received: by mail-pj1-x102e.google.com with SMTP id m10-20020a17090a730a00b001fa986fd8eeso568207pjk.0; Mon, 15 Aug 2022 23:25:58 -0700 (PDT) Received: from roots.. ([106.84.129.185]) by smtp.gmail.com with ESMTPSA id e15-20020a170902784f00b0016f1c1f50f4sm8082868pln.235.2022.08.15.23.25.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Aug 2022 23:25:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=LR986ojhUARUop8jfo7ruxBtsc8WmLIQeeugiixceKA=; b=Lmzd/m9abN23+bEg6o2tXMtbX4nEkWIG/0WVIv+9kvwz5QeWSDPvexT29XV9wDrmru yQSXX7MvLtuWfbCkUlKV8MGs5WRAORL7FpoFB2QFlgRlU/dDkLRvgqzB5GACA45+H/hW AndjRGZr4jJh2p9Olz4d0gS1cr7H+5aRXhjCPBR2tTC7ea/jJFyslnscrobWToQlGh3f ltkFK2ej0M+SC9wqfaZ/YGUbIDTK5iwN6WVOnJji1gOomT9nisuSZ+f7/IygMAe000JP 7NpVGaKT559n6D/emFvPzIKLBWk7W6FHSFPjUXFnSQUJQmrKmb9VLxBZM9vzhBqyUa9b vVrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=LR986ojhUARUop8jfo7ruxBtsc8WmLIQeeugiixceKA=; b=U0AaBFnYIw5Ay7BhBGE81TAx8SGsDCx2eiAa1x0tZVM9f0OZmBJ3O++DIUFwpluPE+ +aUe38+F4rbnCHHXyPiYK2fzYRaYaepZX+6lSdxegcqUMR4ntO7DQ4HrfFR0yZoCodNA hFbbVRzyCxOO4BTQhSOFBvDp3mJAB3TqbuAEFm+Ix3wCibuIKfigeurqRZnYuLSS84h0 Gyl3yCafKn3DS87seQ0fNQBF+1/v4MBRULkvHHz3M1xcBs6CPXAO+kUfial/oZegyZaR R2eHx0/5+Aeo4uWvUPZAqgOjXsDG57i4jaxC2FDf1nbLBbjSL0SmWqv7MpxpLSkN+rkx GRYQ== X-Gm-Message-State: ACgBeo2+I2ro7qz1kewNd4+nzqftdDSfUp5dkfnRbQHvK5oEAGRyOsUa Z4iKWtBa7524Cq+ZB+azGaWk/lJkJix/KA== X-Google-Smtp-Source: AA6agR7gffjW5qF/OZRY42jPBYq6Rhrj/bRgYgncSC7ZVd8H1qeIqH6JhbMC+XZOtArVvPVTP1DQ6A== X-Received: by 2002:a17:90b:33cb:b0:1f4:f635:93f8 with SMTP id lk11-20020a17090b33cb00b001f4f63593f8mr32885998pjb.74.1660631157472; Mon, 15 Aug 2022 23:25:57 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: hare@suse.de, Fam Zheng , Kevin Wolf , Eric Blake , Markus Armbruster , stefanha@redhat.com, Hanna Reitz , dmitry.fomichev@wdc.com, qemu-block@nongnu.org, damien.lemoal@opensource.wdc.com, Sam Li Subject: [PATCH v7 8/8] docs/zoned-storage: add zoned device documentation Date: Tue, 16 Aug 2022 14:25:22 +0800 Message-Id: <20220816062522.85714-9-faithilikerun@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220816062522.85714-1-faithilikerun@gmail.com> References: <20220816062522.85714-1-faithilikerun@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=faithilikerun@gmail.com; helo=mail-pj1-x102e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1660632357723100001 Content-Type: text/plain; charset="utf-8" Add the documentation about the zoned device support to virtio-blk emulation. Signed-off-by: Sam Li Reviewed-by: Stefan Hajnoczi --- docs/devel/zoned-storage.rst | 41 ++++++++++++++++++++++++++ docs/system/qemu-block-drivers.rst.inc | 6 ++++ 2 files changed, 47 insertions(+) create mode 100644 docs/devel/zoned-storage.rst diff --git a/docs/devel/zoned-storage.rst b/docs/devel/zoned-storage.rst new file mode 100644 index 0000000000..ead2d149cc --- /dev/null +++ b/docs/devel/zoned-storage.rst @@ -0,0 +1,41 @@ +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +zoned-storage +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Zoned Block Devices (ZBDs) devide the LBA space into block regions called = zones +that are larger than the LBA size. It can only allow sequential writes, wh= ich +reduces write amplification in SSDs, leading to higher throughput and incr= eased +capacity. More details about ZBDs can be found at: + +https://zonedstorage.io/docs/introduction/zoned-storage + +1. Block layer APIs for zoned storage +------------------------------------- +QEMU block layer has three zoned storage model: +- BLK_Z_HM: This model only allows sequential writes access. It supports a= set +of ZBD-specific I/O request that used by the host to manage device zones. +- BLK_Z_HA: It deals with both sequential writes and random writes access. +- BLK_Z_NONE: Regular block devices and drive-managed ZBDs are treated as +non-zoned devices. + +The block device information 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, the command line for zone report testing a null_blk device of +qemu-io-cmds.c is: +$ path/to/qemu-io --image-opts driver=3Dzoned_host_device,filename=3D/dev/= nullb0 -c +"zrp offset nr_zones" diff --git a/docs/system/qemu-block-drivers.rst.inc b/docs/system/qemu-bloc= k-drivers.rst.inc index dfe5d2293d..0b97227fd9 100644 --- a/docs/system/qemu-block-drivers.rst.inc +++ b/docs/system/qemu-block-drivers.rst.inc @@ -430,6 +430,12 @@ Hard disks you may corrupt your host data (use the ``-snapshot`` command line option or modify the device permissions accordingly). =20 +Zoned block devices + Zoned block devices can be passed through to the guest if the emulated s= torage + controller supports zoned storage. Use ``--blockdev zoned_host_device, + node-name=3Ddrive0,filename=3D/dev/nullb0`` to pass through ``/dev/nullb= 0`` + as ``drive0``. + Windows ^^^^^^^ =20 --=20 2.37.1