From nobody Tue Nov 26 07:22:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1582516614; cv=none; d=zohomail.com; s=zohoarc; b=O0mb1YWaT4T3giBZCcOJQ/nm41zOoFmPXg1zVAXYE9m7GEK9bqdN1kAGw1kbYa39SXd/b26BTBiTHBL+4BZqpUrG5CHC5JaknkdJysy5mYxT9olKu0bppGnEY1moPFC8LJY+CD4u8ES9NjBFb95lIBoWKKdzKfjCrFiT9AYgwgc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582516614; 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=e3hjBoG1GAItCC3L2BHg2uB6JhRMVz4ild6XaEX4M7k=; b=eC7v1ii0dcQARr9jxNU8GtaN/ls//rja1og6+QEAES6DAlKz0sA7OfkGK2fVeRo9GzmB/DBdHVZRXQM9lfRseYHeem3Z/Vmtc8hqXdhGIaJcQFy3Al/LBfx+0lJDgZ2e+PJhcqctpxWGSyGc4k/jTylCyHXkMRWTBc3LiVAsoKs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1582516614617746.3845994359316; Sun, 23 Feb 2020 19:56:54 -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-472-V_Mu-Xg-MduMWagc7hYyRw-1; Sun, 23 Feb 2020 22:56:51 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9A86F107ACCC; Mon, 24 Feb 2020 03:56:45 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 75F9B8ED1A; Mon, 24 Feb 2020 03:56:45 +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 274F218089CE; Mon, 24 Feb 2020 03:56:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 01O3uhdq014693 for ; Sun, 23 Feb 2020 22:56:43 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4003C1004C79; Mon, 24 Feb 2020 03:56:43 +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 3AD8F10EE6CC for ; Mon, 24 Feb 2020 03:56:41 +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 19DB58007AC for ; Mon, 24 Feb 2020 03:56:41 +0000 (UTC) Received: from mail-qv1-f65.google.com (mail-qv1-f65.google.com [209.85.219.65]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-275-dT7mVedoPaicgXrhom1xEQ-1; Sun, 23 Feb 2020 22:56:38 -0500 Received: by mail-qv1-f65.google.com with SMTP id ff2so3608831qvb.3 for ; Sun, 23 Feb 2020 19:56:38 -0800 (PST) Received: from localhost.localdomain ([191.254.236.241]) by smtp.gmail.com with ESMTPSA id 64sm2652392qkd.78.2020.02.23.19.56.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Feb 2020 19:56:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582516613; 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=e3hjBoG1GAItCC3L2BHg2uB6JhRMVz4ild6XaEX4M7k=; b=InqHUa9Q+VYWns9slg39zyH8b+in5L+fvTpzx1y1OIuB4gFVKLU0GJg2O5DKimYlrKDwjz W1WuWpwQrsrXHyZOEu0cSkEuUJtfK2grupVHct3ISJIHQx2jmq/Ls5ZHpmQcACw6rPM9HY +sXv28t4VKFeh9kJoNNlDk1MonBir8c= X-MC-Unique: V_Mu-Xg-MduMWagc7hYyRw-1 X-MC-Unique: dT7mVedoPaicgXrhom1xEQ-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=RsYEJFoYV4RTPQ0PSP9dXQixDAu5JbRtiFbprMt26Ws=; b=ASRpZS1lOh3q5Ud+tmNH4LmYoJxaiI3ZlbbaDeviVf5LFrYxHGaiQgFqJCdZUxXz3O +vqCEnxUBl/cZIjQaB4zVNHVEIPBfS3UAl1R1q8wcXHPNKKEZFhIIFDJ8ZjqoGoKi1Wv NXcDEs3f29j6taoLfCbb9a9COUbqeKGV/abQA7o0IrvYB9476amLE9IjKuX8I1Yj+6L0 vqR7RzXmLihbdpdEAKYqGkyvwDchU8TxFwZ0mo3TjpsXM0bM0hACBFONrakCdyXXRlg/ cCxSPDurFqiMhbTMcvbxWpQ090dUNvhjRnjeTdyMC/SC4h/0kzap/9BCtwQcdTqBZCjO rkhA== X-Gm-Message-State: APjAAAXjc/l+dYt66G5Vfuctikj5BuqeHVdiNEPmFvaaDXHuNTRspjCH OgmEvnpll2Ekfal75fiBzIR2zDED X-Google-Smtp-Source: APXvYqyGEhwtYnn3WdjS/P2iwwExIvtCE1CZiaaogyRrN1wdtSheF7kXhR+sU2Dqstgfa3av3RnHAQ== X-Received: by 2002:a05:6214:10c1:: with SMTP id r1mr42221798qvs.70.1582516597873; Sun, 23 Feb 2020 19:56:37 -0800 (PST) From: Julio Faracco To: libvir-list@redhat.com Subject: [PATCH v2 5/5] lxc: Count max VCPUs based on cpuset.cpus in native config. Date: Mon, 24 Feb 2020 00:54:31 -0300 Message-Id: <20200224035429.3973-6-jcfaracco@gmail.com> In-Reply-To: <20200224035429.3973-1-jcfaracco@gmail.com> References: <20200224035429.3973-1-jcfaracco@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 01O3uhdq014693 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.13 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_fuse.c | 4 ++-- src/lxc/lxc_native.c | 24 +++++++++++++++++-- .../lxcconf2xml-cpusettune.xml | 2 +- 5 files changed, 50 insertions(+), 5 deletions(-) diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index 3b1ac881ba..63b55c397d 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_fuse.c b/src/lxc/lxc_fuse.c index 70dc68ec85..dc888749bc 100644 --- a/src/lxc/lxc_fuse.c +++ b/src/lxc/lxc_fuse.c @@ -252,7 +252,7 @@ lxcProcReadCpuinfoParse(virDomainDefPtr def, char *base, break; =20 if (curcpu > 0) - virBufferAddLit(new_cpuinfo, "\n", -1); + virBufferAddLit(new_cpuinfo, "\n"); =20 virBufferAsprintf(new_cpuinfo, "processor\t: %zu\n", curcpu); @@ -268,7 +268,7 @@ lxcProcReadCpuinfoParse(virDomainDefPtr def, char *base, } } =20 - virBufferAddLit(new_cpuinfo, "\n", -1); + virBufferAddLit(new_cpuinfo, "\n"); =20 return strlen(virBufferCurrentContent(new_cpuinfo)); } 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