qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PULL 0/5] qga: w32 guest-{set, get}-time implementations and minor fixes
@ 2013-04-02 14:13 Michael Roth
  2013-04-02 14:13 ` [Qemu-devel] [PATCH 1/5] qga: add windows implementation for guest-get-time Michael Roth
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Michael Roth @ 2013-04-02 14:13 UTC (permalink / raw)
  To: qemu-devel; +Cc: aliguori, lersek, lilei, lcapitulino

The following changes since commit 5d45de9796539f95eb6b1201588362981f8cb2d4:

  microblaze: Add support for the sleep insn (2013-04-02 10:47:29 +0200)

are available in the git repository at:

  git://github.com/mdroth/qemu.git qga-pull-4-2-13

for you to fetch changes up to ce7f7cc2715145eadf1ac45a5dae63f535fc8bbf:

  qemu-ga: ga_get_fd_handle(): abort if fd_counter overflows (2013-04-02 09:06:11 -0500)

----------------------------------------------------------------
Laszlo Ersek (2):
      qga schema: mark optional GuestLogicalProcessor.can-offline with #optional
      qga schema: document generic QERR_UNSUPPORTED

Lei Li (2):
      qga: add windows implementation for guest-get-time
      qga: add windows implementation for guest-set-time

Luiz Capitulino (1):
      qemu-ga: ga_get_fd_handle(): abort if fd_counter overflows

 qga/commands-win32.c |   56 +++++++++++++++++++++++++++++++++++++++++++++++---
 qga/main.c           |    8 ++++++--
 qga/qapi-schema.json |   18 +++++++++++++---
 3 files changed, 74 insertions(+), 8 deletions(-)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH 1/5] qga: add windows implementation for guest-get-time
  2013-04-02 14:13 [Qemu-devel] [PULL 0/5] qga: w32 guest-{set, get}-time implementations and minor fixes Michael Roth
@ 2013-04-02 14:13 ` Michael Roth
  2013-04-02 14:13 ` [Qemu-devel] [PATCH 2/5] qga: add windows implementation for guest-set-time Michael Roth
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Michael Roth @ 2013-04-02 14:13 UTC (permalink / raw)
  To: qemu-devel; +Cc: aliguori, lersek, lilei, lcapitulino

From: Lei Li <lilei@linux.vnet.ibm.com>

Signed-off-by: Lei Li <lilei@linux.vnet.ibm.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
 qga/commands-win32.c |   27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index b19be9d..d98e3ee 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,8 +286,25 @@ 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)
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH 2/5] qga: add windows implementation for guest-set-time
  2013-04-02 14:13 [Qemu-devel] [PULL 0/5] qga: w32 guest-{set, get}-time implementations and minor fixes Michael Roth
  2013-04-02 14:13 ` [Qemu-devel] [PATCH 1/5] qga: add windows implementation for guest-get-time Michael Roth
@ 2013-04-02 14:13 ` Michael Roth
  2013-04-02 14:13 ` [Qemu-devel] [PATCH 3/5] qga schema: mark optional GuestLogicalProcessor.can-offline with #optional Michael Roth
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Michael Roth @ 2013-04-02 14:13 UTC (permalink / raw)
  To: qemu-devel; +Cc: aliguori, lersek, lilei, lcapitulino

From: Lei Li <lilei@linux.vnet.ibm.com>

Signed-off-by: Lei Li <lilei@linux.vnet.ibm.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
 qga/commands-win32.c |   29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index d98e3ee..24e4ad0 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -309,7 +309,34 @@ int64_t qmp_guest_get_time(Error **errp)
 
 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)
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH 3/5] qga schema: mark optional GuestLogicalProcessor.can-offline with #optional
  2013-04-02 14:13 [Qemu-devel] [PULL 0/5] qga: w32 guest-{set, get}-time implementations and minor fixes Michael Roth
  2013-04-02 14:13 ` [Qemu-devel] [PATCH 1/5] qga: add windows implementation for guest-get-time Michael Roth
  2013-04-02 14:13 ` [Qemu-devel] [PATCH 2/5] qga: add windows implementation for guest-set-time Michael Roth
