diff mbox

[40/41] migration: eliminate s->migration_file

Message ID 1360950433-17106-41-git-send-email-pbonzini@redhat.com
State New
Headers show

Commit Message

Paolo Bonzini Feb. 15, 2013, 5:47 p.m. UTC
The indirection is useless now.  Backends can open s->file directly.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 include/migration/migration.h |    2 -
 migration-exec.c              |    4 +-
 migration-fd.c                |    2 +-
 migration-tcp.c               |    4 +-
 migration-unix.c              |    4 +-
 migration.c                   |   45 +++-------------------------------------
 6 files changed, 11 insertions(+), 50 deletions(-)

Comments

Juan Quintela Feb. 22, 2013, 11:45 a.m. UTC | #1
Paolo Bonzini <pbonzini@redhat.com> wrote:
> The indirection is useless now.  Backends can open s->file directly.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Juan Quintela <quintela@redhat.com>
Orit Wasserman Feb. 22, 2013, 1:59 p.m. UTC | #2
On 02/15/2013 07:47 PM, Paolo Bonzini wrote:
> The indirection is useless now.  Backends can open s->file directly.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  include/migration/migration.h |    2 -
>  migration-exec.c              |    4 +-
>  migration-fd.c                |    2 +-
>  migration-tcp.c               |    4 +-
>  migration-unix.c              |    4 +-
>  migration.c                   |   45 +++-------------------------------------
>  6 files changed, 11 insertions(+), 50 deletions(-)
> 
> diff --git a/include/migration/migration.h b/include/migration/migration.h
> index bde13c2..a9d4488 100644
> --- a/include/migration/migration.h
> +++ b/include/migration/migration.h
> @@ -36,9 +36,7 @@ struct MigrationState
>      size_t xfer_limit;
>      QemuThread thread;
>      QEMUBH *cleanup_bh;
> -
>      QEMUFile *file;
> -    QEMUFile *migration_file;
>  
>      int state;
>      MigrationParams params;
> diff --git a/migration-exec.c b/migration-exec.c
> index 1c539de..deab4e3 100644
> --- a/migration-exec.c
> +++ b/migration-exec.c
> @@ -35,8 +35,8 @@
>  
>  void exec_start_outgoing_migration(MigrationState *s, const char *command, Error **errp)
>  {
> -    s->migration_file = qemu_popen_cmd(command, "w");
> -    if (s->migration_file == NULL) {
> +    s->file = qemu_popen_cmd(command, "w");
> +    if (s->file == NULL) {
>          error_setg_errno(errp, errno, "failed to popen the migration target");
>          return;
>      }
> diff --git a/migration-fd.c b/migration-fd.c
> index 07c758a..3d4613c 100644
> --- a/migration-fd.c
> +++ b/migration-fd.c
> @@ -36,7 +36,7 @@ void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **
>      if (fd == -1) {
>          return;
>      }
> -    s->migration_file = qemu_fdopen(fd, "wb");
> +    s->file = qemu_fdopen(fd, "wb");
>  
>      migrate_fd_connect(s);
>  }
> diff --git a/migration-tcp.c b/migration-tcp.c
> index 5ea4f3d..b20ee58 100644
> --- a/migration-tcp.c
> +++ b/migration-tcp.c
> @@ -35,11 +35,11 @@ static void tcp_wait_for_connect(int fd, void *opaque)
>  
>      if (fd < 0) {
>          DPRINTF("migrate connect error\n");
> -        s->migration_file = NULL;
> +        s->file = NULL;
>          migrate_fd_error(s);
>      } else {
>          DPRINTF("migrate connect success\n");
> -        s->migration_file = qemu_fopen_socket(fd, "wb");
> +        s->file = qemu_fopen_socket(fd, "wb");
>          migrate_fd_connect(s);
>      }
>  }
> diff --git a/migration-unix.c b/migration-unix.c
> index 64bfa31..94b7022 100644
> --- a/migration-unix.c
> +++ b/migration-unix.c
> @@ -35,11 +35,11 @@ static void unix_wait_for_connect(int fd, void *opaque)
>  
>      if (fd < 0) {
>          DPRINTF("migrate connect error\n");
> -        s->migration_file = NULL;
> +        s->file = NULL;
>          migrate_fd_error(s);
>      } else {
>          DPRINTF("migrate connect success\n");
> -        s->migration_file = qemu_fopen_socket(fd, "wb");
> +        s->file = qemu_fopen_socket(fd, "wb");
>          migrate_fd_connect(s);
>      }
>  }
> diff --git a/migration.c b/migration.c
> index c9a5978..b32dfc1 100644
> --- a/migration.c
> +++ b/migration.c
> @@ -269,9 +269,6 @@ static void migrate_fd_cleanup(void *opaque)
>  
>      if (s->file) {
>          DPRINTF("closing file\n");
> -        qemu_fclose(s->file);
> -        s->file = NULL;
> -
>          qemu_mutex_unlock_iothread();
>          qemu_thread_join(&s->thread);
>          qemu_mutex_lock_iothread();
> @@ -279,7 +276,7 @@ static void migrate_fd_cleanup(void *opaque)
>          migrate_fd_close(s);
>      }
>  
> -    assert(s->migration_file == NULL);
> +    assert(s->file == NULL);
>      assert(s->state != MIG_STATE_ACTIVE);
>  
>      if (s->state != MIG_STATE_COMPLETED) {
> @@ -307,9 +304,9 @@ static void migrate_fd_cancel(MigrationState *s)
>  int migrate_fd_close(MigrationState *s)
>  {
>      int rc = 0;
> -    if (s->migration_file != NULL) {
> -        rc = qemu_fclose(s->migration_file);
> -        s->migration_file = NULL;
> +    if (s->file != NULL) {
> +        rc = qemu_fclose(s->file);
> +        s->file = NULL;
>      }
>      return rc;
>  }
> @@ -495,33 +492,6 @@ int64_t migrate_xbzrle_cache_size(void)
>  
>  /* migration thread support */
>  
> -static int migration_put_buffer(void *opaque, const uint8_t *buf,
> -                               int64_t pos, int size)
> -{
> -    MigrationState *s = opaque;
> -
> -    DPRINTF("putting %d bytes at %" PRId64 "\n", size, pos);
> -
> -    if (size <= 0) {
> -        return size;
> -    }
> -
> -    qemu_put_buffer(s->migration_file, buf, size);
> -    return qemu_file_get_error(s->migration_file);
> -}
> -
> -static int migration_close(void *opaque)
> -{
> -    return 0;
> -}
> -
> -static int migration_get_fd(void *opaque)
> -{
> -    MigrationState *s = opaque;
> -
> -    return qemu_get_fd(s->migration_file);
> -}
> -
>  static void *migration_thread(void *opaque)
>  {
>      MigrationState *s = opaque;
> @@ -601,17 +571,10 @@ static void *migration_thread(void *opaque)
>      return NULL;
>  }
>  
> -static const QEMUFileOps migration_file_ops = {
> -    .get_fd =         migration_get_fd,
> -    .put_buffer =     migration_put_buffer,
> -    .close =          migration_close,
> -};
> -
>  void migrate_fd_connect(MigrationState *s)
>  {
>      s->state = MIG_STATE_ACTIVE;
>      s->cleanup_bh = qemu_bh_new(migrate_fd_cleanup, s);
> -    s->file = qemu_fopen_ops(s, &migration_file_ops);
>  
>      qemu_file_set_rate_limit(s->file,
>                               s->bandwidth_limit / XFER_LIMIT_RATIO);
> 
Reviewed-by: Orit Wasserman <owasserm@redhat.com>
diff mbox

Patch

diff --git a/include/migration/migration.h b/include/migration/migration.h
index bde13c2..a9d4488 100644
--- a/include/migration/migration.h
+++ b/include/migration/migration.h
@@ -36,9 +36,7 @@  struct MigrationState
     size_t xfer_limit;
     QemuThread thread;
     QEMUBH *cleanup_bh;
-
     QEMUFile *file;
-    QEMUFile *migration_file;
 
     int state;
     MigrationParams params;
diff --git a/migration-exec.c b/migration-exec.c
index 1c539de..deab4e3 100644
--- a/migration-exec.c
+++ b/migration-exec.c
@@ -35,8 +35,8 @@ 
 
 void exec_start_outgoing_migration(MigrationState *s, const char *command, Error **errp)
 {
-    s->migration_file = qemu_popen_cmd(command, "w");
-    if (s->migration_file == NULL) {
+    s->file = qemu_popen_cmd(command, "w");
+    if (s->file == NULL) {
         error_setg_errno(errp, errno, "failed to popen the migration target");
         return;
     }
diff --git a/migration-fd.c b/migration-fd.c
index 07c758a..3d4613c 100644
--- a/migration-fd.c
+++ b/migration-fd.c
@@ -36,7 +36,7 @@  void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **
     if (fd == -1) {
         return;
     }
-    s->migration_file = qemu_fdopen(fd, "wb");
+    s->file = qemu_fdopen(fd, "wb");
 
     migrate_fd_connect(s);
 }
diff --git a/migration-tcp.c b/migration-tcp.c
index 5ea4f3d..b20ee58 100644
--- a/migration-tcp.c
+++ b/migration-tcp.c
@@ -35,11 +35,11 @@  static void tcp_wait_for_connect(int fd, void *opaque)
 
     if (fd < 0) {
         DPRINTF("migrate connect error\n");
-        s->migration_file = NULL;
+        s->file = NULL;
         migrate_fd_error(s);
     } else {
         DPRINTF("migrate connect success\n");
-        s->migration_file = qemu_fopen_socket(fd, "wb");
+        s->file = qemu_fopen_socket(fd, "wb");
         migrate_fd_connect(s);
     }
 }
diff --git a/migration-unix.c b/migration-unix.c
index 64bfa31..94b7022 100644
--- a/migration-unix.c
+++ b/migration-unix.c
@@ -35,11 +35,11 @@  static void unix_wait_for_connect(int fd, void *opaque)
 
     if (fd < 0) {
         DPRINTF("migrate connect error\n");
-        s->migration_file = NULL;
+        s->file = NULL;
         migrate_fd_error(s);
     } else {
         DPRINTF("migrate connect success\n");
-        s->migration_file = qemu_fopen_socket(fd, "wb");
+        s->file = qemu_fopen_socket(fd, "wb");
         migrate_fd_connect(s);
     }
 }
diff --git a/migration.c b/migration.c
index c9a5978..b32dfc1 100644
--- a/migration.c
+++ b/migration.c
@@ -269,9 +269,6 @@  static void migrate_fd_cleanup(void *opaque)
 
     if (s->file) {
         DPRINTF("closing file\n");
-        qemu_fclose(s->file);
-        s->file = NULL;
-
         qemu_mutex_unlock_iothread();
         qemu_thread_join(&s->thread);
         qemu_mutex_lock_iothread();
@@ -279,7 +276,7 @@  static void migrate_fd_cleanup(void *opaque)
         migrate_fd_close(s);
     }
 
-    assert(s->migration_file == NULL);
+    assert(s->file == NULL);
     assert(s->state != MIG_STATE_ACTIVE);
 
     if (s->state != MIG_STATE_COMPLETED) {
@@ -307,9 +304,9 @@  static void migrate_fd_cancel(MigrationState *s)
 int migrate_fd_close(MigrationState *s)
 {
     int rc = 0;
-    if (s->migration_file != NULL) {
-        rc = qemu_fclose(s->migration_file);
-        s->migration_file = NULL;
+    if (s->file != NULL) {
+        rc = qemu_fclose(s->file);
+        s->file = NULL;
     }
     return rc;
 }
@@ -495,33 +492,6 @@  int64_t migrate_xbzrle_cache_size(void)
 
 /* migration thread support */
 
-static int migration_put_buffer(void *opaque, const uint8_t *buf,
-                               int64_t pos, int size)
-{
-    MigrationState *s = opaque;
-
-    DPRINTF("putting %d bytes at %" PRId64 "\n", size, pos);
-
-    if (size <= 0) {
-        return size;
-    }
-
-    qemu_put_buffer(s->migration_file, buf, size);
-    return qemu_file_get_error(s->migration_file);
-}
-
-static int migration_close(void *opaque)
-{
-    return 0;
-}
-
-static int migration_get_fd(void *opaque)
-{
-    MigrationState *s = opaque;
-
-    return qemu_get_fd(s->migration_file);
-}
-
 static void *migration_thread(void *opaque)
 {
     MigrationState *s = opaque;
@@ -601,17 +571,10 @@  static void *migration_thread(void *opaque)
     return NULL;
 }
 
-static const QEMUFileOps migration_file_ops = {
-    .get_fd =         migration_get_fd,
-    .put_buffer =     migration_put_buffer,
-    .close =          migration_close,
-};
-
 void migrate_fd_connect(MigrationState *s)
 {
     s->state = MIG_STATE_ACTIVE;
     s->cleanup_bh = qemu_bh_new(migrate_fd_cleanup, s);
-    s->file = qemu_fopen_ops(s, &migration_file_ops);
 
     qemu_file_set_rate_limit(s->file,
                              s->bandwidth_limit / XFER_LIMIT_RATIO);