From patchwork Fri Aug 23 19:22:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Fomichev X-Patchwork-Id: 11112295 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 F389F13B1 for ; Fri, 23 Aug 2019 19:24:41 +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 C994922CE3 for ; Fri, 23 Aug 2019 19:24:41 +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="mYWuV3Z1" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C994922CE3 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]:33362 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1FAu-0001SB-B8 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 23 Aug 2019 15:24:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48041) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1F96-0007cg-ER for qemu-devel@nongnu.org; Fri, 23 Aug 2019 15:22:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i1F95-0004KI-28 for qemu-devel@nongnu.org; Fri, 23 Aug 2019 15:22:48 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:37630) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i1F92-0004HC-3H; Fri, 23 Aug 2019 15:22: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=1566588164; x=1598124164; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wDuJg/PXjCdmnfQAHj6RMyp+qTSDniP3cOnxGOeYBNk=; b=mYWuV3Z1pDCRdFB++hQhsSAVxwwiNSWwtuKNu68RAQi22hu/lbk8sycz cAreNiOzHwza+1LrZMos+SjSd5E5s2zC6d99sGWkkj8p9Yeu6+eqtfn7t IEymrgM69NBCuL5g3RdK5ngG5nnY/SLVfG2yIQaYbr5ZttD+0cKyWkkue 6SotH5YAKbVbBmAay8SCMmlmiWrZOdW7GvHTzTwjC1YavGb9d/Bwwx6HF AyPv48ztbda1oER++smSoE0dGOwE5eNaN796ALcDDg2j1WVBe/GX5ti+y STUdexzIpSRntA65UowsHb5IFwELecWa2wLUdvI5tWoUmonj+oQ6tP/Au Q==; IronPort-SDR: aYoUkXBewh0D0HznMVXD1DSsf3e6UPQMEiRB/KdZ3yqfbt9QyytaHxVVsNoefecrxSpyN19wt6 o5HeJqlvtKSrrzv1HmDrSrrSRq4K8v4WPcAlGZvr6GIynxmj/HMHz+MSkN++Ex+2m6cB3xIcWB Xxtc+3K9Ub8U99ZWDK4US8Gti47qEWwadBvTZ+B48V0Jk0dxkTdlGyQGFI5pc13bD1BgVCXY/E KWzVM1RVVWz6xwr6FUVzmff5Cuk0ihv97PWNbonEQ4zXkKzS3fiZYtEjlhSOYUTMKN5pL7QcmV Y2E= X-IronPort-AV: E=Sophos;i="5.64,422,1559491200"; d="scan'208";a="117476288" 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:22:30 +0800 IronPort-SDR: kOek2LSY7/gV+4Zn3nB3KIxTD7f9BwWi96vDeKLRuhOZ+Stmh7M4IkjHzSKXbSWO9NFACxgrab lDvCZwAzQgm4UwJLwIqMdSenJfzlwFcy5D5+Epnd8//CCWObjXiRopH0a+wzdcHPSokyLf+52T PpLkSgvX3K6druPFcwSrPhm7ZvMqvRp09JR6Kq4do6Ja5dt9HRvq26NXFWVLpmFSWYMI74OFD0 SYvj8rrBc8tKb8F6w2DHz3vPWQfEQ5Wo3tgP8wwB6OD8R5QsZ8GKscjtN3/m7OWmt/Z0bTamH9 kTwGeEDe+wKiDXl4x53ma69c Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Aug 2019 12:19:47 -0700 IronPort-SDR: 1qRi1JXeETMvq5m7WpAT9pOty1mfa2zftBn4HvW1tx4BL6f4Iu0J6prhliTxJxAHaQC1fv0H+Q n0EV1yx8Wdkqsg7knu2WVKAnSiIJTucFnZoWgl0FQNk+B2HNDqHaLHOgtp2QmUc4u2hiiSAkar lWVxMR8uv6+JrskcDFjrLYu7fk/hOJslRDDEGHYmu14uK47YFlg5lZbw219O67fS6fAaTkhZhK 76a23iAmKczNyHRZ7sQu5TAtO9s7bfeIPjZ9ecwXwIjtIc08z5AY+tPcNYgcjaSY0MYI41EZJF wh8= WDCIronportException: Internal Received: from dhcp-10-88-173-43.hgst.com ([10.88.173.43]) by uls-op-cesaip01.wdc.com with ESMTP; 23 Aug 2019 12:22:28 -0700 From: Dmitry Fomichev To: Paolo Bonzini , Kevin Wolf , Max Reitz , "Michael S . Tsirkin" , Stefan Hajnoczi , John Snow Date: Fri, 23 Aug 2019 15:22:23 -0400 Message-Id: <20190823192226.21154-2-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190823192226.21154-1-dmitry.fomichev@wdc.com> References: <20190823192226.21154-1-dmitry.fomichev@wdc.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x X-Received-From: 216.71.153.144 Subject: [Qemu-devel] [PATCH v4 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:22: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: 11112299 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 94F671709 for ; Fri, 23 Aug 2019 19:26:33 +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 6B32B21874 for ; Fri, 23 Aug 2019 19:26:33 +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="lA8F8llc" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6B32B21874 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]:33374 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1FCh-0002tO-Ms for patchwork-qemu-devel@patchwork.kernel.org; Fri, 23 Aug 2019 15:26:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48064) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1F97-0007eV-O4 for qemu-devel@nongnu.org; Fri, 23 Aug 2019 15:22:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i1F96-0004Lk-5O for qemu-devel@nongnu.org; Fri, 23 Aug 2019 15:22:49 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:37630) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i1F92-0004HC-SZ; Fri, 23 Aug 2019 15:22:45 -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=1566588165; x=1598124165; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WrGHKVduBl42d9CD8UFRTIZ6FP7W7UcEwBBJuvUCUsc=; b=lA8F8llcTXjF4JXwDt+cPEmfcHWRY1sWu0W4Aa9hva0rqHx6n994SxFC ISGhKUjwSkuh4QwFs3i3JFhw49PkMkkHIlkmsJEv5ZcI2VUBWoZEeDXM0 kQgsDsUSS4NMnYqjY2zjafIS4I8bLTL0RnWsCDE0vgRY7YNWhs/9WHVQ+ wuG1BGUzfWopBsJtDjyUw8YV+oTmn1PWLfCFRAFW9le0phNOUDl2Kua4y dnrUQUGihBjo6rJytJOdPR8BFVHVtLRt+0D8Z/ZvrcQ/5PBsO9e+x4MX4 QcKYNgljOGJPhPs7SEphetBxTMH43cjUwoybfXXkto8IR9E407WXCpePl Q==; IronPort-SDR: XASYu8BXypx/rDPfhAB4LoNZhGoyCSzvlO7N40V281ATjQ7FTcy8GTx9GxYYM6HSlbRc9FgZSD 6LHidfH0c09bHEkjloBEJjihtJDfed3RbQ741dsZlzcywm6Fe7LUhpUNAS9Sk8rMcAKAlFvb46 gfLNNif3CSlDKnNcQrqRxAVtJ4Hdq12GFiADGxKiGpEBlnS1dH8djQlQp62yV7IT16xue4lTXv Tk7puQ1IqJDBxoPzXC7qKnpA/JGrlRYdJZYtY0HabRHh6EAB80JRuysHnmd8gm+rCiG47lm897 FwY= X-IronPort-AV: E=Sophos;i="5.64,422,1559491200"; d="scan'208";a="117476289" 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:22:31 +0800 IronPort-SDR: RBqpa2s6pCFL8WXrHSv16561IepU9cCbUl1PLdofNbtYc9jCmeMzgwlIEQWKSmAfuTr8lehQ9Y 7u6NCLOa9zACVu9HfCZyI5hWrSeQq0qijYCQ0vwIiL7n+N1XA28nrv3aKslXkWWyL2tT6D4S0I IKtIcBwjC5gULRT0SxC/k4WI4iirsQv6yb2vGVFgtwLh9ymzEyHi+NE7kEhfGUvA1Y/LbyO3Wi HxKh82bcrEEO45QFKEwNoZBAnRPpccSWqrRXLO/3O1V9+8iAbOHHgZytr3kUFAw6LN4HSwLT4U SXbLJ2NRf73gf9+N0PAn9yLo Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Aug 2019 12:19:48 -0700 IronPort-SDR: L5FGHEN/iSt34WooI23cmjDB9NQ8pdQg2y33QUtOeVbz1qlZFdM3DrUUwZjjAoOKZhsxWMjdSA CFRHFMNVZKgu8eYFe+WL3ZuqmTDOAQKnxwA9s7pFSIp0XDfMA0MTdEQAgoI4mQsTRkKyMuhfdn fmE8pc94IRWOcUbRnRyyfF0BzQ8LjRNwjaTNVx0IydupYR8STEo1dBdlAhFPkZwVOL7RwAfkyo RHyRBgzOlPSLftrOZBc5E56eLt5nprus6YGXv8QdebL7QwTBLDqwkQq+4AJELZSYM7GPnLhioE zH0= WDCIronportException: Internal Received: from dhcp-10-88-173-43.hgst.com ([10.88.173.43]) by uls-op-cesaip01.wdc.com with ESMTP; 23 Aug 2019 12:22: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:22:24 -0400 Message-Id: <20190823192226.21154-3-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190823192226.21154-1-dmitry.fomichev@wdc.com> References: <20190823192226.21154-1-dmitry.fomichev@wdc.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x X-Received-From: 216.71.153.144 Subject: [Qemu-devel] [PATCH v4 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:22: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: 11112317 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 30E7214DB for ; Fri, 23 Aug 2019 19:34: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 0594021874 for ; Fri, 23 Aug 2019 19:34: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="jQuIahlw" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0594021874 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]:33468 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1FKL-0001O6-TV for patchwork-qemu-devel@patchwork.kernel.org; Fri, 23 Aug 2019 15:34:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48071) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1F98-0007fA-6z for qemu-devel@nongnu.org; Fri, 23 Aug 2019 15:22:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i1F96-0004M1-HS for qemu-devel@nongnu.org; Fri, 23 Aug 2019 15:22:50 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:37632) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i1F93-0004Hy-0L; Fri, 23 Aug 2019 15:22:45 -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=1566588165; x=1598124165; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ArUqT7gctwo2CvLYjZvaT+85TujFifdpj4yt8JCxXJM=; b=jQuIahlw9eHvpAIjFZTl4UyPgO5bJYelovPfzyeEkHpbs4VgcP8hxZ1U cqAOIVY0ltG9/69SXoSGy3DdntmDii3Q1HH3fQQmM6nM+GicZ0Ot2yQou 5ZaZT0rm0NCzKeWZwAJVGNBEOvSCR9G5Or6p3dptEejCIc/2JLY+z0Eue zUN5nqOD4rr7y5IqIDkP8yTCKkgB5Y3Vsi9oWKBaaxN1xJsRi9GTIygNi cmdRNq8opNk9nD4EBTPf2PyWPTSO3UZL0v4c6d5olwNKDT7yX2U6O1utf zWzbfP1cN35Ho32i6PGVsUhgMGsGCH970j1dyGjd40Up2JuClW0NreoYz A==; IronPort-SDR: YfhTKjs8STB9HTxvBNwENlyzdn9pLsGMPtamkAqFPjvrhxPzzlHRZUdxKLjcPFk4l2gFR+AZG4 p5NdqZkgrBlQeakTEfgYRlHo6pXugTRGRVrFdNQLTzP2pqM1HFs5rNFjaYvmrV9xgPtLK3drAz Bex9zc80a9vaaRVPpJrV9DVQ72Z7x/s2fyxCavp13cjZgkDhnINCfd7jlffrY8U5gsh7SiYe9j IkdO5HV/p8hbPgwiVCpC3flyeKVcGHLh+GlNO3FiFKTUkq9dIugvohyFB8WKMfLmC4rK7KDJxB QnU= X-IronPort-AV: E=Sophos;i="5.64,422,1559491200"; d="scan'208";a="117476290" 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:22:32 +0800 IronPort-SDR: zQCSFt9LrpqykH2dG0yBowDBzD3KclxS4EdduJRKqjKt6J5geD9ffrtKNpuuHwRYBqJ7/FYDli cSLp4+PBTAfqfMsHiIcHueja3ROF6VQJCx0AFW9Z0K6hY4NixAFmzh5hYD/0J3MyaisFoT/lcV bpIglbnUJ3SqDj6trdZqFlQKcMf3oXlHyeOu2cYCt+bi64lA0Ihxma7EJDRJkxZyPuVthk0SLZ Qa88/PuHCv4TXWwAOZ1Zgix2UdFeCfwErdeMNSq/kh5o9dWOd4bdlZLflaGJRTgMNQgl+amJZi Yutj8RfCR5AnNp2b7P2+d2Mj Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Aug 2019 12:19:49 -0700 IronPort-SDR: d7avfQtrZfgVlbjpnhksWMzInrvVipWbbugOOciluZRzv79XzojZ2AbO2NVu3e9n5kqgU6EwmZ t25lekfDvwsNVRKT+ryk9A5P6KD1xVdn9NrVdBxkTXerNDvCgxFHJR2c9rhrjvTq7hhccNnBmx J5D2+fSTXbw239VjkDbmxrfgdeoq+z0oVghjzCB8LHKhYQhIw6UzCRjcUygPOr1aS6MvzSCdrU PbC9GClo29vd021if2jcepNB3sWY/egnb+gayfZDzFyxQj73XCCUy1sLXYw02Ewd1WP6qAjUQp 80E= WDCIronportException: Internal Received: from dhcp-10-88-173-43.hgst.com ([10.88.173.43]) by uls-op-cesaip01.wdc.com with ESMTP; 23 Aug 2019 12:22: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:22:25 -0400 Message-Id: <20190823192226.21154-4-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190823192226.21154-1-dmitry.fomichev@wdc.com> References: <20190823192226.21154-1-dmitry.fomichev@wdc.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x X-Received-From: 216.71.153.144 Subject: [Qemu-devel] [PATCH v4 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 --- 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:22: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: 11112301 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 A34AE13B1 for ; Fri, 23 Aug 2019 19:29: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 78E2521874 for ; Fri, 23 Aug 2019 19:29: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="U1M3SJlU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 78E2521874 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]:33414 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1FFi-0005bJ-7K for patchwork-qemu-devel@patchwork.kernel.org; Fri, 23 Aug 2019 15:29:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48053) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1F97-0007dp-7Q for qemu-devel@nongnu.org; Fri, 23 Aug 2019 15:22:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i1F95-0004LY-VV for qemu-devel@nongnu.org; Fri, 23 Aug 2019 15:22:49 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:37630) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i1F93-0004HC-Lc; Fri, 23 Aug 2019 15:22:45 -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=1566588166; x=1598124166; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oXXVZjLLMipUXBqkSzzjZDHjxHTciBQy9f0jCrV5G90=; b=U1M3SJlUyYrhrYdzFXxMYuTcmsqXaTx9p2DyUqn7DwHr+YCW+HrvLSYq jpROToJN15t2p4Rn5xNtXBuF43y6iRA25rQnGFZwR24zbmerfBC407LwE cKpbCz51+1LtlAn9UlyPya330Iu4jM2B/i3fPFKAgGnhDXqPxJRAnZNsZ oRdj6r6UWvobCLjXfuU6B9+SNTgclBs1qjwC7cC74uOmwIF/eTHEMELVV bf3RqTpNFl82K4uAP3U7otaJg3U9z4fC5x2rR6HLwXd9cZdhsDHiusZVX tS30oHFoKPZdQ74SniTB/m+/Bvg49ufaGD+3zsGMAw0vwzECNbWDa5nP9 w==; IronPort-SDR: 6wZMekoa+ic/mwSicIT0FnxnuyQvWJK5M7ukNHLzllJZEC+AF+76l/BW17cC25maTNsRojPeHG YAnoHJs25M0YMjhcXBdg5KZFNsGMdSuK0qcPfYE1jIkIxK9mJMX+quBmLNSVqbNG7z3ejUyoLk sMckaGAwppxeO8Qy+gmIGtKAO4GxUH/QH2jnk2OHX5U9q7F4f8D13FlfQTOLhCDzw5dzATm2ws MK7kJ9fYjBwuV3troaMqEExZsWuvQNCRf1EKGQgb6QOrbNCNC0xJx2eT8VLn8+Fdu2ubxhhNVQ UnQ= X-IronPort-AV: E=Sophos;i="5.64,422,1559491200"; d="scan'208";a="117476291" 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:22:34 +0800 IronPort-SDR: AhTRtiV61dGhnDBV/gjhpcGdHmKQv+oGv/XT/DEqF0LwRQXbO87LOZnItHK9Mpv6syUVQE2JDE RW/oS4QiD/n7e63wnYbdPdIGNGIRcMo9s6yFbc+LbQHsZuGRbxTsDtKzo1g3a4jSSi+ApznuB9 fP17cl70iuava+J+Eg+Q5Fo3SgorGVRi2tF+lbwu4NZwHkmQXdaRydEUm8KzJ9NTI0lhoWyZTk UBfWHpGycqJCQyVPsDFSblstHtc4YrwBzWO/PFA70NrP0rnHu/7+/2Djt3Uc4bFLfoKpSst0zp ZYj7S7C0wAgj780pgeqAVpHB Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Aug 2019 12:19:50 -0700 IronPort-SDR: wTV4CZHMBxhakaiQ/ILgrVIVZpocjPjP8l7/EF7rlzt7RbLQQnbSrfyyMsioosFTW9ziAhJRyD VwI0XEphzUxXZAggOMPe0LfrOgMaZjl/r3RCgTgSaYx6a1Cx+U32xk9TIFAqZLFBDEuAbdqjXt kaINKOp8kQMHv3oODjEX/ue3ia4FNfxBePA1CY1DnLuTexXVLtBsntvNQ4NWFntUzfa9esuTGP BUESTx1IwUPSIoBKxprxOcwYoDvRse0xr0DLShe8d5mokmoKH4p+nMKlTglrZx9sPHnY7ICM+D SNQ= WDCIronportException: Internal Received: from dhcp-10-88-173-43.hgst.com ([10.88.173.43]) by uls-op-cesaip01.wdc.com with ESMTP; 23 Aug 2019 12:22: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:22:26 -0400 Message-Id: <20190823192226.21154-5-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190823192226.21154-1-dmitry.fomichev@wdc.com> References: <20190823192226.21154-1-dmitry.fomichev@wdc.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x X-Received-From: 216.71.153.144 Subject: [Qemu-devel] [PATCH v4 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 ++++++++++++++ 1 file changed, 14 insertions(+) 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: