Commit 0459650d authored by Peter Maydell's avatar Peter Maydell
Browse files

Merge remote-tracking branch 'remotes/mdroth/qga-pull-2014-02-24' into staging



* remotes/mdroth/qga-pull-2014-02-24:
  qemu-ga: isa-serial support on Windows
  qga: Fix memory allocation pasto
  qga: Don't require 'time' argument in guest-set-time command
  qga: vss-win32: Fix interference with snapshot deletion by other VSS request
  qga: vss-win32: Fix interference with snapshot creation by other VSS requesters
  qga: vss-win32: Use NULL as an invalid pointer for OpenEvent and CreateEvent

Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
parents 05fd3bf2 a749f42d
Loading
Loading
Loading
Loading
+18 −2
Original line number Diff line number Diff line
@@ -287,12 +287,22 @@ GIOStatus ga_channel_write_all(GAChannel *c, const char *buf, size_t size)
static gboolean ga_channel_open(GAChannel *c, GAChannelMethod method,
                                const gchar *path)
{
    if (method != GA_CHANNEL_VIRTIO_SERIAL) {
    COMMTIMEOUTS comTimeOut = {0};
    gchar newpath[MAXPATHLEN] = {0};
    comTimeOut.ReadIntervalTimeout = 1;

    if (method != GA_CHANNEL_VIRTIO_SERIAL && method != GA_CHANNEL_ISA_SERIAL) {
        g_critical("unsupported communication method");
        return false;
    }

    c->handle = CreateFile(path, GENERIC_READ | GENERIC_WRITE, 0, NULL,
    if (method == GA_CHANNEL_ISA_SERIAL){
        snprintf(newpath, sizeof(newpath), "\\\\.\\%s", path);
    }else {
        g_strlcpy(newpath, path, sizeof(newpath));
    }

    c->handle = CreateFile(newpath, GENERIC_READ | GENERIC_WRITE, 0, NULL,
                           OPEN_EXISTING,
                           FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, NULL);
    if (c->handle == INVALID_HANDLE_VALUE) {
@@ -300,6 +310,12 @@ static gboolean ga_channel_open(GAChannel *c, GAChannelMethod method,
        return false;
    }

    if (method == GA_CHANNEL_ISA_SERIAL && !SetCommTimeouts(c->handle,&comTimeOut)) {
        g_critical("error setting timeout for com port: %lu",GetLastError());
        CloseHandle(c->handle);
        return false;
    }

    return true;
}

+24 −15
Original line number Diff line number Diff line
@@ -142,7 +142,7 @@ int64_t qmp_guest_get_time(Error **errp)
   return time_ns;
}

void qmp_guest_set_time(int64_t time_ns, Error **errp)
void qmp_guest_set_time(bool has_time, int64_t time_ns, Error **errp)
{
    int ret;
    int status;
@@ -150,6 +150,8 @@ void qmp_guest_set_time(int64_t time_ns, Error **errp)
    Error *local_err = NULL;
    struct timeval tv;

    /* If user has passed a time, validate and set it. */
    if (has_time) {
        /* year-2038 will overflow in case time_t is 32bit */
        if (time_ns / 1000000000 != (time_t)(time_ns / 1000000000)) {
            error_setg(errp, "Time %" PRId64 " is too large", time_ns);
@@ -164,8 +166,12 @@ void qmp_guest_set_time(int64_t time_ns, Error **errp)
            error_setg_errno(errp, errno, "Failed to set time to guest");
            return;
        }
    }

    /* Set the Hardware Clock to the current System Time. */
    /* Now, if user has passed a time to set and the system time is set, we
     * just need to synchronize the hardware clock. However, if no time was
     * passed, user is requesting the opposite: set the system time from the
     * hardware clock. */
    pid = fork();
    if (pid == 0) {
        setsid();
@@ -173,7 +179,10 @@ void qmp_guest_set_time(int64_t time_ns, Error **errp)
        reopen_fd_to_null(1);
        reopen_fd_to_null(2);

        execle("/sbin/hwclock", "hwclock", "-w", NULL, environ);
        /* Use '/sbin/hwclock -w' to set RTC from the system time,
         * or '/sbin/hwclock -s' to set the system time from RTC. */
        execle("/sbin/hwclock", "hwclock", has_time ? "-w" : "-s",
               NULL, environ);
        _exit(EXIT_FAILURE);
    } else if (pid < 0) {
        error_setg_errno(errp, errno, "failed to create child process");
@@ -525,7 +534,7 @@ struct GuestFileSeek *qmp_guest_file_seek(int64_t handle, int64_t offset,
    if (ret == -1) {
        error_setg_errno(err, errno, "failed to seek file");
    } else {
        seek_data = g_malloc0(sizeof(GuestFileRead));
        seek_data = g_new0(GuestFileSeek, 1);
        seek_data->position = ftell(fh);
        seek_data->eof = feof(fh);
    }
+23 −11
Original line number Diff line number Diff line
@@ -370,12 +370,14 @@ int64_t qmp_guest_get_time(Error **errp)
    return time_ns;
}

void qmp_guest_set_time(int64_t time_ns, Error **errp)
void qmp_guest_set_time(bool has_time, int64_t time_ns, Error **errp)
{
    SYSTEMTIME ts;
    FILETIME tf;
    LONGLONG time;

    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;
@@ -387,9 +389,19 @@ void qmp_guest_set_time(int64_t time_ns, Error **errp)
        tf.dwHighDateTime = (DWORD) (time >> 32);

        if (!FileTimeToSystemTime(&tf, &ts)) {
        error_setg(errp, "Failed to convert system time %d", (int)GetLastError());
            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;
        }
    }

    acquire_privilege(SE_SYSTEMTIME_NAME, errp);
    if (error_is_set(errp)) {
+13 −4
Original line number Diff line number Diff line
@@ -47,9 +47,11 @@
#ifndef _WIN32
#define QGA_VIRTIO_PATH_DEFAULT "/dev/virtio-ports/org.qemu.guest_agent.0"
#define QGA_STATE_RELATIVE_DIR  "run"
#define QGA_SERIAL_PATH_DEFAULT "/dev/ttyS0"
#else
#define QGA_VIRTIO_PATH_DEFAULT "\\\\.\\Global\\org.qemu.guest_agent.0"
#define QGA_STATE_RELATIVE_DIR  "qemu-ga"
#define QGA_SERIAL_PATH_DEFAULT "COM1"
#endif
#ifdef CONFIG_FSFREEZE
#define QGA_FSFREEZE_HOOK_DEFAULT CONFIG_QEMU_CONFDIR "/fsfreeze-hook"
@@ -189,6 +191,8 @@ static void usage(const char *cmd)
"  -m, --method      transport method: one of unix-listen, virtio-serial, or\n"
"                    isa-serial (virtio-serial is the default)\n"
"  -p, --path        device/socket path (the default for virtio-serial is:\n"
"                    %s,\n"
"                    the default for isa-serial is:\n"
"                    %s)\n"
"  -l, --logfile     set logfile path, logs to stderr by default\n"
"  -f, --pidfile     specify pidfile (default is %s)\n"
@@ -215,7 +219,8 @@ static void usage(const char *cmd)
"  -h, --help        display this help and exit\n"
"\n"
"Report bugs to <mdroth@linux.vnet.ibm.com>\n"
    , cmd, QEMU_VERSION, QGA_VIRTIO_PATH_DEFAULT, dfl_pathnames.pidfile,
    , cmd, QEMU_VERSION, QGA_VIRTIO_PATH_DEFAULT, QGA_SERIAL_PATH_DEFAULT,
    dfl_pathnames.pidfile,
#ifdef CONFIG_FSFREEZE
    QGA_FSFREEZE_HOOK_DEFAULT,
#endif
@@ -659,12 +664,16 @@ static gboolean channel_init(GAState *s, const gchar *method, const gchar *path)
    }

    if (path == NULL) {
        if (strcmp(method, "virtio-serial") != 0) {
        if (strcmp(method, "virtio-serial") == 0 ) {
            /* try the default path for the virtio-serial port */
            path = QGA_VIRTIO_PATH_DEFAULT;
        } else if (strcmp(method, "isa-serial") == 0){
            /* try the default path for the serial port - COM1 */
            path = QGA_SERIAL_PATH_DEFAULT;
        } else {
            g_critical("must specify a path for this channel");
            return false;
        }
        /* try the default path for the virtio-serial port */
        path = QGA_VIRTIO_PATH_DEFAULT;
    }

    if (strcmp(method, "virtio-serial") == 0) {
+5 −4
Original line number Diff line number Diff line
@@ -120,17 +120,18 @@
# This command tries to set guest time to the given value,
# then sets the Hardware Clock to the current System Time.
# This will make it easier for a guest to resynchronize
# without waiting for NTP.
# without waiting for NTP. If no @time is specified, then
# the time to set is read from RTC.
#
# @time: time of nanoseconds, relative to the Epoch of
#        1970-01-01 in UTC.
# @time: #optional time of nanoseconds, relative to the Epoch
#        of 1970-01-01 in UTC.
#
# Returns: Nothing on success.
#
# Since: 1.5
##
{ 'command': 'guest-set-time',
  'data': { 'time': 'int' } }
  'data': { '*time': 'int' } }

##
# @GuestAgentCommandInfo:
Loading