From nobody Thu Nov 14 03:52:46 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=1621352943; cv=none; d=zohomail.com; s=zohoarc; b=LIzXjrXA/Y2hNxT2q76SUfBN9YH362Ps20NFOlsf+fcgr59lnu40cFuF7FGEKsmAvrAECkUMsbZ+w91zWBZz5d/LDYxZTmamsC2xM+8DyOJ7wM+EIttb0BvqadPlM9pz9H7yipkUXv4UjV9Aixewr8aRZzcfrWPxhyrmvjgEkus= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621352943; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0Cf6e+Y5ot/AxBT6FqZun54LmULu1mWtZOyAxZ5I6Ng=; b=XIEdb7CYisXGL385sbLUw437/byaizaOVWqyF7V5nwkJClu2vIDIvKAl+UJCS0Fg9a9plGb7UP6uGO+a7w1qxX+9WKTuBkWejnVKhF5FCA6rmLd5eicehqtEQM1mvFqqbCt6JO7F9YI5R+zg1HdIihq2I2ppIuHgDm3fr4+BcnI= 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 1621352943165809.8297043728317; Tue, 18 May 2021 08:49:03 -0700 (PDT) Received: from localhost ([::1]:58394 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lj1xu-000264-0v for importer@patchew.org; Tue, 18 May 2021 11:49:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40158) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lj1qm-0001EZ-2B for qemu-devel@nongnu.org; Tue, 18 May 2021 11:41:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:20492) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lj1qi-0007TL-L3 for qemu-devel@nongnu.org; Tue, 18 May 2021 11:41:39 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-63-MZyOJsrhOaqUs2AuM9nPww-1; Tue, 18 May 2021 11:41:33 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AC93818397BD; Tue, 18 May 2021 15:41:00 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3C12219D7C; Tue, 18 May 2021 15:41:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621352496; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0Cf6e+Y5ot/AxBT6FqZun54LmULu1mWtZOyAxZ5I6Ng=; b=bGIFLUcll830ZHZ20iKEZ5Is1gBFlU8WOaBuF4nOHjXU5gdnEr4UBOyk4WofbqZw7D5H3j okdp2zZzqJthzeCAPw3j9Ynyap23YVz0/Ml04cfAGoG0XnOuFLP+ue1Ffu7Rvgv23hQj58 X2uKwND+7j3ZOG5w1wT0MZTLZGscig4= X-MC-Unique: MZyOJsrhOaqUs2AuM9nPww-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 1/3] qemu-config: parse configuration files to a QDict Date: Tue, 18 May 2021 11:40:57 -0400 Message-Id: <20210518154059.3002446-1-pbonzini@redhat.com> In-Reply-To: <20210518154014.2999326-1-pbonzini@redhat.com> References: <20210518154014.2999326-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.374, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, armbru@redhat.com, qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Change the parser to put the values into a QDict and pass them to a callback. qemu_config_parse's QemuOpts creation is itself turned into a callback function. This is useful for -readconfig to support keyval-based options; getting a QDict from the parser removes a roundtrip from QDict to QemuOpts and then back to QDict. Cc: Kevin Wolf Cc: Markus Armbruster Cc: qemu-stable@nongnu.org Signed-off-by: Paolo Bonzini --- include/qemu/config-file.h | 7 ++- softmmu/vl.c | 4 +- util/qemu-config.c | 91 +++++++++++++++++++++++++------------- 3 files changed, 69 insertions(+), 33 deletions(-) diff --git a/include/qemu/config-file.h b/include/qemu/config-file.h index 0500b3668d..f605423321 100644 --- a/include/qemu/config-file.h +++ b/include/qemu/config-file.h @@ -1,6 +1,8 @@ #ifndef QEMU_CONFIG_FILE_H #define QEMU_CONFIG_FILE_H =20 +typedef void QEMUConfigCB(const char *group, QDict *qdict, void *opaque, E= rror **errp); + void qemu_load_module_for_opts(const char *group); QemuOptsList *qemu_find_opts(const char *group); QemuOptsList *qemu_find_opts_err(const char *group, Error **errp); @@ -14,7 +16,10 @@ void qemu_config_write(FILE *fp); int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname, Error **errp); =20 -int qemu_read_config_file(const char *filename, Error **errp); +/* A default callback for qemu_read_config_file(). */ +void qemu_config_do_parse(const char *group, QDict *qdict, void *opaque, E= rror **errp); + +int qemu_read_config_file(const char *filename, QEMUConfigCB *f, Error **e= rrp); =20 /* Parse QDict options as a replacement for a config file (allowing multip= le enumerated (0..(n-1)) configuration "sections") */ diff --git a/softmmu/vl.c b/softmmu/vl.c index d55424e634..594de0864c 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -2121,7 +2121,7 @@ static void qemu_read_default_config_file(Error **err= p) int ret; g_autofree char *file =3D get_relocated_path(CONFIG_QEMU_CONFDIR "/qem= u.conf"); =20 - ret =3D qemu_read_config_file(file, errp); + ret =3D qemu_read_config_file(file, qemu_config_do_parse, errp); if (ret < 0) { if (ret =3D=3D -ENOENT) { error_free(*errp); @@ -3387,7 +3387,7 @@ void qemu_init(int argc, char **argv, char **envp) qemu_plugin_opt_parse(optarg, &plugin_list); break; case QEMU_OPTION_readconfig: - qemu_read_config_file(optarg, &error_fatal); + qemu_read_config_file(optarg, qemu_config_do_parse, &error= _fatal); break; case QEMU_OPTION_spice: olist =3D qemu_find_opts_err("spice", NULL); diff --git a/util/qemu-config.c b/util/qemu-config.c index 34974c4b47..7bca153c6c 100644 --- a/util/qemu-config.c +++ b/util/qemu-config.c @@ -351,19 +351,19 @@ void qemu_config_write(FILE *fp) } =20 /* Returns number of config groups on success, -errno on error */ -int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname, E= rror **errp) +static int qemu_config_foreach(FILE *fp, QEMUConfigCB *cb, void *opaque, + const char *fname, Error **errp) { - char line[1024], group[64], id[64], arg[64], value[1024]; + char line[1024], prev_group[64], group[64], arg[64], value[1024]; Location loc; - QemuOptsList *list =3D NULL; Error *local_err =3D NULL; - QemuOpts *opts =3D NULL; + QDict *qdict =3D NULL; int res =3D -EINVAL, lno =3D 0; int count =3D 0; =20 loc_push_none(&loc); while (fgets(line, sizeof(line), fp) !=3D NULL) { - loc_set_file(fname, ++lno); + ++lno; if (line[0] =3D=3D '\n') { /* skip empty lines */ continue; @@ -372,39 +372,39 @@ int qemu_config_parse(FILE *fp, QemuOptsList **lists,= const char *fname, Error * /* comment */ continue; } - if (sscanf(line, "[%63s \"%63[^\"]\"]", group, id) =3D=3D 2) { - /* group with id */ - list =3D find_list(lists, group, &local_err); - if (local_err) { - error_propagate(errp, local_err); - goto out; + if (line[0] =3D=3D '[') { + QDict *prev =3D qdict; + if (sscanf(line, "[%63s \"%63[^\"]\"]", group, value) =3D=3D 2= ) { + qdict =3D qdict_new(); + qdict_put_str(qdict, "id", value); + count++; + } else if (sscanf(line, "[%63[^]]]", group) =3D=3D 1) { + qdict =3D qdict_new(); + count++; } - opts =3D qemu_opts_create(list, id, 1, NULL); - count++; - continue; - } - if (sscanf(line, "[%63[^]]]", group) =3D=3D 1) { - /* group without id */ - list =3D find_list(lists, group, &local_err); - if (local_err) { - error_propagate(errp, local_err); - goto out; + if (qdict !=3D prev) { + if (prev) { + cb(prev_group, prev, opaque, &local_err); + qobject_unref(prev); + if (local_err) { + error_propagate(errp, local_err); + goto out; + } + } + strcpy(prev_group, group); + continue; } - opts =3D qemu_opts_create(list, NULL, 0, &error_abort); - count++; - continue; } + loc_set_file(fname, lno); value[0] =3D '\0'; if (sscanf(line, " %63s =3D \"%1023[^\"]\"", arg, value) =3D=3D 2 = || sscanf(line, " %63s =3D \"\"", arg) =3D=3D 1) { /* arg =3D value */ - if (opts =3D=3D NULL) { + if (qdict =3D=3D NULL) { error_setg(errp, "no group defined"); goto out; } - if (!qemu_opt_set(opts, arg, value, errp)) { - goto out; - } + qdict_put_str(qdict, arg, value); continue; } error_setg(errp, "parse error"); @@ -418,10 +418,41 @@ int qemu_config_parse(FILE *fp, QemuOptsList **lists,= const char *fname, Error * res =3D count; out: loc_pop(&loc); + if (qdict) { + cb(group, qdict, opaque, errp); + qobject_unref(qdict); + } return res; } =20 -int qemu_read_config_file(const char *filename, Error **errp) +void qemu_config_do_parse(const char *group, QDict *qdict, void *opaque, E= rror **errp) +{ + QemuOptsList **lists =3D opaque; + const char *id =3D qdict_get_try_str(qdict, "id"); + QemuOptsList *list; + QemuOpts *opts; + + list =3D find_list(lists, group, errp); + if (!list) { + return; + } + + opts =3D qemu_opts_create(list, id, 1, errp); + if (!opts) { + return; + } + if (id) { + qdict_del(qdict, "id"); + } + qemu_opts_absorb_qdict(opts, qdict, errp); +} + +int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname, E= rror **errp) +{ + return qemu_config_foreach(fp, qemu_config_do_parse, lists, fname, err= p); +} + +int qemu_read_config_file(const char *filename, QEMUConfigCB *cb, Error **= errp) { FILE *f =3D fopen(filename, "r"); int ret; @@ -431,7 +462,7 @@ int qemu_read_config_file(const char *filename, Error *= *errp) return -errno; } =20 - ret =3D qemu_config_parse(f, vm_config_groups, filename, errp); + ret =3D qemu_config_foreach(f, cb, vm_config_groups, filename, errp); fclose(f); return ret; } --=20 2.27.0 From nobody Thu Nov 14 03:52:46 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=1621353336; cv=none; d=zohomail.com; s=zohoarc; b=K3eQR9RPl+VUoIAsI5gJfdyiHcZ/rDIrcjnIr4XZCErqLxY962eo1g9nb2pkkR0Bjwxa6ZMV27hSLAeAaN4ACQ0JIflCModNaC/RIcRR6IV+d96RWioAiJyelvt39tdxliaaTPCKWPBUe95mGmAkbyExPECTsRQiiiyFMHS9C0M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621353336; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EI75Wngm50NJ9cQwdqZUt8vyqRv0F1YvqlD1nnOx2Lc=; b=gT6J9K/wHKulzbMozGIMxlDL8PFzW7qlYSQwfWXdYlI0IT4PGHiaSuQarAP6yg5AOqb0R+sCOPKDhAOjFpBuKhGhZqEqIpopwmQ729zNP0fUKr5SnmUj4JvD2ML5YAvyT2ZcyaGIxvyrwp7/jm63CG9Sgm25XHVshPur6uWWl1Y= 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 1621353336569842.5476950349188; Tue, 18 May 2021 08:55:36 -0700 (PDT) Received: from localhost ([::1]:46364 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lj24F-000678-KC for importer@patchew.org; Tue, 18 May 2021 11:55:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40112) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lj1qj-000169-5M for qemu-devel@nongnu.org; Tue, 18 May 2021 11:41:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:39449) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lj1qh-0007Ry-6J for qemu-devel@nongnu.org; Tue, 18 May 2021 11:41:36 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-524-RP2m1Z6fNHWS6DIKfeiC6A-1; Tue, 18 May 2021 11:41:32 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4AEFFA40C3; Tue, 18 May 2021 15:41:01 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id D14302ED8A; Tue, 18 May 2021 15:41:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621352494; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EI75Wngm50NJ9cQwdqZUt8vyqRv0F1YvqlD1nnOx2Lc=; b=W50Xzbr7MviKPMSVUR4xbc8HfcG9FRXMOK+GXp9bT6j6tRYr7j9fjAQg5UXhzWR88n054X NE8KTDKjo+wnhkwR2xTZ/1Elk5O/PvRLbz/BMSfQ1NFqDlvqV4NVKjsq+4KkSWlyV/3Bl1 Y+CwWuf4hBgTtq+GLBUZSHaelzGOj00= X-MC-Unique: RP2m1Z6fNHWS6DIKfeiC6A-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 2/3] vl: plumb keyval-based options into -readconfig Date: Tue, 18 May 2021 11:40:58 -0400 Message-Id: <20210518154059.3002446-2-pbonzini@redhat.com> In-Reply-To: <20210518154014.2999326-1-pbonzini@redhat.com> References: <20210518154014.2999326-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.374, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, armbru@redhat.com, qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Let -readconfig support parsing configuration file groups into QDict in addition to the previous behavior of recording them into QemuOpts. This will be used to add back support for objects in -readconfig. Cc: Kevin Wolf Cc: Markus Armbruster Cc: qemu-stable@nongnu.org Signed-off-by: Paolo Bonzini --- include/block/qdict.h | 2 - include/qapi/qmp/qdict.h | 3 ++ softmmu/vl.c | 82 ++++++++++++++++++++++++++++------------ 3 files changed, 61 insertions(+), 26 deletions(-) diff --git a/include/block/qdict.h b/include/block/qdict.h index d8cb502d7d..ced2acfb92 100644 --- a/include/block/qdict.h +++ b/include/block/qdict.h @@ -20,8 +20,6 @@ void qdict_join(QDict *dest, QDict *src, bool overwrite); void qdict_extract_subqdict(QDict *src, QDict **dst, const char *start); void qdict_array_split(QDict *src, QList **dst); int qdict_array_entries(QDict *src, const char *subqdict); -QObject *qdict_crumple(const QDict *src, Error **errp); -void qdict_flatten(QDict *qdict); =20 typedef struct QDictRenames { const char *from; diff --git a/include/qapi/qmp/qdict.h b/include/qapi/qmp/qdict.h index 9934539c1b..d5b5430e21 100644 --- a/include/qapi/qmp/qdict.h +++ b/include/qapi/qmp/qdict.h @@ -64,4 +64,7 @@ const char *qdict_get_try_str(const QDict *qdict, const c= har *key); =20 QDict *qdict_clone_shallow(const QDict *src); =20 +QObject *qdict_crumple(const QDict *src, Error **errp); +void qdict_flatten(QDict *qdict); + #endif /* QDICT_H */ diff --git a/softmmu/vl.c b/softmmu/vl.c index 594de0864c..90e491cc0c 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -121,6 +121,7 @@ #include "qapi/qapi-commands-misc.h" #include "qapi/qapi-visit-qom.h" #include "qapi/qapi-commands-ui.h" +#include "qapi/qmp/qdict.h" #include "qapi/qmp/qerror.h" #include "sysemu/iothread.h" #include "qemu/guest-random.h" @@ -2115,13 +2116,52 @@ static int global_init_func(void *opaque, QemuOpts = *opts, Error **errp) return 0; } =20 +/* + * Return whether configuration group @group is stored in QemuOpts, or + * recorded as one or more QDicts by qemu_record_config_group. + */ +static bool is_qemuopts_group(const char *group) +{ + return true; +} + +static void qemu_record_config_group(const char *group, QDict *dict, bool = from_json, Error **errp) +{ + abort(); +} + +/* + * Parse non-QemuOpts config file groups, pass the rest to + * qemu_config_do_parse. + */ +static void qemu_parse_config_group(const char *group, QDict *qdict, + void *opaque, Error **errp) +{ + QObject *crumpled; + if (is_qemuopts_group(group)) { + qemu_config_do_parse(group, qdict, opaque, errp); + return; + } + + crumpled =3D qdict_crumple(qdict, errp); + if (!crumpled) { + return; + } + if (qobject_type(crumpled) !=3D QTYPE_QDICT) { + assert(qobject_type(crumpled) =3D=3D QTYPE_QLIST); + error_setg(errp, "Lists cannot be at top level of a configuration = section"); + return; + } + qemu_record_config_group(group, qobject_to(QDict, crumpled), false, er= rp); +} + static void qemu_read_default_config_file(Error **errp) { ERRP_GUARD(); int ret; g_autofree char *file =3D get_relocated_path(CONFIG_QEMU_CONFDIR "/qem= u.conf"); =20 - ret =3D qemu_read_config_file(file, qemu_config_do_parse, errp); + ret =3D qemu_read_config_file(file, qemu_parse_config_group, errp); if (ret < 0) { if (ret =3D=3D -ENOENT) { error_free(*errp); @@ -2130,9 +2170,8 @@ static void qemu_read_default_config_file(Error **err= p) } } =20 -static int qemu_set_option(const char *str) +static void qemu_set_option(const char *str, Error **errp) { - Error *local_err =3D NULL; char group[64], id[64], arg[64]; QemuOptsList *list; QemuOpts *opts; @@ -2140,27 +2179,23 @@ static int qemu_set_option(const char *str) =20 rc =3D sscanf(str, "%63[^.].%63[^.].%63[^=3D]%n", group, id, arg, &off= set); if (rc < 3 || str[offset] !=3D '=3D') { - error_report("can't parse: \"%s\"", str); - return -1; - } - - list =3D qemu_find_opts(group); - if (list =3D=3D NULL) { - return -1; - } - - opts =3D qemu_opts_find(list, id); - if (!opts) { - error_report("there is no %s \"%s\" defined", - list->name, id); - return -1; + error_setg(errp, "can't parse: \"%s\"", str); + return; } =20 - if (!qemu_opt_set(opts, arg, str + offset + 1, &local_err)) { - error_report_err(local_err); - return -1; + if (!is_qemuopts_group(group)) { + error_setg(errp, "-set is not supported with %s", group); + } else { + list =3D qemu_find_opts_err(group, errp); + if (list) { + opts =3D qemu_opts_find(list, id); + if (!opts) { + error_setg(errp, "there is no %s \"%s\" defined", group, i= d); + return; + } + qemu_opt_set(opts, arg, str + offset + 1, errp); + } } - return 0; } =20 static void user_register_global_props(void) @@ -2754,8 +2789,7 @@ void qemu_init(int argc, char **argv, char **envp) } break; case QEMU_OPTION_set: - if (qemu_set_option(optarg) !=3D 0) - exit(1); + qemu_set_option(optarg, &error_fatal); break; case QEMU_OPTION_global: if (qemu_global_option(optarg) !=3D 0) @@ -3387,7 +3421,7 @@ void qemu_init(int argc, char **argv, char **envp) qemu_plugin_opt_parse(optarg, &plugin_list); break; case QEMU_OPTION_readconfig: - qemu_read_config_file(optarg, qemu_config_do_parse, &error= _fatal); + qemu_read_config_file(optarg, qemu_parse_config_group, &er= ror_fatal); break; case QEMU_OPTION_spice: olist =3D qemu_find_opts_err("spice", NULL); --=20 2.27.0 From nobody Thu Nov 14 03:52:46 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=1621353005; cv=none; d=zohomail.com; s=zohoarc; b=kenAdkKmMlt4pa7dvAkWHaxdjJlZKb/t71zdz8+xRM+QezwytXPbo5YxuWPfz5x3dDy1rjVp+WSSdPd11UwSrCqcGLJmH0H+Dx/3Dyy5NWKKqqW7+7O/XcnHDpnFbbeJj7co2eVgUbVp6xkHIsckgh8NsNGXAihZI3YGeTufUmQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621353005; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=43vNoQO6grH4MkSSW/tNt26aVpHvhL/3pAIxOBZf714=; b=EWom9jDrg9L5/hpJldAkmJZMLiiPGpOHHJBbNErBUqI1m68YDvr3oQzS5cM+429ObbZCZ4hdWE45NyhK/vKpnqJ1SzEdHNK6TG8/ORUkGdmeDsrDYcb58/1fYh8zBv2GtoWei6PF0mYL2fKi48T5fme+YB45TEENyJuUuvCEvvY= 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 1621353005914549.4579677453049; Tue, 18 May 2021 08:50:05 -0700 (PDT) Received: from localhost ([::1]:60662 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lj1yu-0003jy-O6 for importer@patchew.org; Tue, 18 May 2021 11:50:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40086) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lj1qh-000101-1Z for qemu-devel@nongnu.org; Tue, 18 May 2021 11:41:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:21445) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lj1qe-0007Oi-9b for qemu-devel@nongnu.org; Tue, 18 May 2021 11:41:34 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-203-Pd2lPYdHMHWDkO5i2mgx1g-1; Tue, 18 May 2021 11:41:29 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E6FAC1034B56; Tue, 18 May 2021 15:41:01 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6CC8434810; Tue, 18 May 2021 15:41:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621352491; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=43vNoQO6grH4MkSSW/tNt26aVpHvhL/3pAIxOBZf714=; b=LiHZ2NQW1suiS1nw6XG6k6y+87SRYZpWjM9uw6KUT5iTz0V+3hYGadjMe8FVX7yU58MzzG GT8jTWs0DtsDogvMuzJ2xj2hyKs2LZk8O8jk9mqVBmMwDfqN5SApBHXP9bv8kjJyGP3tQO RAEsYqjPx8zV6KmkFE/rKXvB5JmXZZs= X-MC-Unique: Pd2lPYdHMHWDkO5i2mgx1g-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 3/3] vl: plug -object back into -readconfig Date: Tue, 18 May 2021 11:40:59 -0400 Message-Id: <20210518154059.3002446-3-pbonzini@redhat.com> In-Reply-To: <20210518154014.2999326-1-pbonzini@redhat.com> References: <20210518154014.2999326-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.374, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, armbru@redhat.com, qemu-stable@nongnu.org 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" Commit bc2f4fcb1d ("qom: move user_creatable_add_opts logic to vl.c and QAPIfy it", 2021-03-19) switched the creation of objects from qemu_opts_foreach to a bespoke QTAILQ in preparation for supporting JSON syntax in -object. Unfortunately in doing so it lost support for [object] stanzas in configuration files and also for "-set object.ID.KEY=3DVAL". The latter is hard to re-establish and probably best solved by deprecating -set. This patch uses the infrastructure introduced by the previous two patches in order to parse QOM objects correctly from configuration files. Cc: Kevin Wolf Cc: Markus Armbruster Cc: qemu-stable@nongnu.org Signed-off-by: Paolo Bonzini --- softmmu/vl.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/softmmu/vl.c b/softmmu/vl.c index 90e491cc0c..a8abf8e740 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -1708,9 +1708,15 @@ static void object_option_foreach_add(bool (*type_op= t_predicate)(const char *)) } } =20 +static void object_option_add_visitor(Visitor *v) +{ + ObjectOption *opt =3D g_new0(ObjectOption, 1); + visit_type_ObjectOptions(v, NULL, &opt->opts, &error_fatal); + QTAILQ_INSERT_TAIL(&object_opts, opt, next); +} + static void object_option_parse(const char *optarg) { - ObjectOption *opt; QemuOpts *opts; const char *type; Visitor *v; @@ -1738,11 +1744,8 @@ static void object_option_parse(const char *optarg) v =3D opts_visitor_new(opts); } =20 - opt =3D g_new0(ObjectOption, 1); - visit_type_ObjectOptions(v, NULL, &opt->opts, &error_fatal); + object_option_add_visitor(v); visit_free(v); - - QTAILQ_INSERT_TAIL(&object_opts, opt, next); } =20 /* @@ -2122,12 +2125,21 @@ static int global_init_func(void *opaque, QemuOpts = *opts, Error **errp) */ static bool is_qemuopts_group(const char *group) { + if (g_str_equal(group, "object")) { + return false; + } return true; } =20 static void qemu_record_config_group(const char *group, QDict *dict, bool = from_json, Error **errp) { - abort(); + if (g_str_equal(group, "object")) { + Visitor *v =3D qobject_input_visitor_new_keyval(QOBJECT(dict)); + object_option_add_visitor(v); + visit_free(v); + } else { + abort(); + } } =20 /* --=20 2.27.0