From nobody Sun Feb 8 20:00:01 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=1582554330; cv=none; d=zohomail.com; s=zohoarc; b=iJKJ1HkTKm5moMUNyQYsBgxF9MBJhdy4xdYN2rEqq3Vikzgi6O/vuvubeAi7PyySOb7kIS69L2GexgnBMspo2XdwmomXP1XKWRlTXAImWJ/I69CajfqMahz+vN7M4bLjTAeK7t0QrlfnIx60NTjpOodlHXdmT2Z1kIDJU8dk8rw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582554330; 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=avz49JMCZVSOFc5eEuqBMbJhJ1Arknczpjnuy1lYuwOa02o5VuS/YWG/npE/brQz7N0nEwIkBkR0IPKvPsXMJK+gDJmklIxMgibCnncExz4jB6XsBnFdDOPPFF4JIwnMe9ElKe2diG2zdc/XmvOb80cf+wzZC/uzMSTOvuB3mSA= 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-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1582554330214111.01386364181292; Mon, 24 Feb 2020 06:25:30 -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-64-vRiMgLmHNaKlKw10X0-b9Q-1; Mon, 24 Feb 2020 09:25:26 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 44494DB88; Mon, 24 Feb 2020 14:25:20 +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 0FB0691833; Mon, 24 Feb 2020 14:25:20 +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 AA436860EF; Mon, 24 Feb 2020 14:25:19 +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 01OEPIfL023417 for ; Mon, 24 Feb 2020 09:25:18 -0500 Received: by smtp.corp.redhat.com (Postfix) id EB7749D44; Mon, 24 Feb 2020 14:25:17 +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 E7623DBF39 for ; Mon, 24 Feb 2020 14:25:17 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (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 CF11B8007D4 for ; Mon, 24 Feb 2020 14:25:17 +0000 (UTC) Received: from mail-qv1-f68.google.com (mail-qv1-f68.google.com [209.85.219.68]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-236-xmqByRQpO5SwhRy8nw_vaQ-1; Mon, 24 Feb 2020 09:25:15 -0500 Received: by mail-qv1-f68.google.com with SMTP id q9so4190392qvu.7 for ; Mon, 24 Feb 2020 06:25:12 -0800 (PST) Received: from localhost.localdomain (201-69-8-70.dial-up.telesp.net.br. [201.69.8.70]) by smtp.gmail.com with ESMTPSA id o16sm6092364qtr.28.2020.02.24.06.25.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2020 06:25:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582554329; 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=BdzM7Q5myRnQ9lEtw2M7aeMAn0U4XDD/GRaaBsiQ0B+5JH2p1w8ilTS38WZKhr/fVwPySd +nsPrg0nbgLk1hSkwW9UNPNg+hUuq0FNDVWRsqVtTn6Qs/2SIpdQA/ZBy2/qlR3SCPob5v nSErJ921XK2a5aLG8sxJRrn72iu8Qyg= X-MC-Unique: vRiMgLmHNaKlKw10X0-b9Q-1 X-MC-Unique: xmqByRQpO5SwhRy8nw_vaQ-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=LGZSdIJ2L1MNkRr/i0+ydbBN3nwkNIiR4A4LWoI5Lu9rAU/n2MVjmsJYAQe2XEqsfz hdCq9AOqce1aaPFgYGFTxhP7JJ7J3nREAC8HtVRpBX8ZwTJ4lzOTuF73OKd/f+GIzf6+ 0/vkdrJyE/GyFzsgNMlMzPycMLd5AAWSY45vj3NhS1A9Cqui375r89lne3RkjyqWnJPI u1uKMEzVaMne2cMHOzvdjPzP59SuhnEV5yK3NJ+0eEbvezw5gwReSvjEC/0rsYTpgcmp 70AYVEWtLCJyfnGlzYghkLKanSJutEuODPaAAWZd5B6Z2k43nHvw4RIpN3LiZPSAVQxL Bxxw== X-Gm-Message-State: APjAAAUyaBtRvoxU8If0viBBQJ3u6BKt+/Of+L6N/4HoOqJpN4ggytTg SqaSsaK4Lv4OBsJGd6QYwYcbmBP/ X-Google-Smtp-Source: APXvYqyfs60IuRTMr7NxkNTJFHuMCkZiWgPXptxzUr/1IuEBAdX28wBcGHMLWvNWS/vgMrWdVWnyyA== X-Received: by 2002:a05:6214:524:: with SMTP id x4mr45491336qvw.4.1582554311649; Mon, 24 Feb 2020 06:25:11 -0800 (PST) From: Julio Faracco To: libvir-list@redhat.com Subject: [PATCH v4 5/5] lxc: Count max VCPUs based on cpuset.cpus in native config Date: Mon, 24 Feb 2020 11:24:29 -0300 Message-Id: <20200224142428.538-6-jcfaracco@gmail.com> In-Reply-To: <20200224142428.538-1-jcfaracco@gmail.com> References: <20200224142428.538-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 01OEPIfL023417 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.15 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