From nobody Thu May 16 20:08:06 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=1674988235; cv=none; d=zohomail.com; s=zohoarc; b=izd/cASuJuf4WIi3wuJT93FEITp8yXjZxOPjHZAu6wjppHdwxbC7fY1FMURU0RJua2DMC64Q3iazrrQaZuJTMV4JLvcrNacRHBo2G8J/TN7DX/OJOR5mSb7C+J3UrKB91aV/eWF2cy05zYk8vhx3ivpiettH6BUYSdFVo/p3DEo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674988235; 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=YqDn66EjQd4XlWrdM2GVsx0GNeNoXLpdBxKQzaRYzMY=; b=ekYsNhRW0vkhUvUop1gpn3fr7TAHGxZLZIvdfDWn2i8jYMCZXgxo1WkMAKgT8N+20SJl84hfuScieBrKEBpbXiRlu9CT4+t4WcLuR8N9NHBQ3Makv/x/uYFEIVQkzVlOhTEslA79PENUDsYagvVRAE63VrnmW9doUOcm7Uy07x8= 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 1674988235960959.2361984691369; Sun, 29 Jan 2023 02:30:35 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pM4wE-0005Ji-Le; Sun, 29 Jan 2023 05:29:30 -0500 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 1pM4vv-0005Hc-Ue; Sun, 29 Jan 2023 05:29:17 -0500 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pM4vu-0007Ag-8Y; Sun, 29 Jan 2023 05:29:11 -0500 Received: by mail-pl1-x635.google.com with SMTP id be8so8892301plb.7; Sun, 29 Jan 2023 02:29:09 -0800 (PST) Received: from fedlinux.. ([106.84.129.237]) by smtp.gmail.com with ESMTPSA id jl1-20020a170903134100b0019644d4242dsm5439416plb.82.2023.01.29.02.29.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Jan 2023 02:29:06 -0800 (PST) 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:subject:date :message-id:reply-to; bh=YqDn66EjQd4XlWrdM2GVsx0GNeNoXLpdBxKQzaRYzMY=; b=cn4fM91MTDXWKoft/t+y0OnX3dclfSljTqcR2zTqe/ApFN6/lFcna/nBYvZjavIlxI +0P5t8EUdeH4HbTPY2xuuuFVdATV//TwjVO1GCoClE2kDWav8i/8oEPgoWTWiiHrY0lY wcCbSxqu+PeuYop3j8Su58+d5RfwfyHicns6H1QKaiyKU02I3bsi1NsuBKyVGerx7CIm 4il/C9fdgzdk3Fm7cb9F2pKA0Jcmuoptoc7267o6EF9p+pObBw5FyhYcF7bocozUjrjs s3yrcKrY2xL3pccIh4Q7wm2iu1qgbqZMgN/G3RA3b3GliyRNF5syU9zrvoTCTYlLCY9o PL7g== 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 :subject:date:message-id:reply-to; bh=YqDn66EjQd4XlWrdM2GVsx0GNeNoXLpdBxKQzaRYzMY=; b=tHTsF1qcjtYEHZwqUVG7tPZUrcwzQLMvdy3//bcjXA6iQUkj1Z6Rs4EZ6gfXn2FT7x uINKylmw/vbo0lt8mcb7zPwHBRLOaFC27UO04uodfkO0YASLak5FK8TX+yLQf92Q4svu eHle3AFtaeeI011ZIC9cvjUuWO/2Kcjs3mTSv+nEBU4vvfdO8KgWY610/pyFHI1KAS+1 oo/cvr5bvvieZgXtSL0uesuWj9HaxHnU/lAHS1g7768m52WGRGTGBub+CuRVuN38pity 7Vl0P7q3o31NJJabLOeha5TG+s/FHnArA8mJe9AEKpskqtJuX0q+9uQ8uzDau8MVG8Ej AO5Q== X-Gm-Message-State: AFqh2kpOLOorBo1fOX5DYw0CE2VYcgMiReQ7oIN3ONH7mvF4x8G7i4qB Cz7MRVMQ3Oerdq7YC91TzSgQGExBF4kLXgxFiTU= X-Google-Smtp-Source: AMrXdXsDz7mwfotFfuAMF1mM4Scdh29BPdGT+nSLTvg2m+Hzk7k7K6r3dDDKKN2QrBhkVfGCfKeTPQ== X-Received: by 2002:a05:6a20:4295:b0:b8:9c66:cd64 with SMTP id o21-20020a056a20429500b000b89c66cd64mr60701740pzj.14.1674988147442; Sun, 29 Jan 2023 02:29:07 -0800 (PST) From: Sam Li To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Stefan Hajnoczi , Kevin Wolf , Paolo Bonzini , Hanna Reitz , dmitry.fomichev@wdc.com, hare@suse.de, damien.lemoal@opensource.wdc.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Fam Zheng , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sam Li Subject: [PATCH v15 1/8] include: add zoned device structs Date: Sun, 29 Jan 2023 18:28:43 +0800 Message-Id: <20230129102850.84731-2-faithilikerun@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230129102850.84731-1-faithilikerun@gmail.com> References: <20230129102850.84731-1-faithilikerun@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=faithilikerun@gmail.com; helo=mail-pl1-x635.google.com X-Spam_score_int: -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 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 @gmail.com) X-ZM-MESSAGEID: 1674988236849100005 Content-Type: text/plain; charset="utf-8" Signed-off-by: Sam Li Reviewed-by: Stefan Hajnoczi Reviewed-by: Damien Le Moal Reviewed-by: Hannes Reinecke --- 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 41686810de..211fbc0847 100644 --- a/include/block/block-common.h +++ b/include/block/block-common.h @@ -58,6 +58,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.38.1 From nobody Thu May 16 20:08:06 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=1674988260; cv=none; d=zohomail.com; s=zohoarc; b=ib5mzcMa5iQASilo105kDu3PPO/ZHTbha9ydLM4i0/DZg3Xg6KZUs7q5TRSfJFlejdhAjbyTD+7JWMH1XYaMtuBxZI4/mWRQ6TtIPaIzx+bQq/LIHgOnCn5SUil3e24nCtMXiZPUTICiz4nwKdHbe5C6q6rshNVuVSsAIRk+q9Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674988260; 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=eQM4NS6srDaBmC6CO8p9fQAiIrm3s/r9yVsLoikHLas=; b=IoIgcDjagaGJEeZUBVw5o04yVl2ASiSvBaic4y6h1hXs1kwYPPDhxXCOnliCUch9socPGBP0ptuKv/4hKZhDn6uPJBgvUioJSQ/3scsG7JC4EiUc2Dlwb0RjpqGYVuMCacujYghCkWxH7lLHeUGXXzXatnuSV2sMP5qt0umNCyA= 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 1674988260560876.0080024886154; Sun, 29 Jan 2023 02:31:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pM4wQ-0005MJ-7O; Sun, 29 Jan 2023 05:29:42 -0500 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 1pM4vz-0005Hm-L2; Sun, 29 Jan 2023 05:29:17 -0500 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pM4vx-0007Ag-Uw; Sun, 29 Jan 2023 05:29:15 -0500 Received: by mail-pl1-x635.google.com with SMTP id be8so8892396plb.7; Sun, 29 Jan 2023 02:29:13 -0800 (PST) Received: from fedlinux.. ([106.84.129.237]) by smtp.gmail.com with ESMTPSA id jl1-20020a170903134100b0019644d4242dsm5439416plb.82.2023.01.29.02.29.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Jan 2023 02:29:11 -0800 (PST) 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:subject:date :message-id:reply-to; bh=eQM4NS6srDaBmC6CO8p9fQAiIrm3s/r9yVsLoikHLas=; b=JaTC1wn8yoVqAmkOo29FNVc59slBjHMZ5fDh7bvdZx4ZIK0WRhIjZVdrcGyZBg5f9t 6JoW5Hlo+imSRGL9/FFR7DTqdLq11QdaI8NXMs68zacQ/W37twAtG2SjOWpAqQOp9Bsy KFpzq1Qd/N+6GX5xs8xYLelujyaxQF2pMIfOJ2Q2zopLZ+ZFYGOXQW1EHyFtrrnzqBZI ZmsTEuYI9iK/2+rvOPIOwxiALgfc1FIR5nYlL4K21phh1zw7SHsVzhvP/OUP4IW0zZk8 OuoqWrk1zRcagordl5+pNP6yRQ4cDPHDzLleo4eqhMYMEkwHbBhMAp5HCMVwaU/Y893g lEIA== 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 :subject:date:message-id:reply-to; bh=eQM4NS6srDaBmC6CO8p9fQAiIrm3s/r9yVsLoikHLas=; b=acA8PgU90febBOPCDA3BtH6cQrRk/xUeCLYxjVDtpWCA+ebOSnwSVitzgqnUBNpfhh OH6OerXn5UKMv7P/Rx9C4+fAhkbOcj5WOKxaR6m9i6gTE5ogP3Axz5IYpkNksi0P3fyB 2VusrLvujGqB2+m8wiaZ31Zq20d9pJxzEZPhmZ/gSYd5hSSjlIVu1hdTR5Jpx3LozKYg 80sFmJVAdY1oahCTyKp/kXquaoKYGsoi4m+/OhGj//FjWFH7zv3/NsYrCmju8liV0WIJ A+hk5eew1891+4+p5v9XSwlm2mFZXSC9zD3tJ36MM59tayJREH2A7t6QtpZjNs85vabl hnXw== X-Gm-Message-State: AFqh2kpskWqR9XkmNnxghodG1hxC/8Ofr3BaGnt55pEtBamB0N3xgBkX uff1kT07tWQBs3u7OgDl3rxwErXBGCKHXymYs98= X-Google-Smtp-Source: AMrXdXvNKA0oygUAs6FcN+qOmLHJHP2jaxLGoWh/VzJSNelYyjNoJ7luPguSz3hOk7Sv4YVTTHb3UA== X-Received: by 2002:a17:902:b092:b0:194:cc66:66f7 with SMTP id p18-20020a170902b09200b00194cc6666f7mr33666860plr.19.1674988152038; Sun, 29 Jan 2023 02:29:12 -0800 (PST) From: Sam Li To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Stefan Hajnoczi , Kevin Wolf , Paolo Bonzini , Hanna Reitz , dmitry.fomichev@wdc.com, hare@suse.de, damien.lemoal@opensource.wdc.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Fam Zheng , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sam Li Subject: [PATCH v15 2/8] file-posix: introduce helper functions for sysfs attributes Date: Sun, 29 Jan 2023 18:28:44 +0800 Message-Id: <20230129102850.84731-3-faithilikerun@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230129102850.84731-1-faithilikerun@gmail.com> References: <20230129102850.84731-1-faithilikerun@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=faithilikerun@gmail.com; helo=mail-pl1-x635.google.com X-Spam_score_int: -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 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 @gmail.com) X-ZM-MESSAGEID: 1674988262705100003 Content-Type: text/plain; charset="utf-8" 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 --- block/file-posix.c | 122 ++++++++++++++++++++++--------- include/block/block_int-common.h | 3 + 2 files changed, 91 insertions(+), 34 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index fa227d9d14..43c59c6d56 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1202,64 +1202,112 @@ static int hdev_get_max_hw_transfer(int fd, struct= stat *st) #endif } =20 -static int hdev_get_max_segments(int fd, struct stat *st) -{ +/* + * Get a sysfs attribute value as character string. + */ +static int get_sysfs_str_val(struct stat *st, const char *attribute, + char **val) { #ifdef CONFIG_LINUX - char buf[32]; - const char *end; - char *sysfspath =3D NULL; + g_autofree char *sysfspath =3D NULL; int ret; - int sysfd =3D -1; - long max_segments; + size_t len; =20 - if (S_ISCHR(st->st_mode)) { - if (ioctl(fd, SG_GET_SG_TABLESIZE, &ret) =3D=3D 0) { - return ret; - } + if (!S_ISBLK(st->st_mode)) { return -ENOTSUP; } =20 - if (!S_ISBLK(st->st_mode)) { - return -ENOTSUP; + sysfspath =3D g_strdup_printf("/sys/dev/block/%u:%u/queue/%s", + major(st->st_rdev), minor(st->st_rdev), + attribute); + ret =3D g_file_get_contents(sysfspath, val, &len, NULL); + if (ret =3D=3D -1) { + return -ENOENT; } =20 - sysfspath =3D g_strdup_printf("/sys/dev/block/%u:%u/queue/max_segments= ", - major(st->st_rdev), minor(st->st_rdev)); - sysfd =3D open(sysfspath, O_RDONLY); - if (sysfd =3D=3D -1) { - ret =3D -errno; - goto out; + /* The file is ended with '\n' */ + char *p; + p =3D *val; + if (*(p + len - 1) =3D=3D '\n') { + *(p + len - 1) =3D '\0'; } - ret =3D RETRY_ON_EINTR(read(sysfd, buf, sizeof(buf) - 1)); + return ret; +#else + return -ENOTSUP; +#endif +} + +static int get_sysfs_zoned_model(struct stat *st, BlockZoneModel *zoned) +{ + g_autofree char *val =3D NULL; + int ret; + + ret =3D get_sysfs_str_val(st, "zoned", &val); if (ret < 0) { - ret =3D -errno; - goto out; - } else if (ret =3D=3D 0) { - ret =3D -EIO; - goto out; + return ret; } - buf[ret] =3D 0; - /* The file is ended with '\n', pass 'end' to accept that. */ - ret =3D qemu_strtol(buf, &end, 10, &max_segments); - if (ret =3D=3D 0 && end && *end =3D=3D '\n') { - ret =3D max_segments; + + if (strcmp(val, "host-managed") =3D=3D 0) { + *zoned =3D BLK_Z_HM; + } else if (strcmp(val, "host-aware") =3D=3D 0) { + *zoned =3D BLK_Z_HA; + } else if (strcmp(val, "none") =3D=3D 0) { + *zoned =3D BLK_Z_NONE; + } else { + return -ENOTSUP; + } + return 0; +} + +/* + * Get a sysfs attribute value as a long integer. + */ +static long get_sysfs_long_val(struct stat *st, const char *attribute) +{ +#ifdef CONFIG_LINUX + g_autofree char *str =3D NULL; + const char *end; + long val; + int ret; + + ret =3D get_sysfs_str_val(st, attribute, &str); + if (ret < 0) { + return ret; } =20 -out: - if (sysfd !=3D -1) { - close(sysfd); + /* The file is ended with '\n', pass 'end' to accept that. */ + ret =3D qemu_strtol(str, &end, 10, &val); + if (ret =3D=3D 0 && end && *end =3D=3D '\0') { + ret =3D val; } - g_free(sysfspath); return ret; #else return -ENOTSUP; #endif } =20 +static int hdev_get_max_segments(int fd, struct stat *st) +{ +#ifdef CONFIG_LINUX + int ret; + + if (S_ISCHR(st->st_mode)) { + if (ioctl(fd, SG_GET_SG_TABLESIZE, &ret) =3D=3D 0) { + return ret; + } + return -ENOTSUP; + } + return get_sysfs_long_val(st, "max_segments"); +#else + return -ENOTSUP; +#endif +} + static void raw_refresh_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); @@ -1297,6 +1345,12 @@ static void raw_refresh_limits(BlockDriverState *bs,= Error **errp) bs->bl.max_hw_iov =3D ret; } } + + ret =3D get_sysfs_zoned_model(&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 887ace7dbd..57f0612f5e 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -836,6 +836,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.38.1 From nobody Thu May 16 20:08:06 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=1674988297; cv=none; d=zohomail.com; s=zohoarc; b=miyvX6GVd7/9OIGo4w7WxkQahZVczcYN6voUwXufW27+ug2csYjATFJyCBjp0wdXUlzW5rgm8cNkKh6MxeqWBr6u5BOZoOAJPfesgji1sI7IhVkFlDP9KgN/7XgJVoh8K7N3ZYNn55TcghP1WcpmEe5M74DpU7hs85JLwph/u1U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674988297; 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=FW2ZGigfmz87PbCTNCe3I+2Ml+9MaoD1lSsLqdLZ5/A=; b=Dntmt9kxfuuFKJWk0vX4iHGw9Hq21JyC8W+HqHJ/cmKkuAGhO60D210bpsi1BRmL2iXkfzr6ZFOVIADQSAXtiaT6A43XQo9kqnC3Z3Wn++Zc8ixgrJTP8wcCmu1nF978W8lx9NzPI5tRqZBzqZfMbXPlIqTHpm4noQLtkQhliZg= 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 1674988297585485.35662209223676; Sun, 29 Jan 2023 02:31:37 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pM4wR-0005MS-0p; Sun, 29 Jan 2023 05:29:43 -0500 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 1pM4w7-0005JB-WF; Sun, 29 Jan 2023 05:29:28 -0500 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pM4w4-0007Bc-Qx; Sun, 29 Jan 2023 05:29:23 -0500 Received: by mail-pj1-x102b.google.com with SMTP id w6-20020a17090ac98600b0022c58cc7a18so4089697pjt.1; Sun, 29 Jan 2023 02:29:19 -0800 (PST) Received: from fedlinux.. ([106.84.129.237]) by smtp.gmail.com with ESMTPSA id jl1-20020a170903134100b0019644d4242dsm5439416plb.82.2023.01.29.02.29.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Jan 2023 02:29:16 -0800 (PST) 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:subject:date :message-id:reply-to; bh=FW2ZGigfmz87PbCTNCe3I+2Ml+9MaoD1lSsLqdLZ5/A=; b=F3v3fFboCk8jJI2Scldu+SbDHBtmb4771dyGg4b/CpKFbr2s9l1NehgJsG5g9ZPcNo +6LiBfLlrGa+zapMgTEsdVwdKTDFyOoH3/NCur3W+sJcaQHSER+18lkbAybPMDlqHE2u r+7zwT9+TphGaF/lfFMQhISQRSGrktpNlSZ+tbAzEIcWXNOsgmxv2yuNZYzAvm6Q6oKO 68IHJBs20UXdr0GHUt87Fok7JMPl272NNDFSJXBEnUrnvnCtMZIYxozUCL3KpmUshLk8 EoEUS2dl7TjHEY6/z1dAJawDj8jX3P/P4V+E5LmTi16Uz55Tz9ayyUqmGcFtMANHhGPK VqMQ== 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 :subject:date:message-id:reply-to; bh=FW2ZGigfmz87PbCTNCe3I+2Ml+9MaoD1lSsLqdLZ5/A=; b=X8qCevutdFGBJMEHGllD3rAWrhXBKo46eopUYS6zZxbS78UUX1ZCTnSGGxNzkp0G8G ZSHeO1P+PeT+/G6VbpxsVa1iJ/AZQFyJPGju1jXNttL+8TA2aRX5GJgIdxUMFecLSbI3 ++gJu4AIfGQL5Do+4xiuJ60Lc1ExvjJLfzsita1/uA3LH8uf++zSfKsBxFTIubHi5BFP vq4l8d+zi/bFq48JkmdoBSihgUQKycTY+ssm6I8ewHfSNQz3SRbeR4sSCmKrbNcYgznC NEEQeOmahObr+OvFPPbIC+xfu33GeUvhAQOBdKYewyPMjJhd8Okq3x2BZJp6R9pBrHsU FTBg== X-Gm-Message-State: AO0yUKXQd/CxjEabd+QNqGRV+c9OBCmeHbkFIY700OwmAXVpI+Te9EhE wnBAO6YgpsvJ+XXtgcbatqhc8LuGiS6mWE6DjV0= X-Google-Smtp-Source: AK7set9pzm/A8UJbmBwUfv24m75esiROU7srNUTk+Nxl59p+amRiOFy2s66BUXZgacG3nk5BI6Zmqg== X-Received: by 2002:a17:902:da91:b0:196:7664:39c with SMTP id j17-20020a170902da9100b001967664039cmr3133631plx.31.1674988157132; Sun, 29 Jan 2023 02:29:17 -0800 (PST) From: Sam Li To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Stefan Hajnoczi , Kevin Wolf , Paolo Bonzini , Hanna Reitz , dmitry.fomichev@wdc.com, hare@suse.de, damien.lemoal@opensource.wdc.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Fam Zheng , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sam Li Subject: [PATCH v15 3/8] block: add block layer APIs resembling Linux ZonedBlockDevice ioctls Date: Sun, 29 Jan 2023 18:28:45 +0800 Message-Id: <20230129102850.84731-4-faithilikerun@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230129102850.84731-1-faithilikerun@gmail.com> References: <20230129102850.84731-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::102b; envelope-from=faithilikerun@gmail.com; helo=mail-pj1-x102b.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 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 @gmail.com) X-ZM-MESSAGEID: 1674988298855100003 Content-Type: text/plain; charset="utf-8" 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 Acked-by: Kevin Wolf --- block/block-backend.c | 147 ++++++++++++++ block/file-posix.c | 323 ++++++++++++++++++++++++++++++ block/io.c | 41 ++++ include/block/block-io.h | 7 + include/block/block_int-common.h | 21 ++ include/block/raw-aio.h | 6 +- include/sysemu/block-backend-io.h | 18 ++ meson.build | 4 + qemu-io-cmds.c | 149 ++++++++++++++ 9 files changed, 715 insertions(+), 1 deletion(-) diff --git a/block/block-backend.c b/block/block-backend.c index ba7bf1d6bc..a4847b9131 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1451,6 +1451,15 @@ typedef struct BlkRwCo { void *iobuf; int ret; BdrvRequestFlags flags; + union { + struct { + unsigned int *nr_zones; + BlockZoneDescriptor *zones; + } zone_report; + struct { + unsigned long op; + } zone_mgmt; + }; } BlkRwCo; =20 int blk_make_zero(BlockBackend *blk, BdrvRequestFlags flags) @@ -1795,6 +1804,144 @@ 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, + rwco->zone_report.nr_zones, + rwco->zone_report.zones); + 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, + .ret =3D NOT_DONE, + .zone_report =3D { + .zones =3D zones, + .nr_zones =3D nr_zones, + }, + }; + acb->has_returned =3D false; + + co =3D qemu_coroutine_create(blk_aio_zone_report_entry, acb); + bdrv_coroutine_enter(blk_bs(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, rwco->zone_mgmt.op, + 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, + .ret =3D NOT_DONE, + .zone_mgmt =3D { + .op =3D op, + }, + }; + acb->bytes =3D len; + acb->has_returned =3D false; + + co =3D qemu_coroutine_create(blk_aio_zone_mgmt_entry, acb); + bdrv_coroutine_enter(blk_bs(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); + 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); + + 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 43c59c6d56..b6d88db208 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 @@ -1351,6 +1361,50 @@ static void raw_refresh_limits(BlockDriverState *bs,= Error **errp) zoned =3D BLK_Z_NONE; } bs->bl.zoned =3D zoned; + if (zoned !=3D BLK_Z_NONE) { + /* + * The zoned device must at least have zone size and nr_zones fiel= ds. + */ + ret =3D get_sysfs_long_val(&st, "chunk_sectors"); + if (ret < 0) { + error_setg_errno(errp, -ret, "Unable to read chunk_sectors " + "sysfs attribute"); + goto out; + } else if (!ret) { + error_setg(errp, "Read 0 from chunk_sectors sysfs attribute"); + goto out; + } + 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"); + goto out; + } else if (!ret) { + error_setg(errp, "Read 0 from nr_zones sysfs attribute"); + goto out; + } + 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; + } + + 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; + } + return; + } +out: + bs->bl.zoned =3D BLK_Z_NONE; } =20 static int check_for_dasd(int fd) @@ -1364,6 +1418,23 @@ static int check_for_dasd(int fd) #endif } =20 +#if defined(CONFIG_BLKZONED) +/** + * Zoned storage needs to be virtualized with the correct physical block s= ize + * and logical block size. + */ +static int hdev_probe_zoned_blocksizes(BlockDriverState *bs, BlockSizes *b= sz) +{ + BDRVRawState *s =3D bs->opaque; + int ret; + + ret =3D probe_logical_blocksize(s->fd, &bsz->log); + if (ret < 0) { + return ret; + } + return probe_physical_blocksize(s->fd, &bsz->phys); +} +#else /** * Try to get @bs's logical and physical block size. * On success, store them in @bsz and return zero. @@ -1384,6 +1455,7 @@ static int hdev_probe_blocksizes(BlockDriverState *bs= , BlockSizes *bsz) } return probe_physical_blocksize(s->fd, &bsz->phys); } +#endif =20 /** * Try to get @bs's geometry: cyls, heads, sectors. @@ -1844,6 +1916,146 @@ 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, 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; @@ -3035,6 +3247,107 @@ 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; + + acb =3D (RawPosixAIOData) { + .bs =3D bs, + .aio_fildes =3D s->fd, + .aio_type =3D QEMU_AIO_ZONE_REPORT, + .aio_offset =3D offset, + .zone_report =3D { + .nr_zones =3D nr_zones, + .zones =3D zones, + }, + }; + + return raw_thread_pool_submit(bs, handle_aiocb_zone_report, &acb); +} +#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(bs, handle_aiocb_zone_mgmt, &acb); + if (ret !=3D 0) { + ret =3D -errno; + 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) @@ -3756,13 +4069,23 @@ static BlockDriver bdrv_host_device =3D { .bdrv_check_perm =3D raw_check_perm, .bdrv_set_perm =3D raw_set_perm, .bdrv_abort_perm_update =3D raw_abort_perm_update, +#ifndef CONFIG_BLKZONED .bdrv_probe_blocksizes =3D hdev_probe_blocksizes, +#endif .bdrv_probe_geometry =3D hdev_probe_geometry, =20 /* generic scsi device */ #ifdef __linux__ .bdrv_co_ioctl =3D hdev_co_ioctl, #endif + + /* zoned device */ +#if defined(CONFIG_BLKZONED) + /* zone management operations */ + .bdrv_probe_blocksizes =3D hdev_probe_zoned_blocksizes, + .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 a09a19f7a7..1586e42ab9 100644 --- a/block/io.c +++ b/block/io.c @@ -3099,6 +3099,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) { + 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) { + co.ret =3D -ENOTSUP; + goto out; + } + co.ret =3D drv->bdrv_co_zone_mgmt(bs, op, offset, len); +out: + bdrv_dec_in_flight(bs); + return co.ret; +} + void *qemu_blockalign(BlockDriverState *bs, size_t size) { IO_CODE(); diff --git a/include/block/block-io.h b/include/block/block-io.h index 3398351596..10ff212036 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -98,6 +98,13 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs); =20 int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes); +/* 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); + 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 57f0612f5e..565228d8dd 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -703,6 +703,12 @@ struct BlockDriver { int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_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 (*bdrv_is_inserted)(BlockDriverState *bs); void (*bdrv_eject)(BlockDriverState *bs, bool eject_flag); @@ -839,6 +845,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 f8cda9df91..eda6a7a253 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 031a27ba10..dc8a4368f0 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); @@ -166,6 +173,17 @@ int co_wrapper_mixed blk_pwrite_zeroes(BlockBackend *b= lk, int64_t offset, int coroutine_fn blk_co_pwrite_zeroes(BlockBackend *blk, int64_t offset, int64_t bytes, BdrvRequestFlags flag= s); =20 +int coroutine_fn blk_co_zone_report(BlockBackend *blk, int64_t offset, + unsigned int *nr_zones, + BlockZoneDescriptor *zones); +int co_wrapper_mixed blk_zone_report(BlockBackend *blk, int64_t offset, + unsigned int *nr_zones, + BlockZoneDescriptor *zones); +int coroutine_fn blk_co_zone_mgmt(BlockBackend *blk, BlockZoneOp op, + int64_t offset, int64_t len); +int co_wrapper_mixed blk_zone_mgmt(BlockBackend *blk, BlockZoneOp op, + int64_t offset, int64_t len); + int co_wrapper_mixed blk_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes); int coroutine_fn blk_co_pdiscard(BlockBackend *blk, int64_t offset, diff --git a/meson.build b/meson.build index 6d3b665629..a267f74536 100644 --- a/meson.build +++ b/meson.build @@ -1962,6 +1962,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')) @@ -2056,6 +2057,9 @@ config_host_data.set('HAVE_SIGEV_NOTIFY_THREAD_ID', config_host_data.set('HAVE_STRUCT_STAT_ST_ATIM', cc.has_member('struct stat', 'st_atim', prefix: '#include ')) +config_host_data.set('HAVE_BLK_ZONE_REP_CAPACITY', + cc.has_member('struct blk_zone', 'capacity', + prefix: '#include ')) =20 # has_type config_host_data.set('CONFIG_IOVEC', diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index 952dc940f1..3a3bad77c3 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -1712,6 +1712,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", @@ -2504,6 +2648,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.38.1 From nobody Thu May 16 20:08:06 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=1674988280; cv=none; d=zohomail.com; s=zohoarc; b=RJ2bQ6EDnI0QRGXK4yniLeaN4Aq0vxwelebcGUIOk0iI3vciY2dz3UP4uhwXpWmMnmYgDEfl+mN1843NJncSsSxYPbbgIAFutNTWyNoIhZhPEzhtpPehA8ovB8yxH1OZ/of/hj/Sg8EG59SVKj5MQlx+Xpq8N4FW+1QptfYMz6w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674988280; 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=B5zy2i6OMLiLxR95p5Lc+yzOP4YWDvHLClp1ZG0GGEk=; b=N2aldjmjqHzT+1fNcVH+WMCg6l5SVEu/9X72YkMhbNFvcmB52WJF5sz9/ae/8WrFi0bo5u5hb5QwkD9WTU4LQFdT1u86TjSQF9HNTVxqDAIuzES3mheXmOOcrYBGSfvbERZX5u6hrGesE0FguycyJeu8qzEuq65q1+HS55Kl7vU= 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 1674988280955847.923592244368; Sun, 29 Jan 2023 02:31:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pM4wS-0005Nq-G0; Sun, 29 Jan 2023 05:29:44 -0500 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 1pM4wD-0005Jg-Au; Sun, 29 Jan 2023 05:29:30 -0500 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pM4w8-0007Bq-27; Sun, 29 Jan 2023 05:29:29 -0500 Received: by mail-pl1-x635.google.com with SMTP id jm10so8867088plb.13; Sun, 29 Jan 2023 02:29:23 -0800 (PST) Received: from fedlinux.. ([106.84.129.237]) by smtp.gmail.com with ESMTPSA id jl1-20020a170903134100b0019644d4242dsm5439416plb.82.2023.01.29.02.29.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Jan 2023 02:29:21 -0800 (PST) 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:subject:date :message-id:reply-to; bh=B5zy2i6OMLiLxR95p5Lc+yzOP4YWDvHLClp1ZG0GGEk=; b=BCpMWMENRvRU7jYNyorQFXQJjJgSSHF0mc3rGE4gpICpKMI2WSndQAe8uvjIo9iGFv nHi41vXT+raZF4yeYrkMl/cOiptQrEhAZvCyJoSdLF/SP5vXn/oY4byWHAcS5sX15P12 tj0vg5JfKy4bsY2q8uM0vqkWfgDXqA/TBtgwPQaQGQFnb/rST9/aFmexyIri3TExTM4D FrAepD2jOUCK+011so+tHJ/CsfrV85AZK5RT3SLEJy7QJP2yxfbrxYoBbCBOjOrP2bZG wvRqJIF+Kd2KuZ0YKczViwK6MyT8vKI5WgDrGU5tH1yZBJMbjKlZhKbFDimq+BgXuxr8 zqxw== 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 :subject:date:message-id:reply-to; bh=B5zy2i6OMLiLxR95p5Lc+yzOP4YWDvHLClp1ZG0GGEk=; b=j+4Pyv9D3rgl2YNSu+loStBak81Qm+iSPn9RW3dY/8yInmVuAS27qidATdTgd+TYHt T5nipUfBgyPQjRALNrsvbHH7VuTKbsdhZVqwEXG7kA99/xOESQuB4GnWEvInvhQw+Z03 UD7ZhZF8c7YcRl3S1niZ9/EGuGP9pbdhMNe2HJDjnLcX5zB6SNIEDHo3pfCodTklyCg5 PljhXjXAaPEtlfV2TFBhse5kbEUvQhyg5tAV2hnmaqBE9izG6Anv6I09+pyGeDipKhBe DddoLq51TY11ideAZcL2LN6OVIxIlYnQDndpGLO7H2dZBPjdquMeDeSrbmQk7pUynRVg QRdA== X-Gm-Message-State: AO0yUKVEfu/Z2rw882vAYw1Wx2l/Y/P0TTwlHeEdsgzHGdLMGllvcGAC 1YBf10xAz0BXXQ0OClJEWssEyeVj4fCx/gqlqQ4= X-Google-Smtp-Source: AK7set9jzR9K1UpPmzLqGlpG/9yoSJGThhJezVG5zHIHjQUNWpYQSXUGiV8HVhetNuCaqIcFe890iQ== X-Received: by 2002:a17:902:e493:b0:192:820d:d1 with SMTP id i19-20020a170902e49300b00192820d00d1mr3639770ple.25.1674988161835; Sun, 29 Jan 2023 02:29:21 -0800 (PST) From: Sam Li To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Stefan Hajnoczi , Kevin Wolf , Paolo Bonzini , Hanna Reitz , dmitry.fomichev@wdc.com, hare@suse.de, damien.lemoal@opensource.wdc.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Fam Zheng , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sam Li Subject: [PATCH v15 4/8] raw-format: add zone operations to pass through requests Date: Sun, 29 Jan 2023 18:28:46 +0800 Message-Id: <20230129102850.84731-5-faithilikerun@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230129102850.84731-1-faithilikerun@gmail.com> References: <20230129102850.84731-1-faithilikerun@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=faithilikerun@gmail.com; helo=mail-pl1-x635.google.com X-Spam_score_int: -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 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 @gmail.com) X-ZM-MESSAGEID: 1674988282740100003 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 Reviewed-by: Damien Le Moal Reviewed-by: Hannes Reinecke Reviewed-by: Dmitry Fomichev --- block/raw-format.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/block/raw-format.c b/block/raw-format.c index b6a0ce58f4..dbbb8f3859 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -317,6 +317,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; @@ -618,6 +629,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.38.1 From nobody Thu May 16 20:08:06 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=1674988292; cv=none; d=zohomail.com; s=zohoarc; b=nWdg4zYxvLYsW7dg5mUITD7EqgfsKaaJXavpq29W9Q10SDFUAPq31P6cIsp9La/pwNyHDO9oklx7WaG6UZDH7/Tre+ueHSlLJxl9xIiKNc4rbUp9GbnUPhal9KuLJV4IRowclIjly8DaZHvgB6Dud5/36RcjsHwWCJLQ4T9DHdk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674988292; 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=7kn/ee/b4uHSDw62GF6lj1ZLODdyoKPhXIYeoKCX5EM=; b=MxnOEjjw4SDrQ2rERYPfNib2+DyFkDzeWtSfUDb5PWg/OQ6Cp+4djUjJ1f5ODGmjVw4NSB2CySc/qzxMMMEk06LWf3v46g6mGupIrS37dRPRswtxZPNsNGmaQpEC7zU8dbzvD3RoODK0/LBMwKj/8mP0jXqYngO27+b7LWtqODQ= 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 1674988292542304.74235928955227; Sun, 29 Jan 2023 02:31:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pM4wT-0005Nx-AS; Sun, 29 Jan 2023 05:29:45 -0500 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 1pM4wE-0005Jz-Lx; Sun, 29 Jan 2023 05:29:30 -0500 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pM4wD-0007C2-20; Sun, 29 Jan 2023 05:29:30 -0500 Received: by mail-pj1-x1036.google.com with SMTP id o13so8658417pjg.2; Sun, 29 Jan 2023 02:29:28 -0800 (PST) Received: from fedlinux.. ([106.84.129.237]) by smtp.gmail.com with ESMTPSA id jl1-20020a170903134100b0019644d4242dsm5439416plb.82.2023.01.29.02.29.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Jan 2023 02:29:26 -0800 (PST) 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:subject:date :message-id:reply-to; bh=7kn/ee/b4uHSDw62GF6lj1ZLODdyoKPhXIYeoKCX5EM=; b=jclzbM+nwHQ15H8xsHycPPwwRdEeWtwk6t9zqEKiOV3cRpRc/1czj4FG/LhZ2W5u6h 0vuCIKbCsGzdztyy13diqUfm2KaluVTbm4s6iaXfKXo2kX0r5Xx7mPFRz6yVM3uLkjnh M0RH7HccSvqPT9sMlCt3K8tSxaVqpiK+Fr1Qk6VbTtJPIvrJWqKUeLsiB7GuUxaP1N5z NXtBJ/DQWNTCL9ZisRO1XKaWH+j+dLpfGwLE4kMTQTe2FBtgJUrn06dA+0tqww+GRxZ0 Di917zBOJg0vKJdeGo1IraeLBUZkQ3FOf6oDxqf3w143+VBGRNfq8se1w2NxEgNmHWE5 comw== 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 :subject:date:message-id:reply-to; bh=7kn/ee/b4uHSDw62GF6lj1ZLODdyoKPhXIYeoKCX5EM=; b=pMT+9tdUWPxy8YiE2HxPt1GbFbYP+z+7o8n9emRycG9Jpemdjrq+fWuaLROhnBfLix yQavhOBo5SSjcHuVdyJaidK23qeuj35XBI+sZs/clHKUOdvtGeYHUP6svm0kp8Sp7KZQ 0kEOC67h5CK22DmMMCuhpPABs5KFtuHIJwMn8sHtpGuQfml9j09YvooHnGYFaEYx9a/H zZH2ETHwjZDwy+OPYmuU8pUhy02nZAkFY55MR6mTafvMtlNWgAZIGbwJQvTwcn49SiI/ PBpV/3djzM6kJvNpf04ch8X1AwYesKydyfqPr91ShPWaye/7J0eGKSE6BGA7n2tC0V3r Dj6w== X-Gm-Message-State: AFqh2kqA+sggsBHtwDhP5ehN1ss7sxlfreLLXRkBVrBcelGb8Mgu+xhi V+LPcVVSGy1h1GTn5zK8azKKhSLaeccV8hMm3WM= X-Google-Smtp-Source: AMrXdXtRMTJyhT/uuOPG1VfRoI8dWUKySrMbXJuJU1eUexhborIWfN2YmuMRlm1X1V+y5ydppsmUrw== X-Received: by 2002:a17:902:d2cd:b0:195:e457:341a with SMTP id n13-20020a170902d2cd00b00195e457341amr44338142plc.4.1674988166795; Sun, 29 Jan 2023 02:29:26 -0800 (PST) From: Sam Li To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Stefan Hajnoczi , Kevin Wolf , Paolo Bonzini , Hanna Reitz , dmitry.fomichev@wdc.com, hare@suse.de, damien.lemoal@opensource.wdc.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Fam Zheng , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sam Li Subject: [PATCH v15 5/8] config: add check to block layer Date: Sun, 29 Jan 2023 18:28:47 +0800 Message-Id: <20230129102850.84731-6-faithilikerun@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230129102850.84731-1-faithilikerun@gmail.com> References: <20230129102850.84731-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::1036; envelope-from=faithilikerun@gmail.com; helo=mail-pj1-x1036.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 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 @gmail.com) X-ZM-MESSAGEID: 1674988292814100001 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 Reviewed-by: Hannes Reinecke Reviewed-by: Dmitry Fomichev --- block.c | 19 +++++++++++++++++++ block/file-posix.c | 12 ++++++++++++ block/raw-format.c | 1 + include/block/block_int-common.h | 5 +++++ 4 files changed, 37 insertions(+) diff --git a/block.c b/block.c index b4a89207ad..5ab0b26510 100644 --- a/block.c +++ b/block.c @@ -7913,6 +7913,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 b6d88db208..f661f202a1 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 ((strcmp(bs->drv->format_name, "zoned_host_device") =3D=3D 0) && + (!(s->open_flags & O_DIRECT))) { + error_setg(errp, "driver=3Dzoned_host_device was specified, but it= " + "requires 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 dbbb8f3859..772ce777ff 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -618,6 +618,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 565228d8dd..cd631f94ed 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -137,6 +137,11 @@ struct BlockDriver { */ bool is_format; =20 + /* + * Set to true if the BlockDriver supports zoned children. + */ + bool supports_zoned_children; + /* * Drivers not implementing bdrv_parse_filename nor bdrv_open should h= ave * this field set to true, except ones that are defined only by their --=20 2.38.1 From nobody Thu May 16 20:08:06 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=1674988256; cv=none; d=zohomail.com; s=zohoarc; b=UCZ00CYwc1je8hlZUJktg5xGzaGk/T21Yo89yLaa9ckiQ/Ce27nVNPa68EgkpGgxfEvnZnrkNSZOtM70jsN0xJRDPuHp7stHxe/CE0ET+EiQb6BQ8WAL2bMLCFe0DOjukwrXN7amxfkk96w2rjzCWRGE3oxbPkBrsSvWYoFTVbs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674988256; 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=Ba1KdXgZrz+MyPcKKB06enubcUStmQwX+oSNsn7lu0s=; b=Cm94f0f3kjgwIWirL6c+qNzbxTWSqopul9O2n7N8lZ7Q2eNwW9L8dmgLJh5Rd/cAXP5HiI9vDiqG9EuGVhmdcPIUoGYhZ3SMbNvz7p3hH7q26vu8xqIBgvMzTIb4tv4qH6TfpYQ09V5CsXY9GVsa0uL8nmSpA8I9g64mz5IJoas= 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 1674988256439169.89812689023893; Sun, 29 Jan 2023 02:30:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pM4wT-0005O1-CF; Sun, 29 Jan 2023 05:29:45 -0500 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 1pM4wK-0005L1-79; Sun, 29 Jan 2023 05:29:41 -0500 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pM4wI-0007Cb-B5; Sun, 29 Jan 2023 05:29:35 -0500 Received: by mail-pl1-x62f.google.com with SMTP id v23so8922043plo.1; Sun, 29 Jan 2023 02:29:33 -0800 (PST) Received: from fedlinux.. ([106.84.129.237]) by smtp.gmail.com with ESMTPSA id jl1-20020a170903134100b0019644d4242dsm5439416plb.82.2023.01.29.02.29.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Jan 2023 02:29:31 -0800 (PST) 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:subject:date :message-id:reply-to; bh=Ba1KdXgZrz+MyPcKKB06enubcUStmQwX+oSNsn7lu0s=; b=g+y5oWVUGEGHIYj/zZSqWi1iDoxrDcbsm6wLpBoJyd3bWnIARmjmCYHKAiT5qphrlA BcnYSFObYGfCmB6kdaPnFyc6FFXQ/tLPeMO3WhIbBsfhcZWqbAWLmfsMbZ0sNfex4A5Z FIYmysMzRO2vPDOH8MiMXPv42W9IXiqQm2V3sNAENIInjvhrZ9c6xxcNUtGShhF9JVib BZIetMTwBO9s0bDGqVnATfAzX2A1q/GnVbM0EXIhkn5I4ua4+82V/VEJznniJC6cUpvf lB9C1qxJlhzUarr6gKH97VJVQj4PFh/cKoMrFY8l2gc4KAPbBAjRHADiZ5ltHc5K3KFO zzlA== 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 :subject:date:message-id:reply-to; bh=Ba1KdXgZrz+MyPcKKB06enubcUStmQwX+oSNsn7lu0s=; b=C28Y4VuvgawYf0tVr3RJsWrFWxhjqKOhwyQWxezBVkHFXrIYz8UaqoMJTp1AZw5vTF +VIMzi98Bepv3Q+kvFE9WfTB52RiIDDUQVY3Q8AMzVF3QPZX+8b8Wxadyi+gdg1+NjMX unfMx2bf1S8HLcHq2A3FZpKZtLRCHwIQuDqdSiON2eyJqtR/d+EMKRjOO7HApVgWCyWK 29E788q2JrhQ25+kmQXLPRZG34I/jg9dUx5b+WAvJhAEXyXPtwEWTpNVrCqjkTYOy/sk IHziZeDyRiX+uuE0+qCgTBF8hWtfFqmaugQIjvxzHVKFXLrTn9kgjuAKQ6emF1jpwqJH Q+WQ== X-Gm-Message-State: AO0yUKVX/qon1zzYcBAkKJYcjT6bSxr58RKAkomWs7fnriHvn/KjgMJ2 TZp8dEUiO/7nzND7tFKFBfWLAfimoonfwszEhbM= X-Google-Smtp-Source: AK7set86iILpPjKXWmIK6vuVjTtKyezexQv472T3CFhbTIGfHdCPyPO+a0EI6c7gJObrGwVyJoNmiQ== X-Received: by 2002:a17:902:c10c:b0:196:7da9:4b3f with SMTP id 12-20020a170902c10c00b001967da94b3fmr1019003pli.54.1674988171788; Sun, 29 Jan 2023 02:29:31 -0800 (PST) From: Sam Li To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Stefan Hajnoczi , Kevin Wolf , Paolo Bonzini , Hanna Reitz , dmitry.fomichev@wdc.com, hare@suse.de, damien.lemoal@opensource.wdc.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Fam Zheng , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sam Li Subject: [PATCH v15 6/8] qemu-iotests: test new zone operations Date: Sun, 29 Jan 2023 18:28:48 +0800 Message-Id: <20230129102850.84731-7-faithilikerun@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230129102850.84731-1-faithilikerun@gmail.com> References: <20230129102850.84731-1-faithilikerun@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=faithilikerun@gmail.com; helo=mail-pl1-x62f.google.com X-Spam_score_int: -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 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 @gmail.com) X-ZM-MESSAGEID: 1674988256740100001 Content-Type: text/plain; charset="utf-8" We have added new block layer APIs of zoned block devices. Test it as follows: Run each zone operation on a newly created null_blk device and see whether the logs show the correct zone information. By: $ ./tests/qemu-iotests/tests/zoned.sh 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..0c8f96deb9 --- /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, [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 diff --git a/tests/qemu-iotests/tests/zoned.sh b/tests/qemu-iotests/tests/z= oned.sh new file mode 100755 index 0000000000..9d7c15dde6 --- /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=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 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" # 0x3e70000000 / 512 =3D 0x1f38= 0000 +echo +echo +echo "(2) opening the first zone" +sudo $QEMU_IO $IMG -c "zo 0 268435456" # 268435456 / 512 =3D 524288 +echo "report after:" +sudo $QEMU_IO $IMG -c "zrp 0 1" +echo +echo "opening the second zone" +sudo $QEMU_IO $IMG -c "zo 268435456 268435456" # +echo "report after:" +sudo $QEMU_IO $IMG -c "zrp 268435456 1" +echo +echo "opening the last zone" +sudo $QEMU_IO $IMG -c "zo 0x3e70000000 268435456" +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 268435456" +echo "report after:" +sudo $QEMU_IO $IMG -c "zrp 0 1" +echo +echo "closing the last zone" +sudo $QEMU_IO $IMG -c "zc 0x3e70000000 268435456" +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 268435456 268435456" +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 268435456 268435456" +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.38.1 From nobody Thu May 16 20:08:06 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=1674988234; cv=none; d=zohomail.com; s=zohoarc; b=DhJ3mqZKTdDvGxCywRC7JefLG5as6leKEx+d8dDJ8kFzGeBEsmlnIyx0jN5rVofbqJg3kgjKV158joIdb4mbTLAuRnQjN49/wJ0rzmqL1MZCCU7/HelgMdXmRQJLixX+5AGLJCztQzwg8kl0daPeYbtdsWPZ86B+VM5/Rr/JeXo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674988234; 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=A96xCuVHr3t/yvA9bSnYfTHNel9t69iWkF+ncfYcpSg=; b=F/RQ4A5Q2BhbpnlJ5Nm5C/Qu+woQdmdmuhuiSFSf5R+V5lQrsLIyWH6o5nFDjl2n2c4X7ZWUPrnYhU5KDKoAxhH/ROJ4Np+uzoNXc/hgfi8yYXjEm4Bg+3VFPjhV4g06BnWsYnAbudkONz8z9pLnTvl73fWZelK0dRLZ73Lll20= 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 1674988234401563.8745057835233; Sun, 29 Jan 2023 02:30:34 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pM4wU-0005Oy-5y; Sun, 29 Jan 2023 05:29:46 -0500 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 1pM4wO-0005LM-IL; Sun, 29 Jan 2023 05:29:41 -0500 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pM4wN-0007Cw-2p; Sun, 29 Jan 2023 05:29:40 -0500 Received: by mail-pj1-x1036.google.com with SMTP id e8-20020a17090a9a8800b0022c387f0f93so7699586pjp.3; Sun, 29 Jan 2023 02:29:38 -0800 (PST) Received: from fedlinux.. ([106.84.129.237]) by smtp.gmail.com with ESMTPSA id jl1-20020a170903134100b0019644d4242dsm5439416plb.82.2023.01.29.02.29.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Jan 2023 02:29:36 -0800 (PST) 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:subject:date :message-id:reply-to; bh=A96xCuVHr3t/yvA9bSnYfTHNel9t69iWkF+ncfYcpSg=; b=oRavDphisDXzkBmHajMvP5/wePKgBRbTzN2ZvKJaG7y7oo6Blm28woX/nv7uU5WzCZ jQW8956AytvG6groy9bI7/RgQ8EdXaoe/nT4dGmOy8rLSLggQF+vyj83QB6GshECbf64 cNmIeUx6ohfKNC6pONoAC0SHaibZ6IgRcCiB2CV+F9p8LDBkivEan8O2C1nIMLGBPOPE DToL3uXJ4u7nCJiWGAdX1k2sD8tYPWrcnC273iuIAyFCbR2LUQHsaYzZxxCBDqMTYIEu OxGfnNvX+95oO+Ygl10hk3SywR8MJJXZZ35Wzec9fY9Qr6cTRTNvxlGBsmvap7Ucecg7 bY1w== 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 :subject:date:message-id:reply-to; bh=A96xCuVHr3t/yvA9bSnYfTHNel9t69iWkF+ncfYcpSg=; b=vJrhMI1Q/S/Wq34jbIb51/feOThcxDje9U08oCTeEA2B/ohL8jL91YgYcEcGebflHg 51ndJDtd2z2NqYxJR/sjwrtFLGwKm6ryCPPF/zWtYS3WrUvQDlnAK0LXZAOLTi22i1SF RVT29H0uVe4imcM5im+LaflAhUaAWz17QpgoUFxLdDom1JO8xzDRTk3tqdxziyt7hEhF UImwGXDQfv7l/muLFD9nCMie2iXouOkGiEGy6BBG4UT9tIU7xijShezst9DIAQkF+FCz GGIc1hl6L1EaCwjiOM2ziMFSJkg3zC/Sq7HIhsgzuxe3Z5pxq779RBisqOoBiV/UH1/y 4Y3Q== X-Gm-Message-State: AO0yUKUcZHwzgx6TzB5N67n1VQ7zB4gbg3/KEEFAU67CCBo/WO5cbeyc l4FQNuUipjo8KgRwxyIpkvzE8Wy+zbzpaPl1d/U= X-Google-Smtp-Source: AK7set8RTYdO7eXsfINmVbVgjhtYvrSNnRTJga9CGcZBUzYsaDFShCpyANhMlW1kBBVr9prVnUAZ5g== X-Received: by 2002:a17:902:e841:b0:196:5554:9a3c with SMTP id t1-20020a170902e84100b0019655549a3cmr10071372plg.48.1674988176645; Sun, 29 Jan 2023 02:29:36 -0800 (PST) From: Sam Li To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Stefan Hajnoczi , Kevin Wolf , Paolo Bonzini , Hanna Reitz , dmitry.fomichev@wdc.com, hare@suse.de, damien.lemoal@opensource.wdc.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Fam Zheng , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sam Li Subject: [PATCH v15 7/8] block: add some trace events for new block layer APIs Date: Sun, 29 Jan 2023 18:28:49 +0800 Message-Id: <20230129102850.84731-8-faithilikerun@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230129102850.84731-1-faithilikerun@gmail.com> References: <20230129102850.84731-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::1036; envelope-from=faithilikerun@gmail.com; helo=mail-pj1-x1036.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 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 @gmail.com) X-ZM-MESSAGEID: 1674988236849100006 Content-Type: text/plain; charset="utf-8" Signed-off-by: Sam Li Reviewed-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 f661f202a1..5cf92608db 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -3272,6 +3272,7 @@ static int coroutine_fn raw_co_zone_report(BlockDrive= rState *bs, int64_t offset, BlockZoneDescriptor *zones) { BDRVRawState *s =3D bs->opaque; RawPosixAIOData acb; + trace_zbd_zone_report(bs, *nr_zones, offset >> BDRV_SECTOR_BITS); =20 acb =3D (RawPosixAIOData) { .bs =3D bs, @@ -3350,6 +3351,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(bs, handle_aiocb_zone_mgmt, &acb); if (ret !=3D 0) { ret =3D -errno; 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.38.1 From nobody Thu May 16 20:08:06 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=1674988308; cv=none; d=zohomail.com; s=zohoarc; b=PSdl2w2oTBJ0dluDNI3DTvxP7s/IGVErQP/sYjMxmvlacBXYLSz+xC1hwMy+zdwS6LJg4g17toIWJeOekPmx1tBM0hUM4oGrD8rpHM7K7iurva2beIbVTwE7ZcLLV2INPcHc3XB67EncwBMjP1rRkEVrYl711gasxLdEgGb7Vv4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674988308; 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=5xermXZz2dzDd2OOV3cCqQeQVqHekRDRYxUpyHfIJKs=; b=gcNNU8f57rNl3qQGrQA8FRP2FwNaKkorksShUsSJHeC7wUVnruSR05kKI6UxIKtFA6PnuqY3hk7MbJx1c0ilMkaROTFLqhtpnEOB81Nkq8i87WLloOjAfdzbNOaKdswwJc4BcR65tQq/y0w/XtnMwuWucp/6p1M6rXFhtzJ+euc= 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 1674988308517481.51461835655346; Sun, 29 Jan 2023 02:31:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pM4wW-0005Rw-2G; Sun, 29 Jan 2023 05:29:48 -0500 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 1pM4wU-0005Oz-4O; Sun, 29 Jan 2023 05:29:46 -0500 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pM4wS-0007DJ-6n; Sun, 29 Jan 2023 05:29:45 -0500 Received: by mail-pj1-x102c.google.com with SMTP id 88so8641011pjo.3; Sun, 29 Jan 2023 02:29:43 -0800 (PST) Received: from fedlinux.. ([106.84.129.237]) by smtp.gmail.com with ESMTPSA id jl1-20020a170903134100b0019644d4242dsm5439416plb.82.2023.01.29.02.29.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Jan 2023 02:29:40 -0800 (PST) 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:subject:date :message-id:reply-to; bh=5xermXZz2dzDd2OOV3cCqQeQVqHekRDRYxUpyHfIJKs=; b=IWNTTZJxUiAIebQwlbdTY37d0POwcjXbBBxU1OHLqUIx0+xpgYkEMKo6pxYRlElEyI LMrbkNNNSH27DdCFbwWHtf1+Jc/IrivxWzNC2oqJc8v8Mwr/TKSF3sRNzMkj5JAKsO6U IyZyWAUpju1zahDXcmkOWfySEgOugaHwiWLjLS6cNIF5+ZFF1ks5pdOrBFCbJnAmebH9 h34WASCOHhCDvPfltIQKcrDAbzkcNOJyrK3RTQ8cQiA166/7fbMoeAYkXIs5qJkh3eId RuGueCJs5oKpjpRqS2t7iQJSxw62OT+L01csVOQBTAMbLLtzraX5lNADNKh2/9p3Rfgp MEjQ== 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 :subject:date:message-id:reply-to; bh=5xermXZz2dzDd2OOV3cCqQeQVqHekRDRYxUpyHfIJKs=; b=ivuvmJyAOtFr5PMMnYc9B9wn3W6Bj3tHamrpA8Dfv3fDBAJ1/gF7LfAD98gwL8M7xT IQj2VJH5GFBfnKsxJ7IUyXyNUHAQvqhLK3gtb2vWUHq5WnG4MibAGUEtghswqmfrthrX oAlof3Ac2mnYQEB0E9TK4d2KTNWi85T5GOlANgY0w/mmByZWqZ/imDdjFx+/btgJPYOX 9XuFya9jy9/TbJfSeqHUoDydK4I6f35ZPX1ZPQ4CyHwWEFmEE14Z48DthCy6AeCGaMxb jK7bbP2O8qELDsaeFLcHop/rhvKKYH5uaejVZgewfaGuyn/ErVyYsVQ1kh0W3HoSEYiT ARaw== X-Gm-Message-State: AFqh2kqOJNkRjYiE8nbYtWjy9yMry4vztk7sI0jWIJZxUScwTyOkEFwZ W3U/PA5Ge7IlhZ5BDVmSxMHm3SEYepZ1Mfvf34Y= X-Google-Smtp-Source: AMrXdXsyV07ayA96a7G1cLHRitPml08to1I86e3aRCgHuPoabfy0HQgEDKJMxxcVDUyvMiH91/V92A== X-Received: by 2002:a17:903:31c9:b0:194:7ce2:aa5e with SMTP id v9-20020a17090331c900b001947ce2aa5emr40542295ple.28.1674988181356; Sun, 29 Jan 2023 02:29:41 -0800 (PST) From: Sam Li To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Stefan Hajnoczi , Kevin Wolf , Paolo Bonzini , Hanna Reitz , dmitry.fomichev@wdc.com, hare@suse.de, damien.lemoal@opensource.wdc.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Fam Zheng , Thomas Huth , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sam Li Subject: [PATCH v15 8/8] docs/zoned-storage: add zoned device documentation Date: Sun, 29 Jan 2023 18:28:50 +0800 Message-Id: <20230129102850.84731-9-faithilikerun@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230129102850.84731-1-faithilikerun@gmail.com> References: <20230129102850.84731-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 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 @gmail.com) X-ZM-MESSAGEID: 1674988308903100001 Content-Type: text/plain; charset="utf-8" Add the documentation about the zoned device support to virtio-blk emulation. Signed-off-by: Sam Li Reviewed-by: Stefan Hajnoczi Reviewed-by: Damien Le Moal Reviewed-by: Dmitry Fomichev --- docs/devel/zoned-storage.rst | 43 ++++++++++++++++++++++++++ docs/system/qemu-block-drivers.rst.inc | 6 ++++ 2 files changed, 49 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..03e52efe2e --- /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=3Dzoned_host_device,filename=3D/d= ev/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.38.1