From patchwork Tue May 30 07:19:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13259271 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 8E403C7EE2E for ; Tue, 30 May 2023 07:20:52 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q3teU-0001CU-K3; Tue, 30 May 2023 03:20: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 1q3teE-0001At-Cz for qemu-devel@nongnu.org; Tue, 30 May 2023 03:20:02 -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 1q3te6-0004rf-Pz for qemu-devel@nongnu.org; Tue, 30 May 2023 03:19:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685431193; 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=KJ2nc6r7b3NmHZi94eqye0nGmDPE0Z7Z+GA/fs4fmiM=; b=XPFZNnPTOierPJXgk3s1PpVcMLukEFBduwXnWTbnvkHpe/xw/9ayTxMUoH0qL1w3V3Byyc 56sC+LKNRvDeIAMxVNLe7pawveEixLm6gbHwpHEyG9yefn0li4AResl61zBoYC124Lczqy y1QgTFDM0sp/I5y+LrS7DVhkilKE7ec= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-224-rd6hoUgvPo-dOXmbWBRpxw-1; Tue, 30 May 2023 03:19:52 -0400 X-MC-Unique: rd6hoUgvPo-dOXmbWBRpxw-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-626070979faso25038446d6.1 for ; Tue, 30 May 2023 00:19:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685431191; x=1688023191; 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=KJ2nc6r7b3NmHZi94eqye0nGmDPE0Z7Z+GA/fs4fmiM=; b=Lqu2SMYiXyrWOKxKvhnm79IAyoKq0slY9j9e330RmsS/hlznKJt1U5/d9Wi/5UyS31 rs5IDz6hZZ1CzZZhOKKweY+e3nm6k9yeyfHW4KwKkj+IQbMupj+50JFohwVwnVyoMCG4 a2XmKmmt4DG4ARK8W2eYKwcErqitDNs1AsHHIqVma0Jk8V3CFSS4hYslzdOI0ff1zENN 5KHBpcvX+NZlHpCTowJuokisojf4HwntmsPFvbcNShNl+6GnV55ZvsYft/jI2Yv7Ce1q WI+aa/+Z0S6AYQUI4R4GUVyKUeojN52LdQrKGTAHw6qFLw5nSXtft4/yHmbmv5XXnp7t yiTQ== X-Gm-Message-State: AC+VfDxCgI25EQDX93RKagIjrulwky4b7XNaAYtVDEO8r9HgRu4kb0MS DORFIneTL3I9mSM0X/U5td9sYA0EnXf5w02xhTmLSgCXL6vroaCA1cblLSCK9rAbS7qNJ10FwII e8wEhchimgzdPxcKGQfqzLs7nVEFatnuzVceSHGlKlS+9435TXDuMXw7JLKX+0GgZPzTqZHatzy Y= X-Received: by 2002:a05:6214:2629:b0:626:1741:f3f3 with SMTP id gv9-20020a056214262900b006261741f3f3mr9723806qvb.28.1685431191685; Tue, 30 May 2023 00:19:51 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ53mUrhw0AUElIQdd8XtPJbRCWf1nTQmLwB6EgrqyIA9uA1FUVpep7Vf/DDyTvs+W7XgFJUWQ== X-Received: by 2002:a05:6214:2629:b0:626:1741:f3f3 with SMTP id gv9-20020a056214262900b006261741f3f3mr9723786qvb.28.1685431191350; Tue, 30 May 2023 00:19:51 -0700 (PDT) Received: from step1.redhat.com (host-87-12-25-16.business.telecomitalia.it. [87.12.25.16]) by smtp.gmail.com with ESMTPSA id v1-20020a05622a144100b003e302c1f498sm4477508qtx.37.2023.05.30.00.19.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 00:19:50 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Kevin Wolf , Thomas Huth , Markus Armbruster , Paolo Bonzini , Stefan Hajnoczi , Eric Blake , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Jonathon Jongsma , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Hanna Reitz , qemu-block@nongnu.org, Stefano Garzarella Subject: [PATCH v5 1/2] block/blkio: use qemu_open() to support fd passing for virtio-blk Date: Tue, 30 May 2023 09:19:40 +0200 Message-Id: <20230530071941.8954-2-sgarzare@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230530071941.8954-1-sgarzare@redhat.com> References: <20230530071941.8954-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-type: text/plain 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: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.16, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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 Some virtio-blk drivers (e.g. virtio-blk-vhost-vdpa) supports the fd passing. Let's expose this to the user, so the management layer can pass the file descriptor of an already opened path. If the libblkio virtio-blk driver supports fd passing, let's always use qemu_open() to open the `path`, so we can handle fd passing from the management layer through the "/dev/fdset/N" special path. Reviewed-by: Stefan Hajnoczi Signed-off-by: Stefano Garzarella --- Notes: v4: - modified commit description v3: - use qemu_open() on `path` to simplify libvirt code [Jonathon] block/blkio.c | 53 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/block/blkio.c b/block/blkio.c index 0cdc99a729..6a6f20f923 100644 --- a/block/blkio.c +++ b/block/blkio.c @@ -672,25 +672,60 @@ static int blkio_virtio_blk_common_open(BlockDriverState *bs, { const char *path = qdict_get_try_str(options, "path"); BDRVBlkioState *s = bs->opaque; - int ret; + bool fd_supported = false; + int fd, ret; if (!path) { error_setg(errp, "missing 'path' option"); return -EINVAL; } - ret = blkio_set_str(s->blkio, "path", path); - qdict_del(options, "path"); - if (ret < 0) { - error_setg_errno(errp, -ret, "failed to set path: %s", - blkio_get_error_msg()); - return ret; - } - if (!(flags & BDRV_O_NOCACHE)) { error_setg(errp, "cache.direct=off is not supported"); return -EINVAL; } + + if (blkio_get_int(s->blkio, "fd", &fd) == 0) { + fd_supported = true; + } + + /* + * If the libblkio driver supports fd passing, let's always use qemu_open() + * to open the `path`, so we can handle fd passing from the management + * 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); + if (fd < 0) { + return -EINVAL; + } + + 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 { + 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; + } + } + + qdict_del(options, "path"); + return 0; } From patchwork Tue May 30 07:19:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13259272 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 8AC07C7EE23 for ; Tue, 30 May 2023 07:20:52 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q3tek-0001OL-PG; Tue, 30 May 2023 03:20:35 -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 1q3teI-0001Bd-6t for qemu-devel@nongnu.org; Tue, 30 May 2023 03:20:07 -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 1q3teE-0004yo-7E for qemu-devel@nongnu.org; Tue, 30 May 2023 03:20:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685431201; 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=iD7g8SG5NfDEouyxjItNuwDXx/YbyC0EvPCvFUKOIOA=; b=LQ2fT4nJ256RQAzX5tvUvOg9znAJgNFb3PgfQRMuEK+CwvKlRAiUPDoihGWZDw2v9DxmEp TMGeBfH3lfvyG4aNcoIkJ26NHfZuczr731YWIbMnmxiaNSq/arUpeVgstP7CwwBqAd1mcc MNsI9yvkIbaWycSxpvBcjz0TDMUT+Kk= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-199-CZl5e2QCO8C8qDwA7k7fmQ-1; Tue, 30 May 2023 03:19:59 -0400 X-MC-Unique: CZl5e2QCO8C8qDwA7k7fmQ-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-75b06a31daaso650369885a.2 for ; Tue, 30 May 2023 00:19:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685431198; x=1688023198; 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=iD7g8SG5NfDEouyxjItNuwDXx/YbyC0EvPCvFUKOIOA=; b=fiydumqzQxQ93LiRGliamJfv/Lu0C4Puk19iDZsqD6Eszzyq8PjcMvw4jYoPbc1R8h N5+Npzo9sdmwBHkUT3517D2n2LgNxUWzoJnFk8ikl5Epk7DL1fYrFtUHarMnclvk3iXY Km2MY10ajHQjLw0kjhwsCLD+beM2d6ARKcbgDDqBHfDwAM9LHYtWbEYQ4OFlW9Ccxdc+ fzOGVOS3yX5R8EOdVpAtGW7/2abppx8wmFcGx/J9f+AbNIwGm49sq+tkxqKnplG/lgM/ xJB0EO9dxNwlWXfwztO6DfQxAoj+lcmyFm/cgP27dziLW9fyxF9xsBtIOKSAflDL1T16 dBXw== X-Gm-Message-State: AC+VfDzL1LulBqJDzgHe8WmMZ+ItAem2MTFvq18Qhh2AlqTYAt+GuEgI a6KewKh/ajtx+8kr88IpqhVmJSDBXzZ5Dk0oo7GljR4PElsxt+6Iqq5sv3MGbgJklDHlHO+gu9x xtIfGEFYDpGSBxNPBpGIBmLXl3mRasPjFWwQMuk/CrbpbL8lOfd+4cE/NDZBFFoYL41rbLoORbH o= X-Received: by 2002:a05:620a:6005:b0:75b:23a0:deb2 with SMTP id dw5-20020a05620a600500b0075b23a0deb2mr1129360qkb.48.1685431198330; Tue, 30 May 2023 00:19:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7LhTTgwV/SODu3ky/bP06IxjQX0qpdlUSFaTUtFeduQ6hvA9Ty6NCIb5ajIPyin4nzh4M/FA== X-Received: by 2002:a05:620a:6005:b0:75b:23a0:deb2 with SMTP id dw5-20020a05620a600500b0075b23a0deb2mr1129336qkb.48.1685431198075; Tue, 30 May 2023 00:19:58 -0700 (PDT) Received: from step1.redhat.com (host-87-12-25-16.business.telecomitalia.it. [87.12.25.16]) by smtp.gmail.com with ESMTPSA id p24-20020a05620a133800b0075b01970aaasm3886705qkj.32.2023.05.30.00.19.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 00:19:57 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Kevin Wolf , Thomas Huth , Markus Armbruster , Paolo Bonzini , Stefan Hajnoczi , Eric Blake , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Jonathon Jongsma , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Hanna Reitz , qemu-block@nongnu.org, Stefano Garzarella Subject: [PATCH v5 2/2] qapi: add '@fdset' feature for BlockdevOptionsVirtioBlkVhostVdpa Date: Tue, 30 May 2023 09:19:41 +0200 Message-Id: <20230530071941.8954-3-sgarzare@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230530071941.8954-1-sgarzare@redhat.com> References: <20230530071941.8954-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-type: text/plain 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: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.16, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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 The virtio-blk-vhost-vdpa driver in libblkio 1.3.0 supports the fd passing through the new 'fd' property. Since now we are using qemu_open() on '@path' if the virtio-blk driver supports the fd passing, let's announce it. In this way, the management layer can pass the file descriptor of an already opened vhost-vdpa character device. This is useful especially when the device can only be accessed with certain privileges. Add the '@fdset' feature only when the virtio-blk-vhost-vdpa driver in libblkio supports it. Suggested-by: Markus Armbruster Reviewed-by: Stefan Hajnoczi Signed-off-by: Stefano Garzarella --- Notes: v5: - moved `features` to the object level to simplify libvirt code [Jonathon] - wrapped a line too long in the documentation [Markus] v4: - added this patch to allow libvirt to discover we support fdset [Markus] meson.build | 4 ++++ qapi/block-core.json | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/meson.build b/meson.build index 2d48aa1e2e..4a9fa4c435 100644 --- a/meson.build +++ b/meson.build @@ -2106,6 +2106,10 @@ config_host_data.set('CONFIG_LZO', lzo.found()) config_host_data.set('CONFIG_MPATH', mpathpersist.found()) config_host_data.set('CONFIG_MPATH_NEW_API', mpathpersist_new_api) config_host_data.set('CONFIG_BLKIO', blkio.found()) +if blkio.found() + config_host_data.set('CONFIG_BLKIO_VHOST_VDPA_FD', + blkio.version().version_compare('>=1.3.0')) +endif config_host_data.set('CONFIG_CURL', curl.found()) config_host_data.set('CONFIG_CURSES', curses.found()) config_host_data.set('CONFIG_GBM', gbm.found()) diff --git a/qapi/block-core.json b/qapi/block-core.json index 98d9116dae..4bf89171c6 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -3955,10 +3955,16 @@ # # @path: path to the vhost-vdpa character device. # +# Features: +# @fdset: Member @path supports the special "/dev/fdset/N" path +# (since 8.1) +# # Since: 7.2 ## { 'struct': 'BlockdevOptionsVirtioBlkVhostVdpa', 'data': { 'path': 'str' }, + 'features': [ { 'name' :'fdset', + 'if': 'CONFIG_BLKIO_VHOST_VDPA_FD' } ], 'if': 'CONFIG_BLKIO' } ##