From patchwork Tue Jul 9 20:38:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Fomichev X-Patchwork-Id: 11037493 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 84A361395 for ; Tue, 9 Jul 2019 20:41:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 74173287ED for ; Tue, 9 Jul 2019 20:41:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 677F3287F9; Tue, 9 Jul 2019 20:41:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E2E18287ED for ; Tue, 9 Jul 2019 20:41:56 +0000 (UTC) Received: from localhost ([::1]:55984 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkww0-00089A-54 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 09 Jul 2019 16:41:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60172) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkwsw-0005lx-Gv for qemu-devel@nongnu.org; Tue, 09 Jul 2019 16:38:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hkwst-0000nX-Or for qemu-devel@nongnu.org; Tue, 09 Jul 2019 16:38:45 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:50348) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hkwsp-0000VW-K3; Tue, 09 Jul 2019 16:38:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1562704726; x=1594240726; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OQdCBt+oA9bpkFs+6bpKPS8S4KbIBEsavxEYZU5NgdY=; b=E2NZkPhDFYtlRQL7knaEwh1jGyx4+WDPKWGXI8PHu+2Vgf8a+Du3xcgd s5L+ZqU4zeLG3F3wt9hoeBs7GrFohOqjKEtZB8EKQnHUrTwj70BV/RqwV GWX1DAT9h6oxvq799QXIeEMkkG8stniKyUe1KH+QFuMEFU70xOcTs6nJH dnwYcaLVLA7yRvRBZqLksIAuK2j+gV9LquiT2thzYCYKsyvrdbi4QS91Q IV4U8SIN3/P0zxtRdMwadvRsozISNr5m/IVWQYqm8uOQxjP+Y3orNJ9lv Xfk7NwYvLW5HIaNh+m6XxvwZEgaNie/lu2cQioAU2ygsJqGlHm6a6TT+x A==; IronPort-SDR: BzOSSjqzzS3xWdYrGhKz19H/KwtGMUABwTg+ZQvlAwQ6i3SiS9T4YZfmCUXZDmZhJl1utkvr2U 3Ogm3vxL+YXH/kLqQyfK5G2vfGh7Ce4FAg5hFJeWLo/YVgiMoYbq63dVOHohfpWmIO7+YMqxc3 me4nufH3CrehYRMgZpaUcBpk7ZeMMAAkc0tMIJFPBxaMG8RSC5f2bTk/kwbfU089X0kHc838GJ xGztUr64AfKZqFCMIDZzznvsvlgi5bdQBd6f2ABqcbS0CSWeHR9PbBCyFDFxD/TtMt2O6w1wtZ Hb4= X-IronPort-AV: E=Sophos;i="5.63,471,1557158400"; d="scan'208";a="212488450" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 10 Jul 2019 04:38:45 +0800 IronPort-SDR: VGaYahW8cBiZdtEJDkdMbP5szS7zktbAJdARmI/UOOE1vVVqHkqdAc86CJQJOB8QDq02CVZMj7 2hvEZ9hY9dIObBLkFDr8ymvqTKneI2P+A7wF/Pa1OWkzOgYzW1OjgFdr86R6mAvD5AWvC2zlrr 0RYKS5JXdUA1O/Exd13gUQib1+N2SYAGg1IoSKECRivOFOxWCjdDtTu98kFl3zRbkT0QumAmoB s6acVgZWhzm0XCkfLNCXa7/SMypEI0aemjUEdLJAZFRd7GEcb4w5ZcAnwM9DCyHeYavTD1TnA6 LuDkoGerHkYvYNTXwXVlypcS Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP; 09 Jul 2019 13:37:26 -0700 IronPort-SDR: NlFTDb4uxrdZbasZNestABKfjsXpdGgznQufMMkh4HuNmWJNEqa7TuaRU0Hsfeg1aFr3EFtTTh smErExmW+D1R1EMHASG8+HWe3rdvKeO4wJFpE5M9l+xvvg6XDVjzWis4VmcbNZ8NNKzSZ0VBF4 l76VqsOcfr8Cl33CF6FJARYnUuWTE4CN0oj78SnIkIrcjXAia15YrSAsC4b7h/PtXuCIRIavoR ph5JWffD9H+/9NJY5pB29c6BXA/R6xWUm6eBosiOiQ4R4UyoccpAh5e6yruN0RKxkynfvtgbRu Hqk= Received: from dhcp-10-88-173-43.hgst.com ([10.88.173.43]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Jul 2019 13:38:39 -0700 From: Dmitry Fomichev To: kwolf@redhat.com, mreitz@redhat.com, mst@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, fam@euphon.net, qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Tue, 9 Jul 2019 16:38:03 -0400 Message-Id: <20190709203806.17550-2-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190709203806.17550-1-dmitry.fomichev@wdc.com> References: <20190709203806.17550-1-dmitry.fomichev@wdc.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x X-Received-From: 68.232.143.124 Subject: [Qemu-devel] [PATCH 1/4] block: Add zoned device model property X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dmitry Fomichev Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This commit adds Zoned Device Model as defined in T10 ZBC and T13 ZAC standards, along with some useful accessor functions. Since the default value of zero in the zoned model field corresponds to a regular (non-zoned) block device, there is no functionality change with this commit. Signed-off-by: Dmitry Fomichev --- block.c | 14 ++++++++++++++ block/block-backend.c | 20 ++++++++++++++++++++ include/block/block.h | 9 +++++++++ include/block/block_int.h | 4 ++++ include/sysemu/block-backend.h | 2 ++ 5 files changed, 49 insertions(+) diff --git a/block.c b/block.c index c139540f2b..396d999f00 100644 --- a/block.c +++ b/block.c @@ -4649,6 +4649,20 @@ void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr) *nb_sectors_ptr = nb_sectors < 0 ? 0 : nb_sectors; } +uint8_t bdrv_get_zoned_model(BlockDriverState *bs) +{ + if (bs->drv->bdrv_get_zoned_info) { + bs->drv->bdrv_get_zoned_info(bs); + } + + return bs->bl.zoned_model; +} + +uint8_t bdrv_is_zoned(BlockDriverState *bs) +{ + return bdrv_get_zoned_model(bs) != BLK_ZONED_NONE; +} + bool bdrv_is_sg(BlockDriverState *bs) { return bs->sg; diff --git a/block/block-backend.c b/block/block-backend.c index a8d160fd5d..34723f3655 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1438,6 +1438,15 @@ int64_t blk_nb_sectors(BlockBackend *blk) return bdrv_nb_sectors(blk_bs(blk)); } +uint8_t blk_get_zoned_model(BlockBackend *blk) +{ + if (!blk_is_available(blk)) { + return BLK_ZONED_NONE; + } + + return bdrv_get_zoned_model(blk_bs(blk)); +} + BlockAIOCB *blk_aio_preadv(BlockBackend *blk, int64_t offset, QEMUIOVector *qiov, BdrvRequestFlags flags, BlockCompletionFunc *cb, void *opaque) @@ -1705,6 +1714,17 @@ bool blk_is_sg(BlockBackend *blk) return bdrv_is_sg(bs); } +bool blk_is_zoned(BlockBackend *blk) +{ + BlockDriverState *bs = blk_bs(blk); + + if (!bs) { + return false; + } + + return bdrv_is_zoned(bs); +} + bool blk_enable_write_cache(BlockBackend *blk) { return blk->enable_write_cache; diff --git a/include/block/block.h b/include/block/block.h index 734c9d2f76..7aa096afcc 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -278,6 +278,13 @@ enum { char *bdrv_perm_names(uint64_t perm); +/* Known zoned device models */ +enum blk_zoned_model { + BLK_ZONED_NONE, /* Regular block device */ + BLK_ZONED_HA, /* Host-aware zoned block device */ + BLK_ZONED_HM, /* Host-managed zoned block device */ +}; + /* disk I/O throttling */ void bdrv_init(void); void bdrv_init_with_whitelist(void); @@ -354,6 +361,8 @@ int64_t bdrv_get_allocated_file_size(BlockDriverState *bs); BlockMeasureInfo *bdrv_measure(BlockDriver *drv, QemuOpts *opts, BlockDriverState *in_bs, Error **errp); void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr); +uint8_t bdrv_get_zoned_model(BlockDriverState *bs); +uint8_t bdrv_is_zoned(BlockDriverState *bs); void bdrv_refresh_limits(BlockDriverState *bs, Error **errp); int bdrv_commit(BlockDriverState *bs); int bdrv_change_backing_file(BlockDriverState *bs, diff --git a/include/block/block_int.h b/include/block/block_int.h index d6415b53c1..8f35591803 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -416,6 +416,7 @@ struct BlockDriver { bool (*bdrv_debug_is_suspended)(BlockDriverState *bs, const char *tag); void (*bdrv_refresh_limits)(BlockDriverState *bs, Error **errp); + void (*bdrv_get_zoned_info)(BlockDriverState *bs); /* * Returns 1 if newly created images are guaranteed to contain only @@ -614,6 +615,9 @@ typedef struct BlockLimits { /* maximum number of iovec elements */ int max_iov; + + /* Zoned device model. Zero value indicates a regular block device */ + uint8_t zoned_model; } BlockLimits; typedef struct BdrvOpBlocker BdrvOpBlocker; diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 733c4957eb..65b6341218 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -156,6 +156,7 @@ int blk_pwrite(BlockBackend *blk, int64_t offset, const void *buf, int bytes, int64_t blk_getlength(BlockBackend *blk); void blk_get_geometry(BlockBackend *blk, uint64_t *nb_sectors_ptr); int64_t blk_nb_sectors(BlockBackend *blk); +uint8_t blk_get_zoned_model(BlockBackend *blk); BlockAIOCB *blk_aio_preadv(BlockBackend *blk, int64_t offset, QEMUIOVector *qiov, BdrvRequestFlags flags, BlockCompletionFunc *cb, void *opaque); @@ -189,6 +190,7 @@ void blk_error_action(BlockBackend *blk, BlockErrorAction action, bool is_read, int error); bool blk_is_read_only(BlockBackend *blk); bool blk_is_sg(BlockBackend *blk); +bool blk_is_zoned(BlockBackend *blk); bool blk_enable_write_cache(BlockBackend *blk); void blk_set_enable_write_cache(BlockBackend *blk, bool wce); void blk_invalidate_cache(BlockBackend *blk, Error **errp); From patchwork Tue Jul 9 20:38:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Fomichev X-Patchwork-Id: 11037497 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 12C48912 for ; Tue, 9 Jul 2019 20:45:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F3B2D287EF for ; Tue, 9 Jul 2019 20:45:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D90A7287FB; Tue, 9 Jul 2019 20:45:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 61182287EF for ; Tue, 9 Jul 2019 20:45:20 +0000 (UTC) Received: from localhost ([::1]:56022 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkwzH-0002KE-NE for patchwork-qemu-devel@patchwork.kernel.org; Tue, 09 Jul 2019 16:45:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60399) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkwt5-0005sM-DC for qemu-devel@nongnu.org; Tue, 09 Jul 2019 16:38:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hkwt0-00011C-4a for qemu-devel@nongnu.org; Tue, 09 Jul 2019 16:38:53 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:50362) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hkwst-0000jE-Js; Tue, 09 Jul 2019 16:38:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1562704733; x=1594240733; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Sv7iJyU3lEXrOaUa/SEaaTKyC8QKbb+Dk4Hz74sYrj0=; b=QaF7MxlHUzNUvglh13GuAAU9zXWPgJg1JMBzZ1oWAPOSQORUQGuFxaAt QoZ5RGYU1Rp4RAsHexBgubz6z4dYa4uEbCK7naxyQFkD8p4txzqz0fONP FWFnsKSmnTvlaO2ydREatD7Yh0FyjdCn4GFso8PNIikj0OnOGBpYncxQm 8kjtJhenu2foGCH1W+cAHNygWEQ/Gg3i5aBrB16HEXb6FFkNWJklsyp1K q0V9UHa4LKVx40sZAD73NYjYcN58+hYPKcCbOKilWExYr8sFeLFDtQVYy sVM/qTPOuVcaBzJG4UPMKtJHSdPIJqLPmXTi79Gseh9DZ/CahAitqgy/k w==; IronPort-SDR: 8xJcHaT2LDwxyzKgViPzhBMjN4RuX5Bn8PPPMkp18q+XhBoeL3EQVaIHg+SmvL7FisM21kWy3i lzBd0OiTkVphCr3ZKznmx7Q67h1Bf3sws6JTPB8mHe2rdVF1F2DN5Er8ckg++FI7p38eGef11A miWfhoBGsu1cxW6Lq/gEnnFn7L6rfJo4Cf0nYEs8lUQeuhUVs4Xgci38nDfP/oRn7FfRLE2Ppn k9eFGV/lSTOvoG+3jsDwVfieN/lej3VbOZYIxCbyUGul7pAzHsfHk1XXbhVnP0hHHok4ShTitB ZNk= X-IronPort-AV: E=Sophos;i="5.63,471,1557158400"; d="scan'208";a="212488453" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 10 Jul 2019 04:38:49 +0800 IronPort-SDR: yVf5SLn/mnWibPCPDzNEv+FmjiAY6c9ylzBYfxU3xGM/XN1h/ZdrcZ7D1/Pj3UApD88+O5Ocg7 Y4AF8rWVRY2p9pf/nk8JsPeNhsyCicG80EZmgWHs2G6T9QgRNUe3qS/rrydWFWXUeLK45dsZUn ZKBvRCUe1k405eKh1dYq11iA1KHNPTfsSQ0kwfZcKRCXEsKdTca1U9y66duK4ocQGvRhsDBUd3 i7pLTghzVN/IMaAGugEzlhySOuisCW71Yogz6PZ5+2ZyMOOgfUhPx3oVpflDLHBnBqmP7GNLnm sifJhsZ/Q1UG6KNLgJw1PPOz Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP; 09 Jul 2019 13:37:28 -0700 IronPort-SDR: It3eFzaf/J8QLJI+9AnCsDyc95s8jHkk0MSBB0hxOBLF6wkN/xiIJUueYojGYXmjEnebfsWPOn pNzYUgtqsk1vz+LECY+DZR7JlJkp4yb7/g2qH8WT6XmLbGqWRDqzNGoNttoRT2kcgKq77Z207p ALtI7jZt4j9BiucXeIzsU5q2KhdqWxSq9FQy4Qpx/44TU6Cg0x7DHSuOC49R1HBd/W6WRwE3B4 YkUWNxF1gpH2omyT4qtvKWxCRi0d4OeUb+aedNznfHRxVHiARyJxk2JmB5zFExOxEXUCwb6y2H aNk= Received: from dhcp-10-88-173-43.hgst.com ([10.88.173.43]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Jul 2019 13:38:41 -0700 From: Dmitry Fomichev To: kwolf@redhat.com, mreitz@redhat.com, mst@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, fam@euphon.net, qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Tue, 9 Jul 2019 16:38:04 -0400 Message-Id: <20190709203806.17550-3-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190709203806.17550-1-dmitry.fomichev@wdc.com> References: <20190709203806.17550-1-dmitry.fomichev@wdc.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x X-Received-From: 68.232.143.124 Subject: [Qemu-devel] [PATCH 2/4] raw: Recognize zoned backing devices X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dmitry Fomichev Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The purpose of this patch is to recognize a zoned block device (ZBD) when it is opened as a raw file. The new code initializes the zoned model propery introduced by the previous commit. This commit is Linux-specific and in essence it checks the Zoned Block Device Model (None/Host-managed/Host-aware) value in sysfs on the host. In order to avoid code duplication in file-posix.c, a common helper function is added to read value of a sysfs entry under /sys/block//queue. Now, the existing function that reads the "max_segments" value and the the new function that reads "zoned" value share the same helper code. Signed-off-by: Dmitry Fomichev --- block/file-posix.c | 69 ++++++++++++++++++++++++++++++++++++++-------- block/raw-format.c | 8 ++++++ 2 files changed, 66 insertions(+), 11 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index ab05b51a66..dd81dc3301 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1055,33 +1055,53 @@ static int hdev_get_max_transfer_length(BlockDriverState *bs, int fd) #endif } -static int hdev_get_max_segments(const struct stat *st) +static int hdev_read_blk_queue_entry(const struct stat *st, const char *key, + char *buf, int buf_len) { #ifdef CONFIG_LINUX - char buf[32]; - const char *end; char *sysfspath; int ret; int fd = -1; - long max_segments; - sysfspath = g_strdup_printf("/sys/dev/block/%u:%u/queue/max_segments", - major(st->st_rdev), minor(st->st_rdev)); + sysfspath = g_strdup_printf("/sys/dev/block/%u:%u/queue/%s", + major(st->st_rdev), minor(st->st_rdev), key); fd = open(sysfspath, O_RDONLY); if (fd == -1) { ret = -errno; goto out; } do { - ret = read(fd, buf, sizeof(buf) - 1); + ret = read(fd, buf, buf_len - 1); } while (ret == -1 && errno == EINTR); if (ret < 0) { ret = -errno; - goto out; } else if (ret == 0) { ret = -EIO; + } +out: + if (fd != -1) { + close(fd); + } + g_free(sysfspath); + return ret; +#else + return -ENOTSUP; +#endif +} + +static int hdev_get_max_segments(const struct stat *st) +{ +#ifdef CONFIG_LINUX + char buf[32]; + const char *end; + int ret; + long max_segments; + + ret = hdev_read_blk_queue_entry(st, "max_segments", buf, sizeof(buf)); + if (ret < 0) { goto out; } + buf[ret] = 0; /* The file is ended with '\n', pass 'end' to accept that. */ ret = qemu_strtol(buf, &end, 10, &max_segments); @@ -1090,10 +1110,33 @@ static int hdev_get_max_segments(const struct stat *st) } out: - if (fd != -1) { - close(fd); + return ret; +#else + return -ENOTSUP; +#endif +} + +static int hdev_get_zoned_model(const struct stat *st) +{ +#ifdef CONFIG_LINUX + char buf[32]; + int ret; + + ret = hdev_read_blk_queue_entry(st, "zoned", buf, sizeof(buf)); + if (ret < 0) { + ret = BLK_ZONED_NONE; + goto out; } - g_free(sysfspath); + + buf[ret - 1] = 0; + ret = BLK_ZONED_NONE; + if (strcmp(buf, "host-managed") == 0) { + ret = BLK_ZONED_HM; + } else if (strcmp(buf, "host-aware") == 0) { + ret = BLK_ZONED_HA; + } + +out: return ret; #else return -ENOTSUP; @@ -1116,6 +1159,10 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp) bs->bl.max_transfer = MIN(bs->bl.max_transfer, ret * getpagesize()); } + ret = hdev_get_zoned_model(&st); + if (ret >= 0) { + bs->bl.zoned_model = ret; + } } } diff --git a/block/raw-format.c b/block/raw-format.c index bffd424dd0..12c2a3f95d 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -369,6 +369,13 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp) } } +static void raw_get_zoned_info(BlockDriverState *bs) +{ + if (!bs->probed) { + bs->bl.zoned_model = bs->file->bs->bl.zoned_model; + } +} + static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offset, PreallocMode prealloc, Error **errp) { @@ -572,6 +579,7 @@ BlockDriver bdrv_raw = { .bdrv_co_ioctl = &raw_co_ioctl, .create_opts = &raw_create_opts, .bdrv_has_zero_init = &raw_has_zero_init, + .bdrv_get_zoned_info = &raw_get_zoned_info, .strong_runtime_opts = raw_strong_runtime_opts, .mutable_opts = mutable_opts, }; From patchwork Tue Jul 9 20:38:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Fomichev X-Patchwork-Id: 11037491 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8813F1395 for ; Tue, 9 Jul 2019 20:41:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7862D212D9 for ; Tue, 9 Jul 2019 20:41:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6A3672839C; Tue, 9 Jul 2019 20:41:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1961B212D9 for ; Tue, 9 Jul 2019 20:41:00 +0000 (UTC) Received: from localhost ([::1]:55982 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkwv6-0007RB-79 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 09 Jul 2019 16:41:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60325) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkwsz-0005pO-TL for qemu-devel@nongnu.org; Tue, 09 Jul 2019 16:38:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hkwsw-0000vk-SV for qemu-devel@nongnu.org; Tue, 09 Jul 2019 16:38:47 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:50362) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hkwsu-0000jE-80; Tue, 09 Jul 2019 16:38:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1562704733; x=1594240733; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WmkBOZQXw8TYDamyy1qpM/47me1gOgpWai3PcMTicTc=; b=XOBA23sVskaWOwy41Ag0uMf4PqJoaPO89neBSdrsNFPpCTrq/3rFZf6Z SgUg/xtf11Q2IDaCH9Yz+NKh8t0TBnzO55JlpSkWX6HX87U+FoW9zz12q AleeUKW7VAn1olLXWHy4eZNSi2ZJqQkdsWSLQBZHlPIU+ahgz/DCfcZjW gHKCRWdoFzEt18al2BHq7cxqHX/XT3u1+4nR9Fh5l69PMTVgVqjiBNgi1 LaJz02d16VMEhulT6Jwk8p2JeO2tsG1bq1flJnAZBaVdZVWdAMVab8PQk 6yMv751R+RcdYf8CJAnuf8/M99SsFWdMwiJ7AX+/Z+7Rqx+EijTvmPmGO g==; IronPort-SDR: F+EwWzUJEar03fkdi64Fye2foTOUyIVux+5TBEzMcs5UfSRl+NB6tBdBJDWJutPtlDkbbl792s yBfyIEBTDebWNrUuBG4ERioRHApNR+dYLmg61qwQV2TZm4wqtrGip9ZUSMppVW0pj1oN4LcTGL 4J2SjZ9Mt36WEQ/i84IjAsV178wEW/9ycLTAHvLLcoKHTTg1+PBNhtKuFguo+uihDas+Ok7JLO TqaOTFE0wMj/yHYffffMxf9Lfuh6MTZaLarJfkQsF2Zb8tKZNNyYa5J2EhsxUO+3OxHlMCyxAZ vUE= X-IronPort-AV: E=Sophos;i="5.63,471,1557158400"; d="scan'208";a="212488454" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 10 Jul 2019 04:38:53 +0800 IronPort-SDR: SH9a08Re68N42/kyJ7TF0h6Z5HT+aNwkR6a6B+OGrnqufwdVSYrfDBumMarc8jv3BZutXFySrI dgspAq7eXuMFD9Fwpxy7OrboMwlZjW8CzcVvdIc81jiDowSyrpd1dJWbxDT9bjTr4lvt6Uujiq uLUBagMuZlUjbMdPRwKhUJKHNVqB7TnZxQ4I65KNWpteQlrVxHOAFE+AN8uIpJWVV/nJotwGpw WZC8TR4j6n6RYuWk0LuFdbhOUv+wDgcwkRZ7nqI2k8v20yJZQHJv2P2tVbwlARyn3YsqpDtKTQ 0NAeQqQYwI9wzscb4WC0V24I Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP; 09 Jul 2019 13:37:31 -0700 IronPort-SDR: VYaDgpXPS3hKGY7rbJDMZ8M1eYIoLDZBFOz7e08/v9DrfOqYZLv2+h498vft5lQBl4tENaTIER XLv1OTdeR6079GrVOVKzNBaU0X3Wwht2COpZwtYcZILs6w8FlIUBBjcGgOdzeIOE4zDgcclDgb tqC8UHVMvUqce4AGUOEvFX7UyNK2owouiZSv9UkxsJtXdL65xT0kEHbPbSRPezDuTDNv057iAJ 8yHGHUmVD9YK0UWNSLgxEX1EA0PUgzbaQEVe13iDKp8tzU1+/fBPieElaiohCyqZz8/LS6qhOC 1z8= Received: from dhcp-10-88-173-43.hgst.com ([10.88.173.43]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Jul 2019 13:38:44 -0700 From: Dmitry Fomichev To: kwolf@redhat.com, mreitz@redhat.com, mst@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, fam@euphon.net, qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Tue, 9 Jul 2019 16:38:05 -0400 Message-Id: <20190709203806.17550-4-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190709203806.17550-1-dmitry.fomichev@wdc.com> References: <20190709203806.17550-1-dmitry.fomichev@wdc.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x X-Received-From: 68.232.143.124 Subject: [Qemu-devel] [PATCH 3/4] virtio-blk: Don't realize zoned block devices X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dmitry Fomichev Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Prevent virtio-blk code from attaching a zoned block device because it will otherwise appear as a reqular block device at the guest and that will most certainly cause problems. The functionality to support ZBDs via virtio-blk should be pretty useful and there are some attempts underway to get it implemented, but such work will inevitably lead to some modifications in virtio protocol spec. Therefore, this activity is considered a more long-term effort. So for now, we just don't allow zoned block devices to work via virtio-blk. Signed-off-by: Dmitry Fomichev --- hw/block/virtio-blk.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index cbb3729158..c11e028308 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1140,6 +1140,11 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp) return; } + if (blk_is_zoned(conf->conf.blk)) { + error_setg(errp, "zoned block devices are not supported"); + return; + } + if (virtio_has_feature(s->host_features, VIRTIO_BLK_F_DISCARD) && (!conf->max_discard_sectors || conf->max_discard_sectors > BDRV_REQUEST_MAX_SECTORS)) { From patchwork Tue Jul 9 20:38:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Fomichev X-Patchwork-Id: 11037495 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0EAD01395 for ; Tue, 9 Jul 2019 20:44:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E7343287EF for ; Tue, 9 Jul 2019 20:44:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D6594287FB; Tue, 9 Jul 2019 20:44:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7A8F3287EF for ; Tue, 9 Jul 2019 20:44:55 +0000 (UTC) Received: from localhost ([::1]:56014 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkwys-0001zX-Hb for patchwork-qemu-devel@patchwork.kernel.org; Tue, 09 Jul 2019 16:44:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60480) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkwt8-0005tm-LL for qemu-devel@nongnu.org; Tue, 09 Jul 2019 16:38:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hkwt5-00014S-BH for qemu-devel@nongnu.org; Tue, 09 Jul 2019 16:38:58 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:50362) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hkwsw-0000jE-QN; Tue, 09 Jul 2019 16:38:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1562704737; x=1594240737; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4bRnmZTuElmpehaFuMCmU2Mkur6fL6pum6lfWyF8J5Q=; b=aSqsNywJvon9Hp/F0CImXxQWALrWFzI0kL52PR7BiORrxHWtFiCrRieY 5D7kCAg5Lja7stMt3GQ0/q+KEs57pFNmTMrQtiAWMTTBd2LNihgn08ELh P9okANY8Lfj7EoJWx6aabyHdB2NujZbhDaJ9sWAoaHjB6OhqA2HtG3pTM UyUFDHehJoRpgF767x84B8SQqAtNdxISLWOWFKgh/LQvoYoB/1i5yllfa 8By/6h0JCRAXb7YJGsNla7gh3Q7famTgiBCwo2x6ttgcdBeWvZop4TiN9 +NyHABcKrQxHQ2Al5yEhrteQazeeP4sHzOlaFmIzHdK2EJngGWZ5F8zXF Q==; IronPort-SDR: s4Gm3O/cjX0OFRNaozLwK1LqHNAg9VE4y7q8GutQjqMpilMsVJ7N8yzGWvr8vqqatosLOjxb07 AWWt17jhbDRLU6mMlK7nGmxYsTZ6B9QEdSoP1hgs0vA3FMJ26JuV0+sccWEMtlAEJVqdKSW0s+ Zcrq1FY+QWqM5q14jO1GN2oly2LMTyp2DrBOeoVKApZP2GKISBlshwM1g8ufJIXGH7CX8OWqcx 3z5aO2Zp9W+9Zsq+0I8hwmP7f3Oe8Cjp1me1mkTgDHPvAzkP5oRoCNhpIWJF7SiOlya2pYJUUG bds= X-IronPort-AV: E=Sophos;i="5.63,471,1557158400"; d="scan'208";a="212488455" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 10 Jul 2019 04:38:57 +0800 IronPort-SDR: YnjMF3amshJBXEm7cdBbDV8BK40nA14C4ZWpIbby4ErTrB1spYm861siMDElG/3yf4An06xhBy eqv9+vKFB9xgey6836ILelnvQb6Xa4cmCo1FKWki5oXkmLo/yNdfKXRend/PrquwUrFVtYCUGf io0rkdziP5LYW73yBgGIUYihOOlMJPfDN3quau3+tlo0DCjNlEgS3rjuHytlImX5UZ0+e4RPGC +RAi23i0XCTrw7h+B/L0vH9q8Fs/pzB0Aqf9o+gqyR7v6geVjXuPh4uzx4kB+PbBRJs7fNxZH/ pwM822F6aN+bPxLGlnZCD5vF Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP; 09 Jul 2019 13:37:33 -0700 IronPort-SDR: LMEA0a0Q09Wv3PN7GtMAPOAKDzRUwdngM/IgoSNM9Rxii8d4dNumYVkxdW72JNti7G/xP0/s0a ZI9z2/JO1ioMXRkLR3XlrTJqtlzDzs8LjkDuY1wgyZyRRjzJ0L27iMQgBUFIwNppaDpczBGqhA EaWp5RJGcrtYzVCY4YNJPTFLP0ZlqlQGhgIXmP98aIsrcwxQAWk/4mfDjzKlSkGc4TNrDAmdm5 3J3uKOd7U4HFAr9kgXRCBZbwbMNLHaqUPoN4bfVcXy278rZHJIH1LKXaNpYXupE/AUOIen2cNe WH0= Received: from dhcp-10-88-173-43.hgst.com ([10.88.173.43]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Jul 2019 13:38:46 -0700 From: Dmitry Fomichev To: kwolf@redhat.com, mreitz@redhat.com, mst@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, fam@euphon.net, qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Tue, 9 Jul 2019 16:38:06 -0400 Message-Id: <20190709203806.17550-5-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190709203806.17550-1-dmitry.fomichev@wdc.com> References: <20190709203806.17550-1-dmitry.fomichev@wdc.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x X-Received-From: 68.232.143.124 Subject: [Qemu-devel] [PATCH 4/4] hw/scsi: Don't realize zoned block devices for virtio-scsi legacy drivers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Shin'ichiro Kawasaki Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Shin'ichiro Kawasaki Prevent scsi-hd and scsi-disk drivers from attaching a zoned block device because it will appear as a regular block device at the guest and will most certainly cause problems. The functionality to support ZBDs is not planned for scsi-hd and scsi-disk legacy drivers. It is supported via scsi-generic driver already and discussion is ongoing for scsi-block driver. Signed-off-by: Shin'ichiro Kawasaki --- hw/scsi/scsi-disk.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index ed7295bfd7..80682a61fb 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -2401,6 +2401,11 @@ static void scsi_hd_realize(SCSIDevice *dev, Error **errp) * backend will be issued in scsi_realize */ if (s->qdev.conf.blk) { + if (blk_is_zoned(s->qdev.conf.blk)) { + error_setg(errp, "zoned block devices are not supported"); + return; + } + ctx = blk_get_aio_context(s->qdev.conf.blk); aio_context_acquire(ctx); blkconf_blocksizes(&s->qdev.conf);