Patchwork [03/12] migration: add qemu_get_fd

login
register
mail settings
Submitter Paolo Bonzini
Date Oct. 18, 2012, 10:22 a.m.
Message ID <1350555758-29988-4-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/192267/
State New
Headers show

Comments

Paolo Bonzini - Oct. 18, 2012, 10:22 a.m.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 buffered_file.c |  8 ++++++++
 qemu-file.h     |  6 ++++++
 savevm.c        | 27 +++++++++++++++++++++++++++
 3 file modificati, 41 inserzioni(+)
Orit Wasserman - Oct. 28, 2012, 11:27 a.m.
On 10/18/2012 12:22 PM, Paolo Bonzini wrote:
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  buffered_file.c |  8 ++++++++
>  qemu-file.h     |  6 ++++++
>  savevm.c        | 27 +++++++++++++++++++++++++++
>  3 file modificati, 41 inserzioni(+)
> 
> diff --git a/buffered_file.c b/buffered_file.c
> index a5c0b12..bd0f61d 100644
> --- a/buffered_file.c
> +++ b/buffered_file.c
> @@ -174,6 +174,13 @@ static int buffered_close(void *opaque)
>   *   1: Time to stop
>   *   negative: There has been an error
>   */
> +static int buffered_get_fd(void *opaque)
> +{
> +    QEMUFileBuffered *s = opaque;
> +
> +    return qemu_get_fd(s->file);
> +}
> +
>  static int buffered_rate_limit(void *opaque)
>  {
>      QEMUFileBuffered *s = opaque;
> @@ -235,6 +242,7 @@ static void buffered_rate_tick(void *opaque)
>  }
>  
>  static const QEMUFileOps buffered_file_ops = {
> +    .get_fd =         buffered_get_fd,
>      .put_buffer =     buffered_put_buffer,
>      .close =          buffered_close,
>      .rate_limit =     buffered_rate_limit,
> diff --git a/qemu-file.h b/qemu-file.h
> index c89e8e0..d552f5d 100644
> --- a/qemu-file.h
> +++ b/qemu-file.h
> @@ -47,6 +47,10 @@ typedef int (QEMUFileGetBufferFunc)(void *opaque, uint8_t *buf,
>   */
>  typedef int (QEMUFileCloseFunc)(void *opaque);
>  
> +/* Called to return the OS file descriptor associated to the QEMUFile.
> + */
> +typedef int (QEMUFileGetFD)(void *opaque);
> +
>  /* Called to determine if the file has exceeded its bandwidth allocation.  The
>   * bandwidth capping is a soft limit, not a hard limit.
>   */
> @@ -63,6 +67,7 @@ typedef struct QEMUFileOps {
>      QEMUFilePutBufferFunc *put_buffer;
>      QEMUFileGetBufferFunc *get_buffer;
>      QEMUFileCloseFunc *close;
> +    QEMUFileGetFD *get_fd;
>      QEMUFileRateLimit *rate_limit;
>      QEMUFileSetRateLimit *set_rate_limit;
>      QEMUFileGetRateLimit *get_rate_limit;
> @@ -74,6 +79,7 @@ QEMUFile *qemu_fdopen(int fd, const char *mode);
>  QEMUFile *qemu_fopen_socket(int fd);
>  QEMUFile *qemu_popen(FILE *popen_file, const char *mode);
>  QEMUFile *qemu_popen_cmd(const char *command, const char *mode);
> +int qemu_get_fd(QEMUFile *f);
>  int qemu_stdio_fd(QEMUFile *f);
>  int qemu_fclose(QEMUFile *f);
>  void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size);
> diff --git a/savevm.c b/savevm.c
> index c3ce00a..5c0a756 100644
> --- a/savevm.c
> +++ b/savevm.c
> @@ -187,6 +187,13 @@ typedef struct QEMUFileSocket
>      QEMUFile *file;
>  } QEMUFileSocket;
>  
> +static int socket_get_fd(void *opaque)
> +{
> +    QEMUFileSocket *s = opaque;
> +
> +    return s->fd;
> +}
> +
>  static int socket_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size)
>  {
>      QEMUFileSocket *s = opaque;
> @@ -209,6 +216,13 @@ static int socket_close(void *opaque)
>      return 0;
>  }
>  
> +static int stdio_get_fd(void *opaque)
> +{
> +    QEMUFileStdio *s = opaque;
> +
> +    return fileno(s->stdio_file);
> +}
> +
>  static int stdio_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, int size)
>  {
>      QEMUFileStdio *s = opaque;
> @@ -252,11 +266,13 @@ static int stdio_fclose(void *opaque)
>  }
>  
>  static const QEMUFileOps stdio_pipe_read_ops = {
> +    .get_fd =     stdio_get_fd,
>      .get_buffer = stdio_get_buffer,
>      .close =      stdio_pclose
>  };
>  
>  static const QEMUFileOps stdio_pipe_write_ops = {
> +    .get_fd =     stdio_get_fd,
>      .put_buffer = stdio_put_buffer,
>      .close =      stdio_pclose
>  };
> @@ -306,11 +322,13 @@ int qemu_stdio_fd(QEMUFile *f)
>  }
>  
>  static const QEMUFileOps stdio_file_read_ops = {
> +    .get_fd =     stdio_get_fd,
>      .get_buffer = stdio_get_buffer,
>      .close =      stdio_fclose
>  };
>  
>  static const QEMUFileOps stdio_file_write_ops = {
> +    .get_fd =     stdio_get_fd,
>      .put_buffer = stdio_put_buffer,
>      .close =      stdio_fclose
>  };
> @@ -344,6 +362,7 @@ fail:
>  }
>  
>  static const QEMUFileOps socket_read_ops = {
> +    .get_fd =     socket_get_fd,
>      .get_buffer = socket_get_buffer,
>      .close =      socket_close
>  };
> @@ -491,6 +510,14 @@ static void qemu_fill_buffer(QEMUFile *f)
>          qemu_file_set_error(f, len);
>  }
>  
> +int qemu_get_fd(QEMUFile *f)
> +{
> +    if (f->ops->get_fd) {
> +        return f->ops->get_fd(f->opaque);
> +    }
> +    return -1;
> +}
> +
>  /** Closes the file
>   *
>   * Returns negative error value if any error happened on previous operations or
> 
Reviewed-by: Orit Wasserman <owasserm@redhat.com>
Juan Quintela - Oct. 30, 2012, 12:27 p.m.
Paolo Bonzini <pbonzini@redhat.com> wrote:
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Juan Quintela <quintela@redhat.com>

Patch

diff --git a/buffered_file.c b/buffered_file.c
index a5c0b12..bd0f61d 100644
--- a/buffered_file.c
+++ b/buffered_file.c
@@ -174,6 +174,13 @@  static int buffered_close(void *opaque)
  *   1: Time to stop
  *   negative: There has been an error
  */
