Michael Roth | 42074a9 | 2012-01-19 22:19:27 -0600 | [diff] [blame] | 1 | /* |
| 2 | * QEMU Guest Agent common/cross-platform command implementations |
| 3 | * |
| 4 | * Copyright IBM Corp. 2012 |
| 5 | * |
| 6 | * Authors: |
| 7 | * Michael Roth <mdroth@linux.vnet.ibm.com> |
| 8 | * |
| 9 | * This work is licensed under the terms of the GNU GPL, version 2 or later. |
| 10 | * See the COPYING file in the top-level directory. |
| 11 | */ |
| 12 | |
| 13 | #include <glib.h> |
| 14 | #include "qga/guest-agent-core.h" |
| 15 | #include "qga-qmp-commands.h" |
Paolo Bonzini | 7b1b5d1 | 2012-12-17 18:19:43 +0100 | [diff] [blame] | 16 | #include "qapi/qmp/qerror.h" |
Michael Roth | 42074a9 | 2012-01-19 22:19:27 -0600 | [diff] [blame] | 17 | |
| 18 | /* Note: in some situations, like with the fsfreeze, logging may be |
| 19 | * temporarilly disabled. if it is necessary that a command be able |
| 20 | * to log for accounting purposes, check ga_logging_enabled() beforehand, |
| 21 | * and use the QERR_QGA_LOGGING_DISABLED to generate an error |
| 22 | */ |
| 23 | void slog(const gchar *fmt, ...) |
| 24 | { |
| 25 | va_list ap; |
| 26 | |
| 27 | va_start(ap, fmt); |
| 28 | g_logv("syslog", G_LOG_LEVEL_INFO, fmt, ap); |
| 29 | va_end(ap); |
| 30 | } |
| 31 | |
Michael Roth | 3cf0bed | 2012-02-07 13:56:48 -0600 | [diff] [blame] | 32 | int64_t qmp_guest_sync_delimited(int64_t id, Error **errp) |
| 33 | { |
| 34 | ga_set_response_delimited(ga_state); |
| 35 | return id; |
| 36 | } |
| 37 | |
Michael Roth | 42074a9 | 2012-01-19 22:19:27 -0600 | [diff] [blame] | 38 | int64_t qmp_guest_sync(int64_t id, Error **errp) |
| 39 | { |
| 40 | return id; |
| 41 | } |
| 42 | |
| 43 | void qmp_guest_ping(Error **err) |
| 44 | { |
| 45 | slog("guest-ping called"); |
| 46 | } |
| 47 | |
Mark Wu | 8dc4d91 | 2013-10-09 11:25:07 +0800 | [diff] [blame] | 48 | static void qmp_command_info(QmpCommand *cmd, void *opaque) |
| 49 | { |
| 50 | GuestAgentInfo *info = opaque; |
| 51 | GuestAgentCommandInfo *cmd_info; |
| 52 | GuestAgentCommandInfoList *cmd_info_list; |
| 53 | |
| 54 | cmd_info = g_malloc0(sizeof(GuestAgentCommandInfo)); |
| 55 | cmd_info->name = g_strdup(qmp_command_name(cmd)); |
| 56 | cmd_info->enabled = qmp_command_is_enabled(cmd); |
Mark Wu | 0106dc4 | 2013-10-09 10:37:26 +0800 | [diff] [blame] | 57 | cmd_info->success_response = qmp_has_success_response(cmd); |
Mark Wu | 8dc4d91 | 2013-10-09 11:25:07 +0800 | [diff] [blame] | 58 | |
| 59 | cmd_info_list = g_malloc0(sizeof(GuestAgentCommandInfoList)); |
| 60 | cmd_info_list->value = cmd_info; |
| 61 | cmd_info_list->next = info->supported_commands; |
| 62 | info->supported_commands = cmd_info_list; |
| 63 | } |
| 64 | |
Michael Roth | 42074a9 | 2012-01-19 22:19:27 -0600 | [diff] [blame] | 65 | struct GuestAgentInfo *qmp_guest_info(Error **err) |
| 66 | { |
| 67 | GuestAgentInfo *info = g_malloc0(sizeof(GuestAgentInfo)); |
Michael Roth | 42074a9 | 2012-01-19 22:19:27 -0600 | [diff] [blame] | 68 | |
Michael Roth | 8efacc4 | 2012-05-14 09:33:48 -0500 | [diff] [blame] | 69 | info->version = g_strdup(QEMU_VERSION); |
Mark Wu | 8dc4d91 | 2013-10-09 11:25:07 +0800 | [diff] [blame] | 70 | qmp_for_each_command(qmp_command_info, info); |
Michael Roth | 42074a9 | 2012-01-19 22:19:27 -0600 | [diff] [blame] | 71 | return info; |
| 72 | } |