From patchwork Fri Jul 14 23:43:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 107836 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp1556476qge; Fri, 14 Jul 2017 16:43:41 -0700 (PDT) X-Received: by 10.237.63.24 with SMTP id p24mr14272982qtf.81.1500075821226; Fri, 14 Jul 2017 16:43:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500075821; cv=none; d=google.com; s=arc-20160816; b=bOTOjreMBzHpVvKfoZV+fibP6V1gZJGPKxYHw84sPZKghFrGHiX7CpaFe1u7x1Rp4P reglQImQqUBAjpA/aU9NM14vsNzBtG3P50gIzBJGLg7jyljexkntyiLAmS5GNFKYflSn tlg+WMEIWChdKpGyrEYZDqGG3YrwRzjCb5KN7OpuPdEt9A0f6111GHOGCw6Oxelx0PDH +QXUw3jOsB/AZVhXyDT3VxM0EFaX3/Md9AFAstu1gfDFDoAWmWQ/9J3iLDCg2wLcNoEK uod5wDu4VWsgdQ057cEIZzxpbvikJboEoMdxZWy2Jq3HiuHwjF3/P6s5f5SPp3uruTkk /Q5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:references :in-reply-to:message-id:date:to:from:delivered-to:dkim-filter :dmarc-filter:arc-authentication-results; bh=+heeGC5ws7Qm0VtzNXFpOe+cD38S+H5xnHLVxL5Ab6E=; b=d8H6tjDiSTYS7AX+8W5f/4GTUSKtZqqGht0S6W0GSguCbnfj7nTo+iYbu13CtDx3dr wfgOuVhd1m2yMP58/PlFF2ajIpsAQIgHpAMwb+u3/nlwzzmTEJWpDI4LO2zvu0Wpz5w4 GKfSZX2dN/G+ckwqf4iu1Mxk40Z8EH8wBoXgKLXF67uLIhhdWR6g+DER3ayrwAozaCX8 IJArHLO6ldoLjcbzENPUTJ2tcr8PQogSz+FDhfSxSDn5IvrjCljl87+R0r4qJbdiHyW5 56r6gN6cRajwulzl0xz15jyg8I6VgPl41kVP4cP5oADmQR0Xgi8CGX7r8QuQ3VuuLtDL hh8A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id p10si8909047qta.70.2017.07.14.16.43.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Jul 2017 16:43:41 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BC188806A8; Fri, 14 Jul 2017 23:43:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BC188806A8 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com BC188806A8 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 7F47068D6D; Fri, 14 Jul 2017 23:43:39 +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 1D9351833033; Fri, 14 Jul 2017 23:43:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6ENhEQT023223 for ; Fri, 14 Jul 2017 19:43:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 36EB918398; Fri, 14 Jul 2017 23:43:14 +0000 (UTC) Delivered-To: libvirt-list@redhat.com Received: from colepc.redhat.com (ovpn-116-206.phx2.redhat.com [10.3.116.206]) by smtp.corp.redhat.com (Postfix) with ESMTP id D31401840D; Fri, 14 Jul 2017 23:43:13 +0000 (UTC) From: Cole Robinson To: libvirt-list@redhat.com Date: Fri, 14 Jul 2017 19:43:05 -0400 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/3] qemu: command: rework adding of default cpu model 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 Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 14 Jul 2017 23:43:40 +0000 (UTC) Certain XML features that aren't in the block map to -cpu flags on the qemu cli. If one of these is specified but the user didn't explicitly pass an XML model, we need to format a default model on the command line. The current code handles this by sprinkling this default cpu handling among all the different flag string formatting. Instead, switch it to do this just once. This alters some test output slightly: the previous code would write the default -cpu in some cases when no flags were actually added, so the output was redundant. Signed-off-by: Cole Robinson --- src/qemu/qemu_command.c | 72 +++++++--------------- .../qemuxml2argvdata/qemuxml2argv-hyperv-off.args | 1 - .../qemuxml2argv-kvm-features-off.args | 1 - 3 files changed, 22 insertions(+), 52 deletions(-) -- 2.13.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index b83261246..aa12479f7 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -6714,11 +6714,11 @@ qemuBuildCpuCommandLine(virCommandPtr cmd, virQEMUCapsPtr qemuCaps) { virArch hostarch = virArchFromHost(); - char *cpu = NULL; + char *cpu = NULL, *cpu_flags = NULL; bool hasHwVirt = false; const char *default_model; - bool have_cpu = false; int ret = -1; + virBuffer cpu_buf = VIR_BUFFER_INITIALIZER; virBuffer buf = VIR_BUFFER_INITIALIZER; size_t i; @@ -6729,9 +6729,8 @@ qemuBuildCpuCommandLine(virCommandPtr cmd, if (def->cpu && (def->cpu->mode != VIR_CPU_MODE_CUSTOM || def->cpu->model)) { - if (qemuBuildCpuModelArgStr(driver, def, &buf, qemuCaps) < 0) + if (qemuBuildCpuModelArgStr(driver, def, &cpu_buf, qemuCaps) < 0) goto cleanup; - have_cpu = true; /* Only 'svm' requires --enable-nesting. The nested 'vmx' patches now * simply hook off the CPU features. */ @@ -6769,8 +6768,7 @@ qemuBuildCpuCommandLine(virCommandPtr cmd, ((hostarch == VIR_ARCH_X86_64 && strstr(def->emulator, "kvm")) || strstr(def->emulator, "x86_64"))) { - virBufferAdd(&buf, default_model, -1); - have_cpu = true; + virBufferAdd(&cpu_buf, default_model, -1); } } @@ -6780,21 +6778,14 @@ qemuBuildCpuCommandLine(virCommandPtr cmd, if (timer->name == VIR_DOMAIN_TIMER_NAME_KVMCLOCK && timer->present != -1) { - virBufferAsprintf(&buf, "%s,%ckvmclock", - have_cpu ? "" : default_model, + virBufferAsprintf(&buf, ",%ckvmclock", timer->present ? '+' : '-'); - have_cpu = true; } else if (timer->name == VIR_DOMAIN_TIMER_NAME_HYPERVCLOCK && timer->present == 1) { - virBufferAsprintf(&buf, "%s,hv_time", - have_cpu ? "" : default_model); - have_cpu = true; + virBufferAddLit(&buf, ",hv_time"); } else if (timer->name == VIR_DOMAIN_TIMER_NAME_TSC && timer->frequency > 0) { - virBufferAsprintf(&buf, "%s,tsc-frequency=%lu", - have_cpu ? "" : default_model, - timer->frequency); - have_cpu = true; + virBufferAsprintf(&buf, ",tsc-frequency=%lu", timer->frequency); } } @@ -6805,10 +6796,7 @@ qemuBuildCpuCommandLine(virCommandPtr cmd, else sign = '-'; - virBufferAsprintf(&buf, "%s,%ckvm_pv_eoi", - have_cpu ? "" : default_model, - sign); - have_cpu = true; + virBufferAsprintf(&buf, ",%ckvm_pv_eoi", sign); } if (def->features[VIR_DOMAIN_FEATURE_PVSPINLOCK]) { @@ -6819,18 +6807,10 @@ qemuBuildCpuCommandLine(virCommandPtr cmd, else sign = '-'; - virBufferAsprintf(&buf, "%s,%ckvm_pv_unhalt", - have_cpu ? "" : default_model, - sign); - have_cpu = true; + virBufferAsprintf(&buf, ",%ckvm_pv_unhalt", sign); } if (def->features[VIR_DOMAIN_FEATURE_HYPERV] == VIR_TRISTATE_SWITCH_ON) { - if (!have_cpu) { - virBufferAdd(&buf, default_model, -1); - have_cpu = true; - } - for (i = 0; i < VIR_DOMAIN_HYPERV_LAST; i++) { switch ((virDomainHyperv) i) { case VIR_DOMAIN_HYPERV_RELAXED: @@ -6866,22 +6846,12 @@ qemuBuildCpuCommandLine(virCommandPtr cmd, for (i = 0; i < def->npanics; i++) { if (def->panics[i]->model == VIR_DOMAIN_PANIC_MODEL_HYPERV) { - if (!have_cpu) { - virBufferAdd(&buf, default_model, -1); - have_cpu = true; - } - virBufferAddLit(&buf, ",hv_crash"); break; } } if (def->features[VIR_DOMAIN_FEATURE_KVM] == VIR_TRISTATE_SWITCH_ON) { - if (!have_cpu) { - virBufferAdd(&buf, default_model, -1); - have_cpu = true; - } - for (i = 0; i < VIR_DOMAIN_KVM_LAST; i++) { switch ((virDomainKVM) i) { case VIR_DOMAIN_KVM_HIDDEN: @@ -6898,12 +6868,8 @@ qemuBuildCpuCommandLine(virCommandPtr cmd, if (def->features[VIR_DOMAIN_FEATURE_PMU]) { virTristateSwitch pmu = def->features[VIR_DOMAIN_FEATURE_PMU]; - if (!have_cpu) - virBufferAdd(&buf, default_model, -1); - virBufferAsprintf(&buf, ",pmu=%s", virTristateSwitchTypeToString(pmu)); - have_cpu = true; } if (def->cpu && def->cpu->cache) { @@ -6911,11 +6877,6 @@ qemuBuildCpuCommandLine(virCommandPtr cmd, bool hostOff = false; bool l3Off = false; - if (!have_cpu) { - virBufferAdd(&buf, default_model, -1); - have_cpu = true; - } - switch (cache->mode) { case VIR_CPU_CACHE_MODE_EMULATE: virBufferAddLit(&buf, ",l3-cache=on"); @@ -6945,13 +6906,22 @@ qemuBuildCpuCommandLine(virCommandPtr cmd, virBufferAddLit(&buf, ",l3-cache=off"); } + if (virBufferCheckError(&cpu_buf) < 0) + goto cleanup; if (virBufferCheckError(&buf) < 0) goto cleanup; - cpu = virBufferContentAndReset(&buf); + cpu = virBufferContentAndReset(&cpu_buf); + cpu_flags = virBufferContentAndReset(&buf); + + if (cpu_flags && !cpu) { + if (VIR_STRDUP(cpu, default_model) < 0) + goto cleanup; + } if (cpu) { - virCommandAddArgList(cmd, "-cpu", cpu, NULL); + virCommandAddArg(cmd, "-cpu"); + virCommandAddArgFormat(cmd, "%s%s", cpu, cpu_flags ? cpu_flags : ""); if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_NESTING) && hasHwVirt) virCommandAddArg(cmd, "-enable-nesting"); @@ -6961,7 +6931,9 @@ qemuBuildCpuCommandLine(virCommandPtr cmd, cleanup: VIR_FREE(cpu); + VIR_FREE(cpu_flags); virBufferFreeAndReset(&buf); + virBufferFreeAndReset(&cpu_buf); return ret; } diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hyperv-off.args b/tests/qemuxml2argvdata/qemuxml2argv-hyperv-off.args index e708feece..d1718d1f9 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-hyperv-off.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-hyperv-off.args @@ -8,7 +8,6 @@ QEMU_AUDIO_DRV=none \ -name QEMUGuest1 \ -S \ -M pc \ --cpu qemu32 \ -m 214 \ -smp 6,sockets=6,cores=1,threads=1 \ -uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ diff --git a/tests/qemuxml2argvdata/qemuxml2argv-kvm-features-off.args b/tests/qemuxml2argvdata/qemuxml2argv-kvm-features-off.args index e708feece..d1718d1f9 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-kvm-features-off.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-kvm-features-off.args @@ -8,7 +8,6 @@ QEMU_AUDIO_DRV=none \ -name QEMUGuest1 \ -S \ -M pc \ --cpu qemu32 \ -m 214 \ -smp 6,sockets=6,cores=1,threads=1 \ -uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \