Patchwork [v9,05/10] Add MigrationParams structure

login
register
mail settings
Submitter Orit Wasserman
Date April 11, 2012, 6:49 p.m.
Message ID <1334170153-9503-6-git-send-email-owasserm@redhat.com>
Download mbox | patch
Permalink /patch/151862/
State New
Headers show

Comments

Orit Wasserman - April 11, 2012, 6:49 p.m.
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
 block-migration.c |    8 ++++----
 migration.c       |   13 ++++++++-----
 migration.h       |    9 +++++++--
 qemu-common.h     |    1 +
 savevm.c          |   11 ++++++++---
 sysemu.h          |    3 ++-
 vmstate.h         |    2 +-
 7 files changed, 31 insertions(+), 16 deletions(-)
Juan Quintela - April 18, 2012, 2:43 p.m.
Orit Wasserman <owasserm@redhat.com> wrote:
> Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>

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

Thought about doing something like that several times.  Thanks.
Anthony Liguori - April 18, 2012, 5:26 p.m.
On 04/11/2012 01:49 PM, Orit Wasserman wrote:
> Signed-off-by: Isaku Yamahata<yamahata@valinux.co.jp>

If you're not going to SoB this patch, please make sure you set the GIT_AUTHOR 
appropriately so that there's a From line for Isaku.  Otherwise it will mess up 
git history (you will be the author but will not have a SoB).

Reards,

Anthony Liguori

