qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/2] make migrate_set_speed work while migration is running
@ 2009-05-20 22:26 Glauber Costa
  2009-05-20 22:26 ` [Qemu-devel] [PATCH 1/2] introduce set_rate_limit function for QEMUFile Glauber Costa
  0 siblings, 1 reply; 3+ messages in thread
From: Glauber Costa @ 2009-05-20 22:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: aliguori

With this series of patches, migration speed can be increased/decreased while
a migration is active. The first patch introduces a new set_rate_limit function
that provides us with the infrastructure, while the second uses it for the
migration code.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Qemu-devel] [PATCH 1/2] introduce set_rate_limit function for QEMUFile
  2009-05-20 22:26 [Qemu-devel] [PATCH 0/2] make migrate_set_speed work while migration is running Glauber Costa
@ 2009-05-20 22:26 ` Glauber Costa
  2009-05-20 22:26   ` [Qemu-devel] [PATCH 2/2] allow changing the speed of a running migration Glauber Costa
  0 siblings, 1 reply; 3+ messages in thread
From: Glauber Costa @ 2009-05-20 22:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: aliguori

Ladies and Gentlemen!

I'm pleased to announce the debut of a set_rate_limit function
in QEMUFile. It will allow us to do exactly what it suggests:
setting the cap limitations of a file on the fly.

This patch converts the current callers of qemu_fopen_ops().

Signed-off-by: Glauber Costa <glommer@redhat.com>
---
 buffered_file.c |   16 +++++++++++++++-
 hw/hw.h         |   10 +++++++++-
 savevm.c        |   27 +++++++++++++++++++--------
 3 files changed, 43 insertions(+), 10 deletions(-)

diff --git a/buffered_file.c b/buffered_file.c
index ec4f664..364b912 100644
--- a/buffered_file.c
+++ b/buffered_file.c
@@ -198,6 +198,19 @@ static int buffered_rate_limit(void *opaque)
     return 0;
 }
 
+static size_t buffered_set_rate_limit(void *opaque, size_t new_rate)
+{
+    QEMUFileBuffered *s = opaque;
+
+    if (s->has_error)
+        goto out;
+
+    s->xfer_limit = new_rate / 10;
+    
+out:
+    return s->xfer_limit;
+}
+
 static void buffered_rate_tick(void *opaque)
 {
     QEMUFileBuffered *s = opaque;
@@ -237,7 +250,8 @@ QEMUFile *qemu_fopen_ops_buffered(void *opaque,
     s->close = close;
 
     s->file = qemu_fopen_ops(s, buffered_put_buffer, NULL,
-                             buffered_close, buffered_rate_limit);
+                             buffered_close, buffered_rate_limit,
+                             buffered_set_rate_limit);
 
     s->timer = qemu_new_timer(rt_clock, buffered_rate_tick, s);
 
diff --git a/hw/hw.h b/hw/hw.h
index c990d1a..dd11f0a 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -36,10 +36,17 @@ typedef int (QEMUFileCloseFunc)(void *opaque);
  */
 typedef int (QEMUFileRateLimit)(void *opaque);
 
+/* Called to change the current bandwidth allocation. This function must return
+ * the new actual bandwidth. It should be new_rate if everything goes ok, and
+ * the old rate otherwise
+ */
+typedef size_t (QEMUFileSetRateLimit)(void *opaque, size_t new_rate);
+
 QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer,
                          QEMUFileGetBufferFunc *get_buffer,
                          QEMUFileCloseFunc *close,
-                         QEMUFileRateLimit *rate_limit);
+                         QEMUFileRateLimit *rate_limit,
+                         QEMUFileSetRateLimit *set_rate_limit);
 QEMUFile *qemu_fopen(const char *filename, const char *mode);
 QEMUFile *qemu_fopen_socket(int fd);
 QEMUFile *qemu_popen(FILE *popen_file, const char *mode);
@@ -73,6 +80,7 @@ unsigned int qemu_get_be16(QEMUFile *f);
 unsigned int qemu_get_be32(QEMUFile *f);
 uint64_t qemu_get_be64(QEMUFile *f);
 int qemu_file_rate_limit(QEMUFile *f);
+size_t qemu_file_set_rate_limit(QEMUFile *f, size_t new_rate);
 int qemu_file_has_error(QEMUFile *f);
 void qemu_file_set_error(QEMUFile *f);
 
diff --git a/savevm.c b/savevm.c
index 8b7909a..3478bb8 100644
--- a/savevm.c
+++ b/savevm.c
@@ -144,6 +144,7 @@ struct QEMUFile {
     QEMUFileGetBufferFunc *get_buffer;
     QEMUFileCloseFunc *close;
     QEMUFileRateLimit *rate_limit;
+    QEMUFileSetRateLimit *set_rate_limit;
     void *opaque;
     int is_write;
 
@@ -224,9 +225,9 @@ QEMUFile *qemu_popen(FILE *popen_file, const char *mode)
     s->popen_file = popen_file;
 
     if(mode[0] == 'r') {
-        s->file = qemu_fopen_ops(s, NULL, popen_get_buffer, popen_close, NULL);
+        s->file = qemu_fopen_ops(s, NULL, popen_get_buffer, popen_close, NULL, NULL);
     } else {
-        s->file = qemu_fopen_ops(s, popen_put_buffer, NULL, popen_close, NULL);
+        s->file = qemu_fopen_ops(s, popen_put_buffer, NULL, popen_close, NULL, NULL);
     }
     fprintf(stderr, "qemu_popen: returning result of qemu_fopen_ops\n");
     return s->file;
@@ -249,7 +250,7 @@ QEMUFile *qemu_fopen_socket(int fd)
     QEMUFileSocket *s = qemu_mallocz(sizeof(QEMUFileSocket));
 
     s->fd = fd;
-    s->file = qemu_fopen_ops(s, NULL, socket_get_buffer, socket_close, NULL);
+    s->file = qemu_fopen_ops(s, NULL, socket_get_buffer, socket_close, NULL, NULL);
     return s->file;
 }
 
@@ -293,9 +294,9 @@ QEMUFile *qemu_fopen(const char *filename, const char *mode)
         goto fail;
 
     if (!strcmp(mode, "wb"))
-        return qemu_fopen_ops(s, file_put_buffer, NULL, file_close, NULL);
+        return qemu_fopen_ops(s, file_put_buffer, NULL, file_close, NULL, NULL);
     else if (!strcmp(mode, "rb"))
-        return qemu_fopen_ops(s, NULL, file_get_buffer, file_close, NULL);
+        return qemu_fopen_ops(s, NULL, file_get_buffer, file_close, NULL, NULL);
 
 fail:
     if (s->outfile)
@@ -341,15 +342,16 @@ static QEMUFile *qemu_fopen_bdrv(BlockDriverState *bs, int64_t offset, int is_wr
     s->base_offset = offset;
 
     if (is_writable)
-        return qemu_fopen_ops(s, block_put_buffer, NULL, bdrv_fclose, NULL);
+        return qemu_fopen_ops(s, block_put_buffer, NULL, bdrv_fclose, NULL, NULL);
 
-    return qemu_fopen_ops(s, NULL, block_get_buffer, bdrv_fclose, NULL);
+    return qemu_fopen_ops(s, NULL, block_get_buffer, bdrv_fclose, NULL, NULL);
 }
 
 QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer,
                          QEMUFileGetBufferFunc *get_buffer,
                          QEMUFileCloseFunc *close,
-                         QEMUFileRateLimit *rate_limit)
+                         QEMUFileRateLimit *rate_limit,
+                         QEMUFileSetRateLimit *set_rate_limit)
 {
     QEMUFile *f;
 
@@ -360,6 +362,7 @@ QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer,
     f->get_buffer = get_buffer;
     f->close = close;
     f->rate_limit = rate_limit;
+    f->set_rate_limit = set_rate_limit;
     f->is_write = 0;
 
     return f;
@@ -537,6 +540,14 @@ int qemu_file_rate_limit(QEMUFile *f)
     return 0;
 }
 
+size_t qemu_file_set_rate_limit(QEMUFile *f, size_t new_rate)
+{
+    if (f->set_rate_limit)
+        return f->set_rate_limit(f->opaque, new_rate);
+
+    return 0;
+}
+
 void qemu_put_be16(QEMUFile *f, unsigned int v)
 {
     qemu_put_byte(f, v >> 8);
-- 
1.5.6.6

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [Qemu-devel] [PATCH 2/2] allow changing the speed of a running migration
  2009-05-20 22:26 ` [Qemu-devel] [PATCH 1/2] introduce set_rate_limit function for QEMUFile Glauber Costa
