From patchwork Sat Aug 9 06:26:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sanidhya Kashyap X-Patchwork-Id: 378726 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 5F6A81400AA for ; Sat, 9 Aug 2014 16:30:25 +1000 (EST) Received: from localhost ([::1]:54267 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XG0AZ-0007TM-An for incoming@patchwork.ozlabs.org; Sat, 09 Aug 2014 02:30:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42025) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XG09p-0006H6-NU for qemu-devel@nongnu.org; Sat, 09 Aug 2014 02:29:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XG09d-0001WT-DW for qemu-devel@nongnu.org; Sat, 09 Aug 2014 02:29:37 -0400 Received: from mail-qa0-x22f.google.com ([2607:f8b0:400d:c00::22f]:61977) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XG09d-0001Vk-82 for qemu-devel@nongnu.org; Sat, 09 Aug 2014 02:29:25 -0400 Received: by mail-qa0-f47.google.com with SMTP id i13so6409863qae.6 for ; Fri, 08 Aug 2014 23:29:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=fPO2N4mfNu/kFzitXBVK2N1J7dpyZnx6G32SLV7Khfk=; b=oc0u59PybI94FnI+f9rFn8iInnw2R9GH7fc5yXCmGztM5pNKfLgXB6CNW+JY/8+c75 en6ofodbKt3tfUBvtItUwcV5zYC/8/djc0G7xhs6l8A62p9YzwWViUVhfMsOvI0tePO2 SRolXsh8QTiexApiZK9xCFp/Zse+S4yBNiU7S1hzzcUIRQ5PKa1dsMWNt/FU5j8Vhrk9 7228x9QQzynQS+0mcyjuipfGwkhFqOWqh2Riq6kiLHqWNjJJ1NGiBwWJ9G/Fuad2KgkW Tt5frFm0N8wPmtYL4WN4WCgz6iQUvNPYRC+6pGkRxD2clr+ZpazrXp+btzwrD5REdoPL 5qbw== X-Received: by 10.140.84.138 with SMTP id l10mr29276070qgd.51.1407565764885; Fri, 08 Aug 2014 23:29:24 -0700 (PDT) Received: from localhost.localdomain ([172.56.1.233]) by mx.google.com with ESMTPSA id w11sm9479489qax.30.2014.08.08.23.29.23 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Aug 2014 23:29:24 -0700 (PDT) From: Sanidhya Kashyap To: qemu list Date: Sat, 9 Aug 2014 02:26:31 -0400 Message-Id: <1407565595-18861-3-git-send-email-sanidhya.iiith@gmail.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1407565595-18861-1-git-send-email-sanidhya.iiith@gmail.com> References: <1407565595-18861-1-git-send-email-sanidhya.iiith@gmail.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400d:c00::22f Cc: Sanidhya Kashyap , "Dr. David Alan Gilbert" , Juan Quintela Subject: [Qemu-devel] [RFC PATCH v3 2/6] VMState test: get information about the registered devices X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Added both qmp and hmp interface to get the information about the devices that have been qdevified and are registered with the SaveVMHandlers. I have not used any format to print the device information for the hmp interface. It would be great if anyone can give me some pointers about this about the printing format if there is something. The qmp command to extract the information about the devices is qmp_query_devices which provides the list of device names and their respective version. The hmp command name is 'info devices' which lists the same information as provided by the qmp interface. Signed-off-by: Sanidhya Kashyap --- hmp-commands.hx | 2 ++ hmp.c | 23 +++++++++++++++++++++++ hmp.h | 1 + monitor.c | 7 +++++++ qapi-schema.json | 26 ++++++++++++++++++++++++++ qmp-commands.hx | 43 +++++++++++++++++++++++++++++++++++++++++++ savevm.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 147 insertions(+) diff --git a/hmp-commands.hx b/hmp-commands.hx index d0943b1..a221459 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1780,6 +1780,8 @@ show qdev device model list show roms @item info tpm show the TPM device +@item info devices +show the devices registered with migration capability @end table ETEXI diff --git a/hmp.c b/hmp.c index 4d1838e..6e1802a 100644 --- a/hmp.c +++ b/hmp.c @@ -1714,3 +1714,26 @@ void hmp_info_memdev(Monitor *mon, const QDict *qdict) monitor_printf(mon, "\n"); } + +void hmp_info_devices(Monitor *mon, const QDict *qdict) +{ + Error *err = NULL; + QemuDeviceList *device_list = qmp_query_devices(&err); + + if (device_list) { + monitor_printf(mon, "devices:\n"); + while (device_list) { + monitor_printf(mon, "device-name: %s, ", + device_list->value->device_name); + monitor_printf(mon, "version: %ld\n", + device_list->value->version); + device_list = device_list->next; + } + } + + if (err) { + hmp_handle_error(mon, &err); + } + + qapi_free_QemuDeviceList(device_list); +} diff --git a/hmp.h b/hmp.h index 4fd3c4a..9d6b577 100644 --- a/hmp.h +++ b/hmp.h @@ -38,6 +38,7 @@ void hmp_info_balloon(Monitor *mon, const QDict *qdict); void hmp_info_pci(Monitor *mon, const QDict *qdict); void hmp_info_block_jobs(Monitor *mon, const QDict *qdict); void hmp_info_tpm(Monitor *mon, const QDict *qdict); +void hmp_info_devices(Monitor *mon, const QDict *qdict); void hmp_quit(Monitor *mon, const QDict *qdict); void hmp_stop(Monitor *mon, const QDict *qdict); void hmp_system_reset(Monitor *mon, const QDict *qdict); diff --git a/monitor.c b/monitor.c index 5bc70a6..2431686 100644 --- a/monitor.c +++ b/monitor.c @@ -2918,6 +2918,13 @@ static mon_cmd_t info_cmds[] = { .mhandler.cmd = hmp_info_memdev, }, { + .name = "devices", + .args_type = "", + .params = "", + .help = "show registered devices", + .mhandler.cmd = hmp_info_devices, + }, + { .name = NULL, }, }; diff --git a/qapi-schema.json b/qapi-schema.json index b11aad2..74d26fe 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -3480,3 +3480,29 @@ # Since: 2.1 ## { 'command': 'rtc-reset-reinjection' } + +## +# @QemuDevice +# +# device that is registered with SaveVMHandlers +# +# @device-name: name of the device that is registered with +# SaveVMHandlers (in vmsd structure). +# +# @version: version of the device. +# +# Since 2.2 +## +{ 'type': 'QemuDevice', + 'data': { 'device-name': 'str', + '*version': 'int' } } + +## +# @query-devices +# +# returns the list of QemuDevice +# +# Since 2.2 +## +{ 'command': 'query-devices', + 'returns': [ 'QemuDevice' ] } diff --git a/qmp-commands.hx b/qmp-commands.hx index 4be4765..e489197 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -3755,3 +3755,46 @@ Example: <- { "return": {} } EQMP + + { + .name = "query-devices", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_input_query_devices, + }, + +SQMP +query-devices +------------- + +Shows registered devices along with the version + +Example (1): + +-> { "execute": "query-devices" } +<- { "return": [ + { + [ { 'device-name': 'kvm-tpr-opt', 'version': 1 }, + { 'device-name': 'apic', 'version': 3 }, + { 'device-name': 'kvmclock', 'version': 1 }, + { 'device-name': 'fw_cfg', 'version': 2 }, + { 'device-name': 'I440FX', 'version': 3 }, + { 'device-name': 'PIIX3', 'version': 3 }, + { 'device-name': 'i8259', 'version': 1 }, + { 'device-name': 'i8259', 'version': 1 }, + { 'device-name': 'ioapic', 'version': 3 }, + { 'device-name': 'cirrus_vga', 'version': 2 }, + { 'device-name': 'hpet', 'version': 2 }, + { 'device-name': 'mc146818rtc', 'version': 3 }, + { 'device-name': 'i8254', 'version': 3 }, + { 'device-name': 'serial', 'version': 3 }, + { 'device-name': 'pckbd', 'version': 3 }, + { 'device-name': 'vmmouse', 'version': 0 }, + { 'device-name': 'port92', 'version': 1 }, + { 'device-name': 'fdc', 'version': 2 }, + { 'device-name': 'e1000', 'version': 2 }, + { 'device-name': 'ide', 'version': 3 }, + { 'device-name': 'piix4_pm', 'version': 3 } ] + } + ] + } +EQMP diff --git a/savevm.c b/savevm.c index e19ae0a..764ca71 100644 --- a/savevm.c +++ b/savevm.c @@ -233,6 +233,7 @@ typedef struct SaveStateEntry { void *opaque; CompatEntry *compat; int is_ram; + DeviceState *dev; } SaveStateEntry; @@ -429,6 +430,7 @@ int register_savevm_live(DeviceState *dev, se->ops = ops; se->opaque = opaque; se->vmsd = NULL; + se->dev = dev; /* if this is a live_savem then set is_ram */ if (ops->save_live_setup != NULL) { se->is_ram = 1; @@ -519,6 +521,7 @@ int vmstate_register_with_alias_id(DeviceState *dev, int instance_id, se->opaque = opaque; se->vmsd = vmsd; se->alias_id = alias_id; + se->dev = dev; if (dev) { char *id = qdev_get_dev_path(dev); @@ -1137,6 +1140,48 @@ void do_savevm(Monitor *mon, const QDict *qdict) } } +static QemuDeviceList *create_device_list(const char *name, int version, + QemuDeviceList *list) +{ + QemuDeviceList *temp_list; + QemuDeviceList *parent_list = list; + int len; + + temp_list = g_malloc0(sizeof(QemuDeviceList)); + len = strlen(name); + temp_list->value = g_malloc0(sizeof(QemuDevice)); + temp_list->value->device_name = g_malloc0(sizeof(char)*(len+1)); + strcpy(temp_list->value->device_name, name); + temp_list->value->version = version; + temp_list->next = NULL; + + if (!list) { + return temp_list; + } + + while (list->next) { + list = list->next; + } + list->next = temp_list; + + return parent_list; +} + +QemuDeviceList *qmp_query_devices(Error **errp) +{ + QemuDeviceList *device_list = NULL; + SaveStateEntry *se; + + QTAILQ_FOREACH(se, &savevm_handlers, entry) { + if (se->dev) { + device_list = create_device_list(se->vmsd->name, se->version_id, + device_list); + } + } + + return device_list; +} + void qmp_xen_save_devices_state(const char *filename, Error **errp) { QEMUFile *f;