From patchwork Fri Aug 23 19:49:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Fomichev X-Patchwork-Id: 11112351 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 1DABA1395 for ; Fri, 23 Aug 2019 19:51:09 +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 E77C92173B for ; Fri, 23 Aug 2019 19:51:08 +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="ZdBx1Oc3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E77C92173B 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]:33788 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1FaV-0002T8-J9 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 23 Aug 2019 15:51:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51959) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1FZ4-0000Md-MV for qemu-devel@nongnu.org; Fri, 23 Aug 2019 15:49:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i1FZ3-0000Yy-1p for qemu-devel@nongnu.org; Fri, 23 Aug 2019 15:49:38 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:47023) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i1FYz-0000VF-Ot; Fri, 23 Aug 2019 15:49:34 -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=1566589773; x=1598125773; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wDuJg/PXjCdmnfQAHj6RMyp+qTSDniP3cOnxGOeYBNk=; b=ZdBx1Oc31O2p3EKfsP1mrbbvP00UeNfeBX4wS14zVgs9i4bcpUNj13PM PVgFXKTtwkvSFIQP/i1105F90o506/O/280bd3HGtPboc1U+1FIdUHa9p duphs02L0t3M/ZEvGa8nqPYbIC5TNrkH3XPVFZdFn+1rLwSpWHslcihSt y1t0AXMi1/7A5xPlyfrWIbUyx0JtyTtwnu5Kfts3YME5QhJxDEYgfes15 hD0NxI82pkmyu2ppfG6UN6aiSOlzocgfJUJVBf6OUic41HEnmwoxmG8sA 2b/UWTXxnmWJRpL7eCp5AlZl2rqb1nXI0le+PI/NXkRmU53dXTaHOnJrv w==; IronPort-SDR: BkLd43PsiEyLo3YtORPUd+trE32xhYz7CPl+yZsW4rctQkkurPhJzwuhGC+twkEKOT5fDcv27i qOM1lV4Mj2JuR14EpmQyROTqM06MWIceY9pnf1HI3cJpRxZD+zzUdSBWzAAw4xTdYgBpb57RZX BrtDjZDmX6z3uk1oOs7hAkhO2SFdahxoBN/KqtdbDBXEzDChJVFmbUsoiKw+vkvKolrGuPiK7H DslOllVyssq7r+4TJpOj0pMPpqqt1VrqwqtMpsBQqCIEe63X3lyl2H4ZPqvrlkLPKJ/5XjSUqJ lcc= X-IronPort-AV: E=Sophos;i="5.64,422,1559491200"; d="scan'208";a="223162541" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 24 Aug 2019 03:49:30 +0800 IronPort-SDR: J2WD8F5Xn2K/+kvKZjgoSimlYh3VTOJ7rBZw7wPc35M5XwQxy5bXiRxsRKyJkXrNFOgqRhgSgc Zo5y2UWR06xSa5iArXaDK8b893rjizFb2Zyy1xXWNrobt2aej7tIt285lWv8gec8ZcGhsZnNuu VYX/uJ2au8uHR4TcDmrF9VGFDjPHPf8W2u4eHLP7dGHG9zKOBEW83gAyF7T+8Rphmcz4mqBhKb X9hDsikyB7+0dwrM+GyNAgkisQ27uidguVLK783vfUJczcn2jWHoMTufw1YKS42MQDy27TJAnQ nG1wYFeJKmu2J2giMp8BIc4l Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Aug 2019 12:46:47 -0700 IronPort-SDR: vBJ9GDBcUKCJ43pvweSm+35EnA3o/bF8Jnl6zCZxQYOqPFDuqfzIo4eNWx4X1/lWRf0Rl8bP6K anjdzADvqGrGsiM9wSoRIR6g030S7Bwi/2eEDeM2XN0y+8FhK87P1BhzhNglLUlzpL8JjplDDD 3uKiNIMlq+PdWJXR07NGJ3C4vdVn2QsRlwR1rJVTgLBFIvMoxsrASxkL89UQisXVnbFr+Rqlq+ r7fEuBA9YNTr9iX+m8QwsWdVRHM0Q5v5P76tBUDBoFa9H3YEl4N46n6sf+VJP3VxFgHKmUH901 HMk= WDCIronportException: Internal Received: from dhcp-10-88-173-43.hgst.com ([10.88.173.43]) by uls-op-cesaip02.wdc.com with ESMTP; 23 Aug 2019 12:49:29 -0700 From: Dmitry Fomichev To: Paolo Bonzini , Kevin Wolf , Max Reitz , "Michael S . Tsirkin" , Stefan Hajnoczi , John Snow Date: Fri, 23 Aug 2019 15:49:24 -0400 Message-Id: <20190823194927.23278-2-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190823194927.23278-1-dmitry.fomichev@wdc.com> References: <20190823194927.23278-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 v5 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_ZONED, is also introduced. Only the drivers having this permission will be allowed to open 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 --- block.c | 19 +++++++++++++++++++ include/block/block.h | 21 ++++++++++++++++++++- include/block/block_int.h | 4 ++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index 874a29a983..6dd4cecded 100644 --- a/block.c +++ b/block.c @@ -4679,6 +4679,25 @@ 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) +{ + /* + * 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) == BLK_ZONED_MODEL_HM; +} + bool bdrv_is_sg(BlockDriverState *bs) { return bs->sg; diff --git a/include/block/block.h b/include/block/block.h index 124ad40809..238c0f5ed7 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -271,18 +271,35 @@ enum { */ BLK_PERM_GRAPH_MOD = 0x10, + /** This permission is required to open zoned block devices. */ + BLK_PERM_SUPPORT_ZONED = 0x20, + BLK_PERM_ALL = 0x1f, DEFAULT_PERM_PASSTHROUGH = BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE | BLK_PERM_WRITE_UNCHANGED - | BLK_PERM_RESIZE, + | BLK_PERM_RESIZE + | BLK_PERM_SUPPORT_ZONED, DEFAULT_PERM_UNCHANGED = BLK_PERM_ALL & ~DEFAULT_PERM_PASSTHROUGH, }; char *bdrv_perm_names(uint64_t perm); +/* + * Known zoned device models. + * + * TODO For a Linux host, it could be preferrable to include + * /usr/include/linux/blkzoned.h instead of defining ZBD-specific + * values here. + */ +enum blk_zoned_model { + BLK_ZONED_MODEL_NONE, /* Regular block device */ + BLK_ZONED_MODEL_HA, /* Host-aware zoned block device */ + BLK_ZONED_MODEL_HM, /* Host-managed zoned block device */ +}; + /* disk I/O throttling */ void bdrv_init(void); void bdrv_init_with_whitelist(void); @@ -359,6 +376,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 ceec8c2f56..91496e8149 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -415,6 +415,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 @@ -620,6 +621,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; From patchwork Fri Aug 23 19:49:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Fomichev X-Patchwork-Id: 11112355 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 C54F21395 for ; Fri, 23 Aug 2019 19:53:15 +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 9B0AF20850 for ; Fri, 23 Aug 2019 19:53:15 +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="ifOB6vc7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9B0AF20850 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]:33840 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1FcY-0005u2-PD for patchwork-qemu-devel@patchwork.kernel.org; Fri, 23 Aug 2019 15:53:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51963) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1FZ4-0000N1-TR for qemu-devel@nongnu.org; Fri, 23 Aug 2019 15:49:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i1FZ3-0000ZH-Dc for qemu-devel@nongnu.org; Fri, 23 Aug 2019 15:49:38 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:47029) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i1FYz-0000Vz-UC; Fri, 23 Aug 2019 15:49:34 -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=1566589773; x=1598125773; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WrGHKVduBl42d9CD8UFRTIZ6FP7W7UcEwBBJuvUCUsc=; b=ifOB6vc7DtOEdvBHYyR0LB8zJ70UG5mFdYJ69KK/MQWGMyRNFG1V+WXY 8gS+M/JjdQhLkhcBWzjn4yYawVNFCrypfwXRXBX5uAlhxeEyRb0KgsYgb YgSt168vKwrHqVNupArxJ1CCRAZ8gS2Xe0nGLLnMOHKKYPeb2G6vta0u9 W5giKvYHhQN9A71QZue98R6iWkwM1GJDGM7PdlNvC2rLTTr52P10VBmfN OZvnjLYDtU/oDOD5qKMRvKmktzL4JeMWKuHCyWTPDLNYh2BwbHpXFnJMw PPCru7lYC1XV2spjb2RNJbEh4nOOB7bb+zCYjsvTnAFPg75DSbQjJtD7Y Q==; IronPort-SDR: tfxG8xI3MsCnbMEhfubaz7syZCjIWqSVYjUmwkaN9BVN1CDbsGMw0pIxLDugT21glrklMEYaJw 0pwABFmujW+TZXrcYLsLjgwEBg7VxE9KJE/Uz3vpBCbUw/krlGs4jCxtbO0ArtizP0y2SyaUOS 1IGTu05Be12AMqC5yBPM2yF1absk62p3YvuZI0ejAeE+y3ha9jPLTfg06HALsaHGXw9yICojLw X4J03UBy6yNueyONuC64b98+YDWNooD8pi8vIYnDp69wNOwefxfbzUR+7ZUJ0386ZazKfFTW4D G9U= X-IronPort-AV: E=Sophos;i="5.64,422,1559491200"; d="scan'208";a="223162544" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 24 Aug 2019 03:49:31 +0800 IronPort-SDR: GSIqev7wKYTasPSm4e3hmBUG21rqNX1YTMPiuRSYpP3v7W0Hs7Lc3D98rv2GrmLRXRai0yMMZP ETIB95m3D+cbtzca38XzUICelQwv1sQynFu3K409yy385waPOz0xC9ohl4tfxJiXTZg+zI4fjM WfLCrGuCgreoQjJdoA2xbLDv5MTgJlWrkhM3kv+iWhWe3DwwZs4oRc+/GKdQ9Nd2kkSWUFO2er FQ5GFvrFhD6TZKRbsDCmSGipY9gUzKUZciY8H1rBcZSu0NGGKCaQ+IzHts4u/8+VcExKB73idU UB9ebLUgMz8iXKLPFZLjkOM8 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Aug 2019 12:46:48 -0700 IronPort-SDR: ZNIbsON233fRjxDLQGGYzjFw8FjCDlQq16etIM21Ox5MLPSBUbrEMXzD033aOsIjPnsm05J2xW MTyx1JTR8ouPSZ+HCOYco/cRJYppmDk2dK5gyL95zJhgZPyYzG9VGhdwUU/35MiRmb3Vc+pkpf ydBQrpOI3eFarT6jWC3/qMWmRglCnWpBb/N/OHQ3OSm9ErFOg2kNuRbpakCgYXqU6hq3piFPsf 6sD4aBfr2H7DqAS0K/+8WpXZs9aYEYjU6S7OjxGIc9hnbIsTXo/DZ/+lWiPZIiS2aEUmnofM1q 0NA= WDCIronportException: Internal Received: from dhcp-10-88-173-43.hgst.com ([10.88.173.43]) by uls-op-cesaip02.wdc.com with ESMTP; 23 Aug 2019 12:49:30 -0700 From: Dmitry Fomichev To: Paolo Bonzini , Kevin Wolf , Max Reitz , "Michael S . Tsirkin" , Stefan Hajnoczi , John Snow Date: Fri, 23 Aug 2019 15:49:25 -0400 Message-Id: <20190823194927.23278-3-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190823194927.23278-1-dmitry.fomichev@wdc.com> References: <20190823194927.23278-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 v5 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 --- block/file-posix.c | 74 ++++++++++++++++++++++++++++++++++++++-------- block/raw-format.c | 8 +++++ 2 files changed, 70 insertions(+), 12 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index fbeb0068db..d9f2fc5e46 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,10 +1128,33 @@ static int sg_get_max_segments(int fd) } out: - if (sysfd != -1) { - close(sysfd); + return ret; +#else + return -ENOTSUP; +#endif +} + +static int hdev_get_zoned_model(int fd) +{ +#ifdef CONFIG_LINUX + char buf[32]; + int ret; + + ret = hdev_read_blk_queue_entry(fd, "zoned", buf, sizeof(buf)); + if (ret < 0) { + ret = BLK_ZONED_MODEL_NONE; + goto out; } - g_free(sysfspath); + + buf[ret - 1] = 0; + ret = BLK_ZONED_MODEL_NONE; + if (strcmp(buf, "host-managed") == 0) { + ret = BLK_ZONED_MODEL_HM; + } else if (strcmp(buf, "host-aware") == 0) { + ret = BLK_ZONED_MODEL_HA; + } + +out: return ret; #else return -ENOTSUP; @@ -1121,9 +1164,10 @@ out: 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 +1177,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/raw-format.c b/block/raw-format.c index 42c28cc29a..a606e4a7fe 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) { @@ -578,6 +585,7 @@ BlockDriver bdrv_raw = { .create_opts = &raw_create_opts, .bdrv_has_zero_init = &raw_has_zero_init, .bdrv_has_zero_init_truncate = &raw_has_zero_init_truncate, + .bdrv_get_zoned_info = &raw_get_zoned_info, .strong_runtime_opts = raw_strong_runtime_opts, .mutable_opts = mutable_opts, }; From patchwork Fri Aug 23 19:49:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Fomichev X-Patchwork-Id: 11112357 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 7B43513A4 for ; Fri, 23 Aug 2019 19:54:59 +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 510BE20850 for ; Fri, 23 Aug 2019 19:54:59 +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="dZlI2o2V" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 510BE20850 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]:33868 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1FeE-00083k-HJ for patchwork-qemu-devel@patchwork.kernel.org; Fri, 23 Aug 2019 15:54:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51998) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1FZ6-0000QV-TC for qemu-devel@nongnu.org; Fri, 23 Aug 2019 15:49:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i1FZ5-0000ad-31 for qemu-devel@nongnu.org; Fri, 23 Aug 2019 15:49:40 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:47023) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i1FZ0-0000VF-Jw; Fri, 23 Aug 2019 15:49:34 -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=1566589774; x=1598125774; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ArUqT7gctwo2CvLYjZvaT+85TujFifdpj4yt8JCxXJM=; b=dZlI2o2V+aNvz81HsUBVYdTyXC/KHYpxu+A+tAIkF/JkRK9X7IKvQwBn rGYIwg6pDqBWLBUSTBGKOe4RWziJS7DcsYRrE76lBrBc94OlZkl+j/tgY chpFVxJE4BoKi49OZyF6WaHW8SthHO1K5MR1lz1d99s9peUkbjSzXKMv8 yQaDdglZ7lITe0+TdbWBZetXhzpbG37n2jWVFWTt7ifDxi6k2ItBYHpG0 hsOcmbpRL9iXXDqq12qcDpmO1EPS3rJZDH3iwJsSYAebJTU7TADV+sr1H vihM9tqPcursKHYosVVKReJnfDrnkXmhO6NIG5PM6+hQd1B2tA1vkZhiY w==; IronPort-SDR: /UxrVOYPyLgIZ9FwO/lRiIxcY0cq1KXTGhflB0CPqVfficLGlXk67Wtch2I2ebuOjZt3CvySDe mbSaIElOqhoHL3dtNGME6gMzFI35lnWD89B67vvo9dMHq54lDKhlKXq23gWp4rlD6PFSMnJC+v f5r9BVKjXkxfZ1BBKCkBohSWnnH2njkosy8cJN9/ZiWVohDDYeGm3AX+jt1MSKBRUfc8OmNR0s s315XaWVRCdpz4f1FYHPwflOtMGUNNVVt8G4THsoqc81D69w7ELbBsLVvPHuFWbYkle7hU5iDg zkk= X-IronPort-AV: E=Sophos;i="5.64,422,1559491200"; d="scan'208";a="223162546" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 24 Aug 2019 03:49:32 +0800 IronPort-SDR: +K+5GtX5218W74b7tDc+y6IiiUHb348xMmdQjxgT35Lq17GjRyIHeGmZnQ2jRmtXm+NvxA9QK1 4XTsrRvfgJ/1/QRfRAD+FhW/QScwDFO3alRDG+YFy1wi6YdwEdAc/Spj1ZbBehaJ2GlMfVf82b CMdwkrQEEoJiYMXMxj5SwXt4JC+QMwy2hAKK8jkV1sSQ3oh1fsmKjA0jrX7W2hj/RfGGa5VP0C kYFdI3b70Yp73co85CLntytf9yWWroSnd0cbPLocQJYZbc3yjkYZ8ME3cRUUwaClmUiRW9Y2+k PgvcuQBFl/XZdl4mZKT7mvVE Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Aug 2019 12:46:49 -0700 IronPort-SDR: 6A7zUUx6WEpxSPBoP0l0I2jMehnUqOsS+i8Ky/ge2bFM0VVnadEylExS+xkRvFZXpx1VW/v27d Gsb2WBXQHBtCyuXH/uFym7Zj2IPoNXc9QbSBbzxz2BiXlERudr6dYS4fTNcf04OlPXHE3HlzWL zXz0Ae9YyYPnDx9Kdh1ThPLuT+cvQYQye3sUDYlkMIVlcXMDTZOYaxEtK6UcUx9tLnNNBP7VxT 0jk/yjebneITZVTU6VuCutLG4Ox0j5I3E+kRGn/x26SeJ9CnR1CFmfklSrNGYM1kAe8nP4jtjt 4RQ= WDCIronportException: Internal Received: from dhcp-10-88-173-43.hgst.com ([10.88.173.43]) by uls-op-cesaip02.wdc.com with ESMTP; 23 Aug 2019 12:49:31 -0700 From: Dmitry Fomichev To: Paolo Bonzini , Kevin Wolf , Max Reitz , "Michael S . Tsirkin" , Stefan Hajnoczi , John Snow Date: Fri, 23 Aug 2019 15:49:26 -0400 Message-Id: <20190823194927.23278-4-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190823194927.23278-1-dmitry.fomichev@wdc.com> References: <20190823194927.23278-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 v5 3/4] block/ide/scsi: Set BLK_PERM_SUPPORT_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 zoned block devices or not. blkconf_apply_backend_options() then sets BLK_PERM_SUPPORT_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 | 8 ++++++-- 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, 24 insertions(+), 17 deletions(-) diff --git a/hw/block/block.c b/hw/block/block.c index bf56c7612b..23fbe4d567 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,9 +99,12 @@ bool blkconf_apply_backend_options(BlockConf *conf, bool readonly, if (!readonly) { perm |= BLK_PERM_WRITE; } + if (zoned_support) { + perm |= BLK_PERM_SUPPORT_ZONED; + } shared_perm = BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED | - BLK_PERM_GRAPH_MOD; + BLK_PERM_GRAPH_MOD | BLK_PERM_SUPPORT_ZONED; if (resizable) { shared_perm |= BLK_PERM_RESIZE; } diff --git a/hw/block/fdc.c b/hw/block/fdc.c index ac5d31e8c1..c5f41b3eb6 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 Fri Aug 23 19:49:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Fomichev X-Patchwork-Id: 11112349 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 559DA13A4 for ; Fri, 23 Aug 2019 19:51:04 +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 278B92173B for ; Fri, 23 Aug 2019 19:51:04 +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="CSz5ivSR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 278B92173B 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]:33784 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1FaQ-0002Ls-Tu for patchwork-qemu-devel@patchwork.kernel.org; Fri, 23 Aug 2019 15:51:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51958) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1FZ4-0000Mc-NZ for qemu-devel@nongnu.org; Fri, 23 Aug 2019 15:49:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i1FZ3-0000ZM-G5 for qemu-devel@nongnu.org; Fri, 23 Aug 2019 15:49:38 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:47029) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i1FZ0-0000Vz-KZ; Fri, 23 Aug 2019 15:49:34 -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=1566589774; x=1598125774; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=w9QPhGBbG9LdiAC/MDYwSdaIk/5gNeFcYnd1Y7poLK0=; b=CSz5ivSR6AuhtD/8B840aPrYcQCcVI03mhGJXDRnLkBNtVoL+s+Ig0AA tbiD6Vidb1WMVvo1Z4zgvLqzqQQp9/UO/mj7HkEDoiNMKlFlIrJnPeAf9 DhPEjJ20AdCQIoRzhgOFwNJpISEXtbdJhFekakyr02ztBjxiwXOTX0WpP t7cA264g9A+Wc0J7Z4nr3JHrq6tsVEo7Av6c3L4+1mIejTGZ768/ElDvT PhETFXSaOuditX7Ljs41qjXtW7aLEcjGRHjwZRxYe8g5JlJaYNDIWsn0X +ADmOUJjzYbPrHpKWRLfDQVU71ZXTUjBjN7rMKNDdbqGlNVi2c2eua5hu w==; IronPort-SDR: n5v0yZbQ0Jxn95Qyl0ZcM2TOgg4/XGTK3HQ1D1b3zak5lA1Fasr1XfINJN4YlPwM8EsBQ94KT+ 6ogl0utomC0v7Nxa65IUtx3FIqGymbM8NRkKfneNTjW1h7MsXOIIkI8m6tTW4UpetrBtpuXS2I ZkIg4wBjzLoytlnz2AsReGHv2SF+R/pgId15b71dkqfSTNOcbzCOMqDgky67U6Zzdy8GfEwyFU G+hFnKrVJQ0eJ1i1uWOrotsUMNOtifh9Yi1Jym3Eevbz4nljb/NH33wdzc3I3KinQIqb6jjyoZ Qlk= X-IronPort-AV: E=Sophos;i="5.64,422,1559491200"; d="scan'208";a="223162547" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 24 Aug 2019 03:49:33 +0800 IronPort-SDR: PkDtSQT+eNoKKhmf3q5A2oU31FevVEKvDY/o9pSyMxSBa9gLVBA1Ilw9u3bvvnylK7l3cXJw7d 7dP9AH322kpgsq0DBmLMlBBUGW7ytrf8udU8gcJARAspKld6fAPx4oKVb47dFiLD3bhtt6OSCK fPidKjYYACNq8Pz8oGikZvorXB2W+lf5J1fqPpYsUxb8OtzjcaRyQ6RZVXVyhF8LUo1Po8lUy2 5jCbh8TS1jV0/Pf3W/7hiaJGPRTPeoOm72tipDPVjWG0zURn5IJ8945HknSMGiC5cNqmMawBUO DGc4jXpJ7K2RieBU+H55KEbN Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Aug 2019 12:46:50 -0700 IronPort-SDR: 10z4T2LRZCTpDuSsedWqMM6SZmhpNfD3GXOevYbSAH2RosAi3TMmlSoInq7HqNm+3/Aw1pHtrP myr2n0Pk34TX0ZXuu1h8w+3b4mhmm9+inmz6vjvh5JA05464x1oUnejxmAX9fLN55fYNCCjeXE Z/EPU9mVDKguD6e/qnIaAty+DGUHmNzljt31AuxXuF8kryZRwKxhujaq8y1pDCeDOevherIHaE EJXuBdMt9sqyOFpBllkW8y5fhAfnfNl8JnXohzceUL0XLnQk1gwYpu6q3yH9ziz/Xe4VBwf/2m 724= WDCIronportException: Internal Received: from dhcp-10-88-173-43.hgst.com ([10.88.173.43]) by uls-op-cesaip02.wdc.com with ESMTP; 23 Aug 2019 12:49:32 -0700 From: Dmitry Fomichev To: Paolo Bonzini , Kevin Wolf , Max Reitz , "Michael S . Tsirkin" , Stefan Hajnoczi , John Snow Date: Fri, 23 Aug 2019 15:49:27 -0400 Message-Id: <20190823194927.23278-5-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190823194927.23278-1-dmitry.fomichev@wdc.com> References: <20190823194927.23278-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 v5 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 --- block/file-posix.c | 14 ++++++++++++++ hw/block/fdc.c | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/block/file-posix.c b/block/file-posix.c index d9f2fc5e46..090e7c4d2f 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2884,6 +2884,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 such devices, abort if not. + */ + if (bdrv_is_zoned(bs) && + (shared & BLK_PERM_SUPPORT_ZONED) && + !(perm & BLK_PERM_SUPPORT_ZONED)) { + error_setg(errp, + "block backend driver doesn't support HM zoned devices"); + ret = -ENOTSUP; + goto fail; + } + return 0; fail: diff --git a/hw/block/fdc.c b/hw/block/fdc.c index c5f41b3eb6..673a8b39bc 100644 --- a/hw/block/fdc.c +++ b/hw/block/fdc.c @@ -570,7 +570,7 @@ static void floppy_drive_realize(DeviceState *qdev, Error **errp) dev->conf.werror = BLOCKDEV_ON_ERROR_AUTO; if (!blkconf_apply_backend_options(&dev->conf, read_only, false, false, - errp)) { + errp)) { return; }