qemu-ga: add guest-suspend-disk
[qemu/wangdongxu.git] / qga / commands-win32.c
blobc688476c890c86a86d87164c6a8793a1affc1d6c
1 /*
2 * QEMU Guest Agent win32-specific command implementations
4 * Copyright IBM Corp. 2012
6 * Authors:
7 * Michael Roth <mdroth@linux.vnet.ibm.com>
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.
13 #include <glib.h>
14 #include "qga/guest-agent-core.h"
15 #include "qga-qmp-commands.h"
16 #include "qerror.h"
18 #ifndef SHTDN_REASON_FLAG_PLANNED
19 #define SHTDN_REASON_FLAG_PLANNED 0x80000000
20 #endif
22 void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err)
24 HANDLE token;
25 TOKEN_PRIVILEGES priv;
26 UINT shutdown_flag = EWX_FORCE;
28 slog("guest-shutdown called, mode: %s", mode);
30 if (!has_mode || strcmp(mode, "powerdown") == 0) {
31 shutdown_flag |= EWX_POWEROFF;
32 } else if (strcmp(mode, "halt") == 0) {
33 shutdown_flag |= EWX_SHUTDOWN;
34 } else if (strcmp(mode, "reboot") == 0) {
35 shutdown_flag |= EWX_REBOOT;
36 } else {
37 error_set(err, QERR_INVALID_PARAMETER_VALUE, "mode",
38 "halt|powerdown|reboot");
39 return;
42 /* Request a shutdown privilege, but try to shut down the system
43 anyway. */
44 if (OpenProcessToken(GetCurrentProcess(),
45 TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &token))
47 LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
48 &priv.Privileges[0].Luid);
50 priv.PrivilegeCount = 1;
51 priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
53 AdjustTokenPrivileges(token, FALSE, &priv, 0, NULL, 0);
56 if (!ExitWindowsEx(shutdown_flag, SHTDN_REASON_FLAG_PLANNED)) {
57 slog("guest-shutdown failed: %d", GetLastError());
58 error_set(err, QERR_UNDEFINED_ERROR);
62 int64_t qmp_guest_file_open(const char *path, bool has_mode, const char *mode, Error **err)
64 error_set(err, QERR_UNSUPPORTED);
65 return 0;
68 void qmp_guest_file_close(int64_t handle, Error **err)
70 error_set(err, QERR_UNSUPPORTED);
73 GuestFileRead *qmp_guest_file_read(int64_t handle, bool has_count,
74 int64_t count, Error **err)
76 error_set(err, QERR_UNSUPPORTED);
77 return 0;
80 GuestFileWrite *qmp_guest_file_write(int64_t handle, const char *buf_b64,
81 bool has_count, int64_t count, Error **err)
83 error_set(err, QERR_UNSUPPORTED);
84 return 0;
87 GuestFileSeek *qmp_guest_file_seek(int64_t handle, int64_t offset,
88 int64_t whence, Error **err)
90 error_set(err, QERR_UNSUPPORTED);
91 return 0;
94 void qmp_guest_file_flush(int64_t handle, Error **err)
96 error_set(err, QERR_UNSUPPORTED);
100 * Return status of freeze/thaw
102 GuestFsfreezeStatus qmp_guest_fsfreeze_status(Error **err)
104 error_set(err, QERR_UNSUPPORTED);
105 return 0;
109 * Walk list of mounted file systems in the guest, and freeze the ones which
110 * are real local file systems.
112 int64_t qmp_guest_fsfreeze_freeze(Error **err)
114 error_set(err, QERR_UNSUPPORTED);
115 return 0;
119 * Walk list of frozen file systems in the guest, and thaw them.
121 int64_t qmp_guest_fsfreeze_thaw(Error **err)
123 error_set(err, QERR_UNSUPPORTED);
124 return 0;
127 void qmp_guest_suspend_disk(Error **err)
129 error_set(err, QERR_UNSUPPORTED);
132 /* register init/cleanup routines for stateful command groups */
133 void ga_command_state_init(GAState *s, GACommandState *cs)