From patchwork Thu Jul 27 20:00:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 13330656 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id E71A8EB64DD for ; Thu, 27 Jul 2023 20:06:44 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qP7Ag-0000ep-7V; Thu, 27 Jul 2023 16:01:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qP7Ac-0000db-7m for qemu-devel@nongnu.org; Thu, 27 Jul 2023 16:01:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qP7AZ-0002fl-Sh for qemu-devel@nongnu.org; Thu, 27 Jul 2023 16:01:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690488066; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EJCKaXx2reEQv2jkA9KLDOTxJPVAu6k6sc0PzTJpPbY=; b=DX0aa1lnfzXhjS1gLJlk5rnF+FzwcLVO3MuMEQp11bEUvzPTvc+bKgGxNf4U2bAS3vIQgE O4DtacGRQ5Zq7hh3XQWoRxnOCmYmN3OUADIe2OhPxBOvqNC0/cOWOnzMQ92LRwwvlFtSZX 9yvkYGpZ2ZuY4E1AHvZVOgDbKy/SFLY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-126-2a7PcnEoON6gcp39mIFEkQ-1; Thu, 27 Jul 2023 16:01:04 -0400 X-MC-Unique: 2a7PcnEoON6gcp39mIFEkQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B4878802A7D; Thu, 27 Jul 2023 20:01:03 +0000 (UTC) Received: from localhost (unknown [10.39.193.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 207CB1454147; Thu, 27 Jul 2023 20:01:02 +0000 (UTC) From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Richard Henderson , Hanna Reitz , Stefano Garzarella Subject: [PULL for-8.1 1/8] block/blkio: enable the completion eventfd Date: Thu, 27 Jul 2023 16:00:51 -0400 Message-ID: <20230727200058.1071776-2-stefanha@redhat.com> In-Reply-To: <20230727200058.1071776-1-stefanha@redhat.com> References: <20230727200058.1071776-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stefano Garzarella Until libblkio 1.3.0, virtio-blk drivers had completion eventfd notifications enabled from the start, but from the next releases this is no longer the case, so we have to explicitly enable them. In fact, the libblkio documentation says they could be disabled, so we should always enable them at the start if we want to be sure to get completion eventfd notifications: By default, the driver might not generate completion events for requests so it is necessary to explicitly enable the completion file descriptor before use: void blkioq_set_completion_fd_enabled(struct blkioq *q, bool enable); I discovered this while trying a development version of libblkio: the guest kernel hangs during boot, while probing the device. Fixes: fd66dbd424f5 ("blkio: add libblkio block driver") Signed-off-by: Stefano Garzarella Message-id: 20230725103744.77343-1-sgarzare@redhat.com Signed-off-by: Stefan Hajnoczi --- block/blkio.c | 1 + 1 file changed, 1 insertion(+) diff --git a/block/blkio.c b/block/blkio.c index 1798648134..bc1fac48b7 100644 --- a/block/blkio.c +++ b/block/blkio.c @@ -845,6 +845,7 @@ static int blkio_file_open(BlockDriverState *bs, QDict *options, int flags, QLIST_INIT(&s->bounce_bufs); s->blkioq = blkio_get_queue(s->blkio, 0); s->completion_fd = blkioq_get_completion_fd(s->blkioq); + blkioq_set_completion_fd_enabled(s->blkioq, true); blkio_attach_aio_context(bs, bdrv_get_aio_context(bs)); return 0; From patchwork Thu Jul 27 20:00:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 13330689 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 8EB5BEB64DD for ; Thu, 27 Jul 2023 20:17:25 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qP7Am-0000fZ-3i; Thu, 27 Jul 2023 16:01:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qP7Ag-0000ez-8l for qemu-devel@nongnu.org; Thu, 27 Jul 2023 16:01:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qP7Ae-0002ie-IQ for qemu-devel@nongnu.org; Thu, 27 Jul 2023 16:01:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690488071; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qBxH1iRanqco3HtF82nh9FMyY8AR3YyxU+2pBdaif24=; b=KjBFYZPPaxHjTzAmFduMurtJEC1wSZiJD5Lq+NU8kmWQE/lSaWnqCUHALd9J783y+Qoe+h Q2IyEydltL8DgU2o/V7v7u8nLY75/YngYES6QMaxtadG40mO+rNDit/hqscE+wwC5Q/D9h 4XjjOoAcrPgQGu5XpMac5aWo663byz8= Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-488-f5ICcI7kMFG2uOf07W61wg-1; Thu, 27 Jul 2023 16:01:08 -0400 X-MC-Unique: f5ICcI7kMFG2uOf07W61wg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A9C5938149B8; Thu, 27 Jul 2023 20:01:06 +0000 (UTC) Received: from localhost (unknown [10.39.193.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id EE2C2C57964; Thu, 27 Jul 2023 20:01:05 +0000 (UTC) From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Richard Henderson , Hanna Reitz , Stefano Garzarella , Qing Wang , =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= Subject: [PULL for-8.1 2/8] block/blkio: do not use open flags in qemu_open() Date: Thu, 27 Jul 2023 16:00:52 -0400 Message-ID: <20230727200058.1071776-3-stefanha@redhat.com> In-Reply-To: <20230727200058.1071776-1-stefanha@redhat.com> References: <20230727200058.1071776-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stefano Garzarella qemu_open() in blkio_virtio_blk_common_open() is used to open the character device (e.g. /dev/vhost-vdpa-0 or /dev/vfio/vfio) or in the future eventually the unix socket. In all these cases we cannot open the path in read-only mode, when the `read-only` option of blockdev is on, because the exchange of IOCTL commands for example will fail. In order to open the device read-only, we have to use the `read-only` property of the libblkio driver as we already do in blkio_file_open(). Fixes: cad2ccc395 ("block/blkio: use qemu_open() to support fd passing for virtio-blk") Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=2225439 Reported-by: Qing Wang Signed-off-by: Stefano Garzarella Reviewed-by: Daniel P. Berrangé Message-id: 20230726074807.14041-1-sgarzare@redhat.com Signed-off-by: Stefan Hajnoczi --- block/blkio.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/block/blkio.c b/block/blkio.c index bc1fac48b7..7eb1b94820 100644 --- a/block/blkio.c +++ b/block/blkio.c @@ -686,15 +686,18 @@ static int blkio_virtio_blk_common_open(BlockDriverState *bs, * layer through the "/dev/fdset/N" special path. */ if (fd_supported) { - int open_flags; - - if (flags & BDRV_O_RDWR) { - open_flags = O_RDWR; - } else { - open_flags = O_RDONLY; - } - - fd = qemu_open(path, open_flags, errp); + /* + * `path` can contain the path of a character device + * (e.g. /dev/vhost-vdpa-0 or /dev/vfio/vfio) or a unix socket. + * + * So, we should always open it with O_RDWR flag, also if BDRV_O_RDWR + * is not set in the open flags, because the exchange of IOCTL commands + * for example will fail. + * + * In order to open the device read-only, we are using the `read-only` + * property of the libblkio driver in blkio_file_open(). + */ + fd = qemu_open(path, O_RDWR, errp); if (fd < 0) { return -EINVAL; } From patchwork Thu Jul 27 20:00:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 13330683 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 484B1EB64DD for ; Thu, 27 Jul 2023 20:11:10 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qP7BC-0000nm-EK; Thu, 27 Jul 2023 16:01:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qP7Ao-0000gC-Aa for qemu-devel@nongnu.org; Thu, 27 Jul 2023 16:01:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qP7Ak-0002jV-Br for qemu-devel@nongnu.org; Thu, 27 Jul 2023 16:01:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690488076; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tsxiWqVUN4b/jGAtlTYnRiq+MCbYH2vLoTyH/YKZ3Gc=; b=dH3gkSq1ZnQmgs/vWoKFPYnyfwRyhy9MRJX+NUdz+yjwN/OOUHJK/rZ7g6CyT29sa+ncpW fmn8CLNDImX8Hki+6xotO7wbi+0LGaMS5161ZZEzVMCHAFdxdvcud/ZXAlmuJpBfjfiRan EcPkOFmdCCgomKAkx5cPjTR3Cy21mmM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-623-SZ-bJ80iPMCPYhZZSr-Efw-1; Thu, 27 Jul 2023 16:01:12 -0400 X-MC-Unique: SZ-bJ80iPMCPYhZZSr-Efw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D5469185A78F; Thu, 27 Jul 2023 20:01:09 +0000 (UTC) Received: from localhost (unknown [10.39.193.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4FAD540C2063; Thu, 27 Jul 2023 20:01:08 +0000 (UTC) From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Richard Henderson , Hanna Reitz , Sam Li , Matthew Rosato , =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= Subject: [PULL for-8.1 3/8] block/file-posix: fix g_file_get_contents return path Date: Thu, 27 Jul 2023 16:00:53 -0400 Message-ID: <20230727200058.1071776-4-stefanha@redhat.com> In-Reply-To: <20230727200058.1071776-1-stefanha@redhat.com> References: <20230727200058.1071776-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass client-ip=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Sam Li The g_file_get_contents() function returns a g_boolean. If it fails, the returned value will be 0 instead of -1. Solve the issue by skipping assigning ret value. This issue was found by Matthew Rosato using virtio-blk-{pci,ccw} backed by an NVMe partition e.g. /dev/nvme0n1p1 on s390x. Signed-off-by: Sam Li Reviewed-by: Matthew Rosato Reviewed-by: Stefan Hajnoczi Reviewed-by: Daniel P. Berrangé Message-id: 20230727115844.8480-1-faithilikerun@gmail.com Signed-off-by: Stefan Hajnoczi --- block/file-posix.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 9e8e3d8ca5..b16e9c21a1 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1232,7 +1232,6 @@ static int hdev_get_max_hw_transfer(int fd, struct stat *st) static int get_sysfs_str_val(struct stat *st, const char *attribute, char **val) { g_autofree char *sysfspath = NULL; - int ret; size_t len; if (!S_ISBLK(st->st_mode)) { @@ -1242,8 +1241,7 @@ static int get_sysfs_str_val(struct stat *st, const char *attribute, sysfspath = g_strdup_printf("/sys/dev/block/%u:%u/queue/%s", major(st->st_rdev), minor(st->st_rdev), attribute); - ret = g_file_get_contents(sysfspath, val, &len, NULL); - if (ret == -1) { + if (!g_file_get_contents(sysfspath, val, &len, NULL)) { return -ENOENT; } @@ -1253,7 +1251,7 @@ static int get_sysfs_str_val(struct stat *st, const char *attribute, if (*(p + len - 1) == '\n') { *(p + len - 1) = '\0'; } - return ret; + return 0; } #endif From patchwork Thu Jul 27 20:00:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 13330684 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id F0D6AEB64DD for ; Thu, 27 Jul 2023 20:15:03 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qP7BE-0000pX-Ga; Thu, 27 Jul 2023 16:01:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qP7Aw-0000ht-SN for qemu-devel@nongnu.org; Thu, 27 Jul 2023 16:01:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qP7As-0002kF-B4 for qemu-devel@nongnu.org; Thu, 27 Jul 2023 16:01:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690488081; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=z2XcPBhRtlf4rI2SPwIwNo+yPFXbfQemEPEauxege4k=; b=gYxvXK5Q0PEvxlPuJT14AI2y7toYOIWJ1f+bRwtIdqTz5y3eG+c98fKVb/lUBU/S/M1yhp HS9INDy+SeoY+pmU/MeWMpidADe0dNx8sFPWV0kE7ok0342xkjnTyrVE5UScNjdzcVb12N Ps2AKWgAndF+r7VFjHr4qosKEjHCELk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-573-fKJLDxhsMWmBfi4aujgOSg-1; Thu, 27 Jul 2023 16:01:20 -0400 X-MC-Unique: fKJLDxhsMWmBfi4aujgOSg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1043F8028B2; Thu, 27 Jul 2023 20:01:18 +0000 (UTC) Received: from localhost (unknown [10.39.193.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 82E0F2166B25; Thu, 27 Jul 2023 20:01:17 +0000 (UTC) From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Richard Henderson , Hanna Reitz , Peter Maydell Subject: [PULL for-8.1 4/8] block: Fix pad_request's request restriction Date: Thu, 27 Jul 2023 16:00:54 -0400 Message-ID: <20230727200058.1071776-5-stefanha@redhat.com> In-Reply-To: <20230727200058.1071776-1-stefanha@redhat.com> References: <20230727200058.1071776-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass client-ip=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Hanna Czenczek bdrv_pad_request() relies on requests' lengths not to exceed SIZE_MAX, which bdrv_check_qiov_request() does not guarantee. bdrv_check_request32() however will guarantee this, and both of bdrv_pad_request()'s callers (bdrv_co_preadv_part() and bdrv_co_pwritev_part()) already run it before calling bdrv_pad_request(). Therefore, bdrv_pad_request() can safely call bdrv_check_request32() without expecting error, too. In effect, this patch will not change guest-visible behavior. It is a clean-up to tighten a condition to match what is guaranteed by our callers, and which exists purely to show clearly why the subsequent assertion (`assert(*bytes <= SIZE_MAX)`) is always true. Note there is a difference between the interfaces of bdrv_check_qiov_request() and bdrv_check_request32(): The former takes an errp, the latter does not, so we can no longer just pass &error_abort. Instead, we need to check the returned value. While we do expect success (because the callers have already run this function), an assert(ret == 0) is not much simpler than just to return an error if it occurs, so let us handle errors by returning them up the stack now. Reported-by: Peter Maydell Signed-off-by: Hanna Czenczek Message-id: 20230714085938.202730-1-hreitz@redhat.com Fixes: 18743311b829cafc1737a5f20bc3248d5f91ee2a ("block: Collapse padded I/O vecs exceeding IOV_MAX") Signed-off-by: Hanna Czenczek Signed-off-by: Stefan Hajnoczi --- block/io.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/block/io.c b/block/io.c index e8293d6b26..055fcf7438 100644 --- a/block/io.c +++ b/block/io.c @@ -1710,7 +1710,11 @@ static int bdrv_pad_request(BlockDriverState *bs, int sliced_niov; size_t sliced_head, sliced_tail; - bdrv_check_qiov_request(*offset, *bytes, *qiov, *qiov_offset, &error_abort); + /* Should have been checked by the caller already */ + ret = bdrv_check_request32(*offset, *bytes, *qiov, *qiov_offset); + if (ret < 0) { + return ret; + } if (!bdrv_init_padding(bs, *offset, *bytes, write, pad)) { if (padded) { @@ -1723,7 +1727,7 @@ static int bdrv_pad_request(BlockDriverState *bs, &sliced_head, &sliced_tail, &sliced_niov); - /* Guaranteed by bdrv_check_qiov_request() */ + /* Guaranteed by bdrv_check_request32() */ assert(*bytes <= SIZE_MAX); ret = bdrv_create_padded_qiov(bs, pad, sliced_iov, sliced_niov, sliced_head, *bytes); From patchwork Thu Jul 27 20:00:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 13330722 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 2AAABC001DC for ; Thu, 27 Jul 2023 20:40:41 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qP7BF-0000qS-A8; Thu, 27 Jul 2023 16:01:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qP7Au-0000gO-5z for qemu-devel@nongnu.org; Thu, 27 Jul 2023 16:01:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qP7As-0002kb-8V for qemu-devel@nongnu.org; Thu, 27 Jul 2023 16:01:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690488083; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=H3+AAufHnWErj5VG+DPHAeiau76Tcpt2M705gGpBbEk=; b=Ems8JvefWOlxz2TXiBHKcvO7eyDswXix+kkume3eUx1yjRNSvVbeF4nmrr7wTaHx0NI2/p MApa1GE7zH4rs4yALsdg6m98reGU5OslkGZaMSeRI10CVbj8jVC73DndWnLbZnoxjWVJWn EcGgV/6I/l190elKttKJk9rQAAD5Atg= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-102-mwJ4Yi3BP4et9knOizb37Q-1; Thu, 27 Jul 2023 16:01:21 -0400 X-MC-Unique: mwJ4Yi3BP4et9knOizb37Q-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9819180027F; Thu, 27 Jul 2023 20:01:20 +0000 (UTC) Received: from localhost (unknown [10.39.193.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id F28391121330; Thu, 27 Jul 2023 20:01:19 +0000 (UTC) From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Richard Henderson , Hanna Reitz , Stefano Garzarella Subject: [PULL for-8.1 5/8] block/blkio: move blkio_connect() in the drivers functions Date: Thu, 27 Jul 2023 16:00:55 -0400 Message-ID: <20230727200058.1071776-6-stefanha@redhat.com> In-Reply-To: <20230727200058.1071776-1-stefanha@redhat.com> References: <20230727200058.1071776-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stefano Garzarella This is in preparation for the next patch, where for virtio-blk drivers we need to handle the failure of blkio_connect(). Let's also rename the *_open() functions to *_connect() to make the code reflect the changes applied. Signed-off-by: Stefano Garzarella Message-id: 20230727161020.84213-2-sgarzare@redhat.com Signed-off-by: Stefan Hajnoczi --- block/blkio.c | 71 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 29 deletions(-) diff --git a/block/blkio.c b/block/blkio.c index 7eb1b94820..8ad7c0b575 100644 --- a/block/blkio.c +++ b/block/blkio.c @@ -603,8 +603,8 @@ static void blkio_unregister_buf(BlockDriverState *bs, void *host, size_t size) } } -static int blkio_io_uring_open(BlockDriverState *bs, QDict *options, int flags, - Error **errp) +static int blkio_io_uring_connect(BlockDriverState *bs, QDict *options, + int flags, Error **errp) { const char *filename = qdict_get_str(options, "filename"); BDRVBlkioState *s = bs->opaque; @@ -627,11 +627,18 @@ static int blkio_io_uring_open(BlockDriverState *bs, QDict *options, int flags, } } + ret = blkio_connect(s->blkio); + if (ret < 0) { + error_setg_errno(errp, -ret, "blkio_connect failed: %s", + blkio_get_error_msg()); + return ret; + } + return 0; } -static int blkio_nvme_io_uring(BlockDriverState *bs, QDict *options, int flags, - Error **errp) +static int blkio_nvme_io_uring_connect(BlockDriverState *bs, QDict *options, + int flags, Error **errp) { const char *path = qdict_get_try_str(options, "path"); BDRVBlkioState *s = bs->opaque; @@ -655,11 +662,18 @@ static int blkio_nvme_io_uring(BlockDriverState *bs, QDict *options, int flags, return -EINVAL; } + ret = blkio_connect(s->blkio); + if (ret < 0) { + error_setg_errno(errp, -ret, "blkio_connect failed: %s", + blkio_get_error_msg()); + return ret; + } + return 0; } -static int blkio_virtio_blk_common_open(BlockDriverState *bs, - QDict *options, int flags, Error **errp) +static int blkio_virtio_blk_connect(BlockDriverState *bs, QDict *options, + int flags, Error **errp) { const char *path = qdict_get_try_str(options, "path"); BDRVBlkioState *s = bs->opaque; @@ -718,6 +732,13 @@ static int blkio_virtio_blk_common_open(BlockDriverState *bs, } } + ret = blkio_connect(s->blkio); + if (ret < 0) { + error_setg_errno(errp, -ret, "blkio_connect failed: %s", + blkio_get_error_msg()); + return ret; + } + qdict_del(options, "path"); return 0; @@ -737,16 +758,26 @@ static int blkio_file_open(BlockDriverState *bs, QDict *options, int flags, return ret; } + if (!(flags & BDRV_O_RDWR)) { + ret = blkio_set_bool(s->blkio, "read-only", true); + if (ret < 0) { + error_setg_errno(errp, -ret, "failed to set read-only: %s", + blkio_get_error_msg()); + blkio_destroy(&s->blkio); + return ret; + } + } + if (strcmp(blkio_driver, "io_uring") == 0) { - ret = blkio_io_uring_open(bs, options, flags, errp); + ret = blkio_io_uring_connect(bs, options, flags, errp); } else if (strcmp(blkio_driver, "nvme-io_uring") == 0) { - ret = blkio_nvme_io_uring(bs, options, flags, errp); + ret = blkio_nvme_io_uring_connect(bs, options, flags, errp); } else if (strcmp(blkio_driver, "virtio-blk-vfio-pci") == 0) { - ret = blkio_virtio_blk_common_open(bs, options, flags, errp); + ret = blkio_virtio_blk_connect(bs, options, flags, errp); } else if (strcmp(blkio_driver, "virtio-blk-vhost-user") == 0) { - ret = blkio_virtio_blk_common_open(bs, options, flags, errp); + ret = blkio_virtio_blk_connect(bs, options, flags, errp); } else if (strcmp(blkio_driver, "virtio-blk-vhost-vdpa") == 0) { - ret = blkio_virtio_blk_common_open(bs, options, flags, errp); + ret = blkio_virtio_blk_connect(bs, options, flags, errp); } else { g_assert_not_reached(); } @@ -755,24 +786,6 @@ static int blkio_file_open(BlockDriverState *bs, QDict *options, int flags, return ret; } - if (!(flags & BDRV_O_RDWR)) { - ret = blkio_set_bool(s->blkio, "read-only", true); - if (ret < 0) { - error_setg_errno(errp, -ret, "failed to set read-only: %s", - blkio_get_error_msg()); - blkio_destroy(&s->blkio); - return ret; - } - } - - ret = blkio_connect(s->blkio); - if (ret < 0) { - error_setg_errno(errp, -ret, "blkio_connect failed: %s", - blkio_get_error_msg()); - blkio_destroy(&s->blkio); - return ret; - } - ret = blkio_get_bool(s->blkio, "needs-mem-regions", &s->needs_mem_regions); From patchwork Thu Jul 27 20:00:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 13330682 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id E9328EB64DD for ; Thu, 27 Jul 2023 20:09:09 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qP7BE-0000pf-Pv; Thu, 27 Jul 2023 16:01:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qP7B1-0000l4-Dh for qemu-devel@nongnu.org; Thu, 27 Jul 2023 16:01:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qP7Ay-0002lp-Pv for qemu-devel@nongnu.org; Thu, 27 Jul 2023 16:01:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690488090; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FuwXOvKeRHEancDJS8OkcP0iOKy6UX86GAg2J5w7NHE=; b=eeWZXL+KqYzp5MpSclWtm6tRvMG9It5j4Yoxp0LSzx87AUzccLq1wnjjI05BClHuri91a8 i6CQl4CeVGOJ3ryH57hA+LkHgFHo3UWkXfob4s1ivCA9r7DPyyaXd8ORGToJSoyXofaR/A BUzh1WOB30NhXxMYIEwKOomOH8PDNLw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-460-tXjbP1HXPpekAzV8j3GmDA-1; Thu, 27 Jul 2023 16:01:24 -0400 X-MC-Unique: tXjbP1HXPpekAzV8j3GmDA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 62FDA185A7A3; Thu, 27 Jul 2023 20:01:23 +0000 (UTC) Received: from localhost (unknown [10.39.193.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB32B492B02; Thu, 27 Jul 2023 20:01:22 +0000 (UTC) From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Richard Henderson , Hanna Reitz , Stefano Garzarella Subject: [PULL for-8.1 6/8] block/blkio: retry blkio_connect() if it fails using `fd` Date: Thu, 27 Jul 2023 16:00:56 -0400 Message-ID: <20230727200058.1071776-7-stefanha@redhat.com> In-Reply-To: <20230727200058.1071776-1-stefanha@redhat.com> References: <20230727200058.1071776-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stefano Garzarella libblkio 1.3.0 added support of "fd" property for virtio-blk-vhost-vdpa driver. In QEMU, starting from commit cad2ccc395 ("block/blkio: use qemu_open() to support fd passing for virtio-blk") we are using `blkio_get_int(..., "fd")` to check if the "fd" property is supported for all the virtio-blk-* driver. Unfortunately that property is also available for those driver that do not support it, such as virtio-blk-vhost-user. So, `blkio_get_int()` is not enough to check whether the driver supports the `fd` property or not. This is because the virito-blk common libblkio driver only checks whether or not `fd` is set during `blkio_connect()` and fails with -EINVAL for those transports that do not support it (all except vhost-vdpa for now). So let's handle the `blkio_connect()` failure, retrying it using `path` directly. Fixes: cad2ccc395 ("block/blkio: use qemu_open() to support fd passing for virtio-blk") Suggested-by: Stefan Hajnoczi Signed-off-by: Stefano Garzarella Message-id: 20230727161020.84213-3-sgarzare@redhat.com Signed-off-by: Stefan Hajnoczi --- block/blkio.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/block/blkio.c b/block/blkio.c index 8ad7c0b575..60d2d0f129 100644 --- a/block/blkio.c +++ b/block/blkio.c @@ -733,6 +733,35 @@ static int blkio_virtio_blk_connect(BlockDriverState *bs, QDict *options, } ret = blkio_connect(s->blkio); + /* + * If the libblkio driver doesn't support the `fd` property, blkio_connect() + * will fail with -EINVAL. So let's try calling blkio_connect() again by + * directly setting `path`. + */ + if (fd_supported && ret == -EINVAL) { + qemu_close(fd); + + /* + * We need to clear the `fd` property we set previously by setting + * it to -1. + */ + ret = blkio_set_int(s->blkio, "fd", -1); + if (ret < 0) { + error_setg_errno(errp, -ret, "failed to set fd: %s", + blkio_get_error_msg()); + return ret; + } + + ret = blkio_set_str(s->blkio, "path", path); + if (ret < 0) { + error_setg_errno(errp, -ret, "failed to set path: %s", + blkio_get_error_msg()); + return ret; + } + + ret = blkio_connect(s->blkio); + } + if (ret < 0) { error_setg_errno(errp, -ret, "blkio_connect failed: %s", blkio_get_error_msg()); From patchwork Thu Jul 27 20:00:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 13330723 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 12A65EB64DD for ; Thu, 27 Jul 2023 20:41:19 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qP7BF-0000qf-Gx; Thu, 27 Jul 2023 16:01:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qP7Az-0000jM-J4 for qemu-devel@nongnu.org; Thu, 27 Jul 2023 16:01:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qP7Ax-0002lj-RU for qemu-devel@nongnu.org; Thu, 27 Jul 2023 16:01:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690488089; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Hz9W4uu3OMb54XF8JKznaOXgNmLIjjW6sqlVLyyADKY=; b=IrOyRLmGCyHA0/ZaAlUMHxnfqJXa/l4ou9HIF/Kyhj3wBvMU47MTekXTC8nZCpzfgz8U6a cuoI5fghYs8TbGyel4g61Fptin37TYkW0gUfM4Z2d2xM8FNnIxYikmubrI5cbITkQBdIAg 97vB9PPEMAe6VobsNip+aza2YzlBqZk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-662-VbPgJ9CWNaGnMVgbk2PYTA-1; Thu, 27 Jul 2023 16:01:27 -0400 X-MC-Unique: VbPgJ9CWNaGnMVgbk2PYTA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CFC54856F67; Thu, 27 Jul 2023 20:01:25 +0000 (UTC) Received: from localhost (unknown [10.39.193.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3528C1121330; Thu, 27 Jul 2023 20:01:24 +0000 (UTC) From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Richard Henderson , Hanna Reitz , Stefano Garzarella , Qing Wang Subject: [PULL for-8.1 7/8] block/blkio: fall back on using `path` when `fd` setting fails Date: Thu, 27 Jul 2023 16:00:57 -0400 Message-ID: <20230727200058.1071776-8-stefanha@redhat.com> In-Reply-To: <20230727200058.1071776-1-stefanha@redhat.com> References: <20230727200058.1071776-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stefano Garzarella qemu_open() fails if called with an unix domain socket in this way: -blockdev node-name=drive0,driver=virtio-blk-vhost-user,path=vhost-user-blk.sock,cache.direct=on: Could not open 'vhost-user-blk.sock': No such device or address Since virtio-blk-vhost-user does not support fd passing, let`s always fall back on using `path` if we fail the fd passing. Fixes: cad2ccc395 ("block/blkio: use qemu_open() to support fd passing for virtio-blk") Reported-by: Qing Wang Signed-off-by: Stefano Garzarella Message-id: 20230727161020.84213-4-sgarzare@redhat.com Signed-off-by: Stefan Hajnoczi --- block/blkio.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/block/blkio.c b/block/blkio.c index 60d2d0f129..72b46d61fd 100644 --- a/block/blkio.c +++ b/block/blkio.c @@ -711,19 +711,19 @@ static int blkio_virtio_blk_connect(BlockDriverState *bs, QDict *options, * In order to open the device read-only, we are using the `read-only` * property of the libblkio driver in blkio_file_open(). */ - fd = qemu_open(path, O_RDWR, errp); + fd = qemu_open(path, O_RDWR, NULL); if (fd < 0) { - return -EINVAL; + fd_supported = false; + } else { + ret = blkio_set_int(s->blkio, "fd", fd); + if (ret < 0) { + fd_supported = false; + qemu_close(fd); + } } + } - ret = blkio_set_int(s->blkio, "fd", fd); - if (ret < 0) { - error_setg_errno(errp, -ret, "failed to set fd: %s", - blkio_get_error_msg()); - qemu_close(fd); - return ret; - } - } else { + if (!fd_supported) { ret = blkio_set_str(s->blkio, "path", path); if (ret < 0) { error_setg_errno(errp, -ret, "failed to set path: %s", From patchwork Thu Jul 27 20:00:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 13330685 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 5593AC00528 for ; Thu, 27 Jul 2023 20:16:35 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qP7BG-0000ql-Bp; Thu, 27 Jul 2023 16:01:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qP7B3-0000li-4j for qemu-devel@nongnu.org; Thu, 27 Jul 2023 16:01:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qP7B1-0002mn-6R for qemu-devel@nongnu.org; Thu, 27 Jul 2023 16:01:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690488093; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KW/dec1j/setmZe1D7OoJVA6gf1hHhrxrVymaFzSgtQ=; b=CNmPV6MbQtJM/2qwHNaz2jS10BGcqSNVKb9yfFbWuWC+8MH5TDMcAFVi8beGSiVa/W98EB omADHrJvSKwarFeRa64QFR8sHQStCGCmCncSPCs6uyufIma3IL8+pO1ButpteH+R1uK04G cTVWJM1q77IMze42ekEJasAHMYI7Bwk= Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-286-WIJuX5zDMdK5RzE8GnsgJg-1; Thu, 27 Jul 2023 16:01:29 -0400 X-MC-Unique: WIJuX5zDMdK5RzE8GnsgJg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 31F7F29A9CA9; Thu, 27 Jul 2023 20:01:28 +0000 (UTC) Received: from localhost (unknown [10.39.193.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8BD611454147; Thu, 27 Jul 2023 20:01:27 +0000 (UTC) From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Richard Henderson , Hanna Reitz , Stefano Garzarella Subject: [PULL for-8.1 8/8] block/blkio: use blkio_set_int("fd") to check fd support Date: Thu, 27 Jul 2023 16:00:58 -0400 Message-ID: <20230727200058.1071776-9-stefanha@redhat.com> In-Reply-To: <20230727200058.1071776-1-stefanha@redhat.com> References: <20230727200058.1071776-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stefano Garzarella Setting the `fd` property fails with virtio-blk-* libblkio drivers that do not support fd passing since https://gitlab.com/libblkio/libblkio/-/merge_requests/208. Getting the `fd` property, on the other hand, always succeeds for virtio-blk-* libblkio drivers even when they don't support fd passing. This patch switches to setting the `fd` property because it is a better mechanism for probing fd passing support than getting the `fd` property. Signed-off-by: Stefano Garzarella Message-id: 20230727161020.84213-5-sgarzare@redhat.com Signed-off-by: Stefan Hajnoczi --- block/blkio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/blkio.c b/block/blkio.c index 72b46d61fd..8e7ce42c79 100644 --- a/block/blkio.c +++ b/block/blkio.c @@ -690,7 +690,7 @@ static int blkio_virtio_blk_connect(BlockDriverState *bs, QDict *options, return -EINVAL; } - if (blkio_get_int(s->blkio, "fd", &fd) == 0) { + if (blkio_set_int(s->blkio, "fd", -1) == 0) { fd_supported = true; }