From nobody Wed Jun 24 21:48:11 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) client-ip=38.145.34.151; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1781769566; cv=none; d=zohomail.com; s=zohoarc; b=lVOZfbpYzjjSMIPOIIifvUbmoJUNdiUoQbNjQ2bTsWrTNn0HX5PDgi1UF5sbvGRtVT/wPwRIloN1Ah9X94I2Ts6nAgQCOk5DGdAoAyZnyGVtnrfuVn5hCVEMxUKfBV+v2lMeImfSQK7Wnqs8rzZ0LkX70IFAqrmS419MJ6lzXtU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781769566; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Subject:Subject:To:To:Message-Id:Cc; bh=ahN4vjah76Jk7fQpOTYu2Diyf2mc8N6I+Whyg3MA+LQ=; b=Cq/sx1xaeQN8PQBemV+GpAIhT/8Uih8XorGmifYhGN5GIkltSC5FNgPDRlDFnKy/9dHb49wctHN/n8+lQj/Iw+T2Di4YD65Mr8nBg/mg9aXOXKdqP2rxOB5c3G3tTeASeykP+ab56NMkkD8WU0QptEy1YP8Hztwg8P/gisOefH0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 38.145.34.151 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [38.145.34.151]) by mx.zohomail.com with SMTPS id 1781769566265125.50569609467084; Thu, 18 Jun 2026 00:59:26 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id B129741BA3; Thu, 18 Jun 2026 03:59:24 -0400 (EDT) Received: from [172.19.199.7] (unknown [10.16.107.18]) by lists.libvirt.org (Postfix) with ESMTP id 25B1341D10; Thu, 18 Jun 2026 03:58:34 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 05BF041BA3; Thu, 18 Jun 2026 03:58:24 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 548D641997 for ; Thu, 18 Jun 2026 03:58:23 -0400 (EDT) Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-677-iJvKWArTOG2yok31E8inIw-1; Thu, 18 Jun 2026 03:58:21 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BB7F71956089 for ; Thu, 18 Jun 2026 07:58:20 +0000 (UTC) Received: from moe (unknown [10.43.3.236]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2AC443000235 for ; Thu, 18 Jun 2026 07:58:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,RCVD_IN_SBL_CSS,SPF_HELO_PASS autolearn=no autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1781769502; h=from:from: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; bh=ahN4vjah76Jk7fQpOTYu2Diyf2mc8N6I+Whyg3MA+LQ=; b=dO754vql7XBTnJe2fOIhDqApg3XQv5gKJQuXslbds/5VdV2D6DpEyP9TK205xwKS75YXCl jxp9YDCQk1G46fd15b/A8Xn6lmdNsJDO37tlR9fhIlJ+LswA62PftgUUnh/YqeXdMB6XJY LyK4fZlL2yT64IGoLM4InYMkBOt74wc= X-MC-Unique: iJvKWArTOG2yok31E8inIw-1 X-Mimecast-MFC-AGG-ID: iJvKWArTOG2yok31E8inIw_1781769500 To: devel@lists.libvirt.org Subject: [PATCH] virsh: Make --type argument of detach-interface optional Date: Thu, 18 Jun 2026 09:58:17 +0200 Message-ID: <4252cfb16fadd1540a14a285d48f857c744d51f0.1781769497.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: P8YzLn9YecSZR2kwwQHn0Pd-Fs1nyARSJKvsxyhRc3I_1781769500 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 7TVZLD4XU4RNQNEKPLC7OURV2V26FR5L X-Message-ID-Hash: 7TVZLD4XU4RNQNEKPLC7OURV2V26FR5L X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1781769570749158500 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik The detach-interface virsh command requires domain (obviously) and --type to identify . Optionally, --mac can be provided to chose from multiple interfaces. Well, that renders --type argument redundant. I mean, if there are but unique MACs within domain XML, then interface type is implied. If there are duplicate MACs then --type can help to differentiate, though at that point detach-device seems like a better fit. Long story short, make --type optional. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- docs/manpages/virsh.rst | 2 +- tools/virsh-domain.c | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 39d91d8375..2992495ecb 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -5586,7 +5586,7 @@ detach-interface =20 :: =20 - detach-interface domain type [--mac mac] + detach-interface domain [--type type] [--mac mac] [[[--live] [--config] | [--current]] | [--persistent]] [--print-xml] =20 Detach a network interface from a domain. diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index f9de3b42a9..8a6f868e34 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -12782,7 +12782,6 @@ static const vshCmdOptDef opts_detach_interface[] = =3D { {.name =3D "type", .type =3D VSH_OT_STRING, .positional =3D true, - .required =3D true, .help =3D N_("network interface type") }, {.name =3D "mac", @@ -12816,7 +12815,7 @@ virshDomainDetachInterface(char *doc, g_autoptr(xmlDoc) xml =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; g_autofree char *detach_xml =3D NULL; - g_autofree char *xpath =3D g_strdup_printf("/domain/devices/interface[= @type=3D'%s']", type); + g_autofree char *xpath =3D NULL; g_autofree xmlNodePtr *nodes =3D NULL; ssize_t nnodes; xmlNodePtr matchNode =3D NULL; @@ -12827,8 +12826,16 @@ virshDomainDetachInterface(char *doc, return false; } =20 + if (type) + xpath =3D g_strdup_printf("/domain/devices/interface[@type=3D'%s']= ", type); + else + xpath =3D g_strdup("/domain/devices/interface"); + if ((nnodes =3D virXPathNodeSet(xpath, ctxt, &nodes)) <=3D 0) { - vshError(ctl, _("No interface found whose type is %1$s"), type); + if (type) + vshError(ctl, _("No interface found whose type is %1$s"), type= ); + else + vshError(ctl, "%s", _("Domain has no interfaces")); return false; } =20 --=20 2.53.0