From nobody Sat Apr 27 15:20:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1507553647317196.66536120550325; Mon, 9 Oct 2017 05:54:07 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id A8CFCC04AC68; Mon, 9 Oct 2017 12:54:05 +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 2E86D6154B; Mon, 9 Oct 2017 12:54:05 +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 CA5E93FAD5; Mon, 9 Oct 2017 12:54:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v99CVW3A010122 for ; Mon, 9 Oct 2017 08:31:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id D3E3B781E3; Mon, 9 Oct 2017 12:31:32 +0000 (UTC) Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com [10.5.110.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8109178201 for ; Mon, 9 Oct 2017 12:31:16 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DA9DD4ACA7 for ; Mon, 9 Oct 2017 12:31:02 +0000 (UTC) Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v99CTdHW137608 for ; Mon, 9 Oct 2017 08:31:02 -0400 Received: from e06smtp12.uk.ibm.com (e06smtp12.uk.ibm.com [195.75.94.108]) by mx0b-001b2d01.pphosted.com with ESMTP id 2dg3xeqnma-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 09 Oct 2017 08:31:02 -0400 Received: from localhost by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 9 Oct 2017 13:31:00 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 9 Oct 2017 13:30:58 +0100 Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v99CUuss8978680; Mon, 9 Oct 2017 12:30:57 GMT Received: from d23av02.au.ibm.com (localhost [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v99CUlHb007915; Mon, 9 Oct 2017 23:30:47 +1100 Received: from powerkvmpok002.pok.stglabs.ibm.com (powerkvmpok002.pok.stglabs.ibm.com [9.114.13.10]) by d23av02.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v99CUii7007781; Mon, 9 Oct 2017 23:30:46 +1100 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A8CFCC04AC68 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A8CFCC04AC68 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com DA9DD4ACA7 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=none smtp.mailfrom=kmp@linux.vnet.ibm.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com DA9DD4ACA7 From: Kothapally Madhu Pavan To: libvir-list@redhat.com Date: Mon, 9 Oct 2017 18:00:50 +0530 X-TM-AS-MML: disable x-cbid: 17100912-0008-0000-0000-0000049DD3C8 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17100912-0009-0000-0000-00001E2F505C Message-Id: <1507552250-29409-1-git-send-email-kmp@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-10-09_03:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1710090183 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 205 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 09 Oct 2017 12:31:03 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 09 Oct 2017 12:31:03 +0000 (UTC) for IP:'148.163.158.5' DOMAIN:'mx0b-001b2d01.pphosted.com' HELO:'mx0a-001b2d01.pphosted.com' FROM:'kmp@linux.vnet.ibm.com' RCPT:'' X-RedHat-Spam-Score: -0.72 (RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL) 148.163.158.5 mx0b-001b2d01.pphosted.com 148.163.158.5 mx0b-001b2d01.pphosted.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Kothapally Madhu Pavan Subject: [libvirt] [PATCH v2] qemu: argv: parse qemu commandline memory arguments 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 09 Oct 2017 12:54:06 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Existing qemuParseCommandLineMem() will parse "-m 4G" format string. This patch allows it to parse "-m size=3D8126464k,slots=3D32,maxmem=3D33554= 432k" format along with existing format. And adds a testcase to validate the chan= ges. Signed-off-by: Kothapally Madhu Pavan --- src/qemu/qemu_parse_command.c | 89 ++++++++++++++++++= +--- .../qemuargv2xml-mem-scale-maxmemory.args | 22 ++++++ .../qemuargv2xml-mem-scale-maxmemory.xml | 38 +++++++++ tests/qemuargv2xmltest.c | 1 + 4 files changed, 138 insertions(+), 12 deletions(-) create mode 100644 tests/qemuargv2xmldata/qemuargv2xml-mem-scale-maxmemory= .args create mode 100644 tests/qemuargv2xmldata/qemuargv2xml-mem-scale-maxmemory= .xml diff --git a/src/qemu/qemu_parse_command.c b/src/qemu/qemu_parse_command.c index 37e1149..f8b6f8b 100644 --- a/src/qemu/qemu_parse_command.c +++ b/src/qemu/qemu_parse_command.c @@ -1629,26 +1629,91 @@ static int qemuParseCommandLineMem(virDomainDefPtr dom, const char *val) { - unsigned long long mem; + unsigned long long mem =3D 0; + unsigned long long size =3D 0; + unsigned long long maxmem =3D 0; + unsigned int slots =3D 0; char *end; + size_t i; + int nkws; + char **kws; + char **vals; + int n; + int ret =3D -1; =20 - if (virStrToLong_ull(val, &end, 10, &mem) < 0) { + if (qemuParseKeywords(val, &kws, &vals, &nkws, 1) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot parse memory level '%s'"), val); - return -1; + _("cannot parse memory '%s'"), val); + goto cleanup; } =20 - if (virScaleInteger(&mem, end, 1024*1024, ULLONG_MAX) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot scale memory: %s"), - virGetLastErrorMessage()); - return -1; + for (i =3D 0; i < nkws; i++) { + if (vals[i] =3D=3D NULL) { + if (i > 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot parse memory '%s'"), val); + goto cleanup; + } + if (virStrToLong_ull(kws[i], &end, 10, &mem) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot parse memory level '%s'"), kws[i]= ); + goto cleanup; + } + if (virScaleInteger(&mem, end, 1024*1024, ULLONG_MAX) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot scale memory: %s"), + virGetLastErrorMessage()); + goto cleanup; + } + + size =3D mem; + + } else { + if (STREQ(kws[i], "size") || STREQ(kws[i], "maxmem")) { + if (virStrToLong_ull(vals[i], &end, 10, &mem) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot parse memory level '%s'"), va= ls[i]); + goto cleanup; + } + if (virScaleInteger(&mem, end, 1024*1024, ULLONG_MAX) < 0)= { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot scale memory: %s"), + virGetLastErrorMessage()); + goto cleanup; + } + + STREQ(kws[i], "size") ? (size =3D mem) : (maxmem =3D mem); + + } + if (STREQ(kws[i], "slots")) { + if (virStrToLong_i(vals[i], &end, 10, &n) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot parse slots value '%s'"), val= s[i]); + goto cleanup; + } + + slots =3D n; + + } + } } =20 - virDomainDefSetMemoryTotal(dom, mem / 1024); - dom->mem.cur_balloon =3D mem / 1024; + virDomainDefSetMemoryTotal(dom, size / 1024); + dom->mem.cur_balloon =3D size / 1024; + dom->mem.memory_slots =3D slots; + dom->mem.max_memory =3D maxmem; =20 - return 0; + ret =3D 0; + + cleanup: + for (i =3D 0; i < nkws; i++) { + VIR_FREE(kws[i]); + VIR_FREE(vals[i]); + } + VIR_FREE(kws); + VIR_FREE(vals); + + return ret; } =20 =20 diff --git a/tests/qemuargv2xmldata/qemuargv2xml-mem-scale-maxmemory.args b= /tests/qemuargv2xmldata/qemuargv2xml-mem-scale-maxmemory.args new file mode 100644 index 0000000..7bce841 --- /dev/null +++ b/tests/qemuargv2xmldata/qemuargv2xml-mem-scale-maxmemory.args @@ -0,0 +1,22 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/home/test \ +USER=3Dtest \ +LOGNAME=3Dtest \ +QEMU_AUDIO_DRV=3Dnone \ +/usr/bin/qemu-system-i686 \ +-name QEMUGuest1 \ +-S \ +-M pc \ +-m 8G,slots=3D16,maxmem=3D16G \ +-smp 1,maxcpus=3D2,sockets=3D2,cores=3D1,threads=3D1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-nographic \ +-monitor unix:/tmp/test-monitor,server,nowait \ +-no-acpi \ +-boot c \ +-usb \ +-drive file=3D/dev/HostVG/QEMUGuest1,format=3Draw,if=3Dide,bus=3D0,unit=3D= 0 \ +-net none \ +-serial none \ +-parallel none diff --git a/tests/qemuargv2xmldata/qemuargv2xml-mem-scale-maxmemory.xml b/= tests/qemuargv2xmldata/qemuargv2xml-mem-scale-maxmemory.xml new file mode 100644 index 0000000..328c4ed --- /dev/null +++ b/tests/qemuargv2xmldata/qemuargv2xml-mem-scale-maxmemory.xml @@ -0,0 +1,38 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 17179869184 + 8388608 + 8388608 + 2 + + hvm + + + + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i686 + + + + +
+ + +
+ + + +
+ + + + + + diff --git a/tests/qemuargv2xmltest.c b/tests/qemuargv2xmltest.c index 1adbcfe..e35726e 100644 --- a/tests/qemuargv2xmltest.c +++ b/tests/qemuargv2xmltest.c @@ -265,6 +265,7 @@ mymain(void) DO_TEST("hostdev-pci-address"); =20 DO_TEST("mem-scale"); + DO_TEST("mem-scale-maxmemory"); DO_TEST("smp"); =20 DO_TEST("hyperv"); --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list