From nobody Thu Apr 25 09:28:58 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623332406321983.2948373536437; Thu, 10 Jun 2021 06:40:06 -0700 (PDT) Received: from localhost ([::1]:57080 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrKud-0001Vo-0a for importer2@patchew.org; Thu, 10 Jun 2021 09:40:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47446) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrKqY-0001ay-3C for qemu-devel@nongnu.org; Thu, 10 Jun 2021 09:35:46 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]:43782) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrKqV-0005cq-V8 for qemu-devel@nongnu.org; Thu, 10 Jun 2021 09:35:45 -0400 Received: by mail-wm1-x334.google.com with SMTP id 3-20020a05600c0243b029019f2f9b2b8aso6455858wmj.2 for ; Thu, 10 Jun 2021 06:35:42 -0700 (PDT) Received: from avogadro.redhat.com ([2001:b07:6468:f312:63a7:c72e:ea0e:6045]) by smtp.gmail.com with ESMTPSA id v8sm4032519wrc.29.2021.06.10.06.35.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 06:35:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eaWfNNyaVagDad1eRt/V1RCmBUTKiX/vUI2Ausu/1+0=; b=lfLrOopv4BLpgD6gZpy9fzPZ1eV7wMIWZa4eHg5rBnr0CTPmr7vsBUi9gbVYvI1QIF zR3Pk/dmziOMiOhcRb+DJtif3cmXkt83vEVcbjYvba+ZX1K9ORjVFOjC5e15NpM87Nji yBzqfC6+X+Zz1xz0NIC0OeuBCPJv7wrvq9HWMQDP/VosaQlrExznFCfErElVTb/knFEY 7f9M5ZcMqQxxIMehyk6zRU59qwz4aEMykQuXxAb05rHa5tUDImnOjSp0Qe1jp1T5fS6L PY0xSxYeIHPZ3wn8oOR7IZZfEFowDkcywA12vanc1n+ByYNpPNLTk4Eh6QVhyFf4ZWGz 7qvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=eaWfNNyaVagDad1eRt/V1RCmBUTKiX/vUI2Ausu/1+0=; b=K9NlFVGEYP6griQD1mg8Wz6uPV3xX7lO6PMZxtQajvbZ0SgQXd8mChSTWExYpSwUYs 3C+m6FFiUKz1ABEOHtMyzL2W4yJZPC0j8/VKXw/qzJZ49VCW0+8etL+JvF3q4y2ilL/m 3mdEbWWjrx0S8yTQBA0NADsVEocNRc2mkLni4GyxlDmSyyY4nB1PzOGou5paZwUMmrPn MmZvu/b4MsygXK2D+j0eYLpRiSqwXC9KZVeLqEsXtPqpukfIF8WoXTeB/JKe+lxjd+we 977YTWE4aPieCypjMC3INM+x1MKICZ24x2ldoBs+Yk1tSuu7mAtL1k354uGub1h+I8Ho qp2Q== X-Gm-Message-State: AOAM5333+PgpMICxcWCv0C1gzIBSQLy56nFgPseyyYKH2z7p6ElLr4Js +yEgSo3Sgk6xZn05H/VT+d5z60zkC4Hy0A== X-Google-Smtp-Source: ABdhPJytjESN3QODT+YUkerqJjdJ3+aeWhUjfPIagGYjNxKXc2D982WDYlmbn2PddvdMxMO3j0mgXQ== X-Received: by 2002:a05:600c:3b11:: with SMTP id m17mr5249700wms.150.1623332141085; Thu, 10 Jun 2021 06:35:41 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 01/11] qom: export more functions for use with non-UserCreatable objects Date: Thu, 10 Jun 2021 15:35:28 +0200 Message-Id: <20210610133538.608390-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210610133538.608390-1-pbonzini@redhat.com> References: <20210610133538.608390-1-pbonzini@redhat.com> MIME-Version: 1.0 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x334.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: berrange@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+importer2=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 Reviewed-by: Daniel P. Berrang=C3=A9 --- 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.31.1 From nobody Thu Apr 25 09:28:58 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623332250737713.679700088513; Thu, 10 Jun 2021 06:37:30 -0700 (PDT) Received: from localhost ([::1]:48504 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrKsD-0004Gi-Gp for importer2@patchew.org; Thu, 10 Jun 2021 09:37:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47440) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrKqY-0001av-0w for qemu-devel@nongnu.org; Thu, 10 Jun 2021 09:35:46 -0400 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]:33661) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrKqV-0005dT-W0 for qemu-devel@nongnu.org; Thu, 10 Jun 2021 09:35:45 -0400 Received: by mail-wr1-x42d.google.com with SMTP id a20so2401029wrc.0 for ; Thu, 10 Jun 2021 06:35:42 -0700 (PDT) Received: from avogadro.redhat.com ([2001:b07:6468:f312:63a7:c72e:ea0e:6045]) by smtp.gmail.com with ESMTPSA id v8sm4032519wrc.29.2021.06.10.06.35.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 06:35:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Qih0GKGRLKmsxOwD0kzGhjmPgfqEGBiIre4xMkTVeaI=; b=ROyIpx71McJWuMv6RtnBZWNiPCQ4qKObtSw5JojLQA+1wwQpxp1gnrlzcBWKX8SJf6 swaGWKQEVILBPfZYOK/Xl2JXmVf5WRO0lTAVBMphQYR9cXT9o3HUS75HCh9T7gb68DHu Z0u8f122RhhOn9QTBRA1aYaS9VSDRE5ZFOchpmo2r2kk3bqOjGN2YuG/FlxA2IUdIjPY ACbvDHeFN5qOAonE/1voEgv3VAWmuEmNKOJZ2AapJujJnITGfxUm/ZEfrB3Pb77CFp8c wVwLVKubBdP0KTna3AitzpwNOWFDbi70K4fVslLutbAZkWGE+pbQw3Mu66/OJv6H760W 2+BQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=Qih0GKGRLKmsxOwD0kzGhjmPgfqEGBiIre4xMkTVeaI=; b=Q8YY63tsONvibBUjvDDUHdJt0VHAVtuPr02ingfi8vKljFTwZ041cpWfG3vp0DYw8I UKnEMTviG7Lh1AYzmirkdLOLpukKlQpT0NvdlK6t/jAn3bYiUUyuYffw+182oxO48Pbr p9KiNw4+0uiQxjCIEY3VWs4IqIUhTPyf3ebF0J0FSO6jjM2GAlsxOrcScDikR2aOJ7jl Z435gfuHO44xNRv0gxeIcJRB4C0AE3w6hbvpPrtkDYS+r+0h5B+VAjJNRSEhgVpSbJsR xs8HxAm9ltTNagL6109w6gCxPymVlrNTulIa4AxQJbahw0EQuKSbkZ5cUK5+lDMJY/7d Oljg== X-Gm-Message-State: AOAM530NGvgJu31QQTBgmKwGP95w9JGXCS7WuxKuijGb4LSj/UGBEEVP +d5TQ0gqln0+AB/e/MMPX04+tdZKu74EPA== X-Google-Smtp-Source: ABdhPJze1A0r9/w316C1CMA2QQEwUjVzwNoqob/lLzFnSeXcKaKxmulTIcUFit8AEVfcoFfvMs1cbg== X-Received: by 2002:a5d:6acf:: with SMTP id u15mr5620993wrw.262.1623332141869; Thu, 10 Jun 2021 06:35:41 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 02/11] keyval: introduce keyval_merge Date: Thu, 10 Jun 2021 15:35:29 +0200 Message-Id: <20210610133538.608390-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210610133538.608390-1-pbonzini@redhat.com> References: <20210610133538.608390-1-pbonzini@redhat.com> MIME-Version: 1.0 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::42d; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x42d.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: berrange@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This patch introduces a function that merges two keyval-produced (or keyval-like) QDicts. It can be used to emulate the behavior of .merge_lists =3D true QemuOpts groups, merging -readconfig sections and command-line options in a single QDict, and also to implement -set. Signed-off-by: Paolo Bonzini --- include/qemu/option.h | 1 + tests/unit/test-keyval.c | 56 ++++++++++++++++++++++++++++++++++++++++ util/keyval.c | 47 +++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+) 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/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.31.1 From nobody Thu Apr 25 09:28:58 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623332283282581.4297718388984; Thu, 10 Jun 2021 06:38:03 -0700 (PDT) Received: from localhost ([::1]:51802 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrKsj-0006SZ-Vz for importer2@patchew.org; Thu, 10 Jun 2021 09:38:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47444) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrKqY-0001ax-2n for qemu-devel@nongnu.org; Thu, 10 Jun 2021 09:35:46 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]:53207) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrKqW-0005dZ-07 for qemu-devel@nongnu.org; Thu, 10 Jun 2021 09:35:45 -0400 Received: by mail-wm1-x32c.google.com with SMTP id f17so6195020wmf.2 for ; Thu, 10 Jun 2021 06:35:43 -0700 (PDT) Received: from avogadro.redhat.com ([2001:b07:6468:f312:63a7:c72e:ea0e:6045]) by smtp.gmail.com with ESMTPSA id v8sm4032519wrc.29.2021.06.10.06.35.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 06:35:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/PRr41PxTyXm10FMURUstxjpacQwh84HXdIsa79wlV8=; b=sOCwqfia5KNKkGHOHIUZB/ovym/LEQjepAQuco4VmTO3Vftl9/BmNe79aatTtbzMZl j4g6Lfi8pD/Zv8osn3S0YWckR6b7zBtz4105UKgj3RLAe+20ZOORc1Q+nuciC4WXNE8s X3pgKziRRsdfdcpNHnh7Z0g4OuYa3+xgxJCx/rY3ozJvsSew0TDUSAxyedr3O8sMgVe5 zZI4825ZzJUwWf8BRl/wiaW2nwqCzfz2fGPnXZtiPFV8K8JZbDf5Ur2WpE1XtwTtbJb6 ajrDSLdoiQ2UoBEcESpcieeHJwofxsXSBBNYu+h+AzStFJ1L61wmslmC3Jh2PIdqJSD4 bPGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=/PRr41PxTyXm10FMURUstxjpacQwh84HXdIsa79wlV8=; b=fimq9TB3hgLpizTNPJ8r/9PLtj5H228jOa5D7WAsLwXl6zCx0Rem9F+/d4ngGbZn5F NBFMl5SkR5FnY9nxdMPZoLSlE5R/J1GJMtFqFXbc3yiS61HnVqwwC85ncFOgWaY4Wqww HDEShtV8rjhc1+qJXVdZ+tsqDAm5Kzp//cNnn1lguHa/LH+GTVO5a9ylDv0WHXuXGzDY tZxznua7J2eNFbNQ8hl/EN9hptCcXzzdPLeQBPahil05y6iYuFhihxgLvoop65YR77n7 Gn2pxNKRHc/eUTNnuD/Vt5p8/OzV6NbC5kUSLkOWTxVialiUASStMLNXTFbMSBfIjXYf YF1A== X-Gm-Message-State: AOAM530+gUWwBplsb2rZSUajBaZMlNg4reL41VqhSCVjmBwLIUslOUiu 5gayZ/IxmZf9dXzDFEDgz6NosctzvglHRg== X-Google-Smtp-Source: ABdhPJwC85AgRNwwJdJjeO1DsVUzD4XIkZ4EV4bm0d+uHW+Zb1i7mezQKjZmRcb51QEVrDs0I3VquA== X-Received: by 2002:a1c:2985:: with SMTP id p127mr5088962wmp.165.1623332142637; Thu, 10 Jun 2021 06:35:42 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 03/11] keyval: introduce keyval_parse_into Date: Thu, 10 Jun 2021 15:35:30 +0200 Message-Id: <20210610133538.608390-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210610133538.608390-1-pbonzini@redhat.com> References: <20210610133538.608390-1-pbonzini@redhat.com> MIME-Version: 1.0 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32c; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x32c.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: berrange@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+importer2=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 Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Markus Armbruster --- 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.31.1 From nobody Thu Apr 25 09:28:58 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16233324165481006.635569171571; Thu, 10 Jun 2021 06:40:16 -0700 (PDT) Received: from localhost ([::1]:57494 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrKut-0001mL-BG for importer2@patchew.org; Thu, 10 Jun 2021 09:40:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47486) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrKqd-0001bm-Nd for qemu-devel@nongnu.org; Thu, 10 Jun 2021 09:35:51 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]:42735) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrKqW-0005dh-TA for qemu-devel@nongnu.org; Thu, 10 Jun 2021 09:35:47 -0400 Received: by mail-wr1-x429.google.com with SMTP id c5so2349074wrq.9 for ; Thu, 10 Jun 2021 06:35:44 -0700 (PDT) Received: from avogadro.redhat.com ([2001:b07:6468:f312:63a7:c72e:ea0e:6045]) by smtp.gmail.com with ESMTPSA id v8sm4032519wrc.29.2021.06.10.06.35.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 06:35:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QSwUNkz7C/UE/bqWbkhtH7ZO8Rrhf/r+2D/bB3t4bOs=; b=Vl39U09vyKe/LrRNiRRsDcm6AnMrppgjBOqsp5M/4XRiJhBRQT/OT76SgvZwG/Ztoq guph3PDa0QY3ihDL1NQ1uDaHTUKjTLcLu1Jj1sID0CnuiR7qMHpcc4OdLczn8125zu3N 6Vlu2OxXhvlTeyo1l+FqNjG2mzd/GOz8FPCDQw4iaOG32ycK7K8LpKrit0y6Yzamz/Jf 0DLC4D/dUPxzwZwrsfr8KZfH/7nPgzWA6oN4vn6pgjund1kTyra/xC0u7pINoi5ERVu+ 7YsUAZ6WrdmR4OR1rwrDwF7gZfEYVgB6cUNwcbsaMMJFkyiOdhE+/zVwkxzEC/uJcCnX cBxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=QSwUNkz7C/UE/bqWbkhtH7ZO8Rrhf/r+2D/bB3t4bOs=; b=r/I/bvmhGz756DaOgwijjbCVgA3i5HVgai5DYmVkcx80wNENtQa7Ye1AHEKGVQL4g/ TYYipCblBWmlhoBAHBBrlBLY4e/IfuCuUoaRUR+3QUta0x2l0jD5QsSym0djEwVLIlzb Ivfmy3JrTZ4bMGx2VJJhDpVZLMi8X/xnBoeuIyGNWv7reSDSZJlQ2vVxxWKo0ABIbe+r KULCVvfsayslv9hiatL5i/X6XGKI8d+WKjB+mxn3SE4RoeMH4Uw0pKqyBL9tzsReL5cq cJGALm4SBTL//wxw6R6HRdsVPKFluxskTwmvNTPrPCg4HG/1QP5Ml9TaUpnH5nvN/d3E IU2A== X-Gm-Message-State: AOAM532WgKz5kHHu6CuRd5q60lwqsYuqujBnIymDM594khRldPwgeREh AgbqcMgH8VDTOqGzvOsbK3G0XG2PpFbjDw== X-Google-Smtp-Source: ABdhPJwRytIVWCnugUnhSUGAduz0prJ9ZNPD5ZgUMl3Dj3llFaaL/7xJK6e1it01q+IarWxnHPgW0Q== X-Received: by 2002:a5d:5182:: with SMTP id k2mr5476978wrv.381.1623332143441; Thu, 10 Jun 2021 06:35:43 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 04/11] vl: switch -M parsing to keyval Date: Thu, 10 Jun 2021 15:35:31 +0200 Message-Id: <20210610133538.608390-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210610133538.608390-1-pbonzini@redhat.com> References: <20210610133538.608390-1-pbonzini@redhat.com> MIME-Version: 1.0 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::429; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x429.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: berrange@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+importer2=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, 140 insertions(+), 163 deletions(-) diff --git a/softmmu/vl.c b/softmmu/vl.c index feb4d201f3..01bcb16560 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -145,6 +145,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; @@ -235,21 +237,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", @@ -498,16 +485,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; @@ -815,33 +792,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" @@ -1546,33 +1496,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; @@ -1625,32 +1573,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 @@ -1669,42 +1616,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 *)) @@ -1819,16 +1794,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; @@ -1857,10 +1830,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 @@ -1907,8 +1878,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(); @@ -2074,16 +2044,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), @@ -2114,8 +2082,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 @@ -2137,7 +2109,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, "object")) { + if (g_str_equal(group, "object") || + g_str_equal(group, "machine")) { return false; } return true; @@ -2150,6 +2123,13 @@ static void qemu_record_config_group(const char *gro= up, QDict *dict, Visitor *v =3D qobject_input_visitor_new_keyval(QOBJECT(dict)); object_option_add_visitor(v); visit_free(v); + } 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(); } @@ -2280,13 +2260,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 @@ -2374,12 +2352,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) { @@ -2719,7 +2696,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); @@ -2760,6 +2736,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); } @@ -2849,8 +2826,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; @@ -2874,16 +2850,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); @@ -2993,7 +2969,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; @@ -3262,17 +3238,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); @@ -3299,12 +3278,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: @@ -3323,12 +3300,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"); @@ -3581,7 +3556,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 /* @@ -3614,7 +3589,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 @@ -3622,12 +3597,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.31.1 From nobody Thu Apr 25 09:28:58 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623332252651565.4772125581677; Thu, 10 Jun 2021 06:37:32 -0700 (PDT) Received: from localhost ([::1]:48800 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrKsF-0004Sd-Fm for importer2@patchew.org; Thu, 10 Jun 2021 09:37:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47488) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrKqd-0001bn-NM for qemu-devel@nongnu.org; Thu, 10 Jun 2021 09:35:51 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]:43779) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrKqX-0005eR-Nc for qemu-devel@nongnu.org; Thu, 10 Jun 2021 09:35:47 -0400 Received: by mail-wm1-x330.google.com with SMTP id 3-20020a05600c0243b029019f2f9b2b8aso6456048wmj.2 for ; Thu, 10 Jun 2021 06:35:45 -0700 (PDT) Received: from avogadro.redhat.com ([2001:b07:6468:f312:63a7:c72e:ea0e:6045]) by smtp.gmail.com with ESMTPSA id v8sm4032519wrc.29.2021.06.10.06.35.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 06:35:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IDPNHb+HPzR8VO7xPUhdfTuo9DK5TmK3Ukrht2Or98o=; b=D1KJfRMRtTVPAJprH8vlx0M83oq0vRrvLhHtlC6MT2EVDOjdRMjaP3gTtWyL3wK8Er ZPI8A2xKKfiOTkN+H/+XPdc/xl+qnzREFDKcX/YrOZZ+XQSMVF7SBt4ecYApqjN3tCZj rGeVhUtnwLn9jauZjtioBrun4thz61fEw+Vu+3g6BA5WHx3F2M505kxwGMw+Xs1g43Zt +OaOmJhSuwwx0KH9ZtoYCMv5onZGVmV7qR49B02DzpTUm2nE4WvZZDTE0cuVWUYWui9t Sj/LYimxQh5TnD/au3oOmzBhN9gi5wMF8CMEFr+9IHesIbzEG5rGLX2yXnS9KKKLaDaN OZ1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=IDPNHb+HPzR8VO7xPUhdfTuo9DK5TmK3Ukrht2Or98o=; b=EWnBMq8NMwSM1xNlemxiNB93U/4+O8JZiyPlklB56AS5B7q6DKcmIttSH1fsIDrE0Y yLbw2UQCFkFb/FUYukkGkodDpu8sfgcNkFN7D5ojyR+kIkt9xENOMJ+pDKgtT8AnR20Y ldZDjzVsOc9E66qagkw2NHTKbNax/ug5nA/XYp2LXYHKgQSIPsfZZCEkZWG4DtS1d0Qs EVKCtlbZBkq3GAwsEkwZqfLn/DECuGdZU35XNA1dRUC4rwDHngyf+an2enDoYvPK7ngd zmo5gTtm4Bm9S1VIAUFunzccmnyqlVhlWcSf0yFAG5sN0e0HOr/RAOXdhekJsyARfNjm Bzgw== X-Gm-Message-State: AOAM533i1vsz1LrKb3RIbLMjZ9+PBV23ql3kTqUHvfpWW0X1HOYOOVs4 EtGeSWKYSz4E/JUBDJiH1sgYHO92PIY8cg== X-Google-Smtp-Source: ABdhPJwq4C3680EcbFmihmGT3eunNjYgfno+seYzIrV+8t6qRHfHqnatt7xaU07X2P6nY3LC+VIgOg== X-Received: by 2002:a05:600c:47d7:: with SMTP id l23mr5285043wmo.49.1623332144392; Thu, 10 Jun 2021 06:35:44 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 05/11] qemu-option: remove now-dead code Date: Thu, 10 Jun 2021 15:35:32 +0200 Message-Id: <20210610133538.608390-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210610133538.608390-1-pbonzini@redhat.com> References: <20210610133538.608390-1-pbonzini@redhat.com> MIME-Version: 1.0 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x330.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: berrange@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+importer2=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.31.1 From nobody Thu Apr 25 09:28:58 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623332589300480.76325553761444; Thu, 10 Jun 2021 06:43:09 -0700 (PDT) Received: from localhost ([::1]:40332 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrKxg-0000o3-7L for importer2@patchew.org; Thu, 10 Jun 2021 09:43:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47516) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrKqf-0001gK-7z for qemu-devel@nongnu.org; Thu, 10 Jun 2021 09:35:53 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]:34478) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrKqY-0005fp-MW for qemu-devel@nongnu.org; Thu, 10 Jun 2021 09:35:52 -0400 Received: by mail-wr1-x42b.google.com with SMTP id q5so2372433wrm.1 for ; Thu, 10 Jun 2021 06:35:46 -0700 (PDT) Received: from avogadro.redhat.com ([2001:b07:6468:f312:63a7:c72e:ea0e:6045]) by smtp.gmail.com with ESMTPSA id v8sm4032519wrc.29.2021.06.10.06.35.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 06:35:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TFaVv/jz4lgF0mz802si5sGlUrBseoogQ4/SE+k7/4A=; b=uWd4xdQyCWr6eTrC4qnK2dR+CCCkNTdmoTaptY/2TL3nMNfMS5clQpIU2LPdblFACw ynpGdPkVwHsgD7ESHpQVD6qMXk7GXxA/qd9h6LhEG/bRIWZ3zle6aS2EZBv90n1s6z5o ls6fimIZV0W8OmWHlIhqWsC07Inlk45Bw1TZFmItpeKFRIynBxGpkfxetuwb8d2wpRxw WcFH72xvKx5cVa8h4SmCNpdameGD5IiXdZqrvAIkJO7xvKfCTLqeEHlPHjDqXw9o2Xrc qDJSg0W8gaHmXZThp2K/dzVRZGTXnZEu2TwTnhXdJr64szxGgCWlt5wgWj5rAn5cNpwE lJeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=TFaVv/jz4lgF0mz802si5sGlUrBseoogQ4/SE+k7/4A=; b=ToPvWTRvX2VuvSkv0uEJD5USY3eE6hWIYPs01B3J0xdy9ajgZ4sgFn13GRUeo6NoiU xzxN7fe25EGqSCZVdb5NVwpBwkEVTAUCSferk8w8s8z617B42/AD2zHKu8YQl8C8R/gT vkigy0ZUAAoUwp76Cz80tcn6Isf/KIZw8c1K8QNornWW0S6+Zvzp1s2UahelA/1hkg44 nvCl5tJdJLmCdRMeEgtXnJuqRKz2+kufbt5WHL/t081wMHuRD4Bnx41faMqFHRflcIrQ BLwobQzv1WyCzSwydQc+4EWo59FTJtxBow/mRzVJExUbenw0nfMYw/uKGYMpXJnJarWL 1GGw== X-Gm-Message-State: AOAM532sIE2f2h7IGGH8cTaMRGTT7JUIJRpwvmiN2hiS+HMd+iGTq1al cP/N3q/Dz0IGg843CpuQ1aCZt0stjuNNVA== X-Google-Smtp-Source: ABdhPJzD02IH73A/RArb90amZD3+BBa65pE4aw+5xxQZsDyaHUTCZj4qHAPsZitoqGqpgmw+u5jMgQ== X-Received: by 2002:a5d:474f:: with SMTP id o15mr5632868wrs.298.1623332145391; Thu, 10 Jun 2021 06:35:45 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 06/11] machine: move dies from X86MachineState to CpuTopology Date: Thu, 10 Jun 2021 15:35:33 +0200 Message-Id: <20210610133538.608390-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210610133538.608390-1-pbonzini@redhat.com> References: <20210610133538.608390-1-pbonzini@redhat.com> MIME-Version: 1.0 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x42b.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: berrange@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+importer2=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 Reviewed-by: Daniel P. Berrang=C3=A9 --- 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 55b9bc7817..d776c8cf20 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -970,6 +970,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 c6d8d0d84d..92958e9ad7 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -712,8 +712,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); @@ -769,7 +767,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.31.1 From nobody Thu Apr 25 09:28:58 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623332397753200.18669132899072; Thu, 10 Jun 2021 06:39:57 -0700 (PDT) Received: from localhost ([::1]:57032 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrKua-0001Tc-KN for importer2@patchew.org; Thu, 10 Jun 2021 09:39:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47526) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrKqf-0001h9-FG for qemu-devel@nongnu.org; Thu, 10 Jun 2021 09:35:53 -0400 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]:37791) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrKqd-0005gA-GE for qemu-devel@nongnu.org; Thu, 10 Jun 2021 09:35:53 -0400 Received: by mail-wr1-x42d.google.com with SMTP id i94so2369137wri.4 for ; Thu, 10 Jun 2021 06:35:47 -0700 (PDT) Received: from avogadro.redhat.com ([2001:b07:6468:f312:63a7:c72e:ea0e:6045]) by smtp.gmail.com with ESMTPSA id v8sm4032519wrc.29.2021.06.10.06.35.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 06:35:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=J/jOftwZDa2RFQJpkwXjrQU/YDdcj+tfPzp2fAN/u3Q=; b=cMyml66DWCP5ijkXtVQSY5I3uiA7O02QfuCzhhXPizd02ydz8MaLKyM6BbfVk5sJc6 jOUzgL/Zeazndp+atzVsLXBruAyxZjF7LkVLM8bD2HMurFwYOci+4JyWO1TMFlSr6ZZX KV3KPu45SdNxSubWFzZGprvlWoip+MjXu4tBKpaKHrEtYVXnP2oDobi7Xun8vPujbHfk tgjXe6089+U5Bby7RwzJYttN439NJ3/E9zDSDgc7gVqnj9NsicVKvxVmRD2Xjpgl1sHs QhB30TLE3VoUrHp8zXflAaY0Pcuum/eRHZNxYzfZMF6TsvKwW+siFAzypO2w4N6SSwwY JsCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=J/jOftwZDa2RFQJpkwXjrQU/YDdcj+tfPzp2fAN/u3Q=; b=mfMq9l7ReM6B1vBBIAmquQosM1yTMpu+YtbyJKHCkMD3aGN4Jem5gufbAC8jkZkFKn 2hF94di9fVB7lIBqxH3Kg41JNRVRVBLReA6C1eHU8fXnKriZ/Xi22et0CuJZElqJqLW+ Ne1GsNCSIqaCAmz3hVHCO71Ll5gyw4oJbp3NcekRPfEqggiGvVC3cjBNbeA85eqfoUSZ IzIPBQNHBqKB++XfZBIkPVYF4T1hMWrE2+Om4DdmE0TLDheIxccjrJMd3/Mx8VSEub6F 8V1a4eFz5+D39//0gm3lidZDOXNzkXlc8Igikd8X1XtNWfk3jrVjvuTUVoVfIecVUl6C cOgw== X-Gm-Message-State: AOAM532WKfrCQZzeCqgvIhSsGemoVFhZwpy35V50Gh5mGvijFVyWoM8b 2tLRA6CihDBRZ3ihlIhNN1zJPUzi3FI8CQ== X-Google-Smtp-Source: ABdhPJxpOg6vaugWcDHqrdikvVxR5uiCyNibEfDtu46AcjSJ20iQ+2j0kNRHzg0VYwHlsUE0ZJvIRA== X-Received: by 2002:adf:ea4c:: with SMTP id j12mr5544646wrn.64.1623332146259; Thu, 10 Jun 2021 06:35:46 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 07/11] machine: move common smp_parse code to caller Date: Thu, 10 Jun 2021 15:35:34 +0200 Message-Id: <20210610133538.608390-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210610133538.608390-1-pbonzini@redhat.com> References: <20210610133538.608390-1-pbonzini@redhat.com> MIME-Version: 1.0 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::42d; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x42d.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: berrange@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+importer2=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 d776c8cf20..1016ec9e1c 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -741,67 +741,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) @@ -1135,7 +1127,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) { @@ -1151,6 +1145,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 92958e9ad7..e206ac85f3 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -712,69 +712,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.31.1 From nobody Thu Apr 25 09:28:58 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623332563242815.0587383068378; Thu, 10 Jun 2021 06:42:43 -0700 (PDT) Received: from localhost ([::1]:38088 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrKxG-0007jV-4q for importer2@patchew.org; Thu, 10 Jun 2021 09:42:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47560) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrKqg-0001iX-7e for qemu-devel@nongnu.org; Thu, 10 Jun 2021 09:35:55 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]:54809) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrKqd-0005gG-Hm for qemu-devel@nongnu.org; Thu, 10 Jun 2021 09:35:53 -0400 Received: by mail-wm1-x329.google.com with SMTP id m3so966435wms.4 for ; Thu, 10 Jun 2021 06:35:48 -0700 (PDT) Received: from avogadro.redhat.com ([2001:b07:6468:f312:63a7:c72e:ea0e:6045]) by smtp.gmail.com with ESMTPSA id v8sm4032519wrc.29.2021.06.10.06.35.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 06:35:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oaLUCvek2OmNr6/JtAkUEqBmw58D1m2VU8lWk8Kuo/k=; b=WR9L9d0X9T5TedhasZu/4Rprgbelx3ipb7lYwfiawEZNqqDF927+zHJs1qT8a6nM9+ cAGI61t71gNdROiHD4ILL7lwnY/L9JdJilgPLtrVvZb+OcTFuhe1if/YGQUUeSXkoTXq nMaF/58HoPa7y5i0En6uxvvO2TY9rUr1Z0VvsWMZFzk1WCo2+c8Eyi+lX38e/cenZNEt lB8/iXKMnspcnoa0xIDyXrNYYwiWw+9vZcQ1f0m+9yjxP87mZArPZWaaW7YF29jqZIWm nXkEw77dHYQQbnfLIWJ4e1o3d7NuZMcAJq+NUVfOG+GN96sLWENJFPrBjgJsKeLT2cdB dvtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=oaLUCvek2OmNr6/JtAkUEqBmw58D1m2VU8lWk8Kuo/k=; b=cPFGP6IfFjA0KwqzwmKuOLeyindy+6+dtNfaf5qCTAfMRUuJ0QUBdPTU5+OEJ0Ienl U/PIZq7ynrsAoiOW6HEOuFRurWmmoTDCZNemnjTzpx5HMICyyyhIVHPSvEu5bAg/5/Hq mxeNBL5siIrxl1w2ILkn30x/l6MyYGadsBXe8Cy716dCqDsrHjzjtDd/fj0XcQnVN89o 2atbpFuEM19h7LgAkUrzzRBTmBHoJTTkbUIlSJQ6i0mllJy64t9wWv9vEFJ/jwZsj6PQ nOhO5+ZBlu57eIQ4yP0PFCb5tpc8FprXM2U6TrloHTlYj0DzMYIQHK4Q6Vu6/QE+63uT 8zfA== X-Gm-Message-State: AOAM533kle9WAo8TrjXit3LIFmtOAvbG5mKBRe1xIECjv/hm2scjoWhx Z6GfAfa//URdmXjP1Pp4jmD+1x9sRgIc0g== X-Google-Smtp-Source: ABdhPJxuvuubkGCCwk2PN51iEPNQaDbhr774mj3nKi97abZZCbxHhzIByd1Uzk+SO18YXquZgSiyrw== X-Received: by 2002:a05:600c:3790:: with SMTP id o16mr15164681wmr.41.1623332147335; Thu, 10 Jun 2021 06:35:47 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 08/11] machine: add error propagation to mc->smp_parse Date: Thu, 10 Jun 2021 15:35:35 +0200 Message-Id: <20210610133538.608390-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210610133538.608390-1-pbonzini@redhat.com> References: <20210610133538.608390-1-pbonzini@redhat.com> MIME-Version: 1.0 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x329.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: berrange@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+importer2=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 Reviewed-by: Daniel P. Berrang=C3=A9 --- 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 1016ec9e1c..5a9c97ccc5 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -739,7 +739,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); @@ -766,28 +766,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; @@ -1126,9 +1126,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 e206ac85f3..cce275dcb1 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -710,7 +710,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); @@ -738,28 +738,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.31.1 From nobody Thu Apr 25 09:28:58 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623332698380850.0957420196858; Thu, 10 Jun 2021 06:44:58 -0700 (PDT) Received: from localhost ([::1]:45856 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrKzP-0004Se-5w for importer2@patchew.org; Thu, 10 Jun 2021 09:44:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47564) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrKqg-0001iZ-Ic for qemu-devel@nongnu.org; Thu, 10 Jun 2021 09:35:55 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]:42624) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrKqd-0005gL-HY for qemu-devel@nongnu.org; Thu, 10 Jun 2021 09:35:54 -0400 Received: by mail-wm1-x331.google.com with SMTP id l7-20020a05600c1d07b02901b0e2ebd6deso6450749wms.1 for ; Thu, 10 Jun 2021 06:35:48 -0700 (PDT) Received: from avogadro.redhat.com ([2001:b07:6468:f312:63a7:c72e:ea0e:6045]) by smtp.gmail.com with ESMTPSA id v8sm4032519wrc.29.2021.06.10.06.35.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 06:35:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AEctVWm7LnklR94IVota7cJxBYDiTHrGLM7X/qOIhdI=; b=J5pUoxIFecL/iMexfmXUMEl1++qTRXlAoODXvaSmj32MmoT7Q7wAViC4BUwoiKj4pm JCKzHkRcDXBlZS/c38bNtrzrcUjKs64LYGqxTR64DEa3SAyz+NDhC12Fo7MFF3UUZthf AacdkRHVfzCNx4jNalwHepL/8zmaJcqsTCzYvpyTbsMoBNHay+va5Nm4WnhpOLsNsHU1 zIS2NfiFnByLorL4GT4B+e9oeGLRNSB+ZAhOJ1fjYFhcyC+X2Zbn3VocRkcy0WI5TkKP 8uy+ouh0HEsu+drGnUniuyhKWrbNUk/4URr0Q4qSeHJbESDkERE8Q9ppLcLPbvUKoS4h uT7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=AEctVWm7LnklR94IVota7cJxBYDiTHrGLM7X/qOIhdI=; b=Wo4og35HCbRsWZcf8BI3q5ApLEe6UJjkwhPdPAJMAdo/uQb7pOGB/S8sC+sKacxMUe 1MThnhcYhgJyR82uIGCTNRgoKKp1ZVJITuj7kBgfh+2X2vfl78uCBkInsQxYv7z0dPng cIplOnGKJguE+hO5ZuMsiRX2/gRpwIhfYxj0LqARabmA0Gk+b6HABuHBjfgTIYgrMska +3JLx53Qu18Gk2uACadr7PhK3UIVszjs+8tCltgPco+/Lp2tXCBplL9A8+lole4exYAO HzSA+yjli/ksu9/IKJpE9t55xsi1/k4eSJTFpnZzWi6UKj0Oirf33jn30csb4aYolkAO XCfg== X-Gm-Message-State: AOAM530DT50bE+HL9tl1PZtU+k77qQIeV9t4HOAV/LLlh7aOk3w7+Fd9 iXM+RHNDP/t9fVUNr7twFYemjJ3XZUdWFg== X-Google-Smtp-Source: ABdhPJwaHW6yIip1QHA7yqEM1PKdYa0UXh/h9qiCxM3vjrYgfHiZgnQDJBKy49sp4Yh7z/mAQoO/xQ== X-Received: by 2002:a7b:cd9a:: with SMTP id y26mr14866708wmj.81.1623332147999; Thu, 10 Jun 2021 06:35:47 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 09/11] machine: pass QAPI struct to mc->smp_parse Date: Thu, 10 Jun 2021 15:35:36 +0200 Message-Id: <20210610133538.608390-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210610133538.608390-1-pbonzini@redhat.com> References: <20210610133538.608390-1-pbonzini@redhat.com> MIME-Version: 1.0 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x331.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: berrange@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+importer2=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 5a9c97ccc5..9ad8341a31 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -739,12 +739,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) { @@ -754,8 +754,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) { @@ -773,8 +772,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"); @@ -1129,7 +1127,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 cce275dcb1..8e1220db72 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -710,13 +710,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) { @@ -726,8 +726,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) { @@ -745,8 +744,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 58a9c86b36..53fd7e60ff 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.31.1 From nobody Thu Apr 25 09:28:58 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623332555139423.5370956514073; Thu, 10 Jun 2021 06:42:35 -0700 (PDT) Received: from localhost ([::1]:37416 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrKx8-0007I2-4A for importer2@patchew.org; Thu, 10 Jun 2021 09:42:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47566) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrKqg-0001ia-If for qemu-devel@nongnu.org; Thu, 10 Jun 2021 09:35:55 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]:52110) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrKqd-0005gU-Hf for qemu-devel@nongnu.org; Thu, 10 Jun 2021 09:35:54 -0400 Received: by mail-wm1-x330.google.com with SMTP id l9so6204574wms.1 for ; Thu, 10 Jun 2021 06:35:49 -0700 (PDT) Received: from avogadro.redhat.com ([2001:b07:6468:f312:63a7:c72e:ea0e:6045]) by smtp.gmail.com with ESMTPSA id v8sm4032519wrc.29.2021.06.10.06.35.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 06:35:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qzpXFnyjgRnwQsHIuTfmXtl8Hzry0AV1o6f9R8rYdXg=; b=o3orkLcxGSnXxx+RvuoYTdJ9SMiJHSEnLeAGv8jQO552y1N7z4jCBM7t1pD1vOW/Gu w2ytTiRWIF66i+d4C95snZvmsA9pMyUtdw6MM5wQKTTycdmfI1hk4z34BQy6vINriW18 04gnDulvYA2I69fHsNUY5VYPbkZi6n1zuosWrx+cI5Ckh+5z2zamXJinhLoiOpsdiPvK 3jN3fFZcMxOlPIMkdJ/0zAcodyLW/XcwIf5D8bB1nfpAObDbU+h4uscFRlpGElyUaUZ1 QJun6V6rBFrqpV5i51cp7fBFZrklzM6rOt7VmZtEKs+OB2R0bVWgIJ46azAX6Mbj0ORc Pn+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=qzpXFnyjgRnwQsHIuTfmXtl8Hzry0AV1o6f9R8rYdXg=; b=G2LNv06rXyownK5mWgQ/KStAF1eHdfxTXIWV2jS8+wX6cau0UYtpag09ImwIdoOzHm EpOXlg2/x8qNEyWDfSGQ/GwsqNL0nlmk7zxG6PwTliN3dImvcZlbvcoKvsarpscy2sfd 2slNj8HKFyNRDdLwnKaatQ8qNrSXDDBv46dmPtZyJGZ3fZ/JDKc4tzdHYr2X3L6mRTKK Hhq/G2cdKK36B4ra8c5tkcAWqNE2kYziWaairG77oU7PEFA4t2wpySCZvmcNVSj76Zxq 7dBXwaxHo3cxZqjn7suETyc7+1UDlRQ0u4egzvIdQFIQCCbvt5M9OVTKONzuq+oPKIcd wWug== X-Gm-Message-State: AOAM533XM0puD3WUg9tGaVKEJgwAvireOUu1cvBZcnWdY4YLIcNTWD7J pXU320Ra2PRtKkG6jLcayjhqkxH5G+93Ug== X-Google-Smtp-Source: ABdhPJyzzuAltizO2p4e/LVClc+cETec7mj9whMSnZn4RVO0D+fxlH42RpFxTkd3BRA7xEM7Y76CVA== X-Received: by 2002:a1c:ed03:: with SMTP id l3mr5257102wmh.130.1623332148891; Thu, 10 Jun 2021 06:35:48 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 10/11] machine: reject -smp dies!=1 for non-PC machines Date: Thu, 10 Jun 2021 15:35:37 +0200 Message-Id: <20210610133538.608390-11-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210610133538.608390-1-pbonzini@redhat.com> References: <20210610133538.608390-1-pbonzini@redhat.com> MIME-Version: 1.0 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x330.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: berrange@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+importer2=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 Reviewed-by: Daniel P. Berrang=C3=A9 --- hw/core/machine.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/core/machine.c b/hw/core/machine.c index 9ad8341a31..ffc076ae84 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -746,6 +746,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.31.1 From nobody Thu Apr 25 09:28:58 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623332560750580.4079637633868; Thu, 10 Jun 2021 06:42:40 -0700 (PDT) Received: from localhost ([::1]:37764 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrKxD-0007W3-K2 for importer2@patchew.org; Thu, 10 Jun 2021 09:42:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47568) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrKqg-0001ib-JM for qemu-devel@nongnu.org; Thu, 10 Jun 2021 09:35:55 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]:43778) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrKqd-0005ga-GZ for qemu-devel@nongnu.org; Thu, 10 Jun 2021 09:35:54 -0400 Received: by mail-wm1-x32e.google.com with SMTP id 3-20020a05600c0243b029019f2f9b2b8aso6456278wmj.2 for ; Thu, 10 Jun 2021 06:35:50 -0700 (PDT) Received: from avogadro.redhat.com ([2001:b07:6468:f312:63a7:c72e:ea0e:6045]) by smtp.gmail.com with ESMTPSA id v8sm4032519wrc.29.2021.06.10.06.35.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 06:35:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nAWdHFUChH2XYzrAnfko90CBZ7OObjzkhm0Xz87vLdw=; b=RCJZ7QS87peivipO9gQodSIowsg5bOd91HJV/vS9WrDjdWe6t/Fc87UuOyu29RhyNy FnOByTWgJQoqsPvLVtOTsX4V4q6t84ciq9bGZNfRm2zkQbAv729uTBJN2PzJpmVKT/Dm XbNnh2QiCX0EBNRHRByAx6Sp2rRZ34a56mp/mws3UXTmGX9ckfRClcR04x265XD/zdsU g1yGzx/uG8efjyzTzQxZTpnnnqS3xh+R/lPvNsKWt8I6Znz9+e3Mu93tOjYPQomtbEAY ngldfOX1fY2gv8whsL2B0Kvfr8R7G6e1waleXSS2/fk+TJgurdb0+MJc9XiFq87IH1vY siSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=nAWdHFUChH2XYzrAnfko90CBZ7OObjzkhm0Xz87vLdw=; b=a6OKWVnrc8QfQLIMwavBUq2OyniU8zhrx5xb6/UC/Ia3Fqvv/ljC5lZqgjY7C4HZZ6 mE9zS+anor4+RYnsVjQIu4igE4fGqUcX3f/LAiTYUJfbellLiDhtd/jFa3+doSzoWAE4 NvFHpdq/UnOs/q/C43QCq5sIBm0hce0/jQ7Pt9LOZzS0583J7AyqlfFLwpWVPGAPTOtG hZO99gzGAeb6GfPpkgonordiOV0p79BwSXzzi4raf1i9DUnEgC+UwUL9CHAz0ok4lnSF atOMGp7fNFtpJdcyhqdnHSRK59++U5OntL99d1lnF5RaF+XehRIGP4St/EoS4jJJ9lSc +m7Q== X-Gm-Message-State: AOAM53222ohzpbnd+Aav4cYYZF/TARtn6u+4t1i96l19oe2HKtlLOgAv JGAEMdQevic/48AIXyVSwnBzz1qED7FblQ== X-Google-Smtp-Source: ABdhPJzE6dMnGDK+OmlUBr7GQSxoadybqE2WMPVMeiiD+GYV+DYaUmgV7jqamhNLhuMjM6Xl1gz9AQ== X-Received: by 2002:a1c:e907:: with SMTP id q7mr15389989wmc.1.1623332149721; Thu, 10 Jun 2021 06:35:49 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 11/11] machine: add smp compound property Date: Thu, 10 Jun 2021 15:35:38 +0200 Message-Id: <20210610133538.608390-12-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210610133538.608390-1-pbonzini@redhat.com> References: <20210610133538.608390-1-pbonzini@redhat.com> MIME-Version: 1.0 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x32e.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: berrange@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+importer2=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 +++++++++++++++++++++------------------- include/hw/boards.h | 1 - softmmu/vl.c | 33 +++++++++--- tests/qtest/numa-test.c | 22 ++++---- 4 files changed, 95 insertions(+), 69 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index ffc076ae84..c6ae89efec 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" @@ -798,6 +799,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); @@ -837,6 +889,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); @@ -1125,56 +1183,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/include/hw/boards.h b/include/hw/boards.h index 1eae4427e8..accd6eff35 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -26,7 +26,6 @@ OBJECT_DECLARE_TYPE(MachineState, MachineClass, MACHINE) extern MachineState *current_machine; =20 void machine_run_board_init(MachineState *machine); -bool machine_smp_parse(MachineState *ms, QemuOpts *opts, Error **errp); bool machine_usb(MachineState *machine); int machine_phandle_start(MachineState *machine); bool machine_dump_guest_core(MachineState *machine); diff --git a/softmmu/vl.c b/softmmu/vl.c index 01bcb16560..683f2bb488 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -1523,6 +1523,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 @@ -1833,6 +1852,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) @@ -2074,9 +2099,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. @@ -3291,10 +3313,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.31.1