From patchwork Sat Sep 7 22:38:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Fomichev X-Patchwork-Id: 11136715 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D1CF016B1 for ; Sat, 7 Sep 2019 22:42:39 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A32BD21835 for ; Sat, 7 Sep 2019 22:42:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="AzHSg2te" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A32BD21835 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:37502 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i6jPi-0007vA-Qe for patchwork-qemu-devel@patchwork.kernel.org; Sat, 07 Sep 2019 18:42:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57509) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i6jM7-00040W-HL for qemu-devel@nongnu.org; Sat, 07 Sep 2019 18:38:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i6jM6-0005di-4X for qemu-devel@nongnu.org; Sat, 07 Sep 2019 18:38:55 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:36655) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i6jM1-0005aj-Pc; Sat, 07 Sep 2019 18:38:50 -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=1567895929; x=1599431929; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nzgcP/IXDXWd7sGOatWYeHRKe9iS1Xze+OLw2406t6o=; b=AzHSg2tew60lE0ajGH0rpvwUa3MOfc0zLNA/L9v4IlcBz30dMfmAmFY+ Arh/kwjSN9TrLJvUCfwJfVNf9IKD/u/LcBFpju4AGlWfqGdNEKD5KYcW7 ZzPVG6PK9a/svDvdtBLlXngZU3Qv4VjIp41xlqs7IARfrY29UZT1pVDOc GQHAjCaQHoiWCNX64d6rpVS6iKrC4fCzyXaIJKcqMooM46by9z9CZ8mo1 PpDHalut76YHXqh/Yk1dvXXgkKKns7y943aLKHHmHdaZbZYHg/6gUfnAm d9JoxDra1cpVXET2Rm5OjxlLituNE3NU+gi9TKUSszP+0h9S8Vrp7Wbu2 A==; IronPort-SDR: PGNpeKMcOLuIFtZtad8U6CcOOXmbxuOJv3IIkGWdj+RJCYurhnO1tkMnh29/cz6xTVEnyvXBl1 SqebIaOk8f4em28UWcsQjWD9XlLAIqkeTgcLXA/7t5pIYQVDItH58Cy9vH9prKm29eCY95XfwK K0n9cF3MIlkvn7Svafq9lzPEhcPhw1YiE6MlgUIi9r0ujcU7J18Abihf4/Ok78oYl+nkCeyS+1 i5yDE8EeWjBnafZF1nBBzLR62UfYT9txOUXuU7WleVCcG0BdE2fADqOU3hxvhRwiyiplPjJH6t e40= X-IronPort-AV: E=Sophos;i="5.64,478,1559491200"; d="scan'208";a="224505947" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 08 Sep 2019 06:38:44 +0800 IronPort-SDR: Qcawq3AMzSD7hQDM0b3fUXxBwC/5HNKmWj1mkRLyaS8ivElxTTkMAnl16G/N1ab5M2ShccfkzO fprCtHwMhAtOMk7n2R3zEHUKyh9yU4B5Kfb+9vkWvwh59wZZGSU/0gO0Xi+4aXa4X9OIk65gfj DFf7WxpU6W4zOuiV3kwts+oZxSjya11CjvbOdYPXHlZMuebLIlh7oNCPP0V9GrlpYR2PJ6S2Hc 7RMuEzYuPEm1NMVPXahjWwLN5dntY+tgkaDe9L9NrJGZ6pIALaHEX1wLOKBk7vIW3I2XtAVr1a 9htQ+cYPhyf7TQr/CH1CCtk4 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Sep 2019 15:35:34 -0700 IronPort-SDR: W+3Jn06x/6nyx/2aVS2fzHbwsn5KXMsa0gMdOEu8e8INbm7U9nBbaJUolsI3zo7wiq16UWGYLk sVZfcKr+P6/4udGmoXERX5mhmafCpHtKXHBYEegFuiv3Xz/cx2P8bk6AL3UEWdnk2SwVbkPFAw 4t22tKpsZNYI1WrgLlG9pfr/KKpNerYQH6WwWDUKrIHbCU15qm1xvB6vaKxivsSQBbQF8T+FLS iPCFAum7vFdWpUyEeeTBWlWyr7Y1ZG9PXwk/nXWt7rZVvW68I9pAcnG2WsZJk1l4sUV4RuKzAt VqQ= WDCIronportException: Internal Received: from dhcp-10-88-173-181.hgst.com ([10.88.173.181]) by uls-op-cesaip02.wdc.com with ESMTP; 07 Sep 2019 15:38:43 -0700 From: Dmitry Fomichev To: Stefano Garzarella , Paolo Bonzini , Kevin Wolf , Max Reitz , "Michael S . Tsirkin" , Stefan Hajnoczi , John Snow Date: Sat, 7 Sep 2019 18:38:38 -0400 Message-Id: <20190907223841.20210-2-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190907223841.20210-1-dmitry.fomichev@wdc.com> References: <20190907223841.20210-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.141.245 Subject: [Qemu-devel] [PATCH v7 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 , Alistair Francis , qemu-devel@nongnu.org, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" This commit adds Zoned Device Model (as defined in T10 ZBC and T13 ZAC standards) as a block driver property, along with some useful access functions. A new backend driver permission, BLK_PERM_SUPPORT_HM_ZONED, is also introduced. Only the drivers having this permission will be allowed to open host managed zoned block devices. No code is added yet to initialize or check the value of this new property, therefore this commit doesn't change any functionality. Signed-off-by: Dmitry Fomichev Reviewed-by: Stefan Hajnoczi Acked-by: Stefano Garzarella --- block.c | 37 +++++++++++++++++++++++++++---------- include/block/block.h | 21 +++++++++++++++++++-- include/block/block_int.h | 3 +++ qapi/block-core.json | 5 ++++- 4 files changed, 53 insertions(+), 13 deletions(-) diff --git a/block.c b/block.c index 5944124845..f0390196f2 100644 --- a/block.c +++ b/block.c @@ -1968,11 +1968,12 @@ char *bdrv_perm_names(uint64_t perm) uint64_t perm; const char *name; } permissions[] = { - { BLK_PERM_CONSISTENT_READ, "consistent read" }, - { BLK_PERM_WRITE, "write" }, - { BLK_PERM_WRITE_UNCHANGED, "write unchanged" }, - { BLK_PERM_RESIZE, "resize" }, - { BLK_PERM_GRAPH_MOD, "change children" }, + { BLK_PERM_CONSISTENT_READ, "consistent read" }, + { BLK_PERM_WRITE, "write" }, + { BLK_PERM_WRITE_UNCHANGED, "write unchanged" }, + { BLK_PERM_RESIZE, "resize" }, + { BLK_PERM_GRAPH_MOD, "change children" }, + { BLK_PERM_SUPPORT_HM_ZONED, "attach hm-zoned" }, { 0, NULL } }; @@ -4678,6 +4679,21 @@ void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr) *nb_sectors_ptr = nb_sectors < 0 ? 0 : nb_sectors; } +BdrvZonedModel bdrv_get_zoned_model(BlockDriverState *bs) +{ + return bs->bl.zoned_model; +} + +bool bdrv_is_hm_zoned(BlockDriverState *bs) +{ + /* + * Host Aware zone devices are supposed to be able to work + * just like regular block devices. Thus, we only consider + * Host Managed devices to be zoned here. + */ + return bdrv_get_zoned_model(bs) == BDRV_ZONED_MODEL_HM; +} + bool bdrv_is_sg(BlockDriverState *bs) { return bs->sg; @@ -4871,11 +4887,12 @@ static void xdbg_graph_add_edge(XDbgBlockGraphConstructor *gr, void *parent, } PermissionMap; static const PermissionMap permissions[] = { - { BLK_PERM_CONSISTENT_READ, BLOCK_PERMISSION_CONSISTENT_READ }, - { BLK_PERM_WRITE, BLOCK_PERMISSION_WRITE }, - { BLK_PERM_WRITE_UNCHANGED, BLOCK_PERMISSION_WRITE_UNCHANGED }, - { BLK_PERM_RESIZE, BLOCK_PERMISSION_RESIZE }, - { BLK_PERM_GRAPH_MOD, BLOCK_PERMISSION_GRAPH_MOD }, + { BLK_PERM_CONSISTENT_READ, BLOCK_PERMISSION_CONSISTENT_READ }, + { BLK_PERM_WRITE, BLOCK_PERMISSION_WRITE }, + { BLK_PERM_WRITE_UNCHANGED, BLOCK_PERMISSION_WRITE_UNCHANGED }, + { BLK_PERM_RESIZE, BLOCK_PERMISSION_RESIZE }, + { BLK_PERM_GRAPH_MOD, BLOCK_PERMISSION_GRAPH_MOD }, + { BLK_PERM_SUPPORT_HM_ZONED, BLOCK_PERMISSION_SUPPORT_HM_ZONED }, { 0, 0 } }; const PermissionMap *p; diff --git a/include/block/block.h b/include/block/block.h index 124ad40809..46cfa5bfa9 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -271,18 +271,33 @@ enum { */ BLK_PERM_GRAPH_MOD = 0x10, - BLK_PERM_ALL = 0x1f, + /** + * This permission is required to open host-managed zoned block devices. + */ + BLK_PERM_SUPPORT_HM_ZONED = 0x20, + + BLK_PERM_ALL = 0x3f, DEFAULT_PERM_PASSTHROUGH = BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE | BLK_PERM_WRITE_UNCHANGED - | BLK_PERM_RESIZE, + | BLK_PERM_RESIZE + | BLK_PERM_SUPPORT_HM_ZONED, DEFAULT_PERM_UNCHANGED = BLK_PERM_ALL & ~DEFAULT_PERM_PASSTHROUGH, }; char *bdrv_perm_names(uint64_t perm); +/* + * Known zoned device models. + */ +typedef enum { + BDRV_ZONED_MODEL_NONE, /* Regular block device */ + BDRV_ZONED_MODEL_HA, /* Host-aware zoned block device */ + BDRV_ZONED_MODEL_HM, /* Host-managed zoned block device */ +} BdrvZonedModel; + /* disk I/O throttling */ void bdrv_init(void); void bdrv_init_with_whitelist(void); @@ -359,6 +374,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); +BdrvZonedModel bdrv_get_zoned_model(BlockDriverState *bs); +bool bdrv_is_hm_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 0422acdf1c..928cbae9a5 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -635,6 +635,9 @@ typedef struct BlockLimits { /* maximum number of iovec elements */ int max_iov; + + /* Zoned device model. Zero value indicates a regular block device */ + BdrvZonedModel zoned_model; } BlockLimits; typedef struct BdrvOpBlocker BdrvOpBlocker; diff --git a/qapi/block-core.json b/qapi/block-core.json index e6edd641f1..860a8e16e5 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -1803,11 +1803,14 @@ # @graph-mod: This permission is required to change the node that this # BdrvChild points to. # +# @support-hm-zoned: This permission is required to attach host-managed +# zoned devices. +# # Since: 4.0 ## { 'enum': 'BlockPermission', 'data': [ 'consistent-read', 'write', 'write-unchanged', 'resize', - 'graph-mod' ] } + 'graph-mod', 'support-hm-zoned' ] } ## # @XDbgBlockGraphEdge: # From patchwork Sat Sep 7 22:38:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Fomichev X-Patchwork-Id: 11136717 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F385416B1 for ; Sat, 7 Sep 2019 22:42:52 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C946B21835 for ; Sat, 7 Sep 2019 22:42:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="VXWX4SXr" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C946B21835 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:37506 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i6jPv-0008DB-T3 for patchwork-qemu-devel@patchwork.kernel.org; Sat, 07 Sep 2019 18:42:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57508) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i6jM7-00040T-Gu for qemu-devel@nongnu.org; Sat, 07 Sep 2019 18:38:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i6jM6-0005da-4G for qemu-devel@nongnu.org; Sat, 07 Sep 2019 18:38:55 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:36655) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i6jM2-0005aj-O9; Sat, 07 Sep 2019 18:38:50 -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=1567895930; x=1599431930; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nEes3Wgtb3JW9qFDYao6VzVJMKi0IJ2s2eYSgN00rvE=; b=VXWX4SXr7xAO+nlZVsMhdnaNOwq5PQIrZ3k4GwF9VqeaGBt6weUcOBTS 3iDJAvSzrqeQZXu+2BQW/YQQJlLA1Kgn3pJKM4gF+F66RoPVB1VJGCtAH PYEexgFHXic1bbgGb2odFrqYHhnBk4q1DErdo1hH/xnEbB7N2eB0nM0Nr O8P1UcXsGMPc8Z6NYG2aXXXasIwFm9wf4XtNxxpI0P6tAIJKagR/IMO0z 3hyUW83hYP3oNSYpT6jj0Ty4GGezo7PaQSHJl9fMkBEnLWIf2AjsVMgvO TmCy4iKJ//glE4NI5YwWxs4yLTscKhQJgso3xe/yYGxJM+CMyeliSBKaZ g==; IronPort-SDR: U4kyYZxVglqzYa0t+r/eo3HuZ8Zqzar2T5zb22IBdlAI+QDtS/iQDT7aRG3MtVM0OjOJ7HRq2g RFA2qk33TuIo1k7lKyq8BuvIw3KUHuX5Xt862wsyxAfs6NigXU53FAHGCYaXNvh8B0yDYAqhs3 XOdvc5gX69VbkFnkw6ErnnHuzSWmWvt1saZh0nqYjd7aZNTYy18rSpu+uy/eqUzDkaWlVK8FpD K2v0JJal5bcLVyjacR33KWkADF4YbeeG5Tu9YU6afMVb4oe4mHP4ZS7zlmBx06nY4eF4ogqwun +VU= X-IronPort-AV: E=Sophos;i="5.64,478,1559491200"; d="scan'208";a="224505948" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 08 Sep 2019 06:38:45 +0800 IronPort-SDR: cWvg8FdTSLz+pI4p3ynedZ6A3tiKxGCdWGD0MpI+01txSXyiSVmcBsoGIEZBwYd2fXCOocneUN nZQULCS4a2UF1ufWLbmCyA0+CCDUPze2a9qLHAKKKpqYlbKQIDu+Dmce9eNjW24gvfebUyfMb5 /pPJJMbYcAQzLojE94Kmdk62ttM33OUszCysXQhckF2PRvEMDqtKVxAEBGG8WKgUrQg0BDJ3at IOkKO6CoRc6G4o7dHZZutCMLPo1aYDqI2N+xPkvL0SWDLl7ZpNoavgUwfXL7ggwgBaRJLKCY3O FSMWF8+dRVLwfeS0vdEsnbcY Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Sep 2019 15:35:35 -0700 IronPort-SDR: CV+8Lu8xnmm8cK8NgcWnkt/dmeQYML/OJpO34JJvn0wO2RBvZINVayjuouJzxNCPL22mJ0xYVv Bfqlwzm5HRgJKYzaQ64Wy60wCEz8lfFxxpO2yHsn5keA4GqKKeANhbF7ZUhw0szv8qzhKCx0MS YxkQMwREKp1NwqszajzoeNTi6KTzYJYZBjqn0h8GEQw8RbQJst/VRx8b4GWEyjL29rTOtN7N0T 7hoI83bJZQW43pEv9kNhWIJlHsHWbnzrhEVt18+eXkS1fu7D1fwAic1zjZfUGcJ3oITvDebgFl tiI= WDCIronportException: Internal Received: from dhcp-10-88-173-181.hgst.com ([10.88.173.181]) by uls-op-cesaip02.wdc.com with ESMTP; 07 Sep 2019 15:38:45 -0700 From: Dmitry Fomichev To: Stefano Garzarella , Paolo Bonzini , Kevin Wolf , Max Reitz , "Michael S . Tsirkin" , Stefan Hajnoczi , John Snow Date: Sat, 7 Sep 2019 18:38:39 -0400 Message-Id: <20190907223841.20210-3-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190907223841.20210-1-dmitry.fomichev@wdc.com> References: <20190907223841.20210-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.141.245 Subject: [Qemu-devel] [PATCH v7 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 , Alistair Francis , qemu-devel@nongnu.org, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 as it gets the Zoned Block Device Model value (none/host-managed/host-aware) from sysfs on the host. In order to avoid code duplication in file-posix.c, a common helper function is added to read values of sysfs entries under /sys/block//queue. This way, the existing function that reads the value of "max_segments" entry and the the new function that reads "zoned" value both share the same helper code. Signed-off-by: Dmitry Fomichev Reviewed-by: Stefan Hajnoczi --- block/file-posix.c | 75 ++++++++++++++++++++++++++++++++++++++-------- block/io.c | 5 ++++ 2 files changed, 67 insertions(+), 13 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 71f168ee2f..caacb21f07 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1067,15 +1067,13 @@ static int sg_get_max_transfer_length(int fd) #endif } -static int sg_get_max_segments(int fd) +static int hdev_read_blk_queue_entry(int fd, const char *key, + char *buf, int buf_len) { #ifdef CONFIG_LINUX - char buf[32]; - const char *end; char *sysfspath = NULL; int ret; int sysfd = -1; - long max_segments; struct stat st; if (fstat(fd, &st)) { @@ -1083,23 +1081,45 @@ static int sg_get_max_segments(int fd) goto out; } - 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); sysfd = open(sysfspath, O_RDONLY); if (sysfd == -1) { ret = -errno; goto out; } do { - ret = read(sysfd, buf, sizeof(buf) - 1); + ret = read(sysfd, buf, buf_len - 1); } while (ret == -1 && errno == EINTR); if (ret < 0) { ret = -errno; - goto out; } else if (ret == 0) { ret = -EIO; + } +out: + if (sysfd != -1) { + close(sysfd); + } + g_free(sysfspath); + return ret; +#else + return -ENOTSUP; +#endif +} + +static int sg_get_max_segments(int fd) +{ +#ifdef CONFIG_LINUX + char buf[32]; + const char *end; + int ret; + long max_segments; + + ret = hdev_read_blk_queue_entry(fd, "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); @@ -1108,22 +1128,45 @@ static int sg_get_max_segments(int fd) } out: - if (sysfd != -1) { - close(sysfd); - } - g_free(sysfspath); return ret; #else return -ENOTSUP; #endif } +static BdrvZonedModel hdev_get_zoned_model(int fd) +{ +#ifdef CONFIG_LINUX + char buf[32]; + BdrvZonedModel zm = BDRV_ZONED_MODEL_NONE; + int ret; + + ret = hdev_read_blk_queue_entry(fd, "zoned", buf, sizeof(buf)); + if (ret < 0) { + goto out; + } + + buf[ret - 1] = '\0'; /* replace the newline character with NULL */ + if (strcmp(buf, "host-managed") == 0) { + zm = BDRV_ZONED_MODEL_HM; + } else if (strcmp(buf, "host-aware") == 0) { + zm = BDRV_ZONED_MODEL_HA; + } + +out: + return zm; +#else + return BDRV_ZONED_MODEL_NONE; +#endif +} + static void raw_refresh_limits(BlockDriverState *bs, Error **errp) { BDRVRawState *s = bs->opaque; + int ret; if (bs->sg) { - int ret = sg_get_max_transfer_length(s->fd); + ret = sg_get_max_transfer_length(s->fd); if (ret > 0 && ret <= BDRV_REQUEST_MAX_BYTES) { bs->bl.max_transfer = pow2floor(ret); @@ -1133,6 +1176,12 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp) if (ret > 0) { bs->bl.max_transfer = MIN(bs->bl.max_transfer, ret * getpagesize()); } + + } + + ret = hdev_get_zoned_model(s->fd); + if (ret >= 0) { + bs->bl.zoned_model = ret; } raw_probe_alignment(bs, s->fd, errp); diff --git a/block/io.c b/block/io.c index 0fa10831ed..147c320061 100644 --- a/block/io.c +++ b/block/io.c @@ -157,6 +157,11 @@ void bdrv_refresh_limits(BlockDriverState *bs, Error **errp) return; } bdrv_merge_limits(&bs->bl, &bs->file->bs->bl); + + /* Propagate zoned model */ + if (!bs->probed) { + bs->bl.zoned_model = bs->file->bs->bl.zoned_model; + } } else { bs->bl.min_mem_alignment = 512; bs->bl.opt_mem_alignment = getpagesize(); From patchwork Sat Sep 7 22:38:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Fomichev X-Patchwork-Id: 11136709 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 50A6713B1 for ; Sat, 7 Sep 2019 22:40:26 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 183DD20693 for ; Sat, 7 Sep 2019 22:40:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="dSFez/Oa" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 183DD20693 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:37470 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i6jNY-0005RO-E0 for patchwork-qemu-devel@patchwork.kernel.org; Sat, 07 Sep 2019 18:40:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57523) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i6jM8-00041b-8q for qemu-devel@nongnu.org; Sat, 07 Sep 2019 18:38:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i6jM6-0005dv-NL for qemu-devel@nongnu.org; Sat, 07 Sep 2019 18:38:56 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:36655) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i6jM3-0005aj-B1; Sat, 07 Sep 2019 18:38:51 -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=1567895931; x=1599431931; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MBBhGo+Tqtqsv62cjvG7ulZIMWT4PuuygCiGCjKrtX0=; b=dSFez/OaNpfU7iSQVqxbP1PZaI/b3AhE7yKEBR3tRu5aUw7Zk+iYh5Vt tazmDW8o2YQzlxIJ9ZKR1riZFUYccaiBr/kHWp8vcVDPzpgwwlZkOr+TV v/t1leXop+ZYZ0mzOPGcqR/yUHCntNvfX+UHEn6vr4+Aoo4jNonVZo0ZT pBaOkEtykFCB2FzF7LnPkH5VWmCsQwyd+5CZ3Nu4s3+RMaZW3kqWpC+p8 rYmwbtuHMCwjuaRjJ27E/h2WUzsUKG+TsJuh/eXXbW7PADB3YncxrDGh6 jY7VuZQ/SEx8KnAH9NGY2OaFyjfMlx2C4DFBlJ6BtDM1CIJWDUKfWlRRd w==; IronPort-SDR: yLzymMVCORlnhR1b62wQw4HSRqxB8rMJeWYFqh6kX+JJMhe7C3giPdI4y9x34GDHseUoxMa9WZ B/XHTuTgWHFzNiGcblxP/UiB+adrsbFMJqiC5BaZBWblgW5uysU4Hi0mk0RU2RafrCCwp4Wxvd 6EFuGJ9yJEJgYq3EujS3RnW25keuhMOf5MZ9rpMmTTXr3EGXfSc0Mg3oFvVfGR0zcQ8Nlt9E65 BkagiIolrcwLo8BsxADaF6dqxl32VXYidAC82DqaHRZxcA/zviwcjLml4N8zjPFjdxPVUiu1d3 zNM= X-IronPort-AV: E=Sophos;i="5.64,478,1559491200"; d="scan'208";a="224505949" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 08 Sep 2019 06:38:46 +0800 IronPort-SDR: 0kcpaEq3UgT4ACtW1JFpWTWYLh7tn1G8rcy5ipsrg0PGEs8hl3ZvUuh0LKQeVf+s+RjPoXd6Tx APY96C8xX1enSVuHdXlJzemPVPWVsJdkZT1vo1tBZyisaRYFjXgtrPoXgorQyzhJi0h5nYCsdK QccFm55j3rpjXqHkW4yGva1WfRGfA41/amTS3cGIH2Yk737LKAJRkTXnXaJ5qVmOxwyDO1lhI2 kp+dMbpo0+0e1vfeHQDXWBKI8ZUsQWz1R4DNuy2x5+5Lmp9oe3x1dsTw/jmc/cSIkNBHfX63Dd FcOOOh7vxfEiS9eIESTN9ykC Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Sep 2019 15:35:36 -0700 IronPort-SDR: tUTrHUswYyjk4QDvvd/N0qKWUuhOM1WG3aGz4snqYqEko7OTrXjqYSizL9xmi5UYM8xuG6ZRkf 4ZfH0FRAdXbgmRKx6sJ3p/1MdgNICxq47/fQ46byIfpK7B6NXfRahzd/t5BRy348mH6LyHfZhi Oe+dc1gOk6mwJn7ab+jJGAzhc6FhTGdJ53dk2xZCJqBAoE5k6wFKJPq0obLUK/sAtY5g3HaHlr HiNsjmTMM0M8G0RKmmrscvN3kUoA64q3PZVml3zZU6wepyr1i5RxEGDaIXNZ9Lld+al1SkhN89 GGQ= WDCIronportException: Internal Received: from dhcp-10-88-173-181.hgst.com ([10.88.173.181]) by uls-op-cesaip02.wdc.com with ESMTP; 07 Sep 2019 15:38:46 -0700 From: Dmitry Fomichev To: Stefano Garzarella , Paolo Bonzini , Kevin Wolf , Max Reitz , "Michael S . Tsirkin" , Stefan Hajnoczi , John Snow Date: Sat, 7 Sep 2019 18:38:40 -0400 Message-Id: <20190907223841.20210-4-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190907223841.20210-1-dmitry.fomichev@wdc.com> References: <20190907223841.20210-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.141.245 Subject: [Qemu-devel] [PATCH v7 3/4] block/ide/scsi: Set BLK_PERM_SUPPORT_HM_ZONED 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 , Alistair Francis , qemu-devel@nongnu.org, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Added a new boolean argument to blkconf_apply_backend_options() to let the common block code know whether the chosen block backend can handle host managed zoned block devices. blkconf_apply_backend_options() then sets BLK_PERM_SUPPORT_HM_ZONED permission accordingly. The raw code can then use this permission to allow or deny opening a zone device by a particular block driver. Signed-off-by: Dmitry Fomichev Acked-by: Paul Durrant Reviewed-by: Stefan Hajnoczi --- hw/block/block.c | 6 +++++- hw/block/fdc.c | 5 +++-- hw/block/nvme.c | 2 +- hw/block/virtio-blk.c | 2 +- hw/block/xen-block.c | 2 +- hw/ide/qdev.c | 2 +- hw/scsi/scsi-disk.c | 13 +++++++------ hw/scsi/scsi-generic.c | 2 +- hw/usb/dev-storage.c | 2 +- include/hw/block/block.h | 3 ++- 10 files changed, 23 insertions(+), 16 deletions(-) diff --git a/hw/block/block.c b/hw/block/block.c index bf56c7612b..1c6019eee7 100644 --- a/hw/block/block.c +++ b/hw/block/block.c @@ -86,7 +86,8 @@ void blkconf_blocksizes(BlockConf *conf) } bool blkconf_apply_backend_options(BlockConf *conf, bool readonly, - bool resizable, Error **errp) + bool resizable, bool zoned_support, + Error **errp) { BlockBackend *blk = conf->blk; BlockdevOnError rerror, werror; @@ -98,6 +99,9 @@ bool blkconf_apply_backend_options(BlockConf *conf, bool readonly, if (!readonly) { perm |= BLK_PERM_WRITE; } + if (zoned_support) { + perm |= BLK_PERM_SUPPORT_HM_ZONED; + } shared_perm = BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED | BLK_PERM_GRAPH_MOD; diff --git a/hw/block/fdc.c b/hw/block/fdc.c index ac5d31e8c1..673a8b39bc 100644 --- a/hw/block/fdc.c +++ b/hw/block/fdc.c @@ -477,7 +477,7 @@ static void fd_change_cb(void *opaque, bool load, Error **errp) } else { if (!blkconf_apply_backend_options(drive->conf, blk_is_read_only(drive->blk), false, - errp)) { + false, errp)) { return; } } @@ -569,7 +569,8 @@ static void floppy_drive_realize(DeviceState *qdev, Error **errp) dev->conf.rerror = BLOCKDEV_ON_ERROR_AUTO; dev->conf.werror = BLOCKDEV_ON_ERROR_AUTO; - if (!blkconf_apply_backend_options(&dev->conf, read_only, false, errp)) { + if (!blkconf_apply_backend_options(&dev->conf, read_only, false, false, + errp)) { return; } diff --git a/hw/block/nvme.c b/hw/block/nvme.c index 12d8254250..07f08d0768 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -1334,7 +1334,7 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp) } blkconf_blocksizes(&n->conf); if (!blkconf_apply_backend_options(&n->conf, blk_is_read_only(n->conf.blk), - false, errp)) { + false, false, errp)) { return; } diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 18851601cb..8be62903e2 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1127,7 +1127,7 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp) if (!blkconf_apply_backend_options(&conf->conf, blk_is_read_only(conf->conf.blk), true, - errp)) { + false, errp)) { return; } s->original_wce = blk_enable_write_cache(conf->conf.blk); diff --git a/hw/block/xen-block.c b/hw/block/xen-block.c index f77343db60..57fe970908 100644 --- a/hw/block/xen-block.c +++ b/hw/block/xen-block.c @@ -229,7 +229,7 @@ static void xen_block_realize(XenDevice *xendev, Error **errp) } if (!blkconf_apply_backend_options(conf, blockdev->info & VDISK_READONLY, - true, errp)) { + true, false, errp)) { return; } diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c index 6fba6b62b8..a57a8f1a8f 100644 --- a/hw/ide/qdev.c +++ b/hw/ide/qdev.c @@ -200,7 +200,7 @@ static void ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind, Error **errp) } } if (!blkconf_apply_backend_options(&dev->conf, kind == IDE_CD, - kind != IDE_CD, errp)) { + kind != IDE_CD, false, errp)) { return; } diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index 915641a0f1..8a57caafd7 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -2318,7 +2318,7 @@ static void scsi_disk_unit_attention_reported(SCSIDevice *dev) } } -static void scsi_realize(SCSIDevice *dev, Error **errp) +static void scsi_realize(SCSIDevice *dev, bool zoned_support, Error **errp) { SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev); bool read_only; @@ -2362,7 +2362,8 @@ static void scsi_realize(SCSIDevice *dev, Error **errp) } if (!blkconf_apply_backend_options(&dev->conf, read_only, - dev->type == TYPE_DISK, errp)) { + dev->type == TYPE_DISK, zoned_support, + errp)) { return; } @@ -2421,7 +2422,7 @@ static void scsi_hd_realize(SCSIDevice *dev, Error **errp) if (!s->product) { s->product = g_strdup("QEMU HARDDISK"); } - scsi_realize(&s->qdev, errp); + scsi_realize(&s->qdev, false, errp); if (ctx) { aio_context_release(ctx); } @@ -2449,7 +2450,7 @@ static void scsi_cd_realize(SCSIDevice *dev, Error **errp) if (!s->product) { s->product = g_strdup("QEMU CD-ROM"); } - scsi_realize(&s->qdev, errp); + scsi_realize(&s->qdev, false, errp); aio_context_release(ctx); } @@ -2459,7 +2460,7 @@ static void scsi_disk_realize(SCSIDevice *dev, Error **errp) Error *local_err = NULL; if (!dev->conf.blk) { - scsi_realize(dev, &local_err); + scsi_realize(dev, false, &local_err); assert(local_err); error_propagate(errp, local_err); return; @@ -2652,7 +2653,7 @@ static void scsi_block_realize(SCSIDevice *dev, Error **errp) */ s->features |= (1 << SCSI_DISK_F_NO_REMOVABLE_DEVOPS); - scsi_realize(&s->qdev, errp); + scsi_realize(&s->qdev, true, errp); scsi_generic_read_device_inquiry(&s->qdev); out: diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c index e7798ebcd0..ccce710497 100644 --- a/hw/scsi/scsi-generic.c +++ b/hw/scsi/scsi-generic.c @@ -692,7 +692,7 @@ static void scsi_generic_realize(SCSIDevice *s, Error **errp) } if (!blkconf_apply_backend_options(&s->conf, blk_is_read_only(s->conf.blk), - true, errp)) { + true, true, errp)) { return; } diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c index 8545193488..c75c0dd6a5 100644 --- a/hw/usb/dev-storage.c +++ b/hw/usb/dev-storage.c @@ -603,7 +603,7 @@ static void usb_msd_storage_realize(USBDevice *dev, Error **errp) blkconf_blocksizes(&s->conf); if (!blkconf_apply_backend_options(&s->conf, blk_is_read_only(blk), true, - errp)) { + false, errp)) { return; } diff --git a/include/hw/block/block.h b/include/hw/block/block.h index 607539057a..f988edc87e 100644 --- a/include/hw/block/block.h +++ b/include/hw/block/block.h @@ -85,7 +85,8 @@ bool blkconf_geometry(BlockConf *conf, int *trans, Error **errp); void blkconf_blocksizes(BlockConf *conf); bool blkconf_apply_backend_options(BlockConf *conf, bool readonly, - bool resizable, Error **errp); + bool resizable, bool zoned_support, + Error **errp); /* Hard disk geometry */ From patchwork Sat Sep 7 22:38:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Fomichev X-Patchwork-Id: 11136711 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C3AC216B1 for ; Sat, 7 Sep 2019 22:40:27 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9B29620693 for ; Sat, 7 Sep 2019 22:40:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="c54lLrnU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9B29620693 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:37474 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i6jNa-0005V1-Nq for patchwork-qemu-devel@patchwork.kernel.org; Sat, 07 Sep 2019 18:40:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57501) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i6jM7-00040B-3P for qemu-devel@nongnu.org; Sat, 07 Sep 2019 18:38:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i6jM6-0005dk-4Y for qemu-devel@nongnu.org; Sat, 07 Sep 2019 18:38:55 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:36657) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i6jM3-0005cW-CK; Sat, 07 Sep 2019 18:38:51 -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=1567895931; x=1599431931; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LI1nlGxApBLJrhe1y3qiBnJa248FPNVAYbXtDolUxMs=; b=c54lLrnUdiTPLI/22EndfndqK3ZpllloyGl1av9uGDBsUyF23E1/ZCCu w8TnCDNp3PosW51LOjJmnD2IMzeJsntx4qT3CGJwfSKLJF62hPPgm+rr7 8v0P6wqS17nZlZQ0U2G4YBcsMVYFL1e6PPZ7JAHgHNJy3Sb9FAJ9aJ2H6 CfCRn+3omZTytMSKmfX68+CNlG9dVNbrxPxwjp+f//mpN0TWqF5gY1pSo CDlt+ttFJm4hFYOf9OE0qgc30o9zjAONrkFdlZhjZ6EIeLyHw2acPYx66 H9Wq+4CdDj30sP5mWu1vgd1JI05wRdZC5j+rDBnXvKlkVqX88Xpvl691/ A==; IronPort-SDR: +WqYKLyu6jtKkhAVzIDA0mWdVOz4cmA0XdDvCxssyFmcZ+uAn2oDgIaRjJrcVGtc8tvZlIKLZr pyASl9ty3thvUR+q6e0FNXb/bHsx9jaGQVLLz6LMrmk8wp1Okos6RJ0pehJmpgcxbofGEoJz3t 49u0cD4jJjqAuxvEbotHjWwTwjPIgugxQlaQxQfgRX3bAGaGsdXMJS+zgH3XCmOmqXwn/uXlJk i1ydsurevJAV8W/6WWh7XjcBWTLzzlpTRRZU/3/fhJLSMQQgRCTXPf4E1LguZDzBjnlhgmJtVz Ft8= X-IronPort-AV: E=Sophos;i="5.64,478,1559491200"; d="scan'208";a="224505950" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 08 Sep 2019 06:38:47 +0800 IronPort-SDR: P3KVC+NxNvbQpAaGrTGMO8GQdI2WT5iFm6QMN7g+4pKwAGE2Zss5syA2x5C5n40ccNh4ibC2M9 CnZt8uFcFgbBaop0aE4NYICXezzRJq3paKdIhOQ5vix5xktMjSQKhcEB8ffHyZkdKxT7aMQZJp o4/PO63WSSRJ8HyaYT7mstkXlBquY/0Vy3zN75nY3VN4O2+0h243TWa6NgYe7W37X13O19fppe qzB66Dt2hM6IwLm6WJcs9jAzA627HwSIbyczGJil6XGVkaHyUayAbGy17XnnCLwd+PXi13ZqIF aZFy517FxI17iqS6QNVjqP6i Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Sep 2019 15:35:37 -0700 IronPort-SDR: /70fQU78ZlVFr7dW7IgmwycdifH+b3HJBsM8+UriisMTG5hR3cguucvCMVUdnknIUw+MZXCBKf UkNx8Gh9OmUaiAdsYGvEGpXLmKXa7HuNd5noTQ46btKA/0uRzWtaegPrh2ZcMjh31/TE+p/08n nLZn+FCvHhXoC2huiMdTFWVMVjNnMX+Ue/aEQj5R02ejRdEdnWCUlSxqEFBTJC9h2ZHoL0TOYR QMM0s86b7gWTPtc2hGEkyUtQKoTIWpFE5IY3saOch999WHiqe5V0fcXU9RBIXVhvstz52xplG/ hI4= WDCIronportException: Internal Received: from dhcp-10-88-173-181.hgst.com ([10.88.173.181]) by uls-op-cesaip02.wdc.com with ESMTP; 07 Sep 2019 15:38:47 -0700 From: Dmitry Fomichev To: Stefano Garzarella , Paolo Bonzini , Kevin Wolf , Max Reitz , "Michael S . Tsirkin" , Stefan Hajnoczi , John Snow Date: Sat, 7 Sep 2019 18:38:41 -0400 Message-Id: <20190907223841.20210-5-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190907223841.20210-1-dmitry.fomichev@wdc.com> References: <20190907223841.20210-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.141.245 Subject: [Qemu-devel] [PATCH v7 4/4] raw: Don't open ZBDs if backend can't handle them 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 , Alistair Francis , qemu-devel@nongnu.org, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Abort opening a zoned device as a raw file in case the chosen block backend driver lacks proper support for this type of storage. Signed-off-by: Dmitry Fomichev Reviewed-by: Stefan Hajnoczi --- block/file-posix.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/block/file-posix.c b/block/file-posix.c index caacb21f07..3de371a97d 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2934,6 +2934,20 @@ static int raw_check_perm(BlockDriverState *bs, uint64_t perm, uint64_t shared, goto fail; } } + + /* + * If we are opening a zoned block device, check if the backend + * driver can properly handle host-managed devices, abort if not. + */ + if (bdrv_is_hm_zoned(bs) && + !(shared & BLK_PERM_SUPPORT_HM_ZONED) && + !(perm & BLK_PERM_SUPPORT_HM_ZONED)) { + error_setg(errp, + "block backend driver doesn't support host-managed zoned devices"); + ret = -ENOTSUP; + goto fail; + } + return 0; fail: