From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: "Markus Armbruster" <armbru@redhat.com>,
"Daniel P . Berrangé" <berrange@redhat.com>,
"Dr. David Alan Gilbert" <dave@treblig.org>,
qemu-devel@nongnu.org
Cc: "Yanan Wang" <wangyanan55@huawei.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Eric Farman" <farman@linux.ibm.com>,
"Thomas Huth" <thuth@redhat.com>,
"Eric Blake" <eblake@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Christian Borntraeger" <borntraeger@linux.ibm.com>,
qemu-s390x@nongnu.org, "Eduardo Habkost" <eduardo@habkost.net>,
"Ilya Leoshkevich" <iii@linux.ibm.com>,
"Halil Pasic" <pasic@linux.ibm.com>,
"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
"David Hildenbrand" <david@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>
Subject: [RFC PATCH 3/3] hw/s390x: Introduce x-query-s390x-cmma QMP command
Date: Mon, 10 Jun 2024 19:58:52 +0200 [thread overview]
Message-ID: <20240610175852.21215-4-philmd@linaro.org> (raw)
In-Reply-To: <20240610175852.21215-1-philmd@linaro.org>
This is a counterpart to the HMP "info cmma" command. It is being
added with an "x-" prefix because this QMP command is intended as an
adhoc debugging tool and will thus not be modelled in QAPI as fully
structured data, nor will it have long term guaranteed stability.
The existing HMP command is rewritten to call the QMP command.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
qapi/machine.json | 20 ++++++++++++++++++++
hw/s390x/s390-stattrib.c | 28 ++++++++++++++++++----------
hmp-commands-info.hx | 2 +-
3 files changed, 39 insertions(+), 11 deletions(-)
diff --git a/qapi/machine.json b/qapi/machine.json
index 6da72f2585..a56b7572b1 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -1905,3 +1905,23 @@
'data': { 'json-args': 'str'},
'returns': 'HumanReadableText',
'features': [ 'unstable' ]}
+
+##
+# @x-query-s390x-cmma:
+#
+# Query information on s390x CMMA storage attributes
+#
+# @json-args: HMP arguments encoded as JSON string.
+#
+# Features:
+#
+# @unstable: This command is meant for debugging.
+#
+# Returns: s390x CMMA storage attributes information
+#
+# Since: 9.1
+##
+{ 'command': 'x-query-s390x-cmma',
+ 'data': { 'json-args': 'str'},
+ 'returns': 'HumanReadableText',
+ 'features': [ 'unstable' ]}
diff --git a/hw/s390x/s390-stattrib.c b/hw/s390x/s390-stattrib.c
index 9b4b8d8d0c..8c2372bd71 100644
--- a/hw/s390x/s390-stattrib.c
+++ b/hw/s390x/s390-stattrib.c
@@ -19,6 +19,9 @@
#include "exec/ram_addr.h"
#include "qapi/error.h"
#include "qapi/qmp/qdict.h"
+#include "qapi/qapi-commands-machine.h"
+#include "qapi/qmp/qjson.h"
+#include "qapi/type-helpers.h"
#include "monitor/hmp-target.h"
#include "monitor/monitor.h"
#include "cpu.h"
@@ -73,10 +76,12 @@ void hmp_migrationmode(Monitor *mon, const QDict *qdict)
}
}
-void hmp_info_cmma(Monitor *mon, const QDict *qdict)
+HumanReadableText *qmp_x_query_s390x_cmma(const char *json_args, Error **errp)
{
+ g_autoptr(GString) buf = g_string_new("");
S390StAttribState *sas = s390_get_stattrib_device();
S390StAttribClass *sac = S390_STATTRIB_GET_CLASS(sas);
+ QDict *qdict = qobject_to(QDict, qobject_from_json(json_args, &error_abort));
uint64_t addr = qdict_get_int(qdict, "addr");
uint64_t buflen = qdict_get_try_int(qdict, "count", 8);
uint8_t *vals;
@@ -84,30 +89,33 @@ void hmp_info_cmma(Monitor *mon, const QDict *qdict)
vals = g_try_malloc(buflen);
if (!vals) {
- monitor_printf(mon, "Error: %s\n", strerror(errno));
- return;
+ error_setg(errp, "Failed to allocate memory");
+ return NULL;
}
len = sac->peek_stattr(sas, addr / TARGET_PAGE_SIZE, buflen, vals);
if (len < 0) {
- monitor_printf(mon, "Error: %s", strerror(-len));
+ error_setg_errno(errp, -len, "Could not get attributes");
goto out;
}
- monitor_printf(mon, " CMMA attributes, "
- "pages %" PRIu64 "+%d (0x%" PRIx64 "):\n",
- addr / TARGET_PAGE_SIZE, len, addr & ~TARGET_PAGE_MASK);
+ g_string_append_printf(buf, " CMMA attributes, "
+ "pages %" PRIu64 "+%d (0x%" PRIx64 "):\n",
+ addr / TARGET_PAGE_SIZE, len,
+ addr & ~TARGET_PAGE_MASK);
for (cx = 0; cx < len; cx++) {
if (cx % 8 == 7) {
- monitor_printf(mon, "%02x\n", vals[cx]);
+ g_string_append_printf(buf, "%02x\n", vals[cx]);
} else {
- monitor_printf(mon, "%02x", vals[cx]);
+ g_string_append_printf(buf, "%02x", vals[cx]);
}
}
- monitor_printf(mon, "\n");
+ g_string_append_c(buf, '\n');
out:
+ qobject_unref(qdict);
g_free(vals);
+ return human_readable_text_from_str(buf);
}
/* Migration support: */
diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
index cfd4ad5651..0a944e43ce 100644
--- a/hmp-commands-info.hx
+++ b/hmp-commands-info.hx
@@ -720,7 +720,7 @@ ERST
.args_type = "addr:l,count:l?",
.params = "address [count]",
.help = "Display the values of the CMMA storage attributes for a range of pages",
- .cmd = hmp_info_cmma,
+ .cmd_info_hrt = qmp_x_query_s390x_cmma,
},
#endif
--
2.41.0
prev parent reply other threads:[~2024-06-10 18:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-10 17:58 [RFC PATCH 0/3] monitor: Pass HMP arguments to QMP HumanReadableText API as JSON Philippe Mathieu-Daudé
2024-06-10 17:58 ` [PATCH 1/3] hw/s390x: Declare target specific monitor commands in hmp-target.h Philippe Mathieu-Daudé
2024-06-10 21:02 ` Dr. David Alan Gilbert
2024-06-10 17:58 ` [RFC PATCH 2/3] monitor: Allow passing HMP arguments to QMP HumanReadableText API Philippe Mathieu-Daudé
2024-06-10 18:26 ` Daniel P. Berrangé
2024-06-10 17:58 ` Philippe Mathieu-Daudé [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240610175852.21215-4-philmd@linaro.org \
--to=philmd@linaro.org \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=borntraeger@linux.ibm.com \
--cc=dave@treblig.org \
--cc=david@redhat.com \
--cc=eblake@redhat.com \
--cc=eduardo@habkost.net \
--cc=farman@linux.ibm.com \
--cc=iii@linux.ibm.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=pasic@linux.ibm.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=thuth@redhat.com \
--cc=wangyanan55@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).