From nobody Fri May 10 17:18:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1623145775; cv=none; d=zohomail.com; s=zohoarc; b=FW8ZUy4JqSGhkz2l3UOrmP6dn6eKHENm3g1ZH97uIzj7YNtySu8E/dHLx0ZeqLc3ebGd9rrY6SojmevendINO/NprWppt0DH/2FHVeUm6ExkpiciE215zcRBtYl87FqcyukWwFjgGmRch1I2KBKU3DouCfLbtprNymivFqkaHj8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623145775; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=eaWfNNyaVagDad1eRt/V1RCmBUTKiX/vUI2Ausu/1+0=; b=TelBN+Bqd1fvkpwYP3UQtxYpnm2Vqi31BUt7+4zOKpS+Z7dIks5gYhEVCmCZ5KDibr3VEs6nfINpAp5KOdBFeLdz3IeR1QxGmPq+FUHoNTAKTr7RS7fJSxhBkmCIDXiJN1i3SeC3LfetBySIyIyTfpgDJ78UZEDgz8ab9maKwFU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623145775366131.03343686500205; Tue, 8 Jun 2021 02:49:35 -0700 (PDT) Received: from localhost ([::1]:59078 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqYMY-00052e-3r for importer@patchew.org; Tue, 08 Jun 2021 05:49:34 -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) 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) 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Machines and accelerators are not user-creatable but they are going to share similar command-line parsing machinery. Export functions that will be used with -machine and -accel in softmmu/vl.c. Signed-off-by: Paolo Bonzini --- include/qom/object.h | 23 ++++++++++++++++ qom/object_interfaces.c | 58 +++++++++++++++++++++++++++++------------ 2 files changed, 65 insertions(+), 16 deletions(-) diff --git a/include/qom/object.h b/include/qom/object.h index 6721cd312e..faae0d841f 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -861,6 +861,29 @@ static void do_qemu_init_ ## type_array(void) = \ } = \ type_init(do_qemu_init_ ## type_array) =20 +/** + * type_print_class_properties: + * @type: a QOM class name + * + * Print the object's class properties to stdout or the monitor. + * Return whether an object was found. + */ +bool type_print_class_properties(const char *type); + +/** + * object_set_properties_from_keyval: + * @obj: a QOM object + * @qdict: a dictionary with the properties to be set + * @from_json: true if leaf values of @qdict are typed, false if they + * are strings + * @errp: pointer to error object + * + * For each key in the dictionary, parse the value string if needed, + * then set the corresponding property in @obj. + */ +void object_set_properties_from_keyval(Object *obj, const QDict *qdict, + bool from_json, Error **errp); + /** * object_class_dynamic_cast_assert: * @klass: The #ObjectClass to attempt to cast. diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c index 4479ee693a..ad9b56b59a 100644 --- a/qom/object_interfaces.c +++ b/qom/object_interfaces.c @@ -42,6 +42,44 @@ bool user_creatable_can_be_deleted(UserCreatable *uc) } } =20 +static void object_set_properties_from_qdict(Object *obj, const QDict *qdi= ct, + Visitor *v, Error **errp) +{ + const QDictEntry *e; + Error *local_err =3D NULL; + + if (!visit_start_struct(v, NULL, NULL, 0, &local_err)) { + goto out; + } + for (e =3D qdict_first(qdict); e; e =3D qdict_next(qdict, e)) { + if (!object_property_set(obj, e->key, v, &local_err)) { + break; + } + } + if (!local_err) { + visit_check_struct(v, &local_err); + } + visit_end_struct(v, NULL); + +out: + if (local_err) { + error_propagate(errp, local_err); + } +} + +void object_set_properties_from_keyval(Object *obj, const QDict *qdict, + bool from_json, Error **errp) +{ + Visitor *v; + if (from_json) { + v =3D qobject_input_visitor_new(QOBJECT(qdict)); + } else { + v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); + } + object_set_properties_from_qdict(obj, qdict, v, errp); + visit_free(v); +} + Object *user_creatable_add_type(const char *type, const char *id, const QDict *qdict, Visitor *v, Error **errp) @@ -49,7 +87,6 @@ Object *user_creatable_add_type(const char *type, const c= har *id, ERRP_GUARD(); Object *obj; ObjectClass *klass; - const QDictEntry *e; Error *local_err =3D NULL; =20 if (id !=3D NULL && !id_wellformed(id)) { @@ -78,18 +115,7 @@ Object *user_creatable_add_type(const char *type, const= char *id, =20 assert(qdict); obj =3D object_new(type); - if (!visit_start_struct(v, NULL, NULL, 0, &local_err)) { - goto out; - } - for (e =3D qdict_first(qdict); e; e =3D qdict_next(qdict, e)) { - if (!object_property_set(obj, e->key, v, &local_err)) { - break; - } - } - if (!local_err) { - visit_check_struct(v, &local_err); - } - visit_end_struct(v, NULL); + object_set_properties_from_qdict(obj, qdict, v, &local_err); if (local_err) { goto out; } @@ -178,7 +204,7 @@ static void user_creatable_print_types(void) g_slist_free(list); } =20 -static bool user_creatable_print_type_properites(const char *type) +bool type_print_class_properties(const char *type) { ObjectClass *klass; ObjectPropertyIterator iter; @@ -224,7 +250,7 @@ bool user_creatable_print_help(const char *type, QemuOp= ts *opts) } =20 if (qemu_opt_has_help_opt(opts)) { - return user_creatable_print_type_properites(type); + return type_print_class_properties(type); } =20 return false; @@ -234,7 +260,7 @@ static void user_creatable_print_help_from_qdict(QDict = *args) { const char *type =3D qdict_get_try_str(args, "qom-type"); =20 - if (!type || !user_creatable_print_type_properites(type)) { + if (!type || !type_print_class_properties(type)) { user_creatable_print_types(); } } --=20 2.31.1 From nobody Fri May 10 17:18:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1623145525; cv=none; d=zohomail.com; s=zohoarc; b=EHFS0+JkcU9Gc9XuX0av5Y2fjiueSD9FqIOc7cBrnMbsWwLlGDoLaRs2bZ3qugT5JUvdsZ4CrIdPClrO3rxFGFzWzdXIMBtmUPtfYOlN9lRv2j/C5qZ7ifn8W118q5MLU2q/R8pvh0nQxwRLc64dZnGGkrZWSWThMUiZuj8C9Do= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623145525; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Qih0GKGRLKmsxOwD0kzGhjmPgfqEGBiIre4xMkTVeaI=; b=e+J9GDog93www/81Pj0bWWJDP7iwrllZfxYPBwzAV+YunDPA+YGRW5LYKPN+m8LbVZcHunHbaAbnMgmUREsVrMb2yF5NkpFLS2jYXP8iL92TROSXjxAU3OZeIhVJtBp9wUAyqGGtVNj+NHydk3xr7cY67OYbmoxIWt87QoNfE0k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623145525182738.1155111971318; Tue, 8 Jun 2021 02:45:25 -0700 (PDT) Received: from localhost ([::1]:46142 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqYIW-0004kj-17 for importer@patchew.org; Tue, 08 Jun 2021 05:45:24 -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) 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) 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This patch introduces a function that merges two keyval-produced (or keyval-like) QDicts. It can be used to emulate the behavior of .merge_lists =3D true QemuOpts groups, merging -readconfig sections and command-line options in a single QDict, and also to implement -set. Signed-off-by: Paolo Bonzini --- include/qemu/option.h | 1 + tests/unit/test-keyval.c | 56 ++++++++++++++++++++++++++++++++++++++++ util/keyval.c | 47 +++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+) diff --git a/include/qemu/option.h b/include/qemu/option.h index f73e0dc7d9..d89c66145a 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -149,5 +149,6 @@ QemuOptsList *qemu_opts_append(QemuOptsList *dst, QemuO= ptsList *list); =20 QDict *keyval_parse(const char *params, const char *implied_key, bool *help, Error **errp); +void keyval_merge(QDict *old, const QDict *new, Error **errp); =20 #endif diff --git a/tests/unit/test-keyval.c b/tests/unit/test-keyval.c index e20c07cf3e..254b51e98c 100644 --- a/tests/unit/test-keyval.c +++ b/tests/unit/test-keyval.c @@ -747,6 +747,59 @@ static void test_keyval_visit_any(void) visit_free(v); } =20 +static void test_keyval_merge_success(void) +{ + QDict *old =3D keyval_parse("opt1=3Dabc,opt2.sub1=3Ddef,opt2.sub2=3Dgh= i,opt3=3Dxyz", + NULL, NULL, &error_abort); + QDict *new =3D keyval_parse("opt1=3DABC,opt2.sub2=3DGHI,opt2.sub3=3DJK= L", + NULL, NULL, &error_abort); + QDict *combined =3D keyval_parse("opt1=3DABC,opt2.sub1=3Ddef,opt2.sub2= =3DGHI,opt2.sub3=3DJKL,opt3=3Dxyz", + NULL, NULL, &error_abort); + Error *err =3D NULL; + + keyval_merge(old, new, &err); + g_assert(!err); + g_assert(qobject_is_equal(QOBJECT(combined), QOBJECT(old))); + qobject_unref(old); + qobject_unref(new); + qobject_unref(combined); +} + +static void test_keyval_merge_list(void) +{ + QDict *old =3D keyval_parse("opt1.0=3Dabc,opt2.0=3Dxyz", + NULL, NULL, &error_abort); + QDict *new =3D keyval_parse("opt1.0=3Ddef", + NULL, NULL, &error_abort); + QDict *combined =3D keyval_parse("opt1.0=3Dabc,opt1.1=3Ddef,opt2.0=3Dx= yz", + NULL, NULL, &error_abort); + Error *err =3D NULL; + + keyval_merge(old, new, &err); + g_assert(!err); + g_assert(qobject_is_equal(QOBJECT(combined), QOBJECT(old))); + qobject_unref(old); + qobject_unref(new); + qobject_unref(combined); +} + +static void test_keyval_merge_conflict(void) +{ + QDict *old =3D keyval_parse("opt2.sub1=3Ddef,opt2.sub2=3Dghi", + NULL, NULL, &error_abort); + QDict *new =3D keyval_parse("opt2=3DABC", + NULL, NULL, &error_abort); + Error *err =3D NULL; + + keyval_merge(new, old, &err); + error_free_or_abort(&err); + keyval_merge(old, new, &err); + error_free_or_abort(&err); + + qobject_unref(old); + qobject_unref(new); +} + int main(int argc, char *argv[]) { g_test_init(&argc, &argv, NULL); @@ -760,6 +813,9 @@ int main(int argc, char *argv[]) g_test_add_func("/keyval/visit/optional", test_keyval_visit_optional); g_test_add_func("/keyval/visit/alternate", test_keyval_visit_alternate= ); g_test_add_func("/keyval/visit/any", test_keyval_visit_any); + g_test_add_func("/keyval/merge/success", test_keyval_merge_success); + g_test_add_func("/keyval/merge/list", test_keyval_merge_list); + g_test_add_func("/keyval/merge/conflict", test_keyval_merge_conflict); g_test_run(); return 0; } diff --git a/util/keyval.c b/util/keyval.c index be34928813..0797f36e1d 100644 --- a/util/keyval.c +++ b/util/keyval.c @@ -310,6 +310,53 @@ static char *reassemble_key(GSList *key) return g_string_free(s, FALSE); } =20 +/* Merge two dictionaries. */ +static void keyval_do_merge(QDict *old, const QDict *new, GString *str, Er= ror **errp) +{ + size_t save_len =3D str->len; + const QDictEntry *ent; + QObject *old_value; + + for (ent =3D qdict_first(new); ent; ent =3D qdict_next(new, ent)) { + old_value =3D qdict_get(old, ent->key); + if (old_value) { + if (qobject_type(old_value) !=3D qobject_type(ent->value)) { + error_setg(errp, "Parameter '%s%s' used inconsistently", s= tr->str, ent->key); + return; + } else if (qobject_type(ent->value) =3D=3D QTYPE_QDICT) { + /* Merge sub-dictionaries. */ + g_string_append(str, ent->key); + g_string_append_c(str, '.'); + keyval_do_merge(qobject_to(QDict, old_value), + qobject_to(QDict, ent->value), + str, errp); + g_string_truncate(str, save_len); + continue; + } else if (qobject_type(ent->value) =3D=3D QTYPE_QLIST) { + /* Append to old list. */ + QList *old =3D qobject_to(QList, old_value); + QList *new =3D qobject_to(QList, ent->value); + const QListEntry *item; + QLIST_FOREACH_ENTRY(new, item) { + qobject_ref(item->value); + qlist_append_obj(old, item->value); + } + continue; + } + } + + qobject_ref(ent->value); + qdict_put_obj(old, ent->key, ent->value); + } +} + +void keyval_merge(QDict *old, const QDict *new, Error **errp) +{ + GString *str =3D g_string_new(""); + keyval_do_merge(old, new, str, errp); + g_string_free(str, TRUE); +} + /* * Listify @cur recursively. * Replace QDicts whose keys are all valid list indexes by QLists. --=20 2.31.1 From nobody Fri May 10 17:18:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1623145995; cv=none; d=zohomail.com; s=zohoarc; b=kuYQ6TBGwUVe9TTNshlY0qxV1fjT0J9xQ2/iFzqRx7pPaNaMstIpNuzcLNbD3Sq6/Co7KCc1ISoilaDmivyy2pNa0xxkYr/xwpJ6nnHfluLSXpLpF1YPkpy/4jXoAJrVm3DuSoEzI3SV+heielh5ZVDzTTWfsWmXA1rnxrWPbuo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623145995; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/PRr41PxTyXm10FMURUstxjpacQwh84HXdIsa79wlV8=; b=KROofIivmWfEAzBqFnMOVom/S1UnZccVsnsW4vUY4OYvKDp7Vx4Ez4WTft/w8FyUw9gZ99/cDZXpEOwklz45Ynuko3lc60YkvR68vFIX6uormSdv/PRULC1OgIWI9tOdl2rFEJaQeQRaGaE7BnYWk6DJucZh7dUAXR8GYs5iTPc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623145995478312.49163714880183; Tue, 8 Jun 2021 02:53:15 -0700 (PDT) Received: from localhost ([::1]:42826 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqYQ6-0004gG-9E for importer@patchew.org; Tue, 08 Jun 2021 05:53:14 -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) 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) 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Allow parsing multiple keyval sequences into the same dictionary. This will be used to simplify the parsing of the -M command line option, which is currently a .merge_lists =3D true QemuOpts group. Signed-off-by: Paolo Bonzini --- include/qemu/option.h | 2 ++ util/keyval.c | 43 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/include/qemu/option.h b/include/qemu/option.h index d89c66145a..fffb03d848 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -147,6 +147,8 @@ void qemu_opts_print_help(QemuOptsList *list, bool prin= t_caption); void qemu_opts_free(QemuOptsList *list); QemuOptsList *qemu_opts_append(QemuOptsList *dst, QemuOptsList *list); =20 +QDict *keyval_parse_into(QDict *qdict, const char *params, const char *imp= lied_key, + bool *p_help, Error **errp); QDict *keyval_parse(const char *params, const char *implied_key, bool *help, Error **errp); void keyval_merge(QDict *old, const QDict *new, Error **errp); diff --git a/util/keyval.c b/util/keyval.c index 0797f36e1d..1ffd6e1204 100644 --- a/util/keyval.c +++ b/util/keyval.c @@ -478,13 +478,14 @@ static QObject *keyval_listify(QDict *cur, GSList *ke= y_of_cur, Error **errp) * If @p_help is not NULL, store whether help is requested there. * If @p_help is NULL and help is requested, fail. * - * On success, return a dictionary of the parsed keys and values. - * On failure, store an error through @errp and return NULL. + * On success, return @dict, now filled with the parsed keys and values. + * + * On failure, store an error through @errp and return NULL. Any keys + * and values parsed so far will be in @dict nevertheless. */ -QDict *keyval_parse(const char *params, const char *implied_key, - bool *p_help, Error **errp) +QDict *keyval_parse_into(QDict *qdict, const char *params, const char *imp= lied_key, + bool *p_help, Error **errp) { - QDict *qdict =3D qdict_new(); QObject *listified; const char *s; bool help =3D false; @@ -493,7 +494,6 @@ QDict *keyval_parse(const char *params, const char *imp= lied_key, while (*s) { s =3D keyval_parse_one(qdict, s, implied_key, &help, errp); if (!s) { - qobject_unref(qdict); return NULL; } implied_key =3D NULL; @@ -503,15 +503,42 @@ QDict *keyval_parse(const char *params, const char *i= mplied_key, *p_help =3D help; } else if (help) { error_setg(errp, "Help is not available for this option"); - qobject_unref(qdict); return NULL; } =20 listified =3D keyval_listify(qdict, NULL, errp); if (!listified) { - qobject_unref(qdict); return NULL; } assert(listified =3D=3D QOBJECT(qdict)); return qdict; } + +/* + * Parse @params in QEMU's traditional KEY=3DVALUE,... syntax. + * + * If @implied_key, the first KEY=3D can be omitted. @implied_key is + * implied then, and VALUE can't be empty or contain ',' or '=3D'. + * + * A parameter "help" or "?" without a value isn't added to the + * resulting dictionary, but instead is interpreted as help request. + * All other options are parsed and returned normally so that context + * specific help can be printed. + * + * If @p_help is not NULL, store whether help is requested there. + * If @p_help is NULL and help is requested, fail. + * + * On success, return a dictionary of the parsed keys and values. + * On failure, store an error through @errp and return NULL. + */ +QDict *keyval_parse(const char *params, const char *implied_key, + bool *p_help, Error **errp) +{ + QDict *qdict =3D qdict_new(); + QDict *ret =3D keyval_parse_into(qdict, params, implied_key, p_help, e= rrp); + + if (!ret) { + qobject_unref(qdict); + } + return ret; +} --=20 2.31.1 From nobody Fri May 10 17:18:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1623145529; cv=none; d=zohomail.com; s=zohoarc; b=hrKOrymV9SXqZN6EjM11hfs5O+ECAAFTbQTEpeqdTzhU6ZOzYB3o6J9lOmzFV0MKdrNLyp2evSxQXqNOVxGD4w7mIq+6WGJOPOIRDvf6eS6wZ17LwKnHtfzIj9oK2mkK7aXp005bnAxifqe3KNC0peV005ZSsiYyAgMlNi0iAko= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623145529; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=LDv+ZH2LmW5070WGtSOldoGmLLz0hT9fiDNARCMiQaI=; b=joJ6GSRl90kHPZEVVQJ9mzyAcf24rX8VaAQwhC/eQSWAlDD+nGCjy8+3p2sgAYxK8bg+TU3CESet6XyzKnEgpvM9h+90GsHfdagrERn9oth8ZXkLxsHEeME+sVLNiJPm2H9oNaGmLeF2B7nJyNBLV7bl3kFdy3yd8FJ/O6RL+O8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623145529920424.0447404187245; Tue, 8 Jun 2021 02:45:29 -0700 (PDT) Received: from localhost ([::1]:46378 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqYIa-0004uB-Ms for importer@patchew.org; Tue, 08 Jun 2021 05:45:28 -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) 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) 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Switch from QemuOpts to keyval. This enables the introduction of non-scalar machine properties, and JSON syntax in the future. For JSON syntax to be supported right now, we would have to consider what would happen if string-based dictionaries (produced by -M key=3Dval) were to be merged with strongly-typed dictionaries (produced by -M {'key': 123}). The simplest way out is to never enter the situation, and only allow one -M option when JSON syntax is in use. However, we want options such as -smp to become syntactic sugar for -M, and this is a problem; as soon as -smp becomes a shortcut for -M, QEMU would forbid using -M '{....}' together with -smp. Therefore, allowing JSON syntax right now for -M would be a forward-compatibility nightmare and it would be impossible anyway to introduce -M incrementally in tools. Instead, support for JSON syntax is delayed until after the main options are converted to QOM compound properties. These include -boot, -acpitable, -smbios, -m, -semihosting-config, -rtc and -fw_cfg. Once JSON syntax is introduced, these options will _also_ be forbidden together with -M '{...}'. Signed-off-by: Paolo Bonzini --- softmmu/vl.c | 303 ++++++++++++++++++++++++--------------------------- 1 file changed, 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 =3D QTAILQ_HEAD_INITIALIZER= (object_opts); static ram_addr_t maxram_size; static uint64_t ram_slots; @@ -235,21 +237,6 @@ static QemuOptsList qemu_option_rom_opts =3D { }, }; =20 -static QemuOptsList qemu_machine_opts =3D { - .name =3D "machine", - .implied_opt_name =3D "type", - .merge_lists =3D true, - .head =3D QTAILQ_HEAD_INITIALIZER(qemu_machine_opts.head), - .desc =3D { - /* - * no elements =3D> accept any - * sanity checking will happen later - * when setting machine properties - */ - { } - }, -}; - static QemuOptsList qemu_accel_opts =3D { .name =3D "accel", .implied_opt_name =3D "accel", @@ -498,16 +485,6 @@ static QemuOptsList qemu_action_opts =3D { }, }; =20 -/** - * Get machine options - * - * Returns: machine options (never null). - */ -static QemuOpts *qemu_get_machine_opts(void) -{ - return qemu_find_opts_singleton("machine"); -} - const char *qemu_get_vm_name(void) { return qemu_name; @@ -815,33 +792,6 @@ static MachineClass *find_default_machine(GSList *mach= ines) return default_machineclass; } =20 -static int machine_help_func(QemuOpts *opts, MachineState *machine) -{ - ObjectProperty *prop; - ObjectPropertyIterator iter; - - if (!qemu_opt_has_help_opt(opts)) { - return 0; - } - - object_property_iter_init(&iter, OBJECT(machine)); - while ((prop =3D object_property_iter_next(&iter))) { - if (!prop->set) { - continue; - } - - printf("%s.%s=3D%s", MACHINE_GET_CLASS(machine)->name, - prop->name, prop->type); - if (prop->description) { - printf(" (%s)\n", prop->description); - } else { - printf("\n"); - } - } - - return 1; -} - static void version(void) { printf("QEMU emulator version " QEMU_FULL_VERSION "\n" @@ -1546,33 +1496,31 @@ static gint machine_class_cmp(gconstpointer a, gcon= stpointer b) object_class_get_name(OBJECT_CLASS(mc1))); } =20 -static MachineClass *machine_parse(const char *name, GSList *machines) +static void machine_help_func(const QDict *qdict) { - MachineClass *mc; - GSList *el; + GSList *machines, *el; + const char *type =3D qdict_get_try_str(qdict, "type"); =20 - if (is_help_option(name)) { - printf("Supported machines are:\n"); - machines =3D g_slist_sort(machines, machine_class_cmp); - for (el =3D machines; el; el =3D el->next) { - MachineClass *mc =3D el->data; - if (mc->alias) { - printf("%-20s %s (alias of %s)\n", mc->alias, mc->desc, mc= ->name); - } - printf("%-20s %s%s%s\n", mc->name, mc->desc, - mc->is_default ? " (default)" : "", - mc->deprecation_reason ? " (deprecated)" : ""); + machines =3D object_class_get_list(TYPE_MACHINE, false); + if (type) { + ObjectClass *machine_class =3D OBJECT_CLASS(find_machine(type, mac= hines)); + if (machine_class) { + type_print_class_properties(object_class_get_name(machine_clas= s)); + return; } - exit(0); } =20 - mc =3D find_machine(name, machines); - if (!mc) { - error_report("unsupported machine type"); - error_printf("Use -machine help to list supported machines\n"); - exit(1); + printf("Supported machines are:\n"); + machines =3D g_slist_sort(machines, machine_class_cmp); + for (el =3D machines; el; el =3D el->next) { + MachineClass *mc =3D el->data; + if (mc->alias) { + printf("%-20s %s (alias of %s)\n", mc->alias, mc->desc, mc->na= me); + } + printf("%-20s %s%s%s\n", mc->name, mc->desc, + mc->is_default ? " (default)" : "", + mc->deprecation_reason ? " (deprecated)" : ""); } - return mc; } =20 static const char *pid_file; @@ -1625,32 +1573,31 @@ static const QEMUOption *lookup_opt(int argc, char = **argv, return popt; } =20 -static MachineClass *select_machine(void) +static MachineClass *select_machine(QDict *qdict, Error **errp) { + const char *optarg =3D qdict_get_try_str(qdict, "type"); GSList *machines =3D object_class_get_list(TYPE_MACHINE, false); - MachineClass *machine_class =3D find_default_machine(machines); - const char *optarg; - QemuOpts *opts; - Location loc; - - loc_push_none(&loc); - - opts =3D qemu_get_machine_opts(); - qemu_opts_loc_restore(opts); + MachineClass *machine_class; + Error *local_err =3D NULL; =20 - optarg =3D qemu_opt_get(opts, "type"); if (optarg) { - machine_class =3D machine_parse(optarg, machines); - } - - if (!machine_class) { - error_report("No machine specified, and there is no default"); - error_printf("Use -machine help to list supported machines\n"); - exit(1); + machine_class =3D find_machine(optarg, machines); + qdict_del(qdict, "type"); + if (!machine_class) { + error_setg(&local_err, "unsupported machine type"); + } + } else { + machine_class =3D find_default_machine(machines); + if (!machine_class) { + error_setg(&local_err, "No machine specified, and there is no = default"); + } } =20 - loc_pop(&loc); g_slist_free(machines); + if (local_err) { + error_append_hint(&local_err, "Use -machine help to list supported= machines\n"); + error_propagate(errp, local_err); + } return machine_class; } =20 @@ -1669,42 +1616,70 @@ static int object_parse_property_opt(Object *obj, return 0; } =20 -static int machine_set_property(void *opaque, - const char *name, const char *value, - Error **errp) +/* *Non*recursively replace underscores with dashes in QDict keys. */ +static void keyval_dashify(QDict *qdict, Error **errp) { - g_autofree char *qom_name =3D g_strdup(name); + const QDictEntry *ent, *next; char *p; =20 - for (p =3D qom_name; *p; p++) { - if (*p =3D=3D '_') { - *p =3D '-'; + for (ent =3D qdict_first(qdict); ent; ent =3D next) { + g_autofree char *new_key =3D NULL; + + next =3D qdict_next(qdict, ent); + if (!strchr(ent->key, '_')) { + continue; } + new_key =3D g_strdup(ent->key); + for (p =3D new_key; *p; p++) { + if (*p =3D=3D '_') { + *p =3D '-'; + } + } + if (qdict_haskey(qdict, new_key)) { + error_setg(errp, "Conflict between '%s' and '%s'", ent->key, n= ew_key); + return; + } + qobject_ref(ent->value); + qdict_put_obj(qdict, new_key, ent->value); + qdict_del(qdict, ent->key); } +} + +static void qemu_apply_legacy_machine_options(QDict *qdict) +{ + const char *value; + + keyval_dashify(qdict, &error_fatal); =20 /* Legacy options do not correspond to MachineState properties. */ - if (g_str_equal(qom_name, "accel")) { - return 0; + value =3D qdict_get_try_str(qdict, "accel"); + if (value) { + accelerators =3D g_strdup(value); + qdict_del(qdict, "accel"); } - if (g_str_equal(qom_name, "igd-passthru")) { - object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), qom_name, valu= e, + + value =3D qdict_get_try_str(qdict, "igd-passthru"); + if (value) { + object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), "igd-passthru"= , value, false); - return 0; + qdict_del(qdict, "igd-passthru"); } - if (g_str_equal(qom_name, "kvm-shadow-mem")) { - object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), qom_name, valu= e, + + value =3D qdict_get_try_str(qdict, "kvm-shadow-mem"); + if (value) { + object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), "kvm-shadow-me= m", value, false); - return 0; + qdict_del(qdict, "kvm-shadow-mem"); } - if (g_str_equal(qom_name, "kernel-irqchip")) { - object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), qom_name, valu= e, + + value =3D qdict_get_try_str(qdict, "kernel-irqchip"); + if (value) { + object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), "kernel-irqchi= p", value, false); - object_register_sugar_prop(ACCEL_CLASS_NAME("whpx"), qom_name, val= ue, + object_register_sugar_prop(ACCEL_CLASS_NAME("whpx"), "kernel-irqch= ip", value, false); - return 0; + qdict_del(qdict, "kernel-irqchip"); } - - return object_parse_property_opt(opaque, name, value, "type", errp); } =20 static void object_option_foreach_add(bool (*type_opt_predicate)(const cha= r *)) @@ -1819,16 +1794,14 @@ static bool object_create_early(const char *type) return true; } =20 -static void qemu_apply_machine_options(void) +static void qemu_apply_machine_options(QDict *qdict) { MachineClass *machine_class =3D MACHINE_GET_CLASS(current_machine); - QemuOpts *machine_opts =3D qemu_get_machine_opts(); const char *boot_order =3D NULL; const char *boot_once =3D NULL; QemuOpts *opts; =20 - qemu_opt_foreach(machine_opts, machine_set_property, current_machine, - &error_fatal); + object_set_properties_from_keyval(OBJECT(current_machine), qdict, fals= e, &error_fatal); current_machine->ram_size =3D ram_size; current_machine->maxram_size =3D maxram_size; current_machine->ram_slots =3D ram_slots; @@ -1857,10 +1830,8 @@ static void qemu_apply_machine_options(void) current_machine->boot_once =3D boot_once; =20 if (semihosting_enabled() && !semihosting_get_argc()) { - const char *kernel_filename =3D qemu_opt_get(machine_opts, "kernel= "); - const char *kernel_cmdline =3D qemu_opt_get(machine_opts, "append"= ) ?: ""; /* fall back to the -kernel/-append */ - semihosting_arg_fallback(kernel_filename, kernel_cmdline); + semihosting_arg_fallback(current_machine->kernel_filename, current= _machine->kernel_cmdline); } } =20 @@ -1907,8 +1878,7 @@ static void qemu_create_early_backends(void) =20 /* * Note: we need to create audio and block backends before - * machine_set_property(), so machine properties can refer to - * them. + * setting machine properties, so they can be referred to. */ configure_blockdev(&bdo_queue, machine_class, snapshot); audio_init_audiodevs(); @@ -2074,16 +2044,14 @@ static void set_memory_options(MachineClass *mc) loc_pop(&loc); } =20 -static void qemu_create_machine(MachineClass *machine_class) +static void qemu_create_machine(QDict *qdict) { + MachineClass *machine_class =3D select_machine(qdict, &error_fatal); object_set_machine_compat_props(machine_class->compat_props); =20 set_memory_options(machine_class); =20 current_machine =3D MACHINE(object_new_with_class(OBJECT_CLASS(machine= _class))); - if (machine_help_func(qemu_get_machine_opts(), current_machine)) { - exit(0); - } object_property_add_child(object_get_root(), "machine", OBJECT(current_machine)); object_property_add_child(container_get(OBJECT(current_machine), @@ -2114,8 +2082,12 @@ static void qemu_create_machine(MachineClass *machin= e_class) * specified either by the configuration file or by the command line. */ if (machine_class->default_machine_opts) { - qemu_opts_set_defaults(qemu_find_opts("machine"), - machine_class->default_machine_opts, 0); + QDict *default_opts =3D + keyval_parse(machine_class->default_machine_opts, NULL, NULL, + &error_abort); + object_set_properties_from_keyval(OBJECT(current_machine), default= _opts, + false, &error_abort); + qobject_unref(default_opts); } } =20 @@ -2137,7 +2109,8 @@ static int global_init_func(void *opaque, QemuOpts *o= pts, Error **errp) */ static bool is_qemuopts_group(const char *group) { - if (g_str_equal(group, "object")) { + if (g_str_equal(group, "object") || + g_str_equal(group, "machine")) { return false; } return true; @@ -2150,6 +2123,13 @@ static void qemu_record_config_group(const char *gro= up, QDict *dict, Visitor *v =3D qobject_input_visitor_new_keyval(QOBJECT(dict)); object_option_add_visitor(v); visit_free(v); + } else if (g_str_equal(group, "machine")) { + /* + * Cannot merge string-valued and type-safe dictionaries, so JSON + * is not accepted yet for -M. + */ + assert(!from_json); + keyval_merge(machine_opts_dict, dict, errp); } else { abort(); } @@ -2280,13 +2260,11 @@ static int do_configure_accelerator(void *opaque, Q= emuOpts *opts, Error **errp) =20 static void configure_accelerators(const char *progname) { - const char *accelerators; bool init_failed =3D false; =20 qemu_opts_foreach(qemu_find_opts("icount"), do_configure_icount, NULL, &error_fatal); =20 - accelerators =3D qemu_opt_get(qemu_get_machine_opts(), "accel"); if (QTAILQ_EMPTY(&qemu_accel_opts.head)) { char **accel_list, **tmp; =20 @@ -2374,12 +2352,11 @@ static void create_default_memdev(MachineState *ms,= const char *path) &error_fatal); } =20 -static void qemu_validate_options(void) +static void qemu_validate_options(const QDict *machine_opts) { - QemuOpts *machine_opts =3D qemu_get_machine_opts(); - const char *kernel_filename =3D qemu_opt_get(machine_opts, "kernel"); - const char *initrd_filename =3D qemu_opt_get(machine_opts, "initrd"); - const char *kernel_cmdline =3D qemu_opt_get(machine_opts, "append"); + const char *kernel_filename =3D qdict_get_try_str(machine_opts, "kerne= l"); + const char *initrd_filename =3D qdict_get_try_str(machine_opts, "initr= d"); + const char *kernel_cmdline =3D qdict_get_try_str(machine_opts, "append= "); =20 if (kernel_filename =3D=3D NULL) { if (kernel_cmdline !=3D NULL) { @@ -2719,7 +2696,6 @@ void qemu_init(int argc, char **argv, char **envp) qemu_add_opts(&qemu_trace_opts); qemu_plugin_add_opts(); qemu_add_opts(&qemu_option_rom_opts); - qemu_add_opts(&qemu_machine_opts); qemu_add_opts(&qemu_accel_opts); qemu_add_opts(&qemu_mem_opts); qemu_add_opts(&qemu_smp_opts); @@ -2760,6 +2736,7 @@ void qemu_init(int argc, char **argv, char **envp) } } =20 + machine_opts_dict =3D qdict_new(); if (userconfig) { qemu_read_default_config_file(&error_fatal); } @@ -2849,8 +2826,7 @@ void qemu_init(int argc, char **argv, char **envp) parse_display(optarg); break; case QEMU_OPTION_nographic: - olist =3D qemu_find_opts("machine"); - qemu_opts_parse_noisily(olist, "graphics=3Doff", false); + qdict_put_str(machine_opts_dict, "graphics", "off"); nographic =3D true; dpy.type =3D DISPLAY_TYPE_NONE; break; @@ -2874,16 +2850,16 @@ void qemu_init(int argc, char **argv, char **envp) } break; case QEMU_OPTION_kernel: - qemu_opts_set(qemu_find_opts("machine"), "kernel", optarg,= &error_abort); + qdict_put_str(machine_opts_dict, "kernel", optarg); break; case QEMU_OPTION_initrd: - qemu_opts_set(qemu_find_opts("machine"), "initrd", optarg,= &error_abort); + qdict_put_str(machine_opts_dict, "initrd", optarg); break; case QEMU_OPTION_append: - qemu_opts_set(qemu_find_opts("machine"), "append", optarg,= &error_abort); + qdict_put_str(machine_opts_dict, "append", optarg); break; case QEMU_OPTION_dtb: - qemu_opts_set(qemu_find_opts("machine"), "dtb", optarg, &e= rror_abort); + qdict_put_str(machine_opts_dict, "dtb", optarg); break; case QEMU_OPTION_cdrom: drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS); @@ -2993,7 +2969,7 @@ void qemu_init(int argc, char **argv, char **envp) } break; case QEMU_OPTION_bios: - qemu_opts_set(qemu_find_opts("machine"), "firmware", optar= g, &error_abort); + qdict_put_str(machine_opts_dict, "firmware", optarg); break; case QEMU_OPTION_singlestep: singlestep =3D 1; @@ -3262,17 +3238,20 @@ void qemu_init(int argc, char **argv, char **envp) preconfig_requested =3D true; break; case QEMU_OPTION_enable_kvm: - olist =3D qemu_find_opts("machine"); - qemu_opts_parse_noisily(olist, "accel=3Dkvm", false); + qdict_put_str(machine_opts_dict, "accel", "kvm"); break; case QEMU_OPTION_M: case QEMU_OPTION_machine: - olist =3D qemu_find_opts("machine"); - opts =3D qemu_opts_parse_noisily(olist, optarg, true); - if (!opts) { - exit(1); + { + bool help; + + keyval_parse_into(machine_opts_dict, optarg, "type", &= help, &error_fatal); + if (help) { + machine_help_func(machine_opts_dict); + exit(EXIT_SUCCESS); + } + break; } - break; case QEMU_OPTION_accel: accel_opts =3D qemu_opts_parse_noisily(qemu_find_opts("acc= el"), optarg, true); @@ -3299,12 +3278,10 @@ void qemu_init(int argc, char **argv, char **envp) } break; case QEMU_OPTION_usb: - olist =3D qemu_find_opts("machine"); - qemu_opts_parse_noisily(olist, "usb=3Don", false); + qdict_put_str(machine_opts_dict, "usb", "on"); break; case QEMU_OPTION_usbdevice: - olist =3D qemu_find_opts("machine"); - qemu_opts_parse_noisily(olist, "usb=3Don", false); + qdict_put_str(machine_opts_dict, "usb", "on"); add_device_config(DEV_USB, optarg); break; case QEMU_OPTION_device: @@ -3323,12 +3300,10 @@ void qemu_init(int argc, char **argv, char **envp) vnc_parse(optarg); break; case QEMU_OPTION_no_acpi: - olist =3D qemu_find_opts("machine"); - qemu_opts_parse_noisily(olist, "acpi=3Doff", false); + qdict_put_str(machine_opts_dict, "acpi", "off"); break; case QEMU_OPTION_no_hpet: - olist =3D qemu_find_opts("machine"); - qemu_opts_parse_noisily(olist, "hpet=3Doff", false); + qdict_put_str(machine_opts_dict, "hpet", "off"); break; case QEMU_OPTION_no_reboot: olist =3D qemu_find_opts("action"); @@ -3581,7 +3556,7 @@ void qemu_init(int argc, char **argv, char **envp) */ loc_set_none(); =20 - qemu_validate_options(); + qemu_validate_options(machine_opts_dict); qemu_process_sugar_options(); =20 /* @@ -3614,7 +3589,7 @@ void qemu_init(int argc, char **argv, char **envp) =20 configure_rtc(qemu_find_opts_singleton("rtc")); =20 - qemu_create_machine(select_machine()); + qemu_create_machine(machine_opts_dict); =20 suspend_mux_open(); =20 @@ -3622,12 +3597,14 @@ void qemu_init(int argc, char **argv, char **envp) qemu_create_default_devices(); qemu_create_early_backends(); =20 - qemu_apply_machine_options(); + qemu_apply_legacy_machine_options(machine_opts_dict); + qemu_apply_machine_options(machine_opts_dict); + qobject_unref(machine_opts_dict); phase_advance(PHASE_MACHINE_CREATED); =20 /* * Note: uses machine properties such as kernel-irqchip, must run - * after machine_set_property(). + * after qemu_apply_machine_options. */ configure_accelerators(argv[0]); phase_advance(PHASE_ACCEL_CREATED); --=20 2.31.1 From nobody Fri May 10 17:18:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1623145363; cv=none; d=zohomail.com; s=zohoarc; b=J5ymOyHAolokAtyJcOZVAdscDi9SOZQ591Gcq3zKGSqAN8zJcFjty2ZR6B9xY93uB44ozO/ntBPbwO0tUB+e8q9gxEbQP9puH2RG2SNT12UE1NthdCksP0xlIxOyWhmFlxMj5YLzUCcoAsCVmDfO3CPt09e3UC8NJEObCgpYEpw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623145363; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=IDPNHb+HPzR8VO7xPUhdfTuo9DK5TmK3Ukrht2Or98o=; b=mj1w+3t44G4/bQboBxQIrLaQ+B1D08foenpsSS1yOwEMaIceppa1070RAtSWr/2kNa3p8Pau8MDurzg7LBK701M5UfE1hAnVTvORoHEF0V2qqf4pfYIOydN84HFTaaZSr1feu/rYGYV7PGuPGdmlAfI2Ak0HoEwKnpIDtkKIr7s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623145363134971.8589591033073; Tue, 8 Jun 2021 02:42:43 -0700 (PDT) Received: from localhost ([::1]:37772 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqYFt-0007Ud-Vw for importer@patchew.org; Tue, 08 Jun 2021 05:42:42 -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) 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) 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" -M was the sole user of qemu_opts_set and qemu_opts_set_defaults, remove them and the arguments that they used. Signed-off-by: Paolo Bonzini --- include/qemu/option.h | 3 --- tests/unit/test-qemu-opts.c | 35 ------------------------- util/qemu-option.c | 51 ++++++++----------------------------- 3 files changed, 10 insertions(+), 79 deletions(-) diff --git a/include/qemu/option.h b/include/qemu/option.h index fffb03d848..306bf07575 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -119,7 +119,6 @@ QemuOpts *qemu_opts_create(QemuOptsList *list, const ch= ar *id, int fail_if_exists, Error **errp); void qemu_opts_reset(QemuOptsList *list); void qemu_opts_loc_restore(QemuOpts *opts); -bool qemu_opts_set(QemuOptsList *list, const char *name, const char *value= , Error **errp); const char *qemu_opts_id(QemuOpts *opts); void qemu_opts_set_id(QemuOpts *opts, char *id); void qemu_opts_del(QemuOpts *opts); @@ -130,8 +129,6 @@ QemuOpts *qemu_opts_parse_noisily(QemuOptsList *list, c= onst char *params, bool permit_abbrev); QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, bool permit_abbrev, Error **errp); -void qemu_opts_set_defaults(QemuOptsList *list, const char *params, - int permit_abbrev); QemuOpts *qemu_opts_from_qdict(QemuOptsList *list, const QDict *qdict, Error **errp); QDict *qemu_opts_to_qdict_filtered(QemuOpts *opts, QDict *qdict, diff --git a/tests/unit/test-qemu-opts.c b/tests/unit/test-qemu-opts.c index 6568e31a72..828d40e928 100644 --- a/tests/unit/test-qemu-opts.c +++ b/tests/unit/test-qemu-opts.c @@ -410,40 +410,6 @@ static void test_qemu_opts_reset(void) g_assert(opts =3D=3D NULL); } =20 -static void test_qemu_opts_set(void) -{ - QemuOptsList *list; - QemuOpts *opts; - const char *opt; - - list =3D qemu_find_opts("opts_list_04"); - g_assert(list !=3D NULL); - g_assert(QTAILQ_EMPTY(&list->head)); - g_assert_cmpstr(list->name, =3D=3D, "opts_list_04"); - - /* should not find anything at this point */ - opts =3D qemu_opts_find(list, NULL); - g_assert(opts =3D=3D NULL); - - /* implicitly create opts and set str3 value */ - qemu_opts_set(list, "str3", "value", &error_abort); - g_assert(!QTAILQ_EMPTY(&list->head)); - - /* get the just created opts */ - opts =3D qemu_opts_find(list, NULL); - g_assert(opts !=3D NULL); - - /* check the str3 value */ - opt =3D qemu_opt_get(opts, "str3"); - g_assert_cmpstr(opt, =3D=3D, "value"); - - qemu_opts_del(opts); - - /* should not find anything at this point */ - opts =3D qemu_opts_find(list, NULL); - g_assert(opts =3D=3D NULL); -} - static int opts_count_iter(void *opaque, const char *name, const char *val= ue, Error **errp) { @@ -1041,7 +1007,6 @@ int main(int argc, char *argv[]) g_test_add_func("/qemu-opts/opt_get_size", test_qemu_opt_get_size); g_test_add_func("/qemu-opts/opt_unset", test_qemu_opt_unset); g_test_add_func("/qemu-opts/opts_reset", test_qemu_opts_reset); - g_test_add_func("/qemu-opts/opts_set", test_qemu_opts_set); g_test_add_func("/qemu-opts/opts_parse/general", test_opts_parse); g_test_add_func("/qemu-opts/opts_parse/bool", test_opts_parse_bool); g_test_add_func("/qemu-opts/opts_parse/number", test_opts_parse_number= ); diff --git a/util/qemu-option.c b/util/qemu-option.c index 4944015a25..ee78e42216 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -479,19 +479,14 @@ int qemu_opt_unset(QemuOpts *opts, const char *name) } } =20 -static QemuOpt *opt_create(QemuOpts *opts, const char *name, char *value, - bool prepend) +static QemuOpt *opt_create(QemuOpts *opts, const char *name, char *value) { QemuOpt *opt =3D g_malloc0(sizeof(*opt)); =20 opt->name =3D g_strdup(name); opt->str =3D value; opt->opts =3D opts; - if (prepend) { - QTAILQ_INSERT_HEAD(&opts->head, opt, next); - } else { - QTAILQ_INSERT_TAIL(&opts->head, opt, next); - } + QTAILQ_INSERT_TAIL(&opts->head, opt, next); =20 return opt; } @@ -518,7 +513,7 @@ static bool opt_validate(QemuOpt *opt, Error **errp) bool qemu_opt_set(QemuOpts *opts, const char *name, const char *value, Error **errp) { - QemuOpt *opt =3D opt_create(opts, name, g_strdup(value), false); + QemuOpt *opt =3D opt_create(opts, name, g_strdup(value)); =20 if (!opt_validate(opt, errp)) { qemu_opt_del(opt); @@ -662,15 +657,6 @@ void qemu_opts_loc_restore(QemuOpts *opts) loc_restore(&opts->loc); } =20 -bool qemu_opts_set(QemuOptsList *list, const char *name, const char *value= , Error **errp) -{ - QemuOpts *opts; - - assert(list->merge_lists); - opts =3D qemu_opts_create(list, NULL, 0, &error_abort); - return qemu_opt_set(opts, name, value, errp); -} - const char *qemu_opts_id(QemuOpts *opts) { return opts->id; @@ -811,7 +797,7 @@ static const char *get_opt_name_value(const char *param= s, } =20 static bool opts_do_parse(QemuOpts *opts, const char *params, - const char *firstname, bool prepend, + const char *firstname, bool warn_on_flag, bool *help_wanted, Error **er= rp) { char *option, *value; @@ -833,7 +819,7 @@ static bool opts_do_parse(QemuOpts *opts, const char *p= arams, continue; } =20 - opt =3D opt_create(opts, option, value, prepend); + opt =3D opt_create(opts, option, value); g_free(option); if (!opt_validate(opt, errp)) { qemu_opt_del(opt); @@ -889,11 +875,11 @@ bool has_help_option(const char *params) bool qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname, Error **errp) { - return opts_do_parse(opts, params, firstname, false, false, NULL, errp= ); + return opts_do_parse(opts, params, firstname, false, NULL, errp); } =20 static QemuOpts *opts_parse(QemuOptsList *list, const char *params, - bool permit_abbrev, bool defaults, + bool permit_abbrev, bool warn_on_flag, bool *help_wanted, Error **= errp) { const char *firstname; @@ -903,21 +889,13 @@ static QemuOpts *opts_parse(QemuOptsList *list, const= char *params, assert(!permit_abbrev || list->implied_opt_name); firstname =3D permit_abbrev ? list->implied_opt_name : NULL; =20 - /* - * This code doesn't work for defaults && !list->merge_lists: when - * params has no id=3D, and list has an element with !opts->id, it - * appends a new element instead of returning the existing opts. - * However, we got no use for this case. Guard against possible - * (if unlikely) future misuse: - */ - assert(!defaults || list->merge_lists); opts =3D qemu_opts_create(list, id, !list->merge_lists, errp); g_free(id); if (opts =3D=3D NULL) { return NULL; } =20 - if (!opts_do_parse(opts, params, firstname, defaults, + if (!opts_do_parse(opts, params, firstname, warn_on_flag, help_wanted, errp)) { qemu_opts_del(opts); return NULL; @@ -936,7 +914,7 @@ static QemuOpts *opts_parse(QemuOptsList *list, const c= har *params, QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, bool permit_abbrev, Error **errp) { - return opts_parse(list, params, permit_abbrev, false, false, NULL, err= p); + return opts_parse(list, params, permit_abbrev, false, NULL, errp); } =20 /** @@ -954,7 +932,7 @@ QemuOpts *qemu_opts_parse_noisily(QemuOptsList *list, c= onst char *params, QemuOpts *opts; bool help_wanted =3D false; =20 - opts =3D opts_parse(list, params, permit_abbrev, false, true, + opts =3D opts_parse(list, params, permit_abbrev, true, opts_accepts_any(list) ? NULL : &help_wanted, &err); if (!opts) { @@ -968,15 +946,6 @@ QemuOpts *qemu_opts_parse_noisily(QemuOptsList *list, = const char *params, return opts; } =20 -void qemu_opts_set_defaults(QemuOptsList *list, const char *params, - int permit_abbrev) -{ - QemuOpts *opts; - - opts =3D opts_parse(list, params, permit_abbrev, true, false, NULL, NU= LL); - assert(opts); -} - static bool qemu_opts_from_qdict_entry(QemuOpts *opts, const QDictEntry *entry, Error **errp) --=20 2.31.1 From nobody Fri May 10 17:18:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1623145360; cv=none; d=zohomail.com; s=zohoarc; b=STZc9dqZCO08Idva6wiLM96oNYfhyUHao/ZqrUDo4QEM31gqNjdAk57vHhzx/aEBVn2elVxBwqMQOg85NCCBOE+HjBk+RfOMLD3GGblb/bcHQl+8cfGMgiz9zvtycdF6PdbJx/0uYJEN3ek6moc0FCNRixBcJ2l6hBA8UMKrnOE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623145360; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TFaVv/jz4lgF0mz802si5sGlUrBseoogQ4/SE+k7/4A=; b=Ez3PyroHrYKbjIB7udF7DfZb2HUrKc0src747UIR1Ru2Rq55x0TRjuJPuvzghJFKU8f1j994Q8aDCW9QhXYy0CJaVKVq9B4VAXhmqNXrwd4OrYB3PIPaLFluBj5L0Rdwnfoj9SH6kH3k4GpFHRYESUvtewNWs1p+XlI+Q9QV1YM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623145360802518.9477410070131; Tue, 8 Jun 2021 02:42:40 -0700 (PDT) Received: from localhost ([::1]:37774 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqYFr-0007Ur-Ku for importer@patchew.org; Tue, 08 Jun 2021 05:42:39 -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) 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) 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" In order to make SMP configuration a Machine property, we need a getter as well as a setter. To simplify the implementation put everything that the getter needs in the CpuTopology struct. Signed-off-by: Paolo Bonzini --- hw/core/machine.c | 1 + hw/i386/pc.c | 4 +--- hw/i386/x86.c | 15 +++++++-------- include/hw/boards.h | 1 + include/hw/i386/pc.h | 1 - include/hw/i386/x86.h | 1 - 6 files changed, 10 insertions(+), 13 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 55b9bc7817..d776c8cf20 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -970,6 +970,7 @@ static void machine_initfn(Object *obj) ms->smp.cpus =3D mc->default_cpus; ms->smp.max_cpus =3D mc->default_cpus; ms->smp.cores =3D 1; + ms->smp.dies =3D 1; ms->smp.threads =3D 1; ms->smp.sockets =3D 1; } diff --git a/hw/i386/pc.c b/hw/i386/pc.c index c6d8d0d84d..92958e9ad7 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -712,8 +712,6 @@ void pc_acpi_smi_interrupt(void *opaque, int irq, int l= evel) */ void pc_smp_parse(MachineState *ms, QemuOpts *opts) { - X86MachineState *x86ms =3D X86_MACHINE(ms); - if (opts) { unsigned cpus =3D qemu_opt_get_number(opts, "cpus", 0); unsigned sockets =3D qemu_opt_get_number(opts, "sockets", 0); @@ -769,7 +767,7 @@ void pc_smp_parse(MachineState *ms, QemuOpts *opts) ms->smp.cores =3D cores; ms->smp.threads =3D threads; ms->smp.sockets =3D sockets; - x86ms->smp_dies =3D dies; + ms->smp.dies =3D dies; } =20 if (ms->smp.cpus > 1) { diff --git a/hw/i386/x86.c b/hw/i386/x86.c index ed796fe6ba..2a99942016 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -64,7 +64,7 @@ inline void init_topo_info(X86CPUTopoInfo *topo_info, { MachineState *ms =3D MACHINE(x86ms); =20 - topo_info->dies_per_pkg =3D x86ms->smp_dies; + topo_info->dies_per_pkg =3D ms->smp.dies; topo_info->cores_per_die =3D ms->smp.cores; topo_info->threads_per_core =3D ms->smp.threads; } @@ -293,7 +293,7 @@ void x86_cpu_pre_plug(HotplugHandler *hotplug_dev, =20 init_topo_info(&topo_info, x86ms); =20 - env->nr_dies =3D x86ms->smp_dies; + env->nr_dies =3D ms->smp.dies; =20 /* * If APIC ID is not set, @@ -301,13 +301,13 @@ void x86_cpu_pre_plug(HotplugHandler *hotplug_dev, */ if (cpu->apic_id =3D=3D UNASSIGNED_APIC_ID) { int max_socket =3D (ms->smp.max_cpus - 1) / - smp_threads / smp_cores / x86ms->smp_dies; + smp_threads / smp_cores / ms->smp.dies; =20 /* * die-id was optional in QEMU 4.0 and older, so keep it optional * if there's only one die per socket. */ - if (cpu->die_id < 0 && x86ms->smp_dies =3D=3D 1) { + if (cpu->die_id < 0 && ms->smp.dies =3D=3D 1) { cpu->die_id =3D 0; } =20 @@ -322,9 +322,9 @@ void x86_cpu_pre_plug(HotplugHandler *hotplug_dev, if (cpu->die_id < 0) { error_setg(errp, "CPU die-id is not set"); return; - } else if (cpu->die_id > x86ms->smp_dies - 1) { + } else if (cpu->die_id > ms->smp.dies - 1) { error_setg(errp, "Invalid CPU die-id: %u must be in range 0:%u= ", - cpu->die_id, x86ms->smp_dies - 1); + cpu->die_id, ms->smp.dies - 1); return; } if (cpu->core_id < 0) { @@ -477,7 +477,7 @@ const CPUArchIdList *x86_possible_cpu_arch_ids(MachineS= tate *ms) &topo_info, &topo_ids); ms->possible_cpus->cpus[i].props.has_socket_id =3D true; ms->possible_cpus->cpus[i].props.socket_id =3D topo_ids.pkg_id; - if (x86ms->smp_dies > 1) { + if (ms->smp.dies > 1) { ms->possible_cpus->cpus[i].props.has_die_id =3D true; ms->possible_cpus->cpus[i].props.die_id =3D topo_ids.die_id; } @@ -1252,7 +1252,6 @@ static void x86_machine_initfn(Object *obj) =20 x86ms->smm =3D ON_OFF_AUTO_AUTO; x86ms->acpi =3D ON_OFF_AUTO_AUTO; - x86ms->smp_dies =3D 1; x86ms->pci_irq_mask =3D ACPI_BUILD_PCI_IRQS; x86ms->oem_id =3D g_strndup(ACPI_BUILD_APPNAME6, 6); x86ms->oem_table_id =3D g_strndup(ACPI_BUILD_APPNAME8, 8); diff --git a/include/hw/boards.h b/include/hw/boards.h index 3d55d2bd62..87ae5cc300 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -282,6 +282,7 @@ typedef struct DeviceMemoryState { */ typedef struct CpuTopology { unsigned int cpus; + unsigned int dies; unsigned int cores; unsigned int threads; unsigned int sockets; diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 1522a3359a..4c2ca6d36a 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -19,7 +19,6 @@ * PCMachineState: * @acpi_dev: link to ACPI PM device that performs ACPI hotplug handling * @boot_cpus: number of present VCPUs - * @smp_dies: number of dies per one package */ typedef struct PCMachineState { /*< private >*/ diff --git a/include/hw/i386/x86.h b/include/hw/i386/x86.h index c09b648dff..a6ffd94562 100644 --- a/include/hw/i386/x86.h +++ b/include/hw/i386/x86.h @@ -62,7 +62,6 @@ struct X86MachineState { unsigned pci_irq_mask; unsigned apic_id_limit; uint16_t boot_cpus; - unsigned smp_dies; =20 OnOffAuto smm; OnOffAuto acpi; --=20 2.31.1 From nobody Fri May 10 17:18:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1623145681; cv=none; d=zohomail.com; s=zohoarc; b=H/SMlEgycbN5f02VHEpoin1499OOmQdjtevm9pJOuKxMiUUCv/QLqqfVB9/nB3sjBgFgakrSa/HiSMsVizANSkpcwqLqS2F0ADnLhGjNpvLpRGJV5gdDYDgz9JWLJwu/J/TeHwsUl0QhzYBzSXkCZIMuiYODEBzXwFGilYxhAeg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623145681; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=J/jOftwZDa2RFQJpkwXjrQU/YDdcj+tfPzp2fAN/u3Q=; b=cEaHlqhRusUELmjH+Xo5w8XSQiwpzDin6X1iHcigom+qzl3nYtBeGPi3wbatO9nJdfJdGBcE+ysxZopd8RSGepqgqrzJqwJ/5zJhVYYD4DZuklgIdZWgbZNw2qnL5KVhmbqzznHJJmbuEsIA6Ttw+AqErzS8rySxXtWBQ/r5zOE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623145681751462.01907862613143; Tue, 8 Jun 2021 02:48:01 -0700 (PDT) Received: from localhost ([::1]:54794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqYL2-0002Az-Je for importer@patchew.org; Tue, 08 Jun 2021 05:48:00 -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) 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) 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Most of smp_parse and pc_smp_parse is guarded by an "if (opts)" conditional, and the rest is common to both function. Move the conditional and the common code to the caller, machine_smp_parse. Move the replay_add_blocker call after all errors are checked for. Signed-off-by: Paolo Bonzini --- hw/core/machine.c | 112 ++++++++++++++++++++++---------------------- hw/i386/pc.c | 116 +++++++++++++++++++++------------------------- 2 files changed, 110 insertions(+), 118 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index d776c8cf20..1016ec9e1c 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -741,67 +741,59 @@ void machine_set_cpu_numa_node(MachineState *machine, =20 static void smp_parse(MachineState *ms, QemuOpts *opts) { - if (opts) { - unsigned cpus =3D qemu_opt_get_number(opts, "cpus", 0); - unsigned sockets =3D qemu_opt_get_number(opts, "sockets", 0); - unsigned cores =3D qemu_opt_get_number(opts, "cores", 0); - unsigned threads =3D qemu_opt_get_number(opts, "threads", 0); - - /* compute missing values, prefer sockets over cores over threads = */ - if (cpus =3D=3D 0 || sockets =3D=3D 0) { - cores =3D cores > 0 ? cores : 1; - threads =3D threads > 0 ? threads : 1; - if (cpus =3D=3D 0) { - sockets =3D sockets > 0 ? sockets : 1; - cpus =3D cores * threads * sockets; - } else { - ms->smp.max_cpus =3D - qemu_opt_get_number(opts, "maxcpus", cpus); - sockets =3D ms->smp.max_cpus / (cores * threads); - } - } else if (cores =3D=3D 0) { - threads =3D threads > 0 ? threads : 1; - cores =3D cpus / (sockets * threads); - cores =3D cores > 0 ? cores : 1; - } else if (threads =3D=3D 0) { - threads =3D cpus / (cores * sockets); - threads =3D threads > 0 ? threads : 1; - } else if (sockets * cores * threads < cpus) { - error_report("cpu topology: " - "sockets (%u) * cores (%u) * threads (%u) < " - "smp_cpus (%u)", - sockets, cores, threads, cpus); - exit(1); - } - - ms->smp.max_cpus =3D - qemu_opt_get_number(opts, "maxcpus", cpus); - - if (ms->smp.max_cpus < cpus) { - error_report("maxcpus must be equal to or greater than smp"); - exit(1); + unsigned cpus =3D qemu_opt_get_number(opts, "cpus", 0); + unsigned sockets =3D qemu_opt_get_number(opts, "sockets", 0); + unsigned cores =3D qemu_opt_get_number(opts, "cores", 0); + unsigned threads =3D qemu_opt_get_number(opts, "threads", 0); + + /* compute missing values, prefer sockets over cores over threads */ + if (cpus =3D=3D 0 || sockets =3D=3D 0) { + cores =3D cores > 0 ? cores : 1; + threads =3D threads > 0 ? threads : 1; + if (cpus =3D=3D 0) { + sockets =3D sockets > 0 ? sockets : 1; + cpus =3D cores * threads * sockets; + } else { + ms->smp.max_cpus =3D + qemu_opt_get_number(opts, "maxcpus", cpus); + sockets =3D ms->smp.max_cpus / (cores * threads); } + } else if (cores =3D=3D 0) { + threads =3D threads > 0 ? threads : 1; + cores =3D cpus / (sockets * threads); + cores =3D cores > 0 ? cores : 1; + } else if (threads =3D=3D 0) { + threads =3D cpus / (cores * sockets); + threads =3D threads > 0 ? threads : 1; + } else if (sockets * cores * threads < cpus) { + error_report("cpu topology: " + "sockets (%u) * cores (%u) * threads (%u) < " + "smp_cpus (%u)", + sockets, cores, threads, cpus); + exit(1); + } =20 - if (sockets * cores * threads !=3D ms->smp.max_cpus) { - error_report("Invalid CPU topology: " - "sockets (%u) * cores (%u) * threads (%u) " - "!=3D maxcpus (%u)", - sockets, cores, threads, - ms->smp.max_cpus); - exit(1); - } + ms->smp.max_cpus =3D + qemu_opt_get_number(opts, "maxcpus", cpus); =20 - ms->smp.cpus =3D cpus; - ms->smp.cores =3D cores; - ms->smp.threads =3D threads; - ms->smp.sockets =3D sockets; + if (ms->smp.max_cpus < cpus) { + error_report("maxcpus must be equal to or greater than smp"); + exit(1); } =20 - if (ms->smp.cpus > 1) { - Error *blocker =3D NULL; - error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, "smp"); - replay_add_blocker(blocker); + if (sockets * cores * threads !=3D ms->smp.max_cpus) { + error_report("Invalid CPU topology: " + "sockets (%u) * cores (%u) * threads (%u) " + "!=3D maxcpus (%u)", + sockets, cores, threads, + ms->smp.max_cpus); + exit(1); } + + ms->smp.cpus =3D cpus; + ms->smp.cores =3D cores; + ms->smp.threads =3D threads; + ms->smp.sockets =3D sockets; } =20 static void machine_class_init(ObjectClass *oc, void *data) @@ -1135,7 +1127,9 @@ bool machine_smp_parse(MachineState *ms, QemuOpts *op= ts, Error **errp) { MachineClass *mc =3D MACHINE_GET_CLASS(ms); =20 - mc->smp_parse(ms, opts); + if (opts) { + mc->smp_parse(ms, opts); + } =20 /* sanity-check smp_cpus and max_cpus against mc */ if (ms->smp.cpus < mc->min_cpus) { @@ -1151,6 +1145,12 @@ bool machine_smp_parse(MachineState *ms, QemuOpts *o= pts, Error **errp) mc->name, mc->max_cpus); return false; } + + if (ms->smp.cpus > 1) { + Error *blocker =3D NULL; + error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, "smp"); + replay_add_blocker(blocker); + } return true; } =20 diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 92958e9ad7..e206ac85f3 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -712,69 +712,61 @@ void pc_acpi_smi_interrupt(void *opaque, int irq, int= level) */ void pc_smp_parse(MachineState *ms, QemuOpts *opts) { - if (opts) { - unsigned cpus =3D qemu_opt_get_number(opts, "cpus", 0); - unsigned sockets =3D qemu_opt_get_number(opts, "sockets", 0); - unsigned dies =3D qemu_opt_get_number(opts, "dies", 1); - unsigned cores =3D qemu_opt_get_number(opts, "cores", 0); - unsigned threads =3D qemu_opt_get_number(opts, "threads", 0); - - /* compute missing values, prefer sockets over cores over threads = */ - if (cpus =3D=3D 0 || sockets =3D=3D 0) { - cores =3D cores > 0 ? cores : 1; - threads =3D threads > 0 ? threads : 1; - if (cpus =3D=3D 0) { - sockets =3D sockets > 0 ? sockets : 1; - cpus =3D cores * threads * dies * sockets; - } else { - ms->smp.max_cpus =3D - qemu_opt_get_number(opts, "maxcpus", cpus); - sockets =3D ms->smp.max_cpus / (cores * threads * dies); - } - } else if (cores =3D=3D 0) { - threads =3D threads > 0 ? threads : 1; - cores =3D cpus / (sockets * dies * threads); - cores =3D cores > 0 ? cores : 1; - } else if (threads =3D=3D 0) { - threads =3D cpus / (cores * dies * sockets); - threads =3D threads > 0 ? threads : 1; - } else if (sockets * dies * cores * threads < cpus) { - error_report("cpu topology: " - "sockets (%u) * dies (%u) * cores (%u) * threads = (%u) < " - "smp_cpus (%u)", - sockets, dies, cores, threads, cpus); - exit(1); - } - - ms->smp.max_cpus =3D - qemu_opt_get_number(opts, "maxcpus", cpus); - - if (ms->smp.max_cpus < cpus) { - error_report("maxcpus must be equal to or greater than smp"); - exit(1); - } - - if (sockets * dies * cores * threads !=3D ms->smp.max_cpus) { - error_report("Invalid CPU topology deprecated: " - "sockets (%u) * dies (%u) * cores (%u) * threads = (%u) " - "!=3D maxcpus (%u)", - sockets, dies, cores, threads, - ms->smp.max_cpus); - exit(1); + unsigned cpus =3D qemu_opt_get_number(opts, "cpus", 0); + unsigned sockets =3D qemu_opt_get_number(opts, "sockets", 0); + unsigned dies =3D qemu_opt_get_number(opts, "dies", 1); + unsigned cores =3D qemu_opt_get_number(opts, "cores", 0); + unsigned threads =3D qemu_opt_get_number(opts, "threads", 0); + + /* compute missing values, prefer sockets over cores over threads */ + if (cpus =3D=3D 0 || sockets =3D=3D 0) { + cores =3D cores > 0 ? cores : 1; + threads =3D threads > 0 ? threads : 1; + if (cpus =3D=3D 0) { + sockets =3D sockets > 0 ? sockets : 1; + cpus =3D cores * threads * dies * sockets; + } else { + ms->smp.max_cpus =3D + qemu_opt_get_number(opts, "maxcpus", cpus); + sockets =3D ms->smp.max_cpus / (cores * threads * dies); } - - ms->smp.cpus =3D cpus; - ms->smp.cores =3D cores; - ms->smp.threads =3D threads; - ms->smp.sockets =3D sockets; - ms->smp.dies =3D dies; - } - - if (ms->smp.cpus > 1) { - Error *blocker =3D NULL; - error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, "smp"); - replay_add_blocker(blocker); - } + } else if (cores =3D=3D 0) { + threads =3D threads > 0 ? threads : 1; + cores =3D cpus / (sockets * dies * threads); + cores =3D cores > 0 ? cores : 1; + } else if (threads =3D=3D 0) { + threads =3D cpus / (cores * dies * sockets); + threads =3D threads > 0 ? threads : 1; + } else if (sockets * dies * cores * threads < cpus) { + error_report("cpu topology: " + "sockets (%u) * dies (%u) * cores (%u) * threads (= %u) < " + "smp_cpus (%u)", + sockets, dies, cores, threads, cpus); + exit(1); + } + + ms->smp.max_cpus =3D + qemu_opt_get_number(opts, "maxcpus", cpus); + + if (ms->smp.max_cpus < cpus) { + error_report("maxcpus must be equal to or greater than smp"); + exit(1); + } + + if (sockets * dies * cores * threads !=3D ms->smp.max_cpus) { + error_report("Invalid CPU topology deprecated: " + "sockets (%u) * dies (%u) * cores (%u) * threads (= %u) " + "!=3D maxcpus (%u)", + sockets, dies, cores, threads, + ms->smp.max_cpus); + exit(1); + } + + ms->smp.cpus =3D cpus; + ms->smp.cores =3D cores; + ms->smp.threads =3D threads; + ms->smp.sockets =3D sockets; + ms->smp.dies =3D dies; } =20 static --=20 2.31.1 From nobody Fri May 10 17:18:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1623145820; cv=none; d=zohomail.com; s=zohoarc; b=W3k1+1iP7Ep8lHj11Dr/w/fmocDH1aYe928yO23OWUyiKWMjlAkCQxQKFHFqx4nhxMypO5fa5zMR+XL8B+RD6MikcBfPYR6LXMWgrryxARzpCyCKlgPmjUF2DR+Gh7L9DcD6xDgWTm/jVjHsmXtv95ifGB1W3OCeZogkPxZAPDM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623145820; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=oaLUCvek2OmNr6/JtAkUEqBmw58D1m2VU8lWk8Kuo/k=; b=InrEMX2Anff+xsujoA8/MITSUNb7MalTLN+3Zt7bWuZWPV7Ro8r447DC516onl4g9gFmxoEcvDwG7MYwYYfNt5dMQjmVKk8GqfvRIqAZfKYB9o6xj0WCK5eUlvYglyraHX4vdtiqEef6MWTRy8857rgUohDjjrk7ffd+Ly+VC5g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623145820009509.9599315068907; Tue, 8 Jun 2021 02:50:20 -0700 (PDT) Received: from localhost ([::1]:33246 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqYNF-0006do-Tv for importer@patchew.org; Tue, 08 Jun 2021 05:50:17 -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) 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) 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Clean up the smp_parse functions to use Error** instead of exiting. Signed-off-by: Paolo Bonzini --- hw/core/machine.c | 34 +++++++++++++++++++--------------- hw/i386/pc.c | 28 ++++++++++++++-------------- include/hw/boards.h | 2 +- include/hw/i386/pc.h | 2 -- 4 files changed, 34 insertions(+), 32 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 1016ec9e1c..5a9c97ccc5 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -739,7 +739,7 @@ void machine_set_cpu_numa_node(MachineState *machine, } } =20 -static void smp_parse(MachineState *ms, QemuOpts *opts) +static void smp_parse(MachineState *ms, QemuOpts *opts, Error **errp) { unsigned cpus =3D qemu_opt_get_number(opts, "cpus", 0); unsigned sockets =3D qemu_opt_get_number(opts, "sockets", 0); @@ -766,28 +766,28 @@ static void smp_parse(MachineState *ms, QemuOpts *opt= s) threads =3D cpus / (cores * sockets); threads =3D threads > 0 ? threads : 1; } else if (sockets * cores * threads < cpus) { - error_report("cpu topology: " - "sockets (%u) * cores (%u) * threads (%u) < " - "smp_cpus (%u)", - sockets, cores, threads, cpus); - exit(1); + error_setg(errp, "cpu topology: " + "sockets (%u) * cores (%u) * threads (%u) < " + "smp_cpus (%u)", + sockets, cores, threads, cpus); + return; } =20 ms->smp.max_cpus =3D qemu_opt_get_number(opts, "maxcpus", cpus); =20 if (ms->smp.max_cpus < cpus) { - error_report("maxcpus must be equal to or greater than smp"); - exit(1); + error_setg(errp, "maxcpus must be equal to or greater than smp"); + return; } =20 if (sockets * cores * threads !=3D ms->smp.max_cpus) { - error_report("Invalid CPU topology: " - "sockets (%u) * cores (%u) * threads (%u) " - "!=3D maxcpus (%u)", - sockets, cores, threads, - ms->smp.max_cpus); - exit(1); + error_setg(errp, "Invalid CPU topology: " + "sockets (%u) * cores (%u) * threads (%u) " + "!=3D maxcpus (%u)", + sockets, cores, threads, + ms->smp.max_cpus); + return; } =20 ms->smp.cpus =3D cpus; @@ -1126,9 +1126,13 @@ MemoryRegion *machine_consume_memdev(MachineState *m= achine, bool machine_smp_parse(MachineState *ms, QemuOpts *opts, Error **errp) { MachineClass *mc =3D MACHINE_GET_CLASS(ms); + ERRP_GUARD(); =20 if (opts) { - mc->smp_parse(ms, opts); + mc->smp_parse(ms, opts, errp); + if (*errp) { + return false; + } } =20 /* sanity-check smp_cpus and max_cpus against mc */ diff --git a/hw/i386/pc.c b/hw/i386/pc.c index e206ac85f3..cce275dcb1 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -710,7 +710,7 @@ void pc_acpi_smi_interrupt(void *opaque, int irq, int l= evel) * This function is very similar to smp_parse() * in hw/core/machine.c but includes CPU die support. */ -void pc_smp_parse(MachineState *ms, QemuOpts *opts) +static void pc_smp_parse(MachineState *ms, QemuOpts *opts, Error **errp) { unsigned cpus =3D qemu_opt_get_number(opts, "cpus", 0); unsigned sockets =3D qemu_opt_get_number(opts, "sockets", 0); @@ -738,28 +738,28 @@ void pc_smp_parse(MachineState *ms, QemuOpts *opts) threads =3D cpus / (cores * dies * sockets); threads =3D threads > 0 ? threads : 1; } else if (sockets * dies * cores * threads < cpus) { - error_report("cpu topology: " - "sockets (%u) * dies (%u) * cores (%u) * threads (= %u) < " - "smp_cpus (%u)", - sockets, dies, cores, threads, cpus); - exit(1); + error_setg(errp, "cpu topology: " + "sockets (%u) * dies (%u) * cores (%u) * threads (%u) <= " + "smp_cpus (%u)", + sockets, dies, cores, threads, cpus); + return; } =20 ms->smp.max_cpus =3D qemu_opt_get_number(opts, "maxcpus", cpus); =20 if (ms->smp.max_cpus < cpus) { - error_report("maxcpus must be equal to or greater than smp"); - exit(1); + error_setg(errp, "maxcpus must be equal to or greater than smp"); + return; } =20 if (sockets * dies * cores * threads !=3D ms->smp.max_cpus) { - error_report("Invalid CPU topology deprecated: " - "sockets (%u) * dies (%u) * cores (%u) * threads (= %u) " - "!=3D maxcpus (%u)", - sockets, dies, cores, threads, - ms->smp.max_cpus); - exit(1); + error_setg(errp, "Invalid CPU topology deprecated: " + "sockets (%u) * dies (%u) * cores (%u) * threads (%u) " + "!=3D maxcpus (%u)", + sockets, dies, cores, threads, + ms->smp.max_cpus); + return; } =20 ms->smp.cpus =3D cpus; diff --git a/include/hw/boards.h b/include/hw/boards.h index 87ae5cc300..0483d6af86 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -210,7 +210,7 @@ struct MachineClass { void (*reset)(MachineState *state); void (*wakeup)(MachineState *state); int (*kvm_type)(MachineState *machine, const char *arg); - void (*smp_parse)(MachineState *ms, QemuOpts *opts); + void (*smp_parse)(MachineState *ms, QemuOpts *opts, Error **errp); =20 BlockInterfaceType block_default_type; int units_per_default_bus; diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 4c2ca6d36a..87294f2632 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -138,8 +138,6 @@ extern int fd_bootchk; =20 void pc_acpi_smi_interrupt(void *opaque, int irq, int level); =20 -void pc_smp_parse(MachineState *ms, QemuOpts *opts); - void pc_guest_info_init(PCMachineState *pcms); =20 #define PCI_HOST_PROP_PCI_HOLE_START "pci-hole-start" --=20 2.31.1 From nobody Fri May 10 17:18:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1623146105; cv=none; d=zohomail.com; s=zohoarc; b=Yy+Rc4UMvls2L8qZ63xf2FPvsWpriJipBIafo7SPOjMEIjFAxvU47AJlC50aBd0hITrKHkZXcJMcrKxgUs393aiRO4lg67c1iVJDsQ/0+ujV0G/cYd7OqZk5/a+EslLZAQK6wRspZLoEb4oEbKzZWXNCvDB9ADkocO9mpcgMxzk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623146105; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=AEctVWm7LnklR94IVota7cJxBYDiTHrGLM7X/qOIhdI=; b=RYVPbjUWVj9816A/uvuwhr42c3u1iOPCXJwGp4C7OqyhorFV2nYIcTTTP5ayH9KZSstVwPp9ZgpF9l9tm8hnSDErkzkXqv2lgut1c9XaLjbZGYRXI+Hyz20Jo80ac8Jbgu8aJ0M2P3nVMh6oLqabDULKVFYx0J7lwV3FcU0ITvA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623146105236900.2243085743988; Tue, 8 Jun 2021 02:55:05 -0700 (PDT) Received: from localhost ([::1]:49220 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqYRs-0000TE-6N for importer@patchew.org; Tue, 08 Jun 2021 05:55:04 -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) 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) 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" As part of converting -smp to a property with a QAPI type, define the struct and use it to do the actual parsing. machine_smp_parse takes care of doing the QemuOpts->QAPI conversion by hand, for now. Signed-off-by: Paolo Bonzini --- hw/core/machine.c | 33 +++++++++++++++++++++++---------- hw/i386/pc.c | 18 ++++++++---------- include/hw/boards.h | 2 +- qapi/machine.json | 27 +++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 21 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 5a9c97ccc5..9ad8341a31 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -739,12 +739,12 @@ void machine_set_cpu_numa_node(MachineState *machine, } } =20 -static void smp_parse(MachineState *ms, QemuOpts *opts, Error **errp) +static void smp_parse(MachineState *ms, SMPConfiguration *config, Error **= errp) { - unsigned cpus =3D qemu_opt_get_number(opts, "cpus", 0); - unsigned sockets =3D qemu_opt_get_number(opts, "sockets", 0); - unsigned cores =3D qemu_opt_get_number(opts, "cores", 0); - unsigned threads =3D qemu_opt_get_number(opts, "threads", 0); + unsigned cpus =3D config->has_cpus ? config->cpus : 0; + unsigned sockets =3D config->has_sockets ? config->sockets : 0; + unsigned cores =3D config->has_cores ? config->cores : 0; + unsigned threads =3D config->has_threads ? config->threads : 0; =20 /* compute missing values, prefer sockets over cores over threads */ if (cpus =3D=3D 0 || sockets =3D=3D 0) { @@ -754,8 +754,7 @@ static void smp_parse(MachineState *ms, QemuOpts *opts,= Error **errp) sockets =3D sockets > 0 ? sockets : 1; cpus =3D cores * threads * sockets; } else { - ms->smp.max_cpus =3D - qemu_opt_get_number(opts, "maxcpus", cpus); + ms->smp.max_cpus =3D config->has_maxcpus ? config->maxcpus : c= pus; sockets =3D ms->smp.max_cpus / (cores * threads); } } else if (cores =3D=3D 0) { @@ -773,8 +772,7 @@ static void smp_parse(MachineState *ms, QemuOpts *opts,= Error **errp) return; } =20 - ms->smp.max_cpus =3D - qemu_opt_get_number(opts, "maxcpus", cpus); + ms->smp.max_cpus =3D config->has_maxcpus ? config->maxcpus : cpus; =20 if (ms->smp.max_cpus < cpus) { error_setg(errp, "maxcpus must be equal to or greater than smp"); @@ -1129,7 +1127,22 @@ bool machine_smp_parse(MachineState *ms, QemuOpts *o= pts, Error **errp) ERRP_GUARD(); =20 if (opts) { - mc->smp_parse(ms, opts, errp); + SMPConfiguration config =3D { + .has_cpus =3D !!qemu_opt_get(opts, "cpus"), + .cpus =3D qemu_opt_get_number(opts, "cpus", 0), + .has_sockets =3D !!qemu_opt_get(opts, "sockets"), + .sockets =3D qemu_opt_get_number(opts, "sockets", 0), + .has_dies =3D !!qemu_opt_get(opts, "dies"), + .dies =3D qemu_opt_get_number(opts, "dies", 0), + .has_cores =3D !!qemu_opt_get(opts, "cores"), + .cores =3D qemu_opt_get_number(opts, "cores", 0), + .has_threads =3D !!qemu_opt_get(opts, "threads"), + .threads =3D qemu_opt_get_number(opts, "threads", 0), + .has_maxcpus =3D !!qemu_opt_get(opts, "maxcpus"), + .maxcpus =3D qemu_opt_get_number(opts, "maxcpus", 0), + }; + + mc->smp_parse(ms, &config, errp); if (*errp) { return false; } diff --git a/hw/i386/pc.c b/hw/i386/pc.c index cce275dcb1..8e1220db72 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -710,13 +710,13 @@ void pc_acpi_smi_interrupt(void *opaque, int irq, int= level) * This function is very similar to smp_parse() * in hw/core/machine.c but includes CPU die support. */ -static void pc_smp_parse(MachineState *ms, QemuOpts *opts, Error **errp) +static void pc_smp_parse(MachineState *ms, SMPConfiguration *config, Error= **errp) { - unsigned cpus =3D qemu_opt_get_number(opts, "cpus", 0); - unsigned sockets =3D qemu_opt_get_number(opts, "sockets", 0); - unsigned dies =3D qemu_opt_get_number(opts, "dies", 1); - unsigned cores =3D qemu_opt_get_number(opts, "cores", 0); - unsigned threads =3D qemu_opt_get_number(opts, "threads", 0); + unsigned cpus =3D config->has_cpus ? config->cpus : 0; + unsigned sockets =3D config->has_sockets ? config->sockets : 0; + unsigned dies =3D config->has_dies ? config->dies : 1; + unsigned cores =3D config->has_cores ? config->cores : 0; + unsigned threads =3D config->has_threads ? config->threads : 0; =20 /* compute missing values, prefer sockets over cores over threads */ if (cpus =3D=3D 0 || sockets =3D=3D 0) { @@ -726,8 +726,7 @@ static void pc_smp_parse(MachineState *ms, QemuOpts *op= ts, Error **errp) sockets =3D sockets > 0 ? sockets : 1; cpus =3D cores * threads * dies * sockets; } else { - ms->smp.max_cpus =3D - qemu_opt_get_number(opts, "maxcpus", cpus); + ms->smp.max_cpus =3D config->has_maxcpus ? config->maxcpus : c= pus; sockets =3D ms->smp.max_cpus / (cores * threads * dies); } } else if (cores =3D=3D 0) { @@ -745,8 +744,7 @@ static void pc_smp_parse(MachineState *ms, QemuOpts *op= ts, Error **errp) return; } =20 - ms->smp.max_cpus =3D - qemu_opt_get_number(opts, "maxcpus", cpus); + ms->smp.max_cpus =3D config->has_maxcpus ? config->maxcpus : cpus; =20 if (ms->smp.max_cpus < cpus) { error_setg(errp, "maxcpus must be equal to or greater than smp"); diff --git a/include/hw/boards.h b/include/hw/boards.h index 0483d6af86..1eae4427e8 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -210,7 +210,7 @@ struct MachineClass { void (*reset)(MachineState *state); void (*wakeup)(MachineState *state); int (*kvm_type)(MachineState *machine, const char *arg); - void (*smp_parse)(MachineState *ms, QemuOpts *opts, Error **errp); + void (*smp_parse)(MachineState *ms, SMPConfiguration *config, Error **= errp); =20 BlockInterfaceType block_default_type; int units_per_default_bus; diff --git a/qapi/machine.json b/qapi/machine.json index 58a9c86b36..53fd7e60ff 100644 --- a/qapi/machine.json +++ b/qapi/machine.json @@ -1274,3 +1274,30 @@ ## { 'event': 'MEM_UNPLUG_ERROR', 'data': { 'device': 'str', 'msg': 'str' } } + +## +# @SMPConfiguration: +# +# Schema for CPU topology configuration. +# +# @cpus: number of virtual CPUs in the virtual machine +# +# @sockets: number of sockets in the CPU topology +# +# @dies: number of dies per socket in the CPU topology +# +# @cores: number of cores per thread in the CPU topology +# +# @threads: number of threads per core in the CPU topology +# +# @maxcpus: maximum number of hotpluggable virtual CPUs in the virtual mac= hine +# +# Since: 6.1 +## +{ 'struct': 'SMPConfiguration', 'data': { + '*cpus': 'int', + '*sockets': 'int', + '*dies': 'int', + '*cores': 'int', + '*threads': 'int', + '*maxcpus': 'int' } } --=20 2.31.1 From nobody Fri May 10 17:18:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1623145906; cv=none; d=zohomail.com; s=zohoarc; b=dk4zRcQz2QkuD4GngvCqwz+V2YO0cdvROhtBJnDazq5zLL7LHnqvmwybJuLRKuTx/kbCFIRB5one/2Z3yJt6qpT57uGxumLVrk/6OJ7vUN3Z2lPsD7iKw3PT4nxX1GsYuIj6lDHPL018xlJJ+k5MVYgrPa9iFVPA9o09KaTtW2s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623145906; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qzpXFnyjgRnwQsHIuTfmXtl8Hzry0AV1o6f9R8rYdXg=; b=MsSPY7X23KgfH5lbK8dGSHdrHAfDIgISBmLL00IPVvNlF8/gweL1OB4ZHZsFk5xiyYPoDcY5v8sY3ynbcGhqvELKCoyz62tE+QsRcH+6+5uO2Gv94H4dgxQp9yUP6jvyQ4eoBgAIJaZmR+94RDQr1n6XQnbXiFK/C3QwAO0+vg4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623145906010934.8880141319336; Tue, 8 Jun 2021 02:51:46 -0700 (PDT) Received: from localhost ([::1]:37794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqYOe-0001EC-At for importer@patchew.org; Tue, 08 Jun 2021 05:51:44 -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) 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) 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- hw/core/machine.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/core/machine.c b/hw/core/machine.c index 9ad8341a31..ffc076ae84 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -746,6 +746,10 @@ static void smp_parse(MachineState *ms, SMPConfigurati= on *config, Error **errp) unsigned cores =3D config->has_cores ? config->cores : 0; unsigned threads =3D config->has_threads ? config->threads : 0; =20 + if (config->has_dies && config->dies !=3D 0 && config->dies !=3D 1) { + error_setg(errp, "dies not supported by this machine's CPU topolog= y"); + } + /* compute missing values, prefer sockets over cores over threads */ if (cpus =3D=3D 0 || sockets =3D=3D 0) { cores =3D cores > 0 ? cores : 1; --=20 2.31.1 From nobody Fri May 10 17:18:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1623145944; cv=none; d=zohomail.com; s=zohoarc; b=PJrU7HM9zFW4Rcc+jDUEL5paLQVMxJO0KhA//HO3231rAD8WL4x8LbOsv6pEoTcVTmp3vgHVLBmcfJmJoLciO5FnipWjAEGCRjJv1Q0C/o8QVq3zeIASMeMt1l0b2GYDK2uV6zglvV5ldCUSjZohGjAuiTK+Bp2e4YINTyeCg38= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623145944; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FCNtjuTxOkAzbUiMDrfyPIHmmLgaE5uOlsEoXeEtEHY=; b=dyDLQKpwoORm5VYVf0WMI81Z+1Jjx8tkoCb9Qo5Foz6NKWIIzBfnfP+On0Hq7MLkcaaoVtsBeMxNNQFgeJrEnMI3ObdwsICx/ipgHYfHp9HQW9j80fiPZFdMFLqpOQgfaRKJMa30AGFaLIhbaCUUMJhhdbpHplcA8H2GYfUnS1c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623145944644600.976865712829; Tue, 8 Jun 2021 02:52:24 -0700 (PDT) Received: from localhost ([::1]:40362 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqYPH-00031h-Cu for importer@patchew.org; Tue, 08 Jun 2021 05:52:23 -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) 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) 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Make -smp syntactic sugar for a compound property "-machine smp.{cores,threads,cpu,...}". machine_smp_parse is replaced by the setter for the property. numa-test will now cover the new syntax, while other tests still use -smp. Signed-off-by: Paolo Bonzini --- hw/core/machine.c | 108 +++++++++++++++++++++------------------- include/hw/boards.h | 1 - softmmu/vl.c | 33 +++++++++--- tests/qtest/numa-test.c | 22 ++++---- 4 files changed, 95 insertions(+), 69 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index ffc076ae84..c6ae89efec 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -19,6 +19,7 @@ #include "hw/loader.h" #include "qapi/error.h" #include "qapi/qapi-visit-common.h" +#include "qapi/qapi-visit-machine.h" #include "qapi/visitor.h" #include "hw/sysbus.h" #include "sysemu/cpus.h" @@ -798,6 +799,57 @@ static void smp_parse(MachineState *ms, SMPConfigurati= on *config, Error **errp) ms->smp.sockets =3D sockets; } =20 +static void machine_get_smp(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + MachineState *ms =3D MACHINE(obj); + SMPConfiguration *config =3D &(SMPConfiguration){ + .has_cores =3D true, .cores =3D ms->smp.cores, + .has_sockets =3D true, .sockets =3D ms->smp.sockets, + .has_dies =3D true, .dies =3D ms->smp.dies, + .has_threads =3D true, .threads =3D ms->smp.threads, + .has_cpus =3D true, .cpus =3D ms->smp.cpus, + .has_maxcpus =3D true, .maxcpus =3D ms->smp.max_cpus, + }; + if (!visit_type_SMPConfiguration(v, name, &config, &error_abort)) { + return; + } +} + +static void machine_set_smp(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + MachineClass *mc =3D MACHINE_GET_CLASS(obj); + MachineState *ms =3D MACHINE(obj); + SMPConfiguration *config; + ERRP_GUARD(); + + if (!visit_type_SMPConfiguration(v, name, &config, errp)) { + return; + } + + mc->smp_parse(ms, config, errp); + if (errp) { + goto out_free; + } + + /* sanity-check smp_cpus and max_cpus against mc */ + if (ms->smp.cpus < mc->min_cpus) { + error_setg(errp, "Invalid SMP CPUs %d. The min CPUs " + "supported by machine '%s' is %d", + ms->smp.cpus, + mc->name, mc->min_cpus); + } else if (ms->smp.max_cpus > mc->max_cpus) { + error_setg(errp, "Invalid SMP CPUs %d. The max CPUs " + "supported by machine '%s' is %d", + current_machine->smp.max_cpus, + mc->name, mc->max_cpus); + } + +out_free: + qapi_free_SMPConfiguration(config); +} + static void machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc =3D MACHINE_CLASS(oc); @@ -837,6 +889,12 @@ static void machine_class_init(ObjectClass *oc, void *= data) object_class_property_set_description(oc, "dumpdtb", "Dump current dtb to a file and quit"); =20 + object_class_property_add(oc, "smp", "SMPConfiguration", + machine_get_smp, machine_set_smp, + NULL, NULL); + object_class_property_set_description(oc, "smp", + "CPU topology"); + object_class_property_add(oc, "phandle-start", "int", machine_get_phandle_start, machine_set_phandle_start, NULL, NULL); @@ -1125,56 +1183,6 @@ MemoryRegion *machine_consume_memdev(MachineState *m= achine, return ret; } =20 -bool machine_smp_parse(MachineState *ms, QemuOpts *opts, Error **errp) -{ - MachineClass *mc =3D MACHINE_GET_CLASS(ms); - ERRP_GUARD(); - - if (opts) { - SMPConfiguration config =3D { - .has_cpus =3D !!qemu_opt_get(opts, "cpus"), - .cpus =3D qemu_opt_get_number(opts, "cpus", 0), - .has_sockets =3D !!qemu_opt_get(opts, "sockets"), - .sockets =3D qemu_opt_get_number(opts, "sockets", 0), - .has_dies =3D !!qemu_opt_get(opts, "dies"), - .dies =3D qemu_opt_get_number(opts, "dies", 0), - .has_cores =3D !!qemu_opt_get(opts, "cores"), - .cores =3D qemu_opt_get_number(opts, "cores", 0), - .has_threads =3D !!qemu_opt_get(opts, "threads"), - .threads =3D qemu_opt_get_number(opts, "threads", 0), - .has_maxcpus =3D !!qemu_opt_get(opts, "maxcpus"), - .maxcpus =3D qemu_opt_get_number(opts, "maxcpus", 0), - }; - - mc->smp_parse(ms, &config, errp); - if (*errp) { - return false; - } - } - - /* sanity-check smp_cpus and max_cpus against mc */ - if (ms->smp.cpus < mc->min_cpus) { - error_setg(errp, "Invalid SMP CPUs %d. The min CPUs " - "supported by machine '%s' is %d", - ms->smp.cpus, - mc->name, mc->min_cpus); - return false; - } else if (ms->smp.max_cpus > mc->max_cpus) { - error_setg(errp, "Invalid SMP CPUs %d. The max CPUs " - "supported by machine '%s' is %d", - current_machine->smp.max_cpus, - mc->name, mc->max_cpus); - return false; - } - - if (ms->smp.cpus > 1) { - Error *blocker =3D NULL; - error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, "smp"); - replay_add_blocker(blocker); - } - return true; -} - void machine_run_board_init(MachineState *machine) { MachineClass *machine_class =3D MACHINE_GET_CLASS(machine); diff --git a/include/hw/boards.h b/include/hw/boards.h index 1eae4427e8..accd6eff35 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -26,7 +26,6 @@ OBJECT_DECLARE_TYPE(MachineState, MachineClass, MACHINE) extern MachineState *current_machine; =20 void machine_run_board_init(MachineState *machine); -bool machine_smp_parse(MachineState *ms, QemuOpts *opts, Error **errp); bool machine_usb(MachineState *machine); int machine_phandle_start(MachineState *machine); bool machine_dump_guest_core(MachineState *machine); diff --git a/softmmu/vl.c b/softmmu/vl.c index c3686a6722..df91371b90 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -1523,6 +1523,25 @@ static void machine_help_func(const QDict *qdict) } } =20 +static void +machine_parse_property_opt(QemuOptsList *opts_list, const char *propname, + const char *arg, Error **errp) +{ + QDict *opts, *prop; + bool help =3D false; + ERRP_GUARD(); + + prop =3D keyval_parse(arg, opts_list->implied_opt_name, &help, errp); + if (help) { + qemu_opts_print_help(opts_list, true); + return; + } + opts =3D qdict_new(); + qdict_put(opts, propname, prop); + keyval_merge(machine_opts_dict, opts, errp); + qobject_unref(opts); +} + static const char *pid_file; static Notifier qemu_unlink_pidfile_notifier; =20 @@ -1833,6 +1852,12 @@ static void qemu_apply_machine_options(QDict *qdict) /* fall back to the -kernel/-append */ semihosting_arg_fallback(current_machine->kernel_filename, current= _machine->kernel_cmdline); } + + if (current_machine->smp.cpus > 1) { + Error *blocker =3D NULL; + error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, "smp"); + replay_add_blocker(blocker); + } } =20 static void qemu_create_early_backends(void) @@ -2074,9 +2099,6 @@ static void qemu_create_machine(QDict *qdict) qemu_set_hw_version(machine_class->hw_version); } =20 - machine_smp_parse(current_machine, - qemu_opts_find(qemu_find_opts("smp-opts"), NULL), &error_fatal); - /* * Get the default machine options from the machine if it is not alrea= dy * specified either by the configuration file or by the command line. @@ -3291,10 +3313,7 @@ void qemu_init(int argc, char **argv, char **envp) } break; case QEMU_OPTION_smp: - if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"), - optarg, true)) { - exit(1); - } + machine_parse_property_opt(qemu_find_opts("smp-opts"), "sm= p", optarg, &error_fatal); break; case QEMU_OPTION_vnc: vnc_parse(optarg); diff --git a/tests/qtest/numa-test.c b/tests/qtest/numa-test.c index dc0ec571ca..c677cd63c4 100644 --- a/tests/qtest/numa-test.c +++ b/tests/qtest/numa-test.c @@ -25,7 +25,7 @@ static void test_mon_explicit(const void *data) g_autofree char *s =3D NULL; g_autofree char *cli =3D NULL; =20 - cli =3D make_cli(data, "-smp 8 -numa node,nodeid=3D0,memdev=3Dram,cpus= =3D0-3 " + cli =3D make_cli(data, "-machine smp.cpus=3D8 -numa node,nodeid=3D0,me= mdev=3Dram,cpus=3D0-3 " "-numa node,nodeid=3D1,cpus=3D4-7"); qts =3D qtest_init(cli); =20 @@ -42,7 +42,7 @@ static void test_def_cpu_split(const void *data) g_autofree char *s =3D NULL; g_autofree char *cli =3D NULL; =20 - cli =3D make_cli(data, "-smp 8 -numa node,memdev=3Dram -numa node"); + cli =3D make_cli(data, "-machine smp.cpus=3D8 -numa node,memdev=3Dram = -numa node"); qts =3D qtest_init(cli); =20 s =3D qtest_hmp(qts, "info numa"); @@ -58,7 +58,7 @@ static void test_mon_partial(const void *data) g_autofree char *s =3D NULL; g_autofree char *cli =3D NULL; =20 - cli =3D make_cli(data, "-smp 8 " + cli =3D make_cli(data, "-machine smp.cpus=3D8 " "-numa node,nodeid=3D0,memdev=3Dram,cpus=3D0-1 " "-numa node,nodeid=3D1,cpus=3D4-5 "); qts =3D qtest_init(cli); @@ -86,7 +86,7 @@ static void test_query_cpus(const void *data) QTestState *qts; g_autofree char *cli =3D NULL; =20 - cli =3D make_cli(data, "-smp 8 -numa node,memdev=3Dram,cpus=3D0-3 " + cli =3D make_cli(data, "-machine smp.cpus=3D8 -numa node,memdev=3Dram,= cpus=3D0-3 " "-numa node,cpus=3D4-7"); qts =3D qtest_init(cli); cpus =3D get_cpus(qts, &resp); @@ -124,7 +124,7 @@ static void pc_numa_cpu(const void *data) QTestState *qts; g_autofree char *cli =3D NULL; =20 - cli =3D make_cli(data, "-cpu pentium -smp 8,sockets=3D2,cores=3D2,thre= ads=3D2 " + cli =3D make_cli(data, "-cpu pentium -machine smp.cpus=3D8,smp.sockets= =3D2,smp.cores=3D2,smp.threads=3D2 " "-numa node,nodeid=3D0,memdev=3Dram -numa node,nodeid=3D1 " "-numa cpu,node-id=3D1,socket-id=3D0 " "-numa cpu,node-id=3D0,socket-id=3D1,core-id=3D0 " @@ -177,7 +177,7 @@ static void spapr_numa_cpu(const void *data) QTestState *qts; g_autofree char *cli =3D NULL; =20 - cli =3D make_cli(data, "-smp 4,cores=3D4 " + cli =3D make_cli(data, "-machine smp.cpus=3D4,smp.cores=3D4 " "-numa node,nodeid=3D0,memdev=3Dram -numa node,nodeid=3D1 " "-numa cpu,node-id=3D0,core-id=3D0 " "-numa cpu,node-id=3D0,core-id=3D1 " @@ -222,7 +222,7 @@ static void aarch64_numa_cpu(const void *data) QTestState *qts; g_autofree char *cli =3D NULL; =20 - cli =3D make_cli(data, "-smp 2 " + cli =3D make_cli(data, "-machine smp.cpus=3D2 " "-numa node,nodeid=3D0,memdev=3Dram -numa node,nodeid=3D1 " "-numa cpu,node-id=3D1,thread-id=3D0 " "-numa cpu,node-id=3D0,thread-id=3D1"); @@ -265,7 +265,7 @@ static void pc_dynamic_cpu_cfg(const void *data) QTestState *qs; g_autofree char *cli =3D NULL; =20 - cli =3D make_cli(data, "-nodefaults --preconfig -smp 2"); + cli =3D make_cli(data, "-nodefaults --preconfig -machine smp.cpus=3D2"= ); qs =3D qtest_init(cli); =20 /* create 2 numa nodes */ @@ -324,7 +324,7 @@ static void pc_hmat_build_cfg(const void *data) g_autofree char *cli =3D NULL; =20 cli =3D make_cli(data, "-nodefaults --preconfig -machine hmat=3Don " - "-smp 2,sockets=3D2 " + "-machine smp.cpus=3D2,smp.sockets=3D2 " "-m 128M,slots=3D2,maxmem=3D1G " "-object memory-backend-ram,size=3D64M,id=3Dm0 " "-object memory-backend-ram,size=3D64M,id=3Dm1 " @@ -453,7 +453,7 @@ static void pc_hmat_off_cfg(const void *data) g_autofree char *cli =3D NULL; =20 cli =3D make_cli(data, "-nodefaults --preconfig " - "-smp 2,sockets=3D2 " + "-machine smp.cpus=3D2,smp.sockets=3D2 " "-m 128M,slots=3D2,maxmem=3D1G " "-object memory-backend-ram,size=3D64M,id=3Dm0,pr= ealloc=3Dy " "-object memory-backend-ram,size=3D64M,id=3Dm1 " @@ -492,7 +492,7 @@ static void pc_hmat_erange_cfg(const void *data) g_autofree char *cli =3D NULL; =20 cli =3D make_cli(data, "-nodefaults --preconfig -machine hmat=3Don " - "-smp 2,sockets=3D2 " + "-machine smp.cpus=3D2,smp.sockets=3D2 " "-m 128M,slots=3D2,maxmem=3D1G " "-object memory-backend-ram,size=3D64M,id=3Dm0 " "-object memory-backend-ram,size=3D64M,id=3Dm1 " --=20 2.31.1 From nobody Fri May 10 17:18:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1623146024; cv=none; d=zohomail.com; s=zohoarc; b=E/fPdFG38vCnNdXBe8jedBwAEst13wtGGiqCOGhADdtcXxFiyOJLi7FawfswyFODBEWYwEKfgqfUBIJNoAZzxz4ByqsGr7V1Z/cUm4u6n7ueffo8xXmMJVhuUUGVJTHYpAeslyaBr+XAZ+/0R4z1XDeTACkqnk+2egw7y2EqRpw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623146024; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Vv2J1Eu+1Gs3q5FfU3Miy7oOhq4eBNKPYhz6liN5ugY=; b=OMT7hHLD31kTEQRpKVCt9hCqzbRHeqMqLM7zAPo/ofY2Xo7W+F0IWQtyH3JIGjlDK6g8GD/OG8uF12Tp4mRoB/5gjMwPn2jvmXHUo3KJy22tKCsvtQ0zp9YSyb3ZBHfDiPdi9C+DuIzYLmn47yZ/XLt1r1mLH1IYePyEOD4ERog= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623146024310900.298533047472; Tue, 8 Jun 2021 02:53:44 -0700 (PDT) Received: from localhost ([::1]:44288 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqYQZ-0005dQ-3e for importer@patchew.org; Tue, 08 Jun 2021 05:53:43 -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) 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) 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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" =20 +/* + * 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) =20 =20 +bool vnc_sasl_server_init(Error **errp) +{ + int saslErr =3D sasl_server_init(NULL, "qemu"); + + if (saslErr !=3D 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; }; =20 +bool vnc_sasl_server_init(Error **errp); void vnc_sasl_client_cleanup(VncState *vs); =20 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); =20 #ifdef CONFIG_VNC_SASL - if (sasl) { - int saslErr =3D sasl_server_init(NULL, "qemu"); - - if (saslErr !=3D 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 =3D lock_key_sync; --=20 2.31.1