Skip to contentSkip to conversation

Add file url support to migration

PATCH In review Benoît Canet 4 participants 9 messages Aug 23, 2012 – Aug 28, 2012

lore
Share & tools
lore
#0 lore raw

cover Add file url support to migration

This patchset add support of file: urls allowing a user to save to and restore from disk the state of a vm in an easy way.

An fflush was added before closing the fd for this use case in order to be sure that all data have reached stable storage.

One new usage would be migrating between two virtualizer which share only the storage but do not see each other on the network. (cisco pvlan for example)

Benoît Canet (2):
migration: Allow the migrate command to work on file: urls
migration: Allow -incoming to work on file: urls

 migration-fd.c |    9 ++++-----
 migration.c    |   34 ++++++++++++++++++++++++++++++++--
 migration.h    |    4 ++--
 3 files changed, 38 insertions(+), 9 deletions(-)
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 1/2 migration: Allow the migrate command to work on file: urls

Usage:
(qemu) migrate file:/path/to/vm_statefile

---
 migration-fd.c |    4 ++--
 migration.c    |   20 +++++++++++++++++++-
 migration.h    |    2 +-
 3 files changed, 22 insertions(+), 4 deletions(-)
migration-fd.c +2 -2
index 50138ed..d39e44a 100644
@@ -73,9 +73,9 @@ static int fd_close(MigrationState *s)
     return 0;
 }
 
-int fd_start_outgoing_migration(MigrationState *s, const char *fdname)
+int fd_start_outgoing_migration(MigrationState *s, const char *fdname, int fd)
 {
-    s->fd = monitor_get_fd(cur_mon, fdname);
+    s->fd = fd ? fd : monitor_get_fd(cur_mon, fdname);
     if (s->fd == -1) {
         DPRINTF("fd_migration: invalid file descriptor identifier\n");
         goto err_after_get_fd;
migration.c +19 -1
index 1edeec5..679847d 100644
@@ -239,9 +239,14 @@ void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params,
 static int migrate_fd_cleanup(MigrationState *s)
 {
     int ret = 0;
+    struct stat st;
 
     qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL);
 
+    if (!fstat(s->fd, &st) && S_ISREG(st.st_mode)) {
+        fsync(s->fd);
+    }
+
     if (s->file) {
         DPRINTF("closing file\n");
         ret = qemu_fclose(s->file);
@@ -475,6 +480,17 @@ void migrate_del_blocker(Error *reason)
     migration_blockers = g_slist_remove(migration_blockers, reason);
 }
 
+static int file_start_outgoing_migration(MigrationState *s,
+                                         const char *filename)
+{
+    int fd;
+    fd = open(filename, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR);
+    if (fd < 0) {
+        return -errno;
+    }
+    return fd_start_outgoing_migration(s, NULL, fd);
+}
+
 void qmp_migrate(const char *uri, bool has_blk, bool blk,
                  bool has_inc, bool inc, bool has_detach, bool detach,
                  Error **errp)
@@ -511,7 +527,9 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
     } else if (strstart(uri, "unix:", &p)) {
         ret = unix_start_outgoing_migration(s, p);
     } else if (strstart(uri, "fd:", &p)) {
-        ret = fd_start_outgoing_migration(s, p);
+        ret = fd_start_outgoing_migration(s, p, 0);
+    } else if (strstart(uri, "file:", &p)) {
+        ret = file_start_outgoing_migration(s, p);
 #endif
     } else {
         error_set(errp, QERR_INVALID_PARAMETER_VALUE, "uri", "a valid migration protocol");
migration.h +1 -1
index a9852fc..d431284 100644
@@ -69,7 +69,7 @@ int unix_start_outgoing_migration(MigrationState *s, const char *path);
 
 int fd_start_incoming_migration(const char *path);
 
-int fd_start_outgoing_migration(MigrationState *s, const char *fdname);
+int fd_start_outgoing_migration(MigrationState *s, const char *fdname, int fd);
 
 void migrate_fd_error(MigrationState *s);
 
Signature · 1 line
1.7.9.5
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] migration: Allow the migrate command to work on file: urls

Quoted 48 lines · Benoît Canet

Usage:
(qemu) migrate file:/path/to/vm_statefile

---
 migration-fd.c |    4 ++--
 migration.c    |   20 +++++++++++++++++++-
 migration.h    |    2 +-
 3 files changed, 22 insertions(+), 4 deletions(-)
migration-fd.c +2 -2
index 50138ed..d39e44a 100644
@@ -73,9 +73,9 @@ static int fd_close(MigrationState *s)
     return 0;
 }
 
