qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Marc-André Lureau" <marcandre.lureau@gmail.com>
To: qemu-devel@nongnu.org
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [Qemu-devel] [PATCH/RFC 2/7] Allow a qemu_fopen_socket() to be opened for writing
Date: Mon, 12 Mar 2012 14:11:28 +0100	[thread overview]
Message-ID: <1331557893-30806-3-git-send-email-marcandre.lureau@redhat.com> (raw)
In-Reply-To: <1331557893-30806-1-git-send-email-marcandre.lureau@redhat.com>

---
 migration-tcp.c  |    2 +-
 migration-unix.c |    2 +-
 qemu-file.h      |    2 +-
 savevm.c         |   36 ++++++++++++++++++++++++++++++++----
 4 files changed, 35 insertions(+), 7 deletions(-)

diff --git a/migration-tcp.c b/migration-tcp.c
index 35a5781..f567898 100644
--- a/migration-tcp.c
+++ b/migration-tcp.c
@@ -140,7 +140,7 @@ static void tcp_accept_incoming_migration(void *opaque)
         goto out2;
     }
 
-    f = qemu_fopen_socket(c);
+    f = qemu_fopen_socket(c, "r");
     if (f == NULL) {
         fprintf(stderr, "could not qemu_fopen socket\n");
         goto out;
diff --git a/migration-unix.c b/migration-unix.c
index 169de88..3928f4c 100644
--- a/migration-unix.c
+++ b/migration-unix.c
@@ -137,7 +137,7 @@ static void unix_accept_incoming_migration(void *opaque)
         goto out2;
     }
 
-    f = qemu_fopen_socket(c);
+    f = qemu_fopen_socket(c, "r");
     if (f == NULL) {
         fprintf(stderr, "could not qemu_fopen socket\n");
         goto out;
diff --git a/qemu-file.h b/qemu-file.h
index 31b83f6..efd6b1c 100644
--- a/qemu-file.h
+++ b/qemu-file.h
@@ -67,7 +67,7 @@ QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer,
                          QEMUFileGetRateLimit *get_rate_limit);
 QEMUFile *qemu_fopen(const char *filename, const char *mode);
 QEMUFile *qemu_fdopen(int fd, const char *mode);
-QEMUFile *qemu_fopen_socket(int fd);
+QEMUFile *qemu_fopen_socket(int fd, 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);
diff --git a/savevm.c b/savevm.c
index 80be1ff..4171ebf 100644
--- a/savevm.c
+++ b/savevm.c
@@ -205,6 +205,21 @@ static int socket_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size)
     return len;
 }
 
+static int socket_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, int size)
+{
+    QEMUFileSocket *s = opaque;
+    ssize_t len;
+
+    do {
+        len = write(s->fd, buf, size);
+    } while (len == -1 && socket_error() == EINTR);
+
+    if (len == -1)
+        len = -socket_error();
+
+    return len;
+}
+
 static int socket_close(void *opaque)
 {
     QEMUFileSocket *s = opaque;
@@ -316,7 +331,7 @@ QEMUFile *qemu_fdopen(int fd, const char *mode)
     if (!s->stdio_file)
         goto fail;
 
-    if(mode[0] == 'r') {
+    if (mode[0] == 'r') {
         s->file = qemu_fopen_ops(s, NULL, stdio_get_buffer, stdio_fclose, 
 				 NULL, NULL, NULL);
     } else {
@@ -330,13 +345,26 @@ fail:
     return NULL;
 }
 
-QEMUFile *qemu_fopen_socket(int fd)
+QEMUFile *qemu_fopen_socket(int fd, const char *mode)
 {
     QEMUFileSocket *s = g_malloc0(sizeof(QEMUFileSocket));
 
+    if (mode == NULL ||
+	(mode[0] != 'r' && mode[0] != 'w') ||
+	mode[1] != 'b' || mode[2] != 0) {
+        fprintf(stderr, "qemu_fopen_socket: Argument validity check failed\n");
+        return NULL;
+    }
+
     s->fd = fd;
-    s->file = qemu_fopen_ops(s, NULL, socket_get_buffer, socket_close, 
-			     NULL, NULL, NULL);
+    if (mode[0] == 'r') {
+        s->file = qemu_fopen_ops(s, NULL, socket_get_buffer, socket_close,
+                                 NULL, NULL, NULL);
+    } else {
+        s->file = qemu_fopen_ops(s, socket_put_buffer, NULL, socket_close,
+                                 NULL, NULL, NULL);
+    }
+
     return s->file;
 }
 
-- 
1.7.7.6

  parent reply	other threads:[~2012-03-12 13:12 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 ` Marc-André Lureau [this message]
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
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=1331557893-30806-3-git-send-email-marcandre.lureau@redhat.com \
    --to=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 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).