All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrange" <berrange@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@gmail.com>
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH/RFC 4/7] Allow saving screendump to a UNIX socket
Date: Mon, 12 Mar 2012 17:07:40 +0000	[thread overview]
Message-ID: <20120312170740.GB20435@redhat.com> (raw)
In-Reply-To: <1331557893-30806-5-git-send-email-marcandre.lureau@redhat.com>

On Mon, Mar 12, 2012 at 02:11:30PM +0100, Marc-André Lureau wrote:
> By using the 'unix:' prefix notation, similar to the migration uri, we
> can now dump to a UNIX socket. IO is still sync
> ---
>  hw/vga.c    |   64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
>  qemu-file.h |    1 +
>  2 files changed, 63 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/vga.c b/hw/vga.c
> index 24af4a1..bb5df70 100644
> --- a/hw/vga.c
> +++ b/hw/vga.c
> @@ -30,6 +30,7 @@
>  #include "pixel_ops.h"
>  #include "qemu-timer.h"
>  #include "xen.h"
> +#include "qemu_socket.h"
>  
>  //#define DEBUG_VGA
>  //#define DEBUG_VGA_MEM
> @@ -37,6 +38,14 @@
>  
>  //#define DEBUG_BOCHS_VBE
>  
> +#ifdef DEBUG_VGA
> +#define DPRINTF(fmt, ...) \
> +    do { printf("vga: " fmt, ## __VA_ARGS__); } while (0)
> +#else
> +#define DPRINTF(fmt, ...) \
> +    do { } while (0)
> +#endif
> +
>  /*
>   * Video Graphics Array (VGA)
>   *
> @@ -2362,7 +2371,58 @@ void vga_init_vbe(VGACommonState *s, MemoryRegion *system_memory)
>  /********************************************************/
>  /* vga screen dump */
>  
> -int ppm_save(const char *filename, struct DisplaySurface *ds)
> +#if !defined(WIN32)
> +static QEMUFile *qemu_fopen_unix(const char *path, const char *mode)
> +{
> +    struct sockaddr_un addr;
> +    int ret, fd;
> +
> +    addr.sun_family = AF_UNIX;
> +    snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", path);
> +
> +    fd = qemu_socket(PF_UNIX, SOCK_STREAM, 0);
> +    if (fd == -1) {
> +        DPRINTF("Unable to open socket: %s\n", strerror(errno));
> +        return NULL;
> +    }
> +
> +    do {
> +        ret = connect(fd, (struct sockaddr *)&addr, sizeof(addr));
> +        if (ret == -1) {
> +            ret = -errno;
> +        }
> +    } while (ret == -EINTR);
> +
> +    if (ret < 0) {
> +        DPRINTF("connect failed: %s\n": strerror(errno));
> +        return NULL;
> +    }
> +
> +    return qemu_fopen_socket(fd, mode);
> +}
> +#endif
> +
> +QEMUFile *qemu_fopen_uri(const char *uri, const char *mode)
> +{
> +    QEMUFile *f = NULL;
> +    const char *p;
> +
> +    g_return_val_if_fail(uri != NULL, NULL);
> +    g_return_val_if_fail(mode != NULL, NULL);
> +
> +#if !defined(WIN32)
> +    if (strstart(uri, "unix:", &p)) {
> +        f = qemu_fopen_unix(p, mode);
> +    }
> +#endif
> +    if (f == NULL) {
> +        f = qemu_fopen(uri, mode);
> +    }
> +
> +    return f;
> +}
> +
> +int ppm_save(const char *uri, struct DisplaySurface *ds)
>  {
>      QEMUFile *f;
>      uint8_t *d, *d1;
> @@ -2372,7 +2432,7 @@ int ppm_save(const char *filename, struct DisplaySurface *ds)
>      char *linebuf, *pbuf;
>      gchar *header;
>  
> -    f = qemu_fopen(filename, "wb");
> +    f = qemu_fopen_uri(uri, "wb");
>      g_return_val_if_fail(f != NULL, -1);
>  
>      header = g_strdup_printf("P6\n%d %d\n%d\n", ds->width, ds->height, 255);
> diff --git a/qemu-file.h b/qemu-file.h
> index efd6b1c..0914d83 100644
> --- a/qemu-file.h
> +++ b/qemu-file.h
> @@ -68,6 +68,7 @@ QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer,
>  QEMUFile *qemu_fopen(const char *filename, const char *mode);
>  QEMUFile *qemu_fdopen(int fd, const char *mode);
>  QEMUFile *qemu_fopen_socket(int fd, const char *mode);
> +QEMUFile *qemu_fopen_uri(const char *uri, const char *mode);
>  QEMUFile *qemu_popen(FILE *popen_file, const char *mode);
>  QEMUFile *qemu_popen_cmd(const char *command, const char *mode);
>  int qemu_stdio_fd(QEMUFile *f);

It would be even more broadly useful if the screendump command was
extended to allow a file descriptor to be just passed across to
QEMU, avoiding the need to interact with the filesystem namespace
at all.

Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

  reply	other threads:[~2012-03-12 17:08 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-12 13:11 [Qemu-devel] [PATCH/RFC 0/7] Screendump to UNIX socket & in PNG format Marc-André Lureau
2012-03-12 13:11 ` [Qemu-devel] [PATCH/RFC 1/7] ppm_save: use QEMUFile Marc-André Lureau
2012-03-12 13:11 ` [Qemu-devel] [PATCH/RFC 2/7] Allow a qemu_fopen_socket() to be opened for writing Marc-André Lureau
2012-03-12 13:11 ` [Qemu-devel] [PATCH/RFC 3/7] Close socket when closing QEMUFile Marc-André Lureau
2012-03-13  6:09   ` Igor Mitsyanko
2012-03-12 13:11 ` [Qemu-devel] [PATCH/RFC 4/7] Allow saving screendump to a UNIX socket Marc-André Lureau
2012-03-12 17:07   ` Daniel P. Berrange [this message]
2012-03-13  8:15   ` Gerd Hoffmann
2012-03-12 13:11 ` [Qemu-devel] [PATCH/RFC 5/7] configure: split PNG support from vnc_png feature Marc-André Lureau
2012-03-12 13:11 ` [Qemu-devel] [PATCH/RFC 6/7] Isolate color conversion from PPM handling Marc-André Lureau
2012-03-12 13:11 ` [Qemu-devel] [PATCH/RFC 7/7] Add PNG screendump Marc-André Lureau
2012-03-12 17:05   ` Daniel P. Berrange
2012-03-12 15:42 ` [Qemu-devel] [PATCH/RFC 0/7] Screendump to UNIX socket & in PNG format Eric Blake
2012-03-12 19:29   ` Marc-André Lureau
2012-03-12 17:10 ` Daniel P. Berrange
2012-03-12 18:06 ` Stefan Hajnoczi
2012-03-12 19:27   ` Marc-André Lureau
2012-03-13 10:59     ` Stefan Hajnoczi
2012-03-13 11:14       ` Marc-André Lureau
2012-03-13 11:17         ` Stefan Hajnoczi
2012-03-13 13:17           ` Gerd Hoffmann
2012-03-14  9:42             ` Stefan Hajnoczi
2012-03-14  9:51               ` Gerd Hoffmann
2012-03-14 10:01                 ` Stefan Hajnoczi
2012-03-14 13:13                   ` Luiz Capitulino
2012-03-14 13:19                     ` Alon Levy
2012-03-14 13:28                       ` Eric Blake
2012-03-14 13:36                         ` Luiz Capitulino
2012-03-14 11:42               ` Kevin Wolf
2012-03-14 13:14                 ` Luiz Capitulino
2012-03-12 18:53 ` Anthony Liguori
2012-03-12 18:56   ` Marc-André Lureau
2012-03-12 18:57     ` Anthony Liguori
2012-03-12 21:22       ` Michael Roth
2012-03-13 10:12         ` Jan Kiszka

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=20120312170740.GB20435@redhat.com \
    --to=berrange@redhat.com \
    --cc=marcandre.lureau@gmail.com \
    --cc=marcandre.lureau@redhat.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.