All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Roth <mdroth@linux.vnet.ibm.com>
To: "Denis V. Lunev" <den@openvz.org>
Cc: Olga Krishtal <okrishtal@parallels.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 2/8] qga: implement file commands for Windows guest
Date: Tue, 03 Feb 2015 15:15:20 -0600	[thread overview]
Message-ID: <20150203211520.6410.51074@loki> (raw)
In-Reply-To: <1420031214-6053-3-git-send-email-den@openvz.org>

Quoting Denis V. Lunev (2014-12-31 07:06:48)
> From: Olga Krishtal <okrishtal@parallels.com>
> 
> The following commands are implemented:
> - guest_file_open
> - guest_file_close
> - guest_file_write
> - guest_file_read
> - guest_file_seek
> - guest_file_flush
> 
> Motivation is quite simple: Windows guests should be supported with the
> same set of features as Linux one. Also this patch is a prerequisite for
> Windows guest-exec command support.
> 
> Signed-off-by: Olga Krishtal <okrishtal@parallels.com>
> Signed-off-by: Denis V. Lunev <den@openvz.org>
> CC: Michael Roth <mdroth@linux.vnet.ibm.com>
> ---
>  qga/commands-win32.c | 271 +++++++++++++++++++++++++++++++++++++++++++++++----
>  1 file changed, 250 insertions(+), 21 deletions(-)
> 
> diff --git a/qga/commands-win32.c b/qga/commands-win32.c
> index 3bcbeae..5db96ef 100644
> --- a/qga/commands-win32.c
> +++ b/qga/commands-win32.c
> @@ -14,10 +14,13 @@
>  #include <glib.h>
>  #include <wtypes.h>
>  #include <powrprof.h>
> +#include <stdio.h>
> +#include <string.h>
>  #include "qga/guest-agent-core.h"
>  #include "qga/vss-win32.h"
>  #include "qga-qmp-commands.h"
>  #include "qapi/qmp/qerror.h"
> +#include "qemu/queue.h"
> 
>  #ifndef SHTDN_REASON_FLAG_PLANNED
>  #define SHTDN_REASON_FLAG_PLANNED 0x80000000
> @@ -29,6 +32,146 @@
>                         (365 * (1970 - 1601) +       \
>                          (1970 - 1601) / 4 - 3))
> 
> +#define INVALID_SET_FILE_POINTER ((DWORD)-1)
> +
> +typedef struct GuestFileHandle {
> +    int64_t id;
> +    HANDLE fh;
> +    QTAILQ_ENTRY(GuestFileHandle) next;
> +} GuestFileHandle;
> +
> +static struct {
> +    QTAILQ_HEAD(, GuestFileHandle) filehandles;
> +} guest_file_state;
> +
> +
> +typedef struct OpenFlags {
> +    const char *forms;
> +    DWORD desired_access;
> +    DWORD creation_disposition;
> +} OpenFlags;
> +static OpenFlags guest_file_open_modes[] = {
> +    {"r",   GENERIC_READ,               OPEN_EXISTING},
> +    {"rb",  GENERIC_READ,               OPEN_EXISTING},
> +    {"w",   GENERIC_WRITE,              CREATE_ALWAYS},
> +    {"wb",  GENERIC_WRITE,              CREATE_ALWAYS},
> +    {"a",   GENERIC_WRITE,              OPEN_ALWAYS  },
> +    {"r+",  GENERIC_WRITE|GENERIC_READ, OPEN_EXISTING},
> +    {"rb+", GENERIC_WRITE|GENERIC_READ, OPEN_EXISTING},
> +    {"r+b", GENERIC_WRITE|GENERIC_READ, OPEN_EXISTING},
> +    {"w+",  GENERIC_WRITE|GENERIC_READ, CREATE_ALWAYS},
> +    {"wb+", GENERIC_WRITE|GENERIC_READ, CREATE_ALWAYS},
> +    {"w+b", GENERIC_WRITE|GENERIC_READ, CREATE_ALWAYS},
> +    {"a+",  GENERIC_WRITE|GENERIC_READ, OPEN_ALWAYS  },
> +    {"ab+", GENERIC_WRITE|GENERIC_READ, OPEN_ALWAYS  },
> +    {"a+b", GENERIC_WRITE|GENERIC_READ, OPEN_ALWAYS  }
> +};
> +
> +static OpenFlags *find_open_flag(const char *mode_str)
> +{
> +    int mode;
> +    Error **errp = NULL;
> +
> +    for (mode = 0; mode < ARRAY_SIZE(guest_file_open_modes); ++mode) {
> +        OpenFlags *flags = guest_file_open_modes + mode;
> +
> +        if (strcmp(flags->forms, mode_str) == 0) {
> +            return flags;
> +        }
> +    }
> +
> +    error_setg(errp, "invalid file open mode '%s'", mode_str);
> +    return NULL;
> +}
> +
> +static int64_t guest_file_handle_add(HANDLE fh, Error **errp)
> +{
> +    GuestFileHandle *gfh;
> +    int64_t handle;
> +
> +    handle = ga_get_fd_handle(ga_state, errp);
> +    if (handle < 0) {
> +        return -1;
> +    }
> +    gfh = g_malloc0(sizeof(GuestFileHandle));
> +    gfh->id = handle;
> +    gfh->fh = fh;
> +    QTAILQ_INSERT_TAIL(&guest_file_state.filehandles, gfh, next);
> +
> +    return handle;
> +}
> +
> +static GuestFileHandle *guest_file_handle_find(int64_t id, Error **errp)
> +{
> +    GuestFileHandle *gfh;
> +    QTAILQ_FOREACH(gfh, &guest_file_state.filehandles, next) {
> +        if (gfh->id == id) {
> +            return gfh;
> +        }
> +    }
> +    error_setg(errp, "handle '%" PRId64 "' has not been found", id);
> +    return NULL;
> +}
> +
> +int64_t qmp_guest_file_open(const char *path, bool has_mode,
> +                            const char *mode, Error **errp)
> +{
> +    int64_t fd;
> +    HANDLE fh;
> +    HANDLE templ_file = NULL;
> +    DWORD share_mode = FILE_SHARE_READ;
> +    DWORD flags_and_attr = FILE_ATTRIBUTE_NORMAL;
> +    LPSECURITY_ATTRIBUTES sa_attr = NULL;
> +    OpenFlags *guest_flags;
> +
> +    if (!has_mode) {
> +        mode = "r";
> +    }
> +    slog("guest-file-open called, filepath: %s, mode: %s", path, mode);
> +    guest_flags = find_open_flag(mode);
> +    if (guest_flags == NULL) {
> +        error_setg(errp, "invalid file open mode");
> +        return -1;
> +    }
> +
> +    fh = CreateFile(path, guest_flags->desired_access, share_mode, sa_attr,
> +                    guest_flags->creation_disposition, flags_and_attr,
> +                    templ_file);
> +    if (fh == INVALID_HANDLE_VALUE) {
> +        error_setg_errno(errp, GetLastError(), "failed to open file '%s'",
> +                         path);

For working with GetLastError() I think error_setg_win32() is what you
want. Same for all the other occurrences.

  reply	other threads:[~2015-02-03 21:15 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-31 13:06 [Qemu-devel] [PATCH v2 0/8] qemu: guest agent: implement guest-exec command for Linux Denis V. Lunev
2014-12-31 13:06 ` [Qemu-devel] [PATCH 1/8] qga: fixed warning in qemu-ga.exe for mingw >= 4.9.1 Denis V. Lunev
2015-02-03 21:29   ` Eric Blake
2015-02-04 14:25     ` Olga Krishtal
2014-12-31 13:06 ` [Qemu-devel] [PATCH 2/8] qga: implement file commands for Windows guest Denis V. Lunev
2015-02-03 21:15   ` Michael Roth [this message]
2014-12-31 13:06 ` [Qemu-devel] [PATCH 3/8] guest agent: guest-file-open: refactoring Denis V. Lunev
2015-02-03 22:04   ` Eric Blake
2014-12-31 13:06 ` [Qemu-devel] [PATCH 4/8] guest agent: add guest-pipe-open Denis V. Lunev
2015-02-03 21:57   ` Eric Blake
2015-02-03 22:06     ` Eric Blake
2014-12-31 13:06 ` [Qemu-devel] [PATCH 5/8] guest agent: add guest-exec and guest-exec-status interfaces Denis V. Lunev
2015-02-03 21:45   ` Eric Blake
2014-12-31 13:06 ` [Qemu-devel] [PATCH 6/8] guest agent: ignore SIGPIPE signal Denis V. Lunev
2014-12-31 13:06 ` [Qemu-devel] [PATCH 7/8] guest agent: add guest-pipe-open command on Windows Denis V. Lunev
2014-12-31 13:06 ` [Qemu-devel] [PATCH 8/8] guest agent: add guest-exec and guest-exec-status interfaces " Denis V. Lunev
2015-01-09 17:06 ` [Qemu-devel] [PATCH v2 0/8] qemu: guest agent: implement guest-exec command for Linux Michael Roth
2015-01-09 17:10   ` Eric Blake
2015-01-09 18:09   ` Denis V. Lunev
2015-01-09 19:29     ` Michael Roth
2015-01-13 10:13       ` Denis V. Lunev
2015-02-03 20:24         ` Michael Roth
2015-02-03 21:31           ` Denis V. Lunev
2015-01-27 13:52 ` Denis V. Lunev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150203211520.6410.51074@loki \
    --to=mdroth@linux.vnet.ibm.com \
    --cc=den@openvz.org \
    --cc=okrishtal@parallels.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.