-int fd_start_outgoing_migration(MigrationState *s, const char *fdname)
+int fd_start_outgoing_migration(MigrationState *s, const char *fdname, int fd)
 {
-    s->fd = monitor_get_fd(cur_mon, fdname);
+    s->fd = fd ? fd : monitor_get_fd(cur_mon, fdname);
     if (s->fd == -1) {
         DPRINTF("fd_migration: invalid file descriptor identifier\n");
         goto err_after_get_fd;
migration.c +5 -0
index 1edeec5..679847d 100644
@@ -239,9 +239,14 @@ void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params,
 static int migrate_fd_cleanup(MigrationState *s)
 {
     int ret = 0;
+    struct stat st;
 
     qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL);
 
+    if (!fstat(s->fd, &st) && S_ISREG(st.st_mode)) {
+        fsync(s->fd);
+    }
+
     if (s->file) {
         DPRINTF("closing file\n");
         ret = qemu_fclose(s->file);
@@ -475,6 +480,17 @@ void migrate_del_blocker(Error *reason)
     migration_blockers = g_slist_remove(migration_blockers, reason);
 }

migration.c void migrate_del_blocker(Error *reason) · line 491

Quoted 10 lines
migration.c +9 -0
 
+static int file_start_outgoing_migration(MigrationState *s,
+                                         const char *filename)
+{
+    int fd;
+    fd = open(filename, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR);
+    if (fd < 0) {
+        return -errno;
+    }
+    return fd_start_outgoing_migration(s, NULL, fd);

'fd_start_outgoing_migration' requires that the FD you give it supports non-blocking I/O. File descriptors opened from plain files or block devices do not honour that requirement. So this proposed code will cause the entire QEMU process to block while migration is taking place. This is why no on has ever implemented the 'file:' protocol in QEMU before.

To deal with this issue you'd either have to use the POSIX async I/O APIs (or QEMU's internal equivalent), or spawn a separate 'dd' helper process and give QEMU a pipe FD instead. The latter is what libvirt does to implement migrate to file.

Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#3 lore raw

Re: [Qemu-devel] [PATCH 1/2] migration: Allow the migrate command to work on file: urls

Quoted 50 lines · Daniel P. Berrange
Quoted 49 lines · Benoît Canet

Usage:
(qemu) migrate file:/path/to/vm_statefile

---
 migration-fd.c |    4 ++--
 migration.c    |   20 +++++++++++++++++++-
 migration.h    |    2 +-
 3 files changed, 22 insertions(+), 4 deletions(-)
migration-fd.c +2 -2
index 50138ed..d39e44a 100644
@@ -73,9 +73,9 @@ static int fd_close(MigrationState *s)
     return 0;
 }
 
-int fd_start_outgoing_migration(MigrationState *s, const char *fdname)
+int fd_start_outgoing_migration(MigrationState *s, const char *fdname, int fd)
 {
-    s->fd = monitor_get_fd(cur_mon, fdname);
+    s->fd = fd ? fd : monitor_get_fd(cur_mon, fdname);
     if (s->fd == -1) {
         DPRINTF("fd_migration: invalid file descriptor identifier\n");
         goto err_after_get_fd;
migration.c +5 -0
index 1edeec5..679847d 100644
@@ -239,9 +239,14 @@ void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params,
 static int migrate_fd_cleanup(MigrationState *s)
 {
     int ret = 0;
+    struct stat st;
 
     qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL);
 
+    if (!fstat(s->fd, &st) && S_ISREG(st.st_mode)) {
+        fsync(s->fd);
+    }
+
     if (s->file) {
         DPRINTF("closing file\n");
         ret = qemu_fclose(s->file);
@@ -475,6 +480,17 @@ void migrate_del_blocker(Error *reason)
     migration_blockers = g_slist_remove(migration_blockers, reason);
 }
 
Quoted 16 lines

migration.c void migrate_del_blocker(Error *reason) · line 491

Quoted 9 lines
migration.c +9 -0
+static int file_start_outgoing_migration(MigrationState *s,
+                                         const char *filename)
+{
+    int fd;
+    fd = open(filename, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR);
+    if (fd < 0) {
+        return -errno;
+    }
+    return fd_start_outgoing_migration(s, NULL, fd);

'fd_start_outgoing_migration' requires that the FD you give it supports non-blocking I/O. File descriptors opened from plain files or block devices do not honour that requirement. So this proposed code will cause the entire QEMU process to block while migration is taking place. This is why no on has ever implemented the 'file:' protocol in QEMU before.

When I run the code it appear it does not block all the time. (guest is still interactive most of the time needed to complete migration) How can it be ?

Benoît

Quoted 12 lines

To deal with this issue you'd either have to use the POSIX async I/O APIs (or QEMU's internal equivalent), or spawn a separate 'dd' helper process and give QEMU a pipe FD instead. The latter is what libvirt does to implement migrate to file.

Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#4 lore raw

Re: [Qemu-devel] [PATCH 1/2] migration: Allow the migrate command to work on file: urls

Quoted 68 lines · Benoît Canet
Quoted 50 lines · Daniel P. Berrange
Quoted 49 lines · Benoît Canet

Usage:
(qemu) migrate file:/path/to/vm_statefile

---
 migration-fd.c |    4 ++--
 migration.c    |   20 +++++++++++++++++++-
 migration.h    |    2 +-
 3 files changed, 22 insertions(+), 4 deletions(-)
migration-fd.c +2 -2
index 50138ed..d39e44a 100644
@@ -73,9 +73,9 @@ static int fd_close(MigrationState *s)
     return 0;
 }
 
-int fd_start_outgoing_migration(MigrationState *s, const char *fdname)
+int fd_start_outgoing_migration(MigrationState *s, const char *fdname, int fd)
 {
-    s->fd = monitor_get_fd(cur_mon, fdname);
+    s->fd = fd ? fd : monitor_get_fd(cur_mon, fdname);
     if (s->fd == -1) {
         DPRINTF("fd_migration: invalid file descriptor identifier\n");
         goto err_after_get_fd;
migration.c +5 -0
index 1edeec5..679847d 100644
@@ -239,9 +239,14 @@ void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params,
 static int migrate_fd_cleanup(MigrationState *s)
 {
     int ret = 0;
+    struct stat st;
 
     qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL);
 
+    if (!fstat(s->fd, &st) && S_ISREG(st.st_mode)) {
+        fsync(s->fd);
+    }
+
     if (s->file) {
         DPRINTF("closing file\n");
         ret = qemu_fclose(s->file);
@@ -475,6 +480,17 @@ void migrate_del_blocker(Error *reason)
     migration_blockers = g_slist_remove(migration_blockers, reason);
 }
 
Quoted 16 lines

migration.c void migrate_del_blocker(Error *reason) · line 491

Quoted 9 lines
migration.c +9 -0
+static int file_start_outgoing_migration(MigrationState *s,
+                                         const char *filename)
+{
+    int fd;
+    fd = open(filename, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR);
+    if (fd < 0) {
+        return -errno;
+    }
+    return fd_start_outgoing_migration(s, NULL, fd);

'fd_start_outgoing_migration' requires that the FD you give it supports non-blocking I/O. File descriptors opened from plain files or block devices do not honour that requirement. So this proposed code will cause the entire QEMU process to block while migration is taking place. This is why no on has ever implemented the 'file:' protocol in QEMU before.

Quoted 3 lines

When I run the code it appear it does not block all the time. (guest is still interactive most of the time needed to complete migration) How can it be ?

The default migration bandwidth limit means qemu throttles the rate at which it sends data, so you won't notice the flaw with I/O blocking.

Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#5 lore raw

Re: [Qemu-devel] [PATCH 1/2] migration: Allow the migrate command to work on file: urls

In reply to Benoît Canet
Quoted 68 lines · Benoît Canet
Quoted 50 lines · Daniel P. Berrange
Quoted 49 lines · Benoît Canet

Usage:
(qemu) migrate file:/path/to/vm_statefile

---
 migration-fd.c |    4 ++--
 migration.c    |   20 +++++++++++++++++++-
 migration.h    |    2 +-
 3 files changed, 22 insertions(+), 4 deletions(-)
migration-fd.c +2 -2
index 50138ed..d39e44a 100644
@@ -73,9 +73,9 @@ static int fd_close(MigrationState *s)
     return 0;
 }
 
-int fd_start_outgoing_migration(MigrationState *s, const char *fdname)
+int fd_start_outgoing_migration(MigrationState *s, const char *fdname, int fd)
 {
-    s->fd = monitor_get_fd(cur_mon, fdname);
+    s->fd = fd ? fd : monitor_get_fd(cur_mon, fdname);
     if (s->fd == -1) {
         DPRINTF("fd_migration: invalid file descriptor identifier\n");
         goto err_after_get_fd;
migration.c +5 -0
index 1edeec5..679847d 100644
@@ -239,9 +239,14 @@ void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params,
 static int migrate_fd_cleanup(MigrationState *s)
 {
     int ret = 0;
+    struct stat st;
 
     qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL);
 
+    if (!fstat(s->fd, &st) && S_ISREG(st.st_mode)) {
+        fsync(s->fd);
+    }
+
     if (s->file) {
         DPRINTF("closing file\n");
         ret = qemu_fclose(s->file);
@@ -475,6 +480,17 @@ void migrate_del_blocker(Error *reason)
     migration_blockers = g_slist_remove(migration_blockers, reason);
 }
 
Quoted 16 lines

migration.c void migrate_del_blocker(Error *reason) · line 491

Quoted 9 lines
migration.c +9 -0
+static int file_start_outgoing_migration(MigrationState *s,
+                                         const char *filename)
+{
+    int fd;
+    fd = open(filename, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR);
+    if (fd < 0) {
+        return -errno;
+    }
+    return fd_start_outgoing_migration(s, NULL, fd);

'fd_start_outgoing_migration' requires that the FD you give it supports non-blocking I/O. File descriptors opened from plain files or block devices do not honour that requirement. So this proposed code will cause the entire QEMU process to block while migration is taking place. This is why no on has ever implemented the 'file:' protocol in QEMU before.

Quoted 9 lines

When I run the code it appear it does not block all the time. (guest is still interactive most of the time needed to complete migration) How can it be ?

Benoît

Quoted 3 lines

To deal with this issue you'd either have to use the POSIX async I/O APIs (or QEMU's internal equivalent)

I don't see how AIO could fit in this scheme.

Quoted 3 lines

, or spawn a

Quoted 2 lines

separate 'dd' helper process and give QEMU a pipe FD instead. The latter is what libvirt does to implement migrate to file.

I could subvert a exec_start_outgoing_migration clone to be fork_start_outgoing_migration doing a for then writing to disk the incoming data.

Does any QEMU developper have an idea on this ?

Benoît

Quoted 8 lines
Quoted 7 lines

Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#6 lore raw

Re: [Qemu-devel] [PATCH 1/2] migration: Allow the migrate command to work on file: urls

In reply to Daniel P. Berrange

Adding Luiz to the thread since he is concerned by migration.

Luiz do you have any hints on doing this properly ?

Benoît

Quoted 80 lines · Daniel P. Berrange
Quoted 48 lines · Benoît Canet

Usage:
(qemu) migrate file:/path/to/vm_statefile

---
 migration-fd.c |    4 ++--
 migration.c    |   20 +++++++++++++++++++-
 migration.h    |    2 +-
 3 files changed, 22 insertions(+), 4 deletions(-)
migration-fd.c +2 -2
index 50138ed..d39e44a 100644
@@ -73,9 +73,9 @@ static int fd_close(MigrationState *s)
     return 0;
 }
 
-int fd_start_outgoing_migration(MigrationState *s, const char *fdname)
+int fd_start_outgoing_migration(MigrationState *s, const char *fdname, int fd)
 {
-    s->fd = monitor_get_fd(cur_mon, fdname);
+    s->fd = fd ? fd : monitor_get_fd(cur_mon, fdname);
     if (s->fd == -1) {
         DPRINTF("fd_migration: invalid file descriptor identifier\n");
         goto err_after_get_fd;
migration.c +5 -0
index 1edeec5..679847d 100644
@@ -239,9 +239,14 @@ void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params,
 static int migrate_fd_cleanup(MigrationState *s)
 {
     int ret = 0;
+    struct stat st;
 
     qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL);
 
+    if (!fstat(s->fd, &st) && S_ISREG(st.st_mode)) {
+        fsync(s->fd);
+    }
+
     if (s->file) {
         DPRINTF("closing file\n");
         ret = qemu_fclose(s->file);
@@ -475,6 +480,17 @@ void migrate_del_blocker(Error *reason)
     migration_blockers = g_slist_remove(migration_blockers, reason);
 }

migration.c void migrate_del_blocker(Error *reason) · line 491

Quoted 10 lines
migration.c +9 -0
 
+static int file_start_outgoing_migration(MigrationState *s,
+                                         const char *filename)
+{
+    int fd;
+    fd = open(filename, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR);
+    if (fd < 0) {
+        return -errno;
+    }
+    return fd_start_outgoing_migration(s, NULL, fd);

'fd_start_outgoing_migration' requires that the FD you give it supports non-blocking I/O. File descriptors opened from plain files or block devices do not honour that requirement. So this proposed code will cause the entire QEMU process to block while migration is taking place. This is why no on has ever implemented the 'file:' protocol in QEMU before.

To deal with this issue you'd either have to use the POSIX async I/O APIs (or QEMU's internal equivalent), or spawn a separate 'dd' helper process and give QEMU a pipe FD instead. The latter is what libvirt does to implement migrate to file.

Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#7 lore raw

Re: [Qemu-devel] [PATCH 1/2] migration: Allow the migrate command to work on file: urls

Quoted 3 lines · On Mon, 27 Aug 2012 09:36:05 +0200 Benoît Canet <[email protected]>…

Adding Luiz to the thread since he is concerned by migration.

Luiz do you have any hints on doing this properly ?

I don't. Juan is a better option though.

But, we use exec migration for this, no?

Quoted 84 lines

Benoît

Quoted 80 lines · Daniel P. Berrange
Quoted 48 lines · Benoît Canet

Usage:
(qemu) migrate file:/path/to/vm_statefile

---
 migration-fd.c |    4 ++--
 migration.c    |   20 +++++++++++++++++++-
 migration.h    |    2 +-
 3 files changed, 22 insertions(+), 4 deletions(-)
migration-fd.c +2 -2
index 50138ed..d39e44a 100644
@@ -73,9 +73,9 @@ static int fd_close(MigrationState *s)
     return 0;
 }
 
-int fd_start_outgoing_migration(MigrationState *s, const char *fdname)
+int fd_start_outgoing_migration(MigrationState *s, const char *fdname, int fd)
 {
-    s->fd = monitor_get_fd(cur_mon, fdname);
+    s->fd = fd ? fd : monitor_get_fd(cur_mon, fdname);
     if (s->fd == -1) {
         DPRINTF("fd_migration: invalid file descriptor identifier\n");
         goto err_after_get_fd;
migration.c +5 -0
index 1edeec5..679847d 100644
@@ -239,9 +239,14 @@ void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params,
 static int migrate_fd_cleanup(MigrationState *s)
 {
     int ret = 0;
+    struct stat st;
 
     qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL);
 
+    if (!fstat(s->fd, &st) && S_ISREG(st.st_mode)) {
+        fsync(s->fd);
+    }
+
     if (s->file) {
         DPRINTF("closing file\n");
         ret = qemu_fclose(s->file);
@@ -475,6 +480,17 @@ void migrate_del_blocker(Error *reason)
     migration_blockers = g_slist_remove(migration_blockers, reason);
 }

migration.c void migrate_del_blocker(Error *reason) · line 491

Quoted 10 lines
migration.c +9 -0
 
+static int file_start_outgoing_migration(MigrationState *s,
+                                         const char *filename)
+{
+    int fd;
+    fd = open(filename, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR);
+    if (fd < 0) {
+        return -errno;
+    }
+    return fd_start_outgoing_migration(s, NULL, fd);

'fd_start_outgoing_migration' requires that the FD you give it supports non-blocking I/O. File descriptors opened from plain files or block devices do not honour that requirement. So this proposed code will cause the entire QEMU process to block while migration is taking place. This is why no on has ever implemented the 'file:' protocol in QEMU before.

To deal with this issue you'd either have to use the POSIX async I/O APIs (or QEMU's internal equivalent), or spawn a separate 'dd' helper process and give QEMU a pipe FD instead. The latter is what libvirt does to implement migrate to file.

Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#8 lore raw

PATCH 2/2 migration: Allow -incoming to work on file: urls

In reply to Benoît Canet

Usage:
-incoming file:/path/to/vm_statefile

---
 migration-fd.c |    5 ++---
 migration.c    |   14 +++++++++++++-
 migration.h    |    2 +-
 3 files changed, 16 insertions(+), 5 deletions(-)
migration-fd.c +2 -3
index d39e44a..bf500a0 100644
@@ -108,14 +108,13 @@ static void fd_accept_incoming_migration(void *opaque)
     qemu_fclose(f);
 }
 
-int fd_start_incoming_migration(const char *infd)
+int fd_start_incoming_migration(const char *infd, int fd)
 {
-    int fd;
     QEMUFile *f;
 
     DPRINTF("Attempting to start an incoming migration via fd\n");
 
-    fd = strtol(infd, NULL, 0);
+    fd = fd ? fd : strtol(infd, NULL, 0);
     f = qemu_fdopen(fd, "rb");
     if(f == NULL) {
         DPRINTF("Unable to apply qemu wrapper to file descriptor\n");
migration.c +13 -1
index 679847d..e4b228e 100644
@@ -64,6 +64,16 @@ static MigrationState *migrate_get_current(void)
     return &current_migration;
 }
 
+static int file_start_incoming_migration(const char *filename)
+{
+    int fd;
+    fd = open(filename, O_RDONLY);
+    if (fd < 0) {
+        return -errno;
+    }
+    return fd_start_incoming_migration(NULL, fd);
+}
+
 int qemu_start_incoming_migration(const char *uri, Error **errp)
 {
     const char *p;
@@ -77,7 +87,9 @@ int qemu_start_incoming_migration(const char *uri, Error **errp)
     else if (strstart(uri, "unix:", &p))
         ret = unix_start_incoming_migration(p);
     else if (strstart(uri, "fd:", &p))
-        ret = fd_start_incoming_migration(p);
+        ret = fd_start_incoming_migration(p, 0);
+    else if (strstart(uri, "file:", &p))
+        ret = file_start_incoming_migration(p);
 #endif
     else {
         fprintf(stderr, "unknown migration protocol: %s\n", uri);
migration.h +1 -1
index d431284..dbdaf72 100644
@@ -67,7 +67,7 @@ int unix_start_incoming_migration(const char *path);
 
 int unix_start_outgoing_migration(MigrationState *s, const char *path);
 
-int fd_start_incoming_migration(const char *path);
+int fd_start_incoming_migration(const char *path, int fd);
 
 int fd_start_outgoing_migration(MigrationState *s, const char *fdname, int fd);
 
Signature · 1 line
1.7.9.5