2012-01-20 05:04:34 +01:00
|
|
|
/*
|
|
|
|
* QEMU Guest Agent win32-specific command implementations
|
|
|
|
*
|
|
|
|
* Copyright IBM Corp. 2012
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Michael Roth <mdroth@linux.vnet.ibm.com>
|
2012-01-29 10:53:31 +01:00
|
|
|
* Gal Hammer <ghammer@redhat.com>
|
2012-01-20 05:04:34 +01:00
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <glib.h>
|
2012-01-29 10:53:31 +01:00
|
|
|
#include <wtypes.h>
|
|
|
|
#include <powrprof.h>
|
2012-01-20 05:04:34 +01:00
|
|
|
#include "qga/guest-agent-core.h"
|
2013-08-07 17:40:25 +02:00
|
|
|
#include "qga/vss-win32.h"
|
2012-01-20 05:04:34 +01:00
|
|
|
#include "qga-qmp-commands.h"
|
2012-12-17 18:19:43 +01:00
|
|
|
#include "qapi/qmp/qerror.h"
|
2012-01-20 05:04:34 +01:00
|
|
|
|
2012-01-23 03:24:37 +01:00
|
|
|
#ifndef SHTDN_REASON_FLAG_PLANNED
|
|
|
|
#define SHTDN_REASON_FLAG_PLANNED 0x80000000
|
|
|
|
#endif
|
|
|
|
|
2013-03-15 10:29:04 +01:00
|
|
|
/* multiple of 100 nanoseconds elapsed between windows baseline
|
|
|
|
* (1/1/1601) and Unix Epoch (1/1/1970), accounting for leap years */
|
|
|
|
#define W32_FT_OFFSET (10000000ULL * 60 * 60 * 24 * \
|
|
|
|
(365 * (1970 - 1601) + \
|
|
|
|
(1970 - 1601) / 4 - 3))
|
|
|
|
|
2014-05-02 13:26:30 +02:00
|
|
|
static void acquire_privilege(const char *name, Error **errp)
|
2012-01-20 05:04:34 +01:00
|
|
|
{
|
2014-05-19 09:26:03 +02:00
|
|
|
HANDLE token = NULL;
|
2012-01-23 03:24:37 +01:00
|
|
|
TOKEN_PRIVILEGES priv;
|
2012-01-29 10:53:31 +01:00
|
|
|
Error *local_err = NULL;
|
|
|
|
|
|
|
|
if (OpenProcessToken(GetCurrentProcess(),
|
|
|
|
TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &token))
|
|
|
|
{
|
|
|
|
if (!LookupPrivilegeValue(NULL, name, &priv.Privileges[0].Luid)) {
|
|
|
|
error_set(&local_err, QERR_QGA_COMMAND_FAILED,
|
|
|
|
"no luid for requested privilege");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv.PrivilegeCount = 1;
|
|
|
|
priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
|
|
|
|
|
|
|
|
if (!AdjustTokenPrivileges(token, FALSE, &priv, 0, NULL, 0)) {
|
|
|
|
error_set(&local_err, QERR_QGA_COMMAND_FAILED,
|
|
|
|
"unable to acquire requested privilege");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
error_set(&local_err, QERR_QGA_COMMAND_FAILED,
|
|
|
|
"failed to open privilege token");
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2014-05-19 09:26:03 +02:00
|
|
|
if (token) {
|
|
|
|
CloseHandle(token);
|
|
|
|
}
|
2012-01-29 10:53:31 +01:00
|
|
|
if (local_err) {
|
2014-05-02 13:26:30 +02:00
|
|
|
error_propagate(errp, local_err);
|
2012-01-29 10:53:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:26:30 +02:00
|
|
|
static void execute_async(DWORD WINAPI (*func)(LPVOID), LPVOID opaque,
|
|
|
|
Error **errp)
|
2012-01-29 10:53:31 +01:00
|
|
|
{
|
|
|
|
Error *local_err = NULL;
|
|
|
|
|
|
|
|
HANDLE thread = CreateThread(NULL, 0, func, opaque, 0, NULL);
|
|
|
|
if (!thread) {
|
|
|
|
error_set(&local_err, QERR_QGA_COMMAND_FAILED,
|
|
|
|
"failed to dispatch asynchronous command");
|
2014-05-02 13:26:30 +02:00
|
|
|
error_propagate(errp, local_err);
|
2012-01-29 10:53:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:26:30 +02:00
|
|
|
void qmp_guest_shutdown(bool has_mode, const char *mode, Error **errp)
|
2012-01-29 10:53:31 +01:00
|
|
|
{
|
2014-05-02 13:26:38 +02:00
|
|
|
Error *local_err = NULL;
|
2012-01-23 03:24:37 +01:00
|
|
|
UINT shutdown_flag = EWX_FORCE;
|
|
|
|
|
|
|
|
slog("guest-shutdown called, mode: %s", mode);
|
|
|
|
|
|
|
|
if (!has_mode || strcmp(mode, "powerdown") == 0) {
|
|
|
|
shutdown_flag |= EWX_POWEROFF;
|
|
|
|
} else if (strcmp(mode, "halt") == 0) {
|
|
|
|
shutdown_flag |= EWX_SHUTDOWN;
|
|
|
|
} else if (strcmp(mode, "reboot") == 0) {
|
|
|
|
shutdown_flag |= EWX_REBOOT;
|
|
|
|
} else {
|
2014-05-02 13:26:30 +02:00
|
|
|
error_set(errp, QERR_INVALID_PARAMETER_VALUE, "mode",
|
2012-01-23 03:24:37 +01:00
|
|
|
"halt|powerdown|reboot");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Request a shutdown privilege, but try to shut down the system
|
|
|
|
anyway. */
|
2014-05-02 13:26:38 +02:00
|
|
|
acquire_privilege(SE_SHUTDOWN_NAME, &local_err);
|
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
2012-01-29 10:53:31 +01:00
|
|
|
return;
|
2012-01-23 03:24:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!ExitWindowsEx(shutdown_flag, SHTDN_REASON_FLAG_PLANNED)) {
|
2013-11-25 20:54:17 +01:00
|
|
|
slog("guest-shutdown failed: %lu", GetLastError());
|
2014-05-02 13:26:30 +02:00
|
|
|
error_set(errp, QERR_UNDEFINED_ERROR);
|
2012-01-23 03:24:37 +01:00
|
|
|
}
|
2012-01-20 05:04:34 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:26:30 +02:00
|
|
|
int64_t qmp_guest_file_open(const char *path, bool has_mode, const char *mode,
|
|
|
|
Error **errp)
|
2012-01-20 05:04:34 +01:00
|
|
|
{
|
2014-05-02 13:26:30 +02:00
|
|
|
error_set(errp, QERR_UNSUPPORTED);
|
2012-01-20 05:04:34 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:26:30 +02:00
|
|
|
void qmp_guest_file_close(int64_t handle, Error **errp)
|
2012-01-20 05:04:34 +01:00
|
|
|
{
|
2014-05-02 13:26:30 +02:00
|
|
|
error_set(errp, QERR_UNSUPPORTED);
|
2012-01-20 05:04:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
GuestFileRead *qmp_guest_file_read(int64_t handle, bool has_count,
|
2014-05-02 13:26:30 +02:00
|
|
|
int64_t count, Error **errp)
|
2012-01-20 05:04:34 +01:00
|
|
|
{
|
2014-05-02 13:26:30 +02:00
|
|
|
error_set(errp, QERR_UNSUPPORTED);
|
2012-01-20 05:04:34 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
GuestFileWrite *qmp_guest_file_write(int64_t handle, const char *buf_b64,
|
2014-05-02 13:26:30 +02:00
|
|
|
bool has_count, int64_t count,
|
|
|
|
Error **errp)
|
2012-01-20 05:04:34 +01:00
|
|
|
{
|
2014-05-02 13:26:30 +02:00
|
|
|
error_set(errp, QERR_UNSUPPORTED);
|
2012-01-20 05:04:34 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
GuestFileSeek *qmp_guest_file_seek(int64_t handle, int64_t offset,
|
2014-05-02 13:26:30 +02:00
|
|
|
int64_t whence, Error **errp)
|
2012-01-20 05:04:34 +01:00
|
|
|
{
|
2014-05-02 13:26:30 +02:00
|
|
|
error_set(errp, QERR_UNSUPPORTED);
|
2012-01-20 05:04:34 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:26:30 +02:00
|
|
|
void qmp_guest_file_flush(int64_t handle, Error **errp)
|
2012-01-20 05:04:34 +01:00
|
|
|
{
|
2014-05-02 13:26:30 +02:00
|
|
|
error_set(errp, QERR_UNSUPPORTED);
|
2012-01-20 05:04:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return status of freeze/thaw
|
|
|
|
*/
|
2014-05-02 13:26:30 +02:00
|
|
|
GuestFsfreezeStatus qmp_guest_fsfreeze_status(Error **errp)
|
2012-01-20 05:04:34 +01:00
|
|
|
{
|
2013-08-07 17:40:25 +02:00
|
|
|
if (!vss_initialized()) {
|
2014-05-02 13:26:30 +02:00
|
|
|
error_set(errp, QERR_UNSUPPORTED);
|
2013-08-07 17:40:25 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ga_is_frozen(ga_state)) {
|
|
|
|
return GUEST_FSFREEZE_STATUS_FROZEN;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GUEST_FSFREEZE_STATUS_THAWED;
|
2012-01-20 05:04:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2013-08-07 17:40:25 +02:00
|
|
|
* Freeze local file systems using Volume Shadow-copy Service.
|
|
|
|
* The frozen state is limited for up to 10 seconds by VSS.
|
2012-01-20 05:04:34 +01:00
|
|
|
*/
|
2014-05-02 13:26:30 +02:00
|
|
|
int64_t qmp_guest_fsfreeze_freeze(Error **errp)
|
2012-01-20 05:04:34 +01:00
|
|
|
{
|
2013-08-07 17:40:25 +02:00
|
|
|
int i;
|
|
|
|
Error *local_err = NULL;
|
|
|
|
|
|
|
|
if (!vss_initialized()) {
|
2014-05-02 13:26:30 +02:00
|
|
|
error_set(errp, QERR_UNSUPPORTED);
|
2013-08-07 17:40:25 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
slog("guest-fsfreeze called");
|
|
|
|
|
|
|
|
/* cannot risk guest agent blocking itself on a write in this state */
|
|
|
|
ga_set_frozen(ga_state);
|
|
|
|
|
2014-05-02 13:26:38 +02:00
|
|
|
qga_vss_fsfreeze(&i, &local_err, true);
|
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
2013-08-07 17:40:25 +02:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return i;
|
|
|
|
|
|
|
|
error:
|
2014-05-02 13:26:38 +02:00
|
|
|
local_err = NULL;
|
2013-08-07 17:40:25 +02:00
|
|
|
qmp_guest_fsfreeze_thaw(&local_err);
|
2014-01-30 15:07:28 +01:00
|
|
|
if (local_err) {
|
2013-08-07 17:40:25 +02:00
|
|
|
g_debug("cleanup thaw: %s", error_get_pretty(local_err));
|
|
|
|
error_free(local_err);
|
|
|
|
}
|
2012-01-20 05:04:34 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2013-08-07 17:40:25 +02:00
|
|
|
* Thaw local file systems using Volume Shadow-copy Service.
|
2012-01-20 05:04:34 +01:00
|
|
|
*/
|
2014-05-02 13:26:30 +02:00
|
|
|
int64_t qmp_guest_fsfreeze_thaw(Error **errp)
|
2012-01-20 05:04:34 +01:00
|
|
|
{
|
2013-08-07 17:40:25 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!vss_initialized()) {
|
2014-05-02 13:26:30 +02:00
|
|
|
error_set(errp, QERR_UNSUPPORTED);
|
2013-08-07 17:40:25 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:26:30 +02:00
|
|
|
qga_vss_fsfreeze(&i, errp, false);
|
2013-08-07 17:40:25 +02:00
|
|
|
|
|
|
|
ga_unset_frozen(ga_state);
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void guest_fsfreeze_cleanup(void)
|
|
|
|
{
|
|
|
|
Error *err = NULL;
|
|
|
|
|
|
|
|
if (!vss_initialized()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ga_is_frozen(ga_state) == GUEST_FSFREEZE_STATUS_FROZEN) {
|
|
|
|
qmp_guest_fsfreeze_thaw(&err);
|
|
|
|
if (err) {
|
|
|
|
slog("failed to clean up frozen filesystems: %s",
|
|
|
|
error_get_pretty(err));
|
|
|
|
error_free(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
vss_deinit(true);
|
2012-01-20 05:04:34 +01:00
|
|
|
}
|
|
|
|
|
2012-06-13 07:41:28 +02:00
|
|
|
/*
|
|
|
|
* Walk list of mounted file systems in the guest, and discard unused
|
|
|
|
* areas.
|
|
|
|
*/
|
2014-05-02 13:26:30 +02:00
|
|
|
void qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **errp)
|
2012-06-13 07:41:28 +02:00
|
|
|
{
|
2014-05-02 13:26:30 +02:00
|
|
|
error_set(errp, QERR_UNSUPPORTED);
|
2012-06-13 07:41:28 +02:00
|
|
|
}
|
|
|
|
|
2012-01-29 10:53:31 +01:00
|
|
|
typedef enum {
|
2012-03-12 18:50:02 +01:00
|
|
|
GUEST_SUSPEND_MODE_DISK,
|
|
|
|
GUEST_SUSPEND_MODE_RAM
|
2012-01-29 10:53:31 +01:00
|
|
|
} GuestSuspendMode;
|
|
|
|
|
2014-05-02 13:26:30 +02:00
|
|
|
static void check_suspend_mode(GuestSuspendMode mode, Error **errp)
|
2012-01-29 10:53:31 +01:00
|
|
|
{
|
|
|
|
SYSTEM_POWER_CAPABILITIES sys_pwr_caps;
|
|
|
|
Error *local_err = NULL;
|
|
|
|
|
|
|
|
ZeroMemory(&sys_pwr_caps, sizeof(sys_pwr_caps));
|
|
|
|
if (!GetPwrCapabilities(&sys_pwr_caps)) {
|
|
|
|
error_set(&local_err, QERR_QGA_COMMAND_FAILED,
|
|
|
|
"failed to determine guest suspend capabilities");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2012-03-12 18:50:02 +01:00
|
|
|
switch (mode) {
|
|
|
|
case GUEST_SUSPEND_MODE_DISK:
|
|
|
|
if (!sys_pwr_caps.SystemS4) {
|
|
|
|
error_set(&local_err, QERR_QGA_COMMAND_FAILED,
|
|
|
|
"suspend-to-disk not supported by OS");
|
2012-01-29 10:53:31 +01:00
|
|
|
}
|
2012-03-12 18:50:02 +01:00
|
|
|
break;
|
|
|
|
case GUEST_SUSPEND_MODE_RAM:
|
|
|
|
if (!sys_pwr_caps.SystemS3) {
|
|
|
|
error_set(&local_err, QERR_QGA_COMMAND_FAILED,
|
|
|
|
"suspend-to-ram not supported by OS");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2012-01-29 10:53:31 +01:00
|
|
|
error_set(&local_err, QERR_INVALID_PARAMETER_VALUE, "mode",
|
|
|
|
"GuestSuspendMode");
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (local_err) {
|
2014-05-02 13:26:30 +02:00
|
|
|
error_propagate(errp, local_err);
|
2012-01-29 10:53:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD WINAPI do_suspend(LPVOID opaque)
|
|
|
|
{
|
|
|
|
GuestSuspendMode *mode = opaque;
|
|
|
|
DWORD ret = 0;
|
|
|
|
|
|
|
|
if (!SetSuspendState(*mode == GUEST_SUSPEND_MODE_DISK, TRUE, TRUE)) {
|
2013-11-25 20:54:17 +01:00
|
|
|
slog("failed to suspend guest, %lu", GetLastError());
|
2012-01-29 10:53:31 +01:00
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
g_free(mode);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:26:30 +02:00
|
|
|
void qmp_guest_suspend_disk(Error **errp)
|
qemu-ga: add guest-suspend-disk
As the command name implies, this command suspends the guest to disk.
The suspend operation is implemented by two functions: bios_supports_mode()
and guest_suspend(). Both functions are generic enough to be used by
other suspend modes (introduced by next commits).
Both functions will try to use the scripts provided by the pm-utils
package if it's available. If it's not available, a manual method,
which consists of directly writing to '/sys/power/state', will be used.
To reap terminated children, a new signal handler is installed in the
parent to catch SIGCHLD signals and a non-blocking call to waitpid()
is done to collect their exit statuses. The statuses, however, are
discarded.
The approach used to query the guest for suspend support deserves some
explanation. It's implemented by bios_supports_mode() and shown below:
qemu-ga
|
create pipe
|
fork()
-----------------
| |
| |
| fork()
| --------------------------
| | |
| | |
| | exec('pm-is-supported')
| |
| wait()
| write exit status to pipe
| exit
|
read pipe
This might look complex, but the resulting code is quite simple.
The purpose of that approach is to allow qemu-ga to reap its children
(semi-)automatically from its SIGCHLD handler.
Implementing this the obvious way, that's, doing the exec() call from
the first child process, would force us to introduce a more complex way
to reap qemu-ga's children. Like registering PIDs to be reaped and
having a way to wait for them when returning their exit status to
qemu-ga is necessary. The approach explained above avoids that complexity.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
2012-02-28 15:03:03 +01:00
|
|
|
{
|
2014-05-02 13:26:38 +02:00
|
|
|
Error *local_err = NULL;
|
2012-01-29 10:53:31 +01:00
|
|
|
GuestSuspendMode *mode = g_malloc(sizeof(GuestSuspendMode));
|
|
|
|
|
|
|
|
*mode = GUEST_SUSPEND_MODE_DISK;
|
2014-05-02 13:26:38 +02:00
|
|
|
check_suspend_mode(*mode, &local_err);
|
|
|
|
acquire_privilege(SE_SHUTDOWN_NAME, &local_err);
|
|
|
|
execute_async(do_suspend, mode, &local_err);
|
2012-01-29 10:53:31 +01:00
|
|
|
|
2014-05-02 13:26:38 +02:00
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
2012-01-29 10:53:31 +01:00
|
|
|
g_free(mode);
|
|
|
|
}
|
qemu-ga: add guest-suspend-disk
As the command name implies, this command suspends the guest to disk.
The suspend operation is implemented by two functions: bios_supports_mode()
and guest_suspend(). Both functions are generic enough to be used by
other suspend modes (introduced by next commits).
Both functions will try to use the scripts provided by the pm-utils
package if it's available. If it's not available, a manual method,
which consists of directly writing to '/sys/power/state', will be used.
To reap terminated children, a new signal handler is installed in the
parent to catch SIGCHLD signals and a non-blocking call to waitpid()
is done to collect their exit statuses. The statuses, however, are
discarded.
The approach used to query the guest for suspend support deserves some
explanation. It's implemented by bios_supports_mode() and shown below:
qemu-ga
|
create pipe
|
fork()
-----------------
| |
| |
| fork()
| --------------------------
| | |
| | |
| | exec('pm-is-supported')
| |
| wait()
| write exit status to pipe
| exit
|
read pipe
This might look complex, but the resulting code is quite simple.
The purpose of that approach is to allow qemu-ga to reap its children
(semi-)automatically from its SIGCHLD handler.
Implementing this the obvious way, that's, doing the exec() call from
the first child process, would force us to introduce a more complex way
to reap qemu-ga's children. Like registering PIDs to be reaped and
having a way to wait for them when returning their exit status to
qemu-ga is necessary. The approach explained above avoids that complexity.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
2012-02-28 15:03:03 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:26:30 +02:00
|
|
|
void qmp_guest_suspend_ram(Error **errp)
|
2012-02-28 15:03:04 +01:00
|
|
|
{
|
2014-05-02 13:26:38 +02:00
|
|
|
Error *local_err = NULL;
|
2012-03-12 18:50:02 +01:00
|
|
|
GuestSuspendMode *mode = g_malloc(sizeof(GuestSuspendMode));
|
|
|
|
|
|
|
|
*mode = GUEST_SUSPEND_MODE_RAM;
|
2014-05-02 13:26:38 +02:00
|
|
|
check_suspend_mode(*mode, &local_err);
|
|
|
|
acquire_privilege(SE_SHUTDOWN_NAME, &local_err);
|
|
|
|
execute_async(do_suspend, mode, &local_err);
|
2012-03-12 18:50:02 +01:00
|
|
|
|
2014-05-02 13:26:38 +02:00
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
2012-03-12 18:50:02 +01:00
|
|
|
g_free(mode);
|
|
|
|
}
|
2012-02-28 15:03:04 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:26:30 +02:00
|
|
|
void qmp_guest_suspend_hybrid(Error **errp)
|
2012-02-28 15:03:05 +01:00
|
|
|
{
|
2014-05-02 13:26:30 +02:00
|
|
|
error_set(errp, QERR_UNSUPPORTED);
|
2012-02-28 15:03:05 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:26:30 +02:00
|
|
|
GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp)
|
2012-02-29 17:02:23 +01:00
|
|
|
{
|
2014-05-02 13:26:30 +02:00
|
|
|
error_set(errp, QERR_UNSUPPORTED);
|
2012-02-29 17:02:23 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-03-05 10:39:11 +01:00
|
|
|
int64_t qmp_guest_get_time(Error **errp)
|
|
|
|
{
|
2013-03-15 10:29:04 +01:00
|
|
|
SYSTEMTIME ts = {0};
|
|
|
|
int64_t time_ns;
|
|
|
|
FILETIME tf;
|
|
|
|
|
|
|
|
GetSystemTime(&ts);
|
|
|
|
if (ts.wYear < 1601 || ts.wYear > 30827) {
|
|
|
|
error_setg(errp, "Failed to get time");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!SystemTimeToFileTime(&ts, &tf)) {
|
|
|
|
error_setg(errp, "Failed to convert system time: %d", (int)GetLastError());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
time_ns = ((((int64_t)tf.dwHighDateTime << 32) | tf.dwLowDateTime)
|
|
|
|
- W32_FT_OFFSET) * 100;
|
|
|
|
|
|
|
|
return time_ns;
|
2013-03-05 10:39:11 +01:00
|
|
|
}
|
|
|
|
|
2014-01-31 11:29:51 +01:00
|
|
|
void qmp_guest_set_time(bool has_time, int64_t time_ns, Error **errp)
|
2013-03-05 10:39:12 +01:00
|
|
|
{
|
2014-05-02 13:26:38 +02:00
|
|
|
Error *local_err = NULL;
|
2013-03-15 10:29:05 +01:00
|
|
|
SYSTEMTIME ts;
|
|
|
|
FILETIME tf;
|
|
|
|
LONGLONG time;
|
|
|
|
|
2014-01-31 11:29:51 +01:00
|
|
|
if (has_time) {
|
|
|
|
/* Okay, user passed a time to set. Validate it. */
|
|
|
|
if (time_ns < 0 || time_ns / 100 > INT64_MAX - W32_FT_OFFSET) {
|
|
|
|
error_setg(errp, "Time %" PRId64 "is invalid", time_ns);
|
|
|
|
return;
|
|
|
|
}
|
2013-03-15 10:29:05 +01:00
|
|
|
|
2014-01-31 11:29:51 +01:00
|
|
|
time = time_ns / 100 + W32_FT_OFFSET;
|
2013-03-15 10:29:05 +01:00
|
|
|
|
2014-01-31 11:29:51 +01:00
|
|
|
tf.dwLowDateTime = (DWORD) time;
|
|
|
|
tf.dwHighDateTime = (DWORD) (time >> 32);
|
2013-03-15 10:29:05 +01:00
|
|
|
|
2014-01-31 11:29:51 +01:00
|
|
|
if (!FileTimeToSystemTime(&tf, &ts)) {
|
|
|
|
error_setg(errp, "Failed to convert system time %d",
|
|
|
|
(int)GetLastError());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Otherwise read the time from RTC which contains the correct value.
|
|
|
|
* Hopefully. */
|
|
|
|
GetSystemTime(&ts);
|
|
|
|
if (ts.wYear < 1601 || ts.wYear > 30827) {
|
|
|
|
error_setg(errp, "Failed to get time");
|
|
|
|
return;
|
|
|
|
}
|
2013-03-15 10:29:05 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:26:38 +02:00
|
|
|
acquire_privilege(SE_SYSTEMTIME_NAME, &local_err);
|
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
2013-03-15 10:29:05 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!SetSystemTime(&ts)) {
|
|
|
|
error_setg(errp, "Failed to set time to guest: %d", (int)GetLastError());
|
|
|
|
return;
|
|
|
|
}
|
2013-03-05 10:39:12 +01:00
|
|
|
}
|
|
|
|
|
2013-03-06 22:59:29 +01:00
|
|
|
GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp)
|
|
|
|
{
|
|
|
|
error_set(errp, QERR_UNSUPPORTED);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp)
|
|
|
|
{
|
|
|
|
error_set(errp, QERR_UNSUPPORTED);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-01-20 05:04:34 +01:00
|
|
|
/* register init/cleanup routines for stateful command groups */
|
|
|
|
void ga_command_state_init(GAState *s, GACommandState *cs)
|
|
|
|
{
|
2013-08-07 17:40:25 +02:00
|
|
|
if (vss_init(true)) {
|
|
|
|
ga_command_state_add(cs, NULL, guest_fsfreeze_cleanup);
|
|
|
|
}
|
2012-01-20 05:04:34 +01:00
|
|
|
}
|