From patchwork Wed Jul 17 21:26:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Fomichev X-Patchwork-Id: 11048255 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A17CE14DB for ; Wed, 17 Jul 2019 21:27:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C33B208C2 for ; Wed, 17 Jul 2019 21:27:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7F09E28734; Wed, 17 Jul 2019 21:27:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E11DD208C2 for ; Wed, 17 Jul 2019 21:27:30 +0000 (UTC) Received: from localhost ([::1]:60552 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnrST-00081I-MI for patchwork-qemu-devel@patchwork.kernel.org; Wed, 17 Jul 2019 17:27:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49567) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnrSA-0006ot-2N for qemu-devel@nongnu.org; Wed, 17 Jul 2019 17:27:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hnrS8-0006yk-SP for qemu-devel@nongnu.org; Wed, 17 Jul 2019 17:27:10 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:14129) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hnrS8-0006xf-7q; Wed, 17 Jul 2019 17:27:08 -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=1563398828; x=1594934828; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=y/EIjQAMc7p+xmtVB2kq6kXWCPJCIc15sNxmhUJdXBw=; b=LxF799K2G9tX624OQHOZHRn6pP2MF/9CYJ05aYpAhzTLK6d/M7Bwp+Az B1/Jy9OhCi6EZcxIzlJ4QF5eQ/FFMkW0zjBzjre7OM7HB3aOjdX+iUJ95 28VtHPWz9hmm7Skfv5lb8bg6E8f6C45SdMZMD/zsLs/DSwjQw+S/yNi5M tMl4QKvYvN8DacOqI5SwPSY85VYEuEc4X1T3UaF+CV3HqyWtlhlxG/3kM prAOqC6wZxeAYS5yGhdddW9iGU3PfZzz+wR+v38dAyKA2C18kRxcBt9nW yUKwTb4KUVvkyHBcS/OcLUmy+cx39LuC3rNY8LWPOV0ZgHWb7E5xWY+bC w==; IronPort-SDR: CD1fLuV1OXkO2ePSTczag5ZnOeYuEfx0tOfXtwPwBmVIo5IOAgGEONPHBnEJ1IZM1GaaiK0wCI 7NLVBgOmmLCb1XqdZI+hGkBftxGWdg7u7FWUjZn//KuXJnwds4UhNBrHjdIRi2Kcd4JLWgYxSo SuySKBxMj1ahP9FMzjDr9AjvNuMUj7ZpYx+kHa3P/8cI8SlWvpZc2+o4y+ThxSNS5PvzZVZxso bwTZ2gmG1kuFwmhE7eFbewBLPDIijImqQJmw4mnmyeDuof2Juu975oFhNTXeiPgzFxRhT/HdPd NK4= X-IronPort-AV: E=Sophos;i="5.64,275,1559491200"; d="scan'208";a="113319440" 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; 18 Jul 2019 05:27:05 +0800 IronPort-SDR: QEOXAHrAzymdaDBgTh5AnlejiZU0Q/6OR0kiCP1Y0KH2sO/0r5YRdQuqgQ4oQca4bkEOB6i7wb WjJ+ZN+Tzw1rLKsHLM72qypC2fISIF1iEr+UZoVbhMU7P569b9aV+DGUz3FIs3LPIP9tN8fENB XBascCoe9KrLfErdT0Y7WFoSumYlFpV+CmQETaOTxx8qM5kLcrig9FP63tqr2K4A/ABTKtlm7R vvcNmbP0Wirn0kcvcO/uX1ASxoGnQy7QQk0eN7GQcImI5Z6sv5rS6fal/tMfAelkEpI/coAI2k fjJHAEcTKSpNSzvjvUNtMG9q Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP; 17 Jul 2019 14:25:32 -0700 IronPort-SDR: J8jzJWqiLDoYijTMj4gXGuPVu8UgDNT6SoXXzkMiskDqzG2MAu4deHRjmEJi0zq5PdyRdiHBjO SFO1H75bK93LKYqCM2/ZJUKghlw162QxMD7HTdp5+a+gOJXe3XOqCiOplsRRTZy3YWkTRR7IJS 44GkmxG64Ke9F7L5L1LAFNi/jRKyx6EfDBSD4KdncgRXYybmOz2tnC9xoy2B1Ssa0TZ6XEkK5h G89iYUFIlaXkkci98N9+0zazWenDuwmnSPUL9zu1VKcM8T0BQkHvwiPuuYxlEb5Gox08bPsZ7Z 4qs= Received: from dhcp-10-88-173-43.hgst.com ([10.88.173.43]) by uls-op-cesaip01.wdc.com with ESMTP; 17 Jul 2019 14:27:05 -0700 From: Dmitry Fomichev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Wed, 17 Jul 2019 17:26:59 -0400 Message-Id: <20190717212703.10205-2-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190717212703.10205-1-dmitry.fomichev@wdc.com> References: <20190717212703.10205-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.154.42 Subject: [Qemu-devel] [PATCH v2 1/5] 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: Kevin Wolf , Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This commit adds Zoned Device Model (as defined in T10 ZBC and T13 ZAC standards) 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 29e931e217..cbdf044d43 100644 --- a/block.c +++ b/block.c @@ -4671,6 +4671,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 734c9d2f76..a465da31b8 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -266,18 +266,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); @@ -354,6 +371,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 50902531b7..73fbccbe8a 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -416,6 +416,7 @@ struct BlockDriver { bool (*bdrv_debug_is_suspended)(BlockDriverState *bs, const char *tag); void (*bdrv_refresh_limits)(BlockDriverState *bs, Error **errp); + void (*bdrv_get_zoned_info)(BlockDriverState *bs); /* * Returns 1 if newly created images are guaranteed to contain only @@ -614,6 +615,9 @@ typedef struct BlockLimits { /* maximum number of iovec elements */ int max_iov; + + /* Zoned device model. Zero value indicates a regular block device */ + uint8_t zoned_model; } BlockLimits; typedef struct BdrvOpBlocker BdrvOpBlocker; From patchwork Wed Jul 17 21:27:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Fomichev X-Patchwork-Id: 11048257 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4F92E912 for ; Wed, 17 Jul 2019 21:27:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F035208C2 for ; Wed, 17 Jul 2019 21:27:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3388F28734; Wed, 17 Jul 2019 21:27:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B028A208C2 for ; Wed, 17 Jul 2019 21:27:32 +0000 (UTC) Received: from localhost ([::1]:60554 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnrSV-00089X-Ot for patchwork-qemu-devel@patchwork.kernel.org; Wed, 17 Jul 2019 17:27:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49573) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnrSA-0006ou-Bu for qemu-devel@nongnu.org; Wed, 17 Jul 2019 17:27:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hnrS9-0006ys-35 for qemu-devel@nongnu.org; Wed, 17 Jul 2019 17:27:10 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:14135) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hnrS8-0006yK-RD; Wed, 17 Jul 2019 17:27:09 -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=1563398828; x=1594934828; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7tzlz4nS/NDt/He6kF5q4UiaEdfHTksSd4cZbWW1HH0=; b=h7Tg7m87VGpMy0vN5b8uXs7TCvprDSJY8lJSkePOCkdi8J87jua38IGu 0a+oFc+O1BUA08NbVn7nDZIRkNDCDUyugAIr4pB948kaoWhGPN3sZX/b6 nYSMu+hvEzFLUquntp0reY3H4Fcu2Kxbx/2HGhNlbDNWLavv6Q7Hl1Wio cthlnYjDndcaCdYkZjK1wFQvuL7I1hhHHFN2WeM3nYI+5piBkVtgptiLF Wh4lwq2Oa/XbmvMdgMqiR0QizcFpYfQoES6iN46MXtNDWQxOk9TyEio/8 byAvryNjdr9EM2u5l+Rf7Fxe+yuvBl91bOforxY6Aa0M/EoYZm97gbOyH Q==; IronPort-SDR: wERviknFKxYqyZhMfEQBhyuQCG2UVc6CD7WWHGlHqIwECmsB6f7rvqDeiWu6xvcL9LdbkA5n9q +dGB04RTUIouc/kpN4m0EAayg/NwN4rIrydCPHJU2zo34kzruH78/K3dunGsvlaVgdb/DjpkDz iVbBaKVISvsWRKE5e92omkU/RzOcseIfhs7/nQSE7Sv+FKnAVLiRPNT8T5DTh2pe54cHJUNohf B0lZd3RZTYdFNqy/anEiBpzxtl6xqE0X5BiYifLvVy8wCw06K8AX475QFZVydGMV5iBMTbSdQl OeY= X-IronPort-AV: E=Sophos;i="5.64,275,1559491200"; d="scan'208";a="113319442" 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; 18 Jul 2019 05:27:06 +0800 IronPort-SDR: g75E7E9Kv5nQCzv+JH354dsHlsHtnRPb/e5lgAgrMJS6LQkrJq166YpsP+55FXswKby/JCYSLg WIThnHt6avF/EfaSPVpGwBtzhYE5o12s/kDVrLpDIWSLJmcG+mx92kjHFeZYawHn7H7i/j+YxU Qa4a91DCWE0TsPqJwKs0QkwMA0pZmvtCICUKIssmnJVHfafu8OM5Sdp19jpLOE9lcwe8a+pNhz fT4zP1CH4ceFcv9vfz1ucjv0DBv8ucDyjIgBOCRbXYCblnEUrhjVwwbflkmoeroDO/B0Fd6SFL y39PqCPio+dMt57hwGWwKBeL Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP; 17 Jul 2019 14:25:33 -0700 IronPort-SDR: pWwyXjhgUXbkCIX7lh4UMF+0zpIC0c8DYI/n4O0d/QKrJXm4mtJE9bB8mKVVHLsjdC1zaR2NBu nnvkCZCMIZP4h3J825+CGrqO4AR0dQXewW+RuxnZE8Tz2IX2kEy1jp2SNQWKZhP8hnWmWxQ9yn 9SPrt3AQ8Ot6vMSjpnJ+ijDtkVhDtxHO1wChhuG2uCFUvKqr4cJ2whO0k4BI/BnGbCAcVYBvW/ gSP51fwPiCHmm8Wd1ES3fS4+PVI2fa+l4HiTiwpSJgG3V2i/WrDhAJwJehfn3vOGI4Gyyy2vk1 FS8= Received: from dhcp-10-88-173-43.hgst.com ([10.88.173.43]) by uls-op-cesaip01.wdc.com with ESMTP; 17 Jul 2019 14:27:06 -0700 From: Dmitry Fomichev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Wed, 17 Jul 2019 17:27:00 -0400 Message-Id: <20190717212703.10205-3-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190717212703.10205-1-dmitry.fomichev@wdc.com> References: <20190717212703.10205-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.154.42 Subject: [Qemu-devel] [PATCH v2 2/5] 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: Kevin Wolf , Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The purpose of this patch is to recognize a zoned block device (ZBD) when it is opened as a raw file. The new code initializes the zoned model propery introduced by the previous commit. This commit is Linux-specific 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 4479cc7ab4..e307cab7a4 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1053,15 +1053,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)) { @@ -1069,23 +1067,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); @@ -1094,10 +1114,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; @@ -1107,9 +1150,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); @@ -1119,6 +1163,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 bffd424dd0..12c2a3f95d 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -369,6 +369,13 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp) } } +static void raw_get_zoned_info(BlockDriverState *bs) +{ + if (!bs->probed) { + bs->bl.zoned_model = bs->file->bs->bl.zoned_model; + } +} + static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offset, PreallocMode prealloc, Error **errp) { @@ -572,6 +579,7 @@ BlockDriver bdrv_raw = { .bdrv_co_ioctl = &raw_co_ioctl, .create_opts = &raw_create_opts, .bdrv_has_zero_init = &raw_has_zero_init, + .bdrv_get_zoned_info = &raw_get_zoned_info, .strong_runtime_opts = raw_strong_runtime_opts, .mutable_opts = mutable_opts, }; From patchwork Wed Jul 17 21:27:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Fomichev X-Patchwork-Id: 11048265 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6125B912 for ; Wed, 17 Jul 2019 21:28:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E2F5208C2 for ; Wed, 17 Jul 2019 21:28:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3F06A28734; Wed, 17 Jul 2019 21:28:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9E6F8208C2 for ; Wed, 17 Jul 2019 21:28:27 +0000 (UTC) Received: from localhost ([::1]:60602 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnrTP-0003kw-0n for patchwork-qemu-devel@patchwork.kernel.org; Wed, 17 Jul 2019 17:28:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49599) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnrSB-0006oy-3k for qemu-devel@nongnu.org; Wed, 17 Jul 2019 17:27:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hnrS9-0006zB-Lu for qemu-devel@nongnu.org; Wed, 17 Jul 2019 17:27:11 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:14129) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hnrS9-0006xf-D4; Wed, 17 Jul 2019 17:27:09 -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=1563398829; x=1594934829; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=by5qDPAghaT24+Q7Y+BWV+7eEwBr8LsYWNFox979xzw=; b=XdjK5WQ4+7Yf2BRAFb3PvW8SDT6sGb5Tv5c8XsQc/jih643VejUwIJVR hBoEp2yJK02UefAammLOocjO0/Jpqz2me7IiecRQxdieKrNruKT6Djtqt V/BYt0a8EndDknqVYOuRmQTte87YfWcRzaZlvbWea55fMldR/ld07YF/o NU/EkY97ujfDFB+Py7VIkdbyBZr/THDke24Vbmoz3RalxOP9Nopwyorvn Wg8YGfwbrjNE2A9FZxAJSoLeCFvibL+gINxk14gfVZW8I7WXD/fm4KOX0 m45x5SNvXQ2hSChVDpC4E9plcWE37hf3EMsBH6U6hZNNs8y7BdYEQAmY/ w==; IronPort-SDR: 9OpBeZ63nJQTrIb7t75dVdmPWwI/GWZhDybkptkGLuObhQq/5zdE0maxgNp7r4UJXJQwV/tTpW 51buf0Hb+ZgSFCJwODigFsMjHHV5U3rrnmWEEyz6KKjGxEHl14vkpY0E6W9Ib1YbVYJT0x7JDQ 9A5l3E3waluUVwbCknsifQYd1iUMkMFr2RjbqcEE8K5j25+3afETaXud/wR8I/VriGryVkm3HU NCKcn/RjO/bjniXcNMCmQEgqMsNmzZ2ep2gPqqMF1aMKdHlHdnYUdHKF/tuYNmska8ALFH9tRL 6j4= X-IronPort-AV: E=Sophos;i="5.64,275,1559491200"; d="scan'208";a="113319444" 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; 18 Jul 2019 05:27:07 +0800 IronPort-SDR: N14iLDMXInbykI+cWVS3K5L0xgFr4TuTL5YD8ivTviKkH6FH+WxJAQ9JNEhfuW/neS9YqG2LPc IVHpcNGgTo0Kql5KerCferRVWpIm5BhF4Ve7dQ16IXQVYyRGx0SjdManfT52ibiPx5tWYpx1hP vKVOevpuH/QigZIYt1diAcmVU2C+IsbM4yWuaGq5H1VzbqDiLqfy/upDb7xzItUSybouL/o9WO 1tf/yQDA++vVNcoD3k0D7Mv9o08gDeBP/hNP2vPMB0MOFkI95y3hfEHCuiCPkx2Q7GRkLBg9gE DFbkfdmqZxy1KZz33OoS1mJx Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP; 17 Jul 2019 14:25:35 -0700 IronPort-SDR: KaA+C8Ge9txD3jq/Sz0bsuNZVJ/bR55MQSq9f8BXS3ZAEMQXRS/PpwxPcEov+A8K9cAcicxxH2 QAryfRRsCN2N0bNTCZnKEBblogBgGPHrkX7SElZaoS92vTHNmtPwIYE09AhneiIY9fxyw4WuB+ 4fmh7i8wqm8f6NSqWL4W2pdJu15wBttvzAz/RjI5r5aQ728pKpk67pdEPPqfSOpQFqRRz7r7mT dPjORN0tPmqI8J/skfwTfsv6nPgLW1wPDE7D92sfqhUyAS/sJnFQ6DeRXeAFaOcX0yFyZAP0x/ iJk= Received: from dhcp-10-88-173-43.hgst.com ([10.88.173.43]) by uls-op-cesaip01.wdc.com with ESMTP; 17 Jul 2019 14:27:07 -0700 From: Dmitry Fomichev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Wed, 17 Jul 2019 17:27:01 -0400 Message-Id: <20190717212703.10205-4-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190717212703.10205-1-dmitry.fomichev@wdc.com> References: <20190717212703.10205-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.154.42 Subject: [Qemu-devel] [PATCH v2 3/5] 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: Kevin Wolf , Fam Zheng , Stefano Stabellini , "Michael S. Tsirkin" , Max Reitz , Keith Busch , Paul Durrant , Gerd Hoffmann , Stefan Hajnoczi , Anthony Perard , Paolo Bonzini , John Snow Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 | 4 ++-- 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(+), 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 77af9979de..85efc80992 100644 --- a/hw/block/fdc.c +++ b/hw/block/fdc.c @@ -474,7 +474,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; } } @@ -561,7 +561,7 @@ static void floppy_drive_realize(DeviceState *qdev, Error **errp) if (!blkconf_apply_backend_options(&dev->conf, blk_is_read_only(dev->conf.blk), - false, errp)) { + false, false, errp)) { return; } diff --git a/hw/block/nvme.c b/hw/block/nvme.c index 36d6a8bb3a..71b35bf4e7 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -1333,7 +1333,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 cbb3729158..8894bdbb0c 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1123,7 +1123,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 69d73196e2..8ed5e9d832 100644 --- a/hw/block/xen-block.c +++ b/hw/block/xen-block.c @@ -228,7 +228,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 9d8502785d..c0b4a445e4 100644 --- a/hw/ide/qdev.c +++ b/hw/ide/qdev.c @@ -197,7 +197,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 8e95e3e38d..f20815b1d7 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -2315,7 +2315,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); @@ -2353,7 +2353,8 @@ static void scsi_realize(SCSIDevice *dev, Error **errp) } if (!blkconf_apply_backend_options(&dev->conf, blk_is_read_only(s->qdev.conf.blk), - dev->type == TYPE_DISK, errp)) { + dev->type == TYPE_DISK, zoned_support, + errp)) { return; } @@ -2412,7 +2413,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); } @@ -2440,7 +2441,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); } @@ -2450,7 +2451,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; @@ -2643,7 +2644,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 f07891b3f6..a43efe39ec 100644 --- a/hw/scsi/scsi-generic.c +++ b/hw/scsi/scsi-generic.c @@ -686,7 +686,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 9ffb88ea5b..60d6a92ce1 100644 --- a/hw/usb/dev-storage.c +++ b/hw/usb/dev-storage.c @@ -601,7 +601,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 Wed Jul 17 21:27:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Fomichev X-Patchwork-Id: 11048261 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2A54D912 for ; Wed, 17 Jul 2019 21:28:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B1FE208C2 for ; Wed, 17 Jul 2019 21:28:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0F75B28734; Wed, 17 Jul 2019 21:28:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B4A7D208C2 for ; Wed, 17 Jul 2019 21:28:05 +0000 (UTC) Received: from localhost ([::1]:60584 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnrT2-00029X-Qg for patchwork-qemu-devel@patchwork.kernel.org; Wed, 17 Jul 2019 17:28:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49593) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnrSA-0006ow-W7 for qemu-devel@nongnu.org; Wed, 17 Jul 2019 17:27:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hnrS9-0006zQ-QU for qemu-devel@nongnu.org; Wed, 17 Jul 2019 17:27:10 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:14135) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hnrS9-0006yK-If; Wed, 17 Jul 2019 17:27:09 -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=1563398829; x=1594934829; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=boA+Z2tHFjiw8PC+GjVyKRaSk8JwNJ8dEkm+i6cC7Zo=; b=diPX4W7HczdBxeSCfH+rxW2n0F7cEOiZz5F4G5hjXS5sFimvRchoL8h6 ewozTLyqntqaPye0LcZTZatDkK3mtfpLSyVpS7jQ69R8rhLojQiJYMb2d MFCABgedBDnuc6tPMgNebMyr29uFC2fusQ5/GQMvSzzC86w1KjGB2C9+Y +1nzeq/trZKPIYR3VRDwKY9QxCH88Ir2ZEF4tK/07Hgm6MVWi57PNrBZK 3U/vJVzola0T9VhqU4kzKjnhb6caFLZFRIJ22pKUdSUH8mrWmtdy/1cDx RqnSDKCpovP3H55lPC/jqXEpIxEK6aCGAEDiy7IbT416+KvxwvgiSaN/9 w==; IronPort-SDR: Prnw1PHzhfEdqwNueNAwrKVD59xmXlXzBQhfpHdbUrqYleJwSWGmTJfypmwBaznzdPYnJF9uPD PaueyoaOTaPy5Al2g6qEmfScJobxH2GHd5btlpji6IXhDzu8A00T9YY4uedSUszs1uZIceWYQ2 jFmaTCASiNtAAb7/VyGhKZDpK3DuSXiQCdyTpbOXQo6PMc77Wzgg/iYKofhNLxW2RuXAEOUAmA X6//CUEp/GcbB5DnQxqqjn7UbPGcqKMCw3oG04N6gmQSCsrIy+I8J8C7Q7hOU/Zv646LBG6QM/ 1z8= X-IronPort-AV: E=Sophos;i="5.64,275,1559491200"; d="scan'208";a="113319447" 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; 18 Jul 2019 05:27:08 +0800 IronPort-SDR: hxbdVCgC3vjJKO0w6XQ3CCw/rQw1hAeCdzxVvU4ur0HfmRZdkCe+88BWH+HhCPdl0lHoJXb5/I Kt9Ju8rXuJHIePYY3S8crONoEQljh0KqYivM5ZOPSYRm/sQMg8fzRm3ZSrB7H5aDLkVLFRY+Km gT8Vk6SYk24yi+buJ25OvkLuSzjva0kvTflDkHiSjkzBgvTL6dxO1jxipWrc/uyimYHKKowtLp 3BQZUIkCjpVq3/65cdyDXzfcD2QYJcRMLbZPj44DNng8HIgZQh4p0FU/rT5XOBr4cpUImb4MjK z/8eNOTwoo+Qsq8RMqGaBbrD Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP; 17 Jul 2019 14:25:36 -0700 IronPort-SDR: i6dSGGfgNw2q26TUbfrnLHJlPwHuIJu1XYym0gebcG0sNlDUXfDAofW6BBUrU0+n4aQRPVO2QL 62rU6kqfhHzP6wNsc5n9JQoXWvWOaCKFjJdC9HTxGyKOZNyNSwNpB4JBhmapE5DaOZo0/M4L65 7Yd6Xj6tMIo0kyxpk/LyxBJo27iU1cfV1s7cr8vg3nUXM9NErlNofRkhDKVE8eezkNwQReQeHd 5TneA//9dC2sl31RARW+SSnZ7miKzcNsLR4saSXshC3h+fVqqMz+rxwvA9OlVgPO3O8veJWOyi fN4= Received: from dhcp-10-88-173-43.hgst.com ([10.88.173.43]) by uls-op-cesaip01.wdc.com with ESMTP; 17 Jul 2019 14:27:08 -0700 From: Dmitry Fomichev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Wed, 17 Jul 2019 17:27:02 -0400 Message-Id: <20190717212703.10205-5-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190717212703.10205-1-dmitry.fomichev@wdc.com> References: <20190717212703.10205-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.154.42 Subject: [Qemu-devel] [PATCH v2 4/5] 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: Kevin Wolf , Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 e307cab7a4..507dba98c5 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2870,6 +2870,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: From patchwork Wed Jul 17 21:27:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Fomichev X-Patchwork-Id: 11048259 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1F92914DB for ; Wed, 17 Jul 2019 21:27:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0DF06208C2 for ; Wed, 17 Jul 2019 21:27:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 026CA28734; Wed, 17 Jul 2019 21:27:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8ABC2208C2 for ; Wed, 17 Jul 2019 21:27:34 +0000 (UTC) Received: from localhost ([::1]:60556 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnrSX-0008Fa-97 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 17 Jul 2019 17:27:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49607) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnrSB-0006p4-D9 for qemu-devel@nongnu.org; Wed, 17 Jul 2019 17:27:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hnrSA-0006zc-9a for qemu-devel@nongnu.org; Wed, 17 Jul 2019 17:27:11 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:14129) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hnrSA-0006xf-0I; Wed, 17 Jul 2019 17:27:10 -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=1563398830; x=1594934830; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/Kwi8Jp1yIRIowLQtDYQc9c9gPWOx1jGUCy5ob5WQvw=; b=QVtBZfgV58RJUv3FAS/sgPpm0/jEhjGD+EjQjEyi7xnb0n0tWnDbKgOF BF7U9Brf97SGk+SmoSC4E3unAD/6kQg4eBzq/FcG6gbyJt3KknSMoiotL VaPkmQMXFBE69kvk9cCYEF+QFBUvZof5dsTjjj8lcLOt4DV6V9llwBu8P 6fVMpuPfsvb17K3Li5jA4A/qsbdzBIuSX26588xkrT8q1ABmg5Cfme3z2 fzfwkOv3NxjoLpDuMWJMKtFTjFI8KVO/F2oKCyQwDSCjUceUn03NxorWh apsWihxBRDW4M7xsY5D4q8brrHtXl5QS7nJR1g6DeEjEiICpAnJi/1Ess A==; IronPort-SDR: G/rveNnfRilmOVnYQBBdXo9jt9JOz9hMRSkj9tB8vNzdhfHUve2Eq/TmZo/K9ZDfNxRcAVFFKb TE4bBbvoy9frg9vh/oc+BedNiOqrXIaZGBzei6iqdlkHiO594O8mHkkMNpG7Eo1Fjusw25Vreq LfbXMHfq06kP/EQDzxSFbNV/v/CC5O91XwHrQcDHaiZYT79S9a5V/7bDNbiAhyk8x9zUsfIoEk lpoNw1YrzAiv5vhMwtqWHRIlFpA+YPi1Ol597RuuI2goWD10uZQEyxRznSD5XqfpXKETxPDkFJ Gns= X-IronPort-AV: E=Sophos;i="5.64,275,1559491200"; d="scan'208";a="113319452" 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; 18 Jul 2019 05:27:09 +0800 IronPort-SDR: t8V0AnoNdPujx04FaQDJId0OEaCDTezSqzL6zwoIU88Ib0BTxPYPOmtm43nHAXarR2c4gzzl7o +ElfJtaFz/o/rniuxgTXJjCsxUSHLNE8gMp4EiEUQjXP5ht7R1fO1mBTM29YvT1k3+kfXKLAKI 7VnMqqJfacT5qKpsygFBhjrD3w4F04ChlaTIFzD7LOZHi1EcA3IRObThl0RBqfJEKunGBJRJu6 UZ8Pl29OO4KviOCELNsy41GPoXionG+AAFLTF1rp831fiU1DNewmVJsRQQF9L71Hu1IkhuyhEU ksTzfzPCenI9waunsLvrO70d Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP; 17 Jul 2019 14:25:36 -0700 IronPort-SDR: pTb1FxQsRwIPStElC3a+7qw8scmcMYrbh+vKglXa6/CVEi1hz3Yx8u2UOV8+1q/OnpBBwF46+a /xJR6utYIsdAjx8+WXGxVGD/keLI+lQgiRB2X9oZb7YuBlPbphTmako+bCVVRi1ndVfSp2MKl9 YywV6BqRjHKzwTckNgZIm9nsZ2R7wx/ZVshOTmhktvaJZF3Bh1NY91xlKytkEmektF4Nvp7Nww csFUoQUsN3YLZSHe5CNW2jt+evWj2AKoRjjjZ+5gbq12UQkf7sBZW9wpIfaqOlr6aGSiPN/ert VUM= Received: from dhcp-10-88-173-43.hgst.com ([10.88.173.43]) by uls-op-cesaip01.wdc.com with ESMTP; 17 Jul 2019 14:27:09 -0700 From: Dmitry Fomichev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Wed, 17 Jul 2019 17:27:03 -0400 Message-Id: <20190717212703.10205-6-dmitry.fomichev@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190717212703.10205-1-dmitry.fomichev@wdc.com> References: <20190717212703.10205-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.154.42 Subject: [Qemu-devel] [PATCH v2 5/5] hw/scsi: Check sense key before READ CAPACITY output snoop 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: Fam Zheng , Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Shin'ichiro Kawasaki When READ CAPACITY command completes, scsi_read_complete() function snoops the command result and updates SCSIDevice members blocksize and max_lba . However, this update is executed even when READ CAPACITY command indicates an error in sense data. This causes unexpected blocksize update with zero value for SCSI devices without READ CAPACITY(10) command support and eventually results in a divide by zero. An emulated device by TCMU-runner is an example of a device that doesn't support READ CAPACITY(10) command. To avoid the unexpected update, add sense key check in scsi_read_complete() function. The function already checks the sense key for VPD Block Limits emulation. Make scsi_parse_sense_buf() call common for VPD Block Limits emulation and READ CAPACITY snoop. Update blocksize and max_lba only if READ CAPACITY returns zero sense key. Signed-off-by: Shin'ichiro Kawasaki --- hw/scsi/scsi-generic.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c index a43efe39ec..e38d3160fa 100644 --- a/hw/scsi/scsi-generic.c +++ b/hw/scsi/scsi-generic.c @@ -238,6 +238,7 @@ static void scsi_read_complete(void * opaque, int ret) SCSIGenericReq *r = (SCSIGenericReq *)opaque; SCSIDevice *s = r->req.dev; int len; + uint8_t sense_key = NO_SENSE; assert(r->req.aiocb != NULL); r->req.aiocb = NULL; @@ -254,6 +255,12 @@ static void scsi_read_complete(void * opaque, int ret) r->len = -1; + if (r->io_header.driver_status & SG_ERR_DRIVER_SENSE) { + SCSISense sense = + scsi_parse_sense_buf(r->req.sense, r->io_header.sb_len_wr); + sense_key = sense.key; + } + /* * Check if this is a VPD Block Limits request that * resulted in sense error but would need emulation. @@ -264,9 +271,7 @@ static void scsi_read_complete(void * opaque, int ret) r->req.cmd.buf[0] == INQUIRY && (r->req.cmd.buf[1] & 0x01) && r->req.cmd.buf[2] == 0xb0) { - SCSISense sense = - scsi_parse_sense_buf(r->req.sense, r->io_header.sb_len_wr); - if (sense.key == ILLEGAL_REQUEST) { + if (sense_key == ILLEGAL_REQUEST) { len = scsi_generic_emulate_block_limits(r, s); /* * No need to let scsi_read_complete go on and handle an @@ -281,15 +286,17 @@ static void scsi_read_complete(void * opaque, int ret) goto done; } - /* Snoop READ CAPACITY output to set the blocksize. */ - if (r->req.cmd.buf[0] == READ_CAPACITY_10 && - (ldl_be_p(&r->buf[0]) != 0xffffffffU || s->max_lba == 0)) { - s->blocksize = ldl_be_p(&r->buf[4]); - s->max_lba = ldl_be_p(&r->buf[0]) & 0xffffffffULL; - } else if (r->req.cmd.buf[0] == SERVICE_ACTION_IN_16 && - (r->req.cmd.buf[1] & 31) == SAI_READ_CAPACITY_16) { - s->blocksize = ldl_be_p(&r->buf[8]); - s->max_lba = ldq_be_p(&r->buf[0]); + /* Snoop READ CAPACITY output to set the blocksize. */ + if (sense_key == NO_SENSE) { + if (r->req.cmd.buf[0] == READ_CAPACITY_10 && + (ldl_be_p(&r->buf[0]) != 0xffffffffU || s->max_lba == 0)) { + s->blocksize = ldl_be_p(&r->buf[4]); + s->max_lba = ldl_be_p(&r->buf[0]) & 0xffffffffULL; + } else if (r->req.cmd.buf[0] == SERVICE_ACTION_IN_16 && + (r->req.cmd.buf[1] & 31) == SAI_READ_CAPACITY_16) { + s->blocksize = ldl_be_p(&r->buf[8]); + s->max_lba = ldq_be_p(&r->buf[0]); + } } blk_set_guest_block_size(s->conf.blk, s->blocksize);