From nobody Sat Nov 23 02:15:47 2024 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 Reviewed-by: J=C3=A1n Tomko --- 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 From nobody Sat Nov 23 02:15:47 2024 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=1682409966; cv=none; d=zohomail.com; s=zohoarc; b=bpvaQNg5U/Bk8tNOVbeZuweIiJhlFVswgtoxs8QTAvvYudyZEVtp1e245Jkuqjxtv3wOw9moYSRmnZzSkttjkW0Bk4ipigJ8RMAjqx70RHXXqS7pNPmC8T7sipBQch+7cebacCH/SI3EVppFhBrlgfSl4V0A6NVWbHSfB0Cr9Fs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682409966; 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=Vgyd8G2fXxKMsNVTDNRMuQ9tjVpS92HNRXxdHN3Wvi0=; b=GR7MHfK4AT+4GFfJ6sDxaeSfvrTExs0ppuIkaPLoMg1hzTSyDJCQJCMH6UtV2f9z8JsB1lsRxlamrbmsSL2dFSjmApP9JWw2VFwI7O4O1OG5hUyT6DDiMJDYnd5s6qdk41BGjZAFtmKvv/GMDieFj5NEQ3vnyFc7zrUkOlTmkFU= 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 1682409966961952.2085988300789; Tue, 25 Apr 2023 01:06:06 -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-177-7E54Kv_sNxGG1oc9fqK62A-1; Tue, 25 Apr 2023 04:04:50 -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 45CEE87B2CE; Tue, 25 Apr 2023 08:04:47 +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 23C1D4E3C5; Tue, 25 Apr 2023 08:04:47 +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 C320B1946A4C; 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 9B5A9194658D for ; Tue, 25 Apr 2023 08:04:44 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 8AE012027046; Tue, 25 Apr 2023 08:04:44 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 320E72027043 for ; Tue, 25 Apr 2023 08:04:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682409965; 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=Vgyd8G2fXxKMsNVTDNRMuQ9tjVpS92HNRXxdHN3Wvi0=; b=d0GTJIcBN4vt0AKLVEuFLURxroUvFQMhb2xogAxg5yg/ojoD2LZ0NjAO3DFnnZI+HhLZSC +srYRRxfY/7p9gBBv4pjRm1FMV6QJPTYh6ugjxACcJP0u/EkIPVymqbD/4dV2Ck3BRn5ws dfeEG97f/j6W18bELZnE4AhYsfljzas= X-MC-Unique: 7E54Kv_sNxGG1oc9fqK62A-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/2] lxc: Fix access to hostdev capabilities Date: Tue, 25 Apr 2023 10:04:41 +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: 1682409968264100001 Content-Type: text/plain; charset="utf-8"; x-default="true" In a few places, where a capabilities is processed, a wrong union member is access: def->source.subsys.type instead of def->source.caps.type. Fortunately, both union members have .type as the very first member so no real harm is done. Nevertheless, we should access the correct union member. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/lxc/lxc_controller.c | 2 +- src/lxc/lxc_hostdev.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index 60b961dcb5..86dcd880e8 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -1788,7 +1788,7 @@ virLXCControllerSetupHostdevCaps(virDomainDef *vmDef, virDomainHostdevDef *def, virSecurityManager *securityDriver) { - switch (def->source.subsys.type) { + switch (def->source.caps.type) { case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_STORAGE: return virLXCControllerSetupHostdevCapsStorage(vmDef, def, diff --git a/src/lxc/lxc_hostdev.c b/src/lxc/lxc_hostdev.c index d18d61cb19..8fe02a4276 100644 --- a/src/lxc/lxc_hostdev.c +++ b/src/lxc/lxc_hostdev.c @@ -85,7 +85,7 @@ int virLXCPrepareHostDevices(virLXCDriver *driver, break; =20 case VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES: - switch (dev->source.subsys.type) { + switch (dev->source.caps.type) { case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_STORAGE: case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_MISC: case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET: @@ -93,7 +93,7 @@ int virLXCPrepareHostDevices(virLXCDriver *driver, default: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported hostdev type %1$s"), - virDomainHostdevSubsysTypeToString(dev->sou= rce.subsys.type)); + virDomainHostdevSubsysTypeToString(dev->sou= rce.caps.type)); return -1; } break; --=20 2.39.2