@ 2013-04-02 14:13 ` Michael Roth
  2013-04-02 14:13 ` [Qemu-devel] [PATCH 4/5] qga schema: document generic QERR_UNSUPPORTED Michael Roth
  2013-04-02 14:13 ` [Qemu-devel] [PATCH 5/5] qemu-ga: ga_get_fd_handle(): abort if fd_counter overflows Michael Roth
  4 siblings, 0 replies; 6+ messages in thread
From: Michael Roth @ 2013-04-02 14:13 UTC (permalink / raw)
  To: qemu-devel; +Cc: aliguori, lersek, lilei, lcapitulino

From: Laszlo Ersek <lersek@redhat.com>

Suggested-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
 qga/qapi-schema.json |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json
index dac4e6f..2af3515 100644
--- a/qga/qapi-schema.json
+++ b/qga/qapi-schema.json
@@ -562,9 +562,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
 ##
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH 4/5] qga schema: document generic QERR_UNSUPPORTED
  2013-04-02 14:13 [Qemu-devel] [PULL 0/5] qga: w32 guest-{set, get}-time implementations and minor fixes Michael Roth
                   ` (2 preceding siblings ...)
  2013-04-02 14:13 ` [Qemu-devel] [PATCH 3/5] qga schema: mark optional GuestLogicalProcessor.can-offline with #optional Michael Roth
@ 2013-04-02 14:13 ` Michael Roth
  2013-04-02 14:13 ` [Qemu-devel] [PATCH 5/5] qemu-ga: ga_get_fd_handle(): abort if fd_counter overflows Michael Roth
  4 siblings, 0 replies; 6+ messages in thread
From: Michael Roth @ 2013-04-02 14:13 UTC (permalink / raw)
  To: qemu-devel; +Cc: aliguori, lersek, lilei, lcapitulino

From: Laszlo Ersek <lersek@redhat.com>

Part of the wording was shamelessly stolen from Michael Roth's email.

Suggested-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
 qga/qapi-schema.json |   11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json
index 2af3515..7155b7a 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.
 #
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH 5/5] qemu-ga: ga_get_fd_handle(): abort if fd_counter overflows
  2013-04-02 14:13 [Qemu-devel] [PULL 0/5] qga: w32 guest-{set, get}-time implementations and minor fixes Michael Roth
                   ` (3 preceding siblings ...)
  2013-04-02 14:13 ` [Qemu-devel] [PATCH 4/5] qga schema: document generic QERR_UNSUPPORTED Michael Roth
@ 2013-04-02 14:13 ` Michael Roth
  4 siblings, 0 replies; 6+ messages in thread
From: Michael Roth @ 2013-04-02 14:13 UTC (permalink / raw)
  To: qemu-devel; +Cc: aliguori, lersek, lilei, lcapitulino

From: Luiz Capitulino <lcapitulino@redhat.com>

Today we reset fd_counter if it wraps, but it's better to abort()
instead, as fd_counter should never reach INT64_MAX.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>

*fixed typo: s/resonable/reasonable/

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
 qga/main.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/qga/main.c b/qga/main.c
index 74ef788..1841759 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");
     }
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-04-02 14:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-02 14:13 [Qemu-devel] [PULL 0/5] qga: w32 guest-{set, get}-time implementations and minor fixes Michael Roth
2013-04-02 14:13 ` [Qemu-devel] [PATCH 1/5] qga: add windows implementation for guest-get-time Michael Roth
2013-04-02 14:13 ` [Qemu-devel] [PATCH 2/5] qga: add windows implementation for guest-set-time Michael Roth
2013-04-02 14:13 ` [Qemu-devel] [PATCH 3/5] qga schema: mark optional GuestLogicalProcessor.can-offline with #optional Michael Roth
2013-04-02 14:13 ` [Qemu-devel] [PATCH 4/5] qga schema: document generic QERR_UNSUPPORTED Michael Roth
2013-04-02 14:13 ` [Qemu-devel] [PATCH 5/5] qemu-ga: ga_get_fd_handle(): abort if fd_counter overflows Michael Roth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).