@ 2009-05-20 22:26   ` Glauber Costa
  0 siblings, 0 replies; 3+ messages in thread
From: Glauber Costa @ 2009-05-20 22:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: aliguori

This patch allow us to call migrate_set_speed on running
migrations. This should allow mgmt tools to increase the allocated
bandwidth of a running migration if there is no progress, and they
really want the migration to succeed.

Signed-off-by: Glauber Costa <glommer@redhat.com>
---
 migration.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/migration.c b/migration.c
index ca397fa..b9e3368 100644
--- a/migration.c
+++ b/migration.c
@@ -84,6 +84,7 @@ void do_migrate_set_speed(Monitor *mon, const char *value)
 {
     double d;
     char *ptr;
+    FdMigrationState *s;
 
     d = strtod(value, &ptr);
     switch (*ptr) {
@@ -98,6 +99,12 @@ void do_migrate_set_speed(Monitor *mon, const char *value)
     }
 
     max_throttle = (uint32_t)d;
+    s = migrate_to_fms(current_migration);
+
+    if (s) {
+        qemu_file_set_rate_limit(s->file, max_throttle);
+    }
+    
 }
 
 void do_info_migrate(Monitor *mon)
-- 
1.5.6.6

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-05-20 22:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-20 22:26 [Qemu-devel] [PATCH 0/2] make migrate_set_speed work while migration is running Glauber Costa
2009-05-20 22:26 ` [Qemu-devel] [PATCH 1/2] introduce set_rate_limit function for QEMUFile Glauber Costa
2009-05-20 22:26   ` [Qemu-devel] [PATCH 2/2] allow changing the speed of a running migration Glauber Costa

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).