> ---
>   block-migration.c |    8 ++++----
>   migration.c       |   13 ++++++++-----
>   migration.h       |    9 +++++++--
>   qemu-common.h     |    1 +
>   savevm.c          |   11 ++++++++---
>   sysemu.h          |    3 ++-
>   vmstate.h         |    2 +-
>   7 files changed, 31 insertions(+), 16 deletions(-)
>
> diff --git a/block-migration.c b/block-migration.c
> index fd2ffff..b95b4e1 100644
> --- a/block-migration.c
> +++ b/block-migration.c
> @@ -700,13 +700,13 @@ static int block_load(QEMUFile *f, void *opaque, int version_id)
>       return 0;
>   }
>
> -static void block_set_params(int blk_enable, int shared_base, void *opaque)
> +static void block_set_params(const MigrationParams *params, void *opaque)
>   {
> -    block_mig_state.blk_enable = blk_enable;
> -    block_mig_state.shared_base = shared_base;
> +    block_mig_state.blk_enable = params->blk;
> +    block_mig_state.shared_base = params->shared;
>
>       /* shared base means that blk_enable = 1 */
> -    block_mig_state.blk_enable |= shared_base;
> +    block_mig_state.blk_enable |= params->shared;
>   }
>
>   void blk_mig_init(void)
> diff --git a/migration.c b/migration.c
> index 94f7839..fc9511c 100644
> --- a/migration.c
> +++ b/migration.c
> @@ -351,7 +351,7 @@ void migrate_fd_connect(MigrationState *s)
>                                         migrate_fd_close);
>
>       DPRINTF("beginning savevm\n");
> -    ret = qemu_savevm_state_begin(s->file, s->blk, s->shared);
> +    ret = qemu_savevm_state_begin(s->file,&s->params);
>       if (ret<  0) {
>           DPRINTF("failed, %d\n", ret);
>           migrate_fd_error(s);
> @@ -360,15 +360,14 @@ void migrate_fd_connect(MigrationState *s)
>       migrate_fd_put_ready(s);
>   }
>
> -static MigrationState *migrate_init(int blk, int inc)
> +static MigrationState *migrate_init(const MigrationParams *params)
>   {
>       MigrationState *s = migrate_get_current();
>       int64_t bandwidth_limit = s->bandwidth_limit;
>
>       memset(s, 0, sizeof(*s));
>       s->bandwidth_limit = bandwidth_limit;
> -    s->blk = blk;
> -    s->shared = inc;
> +    s->params = *params;
>
>       s->bandwidth_limit = bandwidth_limit;
>       s->state = MIG_STATE_SETUP;
> @@ -393,9 +392,13 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
>                    Error **errp)
>   {
>       MigrationState *s = migrate_get_current();
> +    MigrationParams params;
>       const char *p;
>       int ret;
>
> +    params.blk = blk;
> +    params.shared = inc;
> +
>       if (s->state == MIG_STATE_ACTIVE) {
>           error_set(errp, QERR_MIGRATION_ACTIVE);
>           return;
> @@ -410,7 +413,7 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
>           return;
>       }
>
> -    s = migrate_init(blk, inc);
> +    s = migrate_init(&params);
>
>       if (strstart(uri, "tcp:",&p)) {
>           ret = tcp_start_outgoing_migration(s, p);
> diff --git a/migration.h b/migration.h
> index d798fac..b2097a9 100644
> --- a/migration.h
> +++ b/migration.h
> @@ -19,6 +19,11 @@
>   #include "notify.h"
>   #include "error.h"
>
> +struct MigrationParams {
> +    int blk;
> +    int shared;
> +};
> +
>   typedef struct MigrationState MigrationState;
>
>   struct MigrationState
> @@ -31,10 +36,10 @@ struct MigrationState
>       int (*close)(MigrationState *s);
>       int (*write)(MigrationState *s, const void *buff, size_t size);
>       void *opaque;
> -    int blk;
> -    int shared;
> +    MigrationParams params;
>   };
>
> +
>   void process_incoming_migration(QEMUFile *f);
>
>   int qemu_start_incoming_migration(const char *uri);
> diff --git a/qemu-common.h b/qemu-common.h
> index 50f659a..30c59c8 100644
> --- a/qemu-common.h
> +++ b/qemu-common.h
> @@ -17,6 +17,7 @@ typedef struct DeviceState DeviceState;
>
>   struct Monitor;
>   typedef struct Monitor Monitor;
> +typedef struct MigrationParams MigrationParams;
>
>   /* we put basic includes here to avoid repeating them in device drivers */
>   #include<stdlib.h>
> diff --git a/savevm.c b/savevm.c
> index 0b2fe38..4736784 100644
> --- a/savevm.c
> +++ b/savevm.c
> @@ -1561,7 +1561,8 @@ bool qemu_savevm_state_blocked(Error **errp)
>       return false;
>   }
>
> -int qemu_savevm_state_begin(QEMUFile *f, int blk_enable, int shared)
> +int qemu_savevm_state_begin(QEMUFile *f,
> +                            const MigrationParams *params)
>   {
>       SaveStateEntry *se;
>       int ret;
> @@ -1570,7 +1571,7 @@ int qemu_savevm_state_begin(QEMUFile *f, int blk_enable, int shared)
>           if(se->set_params == NULL) {
>               continue;
>   	}
> -	se->set_params(blk_enable, shared, se->opaque);
> +        se->set_params(params, se->opaque);
>       }
>
>       qemu_put_be32(f, QEMU_VM_FILE_MAGIC);
> @@ -1708,13 +1709,17 @@ void qemu_savevm_state_cancel(QEMUFile *f)
>   static int qemu_savevm_state(QEMUFile *f)
>   {
>       int ret;
> +    MigrationParams params = {
> +        .blk = 0,
> +        .shared = 0
> +    };
>
>       if (qemu_savevm_state_blocked(NULL)) {
>           ret = -EINVAL;
>           goto out;
>       }
>
> -    ret = qemu_savevm_state_begin(f, 0, 0);
> +    ret = qemu_savevm_state_begin(f,&params);
>       if (ret<  0)
>           goto out;
>
> diff --git a/sysemu.h b/sysemu.h
> index bc2c788..6540c79 100644
> --- a/sysemu.h
> +++ b/sysemu.h
> @@ -77,7 +77,8 @@ void do_info_snapshots(Monitor *mon);
>   void qemu_announce_self(void);
>
>   bool qemu_savevm_state_blocked(Error **errp);
> -int qemu_savevm_state_begin(QEMUFile *f, int blk_enable, int shared);
> +int qemu_savevm_state_begin(QEMUFile *f,
> +                            const MigrationParams *params);
>   int qemu_savevm_state_iterate(QEMUFile *f);
>   int qemu_savevm_state_complete(QEMUFile *f);
>   void qemu_savevm_state_cancel(QEMUFile *f);
> diff --git a/vmstate.h b/vmstate.h
> index 82d97ae..5af45e0 100644
> --- a/vmstate.h
> +++ b/vmstate.h
> @@ -26,7 +26,7 @@
>   #ifndef QEMU_VMSTATE_H
>   #define QEMU_VMSTATE_H 1
>
> -typedef void SaveSetParamsHandler(int blk_enable, int shared, void * opaque);
> +typedef void SaveSetParamsHandler(const MigrationParams *params, void * opaque);
>   typedef void SaveStateHandler(QEMUFile *f, void *opaque);
>   typedef int SaveLiveStateHandler(QEMUFile *f, int stage, void *opaque);
>   typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id);
Orit Wasserman - April 19, 2012, 6:39 a.m.
On 04/18/2012 08:26 PM, Anthony Liguori wrote:
> On 04/11/2012 01:49 PM, Orit Wasserman wrote:
>> Signed-off-by: Isaku Yamahata<yamahata@valinux.co.jp>
> 
> If you're not going to SoB this patch, please make sure you set the GIT_AUTHOR appropriately so that there's a From line for Isaku.  Otherwise it will mess up git history (you will be the author but will not have a SoB).
> 
Sure. 

Thanks,
Orit
> Reards,
> 
> Anthony Liguori
> 
>> ---
>>   block-migration.c |    8 ++++----
>>   migration.c       |   13 ++++++++-----
>>   migration.h       |    9 +++++++--
>>   qemu-common.h     |    1 +
>>   savevm.c          |   11 ++++++++---
>>   sysemu.h          |    3 ++-
>>   vmstate.h         |    2 +-
>>   7 files changed, 31 insertions(+), 16 deletions(-)
>>
>> diff --git a/block-migration.c b/block-migration.c
>> index fd2ffff..b95b4e1 100644
>> --- a/block-migration.c
>> +++ b/block-migration.c
>> @@ -700,13 +700,13 @@ static int block_load(QEMUFile *f, void *opaque, int version_id)
>>       return 0;
>>   }
>>
>> -static void block_set_params(int blk_enable, int shared_base, void *opaque)
>> +static void block_set_params(const MigrationParams *params, void *opaque)
>>   {
>> -    block_mig_state.blk_enable = blk_enable;
>> -    block_mig_state.shared_base = shared_base;
>> +    block_mig_state.blk_enable = params->blk;
>> +    block_mig_state.shared_base = params->shared;
>>
>>       /* shared base means that blk_enable = 1 */
>> -    block_mig_state.blk_enable |= shared_base;
>> +    block_mig_state.blk_enable |= params->shared;
>>   }
>>
>>   void blk_mig_init(void)
>> diff --git a/migration.c b/migration.c
>> index 94f7839..fc9511c 100644
>> --- a/migration.c
>> +++ b/migration.c
>> @@ -351,7 +351,7 @@ void migrate_fd_connect(MigrationState *s)
>>                                         migrate_fd_close);
>>
>>       DPRINTF("beginning savevm\n");
>> -    ret = qemu_savevm_state_begin(s->file, s->blk, s->shared);
>> +    ret = qemu_savevm_state_begin(s->file,&s->params);
>>       if (ret<  0) {
>>           DPRINTF("failed, %d\n", ret);
>>           migrate_fd_error(s);
>> @@ -360,15 +360,14 @@ void migrate_fd_connect(MigrationState *s)
>>       migrate_fd_put_ready(s);
>>   }
>>
>> -static MigrationState *migrate_init(int blk, int inc)
>> +static MigrationState *migrate_init(const MigrationParams *params)
>>   {
>>       MigrationState *s = migrate_get_current();
>>       int64_t bandwidth_limit = s->bandwidth_limit;
>>
>>       memset(s, 0, sizeof(*s));
>>       s->bandwidth_limit = bandwidth_limit;
>> -    s->blk = blk;
>> -    s->shared = inc;
>> +    s->params = *params;
>>
>>       s->bandwidth_limit = bandwidth_limit;
>>       s->state = MIG_STATE_SETUP;
>> @@ -393,9 +392,13 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
>>                    Error **errp)
>>   {
>>       MigrationState *s = migrate_get_current();
>> +    MigrationParams params;
>>       const char *p;
>>       int ret;
>>
>> +    params.blk = blk;
>> +    params.shared = inc;
>> +
>>       if (s->state == MIG_STATE_ACTIVE) {
>>           error_set(errp, QERR_MIGRATION_ACTIVE);
>>           return;
>> @@ -410,7 +413,7 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
>>           return;
>>       }
>>
>> -    s = migrate_init(blk, inc);
>> +    s = migrate_init(&params);
>>
>>       if (strstart(uri, "tcp:",&p)) {
>>           ret = tcp_start_outgoing_migration(s, p);
>> diff --git a/migration.h b/migration.h
>> index d798fac..b2097a9 100644
>> --- a/migration.h
>> +++ b/migration.h
>> @@ -19,6 +19,11 @@
>>   #include "notify.h"
>>   #include "error.h"
>>
>> +struct MigrationParams {
>> +    int blk;
>> +    int shared;
>> +};
>> +
>>   typedef struct MigrationState MigrationState;
>>
>>   struct MigrationState
>> @@ -31,10 +36,10 @@ struct MigrationState
>>       int (*close)(MigrationState *s);
>>       int (*write)(MigrationState *s, const void *buff, size_t size);
>>       void *opaque;
>> -    int blk;
>> -    int shared;
>> +    MigrationParams params;
>>   };
>>
>> +
>>   void process_incoming_migration(QEMUFile *f);
>>
>>   int qemu_start_incoming_migration(const char *uri);
>> diff --git a/qemu-common.h b/qemu-common.h
>> index 50f659a..30c59c8 100644
>> --- a/qemu-common.h
>> +++ b/qemu-common.h
>> @@ -17,6 +17,7 @@ typedef struct DeviceState DeviceState;
>>
>>   struct Monitor;
>>   typedef struct Monitor Monitor;
>> +typedef struct MigrationParams MigrationParams;
>>
>>   /* we put basic includes here to avoid repeating them in device drivers */
>>   #include<stdlib.h>
>> diff --git a/savevm.c b/savevm.c
>> index 0b2fe38..4736784 100644
>> --- a/savevm.c
>> +++ b/savevm.c
>> @@ -1561,7 +1561,8 @@ bool qemu_savevm_state_blocked(Error **errp)
>>       return false;
>>   }
>>
>> -int qemu_savevm_state_begin(QEMUFile *f, int blk_enable, int shared)
>> +int qemu_savevm_state_begin(QEMUFile *f,
>> +                            const MigrationParams *params)
>>   {
>>       SaveStateEntry *se;
>>       int ret;
>> @@ -1570,7 +1571,7 @@ int qemu_savevm_state_begin(QEMUFile *f, int blk_enable, int shared)
>>           if(se->set_params == NULL) {
>>               continue;
>>       }
>> -    se->set_params(blk_enable, shared, se->opaque);
>> +        se->set_params(params, se->opaque);
>>       }
>>
>>       qemu_put_be32(f, QEMU_VM_FILE_MAGIC);
>> @@ -1708,13 +1709,17 @@ void qemu_savevm_state_cancel(QEMUFile *f)
>>   static int qemu_savevm_state(QEMUFile *f)
>>   {
>>       int ret;
>> +    MigrationParams params = {
>> +        .blk = 0,
>> +        .shared = 0
>> +    };
>>
>>       if (qemu_savevm_state_blocked(NULL)) {
>>           ret = -EINVAL;
>>           goto out;
>>       }
>>
>> -    ret = qemu_savevm_state_begin(f, 0, 0);
>> +    ret = qemu_savevm_state_begin(f,&params);
>>       if (ret<  0)
>>           goto out;
>>
>> diff --git a/sysemu.h b/sysemu.h
>> index bc2c788..6540c79 100644
>> --- a/sysemu.h
>> +++ b/sysemu.h
>> @@ -77,7 +77,8 @@ void do_info_snapshots(Monitor *mon);
>>   void qemu_announce_self(void);
>>
>>   bool qemu_savevm_state_blocked(Error **errp);
>> -int qemu_savevm_state_begin(QEMUFile *f, int blk_enable, int shared);
>> +int qemu_savevm_state_begin(QEMUFile *f,
>> +                            const MigrationParams *params);
>>   int qemu_savevm_state_iterate(QEMUFile *f);
>>   int qemu_savevm_state_complete(QEMUFile *f);
>>   void qemu_savevm_state_cancel(QEMUFile *f);
>> diff --git a/vmstate.h b/vmstate.h
>> index 82d97ae..5af45e0 100644
>> --- a/vmstate.h
>> +++ b/vmstate.h
>> @@ -26,7 +26,7 @@
>>   #ifndef QEMU_VMSTATE_H
>>   #define QEMU_VMSTATE_H 1
>>
>> -typedef void SaveSetParamsHandler(int blk_enable, int shared, void * opaque);
>> +typedef void SaveSetParamsHandler(const MigrationParams *params, void * opaque);
>>   typedef void SaveStateHandler(QEMUFile *f, void *opaque);
>>   typedef int SaveLiveStateHandler(QEMUFile *f, int stage, void *opaque);
>>   typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id);
> 
>

