From nobody Fri May 10 11:48:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1620923482; cv=none; d=zohomail.com; s=zohoarc; b=i7Ji2CokYPzqp+6ABgQVlOI6whL8IYwUQrbZ9S6/iDvmLEJl1jiHQNQN9v89dUDTF1UoB11g/Sy0yl/DrjJfyGy8RsLn82crmaOjC4UG5/1T5W0bQiPiJRUf/YGLtOpUFYGKjnfBJt+khxaKqQwNZH4hjYr02XN+4IcP4FXM9f0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620923482; 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=wjlhzWTTlvRzXm4f0NDH6/Mp9uL080ScOYiGJuLVlIU=; b=QhvcQIk7KgzCoQMaDZlJ2kLQk9GhHuzf6pEgi8lGegYPinPS061uov2EN4pZeivzHnsGtmWhAHYy4prMANezpTeUzn4QN3zDkHud1CvwaeRQRbT2f0xAGn+O/X5MinS5dxaoshtwYM0rC5+QU3RzRFFcV3r2gbWtriZb34g3/ZA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620923482347449.3397071809037; Thu, 13 May 2021 09:31:22 -0700 (PDT) Received: from localhost ([::1]:52506 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lhEF5-0004vg-Qj for importer@patchew.org; Thu, 13 May 2021 12:31:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40468) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhED2-0002H7-J3 for qemu-devel@nongnu.org; Thu, 13 May 2021 12:29:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:49587) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhECx-0003QW-Hg for qemu-devel@nongnu.org; Thu, 13 May 2021 12:29:12 -0400 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-533-Z7Vw7dNGP2GMEVHOWlB4tQ-1; Thu, 13 May 2021 12:29:04 -0400 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 9AADF1922035; Thu, 13 May 2021 16:29:03 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2EDAF687D7; Thu, 13 May 2021 16:29:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620923346; h=from:from: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; bh=wjlhzWTTlvRzXm4f0NDH6/Mp9uL080ScOYiGJuLVlIU=; b=VFwx93EMPXD0jYnIzZPEBPKD62p2nvBoiUtm0t1Oc55q3ze4iBm0VEi4XOT0dTAkJ9Xtmc J8PTY/mPOf8nakRsee495ecPzoPQaJiT0IzLBFFTgqq6kJtv5rmC/yMK9CRSeOVAyO9c5x Sik728LrLSPrJPgLZnffAwX5z9S0SnU= X-MC-Unique: Z7Vw7dNGP2GMEVHOWlB4tQ-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 01/14] remove -writeconfig Date: Thu, 13 May 2021 12:28:48 -0400 Message-Id: <20210513162901.1310239-2-pbonzini@redhat.com> In-Reply-To: <20210513162901.1310239-1-pbonzini@redhat.com> References: <20210513162901.1310239-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yang.zhong@intel.com, berrange@redhat.com, ehabkost@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Like -set and -readconfig, it would not really be too hard to extend -writeconfig to parsing mechanisms other than QemuOpts. However, the uses of -writeconfig are substantially more limited, as it is generally easier to write the configuration by hand in the first place. In addition, -writeconfig does not even try to detect cases where it prints incorrect syntax (for example if values have a quote in them, since qemu_config_parse does not support any kind of escaping. Just remove it. Signed-off-by: Paolo Bonzini --- docs/system/deprecated.rst | 7 ------ docs/system/removed-features.rst | 6 +++++ include/qemu/config-file.h | 1 - qemu-options.hx | 8 ++---- softmmu/vl.c | 20 --------------- util/qemu-config.c | 42 -------------------------------- 6 files changed, 8 insertions(+), 76 deletions(-) diff --git a/docs/system/deprecated.rst b/docs/system/deprecated.rst index f9169077ae..36d0b24633 100644 --- a/docs/system/deprecated.rst +++ b/docs/system/deprecated.rst @@ -96,13 +96,6 @@ library enabled as a cryptography provider. Neither the ``nettle`` library, or the built-in cryptography provider are supported on FIPS enabled hosts. =20 -``-writeconfig`` (since 6.0) -''''''''''''''''''''''''''''' - -The ``-writeconfig`` option is not able to serialize the entire contents -of the QEMU command line. It is thus considered a failed experiment -and deprecated, with no current replacement. - Userspace local APIC with KVM (x86, since 6.0) '''''''''''''''''''''''''''''''''''''''''''''' =20 diff --git a/docs/system/removed-features.rst b/docs/system/removed-feature= s.rst index c21e6fa5ee..85a988ce2d 100644 --- a/docs/system/removed-features.rst +++ b/docs/system/removed-features.rst @@ -126,6 +126,12 @@ devices. Drives the board doesn't pick up can no long= er be used with This option was undocumented and not used in the field. Use `-device usb-ccid`` instead. =20 +``-writeconfig`` (since 6.1) +''''''''''''''''''''''''''''' + +The ``-writeconfig`` option was not able to serialize the entire contents +of the QEMU command line. It is thus considered a failed experiment +and removed without a replacement. =20 QEMU Machine Protocol (QMP) commands ------------------------------------ diff --git a/include/qemu/config-file.h b/include/qemu/config-file.h index 8d3e53ae4d..9a44d2a77b 100644 --- a/include/qemu/config-file.h +++ b/include/qemu/config-file.h @@ -10,7 +10,6 @@ void qemu_add_opts(QemuOptsList *list); void qemu_add_drive_opts(QemuOptsList *list); int qemu_global_option(const char *str); =20 -void qemu_config_write(FILE *fp); int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname, Error **errp); =20 diff --git a/qemu-options.hx b/qemu-options.hx index acd8b4f6f9..317d33ea11 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4395,18 +4395,14 @@ SRST ERST =20 DEF("readconfig", HAS_ARG, QEMU_OPTION_readconfig, - "-readconfig \n", QEMU_ARCH_ALL) + "-readconfig \n" + " read config file\n", QEMU_ARCH_ALL) SRST ``-readconfig file`` Read device configuration from file. This approach is useful when you want to spawn QEMU process with many command line options but you don't want to exceed the command line character limit. ERST -DEF("writeconfig", HAS_ARG, QEMU_OPTION_writeconfig, - "-writeconfig \n" - " read/write config file (deprecated)\n", QEMU_ARCH_ALL) -SRST -ERST =20 DEF("no-user-config", 0, QEMU_OPTION_nouserconfig, "-no-user-config\n" diff --git a/softmmu/vl.c b/softmmu/vl.c index 11ac3750d8..c7653fe788 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -3388,26 +3388,6 @@ void qemu_init(int argc, char **argv, char **envp) } display_remote++; break; - case QEMU_OPTION_writeconfig: - { - FILE *fp; - warn_report("-writeconfig is deprecated and will go aw= ay without a replacement"); - if (strcmp(optarg, "-") =3D=3D 0) { - fp =3D stdout; - } else { - fp =3D fopen(optarg, "w"); - if (fp =3D=3D NULL) { - error_report("open %s: %s", optarg, - strerror(errno)); - exit(1); - } - } - qemu_config_write(fp); - if (fp !=3D stdout) { - fclose(fp); - } - break; - } case QEMU_OPTION_qtest: qtest_chrdev =3D optarg; break; diff --git a/util/qemu-config.c b/util/qemu-config.c index 670bd6ebca..9bd86aab1b 100644 --- a/util/qemu-config.c +++ b/util/qemu-config.c @@ -307,48 +307,6 @@ void qemu_add_opts(QemuOptsList *list) abort(); } =20 -struct ConfigWriteData { - QemuOptsList *list; - FILE *fp; -}; - -static int config_write_opt(void *opaque, const char *name, const char *va= lue, - Error **errp) -{ - struct ConfigWriteData *data =3D opaque; - - fprintf(data->fp, " %s =3D \"%s\"\n", name, value); - return 0; -} - -static int config_write_opts(void *opaque, QemuOpts *opts, Error **errp) -{ - struct ConfigWriteData *data =3D opaque; - const char *id =3D qemu_opts_id(opts); - - if (id) { - fprintf(data->fp, "[%s \"%s\"]\n", data->list->name, id); - } else { - fprintf(data->fp, "[%s]\n", data->list->name); - } - qemu_opt_foreach(opts, config_write_opt, data, NULL); - fprintf(data->fp, "\n"); - return 0; -} - -void qemu_config_write(FILE *fp) -{ - struct ConfigWriteData data =3D { .fp =3D fp }; - QemuOptsList **lists =3D vm_config_groups; - int i; - - fprintf(fp, "# qemu config file\n\n"); - for (i =3D 0; lists[i] !=3D NULL; i++) { - data.list =3D lists[i]; - qemu_opts_foreach(data.list, config_write_opts, &data, NULL); - } -} - /* Returns number of config groups on success, -errno on error */ int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname, E= rror **errp) { --=20 2.26.2 From nobody Fri May 10 11:48:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1620923832; cv=none; d=zohomail.com; s=zohoarc; b=KlvOo+ZCgKKxrMjUdzwtrRfiaIQJ2RxUteaLkY/kAm3PNjjgwkDwPTC4oUHeKaI9QiJPKUgLnezvXfJGnN1L2fQ1nx8XfJsOrozEtHv1wWc4RRiT1AHZ6VstWXs0Z8lZYVgCRBPElR1svt812EkDXHuf9/1/5nMLRWdjbLN7R6M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620923832; 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=/7dcJAOC1FOAushP7yW2YZrbVyj0SOxFh30cEe+UGVI=; b=apovd37jyDuM78LxKPdYA0xSq/DTitivEHRclCRD04gXT0hYuPs9yBT6HVuncPXA4ZDpzpFTCfUlroLYetJu9jmzvllOQee3Ja3yFJ/WDhKiWb7hFGynro+kx3Jfw6BocJ0jL3a8rN+U3Zr9+CKttJx5ou7+7bHkpoafTYD0IfM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620923832958309.30377523165043; Thu, 13 May 2021 09:37:12 -0700 (PDT) Received: from localhost ([::1]:40810 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lhEKl-0007dc-0s for importer@patchew.org; Thu, 13 May 2021 12:37:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40594) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhEDD-0002OD-8D for qemu-devel@nongnu.org; Thu, 13 May 2021 12:29:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:25061) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhED7-0003VV-Ty for qemu-devel@nongnu.org; Thu, 13 May 2021 12:29:22 -0400 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-373-qDJqiOQpO2u9mEQ4jn4FUQ-1; Thu, 13 May 2021 12:29:05 -0400 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 2DDC280006E; Thu, 13 May 2021 16:29:04 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id B4D8E687D7; Thu, 13 May 2021 16:29:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620923357; h=from:from: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; bh=/7dcJAOC1FOAushP7yW2YZrbVyj0SOxFh30cEe+UGVI=; b=A7ieTQ2wumq2RjHEppdFU+j4kgmaBxT8xrzBeaPDEXeDYmfG9mDzpkXT01rXj2eaemzDXJ E1P7gAZQ81TJBw0B2shvaVR7wLI+EmGG58urQlYflccX8mBcCNpa/mgyOniDNxGjWBCIcR cKS75xpNQ1p8oBXIh7UW0bd10kOOEc8= X-MC-Unique: qDJqiOQpO2u9mEQ4jn4FUQ-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 02/14] qemu-config: parse configuration files to a QDict Date: Thu, 13 May 2021 12:28:49 -0400 Message-Id: <20210513162901.1310239-3-pbonzini@redhat.com> In-Reply-To: <20210513162901.1310239-1-pbonzini@redhat.com> References: <20210513162901.1310239-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yang.zhong@intel.com, berrange@redhat.com, ehabkost@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Change the parser to put the values into a QDict and pass them to a callback. qemu_config_parse's QemuOpts creation is itself turned into a callback function. This is useful for -readconfig to support keyval-based options; getting a QDict from the parser removes a roundtrip from QDict to QemuOpts and then back to QDict. Signed-off-by: Paolo Bonzini --- include/qemu/config-file.h | 6 ++- softmmu/vl.c | 4 +- util/qemu-config.c | 91 +++++++++++++++++++++++++------------- 3 files changed, 68 insertions(+), 33 deletions(-) diff --git a/include/qemu/config-file.h b/include/qemu/config-file.h index 9a44d2a77b..217a909053 100644 --- a/include/qemu/config-file.h +++ b/include/qemu/config-file.h @@ -1,6 +1,7 @@ #ifndef QEMU_CONFIG_FILE_H #define QEMU_CONFIG_FILE_H =20 +typedef void QEMUConfigCB(const char *group, QDict *qdict, void *opaque, E= rror **errp); =20 QemuOptsList *qemu_find_opts(const char *group); QemuOptsList *qemu_find_opts_err(const char *group, Error **errp); @@ -13,7 +14,10 @@ int qemu_global_option(const char *str); int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname, Error **errp); =20 -int qemu_read_config_file(const char *filename, Error **errp); +/* A default callback for qemu_read_config_file(). */ +void qemu_config_do_parse(const char *group, QDict *qdict, void *opaque, E= rror **errp); + +int qemu_read_config_file(const char *filename, QEMUConfigCB *f, Error **e= rrp); =20 /* Parse QDict options as a replacement for a config file (allowing multip= le enumerated (0..(n-1)) configuration "sections") */ diff --git a/softmmu/vl.c b/softmmu/vl.c index c7653fe788..598d064a8e 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -2121,7 +2121,7 @@ static void qemu_read_default_config_file(Error **err= p) int ret; g_autofree char *file =3D get_relocated_path(CONFIG_QEMU_CONFDIR "/qem= u.conf"); =20 - ret =3D qemu_read_config_file(file, errp); + ret =3D qemu_read_config_file(file, qemu_config_do_parse, errp); if (ret < 0) { if (ret =3D=3D -ENOENT) { error_free(*errp); @@ -3370,7 +3370,7 @@ void qemu_init(int argc, char **argv, char **envp) qemu_plugin_opt_parse(optarg, &plugin_list); break; case QEMU_OPTION_readconfig: - qemu_read_config_file(optarg, &error_fatal); + qemu_read_config_file(optarg, qemu_config_do_parse, &error= _fatal); break; case QEMU_OPTION_spice: olist =3D qemu_find_opts_err("spice", NULL); diff --git a/util/qemu-config.c b/util/qemu-config.c index 9bd86aab1b..22eebca3a8 100644 --- a/util/qemu-config.c +++ b/util/qemu-config.c @@ -308,19 +308,19 @@ void qemu_add_opts(QemuOptsList *list) } =20 /* Returns number of config groups on success, -errno on error */ -int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname, E= rror **errp) +static int qemu_config_foreach(FILE *fp, QEMUConfigCB *cb, void *opaque, + const char *fname, Error **errp) { - char line[1024], group[64], id[64], arg[64], value[1024]; + char line[1024], prev_group[64], group[64], arg[64], value[1024]; Location loc; - QemuOptsList *list =3D NULL; Error *local_err =3D NULL; - QemuOpts *opts =3D NULL; + QDict *qdict =3D NULL; int res =3D -EINVAL, lno =3D 0; int count =3D 0; =20 loc_push_none(&loc); while (fgets(line, sizeof(line), fp) !=3D NULL) { - loc_set_file(fname, ++lno); + ++lno; if (line[0] =3D=3D '\n') { /* skip empty lines */ continue; @@ -329,39 +329,39 @@ int qemu_config_parse(FILE *fp, QemuOptsList **lists,= const char *fname, Error * /* comment */ continue; } - if (sscanf(line, "[%63s \"%63[^\"]\"]", group, id) =3D=3D 2) { - /* group with id */ - list =3D find_list(lists, group, &local_err); - if (local_err) { - error_propagate(errp, local_err); - goto out; + if (line[0] =3D=3D '[') { + QDict *prev =3D qdict; + if (sscanf(line, "[%63s \"%63[^\"]\"]", group, value) =3D=3D 2= ) { + qdict =3D qdict_new(); + qdict_put_str(qdict, "id", value); + count++; + } else if (sscanf(line, "[%63[^]]]", group) =3D=3D 1) { + qdict =3D qdict_new(); + count++; } - opts =3D qemu_opts_create(list, id, 1, NULL); - count++; - continue; - } - if (sscanf(line, "[%63[^]]]", group) =3D=3D 1) { - /* group without id */ - list =3D find_list(lists, group, &local_err); - if (local_err) { - error_propagate(errp, local_err); - goto out; + if (qdict !=3D prev) { + if (prev) { + cb(prev_group, prev, opaque, &local_err); + qobject_unref(prev); + if (local_err) { + error_propagate(errp, local_err); + goto out; + } + } + strcpy(prev_group, group); + continue; } - opts =3D qemu_opts_create(list, NULL, 0, &error_abort); - count++; - continue; } + loc_set_file(fname, lno); value[0] =3D '\0'; if (sscanf(line, " %63s =3D \"%1023[^\"]\"", arg, value) =3D=3D 2 = || sscanf(line, " %63s =3D \"\"", arg) =3D=3D 1) { /* arg =3D value */ - if (opts =3D=3D NULL) { + if (qdict =3D=3D NULL) { error_setg(errp, "no group defined"); goto out; } - if (!qemu_opt_set(opts, arg, value, errp)) { - goto out; - } + qdict_put_str(qdict, arg, value); continue; } error_setg(errp, "parse error"); @@ -375,10 +375,41 @@ int qemu_config_parse(FILE *fp, QemuOptsList **lists,= const char *fname, Error * res =3D count; out: loc_pop(&loc); + if (qdict) { + cb(group, qdict, opaque, errp); + qobject_unref(qdict); + } return res; } =20 -int qemu_read_config_file(const char *filename, Error **errp) +void qemu_config_do_parse(const char *group, QDict *qdict, void *opaque, E= rror **errp) +{ + QemuOptsList **lists =3D opaque; + const char *id =3D qdict_get_try_str(qdict, "id"); + QemuOptsList *list; + QemuOpts *opts; + + list =3D find_list(lists, group, errp); + if (!list) { + return; + } + + opts =3D qemu_opts_create(list, id, 1, errp); + if (!opts) { + return; + } + if (id) { + qdict_del(qdict, "id"); + } + qemu_opts_absorb_qdict(opts, qdict, errp); +} + +int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname, E= rror **errp) +{ + return qemu_config_foreach(fp, qemu_config_do_parse, lists, fname, err= p); +} + +int qemu_read_config_file(const char *filename, QEMUConfigCB *cb, Error **= errp) { FILE *f =3D fopen(filename, "r"); int ret; @@ -388,7 +419,7 @@ int qemu_read_config_file(const char *filename, Error *= *errp) return -errno; } =20 - ret =3D qemu_config_parse(f, vm_config_groups, filename, errp); + ret =3D qemu_config_foreach(f, cb, vm_config_groups, filename, errp); fclose(f); return ret; } --=20 2.26.2 From nobody Fri May 10 11:48:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1620923484; cv=none; d=zohomail.com; s=zohoarc; b=Ws/NT094L/usheVwywnRF/44O6gDO+rqkAiOJh1D4AYImfRkrw3klyqLXNy7y290U3XNfi4Ccu2aGH20Re770VmPmDVY/zaKUVeGy4O4g4ATRLzRoJvEqEAjdqddCSp96It1oMVg86WtuskFCsuXBMUvPTYT63krdd/dLjlVmJw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620923484; 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=61Ee2HViC1ldm+GMk34PWH9wEDLE7t+AJkoer+IYyDg=; b=AhKkmX03jCRuepqrCAqG/6jIQCrnhpnn5K7N7a8XCCP/t+qD9IBkIOQgGu68SFB7Z3c4shWO7Tc4q73WhS3qU21ujiQCEGEMtUZhVEyoN3LMhQlw6F0Tik1YBtj+Tzc0jjJ82ECX7EQJdRRCSvnFxXL5nVPkWQxLaH1su+aT/1A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620923484965495.48859137014676; Thu, 13 May 2021 09:31:24 -0700 (PDT) Received: from localhost ([::1]:52812 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lhEF8-00058E-9V for importer@patchew.org; Thu, 13 May 2021 12:31:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40506) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhED5-0002J0-Nx for qemu-devel@nongnu.org; Thu, 13 May 2021 12:29:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:28403) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhECy-0003Qd-2l for qemu-devel@nongnu.org; Thu, 13 May 2021 12:29:15 -0400 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-394-bUcfel7MNpicxdhksfVgoQ-1; Thu, 13 May 2021 12:29:05 -0400 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 B4432107ACE8; Thu, 13 May 2021 16:29:04 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 483C4687D7; Thu, 13 May 2021 16:29:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620923347; h=from:from: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; bh=61Ee2HViC1ldm+GMk34PWH9wEDLE7t+AJkoer+IYyDg=; b=iitiQYVFf3UcMNQI2EenzGNaatQnRXQJCbEOfY0SRgKRXHHDuWWuvzVA/KErgcidXfxLPJ dZK+vCVqxChJ9Qmgr64IlpSmsHTbFI8mVMeObFEOON4QPwXFEA5yjlpYxVvBanOnk3MBcE SGZAb+Pu146lQ6izLAPQ7zTj0Anl/No= X-MC-Unique: bUcfel7MNpicxdhksfVgoQ-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 03/14] vl: plumb keyval-based options into -set and -readconfig Date: Thu, 13 May 2021 12:28:50 -0400 Message-Id: <20210513162901.1310239-4-pbonzini@redhat.com> In-Reply-To: <20210513162901.1310239-1-pbonzini@redhat.com> References: <20210513162901.1310239-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yang.zhong@intel.com, berrange@redhat.com, ehabkost@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Let -set and -readconfig support parsing command line options with keyval either QemuOpts. The underlying data structure is QDict for command line options that opt into keyval-based parsing. This patch introduces a keyval_merge function that merges two keyval-produced (or keyval-like) QDicts. Right now it is used for -set, which is slightly heavyweight; later, it will be used also to emulate the behavior of .merge_lists =3D true QemuOpts groups, merging -readconfig sections and command-line options in a single QDict. Signed-off-by: Paolo Bonzini --- include/block/qdict.h | 2 - include/qapi/qmp/qdict.h | 3 + include/qemu/option.h | 1 + softmmu/vl.c | 146 +++++++++++++++++++++++++++++++++------ tests/unit/test-keyval.c | 56 +++++++++++++++ util/keyval.c | 47 +++++++++++++ 6 files changed, 232 insertions(+), 23 deletions(-) diff --git a/include/block/qdict.h b/include/block/qdict.h index d8cb502d7d..ced2acfb92 100644 --- a/include/block/qdict.h +++ b/include/block/qdict.h @@ -20,8 +20,6 @@ void qdict_join(QDict *dest, QDict *src, bool overwrite); void qdict_extract_subqdict(QDict *src, QDict **dst, const char *start); void qdict_array_split(QDict *src, QList **dst); int qdict_array_entries(QDict *src, const char *subqdict); -QObject *qdict_crumple(const QDict *src, Error **errp); -void qdict_flatten(QDict *qdict); =20 typedef struct QDictRenames { const char *from; diff --git a/include/qapi/qmp/qdict.h b/include/qapi/qmp/qdict.h index 9934539c1b..d5b5430e21 100644 --- a/include/qapi/qmp/qdict.h +++ b/include/qapi/qmp/qdict.h @@ -64,4 +64,7 @@ const char *qdict_get_try_str(const QDict *qdict, const c= har *key); =20 QDict *qdict_clone_shallow(const QDict *src); =20 +QObject *qdict_crumple(const QDict *src, Error **errp); +void qdict_flatten(QDict *qdict); + #endif /* QDICT_H */ diff --git a/include/qemu/option.h b/include/qemu/option.h index f73e0dc7d9..d89c66145a 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -149,5 +149,6 @@ QemuOptsList *qemu_opts_append(QemuOptsList *dst, QemuO= ptsList *list); =20 QDict *keyval_parse(const char *params, const char *implied_key, bool *help, Error **errp); +void keyval_merge(QDict *old, const QDict *new, Error **errp); =20 #endif diff --git a/softmmu/vl.c b/softmmu/vl.c index 598d064a8e..d60813770b 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -121,6 +121,7 @@ #include "qapi/qapi-commands-misc.h" #include "qapi/qapi-visit-qom.h" #include "qapi/qapi-commands-ui.h" +#include "qapi/qmp/qdict.h" #include "qapi/qmp/qerror.h" #include "sysemu/iothread.h" #include "qemu/guest-random.h" @@ -140,6 +141,14 @@ typedef struct ObjectOption { QTAILQ_ENTRY(ObjectOption) next; } ObjectOption; =20 +typedef struct KeyvalConfigEntry { + QDict *dict; + bool from_json; + QTAILQ_ENTRY(KeyvalConfigEntry) next; +} KeyvalConfigEntry; + +typedef QTAILQ_HEAD(, KeyvalConfigEntry) KeyvalConfigGroup; + static const char *cpu_option; static const char *mem_path; static const char *incoming; @@ -2115,13 +2124,98 @@ static int global_init_func(void *opaque, QemuOpts = *opts, Error **errp) return 0; } =20 +/* + * Return whether configuration group @group is stored in QemuOpts or + * in a list of QDicts. + */ +static bool is_qemuopts_group(const char *group) +{ + return true; +} + +/* + * Return a pointer to a list of QDicts, used to store options for + * "-set GROUP.*". + */ +static KeyvalConfigGroup *qemu_config_list(const char *group) +{ + return NULL; +} + +/* + * Return a pointer to a QDict inside the list starting at @head, + * used to store options for "-GROUP id=3D...". + */ +static KeyvalConfigEntry *qemu_find_config(KeyvalConfigGroup *head, const = char *id) +{ + KeyvalConfigEntry *e; + assert(id); + QTAILQ_FOREACH(e, head, next) { + if (g_strcmp0(qdict_get_try_str(e->dict, "id"), id) =3D=3D 0) { + return e; + } + } + return NULL; +} + +static void qemu_record_config_group(const char *group, QDict *dict, bool = from_json, Error **errp) +{ + KeyvalConfigGroup *head; + + head =3D qemu_config_list(group); + if (head) { + KeyvalConfigEntry *e =3D g_new(KeyvalConfigEntry, 1); + e->dict =3D dict; + e->from_json =3D from_json; + QTAILQ_INSERT_HEAD(head, e, next); + } else { + abort(); + } +} + +static void qemu_set_qdict_option(QDict *dict, const char *key, const char= *value, + Error **errp) +{ + QDict *merge_dict; + + merge_dict =3D qdict_new(); + qdict_put_str(merge_dict, key, value); + keyval_merge(dict, merge_dict, errp); + qobject_unref(merge_dict); +} + +/* + * Parse non-QemuOpts config file groups, pass the rest to + * qemu_config_do_parse. + */ +static void qemu_parse_config_group(const char *group, QDict *qdict, + void *opaque, Error **errp) +{ + QObject *crumpled; + if (is_qemuopts_group(group)) { + qemu_config_do_parse(group, qdict, opaque, errp); + return; + } + + crumpled =3D qdict_crumple(qdict, errp); + if (!crumpled) { + return; + } + if (qobject_type(crumpled) !=3D QTYPE_QDICT) { + assert(qobject_type(crumpled) =3D=3D QTYPE_QLIST); + error_setg(errp, "Lists cannot be at top level of a configuration = section"); + return; + } + qemu_record_config_group(group, qobject_to(QDict, crumpled), false, er= rp); +} + static void qemu_read_default_config_file(Error **errp) { ERRP_GUARD(); int ret; g_autofree char *file =3D get_relocated_path(CONFIG_QEMU_CONFDIR "/qem= u.conf"); =20 - ret =3D qemu_read_config_file(file, qemu_config_do_parse, errp); + ret =3D qemu_read_config_file(file, qemu_parse_config_group, errp); if (ret < 0) { if (ret =3D=3D -ENOENT) { error_free(*errp); @@ -2130,37 +2224,48 @@ static void qemu_read_default_config_file(Error **e= rrp) } } =20 -static int qemu_set_option(const char *str) +static void qemu_set_option(const char *str, Error **errp) { - Error *local_err =3D NULL; char group[64], id[64], arg[64]; QemuOptsList *list; QemuOpts *opts; + KeyvalConfigGroup *head; int rc, offset; =20 rc =3D sscanf(str, "%63[^.].%63[^.].%63[^=3D]%n", group, id, arg, &off= set); if (rc < 3 || str[offset] !=3D '=3D') { - error_report("can't parse: \"%s\"", str); - return -1; + error_setg(errp, "can't parse: \"%s\"", str); + return; } =20 - list =3D qemu_find_opts(group); - if (list =3D=3D NULL) { - return -1; + head =3D qemu_config_list(group); + if (head) { + KeyvalConfigEntry *e =3D qemu_find_config(head, id); + if (!e) { + goto not_found; + } + if (e->from_json) { + error_setg(errp, "cannot use -set with %s \"%s\" passed as JSO= N", group, id); + return; + } + qemu_set_qdict_option(e->dict, arg, str + offset + 1, errp); + return; } =20 - opts =3D qemu_opts_find(list, id); - if (!opts) { - error_report("there is no %s \"%s\" defined", - list->name, id); - return -1; + list =3D qemu_find_opts_err(group, errp); + if (list) { + opts =3D qemu_opts_find(list, id); + if (!opts) { + goto not_found; + } + qemu_opt_set(opts, arg, str + offset + 1, errp); + return; } =20 - if (!qemu_opt_set(opts, arg, str + offset + 1, &local_err)) { - error_report_err(local_err); - return -1; - } - return 0; + return; + +not_found: + error_setg(errp, "there is no %s \"%s\" defined", group, id); } =20 static void user_register_global_props(void) @@ -2737,8 +2842,7 @@ void qemu_init(int argc, char **argv, char **envp) } break; case QEMU_OPTION_set: - if (qemu_set_option(optarg) !=3D 0) - exit(1); + qemu_set_option(optarg, &error_fatal); break; case QEMU_OPTION_global: if (qemu_global_option(optarg) !=3D 0) @@ -3370,7 +3474,7 @@ void qemu_init(int argc, char **argv, char **envp) qemu_plugin_opt_parse(optarg, &plugin_list); break; case QEMU_OPTION_readconfig: - qemu_read_config_file(optarg, qemu_config_do_parse, &error= _fatal); + qemu_read_config_file(optarg, qemu_parse_config_group, &er= ror_fatal); break; case QEMU_OPTION_spice: olist =3D qemu_find_opts_err("spice", NULL); diff --git a/tests/unit/test-keyval.c b/tests/unit/test-keyval.c index e20c07cf3e..254b51e98c 100644 --- a/tests/unit/test-keyval.c +++ b/tests/unit/test-keyval.c @@ -747,6 +747,59 @@ static void test_keyval_visit_any(void) visit_free(v); } =20 +static void test_keyval_merge_success(void) +{ + QDict *old =3D keyval_parse("opt1=3Dabc,opt2.sub1=3Ddef,opt2.sub2=3Dgh= i,opt3=3Dxyz", + NULL, NULL, &error_abort); + QDict *new =3D keyval_parse("opt1=3DABC,opt2.sub2=3DGHI,opt2.sub3=3DJK= L", + NULL, NULL, &error_abort); + QDict *combined =3D keyval_parse("opt1=3DABC,opt2.sub1=3Ddef,opt2.sub2= =3DGHI,opt2.sub3=3DJKL,opt3=3Dxyz", + NULL, NULL, &error_abort); + Error *err =3D NULL; + + keyval_merge(old, new, &err); + g_assert(!err); + g_assert(qobject_is_equal(QOBJECT(combined), QOBJECT(old))); + qobject_unref(old); + qobject_unref(new); + qobject_unref(combined); +} + +static void test_keyval_merge_list(void) +{ + QDict *old =3D keyval_parse("opt1.0=3Dabc,opt2.0=3Dxyz", + NULL, NULL, &error_abort); + QDict *new =3D keyval_parse("opt1.0=3Ddef", + NULL, NULL, &error_abort); + QDict *combined =3D keyval_parse("opt1.0=3Dabc,opt1.1=3Ddef,opt2.0=3Dx= yz", + NULL, NULL, &error_abort); + Error *err =3D NULL; + + keyval_merge(old, new, &err); + g_assert(!err); + g_assert(qobject_is_equal(QOBJECT(combined), QOBJECT(old))); + qobject_unref(old); + qobject_unref(new); + qobject_unref(combined); +} + +static void test_keyval_merge_conflict(void) +{ + QDict *old =3D keyval_parse("opt2.sub1=3Ddef,opt2.sub2=3Dghi", + NULL, NULL, &error_abort); + QDict *new =3D keyval_parse("opt2=3DABC", + NULL, NULL, &error_abort); + Error *err =3D NULL; + + keyval_merge(new, old, &err); + error_free_or_abort(&err); + keyval_merge(old, new, &err); + error_free_or_abort(&err); + + qobject_unref(old); + qobject_unref(new); +} + int main(int argc, char *argv[]) { g_test_init(&argc, &argv, NULL); @@ -760,6 +813,9 @@ int main(int argc, char *argv[]) g_test_add_func("/keyval/visit/optional", test_keyval_visit_optional); g_test_add_func("/keyval/visit/alternate", test_keyval_visit_alternate= ); g_test_add_func("/keyval/visit/any", test_keyval_visit_any); + g_test_add_func("/keyval/merge/success", test_keyval_merge_success); + g_test_add_func("/keyval/merge/list", test_keyval_merge_list); + g_test_add_func("/keyval/merge/conflict", test_keyval_merge_conflict); g_test_run(); return 0; } diff --git a/util/keyval.c b/util/keyval.c index be34928813..0797f36e1d 100644 --- a/util/keyval.c +++ b/util/keyval.c @@ -310,6 +310,53 @@ static char *reassemble_key(GSList *key) return g_string_free(s, FALSE); } =20 +/* Merge two dictionaries. */ +static void keyval_do_merge(QDict *old, const QDict *new, GString *str, Er= ror **errp) +{ + size_t save_len =3D str->len; + const QDictEntry *ent; + QObject *old_value; + + for (ent =3D qdict_first(new); ent; ent =3D qdict_next(new, ent)) { + old_value =3D qdict_get(old, ent->key); + if (old_value) { + if (qobject_type(old_value) !=3D qobject_type(ent->value)) { + error_setg(errp, "Parameter '%s%s' used inconsistently", s= tr->str, ent->key); + return; + } else if (qobject_type(ent->value) =3D=3D QTYPE_QDICT) { + /* Merge sub-dictionaries. */ + g_string_append(str, ent->key); + g_string_append_c(str, '.'); + keyval_do_merge(qobject_to(QDict, old_value), + qobject_to(QDict, ent->value), + str, errp); + g_string_truncate(str, save_len); + continue; + } else if (qobject_type(ent->value) =3D=3D QTYPE_QLIST) { + /* Append to old list. */ + QList *old =3D qobject_to(QList, old_value); + QList *new =3D qobject_to(QList, ent->value); + const QListEntry *item; + QLIST_FOREACH_ENTRY(new, item) { + qobject_ref(item->value); + qlist_append_obj(old, item->value); + } + continue; + } + } + + qobject_ref(ent->value); + qdict_put_obj(old, ent->key, ent->value); + } +} + +void keyval_merge(QDict *old, const QDict *new, Error **errp) +{ + GString *str =3D g_string_new(""); + keyval_do_merge(old, new, str, errp); + g_string_free(str, TRUE); +} + /* * Listify @cur recursively. * Replace QDicts whose keys are all valid list indexes by QLists. --=20 2.26.2 From nobody Fri May 10 11:48:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1620923819; cv=none; d=zohomail.com; s=zohoarc; b=LIO+GyJyvEf8ZYGx0pjqcT4EBkEnvd+SrfL2YT0dD/lVkMemUUnPxfyXp1SsqPNqqpwqjHJEYqIc9/4dKgbQgN4+z5rHBUFQkyYEPx7HNfWHw+KAuqIo1r1RWkY00IqiUacH6lE65Kr+XfYngXkovYS7vUYKtbC8KCrFKOUDcOw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620923819; 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=7g70nuBGmoRsJSYKRsOXvNdwmWUuMa/hG3dgdNxQcvg=; b=E7YNvh8TzKO3pqsy15xR8aoYADCcz+KfHDjxQ/79p962uPDRSLlf9uQArpUosGYYiBnT11sh8BkwPPQ3XvfBfwaMlcMCttDGIEwYM+eSH7MEGR5QxBOKi5QmCTYcxzBHfHN/ChVSjVtTVx77tGlQw9HWCAQ9ISfKhGspz+/0ZJA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620923819138286.5078800754151; Thu, 13 May 2021 09:36:59 -0700 (PDT) Received: from localhost ([::1]:40424 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lhEKX-0007MA-3Z for importer@patchew.org; Thu, 13 May 2021 12:36:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40574) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhEDB-0002LT-Hs for qemu-devel@nongnu.org; Thu, 13 May 2021 12:29:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:43251) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhED0-0003RK-Aw for qemu-devel@nongnu.org; Thu, 13 May 2021 12:29:20 -0400 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-460-5xeI1KbpO5Kzkbvt3R--yQ-1; Thu, 13 May 2021 12:29:06 -0400 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 47E8D1005D51; Thu, 13 May 2021 16:29:05 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id CEA6B687D7; Thu, 13 May 2021 16:29:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620923348; h=from:from: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; bh=7g70nuBGmoRsJSYKRsOXvNdwmWUuMa/hG3dgdNxQcvg=; b=Onl8X6jNxWQ7YGbgYRq7Uon00MQJt249RXqfGWCxxc1vjwNTNZRYStHyxS0NZlPLjZFOM8 z6Q5dBN5YXHJ3UV9wTtlY/Xirph3qibeJY2OyIO9F4eJoQWW6er0oeI7SFNdcEgJpU1sjp xAG/My3G+jTGv/qHraICwYFoQE1Bkpk= X-MC-Unique: 5xeI1KbpO5Kzkbvt3R--yQ-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 04/14] qom: export more functions for use with non-UserCreatable objects Date: Thu, 13 May 2021 12:28:51 -0400 Message-Id: <20210513162901.1310239-5-pbonzini@redhat.com> In-Reply-To: <20210513162901.1310239-1-pbonzini@redhat.com> References: <20210513162901.1310239-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yang.zhong@intel.com, berrange@redhat.com, ehabkost@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Machines and accelerators are not user-creatable but they are going to share similar command-line parsing machinery. Export functions that will be used with -machine and -accel in softmmu/vl.c. Signed-off-by: Paolo Bonzini --- include/qom/object.h | 23 ++++++++++++++++ qom/object_interfaces.c | 58 +++++++++++++++++++++++++++++------------ 2 files changed, 65 insertions(+), 16 deletions(-) diff --git a/include/qom/object.h b/include/qom/object.h index 6721cd312e..faae0d841f 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -861,6 +861,29 @@ static void do_qemu_init_ ## type_array(void) = \ } = \ type_init(do_qemu_init_ ## type_array) =20 +/** + * type_print_class_properties: + * @type: a QOM class name + * + * Print the object's class properties to stdout or the monitor. + * Return whether an object was found. + */ +bool type_print_class_properties(const char *type); + +/** + * object_set_properties_from_keyval: + * @obj: a QOM object + * @qdict: a dictionary with the properties to be set + * @from_json: true if leaf values of @qdict are typed, false if they + * are strings + * @errp: pointer to error object + * + * For each key in the dictionary, parse the value string if needed, + * then set the corresponding property in @obj. + */ +void object_set_properties_from_keyval(Object *obj, const QDict *qdict, + bool from_json, Error **errp); + /** * object_class_dynamic_cast_assert: * @klass: The #ObjectClass to attempt to cast. diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c index 4479ee693a..ad9b56b59a 100644 --- a/qom/object_interfaces.c +++ b/qom/object_interfaces.c @@ -42,6 +42,44 @@ bool user_creatable_can_be_deleted(UserCreatable *uc) } } =20 +static void object_set_properties_from_qdict(Object *obj, const QDict *qdi= ct, + Visitor *v, Error **errp) +{ + const QDictEntry *e; + Error *local_err =3D NULL; + + if (!visit_start_struct(v, NULL, NULL, 0, &local_err)) { + goto out; + } + for (e =3D qdict_first(qdict); e; e =3D qdict_next(qdict, e)) { + if (!object_property_set(obj, e->key, v, &local_err)) { + break; + } + } + if (!local_err) { + visit_check_struct(v, &local_err); + } + visit_end_struct(v, NULL); + +out: + if (local_err) { + error_propagate(errp, local_err); + } +} + +void object_set_properties_from_keyval(Object *obj, const QDict *qdict, + bool from_json, Error **errp) +{ + Visitor *v; + if (from_json) { + v =3D qobject_input_visitor_new(QOBJECT(qdict)); + } else { + v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); + } + object_set_properties_from_qdict(obj, qdict, v, errp); + visit_free(v); +} + Object *user_creatable_add_type(const char *type, const char *id, const QDict *qdict, Visitor *v, Error **errp) @@ -49,7 +87,6 @@ Object *user_creatable_add_type(const char *type, const c= har *id, ERRP_GUARD(); Object *obj; ObjectClass *klass; - const QDictEntry *e; Error *local_err =3D NULL; =20 if (id !=3D NULL && !id_wellformed(id)) { @@ -78,18 +115,7 @@ Object *user_creatable_add_type(const char *type, const= char *id, =20 assert(qdict); obj =3D object_new(type); - if (!visit_start_struct(v, NULL, NULL, 0, &local_err)) { - goto out; - } - for (e =3D qdict_first(qdict); e; e =3D qdict_next(qdict, e)) { - if (!object_property_set(obj, e->key, v, &local_err)) { - break; - } - } - if (!local_err) { - visit_check_struct(v, &local_err); - } - visit_end_struct(v, NULL); + object_set_properties_from_qdict(obj, qdict, v, &local_err); if (local_err) { goto out; } @@ -178,7 +204,7 @@ static void user_creatable_print_types(void) g_slist_free(list); } =20 -static bool user_creatable_print_type_properites(const char *type) +bool type_print_class_properties(const char *type) { ObjectClass *klass; ObjectPropertyIterator iter; @@ -224,7 +250,7 @@ bool user_creatable_print_help(const char *type, QemuOp= ts *opts) } =20 if (qemu_opt_has_help_opt(opts)) { - return user_creatable_print_type_properites(type); + return type_print_class_properties(type); } =20 return false; @@ -234,7 +260,7 @@ static void user_creatable_print_help_from_qdict(QDict = *args) { const char *type =3D qdict_get_try_str(args, "qom-type"); =20 - if (!type || !user_creatable_print_type_properites(type)) { + if (!type || !type_print_class_properties(type)) { user_creatable_print_types(); } } --=20 2.26.2 From nobody Fri May 10 11:48:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1620923671; cv=none; d=zohomail.com; s=zohoarc; b=kVUfudomfsgexwYtqbHEspzmvi2Kco20FBFIh4B0L4+nRTa0VZR1fwSJGmEy9ig2D0nrkox1BA4MraLJh0BlusZasOox9eSrlzO0+K+jPkl/2jG8/X1QHbqsXFllzfYpIOKP7kYtu+4cllSH25shSxkoyPoHT8TBCCxwPHqYrE4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620923671; 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=zbEmGkmDmj9pMtxlajDGAZWEB04zSWltDUEbzYiGquE=; b=gIxUi4QJGZmGO+KHYZtUL8BKynIMhOgw5S1U6kHvgzkiK8ZQimc9tR8tIeUKcMZYjz2yZbNIisqcDHHbemOo+8aZP6kSPxTa3I9de9r9FxHoVqRHmQJkHQ0l5HbC1ybzelIMNMhZp0a44vZZir/o8a4bu/qiExVbl/yEVhjoQ+8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620923671955643.5324780171345; Thu, 13 May 2021 09:34:31 -0700 (PDT) Received: from localhost ([::1]:60986 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lhEIA-0002GA-2y for importer@patchew.org; Thu, 13 May 2021 12:34:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40500) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhED4-0002IN-Ma for qemu-devel@nongnu.org; Thu, 13 May 2021 12:29:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:57220) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhED2-0003Sb-Aq for qemu-devel@nongnu.org; Thu, 13 May 2021 12:29:14 -0400 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-120-HLo54g2gPOGiRN3efDXFdg-1; Thu, 13 May 2021 12:29:09 -0400 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 E44711005D4E; Thu, 13 May 2021 16:29:08 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 60ED3687D7; Thu, 13 May 2021 16:29:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620923351; h=from:from: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; bh=zbEmGkmDmj9pMtxlajDGAZWEB04zSWltDUEbzYiGquE=; b=PLkGeQjWglnPY9ps57VpnGiJvdmxA/ER7MibhLr5zXZ0pQp+MRmUYya2sOEleKs5nfgjO/ o7PjNd+Ur0MgkVi0H92OGvcVMqHf2uCuz51LLVY28F7YIw6Z8vVRdGy1IDeSDSeZHKLaVw ZJhW1odmxxtsDtl0WFbwgAiQaMJx4sg= X-MC-Unique: HLo54g2gPOGiRN3efDXFdg-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 05/14] keyval: introduce keyval_parse_into Date: Thu, 13 May 2021 12:28:52 -0400 Message-Id: <20210513162901.1310239-6-pbonzini@redhat.com> In-Reply-To: <20210513162901.1310239-1-pbonzini@redhat.com> References: <20210513162901.1310239-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yang.zhong@intel.com, berrange@redhat.com, ehabkost@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Allow parsing multiple keyval sequences into the same dictionary. This will be used to simplify the parsing of the -M command line option, which is currently a .merge_lists =3D true QemuOpts group. Signed-off-by: Paolo Bonzini --- include/qemu/option.h | 2 ++ util/keyval.c | 43 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/include/qemu/option.h b/include/qemu/option.h index d89c66145a..fffb03d848 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -147,6 +147,8 @@ void qemu_opts_print_help(QemuOptsList *list, bool prin= t_caption); void qemu_opts_free(QemuOptsList *list); QemuOptsList *qemu_opts_append(QemuOptsList *dst, QemuOptsList *list); =20 +QDict *keyval_parse_into(QDict *qdict, const char *params, const char *imp= lied_key, + bool *p_help, Error **errp); QDict *keyval_parse(const char *params, const char *implied_key, bool *help, Error **errp); void keyval_merge(QDict *old, const QDict *new, Error **errp); diff --git a/util/keyval.c b/util/keyval.c index 0797f36e1d..1ffd6e1204 100644 --- a/util/keyval.c +++ b/util/keyval.c @@ -478,13 +478,14 @@ static QObject *keyval_listify(QDict *cur, GSList *ke= y_of_cur, Error **errp) * If @p_help is not NULL, store whether help is requested there. * If @p_help is NULL and help is requested, fail. * - * On success, return a dictionary of the parsed keys and values. - * On failure, store an error through @errp and return NULL. + * On success, return @dict, now filled with the parsed keys and values. + * + * On failure, store an error through @errp and return NULL. Any keys + * and values parsed so far will be in @dict nevertheless. */ -QDict *keyval_parse(const char *params, const char *implied_key, - bool *p_help, Error **errp) +QDict *keyval_parse_into(QDict *qdict, const char *params, const char *imp= lied_key, + bool *p_help, Error **errp) { - QDict *qdict =3D qdict_new(); QObject *listified; const char *s; bool help =3D false; @@ -493,7 +494,6 @@ QDict *keyval_parse(const char *params, const char *imp= lied_key, while (*s) { s =3D keyval_parse_one(qdict, s, implied_key, &help, errp); if (!s) { - qobject_unref(qdict); return NULL; } implied_key =3D NULL; @@ -503,15 +503,42 @@ QDict *keyval_parse(const char *params, const char *i= mplied_key, *p_help =3D help; } else if (help) { error_setg(errp, "Help is not available for this option"); - qobject_unref(qdict); return NULL; } =20 listified =3D keyval_listify(qdict, NULL, errp); if (!listified) { - qobject_unref(qdict); return NULL; } assert(listified =3D=3D QOBJECT(qdict)); return qdict; } + +/* + * Parse @params in QEMU's traditional KEY=3DVALUE,... syntax. + * + * If @implied_key, the first KEY=3D can be omitted. @implied_key is + * implied then, and VALUE can't be empty or contain ',' or '=3D'. + * + * A parameter "help" or "?" without a value isn't added to the + * resulting dictionary, but instead is interpreted as help request. + * All other options are parsed and returned normally so that context + * specific help can be printed. + * + * If @p_help is not NULL, store whether help is requested there. + * If @p_help is NULL and help is requested, fail. + * + * On success, return a dictionary of the parsed keys and values. + * On failure, store an error through @errp and return NULL. + */ +QDict *keyval_parse(const char *params, const char *implied_key, + bool *p_help, Error **errp) +{ + QDict *qdict =3D qdict_new(); + QDict *ret =3D keyval_parse_into(qdict, params, implied_key, p_help, e= rrp); + + if (!ret) { + qobject_unref(qdict); + } + return ret; +} --=20 2.26.2 From nobody Fri May 10 11:48:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1620924539; cv=none; d=zohomail.com; s=zohoarc; b=C1QUuxrbwVrjdFzzX4hUvY4X4rX6XBbeqwhV7ccqUcTTYPe6O8I/tAE2A6pOuQPy6ehCE5FKEZufu5QUW6Ir0y0qQ4sQKLTtGHX559bf2zg7vdXVmO6c0vPHjIff/vmCEenLRHrvUFeI26Gfl4Wr9OKHyUr+Yh7EFWhiA8srRcc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620924539; 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=AvGxY0OzzCfUeGQa5UQELjRvnfc8YxWD5ul+vHGJVMQ=; b=NuLV8jnxm2wQlmLwryKL5u4Z8SefZzrjhVw+lSj1zzkV8oA7I0yiXaYQxwz2W114S+JzseHy4P5XkPsluviKCPd6ZVUfvysIcMZYWclUCa8DvBpVqJhURVPl3yh23z3EkEIOxq+HYeYvr5kjrYdgVmBKM64mUtlM+zrd5HqzJSc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620924539474443.77030376048276; Thu, 13 May 2021 09:48:59 -0700 (PDT) Received: from localhost ([::1]:58006 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lhEW9-00032R-RT for importer@patchew.org; Thu, 13 May 2021 12:48:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40616) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhEDF-0002Q1-E9 for qemu-devel@nongnu.org; Thu, 13 May 2021 12:29:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:23380) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhED3-0003Ss-FT for qemu-devel@nongnu.org; Thu, 13 May 2021 12:29:25 -0400 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-284-G03aQn2YOOaMQKBTjtuX-g-1; Thu, 13 May 2021 12:29:10 -0400 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 787058005AD; Thu, 13 May 2021 16:29:09 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0AE8B687C3; Thu, 13 May 2021 16:29:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620923352; h=from:from: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; bh=AvGxY0OzzCfUeGQa5UQELjRvnfc8YxWD5ul+vHGJVMQ=; b=eg2lI7U1AOKX0G/7s1AoEJLaesNmfcJbcIugW17LJeYoAtrJgbMT2gzqGUPKg+e9gESWBK EWmmAWNvXloP2Tdk1Hy4KLfnqCRuOcmNd5gAddprHEUzkhlyPEBk0wxwuTDBdxiT66jhe2 M+RNAaSHHOQ2S/ul1KHOaB5J/eQDREU= X-MC-Unique: G03aQn2YOOaMQKBTjtuX-g-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 06/14] vl: switch -M parsing to keyval Date: Thu, 13 May 2021 12:28:53 -0400 Message-Id: <20210513162901.1310239-7-pbonzini@redhat.com> In-Reply-To: <20210513162901.1310239-1-pbonzini@redhat.com> References: <20210513162901.1310239-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yang.zhong@intel.com, berrange@redhat.com, ehabkost@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Switch from QemuOpts to keyval. This enables the introduction of non-scalar machine properties, and JSON syntax in the future. For JSON syntax to be supported right now, we would have to consider what would happen if string-based dictionaries (produced by -M key=3Dval) were to be merged with strongly-typed dictionaries (produced by -M {'key': 123}). The simplest way out is to never enter the situation, and only allow one -M option when JSON syntax is in use. However, we want options such as -smp to become syntactic sugar for -M, and this is a problem; as soon as -smp becomes a shortcut for -M, QEMU would forbid using -M '{....}' together with -smp. Therefore, allowing JSON syntax right now for -M would be a forward-compatibility nightmare and it would be impossible anyway to introduce -M incrementally in tools. Instead, support for JSON syntax is delayed until after the main options are converted to QOM compound properties. These include -boot, -acpitable, -smbios, -m, -semihosting-config, -rtc and -fw_cfg. Once JSON syntax is introduced, these options will _also_ be forbidden together with -M '{...}'. Signed-off-by: Paolo Bonzini --- softmmu/vl.c | 303 ++++++++++++++++++++++++--------------------------- 1 file changed, 141 insertions(+), 162 deletions(-) diff --git a/softmmu/vl.c b/softmmu/vl.c index d60813770b..6b670fb301 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -153,6 +153,8 @@ static const char *cpu_option; static const char *mem_path; static const char *incoming; static const char *loadvm; +static const char *accelerators; +static QDict *machine_opts_dict; static QTAILQ_HEAD(, ObjectOption) object_opts =3D QTAILQ_HEAD_INITIALIZER= (object_opts); static ram_addr_t maxram_size; static uint64_t ram_slots; @@ -243,21 +245,6 @@ static QemuOptsList qemu_option_rom_opts =3D { }, }; =20 -static QemuOptsList qemu_machine_opts =3D { - .name =3D "machine", - .implied_opt_name =3D "type", - .merge_lists =3D true, - .head =3D QTAILQ_HEAD_INITIALIZER(qemu_machine_opts.head), - .desc =3D { - /* - * no elements =3D> accept any - * sanity checking will happen later - * when setting machine properties - */ - { } - }, -}; - static QemuOptsList qemu_accel_opts =3D { .name =3D "accel", .implied_opt_name =3D "accel", @@ -506,16 +493,6 @@ static QemuOptsList qemu_action_opts =3D { }, }; =20 -/** - * Get machine options - * - * Returns: machine options (never null). - */ -static QemuOpts *qemu_get_machine_opts(void) -{ - return qemu_find_opts_singleton("machine"); -} - const char *qemu_get_vm_name(void) { return qemu_name; @@ -823,33 +800,6 @@ static MachineClass *find_default_machine(GSList *mach= ines) return default_machineclass; } =20 -static int machine_help_func(QemuOpts *opts, MachineState *machine) -{ - ObjectProperty *prop; - ObjectPropertyIterator iter; - - if (!qemu_opt_has_help_opt(opts)) { - return 0; - } - - object_property_iter_init(&iter, OBJECT(machine)); - while ((prop =3D object_property_iter_next(&iter))) { - if (!prop->set) { - continue; - } - - printf("%s.%s=3D%s", MACHINE_GET_CLASS(machine)->name, - prop->name, prop->type); - if (prop->description) { - printf(" (%s)\n", prop->description); - } else { - printf("\n"); - } - } - - return 1; -} - static void version(void) { printf("QEMU emulator version " QEMU_FULL_VERSION "\n" @@ -1540,33 +1490,31 @@ static gint machine_class_cmp(gconstpointer a, gcon= stpointer b) object_class_get_name(OBJECT_CLASS(mc1))); } =20 -static MachineClass *machine_parse(const char *name, GSList *machines) +static void machine_help_func(const QDict *qdict) { - MachineClass *mc; - GSList *el; + GSList *machines, *el; + const char *type =3D qdict_get_try_str(qdict, "type"); =20 - if (is_help_option(name)) { - printf("Supported machines are:\n"); - machines =3D g_slist_sort(machines, machine_class_cmp); - for (el =3D machines; el; el =3D el->next) { - MachineClass *mc =3D el->data; - if (mc->alias) { - printf("%-20s %s (alias of %s)\n", mc->alias, mc->desc, mc= ->name); - } - printf("%-20s %s%s%s\n", mc->name, mc->desc, - mc->is_default ? " (default)" : "", - mc->deprecation_reason ? " (deprecated)" : ""); + machines =3D object_class_get_list(TYPE_MACHINE, false); + if (type) { + ObjectClass *machine_class =3D OBJECT_CLASS(find_machine(type, mac= hines)); + if (machine_class) { + type_print_class_properties(object_class_get_name(machine_clas= s)); + return; } - exit(0); } =20 - mc =3D find_machine(name, machines); - if (!mc) { - error_report("unsupported machine type"); - error_printf("Use -machine help to list supported machines\n"); - exit(1); + printf("Supported machines are:\n"); + machines =3D g_slist_sort(machines, machine_class_cmp); + for (el =3D machines; el; el =3D el->next) { + MachineClass *mc =3D el->data; + if (mc->alias) { + printf("%-20s %s (alias of %s)\n", mc->alias, mc->desc, mc->na= me); + } + printf("%-20s %s%s%s\n", mc->name, mc->desc, + mc->is_default ? " (default)" : "", + mc->deprecation_reason ? " (deprecated)" : ""); } - return mc; } =20 static const char *pid_file; @@ -1619,32 +1567,31 @@ static const QEMUOption *lookup_opt(int argc, char = **argv, return popt; } =20 -static MachineClass *select_machine(void) +static MachineClass *select_machine(QDict *qdict, Error **errp) { + const char *optarg =3D qdict_get_try_str(qdict, "type"); GSList *machines =3D object_class_get_list(TYPE_MACHINE, false); - MachineClass *machine_class =3D find_default_machine(machines); - const char *optarg; - QemuOpts *opts; - Location loc; - - loc_push_none(&loc); - - opts =3D qemu_get_machine_opts(); - qemu_opts_loc_restore(opts); + MachineClass *machine_class; + Error *local_err =3D NULL; =20 - optarg =3D qemu_opt_get(opts, "type"); if (optarg) { - machine_class =3D machine_parse(optarg, machines); - } - - if (!machine_class) { - error_report("No machine specified, and there is no default"); - error_printf("Use -machine help to list supported machines\n"); - exit(1); + machine_class =3D find_machine(optarg, machines); + qdict_del(qdict, "type"); + if (!machine_class) { + error_setg(&local_err, "unsupported machine type"); + } + } else { + machine_class =3D find_default_machine(machines); + if (!machine_class) { + error_setg(&local_err, "No machine specified, and there is no = default"); + } } =20 - loc_pop(&loc); g_slist_free(machines); + if (local_err) { + error_append_hint(&local_err, "Use -machine help to list supported= machines\n"); + error_propagate(errp, local_err); + } return machine_class; } =20 @@ -1663,42 +1610,70 @@ static int object_parse_property_opt(Object *obj, return 0; } =20 -static int machine_set_property(void *opaque, - const char *name, const char *value, - Error **errp) +/* *Non*recursively replace underscores with dashes in QDict keys. */ +static void keyval_dashify(QDict *qdict, Error **errp) { - g_autofree char *qom_name =3D g_strdup(name); + const QDictEntry *ent, *next; char *p; =20 - for (p =3D qom_name; *p; p++) { - if (*p =3D=3D '_') { - *p =3D '-'; + for (ent =3D qdict_first(qdict); ent; ent =3D next) { + g_autofree char *new_key =3D NULL; + + next =3D qdict_next(qdict, ent); + if (!strchr(ent->key, '_')) { + continue; + } + new_key =3D g_strdup(ent->key); + for (p =3D new_key; *p; p++) { + if (*p =3D=3D '_') { + *p =3D '-'; + } } + if (qdict_haskey(qdict, new_key)) { + error_setg(errp, "Conflict between '%s' and '%s'", ent->key, n= ew_key); + return; + } + qobject_ref(ent->value); + qdict_put_obj(qdict, new_key, ent->value); + qdict_del(qdict, ent->key); } +} + +static void qemu_apply_legacy_machine_options(QDict *qdict) +{ + const char *value; + + keyval_dashify(qdict, &error_fatal); =20 /* Legacy options do not correspond to MachineState properties. */ - if (g_str_equal(qom_name, "accel")) { - return 0; + value =3D qdict_get_try_str(qdict, "accel"); + if (value) { + accelerators =3D g_strdup(value); + qdict_del(qdict, "accel"); } - if (g_str_equal(qom_name, "igd-passthru")) { - object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), qom_name, valu= e, + + value =3D qdict_get_try_str(qdict, "igd-passthru"); + if (value) { + object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), "igd-passthru"= , value, false); - return 0; + qdict_del(qdict, "igd-passthru"); } - if (g_str_equal(qom_name, "kvm-shadow-mem")) { - object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), qom_name, valu= e, + + value =3D qdict_get_try_str(qdict, "kvm-shadow-mem"); + if (value) { + object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), "kvm-shadow-me= m", value, false); - return 0; + qdict_del(qdict, "kvm-shadow-mem"); } - if (g_str_equal(qom_name, "kernel-irqchip")) { - object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), qom_name, valu= e, + + value =3D qdict_get_try_str(qdict, "kernel-irqchip"); + if (value) { + object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), "kernel-irqchi= p", value, false); - object_register_sugar_prop(ACCEL_CLASS_NAME("whpx"), qom_name, val= ue, + object_register_sugar_prop(ACCEL_CLASS_NAME("whpx"), "kernel-irqch= ip", value, false); - return 0; + qdict_del(qdict, "kernel-irqchip"); } - - return object_parse_property_opt(opaque, name, value, "type", errp); } =20 static void object_option_foreach_add(bool (*type_opt_predicate)(const cha= r *)) @@ -1810,16 +1785,14 @@ static bool object_create_early(const char *type) return true; } =20 -static void qemu_apply_machine_options(void) +static void qemu_apply_machine_options(QDict *qdict) { MachineClass *machine_class =3D MACHINE_GET_CLASS(current_machine); - QemuOpts *machine_opts =3D qemu_get_machine_opts(); const char *boot_order =3D NULL; const char *boot_once =3D NULL; QemuOpts *opts; =20 - qemu_opt_foreach(machine_opts, machine_set_property, current_machine, - &error_fatal); + object_set_properties_from_keyval(OBJECT(current_machine), qdict, fals= e, &error_fatal); current_machine->ram_size =3D ram_size; current_machine->maxram_size =3D maxram_size; current_machine->ram_slots =3D ram_slots; @@ -1848,10 +1821,8 @@ static void qemu_apply_machine_options(void) current_machine->boot_once =3D boot_once; =20 if (semihosting_enabled() && !semihosting_get_argc()) { - const char *kernel_filename =3D qemu_opt_get(machine_opts, "kernel= "); - const char *kernel_cmdline =3D qemu_opt_get(machine_opts, "append"= ) ?: ""; /* fall back to the -kernel/-append */ - semihosting_arg_fallback(kernel_filename, kernel_cmdline); + semihosting_arg_fallback(current_machine->kernel_filename, current= _machine->kernel_cmdline); } } =20 @@ -1898,8 +1869,7 @@ static void qemu_create_early_backends(void) =20 /* * Note: we need to create audio and block backends before - * machine_set_property(), so machine properties can refer to - * them. + * setting machine properties, so they can be referred to. */ configure_blockdev(&bdo_queue, machine_class, snapshot); audio_init_audiodevs(); @@ -2067,16 +2037,14 @@ static void set_memory_options(MachineClass *mc) loc_pop(&loc); } =20 -static void qemu_create_machine(MachineClass *machine_class) +static void qemu_create_machine(QDict *qdict) { + MachineClass *machine_class =3D select_machine(qdict, &error_fatal); object_set_machine_compat_props(machine_class->compat_props); =20 set_memory_options(machine_class); =20 current_machine =3D MACHINE(object_new_with_class(OBJECT_CLASS(machine= _class))); - if (machine_help_func(qemu_get_machine_opts(), current_machine)) { - exit(0); - } object_property_add_child(object_get_root(), "machine", OBJECT(current_machine)); object_property_add_child(container_get(OBJECT(current_machine), @@ -2107,8 +2075,12 @@ static void qemu_create_machine(MachineClass *machin= e_class) * specified either by the configuration file or by the command line. */ if (machine_class->default_machine_opts) { - qemu_opts_set_defaults(qemu_find_opts("machine"), - machine_class->default_machine_opts, 0); + QDict *default_opts =3D + keyval_parse(machine_class->default_machine_opts, NULL, NULL, + &error_abort); + object_set_properties_from_keyval(OBJECT(current_machine), default= _opts, + false, &error_abort); + qobject_unref(default_opts); } } =20 @@ -2130,6 +2102,9 @@ static int global_init_func(void *opaque, QemuOpts *o= pts, Error **errp) */ static bool is_qemuopts_group(const char *group) { + if (g_str_equal(group, "machine")) { + return false; + } return true; } =20 @@ -2168,6 +2143,13 @@ static void qemu_record_config_group(const char *gro= up, QDict *dict, bool from_j e->dict =3D dict; e->from_json =3D from_json; QTAILQ_INSERT_HEAD(head, e, next); + } else if (g_str_equal(group, "machine")) { + /* + * Cannot merge string-valued and type-safe dictionaries, so JSON + * is not accepted yet for -M. + */ + assert(!from_json); + keyval_merge(machine_opts_dict, dict, errp); } else { abort(); } @@ -2325,13 +2307,11 @@ static int do_configure_accelerator(void *opaque, Q= emuOpts *opts, Error **errp) =20 static void configure_accelerators(const char *progname) { - const char *accelerators; bool init_failed =3D false; =20 qemu_opts_foreach(qemu_find_opts("icount"), do_configure_icount, NULL, &error_fatal); =20 - accelerators =3D qemu_opt_get(qemu_get_machine_opts(), "accel"); if (QTAILQ_EMPTY(&qemu_accel_opts.head)) { char **accel_list, **tmp; =20 @@ -2419,12 +2399,11 @@ static void create_default_memdev(MachineState *ms,= const char *path) &error_fatal); } =20 -static void qemu_validate_options(void) +static void qemu_validate_options(const QDict *machine_opts) { - QemuOpts *machine_opts =3D qemu_get_machine_opts(); - const char *kernel_filename =3D qemu_opt_get(machine_opts, "kernel"); - const char *initrd_filename =3D qemu_opt_get(machine_opts, "initrd"); - const char *kernel_cmdline =3D qemu_opt_get(machine_opts, "append"); + const char *kernel_filename =3D qdict_get_try_str(machine_opts, "kerne= l"); + const char *initrd_filename =3D qdict_get_try_str(machine_opts, "initr= d"); + const char *kernel_cmdline =3D qdict_get_try_str(machine_opts, "append= "); =20 if (kernel_filename =3D=3D NULL) { if (kernel_cmdline !=3D NULL) { @@ -2747,7 +2726,6 @@ void qemu_init(int argc, char **argv, char **envp) qemu_add_opts(&qemu_trace_opts); qemu_plugin_add_opts(); qemu_add_opts(&qemu_option_rom_opts); - qemu_add_opts(&qemu_machine_opts); qemu_add_opts(&qemu_accel_opts); qemu_add_opts(&qemu_mem_opts); qemu_add_opts(&qemu_smp_opts); @@ -2788,6 +2766,7 @@ void qemu_init(int argc, char **argv, char **envp) } } =20 + machine_opts_dict =3D qdict_new(); if (userconfig) { qemu_read_default_config_file(&error_fatal); } @@ -2877,8 +2856,7 @@ void qemu_init(int argc, char **argv, char **envp) parse_display(optarg); break; case QEMU_OPTION_nographic: - olist =3D qemu_find_opts("machine"); - qemu_opts_parse_noisily(olist, "graphics=3Doff", false); + qdict_put_str(machine_opts_dict, "graphics", "off"); nographic =3D true; dpy.type =3D DISPLAY_TYPE_NONE; break; @@ -2902,16 +2880,16 @@ void qemu_init(int argc, char **argv, char **envp) } break; case QEMU_OPTION_kernel: - qemu_opts_set(qemu_find_opts("machine"), "kernel", optarg,= &error_abort); + qdict_put_str(machine_opts_dict, "kernel", optarg); break; case QEMU_OPTION_initrd: - qemu_opts_set(qemu_find_opts("machine"), "initrd", optarg,= &error_abort); + qdict_put_str(machine_opts_dict, "initrd", optarg); break; case QEMU_OPTION_append: - qemu_opts_set(qemu_find_opts("machine"), "append", optarg,= &error_abort); + qdict_put_str(machine_opts_dict, "append", optarg); break; case QEMU_OPTION_dtb: - qemu_opts_set(qemu_find_opts("machine"), "dtb", optarg, &e= rror_abort); + qdict_put_str(machine_opts_dict, "dtb", optarg); break; case QEMU_OPTION_cdrom: drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS); @@ -3021,7 +2999,7 @@ void qemu_init(int argc, char **argv, char **envp) } break; case QEMU_OPTION_bios: - qemu_opts_set(qemu_find_opts("machine"), "firmware", optar= g, &error_abort); + qdict_put_str(machine_opts_dict, "firmware", optarg); break; case QEMU_OPTION_singlestep: singlestep =3D 1; @@ -3290,17 +3268,20 @@ void qemu_init(int argc, char **argv, char **envp) preconfig_requested =3D true; break; case QEMU_OPTION_enable_kvm: - olist =3D qemu_find_opts("machine"); - qemu_opts_parse_noisily(olist, "accel=3Dkvm", false); + qdict_put_str(machine_opts_dict, "accel", "kvm"); break; case QEMU_OPTION_M: case QEMU_OPTION_machine: - olist =3D qemu_find_opts("machine"); - opts =3D qemu_opts_parse_noisily(olist, optarg, true); - if (!opts) { - exit(1); + { + bool help; + + keyval_parse_into(machine_opts_dict, optarg, "type", &= help, &error_fatal); + if (help) { + machine_help_func(machine_opts_dict); + exit(EXIT_SUCCESS); + } + break; } - break; case QEMU_OPTION_accel: accel_opts =3D qemu_opts_parse_noisily(qemu_find_opts("acc= el"), optarg, true); @@ -3327,12 +3308,10 @@ void qemu_init(int argc, char **argv, char **envp) } break; case QEMU_OPTION_usb: - olist =3D qemu_find_opts("machine"); - qemu_opts_parse_noisily(olist, "usb=3Don", false); + qdict_put_str(machine_opts_dict, "usb", "on"); break; case QEMU_OPTION_usbdevice: - olist =3D qemu_find_opts("machine"); - qemu_opts_parse_noisily(olist, "usb=3Don", false); + qdict_put_str(machine_opts_dict, "usb", "on"); add_device_config(DEV_USB, optarg); break; case QEMU_OPTION_device: @@ -3351,12 +3330,10 @@ void qemu_init(int argc, char **argv, char **envp) vnc_parse(optarg); break; case QEMU_OPTION_no_acpi: - olist =3D qemu_find_opts("machine"); - qemu_opts_parse_noisily(olist, "acpi=3Doff", false); + qdict_put_str(machine_opts_dict, "acpi", "off"); break; case QEMU_OPTION_no_hpet: - olist =3D qemu_find_opts("machine"); - qemu_opts_parse_noisily(olist, "hpet=3Doff", false); + qdict_put_str(machine_opts_dict, "hpet", "off"); break; case QEMU_OPTION_no_reboot: olist =3D qemu_find_opts("action"); @@ -3593,7 +3570,7 @@ void qemu_init(int argc, char **argv, char **envp) */ loc_set_none(); =20 - qemu_validate_options(); + qemu_validate_options(machine_opts_dict); qemu_process_sugar_options(); =20 /* @@ -3626,7 +3603,7 @@ void qemu_init(int argc, char **argv, char **envp) =20 configure_rtc(qemu_find_opts_singleton("rtc")); =20 - qemu_create_machine(select_machine()); + qemu_create_machine(machine_opts_dict); =20 suspend_mux_open(); =20 @@ -3634,12 +3611,14 @@ void qemu_init(int argc, char **argv, char **envp) qemu_create_default_devices(); qemu_create_early_backends(); =20 - qemu_apply_machine_options(); + qemu_apply_legacy_machine_options(machine_opts_dict); + qemu_apply_machine_options(machine_opts_dict); + qobject_unref(machine_opts_dict); phase_advance(PHASE_MACHINE_CREATED); =20 /* * Note: uses machine properties such as kernel-irqchip, must run - * after machine_set_property(). + * after qemu_apply_machine_options. */ configure_accelerators(argv[0]); phase_advance(PHASE_ACCEL_CREATED); --=20 2.26.2 From nobody Fri May 10 11:48:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1620923486; cv=none; d=zohomail.com; s=zohoarc; b=XcmRakZzUiqXep6iCJOrMY28CuQ9SyxbvvFqATNlxVybVQXSq/rk/lREltdhPc31dQ/82YV2TDSF5uxpAbbH31k5VWrtdDzA4sAjkqWTK5DKEYCkDsK3sZhw3ZP5FX+uJCtTT4ytwSe97SjcBAucCF0xjHRFlW8b8J3WtzZfm5c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620923486; 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=dBZjcIE5iW9BJe91mAf9MP8HatO8qabRsBFwx5nCBUA=; b=H6CxBLLUpOdRl6KkJS6pI5f/VYSkx0zC4p5IsJ7KafuyNgH75Cn5MDt5UbSF4KVzxzrQXRp2SdBKgbge9VsehpdgAz3ULskt5objz8f1ga9vD/Eogwj1Ez3AcErFCspguSIXo8M1rUwF+XuGB3oUH38jRi1IgmqB36Bbz4okrWY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620923486385181.38308819937743; Thu, 13 May 2021 09:31:26 -0700 (PDT) Received: from localhost ([::1]:52824 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lhEF9-00058m-6w for importer@patchew.org; Thu, 13 May 2021 12:31:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40544) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhED8-0002Jl-94 for qemu-devel@nongnu.org; Thu, 13 May 2021 12:29:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:29962) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhED2-0003So-V6 for qemu-devel@nongnu.org; Thu, 13 May 2021 12:29:17 -0400 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-350-qXWMVs5YOuWfO2rId7DHWg-1; Thu, 13 May 2021 12:29:10 -0400 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 0AE236D5CE; Thu, 13 May 2021 16:29:10 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 92904687D7; Thu, 13 May 2021 16:29:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620923352; h=from:from: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; bh=dBZjcIE5iW9BJe91mAf9MP8HatO8qabRsBFwx5nCBUA=; b=Xa0V4lKOzGpsVvi062kL8FVjhd94IWsYEGf7qhCe9zHCn4guyioAI5T44COPpM74OjKOAO /KUuoPlp1fZ8w5rTevyd7aRsZQxCUE89rXiJjn3V3knh93+beZh54cWIZs5m4oxEcJZzXJ rKosZGcTOgZIjlWAYbq2p6DbJahjxj4= X-MC-Unique: qXWMVs5YOuWfO2rId7DHWg-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 07/14] qemu-option: remove now-dead code Date: Thu, 13 May 2021 12:28:54 -0400 Message-Id: <20210513162901.1310239-8-pbonzini@redhat.com> In-Reply-To: <20210513162901.1310239-1-pbonzini@redhat.com> References: <20210513162901.1310239-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yang.zhong@intel.com, berrange@redhat.com, ehabkost@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" -M was the sole user of qemu_opts_set and qemu_opts_set_defaults, remove them and the arguments that they used. Signed-off-by: Paolo Bonzini --- include/qemu/option.h | 3 --- tests/unit/test-qemu-opts.c | 35 ------------------------- util/qemu-option.c | 51 ++++++++----------------------------- 3 files changed, 10 insertions(+), 79 deletions(-) diff --git a/include/qemu/option.h b/include/qemu/option.h index fffb03d848..306bf07575 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -119,7 +119,6 @@ QemuOpts *qemu_opts_create(QemuOptsList *list, const ch= ar *id, int fail_if_exists, Error **errp); void qemu_opts_reset(QemuOptsList *list); void qemu_opts_loc_restore(QemuOpts *opts); -bool qemu_opts_set(QemuOptsList *list, const char *name, const char *value= , Error **errp); const char *qemu_opts_id(QemuOpts *opts); void qemu_opts_set_id(QemuOpts *opts, char *id); void qemu_opts_del(QemuOpts *opts); @@ -130,8 +129,6 @@ QemuOpts *qemu_opts_parse_noisily(QemuOptsList *list, c= onst char *params, bool permit_abbrev); QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, bool permit_abbrev, Error **errp); -void qemu_opts_set_defaults(QemuOptsList *list, const char *params, - int permit_abbrev); QemuOpts *qemu_opts_from_qdict(QemuOptsList *list, const QDict *qdict, Error **errp); QDict *qemu_opts_to_qdict_filtered(QemuOpts *opts, QDict *qdict, diff --git a/tests/unit/test-qemu-opts.c b/tests/unit/test-qemu-opts.c index 6568e31a72..828d40e928 100644 --- a/tests/unit/test-qemu-opts.c +++ b/tests/unit/test-qemu-opts.c @@ -410,40 +410,6 @@ static void test_qemu_opts_reset(void) g_assert(opts =3D=3D NULL); } =20 -static void test_qemu_opts_set(void) -{ - QemuOptsList *list; - QemuOpts *opts; - const char *opt; - - list =3D qemu_find_opts("opts_list_04"); - g_assert(list !=3D NULL); - g_assert(QTAILQ_EMPTY(&list->head)); - g_assert_cmpstr(list->name, =3D=3D, "opts_list_04"); - - /* should not find anything at this point */ - opts =3D qemu_opts_find(list, NULL); - g_assert(opts =3D=3D NULL); - - /* implicitly create opts and set str3 value */ - qemu_opts_set(list, "str3", "value", &error_abort); - g_assert(!QTAILQ_EMPTY(&list->head)); - - /* get the just created opts */ - opts =3D qemu_opts_find(list, NULL); - g_assert(opts !=3D NULL); - - /* check the str3 value */ - opt =3D qemu_opt_get(opts, "str3"); - g_assert_cmpstr(opt, =3D=3D, "value"); - - qemu_opts_del(opts); - - /* should not find anything at this point */ - opts =3D qemu_opts_find(list, NULL); - g_assert(opts =3D=3D NULL); -} - static int opts_count_iter(void *opaque, const char *name, const char *val= ue, Error **errp) { @@ -1041,7 +1007,6 @@ int main(int argc, char *argv[]) g_test_add_func("/qemu-opts/opt_get_size", test_qemu_opt_get_size); g_test_add_func("/qemu-opts/opt_unset", test_qemu_opt_unset); g_test_add_func("/qemu-opts/opts_reset", test_qemu_opts_reset); - g_test_add_func("/qemu-opts/opts_set", test_qemu_opts_set); g_test_add_func("/qemu-opts/opts_parse/general", test_opts_parse); g_test_add_func("/qemu-opts/opts_parse/bool", test_opts_parse_bool); g_test_add_func("/qemu-opts/opts_parse/number", test_opts_parse_number= ); diff --git a/util/qemu-option.c b/util/qemu-option.c index 4944015a25..ee78e42216 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -479,19 +479,14 @@ int qemu_opt_unset(QemuOpts *opts, const char *name) } } =20 -static QemuOpt *opt_create(QemuOpts *opts, const char *name, char *value, - bool prepend) +static QemuOpt *opt_create(QemuOpts *opts, const char *name, char *value) { QemuOpt *opt =3D g_malloc0(sizeof(*opt)); =20 opt->name =3D g_strdup(name); opt->str =3D value; opt->opts =3D opts; - if (prepend) { - QTAILQ_INSERT_HEAD(&opts->head, opt, next); - } else { - QTAILQ_INSERT_TAIL(&opts->head, opt, next); - } + QTAILQ_INSERT_TAIL(&opts->head, opt, next); =20 return opt; } @@ -518,7 +513,7 @@ static bool opt_validate(QemuOpt *opt, Error **errp) bool qemu_opt_set(QemuOpts *opts, const char *name, const char *value, Error **errp) { - QemuOpt *opt =3D opt_create(opts, name, g_strdup(value), false); + QemuOpt *opt =3D opt_create(opts, name, g_strdup(value)); =20 if (!opt_validate(opt, errp)) { qemu_opt_del(opt); @@ -662,15 +657,6 @@ void qemu_opts_loc_restore(QemuOpts *opts) loc_restore(&opts->loc); } =20 -bool qemu_opts_set(QemuOptsList *list, const char *name, const char *value= , Error **errp) -{ - QemuOpts *opts; - - assert(list->merge_lists); - opts =3D qemu_opts_create(list, NULL, 0, &error_abort); - return qemu_opt_set(opts, name, value, errp); -} - const char *qemu_opts_id(QemuOpts *opts) { return opts->id; @@ -811,7 +797,7 @@ static const char *get_opt_name_value(const char *param= s, } =20 static bool opts_do_parse(QemuOpts *opts, const char *params, - const char *firstname, bool prepend, + const char *firstname, bool warn_on_flag, bool *help_wanted, Error **er= rp) { char *option, *value; @@ -833,7 +819,7 @@ static bool opts_do_parse(QemuOpts *opts, const char *p= arams, continue; } =20 - opt =3D opt_create(opts, option, value, prepend); + opt =3D opt_create(opts, option, value); g_free(option); if (!opt_validate(opt, errp)) { qemu_opt_del(opt); @@ -889,11 +875,11 @@ bool has_help_option(const char *params) bool qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname, Error **errp) { - return opts_do_parse(opts, params, firstname, false, false, NULL, errp= ); + return opts_do_parse(opts, params, firstname, false, NULL, errp); } =20 static QemuOpts *opts_parse(QemuOptsList *list, const char *params, - bool permit_abbrev, bool defaults, + bool permit_abbrev, bool warn_on_flag, bool *help_wanted, Error **= errp) { const char *firstname; @@ -903,21 +889,13 @@ static QemuOpts *opts_parse(QemuOptsList *list, const= char *params, assert(!permit_abbrev || list->implied_opt_name); firstname =3D permit_abbrev ? list->implied_opt_name : NULL; =20 - /* - * This code doesn't work for defaults && !list->merge_lists: when - * params has no id=3D, and list has an element with !opts->id, it - * appends a new element instead of returning the existing opts. - * However, we got no use for this case. Guard against possible - * (if unlikely) future misuse: - */ - assert(!defaults || list->merge_lists); opts =3D qemu_opts_create(list, id, !list->merge_lists, errp); g_free(id); if (opts =3D=3D NULL) { return NULL; } =20 - if (!opts_do_parse(opts, params, firstname, defaults, + if (!opts_do_parse(opts, params, firstname, warn_on_flag, help_wanted, errp)) { qemu_opts_del(opts); return NULL; @@ -936,7 +914,7 @@ static QemuOpts *opts_parse(QemuOptsList *list, const c= har *params, QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, bool permit_abbrev, Error **errp) { - return opts_parse(list, params, permit_abbrev, false, false, NULL, err= p); + return opts_parse(list, params, permit_abbrev, false, NULL, errp); } =20 /** @@ -954,7 +932,7 @@ QemuOpts *qemu_opts_parse_noisily(QemuOptsList *list, c= onst char *params, QemuOpts *opts; bool help_wanted =3D false; =20 - opts =3D opts_parse(list, params, permit_abbrev, false, true, + opts =3D opts_parse(list, params, permit_abbrev, true, opts_accepts_any(list) ? NULL : &help_wanted, &err); if (!opts) { @@ -968,15 +946,6 @@ QemuOpts *qemu_opts_parse_noisily(QemuOptsList *list, = const char *params, return opts; } =20 -void qemu_opts_set_defaults(QemuOptsList *list, const char *params, - int permit_abbrev) -{ - QemuOpts *opts; - - opts =3D opts_parse(list, params, permit_abbrev, true, false, NULL, NU= LL); - assert(opts); -} - static bool qemu_opts_from_qdict_entry(QemuOpts *opts, const QDictEntry *entry, Error **errp) --=20 2.26.2 From nobody Fri May 10 11:48:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1620923677; cv=none; d=zohomail.com; s=zohoarc; b=kk7rtLudq9+o8NKvtBgJ2dk60EZRg59O/GnUqLV8sTLcosqBAAG8SNZwTLerppBjT5sBDVpFGnroBt8Y05sGrrKvGjizh1VWuDe8hfAmYoyks+VdM7bic8O1Do4xcCBwxpHWVKK378cOm5pVyuJ8RKcUO2f0c9wuemDJilJVwKs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620923677; 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=BEDSmJdDTA38XYMTjvkWT16wPaTZYkKKf4rp7gUJZ1s=; b=dBuGZuejXtuBUp2WEMNVclAJtgRjgkV9MlO9+uchdA13l8x1j4iuxEx1HDe/Mv2WcApa3E/gJvWVA9K1yk7UfVxAZeToBXMY7m6T6PZ1jopCQreqhuQvkLUwiOWSQdUlZAyyb6YEUDPY1QSJg7KbxZdh1Rc189OoSD4F6UBmwv0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620923677849440.6350882979573; Thu, 13 May 2021 09:34:37 -0700 (PDT) Received: from localhost ([::1]:33282 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lhEIG-0002ba-64 for importer@patchew.org; Thu, 13 May 2021 12:34:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40556) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhEDA-0002L0-0v for qemu-devel@nongnu.org; Thu, 13 May 2021 12:29:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:59435) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhED6-0003Tw-9e for qemu-devel@nongnu.org; Thu, 13 May 2021 12:29:19 -0400 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-465-TNJnPMeFPY-4wA7ETT7kMA-1; Thu, 13 May 2021 12:29:11 -0400 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 BE8E5803620; Thu, 13 May 2021 16:29:10 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 25155687C3; Thu, 13 May 2021 16:29:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620923355; h=from:from: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; bh=BEDSmJdDTA38XYMTjvkWT16wPaTZYkKKf4rp7gUJZ1s=; b=dIxcWU3C9c3QMJTKvlSTZBIhl1AN0Jxow+34uuDy0XZ8w2CnjbkUAUa7G+oQIc5og0mpVj W06vbucY4aP1iqSZSYAooLwVxz4m9mPg3M6lQ2k8aMK83+1eeqDY9u0YxDGCbBPUIam0Ns 5bWOyx7arShyF0TU/TGRqOVOoE3O/FQ= X-MC-Unique: TNJnPMeFPY-4wA7ETT7kMA-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 08/14] vl: switch -accel parsing to keyval Date: Thu, 13 May 2021 12:28:55 -0400 Message-Id: <20210513162901.1310239-9-pbonzini@redhat.com> In-Reply-To: <20210513162901.1310239-1-pbonzini@redhat.com> References: <20210513162901.1310239-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yang.zhong@intel.com, berrange@redhat.com, ehabkost@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Switch from QemuOpts to keyval. This enables compound options for accelerators as well as passing the options as JSON, using for example -accel '{"accel":"kvm"}'. Signed-off-by: Paolo Bonzini --- accel/accel-softmmu.c | 6 ++ include/qemu/accel.h | 1 + softmmu/vl.c | 156 ++++++++++++++++++++++-------------------- 3 files changed, 87 insertions(+), 76 deletions(-) diff --git a/accel/accel-softmmu.c b/accel/accel-softmmu.c index 50fa5acaa4..37717a3757 100644 --- a/accel/accel-softmmu.c +++ b/accel/accel-softmmu.c @@ -30,6 +30,12 @@ =20 #include "accel-softmmu.h" =20 +bool accel_print_class_properties(const char *opt_name) +{ + g_autofree char *class_name =3D g_strdup_printf(ACCEL_CLASS_NAME("%s")= , opt_name); + return type_print_class_properties(class_name); +} + int accel_init_machine(AccelState *accel, MachineState *ms) { AccelClass *acc =3D ACCEL_GET_CLASS(accel); diff --git a/include/qemu/accel.h b/include/qemu/accel.h index 4f4c283f6f..2c712d3846 100644 --- a/include/qemu/accel.h +++ b/include/qemu/accel.h @@ -70,6 +70,7 @@ AccelClass *accel_find(const char *opt_name); AccelState *current_accel(void); =20 void accel_init_interfaces(AccelClass *ac); +bool accel_print_class_properties(const char *opt_name); =20 #ifndef CONFIG_USER_ONLY int accel_init_machine(AccelState *accel, MachineState *ms); diff --git a/softmmu/vl.c b/softmmu/vl.c index 6b670fb301..de844f08d7 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -155,6 +155,7 @@ static const char *incoming; static const char *loadvm; static const char *accelerators; static QDict *machine_opts_dict; +static KeyvalConfigGroup accel_opts_list; static QTAILQ_HEAD(, ObjectOption) object_opts =3D QTAILQ_HEAD_INITIALIZER= (object_opts); static ram_addr_t maxram_size; static uint64_t ram_slots; @@ -245,20 +246,6 @@ static QemuOptsList qemu_option_rom_opts =3D { }, }; =20 -static QemuOptsList qemu_accel_opts =3D { - .name =3D "accel", - .implied_opt_name =3D "accel", - .head =3D QTAILQ_HEAD_INITIALIZER(qemu_accel_opts.head), - .desc =3D { - /* - * no elements =3D> accept any - * sanity checking will happen later - * when setting accelerator properties - */ - { } - }, -}; - static QemuOptsList qemu_boot_opts =3D { .name =3D "boot-opts", .implied_opt_name =3D "order", @@ -1595,21 +1582,6 @@ static MachineClass *select_machine(QDict *qdict, Er= ror **errp) return machine_class; } =20 -static int object_parse_property_opt(Object *obj, - const char *name, const char *value, - const char *skip, Error **errp) -{ - if (g_str_equal(name, skip)) { - return 0; - } - - if (!object_property_parse(obj, name, value, errp)) { - return -1; - } - - return 0; -} - /* *Non*recursively replace underscores with dashes in QDict keys. */ static void keyval_dashify(QDict *qdict, Error **errp) { @@ -2102,7 +2074,8 @@ static int global_init_func(void *opaque, QemuOpts *o= pts, Error **errp) */ static bool is_qemuopts_group(const char *group) { - if (g_str_equal(group, "machine")) { + if (g_str_equal(group, "machine") || + g_str_equal(group, "accel")) { return false; } return true; @@ -2114,6 +2087,9 @@ static bool is_qemuopts_group(const char *group) */ static KeyvalConfigGroup *qemu_config_list(const char *group) { + if (g_str_equal(group, "accel")) { + return &accel_opts_list; + } return NULL; } =20 @@ -2155,6 +2131,26 @@ static void qemu_record_config_group(const char *gro= up, QDict *dict, bool from_j } } =20 +static QDict *qemu_parse_config_option(const char *group, const char *arg, + bool *help, Error **errp) +{ + QDict *args; + + *help =3D false; + if (arg[0] =3D=3D '{') { + args =3D (QDict*) qobject_from_json(arg, errp); + if (args) { + qemu_record_config_group(group, args, true, &error_abort); + } + } else { + args =3D keyval_parse(arg, group, help, errp); + if (args) { + qemu_record_config_group(group, args, false, &error_abort); + } + } + return args; +} + static void qemu_set_qdict_option(QDict *dict, const char *key, const char= *value, Error **errp) { @@ -2262,17 +2258,9 @@ static int do_configure_icount(void *opaque, QemuOpt= s *opts, Error **errp) return 0; } =20 -static int accelerator_set_property(void *opaque, - const char *name, const char *value, - Error **errp) -{ - return object_parse_property_opt(opaque, name, value, "accel", errp); -} - -static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **= errp) +static bool do_configure_accelerator(KeyvalConfigEntry *e) { - bool *p_init_failed =3D opaque; - const char *acc =3D qemu_opt_get(opts, "accel"); + const char *acc =3D qdict_get_try_str(e->dict, "accel"); AccelClass *ac =3D accel_find(acc); AccelState *accel; int ret; @@ -2281,38 +2269,36 @@ static int do_configure_accelerator(void *opaque, Q= emuOpts *opts, Error **errp) qtest_with_kvm =3D g_str_equal(acc, "kvm") && qtest_chrdev !=3D NULL; =20 if (!ac) { - *p_init_failed =3D true; if (!qtest_with_kvm) { error_report("invalid accelerator %s", acc); } - return 0; + return true; } accel =3D ACCEL(object_new_with_class(OBJECT_CLASS(ac))); object_apply_compat_props(OBJECT(accel)); - qemu_opt_foreach(opts, accelerator_set_property, - accel, - &error_fatal); + qdict_del(e->dict, "accel"); + object_set_properties_from_keyval(OBJECT(accel), e->dict, e->from_json= , &error_fatal); =20 ret =3D accel_init_machine(accel, current_machine); if (ret < 0) { - *p_init_failed =3D true; if (!qtest_with_kvm || ret !=3D -ENOENT) { - error_report("failed to initialize %s: %s", acc, strerror(-ret= )); + error_report("failed to initialize %s: %s", ac->name, strerror= (-ret)); } - return 0; + return true; } =20 - return 1; + return false; } =20 static void configure_accelerators(const char *progname) { bool init_failed =3D false; + KeyvalConfigEntry *accel; =20 qemu_opts_foreach(qemu_find_opts("icount"), do_configure_icount, NULL, &error_fatal); =20 - if (QTAILQ_EMPTY(&qemu_accel_opts.head)) { + if (QTAILQ_EMPTY(&accel_opts_list)) { char **accel_list, **tmp; =20 if (accelerators =3D=3D NULL) { @@ -2345,7 +2331,9 @@ static void configure_accelerators(const char *progna= me) * such as "-machine accel=3Dtcg,,thread=3Dsingle". */ if (accel_find(*tmp)) { - qemu_opts_parse_noisily(qemu_find_opts("accel"), *tmp, tru= e); + QDict *qdict =3D qdict_new(); + qdict_put_str(qdict, "accel", *tmp); + qemu_record_config_group("accel", qdict, true, &error_abor= t); } else { init_failed =3D true; error_report("invalid accelerator %s", *tmp); @@ -2359,8 +2347,14 @@ static void configure_accelerators(const char *progn= ame) } } =20 - if (!qemu_opts_foreach(qemu_find_opts("accel"), - do_configure_accelerator, &init_failed, &error_= fatal)) { + QTAILQ_FOREACH_REVERSE(accel, &accel_opts_list, next) { + init_failed =3D do_configure_accelerator(accel); + if (current_accel()) { + break; + } + } + + if (!current_accel()) { if (!init_failed) { error_report("no accelerator found"); } @@ -2378,6 +2372,27 @@ static void configure_accelerators(const char *progn= ame) } } =20 +static void list_accelerators(void) +{ + printf("Accelerators supported in QEMU binary:\n"); + GSList *el, *accel_list =3D object_class_get_list(TYPE_ACCEL, + false); + for (el =3D accel_list; el; el =3D el->next) { + gchar *typename =3D g_strdup(object_class_get_name( + OBJECT_CLASS(el->data))); + /* omit qtest which is used for tests only */ + if (g_strcmp0(typename, ACCEL_CLASS_NAME("qtest")) && + g_str_has_suffix(typename, ACCEL_CLASS_SUFFIX)) { + gchar **optname =3D g_strsplit(typename, + ACCEL_CLASS_SUFFIX, 0); + printf("%s\n", optname[0]); + g_strfreev(optname); + } + g_free(typename); + } + g_slist_free(accel_list); +} + static void create_default_memdev(MachineState *ms, const char *path) { Object *obj; @@ -2702,7 +2717,7 @@ void qmp_x_exit_preconfig(Error **errp) void qemu_init(int argc, char **argv, char **envp) { QemuOpts *opts; - QemuOpts *icount_opts =3D NULL, *accel_opts =3D NULL; + QemuOpts *icount_opts =3D NULL; QemuOptsList *olist; int optind; const char *optarg; @@ -2726,7 +2741,6 @@ void qemu_init(int argc, char **argv, char **envp) qemu_add_opts(&qemu_trace_opts); qemu_plugin_add_opts(); qemu_add_opts(&qemu_option_rom_opts); - qemu_add_opts(&qemu_accel_opts); qemu_add_opts(&qemu_mem_opts); qemu_add_opts(&qemu_smp_opts); qemu_add_opts(&qemu_boot_opts); @@ -3283,30 +3297,20 @@ void qemu_init(int argc, char **argv, char **envp) break; } case QEMU_OPTION_accel: - accel_opts =3D qemu_opts_parse_noisily(qemu_find_opts("acc= el"), - optarg, true); - optarg =3D qemu_opt_get(accel_opts, "accel"); - if (!optarg || is_help_option(optarg)) { - printf("Accelerators supported in QEMU binary:\n"); - GSList *el, *accel_list =3D object_class_get_list(TYPE= _ACCEL, - false); - for (el =3D accel_list; el; el =3D el->next) { - gchar *typename =3D g_strdup(object_class_get_name( - OBJECT_CLASS(el->data))= ); - /* omit qtest which is used for tests only */ - if (g_strcmp0(typename, ACCEL_CLASS_NAME("qtest"))= && - g_str_has_suffix(typename, ACCEL_CLASS_SUFFIX)= ) { - gchar **optname =3D g_strsplit(typename, - ACCEL_CLASS_SUFFI= X, 0); - printf("%s\n", optname[0]); - g_strfreev(optname); + { + bool help; + QDict *args; + + args =3D qemu_parse_config_option("accel", optarg, &he= lp, &error_fatal); + if (help) { + const char *type =3D qdict_get_try_str(args, "acce= l"); + if (!type || !accel_print_class_properties(type)) { + list_accelerators(); } - g_free(typename); + exit(0); } - g_slist_free(accel_list); - exit(0); + break; } - break; case QEMU_OPTION_usb: qdict_put_str(machine_opts_dict, "usb", "on"); break; --=20 2.26.2 From nobody Fri May 10 11:48:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1620923673; cv=none; d=zohomail.com; s=zohoarc; b=fhuC3fcyMTPPm6P493+mVEFRbLCXXqyqu4VdL8PF+SQvUaZGAoemyGYVS7WEezU/PadtG9UvdF5TsnxwMn1oaz0RVNzAEzbGU76npe2u5UbyEPoTPm6qGxLQSkpwuVVioQ0Ht3oZa2KSLiCsbj3pkLcAXWyokSoMug5hyWfg+Xk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620923673; 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=RTq3RNnTC+qZyVHsj9aAv/eM72lcMaCSvJhdqRSdrFU=; b=k/rAAZXdYXUfzDx5E4iDhGzkn5bxaqRAEIg1Sej/jx46LBn0VClKvjWjz3oTRlJsqvsUNrHJUrZd2sod7Xuotlz13SadBkv4dINKDnVBHDeUQ/lNTEXE8wwEIKQlptrmhrN4vpx9GxRaiUB5Hfv4MfiIUwrOzMJT46FnLzJPICo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620923673397969.2587759954729; Thu, 13 May 2021 09:34:33 -0700 (PDT) Received: from localhost ([::1]:32832 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lhEIB-0002Jm-9B for importer@patchew.org; Thu, 13 May 2021 12:34:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40554) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhED9-0002KQ-R1 for qemu-devel@nongnu.org; Thu, 13 May 2021 12:29:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:43822) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhED5-0003Tq-Cd for qemu-devel@nongnu.org; Thu, 13 May 2021 12:29:19 -0400 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-311-7RcoFBsMPEST7ncOymhZGA-1; Thu, 13 May 2021 12:29:12 -0400 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 530548015F7; Thu, 13 May 2021 16:29:11 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id D9445687C6; Thu, 13 May 2021 16:29:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620923354; h=from:from: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; bh=RTq3RNnTC+qZyVHsj9aAv/eM72lcMaCSvJhdqRSdrFU=; b=SfwJCCVRIk9zltMVCQXgeoq5i21kjkobMi+tVPGKUL9xSK6/DHCI1lCu1FSEm4qeg7u79F TEoJshXRyzVIfurZ5siQRgI1b+9+e6RncFDY/OuJwfA8u89WwhoT2ZVQ55DFuygU/lcn6U 29sv9+Q+vVko/IHdjhN8oHA4UYeq0VM= X-MC-Unique: 7RcoFBsMPEST7ncOymhZGA-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 09/14] machine: move dies from X86MachineState to CpuTopology Date: Thu, 13 May 2021 12:28:56 -0400 Message-Id: <20210513162901.1310239-10-pbonzini@redhat.com> In-Reply-To: <20210513162901.1310239-1-pbonzini@redhat.com> References: <20210513162901.1310239-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yang.zhong@intel.com, berrange@redhat.com, ehabkost@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" In order to make SMP configuration a Machine property, we need a getter as well as a setter. To simplify the implementation put everything that the getter needs in the CpuTopology struct. Signed-off-by: Paolo Bonzini --- hw/core/machine.c | 1 + hw/i386/pc.c | 4 +--- hw/i386/x86.c | 15 +++++++-------- include/hw/boards.h | 1 + include/hw/i386/pc.h | 1 - include/hw/i386/x86.h | 1 - 6 files changed, 10 insertions(+), 13 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 1bf0e687b9..79efae89ce 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -969,6 +969,7 @@ static void machine_initfn(Object *obj) ms->smp.cpus =3D mc->default_cpus; ms->smp.max_cpus =3D mc->default_cpus; ms->smp.cores =3D 1; + ms->smp.dies =3D 1; ms->smp.threads =3D 1; ms->smp.sockets =3D 1; } diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 8cfaf216e7..466e57acbe 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -708,8 +708,6 @@ void pc_acpi_smi_interrupt(void *opaque, int irq, int l= evel) */ void pc_smp_parse(MachineState *ms, QemuOpts *opts) { - X86MachineState *x86ms =3D X86_MACHINE(ms); - if (opts) { unsigned cpus =3D qemu_opt_get_number(opts, "cpus", 0); unsigned sockets =3D qemu_opt_get_number(opts, "sockets", 0); @@ -765,7 +763,7 @@ void pc_smp_parse(MachineState *ms, QemuOpts *opts) ms->smp.cores =3D cores; ms->smp.threads =3D threads; ms->smp.sockets =3D sockets; - x86ms->smp_dies =3D dies; + ms->smp.dies =3D dies; } =20 if (ms->smp.cpus > 1) { diff --git a/hw/i386/x86.c b/hw/i386/x86.c index ed796fe6ba..2a99942016 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -64,7 +64,7 @@ inline void init_topo_info(X86CPUTopoInfo *topo_info, { MachineState *ms =3D MACHINE(x86ms); =20 - topo_info->dies_per_pkg =3D x86ms->smp_dies; + topo_info->dies_per_pkg =3D ms->smp.dies; topo_info->cores_per_die =3D ms->smp.cores; topo_info->threads_per_core =3D ms->smp.threads; } @@ -293,7 +293,7 @@ void x86_cpu_pre_plug(HotplugHandler *hotplug_dev, =20 init_topo_info(&topo_info, x86ms); =20 - env->nr_dies =3D x86ms->smp_dies; + env->nr_dies =3D ms->smp.dies; =20 /* * If APIC ID is not set, @@ -301,13 +301,13 @@ void x86_cpu_pre_plug(HotplugHandler *hotplug_dev, */ if (cpu->apic_id =3D=3D UNASSIGNED_APIC_ID) { int max_socket =3D (ms->smp.max_cpus - 1) / - smp_threads / smp_cores / x86ms->smp_dies; + smp_threads / smp_cores / ms->smp.dies; =20 /* * die-id was optional in QEMU 4.0 and older, so keep it optional * if there's only one die per socket. */ - if (cpu->die_id < 0 && x86ms->smp_dies =3D=3D 1) { + if (cpu->die_id < 0 && ms->smp.dies =3D=3D 1) { cpu->die_id =3D 0; } =20 @@ -322,9 +322,9 @@ void x86_cpu_pre_plug(HotplugHandler *hotplug_dev, if (cpu->die_id < 0) { error_setg(errp, "CPU die-id is not set"); return; - } else if (cpu->die_id > x86ms->smp_dies - 1) { + } else if (cpu->die_id > ms->smp.dies - 1) { error_setg(errp, "Invalid CPU die-id: %u must be in range 0:%u= ", - cpu->die_id, x86ms->smp_dies - 1); + cpu->die_id, ms->smp.dies - 1); return; } if (cpu->core_id < 0) { @@ -477,7 +477,7 @@ const CPUArchIdList *x86_possible_cpu_arch_ids(MachineS= tate *ms) &topo_info, &topo_ids); ms->possible_cpus->cpus[i].props.has_socket_id =3D true; ms->possible_cpus->cpus[i].props.socket_id =3D topo_ids.pkg_id; - if (x86ms->smp_dies > 1) { + if (ms->smp.dies > 1) { ms->possible_cpus->cpus[i].props.has_die_id =3D true; ms->possible_cpus->cpus[i].props.die_id =3D topo_ids.die_id; } @@ -1252,7 +1252,6 @@ static void x86_machine_initfn(Object *obj) =20 x86ms->smm =3D ON_OFF_AUTO_AUTO; x86ms->acpi =3D ON_OFF_AUTO_AUTO; - x86ms->smp_dies =3D 1; x86ms->pci_irq_mask =3D ACPI_BUILD_PCI_IRQS; x86ms->oem_id =3D g_strndup(ACPI_BUILD_APPNAME6, 6); x86ms->oem_table_id =3D g_strndup(ACPI_BUILD_APPNAME8, 8); diff --git a/include/hw/boards.h b/include/hw/boards.h index 3d55d2bd62..87ae5cc300 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -282,6 +282,7 @@ typedef struct DeviceMemoryState { */ typedef struct CpuTopology { unsigned int cpus; + unsigned int dies; unsigned int cores; unsigned int threads; unsigned int sockets; diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 1522a3359a..4c2ca6d36a 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -19,7 +19,6 @@ * PCMachineState: * @acpi_dev: link to ACPI PM device that performs ACPI hotplug handling * @boot_cpus: number of present VCPUs - * @smp_dies: number of dies per one package */ typedef struct PCMachineState { /*< private >*/ diff --git a/include/hw/i386/x86.h b/include/hw/i386/x86.h index c09b648dff..a6ffd94562 100644 --- a/include/hw/i386/x86.h +++ b/include/hw/i386/x86.h @@ -62,7 +62,6 @@ struct X86MachineState { unsigned pci_irq_mask; unsigned apic_id_limit; uint16_t boot_cpus; - unsigned smp_dies; =20 OnOffAuto smm; OnOffAuto acpi; --=20 2.26.2 From nobody Fri May 10 11:48:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1620923819; cv=none; d=zohomail.com; s=zohoarc; b=F3lFhH3krSpFmfckVNRiKWEa8f0+uC8/F1SdITh+8L5/4B4Gk2LJWeuBmadNkyWYqxRTfbU9DvlXJxB4YM1PSNMeEIeJicVY7gfJ2rv3t7rP96R+MCO75kBV/xbeNnT6eg0tNX7Wqydcsubig/0IQ9KUAXos2Obh0nyd3uiyLLY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620923819; 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=viKv+L/NizaIhWDUT8p9ZI7E1JUiGNs7wb8iI18iM+E=; b=j/g7NZa2EtEUL6Kxbt8b2BF2WI++RdDORCJD42P7ZIC9Kr4REAXPR5GwnuTVPb5SFWydgGzAAwb8g+Tx3x+a7yRdTvDCUI1EurVPZR2qxEomx7pQGX+APoY7tMDSgsSkL0tcSkd6MqmpE0xkm8zocHIX5CaFre2D3DZ1q8Ro+dM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620923819821271.6065848349814; Thu, 13 May 2021 09:36:59 -0700 (PDT) Received: from localhost ([::1]:40382 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lhEKX-0007L0-Pk for importer@patchew.org; Thu, 13 May 2021 12:36:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40578) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhEDB-0002Ld-Jy for qemu-devel@nongnu.org; Thu, 13 May 2021 12:29:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:33902) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhED5-0003Tl-4P for qemu-devel@nongnu.org; Thu, 13 May 2021 12:29:21 -0400 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-582-LARmzPbjOUeCn5puHuzw_A-1; Thu, 13 May 2021 12:29:13 -0400 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 3837E107ACCD; Thu, 13 May 2021 16:29:12 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id ADE59BA6F; Thu, 13 May 2021 16:29:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620923354; h=from:from: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; bh=viKv+L/NizaIhWDUT8p9ZI7E1JUiGNs7wb8iI18iM+E=; b=cERcfgXPTySGG6g31FILmGj6L5Z7Cj0dEPUU4iQMbC8KC7cAAosFHJeYsL9kvcogVGJCwx 2VlO6nMMeDKceEhrX/9N7h6KKbjQfAVZMiY4NFT6q6Xjgw4KrXZSIg/BO9l9FRP08+UXfb SlV2jQBhrGMCsJuhunDsQmOOWYK+57k= X-MC-Unique: LARmzPbjOUeCn5puHuzw_A-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 10/14] machine: move common smp_parse code to caller Date: Thu, 13 May 2021 12:28:57 -0400 Message-Id: <20210513162901.1310239-11-pbonzini@redhat.com> In-Reply-To: <20210513162901.1310239-1-pbonzini@redhat.com> References: <20210513162901.1310239-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yang.zhong@intel.com, berrange@redhat.com, ehabkost@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Most of smp_parse and pc_smp_parse is guarded by an "if (opts)" conditional, and the rest is common to both function. Move the conditional and the common code to the caller, machine_smp_parse. Move the replay_add_blocker call after all errors are checked for. Signed-off-by: Paolo Bonzini --- hw/core/machine.c | 112 ++++++++++++++++++++++---------------------- hw/i386/pc.c | 116 +++++++++++++++++++++------------------------- 2 files changed, 110 insertions(+), 118 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 79efae89ce..7e57c287b0 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -740,67 +740,59 @@ void machine_set_cpu_numa_node(MachineState *machine, =20 static void smp_parse(MachineState *ms, QemuOpts *opts) { - if (opts) { - unsigned cpus =3D qemu_opt_get_number(opts, "cpus", 0); - unsigned sockets =3D qemu_opt_get_number(opts, "sockets", 0); - unsigned cores =3D qemu_opt_get_number(opts, "cores", 0); - unsigned threads =3D qemu_opt_get_number(opts, "threads", 0); - - /* compute missing values, prefer sockets over cores over threads = */ - if (cpus =3D=3D 0 || sockets =3D=3D 0) { - cores =3D cores > 0 ? cores : 1; - threads =3D threads > 0 ? threads : 1; - if (cpus =3D=3D 0) { - sockets =3D sockets > 0 ? sockets : 1; - cpus =3D cores * threads * sockets; - } else { - ms->smp.max_cpus =3D - qemu_opt_get_number(opts, "maxcpus", cpus); - sockets =3D ms->smp.max_cpus / (cores * threads); - } - } else if (cores =3D=3D 0) { - threads =3D threads > 0 ? threads : 1; - cores =3D cpus / (sockets * threads); - cores =3D cores > 0 ? cores : 1; - } else if (threads =3D=3D 0) { - threads =3D cpus / (cores * sockets); - threads =3D threads > 0 ? threads : 1; - } else if (sockets * cores * threads < cpus) { - error_report("cpu topology: " - "sockets (%u) * cores (%u) * threads (%u) < " - "smp_cpus (%u)", - sockets, cores, threads, cpus); - exit(1); - } - - ms->smp.max_cpus =3D - qemu_opt_get_number(opts, "maxcpus", cpus); - - if (ms->smp.max_cpus < cpus) { - error_report("maxcpus must be equal to or greater than smp"); - exit(1); + unsigned cpus =3D qemu_opt_get_number(opts, "cpus", 0); + unsigned sockets =3D qemu_opt_get_number(opts, "sockets", 0); + unsigned cores =3D qemu_opt_get_number(opts, "cores", 0); + unsigned threads =3D qemu_opt_get_number(opts, "threads", 0); + + /* compute missing values, prefer sockets over cores over threads */ + if (cpus =3D=3D 0 || sockets =3D=3D 0) { + cores =3D cores > 0 ? cores : 1; + threads =3D threads > 0 ? threads : 1; + if (cpus =3D=3D 0) { + sockets =3D sockets > 0 ? sockets : 1; + cpus =3D cores * threads * sockets; + } else { + ms->smp.max_cpus =3D + qemu_opt_get_number(opts, "maxcpus", cpus); + sockets =3D ms->smp.max_cpus / (cores * threads); } + } else if (cores =3D=3D 0) { + threads =3D threads > 0 ? threads : 1; + cores =3D cpus / (sockets * threads); + cores =3D cores > 0 ? cores : 1; + } else if (threads =3D=3D 0) { + threads =3D cpus / (cores * sockets); + threads =3D threads > 0 ? threads : 1; + } else if (sockets * cores * threads < cpus) { + error_report("cpu topology: " + "sockets (%u) * cores (%u) * threads (%u) < " + "smp_cpus (%u)", + sockets, cores, threads, cpus); + exit(1); + } =20 - if (sockets * cores * threads !=3D ms->smp.max_cpus) { - error_report("Invalid CPU topology: " - "sockets (%u) * cores (%u) * threads (%u) " - "!=3D maxcpus (%u)", - sockets, cores, threads, - ms->smp.max_cpus); - exit(1); - } + ms->smp.max_cpus =3D + qemu_opt_get_number(opts, "maxcpus", cpus); =20 - ms->smp.cpus =3D cpus; - ms->smp.cores =3D cores; - ms->smp.threads =3D threads; - ms->smp.sockets =3D sockets; + if (ms->smp.max_cpus < cpus) { + error_report("maxcpus must be equal to or greater than smp"); + exit(1); } =20 - if (ms->smp.cpus > 1) { - Error *blocker =3D NULL; - error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, "smp"); - replay_add_blocker(blocker); + if (sockets * cores * threads !=3D ms->smp.max_cpus) { + error_report("Invalid CPU topology: " + "sockets (%u) * cores (%u) * threads (%u) " + "!=3D maxcpus (%u)", + sockets, cores, threads, + ms->smp.max_cpus); + exit(1); } + + ms->smp.cpus =3D cpus; + ms->smp.cores =3D cores; + ms->smp.threads =3D threads; + ms->smp.sockets =3D sockets; } =20 static void machine_class_init(ObjectClass *oc, void *data) @@ -1134,7 +1126,9 @@ bool machine_smp_parse(MachineState *ms, QemuOpts *op= ts, Error **errp) { MachineClass *mc =3D MACHINE_GET_CLASS(ms); =20 - mc->smp_parse(ms, opts); + if (opts) { + mc->smp_parse(ms, opts); + } =20 /* sanity-check smp_cpus and max_cpus against mc */ if (ms->smp.cpus < mc->min_cpus) { @@ -1150,6 +1144,12 @@ bool machine_smp_parse(MachineState *ms, QemuOpts *o= pts, Error **errp) mc->name, mc->max_cpus); return false; } + + if (ms->smp.cpus > 1) { + Error *blocker =3D NULL; + error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, "smp"); + replay_add_blocker(blocker); + } return true; } =20 diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 466e57acbe..2942ddf0f9 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -708,69 +708,61 @@ void pc_acpi_smi_interrupt(void *opaque, int irq, int= level) */ void pc_smp_parse(MachineState *ms, QemuOpts *opts) { - if (opts) { - unsigned cpus =3D qemu_opt_get_number(opts, "cpus", 0); - unsigned sockets =3D qemu_opt_get_number(opts, "sockets", 0); - unsigned dies =3D qemu_opt_get_number(opts, "dies", 1); - unsigned cores =3D qemu_opt_get_number(opts, "cores", 0); - unsigned threads =3D qemu_opt_get_number(opts, "threads", 0); - - /* compute missing values, prefer sockets over cores over threads = */ - if (cpus =3D=3D 0 || sockets =3D=3D 0) { - cores =3D cores > 0 ? cores : 1; - threads =3D threads > 0 ? threads : 1; - if (cpus =3D=3D 0) { - sockets =3D sockets > 0 ? sockets : 1; - cpus =3D cores * threads * dies * sockets; - } else { - ms->smp.max_cpus =3D - qemu_opt_get_number(opts, "maxcpus", cpus); - sockets =3D ms->smp.max_cpus / (cores * threads * dies); - } - } else if (cores =3D=3D 0) { - threads =3D threads > 0 ? threads : 1; - cores =3D cpus / (sockets * dies * threads); - cores =3D cores > 0 ? cores : 1; - } else if (threads =3D=3D 0) { - threads =3D cpus / (cores * dies * sockets); - threads =3D threads > 0 ? threads : 1; - } else if (sockets * dies * cores * threads < cpus) { - error_report("cpu topology: " - "sockets (%u) * dies (%u) * cores (%u) * threads = (%u) < " - "smp_cpus (%u)", - sockets, dies, cores, threads, cpus); - exit(1); - } - - ms->smp.max_cpus =3D - qemu_opt_get_number(opts, "maxcpus", cpus); - - if (ms->smp.max_cpus < cpus) { - error_report("maxcpus must be equal to or greater than smp"); - exit(1); - } - - if (sockets * dies * cores * threads !=3D ms->smp.max_cpus) { - error_report("Invalid CPU topology deprecated: " - "sockets (%u) * dies (%u) * cores (%u) * threads = (%u) " - "!=3D maxcpus (%u)", - sockets, dies, cores, threads, - ms->smp.max_cpus); - exit(1); + unsigned cpus =3D qemu_opt_get_number(opts, "cpus", 0); + unsigned sockets =3D qemu_opt_get_number(opts, "sockets", 0); + unsigned dies =3D qemu_opt_get_number(opts, "dies", 1); + unsigned cores =3D qemu_opt_get_number(opts, "cores", 0); + unsigned threads =3D qemu_opt_get_number(opts, "threads", 0); + + /* compute missing values, prefer sockets over cores over threads */ + if (cpus =3D=3D 0 || sockets =3D=3D 0) { + cores =3D cores > 0 ? cores : 1; + threads =3D threads > 0 ? threads : 1; + if (cpus =3D=3D 0) { + sockets =3D sockets > 0 ? sockets : 1; + cpus =3D cores * threads * dies * sockets; + } else { + ms->smp.max_cpus =3D + qemu_opt_get_number(opts, "maxcpus", cpus); + sockets =3D ms->smp.max_cpus / (cores * threads * dies); } - - ms->smp.cpus =3D cpus; - ms->smp.cores =3D cores; - ms->smp.threads =3D threads; - ms->smp.sockets =3D sockets; - ms->smp.dies =3D dies; - } - - if (ms->smp.cpus > 1) { - Error *blocker =3D NULL; - error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, "smp"); - replay_add_blocker(blocker); - } + } else if (cores =3D=3D 0) { + threads =3D threads > 0 ? threads : 1; + cores =3D cpus / (sockets * dies * threads); + cores =3D cores > 0 ? cores : 1; + } else if (threads =3D=3D 0) { + threads =3D cpus / (cores * dies * sockets); + threads =3D threads > 0 ? threads : 1; + } else if (sockets * dies * cores * threads < cpus) { + error_report("cpu topology: " + "sockets (%u) * dies (%u) * cores (%u) * threads (= %u) < " + "smp_cpus (%u)", + sockets, dies, cores, threads, cpus); + exit(1); + } + + ms->smp.max_cpus =3D + qemu_opt_get_number(opts, "maxcpus", cpus); + + if (ms->smp.max_cpus < cpus) { + error_report("maxcpus must be equal to or greater than smp"); + exit(1); + } + + if (sockets * dies * cores * threads !=3D ms->smp.max_cpus) { + error_report("Invalid CPU topology deprecated: " + "sockets (%u) * dies (%u) * cores (%u) * threads (= %u) " + "!=3D maxcpus (%u)", + sockets, dies, cores, threads, + ms->smp.max_cpus); + exit(1); + } + + ms->smp.cpus =3D cpus; + ms->smp.cores =3D cores; + ms->smp.threads =3D threads; + ms->smp.sockets =3D sockets; + ms->smp.dies =3D dies; } =20 static --=20 2.26.2 From nobody Fri May 10 11:48:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1620924081; cv=none; d=zohomail.com; s=zohoarc; b=F4TZbo2JxyU8IaIWC+L/MAQZKPHHFIMHsZc/ipyzxoxUhxlUiACci5Mql8DyBPnXXKUL01YbN8/J+LnUC7verYZeR1wlMu8sNv4vFxCi+x0ySgdtYh2AVsOSAFe5WHolqoSQ6hV954kFygLjmKLeP/8m1t4Ii1fQ17XoCVzms0w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620924081; 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=MaLIKqwKJBJhKNVErx6Hfd59liy+eolRDjzMv+cEjwc=; b=Q/cMC9ig+V3buy8rA1evFH73oTLUFnjRASnE0iV4nvkcs856mn+N33IetBHoCblqCxlhmpBQpUX+SLRe2CpDC4oXQO/av39TE08Zo+bwnseot59IHbGeF4cyXMiwtf2a69+KCF4hG6q0wNiU6zrFG64ZtK7F3IOWgBwoZwwjQ2c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162092408131922.509810406314273; Thu, 13 May 2021 09:41:21 -0700 (PDT) Received: from localhost ([::1]:47662 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lhEOl-0004CY-BZ for importer@patchew.org; Thu, 13 May 2021 12:41:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40630) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhEDJ-0002Ww-4b for qemu-devel@nongnu.org; Thu, 13 May 2021 12:29:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:39647) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhED6-0003UK-9o for qemu-devel@nongnu.org; Thu, 13 May 2021 12:29:28 -0400 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-146-9MwOsTc0PrC7Aj4TprEn5Q-1; Thu, 13 May 2021 12:29:13 -0400 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 BFA731922038; Thu, 13 May 2021 16:29:12 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 52808BA6F; Thu, 13 May 2021 16:29:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620923355; h=from:from: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; bh=MaLIKqwKJBJhKNVErx6Hfd59liy+eolRDjzMv+cEjwc=; b=KTDY9i/CD7af4pMLn+0bGYvPCNOx/bbqsJmXbd4vxau9gvxcvsoOUBxBA1KpY+ocQsC+Gj utIEE7pE6/GUhysZj82QOX1YYkrVmoKKMHQVS7DiTYeE/fdPDlbR5Oq86gzOLMmugHnRNo y3GngMnj5Wpi544QvgPDp0br6ucLxdY= X-MC-Unique: 9MwOsTc0PrC7Aj4TprEn5Q-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 11/14] machine: add error propagation to mc->smp_parse Date: Thu, 13 May 2021 12:28:58 -0400 Message-Id: <20210513162901.1310239-12-pbonzini@redhat.com> In-Reply-To: <20210513162901.1310239-1-pbonzini@redhat.com> References: <20210513162901.1310239-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yang.zhong@intel.com, berrange@redhat.com, ehabkost@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Clean up the smp_parse functions to use Error** instead of exiting. Signed-off-by: Paolo Bonzini --- hw/core/machine.c | 34 +++++++++++++++++++--------------- hw/i386/pc.c | 28 ++++++++++++++-------------- include/hw/boards.h | 2 +- include/hw/i386/pc.h | 2 -- 4 files changed, 34 insertions(+), 32 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 7e57c287b0..70c297a7de 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -738,7 +738,7 @@ void machine_set_cpu_numa_node(MachineState *machine, } } =20 -static void smp_parse(MachineState *ms, QemuOpts *opts) +static void smp_parse(MachineState *ms, QemuOpts *opts, Error **errp) { unsigned cpus =3D qemu_opt_get_number(opts, "cpus", 0); unsigned sockets =3D qemu_opt_get_number(opts, "sockets", 0); @@ -765,28 +765,28 @@ static void smp_parse(MachineState *ms, QemuOpts *opt= s) threads =3D cpus / (cores * sockets); threads =3D threads > 0 ? threads : 1; } else if (sockets * cores * threads < cpus) { - error_report("cpu topology: " - "sockets (%u) * cores (%u) * threads (%u) < " - "smp_cpus (%u)", - sockets, cores, threads, cpus); - exit(1); + error_setg(errp, "cpu topology: " + "sockets (%u) * cores (%u) * threads (%u) < " + "smp_cpus (%u)", + sockets, cores, threads, cpus); + return; } =20 ms->smp.max_cpus =3D qemu_opt_get_number(opts, "maxcpus", cpus); =20 if (ms->smp.max_cpus < cpus) { - error_report("maxcpus must be equal to or greater than smp"); - exit(1); + error_setg(errp, "maxcpus must be equal to or greater than smp"); + return; } =20 if (sockets * cores * threads !=3D ms->smp.max_cpus) { - error_report("Invalid CPU topology: " - "sockets (%u) * cores (%u) * threads (%u) " - "!=3D maxcpus (%u)", - sockets, cores, threads, - ms->smp.max_cpus); - exit(1); + error_setg(errp, "Invalid CPU topology: " + "sockets (%u) * cores (%u) * threads (%u) " + "!=3D maxcpus (%u)", + sockets, cores, threads, + ms->smp.max_cpus); + return; } =20 ms->smp.cpus =3D cpus; @@ -1125,9 +1125,13 @@ MemoryRegion *machine_consume_memdev(MachineState *m= achine, bool machine_smp_parse(MachineState *ms, QemuOpts *opts, Error **errp) { MachineClass *mc =3D MACHINE_GET_CLASS(ms); + ERRP_GUARD(); =20 if (opts) { - mc->smp_parse(ms, opts); + mc->smp_parse(ms, opts, errp); + if (*errp) { + return false; + } } =20 /* sanity-check smp_cpus and max_cpus against mc */ diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 2942ddf0f9..1760e94ff5 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -706,7 +706,7 @@ void pc_acpi_smi_interrupt(void *opaque, int irq, int l= evel) * This function is very similar to smp_parse() * in hw/core/machine.c but includes CPU die support. */ -void pc_smp_parse(MachineState *ms, QemuOpts *opts) +static void pc_smp_parse(MachineState *ms, QemuOpts *opts, Error **errp) { unsigned cpus =3D qemu_opt_get_number(opts, "cpus", 0); unsigned sockets =3D qemu_opt_get_number(opts, "sockets", 0); @@ -734,28 +734,28 @@ void pc_smp_parse(MachineState *ms, QemuOpts *opts) threads =3D cpus / (cores * dies * sockets); threads =3D threads > 0 ? threads : 1; } else if (sockets * dies * cores * threads < cpus) { - error_report("cpu topology: " - "sockets (%u) * dies (%u) * cores (%u) * threads (= %u) < " - "smp_cpus (%u)", - sockets, dies, cores, threads, cpus); - exit(1); + error_setg(errp, "cpu topology: " + "sockets (%u) * dies (%u) * cores (%u) * threads (%u) <= " + "smp_cpus (%u)", + sockets, dies, cores, threads, cpus); + return; } =20 ms->smp.max_cpus =3D qemu_opt_get_number(opts, "maxcpus", cpus); =20 if (ms->smp.max_cpus < cpus) { - error_report("maxcpus must be equal to or greater than smp"); - exit(1); + error_setg(errp, "maxcpus must be equal to or greater than smp"); + return; } =20 if (sockets * dies * cores * threads !=3D ms->smp.max_cpus) { - error_report("Invalid CPU topology deprecated: " - "sockets (%u) * dies (%u) * cores (%u) * threads (= %u) " - "!=3D maxcpus (%u)", - sockets, dies, cores, threads, - ms->smp.max_cpus); - exit(1); + error_setg(errp, "Invalid CPU topology deprecated: " + "sockets (%u) * dies (%u) * cores (%u) * threads (%u) " + "!=3D maxcpus (%u)", + sockets, dies, cores, threads, + ms->smp.max_cpus); + return; } =20 ms->smp.cpus =3D cpus; diff --git a/include/hw/boards.h b/include/hw/boards.h index 87ae5cc300..0483d6af86 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -210,7 +210,7 @@ struct MachineClass { void (*reset)(MachineState *state); void (*wakeup)(MachineState *state); int (*kvm_type)(MachineState *machine, const char *arg); - void (*smp_parse)(MachineState *ms, QemuOpts *opts); + void (*smp_parse)(MachineState *ms, QemuOpts *opts, Error **errp); =20 BlockInterfaceType block_default_type; int units_per_default_bus; diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 4c2ca6d36a..87294f2632 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -138,8 +138,6 @@ extern int fd_bootchk; =20 void pc_acpi_smi_interrupt(void *opaque, int irq, int level); =20 -void pc_smp_parse(MachineState *ms, QemuOpts *opts); - void pc_guest_info_init(PCMachineState *pcms); =20 #define PCI_HOST_PROP_PCI_HOLE_START "pci-hole-start" --=20 2.26.2 From nobody Fri May 10 11:48:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1620924782; cv=none; d=zohomail.com; s=zohoarc; b=P69PgQsVYHgReIRfIKhyArgmEMAL/TENv0AtFvCQfZp0w7wmtTDq3tMDkaZQ09h8Vwo2k+KaNOHu9UqxmXpLtOjp+riY3yWK/fYEd4XWzo6Z5ZW4UJRI4PdpTMIjVCC48MchKqaV/sHIKeuO775Kxew234Sc0+T1kFG2oZu6GV8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620924782; 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=ZNccPugVjVOzLgx/53bLQVRPvqP22s7Wh4n+2tEnJ24=; b=KlmqAVD5zYn0LuBjuWbJ6wWoQB2Wl9b7lppu/a+XGciqErv/qn7TvqnalwasinlNjMs7pRL7PluHb+q12E8nu60dNqhC/WlkNmqXvW1REVO/kqbMYeOG8XkQ14yCzcs6JaztxfocAoVnPzuB/qAmslB2GIhKg8oU8Vu4XCfVsF8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620924782732974.6401380975461; Thu, 13 May 2021 09:53:02 -0700 (PDT) Received: from localhost ([::1]:38642 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lhEa4-0000p0-TM for importer@patchew.org; Thu, 13 May 2021 12:53:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40618) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhEDH-0002Sf-Cn for qemu-devel@nongnu.org; Thu, 13 May 2021 12:29:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:41360) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhED7-0003Uj-Tx for qemu-devel@nongnu.org; Thu, 13 May 2021 12:29:27 -0400 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-428-5lIRRvqcNcioxs1OhTbeAg-1; Thu, 13 May 2021 12:29:14 -0400 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 53AC88005AD; Thu, 13 May 2021 16:29:13 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id D9F14BA6F; Thu, 13 May 2021 16:29:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620923356; h=from:from: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; bh=ZNccPugVjVOzLgx/53bLQVRPvqP22s7Wh4n+2tEnJ24=; b=MqEyTDJ26/dSTTY1hrqmV0ZluOA8LbzwLcV3aGwnyQK9J5eE5r7DQnd+m2ri/sXDj8rG7P rNnm29TQGtMQDJQ1VBiuCBQKhD6nXyOWZJTNywg/foX0rloXS3d9eCIVczSo5/vhbMlt4g Ws9dzpXF9ytJaN9z+vMXeB/hTYLm1hQ= X-MC-Unique: 5lIRRvqcNcioxs1OhTbeAg-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 12/14] machine: pass QAPI struct to mc->smp_parse Date: Thu, 13 May 2021 12:28:59 -0400 Message-Id: <20210513162901.1310239-13-pbonzini@redhat.com> In-Reply-To: <20210513162901.1310239-1-pbonzini@redhat.com> References: <20210513162901.1310239-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yang.zhong@intel.com, berrange@redhat.com, ehabkost@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" As part of converting -smp to a property with a QAPI type, define the struct and use it to do the actual parsing. machine_smp_parse takes care of doing the QemuOpts->QAPI conversion by hand, for now. Signed-off-by: Paolo Bonzini --- hw/core/machine.c | 33 +++++++++++++++++++++++---------- hw/i386/pc.c | 18 ++++++++---------- include/hw/boards.h | 2 +- qapi/machine.json | 27 +++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 21 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 70c297a7de..7daca0b86a 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -738,12 +738,12 @@ void machine_set_cpu_numa_node(MachineState *machine, } } =20 -static void smp_parse(MachineState *ms, QemuOpts *opts, Error **errp) +static void smp_parse(MachineState *ms, SMPConfiguration *config, Error **= errp) { - unsigned cpus =3D qemu_opt_get_number(opts, "cpus", 0); - unsigned sockets =3D qemu_opt_get_number(opts, "sockets", 0); - unsigned cores =3D qemu_opt_get_number(opts, "cores", 0); - unsigned threads =3D qemu_opt_get_number(opts, "threads", 0); + unsigned cpus =3D config->has_cpus ? config->cpus : 0; + unsigned sockets =3D config->has_sockets ? config->sockets : 0; + unsigned cores =3D config->has_cores ? config->cores : 0; + unsigned threads =3D config->has_threads ? config->threads : 0; =20 /* compute missing values, prefer sockets over cores over threads */ if (cpus =3D=3D 0 || sockets =3D=3D 0) { @@ -753,8 +753,7 @@ static void smp_parse(MachineState *ms, QemuOpts *opts,= Error **errp) sockets =3D sockets > 0 ? sockets : 1; cpus =3D cores * threads * sockets; } else { - ms->smp.max_cpus =3D - qemu_opt_get_number(opts, "maxcpus", cpus); + ms->smp.max_cpus =3D config->has_maxcpus ? config->maxcpus : c= pus; sockets =3D ms->smp.max_cpus / (cores * threads); } } else if (cores =3D=3D 0) { @@ -772,8 +771,7 @@ static void smp_parse(MachineState *ms, QemuOpts *opts,= Error **errp) return; } =20 - ms->smp.max_cpus =3D - qemu_opt_get_number(opts, "maxcpus", cpus); + ms->smp.max_cpus =3D config->has_maxcpus ? config->maxcpus : cpus; =20 if (ms->smp.max_cpus < cpus) { error_setg(errp, "maxcpus must be equal to or greater than smp"); @@ -1128,7 +1126,22 @@ bool machine_smp_parse(MachineState *ms, QemuOpts *o= pts, Error **errp) ERRP_GUARD(); =20 if (opts) { - mc->smp_parse(ms, opts, errp); + SMPConfiguration config =3D { + .has_cpus =3D !!qemu_opt_get(opts, "cpus"), + .cpus =3D qemu_opt_get_number(opts, "cpus", 0), + .has_sockets =3D !!qemu_opt_get(opts, "sockets"), + .sockets =3D qemu_opt_get_number(opts, "sockets", 0), + .has_dies =3D !!qemu_opt_get(opts, "dies"), + .dies =3D qemu_opt_get_number(opts, "dies", 0), + .has_cores =3D !!qemu_opt_get(opts, "cores"), + .cores =3D qemu_opt_get_number(opts, "cores", 0), + .has_threads =3D !!qemu_opt_get(opts, "threads"), + .threads =3D qemu_opt_get_number(opts, "threads", 0), + .has_maxcpus =3D !!qemu_opt_get(opts, "maxcpus"), + .maxcpus =3D qemu_opt_get_number(opts, "maxcpus", 0), + }; + + mc->smp_parse(ms, &config, errp); if (*errp) { return false; } diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 1760e94ff5..14ed30bb78 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -706,13 +706,13 @@ void pc_acpi_smi_interrupt(void *opaque, int irq, int= level) * This function is very similar to smp_parse() * in hw/core/machine.c but includes CPU die support. */ -static void pc_smp_parse(MachineState *ms, QemuOpts *opts, Error **errp) +static void pc_smp_parse(MachineState *ms, SMPConfiguration *config, Error= **errp) { - unsigned cpus =3D qemu_opt_get_number(opts, "cpus", 0); - unsigned sockets =3D qemu_opt_get_number(opts, "sockets", 0); - unsigned dies =3D qemu_opt_get_number(opts, "dies", 1); - unsigned cores =3D qemu_opt_get_number(opts, "cores", 0); - unsigned threads =3D qemu_opt_get_number(opts, "threads", 0); + unsigned cpus =3D config->has_cpus ? config->cpus : 0; + unsigned sockets =3D config->has_sockets ? config->sockets : 0; + unsigned dies =3D config->has_dies ? config->dies : 1; + unsigned cores =3D config->has_cores ? config->cores : 0; + unsigned threads =3D config->has_threads ? config->threads : 0; =20 /* compute missing values, prefer sockets over cores over threads */ if (cpus =3D=3D 0 || sockets =3D=3D 0) { @@ -722,8 +722,7 @@ static void pc_smp_parse(MachineState *ms, QemuOpts *op= ts, Error **errp) sockets =3D sockets > 0 ? sockets : 1; cpus =3D cores * threads * dies * sockets; } else { - ms->smp.max_cpus =3D - qemu_opt_get_number(opts, "maxcpus", cpus); + ms->smp.max_cpus =3D config->has_maxcpus ? config->maxcpus : c= pus; sockets =3D ms->smp.max_cpus / (cores * threads * dies); } } else if (cores =3D=3D 0) { @@ -741,8 +740,7 @@ static void pc_smp_parse(MachineState *ms, QemuOpts *op= ts, Error **errp) return; } =20 - ms->smp.max_cpus =3D - qemu_opt_get_number(opts, "maxcpus", cpus); + ms->smp.max_cpus =3D config->has_maxcpus ? config->maxcpus : cpus; =20 if (ms->smp.max_cpus < cpus) { error_setg(errp, "maxcpus must be equal to or greater than smp"); diff --git a/include/hw/boards.h b/include/hw/boards.h index 0483d6af86..1eae4427e8 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -210,7 +210,7 @@ struct MachineClass { void (*reset)(MachineState *state); void (*wakeup)(MachineState *state); int (*kvm_type)(MachineState *machine, const char *arg); - void (*smp_parse)(MachineState *ms, QemuOpts *opts, Error **errp); + void (*smp_parse)(MachineState *ms, SMPConfiguration *config, Error **= errp); =20 BlockInterfaceType block_default_type; int units_per_default_bus; diff --git a/qapi/machine.json b/qapi/machine.json index 6e90d463fc..3a6a21fd01 100644 --- a/qapi/machine.json +++ b/qapi/machine.json @@ -1274,3 +1274,30 @@ ## { 'event': 'MEM_UNPLUG_ERROR', 'data': { 'device': 'str', 'msg': 'str' } } + +## +# @SMPConfiguration: +# +# Schema for CPU topology configuration. +# +# @cpus: number of virtual CPUs in the virtual machine +# +# @sockets: number of sockets in the CPU topology +# +# @dies: number of dies per socket in the CPU topology +# +# @cores: number of cores per thread in the CPU topology +# +# @threads: number of threads per core in the CPU topology +# +# @maxcpus: maximum number of hotpluggable virtual CPUs in the virtual mac= hine +# +# Since: 6.1 +## +{ 'struct': 'SMPConfiguration', 'data': { + '*cpus': 'int', + '*sockets': 'int', + '*dies': 'int', + '*cores': 'int', + '*threads': 'int', + '*maxcpus': 'int' } } --=20 2.26.2 From nobody Fri May 10 11:48:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1620923674; cv=none; d=zohomail.com; s=zohoarc; b=O9P8wsBgsWvXGmkQ5mKIPQIlCI3RzSwbPkiRWzqhWU5UTipt1QPbD/4dzSGZvCB5fluy2G8O5vX8W0ikgDUv6aGNLES7EWRh2j6DQBZMtdTLu59D2ZTmCJ78vo0fSG3XsvoRMXPd+Z+pMcZcKLigvkTxUtdvZoYLfpvRmg/wYUc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620923674; 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=5+1H2gGtRtAZDG0VpRdXHhbd0wUiC91qkBw+/1V6wv8=; b=n5TQK03H1x5m4c13ZvzhqWHJ3HiUCIxNw7fWWITqs6bovcC9NQrFkw8xz+dU5XcS9YMnj5XDp/oabVzNWX+aiLPLiSPpESSluviTHlS4YgJLfP/LrzljJtQSPOVyXkDawmk17lTEbgLZOH0wGl+pGkwQi3WRELkRRZHpo0cDjVE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620923674410600.2888840698662; Thu, 13 May 2021 09:34:34 -0700 (PDT) Received: from localhost ([::1]:33070 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lhEIC-0002T5-Gr for importer@patchew.org; Thu, 13 May 2021 12:34:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40636) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhEDK-0002YR-L8 for qemu-devel@nongnu.org; Thu, 13 May 2021 12:29:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:38617) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhED8-0003V7-1e for qemu-devel@nongnu.org; Thu, 13 May 2021 12:29:30 -0400 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-27-VYTMDIdINgqF4ji7VANMyg-1; Thu, 13 May 2021 12:29:14 -0400 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 DDFD31005D4E; Thu, 13 May 2021 16:29:13 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E276BA6F; Thu, 13 May 2021 16:29:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620923356; h=from:from: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; bh=5+1H2gGtRtAZDG0VpRdXHhbd0wUiC91qkBw+/1V6wv8=; b=a5G3o/AU+Xn/7bTcBa5QcyjeDHtL1JRvJKB5ekBJNa+yEgqO2AiPVy9CBQUCgfK7bZvlpN nPfLWhsIa88/HFhNTmnlTu96YzPai8DxiTd9jKP1wg3eiEhUwnKKG9N53nxRiwme0Pdj7t ejw6DruIcdtR+PAF2ile4SCLLos64zg= X-MC-Unique: VYTMDIdINgqF4ji7VANMyg-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 13/14] machine: reject -smp dies!=1 for non-PC machines Date: Thu, 13 May 2021 12:29:00 -0400 Message-Id: <20210513162901.1310239-14-pbonzini@redhat.com> In-Reply-To: <20210513162901.1310239-1-pbonzini@redhat.com> References: <20210513162901.1310239-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yang.zhong@intel.com, berrange@redhat.com, ehabkost@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- hw/core/machine.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/core/machine.c b/hw/core/machine.c index 7daca0b86a..55e878fc3e 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -745,6 +745,10 @@ static void smp_parse(MachineState *ms, SMPConfigurati= on *config, Error **errp) unsigned cores =3D config->has_cores ? config->cores : 0; unsigned threads =3D config->has_threads ? config->threads : 0; =20 + if (config->has_dies && config->dies !=3D 0 && config->dies !=3D 1) { + error_setg(errp, "dies not supported by this machine's CPU topolog= y"); + } + /* compute missing values, prefer sockets over cores over threads */ if (cpus =3D=3D 0 || sockets =3D=3D 0) { cores =3D cores > 0 ? cores : 1; --=20 2.26.2 From nobody Fri May 10 11:48:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1620924253; cv=none; d=zohomail.com; s=zohoarc; b=R2RM8KQWdb+t0Sw1WR6Ncj2aB71yuhefEk0ml3HwJbIOaaeR9BLYwIURJwSydy5/YoEOYxsyoXdEfU4jRsZVXuToAz2Od65qYcPire02X4iUaX8jIp3VQnVDqzAmX7WOqdkzufhMEzEL64anzQsh2Enx9gb1P2Bq2/e3i3IFMpk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620924253; 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=J9qZn9QgVHrZreV/T0Lm7SWjQEmBkWaOZe/+7WLLBdM=; b=ifvcI/9toa+JOJjPUnXc1oBfDB35wLwtzY5hd+tyzVIJSKCghkQbf+3FRip12tlHmMu7NpM4sZeMadFQDW/aI/oCSK3nbwQIzj707o165UUELh8jg92dTT1EzSmNo2WTOBDFHVzaSjpYKWTTXFNJ4FOhw2UpU079gCas9po+zD0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620924253544563.4365806024496; Thu, 13 May 2021 09:44:13 -0700 (PDT) Received: from localhost ([::1]:50212 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lhERQ-0005tH-R7 for importer@patchew.org; Thu, 13 May 2021 12:44:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40602) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhEDD-0002Op-LU for qemu-devel@nongnu.org; Thu, 13 May 2021 12:29:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:56914) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhED7-0003VT-VK for qemu-devel@nongnu.org; Thu, 13 May 2021 12:29:23 -0400 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-2-dHPLcBydPKmnvyINEOe8vg-1; Thu, 13 May 2021 12:29:15 -0400 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 735AA1922025; Thu, 13 May 2021 16:29:14 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0386150233; Thu, 13 May 2021 16:29:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620923357; h=from:from: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; bh=J9qZn9QgVHrZreV/T0Lm7SWjQEmBkWaOZe/+7WLLBdM=; b=LU6uJkbBE7ovQkBu5X/W82wGxfdy++GVijT5mp8JvtrR73KnqYquy0++UOuqX0BwVxabTR tr/hNuboSee+QbiML+RmZK2M/iH+JBdjeQOaIoZk7pUCULs3qJth7QPFPXtnw9rRPSfrAk d+hmMt1KwPFQ0+oMsqlQ3fPnWjmOe0g= X-MC-Unique: dHPLcBydPKmnvyINEOe8vg-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 14/14] machine: add smp compound property Date: Thu, 13 May 2021 12:29:01 -0400 Message-Id: <20210513162901.1310239-15-pbonzini@redhat.com> In-Reply-To: <20210513162901.1310239-1-pbonzini@redhat.com> References: <20210513162901.1310239-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yang.zhong@intel.com, berrange@redhat.com, ehabkost@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Make -smp syntactic sugar for a compound property "-machine smp.{cores,threads,cpu,...}". machine_smp_parse is replaced by the setter for the property. numa-test will now cover the new syntax, while other tests still use -smp. Signed-off-by: Paolo Bonzini --- hw/core/machine.c | 108 +++++++++++++++++++++------------------- softmmu/vl.c | 33 +++++++++--- tests/qtest/numa-test.c | 22 ++++---- 3 files changed, 95 insertions(+), 68 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 55e878fc3e..f33c9ce78c 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -19,6 +19,7 @@ #include "hw/loader.h" #include "qapi/error.h" #include "qapi/qapi-visit-common.h" +#include "qapi/qapi-visit-machine.h" #include "qapi/visitor.h" #include "hw/sysbus.h" #include "sysemu/cpus.h" @@ -797,6 +798,57 @@ static void smp_parse(MachineState *ms, SMPConfigurati= on *config, Error **errp) ms->smp.sockets =3D sockets; } =20 +static void machine_get_smp(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + MachineState *ms =3D MACHINE(obj); + SMPConfiguration *config =3D &(SMPConfiguration){ + .has_cores =3D true, .cores =3D ms->smp.cores, + .has_sockets =3D true, .sockets =3D ms->smp.sockets, + .has_dies =3D true, .dies =3D ms->smp.dies, + .has_threads =3D true, .threads =3D ms->smp.threads, + .has_cpus =3D true, .cpus =3D ms->smp.cpus, + .has_maxcpus =3D true, .maxcpus =3D ms->smp.max_cpus, + }; + if (!visit_type_SMPConfiguration(v, name, &config, &error_abort)) { + return; + } +} + +static void machine_set_smp(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + MachineClass *mc =3D MACHINE_GET_CLASS(obj); + MachineState *ms =3D MACHINE(obj); + SMPConfiguration *config; + ERRP_GUARD(); + + if (!visit_type_SMPConfiguration(v, name, &config, errp)) { + return; + } + + mc->smp_parse(ms, config, errp); + if (errp) { + goto out_free; + } + + /* sanity-check smp_cpus and max_cpus against mc */ + if (ms->smp.cpus < mc->min_cpus) { + error_setg(errp, "Invalid SMP CPUs %d. The min CPUs " + "supported by machine '%s' is %d", + ms->smp.cpus, + mc->name, mc->min_cpus); + } else if (ms->smp.max_cpus > mc->max_cpus) { + error_setg(errp, "Invalid SMP CPUs %d. The max CPUs " + "supported by machine '%s' is %d", + current_machine->smp.max_cpus, + mc->name, mc->max_cpus); + } + +out_free: + qapi_free_SMPConfiguration(config); +} + static void machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc =3D MACHINE_CLASS(oc); @@ -836,6 +888,12 @@ static void machine_class_init(ObjectClass *oc, void *= data) object_class_property_set_description(oc, "dumpdtb", "Dump current dtb to a file and quit"); =20 + object_class_property_add(oc, "smp", "SMPConfiguration", + machine_get_smp, machine_set_smp, + NULL, NULL); + object_class_property_set_description(oc, "smp", + "CPU topology"); + object_class_property_add(oc, "phandle-start", "int", machine_get_phandle_start, machine_set_phandle_start, NULL, NULL); @@ -1124,56 +1182,6 @@ MemoryRegion *machine_consume_memdev(MachineState *m= achine, return ret; } =20 -bool machine_smp_parse(MachineState *ms, QemuOpts *opts, Error **errp) -{ - MachineClass *mc =3D MACHINE_GET_CLASS(ms); - ERRP_GUARD(); - - if (opts) { - SMPConfiguration config =3D { - .has_cpus =3D !!qemu_opt_get(opts, "cpus"), - .cpus =3D qemu_opt_get_number(opts, "cpus", 0), - .has_sockets =3D !!qemu_opt_get(opts, "sockets"), - .sockets =3D qemu_opt_get_number(opts, "sockets", 0), - .has_dies =3D !!qemu_opt_get(opts, "dies"), - .dies =3D qemu_opt_get_number(opts, "dies", 0), - .has_cores =3D !!qemu_opt_get(opts, "cores"), - .cores =3D qemu_opt_get_number(opts, "cores", 0), - .has_threads =3D !!qemu_opt_get(opts, "threads"), - .threads =3D qemu_opt_get_number(opts, "threads", 0), - .has_maxcpus =3D !!qemu_opt_get(opts, "maxcpus"), - .maxcpus =3D qemu_opt_get_number(opts, "maxcpus", 0), - }; - - mc->smp_parse(ms, &config, errp); - if (*errp) { - return false; - } - } - - /* sanity-check smp_cpus and max_cpus against mc */ - if (ms->smp.cpus < mc->min_cpus) { - error_setg(errp, "Invalid SMP CPUs %d. The min CPUs " - "supported by machine '%s' is %d", - ms->smp.cpus, - mc->name, mc->min_cpus); - return false; - } else if (ms->smp.max_cpus > mc->max_cpus) { - error_setg(errp, "Invalid SMP CPUs %d. The max CPUs " - "supported by machine '%s' is %d", - current_machine->smp.max_cpus, - mc->name, mc->max_cpus); - return false; - } - - if (ms->smp.cpus > 1) { - Error *blocker =3D NULL; - error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, "smp"); - replay_add_blocker(blocker); - } - return true; -} - void machine_run_board_init(MachineState *machine) { MachineClass *machine_class =3D MACHINE_GET_CLASS(machine); diff --git a/softmmu/vl.c b/softmmu/vl.c index de844f08d7..555385e64d 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -1504,6 +1504,25 @@ static void machine_help_func(const QDict *qdict) } } =20 +static void +machine_parse_property_opt(QemuOptsList *opts_list, const char *propname, + const char *arg, Error **errp) +{ + QDict *opts, *prop; + bool help =3D false; + ERRP_GUARD(); + + prop =3D keyval_parse(arg, opts_list->implied_opt_name, &help, errp); + if (help) { + qemu_opts_print_help(opts_list, true); + return; + } + opts =3D qdict_new(); + qdict_put(opts, propname, prop); + keyval_merge(machine_opts_dict, opts, errp); + qobject_unref(opts); +} + static const char *pid_file; static Notifier qemu_unlink_pidfile_notifier; =20 @@ -1796,6 +1815,12 @@ static void qemu_apply_machine_options(QDict *qdict) /* fall back to the -kernel/-append */ semihosting_arg_fallback(current_machine->kernel_filename, current= _machine->kernel_cmdline); } + + if (current_machine->smp.cpus > 1) { + Error *blocker =3D NULL; + error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, "smp"); + replay_add_blocker(blocker); + } } =20 static void qemu_create_early_backends(void) @@ -2039,9 +2064,6 @@ static void qemu_create_machine(QDict *qdict) qemu_set_hw_version(machine_class->hw_version); } =20 - machine_smp_parse(current_machine, - qemu_opts_find(qemu_find_opts("smp-opts"), NULL), &error_fatal); - /* * Get the default machine options from the machine if it is not alrea= dy * specified either by the configuration file or by the command line. @@ -3325,10 +3347,7 @@ void qemu_init(int argc, char **argv, char **envp) } break; case QEMU_OPTION_smp: - if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"), - optarg, true)) { - exit(1); - } + machine_parse_property_opt(qemu_find_opts("smp-opts"), "sm= p", optarg, &error_fatal); break; case QEMU_OPTION_vnc: vnc_parse(optarg); diff --git a/tests/qtest/numa-test.c b/tests/qtest/numa-test.c index dc0ec571ca..c677cd63c4 100644 --- a/tests/qtest/numa-test.c +++ b/tests/qtest/numa-test.c @@ -25,7 +25,7 @@ static void test_mon_explicit(const void *data) g_autofree char *s =3D NULL; g_autofree char *cli =3D NULL; =20 - cli =3D make_cli(data, "-smp 8 -numa node,nodeid=3D0,memdev=3Dram,cpus= =3D0-3 " + cli =3D make_cli(data, "-machine smp.cpus=3D8 -numa node,nodeid=3D0,me= mdev=3Dram,cpus=3D0-3 " "-numa node,nodeid=3D1,cpus=3D4-7"); qts =3D qtest_init(cli); =20 @@ -42,7 +42,7 @@ static void test_def_cpu_split(const void *data) g_autofree char *s =3D NULL; g_autofree char *cli =3D NULL; =20 - cli =3D make_cli(data, "-smp 8 -numa node,memdev=3Dram -numa node"); + cli =3D make_cli(data, "-machine smp.cpus=3D8 -numa node,memdev=3Dram = -numa node"); qts =3D qtest_init(cli); =20 s =3D qtest_hmp(qts, "info numa"); @@ -58,7 +58,7 @@ static void test_mon_partial(const void *data) g_autofree char *s =3D NULL; g_autofree char *cli =3D NULL; =20 - cli =3D make_cli(data, "-smp 8 " + cli =3D make_cli(data, "-machine smp.cpus=3D8 " "-numa node,nodeid=3D0,memdev=3Dram,cpus=3D0-1 " "-numa node,nodeid=3D1,cpus=3D4-5 "); qts =3D qtest_init(cli); @@ -86,7 +86,7 @@ static void test_query_cpus(const void *data) QTestState *qts; g_autofree char *cli =3D NULL; =20 - cli =3D make_cli(data, "-smp 8 -numa node,memdev=3Dram,cpus=3D0-3 " + cli =3D make_cli(data, "-machine smp.cpus=3D8 -numa node,memdev=3Dram,= cpus=3D0-3 " "-numa node,cpus=3D4-7"); qts =3D qtest_init(cli); cpus =3D get_cpus(qts, &resp); @@ -124,7 +124,7 @@ static void pc_numa_cpu(const void *data) QTestState *qts; g_autofree char *cli =3D NULL; =20 - cli =3D make_cli(data, "-cpu pentium -smp 8,sockets=3D2,cores=3D2,thre= ads=3D2 " + cli =3D make_cli(data, "-cpu pentium -machine smp.cpus=3D8,smp.sockets= =3D2,smp.cores=3D2,smp.threads=3D2 " "-numa node,nodeid=3D0,memdev=3Dram -numa node,nodeid=3D1 " "-numa cpu,node-id=3D1,socket-id=3D0 " "-numa cpu,node-id=3D0,socket-id=3D1,core-id=3D0 " @@ -177,7 +177,7 @@ static void spapr_numa_cpu(const void *data) QTestState *qts; g_autofree char *cli =3D NULL; =20 - cli =3D make_cli(data, "-smp 4,cores=3D4 " + cli =3D make_cli(data, "-machine smp.cpus=3D4,smp.cores=3D4 " "-numa node,nodeid=3D0,memdev=3Dram -numa node,nodeid=3D1 " "-numa cpu,node-id=3D0,core-id=3D0 " "-numa cpu,node-id=3D0,core-id=3D1 " @@ -222,7 +222,7 @@ static void aarch64_numa_cpu(const void *data) QTestState *qts; g_autofree char *cli =3D NULL; =20 - cli =3D make_cli(data, "-smp 2 " + cli =3D make_cli(data, "-machine smp.cpus=3D2 " "-numa node,nodeid=3D0,memdev=3Dram -numa node,nodeid=3D1 " "-numa cpu,node-id=3D1,thread-id=3D0 " "-numa cpu,node-id=3D0,thread-id=3D1"); @@ -265,7 +265,7 @@ static void pc_dynamic_cpu_cfg(const void *data) QTestState *qs; g_autofree char *cli =3D NULL; =20 - cli =3D make_cli(data, "-nodefaults --preconfig -smp 2"); + cli =3D make_cli(data, "-nodefaults --preconfig -machine smp.cpus=3D2"= ); qs =3D qtest_init(cli); =20 /* create 2 numa nodes */ @@ -324,7 +324,7 @@ static void pc_hmat_build_cfg(const void *data) g_autofree char *cli =3D NULL; =20 cli =3D make_cli(data, "-nodefaults --preconfig -machine hmat=3Don " - "-smp 2,sockets=3D2 " + "-machine smp.cpus=3D2,smp.sockets=3D2 " "-m 128M,slots=3D2,maxmem=3D1G " "-object memory-backend-ram,size=3D64M,id=3Dm0 " "-object memory-backend-ram,size=3D64M,id=3Dm1 " @@ -453,7 +453,7 @@ static void pc_hmat_off_cfg(const void *data) g_autofree char *cli =3D NULL; =20 cli =3D make_cli(data, "-nodefaults --preconfig " - "-smp 2,sockets=3D2 " + "-machine smp.cpus=3D2,smp.sockets=3D2 " "-m 128M,slots=3D2,maxmem=3D1G " "-object memory-backend-ram,size=3D64M,id=3Dm0,pr= ealloc=3Dy " "-object memory-backend-ram,size=3D64M,id=3Dm1 " @@ -492,7 +492,7 @@ static void pc_hmat_erange_cfg(const void *data) g_autofree char *cli =3D NULL; =20 cli =3D make_cli(data, "-nodefaults --preconfig -machine hmat=3Don " - "-smp 2,sockets=3D2 " + "-machine smp.cpus=3D2,smp.sockets=3D2 " "-m 128M,slots=3D2,maxmem=3D1G " "-object memory-backend-ram,size=3D64M,id=3Dm0 " "-object memory-backend-ram,size=3D64M,id=3Dm1 " --=20 2.26.2