From nobody Sun May 19 08:30:49 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=1591625285; cv=none; d=zohomail.com; s=zohoarc; b=PgdpaIC6bL/bYHnb3hRmGlfdBtHi4ieaDsBTF2yB+tE2O6AcBuiLaobVh9GCxFKInq0UdAweETB3owyHkWocEc3ZIDOlBkcSbuO1IYsEHKYix3FB5M9SUxikEl3herJVl55MoffV0fLEnbpBjE8Df4og/esQQFG5H7YD0qmitSI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591625285; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=E73iYbdemzWE1AkNOjHlNMnKmCrTX1tlgwbyjII/ias=; b=kfMCNOullW6fW1dTCVYunAYvC3PVttuJs0gEE4JTqFKqzB6bD8CssT+xAL6dnLswivIUxRmJmrhZLfqS7zPUWEupWrDUqAgf3INNlkXuZauoAbA9685SOyriE50cfgfIkv7yXm/0ZkpZj7e1YZpZ8G7i3MKvWknpZWe/QrwVaZU= 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 1591625285460844.0215932964627; Mon, 8 Jun 2020 07:08:05 -0700 (PDT) Received: from localhost ([::1]:38598 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jiIRY-0003gY-0R for importer@patchew.org; Mon, 08 Jun 2020 10:08:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52108) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jiIQc-0003FX-RD for qemu-devel@nongnu.org; Mon, 08 Jun 2020 10:07:06 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:59228 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jiIQb-0002pT-8G for qemu-devel@nongnu.org; Mon, 08 Jun 2020 10:07:06 -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-495-Wt7fFKz2O7KEQ-Dz3-euvg-1; Mon, 08 Jun 2020 10:06:57 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8061A1940926 for ; Mon, 8 Jun 2020 14:06:56 +0000 (UTC) Received: from t480s.redhat.com (ovpn-113-136.ams2.redhat.com [10.36.113.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id CD9F97F4DF; Mon, 8 Jun 2020 14:06:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591625223; 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; bh=E73iYbdemzWE1AkNOjHlNMnKmCrTX1tlgwbyjII/ias=; b=hredRZhp6gy4oI3fDjDkjt08mLhF661wA/F28iuewCW8hwNKx0yCTe9GXr24aGKrZqb+ui UsG8KwLhEisIRjI/PF+TEZdnOq/WiwST54aDqPHrtbue8LZoI4AGJWqeY+7eNgPd+BBY9F hgzALoq4l5PvO78LQblsbvXNYpUFXCc= X-MC-Unique: Wt7fFKz2O7KEQ-Dz3-euvg-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v1] hmp: Make json format optional for qom-set Date: Mon, 8 Jun 2020 16:06:50 +0200 Message-Id: <20200608140650.91517-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=207.211.31.120; envelope-from=david@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/08 05:40:56 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , David Hildenbrand , Markus Armbruster , "Dr . David Alan Gilbert" , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Commit 7d2ef6dcc1cf ("hmp: Simplify qom-set") switched to the json parser, making it possible to specify complex types. However, with this change it is no longer possible to specify proper sizes (e.g., 2G, 128M), turning the interface harder to use for properties that consume sizes. Let's switch back to the previous handling and allow to specify passing json via the "-j" parameter. Cc: Philippe Mathieu-Daud=C3=A9 Cc: Markus Armbruster Cc: Dr. David Alan Gilbert Cc: Paolo Bonzini Cc: "Daniel P. Berrang=C3=A9" Cc: Eduardo Habkost Signed-off-by: David Hildenbrand --- An alternative would be to teach the json parser about sizes. But I am not completely sure if that is desirable. I make excessive use of qom-set with size properties in virtio-mem. --- hmp-commands.hx | 7 ++++--- qom/qom-hmp-cmds.c | 20 ++++++++++++++++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/hmp-commands.hx b/hmp-commands.hx index 28256209b5..b44f220c3e 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1806,9 +1806,10 @@ ERST =20 { .name =3D "qom-set", - .args_type =3D "path:s,property:s,value:S", - .params =3D "path property value", - .help =3D "set QOM property", + .args_type =3D "json:-j,path:s,property:s,value:s", + .params =3D "[-j] path property value", + .help =3D "set QOM property.\n\t\t\t" + "-j: the property is specified in json format.", .cmd =3D hmp_qom_set, .flags =3D "p", }, diff --git a/qom/qom-hmp-cmds.c b/qom/qom-hmp-cmds.c index f704b6949a..a794e62f0b 100644 --- a/qom/qom-hmp-cmds.c +++ b/qom/qom-hmp-cmds.c @@ -44,15 +44,27 @@ void hmp_qom_list(Monitor *mon, const QDict *qdict) =20 void hmp_qom_set(Monitor *mon, const QDict *qdict) { + const bool json =3D qdict_get_try_bool(qdict, "json", false); const char *path =3D qdict_get_str(qdict, "path"); const char *property =3D qdict_get_str(qdict, "property"); const char *value =3D qdict_get_str(qdict, "value"); Error *err =3D NULL; - QObject *obj; =20 - obj =3D qobject_from_json(value, &err); - if (err =3D=3D NULL) { - qmp_qom_set(path, property, obj, &err); + if (!json) { + Object *obj =3D object_resolve_path(path, NULL); + + if (!obj) { + error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", path); + } else { + object_property_parse(obj, value, property, &err); + } + } else { + QObject *obj =3D qobject_from_json(value, &err); + + if (!err) { + qmp_qom_set(path, property, obj, &err); + } } =20 hmp_handle_error(mon, err); --=20 2.26.2