From nobody Sun May 19 22:46:17 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=1678443906; cv=none; d=zohomail.com; s=zohoarc; b=lv2KgPwKeFepKT4/i/Y9Vg3fhmSbAanuW6hWcgIvd/KijZCceIMtNXfM+8nCI6fkPD7ux9qYQCI5GweH2q1+FPIK0XWoEq3yZCUGsNd+/AbDEMXk93o3mPXqfZtvpFKCko7NRBluDs8VO80PjUj3IZudQXkjJC3YuxOwWTgmntQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678443906; 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=cV4cpNh8SauJymuql2kvn1bbRIlM6L2aipAAvasPZNE=; b=VD3R5Ubee/po0km0ZaRI7/T9y5e6v1Fc+C9io0PFt7yKYxRcXQvOoC2Amk7tiYVVLNpBAXOfi/5VzkY5o0e4kXuU3ctEDxe2lmGqds3Df9hv9ROHdZc5Ce3tgai6cnsgsWVgE2g15OlHYuXjabJBj1jkRYxEetoPjJuvlvfEZRA= 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 1678443906362899.620142006898; Fri, 10 Mar 2023 02:25:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1paZvB-0007st-PD; Fri, 10 Mar 2023 05:24:21 -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 1paZv9-0007qg-JZ; Fri, 10 Mar 2023 05:24:19 -0500 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1paZv8-0002Qi-2l; Fri, 10 Mar 2023 05:24:19 -0500 Received: by mail-pf1-x42f.google.com with SMTP id ay18so3321780pfb.2; Fri, 10 Mar 2023 02:24:17 -0800 (PST) Received: from fedlinux.. ([106.84.129.9]) by smtp.gmail.com with ESMTPSA id f8-20020a63f748000000b005030113f46dsm1008719pgk.37.2023.03.10.02.24.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Mar 2023 02:24:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678443856; 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=cV4cpNh8SauJymuql2kvn1bbRIlM6L2aipAAvasPZNE=; b=MC+CrQ+CPR+NIK6v6UvUxq1LIfyn7/fRVqIoVb/44ITmbvNK0MRSy5sbdlkTpCris7 UeqduuD/ETCAakxGg27ZJdykPJO8hGKKo355Isl3uv2JsaOCC3sYVMQR/DIhY+f2A2Be PG8G5XPU0+p1WWKK2cVBaz6Tns0ToXiaBP1fUutoMM7Eo7hYFd1KQ3wblPsPmezpahXm 6cjbkCeUM/kAiWG0fH9mW+UbcvF5ApydkV87eN68BYlSjJXkwm6oAWmzbLftdrIMxumQ WA+WjshR7jfcw9GXQewSFNEwTEUuJVs7GEgq6ncbMjqrFBDWq3qX/AcryZ8++Bk0rt7X 4SWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678443856; 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=cV4cpNh8SauJymuql2kvn1bbRIlM6L2aipAAvasPZNE=; b=zErUKSWSOdWu88Rt4noKVv4lzIflF6g6JIbhgfEou8raaV/eXuDy8k5cEB2OqmJvPa 3nI7pFyw6sTnjRn2EwK+khFCKzUxQIv2EErjvPjzmPqxIyrchKT6XnkbKM5DxrTqW208 jzLKRnV8aZ4g4mZnCoNojJdytGw8pO0kU+ICgE7Y9uEARq8TT9KYSKxKsQNbsfs4yAk7 YxcFXj1Vc/0b4WomrrNbSJ+CwfKdAy3te2bFwxzd5bQttoZ+skPC1W0cSEOa1spmmmxZ YPVgC1DttXhUS9+WsztLy8uT1ApdiiKUO00LVXOYJENyRkZsGKhHEWRtl4Kay4A49W3+ y93g== X-Gm-Message-State: AO0yUKXwWsK4d84YahIT2A1mFVw7iM/nj0wSU/oKHbOmMP1bIUT5xIXG vTZqWW7hG6bczvJ0RMzXFJ7AfneYTpr8AGyw+vM= X-Google-Smtp-Source: AK7set+EMDUAN5aBLxpfW25lBDQPMqpZYriXaH4WsEhqTpKpEZUQRharTQ23YG+MVyNumFh4RQC/PQ== X-Received: by 2002:a05:6a00:27ac:b0:5a8:cc39:fc58 with SMTP id bd44-20020a056a0027ac00b005a8cc39fc58mr1438487pfb.6.1678443855459; Fri, 10 Mar 2023 02:24:15 -0800 (PST) From: Sam Li To: qemu-devel@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , qemu-block@nongnu.org, damien.lemoal@opensource.wdc.com, hare@suse.de, Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Fam Zheng , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , dmitry.fomichev@wdc.com, Thomas Huth , Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sam Li Subject: [PATCH v16 1/8] include: add zoned device structs Date: Fri, 10 Mar 2023 18:23:56 +0800 Message-Id: <20230310102403.61347-2-faithilikerun@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230310102403.61347-1-faithilikerun@gmail.com> References: <20230310102403.61347-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::42f; envelope-from=faithilikerun@gmail.com; helo=mail-pf1-x42f.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: 1678443908352100010 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 Reviewed-by: Dmitry Fomichev --- include/block/block-common.h | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/include/block/block-common.h b/include/block/block-common.h index b5122ef8ab..1576fcf2ed 100644 --- a/include/block/block-common.h +++ b/include/block/block-common.h @@ -75,6 +75,49 @@ typedef struct BlockDriver BlockDriver; typedef struct BdrvChild BdrvChild; typedef struct BdrvChildClass BdrvChildClass; =20 +typedef enum BlockZoneOp { + BLK_ZO_OPEN, + BLK_ZO_CLOSE, + BLK_ZO_FINISH, + BLK_ZO_RESET, +} BlockZoneOp; + +typedef enum BlockZoneModel { + BLK_Z_NONE =3D 0x0, /* Regular block device */ + BLK_Z_HM =3D 0x1, /* Host-managed zoned block device */ + BLK_Z_HA =3D 0x2, /* Host-aware zoned block device */ +} BlockZoneModel; + +typedef enum BlockZoneState { + BLK_ZS_NOT_WP =3D 0x0, + BLK_ZS_EMPTY =3D 0x1, + BLK_ZS_IOPEN =3D 0x2, + BLK_ZS_EOPEN =3D 0x3, + BLK_ZS_CLOSED =3D 0x4, + BLK_ZS_RDONLY =3D 0xD, + BLK_ZS_FULL =3D 0xE, + BLK_ZS_OFFLINE =3D 0xF, +} BlockZoneState; + +typedef enum BlockZoneType { + BLK_ZT_CONV =3D 0x1, /* Conventional random writes supported */ + BLK_ZT_SWR =3D 0x2, /* Sequential writes required */ + BLK_ZT_SWP =3D 0x3, /* Sequential writes preferred */ +} BlockZoneType; + +/* + * Zone descriptor data structure. + * Provides information on a zone with all position and size values in byt= es. + */ +typedef struct BlockZoneDescriptor { + uint64_t start; + uint64_t length; + uint64_t cap; + uint64_t wp; + BlockZoneType type; + BlockZoneState state; +} BlockZoneDescriptor; + typedef struct BlockDriverInfo { /* in bytes, 0 if irrelevant */ int cluster_size; --=20 2.39.2 From nobody Sun May 19 22:46:17 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=1678443906; cv=none; d=zohomail.com; s=zohoarc; b=VFwmRFHsxRG1q+1BVweCk2jkP1taBZJ0FoBC9QpkPccfVGcbYkRJ4XdQw9voV0zSHQzhZgwM189v3EJREjspZoYlC5xCVQj0NppNJsZzOfW3DvDdg5o4nP1a/QY/ZoHwzSOZZE2ahcPqQmK0daaXv/toIqH3D1pLB3T5ZFGjmhI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678443906; 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=fJolfis9eNU4/OYkJ16j42VmOzq14bXYMKd+Adi/cMk=; b=M633tVchoGN7NANH2q1hDr518OyICh3Wt/KbCe/lyrshQRs2uO22YgnMeH/3uOVx24SRrggm6ZvHugFrJ9jAJq+GhebsXYxfn6e5bKw1iA2jCDWGGDI5KOiv/nZ0uGCyAxTbOtOod0T6bt0cz0oSxIciPHgkpXl7mGgLIKLrLG8= 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 1678443906297864.5785791306778; Fri, 10 Mar 2023 02:25:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1paZvP-00083i-Uq; Fri, 10 Mar 2023 05:24:37 -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 1paZvE-0007yl-L5; Fri, 10 Mar 2023 05:24:24 -0500 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1paZvC-0002RJ-FN; Fri, 10 Mar 2023 05:24:24 -0500 Received: by mail-pj1-x1029.google.com with SMTP id h17-20020a17090aea9100b0023739b10792so4753222pjz.1; Fri, 10 Mar 2023 02:24:21 -0800 (PST) Received: from fedlinux.. ([106.84.129.9]) by smtp.gmail.com with ESMTPSA id f8-20020a63f748000000b005030113f46dsm1008719pgk.37.2023.03.10.02.24.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Mar 2023 02:24:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678443860; 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=fJolfis9eNU4/OYkJ16j42VmOzq14bXYMKd+Adi/cMk=; b=CsiQUIQ5rE8BsCFmrACCyOHRAIekHOp7YSK//FxYMEwA+RFkbzPi4A/j+AE8HrayNB HQyHdPbAd+NqxYqM01W+BSzLspQfyIBqcZfP7TIvpSvjPRP2qvHsuaoNa1GRcKUqXxkh tColyGb+6bOPyIDfvS3/a+B1MF8JgY8S08GkqzWOFwtdwrdG+O7WtFV9GV6Ytkrfm3+Q ApfONEb7uHmGcgJwZYFjKS+GW/QhVmRlUqwKkvAgv2is8niNc9+8IYSg/KLRewcdy3Pw CKV1WT66AcSVXdTUKhwMxc2BkyLwlHv351u/tgwxLPoBvPDVDLolOjeLsXyPFCiMjOuo aGew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678443860; 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=fJolfis9eNU4/OYkJ16j42VmOzq14bXYMKd+Adi/cMk=; b=tkbcHaiR4V4dBGPx2OFxdf5Nzpvd8ZFyesif3mN7ozrD3NaGMYqnjXlbobm7nj3/Z4 GwBUZq0zdcQrmHSVe18HLBoq4rNt134efmKlgvc4NbnL5F1kPnBzg2L9ijnYmrwOBrEe 3WrzEvTA6sAa63aBWY+hJDTjt7APIqK7NPhduJba6A0JlmORR9lXa3Mxim/9U6UONJne 0c0dYWv4jSLau9cuigdCmVfqkRQeUrX3nX0DXwwbdBaCLFFl/zZEp1VUsk6tQjW319dP LMgplcOjJhuhZKElTUiGOFp5NSvbfUvft7zxl8ZSMKUxg4QP7XHMPx7zR696c+dq1/T+ KzVQ== X-Gm-Message-State: AO0yUKXsUndrjvbqOuFNjWXTwuamLgF/RoYh4Dlwo1CtLF9POhavikeE aGxMp+etglOb5xMlHQTmx+uhO5OIdDo5ytnLG4U= X-Google-Smtp-Source: AK7set8WlK+kwV6J+vtmiET4KH2bMjPgKi8i/chCBo1knZxM+HHUgshR16una61FlkHYYfYGLcqu6g== X-Received: by 2002:a05:6a20:441d:b0:ce:2fb4:5fc4 with SMTP id ce29-20020a056a20441d00b000ce2fb45fc4mr29090852pzb.38.1678443859857; Fri, 10 Mar 2023 02:24:19 -0800 (PST) From: Sam Li To: qemu-devel@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , qemu-block@nongnu.org, damien.lemoal@opensource.wdc.com, hare@suse.de, Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Fam Zheng , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , dmitry.fomichev@wdc.com, Thomas Huth , Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sam Li Subject: [PATCH v16 2/8] file-posix: introduce helper functions for sysfs attributes Date: Fri, 10 Mar 2023 18:23:57 +0800 Message-Id: <20230310102403.61347-3-faithilikerun@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230310102403.61347-1-faithilikerun@gmail.com> References: <20230310102403.61347-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::1029; envelope-from=faithilikerun@gmail.com; helo=mail-pj1-x1029.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: 1678443908367100011 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 5760cf22d1..496edc644c 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 d419017328..6d0f470626 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -855,6 +855,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.39.2 From nobody Sun May 19 22:46:17 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=1678443955; cv=none; d=zohomail.com; s=zohoarc; b=XvHXpCB8xc5l7+WvRbQah49JHXmxrzB3+xXGls+6mUiLlf0GUqfGtonhf/x+foM1ecVcpkMta7UoLyz/L95w+XtG6mwxfZPwZMRYDkGWCLts37p355UyhnhBgGpIuh4AhCYc0BumFOvZpKQyAzpNuAuAPfDl2DMob0rFjYXqKHI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678443955; 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=iQiKavWLIAJxbR8pnPkUvMWWk9syLCgOcAT7ld373Ew=; b=hOKklnN0ssx0AMYYmcxxIUUjBvLY24ju6ng+nI23K+hKD5C3b+fcZrPOXEtXub7lrwMLL2RMz5rEeHDQ99kR34qNFYwiADgJOkTJCCe+mr+AVGZ+znSfMxmf/QaevB4mpM+2z0zD8tLfU4NJhP43+vJPa/Js6CiDmgp0mXet8Yk= 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 1678443955379875.6524251095055; Fri, 10 Mar 2023 02:25:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1paZve-0008N0-6T; Fri, 10 Mar 2023 05:24:50 -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 1paZvQ-00089f-BV; Fri, 10 Mar 2023 05:24:37 -0500 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1paZvL-0002S7-14; Fri, 10 Mar 2023 05:24:34 -0500 Received: by mail-pj1-x1035.google.com with SMTP id m8-20020a17090a4d8800b002377bced051so9349962pjh.0; Fri, 10 Mar 2023 02:24:26 -0800 (PST) Received: from fedlinux.. ([106.84.129.9]) by smtp.gmail.com with ESMTPSA id f8-20020a63f748000000b005030113f46dsm1008719pgk.37.2023.03.10.02.24.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Mar 2023 02:24:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678443865; 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=iQiKavWLIAJxbR8pnPkUvMWWk9syLCgOcAT7ld373Ew=; b=UsKoxTHjWVaop4FW8DS7vVon9Pno2JlNI6SkSxD/ex0gBmgIu5HBSpINVvHUoFdTTi LRDL7Uq07Xq7W8v/01tIysGhxNuNzXNiL82bDJ6uIlfFIXCMEtzBO3fuEPPF7RuZbryR FIvGvCDE9S5fJ+SpvK77xHrASu2KMdrC83khcpTsybkxz4UHChjjJT/sqAHLOux2fUP1 BlCrL6E5XG54tdfJR8F7+z5qNIk8e45vhdiWpiSeKuJ/korqzZE+JGmYvgYlJcciGqU/ ewo2eaK2Wj/O2wCV7Oy5wVuKNmPubGmeSs2xCZeAaWFIEATHOLWavs7wJUfKIOtReWcd uwyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678443865; 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=iQiKavWLIAJxbR8pnPkUvMWWk9syLCgOcAT7ld373Ew=; b=fn6dAqlwiUoP6x8NHafUg/c4IcOWnJzNhJj1zmb8ksHikzSXN0CBYQo0PgnqCzhv6F 0gNPPKz/ZgjUpj147ms0PcId+5piCnZ4tjPdGQtXHgmXwxuN/NflT6GjHWPmlamx3R7S G0WFL2y1SvfOyYJsG4c2VKlQKacJsVwc02mskiSHHPVIY+ViLuUOm2xEEZEnPl3MnLCS hsCQzGhY3S+iMhJJXD4C81/SEpVoVSMrvpl/W+zqPFdoptvV2uv5xwRzoB4SZYxM/fcI Si+B0oXBtGULh4vwEWm3XMfg8ETmORBh/Fu7li7RQfdaPp1ERz/thY0789PoOnu6Dloq G0RQ== X-Gm-Message-State: AO0yUKWpRPJLtxEPomwPsUQ1Um5HDHdmfsVaWfh0puEjOpZ1gwRcL6Lg YeaYTBjLDU4GwIvFDFTnAIY4Ydub+Ney+NM3JEs= X-Google-Smtp-Source: AK7set/O8tH+iW9Ut1Iksyl7WBpnJsjtatX5JBtT5FJWS89Y1vu09F6PhycuhndgY3bZY86YZ+6J7A== X-Received: by 2002:a05:6a20:12d4:b0:cc:beae:c2c2 with SMTP id v20-20020a056a2012d400b000ccbeaec2c2mr29535841pzg.1.1678443864666; Fri, 10 Mar 2023 02:24:24 -0800 (PST) From: Sam Li To: qemu-devel@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , qemu-block@nongnu.org, damien.lemoal@opensource.wdc.com, hare@suse.de, Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Fam Zheng , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , dmitry.fomichev@wdc.com, Thomas Huth , Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sam Li Subject: [PATCH v16 3/8] block: add block layer APIs resembling Linux ZonedBlockDevice ioctls Date: Fri, 10 Mar 2023 18:23:58 +0800 Message-Id: <20230310102403.61347-4-faithilikerun@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230310102403.61347-1-faithilikerun@gmail.com> References: <20230310102403.61347-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::1035; envelope-from=faithilikerun@gmail.com; helo=mail-pj1-x1035.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: 1678443956678100001 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 Reviewed-by: Dmitry Fomichev --- block/block-backend.c | 133 +++++++++++++ block/file-posix.c | 309 +++++++++++++++++++++++++++++- block/io.c | 41 ++++ include/block/block-io.h | 9 + include/block/block_int-common.h | 21 ++ include/block/raw-aio.h | 6 +- include/sysemu/block-backend-io.h | 18 ++ meson.build | 4 + qemu-io-cmds.c | 149 ++++++++++++++ 9 files changed, 687 insertions(+), 3 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index 278b04ce69..f70b08e3f6 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1806,6 +1806,139 @@ int coroutine_fn blk_co_flush(BlockBackend *blk) return ret; } =20 +static void coroutine_fn blk_aio_zone_report_entry(void *opaque) +{ + BlkAioEmAIOCB *acb =3D opaque; + BlkRwCo *rwco =3D &acb->rwco; + + rwco->ret =3D blk_co_zone_report(rwco->blk, rwco->offset, + (unsigned int*)acb->bytes,rwco->iobuf); + blk_aio_complete(acb); +} + +BlockAIOCB *blk_aio_zone_report(BlockBackend *blk, int64_t offset, + unsigned int *nr_zones, + BlockZoneDescriptor *zones, + BlockCompletionFunc *cb, void *opaque) +{ + BlkAioEmAIOCB *acb; + Coroutine *co; + IO_CODE(); + + blk_inc_in_flight(blk); + acb =3D blk_aio_get(&blk_aio_em_aiocb_info, blk, cb, opaque); + acb->rwco =3D (BlkRwCo) { + .blk =3D blk, + .offset =3D offset, + .iobuf =3D zones, + .ret =3D NOT_DONE, + }; + acb->bytes =3D (int64_t)nr_zones, + acb->has_returned =3D false; + + co =3D qemu_coroutine_create(blk_aio_zone_report_entry, acb); + aio_co_enter(blk_get_aio_context(blk), co); + + acb->has_returned =3D true; + if (acb->rwco.ret !=3D NOT_DONE) { + replay_bh_schedule_oneshot_event(blk_get_aio_context(blk), + blk_aio_complete_bh, acb); + } + + return &acb->common; +} + +static void coroutine_fn blk_aio_zone_mgmt_entry(void *opaque) +{ + BlkAioEmAIOCB *acb =3D opaque; + BlkRwCo *rwco =3D &acb->rwco; + + rwco->ret =3D blk_co_zone_mgmt(rwco->blk, (BlockZoneOp)rwco->iobuf, + rwco->offset, acb->bytes); + blk_aio_complete(acb); +} + +BlockAIOCB *blk_aio_zone_mgmt(BlockBackend *blk, BlockZoneOp op, + int64_t offset, int64_t len, + BlockCompletionFunc *cb, void *opaque) { + BlkAioEmAIOCB *acb; + Coroutine *co; + IO_CODE(); + + blk_inc_in_flight(blk); + acb =3D blk_aio_get(&blk_aio_em_aiocb_info, blk, cb, opaque); + acb->rwco =3D (BlkRwCo) { + .blk =3D blk, + .offset =3D offset, + .iobuf =3D (void *)op, + .ret =3D NOT_DONE, + }; + acb->bytes =3D len; + acb->has_returned =3D false; + + co =3D qemu_coroutine_create(blk_aio_zone_mgmt_entry, acb); + aio_co_enter(blk_get_aio_context(blk), co); + + acb->has_returned =3D true; + if (acb->rwco.ret !=3D NOT_DONE) { + replay_bh_schedule_oneshot_event(blk_get_aio_context(blk), + blk_aio_complete_bh, acb); + } + + return &acb->common; +} + +/* + * Send a zone_report command. + * offset is a byte offset from the start of the device. No alignment + * required for offset. + * nr_zones represents IN maximum and OUT actual. + */ +int coroutine_fn blk_co_zone_report(BlockBackend *blk, int64_t offset, + unsigned int *nr_zones, + BlockZoneDescriptor *zones) +{ + int ret; + IO_CODE(); + + blk_inc_in_flight(blk); /* increase before waiting */ + blk_wait_while_drained(blk); + 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 496edc644c..df9b9f1e30 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) @@ -1374,9 +1428,12 @@ static int hdev_probe_blocksizes(BlockDriverState *b= s, BlockSizes *bsz) BDRVRawState *s =3D bs->opaque; int ret; =20 - /* If DASD, get blocksizes */ + /* If DASD or zoned devices, get blocksizes */ if (check_for_dasd(s->fd) < 0) { - return -ENOTSUP; + /* zoned devices are not DASD */ + if (bs->bl.zoned =3D=3D BLK_Z_NONE) { + return -ENOTSUP; + } } ret =3D probe_logical_blocksize(s->fd, &bsz->log); if (ret < 0) { @@ -1844,6 +1901,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; @@ -3034,6 +3231,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) @@ -3789,6 +4087,13 @@ static BlockDriver bdrv_host_device =3D { #ifdef __linux__ .bdrv_co_ioctl =3D hdev_co_ioctl, #endif + + /* zoned device */ +#if defined(CONFIG_BLKZONED) + /* zone management operations */ + .bdrv_co_zone_report =3D raw_co_zone_report, + .bdrv_co_zone_mgmt =3D raw_co_zone_mgmt, +#endif }; =20 #if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel= __) diff --git a/block/io.c b/block/io.c index 8974d46941..5dbf1e50f2 100644 --- a/block/io.c +++ b/block/io.c @@ -3111,6 +3111,47 @@ out: return co.ret; } =20 +int coroutine_fn bdrv_co_zone_report(BlockDriverState *bs, int64_t offset, + unsigned int *nr_zones, + BlockZoneDescriptor *zones) +{ + BlockDriver *drv =3D bs->drv; + CoroutineIOCompletion co =3D { + .coroutine =3D qemu_coroutine_self(), + }; + IO_CODE(); + + bdrv_inc_in_flight(bs); + if (!drv || !drv->bdrv_co_zone_report || bs->bl.zoned =3D=3D BLK_Z_NON= E) { + co.ret =3D -ENOTSUP; + goto out; + } + co.ret =3D drv->bdrv_co_zone_report(bs, offset, nr_zones, zones); +out: + bdrv_dec_in_flight(bs); + return co.ret; +} + +int coroutine_fn bdrv_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, + int64_t offset, int64_t len) +{ + BlockDriver *drv =3D bs->drv; + CoroutineIOCompletion co =3D { + .coroutine =3D qemu_coroutine_self(), + }; + IO_CODE(); + + bdrv_inc_in_flight(bs); + if (!drv || !drv->bdrv_co_zone_mgmt || bs->bl.zoned =3D=3D BLK_Z_NONE)= { + co.ret =3D -ENOTSUP; + goto out; + } + co.ret =3D drv->bdrv_co_zone_mgmt(bs, op, offset, len); +out: + bdrv_dec_in_flight(bs); + return co.ret; +} + void *qemu_blockalign(BlockDriverState *bs, size_t size) { IO_CODE(); diff --git a/include/block/block-io.h b/include/block/block-io.h index 5da99d4d60..19d1fad9cf 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -112,6 +112,15 @@ int coroutine_fn GRAPH_RDLOCK bdrv_co_flush(BlockDrive= rState *bs); int coroutine_fn GRAPH_RDLOCK bdrv_co_pdiscard(BdrvChild *child, int64_t o= ffset, int64_t bytes); =20 +/* Report zone information of zone block device. */ +int coroutine_fn GRAPH_RDLOCK bdrv_co_zone_report(BlockDriverState *bs, + int64_t offset, + unsigned int *nr_zones, + BlockZoneDescriptor *zon= es); +int coroutine_fn GRAPH_RDLOCK bdrv_co_zone_mgmt(BlockDriverState *bs, + BlockZoneOp op, + int64_t offset, int64_t le= n); + bool bdrv_can_write_zeroes_with_unmap(BlockDriverState *bs); int bdrv_block_status(BlockDriverState *bs, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map, diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 6d0f470626..a3efb385e0 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -714,6 +714,12 @@ struct BlockDriver { int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_load_vmstate)( BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos); =20 + int coroutine_fn (*bdrv_co_zone_report)(BlockDriverState *bs, + int64_t offset, unsigned int *nr_zones, + BlockZoneDescriptor *zones); + int coroutine_fn (*bdrv_co_zone_mgmt)(BlockDriverState *bs, BlockZoneO= p op, + int64_t offset, int64_t len); + /* removable device specific */ bool coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_is_inserted)( BlockDriverState *bs); @@ -858,6 +864,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 40ab178719..f575ab5b6b 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); @@ -184,6 +191,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 6bcab8bf0d..2985135802 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')) @@ -2048,6 +2049,9 @@ config_host_data.set('HAVE_SIGEV_NOTIFY_THREAD_ID', config_host_data.set('HAVE_STRUCT_STAT_ST_ATIM', cc.has_member('struct stat', 'st_atim', prefix: '#include ')) +config_host_data.set('HAVE_BLK_ZONE_REP_CAPACITY', + cc.has_member('struct blk_zone', 'capacity', + prefix: '#include ')) =20 # has_type config_host_data.set('CONFIG_IOVEC', diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index e7a02f5b99..f35ea627d7 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -1730,6 +1730,150 @@ static const cmdinfo_t flush_cmd =3D { .oneline =3D "flush all in-core file state to disk", }; =20 +static inline int64_t tosector(int64_t bytes) +{ + return bytes >> BDRV_SECTOR_BITS; +} + +static int zone_report_f(BlockBackend *blk, int argc, char **argv) +{ + int ret; + int64_t offset; + unsigned int nr_zones; + + ++optind; + offset =3D cvtnum(argv[optind]); + ++optind; + nr_zones =3D cvtnum(argv[optind]); + + g_autofree BlockZoneDescriptor *zones =3D NULL; + zones =3D g_new(BlockZoneDescriptor, nr_zones); + ret =3D blk_zone_report(blk, offset, &nr_zones, zones); + if (ret < 0) { + printf("zone report failed: %s\n", strerror(-ret)); + } else { + for (int i =3D 0; i < nr_zones; ++i) { + printf("start: 0x%" PRIx64 ", len 0x%" PRIx64 ", " + "cap"" 0x%" PRIx64 ", wptr 0x%" PRIx64 ", " + "zcond:%u, [type: %u]\n", + tosector(zones[i].start), tosector(zones[i].length), + tosector(zones[i].cap), tosector(zones[i].wp), + zones[i].state, zones[i].type); + } + } + return ret; +} + +static const cmdinfo_t zone_report_cmd =3D { + .name =3D "zone_report", + .altname =3D "zrp", + .cfunc =3D zone_report_f, + .argmin =3D 2, + .argmax =3D 2, + .args =3D "offset number", + .oneline =3D "report zone information", +}; + +static int zone_open_f(BlockBackend *blk, int argc, char **argv) +{ + int ret; + int64_t offset, len; + ++optind; + offset =3D cvtnum(argv[optind]); + ++optind; + len =3D cvtnum(argv[optind]); + ret =3D blk_zone_mgmt(blk, BLK_ZO_OPEN, offset, len); + if (ret < 0) { + printf("zone open failed: %s\n", strerror(-ret)); + } + return ret; +} + +static const cmdinfo_t zone_open_cmd =3D { + .name =3D "zone_open", + .altname =3D "zo", + .cfunc =3D zone_open_f, + .argmin =3D 2, + .argmax =3D 2, + .args =3D "offset len", + .oneline =3D "explicit open a range of zones in zone block device", +}; + +static int zone_close_f(BlockBackend *blk, int argc, char **argv) +{ + int ret; + int64_t offset, len; + ++optind; + offset =3D cvtnum(argv[optind]); + ++optind; + len =3D cvtnum(argv[optind]); + ret =3D blk_zone_mgmt(blk, BLK_ZO_CLOSE, offset, len); + if (ret < 0) { + printf("zone close failed: %s\n", strerror(-ret)); + } + return ret; +} + +static const cmdinfo_t zone_close_cmd =3D { + .name =3D "zone_close", + .altname =3D "zc", + .cfunc =3D zone_close_f, + .argmin =3D 2, + .argmax =3D 2, + .args =3D "offset len", + .oneline =3D "close a range of zones in zone block device", +}; + +static int zone_finish_f(BlockBackend *blk, int argc, char **argv) +{ + int ret; + int64_t offset, len; + ++optind; + offset =3D cvtnum(argv[optind]); + ++optind; + len =3D cvtnum(argv[optind]); + ret =3D blk_zone_mgmt(blk, BLK_ZO_FINISH, offset, len); + if (ret < 0) { + printf("zone finish failed: %s\n", strerror(-ret)); + } + return ret; +} + +static const cmdinfo_t zone_finish_cmd =3D { + .name =3D "zone_finish", + .altname =3D "zf", + .cfunc =3D zone_finish_f, + .argmin =3D 2, + .argmax =3D 2, + .args =3D "offset len", + .oneline =3D "finish a range of zones in zone block device", +}; + +static int zone_reset_f(BlockBackend *blk, int argc, char **argv) +{ + int ret; + int64_t offset, len; + ++optind; + offset =3D cvtnum(argv[optind]); + ++optind; + len =3D cvtnum(argv[optind]); + ret =3D blk_zone_mgmt(blk, BLK_ZO_RESET, offset, len); + if (ret < 0) { + printf("zone reset failed: %s\n", strerror(-ret)); + } + return ret; +} + +static const cmdinfo_t zone_reset_cmd =3D { + .name =3D "zone_reset", + .altname =3D "zrs", + .cfunc =3D zone_reset_f, + .argmin =3D 2, + .argmax =3D 2, + .args =3D "offset len", + .oneline =3D "reset a zone write pointer in zone block device", +}; + static int truncate_f(BlockBackend *blk, int argc, char **argv); static const cmdinfo_t truncate_cmd =3D { .name =3D "truncate", @@ -2523,6 +2667,11 @@ static void __attribute((constructor)) init_qemuio_c= ommands(void) qemuio_add_command(&aio_write_cmd); qemuio_add_command(&aio_flush_cmd); qemuio_add_command(&flush_cmd); + qemuio_add_command(&zone_report_cmd); + qemuio_add_command(&zone_open_cmd); + qemuio_add_command(&zone_close_cmd); + qemuio_add_command(&zone_finish_cmd); + qemuio_add_command(&zone_reset_cmd); qemuio_add_command(&truncate_cmd); qemuio_add_command(&length_cmd); qemuio_add_command(&info_cmd); --=20 2.39.2 From nobody Sun May 19 22:46:17 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=1678443912; cv=none; d=zohomail.com; s=zohoarc; b=bnBaRP2cWPJKk9ANGh23DHM2M9DB8hYhMLwFutF+Z0IRBDxnP7QA59aeUHCzz3xgIzQ3wBak0rJGF0OoGvbujuZFSp+uRs6BQcofddNyEE6GffPP1s0mmBPS1/U8BmH0Sz6lsGQpyHzgCcmxrMS7f5U8UX/7Zc8fkyDmLLa5gwo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678443912; 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=jtxZ8v3YWpYA+etoCTcOvJcHPgV19dkZSoY9cWpKuXw=; b=NZEDm0m7gxjhGGiSiWH5u5SLvTNDI/l1UcHwvDz1DADVxQMgY0L497GoY3kkqtv/3Yywp1eSUi79wVeNRqjqxoJwRJ5jLc+gY6ZaVp2Y3faOggzgtkao9Ffizr+4YHxUK4Jx1atLgvW0BllqFAkM9/CLuyE1HERfVY+JGZZQun8= 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 1678443912343945.638485795204; Fri, 10 Mar 2023 02:25:12 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1paZvd-0008Df-AR; Fri, 10 Mar 2023 05:24:49 -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 1paZvQ-00089c-64; Fri, 10 Mar 2023 05:24:37 -0500 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1paZvM-0002Sf-2D; Fri, 10 Mar 2023 05:24:33 -0500 Received: by mail-pj1-x102a.google.com with SMTP id p3-20020a17090ad30300b0023a1cd5065fso4783121pju.0; Fri, 10 Mar 2023 02:24:31 -0800 (PST) Received: from fedlinux.. ([106.84.129.9]) by smtp.gmail.com with ESMTPSA id f8-20020a63f748000000b005030113f46dsm1008719pgk.37.2023.03.10.02.24.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Mar 2023 02:24:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678443870; 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=jtxZ8v3YWpYA+etoCTcOvJcHPgV19dkZSoY9cWpKuXw=; b=p8VTohKiqcr5/wknxSovzPT7hYqyRuzJmCXYFvIXtCpNRuBrkqJeHGZz+FN2j01e/8 WFmm6dCUEcl5ZVJHrym3WkYcrrwvQIGxgK2J1IuV2QqHYMWMerV2qnjq8YoD10VszK+z xbpKfbiKwjE4x1pEAKl6Nrby14BZDCgJN3nC6Cd0SMtki+udg5p0Bd9Ps7Xu8MhXKiJ4 G85nwkR9ygSXbTUqqSeyHgLqVQd4HWxnVL52nNyDGjPIkQ+2QzWTO7i2gj13wa9b/iY8 EDG8GhvTFXbPrZdyU2l5uUBf++OwjSbP6RZyeJwPu4PKD5+vHIFIp09AGBwwrJI3pX/m 07lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678443870; 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=jtxZ8v3YWpYA+etoCTcOvJcHPgV19dkZSoY9cWpKuXw=; b=xhfBbD5GT3FTQbkghRtIAy9xt/zFgWFk7BBsw2wtYskk2HivIBQd1omfT7G62Exmwk ipKr+zYS+l4t3CEvVG35zy6KEkoTvpk8xnUPQUat4kxm4VDwzXPxlH0sWFeJNtFtdOVw 9Z9+hqSIKxaecOvqCCMxXNmJ1VFGbGREVqb7xnz/ci/cCA192vSFqNK8E7VEFJT2Bv70 KO8/oKeXHXxBT7mpwKsBeP6Q4uox6MRPaHzxk+BvwjIjq/q36VsEy0p/wOwG3ZYiSNCP 2+EiWZbw4Dfm9+drHf+4pchCTpeTEmnj4oEwMYIb3Qlx9tgXno9FfPFUC15/2/Fus/ch znFg== X-Gm-Message-State: AO0yUKUiBGtQqHQjxwPwxtPRJSQYAuBjfyJWgE+pReFF9pMxAfeTU/Wu yMtwpN0aoKyU+D0APvy/UBCE9CshTl9S2mUl5Z0= X-Google-Smtp-Source: AK7set+6/zlvS69l2yTuS4NIpE3gmWj1iuS3E+G3+LYaIeA2IppGwpTpxk8QBUY+l5cczPQCiTacsg== X-Received: by 2002:a05:6a20:9386:b0:cc:d762:64a with SMTP id x6-20020a056a20938600b000ccd762064amr30716166pzh.8.1678443869569; Fri, 10 Mar 2023 02:24:29 -0800 (PST) From: Sam Li To: qemu-devel@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , qemu-block@nongnu.org, damien.lemoal@opensource.wdc.com, hare@suse.de, Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Fam Zheng , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , dmitry.fomichev@wdc.com, Thomas Huth , Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sam Li Subject: [PATCH v16 4/8] raw-format: add zone operations to pass through requests Date: Fri, 10 Mar 2023 18:23:59 +0800 Message-Id: <20230310102403.61347-5-faithilikerun@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230310102403.61347-1-faithilikerun@gmail.com> References: <20230310102403.61347-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::102a; envelope-from=faithilikerun@gmail.com; helo=mail-pj1-x102a.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: 1678443914211100003 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 | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/block/raw-format.c b/block/raw-format.c index 66783ed8e7..6e1b9394c8 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -317,6 +317,21 @@ raw_co_pdiscard(BlockDriverState *bs, int64_t offset, = int64_t bytes) return bdrv_co_pdiscard(bs->file, offset, bytes); } =20 +static int coroutine_fn GRAPH_RDLOCK +raw_co_zone_report(BlockDriverState *bs, int64_t offset, + unsigned int *nr_zones, + BlockZoneDescriptor *zones) +{ + return bdrv_co_zone_report(bs->file->bs, offset, nr_zones, zones); +} + +static int coroutine_fn GRAPH_RDLOCK +raw_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, + int64_t offset, int64_t len) +{ + return bdrv_co_zone_mgmt(bs->file->bs, op, offset, len); +} + static int64_t coroutine_fn GRAPH_RDLOCK raw_co_getlength(BlockDriverState *bs) { @@ -617,6 +632,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.39.2 From nobody Sun May 19 22:46:17 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=1678443906; cv=none; d=zohomail.com; s=zohoarc; b=OtqMD4G/pslEsHj3Q5YHsazqpae25R5Ci0SP78fOGDLab/WoWPNzZp26XVAzAnOheWB0VEog221i2mrE/CicZn6c9ztBz1CM6hG+RWLerNjist889WJfmj8n3n2qJtkQuqvQqT7zh45/90K5LTCt/lewzY0Lo3q1L43uQPhXgmg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678443906; 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=sd6ljlicDsYI4fnvkG+5cr+IU4uKMWOEEDAKptPOLME=; b=GIrLy0ycDCPeOUPY3F651mLwKGpkCCoiqgFC7z1aDU3TEjXwwyq+GgSpL0dVvw1AqAGhtmdD91U0Z/lw3+D7o/2urY9QpmadVgJEvcsxfvA+6Z6v4R1O6ghP4rf/rQ3iUf39t4nTBpspxK/lrrjxIV+HFDod+WBF93TZVfgqICQ= 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 1678443906362596.5331607249431; Fri, 10 Mar 2023 02:25:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1paZvh-00008b-5c; Fri, 10 Mar 2023 05:24:53 -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 1paZvX-0008Ba-KX; Fri, 10 Mar 2023 05:24:43 -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 1paZvR-0002Tz-45; Fri, 10 Mar 2023 05:24:39 -0500 Received: by mail-pl1-x62f.google.com with SMTP id a9so5041062plh.11; Fri, 10 Mar 2023 02:24:36 -0800 (PST) Received: from fedlinux.. ([106.84.129.9]) by smtp.gmail.com with ESMTPSA id f8-20020a63f748000000b005030113f46dsm1008719pgk.37.2023.03.10.02.24.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Mar 2023 02:24:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678443875; 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=sd6ljlicDsYI4fnvkG+5cr+IU4uKMWOEEDAKptPOLME=; b=gpX8rIWc+pZ83fShsxF0CeacSBCO988+JUZYz7hsGYJScvFyDZkvrTetwDvcVD4RBi 4hC92tRTdqOplW1yr7FrYvnLUHksCVaKg3dGS7qjE5WhFaa9sRh+f2rtK11jLnKScTcJ 0XfaxaX71qD6dWlK/FFCLo/nx12rAk3hLoqQ16kABPFEvJDugcsDhis3zyXd6QX3U6yW XY1K/vC6UNPgDQUwJyMuZnrJ2i+nLtSMbnDsDLxSVMr103p/sNy9M5KSnJGnekpQfn52 ONO8wiEKrri/40LtvH6H2eS9FI/RRm2Y0yOAfGbWbvwuj5ip0/8CwQHIVqpA25Ywo6p/ WtlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678443875; 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=sd6ljlicDsYI4fnvkG+5cr+IU4uKMWOEEDAKptPOLME=; b=g4Hv+j+3lb3kpRcM3+4pbDlSaXwuII7r6/iJg8QgHwcag+vd2vruR5zUALnmmAYunt nVtvOyTvcpkNDI1gt2I8kBR2pd2HLlMlZtPA5v9z1wr1YiwYSH4PCaW/JAKXqUDHfrWd kduENpryAg40pBlOTTfMKQoCGjTAp2+5pO4N+HRSm4hl7cFToeKRNcWYBvafs1dAxgpM Q/1ImFgwcrdw5Imq3bwIVqyX6C7PfiHHl+IVOO8KZ7tCn0XHDcVfZXipq8EeBKuLhG5o WrkRp4ZlLiwcZzvJeshhCjhQmHIicY8mJuOkf9Mb3OT7txfowIcmv5YRPr4RtbaspG3u /ERA== X-Gm-Message-State: AO0yUKWKLBs3ClY3ewZx8Puq/ORpD/m814h/B9nczjYz2a4A5qpz+m0A fWWrEG4TWvNy3UOYgRngQA/qun0VJZqpVaSfQn0= X-Google-Smtp-Source: AK7set/Wq+K1Nhk6VLnoRMeCj5FHZvh3YOmGfS6lsgMUqKdv/N2Oi4CwQkpCQTm4sBi45qi3ugbuZg== X-Received: by 2002:a05:6a21:6d9a:b0:be:a9c7:5d12 with SMTP id wl26-20020a056a216d9a00b000bea9c75d12mr27825293pzb.18.1678443874162; Fri, 10 Mar 2023 02:24:34 -0800 (PST) From: Sam Li To: qemu-devel@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , qemu-block@nongnu.org, damien.lemoal@opensource.wdc.com, hare@suse.de, Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Fam Zheng , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , dmitry.fomichev@wdc.com, Thomas Huth , Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sam Li Subject: [PATCH v16 5/8] config: add check to block layer Date: Fri, 10 Mar 2023 18:24:00 +0800 Message-Id: <20230310102403.61347-6-faithilikerun@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230310102403.61347-1-faithilikerun@gmail.com> References: <20230310102403.61347-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: 1678443908342100009 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 0dd604d0f6..4ebf7bbc90 100644 --- a/block.c +++ b/block.c @@ -7953,6 +7953,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 df9b9f1e30..2eceb250f1 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -776,6 +776,18 @@ static int raw_open_common(BlockDriverState *bs, QDict= *options, goto fail; } } +#ifdef CONFIG_BLKZONED + /* + * The kernel page cache does not reliably work for writes to SWR zones + * of zoned block device because it can not guarantee the order of wri= tes. + */ + if ((bs->bl.zoned !=3D BLK_Z_NONE) && + (!(s->open_flags & O_DIRECT))) { + error_setg(errp, "The driver supports zoned devices, and it requir= es " + "cache.direct=3Don, which was not specified."); + return -EINVAL; /* No host kernel page cache */ + } +#endif =20 if (S_ISBLK(st.st_mode)) { #ifdef __linux__ diff --git a/block/raw-format.c b/block/raw-format.c index 6e1b9394c8..72e23e7b55 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -621,6 +621,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 a3efb385e0..1bd2aef4d5 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.39.2 From nobody Sun May 19 22:46:17 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=1678443940; cv=none; d=zohomail.com; s=zohoarc; b=bSvToZh6IJs/d4mq++/eNPt+xbWo8t2FSvUzD3CUEnqURb/tsU9XJSVLWSD/KCTTz3tA8GUMVuvEjoQxvnquC9VT0BTidxgGNTUsv0XDlLPMdqT8YQ7HpZwLS1z9+cvqSgvQRNnBPVVvufunpAmdFh3/pk2LG8qhxSFGIpj6DWU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678443940; 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=sHpIFifiCkLYqwnJRAcbwyyCPXS0ckwTK55Q130o80g=; b=kcxndySXjbIFDzOqpQXNnU9upYKI3/ponO/iPEB85c96HAa7VbLNkYNbsGKb37zfJpSYUTywr5zYt4j2Cf4qem7TEIjSj3XXGalh6bbA5BuHs0qRLNpZse8M5JrjrX4xbnEmkbr70hstBzJCIG1t33fE68OiBISZHHUV2fkCeAE= 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 1678443940940892.3063165395073; Fri, 10 Mar 2023 02:25:40 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1paZvf-0008Tb-BX; Fri, 10 Mar 2023 05:24:51 -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 1paZva-0008Dd-I7; Fri, 10 Mar 2023 05:24:47 -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 1paZvX-0002WR-QD; Fri, 10 Mar 2023 05:24:45 -0500 Received: by mail-pj1-x1036.google.com with SMTP id u3-20020a17090a450300b00239db6d7d47so4727421pjg.4; Fri, 10 Mar 2023 02:24:40 -0800 (PST) Received: from fedlinux.. ([106.84.129.9]) by smtp.gmail.com with ESMTPSA id f8-20020a63f748000000b005030113f46dsm1008719pgk.37.2023.03.10.02.24.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Mar 2023 02:24:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678443879; 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=sHpIFifiCkLYqwnJRAcbwyyCPXS0ckwTK55Q130o80g=; b=eG9J5oP/nKY/zEZFBEPTPTDe09ncDQ8EkvV101FRyXj/67Opm1MdwHCuNqVrRuncYH 0youZTxGOnbSy8vyDWUs+JWVHAQ1bqtfAFjlpexeHmxcmOr0sbEU18ocOj41Tz1C4b11 n47bzmm/1xFkKJhnvpkhktAqaABmO8m/NJ+0gBNW1slli9yj2rI1Vm2Yon2VkJc/F14K SQUR6xqr8soAE7kCOav80sjht+0DjqOKNuFWNeQPJNj8Uok1JGjJFXwU5Im7i9IiJhB6 OiwP3LJeGEa//lONJEP5eZUxLL2Ko5Rl1Xt5ec4/0U+VJ4pbLFnFQId3TT2k30I/UZ0v BNgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678443879; 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=sHpIFifiCkLYqwnJRAcbwyyCPXS0ckwTK55Q130o80g=; b=OgOlPOvoYgJSsRhEb/9f4VWzbLxwXF/3UDHFKtjA+ltLyLyDDJgSZWyUAIIooVY45f kgEp6GvKl1IXldFkAQoxnqUuOr3R58hureQ00QHzeGChFn09GIT4YHqjDcr2J9+MXWWJ Qb55e4JERs+nUlBxPkPkZlPg7C/M9CND7lb/8NHpwqIL8zy+rh+ZmPt3LFbknBtwqjPL QiAEC1nSZXM2qGpiab22w00nBINuKaN0VNXEzXe2m2a2WfR3Ofeq4y0f3Ducb4lGEWEC ck1Atz/zPVFCQRPKZrwQV+pAs3m5NqRjwnaM3YN9/PkJbCDvXPJCfqMtn83CvvXLpa1p hiwA== X-Gm-Message-State: AO0yUKV2kxf3mgOOOdFftDGWOeU8QpcUjBXl+32D5dJGSU9EZyEgu3NI I+aHdiTnBWXWZdungxQN/0mgQCzTPfAPd1sN6H0= X-Google-Smtp-Source: AK7set9Kj4sBd7p/P24bVyU1R9h2WdJQMHOFgeY2vZ1Tq21B4WZImTZuGYPWfDvAhWiubdfbiXLQqA== X-Received: by 2002:a17:903:1103:b0:19e:8075:5545 with SMTP id n3-20020a170903110300b0019e80755545mr30156488plh.54.1678443878587; Fri, 10 Mar 2023 02:24:38 -0800 (PST) From: Sam Li To: qemu-devel@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , qemu-block@nongnu.org, damien.lemoal@opensource.wdc.com, hare@suse.de, Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Fam Zheng , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , dmitry.fomichev@wdc.com, Thomas Huth , Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sam Li Subject: [PATCH v16 6/8] qemu-iotests: test new zone operations Date: Fri, 10 Mar 2023 18:24:01 +0800 Message-Id: <20230310102403.61347-7-faithilikerun@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230310102403.61347-1-faithilikerun@gmail.com> References: <20230310102403.61347-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: 1678443942597100003 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.39.2 From nobody Sun May 19 22:46:17 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=1678443921; cv=none; d=zohomail.com; s=zohoarc; b=KElU3i6iRWHvgsBFtCHFqPTIc0XiOACm4xtLGDC9IkQnwgEWMmOeUN0YJdLQURtaJqjnP2qK6BTZxOzrkHFnKxoAgVuVJ+/ZDOUEi6EZK2XwSbrSwIXUIl2Gt54evtvtEty1ytfCWHaNV5r0SB2GSOBq54kmuhxwUiGLrO3BNnw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678443921; 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=QG+AAXzepHKbYqtRZGp9hrm1xZfMYJgGYoJhT6HWfHQ=; b=GEZssKZtoV/5fveyhgjijJCo8r0ZrRvRzOOEEqbUV9DTuC11T4Xf05uBr0if2Hg/X5vdVq6rMS+zi1HpgtDyqAsi+MCQNcH6TKoXxiXrCkGW4BRIJe102lz4q5E3w4Xu3cmRcIe21SR+pKEMSWtH2eaHa6zwKONbsm5RY7jsu2I= 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 1678443921569561.7699094528847; Fri, 10 Mar 2023 02:25:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1paZvf-0008Ur-Te; Fri, 10 Mar 2023 05:24:51 -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 1paZvc-0008E2-27; Fri, 10 Mar 2023 05:24:49 -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 1paZva-0002XK-Js; Fri, 10 Mar 2023 05:24:47 -0500 Received: by mail-pj1-x1036.google.com with SMTP id qa18-20020a17090b4fd200b0023750b675f5so9308088pjb.3; Fri, 10 Mar 2023 02:24:44 -0800 (PST) Received: from fedlinux.. ([106.84.129.9]) by smtp.gmail.com with ESMTPSA id f8-20020a63f748000000b005030113f46dsm1008719pgk.37.2023.03.10.02.24.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Mar 2023 02:24:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678443883; 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=QG+AAXzepHKbYqtRZGp9hrm1xZfMYJgGYoJhT6HWfHQ=; b=E/ub2t/C6YkAvlcGcsEdP11Q5roNvVS6nWNUIA5seUmzqx4EmD5JVrSckCpsz+QodN +jkRsKYe2YPT7Td3NILHvs1e/gJBUJteolaYGBjmCkyR3IemfWV8URMhlbM6JfWm2+7m zOZQnw2VZBNSjg+ZturyrgaTyBcWeC6kttURomYzjx63Z3IMeGQpQhx885h/QZd7CXk4 VVKn8qhDDLC/8Rgb+6Imp6I3FXVd3sDg/CGssh51I7geRIr6B9fLwyCXM0yVyqtPi2mJ 19T04eN/5VstR5wrXo81e/S8ItAr4DppaVQc0Ec8t5Ez1fUQeeXCTY0a2okc8sxzLdyO xSXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678443883; 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=QG+AAXzepHKbYqtRZGp9hrm1xZfMYJgGYoJhT6HWfHQ=; b=lZ9Vi9uPk1GVpU3BFQ1zlrWQAQPh332lAM10pArbPlT3Ebln5QBZF7A5Dl2fS0htp+ TVtpOU94XPxamHnMamUvrsdeJct024e3+tXoOtRTEjGgUPZXfi9YaKB+cdasvFLmrZtZ CETM3jXPzRQ/bHmC8xsDg6aDaD2q/AEFvC7F5jrZm/zMYXfYlBFyM6bFJRj54ZLZPptZ 2zWvTVXH4nBi4LK9fo11D8O7qBGh024A8GfZTbP6XcgxRmMBpq5dJ0oaIYdai4YGRvcs 1Y+TIqqiTQMBEqYkVtQrogKAXj/HY1snxpHkgoZ85VeZIu6hj+UPoexqM8fFtqpTEN5W /wmw== X-Gm-Message-State: AO0yUKXmO0ZP6SlEHQVUsCb81WIOcDzlFC/3yYunh/7+SdN38PjSDLGL UOTP7eOGdO1hNl/I9Z5hnSg1p5Cn0uJ8iZGQByQ= X-Google-Smtp-Source: AK7set+cuA40IYZ2/ov237l6gMdwaoYKqVebEQ7jnjNHGWYzYcCo66jIFib+unbg3se4e7U7qDFRlw== X-Received: by 2002:a05:6a20:7d8b:b0:cc:39c5:1241 with SMTP id v11-20020a056a207d8b00b000cc39c51241mr34010794pzj.16.1678443883179; Fri, 10 Mar 2023 02:24:43 -0800 (PST) From: Sam Li To: qemu-devel@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , qemu-block@nongnu.org, damien.lemoal@opensource.wdc.com, hare@suse.de, Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Fam Zheng , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , dmitry.fomichev@wdc.com, Thomas Huth , Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sam Li Subject: [PATCH v16 7/8] block: add some trace events for new block layer APIs Date: Fri, 10 Mar 2023 18:24:02 +0800 Message-Id: <20230310102403.61347-8-faithilikerun@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230310102403.61347-1-faithilikerun@gmail.com> References: <20230310102403.61347-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: 1678443922376100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Sam Li Reviewed-by: Stefan Hajnoczi Reviewed-by: Dmitry Fomichev --- 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 2eceb250f1..563acc76ae 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -3256,6 +3256,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, @@ -3334,6 +3335,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.39.2 From nobody Sun May 19 22:46:17 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=1678443933; cv=none; d=zohomail.com; s=zohoarc; b=bw3+e18N0fGbgF+6OwNnq+YtWfKPVGEHi6NTRrTUU0RidX2/BQiZhL/V6c6MfmfjGR7/SVpDd/HCRourwz2WgTN4uKmndya/mnCuDUkag5mWWgHIfbt3z8rSqagFqBkS8wBnjAX+TdLX+adWTkCrOUva2BgjCCQNwscUrxCKmNI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678443933; 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=4E8gndD2asyocPN155ZzqxwgK2K7nT15tzIEILi0sRQ=; b=DINnOlfyxJHja1BuI7ReQeMexF+IEtb+BYSyCd6qi+DgOVc1k2cZjE0nlVlwiDcP7p0Kcj5y5A8eMJ7m3Ed4sO6Ht2J3I3ms80SCMAWWsKwEXpcWoFr8qqfnSxhNsloD6pNSrxGFFx50sg790PTnacLqeNMugn4wi7qL5pfB3I8= 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 1678443932994215.3578164587924; Fri, 10 Mar 2023 02:25:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1paZvm-0000Ba-Vs; Fri, 10 Mar 2023 05:24:59 -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 1paZvg-0008WQ-BC; Fri, 10 Mar 2023 05:24:52 -0500 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1paZve-0002Y1-Hq; Fri, 10 Mar 2023 05:24:52 -0500 Received: by mail-pl1-x632.google.com with SMTP id a2so5070152plm.4; Fri, 10 Mar 2023 02:24:49 -0800 (PST) Received: from fedlinux.. ([106.84.129.9]) by smtp.gmail.com with ESMTPSA id f8-20020a63f748000000b005030113f46dsm1008719pgk.37.2023.03.10.02.24.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Mar 2023 02:24:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678443888; 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=4E8gndD2asyocPN155ZzqxwgK2K7nT15tzIEILi0sRQ=; b=fKRK/IhLxG+8jjdvjDPwMP88bVUEtdQalHQvuDri2GktdKL0XxLVDDYooky0y7HiRx GEmzT4Tiua06YbYt0fl3NfYNz4NcFmla0PiLBUale8tHoj/Wk43slY1dnLhHS7YFtW3M lPxehkaY1V3VH2OKvBcE7VIouyoPHLg320nRzmZDtlkqKn6sg5F8uz/qQDG6gauLZ5HS XDjcv1ve1oPcybXuxV1+rWWwEejs8skKBgbGTZoZ/BcVWE88FxDC0vxoAUhg8V99x4II Mw7HgyIdQB9StQ36WhIHUBzjeEeDmu+9wBez+CjiGpmtjBcwKr3UnKK+7QKSsrK9wEQQ nOZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678443888; 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=4E8gndD2asyocPN155ZzqxwgK2K7nT15tzIEILi0sRQ=; b=wTAstIV01h5RtiYY597NG8521tHRsP3jWkRp17Im7YCYXx7CfAdnmXoonm+Vmp29u4 FFpDRsB6knIM14jgYQVZ40Mnj2EdhH82exU/7syVOj1webxDlSeH8lUPKSsTuXZfQGQ+ 083GcuDyJoM7BSMqSwyPVQJ/CAtEwSSpu+Tg4kFV9lGwD/d7O0a/cn+VZAR10BKnEBgg VD9ooQqqSm3hMyJh9fuH4nFRVBjdaNDeLFLmo4j9XMFF31HwxlMSR/N9YtpZRNJIYB8D gsDcvYqakH/xvC/faFC1UYnKifFlLtL41NBZWX7E+YwSKmvnBhsOYgK9wNrlyr0t+mAp 0XVg== X-Gm-Message-State: AO0yUKVgCo72/UsU3679TBUGB9bK714kpgKqoy04jUHi/wTPFnYJ2Wxa dxrC7zM8sHUJOIyRO1wD6YYo0/atRQPY7dhruXk= X-Google-Smtp-Source: AK7set/p/d+uhMUQqIxpnt3ynkAy2kvRu/xGdTM0/AHC7DiisCKMsF/2818tq6nF5pKPFb3g3ZOTyg== X-Received: by 2002:a17:902:d486:b0:19d:1230:439b with SMTP id c6-20020a170902d48600b0019d1230439bmr30421070plg.63.1678443887793; Fri, 10 Mar 2023 02:24:47 -0800 (PST) From: Sam Li To: qemu-devel@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , qemu-block@nongnu.org, damien.lemoal@opensource.wdc.com, hare@suse.de, Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Fam Zheng , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , dmitry.fomichev@wdc.com, Thomas Huth , Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sam Li Subject: [PATCH v16 8/8] docs/zoned-storage: add zoned device documentation Date: Fri, 10 Mar 2023 18:24:03 +0800 Message-Id: <20230310102403.61347-9-faithilikerun@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230310102403.61347-1-faithilikerun@gmail.com> References: <20230310102403.61347-1-faithilikerun@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=faithilikerun@gmail.com; helo=mail-pl1-x632.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: 1678443934548100003 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..6a36133e51 --- /dev/null +++ b/docs/devel/zoned-storage.rst @@ -0,0 +1,43 @@ +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +zoned-storage +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Zoned Block Devices (ZBDs) divide the LBA space into block regions called = zones +that are larger than the LBA size. They can only allow sequential writes, = which +can reduce write amplification in SSDs, and potentially lead to higher +throughput and increased capacity. More details about ZBDs can be found at: + +https://zonedstorage.io/docs/introduction/zoned-storage + +1. Block layer APIs for zoned storage +------------------------------------- +QEMU block layer supports three zoned storage models: +- BLK_Z_HM: The host-managed zoned model only allows sequential writes acc= ess +to zones. It supports ZBD-specific I/O commands that can be used by a host= to +manage the zones of a device. +- BLK_Z_HA: The host-aware zoned model allows random write operations in +zones, making it backward compatible with regular block devices. +- BLK_Z_NONE: The non-zoned model has no zones support. It includes both +regular and drive-managed ZBD devices. ZBD-specific I/O commands are not +supported. + +The block device information resides inside BlockDriverState. QEMU uses +BlockLimits struct(BlockDriverState::bl) that is continuously accessed by = the +block layer while processing I/O requests. A BlockBackend has a root point= er to +a BlockDriverState graph(for example, raw format on top of file-posix). The +zoned storage information can be propagated from the leaf BlockDriverState= all +the way up to the BlockBackend. If the zoned storage model in file-posix is +set to BLK_Z_HM, then block drivers will declare support for zoned host de= vice. + +The block layer APIs support commands needed for zoned storage devices, +including report zones, four zone operations, and zone append. + +2. Emulating zoned storage controllers +-------------------------------------- +When the BlockBackend's BlockLimits model reports a zoned storage device, = users +like the virtio-blk emulation or the qemu-io-cmds.c utility can use block = layer +APIs for zoned storage emulation or testing. + +For example, to test zone_report on a null_blk device using qemu-io is: +$ path/to/qemu-io --image-opts -n driver=3Dhost_device,filename=3D/dev/nul= lb0 +-c "zrp offset nr_zones" diff --git a/docs/system/qemu-block-drivers.rst.inc b/docs/system/qemu-bloc= k-drivers.rst.inc index dfe5d2293d..105cb9679c 100644 --- a/docs/system/qemu-block-drivers.rst.inc +++ b/docs/system/qemu-block-drivers.rst.inc @@ -430,6 +430,12 @@ Hard disks you may corrupt your host data (use the ``-snapshot`` command line option or modify the device permissions accordingly). =20 +Zoned block devices + Zoned block devices can be passed through to the guest if the emulated s= torage + controller supports zoned storage. Use ``--blockdev host_device, + node-name=3Ddrive0,filename=3D/dev/nullb0,cache.direct=3Don`` to pass th= rough + ``/dev/nullb0`` as ``drive0``. + Windows ^^^^^^^ =20 --=20 2.39.2