From nobody Sat May 18 09:01:38 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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1667122481; cv=none; d=zohomail.com; s=zohoarc; b=GilIl0ndx/Hb/o7/p4kEmYAjnj05g3k6sXpKOac8Ab0B1uPiQH58p9xSDfGrC7OmwGbrbkYmIATVNhWeb+09QKtgXhf66SaCRePYmbs+m7WzO7Vxndqy2rruFTEft3/Ccvhn3mhFuNRotpLusM7+K5SERvkpjVQoMM+vUbKy7kk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667122481; 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=wuWrzcyOarkyOpTUC6Ui2WY9KWls5fEE4N4lW+GvR70=; b=QKVhJLrpQE0DVUu9sBhvSVdE3fzXIEFd+HGfOp3KpAceS9qfTylTCQGm+9M4m3+aJ2e5RRUT5+1+Yl8VmaZsAkzqAZawOlgGelHDQKwjlaGU7aXyUu0jXtksCLMEHL/GJ37IBzY5YUm3AhZwjGNnqAyh3ha19EpCnMiJ26s7ZVc= 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+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 1667122481756104.85170812239062; Sun, 30 Oct 2022 02:34:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1op4gv-0003w6-Al; Sun, 30 Oct 2022 05:33:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1op4gt-0003vv-QR; Sun, 30 Oct 2022 05:33:16 -0400 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1op4gs-0000kj-0B; Sun, 30 Oct 2022 05:33:15 -0400 Received: by mail-pg1-x536.google.com with SMTP id q1so8353390pgl.11; Sun, 30 Oct 2022 02:33:13 -0700 (PDT) Received: from fedora.. ([112.44.202.248]) by smtp.gmail.com with ESMTPSA id 1-20020a17090a0d4100b00205db4ff6dfsm2113445pju.46.2022.10.30.02.33.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Oct 2022 02:33:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wuWrzcyOarkyOpTUC6Ui2WY9KWls5fEE4N4lW+GvR70=; b=bgV4WIYHXuiO5umP+VMDX3bcGczLv+c+RwyoSu2Be3resKndNj3qiLoBHy7P+uBmyw bz1LCwCQSYGpqZhOSuQJ0BA0WSRs4fl+yxQpzus2nSeJuGlikQlv5i0eTIJ8uI7lxhgX JhszpOluo63p7nTgyiwtc1ZcDQ9gO0vgnNq2uoAQ2JpT27mg8+zvLw6QkbEhBsNIO8mZ ZcbKtpgVZrrSjA5E1JnQvkV90x71NvD6kXIwFbOjrtBVOKU9vwMD73cZ80uXS1Nxiw0G z/qrncM2lZIxMNKnyuNCakVA4GISkbW83zeP1/cRAPd8p2USyEVPaobymVJsTHEgDuVM jwWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wuWrzcyOarkyOpTUC6Ui2WY9KWls5fEE4N4lW+GvR70=; b=OD9Vg1tzWWfnyV7UUQlxygRpSlFLB7AiXy01GM5iJhA2POKeQzL9L2XF9LViG8LfIJ JxT/h3W9xPhRSjS34cXZBqHvITLg4OcnGFnHYo7zDTxJERB26fjrLlKWUU27B0TKlh0X ha45PWl2Ti4AZ6GDdvOevhfGQApfJ7R/wmO4JYH8H9THKCqaX9QRIHl0iL7gz/pukuzD KhwAsPb1IkYuNMBv6GZeG5nzjylypUSBbUa9Nlf2KgGn0RPTQzhvZCQg3dH7smHsJe89 1/RNAYoMGxDMbVHbeoZ7DOkVT2zUzeE+2PorGG2iLonaPXdcsHqIe3SgtPmnTSLQKX9m 0uUA== X-Gm-Message-State: ACrzQf2Ldwr4MTZA1ykpxu3cyakaqCQeddSyFO5l2tPE/Etv8qZm9amk nkb3P7T1oF0M/E2aljoAPJC/O087yb1KESrY X-Google-Smtp-Source: AMsMyM7CqVFt3NlgL+hnTpeitpFRngtobuKIUZP/onOxhKAcjwDM5NeNFrIafas9PLfp2gU0Nnmz5g== X-Received: by 2002:aa7:9152:0:b0:565:895b:e524 with SMTP id 18-20020aa79152000000b00565895be524mr8266378pfi.85.1667122390433; Sun, 30 Oct 2022 02:33:10 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: Raphael Norwitz , stefanha@redhat.com, damien.lemoal@opensource.wdc.com, "Michael S. Tsirkin" , Kevin Wolf , hare@suse.de, Hanna Reitz , qemu-block@nongnu.org, dmitry.fomichev@wdc.com, Sam Li Subject: [RFC v4 1/3] include: update virtio_blk headers Date: Sun, 30 Oct 2022 05:32:40 -0400 Message-Id: <20221030093242.208839-2-faithilikerun@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221030093242.208839-1-faithilikerun@gmail.com> References: <20221030093242.208839-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::536; envelope-from=faithilikerun@gmail.com; helo=mail-pg1-x536.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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1667122483533100002 Content-Type: text/plain; charset="utf-8" Use scripts/update-linux-headers.sh to update virtio-blk headers from Dmitry's "virtio-blk:add support for zoned block devices" Linux patches. Signed-off-by: Sam Li Reviewed-by: Stefan Hajnoczi Reviewed-by: Dmitry Fomichev --- include/standard-headers/linux/virtio_blk.h | 158 ++++++++++++++++++-- 1 file changed, 142 insertions(+), 16 deletions(-) diff --git a/include/standard-headers/linux/virtio_blk.h b/include/standard= -headers/linux/virtio_blk.h index 2dcc90826a..3744e4da1b 100644 --- a/include/standard-headers/linux/virtio_blk.h +++ b/include/standard-headers/linux/virtio_blk.h @@ -25,10 +25,10 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY W= AY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ -#include "standard-headers/linux/types.h" -#include "standard-headers/linux/virtio_ids.h" -#include "standard-headers/linux/virtio_config.h" -#include "standard-headers/linux/virtio_types.h" +#include +#include +#include +#include =20 /* Feature bits */ #define VIRTIO_BLK_F_SIZE_MAX 1 /* Indicates maximum segment size */ @@ -40,6 +40,8 @@ #define VIRTIO_BLK_F_MQ 12 /* support more than one vq */ #define VIRTIO_BLK_F_DISCARD 13 /* DISCARD is supported */ #define VIRTIO_BLK_F_WRITE_ZEROES 14 /* WRITE ZEROES is supported */ +#define VIRTIO_BLK_F_SECURE_ERASE 16 /* Secure Erase is supported */ +#define VIRTIO_BLK_F_ZONED 17 /* Zoned block device */ =20 /* Legacy feature bits */ #ifndef VIRTIO_BLK_NO_LEGACY @@ -47,8 +49,10 @@ #define VIRTIO_BLK_F_SCSI 7 /* Supports scsi command passthru */ #define VIRTIO_BLK_F_FLUSH 9 /* Flush command supported */ #define VIRTIO_BLK_F_CONFIG_WCE 11 /* Writeback mode available in config */ +#ifndef __KERNEL__ /* Old (deprecated) name for VIRTIO_BLK_F_FLUSH. */ #define VIRTIO_BLK_F_WCE VIRTIO_BLK_F_FLUSH +#endif #endif /* !VIRTIO_BLK_NO_LEGACY */ =20 #define VIRTIO_BLK_ID_BYTES 20 /* ID string length */ @@ -63,8 +67,8 @@ struct virtio_blk_config { /* geometry of the device (if VIRTIO_BLK_F_GEOMETRY) */ struct virtio_blk_geometry { __virtio16 cylinders; - uint8_t heads; - uint8_t sectors; + __u8 heads; + __u8 sectors; } geometry; =20 /* block size of device (if VIRTIO_BLK_F_BLK_SIZE) */ @@ -72,17 +76,17 @@ struct virtio_blk_config { =20 /* the next 4 entries are guarded by VIRTIO_BLK_F_TOPOLOGY */ /* exponent for physical block per logical block. */ - uint8_t physical_block_exp; + __u8 physical_block_exp; /* alignment offset in logical blocks. */ - uint8_t alignment_offset; + __u8 alignment_offset; /* minimum I/O size without performance penalty in logical blocks. */ __virtio16 min_io_size; /* optimal sustained I/O size in logical blocks. */ __virtio32 opt_io_size; =20 /* writeback mode (if VIRTIO_BLK_F_CONFIG_WCE) */ - uint8_t wce; - uint8_t unused; + __u8 wce; + __u8 unused; =20 /* number of vqs, only available when VIRTIO_BLK_F_MQ is set */ __virtio16 num_queues; @@ -116,10 +120,35 @@ struct virtio_blk_config { * Set if a VIRTIO_BLK_T_WRITE_ZEROES request may result in the * deallocation of one or more of the sectors. */ - uint8_t write_zeroes_may_unmap; + __u8 write_zeroes_may_unmap; =20 - uint8_t unused1[3]; -} QEMU_PACKED; + __u8 unused1[3]; + + /* the next 3 entries are guarded by VIRTIO_BLK_F_SECURE_ERASE */ + /* + * The maximum secure erase sectors (in 512-byte sectors) for + * one segment. + */ + __virtio32 max_secure_erase_sectors; + /* + * The maximum number of secure erase segments in a + * secure erase command. + */ + __virtio32 max_secure_erase_seg; + /* Secure erase commands must be aligned to this number of sectors. */ + __virtio32 secure_erase_sector_alignment; + + /* Zoned block device characteristics (if VIRTIO_BLK_F_ZONED) */ + struct virtio_blk_zoned_characteristics { + __virtio32 zone_sectors; + __virtio32 max_open_zones; + __virtio32 max_active_zones; + __virtio32 max_append_sectors; + __virtio32 write_granularity; + __u8 model; + __u8 unused2[3]; + } zoned; +} __attribute__((packed)); =20 /* * Command types @@ -153,6 +182,30 @@ struct virtio_blk_config { /* Write zeroes command */ #define VIRTIO_BLK_T_WRITE_ZEROES 13 =20 +/* Secure erase command */ +#define VIRTIO_BLK_T_SECURE_ERASE 14 + +/* Zone append command */ +#define VIRTIO_BLK_T_ZONE_APPEND 15 + +/* Report zones command */ +#define VIRTIO_BLK_T_ZONE_REPORT 16 + +/* Open zone command */ +#define VIRTIO_BLK_T_ZONE_OPEN 18 + +/* Close zone command */ +#define VIRTIO_BLK_T_ZONE_CLOSE 20 + +/* Finish zone command */ +#define VIRTIO_BLK_T_ZONE_FINISH 22 + +/* Reset zone command */ +#define VIRTIO_BLK_T_ZONE_RESET 24 + +/* Reset All zones command */ +#define VIRTIO_BLK_T_ZONE_RESET_ALL 26 + #ifndef VIRTIO_BLK_NO_LEGACY /* Barrier before this op. */ #define VIRTIO_BLK_T_BARRIER 0x80000000 @@ -172,17 +225,83 @@ struct virtio_blk_outhdr { __virtio64 sector; }; =20 +/* + * Supported zoned device models. + */ + +/* Regular block device */ +#define VIRTIO_BLK_Z_NONE 0 +/* Host-managed zoned device */ +#define VIRTIO_BLK_Z_HM 1 +/* Host-aware zoned device */ +#define VIRTIO_BLK_Z_HA 2 + +/* + * Zone descriptor. A part of VIRTIO_BLK_T_ZONE_REPORT command reply. + */ +struct virtio_blk_zone_descriptor { + /* Zone capacity */ + __virtio64 z_cap; + /* The starting sector of the zone */ + __virtio64 z_start; + /* Zone write pointer position in sectors */ + __virtio64 z_wp; + /* Zone type */ + __u8 z_type; + /* Zone state */ + __u8 z_state; + __u8 reserved[38]; +}; + +struct virtio_blk_zone_report { + __virtio64 nr_zones; + __u8 reserved[56]; + struct virtio_blk_zone_descriptor zones[]; +}; + +/* + * Supported zone types. + */ + +/* Conventional zone */ +#define VIRTIO_BLK_ZT_CONV 1 +/* Sequential Write Required zone */ +#define VIRTIO_BLK_ZT_SWR 2 +/* Sequential Write Preferred zone */ +#define VIRTIO_BLK_ZT_SWP 3 + +/* + * Zone states that are available for zones of all types. + */ + +/* Not a write pointer (conventional zones only) */ +#define VIRTIO_BLK_ZS_NOT_WP 0 +/* Empty */ +#define VIRTIO_BLK_ZS_EMPTY 1 +/* Implicitly Open */ +#define VIRTIO_BLK_ZS_IOPEN 2 +/* Explicitly Open */ +#define VIRTIO_BLK_ZS_EOPEN 3 +/* Closed */ +#define VIRTIO_BLK_ZS_CLOSED 4 +/* Read-Only */ +#define VIRTIO_BLK_ZS_RDONLY 13 +/* Full */ +#define VIRTIO_BLK_ZS_FULL 14 +/* Offline */ +#define VIRTIO_BLK_ZS_OFFLINE 15 + /* Unmap this range (only valid for write zeroes command) */ #define VIRTIO_BLK_WRITE_ZEROES_FLAG_UNMAP 0x00000001 =20 /* Discard/write zeroes range for each request. */ struct virtio_blk_discard_write_zeroes { /* discard/write zeroes start sector */ - uint64_t sector; + __le64 sector; /* number of discard/write zeroes sectors */ - uint32_t num_sectors; + __le32 num_sectors; /* flags for this range */ - uint32_t flags; + __le32 flags; }; =20 #ifndef VIRTIO_BLK_NO_LEGACY @@ -198,4 +317,11 @@ struct virtio_scsi_inhdr { #define VIRTIO_BLK_S_OK 0 #define VIRTIO_BLK_S_IOERR 1 #define VIRTIO_BLK_S_UNSUPP 2 + +/* Error codes that are specific to zoned block devices */ +#define VIRTIO_BLK_S_ZONE_INVALID_CMD 3 +#define VIRTIO_BLK_S_ZONE_UNALIGNED_WP 4 +#define VIRTIO_BLK_S_ZONE_OPEN_RESOURCE 5 +#define VIRTIO_BLK_S_ZONE_ACTIVE_RESOURCE 6 + #endif /* _LINUX_VIRTIO_BLK_H */ --=20 2.38.1 From nobody Sat May 18 09:01:38 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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1667122457; cv=none; d=zohomail.com; s=zohoarc; b=XR8wli40clTv0sb17PIvMeNTRusLTjPhAnk/A/Q4ezyDE5aJaDsrUwOFXl+3h1an4dn2upDcOAGnICPf+fAR0KPrBIe3IqR/ZmPqpK2c8Dd4hr7/AnQRBHNX19ogp4uT4ci0nexRSMyj9uF6Lu7w9LjWdKSvhyFrr+h2ueDqDtY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667122457; 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=eDw3cznZc0f+eBouF5z7mgqI44gifZLBNWO26L9o9pI=; b=Ce2a55muU4wDKyBloRUVqR4m/9o74ZDPIjtyHy+CuR3KCFec1bWu3hLw8Yi/tX5PMT5tDP4OHh7VNw2/2iEVXGyg1v4107I0QOvEbEYD4/1cpo8rZ96Q+/JGNughVx+Mub1IDOgwR6kTD6rBPjp3FPDhIYWTW4BbgtOmgOK5/kA= 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+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 1667122457933858.0434792378334; Sun, 30 Oct 2022 02:34:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1op4h3-0003xF-UD; Sun, 30 Oct 2022 05:33:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1op4h0-0003wo-Dr; Sun, 30 Oct 2022 05:33:22 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1op4gy-0000mD-0s; Sun, 30 Oct 2022 05:33:22 -0400 Received: by mail-pl1-x631.google.com with SMTP id l2so8377551pld.13; Sun, 30 Oct 2022 02:33:19 -0700 (PDT) Received: from fedora.. ([112.44.202.248]) by smtp.gmail.com with ESMTPSA id 1-20020a17090a0d4100b00205db4ff6dfsm2113445pju.46.2022.10.30.02.33.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Oct 2022 02:33:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eDw3cznZc0f+eBouF5z7mgqI44gifZLBNWO26L9o9pI=; b=g3v+wUyghytDZKDVUEOOTaxSE+89WMKAHiiNTsc7ckMXAQBiMSv1TiBgCin/Yp4Nik U9aQQq0Ns1sZWJ6cRbd0TsHxDb5Tth6aslrPjhkrfyWZQtuRD9AUh+pYDsNxCIVKHB5T Q8ZwJqAA5TD7rtswg34b3ID9Mq0wpoDGJa9nrLORIZkhgLqPo65wbyuAMwYcrdeJu72i S7Cds6SVuBafjFcNdR+C0i1vQu+50ebdRqxISiuqp5ZXjcwJJ+uoOItdevfoTX+n1cQ7 KUlyzZ4mvYLCBjhq3OHdgIFQY9AIcNvfy68RQr2cHuuToZsiRP2p05plx3dI+ubJmsil mx5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eDw3cznZc0f+eBouF5z7mgqI44gifZLBNWO26L9o9pI=; b=OFA7mRIZ4nQGy3RqPIY7+mJtglBr6Z0ehbGSV/BzYh5Mta8D/dtCV8bUbfBse0xZIv WzJd/9EeogGLOOcD0hNmUSkgF7CXXOfanRM4OFVeV6MRJdkavweb7bkqeQ4xjGm6rhUL p5HZcB3HmNfZhytrIzjAttmEFTQHjJAyaqJUoTB6SxOy/TUZGFFtmZVwqW7k2dS9pm7K LVoRegLs0q35FswganT277Qyxz/goj1QCI64oERE07Q/f4XldwDSyIv3irjp5G+I0kwN 5DU0rG4ISJ+likjb/knfVV5fdJknVipxQ5f5SImPa+nsqyHbbI22HTF2z7uaazhAlFBh SO3Q== X-Gm-Message-State: ACrzQf2ZGkcMM4XELP3Dg+ajUrVVwVbQfAYu0iSR+Eo5rJNdi+/1hKqg unC+oly/htnFZBLAQ30/0+hyR9QuzKsbnhL6 X-Google-Smtp-Source: AMsMyM7hOWAH8hlTH2bfshqUxpp1DVnbNppAUksyF8asxns9+QPbIyG+uGQQ5H/Gof0SyjJBiPr8dQ== X-Received: by 2002:a17:902:aa94:b0:183:f6ff:f5ba with SMTP id d20-20020a170902aa9400b00183f6fff5bamr8418109plr.81.1667122397796; Sun, 30 Oct 2022 02:33:17 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: Raphael Norwitz , stefanha@redhat.com, damien.lemoal@opensource.wdc.com, "Michael S. Tsirkin" , Kevin Wolf , hare@suse.de, Hanna Reitz , qemu-block@nongnu.org, dmitry.fomichev@wdc.com, Sam Li Subject: [RFC v4 2/3] virtio-blk: add zoned storage emulation for zoned devices Date: Sun, 30 Oct 2022 05:32:41 -0400 Message-Id: <20221030093242.208839-3-faithilikerun@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221030093242.208839-1-faithilikerun@gmail.com> References: <20221030093242.208839-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=faithilikerun@gmail.com; helo=mail-pl1-x631.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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1667122459688100011 Content-Type: text/plain; charset="utf-8" This patch extends virtio-blk emulation to handle zoned device commands by calling the new block layer APIs to perform zoned device I/O on behalf of the guest. It supports Report Zone, four zone oparations (open, close, finish, reset), and Append Zone. The VIRTIO_BLK_F_ZONED feature bit will only be set if the host does support zoned block devices. Regular block devices(conventional zones) will not be set. The guest os can use blktests, fio to test those commands on zoned devices. Furthermore, using zonefs to test zone append write is also supported. Signed-off-by: Sam Li --- hw/block/virtio-blk-common.c | 2 + hw/block/virtio-blk.c | 387 +++++++++++++++++++++++++++++++++++ 2 files changed, 389 insertions(+) diff --git a/hw/block/virtio-blk-common.c b/hw/block/virtio-blk-common.c index ac52d7c176..e2f8e2f6da 100644 --- a/hw/block/virtio-blk-common.c +++ b/hw/block/virtio-blk-common.c @@ -29,6 +29,8 @@ static const VirtIOFeature feature_sizes[] =3D { .end =3D endof(struct virtio_blk_config, discard_sector_alignment)}, {.flags =3D 1ULL << VIRTIO_BLK_F_WRITE_ZEROES, .end =3D endof(struct virtio_blk_config, write_zeroes_may_unmap)}, + {.flags =3D 1ULL << VIRTIO_BLK_F_ZONED, + .end =3D endof(struct virtio_blk_config, zoned)}, {} }; =20 diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 8131ec2dbc..4f3625840a 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -26,6 +26,9 @@ #include "hw/virtio/virtio-blk.h" #include "dataplane/virtio-blk.h" #include "scsi/constants.h" +#if defined(CONFIG_BLKZONED) +#include +#endif #ifdef __linux__ # include #endif @@ -592,6 +595,332 @@ err: return err_status; } =20 +typedef struct ZoneCmdData { + VirtIOBlockReq *req; + union { + struct { + unsigned int nr_zones; + BlockZoneDescriptor *zones; + } zone_report_data; + struct { + int64_t offset; + } zone_append_data; + }; +} ZoneCmdData; + +/* + * check zoned_request: error checking before issuing requests. If all che= cks + * passed, return true. + * append: true if only zone append requests issued. + */ +static bool check_zoned_request(VirtIOBlock *s, int64_t offset, int64_t le= n, + bool append, uint8_t *status) { + BlockDriverState *bs =3D blk_bs(s->blk); + int index =3D offset / bs->bl.zone_size; + + if (offset < 0 || len < 0 || offset > (bs->total_sectors << BDRV_SECTO= R_BITS) - len) { + *status =3D VIRTIO_BLK_S_ZONE_INVALID_CMD; + return false; + } + + if (!virtio_has_feature(s->host_features, VIRTIO_BLK_F_ZONED)) { + *status =3D VIRTIO_BLK_S_UNSUPP; + return false; + } + + if (append) { + if ((offset % bs->bl.write_granularity) !=3D 0) { + *status =3D VIRTIO_BLK_S_ZONE_UNALIGNED_WP; + return false; + } + + if (BDRV_ZT_IS_CONV(bs->bl.wps->wp[index])) { + *status =3D VIRTIO_BLK_S_ZONE_INVALID_CMD; + return false; + } + + if (len / 512 > bs->bl.max_append_sectors) { + if (bs->bl.max_append_sectors =3D=3D 0) { + *status =3D VIRTIO_BLK_S_UNSUPP; + } else { + *status =3D VIRTIO_BLK_S_ZONE_INVALID_CMD; + } + return false; + } + } + return true; +} + +static void virtio_blk_zone_report_complete(void *opaque, int ret) +{ + ZoneCmdData *data =3D opaque; + VirtIOBlockReq *req =3D data->req; + VirtIOBlock *s =3D req->dev; + VirtIODevice *vdev =3D VIRTIO_DEVICE(req->dev); + struct iovec *in_iov =3D req->elem.in_sg; + unsigned in_num =3D req->elem.in_num; + int64_t zrp_size, n, j =3D 0; + int64_t nz =3D data->zone_report_data.nr_zones; + int8_t err_status =3D VIRTIO_BLK_S_OK; + + if (ret) { + err_status =3D VIRTIO_BLK_S_ZONE_INVALID_CMD; + goto out; + } + + struct virtio_blk_zone_report zrp_hdr =3D (struct virtio_blk_zone_repo= rt) { + .nr_zones =3D cpu_to_le64(nz), + }; + zrp_size =3D sizeof(struct virtio_blk_zone_report) + + sizeof(struct virtio_blk_zone_descriptor) * nz; + n =3D iov_from_buf(in_iov, in_num, 0, &zrp_hdr, sizeof(zrp_hdr)); + if (n !=3D sizeof(zrp_hdr)) { + virtio_error(vdev, "Driver provided intput buffer that is too smal= l!"); + err_status =3D VIRTIO_BLK_S_ZONE_INVALID_CMD; + goto out; + } + + for (size_t i =3D sizeof(zrp_hdr); i < zrp_size; + i +=3D sizeof(struct virtio_blk_zone_descriptor), ++j) { + struct virtio_blk_zone_descriptor desc =3D + (struct virtio_blk_zone_descriptor) { + .z_start =3D cpu_to_le64(data->zone_report_data.zones[j].s= tart + >> BDRV_SECTOR_BITS), + .z_cap =3D cpu_to_le64(data->zone_report_data.zones[j].cap + >> BDRV_SECTOR_BITS), + .z_wp =3D cpu_to_le64(data->zone_report_data.zones[j].wp + >> BDRV_SECTOR_BITS), + }; + + switch (data->zone_report_data.zones[j].type) { + case BLK_ZT_CONV: + desc.z_type =3D VIRTIO_BLK_ZT_CONV; + break; + case BLK_ZT_SWR: + desc.z_type =3D VIRTIO_BLK_ZT_SWR; + break; + case BLK_ZT_SWP: + desc.z_type =3D VIRTIO_BLK_ZT_SWP; + break; + default: + g_assert_not_reached(); + } + + switch (data->zone_report_data.zones[j].state) { + case BLK_ZS_RDONLY: + desc.z_state =3D VIRTIO_BLK_ZS_RDONLY; + break; + case BLK_ZS_OFFLINE: + desc.z_state =3D VIRTIO_BLK_ZS_OFFLINE; + break; + case BLK_ZS_EMPTY: + desc.z_state =3D VIRTIO_BLK_ZS_EMPTY; + break; + case BLK_ZS_CLOSED: + desc.z_state =3D VIRTIO_BLK_ZS_CLOSED; + break; + case BLK_ZS_FULL: + desc.z_state =3D VIRTIO_BLK_ZS_FULL; + break; + case BLK_ZS_EOPEN: + desc.z_state =3D VIRTIO_BLK_ZS_EOPEN; + break; + case BLK_ZS_IOPEN: + desc.z_state =3D VIRTIO_BLK_ZS_IOPEN; + break; + case BLK_ZS_NOT_WP: + desc.z_state =3D VIRTIO_BLK_ZS_NOT_WP; + break; + default: + g_assert_not_reached(); + } + + /* TODO: it takes O(n^2) time complexity. Optimizations required. = */ + n =3D iov_from_buf(in_iov, in_num, i, &desc, sizeof(desc)); + if (n !=3D sizeof(desc)) { + virtio_error(vdev, "Driver provided input buffer " + "for descriptors that is too small!"); + err_status =3D VIRTIO_BLK_S_ZONE_INVALID_CMD; + } + } + +out: + aio_context_acquire(blk_get_aio_context(s->conf.conf.blk)); + virtio_blk_req_complete(req, err_status); + virtio_blk_free_request(req); + aio_context_release(blk_get_aio_context(s->conf.conf.blk)); + g_free(data->zone_report_data.zones); + g_free(data); +} + +static int virtio_blk_handle_zone_report(VirtIOBlockReq *req) +{ + VirtIOBlock *s =3D req->dev; + VirtIODevice *vdev =3D VIRTIO_DEVICE(s); + unsigned int nr_zones; + ZoneCmdData *data; + int64_t zone_size, offset; + uint8_t err_status; + + if (req->in_len < sizeof(struct virtio_blk_inhdr) + + sizeof(struct virtio_blk_zone_report) + + sizeof(struct virtio_blk_zone_descriptor)) { + virtio_error(vdev, "in buffer too small for zone report"); + return -1; + } + + /* start byte offset of the zone report */ + offset =3D virtio_ldq_p(vdev, &req->out.sector) << BDRV_SECTOR_BITS; + if (!check_zoned_request(s, offset, 0, false, &err_status)) { + goto out; + } + nr_zones =3D (req->in_len - sizeof(struct virtio_blk_inhdr) - + sizeof(struct virtio_blk_zone_report)) / + sizeof(struct virtio_blk_zone_descriptor); + + zone_size =3D sizeof(BlockZoneDescriptor) * nr_zones; + data =3D g_malloc(sizeof(ZoneCmdData)); + data->req =3D req; + data->zone_report_data.nr_zones =3D nr_zones; + data->zone_report_data.zones =3D g_malloc(zone_size), + + blk_aio_zone_report(s->blk, offset, &data->zone_report_data.nr_zones, + data->zone_report_data.zones, + virtio_blk_zone_report_complete, data); + return 0; + +out: + aio_context_acquire(blk_get_aio_context(s->conf.conf.blk)); + virtio_blk_req_complete(req, err_status); + virtio_blk_free_request(req); + aio_context_release(blk_get_aio_context(s->conf.conf.blk)); + return err_status; +} + +static void virtio_blk_zone_mgmt_complete(void *opaque, int ret) +{ + ZoneCmdData *data =3D opaque; + VirtIOBlockReq *req =3D data->req; + VirtIOBlock *s =3D req->dev; + int8_t err_status =3D VIRTIO_BLK_S_OK; + + if (ret) { + err_status =3D VIRTIO_BLK_S_ZONE_INVALID_CMD; + } + + aio_context_acquire(blk_get_aio_context(s->conf.conf.blk)); + virtio_blk_req_complete(req, err_status); + virtio_blk_free_request(req); + aio_context_release(blk_get_aio_context(s->conf.conf.blk)); + g_free(data); +} + +static int virtio_blk_handle_zone_mgmt(VirtIOBlockReq *req, BlockZoneOp op) +{ + VirtIOBlock *s =3D req->dev; + VirtIODevice *vdev =3D VIRTIO_DEVICE(s); + BlockDriverState *bs =3D blk_bs(s->blk); + int64_t offset =3D virtio_ldq_p(vdev, &req->out.sector) << BDRV_SECTOR= _BITS; + uint64_t len; + uint64_t capacity =3D bs->total_sectors << BDRV_SECTOR_BITS; + uint8_t err_status =3D VIRTIO_BLK_S_OK; + + uint32_t type =3D virtio_ldl_p(vdev, &req->out.type); + if (type =3D=3D VIRTIO_BLK_T_ZONE_RESET_ALL) { + /* Entire drive capacity */ + offset =3D 0; + len =3D capacity; + } else { + if (bs->bl.zone_size > capacity - offset) { + /* The zoned device allows the last smaller zone. */ + len =3D capacity - bs->bl.zone_size * (bs->bl.nr_zones - 1); + } else { + len =3D bs->bl.zone_size; + } + } + + if (!check_zoned_request(s, offset, 0, false, &err_status)) { + goto out; + } + + ZoneCmdData *data =3D g_malloc(sizeof(ZoneCmdData)); + data->req =3D req; + blk_aio_zone_mgmt(s->blk, op, offset, len, + virtio_blk_zone_mgmt_complete, data); + + return 0; +out: + aio_context_acquire(blk_get_aio_context(s->conf.conf.blk)); + virtio_blk_req_complete(req, err_status); + virtio_blk_free_request(req); + aio_context_release(blk_get_aio_context(s->conf.conf.blk)); + return err_status; +} + +static void virtio_blk_zone_append_complete(void *opaque, int ret) +{ + ZoneCmdData *data =3D opaque; + VirtIOBlockReq *req =3D data->req; + VirtIOBlock *s =3D req->dev; + VirtIODevice *vdev =3D VIRTIO_DEVICE(req->dev); + int64_t append_sector, n; + struct iovec *out_iov =3D req->elem.out_sg; + unsigned out_num =3D req->elem.out_num; + uint8_t err_status =3D VIRTIO_BLK_S_OK; + + if (ret) { + err_status =3D VIRTIO_BLK_S_ZONE_INVALID_CMD; + goto out; + } + + virtio_stl_p(vdev, &append_sector, + data->zone_append_data.offset >> BDRV_SECTOR_BITS); + n =3D iov_to_buf(out_iov, out_num, 0, &append_sector, sizeof(append_se= ctor)); + if (n !=3D sizeof(append_sector)) { + virtio_error(vdev, "Driver provided input buffer less than size of= " + "append_sector"); + err_status =3D VIRTIO_BLK_S_ZONE_INVALID_CMD; + goto out; + } + +out: + aio_context_acquire(blk_get_aio_context(s->conf.conf.blk)); + virtio_blk_req_complete(req, err_status); + virtio_blk_free_request(req); + aio_context_release(blk_get_aio_context(s->conf.conf.blk)); + g_free(data); +} + +static int virtio_blk_handle_zone_append(VirtIOBlockReq *req, + struct iovec *out_iov, + uint64_t niov) { + VirtIOBlock *s =3D req->dev; + VirtIODevice *vdev =3D VIRTIO_DEVICE(s); + uint8_t err_status =3D VIRTIO_BLK_S_OK; + + int64_t offset =3D virtio_ldq_p(vdev, &req->out.sector) << BDRV_SECTOR= _BITS; + int64_t len =3D iov_size(out_iov, niov); + + if (!check_zoned_request(s, offset, len, true, &err_status)) { + goto out; + } + + ZoneCmdData *data =3D g_malloc(sizeof(ZoneCmdData)); + data->req =3D req; + data->zone_append_data.offset =3D offset; + qemu_iovec_init_external(&req->qiov, out_iov, niov); + blk_aio_zone_append(s->blk, &data->zone_append_data.offset, &req->qiov= , 0, + virtio_blk_zone_append_complete, data); + return 0; + +out: + aio_context_acquire(blk_get_aio_context(s->conf.conf.blk)); + virtio_blk_req_complete(req, err_status); + virtio_blk_free_request(req); + aio_context_release(blk_get_aio_context(s->conf.conf.blk)); + return err_status; +} + static int virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *= mrb) { uint32_t type; @@ -678,6 +1007,24 @@ static int virtio_blk_handle_request(VirtIOBlockReq *= req, MultiReqBuffer *mrb) case VIRTIO_BLK_T_FLUSH: virtio_blk_handle_flush(req, mrb); break; + case VIRTIO_BLK_T_ZONE_REPORT: + virtio_blk_handle_zone_report(req); + break; + case VIRTIO_BLK_T_ZONE_OPEN: + virtio_blk_handle_zone_mgmt(req, BLK_ZO_OPEN); + break; + case VIRTIO_BLK_T_ZONE_CLOSE: + virtio_blk_handle_zone_mgmt(req, BLK_ZO_CLOSE); + break; + case VIRTIO_BLK_T_ZONE_FINISH: + virtio_blk_handle_zone_mgmt(req, BLK_ZO_FINISH); + break; + case VIRTIO_BLK_T_ZONE_RESET: + virtio_blk_handle_zone_mgmt(req, BLK_ZO_RESET); + break; + case VIRTIO_BLK_T_ZONE_RESET_ALL: + virtio_blk_handle_zone_mgmt(req, BLK_ZO_RESET); + break; case VIRTIO_BLK_T_SCSI_CMD: virtio_blk_handle_scsi(req); break; @@ -696,6 +1043,13 @@ static int virtio_blk_handle_request(VirtIOBlockReq *= req, MultiReqBuffer *mrb) virtio_blk_free_request(req); break; } + case VIRTIO_BLK_T_ZONE_APPEND & ~VIRTIO_BLK_T_OUT: + /* + * It is not safe to access req->elem.out_sg directly because it + * may be modified by virtio_blk_handle_request(). + */ + virtio_blk_handle_zone_append(req, out_iov, out_num); + break; /* * VIRTIO_BLK_T_DISCARD and VIRTIO_BLK_T_WRITE_ZEROES are defined with * VIRTIO_BLK_T_OUT flag set. We masked this flag in the switch statem= ent, @@ -895,6 +1249,7 @@ static void virtio_blk_update_config(VirtIODevice *vde= v, uint8_t *config) { VirtIOBlock *s =3D VIRTIO_BLK(vdev); BlockConf *conf =3D &s->conf.conf; + BlockDriverState *bs =3D blk_bs(s->blk); struct virtio_blk_config blkcfg; uint64_t capacity; int64_t length; @@ -954,6 +1309,30 @@ static void virtio_blk_update_config(VirtIODevice *vd= ev, uint8_t *config) blkcfg.write_zeroes_may_unmap =3D 1; virtio_stl_p(vdev, &blkcfg.max_write_zeroes_seg, 1); } + if (bs->bl.zoned !=3D BLK_Z_NONE) { + switch (bs->bl.zoned) { + case BLK_Z_HM: + blkcfg.zoned.model =3D VIRTIO_BLK_Z_HM; + break; + case BLK_Z_HA: + blkcfg.zoned.model =3D VIRTIO_BLK_Z_HA; + break; + default: + g_assert_not_reached(); + } + + virtio_stl_p(vdev, &blkcfg.zoned.zone_sectors, + bs->bl.zone_size / 512); + virtio_stl_p(vdev, &blkcfg.zoned.max_active_zones, + bs->bl.max_active_zones); + virtio_stl_p(vdev, &blkcfg.zoned.max_open_zones, + bs->bl.max_open_zones); + virtio_stl_p(vdev, &blkcfg.zoned.write_granularity, blk_size); + virtio_stl_p(vdev, &blkcfg.zoned.max_append_sectors, + bs->bl.max_append_sectors); + } else { + blkcfg.zoned.model =3D VIRTIO_BLK_Z_NONE; + } memcpy(config, &blkcfg, s->config_size); } =20 @@ -1118,6 +1497,7 @@ static void virtio_blk_device_realize(DeviceState *de= v, Error **errp) VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); VirtIOBlock *s =3D VIRTIO_BLK(dev); VirtIOBlkConf *conf =3D &s->conf; + BlockDriverState *bs =3D blk_bs(conf->conf.blk); Error *err =3D NULL; unsigned i; =20 @@ -1163,6 +1543,13 @@ static void virtio_blk_device_realize(DeviceState *d= ev, Error **errp) return; } =20 + if (bs->bl.zoned !=3D BLK_Z_NONE) { + virtio_add_feature(&s->host_features, VIRTIO_BLK_F_ZONED); + if (bs->bl.zoned =3D=3D BLK_Z_HM) { + virtio_clear_feature(&s->host_features, VIRTIO_BLK_F_DISCARD); + } + } + if (virtio_has_feature(s->host_features, VIRTIO_BLK_F_DISCARD) && (!conf->max_discard_sectors || conf->max_discard_sectors > BDRV_REQUEST_MAX_SECTORS)) { --=20 2.38.1 From nobody Sat May 18 09:01:38 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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1667122457; cv=none; d=zohomail.com; s=zohoarc; b=iMrUpTBQc9+5zdJyX2luvKlQG3Ddvkkv8+Cg/8O/hZ0HZrP+B0aOSSJWk3tFWJ5GtQrmymPqr0qSEH02Z2brcilDqcCDmAQfJ5gX/ukz9JrUhRJNnMpTT6H4ebdGsOu8cY6AXHCV1xompZtVFL/3Gzc4jI+aTpe+bb/GndMI2JI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667122457; 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=jMwC0K4PsRrQP3rpYiwpRQ7xJrrJ0aJem8BSMOC/Wnk=; b=l5sbG2C53rFVMFIqHIEbnoNG/s09XVhjkFj5KaWVuOi/HqQt63Asm2SXDUXrpy0tBq9zW/pI8WOJ04ra2NhquBCT0BJSHgo9p+twPUH3VNa2VLU1oHeMbhjmqLJr6OMTcvFqjh6gXTyQA1JF1QXI9fQNxyAA3nQ7Gy6pofaSu04= 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+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 1667122457861895.0023939203038; Sun, 30 Oct 2022 02:34:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1op4hW-00041V-O3; Sun, 30 Oct 2022 05:33:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1op4h9-0003yE-Lm; Sun, 30 Oct 2022 05:33:36 -0400 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1op4h6-0000mQ-2V; Sun, 30 Oct 2022 05:33:29 -0400 Received: by mail-pj1-x1034.google.com with SMTP id r61-20020a17090a43c300b00212f4e9cccdso13480306pjg.5; Sun, 30 Oct 2022 02:33:26 -0700 (PDT) Received: from fedora.. ([112.44.202.248]) by smtp.gmail.com with ESMTPSA id 1-20020a17090a0d4100b00205db4ff6dfsm2113445pju.46.2022.10.30.02.33.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Oct 2022 02:33:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jMwC0K4PsRrQP3rpYiwpRQ7xJrrJ0aJem8BSMOC/Wnk=; b=KbDYFN6ugjEuOxr5YELTByUG08kni8Vs4oDHtpmnvbCW/cUq/2E+2Ks1uUA4U7/Tr5 FqCDbn2JABmw0fRNmHBbRjAh+S/+F7xI7hOey7WcKxi5OmDwLxDqyK4OojQQ41k8rJxO VL/1UZ2eDa5BnpG9DEakbLMKEsoWOiyux5E/LegKjZ0ul5X9I1auT8Ed9Q7dcPQtEZ2t rgkiKmUcg0SK+Q89pIDj8DPpIJUEnhDeyaEyMMelcMLh0JAUGik0SafRcmMXCMxEdGRD cCsyZ+ePS1xMrQox1Z3Hjqby4C8lxiDE1Vc8L05N4EoHwAKPblYU7gVuUUaEvp6KoCVE yISA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jMwC0K4PsRrQP3rpYiwpRQ7xJrrJ0aJem8BSMOC/Wnk=; b=NzihBqZHVblY2n5L7lGWm9ixOFywJsTw+zDR/RnpbZ7oSTHl5S3prT8hlrefVgPEd1 Nu49tbWZcQH/Sy4CW9+Ak/Zwu6HkqTRqz5Jmu2J6vJa+LoYgUE/WYv2xmPqrX/Cw7/xc oAV5oDw5PEtM9LInqiKC+bpbjhbo7NQxZnAkssnAlzsxhrUOPONQ5pPTG1mrxuxPtZNK zoqi7ln2WuEXN7LW7jCqIlOiTvZfoPb9vfsJQukLcj7gxr1pus2SOyqpZKd1MAmOnr4i Hzq66/cC7qRlcEPX7ZDQEYPBtgvs0nDoBb1liYJUXBPJt0GZMXQkUs5YsS/grHQxmGkP 9DGQ== X-Gm-Message-State: ACrzQf3h6f251/9KtsIEeFv2pbiLMgqcjrBv14ofza7dl0v5qFU2JDFq 8JgdNhJ8/sD/3eoARLOCUPzyV4DRBPJXmtf3 X-Google-Smtp-Source: AMsMyM797oAnLQPBbxVhWGeRkULwN+ct+TxRK4zsg3+OUsDvxhjwinxC1QK6wlPWRzDyBivANZy88w== X-Received: by 2002:a17:902:e1ca:b0:186:878e:3b03 with SMTP id t10-20020a170902e1ca00b00186878e3b03mr8593573pla.95.1667122405057; Sun, 30 Oct 2022 02:33:25 -0700 (PDT) From: Sam Li To: qemu-devel@nongnu.org Cc: Raphael Norwitz , stefanha@redhat.com, damien.lemoal@opensource.wdc.com, "Michael S. Tsirkin" , Kevin Wolf , hare@suse.de, Hanna Reitz , qemu-block@nongnu.org, dmitry.fomichev@wdc.com, Sam Li Subject: [RFC v4 3/3] virtio-blk: add some trace events for zoned emulation Date: Sun, 30 Oct 2022 05:32:42 -0400 Message-Id: <20221030093242.208839-4-faithilikerun@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221030093242.208839-1-faithilikerun@gmail.com> References: <20221030093242.208839-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1034; envelope-from=faithilikerun@gmail.com; helo=mail-pj1-x1034.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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1667122459585100005 Content-Type: text/plain; charset="utf-8" Signed-off-by: Sam Li Reviewed-by: Stefan Hajnoczi --- hw/block/trace-events | 7 +++++++ hw/block/virtio-blk.c | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/hw/block/trace-events b/hw/block/trace-events index 2c45a62bd5..f47da6fcd4 100644 --- a/hw/block/trace-events +++ b/hw/block/trace-events @@ -44,9 +44,16 @@ pflash_write_unknown(const char *name, uint8_t cmd) "%s:= unknown command 0x%02x" # virtio-blk.c virtio_blk_req_complete(void *vdev, void *req, int status) "vdev %p req %p= status %d" virtio_blk_rw_complete(void *vdev, void *req, int ret) "vdev %p req %p ret= %d" +virtio_blk_zone_report_complete(void *vdev, void *req, unsigned int nr_zon= es, int ret) "vdev %p req %p nr_zones %d ret %d" +virtio_blk_zone_mgmt_complete(void *vdev, void *req, int ret) "vdev %p req= %p ret %d" +virtio_blk_zone_append_complete(void *vdev, void *req, int64_t sector, int= ret) "vdev %p req %p, append sector 0x%" PRIx64 " ret %d" virtio_blk_handle_write(void *vdev, void *req, uint64_t sector, size_t nse= ctors) "vdev %p req %p sector %"PRIu64" nsectors %zu" virtio_blk_handle_read(void *vdev, void *req, uint64_t sector, size_t nsec= tors) "vdev %p req %p sector %"PRIu64" nsectors %zu" virtio_blk_submit_multireq(void *vdev, void *mrb, int start, int num_reqs,= uint64_t offset, size_t size, bool is_write) "vdev %p mrb %p start %d num_= reqs %d offset %"PRIu64" size %zu is_write %d" +virtio_blk_handle_zone_report(void *vdev, void *req, int64_t sector, unsig= ned int nr_zones) "vdev %p req %p sector 0x%" PRIx64 " nr_zones %d" +virtio_blk_handle_zone_mgmt(void *vdev, void *req, uint8_t op, int64_t sec= tor, int64_t len) "vdev %p req %p op 0x%x sector 0x%" PRIx64 " len 0x%" PRI= x64 "" +virtio_blk_handle_zone_reset_all(void *vdev, void *req, int64_t sector, in= t64_t len) "vdev %p req %p sector 0x%" PRIx64 " cap 0x%" PRIx64 "" +virtio_blk_handle_zone_append(void *vdev, void *req, int64_t sector) "vdev= %p req %p, append sector 0x%" PRIx64 "" =20 # hd-geometry.c hd_geometry_lchs_guess(void *blk, int cyls, int heads, int secs) "blk %p L= CHS %d %d %d" diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 4f3625840a..e7d85dc049 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -663,6 +663,7 @@ static void virtio_blk_zone_report_complete(void *opaqu= e, int ret) int64_t nz =3D data->zone_report_data.nr_zones; int8_t err_status =3D VIRTIO_BLK_S_OK; =20 + trace_virtio_blk_zone_report_complete(vdev, req, nz, ret); if (ret) { err_status =3D VIRTIO_BLK_S_ZONE_INVALID_CMD; goto out; @@ -777,6 +778,8 @@ static int virtio_blk_handle_zone_report(VirtIOBlockReq= *req) nr_zones =3D (req->in_len - sizeof(struct virtio_blk_inhdr) - sizeof(struct virtio_blk_zone_report)) / sizeof(struct virtio_blk_zone_descriptor); + trace_virtio_blk_handle_zone_report(vdev, req, + offset >> BDRV_SECTOR_BITS, nr_zon= es); =20 zone_size =3D sizeof(BlockZoneDescriptor) * nr_zones; data =3D g_malloc(sizeof(ZoneCmdData)); @@ -802,7 +805,9 @@ static void virtio_blk_zone_mgmt_complete(void *opaque,= int ret) ZoneCmdData *data =3D opaque; VirtIOBlockReq *req =3D data->req; VirtIOBlock *s =3D req->dev; + VirtIODevice *vdev =3D VIRTIO_DEVICE(s); int8_t err_status =3D VIRTIO_BLK_S_OK; + trace_virtio_blk_zone_mgmt_complete(vdev, req,ret); =20 if (ret) { err_status =3D VIRTIO_BLK_S_ZONE_INVALID_CMD; @@ -830,6 +835,8 @@ static int virtio_blk_handle_zone_mgmt(VirtIOBlockReq *= req, BlockZoneOp op) /* Entire drive capacity */ offset =3D 0; len =3D capacity; + trace_virtio_blk_handle_zone_reset_all(vdev, req, 0, + bs->total_sectors); } else { if (bs->bl.zone_size > capacity - offset) { /* The zoned device allows the last smaller zone. */ @@ -837,6 +844,9 @@ static int virtio_blk_handle_zone_mgmt(VirtIOBlockReq *= req, BlockZoneOp op) } else { len =3D bs->bl.zone_size; } + trace_virtio_blk_handle_zone_mgmt(vdev, req, op, + offset >> BDRV_SECTOR_BITS, + len >> BDRV_SECTOR_BITS); } =20 if (!check_zoned_request(s, offset, 0, false, &err_status)) { @@ -882,6 +892,7 @@ static void virtio_blk_zone_append_complete(void *opaqu= e, int ret) err_status =3D VIRTIO_BLK_S_ZONE_INVALID_CMD; goto out; } + trace_virtio_blk_zone_append_complete(vdev, req, append_sector, ret); =20 out: aio_context_acquire(blk_get_aio_context(s->conf.conf.blk)); @@ -901,6 +912,7 @@ static int virtio_blk_handle_zone_append(VirtIOBlockReq= *req, int64_t offset =3D virtio_ldq_p(vdev, &req->out.sector) << BDRV_SECTOR= _BITS; int64_t len =3D iov_size(out_iov, niov); =20 + trace_virtio_blk_handle_zone_append(vdev, req, offset >> BDRV_SECTOR_B= ITS); if (!check_zoned_request(s, offset, len, true, &err_status)) { goto out; } --=20 2.38.1