Patch

diff --git a/block-migration.c b/block-migration.c
index fd2ffff..b95b4e1 100644
--- a/block-migration.c
+++ b/block-migration.c
@@ -700,13 +700,13 @@  static int block_load(QEMUFile *f, void *opaque, int version_id)
     return 0;
 }
 
-static void block_set_params(int blk_enable, int shared_base, void *opaque)
+static void block_set_params(const MigrationParams *params, void *opaque)
 {
-    block_mig_state.blk_enable = blk_enable;
-    block_mig_state.shared_base = shared_base;
+    block_mig_state.blk_enable = params->blk;
+    block_mig_state.shared_base = params->shared;
 
     /* shared base means that blk_enable = 1 */
-    block_mig_state.blk_enable |= shared_base;
+    block_mig_state.blk_enable |= params->shared;
 }
 
 void blk_mig_init(void)
diff --git a/migration.c b/migration.c
index 94f7839..fc9511c 100644
--- a/migration.c
+++ b/migration.c
@@ -351,7 +351,7 @@  void migrate_fd_connect(MigrationState *s)
                                       migrate_fd_close);
 
     DPRINTF("beginning savevm\n");
-    ret = qemu_savevm_state_begin(s->file, s->blk, s->shared);
+    ret = qemu_savevm_state_begin(s->file, &s->params);
     if (ret < 0) {
         DPRINTF("failed, %d\n", ret);
         migrate_fd_error(s);
@@ -360,15 +360,14 @@  void migrate_fd_connect(MigrationState *s)
     migrate_fd_put_ready(s);
 }
 
