From nobody Mon May 6 02:30:23 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623945387649403.87710504558083; Thu, 17 Jun 2021 08:56:27 -0700 (PDT) Received: from localhost ([::1]:36008 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltuNW-00033H-L5 for importer@patchew.org; Thu, 17 Jun 2021 11:56:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43930) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltuKP-0006Ww-W3 for qemu-devel@nongnu.org; Thu, 17 Jun 2021 11:53:14 -0400 Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636]:41596) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltuKO-0001Qp-28 for qemu-devel@nongnu.org; Thu, 17 Jun 2021 11:53:13 -0400 Received: by mail-ej1-x636.google.com with SMTP id ho18so10650448ejc.8 for ; Thu, 17 Jun 2021 08:53:11 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id p13sm4604061edh.79.2021.06.17.08.53.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 08:53:10 -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=/w3OWkmILd9DHLt7xHUVjE/0QCuFPWmxaED4RkhRstM=; b=tFhMvECHBbgWN5fZGG9/3v3wG3Gi6GBnRvNVWLfmnzFamb67+GbnSOtq9dZLNLKYBd 7+V8D8p6BijEApQMLguulML8eC1gzxcVauj3PTSDYBkMq1uzQyysMqExqQXdcpA4frkT LH98yR/GUha2EDRzGMP0ocqy68uMcdphP0Reg8JzzHnpleIbvRDuLJRSWYtNPLoJVvz0 xEfCjnZ38s2Ousiw+uXTdUwlO3w+Ui5eWTYBtDp8eR1WCGGYlw28IzX4UhNhqu1leCuK uWOE+0oS043FURkn9vPDuiE8hpq4Lhv0XCgyC31kjn8w+met8HsypBKqF7yeBIERdAtV 1HbQ== 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=/w3OWkmILd9DHLt7xHUVjE/0QCuFPWmxaED4RkhRstM=; b=A8FYTLAW7czIAjLmVfTJPs0YidWANHSmBOQnG9xWxN+eAt8rzoUZJx5g/GA8demrl+ f8VpMvzfwiAhQN2ncol4IZG/N4aKTzJatROwgdikyazNcmZheTEOFTpfK99s6TIm7nY8 oFBm6eZx7P5ZfrxKYf0t3rLy6Qu4+6P8uHHgj5iqGtWRplQvOmCoOCXzKo6QwO4m5Kp3 RCPoikT9Zf6k4ggbKrLKTZCZyfFckPrJ/5hEVPFoZlWiPnJfypgBBgyyib1mEuO46Crj tpiP+lUksewARV5U68dBClGyCkF9vQhdbwlq8cTU+BuiKvgWtSbTr5k9DybCnPeJu+Go kfVA== X-Gm-Message-State: AOAM533QneevR73dGJCekSYynvjIkjJbtuBzbY7CYzVkbDaAjbX6YZsR B9gRhhu7eYXaA5QTyXiQgvf3iVbqJnY= X-Google-Smtp-Source: ABdhPJxAOzcZZdD+OAOYfEuUBKZISNQvTgBSvHDdqPLu7UFzEDi+Mz5lO1V4MHWNpLxNbxNEP3sKZA== X-Received: by 2002:a17:906:744:: with SMTP id z4mr6040482ejb.347.1623945190533; Thu, 17 Jun 2021 08:53:10 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 01/11] qom: export more functions for use with non-UserCreatable objects Date: Thu, 17 Jun 2021 17:52:58 +0200 Message-Id: <20210617155308.928754-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617155308.928754-1-pbonzini@redhat.com> References: <20210617155308.928754-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::636; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x636.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: =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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. Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Paolo Bonzini --- include/qom/object.h | 23 ++++++++++++++++ qom/object_interfaces.c | 58 +++++++++++++++++++++++++++++------------ 2 files changed, 65 insertions(+), 16 deletions(-) diff --git a/include/qom/object.h b/include/qom/object.h index 6721cd312e..faae0d841f 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -861,6 +861,29 @@ static void do_qemu_init_ ## type_array(void) = \ } = \ type_init(do_qemu_init_ ## type_array) =20 +/** + * type_print_class_properties: + * @type: a QOM class name + * + * Print the object's class properties to stdout or the monitor. + * Return whether an object was found. + */ +bool type_print_class_properties(const char *type); + +/** + * object_set_properties_from_keyval: + * @obj: a QOM object + * @qdict: a dictionary with the properties to be set + * @from_json: true if leaf values of @qdict are typed, false if they + * are strings + * @errp: pointer to error object + * + * For each key in the dictionary, parse the value string if needed, + * then set the corresponding property in @obj. + */ +void object_set_properties_from_keyval(Object *obj, const QDict *qdict, + bool from_json, Error **errp); + /** * object_class_dynamic_cast_assert: * @klass: The #ObjectClass to attempt to cast. diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c index 4479ee693a..ad9b56b59a 100644 --- a/qom/object_interfaces.c +++ b/qom/object_interfaces.c @@ -42,6 +42,44 @@ bool user_creatable_can_be_deleted(UserCreatable *uc) } } =20 +static void object_set_properties_from_qdict(Object *obj, const QDict *qdi= ct, + Visitor *v, Error **errp) +{ + const QDictEntry *e; + Error *local_err =3D NULL; + + if (!visit_start_struct(v, NULL, NULL, 0, &local_err)) { + goto out; + } + for (e =3D qdict_first(qdict); e; e =3D qdict_next(qdict, e)) { + if (!object_property_set(obj, e->key, v, &local_err)) { + break; + } + } + if (!local_err) { + visit_check_struct(v, &local_err); + } + visit_end_struct(v, NULL); + +out: + if (local_err) { + error_propagate(errp, local_err); + } +} + +void object_set_properties_from_keyval(Object *obj, const QDict *qdict, + bool from_json, Error **errp) +{ + Visitor *v; + if (from_json) { + v =3D qobject_input_visitor_new(QOBJECT(qdict)); + } else { + v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); + } + object_set_properties_from_qdict(obj, qdict, v, errp); + visit_free(v); +} + Object *user_creatable_add_type(const char *type, const char *id, const QDict *qdict, Visitor *v, Error **errp) @@ -49,7 +87,6 @@ Object *user_creatable_add_type(const char *type, const c= har *id, ERRP_GUARD(); Object *obj; ObjectClass *klass; - const QDictEntry *e; Error *local_err =3D NULL; =20 if (id !=3D NULL && !id_wellformed(id)) { @@ -78,18 +115,7 @@ Object *user_creatable_add_type(const char *type, const= char *id, =20 assert(qdict); obj =3D object_new(type); - if (!visit_start_struct(v, NULL, NULL, 0, &local_err)) { - goto out; - } - for (e =3D qdict_first(qdict); e; e =3D qdict_next(qdict, e)) { - if (!object_property_set(obj, e->key, v, &local_err)) { - break; - } - } - if (!local_err) { - visit_check_struct(v, &local_err); - } - visit_end_struct(v, NULL); + object_set_properties_from_qdict(obj, qdict, v, &local_err); if (local_err) { goto out; } @@ -178,7 +204,7 @@ static void user_creatable_print_types(void) g_slist_free(list); } =20 -static bool user_creatable_print_type_properites(const char *type) +bool type_print_class_properties(const char *type) { ObjectClass *klass; ObjectPropertyIterator iter; @@ -224,7 +250,7 @@ bool user_creatable_print_help(const char *type, QemuOp= ts *opts) } =20 if (qemu_opt_has_help_opt(opts)) { - return user_creatable_print_type_properites(type); + return type_print_class_properties(type); } =20 return false; @@ -234,7 +260,7 @@ static void user_creatable_print_help_from_qdict(QDict = *args) { const char *type =3D qdict_get_try_str(args, "qom-type"); =20 - if (!type || !user_creatable_print_type_properites(type)) { + if (!type || !type_print_class_properties(type)) { user_creatable_print_types(); } } --=20 2.31.1 From nobody Mon May 6 02:30:23 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623945519310591.5567335010295; Thu, 17 Jun 2021 08:58:39 -0700 (PDT) Received: from localhost ([::1]:43354 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltuPe-00081b-9f for importer@patchew.org; Thu, 17 Jun 2021 11:58:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43946) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltuKQ-0006Zv-RO for qemu-devel@nongnu.org; Thu, 17 Jun 2021 11:53:14 -0400 Received: from mail-ed1-x52d.google.com ([2a00:1450:4864:20::52d]:43558) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltuKO-0001RV-U8 for qemu-devel@nongnu.org; Thu, 17 Jun 2021 11:53:14 -0400 Received: by mail-ed1-x52d.google.com with SMTP id s6so4665688edu.10 for ; Thu, 17 Jun 2021 08:53:12 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id p13sm4604061edh.79.2021.06.17.08.53.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 08:53:10 -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=QV2IkEhhrKo5mk74ZPyHtqyoKqzRDGwZB/XiBTg7CPQ=; b=lO2N7GkNLpd9DMXe6JQ6c7OzuaI2tImTDWK33PVk7rqRQoWL/i8LPsxZzYkwTra2y1 mrHJ8bvaqK5ooLqCYymEBw3OS4kt89J5aGzGvvfJau1ZdjKNMLrlE6MjxMV/XRFgGfrK CoSFobXB3FfvuC7romwHOtu570tVv8M3uCUZsQmkJ+J++klXLNzdGO+1pJH5L7xSFjKs NO78WOVxGFzec53vxBiN1AXiFFO2Ym24V5rWeg1daXYfxrArrMndoZ2JhGnmrpu5NMvZ u5KX5VPJ1Ag3SBTOdMbJnU5+8WaUdX+m1Mm1qvq7QeAjdfUAxsnamdyf7wMO7V7iXYM/ gb2Q== 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=QV2IkEhhrKo5mk74ZPyHtqyoKqzRDGwZB/XiBTg7CPQ=; b=BFm9fLCG8V0+h5XWbYfrWzF453PBVHSyJZX/Go1TVbCETmv6gWZz0PBpgTSyk/L6kU X0o4t7KJpbOLV126KbnZ3M3BIQfveCGl07302Cwm08V0OpUcIwPU9bI9Ljddw8h2r0TL zuTlRoHVbD0b2yLvdEqPWf0K4xS8lB49No+kwP20hHS6Qgd3D3psLSDTcjDBiwYOki4+ 0nyhFxsJmsqbhK4i5sRDWH27jmZ1NCcGlFTreGOQQ3qFJACMxIUwRwko2+8bGhB1/G7m RNrguAqEe/Q08pUIsYwor9Zp93TPFVAFPN14GepoD/6SLJbax0KYVqvIz/qkDebta2ZA sQtw== X-Gm-Message-State: AOAM531j8CdJT1QseFOhYDH00QX22RR4stR0/D6Z4BDo+cJyUeDtX+51 Sn+F8dWRWpeBprqH1rq+pWdu054pzkI= X-Google-Smtp-Source: ABdhPJxLB5UlhMIOg98sHI+qKfPVo/uMPbJeYNJPSBOtnb4I5uyk4aewDiGSBs4IKDc64eI8JgO4FA== X-Received: by 2002:a05:6402:31a9:: with SMTP id dj9mr5113142edb.164.1623945191452; Thu, 17 Jun 2021 08:53:11 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 02/11] keyval: introduce keyval_merge Date: Thu, 17 Jun 2021 17:52:59 +0200 Message-Id: <20210617155308.928754-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617155308.928754-1-pbonzini@redhat.com> References: <20210617155308.928754-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::52d; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x52d.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: armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Markus Armbruster --- include/qemu/option.h | 1 + tests/unit/test-keyval.c | 58 ++++++++++++++++++++++++++++++++ util/keyval.c | 71 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 130 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..af0581ae6c 100644 --- a/tests/unit/test-keyval.c +++ b/tests/unit/test-keyval.c @@ -747,6 +747,61 @@ static void test_keyval_visit_any(void) visit_free(v); } =20 +static void test_keyval_merge_dict(void) +{ + QDict *first =3D keyval_parse("opt1=3Dabc,opt2.sub1=3Ddef,opt2.sub2=3D= ghi,opt3=3Dxyz", + NULL, NULL, &error_abort); + QDict *second =3D keyval_parse("opt1=3DABC,opt2.sub2=3DGHI,opt2.sub3= =3DJKL", + 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(first, second, &err); + g_assert(!err); + g_assert(qobject_is_equal(QOBJECT(combined), QOBJECT(first))); + qobject_unref(first); + qobject_unref(second); + qobject_unref(combined); +} + +static void test_keyval_merge_list(void) +{ + QDict *first =3D keyval_parse("opt1.0=3Dabc,opt2.0=3Dxyz", + NULL, NULL, &error_abort); + QDict *second =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(first, second, &err); + g_assert(!err); + g_assert(qobject_is_equal(QOBJECT(combined), QOBJECT(first))); + qobject_unref(first); + qobject_unref(second); + qobject_unref(combined); +} + +static void test_keyval_merge_conflict(void) +{ + QDict *first =3D keyval_parse("opt2=3DABC", + NULL, NULL, &error_abort); + QDict *second =3D keyval_parse("opt2.sub1=3Ddef,opt2.sub2=3Dghi", + NULL, NULL, &error_abort); + QDict *third =3D qdict_clone_shallow(first); + Error *err =3D NULL; + + keyval_merge(first, second, &err); + error_free_or_abort(&err); + keyval_merge(second, third, &err); + error_free_or_abort(&err); + + qobject_unref(first); + qobject_unref(second); + qobject_unref(third); +} + int main(int argc, char *argv[]) { g_test_init(&argc, &argv, NULL); @@ -760,6 +815,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/dict", test_keyval_merge_dict); + 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..8006c5df20 100644 --- a/util/keyval.c +++ b/util/keyval.c @@ -310,6 +310,77 @@ static char *reassemble_key(GSList *key) return g_string_free(s, FALSE); } =20 +/* + * Recursive worker for keyval_merge. @str is the path that led to the + * current dictionary, to be used for error messages. It is modified + * internally but restored before the function returns. + */ +static void keyval_do_merge(QDict *dest, const QDict *merged, GString *str= , Error **errp) +{ + size_t save_len =3D str->len; + const QDictEntry *ent; + QObject *old_value; + + for (ent =3D qdict_first(merged); ent; ent =3D qdict_next(merged, ent)= ) { + old_value =3D qdict_get(dest, 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; + } else { + assert(qobject_type(ent->value) =3D=3D QTYPE_QSTRING); + } + } + + qobject_ref(ent->value); + qdict_put_obj(dest, ent->key, ent->value); + } +} + +/* Merge the @merged dictionary into @dest. The dictionaries are expected= to be + * returned by the keyval parser, and therefore the only expected scalar t= ype + * is the * string. In case the same path is present in both @dest and @m= erged, + * the semantics are as follows: + * + * - lists are concatenated + * + * - dictionaries are merged recursively + * + * - for scalar values, @merged wins + * + * In case an error is reported, @dest may already have been modified. + * + * This function can be used to implement semantics analogous to QemuOpts's + * .merge_lists =3D true case, or to implement -set for options backed by = QDicts. + */ +void keyval_merge(QDict *dest, const QDict *merged, Error **errp) +{ + GString *str; + + str =3D g_string_new(""); + keyval_do_merge(dest, merged, 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 Mon May 6 02:30:23 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162394628991362.64378881928815; Thu, 17 Jun 2021 09:11:29 -0700 (PDT) Received: from localhost ([::1]:47536 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltuc4-0004Qk-Op for importer@patchew.org; Thu, 17 Jun 2021 12:11:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43960) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltuKR-0006e4-RM for qemu-devel@nongnu.org; Thu, 17 Jun 2021 11:53:15 -0400 Received: from mail-ej1-x632.google.com ([2a00:1450:4864:20::632]:44901) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltuKP-0001Rm-UT for qemu-devel@nongnu.org; Thu, 17 Jun 2021 11:53:15 -0400 Received: by mail-ej1-x632.google.com with SMTP id gt18so10622982ejc.11 for ; Thu, 17 Jun 2021 08:53:13 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id p13sm4604061edh.79.2021.06.17.08.53.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 08:53:11 -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=1AXreqKY+hL7+OHi5Zt8L7qOfGiJrOmEH2Pb5pryjdM=; b=AxZh5WIWrgJdUx9qA7pmxHKVuuRDglfEKbzrDq17a1fhCHH/pAfFK35bnuSBojwoO3 GjbgFkk5t4RM/U11jSoKr2dWZheH+7+yHM/okJ/VI+ck1/6NVUPlXu8yEn3W8zdnR/1k fyq5MWtyM5SJbwismyee8KgSfcVPGKJBpsk9/cUh56f9SY30MyAVyksoLNuZTX4XY+ew weehLph/LX59/SiNTYpxdXIEmTjyN7xZwLF6toEByMND9lilI/AEX4/dTJWgnqGKrrIH csn+YXLdbrROkEcsIuJAk7tqBDTDNrN5M6gtFg0zS4/xa+++zsLrM4/Zm9C+SexYbal6 2nAg== 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=1AXreqKY+hL7+OHi5Zt8L7qOfGiJrOmEH2Pb5pryjdM=; b=GJFk4ymk9SXCn2QM3VlN0dUYJREj6NzN0JvpjQytkkJFiMBEoeKw3DwgYUgmB3n1J0 C5UjR8V5B0FI5yCIUPMW5ouUyYVNlQem6CE1oJQ5HybB8bpEZG4zQylQnLaHx80vADSt 4H+NVP6gz7/1dwZUf4dez5ov9+N/st80wwdNUCMQ+fiWAaJqrj0bvBrsxkSLPj+yr+pg 2huIGEaYWKt4xaXF5nsMeoPdyUE2mDu3hK7CmpM4JrdjHTUVL69mm6QB+sI1g39bH9qb yeLfq9jzIluNrfIN5suOKPRoxLeRPItnJGj0DUQa0iXDe31hQqYqyPC0JtSxELCKxKEZ 3vtQ== X-Gm-Message-State: AOAM530axOpPedyGJZ6SMPh3khDQPeA6ri2VGqx4OzsfTdFoLWcEWr+4 UyFMBWI2RgcZs3/w9f/e7vjsPcf4rjQ= X-Google-Smtp-Source: ABdhPJywgOfAX6kbLQR3unPyzEf59y9S9K9y2QUQavDL2SMiLRrtzym+A0Tjmt/qNPqCDQRcs1wsZA== X-Received: by 2002:a17:907:a8b:: with SMTP id by11mr6068303ejc.357.1623945192502; Thu, 17 Jun 2021 08:53:12 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 03/11] keyval: introduce keyval_parse_into Date: Thu, 17 Jun 2021 17:53:00 +0200 Message-Id: <20210617155308.928754-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617155308.928754-1-pbonzini@redhat.com> References: <20210617155308.928754-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::632; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x632.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: =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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. Reviewed-by: Markus Armbruster Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Paolo Bonzini --- include/qemu/option.h | 2 ++ util/keyval.c | 43 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/include/qemu/option.h b/include/qemu/option.h index d89c66145a..fffb03d848 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -147,6 +147,8 @@ void qemu_opts_print_help(QemuOptsList *list, bool prin= t_caption); void qemu_opts_free(QemuOptsList *list); QemuOptsList *qemu_opts_append(QemuOptsList *dst, QemuOptsList *list); =20 +QDict *keyval_parse_into(QDict *qdict, const char *params, const char *imp= lied_key, + bool *p_help, Error **errp); QDict *keyval_parse(const char *params, const char *implied_key, bool *help, Error **errp); void keyval_merge(QDict *old, const QDict *new, Error **errp); diff --git a/util/keyval.c b/util/keyval.c index 8006c5df20..a6cf1d9606 100644 --- a/util/keyval.c +++ b/util/keyval.c @@ -502,13 +502,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; @@ -517,7 +518,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; @@ -527,15 +527,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 Mon May 6 02:30:23 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623946559414599.3701048998412; Thu, 17 Jun 2021 09:15:59 -0700 (PDT) Received: from localhost ([::1]:53354 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltugQ-0000KF-MB for importer@patchew.org; Thu, 17 Jun 2021 12:15:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43992) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltuKT-0006k1-Rn for qemu-devel@nongnu.org; Thu, 17 Jun 2021 11:53:17 -0400 Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636]:44905) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltuKQ-0001SV-LF for qemu-devel@nongnu.org; Thu, 17 Jun 2021 11:53:17 -0400 Received: by mail-ej1-x636.google.com with SMTP id gt18so10623050ejc.11 for ; Thu, 17 Jun 2021 08:53:14 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id p13sm4604061edh.79.2021.06.17.08.53.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 08:53:12 -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=UV5u3jceKBjdF9e8b3ljOpTAsUpfLkDxQeFoakpnr7s=; b=dxV8rRDFElqp/QpK9sZUWfoHkcu0/TLoVnUirugvbN96n4FJolgisd0hxWM7m4oL17 5PhvoXQgEQFiT/BkbLNiUYXKMILgMeVJGrFHYmjUQmMw9Ro3AA4/F0C8Dk7xw49HS+11 LtBxorMFOF/3xwmgQ+1pkuTJM2ZHzAILEghHesUvLXmxO4HbUjJb3CFTKjTvosQrCdr8 sjbHY9kzhFskEobKQUNF3lA80GAUBog2Sg6ncN3Ts64uMmB/t0B36klNkYzYDGskfLz6 pqNaXwsrLplJoSXZy3eRPitAFFjbsWPz/yqrJ0v6us5iwc17YbPd2mFdmllgPbeXAw2M QINw== 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=UV5u3jceKBjdF9e8b3ljOpTAsUpfLkDxQeFoakpnr7s=; b=TQZ3Ha3LDinBtayQrilsY7mzzyLQSUMr5P8yYFoC1Z6X4UsjkScixhq+vrpAG2jW/E b2n4Rggu7X4KohbDyTxRL3ikXYpsb/oFA9eYKAaJxRqcTgyND0ddE/tl6913ioj9Idwa LriwIVa8fK5cDaE9jdJQrl6VY879UmBY+UA9jy2Mdfnc9o5AsWY/OjpgOhi0Z9hGiXr3 9tsDGvS+pjfZDL1EyiDE1hkMUozlNCu9SZJf2UZ1ZtaIaPVTLtc2R4HIvxeitBqRwod0 Om8ASnSmQ1WexEy43+15iOZNQixq7v6WIpX50cZAnwY+OkfLpqiY6OMH6yfZHLqvYGXb leQw== X-Gm-Message-State: AOAM533PNQs2XlNtyYK/p441cQgLH+QKVuinY009UtXaD5/jJWWYAI5I IQ5UxEg79vYDkaETOLSXTISwlBkbVfc= X-Google-Smtp-Source: ABdhPJy4vVM5r6R/XPXghSOiFy76taccvgQjECpKij3H/jkaKWjf3Hd2LOyuu9GhP8YmVLFlG8xcAQ== X-Received: by 2002:a17:906:4e93:: with SMTP id v19mr6025008eju.335.1623945193320; Thu, 17 Jun 2021 08:53:13 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 04/11] vl: switch -M parsing to keyval Date: Thu, 17 Jun 2021 17:53:01 +0200 Message-Id: <20210617155308.928754-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617155308.928754-1-pbonzini@redhat.com> References: <20210617155308.928754-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::636; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x636.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: armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Switch from QemuOpts to keyval. This enables the introduction of non-scalar machine properties, and JSON syntax in the future. For JSON syntax to be supported right now, we would have to consider what would happen if string-based dictionaries (produced by -M key=3Dval) were to be merged with strongly-typed dictionaries (produced by -M {'key': 123}). The simplest way out is to never enter the situation, and only allow one -M option when JSON syntax is in use. However, we want options such as -smp to become syntactic sugar for -M, and this is a problem; as soon as -smp becomes a shortcut for -M, QEMU would forbid using -M '{....}' together with -smp. Therefore, allowing JSON syntax right now for -M would be a forward-compatibility nightmare and it would be impossible anyway to introduce -M incrementally in tools. Instead, support for JSON syntax is delayed until after the main options are converted to QOM compound properties. These include -boot, -acpitable, -smbios, -m, -semihosting-config, -rtc and -fw_cfg. Once JSON syntax is introduced, these options will _also_ be forbidden together with -M '{...}'. Signed-off-by: Paolo Bonzini --- softmmu/vl.c | 315 ++++++++++++++++++++++++--------------------------- 1 file changed, 146 insertions(+), 169 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; + MachineClass *machine_class; + Error *local_err =3D NULL; =20 - loc_push_none(&loc); - - opts =3D qemu_get_machine_opts(); - qemu_opts_loc_restore(opts); - - optarg =3D qemu_opt_get(opts, "type"); if (optarg) { - machine_class =3D machine_parse(optarg, machines); + 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 - 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); - } - - 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; - } - if (g_str_equal(qom_name, "igd-passthru")) { - object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), qom_name, valu= e, - false); - return 0; - } - if (g_str_equal(qom_name, "kvm-shadow-mem")) { - object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), qom_name, valu= e, - false); - return 0; - } - if (g_str_equal(qom_name, "kernel-irqchip")) { - object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), qom_name, valu= e, - false); - object_register_sugar_prop(ACCEL_CLASS_NAME("whpx"), qom_name, val= ue, - false); - return 0; + value =3D qdict_get_try_str(qdict, "accel"); + if (value) { + accelerators =3D g_strdup(value); + qdict_del(qdict, "accel"); } =20 - return object_parse_property_opt(opaque, name, value, "type", errp); + value =3D qdict_get_try_str(qdict, "igd-passthru"); + if (value) { + object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), "igd-passthru"= , value, + false); + qdict_del(qdict, "igd-passthru"); + } + + 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); + qdict_del(qdict, "kvm-shadow-mem"); + } + + 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"), "kernel-irqch= ip", value, + false); + qdict_del(qdict, "kernel-irqchip"); + } } =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 Mon May 6 02:30:23 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623946434066816.2795411408199; Thu, 17 Jun 2021 09:13:54 -0700 (PDT) Received: from localhost ([::1]:51240 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltueO-00077v-NS for importer@patchew.org; Thu, 17 Jun 2021 12:13:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43994) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltuKT-0006k6-RE for qemu-devel@nongnu.org; Thu, 17 Jun 2021 11:53:17 -0400 Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]:40851) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltuKR-0001TF-IL for qemu-devel@nongnu.org; Thu, 17 Jun 2021 11:53:17 -0400 Received: by mail-ed1-x534.google.com with SMTP id t3so4687764edc.7 for ; Thu, 17 Jun 2021 08:53:15 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id p13sm4604061edh.79.2021.06.17.08.53.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 08:53:13 -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=cQPCOXJcQKbCGVpqBm4Bso5iyPRXz8tqeSU7oBqkO/cqXq4mygtf23jPO8g/oqOiWg bjr6PbcFzTUZJTEyUa30ZzbX62RZwcahzI8TL1suDJAGUDO86drW4QAL45aQ3djFhpiM NWMEysNtYapSKD5ZJhC0hdRwin96uFvzat6G9QHtaLYizb3P/krNvSLt1QsQ1HGC4Tk+ PvraqhaCS4h4YMSne9rxTNpG8L2ecZOeJTPmCpqGdAFYsuFLRyAkTwkJfIsfBbqc6AaI Z4+2pG5gN8ZLsADg+nL4dpX5qxBYIFhsGqGk6qELnxxW1HS4LD7FTeVZiAJL5dq1elxw mwLw== 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=MR7ru/q8HaWy4670/DT/zEskAnYUJFXpviu5jRZdpz/xU2eHy9ERNXMObd7SnAWBzi xKJsUVLxOIcpFfBvxhIl8c5YwLerp4WslBDGTRVa8e2R319/Zhx69YK98/g2jr5ZiM8o YhI0c6hYeAZbu/pKmy+TMriBdcL/8h/N2dtW4XTWsReY/OfCXGa5XuJNT8f+tF+h8UFK 3SQ9wIBhnAMUX34l/42UtXG4w1+NMCxAR+fjBsQPTBpim4SdjWMbACAaaF5YmAYh5IOd hDxBlzH/UE7Uacq3qY2xYnV80CfyngfEC4NhQ4hv4c17Mv9BE4dtE7NB5aL/j5F+ly/h KHrA== X-Gm-Message-State: AOAM532jE5nOKZkj5p9tr+N6HmSGBtK72YYazldvUSPMmBkeBRpTAnVD EaX+Yrm7wR7M5uI4trPBrnsJ7oTgbBQ= X-Google-Smtp-Source: ABdhPJwHgi4pQ7ylFHtgCPekbThSxw0vjyZ3Jocj5fmM4vFZ4eEUszPYPT+Z1ZUa+JxwDXj/qTz0eA== X-Received: by 2002:a05:6402:28a:: with SMTP id l10mr7436062edv.365.1623945194039; Thu, 17 Jun 2021 08:53:14 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 05/11] qemu-option: remove now-dead code Date: Thu, 17 Jun 2021 17:53:02 +0200 Message-Id: <20210617155308.928754-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617155308.928754-1-pbonzini@redhat.com> References: <20210617155308.928754-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::534; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x534.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: armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" -M was the sole user of qemu_opts_set and qemu_opts_set_defaults, remove them and the arguments that they used. Signed-off-by: Paolo Bonzini --- include/qemu/option.h | 3 --- tests/unit/test-qemu-opts.c | 35 ------------------------- util/qemu-option.c | 51 ++++++++----------------------------- 3 files changed, 10 insertions(+), 79 deletions(-) diff --git a/include/qemu/option.h b/include/qemu/option.h index fffb03d848..306bf07575 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -119,7 +119,6 @@ QemuOpts *qemu_opts_create(QemuOptsList *list, const ch= ar *id, int fail_if_exists, Error **errp); void qemu_opts_reset(QemuOptsList *list); void qemu_opts_loc_restore(QemuOpts *opts); -bool qemu_opts_set(QemuOptsList *list, const char *name, const char *value= , Error **errp); const char *qemu_opts_id(QemuOpts *opts); void qemu_opts_set_id(QemuOpts *opts, char *id); void qemu_opts_del(QemuOpts *opts); @@ -130,8 +129,6 @@ QemuOpts *qemu_opts_parse_noisily(QemuOptsList *list, c= onst char *params, bool permit_abbrev); QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, bool permit_abbrev, Error **errp); -void qemu_opts_set_defaults(QemuOptsList *list, const char *params, - int permit_abbrev); QemuOpts *qemu_opts_from_qdict(QemuOptsList *list, const QDict *qdict, Error **errp); QDict *qemu_opts_to_qdict_filtered(QemuOpts *opts, QDict *qdict, diff --git a/tests/unit/test-qemu-opts.c b/tests/unit/test-qemu-opts.c index 6568e31a72..828d40e928 100644 --- a/tests/unit/test-qemu-opts.c +++ b/tests/unit/test-qemu-opts.c @@ -410,40 +410,6 @@ static void test_qemu_opts_reset(void) g_assert(opts =3D=3D NULL); } =20 -static void test_qemu_opts_set(void) -{ - QemuOptsList *list; - QemuOpts *opts; - const char *opt; - - list =3D qemu_find_opts("opts_list_04"); - g_assert(list !=3D NULL); - g_assert(QTAILQ_EMPTY(&list->head)); - g_assert_cmpstr(list->name, =3D=3D, "opts_list_04"); - - /* should not find anything at this point */ - opts =3D qemu_opts_find(list, NULL); - g_assert(opts =3D=3D NULL); - - /* implicitly create opts and set str3 value */ - qemu_opts_set(list, "str3", "value", &error_abort); - g_assert(!QTAILQ_EMPTY(&list->head)); - - /* get the just created opts */ - opts =3D qemu_opts_find(list, NULL); - g_assert(opts !=3D NULL); - - /* check the str3 value */ - opt =3D qemu_opt_get(opts, "str3"); - g_assert_cmpstr(opt, =3D=3D, "value"); - - qemu_opts_del(opts); - - /* should not find anything at this point */ - opts =3D qemu_opts_find(list, NULL); - g_assert(opts =3D=3D NULL); -} - static int opts_count_iter(void *opaque, const char *name, const char *val= ue, Error **errp) { @@ -1041,7 +1007,6 @@ int main(int argc, char *argv[]) g_test_add_func("/qemu-opts/opt_get_size", test_qemu_opt_get_size); g_test_add_func("/qemu-opts/opt_unset", test_qemu_opt_unset); g_test_add_func("/qemu-opts/opts_reset", test_qemu_opts_reset); - g_test_add_func("/qemu-opts/opts_set", test_qemu_opts_set); g_test_add_func("/qemu-opts/opts_parse/general", test_opts_parse); g_test_add_func("/qemu-opts/opts_parse/bool", test_opts_parse_bool); g_test_add_func("/qemu-opts/opts_parse/number", test_opts_parse_number= ); diff --git a/util/qemu-option.c b/util/qemu-option.c index 4944015a25..ee78e42216 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -479,19 +479,14 @@ int qemu_opt_unset(QemuOpts *opts, const char *name) } } =20 -static QemuOpt *opt_create(QemuOpts *opts, const char *name, char *value, - bool prepend) +static QemuOpt *opt_create(QemuOpts *opts, const char *name, char *value) { QemuOpt *opt =3D g_malloc0(sizeof(*opt)); =20 opt->name =3D g_strdup(name); opt->str =3D value; opt->opts =3D opts; - if (prepend) { - QTAILQ_INSERT_HEAD(&opts->head, opt, next); - } else { - QTAILQ_INSERT_TAIL(&opts->head, opt, next); - } + QTAILQ_INSERT_TAIL(&opts->head, opt, next); =20 return opt; } @@ -518,7 +513,7 @@ static bool opt_validate(QemuOpt *opt, Error **errp) bool qemu_opt_set(QemuOpts *opts, const char *name, const char *value, Error **errp) { - QemuOpt *opt =3D opt_create(opts, name, g_strdup(value), false); + QemuOpt *opt =3D opt_create(opts, name, g_strdup(value)); =20 if (!opt_validate(opt, errp)) { qemu_opt_del(opt); @@ -662,15 +657,6 @@ void qemu_opts_loc_restore(QemuOpts *opts) loc_restore(&opts->loc); } =20 -bool qemu_opts_set(QemuOptsList *list, const char *name, const char *value= , Error **errp) -{ - QemuOpts *opts; - - assert(list->merge_lists); - opts =3D qemu_opts_create(list, NULL, 0, &error_abort); - return qemu_opt_set(opts, name, value, errp); -} - const char *qemu_opts_id(QemuOpts *opts) { return opts->id; @@ -811,7 +797,7 @@ static const char *get_opt_name_value(const char *param= s, } =20 static bool opts_do_parse(QemuOpts *opts, const char *params, - const char *firstname, bool prepend, + const char *firstname, bool warn_on_flag, bool *help_wanted, Error **er= rp) { char *option, *value; @@ -833,7 +819,7 @@ static bool opts_do_parse(QemuOpts *opts, const char *p= arams, continue; } =20 - opt =3D opt_create(opts, option, value, prepend); + opt =3D opt_create(opts, option, value); g_free(option); if (!opt_validate(opt, errp)) { qemu_opt_del(opt); @@ -889,11 +875,11 @@ bool has_help_option(const char *params) bool qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname, Error **errp) { - return opts_do_parse(opts, params, firstname, false, false, NULL, errp= ); + return opts_do_parse(opts, params, firstname, false, NULL, errp); } =20 static QemuOpts *opts_parse(QemuOptsList *list, const char *params, - bool permit_abbrev, bool defaults, + bool permit_abbrev, bool warn_on_flag, bool *help_wanted, Error **= errp) { const char *firstname; @@ -903,21 +889,13 @@ static QemuOpts *opts_parse(QemuOptsList *list, const= char *params, assert(!permit_abbrev || list->implied_opt_name); firstname =3D permit_abbrev ? list->implied_opt_name : NULL; =20 - /* - * This code doesn't work for defaults && !list->merge_lists: when - * params has no id=3D, and list has an element with !opts->id, it - * appends a new element instead of returning the existing opts. - * However, we got no use for this case. Guard against possible - * (if unlikely) future misuse: - */ - assert(!defaults || list->merge_lists); opts =3D qemu_opts_create(list, id, !list->merge_lists, errp); g_free(id); if (opts =3D=3D NULL) { return NULL; } =20 - if (!opts_do_parse(opts, params, firstname, defaults, + if (!opts_do_parse(opts, params, firstname, warn_on_flag, help_wanted, errp)) { qemu_opts_del(opts); return NULL; @@ -936,7 +914,7 @@ static QemuOpts *opts_parse(QemuOptsList *list, const c= har *params, QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, bool permit_abbrev, Error **errp) { - return opts_parse(list, params, permit_abbrev, false, false, NULL, err= p); + return opts_parse(list, params, permit_abbrev, false, NULL, errp); } =20 /** @@ -954,7 +932,7 @@ QemuOpts *qemu_opts_parse_noisily(QemuOptsList *list, c= onst char *params, QemuOpts *opts; bool help_wanted =3D false; =20 - opts =3D opts_parse(list, params, permit_abbrev, false, true, + opts =3D opts_parse(list, params, permit_abbrev, true, opts_accepts_any(list) ? NULL : &help_wanted, &err); if (!opts) { @@ -968,15 +946,6 @@ QemuOpts *qemu_opts_parse_noisily(QemuOptsList *list, = const char *params, return opts; } =20 -void qemu_opts_set_defaults(QemuOptsList *list, const char *params, - int permit_abbrev) -{ - QemuOpts *opts; - - opts =3D opts_parse(list, params, permit_abbrev, true, false, NULL, NU= LL); - assert(opts); -} - static bool qemu_opts_from_qdict_entry(QemuOpts *opts, const QDictEntry *entry, Error **errp) --=20 2.31.1 From nobody Mon May 6 02:30:23 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623945800911750.7069132790201; Thu, 17 Jun 2021 09:03:20 -0700 (PDT) Received: from localhost ([::1]:58502 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltuUB-0001II-KI for importer@patchew.org; Thu, 17 Jun 2021 12:03:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43998) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltuKU-0006m1-Dr for qemu-devel@nongnu.org; Thu, 17 Jun 2021 11:53:18 -0400 Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]:45572) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltuKS-0001Tj-Cj for qemu-devel@nongnu.org; Thu, 17 Jun 2021 11:53:18 -0400 Received: by mail-ed1-x52c.google.com with SMTP id r7so4652613edv.12 for ; Thu, 17 Jun 2021 08:53:15 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id p13sm4604061edh.79.2021.06.17.08.53.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 08:53:14 -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=ueWdoB0GQlmrLTUBFaKYFQsgmruSTsqBBBENLZQkgjg=; b=mG6TcqCF7EsHAwdT8J7bXMuMReFby1AnH/mhxYmyDs3wvR+Gk7Y24VoLe9187hzz6g yOPWAIVsrRAm07sLDkWHrdwQwXhK8XmsUnj+ILHBbl+ALgrRnQFftBp3zu8eajEHddFI eBGmi1zdWYhjsjJxyJK5GaHl6n2Z5C66zldiGTo1u5yrCirQHopt/puCRDWeLrCvoVXF moIf8Ilf3T9j4jNdQQBFnlipmjjj7IP3B86ExY2jCiRBXXN7brNTYI7DHuHty9UokP95 Ips6uGIXxgcD1jI5A1urD7xjN5ka+m0WriWHUdiXFcbknzcyY9/Npf0Dkicset2quo2T dg1A== 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=ueWdoB0GQlmrLTUBFaKYFQsgmruSTsqBBBENLZQkgjg=; b=C4lcBBRT65eHvXluDnAHz82T3fmVHDBMepwNaNzKByfov+3K1SFUni1cuDRiRWugAo vMK1jfbm6cL1xEE7LrzrWA6gyqiO+B1+7n0i8laY3foJTSSL6aQoRVz8692Nf4/WiPMz a1jyDz0xC8PxDB4RgNeqa162q1TonHSWSR2lmTiYaYDtYJ8NttHhHL6syj1tpu3HX00L xqzbQPUYGrLKWdN33Y0xHERqlD6XmZQBTPTBmuh/2Fx2T3XXhvnTVSurtxTuWMs8mQD4 u64rJ//jtuIl2/mI3h3TkGP+06OD8Zbh4+99fzbRH8wWiaKx9RyjIB/82nMpjSl0XAQM Idbw== X-Gm-Message-State: AOAM533LRikxLpCkVAPOXCPorT+lYgO8DgXVsZ8fE8BBL2Htq/KR8x+w aN5huI4cS7QNyc1m4XvMt8RwDagpVVY= X-Google-Smtp-Source: ABdhPJzWclVQEDEZo+gxPcJKT2A1ZelTCQHtsneYur6aP7f10yr7HyHTrGc75wF4VvgSlL3ns/dCmg== X-Received: by 2002:a50:ce0b:: with SMTP id y11mr7748051edi.356.1623945194895; Thu, 17 Jun 2021 08:53:14 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 06/11] machine: move dies from X86MachineState to CpuTopology Date: Thu, 17 Jun 2021 17:53:03 +0200 Message-Id: <20210617155308.928754-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617155308.928754-1-pbonzini@redhat.com> References: <20210617155308.928754-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::52c; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x52c.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: =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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. Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Paolo Bonzini --- hw/core/machine.c | 1 + hw/i386/pc.c | 4 +--- hw/i386/x86.c | 15 +++++++-------- include/hw/boards.h | 1 + include/hw/i386/pc.h | 1 - include/hw/i386/x86.h | 1 - 6 files changed, 10 insertions(+), 13 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 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 Mon May 6 02:30:23 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623945483138330.22577795017185; Thu, 17 Jun 2021 08:58:03 -0700 (PDT) Received: from localhost ([::1]:40980 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltuP3-0006Ro-V8 for importer@patchew.org; Thu, 17 Jun 2021 11:58:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44028) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltuKW-0006p1-PZ for qemu-devel@nongnu.org; Thu, 17 Jun 2021 11:53:22 -0400 Received: from mail-ej1-x631.google.com ([2a00:1450:4864:20::631]:45668) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltuKT-0001UH-E4 for qemu-devel@nongnu.org; Thu, 17 Jun 2021 11:53:19 -0400 Received: by mail-ej1-x631.google.com with SMTP id hv20so4693512ejc.12 for ; Thu, 17 Jun 2021 08:53:16 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id p13sm4604061edh.79.2021.06.17.08.53.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 08:53:15 -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=5ylDY+0JSvlA4RffEZW471J4NjK7IbPmm9MIR9Ryzqk=; b=SAfocpMZplIGdsJc1YK+0x3sYubSN8L5uUXJH8jOefV+K+cPu2+U7Oyqo+gYDqfgPu l3TBL2gX5zKePAuiqmV4i1DB+VaIcu28XnK0MX/4ZSglUwv30cHD02tDS0TAVY1mRdyt 3EhLjIDnUkoZ4xliZS+m65jF9VtbHnxMBqZILyvNtjfgYT4jTwUn05YeuDno5Hk0LXYK 0YJYXI18dX1cZrlDVsExYibfrFH2Bv0dIdfkUvvZ5Q9qXmmWeQunOL/nlct2wMPaqaIW bd+hnEFKOViPSSyMlbUtueB/XX1iwElu43dqDuXMKUFdAeOuyjkc6MdbKhuw3OoMKN58 rkog== 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=5ylDY+0JSvlA4RffEZW471J4NjK7IbPmm9MIR9Ryzqk=; b=ZiVCwHi9LjgwvT4DP6A5hJtD7BlhZIgh72Sf83iseRZYgDK80+obXz6OoqGHyy/VYe wsa1+IIBDvk1Ee9ICtp98+444p5i19ekxpNwhqEBxM8k8OoCkLlUf9CMDKPMf2pxQCVk t72n5SCM9zQXqFwVcNAhshwPVTNOklGvvAOqhXVXbVe0Yy7pZNTygvVYZ/JIOWu0QKB7 GkDZXx5JvzAo4Bf88xjEDCmbOLo8WDBkgCgql+XlqeJ94b+TpYRzlejmIFDFOmi16+Gc B3fb9XwB3wNO12v3tlpjY1oSL/VSvZoR6pawUgDkuRlPPeuFASDAgwP/plZp18Uiam3s taog== X-Gm-Message-State: AOAM530/KUYa+oQZtabsIXLNXguzIIuy2Yqk+umQMw17GHPBfiBrtoYC T6Ipzeqzu7rgvAgd3JC2Pz5+WYaTWvE= X-Google-Smtp-Source: ABdhPJyg6JdY8TRJxKiDHnETn1Uf817kT3BrKf4unbzEGu3ag8PF+yH7O0xsGVmqhvHrr3THSuf3+Q== X-Received: by 2002:a17:907:9813:: with SMTP id ji19mr6100726ejc.318.1623945195656; Thu, 17 Jun 2021 08:53:15 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 07/11] machine: move common smp_parse code to caller Date: Thu, 17 Jun 2021 17:53:04 +0200 Message-Id: <20210617155308.928754-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617155308.928754-1-pbonzini@redhat.com> References: <20210617155308.928754-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::631; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x631.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: armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Most of smp_parse and pc_smp_parse is guarded by an "if (opts)" conditional, and the rest is common to both function. Move the conditional and the common code to the caller, machine_smp_parse. Move the replay_add_blocker call after all errors are checked for. Signed-off-by: Paolo Bonzini --- hw/core/machine.c | 114 +++++++++++++++++++++++----------------------- hw/i386/pc.c | 108 ++++++++++++++++++++----------------------- 2 files changed, 107 insertions(+), 115 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); + 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); =20 - /* 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); + /* 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); } - - 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 * 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; + } 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 (ms->smp.cpus > 1) { - Error *blocker =3D NULL; - error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, "smp"); - replay_add_blocker(blocker); + 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 * 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); + 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); =20 - /* 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); + /* 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.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; + } 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); } =20 - if (ms->smp.cpus > 1) { - Error *blocker =3D NULL; - error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, "smp"); - replay_add_blocker(blocker); + 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 Mon May 6 02:30:23 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623946646545664.8821078550715; Thu, 17 Jun 2021 09:17:26 -0700 (PDT) Received: from localhost ([::1]:55470 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltuhp-0001pd-B1 for importer@patchew.org; Thu, 17 Jun 2021 12:17:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44030) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltuKW-0006p2-PJ for qemu-devel@nongnu.org; Thu, 17 Jun 2021 11:53:22 -0400 Received: from mail-ed1-x52a.google.com ([2a00:1450:4864:20::52a]:35823) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltuKT-0001UL-Oa for qemu-devel@nongnu.org; Thu, 17 Jun 2021 11:53:19 -0400 Received: by mail-ed1-x52a.google.com with SMTP id df12so2207288edb.2 for ; Thu, 17 Jun 2021 08:53:17 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id p13sm4604061edh.79.2021.06.17.08.53.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 08:53:16 -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=NsW6bhE3jhhDb6OGyNulY9l1vVYB3OpXnDEeg4R99GY=; b=JAiW5/h3DUG/Fyy7F4La4CwwNyQZebd+65yF7gynTuux4rzSLzJPH/KP1ba8VWOv9Y W9PpYgh7vgrf3+koOieRlVpPJnMWajl1VBXl7FFM20WPYzk31kPMMi4nR0y18kmGlVKf tIM+kV8DR/TYvrfz9z8RvseveA58/fWU3UUGv9blHQvEIJnpZydEZWC2KgJkCQHfLq/J /49sXZ/ESrE1fjgjmmtI6o/G3xh0jRmT4fymt2NV3arwNSGsXLKUgDMB6JUzUUQ6pjPa MsOWpkxeUsmVamLG3XOY6yaZOE9ddO9Azt4Mmhn+vYqzYK8B99CcoM9MlwIvjpplZ6tN 8p3g== 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=NsW6bhE3jhhDb6OGyNulY9l1vVYB3OpXnDEeg4R99GY=; b=KR+D6HRXlqSOmgDHSGty8R4wXXWLqv+fzzs0Ispd91+XeCHJfJ5/cRwH+M3ZrLqNcd WnhCsePahuV4yau9IyxMTEKXWJy/gi9a938AyAr24tLSq+DvC+1lTHUBODm8FehLtNuN L5WlnME09bn+0OLqSX5Z7uzShFNJXmrazgf5pBtyuBZwc1t07dN4fZR4+8ZU0VadwAeq TjRNf+t8wygd7MjDwv5Gpun9sEJNP+qTuvhL3pRPtIAMsYg8LeqFfVkAmDJmlK+9Qsu3 BLP6od2JVK/hYd9+eSLTJdcWQimMUGkWpDZGYNRqzwe2zlrdIvUSlifwN7qVvHxae7rH tc3A== X-Gm-Message-State: AOAM530HU0MC88eSfYJM0er6RsWAnIc5HZNldqQywiKWGovt77tNNoCa 8tso5j4K6TCDgZsxDFKgKLLs25isAGM= X-Google-Smtp-Source: ABdhPJzClEDfLLJG2+5X5VHOLaTDW7VWbYvHbIjFxPaGrIWTc6NPb4VWGW/7UsdbPGUkDjUhsZHkuw== X-Received: by 2002:aa7:dd8d:: with SMTP id g13mr7692396edv.30.1623945196470; Thu, 17 Jun 2021 08:53:16 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 08/11] machine: add error propagation to mc->smp_parse Date: Thu, 17 Jun 2021 17:53:05 +0200 Message-Id: <20210617155308.928754-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617155308.928754-1-pbonzini@redhat.com> References: <20210617155308.928754-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::52a; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x52a.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: =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Clean up the smp_parse functions to use Error** instead of exiting. Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Paolo Bonzini --- hw/core/machine.c | 34 +++++++++++++++++++--------------- hw/i386/pc.c | 28 ++++++++++++++-------------- include/hw/boards.h | 2 +- include/hw/i386/pc.h | 2 -- 4 files changed, 34 insertions(+), 32 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 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 Mon May 6 02:30:23 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16239455679931012.891899377811; Thu, 17 Jun 2021 08:59:27 -0700 (PDT) Received: from localhost ([::1]:47462 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltuQR-0002Ix-0V for importer@patchew.org; Thu, 17 Jun 2021 11:59:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44050) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltuKa-0006r8-Hj for qemu-devel@nongnu.org; Thu, 17 Jun 2021 11:53:25 -0400 Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]:43622) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltuKU-0001VB-SR for qemu-devel@nongnu.org; Thu, 17 Jun 2021 11:53:20 -0400 Received: by mail-ej1-x634.google.com with SMTP id nb6so10600092ejc.10 for ; Thu, 17 Jun 2021 08:53:18 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id p13sm4604061edh.79.2021.06.17.08.53.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 08:53:16 -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=kXjHX9Z/i2zcvKzvG1jdWjbGn1gexPthFv0YNAlYjfk=; b=Kssm8kij/ledTFbZhypRGkmN0bEU06TZLSriJ7pFbFvAa118h1P8uBVC5P1FgjPAHG fV6fn9rBSMIFYyE6UefONeNG6lb2pYgbbV46ydjTbk/iyWCZ1bujDyJMkxWWksMe2tPE cPPQT/JDkb80/xjXfN4cGEg5MPFASXg+IXPoK+mIq5JTOSwG//XtG4/pOyRYfacUEz5X yPIpig8eJWxZi+M4aqeIQhf7jgXP2TutztK/CLS4SV3NlYaVhPvCh9wFQHMMHSfJLIE0 JdSeKRcJyZffy5VYoB4AIbuJ2SCs2T1Axw6OEnk3Lpdqqg0/Pl81EpbulfWtP1U4Sogy H6dQ== 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=kXjHX9Z/i2zcvKzvG1jdWjbGn1gexPthFv0YNAlYjfk=; b=E56JQQvupWjwCyQ7s7iDY4IcznGsJ2CDGQ8Ur8eUnavgoJNluPWH3ZIQ/LRpCx9uX5 0tdkL8un3OdgPR/BdRMj3EtxLSJzGJIZmU6144zuTitTGUjO9QxHvx14q5Cm9tRIJSyu umHQWMA8acZzm/LE7o4QufJ8IMBJM2H6mFHSg5kMYEeS3p7bkCx83SHzPJJc0r9Gmk21 pyRdjkQHKA79YU+wwdgckq8I3xmzsEBQxO6bYjj5MAvzAXDM5fTciGD4bJnwv7Glo+5A hNAVLPl3VcbZFqnU2urmWV0pAYs4l0OqN/bJN0cY8IuAgE0oxJOpZjJ2kLSfOuFi+ST0 OCQw== X-Gm-Message-State: AOAM531gcqQGvxqxnE+zm86IUw6QEF4Dfrcj+EwjOdJE1UP7dGBCJB/L Zc6t9hZWAe2oxI4pCoCN+ZfqaYyP9Ss= X-Google-Smtp-Source: ABdhPJzPRBC4CLmd/H+dIdIUvyhFtMSPAh6R3+Nf4P2FWBVDLFv8F8it4U+RlF6RH9dNs/pe3ayqPg== X-Received: by 2002:a17:906:cc14:: with SMTP id ml20mr6044897ejb.515.1623945197393; Thu, 17 Jun 2021 08:53:17 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 09/11] machine: pass QAPI struct to mc->smp_parse Date: Thu, 17 Jun 2021 17:53:06 +0200 Message-Id: <20210617155308.928754-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617155308.928754-1-pbonzini@redhat.com> References: <20210617155308.928754-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::634; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x634.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: =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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. Reviewed-by: Daniel P. Berrang=C3=A9 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 e4d0f9b24f..3301f5235e 100644 --- a/qapi/machine.json +++ b/qapi/machine.json @@ -1284,3 +1284,31 @@ ## { 'event': 'MEM_UNPLUG_ERROR', 'data': { 'device': 'str', 'msg': 'str' } } + +## +# @SMPConfiguration: +# +# Schema for CPU topology configuration. "0" or a missing value is taken = to +# mean "figure out a suitable value based on the ones that are provided. +# +# @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 Mon May 6 02:30:23 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623945865026272.8249416223093; Thu, 17 Jun 2021 09:04:25 -0700 (PDT) Received: from localhost ([::1]:34586 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltuVE-00047a-1k for importer@patchew.org; Thu, 17 Jun 2021 12:04:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44052) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltuKc-0006s2-E9 for qemu-devel@nongnu.org; Thu, 17 Jun 2021 11:53:26 -0400 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]:38900) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltuKW-0001Vs-IX for qemu-devel@nongnu.org; Thu, 17 Jun 2021 11:53:21 -0400 Received: by mail-ej1-x62d.google.com with SMTP id og14so10669676ejc.5 for ; Thu, 17 Jun 2021 08:53:19 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id p13sm4604061edh.79.2021.06.17.08.53.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 08:53:17 -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=QBnoN+mJIyViJRaC52bSEIIRzamZ0YRTp8VHhJaLMeU=; b=ZxdECt5TEuUAd0VInp20ZKofrZrflkx6rEyoUDWdNZmE5k82TALG2fRKxt4SjlXtL4 WD0SMGIA5wxNo/9EbDdmpdGaq40f6feUYJ30FDtUMmkdWYkksVtvyLKmqTkeoa/TOC2R bXQfQDLXG1O7o4MHE2LpHaENxtf5NUzX2ZoEghvxPzw0ZDjvTeCKG9pN9W6dqF7pvFAp RiTc5IS1hs75IIRi4vXTk0YwEgeUV7aoA2dQAvwRJOfPHYRcj+4iox8XsWAUcz6aC1im xiDzZfdQeUY2nr42axvSeifESGYHsMw+ngPAX0Ka4IsW/D5nK+5zcxUujTHiis6+M61H p4zA== 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=QBnoN+mJIyViJRaC52bSEIIRzamZ0YRTp8VHhJaLMeU=; b=tIcyk5/KIs+aBv92B+2+SOcr9p06+t5N9tEaksJ+fGVC0RTbFy5ZMoawIwfMu/jKcG ZjB8o6vjj2xkhA8I0B8qYQF9PcwZyhENNHLPMHBeg7Mt0zDTaWqTQiY/ks1by0joVVMF lOsmTdn1Fr5SomLUQDTWHetbCMMT0NdhCgzvHfboJPqAR0nEuWm5f69Ylf5Ald3XgvyH DzkZ+D2EH+JuWGjfOBf1JimhsScdUOtDj0NI2YIjcdSV7M9ExmqCoSxP1J2QsJwLoTFN P4pQNxM4V+Pp+rsWeyfFBvCAj9usVMLNF3uZ3C3Xery4dYJugcpz7JF80VfBJe7k1gne P35g== X-Gm-Message-State: AOAM5330RORidp0jGQirZtPBt/6fGXbTWuQoYHsoyWkUr1JTvHGcJmWr h++HB404+vOPPdqSHOQjr04jqDGCv4c= X-Google-Smtp-Source: ABdhPJyB3Sew+49i0RPdIILhcmc2W+7s826P5cp7M0kza4iGAxyPe/9LfY6Q0rNcSdGxbtu6y7hODw== X-Received: by 2002:a17:906:2bcc:: with SMTP id n12mr5772263ejg.430.1623945198172; Thu, 17 Jun 2021 08:53:18 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 10/11] machine: reject -smp dies!=1 for non-PC machines Date: Thu, 17 Jun 2021 17:53:07 +0200 Message-Id: <20210617155308.928754-11-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617155308.928754-1-pbonzini@redhat.com> References: <20210617155308.928754-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::62d; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x62d.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: =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Paolo Bonzini --- hw/core/machine.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/core/machine.c b/hw/core/machine.c index 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 Mon May 6 02:30:23 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623945746249893.6478960110779; Thu, 17 Jun 2021 09:02:26 -0700 (PDT) Received: from localhost ([::1]:54502 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltuTJ-00072k-1g for importer@patchew.org; Thu, 17 Jun 2021 12:02:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44054) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltuKc-0006s3-EW for qemu-devel@nongnu.org; Thu, 17 Jun 2021 11:53:26 -0400 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]:45663) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltuKW-0001Wc-In for qemu-devel@nongnu.org; Thu, 17 Jun 2021 11:53:22 -0400 Received: by mail-ej1-x62b.google.com with SMTP id hv20so4693775ejc.12 for ; Thu, 17 Jun 2021 08:53:19 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id p13sm4604061edh.79.2021.06.17.08.53.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 08:53:18 -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=ZFO/UMEmJMubJrnMepHG1AoNAy52aBuH4F/TAA1PGdmCoduer58ja6MRBw1jbEGf4H MX6dqmW4KTdnYMyUHARWauMoODWYNrTvysaneQwwGqMaUqTaCA6ldO5iydc0yAOZ4/0J mqT2oFCnFYrRLOKm96nh/0KpTTgqyKlHvm7kXl2IYD/RtjDO3wyZrhtiu3KDNSE8HX9b dF/bjdAAupnKkR7F3Yze8oNLL5KF7A+MGTHEdtgB3Mzg+zxJ02WADHKD22oMwy2nmN5n Uzh/2moZgKvODaFL/FDz7wDuR+VmbF0Hm/kAGtlrlLE1DooNybPN/eCKpDNx71yq7LDN OBxg== 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=Yi9Idu1eChoMqhvq2hCaRbHRJrch7hRFcZFBnPo+VSqlO9bmkaS8JtfbBvIkxOJ6B6 KTXqNNe3IUkl+rHlI32xgw33LN/818gdkrEDv3oyWzY/jbHV7xrgE0iH2ChLY+RxKS6S UEt3Ycn4+vEPwDw4G5Hz81SLYOHiWrn1z0dCJDQC2KYf9irvdyermNiwJwJs51T+E3SF 6Y11QKx3h+MqrkKNw6Bbb83eldEjoxDuVdgjzF1TngUqR0f6Hod4jFyBnWmoyvFts0ih vG0IUhXWQd182Jvxpc6NONpiY3o9Jm5j/DXUyv9HF4wGAfM314OCmesaUOiaNLk/X/7K TfgQ== X-Gm-Message-State: AOAM532fdkajxHhWJ0DcWDJq2O5IHKD335Zci2gB9xeBt+o1p6cshKA0 WLy1J4XiTrsHBTHhOD3tHw/ifd7PfEM= X-Google-Smtp-Source: ABdhPJxFI0QvfMy/doTIHs63ntatI7DQBa5OpWsS7IEnQ3kCDBpV/IRZqtDwuOlgum5vvxMp702Utw== X-Received: by 2002:a17:906:365a:: with SMTP id r26mr6079981ejb.340.1623945198977; Thu, 17 Jun 2021 08:53:18 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 11/11] machine: add smp compound property Date: Thu, 17 Jun 2021 17:53:08 +0200 Message-Id: <20210617155308.928754-12-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617155308.928754-1-pbonzini@redhat.com> References: <20210617155308.928754-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::62b; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x62b.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: armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Make -smp syntactic sugar for a compound property "-machine smp.{cores,threads,cpu,...}". machine_smp_parse is replaced by the setter for the property. numa-test will now cover the new syntax, while other tests still use -smp. Signed-off-by: Paolo Bonzini --- hw/core/machine.c | 108 +++++++++++++++++++++------------------- 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