+static int buffered_get_fd(void *opaque)
+{
+    QEMUFileBuffered *s = opaque;
+
+    return qemu_get_fd(s->file);
+}
+
 static int buffered_rate_limit(void *opaque)
 {
     QEMUFileBuffered *s = opaque;
@@ -235,6 +242,7 @@  static void buffered_rate_tick(void *opaque)
 }
 
 static const QEMUFileOps buffered_file_ops = {
+    .get_fd =         buffered_get_fd,
     .put_buffer =     buffered_put_buffer,
     .close =          buffered_close,
     .rate_limit =     buffered_rate_limit,
diff --git a/qemu-file.h b/qemu-file.h
index c89e8e0..d552f5d 100644
--- a/qemu-file.h
+++ b/qemu-file.h
@@ -47,6 +47,10 @@  typedef int (QEMUFileGetBufferFunc)(void *opaque, uint8_t *buf,
  */
 typedef int (QEMUFileCloseFunc)(void *opaque);
 
+/* Called to return the OS file descriptor associated to the QEMUFile.
+ */
+typedef int (QEMUFileGetFD)(void *opaque);
+
 /* Called to determine if the file has exceeded its bandwidth allocation.  The
  * bandwidth capping is a soft limit, not a hard limit.
  */
@@ -63,6 +67,7 @@  typedef struct QEMUFileOps {
     QEMUFilePutBufferFunc *put_buffer;
     QEMUFileGetBufferFunc *get_buffer;
     QEMUFileCloseFunc *close;
+    QEMUFileGetFD *get_fd;
     QEMUFileRateLimit *rate_limit;
     QEMUFileSetRateLimit *set_rate_limit;
     QEMUFileGetRateLimit *get_rate_limit;
@@ -74,6 +79,7 @@  QEMUFile *qemu_fdopen(int fd, const char *mode);
 QEMUFile *qemu_fopen_socket(int fd);
 QEMUFile *qemu_popen(FILE *popen_file, const char *mode);
 QEMUFile *qemu_popen_cmd(const char *command, const char *mode);
+int qemu_get_fd(QEMUFile *f);
 int qemu_stdio_fd(QEMUFile *f);
 int qemu_fclose(QEMUFile *f);
 void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size);
diff --git a/savevm.c b/savevm.c
index c3ce00a..5c0a756 100644
--- a/savevm.c
+++ b/savevm.c
@@ -187,6 +187,13 @@  typedef struct QEMUFileSocket
     QEMUFile *file;
 } QEMUFileSocket;
 
+static int socket_get_fd(void *opaque)
+{
+    QEMUFileSocket *s = opaque;
+
+    return s->fd;
+}
+
 static int socket_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size)
 {
     QEMUFileSocket *s = opaque;
@@ -209,6 +216,13 @@  static int socket_close(void *opaque)
     return 0;
 }
 
