From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:37338) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S78iu-0003C8-S4 for qemu-devel@nongnu.org; Mon, 12 Mar 2012 13:08:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S78io-0001IY-8T for qemu-devel@nongnu.org; Mon, 12 Mar 2012 13:07:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58352) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S78io-0001IF-01 for qemu-devel@nongnu.org; Mon, 12 Mar 2012 13:07:46 -0400 Date: Mon, 12 Mar 2012 17:07:40 +0000 From: "Daniel P. Berrange" Message-ID: <20120312170740.GB20435@redhat.com> References: <1331557893-30806-1-git-send-email-marcandre.lureau@redhat.com> <1331557893-30806-5-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1331557893-30806-5-git-send-email-marcandre.lureau@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH/RFC 4/7] Allow saving screendump to a UNIX socket Reply-To: "Daniel P. Berrange" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?utf-8?Q?Marc-Andr=C3=A9?= Lureau Cc: =?utf-8?Q?Marc-Andr=C3=A9?= Lureau , qemu-devel@nongnu.org On Mon, Mar 12, 2012 at 02:11:30PM +0100, Marc-Andr=C3=A9 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(-) >=20 > 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" > =20 > //#define DEBUG_VGA > //#define DEBUG_VGA_MEM > @@ -37,6 +38,14 @@ > =20 > //#define DEBUG_BOCHS_VBE > =20 > +#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, MemoryRegio= n *system_memory) > /********************************************************/ > /* vga screen dump */ > =20 > -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 =3D AF_UNIX; > + snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", path); > + > + fd =3D qemu_socket(PF_UNIX, SOCK_STREAM, 0); > + if (fd =3D=3D -1) { > + DPRINTF("Unable to open socket: %s\n", strerror(errno)); > + return NULL; > + } > + > + do { > + ret =3D connect(fd, (struct sockaddr *)&addr, sizeof(addr)); > + if (ret =3D=3D -1) { > + ret =3D -errno; > + } > + } while (ret =3D=3D -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 =3D NULL; > + const char *p; > + > + g_return_val_if_fail(uri !=3D NULL, NULL); > + g_return_val_if_fail(mode !=3D NULL, NULL); > + > +#if !defined(WIN32) > + if (strstart(uri, "unix:", &p)) { > + f =3D qemu_fopen_unix(p, mode); > + } > +#endif > + if (f =3D=3D NULL) { > + f =3D 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 Display= Surface *ds) > char *linebuf, *pbuf; > gchar *header; > =20 > - f =3D qemu_fopen(filename, "wb"); > + f =3D qemu_fopen_uri(uri, "wb"); > g_return_val_if_fail(f !=3D NULL, -1); > =20 > header =3D g_strdup_printf("P6\n%d %d\n%d\n", ds->width, ds->heigh= t, 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, QEMUFilePutBuf= ferFunc *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 --=20 |: http://berrange.com -o- http://www.flickr.com/photos/dberrange= / :| |: http://libvirt.org -o- http://virt-manager.or= g :| |: http://autobuild.org -o- http://search.cpan.org/~danberr= / :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vn= c :|