From nobody Fri May 17 01:44:20 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1691051372; cv=none; d=zohomail.com; s=zohoarc; b=d+6Dkmmk9eSsAE1G8ibLmbEqtKHB6Y/ZImf8wxC7M/NjpLMUTuUIi3tKJfrP0qgqy4lQgPjGRITmBa2sz9Qp0aoNP11wedSq4KVcWyA6VM0D8b7DvdmJttYwjgXMoMCZXkkAaROQeD6hqZUCeFolMl8ApgqduNnj//pXBAY6stM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691051372; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yR04ak6EpRTzBzWjBrh7Bwe/4mz3xwmXIHbNOJbbDLM=; b=I6arVDP64k0vJ1GHoLUtK0xTlPbILEOY4eG40Y0VS60+0fJ8ju0IFpGixe3s7Snrrq1xhTMybVN+OTa/McchHxgtg7DUpS7LRCK6YcEQNAGR6SqORBITqiYCmygGum+JgnRbExzdgNwVW7kdrDdcD+JKJ0qIVglusSexayO5dKY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691051372500194.0378430240188; Thu, 3 Aug 2023 01:29:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRThG-0005vG-Me; Thu, 03 Aug 2023 04:28:38 -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 1qRThF-0005t2-61 for qemu-devel@nongnu.org; Thu, 03 Aug 2023 04:28:37 -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 1qRThD-0007qf-P2 for qemu-devel@nongnu.org; Thu, 03 Aug 2023 04:28:36 -0400 Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-517-X4pboDjuM3mGMw7jXCuyWA-1; Thu, 03 Aug 2023 04:28:33 -0400 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-99bfe6a531bso85243166b.1 for ; Thu, 03 Aug 2023 01:28:33 -0700 (PDT) Received: from step1.home (host-82-57-51-214.retail.telecomitalia.it. [82.57.51.214]) by smtp.gmail.com with ESMTPSA id qp3-20020a170907206300b00991e2b5a27dsm10233139ejb.37.2023.08.03.01.28.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 01:28:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691051314; 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=yR04ak6EpRTzBzWjBrh7Bwe/4mz3xwmXIHbNOJbbDLM=; b=HC1wHNpV81RPC2E7/1yiDDm+JrE2YM63hhS2THvMT3r+Y+CtzFznvFPQ0kdHYBctnCrbIk b84+qBgGmCocFhnt+4BT/2OAGH3FbGG3kTJNG2mLQomFgfNBjZQXzHWRV0KB27vLzLRlG8 975sXvl7iRL8EZTsvKArfuAGosslKeY= X-MC-Unique: X4pboDjuM3mGMw7jXCuyWA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691051312; x=1691656112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yR04ak6EpRTzBzWjBrh7Bwe/4mz3xwmXIHbNOJbbDLM=; b=StoNU6jDkTtyHZ10Ki+mixt9woy0pwbtco7kppjXH+U2je//QdpJx16km8MMjnSig4 WNugZ1hz6Uc2AnS/yHkxmU/72tDCsKjRuLD0hI1h6wkT8v/FU9uGOY1xmSWF1JtornA/ MDcttK1i0kSzhBhCpr5K4tFyZlDsNndu4oYpkZPGS+K+0Q81wof17R8ibP+B8y7zEiVO 4d41cPx4byuLC9rADemW1FlgMu6+q/0M/uKsofpUqg1o/icNOegEjLOmI14DFVlFi7EY KdsBjkbF7fet7kyZPIitrpElkB7G34OHa4hhAu+rAVmbn99BefS7uEmPX29HSWdSxZOh EH5Q== X-Gm-Message-State: ABy/qLYkGcociferSE4UWosGuoNXKaTFnwmJtuvQgWtnDpQeIobIvg/c Z4ZQ8Y1OZEkca+Ogq5HIBF/4zISYzIGLLGIliSLg+et7/3i2vxWQUFIIC+7H0huRDA+iTC3BBOW ZHSpGObW452zm3CdXk5ddI5fkQvUN2CcJgco8b9HD2oZaBqOieZH6Vx+yxHUM74GMyTlp/i+Dgf E= X-Received: by 2002:a17:906:7389:b0:99b:4bab:2838 with SMTP id f9-20020a170906738900b0099b4bab2838mr7155513ejl.0.1691051312298; Thu, 03 Aug 2023 01:28:32 -0700 (PDT) X-Google-Smtp-Source: APBJJlGmhOLvW23SjK5Qx0lfsu8Z9VF5vgwAaZTgTqOekffdxDSJT5V1sN8ayydvH6Ys0HEFcHbYkg== X-Received: by 2002:a17:906:7389:b0:99b:4bab:2838 with SMTP id f9-20020a170906738900b0099b4bab2838mr7155468ejl.0.1691051311111; Thu, 03 Aug 2023 01:28:31 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Hanna Reitz , Stefan Hajnoczi , qemu-block@nongnu.org, Kevin Wolf , Stefano Garzarella Subject: [PATCH v2 1/2] block/blkio: close the fd when blkio_connect() fails Date: Thu, 3 Aug 2023 10:28:24 +0200 Message-ID: <20230803082825.25293-2-sgarzare@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230803082825.25293-1-sgarzare@redhat.com> References: <20230803082825.25293-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1691051373418100001 Content-Type: text/plain; charset="utf-8" libblkio drivers take ownership of `fd` only after a successful blkio_connect(), so if it fails, we are still the owners. Fixes: cad2ccc395 ("block/blkio: use qemu_open() to support fd passing for = virtio-blk") Suggested-by: Hanna Czenczek Signed-off-by: Stefano Garzarella Reviewed-by: Hanna Czenczek --- Notes: v2: - avoid to use `fd_supported` to track a valid fd [Hanna] block/blkio.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/block/blkio.c b/block/blkio.c index 8e7ce42c79..baba2f0b67 100644 --- a/block/blkio.c +++ b/block/blkio.c @@ -678,7 +678,7 @@ static int blkio_virtio_blk_connect(BlockDriverState *b= s, QDict *options, const char *path =3D qdict_get_try_str(options, "path"); BDRVBlkioState *s =3D bs->opaque; bool fd_supported =3D false; - int fd, ret; + int fd =3D -1, ret; =20 if (!path) { error_setg(errp, "missing 'path' option"); @@ -719,6 +719,7 @@ static int blkio_virtio_blk_connect(BlockDriverState *b= s, QDict *options, if (ret < 0) { fd_supported =3D false; qemu_close(fd); + fd =3D -1; } } } @@ -733,14 +734,18 @@ static int blkio_virtio_blk_connect(BlockDriverState = *bs, QDict *options, } =20 ret =3D blkio_connect(s->blkio); + if (ret < 0 && fd >=3D 0) { + /* Failed to give the FD to libblkio, close it */ + qemu_close(fd); + fd =3D -1; + } + /* * If the libblkio driver doesn't support the `fd` property, blkio_con= nect() * will fail with -EINVAL. So let's try calling blkio_connect() again = by * directly setting `path`. */ if (fd_supported && ret =3D=3D -EINVAL) { - qemu_close(fd); - /* * We need to clear the `fd` property we set previously by setting * it to -1. --=20 2.41.0 From nobody Fri May 17 01:44:20 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1691051389; cv=none; d=zohomail.com; s=zohoarc; b=QcDOJl6UaAPycIuzsnfw5BnoY/YIntJhL6wTemHdjdfFXLlqQ6hIign2Ge37KR3vSulzHcfCgDz+x6j/jgAjzzuserSdwDnjVKprE9rNBYVbHcEnGS9b63XtHpmbfvNGapAJxSgrUfFYs0WQTvlL1HyH89McekpttHEMOM/x9fg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691051389; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=AQj+RyBDUao2ZglCFKibOMg+XHj0z4ipB9ZybK94U/U=; b=hEJiZkw82xMZmtSJxpNKVnVvQcNWhmo1f0JAG6xDG9prq3DyQq92FT9uceKQUUSjDxymDmXK+hN7Sn3TP2Utu5NmC7KnKTXBjMm6Hydrz6sC+URirz4/SUQDJCwnDAD+dn5TTNFWQnyyQgc5/TIsraF9qlX01wV70bTPCJXEc6M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691051389371140.37830750292892; Thu, 3 Aug 2023 01:29:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRThJ-00063z-Jt; Thu, 03 Aug 2023 04:28:41 -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 1qRThI-00063l-Km for qemu-devel@nongnu.org; Thu, 03 Aug 2023 04:28: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 1qRThH-0007rN-2G for qemu-devel@nongnu.org; Thu, 03 Aug 2023 04:28:40 -0400 Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-590-FO3bK_nCO7GklkK4p_gtLw-1; Thu, 03 Aug 2023 04:28:37 -0400 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-52256d84ab1so475483a12.3 for ; Thu, 03 Aug 2023 01:28:37 -0700 (PDT) Received: from step1.home (host-82-57-51-214.retail.telecomitalia.it. [82.57.51.214]) by smtp.gmail.com with ESMTPSA id v26-20020aa7d65a000000b0051e0be09297sm9774601edr.53.2023.08.03.01.28.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 01:28:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691051318; 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=AQj+RyBDUao2ZglCFKibOMg+XHj0z4ipB9ZybK94U/U=; b=CrWGVkTmiVtVUm0iIDjP4bOGsy7Wc+KxHQPwDieYzBM3v3c5J49pvF0/TUgv01v4TZlD2G SOfDVoVYFYL/HON9BWTVEBHKcm2wtNax9YEWxjE3H23E174uE62c/ZrrMqwcT/8FBxmoas HxK4AAD7vE8DWUsjS0Rwy9Y7axkgLM4= X-MC-Unique: FO3bK_nCO7GklkK4p_gtLw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691051316; x=1691656116; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AQj+RyBDUao2ZglCFKibOMg+XHj0z4ipB9ZybK94U/U=; b=iM+GFhPYqiQmN/5WJ6165jRM6yFVbIDI+d4yuECCuyOCutg6ZCIFTK1GpV3KQCSaNm 2nOZ6VTbCYix/xZauuvhF0Jts1vWLfl2nicPffOmGzfNu8WauDxB9eJFHlcvH8zeUp9y nsSsI3Xfp5UoeChM2qgNPlA0sA37fkCjX3qU1J9b5fOwI8GpENTMPnZFxez9gCD2dTp9 1gGBFLRbKS4W8zwaCpqSf9IetewQDwgj0I6B3iHDbvtkn9zPRqGLq2tvdsyvAIjTp+Tk 59LFrCaNW4TKeY4sAVnkA/glfByoaNN/RTi2KxxQTRZkbPedfP1vcRJDIkIZxMaZfwNN Jo7Q== X-Gm-Message-State: ABy/qLYPJsZhppna/Ydzokj5XPWOHnA2YdsWKZk12i1epa3dVSz8nRBE eLlpvU2LwDJjWIxyj9Q4ibje/afI7Br8mhJ1K2E1b98babgn7sfsb1xthtiguvYDbS1WxzMVxIe +23uVZ7GT3CCtl7YfcuaWzFQaBjX6KzJPMPJ25/vWloqhMQTjrUfPcJMJeOdITnoQnv/KMqiiGi U= X-Received: by 2002:a05:6402:1646:b0:522:3149:1596 with SMTP id s6-20020a056402164600b0052231491596mr6962671edx.13.1691051316145; Thu, 03 Aug 2023 01:28:36 -0700 (PDT) X-Google-Smtp-Source: APBJJlEWh3qtl3XHmIwpWDD9YOjicU/DDblWuL0UCNpZO9R2yZXCjgLJvwIDXirVUSfNVEdNT7gV+w== X-Received: by 2002:a05:6402:1646:b0:522:3149:1596 with SMTP id s6-20020a056402164600b0052231491596mr6962659edx.13.1691051315962; Thu, 03 Aug 2023 01:28:35 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Hanna Reitz , Stefan Hajnoczi , qemu-block@nongnu.org, Kevin Wolf , Stefano Garzarella Subject: [PATCH v2 2/2] block/blkio: add more comments on the fd passing handling Date: Thu, 3 Aug 2023 10:28:25 +0200 Message-ID: <20230803082825.25293-3-sgarzare@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230803082825.25293-1-sgarzare@redhat.com> References: <20230803082825.25293-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=sgarzare@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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1691051390707100003 Content-Type: text/plain; charset="utf-8" As Hanna pointed out, it is not clear in the code why qemu_open() can fail, and why blkio_set_int("fd") is not enough to discover the `fd` property support. Let's fix them by adding more details in the code comments. Suggested-by: Hanna Czenczek Reviewed-by: Hanna Czenczek Signed-off-by: Stefano Garzarella --- block/blkio.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/block/blkio.c b/block/blkio.c index baba2f0b67..1dd495617c 100644 --- a/block/blkio.c +++ b/block/blkio.c @@ -713,6 +713,12 @@ static int blkio_virtio_blk_connect(BlockDriverState *= bs, QDict *options, */ fd =3D qemu_open(path, O_RDWR, NULL); if (fd < 0) { + /* + * qemu_open() can fail if the user specifies a path that is n= ot + * a file or device, for example in the case of Unix Domain So= cket + * for the virtio-blk-vhost-user driver. In such cases let's h= ave + * libblkio open the path directly. + */ fd_supported =3D false; } else { ret =3D blkio_set_int(s->blkio, "fd", fd); @@ -741,9 +747,12 @@ static int blkio_virtio_blk_connect(BlockDriverState *= bs, QDict *options, } =20 /* - * If the libblkio driver doesn't support the `fd` property, blkio_con= nect() - * will fail with -EINVAL. So let's try calling blkio_connect() again = by - * directly setting `path`. + * Before https://gitlab.com/libblkio/libblkio/-/merge_requests/208 + * (libblkio <=3D v1.3.0), setting the `fd` property is not enough to = check + * whether the driver supports the `fd` property or not. In that case, + * blkio_connect() will fail with -EINVAL. + * So let's try calling blkio_connect() again by directly setting `pat= h` + * to cover this scenario. */ if (fd_supported && ret =3D=3D -EINVAL) { /* --=20 2.41.0