From nobody Mon Feb 9 02:12:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1582517468; cv=none; d=zohomail.com; s=zohoarc; b=NdZEBdVq3D/Z2/2cQMApkgvh51xfS5rI4uWAyeP/j6W3xfmUSstaqB7u5zgKh6MirnAg6gqgz+xrGamik9q5dqhCcdmpWaeuI3v320Xk1ZC7KnAkoQLxBzwTcEKoqGS6cBrfBZwkav7YCV1iDEzBTrjWDaBQEcn50ei5bsm4dQQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582517468; h=Content-Type:Content-Transfer-Encoding:Cc: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=0KxKExLV8XoSIvsHrNRPkyPn5SO9ysibkBHD9fKcg04=; b=WCrQFDAzSF0owmkk6yS+pnVOgJPy9X/7BxFgIZn+Bx4BvyZuRomdga4500++O/iXk+YdAW19OSaL5KX8wWRZpv6Vu0/HKCYROkWYLJtVOjD4NRQ4e/PgY2RySCknZ0p7tcn4pNRBx4DC+JceXaz/SXFBHkOr9vTYDEk94cxNRno= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1582517468602826.9678615218585; Sun, 23 Feb 2020 20:11:08 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-372-kAAKaRu7M6ayb3YEjWiABg-1; Sun, 23 Feb 2020 23:11:05 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 11641DB75; Mon, 24 Feb 2020 04:11:00 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D358760BF7; Mon, 24 Feb 2020 04:10:59 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 8C084860EA; Mon, 24 Feb 2020 04:10:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 01O4AwKS015646 for ; Sun, 23 Feb 2020 23:10:58 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0F8FAAF988; Mon, 24 Feb 2020 04:10:58 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0AE88AF9A5 for ; Mon, 24 Feb 2020 04:10:55 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BFDAC8007A4 for ; Mon, 24 Feb 2020 04:10:55 +0000 (UTC) Received: from mail-qt1-f193.google.com (mail-qt1-f193.google.com [209.85.160.193]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-465-05RRAZxwNwqwACP7xxpIUQ-1; Sun, 23 Feb 2020 23:10:53 -0500 Received: by mail-qt1-f193.google.com with SMTP id i14so5699834qtv.13 for ; Sun, 23 Feb 2020 20:10:53 -0800 (PST) Received: from localhost.localdomain ([191.254.236.241]) by smtp.gmail.com with ESMTPSA id p126sm5355658qkd.108.2020.02.23.20.10.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Feb 2020 20:10:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582517467; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=0KxKExLV8XoSIvsHrNRPkyPn5SO9ysibkBHD9fKcg04=; b=Tztl1dzh+Vn5t5HuzjpL7Dzr2t+BTrbFi4wGEEtEB4pmP7T/xG7TRwQEeo/RthewTJUG+/ fW9yu+Wu6ydqexMvZAethO1++b4L7OvmfI+y25+KRNvViRuJJU3DKBNKNRoi7k/gQnPYxh DuKWGWhek7WYbuVtpucl16wpUdIlCDk= X-MC-Unique: kAAKaRu7M6ayb3YEjWiABg-1 X-MC-Unique: 05RRAZxwNwqwACP7xxpIUQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rXptADVXU0Q8zjtlr7rTjCE8M4ADdrHTmteju02X3JI=; b=f3XpQowXQqHBm4jdB7SWHxxyT1GHJlLmpZgbMF+qbB55tt0F+AmoyCkbnwaFGEKerj zv31zqDzD//hIYP3PiHqhJEAKa+zt/uiAgD1kjyYR8vKKye4fXIoUVBPFAGtLOKGHbHz MwpG4tqd+9ovFwYJlYZ0cli7VmfEgNpabGoP56VATOK4k8GQdX1W3uHW8ZBvZr9+FwVZ JwfnoN8/d+c/+eFGxQfRD/2uuonl+vEpT4QNjDZCpVxYg6LPEVCFWsaMATW/I0dZT4um qRcRcSW9oaYusnKpVR/RXCi21afnvjCV5SDBXUbHcK6hTGif7u3AmTCCHVWx08EPwpJr PRCg== X-Gm-Message-State: APjAAAUSfZB9MoNie6+C+1Dl+eY1PvggmfoL2ulPosy3xYzQOsByKaV1 vF7RmodhlWA2DZIdYYz7F0FwN3UT X-Google-Smtp-Source: APXvYqyU3bUKiG19GPwu/MldBUWwMFBNvlqyPJzDd/6iFiSNPG1QJh6vGrEvg4m273vXlq5DvdwP+A== X-Received: by 2002:aed:36a5:: with SMTP id f34mr44341951qtb.57.1582517452400; Sun, 23 Feb 2020 20:10:52 -0800 (PST) From: Julio Faracco To: libvir-list@redhat.com Subject: [PATCH v3 5/5] lxc: Count max VCPUs based on cpuset.cpus in native config. Date: Mon, 24 Feb 2020 01:09:46 -0300 Message-Id: <20200224040942.17695-6-jcfaracco@gmail.com> In-Reply-To: <20200224040942.17695-1-jcfaracco@gmail.com> References: <20200224040942.17695-1-jcfaracco@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 01O4AwKS015646 X-loop: libvir-list@redhat.com Cc: danielhb413@gmail.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Native config files sometimes can setup cpuset.cpus to pin some CPUs. Before this, LXC was using a fixed number of 1 VCPU. After this commit, XML definition will generate a dynamic number of VCPUs based on that cgroup attribute. Signed-off-by: Julio Faracco --- src/lxc/lxc_container.c | 23 ++++++++++++++++++ src/lxc/lxc_container.h | 2 ++ src/lxc/lxc_native.c | 24 +++++++++++++++++-- .../lxcconf2xml-cpusettune.xml | 2 +- 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index 88e27f3060..c5788e5c32 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -2487,3 +2487,26 @@ int lxcContainerChown(virDomainDefPtr def, const cha= r *path) =20 return 0; } + + +int lxcContainerGetMaxCpusInCpuset(const char *cpuset) +{ + const char *c =3D cpuset; + int max_cpu =3D 0; + + while (c) { + int a, b, ret; + + ret =3D sscanf(c, "%d-%d", &a, &b); + if (ret =3D=3D 1) + max_cpu++; + else if (ret =3D=3D 2) + max_cpu +=3D a > b ? a - b + 1 : b - a + 1; + + if (!(c =3D strchr(c+1, ','))) + break; + c++; + } + + return max_cpu; +} diff --git a/src/lxc/lxc_container.h b/src/lxc/lxc_container.h index 94a6c5309c..6f112e0667 100644 --- a/src/lxc/lxc_container.h +++ b/src/lxc/lxc_container.h @@ -63,3 +63,5 @@ virArch lxcContainerGetAlt32bitArch(virArch arch); int lxcContainerChown(virDomainDefPtr def, const char *path); =20 bool lxcIsBasicMountLocation(const char *path); + +int lxcContainerGetMaxCpusInCpuset(const char *cpuset); diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index 02d2bf33e4..409bf00bd2 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -993,6 +993,24 @@ lxcSetCpusetTune(virDomainDefPtr def, virConfPtr prope= rties) return 0; } =20 + +static int +lxcGetVCpuMax(virConfPtr properties) +{ + g_autofree char *value =3D NULL; + int vcpumax =3D 1; + + if (virConfGetValueString(properties, "lxc.cgroup.cpuset.cpus", + &value) > 0) { + vcpumax =3D lxcContainerGetMaxCpusInCpuset(value); + if (vcpumax > 0) + return vcpumax; + } + + return vcpumax; +} + + static int lxcBlkioDeviceWalkCallback(const char *name, virConfValuePtr value, void *= data) { @@ -1132,6 +1150,7 @@ lxcParseConfigString(const char *config, virDomainDefPtr vmdef =3D NULL; g_autoptr(virConf) properties =3D NULL; g_autofree char *value =3D NULL; + int vcpumax; =20 if (!(properties =3D virConfReadString(config, VIR_CONF_FLAG_LXC_FORMA= T))) return NULL; @@ -1155,10 +1174,11 @@ lxcParseConfigString(const char *config, =20 /* Value not handled by the LXC driver, setting to * minimum required to make XML parsing pass */ - if (virDomainDefSetVcpusMax(vmdef, 1, xmlopt) < 0) + vcpumax =3D lxcGetVCpuMax(properties); + if (virDomainDefSetVcpusMax(vmdef, vcpumax, xmlopt) < 0) goto error; =20 - if (virDomainDefSetVcpus(vmdef, 1) < 0) + if (virDomainDefSetVcpus(vmdef, vcpumax) < 0) goto error; =20 vmdef->nfss =3D 0; diff --git a/tests/lxcconf2xmldata/lxcconf2xml-cpusettune.xml b/tests/lxcco= nf2xmldata/lxcconf2xml-cpusettune.xml index 6df089d00f..a1fec12d9b 100644 --- a/tests/lxcconf2xmldata/lxcconf2xml-cpusettune.xml +++ b/tests/lxcconf2xmldata/lxcconf2xml-cpusettune.xml @@ -3,7 +3,7 @@ c7a5fdbd-edaf-9455-926a-d65c16db1809 65536 65536 - 1 + 5 --=20 2.20.1