-static MigrationState *migrate_init(int blk, int inc)
+static MigrationState *migrate_init(const MigrationParams *params)
 {
     MigrationState *s = migrate_get_current();
     int64_t bandwidth_limit = s->bandwidth_limit;
 
     memset(s, 0, sizeof(*s));
     s->bandwidth_limit = bandwidth_limit;
-    s->blk = blk;
-    s->shared = inc;
+    s->params = *params;
 
     s->bandwidth_limit = bandwidth_limit;
     s->state = MIG_STATE_SETUP;
@@ -393,9 +392,13 @@  void qmp_migrate(const char *uri, bool has_blk, bool blk,
                  Error **errp)
 {
     MigrationState *s = migrate_get_current();
+    MigrationParams params;
     const char *p;
     int ret;
 
+    params.blk = blk;
+    params.shared = inc;
+
     if (s->state == MIG_STATE_ACTIVE) {
         error_set(errp, QERR_MIGRATION_ACTIVE);
         return;
@@ -410,7 +413,7 @@  void qmp_migrate(const char *uri, bool has_blk, bool blk,
         return;
     }
 
-    s = migrate_init(blk, inc);
+    s = migrate_init(&params);
 
     if (strstart(uri, "tcp:", &p)) {
         ret = tcp_start_outgoing_migration(s, p);
diff --git a/migration.h b/migration.h
index d798fac..b2097a9 100644
--- a/migration.h
+++ b/migration.h
@@ -19,6 +19,11 @@ 
 #include "notify.h"
 #include "error.h"
 
+struct MigrationParams {
+    int blk;
+    int shared;
+};
+
 typedef struct MigrationState MigrationState;
 
 struct MigrationState
@@ -31,10 +36,10 @@  struct MigrationState
     int (*close)(MigrationState *s);
     int (*write)(MigrationState *s, const void *buff, size_t size);
     void *opaque;
-    int blk;
-    int shared;
+    MigrationParams params;
 };
 
+
 void process_incoming_migration(QEMUFile *f);
 
 int qemu_start_incoming_migration(const char *uri);
diff --git a/qemu-common.h b/qemu-common.h
index 50f659a..30c59c8 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -17,6 +17,7 @@  typedef struct DeviceState DeviceState;
 
 struct Monitor;
 typedef struct Monitor Monitor;
+typedef struct MigrationParams MigrationParams;
 
 /* we put basic includes here to avoid repeating them in device drivers */
 #include <stdlib.h>
diff --git a/savevm.c b/savevm.c
index 0b2fe38..4736784 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1561,7 +1561,8 @@  bool qemu_savevm_state_blocked(Error **errp)
     return false;
 }
 
-int qemu_savevm_state_begin(QEMUFile *f, int blk_enable, int shared)
+int qemu_savevm_state_begin(QEMUFile *f,
+                            const MigrationParams *params)
 {
     SaveStateEntry *se;
     int ret;
@@ -1570,7 +1571,7 @@  int qemu_savevm_state_begin(QEMUFile *f, int blk_enable, int shared)
         if(se->set_params == NULL) {
             continue;
 	}
-	se->set_params(blk_enable, shared, se->opaque);
+        se->set_params(params, se->opaque);
     }
     
     qemu_put_be32(f, QEMU_VM_FILE_MAGIC);
@@ -1708,13 +1709,17 @@  void qemu_savevm_state_cancel(QEMUFile *f)
 static int qemu_savevm_state(QEMUFile *f)
 {
     int ret;
+    MigrationParams params = {
+        .blk = 0,
+        .shared = 0
+    };
 
     if (qemu_savevm_state_blocked(NULL)) {
         ret = -EINVAL;
         goto out;
     }
 
-    ret = qemu_savevm_state_begin(f, 0, 0);
+    ret = qemu_savevm_state_begin(f, &params);
     if (ret < 0)
         goto out;
 
diff --git a/sysemu.h b/sysemu.h
index bc2c788..6540c79 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -77,7 +77,8 @@  void do_info_snapshots(Monitor *mon);
 void qemu_announce_self(void);
 
 bool qemu_savevm_state_blocked(Error **errp);
-int qemu_savevm_state_begin(QEMUFile *f, int blk_enable, int shared);
+int qemu_savevm_state_begin(QEMUFile *f,
+                            const MigrationParams *params);
 int qemu_savevm_state_iterate(QEMUFile *f);
 int qemu_savevm_state_complete(QEMUFile *f);
 void qemu_savevm_state_cancel(QEMUFile *f);
diff --git a/vmstate.h b/vmstate.h
index 82d97ae..5af45e0 100644
--- a/vmstate.h
+++ b/vmstate.h
@@ -26,7 +26,7 @@ 
 #ifndef QEMU_VMSTATE_H
 #define QEMU_VMSTATE_H 1
 
-typedef void SaveSetParamsHandler(int blk_enable, int shared, void * opaque);
+typedef void SaveSetParamsHandler(const MigrationParams *params, void * opaque);
 typedef void SaveStateHandler(QEMUFile *f, void *opaque);
 typedef int SaveLiveStateHandler(QEMUFile *f, int stage, void *opaque);
 typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id);