+static int stdio_get_fd(void *opaque)
+{
+    QEMUFileStdio *s = opaque;
+
+    return fileno(s->stdio_file);
+}
+
 static int stdio_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, int size)
 {
     QEMUFileStdio *s = opaque;
@@ -252,11 +266,13 @@  static int stdio_fclose(void *opaque)
 }
 
 static const QEMUFileOps stdio_pipe_read_ops = {
+    .get_fd =     stdio_get_fd,
     .get_buffer = stdio_get_buffer,
     .close =      stdio_pclose
 };
 
 static const QEMUFileOps stdio_pipe_write_ops = {
+    .get_fd =     stdio_get_fd,
     .put_buffer = stdio_put_buffer,
     .close =      stdio_pclose
 };
@@ -306,11 +322,13 @@  int qemu_stdio_fd(QEMUFile *f)
 }
 
 static const QEMUFileOps stdio_file_read_ops = {
+    .get_fd =     stdio_get_fd,
     .get_buffer = stdio_get_buffer,
     .close =      stdio_fclose
 };
 
 static const QEMUFileOps stdio_file_write_ops = {
+    .get_fd =     stdio_get_fd,
     .put_buffer = stdio_put_buffer,
     .close =      stdio_fclose
 };
@@ -344,6 +362,7 @@  fail:
 }
 
 static const QEMUFileOps socket_read_ops = {
+    .get_fd =     socket_get_fd,
     .get_buffer = socket_get_buffer,
     .close =      socket_close
 };
@@ -491,6 +510,14 @@  static void qemu_fill_buffer(QEMUFile *f)
         qemu_file_set_error(f, len);
 }
 
+int qemu_get_fd(QEMUFile *f)
+{
+    if (f->ops->get_fd) {
+        return f->ops->get_fd(f->opaque);
+    }
+    return -1;
+}
+
 /** Closes the file
  *
  * Returns negative error value if any error happened on previous operations or