From nobody Mon Feb 9 09:28:56 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1673266749; cv=none; d=zohomail.com; s=zohoarc; b=mMll5oGKrnLzZ/QClkwAE94TWrJzxE6lJwjJ+UetH0ko7IUd3GXgrD6YhbtfjeyhrgKJKMuyoAdjqelvv8qhSb9k8t/rX1j6cfSxgzem6wH4LYdnbkeDvMi9MKR5LreDMEe64/ZezgsRXMFRW+AzdABzVTqZjr0VeZuAVEGIgPQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673266749; h=Content-Type:Content-Transfer-Encoding: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=6wsWUSaOWDSeSP9MkydOJPt+4/51b0mS1A6ZIVCDa7s=; b=m0hwbZbvmEOvpxRWdgV7PuwJGWZf7bLY4pCLgJF352frW7aEH5C2Ghu6U/AdR1lzywQpEj8EFLv5aG28QzEG1CngxDVA0RR899sLlfIC6Uu95yTsPPhxtKjk9T12STQiuX7on8mvU/ATG38B/EM1YXhUtOPk1WbhhzYmdprSWCk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 167326674900057.640848860462256; Mon, 9 Jan 2023 04:19:09 -0800 (PST) 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-369-Jr7TGzAXMte0BQl2Mz-Ziw-1; Mon, 09 Jan 2023 07:19:03 -0500 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 0E903811E6E; Mon, 9 Jan 2023 12:19:01 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED4F940C2064; Mon, 9 Jan 2023 12:19:00 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id D6AA41947B8C; Mon, 9 Jan 2023 12:19:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id D29A01946586 for ; Mon, 9 Jan 2023 12:18:59 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id B535440C115E; Mon, 9 Jan 2023 12:18:59 +0000 (UTC) Received: from speedmetal.redhat.com (ovpn-208-20.brq.redhat.com [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2CDC240C1141 for ; Mon, 9 Jan 2023 12:18:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673266747; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=6wsWUSaOWDSeSP9MkydOJPt+4/51b0mS1A6ZIVCDa7s=; b=RTJbK3Q/cIS12RxccEz5dxas9E1AMLiOOkK3jIFCJShH6Eriv6Hfecx2alxe/69f2nFXWZ 7bya3NUkowRdYzJY5tblIzYFBPwZqdP4bjsQ6uHLvmSbTDnELdCa7PesVow8qSiewz9xzM /UqAh3PbRNpjwfAzkuI9YTCuaO7KZN0= X-MC-Unique: Jr7TGzAXMte0BQl2Mz-Ziw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH v2 02/17] virsh: Introduce 'dom-fd-associate' for invoking virDomainFDAssociate() Date: Mon, 9 Jan 2023 13:18:40 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1673266751059100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: Pavel Hrdina --- docs/manpages/virsh.rst | 19 +++++++++++ tools/virsh-domain.c | 76 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index c85bc8151d..88b7fa1da8 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -5225,6 +5225,25 @@ If *--print-xml* is specified, the XML that would be= used to change media is printed instead of changing the media. +dom-fd-associate +---------------- + +**Syntax:** + +:: + + dom-fd-associate domain --name FDGROUPNAME --pass-fds M,N,.... + [--seclabel-writable] [--seclabel-restore] + +Associate one or more fds described via *--pass-fds* argument to *domain* = as +*--name*. The lifetime of the passed fd group is the same as the connectio= n, thus +exitting virsh un-registers them afterwards. + +By default security labels are applied if needed but they are not restored= after +use to avoid keeping them open unnecessarily. Best-effort security label r= estore +may be requested by using the *--seclabel-restore* flag. + + NODEDEV COMMANDS =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 2d162cf8c0..3751b69e03 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -9816,6 +9816,76 @@ cmdDomSetLaunchSecState(vshControl * ctl, const vshC= md * cmd) return ret; } + +/* + * "dom-fd-associate" command + */ +static const vshCmdInfo info_dom_fd_associate[] =3D { + {.name =3D "help", + .data =3D N_("associate a FD with a domain") + }, + {.name =3D "desc", + .data =3D N_("associate a FD with a domain") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_dom_fd_associate[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "name", + .type =3D VSH_OT_DATA, + .flags =3D VSH_OFLAG_REQ, + .completer =3D virshCompleteEmpty, + .help =3D N_("name of the FD group") + }, + {.name =3D "pass-fds", + .type =3D VSH_OT_DATA, + .flags =3D VSH_OFLAG_REQ, + .completer =3D virshCompleteEmpty, + .help =3D N_("file descriptors N,M,... to associate") + }, + {.name =3D "seclabel-writable", + .type =3D VSH_OT_BOOL, + .help =3D N_("use seclabels allowing writes") + }, + {.name =3D "seclabel-restore", + .type =3D VSH_OT_BOOL, + .help =3D N_("try to restore security label after use if possible") + }, + {.name =3D NULL} +}; + +static bool +cmdDomFdAssociate(vshControl *ctl, const vshCmd *cmd) +{ + g_autoptr(virshDomain) dom =3D NULL; + const char *name =3D NULL; + unsigned int flags =3D 0; + g_autofree int *fds =3D NULL; + size_t nfds =3D 0; + + if (vshCommandOptBool(cmd, "seclabel-writable")) + flags |=3D VIR_DOMAIN_FD_ASSOCIATE_SECLABEL_WRITABLE; + + if (vshCommandOptBool(cmd, "seclabel-restore")) + flags |=3D VIR_DOMAIN_FD_ASSOCIATE_SECLABEL_RESTORE; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return false; + + if (vshCommandOptStringReq(ctl, cmd, "name", &name) < 0) + return false; + + if (virshFetchPassFdsList(ctl, cmd, &nfds, &fds) < 0) + return false; + + if (virDomainFDAssociate(dom, name, nfds, fds, flags) < 0) + return false; + + return true; +} + + /* * "qemu-monitor-command" command */ @@ -14417,5 +14487,11 @@ const vshCmdDef domManagementCmds[] =3D { .info =3D info_domdirtyrate_calc, .flags =3D 0 }, + {.name =3D "dom-fd-associate", + .handler =3D cmdDomFdAssociate, + .opts =3D opts_dom_fd_associate, + .info =3D info_dom_fd_associate, + .flags =3D 0 + }, {.name =3D NULL} }; --=20 2.38.1