From nobody Sat Feb 7 11:25:21 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1682409894; cv=none; d=zohomail.com; s=zohoarc; b=KirH5fJUl7Ab5ZWmPOGPsjG2PhZzGXSSLp9/JiuX+gx/Al3vdEME6GxmCa+VLBWpTPETXZzOzPo4puO+p3TjRB7eadIsRTbnWPcp5KDCaJHoSbtneB/9ev6kyZLV0cADzS2Q3Y1Pbe6tRXckxkjsexcHKKLs6ClH4cfXfBRapHc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682409894; 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=c7JH15a4vfi+AH2SZjtgzIcDJ7IT45oMf5pPCpICmbE=; b=aeo3kUGP1PXLCLIeEwcw6gUVvO5LBJqFziNaPmaCdAhT5go7mNJjze1hf2T5Ke7dR/VihsrgktkGaxIv+Nvf9NbSeEjQFLHJQYY1d37ULEAvegq8rsgXpy1j/AtvoNNf9JYC4X2brSEgnJQEIehx7K6TvU0vf8dlkHNwyUUqWjg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 16824098939078.784856515920978; Tue, 25 Apr 2023 01:04:53 -0700 (PDT) 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-644-uEU0oGGEM4KDCRiTGB7ATQ-1; Tue, 25 Apr 2023 04:04:48 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7E33E101B451; Tue, 25 Apr 2023 08:04:46 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id DCF144C82F; Tue, 25 Apr 2023 08:04:45 +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 8059919465A2; Tue, 25 Apr 2023 08:04:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 19808194658D for ; Tue, 25 Apr 2023 08:04:44 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id EF7BF2027046; Tue, 25 Apr 2023 08:04:43 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 96BEE2027043 for ; Tue, 25 Apr 2023 08:04:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682409893; 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=c7JH15a4vfi+AH2SZjtgzIcDJ7IT45oMf5pPCpICmbE=; b=Ff4sFb/kjERZ+sloH92curNpciLkyVTCMMEYKga5HzaK1Z4+4/BVAElx1ZzBNBkn564nSZ Jqrsuo0nGpDHXHyLzs1ULAbGfOe6JGl8IzcW6cq55v77t60BUr1zePcJE122C2eVqk15La JXPCf31xP9lKY8chFmJ79WsxxFLKr/c= X-MC-Unique: uEU0oGGEM4KDCRiTGB7ATQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/2] lxc: Make lxcCreateHostdevDef() less versatile Date: Tue, 25 Apr 2023 10:04:40 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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.5 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: 1682409894541100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Usually, we want a function to be as reusable as possible. But in this specific case, when it's used just once we don't need that. The lxcCreateHostdevDef() function is meant to create a hostdev. The first argument selects the hostdev mode (caps/subsys) and the second argument selects the type of hostdev (NET/STORAGE/MISC). But because of how the function is written, it's impossible to create a subsys hostdev as the function sets hostdev->source.caps.type, regardless of mode. So the @mode argument can be dropped. Then, the function is called from one place and one place only. And in there, VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET is passed for @type so we can drop that argument too. Signed-off-by: Michal Privoznik --- src/lxc/lxc_native.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index d311f5a5ad..0ae208ef11 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -375,18 +375,16 @@ lxcCreateNetDef(const char *type, } =20 static virDomainHostdevDef * -lxcCreateHostdevDef(int mode, int type, const char *data) +lxcCreateHostdevDef(const char *data) { virDomainHostdevDef *hostdev =3D virDomainHostdevDefNew(); =20 if (!hostdev) return NULL; =20 - hostdev->mode =3D mode; - hostdev->source.caps.type =3D type; - - if (type =3D=3D VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET) - hostdev->source.caps.u.net.ifname =3D g_strdup(data); + hostdev->mode =3D VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES; + hostdev->source.caps.type =3D VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET; + hostdev->source.caps.u.net.ifname =3D g_strdup(data); =20 return hostdev; } @@ -457,9 +455,7 @@ lxcAddNetworkDefinition(virDomainDef *def, lxcNetworkPa= rseData *data) _("Missing 'link' attribute for NIC")); goto error; } - if (!(hostdev =3D lxcCreateHostdevDef(VIR_DOMAIN_HOSTDEV_MODE_CAPA= BILITIES, - VIR_DOMAIN_HOSTDEV_CAPS_TYPE_N= ET, - data->link))) + if (!(hostdev =3D lxcCreateHostdevDef(data->link))) goto error; =20 /* This still requires the user to manually setup the vlan interfa= ce --=20 2.39.2