From patchwork Tue Jun 8 09:40:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12306193 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AFC74C47082 for ; Tue, 8 Jun 2021 09:49:23 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3C8FA61185 for ; Tue, 8 Jun 2021 09:49:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3C8FA61185 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:59078 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqYMM-00052e-2p for qemu-devel@archiver.kernel.org; Tue, 08 Jun 2021 05:49:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51542) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqYDk-0004YJ-OQ for qemu-devel@nongnu.org; Tue, 08 Jun 2021 05:40:29 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]:33777) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lqYDi-0001nE-KA for qemu-devel@nongnu.org; Tue, 08 Jun 2021 05:40:28 -0400 Received: by mail-wm1-x335.google.com with SMTP id s70-20020a1ca9490000b02901a589651424so1262735wme.0 for ; Tue, 08 Jun 2021 02:40:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eaWfNNyaVagDad1eRt/V1RCmBUTKiX/vUI2Ausu/1+0=; b=H4Basa8zKJF3LcVumn5Llaqmeg02e6S+xe9JkesJaocpM9g/gYZgfWXSS94MMDrRZ5 JQnvn7HF1ig/oihfLwhrqtCtPWH1Tt0N1+IQ+EgXNxx7VBvgjCb0MTqBvdVjrkP0+bTj bxpiynCxEgDONiMaH/LesEMlg9rZV74T0F6ZLM6baPhW/wfJChgaeiRNq57EFIXhkmdh 2UhoHOPZImW6OoeEEcF3iVdcmZHpBaCT5929f8W7Ai/hOynVwtEIAwUUqFEr97XQkjOo E5H3pnT8wAkSMWKPSTs8Qd1EXPIPV/Nue4ZC7oYbZg+3uK19L7VQh3aWWrvRlGFxFXDW 67jA== 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:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=eaWfNNyaVagDad1eRt/V1RCmBUTKiX/vUI2Ausu/1+0=; b=V4/vTjvnWPZsaO1S2OfK2/uEBurSN30p6La2WlHwest+mgROoXIGA1ueMJCqWLjUs2 Q7B96bRPzxdEpHbwfuK9KiR/whEH5Z9fiuDmJVMqN4g3lho2K+tpssz4YkKAvKWtTnk9 l/0yedba0EXwhn26Jq0/++SoyGdNT7fISWq/k2VayKtZNw8qAFPwRAoDZZPsSNx5LNWA FCmNakd6sS0ePs2lgE3unUWqKb/D214gWvAxwo0QUmxj07QqYUC4/l3qdHun61eqaLXH qiPdZTHkjs/1P8x/bYnM0SO/QDG6UuepxwIhrWvYrng+r/q1KCErX6M669ALzNBb4GQn lN9g== X-Gm-Message-State: AOAM531xUbyHJ1lzBd2mOO6jVvx/Tl/llxpi5TLi0G3faas9EV3oyPx9 nQY9dpr8HZJT5kq0TukkIH2JrdrTgGk= X-Google-Smtp-Source: ABdhPJwIB2L6NkS4SjqXjhISX6wIpD6AYTMirZ9JN6szqaz8/X38Jmc6Xd50KFSSpeCJiucSuvbgAg== X-Received: by 2002:a05:600c:b43:: with SMTP id k3mr21104774wmr.18.1623145220931; Tue, 08 Jun 2021 02:40:20 -0700 (PDT) Received: from avogadro.lan ([93.56.169.140]) by smtp.gmail.com with ESMTPSA id d15sm8608764wri.58.2021.06.08.02.40.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 02:40:20 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 01/12] qom: export more functions for use with non-UserCreatable objects Date: Tue, 8 Jun 2021 11:40:06 +0200 Message-Id: <20210608094017.392673-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210608094017.392673-1-pbonzini@redhat.com> References: <20210608094017.392673-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::335; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x335.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.248, 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Machines and accelerators are not user-creatable but they are going to share similar command-line parsing machinery. Export functions that will be used with -machine and -accel in softmmu/vl.c. Signed-off-by: Paolo Bonzini --- include/qom/object.h | 23 ++++++++++++++++ qom/object_interfaces.c | 58 +++++++++++++++++++++++++++++------------ 2 files changed, 65 insertions(+), 16 deletions(-) diff --git a/include/qom/object.h b/include/qom/object.h index 6721cd312e..faae0d841f 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -861,6 +861,29 @@ static void do_qemu_init_ ## type_array(void) \ } \ type_init(do_qemu_init_ ## type_array) +/** + * 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) } } +static void object_set_properties_from_qdict(Object *obj, const QDict *qdict, + Visitor *v, Error **errp) +{ + const QDictEntry *e; + Error *local_err = NULL; + + if (!visit_start_struct(v, NULL, NULL, 0, &local_err)) { + goto out; + } + for (e = qdict_first(qdict); e; e = 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 = qobject_input_visitor_new(QOBJECT(qdict)); + } else { + v = 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 char *id, ERRP_GUARD(); Object *obj; ObjectClass *klass; - const QDictEntry *e; Error *local_err = NULL; if (id != NULL && !id_wellformed(id)) { @@ -78,18 +115,7 @@ Object *user_creatable_add_type(const char *type, const char *id, assert(qdict); obj = object_new(type); - if (!visit_start_struct(v, NULL, NULL, 0, &local_err)) { - goto out; - } - for (e = qdict_first(qdict); e; e = 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); } -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, QemuOpts *opts) } if (qemu_opt_has_help_opt(opts)) { - return user_creatable_print_type_properites(type); + return type_print_class_properties(type); } return false; @@ -234,7 +260,7 @@ static void user_creatable_print_help_from_qdict(QDict *args) { const char *type = qdict_get_try_str(args, "qom-type"); - if (!type || !user_creatable_print_type_properites(type)) { + if (!type || !type_print_class_properties(type)) { user_creatable_print_types(); } } From patchwork Tue Jun 8 09:40:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12306183 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB725C47082 for ; Tue, 8 Jun 2021 09:45:05 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 71AB961003 for ; Tue, 8 Jun 2021 09:45:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 71AB961003 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:46142 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqYIC-0004kj-Fp for qemu-devel@archiver.kernel.org; Tue, 08 Jun 2021 05:45:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51600) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqYDm-0004Yp-Fs for qemu-devel@nongnu.org; Tue, 08 Jun 2021 05:40:30 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]:37514) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lqYDj-0001mu-5g for qemu-devel@nongnu.org; Tue, 08 Jun 2021 05:40:29 -0400 Received: by mail-wm1-x330.google.com with SMTP id f16-20020a05600c1550b02901b00c1be4abso1475940wmg.2 for ; Tue, 08 Jun 2021 02:40:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Qih0GKGRLKmsxOwD0kzGhjmPgfqEGBiIre4xMkTVeaI=; b=SfvFqD3EHZcFGVo/G+HY407pputV9uFxzJ9cIqmJ6yl+ouVl//Ee1r7xevDXFSH85Y FXEK++I1qaDnT79PI8QhMYT9mbihdFY0yc2axBjdNKdZUsXuT8IS3fH0gM65RR75Ma1l 67kI9+l02mo5Mt41llOb/0E7ZsXhqvVoer64zNxsagZI2WzmjtOlSg3NZskiUYAaIjLu aL9FcmfYuRVAMYFRv2WThaDk5XLdHxEGVyezMvt0RaR77OT9Jo2f/JHgKL0TxXA3IfKY YI4RLOKVvcJMfsgj3xIpz1yNkaNeh9bRsI3HmsdvJisqaqGngH+uVQF5KIPne/4VkPcm KUkA== 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:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=Qih0GKGRLKmsxOwD0kzGhjmPgfqEGBiIre4xMkTVeaI=; b=Jw2d7ffnBHerloe1Y6rh924klwjj8Udggw9lkIQd6XKScQaW+OScKzcHc5ilW5kbwc sIEomeGTuDRtMLPnL+3Tdy5oGZjbAxbwfFjcvU6xw9rsyp2t9oXEWRTEsdzD+oG7JG+z ZAG9mzFbYIZ0kXkpzRPH9tujg11XAaaHLA5soEZ4apCdU5CAYQm5PVgzxgNfVL2ihwN/ GJMcSd5UGK4nf5S1FtzW2vOEuXxPncmAtRw9qOSOGRTMVLF0BovtWDne2458iQZJf+AZ DyUKF8LWknZKY3IxOJw5rleZ9+gmN2aUA7HNFQ/4JEcx/t5I7BrRfXh3L5Dz5J683EBT va7A== X-Gm-Message-State: AOAM5329ECraSBRruft3DmF2vIKrxfm0QVnh0xLCh82mT6qWVltxxHU6 PF8+K/G82ZYmI+k+LuiLrgVDHzHCnMo= X-Google-Smtp-Source: ABdhPJxCS6UsNNkKkyGelNAtdF+PXGYSl9tIChR301XtsWWGsA/6KWqDj/Cp/4QaSxdyqfG4HIbjQw== X-Received: by 2002:a1c:8049:: with SMTP id b70mr3284569wmd.92.1623145221655; Tue, 08 Jun 2021 02:40:21 -0700 (PDT) Received: from avogadro.lan ([93.56.169.140]) by smtp.gmail.com with ESMTPSA id d15sm8608764wri.58.2021.06.08.02.40.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 02:40:21 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 02/12] keyval: introduce keyval_merge Date: Tue, 8 Jun 2021 11:40:07 +0200 Message-Id: <20210608094017.392673-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210608094017.392673-1-pbonzini@redhat.com> References: <20210608094017.392673-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x330.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.248, 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 = true QemuOpts groups, merging -readconfig sections and command-line options in a single QDict, and also to implement -set. Signed-off-by: Paolo Bonzini --- include/qemu/option.h | 1 + tests/unit/test-keyval.c | 56 ++++++++++++++++++++++++++++++++++++++++ util/keyval.c | 47 +++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+) diff --git a/include/qemu/option.h b/include/qemu/option.h index f73e0dc7d9..d89c66145a 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -149,5 +149,6 @@ QemuOptsList *qemu_opts_append(QemuOptsList *dst, QemuOptsList *list); QDict *keyval_parse(const char *params, const char *implied_key, bool *help, Error **errp); +void keyval_merge(QDict *old, const QDict *new, Error **errp); #endif diff --git a/tests/unit/test-keyval.c b/tests/unit/test-keyval.c index e20c07cf3e..254b51e98c 100644 --- a/tests/unit/test-keyval.c +++ b/tests/unit/test-keyval.c @@ -747,6 +747,59 @@ static void test_keyval_visit_any(void) visit_free(v); } +static void test_keyval_merge_success(void) +{ + QDict *old = keyval_parse("opt1=abc,opt2.sub1=def,opt2.sub2=ghi,opt3=xyz", + NULL, NULL, &error_abort); + QDict *new = keyval_parse("opt1=ABC,opt2.sub2=GHI,opt2.sub3=JKL", + NULL, NULL, &error_abort); + QDict *combined = keyval_parse("opt1=ABC,opt2.sub1=def,opt2.sub2=GHI,opt2.sub3=JKL,opt3=xyz", + NULL, NULL, &error_abort); + Error *err = NULL; + + keyval_merge(old, new, &err); + g_assert(!err); + g_assert(qobject_is_equal(QOBJECT(combined), QOBJECT(old))); + qobject_unref(old); + qobject_unref(new); + qobject_unref(combined); +} + +static void test_keyval_merge_list(void) +{ + QDict *old = keyval_parse("opt1.0=abc,opt2.0=xyz", + NULL, NULL, &error_abort); + QDict *new = keyval_parse("opt1.0=def", + NULL, NULL, &error_abort); + QDict *combined = keyval_parse("opt1.0=abc,opt1.1=def,opt2.0=xyz", + NULL, NULL, &error_abort); + Error *err = NULL; + + keyval_merge(old, new, &err); + g_assert(!err); + g_assert(qobject_is_equal(QOBJECT(combined), QOBJECT(old))); + qobject_unref(old); + qobject_unref(new); + qobject_unref(combined); +} + +static void test_keyval_merge_conflict(void) +{ + QDict *old = keyval_parse("opt2.sub1=def,opt2.sub2=ghi", + NULL, NULL, &error_abort); + QDict *new = keyval_parse("opt2=ABC", + NULL, NULL, &error_abort); + Error *err = NULL; + + keyval_merge(new, old, &err); + error_free_or_abort(&err); + keyval_merge(old, new, &err); + error_free_or_abort(&err); + + qobject_unref(old); + qobject_unref(new); +} + int main(int argc, char *argv[]) { g_test_init(&argc, &argv, NULL); @@ -760,6 +813,9 @@ int main(int argc, char *argv[]) g_test_add_func("/keyval/visit/optional", test_keyval_visit_optional); g_test_add_func("/keyval/visit/alternate", test_keyval_visit_alternate); g_test_add_func("/keyval/visit/any", test_keyval_visit_any); + g_test_add_func("/keyval/merge/success", test_keyval_merge_success); + g_test_add_func("/keyval/merge/list", test_keyval_merge_list); + g_test_add_func("/keyval/merge/conflict", test_keyval_merge_conflict); g_test_run(); return 0; } diff --git a/util/keyval.c b/util/keyval.c index be34928813..0797f36e1d 100644 --- a/util/keyval.c +++ b/util/keyval.c @@ -310,6 +310,53 @@ static char *reassemble_key(GSList *key) return g_string_free(s, FALSE); } +/* Merge two dictionaries. */ +static void keyval_do_merge(QDict *old, const QDict *new, GString *str, Error **errp) +{ + size_t save_len = str->len; + const QDictEntry *ent; + QObject *old_value; + + for (ent = qdict_first(new); ent; ent = qdict_next(new, ent)) { + old_value = qdict_get(old, ent->key); + if (old_value) { + if (qobject_type(old_value) != qobject_type(ent->value)) { + error_setg(errp, "Parameter '%s%s' used inconsistently", str->str, ent->key); + return; + } else if (qobject_type(ent->value) == 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) == QTYPE_QLIST) { + /* Append to old list. */ + QList *old = qobject_to(QList, old_value); + QList *new = qobject_to(QList, ent->value); + const QListEntry *item; + QLIST_FOREACH_ENTRY(new, item) { + qobject_ref(item->value); + qlist_append_obj(old, item->value); + } + continue; + } + } + + qobject_ref(ent->value); + qdict_put_obj(old, ent->key, ent->value); + } +} + +void keyval_merge(QDict *old, const QDict *new, Error **errp) +{ + GString *str = g_string_new(""); + keyval_do_merge(old, new, str, errp); + g_string_free(str, TRUE); +} + /* * Listify @cur recursively. * Replace QDicts whose keys are all valid list indexes by QLists. From patchwork Tue Jun 8 09:40:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12306203 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E800AC47082 for ; Tue, 8 Jun 2021 09:53:11 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 61676611BD for ; Tue, 8 Jun 2021 09:53:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 61676611BD Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:42826 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqYQ2-0004gG-9P for qemu-devel@archiver.kernel.org; Tue, 08 Jun 2021 05:53:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51598) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqYDm-0004Ym-FH for qemu-devel@nongnu.org; Tue, 08 Jun 2021 05:40:30 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]:45631) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lqYDj-0001nl-5K for qemu-devel@nongnu.org; Tue, 08 Jun 2021 05:40:29 -0400 Received: by mail-wm1-x32a.google.com with SMTP id v206-20020a1cded70000b02901a586d3fa23so1386135wmg.4 for ; Tue, 08 Jun 2021 02:40:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/PRr41PxTyXm10FMURUstxjpacQwh84HXdIsa79wlV8=; b=YtXe09RQcmPQ5bxuCluMBVTDLhc6/KvpT1EgkyxWBrr8yQnydzNvaIYAOUTF0jpQ8H x5xpihYdoM3s0O/4wALNmf0zwHgrpW6jvEHtQn/mlP4qC/MmkwR5bUR+17ZQpBrgn41o MdIsKxhnK/4VKbx9m2QNeRWlg7UOGZTmvG4d4fBNIod1UghtK3GSB3p90B2Z4+ka/fT0 V+W2qDDO8xDwZeoX6D6oUFd0uFYqHkKLsTidBuO+UuTG5Jij98hc8x/2rYmCixi06fEH ZcHZP+Mu52/IMghTagmIM41jGhMr1jhp4iO4vw3zOydQqOGW0UclnnvmbPz5i776Ph7U Yc+Q== 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:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=/PRr41PxTyXm10FMURUstxjpacQwh84HXdIsa79wlV8=; b=agMOhpdUY+jikCJ46fC4T611lWDYzTfZHLpwlxtF7ks9SSist88ejz0AXzemz+k+qF arCtxouN6abeqSa1ljQ8kU6CtgNnMNKXQL+aAq6b6jbHaBlOsOrl2+VJqsusEUUxb6rh sK40Qlv04Vrg2OiiofZawm1MvMSND9dZELe4tkoOrewJ+djUtO+4qFe4Qazkm08DHJgO A/KSOLTtERxCNp078c+NYHXpyR1mfEkfhO0OYJk6pmXmZp543Vpn5diwcL6UNWy5qHOH bdoZuhKeCpYxL2xfjftEhKzfSX5ITbsguf27p3sLR8lTFe5pj/XD8khZOrCFwdB4qX3N 1Rlg== X-Gm-Message-State: AOAM5338LYqb2pTj6kABASuqhPOoFIlAX44DjLzkYPNOr0MA/Drw+a5V al8Evu8oC55CYceqEjLHOOuKmtdI7y4= X-Google-Smtp-Source: ABdhPJx8mBdJzT+8OhXJNCOe1rQR3NXzlcKh9TmUr5Nx+zujaJdmbLnSfTjkqpTAgU+awpOqVYMF2g== X-Received: by 2002:a7b:cde1:: with SMTP id p1mr3111734wmj.13.1623145222552; Tue, 08 Jun 2021 02:40:22 -0700 (PDT) Received: from avogadro.lan ([93.56.169.140]) by smtp.gmail.com with ESMTPSA id d15sm8608764wri.58.2021.06.08.02.40.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 02:40:22 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 03/12] keyval: introduce keyval_parse_into Date: Tue, 8 Jun 2021 11:40:08 +0200 Message-Id: <20210608094017.392673-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210608094017.392673-1-pbonzini@redhat.com> References: <20210608094017.392673-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x32a.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.248, 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 = true QemuOpts group. Signed-off-by: Paolo Bonzini --- include/qemu/option.h | 2 ++ util/keyval.c | 43 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/include/qemu/option.h b/include/qemu/option.h index d89c66145a..fffb03d848 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -147,6 +147,8 @@ void qemu_opts_print_help(QemuOptsList *list, bool print_caption); void qemu_opts_free(QemuOptsList *list); QemuOptsList *qemu_opts_append(QemuOptsList *dst, QemuOptsList *list); +QDict *keyval_parse_into(QDict *qdict, const char *params, const char *implied_key, + bool *p_help, Error **errp); QDict *keyval_parse(const char *params, const char *implied_key, bool *help, Error **errp); void keyval_merge(QDict *old, const QDict *new, Error **errp); diff --git a/util/keyval.c b/util/keyval.c index 0797f36e1d..1ffd6e1204 100644 --- a/util/keyval.c +++ b/util/keyval.c @@ -478,13 +478,14 @@ static QObject *keyval_listify(QDict *cur, GSList *key_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 *implied_key, + bool *p_help, Error **errp) { - QDict *qdict = qdict_new(); QObject *listified; const char *s; bool help = false; @@ -493,7 +494,6 @@ QDict *keyval_parse(const char *params, const char *implied_key, while (*s) { s = keyval_parse_one(qdict, s, implied_key, &help, errp); if (!s) { - qobject_unref(qdict); return NULL; } implied_key = NULL; @@ -503,15 +503,42 @@ QDict *keyval_parse(const char *params, const char *implied_key, *p_help = help; } else if (help) { error_setg(errp, "Help is not available for this option"); - qobject_unref(qdict); return NULL; } listified = keyval_listify(qdict, NULL, errp); if (!listified) { - qobject_unref(qdict); return NULL; } assert(listified == QOBJECT(qdict)); return qdict; } + +/* + * Parse @params in QEMU's traditional KEY=VALUE,... syntax. + * + * If @implied_key, the first KEY= can be omitted. @implied_key is + * implied then, and VALUE can't be empty or contain ',' or '='. + * + * 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 = qdict_new(); + QDict *ret = keyval_parse_into(qdict, params, implied_key, p_help, errp); + + if (!ret) { + qobject_unref(qdict); + } + return ret; +} From patchwork Tue Jun 8 09:40:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12306185 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A10ADC47082 for ; Tue, 8 Jun 2021 09:45:17 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 30EA761003 for ; Tue, 8 Jun 2021 09:45:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 30EA761003 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:46378 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqYIN-0004uB-Ub for qemu-devel@archiver.kernel.org; Tue, 08 Jun 2021 05:45:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51622) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqYDn-0004af-2l for qemu-devel@nongnu.org; Tue, 08 Jun 2021 05:40:31 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]:42536) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lqYDj-0001oO-5u for qemu-devel@nongnu.org; Tue, 08 Jun 2021 05:40:30 -0400 Received: by mail-wm1-x329.google.com with SMTP id l7-20020a05600c1d07b02901b0e2ebd6deso1394144wms.1 for ; Tue, 08 Jun 2021 02:40:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LDv+ZH2LmW5070WGtSOldoGmLLz0hT9fiDNARCMiQaI=; b=WRMdHn1ztMJA2yBVXkE6noEhAIyyrt38JWWLdLvK4zr3Xakt0IDq6tSXDeUkGtV5vV N5fXC1tuEBW8umbTXkOgX+BVjZOGeeJmsGpHaUYE4UhhxedytAG5yq3HYcWPq+BroaMI 5tzqSlmKMuVIKa/u6jeA3+cZanJHaxVs3G3GURT19N4SkXNtXG8oCBimvkmk9y53BFnD DYa299ad1HJRPDiaDJnRvrYfUFwaFW1mPjWiOKo25bsFUD7iwIRGMIJipOguw9KkE95C iCahtOYAQApWyKRrWHaQNRkKneOIhZyPiDgqFaqaxti5DYAQ7EIyVicxwk6BCouClTKd I43A== 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:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=LDv+ZH2LmW5070WGtSOldoGmLLz0hT9fiDNARCMiQaI=; b=tDSiQQyrxhfSE62c2cetaSjQaFKyyLxid5lpt7m2AL/iH3EEpae0OwtPBl5PODycKF Eu54itFs5Hf0/b9mdDZpshf+gs8IiPLzbiy8kGcJX82rUZ/HMcPP2CjTZOChvGg1mxdk xrNdFMJAtYPjdOyOML0Q9bmCvUfGPY8j6dL7ZW49RS/v/zY7R5jpNCwlA9v4VxQzTCqL R8HM0Xbx2q8q1HV7iAQDrQ4lqffHu4GO7zVnuJiZu9HH7YvCSSXX6Y4c5xwQRWS4JHWb 98nTF6Meus4l0QyMZ+D/EtT/yUbqE78OJgbzySwn/xRPdfECT1nPCb/UmAE9LWWfPLFM l7zA== X-Gm-Message-State: AOAM5305Q1cE78hBHKMC226AuauLFpf+O1cAkelhuZunTfX7xAPmK4tS FluCQtEUp0Q0uWIRAPOQrHMOnKOzNuM= X-Google-Smtp-Source: ABdhPJx4u5NW2U7/XaheAghhe2rfnYbfrxQEyoUHQs/UklIUbgsgBwaYfGu8q7G34CzWqmiHpxiflA== X-Received: by 2002:a05:600c:1d0a:: with SMTP id l10mr3292799wms.124.1623145223476; Tue, 08 Jun 2021 02:40:23 -0700 (PDT) Received: from avogadro.lan ([93.56.169.140]) by smtp.gmail.com with ESMTPSA id d15sm8608764wri.58.2021.06.08.02.40.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 02:40:23 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 04/12] vl: switch -M parsing to keyval Date: Tue, 8 Jun 2021 11:40:09 +0200 Message-Id: <20210608094017.392673-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210608094017.392673-1-pbonzini@redhat.com> References: <20210608094017.392673-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x329.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.248, 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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=val) were to be merged with strongly-typed dictionaries (produced by -M {'key': 123}). The simplest way out is to never enter the situation, and only allow one -M option when JSON syntax is in use. However, we want options such as -smp to become syntactic sugar for -M, and this is a problem; as soon as -smp becomes a shortcut for -M, QEMU would forbid using -M '{....}' together with -smp. Therefore, allowing JSON syntax right now for -M would be a forward-compatibility nightmare and it would be impossible anyway to introduce -M incrementally in tools. Instead, support for JSON syntax is delayed until after the main options are converted to QOM compound properties. These include -boot, -acpitable, -smbios, -m, -semihosting-config, -rtc and -fw_cfg. Once JSON syntax is introduced, these options will _also_ be forbidden together with -M '{...}'. Signed-off-by: Paolo Bonzini --- softmmu/vl.c | 303 ++++++++++++++++++++++++--------------------------- 1 file changed, 140 insertions(+), 163 deletions(-) diff --git a/softmmu/vl.c b/softmmu/vl.c index 326c1e9080..c3686a6722 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 = 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 = { }, }; -static QemuOptsList qemu_machine_opts = { - .name = "machine", - .implied_opt_name = "type", - .merge_lists = true, - .head = QTAILQ_HEAD_INITIALIZER(qemu_machine_opts.head), - .desc = { - /* - * no elements => accept any - * sanity checking will happen later - * when setting machine properties - */ - { } - }, -}; - static QemuOptsList qemu_accel_opts = { .name = "accel", .implied_opt_name = "accel", @@ -498,16 +485,6 @@ static QemuOptsList qemu_action_opts = { }, }; -/** - * 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 *machines) return default_machineclass; } -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 = object_property_iter_next(&iter))) { - if (!prop->set) { - continue; - } - - printf("%s.%s=%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, gconstpointer b) object_class_get_name(OBJECT_CLASS(mc1))); } -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 = qdict_get_try_str(qdict, "type"); - if (is_help_option(name)) { - printf("Supported machines are:\n"); - machines = g_slist_sort(machines, machine_class_cmp); - for (el = machines; el; el = el->next) { - MachineClass *mc = 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 = object_class_get_list(TYPE_MACHINE, false); + if (type) { + ObjectClass *machine_class = OBJECT_CLASS(find_machine(type, machines)); + if (machine_class) { + type_print_class_properties(object_class_get_name(machine_class)); + return; } - exit(0); } - mc = 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 = g_slist_sort(machines, machine_class_cmp); + for (el = machines; el; el = el->next) { + MachineClass *mc = 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)" : ""); } - return mc; } static const char *pid_file; @@ -1625,32 +1573,31 @@ static const QEMUOption *lookup_opt(int argc, char **argv, return popt; } -static MachineClass *select_machine(void) +static MachineClass *select_machine(QDict *qdict, Error **errp) { + const char *optarg = qdict_get_try_str(qdict, "type"); GSList *machines = object_class_get_list(TYPE_MACHINE, false); - MachineClass *machine_class = find_default_machine(machines); - const char *optarg; - QemuOpts *opts; - Location loc; - - loc_push_none(&loc); - - opts = qemu_get_machine_opts(); - qemu_opts_loc_restore(opts); + MachineClass *machine_class; + Error *local_err = NULL; - optarg = qemu_opt_get(opts, "type"); if (optarg) { - machine_class = machine_parse(optarg, machines); - } - - if (!machine_class) { - error_report("No machine specified, and there is no default"); - error_printf("Use -machine help to list supported machines\n"); - exit(1); + machine_class = find_machine(optarg, machines); + qdict_del(qdict, "type"); + if (!machine_class) { + error_setg(&local_err, "unsupported machine type"); + } + } else { + machine_class = find_default_machine(machines); + if (!machine_class) { + error_setg(&local_err, "No machine specified, and there is no default"); + } } - 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; } @@ -1669,42 +1616,70 @@ static int object_parse_property_opt(Object *obj, return 0; } -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 = g_strdup(name); + const QDictEntry *ent, *next; char *p; - for (p = qom_name; *p; p++) { - if (*p == '_') { - *p = '-'; + for (ent = qdict_first(qdict); ent; ent = next) { + g_autofree char *new_key = NULL; + + next = qdict_next(qdict, ent); + if (!strchr(ent->key, '_')) { + continue; } + new_key = g_strdup(ent->key); + for (p = new_key; *p; p++) { + if (*p == '_') { + *p = '-'; + } + } + if (qdict_haskey(qdict, new_key)) { + error_setg(errp, "Conflict between '%s' and '%s'", ent->key, new_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); /* Legacy options do not correspond to MachineState properties. */ - if (g_str_equal(qom_name, "accel")) { - return 0; + value = qdict_get_try_str(qdict, "accel"); + if (value) { + accelerators = g_strdup(value); + qdict_del(qdict, "accel"); } - if (g_str_equal(qom_name, "igd-passthru")) { - object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), qom_name, value, + + value = qdict_get_try_str(qdict, "igd-passthru"); + if (value) { + object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), "igd-passthru", value, false); - return 0; + qdict_del(qdict, "igd-passthru"); } - if (g_str_equal(qom_name, "kvm-shadow-mem")) { - object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), qom_name, value, + + value = qdict_get_try_str(qdict, "kvm-shadow-mem"); + if (value) { + object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), "kvm-shadow-mem", value, false); - return 0; + qdict_del(qdict, "kvm-shadow-mem"); } - if (g_str_equal(qom_name, "kernel-irqchip")) { - object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), qom_name, value, + + value = qdict_get_try_str(qdict, "kernel-irqchip"); + if (value) { + object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), "kernel-irqchip", value, false); - object_register_sugar_prop(ACCEL_CLASS_NAME("whpx"), qom_name, value, + object_register_sugar_prop(ACCEL_CLASS_NAME("whpx"), "kernel-irqchip", value, false); - return 0; + qdict_del(qdict, "kernel-irqchip"); } - - return object_parse_property_opt(opaque, name, value, "type", errp); } static void object_option_foreach_add(bool (*type_opt_predicate)(const char *)) @@ -1819,16 +1794,14 @@ static bool object_create_early(const char *type) return true; } -static void qemu_apply_machine_options(void) +static void qemu_apply_machine_options(QDict *qdict) { MachineClass *machine_class = MACHINE_GET_CLASS(current_machine); - QemuOpts *machine_opts = qemu_get_machine_opts(); const char *boot_order = NULL; const char *boot_once = NULL; QemuOpts *opts; - qemu_opt_foreach(machine_opts, machine_set_property, current_machine, - &error_fatal); + object_set_properties_from_keyval(OBJECT(current_machine), qdict, false, &error_fatal); current_machine->ram_size = ram_size; current_machine->maxram_size = maxram_size; current_machine->ram_slots = ram_slots; @@ -1857,10 +1830,8 @@ static void qemu_apply_machine_options(void) current_machine->boot_once = boot_once; if (semihosting_enabled() && !semihosting_get_argc()) { - const char *kernel_filename = qemu_opt_get(machine_opts, "kernel"); - const char *kernel_cmdline = 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); } } @@ -1907,8 +1878,7 @@ static void qemu_create_early_backends(void) /* * 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); } -static void qemu_create_machine(MachineClass *machine_class) +static void qemu_create_machine(QDict *qdict) { + MachineClass *machine_class = select_machine(qdict, &error_fatal); object_set_machine_compat_props(machine_class->compat_props); set_memory_options(machine_class); current_machine = 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 *machine_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 = + 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); } } @@ -2137,7 +2109,8 @@ static int global_init_func(void *opaque, QemuOpts *opts, 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 *group, QDict *dict, Visitor *v = 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, QemuOpts *opts, Error **errp) static void configure_accelerators(const char *progname) { - const char *accelerators; bool init_failed = false; qemu_opts_foreach(qemu_find_opts("icount"), do_configure_icount, NULL, &error_fatal); - accelerators = qemu_opt_get(qemu_get_machine_opts(), "accel"); if (QTAILQ_EMPTY(&qemu_accel_opts.head)) { char **accel_list, **tmp; @@ -2374,12 +2352,11 @@ static void create_default_memdev(MachineState *ms, const char *path) &error_fatal); } -static void qemu_validate_options(void) +static void qemu_validate_options(const QDict *machine_opts) { - QemuOpts *machine_opts = qemu_get_machine_opts(); - const char *kernel_filename = qemu_opt_get(machine_opts, "kernel"); - const char *initrd_filename = qemu_opt_get(machine_opts, "initrd"); - const char *kernel_cmdline = qemu_opt_get(machine_opts, "append"); + const char *kernel_filename = qdict_get_try_str(machine_opts, "kernel"); + const char *initrd_filename = qdict_get_try_str(machine_opts, "initrd"); + const char *kernel_cmdline = qdict_get_try_str(machine_opts, "append"); if (kernel_filename == NULL) { if (kernel_cmdline != 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) } } + machine_opts_dict = 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 = qemu_find_opts("machine"); - qemu_opts_parse_noisily(olist, "graphics=off", false); + qdict_put_str(machine_opts_dict, "graphics", "off"); nographic = true; dpy.type = 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, &error_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", optarg, &error_abort); + qdict_put_str(machine_opts_dict, "firmware", optarg); break; case QEMU_OPTION_singlestep: singlestep = 1; @@ -3262,17 +3238,20 @@ void qemu_init(int argc, char **argv, char **envp) preconfig_requested = true; break; case QEMU_OPTION_enable_kvm: - olist = qemu_find_opts("machine"); - qemu_opts_parse_noisily(olist, "accel=kvm", false); + qdict_put_str(machine_opts_dict, "accel", "kvm"); break; case QEMU_OPTION_M: case QEMU_OPTION_machine: - olist = qemu_find_opts("machine"); - opts = 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 = qemu_opts_parse_noisily(qemu_find_opts("accel"), optarg, true); @@ -3299,12 +3278,10 @@ void qemu_init(int argc, char **argv, char **envp) } break; case QEMU_OPTION_usb: - olist = qemu_find_opts("machine"); - qemu_opts_parse_noisily(olist, "usb=on", false); + qdict_put_str(machine_opts_dict, "usb", "on"); break; case QEMU_OPTION_usbdevice: - olist = qemu_find_opts("machine"); - qemu_opts_parse_noisily(olist, "usb=on", 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 = qemu_find_opts("machine"); - qemu_opts_parse_noisily(olist, "acpi=off", false); + qdict_put_str(machine_opts_dict, "acpi", "off"); break; case QEMU_OPTION_no_hpet: - olist = qemu_find_opts("machine"); - qemu_opts_parse_noisily(olist, "hpet=off", false); + qdict_put_str(machine_opts_dict, "hpet", "off"); break; case QEMU_OPTION_no_reboot: olist = qemu_find_opts("action"); @@ -3581,7 +3556,7 @@ void qemu_init(int argc, char **argv, char **envp) */ loc_set_none(); - qemu_validate_options(); + qemu_validate_options(machine_opts_dict); qemu_process_sugar_options(); /* @@ -3614,7 +3589,7 @@ void qemu_init(int argc, char **argv, char **envp) configure_rtc(qemu_find_opts_singleton("rtc")); - qemu_create_machine(select_machine()); + qemu_create_machine(machine_opts_dict); suspend_mux_open(); @@ -3622,12 +3597,14 @@ void qemu_init(int argc, char **argv, char **envp) qemu_create_default_devices(); qemu_create_early_backends(); - 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); /* * 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); From patchwork Tue Jun 8 09:40:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12306177 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 246BFC4743D for ; Tue, 8 Jun 2021 09:42:37 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9CC2561003 for ; Tue, 8 Jun 2021 09:42:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9CC2561003 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:37772 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqYFn-0007Ud-Pp for qemu-devel@archiver.kernel.org; Tue, 08 Jun 2021 05:42:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51592) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqYDm-0004Yk-FR for qemu-devel@nongnu.org; Tue, 08 Jun 2021 05:40:30 -0400 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]:46891) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lqYDi-0001pZ-Up for qemu-devel@nongnu.org; Tue, 08 Jun 2021 05:40:29 -0400 Received: by mail-wr1-x433.google.com with SMTP id a11so18949762wrt.13 for ; Tue, 08 Jun 2021 02:40:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IDPNHb+HPzR8VO7xPUhdfTuo9DK5TmK3Ukrht2Or98o=; b=m4HM9/9HjlVd0G5zJLxBa5tGnWGGie2cMklPB2rUc2/FOHD63NF9gcuDaxmgcVrKDE vnh+hgBhclw4tINkdxmEF+7LPLmLf6FUgWkow0NaBLaIENcY2FY2HKXeuVudDkksXyaN Gd8rUTLL1s2mhDtHdvGe8KrzT78Bcy3cXrP1SxLlRDg/f4xKBb2K2m9hRK35kqjwwho2 olERJiZvl1d7qwWHeAV5AXskfHguKDp+R7wZICi36kizh0k3EIbI1fS70eepEEKvSfJt A3eAvGToNbf1YYCcQGx4DKXOkt1RV9gcESJFbrnN70xtxNJ3CmjROpXnSz2l0q+m4vYn jP4w== 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:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=IDPNHb+HPzR8VO7xPUhdfTuo9DK5TmK3Ukrht2Or98o=; b=rxOtHl863ntAxCXXLtxKJHI3uKBL4H5Wh4yKvGlM2suRaKfRHfL5hRggoY0MtvbttT ByJOkgci7PnHcOmS48sENsjk3cRTVxO5DfT6QwWdJeEgwSuQbuSZpRKUbfOIvo3mbEkk t0KuUXUiyRmRDj8a4J98TdaGArbimglfUjRlkGGnZD6P+Cbq532nOpP7f5SJifhD0ISY DPMjLt6NvEkWpwOse5fQtWFG+At/vy6HjII2IYf9eXhHoqySUv2OyWZ2KgNpMDeS4jVl cxduo0fwGI8xu1BkQyVypzWbANnSyoo25mFj2wKK+/H9uSbfSaDdax1zZ0um3OB3FbzI +6hw== X-Gm-Message-State: AOAM531akJ8jkBibYtH5QZByFf5mn/RnzlBSVmE9D4Ftj4HVjXdCMP87 Qzuj04lWlQZALk62KGoI0M4Yel3z1qo= X-Google-Smtp-Source: ABdhPJzgy7yuZfDbwI0Ljf809J6h9IuCzGndJmdPsnm1NQIk/mnh2RzJ6OV8N0fX8oajfZXfABwleQ== X-Received: by 2002:adf:f54a:: with SMTP id j10mr20993496wrp.383.1623145224646; Tue, 08 Jun 2021 02:40:24 -0700 (PDT) Received: from avogadro.lan ([93.56.169.140]) by smtp.gmail.com with ESMTPSA id d15sm8608764wri.58.2021.06.08.02.40.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 02:40:24 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 05/12] qemu-option: remove now-dead code Date: Tue, 8 Jun 2021 11:40:10 +0200 Message-Id: <20210608094017.392673-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210608094017.392673-1-pbonzini@redhat.com> References: <20210608094017.392673-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::433; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x433.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.248, 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" -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 char *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, const 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 == NULL); } -static void test_qemu_opts_set(void) -{ - QemuOptsList *list; - QemuOpts *opts; - const char *opt; - - list = qemu_find_opts("opts_list_04"); - g_assert(list != NULL); - g_assert(QTAILQ_EMPTY(&list->head)); - g_assert_cmpstr(list->name, ==, "opts_list_04"); - - /* should not find anything at this point */ - opts = qemu_opts_find(list, NULL); - g_assert(opts == 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 = qemu_opts_find(list, NULL); - g_assert(opts != NULL); - - /* check the str3 value */ - opt = qemu_opt_get(opts, "str3"); - g_assert_cmpstr(opt, ==, "value"); - - qemu_opts_del(opts); - - /* should not find anything at this point */ - opts = qemu_opts_find(list, NULL); - g_assert(opts == NULL); -} - static int opts_count_iter(void *opaque, const char *name, const char *value, 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) } } -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 = g_malloc0(sizeof(*opt)); opt->name = g_strdup(name); opt->str = value; opt->opts = 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); 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 = opt_create(opts, name, g_strdup(value), false); + QemuOpt *opt = opt_create(opts, name, g_strdup(value)); if (!opt_validate(opt, errp)) { qemu_opt_del(opt); @@ -662,15 +657,6 @@ void qemu_opts_loc_restore(QemuOpts *opts) loc_restore(&opts->loc); } -bool qemu_opts_set(QemuOptsList *list, const char *name, const char *value, Error **errp) -{ - QemuOpts *opts; - - assert(list->merge_lists); - opts = 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 *params, } 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 **errp) { char *option, *value; @@ -833,7 +819,7 @@ static bool opts_do_parse(QemuOpts *opts, const char *params, continue; } - opt = opt_create(opts, option, value, prepend); + opt = 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); } 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 = permit_abbrev ? list->implied_opt_name : NULL; - /* - * This code doesn't work for defaults && !list->merge_lists: when - * params has no id=, 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 = qemu_opts_create(list, id, !list->merge_lists, errp); g_free(id); if (opts == NULL) { return NULL; } - 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 char *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, errp); + return opts_parse(list, params, permit_abbrev, false, NULL, errp); } /** @@ -954,7 +932,7 @@ QemuOpts *qemu_opts_parse_noisily(QemuOptsList *list, const char *params, QemuOpts *opts; bool help_wanted = false; - opts = opts_parse(list, params, permit_abbrev, false, true, + opts = 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; } -void qemu_opts_set_defaults(QemuOptsList *list, const char *params, - int permit_abbrev) -{ - QemuOpts *opts; - - opts = opts_parse(list, params, permit_abbrev, true, false, NULL, NULL); - assert(opts); -} - static bool qemu_opts_from_qdict_entry(QemuOpts *opts, const QDictEntry *entry, Error **errp) From patchwork Tue Jun 8 09:40:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12306175 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D155C47082 for ; Tue, 8 Jun 2021 09:42:36 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D611D610FB for ; Tue, 8 Jun 2021 09:42:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D611D610FB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:37774 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqYFn-0007Ur-0J for qemu-devel@archiver.kernel.org; Tue, 08 Jun 2021 05:42:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51590) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqYDm-0004Yi-DG for qemu-devel@nongnu.org; Tue, 08 Jun 2021 05:40:30 -0400 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]:44847) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lqYDj-0001q3-5P for qemu-devel@nongnu.org; Tue, 08 Jun 2021 05:40:29 -0400 Received: by mail-wr1-x42d.google.com with SMTP id f2so20780174wri.11 for ; Tue, 08 Jun 2021 02:40:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TFaVv/jz4lgF0mz802si5sGlUrBseoogQ4/SE+k7/4A=; b=fyUIvR9OKvK6ocIb70b7RslMiNKvwesrc146Us/t07Bc/ZXE39zPmZslJc4gW+xQ7L mANFPR2r7U8WvKxhPYfXHyKmocS0cVlF2fb30pCFfgM7QwP7Lp+xhoNGsN9fRhJSCadO IefWXVFsVN9BrILPAaNlnkK6H/HSMuHpEh3AJ5GHaKREGKr7GAr0OnMYcnQSqhlcWht7 4Tz5iHQbr01T1u4ffgXVNklZbt/QmUbH7MHATKjv5B5RWFf1aZocX18Q81j7uhk5JuKR O6M3qO9TPGYgC3V6+KXGYK+mvbt9tCWPSDDo5C1YRf4o6QKYITT3Szsd6YBc6+Dv9qHi PT6A== 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:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=TFaVv/jz4lgF0mz802si5sGlUrBseoogQ4/SE+k7/4A=; b=Qffo0+gqxpDZYD25Ew7sWteVgFEonUeUpWCL8x1+SdrOoTBKfwjs/sydCmBvv7I6NW 869uLfwst4r3FSeGuOvcwGidYqyFPxcT1pLMD/tAoRfEqvgF36FPqllnq6DgvTVw/2El 2dRNZyJF5S/3aDRC1aYRegdafetG4kfPl+3Men1jUMV1hJmuLJeBYUstApbt9G5zMYEu Lp5b+f0H4mhh3AGE6QAflspax3H39Uqq+wuPLySQgZP2Mb/AcFCDm0hQBaTb/AL2jB07 iCRmLFrHjvmIZudVZReXMmu2qenmYH2dnWc6FH+e+vsvnZv8GzuJMgPOIkqpFrxd8GS5 ZOoQ== X-Gm-Message-State: AOAM530tcd35vI0DBd5Ww8VKqhziHproOLerbnjoiyPYO9Dfprtt5bWs 3V0nv4ApFA6lzkIRoc4txGAPkCxHC/A= X-Google-Smtp-Source: ABdhPJx8CpH+n8GWUf1GVFjtiXjFWpvbYXaET9jJdWuymXOs4/ZaCznP593YX3ppYhhm3AgzQYUxew== X-Received: by 2002:adf:a1d2:: with SMTP id v18mr21151197wrv.280.1623145225735; Tue, 08 Jun 2021 02:40:25 -0700 (PDT) Received: from avogadro.lan ([93.56.169.140]) by smtp.gmail.com with ESMTPSA id d15sm8608764wri.58.2021.06.08.02.40.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 02:40:25 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 06/12] machine: move dies from X86MachineState to CpuTopology Date: Tue, 8 Jun 2021 11:40:11 +0200 Message-Id: <20210608094017.392673-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210608094017.392673-1-pbonzini@redhat.com> References: <20210608094017.392673-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42d; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x42d.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.248, 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" In order to make SMP configuration a Machine property, we need a getter as well as a setter. To simplify the implementation put everything that the getter needs in the CpuTopology struct. Signed-off-by: Paolo Bonzini --- hw/core/machine.c | 1 + hw/i386/pc.c | 4 +--- hw/i386/x86.c | 15 +++++++-------- include/hw/boards.h | 1 + include/hw/i386/pc.h | 1 - include/hw/i386/x86.h | 1 - 6 files changed, 10 insertions(+), 13 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 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 = mc->default_cpus; ms->smp.max_cpus = mc->default_cpus; ms->smp.cores = 1; + ms->smp.dies = 1; ms->smp.threads = 1; ms->smp.sockets = 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 level) */ void pc_smp_parse(MachineState *ms, QemuOpts *opts) { - X86MachineState *x86ms = X86_MACHINE(ms); - if (opts) { unsigned cpus = qemu_opt_get_number(opts, "cpus", 0); unsigned sockets = qemu_opt_get_number(opts, "sockets", 0); @@ -769,7 +767,7 @@ void pc_smp_parse(MachineState *ms, QemuOpts *opts) ms->smp.cores = cores; ms->smp.threads = threads; ms->smp.sockets = sockets; - x86ms->smp_dies = dies; + ms->smp.dies = dies; } 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 = MACHINE(x86ms); - topo_info->dies_per_pkg = x86ms->smp_dies; + topo_info->dies_per_pkg = ms->smp.dies; topo_info->cores_per_die = ms->smp.cores; topo_info->threads_per_core = ms->smp.threads; } @@ -293,7 +293,7 @@ void x86_cpu_pre_plug(HotplugHandler *hotplug_dev, init_topo_info(&topo_info, x86ms); - env->nr_dies = x86ms->smp_dies; + env->nr_dies = ms->smp.dies; /* * If APIC ID is not set, @@ -301,13 +301,13 @@ void x86_cpu_pre_plug(HotplugHandler *hotplug_dev, */ if (cpu->apic_id == UNASSIGNED_APIC_ID) { int max_socket = (ms->smp.max_cpus - 1) / - smp_threads / smp_cores / x86ms->smp_dies; + smp_threads / smp_cores / ms->smp.dies; /* * 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 == 1) { + if (cpu->die_id < 0 && ms->smp.dies == 1) { cpu->die_id = 0; } @@ -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(MachineState *ms) &topo_info, &topo_ids); ms->possible_cpus->cpus[i].props.has_socket_id = true; ms->possible_cpus->cpus[i].props.socket_id = topo_ids.pkg_id; - if (x86ms->smp_dies > 1) { + if (ms->smp.dies > 1) { ms->possible_cpus->cpus[i].props.has_die_id = true; ms->possible_cpus->cpus[i].props.die_id = topo_ids.die_id; } @@ -1252,7 +1252,6 @@ static void x86_machine_initfn(Object *obj) x86ms->smm = ON_OFF_AUTO_AUTO; x86ms->acpi = ON_OFF_AUTO_AUTO; - x86ms->smp_dies = 1; x86ms->pci_irq_mask = ACPI_BUILD_PCI_IRQS; x86ms->oem_id = g_strndup(ACPI_BUILD_APPNAME6, 6); x86ms->oem_table_id = 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; OnOffAuto smm; OnOffAuto acpi; From patchwork Tue Jun 8 09:40:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12306191 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 766ABC47082 for ; Tue, 8 Jun 2021 09:47:58 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0C77161008 for ; Tue, 8 Jun 2021 09:47:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0C77161008 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:54794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqYKz-0002Az-6K for qemu-devel@archiver.kernel.org; Tue, 08 Jun 2021 05:47:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51634) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqYDn-0004bL-Bt for qemu-devel@nongnu.org; Tue, 08 Jun 2021 05:40:31 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]:55877) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lqYDk-0001qY-0R for qemu-devel@nongnu.org; Tue, 08 Jun 2021 05:40:31 -0400 Received: by mail-wm1-x336.google.com with SMTP id g204so1390511wmf.5 for ; Tue, 08 Jun 2021 02:40:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=J/jOftwZDa2RFQJpkwXjrQU/YDdcj+tfPzp2fAN/u3Q=; b=fbmvFC5G2olYdapW0dcnswicmUt/CagkADNkyuy05EVEAdbqZS9jQ3PPJMcvqKI05T Hus95Wdmge9MjnYMZw9liFgHuWyS/dc1wkXapVUAAoUMuYNAsMPEJYL4j9RpzRXak2zw eUiMn/oZKA984dPIgnj/2Om/pZIxzFxK5tu1RFh1p0xfrRGRt9Nab7i0azYL9J0TRXIw YGQ9wLNVOXrjOVDpfrM12jYheczlxeR5b54OuLXOTylsBK9HCorfh/fWbN6GAn69vGvx 8HyJ/80vzwD/tDcbn5iBDObORHT+uWlL1BBKa4A4lFS+TtBa63KEJUYqvOcBkyygUbqq 9xiQ== 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:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=J/jOftwZDa2RFQJpkwXjrQU/YDdcj+tfPzp2fAN/u3Q=; b=dk/6IDi8b5ZuHR6GHLRQSgTUDtly5XzVbefK1THPBxZAA5O6lpz6enPiHfxNtnGAKZ 6uDoz+k/rEw3q5Q3Lv/vI20CnELB8t5Hhvd4QFrPcCWoGlfRjN9mEcHrtEzGScK4JQWl Zj+3gj8mMUirA+5hIajaD3HSt+EUyZn7xkL1d0wcc6OFLkSBcjACIlgxpIqePa0yw1A6 rRewo0fsl/x0heSOlsN9Fcjl9mMWa0eWuYG52QEpsI0spQv28SmAu44q9r6N1EhRmHKY c77qnEyExW90HDHRlCDfmAwEhNIkgMDBHFPtkT0tWZAG6h/aasE2Z2bX/Yrm0apPGyNL /apg== X-Gm-Message-State: AOAM530MMjGhE613BKLIdGLzJnzZYpKWvGspYIVZm84bpCvlJsP48S1V ep48iyHmxz1/fA5zkngc/bWdeZ4yI+s= X-Google-Smtp-Source: ABdhPJzxRu199kMbVIzEiJ360DRqtnf/JkyfNpyIo36EXSYSvYFGD5J8K7BVy4Delx8+RFiu2dT6bw== X-Received: by 2002:a05:600c:35c3:: with SMTP id r3mr3214766wmq.169.1623145226550; Tue, 08 Jun 2021 02:40:26 -0700 (PDT) Received: from avogadro.lan ([93.56.169.140]) by smtp.gmail.com with ESMTPSA id d15sm8608764wri.58.2021.06.08.02.40.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 02:40:26 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 07/12] machine: move common smp_parse code to caller Date: Tue, 8 Jun 2021 11:40:12 +0200 Message-Id: <20210608094017.392673-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210608094017.392673-1-pbonzini@redhat.com> References: <20210608094017.392673-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x336.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.248, 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Most of smp_parse and pc_smp_parse is guarded by an "if (opts)" conditional, and the rest is common to both function. Move the conditional and the common code to the caller, machine_smp_parse. Move the replay_add_blocker call after all errors are checked for. Signed-off-by: Paolo Bonzini --- hw/core/machine.c | 112 ++++++++++++++++++++++---------------------- hw/i386/pc.c | 116 +++++++++++++++++++++------------------------- 2 files changed, 110 insertions(+), 118 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index d776c8cf20..1016ec9e1c 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -741,67 +741,59 @@ void machine_set_cpu_numa_node(MachineState *machine, static void smp_parse(MachineState *ms, QemuOpts *opts) { - if (opts) { - unsigned cpus = qemu_opt_get_number(opts, "cpus", 0); - unsigned sockets = qemu_opt_get_number(opts, "sockets", 0); - unsigned cores = qemu_opt_get_number(opts, "cores", 0); - unsigned threads = qemu_opt_get_number(opts, "threads", 0); - - /* compute missing values, prefer sockets over cores over threads */ - if (cpus == 0 || sockets == 0) { - cores = cores > 0 ? cores : 1; - threads = threads > 0 ? threads : 1; - if (cpus == 0) { - sockets = sockets > 0 ? sockets : 1; - cpus = cores * threads * sockets; - } else { - ms->smp.max_cpus = - qemu_opt_get_number(opts, "maxcpus", cpus); - sockets = ms->smp.max_cpus / (cores * threads); - } - } else if (cores == 0) { - threads = threads > 0 ? threads : 1; - cores = cpus / (sockets * threads); - cores = cores > 0 ? cores : 1; - } else if (threads == 0) { - threads = cpus / (cores * sockets); - threads = threads > 0 ? threads : 1; - } else if (sockets * cores * threads < cpus) { - error_report("cpu topology: " - "sockets (%u) * cores (%u) * threads (%u) < " - "smp_cpus (%u)", - sockets, cores, threads, cpus); - exit(1); - } - - ms->smp.max_cpus = - qemu_opt_get_number(opts, "maxcpus", cpus); - - if (ms->smp.max_cpus < cpus) { - error_report("maxcpus must be equal to or greater than smp"); - exit(1); + unsigned cpus = qemu_opt_get_number(opts, "cpus", 0); + unsigned sockets = qemu_opt_get_number(opts, "sockets", 0); + unsigned cores = qemu_opt_get_number(opts, "cores", 0); + unsigned threads = qemu_opt_get_number(opts, "threads", 0); + + /* compute missing values, prefer sockets over cores over threads */ + if (cpus == 0 || sockets == 0) { + cores = cores > 0 ? cores : 1; + threads = threads > 0 ? threads : 1; + if (cpus == 0) { + sockets = sockets > 0 ? sockets : 1; + cpus = cores * threads * sockets; + } else { + ms->smp.max_cpus = + qemu_opt_get_number(opts, "maxcpus", cpus); + sockets = ms->smp.max_cpus / (cores * threads); } + } else if (cores == 0) { + threads = threads > 0 ? threads : 1; + cores = cpus / (sockets * threads); + cores = cores > 0 ? cores : 1; + } else if (threads == 0) { + threads = cpus / (cores * sockets); + threads = 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); + } - if (sockets * cores * threads != ms->smp.max_cpus) { - error_report("Invalid CPU topology: " - "sockets (%u) * cores (%u) * threads (%u) " - "!= maxcpus (%u)", - sockets, cores, threads, - ms->smp.max_cpus); - exit(1); - } + ms->smp.max_cpus = + qemu_opt_get_number(opts, "maxcpus", cpus); - ms->smp.cpus = cpus; - ms->smp.cores = cores; - ms->smp.threads = threads; - ms->smp.sockets = sockets; + if (ms->smp.max_cpus < cpus) { + error_report("maxcpus must be equal to or greater than smp"); + exit(1); } - if (ms->smp.cpus > 1) { - Error *blocker = NULL; - error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, "smp"); - replay_add_blocker(blocker); + if (sockets * cores * threads != ms->smp.max_cpus) { + error_report("Invalid CPU topology: " + "sockets (%u) * cores (%u) * threads (%u) " + "!= maxcpus (%u)", + sockets, cores, threads, + ms->smp.max_cpus); + exit(1); } + + ms->smp.cpus = cpus; + ms->smp.cores = cores; + ms->smp.threads = threads; + ms->smp.sockets = sockets; } static void machine_class_init(ObjectClass *oc, void *data) @@ -1135,7 +1127,9 @@ bool machine_smp_parse(MachineState *ms, QemuOpts *opts, Error **errp) { MachineClass *mc = MACHINE_GET_CLASS(ms); - mc->smp_parse(ms, opts); + if (opts) { + mc->smp_parse(ms, opts); + } /* 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 *opts, Error **errp) mc->name, mc->max_cpus); return false; } + + if (ms->smp.cpus > 1) { + Error *blocker = NULL; + error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, "smp"); + replay_add_blocker(blocker); + } return true; } 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 = qemu_opt_get_number(opts, "cpus", 0); - unsigned sockets = qemu_opt_get_number(opts, "sockets", 0); - unsigned dies = qemu_opt_get_number(opts, "dies", 1); - unsigned cores = qemu_opt_get_number(opts, "cores", 0); - unsigned threads = qemu_opt_get_number(opts, "threads", 0); - - /* compute missing values, prefer sockets over cores over threads */ - if (cpus == 0 || sockets == 0) { - cores = cores > 0 ? cores : 1; - threads = threads > 0 ? threads : 1; - if (cpus == 0) { - sockets = sockets > 0 ? sockets : 1; - cpus = cores * threads * dies * sockets; - } else { - ms->smp.max_cpus = - qemu_opt_get_number(opts, "maxcpus", cpus); - sockets = ms->smp.max_cpus / (cores * threads * dies); - } - } else if (cores == 0) { - threads = threads > 0 ? threads : 1; - cores = cpus / (sockets * dies * threads); - cores = cores > 0 ? cores : 1; - } else if (threads == 0) { - threads = cpus / (cores * dies * sockets); - threads = threads > 0 ? threads : 1; - } else if (sockets * dies * cores * threads < cpus) { - error_report("cpu topology: " - "sockets (%u) * dies (%u) * cores (%u) * threads (%u) < " - "smp_cpus (%u)", - sockets, dies, cores, threads, cpus); - exit(1); - } - - ms->smp.max_cpus = - 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 != ms->smp.max_cpus) { - error_report("Invalid CPU topology deprecated: " - "sockets (%u) * dies (%u) * cores (%u) * threads (%u) " - "!= maxcpus (%u)", - sockets, dies, cores, threads, - ms->smp.max_cpus); - exit(1); + unsigned cpus = qemu_opt_get_number(opts, "cpus", 0); + unsigned sockets = qemu_opt_get_number(opts, "sockets", 0); + unsigned dies = qemu_opt_get_number(opts, "dies", 1); + unsigned cores = qemu_opt_get_number(opts, "cores", 0); + unsigned threads = qemu_opt_get_number(opts, "threads", 0); + + /* compute missing values, prefer sockets over cores over threads */ + if (cpus == 0 || sockets == 0) { + cores = cores > 0 ? cores : 1; + threads = threads > 0 ? threads : 1; + if (cpus == 0) { + sockets = sockets > 0 ? sockets : 1; + cpus = cores * threads * dies * sockets; + } else { + ms->smp.max_cpus = + qemu_opt_get_number(opts, "maxcpus", cpus); + sockets = ms->smp.max_cpus / (cores * threads * dies); } - - ms->smp.cpus = cpus; - ms->smp.cores = cores; - ms->smp.threads = threads; - ms->smp.sockets = sockets; - ms->smp.dies = dies; - } - - if (ms->smp.cpus > 1) { - Error *blocker = NULL; - error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, "smp"); - replay_add_blocker(blocker); - } + } else if (cores == 0) { + threads = threads > 0 ? threads : 1; + cores = cpus / (sockets * dies * threads); + cores = cores > 0 ? cores : 1; + } else if (threads == 0) { + threads = cpus / (cores * dies * sockets); + threads = threads > 0 ? threads : 1; + } else if (sockets * dies * cores * threads < cpus) { + error_report("cpu topology: " + "sockets (%u) * dies (%u) * cores (%u) * threads (%u) < " + "smp_cpus (%u)", + sockets, dies, cores, threads, cpus); + exit(1); + } + + ms->smp.max_cpus = + 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 != ms->smp.max_cpus) { + error_report("Invalid CPU topology deprecated: " + "sockets (%u) * dies (%u) * cores (%u) * threads (%u) " + "!= maxcpus (%u)", + sockets, dies, cores, threads, + ms->smp.max_cpus); + exit(1); + } + + ms->smp.cpus = cpus; + ms->smp.cores = cores; + ms->smp.threads = threads; + ms->smp.sockets = sockets; + ms->smp.dies = dies; } static From patchwork Tue Jun 8 09:40:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12306195 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA567C4743D for ; Tue, 8 Jun 2021 09:50:15 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 63EFA61008 for ; Tue, 8 Jun 2021 09:50:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 63EFA61008 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:33246 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqYNC-0006do-HZ for qemu-devel@archiver.kernel.org; Tue, 08 Jun 2021 05:50:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51656) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqYDn-0004ch-TD for qemu-devel@nongnu.org; Tue, 08 Jun 2021 05:40:31 -0400 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]:34407) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lqYDk-0001sb-Kf for qemu-devel@nongnu.org; Tue, 08 Jun 2021 05:40:31 -0400 Received: by mail-wr1-x436.google.com with SMTP id q5so20843621wrm.1 for ; Tue, 08 Jun 2021 02:40:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oaLUCvek2OmNr6/JtAkUEqBmw58D1m2VU8lWk8Kuo/k=; b=ncrmjzGRu4FHsrsplib58RJGImVXhPO1gwSGsgZg/tCuf/VwasI67O917pAwX3Pa5l hbGaDNbMuMTAV6vjct/C2dB3BQu2qSbGw+Yu1Ua3tPxvOn9ZQ5uUJsHHn48pG75xnu74 rC6JsdMBxilN8wC7SdRHUZXhn6I7Y2Jgv5QxsSUwAuPIWX+4As/jjavxnII+p4vsv2Z3 l1ZWK0bRqgBhTbIFu82CCTH76pUbjjGA9W3x5oNIIsE8NfLZIkXS1kDJvFhVoN00ajDy xvEFejq3QOg4ay8CyJ7yE8Qjeyr8oneAof8UtKFyOW4gxIdWNA2sAMRfWO7DUc/wKTJK d7GQ== 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:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=oaLUCvek2OmNr6/JtAkUEqBmw58D1m2VU8lWk8Kuo/k=; b=lEPCXqnjvlPnuSOHscqD4sJToVVwJkcaz4maK8uO2zQOUkCmQFUgbt+8Sq3CSWPtgw ou9nDWLgj+IX02IxLhLV8OfyXx9YUdqdNAi1pFMT8Mc26IONo+Q/ivJi64FqaD4L7ICK u8qgp/cC6XIQPRsA6q8EG2+757FY9yyM4+5rtqH+AlN2bqLhJ5GcellSkDDA6//odNDp 6SvIBOnD7APxNlzI2ZIoxraA7XZwU6tcySHaQmoR32WwIvPQGEhnzdw/NviTchllq98a SQD3t+IeAN5TNwm0yujYjaYFeeE3I33k3yeNuVO+VZCl043WYEswl1YdtPp/n29bctuM TSYA== X-Gm-Message-State: AOAM533qjaJs/3Ya3KprBbOywJRTIjujS7vvOIX8kj0X8mj3PbC5Yj6Q yM/5l5iLIVlDKCOICSKClZu4RvVeFow= X-Google-Smtp-Source: ABdhPJyvnXRZ/WTCtCxHdV36OPIIyThXK+WvAPAsWq0WlezDa2FeBENnSp0wIsG5Z4f41a2HEEiduw== X-Received: by 2002:a5d:6485:: with SMTP id o5mr21220262wri.91.1623145227281; Tue, 08 Jun 2021 02:40:27 -0700 (PDT) Received: from avogadro.lan ([93.56.169.140]) by smtp.gmail.com with ESMTPSA id d15sm8608764wri.58.2021.06.08.02.40.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 02:40:26 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 08/12] machine: add error propagation to mc->smp_parse Date: Tue, 8 Jun 2021 11:40:13 +0200 Message-Id: <20210608094017.392673-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210608094017.392673-1-pbonzini@redhat.com> References: <20210608094017.392673-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x436.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.248, 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Clean up the smp_parse functions to use Error** instead of exiting. Signed-off-by: Paolo Bonzini --- hw/core/machine.c | 34 +++++++++++++++++++--------------- hw/i386/pc.c | 28 ++++++++++++++-------------- include/hw/boards.h | 2 +- include/hw/i386/pc.h | 2 -- 4 files changed, 34 insertions(+), 32 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 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, } } -static void smp_parse(MachineState *ms, QemuOpts *opts) +static void smp_parse(MachineState *ms, QemuOpts *opts, Error **errp) { unsigned cpus = qemu_opt_get_number(opts, "cpus", 0); unsigned sockets = qemu_opt_get_number(opts, "sockets", 0); @@ -766,28 +766,28 @@ static void smp_parse(MachineState *ms, QemuOpts *opts) threads = cpus / (cores * sockets); threads = 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; } ms->smp.max_cpus = 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); + error_setg(errp, "maxcpus must be equal to or greater than smp"); + return; } if (sockets * cores * threads != ms->smp.max_cpus) { - error_report("Invalid CPU topology: " - "sockets (%u) * cores (%u) * threads (%u) " - "!= maxcpus (%u)", - sockets, cores, threads, - ms->smp.max_cpus); - exit(1); + error_setg(errp, "Invalid CPU topology: " + "sockets (%u) * cores (%u) * threads (%u) " + "!= maxcpus (%u)", + sockets, cores, threads, + ms->smp.max_cpus); + return; } ms->smp.cpus = cpus; @@ -1126,9 +1126,13 @@ MemoryRegion *machine_consume_memdev(MachineState *machine, bool machine_smp_parse(MachineState *ms, QemuOpts *opts, Error **errp) { MachineClass *mc = MACHINE_GET_CLASS(ms); + ERRP_GUARD(); if (opts) { - mc->smp_parse(ms, opts); + mc->smp_parse(ms, opts, errp); + if (*errp) { + return false; + } } /* 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 level) * 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 = qemu_opt_get_number(opts, "cpus", 0); unsigned sockets = qemu_opt_get_number(opts, "sockets", 0); @@ -738,28 +738,28 @@ void pc_smp_parse(MachineState *ms, QemuOpts *opts) threads = cpus / (cores * dies * sockets); threads = 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; } ms->smp.max_cpus = 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); + error_setg(errp, "maxcpus must be equal to or greater than smp"); + return; } if (sockets * dies * cores * threads != ms->smp.max_cpus) { - error_report("Invalid CPU topology deprecated: " - "sockets (%u) * dies (%u) * cores (%u) * threads (%u) " - "!= 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) " + "!= maxcpus (%u)", + sockets, dies, cores, threads, + ms->smp.max_cpus); + return; } ms->smp.cpus = 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); 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; void pc_acpi_smi_interrupt(void *opaque, int irq, int level); -void pc_smp_parse(MachineState *ms, QemuOpts *opts); - void pc_guest_info_init(PCMachineState *pcms); #define PCI_HOST_PROP_PCI_HOLE_START "pci-hole-start" From patchwork Tue Jun 8 09:40:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12306207 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45F89C4743F for ; Tue, 8 Jun 2021 09:55:01 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BE3DD61008 for ; Tue, 8 Jun 2021 09:55:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BE3DD61008 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:49220 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqYRo-0000TE-16 for qemu-devel@archiver.kernel.org; Tue, 08 Jun 2021 05:55:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51666) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqYDo-0004eL-Gg for qemu-devel@nongnu.org; Tue, 08 Jun 2021 05:40:32 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]:39463) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lqYDm-0001tq-7Q for qemu-devel@nongnu.org; Tue, 08 Jun 2021 05:40:32 -0400 Received: by mail-wm1-x32b.google.com with SMTP id l18-20020a1ced120000b029014c1adff1edso1455928wmh.4 for ; Tue, 08 Jun 2021 02:40:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AEctVWm7LnklR94IVota7cJxBYDiTHrGLM7X/qOIhdI=; b=gWgEll28uykvnr0WORZQXz0wMYDTLQ69OOuVn157DoZnSsED9SKOW70U9F3+WHu38S aRhbWDMmjDEh4utqctqQt74pg82xWbiXM/Yu3AVQ80gADdVPrJo8pXlbXJYDWfeGNvx8 WcMDsJqLNc0FDVbRD95pl6n8DM1udXIfbPFRqHGVNpsLgGCC4O56ddMDzRrE4nk0h3GM VnX9VDwhy0E/xQ45JIBjrcIDsSuGrlmMnV9VeHXH8mrsK/Kgvv8/WxE9N9KKove7jLZ7 6CK9d1hWYa7QRnLL1f+FIcK/yoHUu3aQYspF7uIVmMIP5OFhwiBLuHXcb7mGdTgZQoxT crmA== 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:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=AEctVWm7LnklR94IVota7cJxBYDiTHrGLM7X/qOIhdI=; b=BvTAKM96+K1h5FB/74TYVmBnpn3Ey0LfGQcCvlbvPkZ3ggc6OSnE0Sg26fj73yB2Cv UGE8DOIVxaanyee+fTAxm+sKM64+eudelyaPhCVNkrJbinZPiKzdGetCimEz1F1j1fWf 88nxuab3bdYOO0O37FmPAMskg/zmqiCrCgSyY0GZmJLKLc9KBQ6rN+0/EY2SP+ymhyy2 D9EqcjUQhKOWEKjLxjJzOK8aw5TDAJYaSpx9JdE20/4eckcl98lQGvh0mcXMm0u8Qg7y 1o7hZyLqylflPOAxNn5U5JmLJ/T6x6NAL1THVng3buJsEE/RuGhLSRyJiGvMOILpMLYm 1tIA== X-Gm-Message-State: AOAM530YoROlePopplvWtQHj0JsVtHmbjcdzPioz/M1NOAzYrH2pYRPd 24PyMFOmsX9OA046uXa3GeF1LgSNkVM= X-Google-Smtp-Source: ABdhPJzSAbtUI2WmPcePg1t3Za0LbaRF7o34PXcCsGzwAlMx5FUYVxtTT+wgApnM42b6us7DBiom2A== X-Received: by 2002:a05:600c:35c1:: with SMTP id r1mr3179229wmq.181.1623145228155; Tue, 08 Jun 2021 02:40:28 -0700 (PDT) Received: from avogadro.lan ([93.56.169.140]) by smtp.gmail.com with ESMTPSA id d15sm8608764wri.58.2021.06.08.02.40.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 02:40:27 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 09/12] machine: pass QAPI struct to mc->smp_parse Date: Tue, 8 Jun 2021 11:40:14 +0200 Message-Id: <20210608094017.392673-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210608094017.392673-1-pbonzini@redhat.com> References: <20210608094017.392673-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x32b.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.248, 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" As part of converting -smp to a property with a QAPI type, define the struct and use it to do the actual parsing. machine_smp_parse takes care of doing the QemuOpts->QAPI conversion by hand, for now. Signed-off-by: Paolo Bonzini --- hw/core/machine.c | 33 +++++++++++++++++++++++---------- hw/i386/pc.c | 18 ++++++++---------- include/hw/boards.h | 2 +- qapi/machine.json | 27 +++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 21 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 5a9c97ccc5..9ad8341a31 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -739,12 +739,12 @@ void machine_set_cpu_numa_node(MachineState *machine, } } -static void smp_parse(MachineState *ms, QemuOpts *opts, Error **errp) +static void smp_parse(MachineState *ms, SMPConfiguration *config, Error **errp) { - unsigned cpus = qemu_opt_get_number(opts, "cpus", 0); - unsigned sockets = qemu_opt_get_number(opts, "sockets", 0); - unsigned cores = qemu_opt_get_number(opts, "cores", 0); - unsigned threads = qemu_opt_get_number(opts, "threads", 0); + unsigned cpus = config->has_cpus ? config->cpus : 0; + unsigned sockets = config->has_sockets ? config->sockets : 0; + unsigned cores = config->has_cores ? config->cores : 0; + unsigned threads = config->has_threads ? config->threads : 0; /* compute missing values, prefer sockets over cores over threads */ if (cpus == 0 || sockets == 0) { @@ -754,8 +754,7 @@ static void smp_parse(MachineState *ms, QemuOpts *opts, Error **errp) sockets = sockets > 0 ? sockets : 1; cpus = cores * threads * sockets; } else { - ms->smp.max_cpus = - qemu_opt_get_number(opts, "maxcpus", cpus); + ms->smp.max_cpus = config->has_maxcpus ? config->maxcpus : cpus; sockets = ms->smp.max_cpus / (cores * threads); } } else if (cores == 0) { @@ -773,8 +772,7 @@ static void smp_parse(MachineState *ms, QemuOpts *opts, Error **errp) return; } - ms->smp.max_cpus = - qemu_opt_get_number(opts, "maxcpus", cpus); + ms->smp.max_cpus = config->has_maxcpus ? config->maxcpus : cpus; 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 *opts, Error **errp) ERRP_GUARD(); if (opts) { - mc->smp_parse(ms, opts, errp); + SMPConfiguration config = { + .has_cpus = !!qemu_opt_get(opts, "cpus"), + .cpus = qemu_opt_get_number(opts, "cpus", 0), + .has_sockets = !!qemu_opt_get(opts, "sockets"), + .sockets = qemu_opt_get_number(opts, "sockets", 0), + .has_dies = !!qemu_opt_get(opts, "dies"), + .dies = qemu_opt_get_number(opts, "dies", 0), + .has_cores = !!qemu_opt_get(opts, "cores"), + .cores = qemu_opt_get_number(opts, "cores", 0), + .has_threads = !!qemu_opt_get(opts, "threads"), + .threads = qemu_opt_get_number(opts, "threads", 0), + .has_maxcpus = !!qemu_opt_get(opts, "maxcpus"), + .maxcpus = 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 = qemu_opt_get_number(opts, "cpus", 0); - unsigned sockets = qemu_opt_get_number(opts, "sockets", 0); - unsigned dies = qemu_opt_get_number(opts, "dies", 1); - unsigned cores = qemu_opt_get_number(opts, "cores", 0); - unsigned threads = qemu_opt_get_number(opts, "threads", 0); + unsigned cpus = config->has_cpus ? config->cpus : 0; + unsigned sockets = config->has_sockets ? config->sockets : 0; + unsigned dies = config->has_dies ? config->dies : 1; + unsigned cores = config->has_cores ? config->cores : 0; + unsigned threads = config->has_threads ? config->threads : 0; /* compute missing values, prefer sockets over cores over threads */ if (cpus == 0 || sockets == 0) { @@ -726,8 +726,7 @@ static void pc_smp_parse(MachineState *ms, QemuOpts *opts, Error **errp) sockets = sockets > 0 ? sockets : 1; cpus = cores * threads * dies * sockets; } else { - ms->smp.max_cpus = - qemu_opt_get_number(opts, "maxcpus", cpus); + ms->smp.max_cpus = config->has_maxcpus ? config->maxcpus : cpus; sockets = ms->smp.max_cpus / (cores * threads * dies); } } else if (cores == 0) { @@ -745,8 +744,7 @@ static void pc_smp_parse(MachineState *ms, QemuOpts *opts, Error **errp) return; } - ms->smp.max_cpus = - qemu_opt_get_number(opts, "maxcpus", cpus); + ms->smp.max_cpus = config->has_maxcpus ? config->maxcpus : cpus; 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); BlockInterfaceType block_default_type; int units_per_default_bus; diff --git a/qapi/machine.json b/qapi/machine.json index 58a9c86b36..53fd7e60ff 100644 --- a/qapi/machine.json +++ b/qapi/machine.json @@ -1274,3 +1274,30 @@ ## { 'event': 'MEM_UNPLUG_ERROR', 'data': { 'device': 'str', 'msg': 'str' } } + +## +# @SMPConfiguration: +# +# Schema for CPU topology configuration. +# +# @cpus: number of virtual CPUs in the virtual machine +# +# @sockets: number of sockets in the CPU topology +# +# @dies: number of dies per socket in the CPU topology +# +# @cores: number of cores per thread in the CPU topology +# +# @threads: number of threads per core in the CPU topology +# +# @maxcpus: maximum number of hotpluggable virtual CPUs in the virtual machine +# +# Since: 6.1 +## +{ 'struct': 'SMPConfiguration', 'data': { + '*cpus': 'int', + '*sockets': 'int', + '*dies': 'int', + '*cores': 'int', + '*threads': 'int', + '*maxcpus': 'int' } } From patchwork Tue Jun 8 09:40:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12306199 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA3C1C4743D for ; Tue, 8 Jun 2021 09:51:41 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 857E661287 for ; Tue, 8 Jun 2021 09:51:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 857E661287 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:37794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqYOa-0001EC-Ha for qemu-devel@archiver.kernel.org; Tue, 08 Jun 2021 05:51:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51662) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqYDo-0004e4-DN for qemu-devel@nongnu.org; Tue, 08 Jun 2021 05:40:32 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]:43940) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lqYDm-0001uM-Av for qemu-devel@nongnu.org; Tue, 08 Jun 2021 05:40:32 -0400 Received: by mail-wr1-x432.google.com with SMTP id r9so4118318wrz.10 for ; Tue, 08 Jun 2021 02:40:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qzpXFnyjgRnwQsHIuTfmXtl8Hzry0AV1o6f9R8rYdXg=; b=Ez1zo9Ww/47Muge28SLE1xIluNeq5CprwHSYB8B3ev07THNS7H1qSnhCO4KnYobzri /BzzN7gYgl1avvORo6v9jxhuYvwy4wMIxPOzWVdHU6jJoKNWD9YftG5E3HidzyusTgbu R3GjUyo7gNB0zNaxWyqgXA7ga9JjxPuUTff/Eu1Yv8vB64OljXGmVDYXUDi95shrpnKT z2AJ7/8Gb68hoBmWYoZ51lYupEfEJfJJ55mZC0CzuIARRuGc/TzCnxAvcHHeZ/sAB68e I4Dj12Unxm/P2SR8lSGGUPMM/jbqj2mHV9tG4TG7GikyypSVypCbxgeY3NYdDe9LOLYJ RBmg== 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:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=qzpXFnyjgRnwQsHIuTfmXtl8Hzry0AV1o6f9R8rYdXg=; b=dxJ+kjZ7VQbWX0nQYrS4t4lG5ZKMthwoypOQvgvNmMBY2LE0bLm4P92vOlKjZBPutz At19ZTFdg58QQDyCvmnttyRyRmXMjS3+Tx87AeOzmlvDh15YqNQUPd7n1S4MOzLU2rSs pEKcChDlwRltrRjltOHS8YMAL5qCJcoearrF258z977MaDo1R2ik5iz2PIV95LfmV96A mVljbAXY4GImF6ce6kT1CfI0p/v2OWBFM6wQwsieLsZ+h92DjYSabFRZIqAha1I/mF1b h8lDrk6+NTfBLLepFYPi4L1QeXIvrWM6EHJf7kLTZYMKgYmE0DuRTlfjrL0Lqvx7KnP0 hhWw== X-Gm-Message-State: AOAM533yrGbyiiK0dmYx7yFYwniD4AUYzB48EiuaIMMgNZroiDXGigTr LOH4rugWlBUhEDalYE9b7pNvJmWPXtU= X-Google-Smtp-Source: ABdhPJwSQEvOUA0zQH25P1DzxHkt7OPNUevyv6q1MytJ9RaCX8px3WZ/nS3j0rLU3Kj1JsqQdV9RRQ== X-Received: by 2002:a05:6000:2cc:: with SMTP id o12mr4847886wry.279.1623145229026; Tue, 08 Jun 2021 02:40:29 -0700 (PDT) Received: from avogadro.lan ([93.56.169.140]) by smtp.gmail.com with ESMTPSA id d15sm8608764wri.58.2021.06.08.02.40.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 02:40:28 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 10/12] machine: reject -smp dies!=1 for non-PC machines Date: Tue, 8 Jun 2021 11:40:15 +0200 Message-Id: <20210608094017.392673-11-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210608094017.392673-1-pbonzini@redhat.com> References: <20210608094017.392673-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x432.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.248, 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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, SMPConfiguration *config, Error **errp) unsigned cores = config->has_cores ? config->cores : 0; unsigned threads = config->has_threads ? config->threads : 0; + if (config->has_dies && config->dies != 0 && config->dies != 1) { + error_setg(errp, "dies not supported by this machine's CPU topology"); + } + /* compute missing values, prefer sockets over cores over threads */ if (cpus == 0 || sockets == 0) { cores = cores > 0 ? cores : 1; From patchwork Tue Jun 8 09:40:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12306201 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6B66C47082 for ; Tue, 8 Jun 2021 09:52:20 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 35AF661185 for ; Tue, 8 Jun 2021 09:52:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 35AF661185 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:40362 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqYPD-00031h-9r for qemu-devel@archiver.kernel.org; Tue, 08 Jun 2021 05:52:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51688) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqYDp-0004gz-Ff for qemu-devel@nongnu.org; Tue, 08 Jun 2021 05:40:36 -0400 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]:44848) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lqYDn-0001ux-BT for qemu-devel@nongnu.org; Tue, 08 Jun 2021 05:40:33 -0400 Received: by mail-wr1-x42d.google.com with SMTP id f2so20780535wri.11 for ; Tue, 08 Jun 2021 02:40:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FCNtjuTxOkAzbUiMDrfyPIHmmLgaE5uOlsEoXeEtEHY=; b=Ygfv10f3lWqzuOqDQD+ap3oahoxO+GzlLxDpGpjaRNFaOL4pygn6i2C15QKy3dCOyg Yz+Ma7xIj2lohbigiCLZSbUizwZzJnDwCszb4MHcVu0XO7T1TFbmQV94cqhV2UDpFdi5 39T6viyjPLhVycAoh6sm1IQHUs6lNWkCCT7/QxcWMTR4fUprrIdMtSOwtPjP4VBE3/GP oH1ThEfyWGlqyDYbh73oQvpelRmRrTyqSMNhzRhu7hex4MTUuFhdArKrk57dwa6fQ9M+ Mfw4oYqgD10nubuVL3DtU5lG48GrTrc6dSfnI5NrigeP4fOqOd1ic8TRXXSmEW4D/kP4 gO5g== 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:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=FCNtjuTxOkAzbUiMDrfyPIHmmLgaE5uOlsEoXeEtEHY=; b=Hw8EwfLTnrv08B/kQnGwVwyfC5gykPVLwd3Lbhc1U4dWiKSyqDqu3vTPYx8UHvKsSC pKEMt6tbyeYSzhHA8HFiH19Jn4ZIj5Ay3Vq0M0Iao8Eb9nEMMGlxci91oRNk6qML+1+3 ntxzlUUFlDyZk0jFccO37YOlmbURb3A0RrHOzDJgCmUrANLMR7/X44qERfV/K4HfSiFC tOfVl6m9lgNQqXHprC+vftkPjNIm5Jefjl52X29GDcW7imj4CzM9d0Og6PK0KCsLJjZH y150p/be03thUQc43KXkkuKtTw5aj50dEq+zFtKsdcK0jr5UGv4ZZntfensLrwnbSWMP MH6Q== X-Gm-Message-State: AOAM531elTDBSmxlLAYviaC1KzgSrweqBnoxypdH2ixK2yc2Ihm1KllF 7FOdWJ/CDgpIQCcyjGv76P7eLl7N5Gk= X-Google-Smtp-Source: ABdhPJwHG1miwrWb0rLZa8IU1lhQK3G8dWeYbEj5AtwsDVh6Qgf535FaSqm6I+Prs7LGt0KQKY23kQ== X-Received: by 2002:adf:bd88:: with SMTP id l8mr6331397wrh.90.1623145229999; Tue, 08 Jun 2021 02:40:29 -0700 (PDT) Received: from avogadro.lan ([93.56.169.140]) by smtp.gmail.com with ESMTPSA id d15sm8608764wri.58.2021.06.08.02.40.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 02:40:29 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 11/12] machine: add smp compound property Date: Tue, 8 Jun 2021 11:40:16 +0200 Message-Id: <20210608094017.392673-12-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210608094017.392673-1-pbonzini@redhat.com> References: <20210608094017.392673-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42d; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x42d.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.248, 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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, SMPConfiguration *config, Error **errp) ms->smp.sockets = sockets; } +static void machine_get_smp(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + MachineState *ms = MACHINE(obj); + SMPConfiguration *config = &(SMPConfiguration){ + .has_cores = true, .cores = ms->smp.cores, + .has_sockets = true, .sockets = ms->smp.sockets, + .has_dies = true, .dies = ms->smp.dies, + .has_threads = true, .threads = ms->smp.threads, + .has_cpus = true, .cpus = ms->smp.cpus, + .has_maxcpus = true, .maxcpus = 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 = MACHINE_GET_CLASS(obj); + MachineState *ms = 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 = 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"); + 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 *machine, return ret; } -bool machine_smp_parse(MachineState *ms, QemuOpts *opts, Error **errp) -{ - MachineClass *mc = MACHINE_GET_CLASS(ms); - ERRP_GUARD(); - - if (opts) { - SMPConfiguration config = { - .has_cpus = !!qemu_opt_get(opts, "cpus"), - .cpus = qemu_opt_get_number(opts, "cpus", 0), - .has_sockets = !!qemu_opt_get(opts, "sockets"), - .sockets = qemu_opt_get_number(opts, "sockets", 0), - .has_dies = !!qemu_opt_get(opts, "dies"), - .dies = qemu_opt_get_number(opts, "dies", 0), - .has_cores = !!qemu_opt_get(opts, "cores"), - .cores = qemu_opt_get_number(opts, "cores", 0), - .has_threads = !!qemu_opt_get(opts, "threads"), - .threads = qemu_opt_get_number(opts, "threads", 0), - .has_maxcpus = !!qemu_opt_get(opts, "maxcpus"), - .maxcpus = 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 = 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 = 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; 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 c3686a6722..df91371b90 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -1523,6 +1523,25 @@ static void machine_help_func(const QDict *qdict) } } +static void +machine_parse_property_opt(QemuOptsList *opts_list, const char *propname, + const char *arg, Error **errp) +{ + QDict *opts, *prop; + bool help = false; + ERRP_GUARD(); + + prop = keyval_parse(arg, opts_list->implied_opt_name, &help, errp); + if (help) { + qemu_opts_print_help(opts_list, true); + return; + } + opts = 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; @@ -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 = NULL; + error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, "smp"); + replay_add_blocker(blocker); + } } 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); } - 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 already * 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"), "smp", 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 = NULL; g_autofree char *cli = NULL; - cli = make_cli(data, "-smp 8 -numa node,nodeid=0,memdev=ram,cpus=0-3 " + cli = make_cli(data, "-machine smp.cpus=8 -numa node,nodeid=0,memdev=ram,cpus=0-3 " "-numa node,nodeid=1,cpus=4-7"); qts = qtest_init(cli); @@ -42,7 +42,7 @@ static void test_def_cpu_split(const void *data) g_autofree char *s = NULL; g_autofree char *cli = NULL; - cli = make_cli(data, "-smp 8 -numa node,memdev=ram -numa node"); + cli = make_cli(data, "-machine smp.cpus=8 -numa node,memdev=ram -numa node"); qts = qtest_init(cli); s = qtest_hmp(qts, "info numa"); @@ -58,7 +58,7 @@ static void test_mon_partial(const void *data) g_autofree char *s = NULL; g_autofree char *cli = NULL; - cli = make_cli(data, "-smp 8 " + cli = make_cli(data, "-machine smp.cpus=8 " "-numa node,nodeid=0,memdev=ram,cpus=0-1 " "-numa node,nodeid=1,cpus=4-5 "); qts = qtest_init(cli); @@ -86,7 +86,7 @@ static void test_query_cpus(const void *data) QTestState *qts; g_autofree char *cli = NULL; - cli = make_cli(data, "-smp 8 -numa node,memdev=ram,cpus=0-3 " + cli = make_cli(data, "-machine smp.cpus=8 -numa node,memdev=ram,cpus=0-3 " "-numa node,cpus=4-7"); qts = qtest_init(cli); cpus = get_cpus(qts, &resp); @@ -124,7 +124,7 @@ static void pc_numa_cpu(const void *data) QTestState *qts; g_autofree char *cli = NULL; - cli = make_cli(data, "-cpu pentium -smp 8,sockets=2,cores=2,threads=2 " + cli = make_cli(data, "-cpu pentium -machine smp.cpus=8,smp.sockets=2,smp.cores=2,smp.threads=2 " "-numa node,nodeid=0,memdev=ram -numa node,nodeid=1 " "-numa cpu,node-id=1,socket-id=0 " "-numa cpu,node-id=0,socket-id=1,core-id=0 " @@ -177,7 +177,7 @@ static void spapr_numa_cpu(const void *data) QTestState *qts; g_autofree char *cli = NULL; - cli = make_cli(data, "-smp 4,cores=4 " + cli = make_cli(data, "-machine smp.cpus=4,smp.cores=4 " "-numa node,nodeid=0,memdev=ram -numa node,nodeid=1 " "-numa cpu,node-id=0,core-id=0 " "-numa cpu,node-id=0,core-id=1 " @@ -222,7 +222,7 @@ static void aarch64_numa_cpu(const void *data) QTestState *qts; g_autofree char *cli = NULL; - cli = make_cli(data, "-smp 2 " + cli = make_cli(data, "-machine smp.cpus=2 " "-numa node,nodeid=0,memdev=ram -numa node,nodeid=1 " "-numa cpu,node-id=1,thread-id=0 " "-numa cpu,node-id=0,thread-id=1"); @@ -265,7 +265,7 @@ static void pc_dynamic_cpu_cfg(const void *data) QTestState *qs; g_autofree char *cli = NULL; - cli = make_cli(data, "-nodefaults --preconfig -smp 2"); + cli = make_cli(data, "-nodefaults --preconfig -machine smp.cpus=2"); qs = qtest_init(cli); /* create 2 numa nodes */ @@ -324,7 +324,7 @@ static void pc_hmat_build_cfg(const void *data) g_autofree char *cli = NULL; cli = make_cli(data, "-nodefaults --preconfig -machine hmat=on " - "-smp 2,sockets=2 " + "-machine smp.cpus=2,smp.sockets=2 " "-m 128M,slots=2,maxmem=1G " "-object memory-backend-ram,size=64M,id=m0 " "-object memory-backend-ram,size=64M,id=m1 " @@ -453,7 +453,7 @@ static void pc_hmat_off_cfg(const void *data) g_autofree char *cli = NULL; cli = make_cli(data, "-nodefaults --preconfig " - "-smp 2,sockets=2 " + "-machine smp.cpus=2,smp.sockets=2 " "-m 128M,slots=2,maxmem=1G " "-object memory-backend-ram,size=64M,id=m0,prealloc=y " "-object memory-backend-ram,size=64M,id=m1 " @@ -492,7 +492,7 @@ static void pc_hmat_erange_cfg(const void *data) g_autofree char *cli = NULL; cli = make_cli(data, "-nodefaults --preconfig -machine hmat=on " - "-smp 2,sockets=2 " + "-machine smp.cpus=2,smp.sockets=2 " "-m 128M,slots=2,maxmem=1G " "-object memory-backend-ram,size=64M,id=m0 " "-object memory-backend-ram,size=64M,id=m1 " From patchwork Tue Jun 8 09:40:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12306205 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8BBBC47082 for ; Tue, 8 Jun 2021 09:53:40 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 92C0461185 for ; Tue, 8 Jun 2021 09:53:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 92C0461185 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:44288 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqYQV-0005dQ-Pc for qemu-devel@archiver.kernel.org; Tue, 08 Jun 2021 05:53:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51698) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqYDs-0004iD-Sl for qemu-devel@nongnu.org; Tue, 08 Jun 2021 05:40:36 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]:34361) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lqYDo-0001ww-7b for qemu-devel@nongnu.org; Tue, 08 Jun 2021 05:40:33 -0400 Received: by mail-wm1-x333.google.com with SMTP id u5-20020a7bc0450000b02901480e40338bso1233391wmc.1 for ; Tue, 08 Jun 2021 02:40:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Vv2J1Eu+1Gs3q5FfU3Miy7oOhq4eBNKPYhz6liN5ugY=; b=cYdVyniv8mQg3NRAJpLF+f533QWroQdU2ACIsDvgUHYuSIUCAqm8XZuk9ymaVERZ0B j99rqJtI5a89k5dhUWTt9A1mzezkg1Nsyi9KPLT/gHh7gK9Mi8GSRO6LnCVQuNdPIaht x8TfFOLelS2IaF1lHFh2jzvfPOxwIrN6K8970+UdZXs+085ttAp/5YV2G5e/H+QQW4Qu iO9w2gELNFX2uqS9OXDeedIk7R0N5KjQpBMJmJQmWX+rHL90FBtDItatDNGoAE7ylrNM fe2ksQKfe9jn0Gg8593hElAIP4+krzJgH+RQlthD3EBUJCj5SVfv6U7T4DpBdOwGidgT uA2w== 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:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=Vv2J1Eu+1Gs3q5FfU3Miy7oOhq4eBNKPYhz6liN5ugY=; b=fHq0aCpWTX0dRDiGlwpNTtTg0pY6BeWq8LgKoueLax36op6LchiCRwzBziaib07NdO YEpUFNRdbMMgSAr7u16FeAjwsyXcZ36oxQcs/g+pVn3eFoijTFpWb3UY0ehyb6PefF4w v09z8QGvw8G8cIjQG+iZ7NBsYosdaHsSZ6F9nrPf0QxiSX/aF82AvWLLKtWAQTuzgpee ARIuMasgQX1/gr9ldq+RYvwclx2cDUoOp2pRcJ8bS6LN3wGV4uml9TP+Zjke6weaZGET hmJtO6GJGxu/BLjQ0plAl4M0ztyDm32YGQvnXFI8TKD8jFpK6Y8Tns27g3drAZO+t6w+ YsBQ== X-Gm-Message-State: AOAM531dyM8o76O/K6IEYwfu9fVnX3yO/tUV4Nw9qAU6nhm/AJ8j3GUv VzGcxOaHQeILZc1m8CZcFSW/GeO9foc= X-Google-Smtp-Source: ABdhPJzhUgKRNOFBEoixl1RzWQK9uLTjbAy7V5clQMnD/yJoCyedn5ozjGcSvFUcKdTLfMyH6DxlzQ== X-Received: by 2002:a1c:1d04:: with SMTP id d4mr20756428wmd.126.1623145230810; Tue, 08 Jun 2021 02:40:30 -0700 (PDT) Received: from avogadro.lan ([93.56.169.140]) by smtp.gmail.com with ESMTPSA id d15sm8608764wri.58.2021.06.08.02.40.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 02:40:30 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 12/12] vnc: avoid deprecation warnings for SASL on OS X Date: Tue, 8 Jun 2021 11:40:17 +0200 Message-Id: <20210608094017.392673-13-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210608094017.392673-1-pbonzini@redhat.com> References: <20210608094017.392673-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::333; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x333.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.248, 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Apple has deprecated sasl.h functions in OS X 10.11. Therefore, all files that use SASL API need to disable -Wdeprecated-declarations. Remove the only use that is outside vnc-auth-sasl.c and add the relevant #pragma GCC diagnostic there. Signed-off-by: Paolo Bonzini Message-Id: <20210604120915.286195-1-pbonzini@redhat.com> Signed-off-by: Paolo Bonzini --- ui/vnc-auth-sasl.c | 20 ++++++++++++++++++++ ui/vnc-auth-sasl.h | 1 + ui/vnc.c | 10 ++-------- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/ui/vnc-auth-sasl.c b/ui/vnc-auth-sasl.c index df7dc08e9f..cf65a0b161 100644 --- a/ui/vnc-auth-sasl.c +++ b/ui/vnc-auth-sasl.c @@ -28,10 +28,30 @@ #include "vnc.h" #include "trace.h" +/* + * Apple has deprecated sasl.h functions in OS X 10.11. Therefore, + * files that use SASL API need to disable -Wdeprecated-declarations. + */ +#ifdef CONFIG_DARWIN +#pragma GCC diagnostic warning "-Wdeprecated-declarations" +#endif + /* Max amount of data we send/recv for SASL steps to prevent DOS */ #define SASL_DATA_MAX_LEN (1024 * 1024) +bool vnc_sasl_server_init(Error **errp) +{ + int saslErr = sasl_server_init(NULL, "qemu"); + + if (saslErr != SASL_OK) { + error_setg(errp, "Failed to initialize SASL auth: %s", + sasl_errstring(saslErr, NULL, NULL)); + return false; + } + return true; +} + void vnc_sasl_client_cleanup(VncState *vs) { if (vs->sasl.conn) { diff --git a/ui/vnc-auth-sasl.h b/ui/vnc-auth-sasl.h index 1bfb86c6f5..367b8672cc 100644 --- a/ui/vnc-auth-sasl.h +++ b/ui/vnc-auth-sasl.h @@ -63,6 +63,7 @@ struct VncDisplaySASL { char *authzid; }; +bool vnc_sasl_server_init(Error **errp); void vnc_sasl_client_cleanup(VncState *vs); size_t vnc_client_read_sasl(VncState *vs); diff --git a/ui/vnc.c b/ui/vnc.c index b3d4d7b9a5..f0a1550d58 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -4154,14 +4154,8 @@ void vnc_display_open(const char *id, Error **errp) trace_vnc_auth_init(vd, 1, vd->ws_auth, vd->ws_subauth); #ifdef CONFIG_VNC_SASL - if (sasl) { - int saslErr = sasl_server_init(NULL, "qemu"); - - if (saslErr != SASL_OK) { - error_setg(errp, "Failed to initialize SASL auth: %s", - sasl_errstring(saslErr, NULL, NULL)); - goto fail; - } + if (sasl && !vnc_sasl_server_init(errp)) { + goto fail; } #endif vd->lock_key_sync = lock_key_sync;