diff options
author | Anthony Liguori <aliguori@us.ibm.com> | 2013-04-08 10:37:06 -0500 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2013-04-08 10:37:06 -0500 |
commit | b9a7cfee1280cc70ba0db2eb528ea3e5a072c80e (patch) | |
tree | e6262044a98176c69a0d4dd279663afb0aa1a2c8 | |
parent | 2a7a239ff09aa87cc3682a976c7a57d9ea1321d7 (diff) | |
parent | ce7f7cc2715145eadf1ac45a5dae63f535fc8bbf (diff) |
Merge remote-tracking branch 'mdroth/qga-pull-4-2-13' into staging
# By Laszlo Ersek (2) and others
# Via Michael Roth
* mdroth/qga-pull-4-2-13:
qemu-ga: ga_get_fd_handle(): abort if fd_counter overflows
qga schema: document generic QERR_UNSUPPORTED
qga schema: mark optional GuestLogicalProcessor.can-offline with #optional
qga: add windows implementation for guest-set-time
qga: add windows implementation for guest-get-time
-rw-r--r-- | qga/commands-win32.c | 56 | ||||
-rw-r--r-- | qga/main.c | 8 | ||||
-rw-r--r-- | qga/qapi-schema.json | 18 |
3 files changed, 74 insertions, 8 deletions
diff --git a/qga/commands-win32.c b/qga/commands-win32.c index b19be9db48..24e4ad0319 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -22,6 +22,12 @@ #define SHTDN_REASON_FLAG_PLANNED 0x80000000 #endif +/* 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)) + static void acquire_privilege(const char *name, Error **err) { HANDLE token; @@ -280,13 +286,57 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **err) int64_t qmp_guest_get_time(Error **errp) { - error_set(errp, QERR_UNSUPPORTED); - return -1; + 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; } void qmp_guest_set_time(int64_t time_ns, Error **errp) { - error_set(errp, QERR_UNSUPPORTED); + SYSTEMTIME ts; + FILETIME tf; + LONGLONG time; + + if (time_ns < 0 || time_ns / 100 > INT64_MAX - W32_FT_OFFSET) { + error_setg(errp, "Time %" PRId64 "is invalid", time_ns); + return; + } + + time = time_ns / 100 + W32_FT_OFFSET; + + tf.dwLowDateTime = (DWORD) time; + tf.dwHighDateTime = (DWORD) (time >> 32); + + if (!FileTimeToSystemTime(&tf, &ts)) { + error_setg(errp, "Failed to convert system time %d", (int)GetLastError()); + return; + } + + acquire_privilege(SE_SYSTEMTIME_NAME, errp); + if (error_is_set(errp)) { + return; + } + + if (!SetSystemTime(&ts)) { + error_setg(errp, "Failed to set time to guest: %d", (int)GetLastError()); + return; + } } GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp) diff --git a/qga/main.c b/qga/main.c index 74ef7885b2..1841759db2 100644 --- a/qga/main.c +++ b/qga/main.c @@ -889,9 +889,13 @@ int64_t ga_get_fd_handle(GAState *s, Error **errp) g_assert(!ga_is_frozen(s)); handle = s->pstate.fd_counter++; - if (s->pstate.fd_counter < 0) { - s->pstate.fd_counter = 0; + + /* This should never happen on a reasonable timeframe, as guest-file-open + * would have to be issued 2^63 times */ + if (s->pstate.fd_counter == INT64_MAX) { + abort(); } + if (!write_persistent_state(&s->pstate, s->pstate_filepath)) { error_setg(errp, "failed to commit persistent state to disk"); } diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index dac4e6f95f..7155b7ab55 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -2,6 +2,17 @@ ## # +# General note concerning the use of guest agent interfaces: +# +# "unsupported" is a higher-level error than the errors that individual +# commands might document. The caller should always be prepared to receive +# QERR_UNSUPPORTED, even if the given command doesn't specify it, or doesn't +# document any failure mode at all. +# +## + +## +# # Echo back a unique integer value, and prepend to response a # leading sentinel byte (0xFF) the client can check scan for. # @@ -562,9 +573,10 @@ # # @online: Whether the VCPU is enabled. # -# @can-offline: Whether offlining the VCPU is possible. This member is always -# filled in by the guest agent when the structure is returned, -# and always ignored on input (hence it can be omitted then). +# @can-offline: #optional Whether offlining the VCPU is possible. This member +# is always filled in by the guest agent when the structure is +# returned, and always ignored on input (hence it can be omitted +# then). # # Since: 1.5 ## |