Live migration - exec: support to be reintroduced?
Howdy.
KVM's live migration support used to support an exec: protoco, allowing
either a completely arbitrary transport or a mechanism for storing
system state to a separate file for later resurrection, being used in the latter by libvirt's qemu driver. I notice that this support no longer exists in the current codebase.
Would a patch reimplementing this support be welcome?
Quoted 4 lines · Charles Duffy
Howdy.
KVM's live migration support used to support an exec: protoco, allowing either a completely arbitrary transport or a mechanism for storing system state to a separate file for later resurrection, being used in the latter by libvirt's qemu driver. I notice that this support no longer exists in the current codebase. Would a patch reimplementing this support be welcome?
Absolutely. I wasn't aware that libvirt used the exec: protocol. I'm somewhat surprised by that. What did it use it for?
Regards,
Anthony Liguori
Quoted 2 lines
Quoted 10 lines · Anthony Liguori
Quoted 8 lines · Charles Duffy
Howdy.
KVM's live migration support used to support an exec: protoco, allowing either a completely arbitrary transport or a mechanism for storing system state to a separate file for later resurrection, being used in the latter by libvirt's qemu driver. I notice that this support no longer exists in the current codebase.
Would a patch reimplementing this support be welcome?
Quoted 2 lines
Absolutely. I wasn't aware that libvirt used the exec: protocol. I'm somewhat surprised by that. What did it use it for?
Hm, I didn't realize it used it either, but it uses it for doing a save operation:
static int qemudDomainSave(virDomainPtr dom,
const char *path) {
...
if (asprintf (&command, "migrate \"exec:"
"dd of='%s' oflag=append conv=notrunc 2>/dev/null"
"\"", safe_path) == -1) {
qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
"%s", _("out of memory"));
VIR_FREE(safe_path);
return -1;
}
free(safe_path);
if (qemudMonitorCommand(driver, vm, command, &info) < 0) {...
I don't know if there is a better way to do that with the qemu monitor, to avoid
using migrate altogether. In any case, I'm sure other people would find exec:
useful as well.
Signature · 1 line
Chris Lalancette
Quoted 28 lines · Chris Lalancette
Quoted 9 lines · Anthony Liguori
Quoted 5 lines · Charles Duffy
Howdy.
KVM's live migration support used to support an exec: protoco, allowing either a completely arbitrary transport or a mechanism for storing system state to a separate file for later resurrection, being used in the latter by libvirt's qemu driver. I notice that this support no longer exists in the current codebase. Would a patch reimplementing this support be welcome?
Absolutely. I wasn't aware that libvirt used the exec: protocol. I'm somewhat surprised by that. What did it use it for?
Hm, I didn't realize it used it either, but it uses it for doing a save operation:
static int qemudDomainSave(virDomainPtr dom,
const char *path) { ... if (asprintf (&command, "migrate \"exec:" "dd of='%s' oflag=append conv=notrunc 2>/dev/null" "\"", safe_path) == -1) { qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED, "%s", _("out of memory")); VIR_FREE(safe_path); return -1; } free(safe_path); if (qemudMonitorCommand(driver, vm, command, &info) < 0) {
Quoted 6 lines
...
I don't know if there is a better way to do that with the qemu monitor, to avoid
using migrate altogether. In any case, I'm sure other people would find exec:
useful as well.
Sure. It would make sense for it to use file: instead of exec: though.
However, why is it not just using savevm? Saving the CPU state in the absence of checkpointing storage doesn't make a lot of sense.
Regards,
Anthony Liguori
Quoted 44 lines · Anthony Liguori
Quoted 33 lines · Chris Lalancette
Quoted 11 lines · Anthony Liguori
Quoted 9 lines · Charles Duffy
Howdy.
KVM's live migration support used to support an exec: protoco, allowing either a completely arbitrary transport or a mechanism for storing system state to a separate file for later resurrection, being used in the latter by libvirt's qemu driver. I notice that this support no longer exists in the current codebase.
Would a patch reimplementing this support be welcome?Quoted 3 lines
Absolutely. I wasn't aware that libvirt used the exec: protocol. I'm somewhat surprised by that. What did it use it for?
Hm, I didn't realize it used it either, but it uses it for doing a save operation:
static int qemudDomainSave(virDomainPtr dom,
const char *path) { ... if (asprintf (&command, "migrate \"exec:" "dd of='%s' oflag=append conv=notrunc 2>/dev/null" "\"", safe_path) == -1) { qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED, "%s", _("out of memory")); VIR_FREE(safe_path); return -1;}
free(safe_path);Quoted 9 lines
if (qemudMonitorCommand(driver, vm, command, &info) < 0) {...
I don't know if there is a better way to do that with the qemu monitor, to avoid
using migrate altogether. In any case, I'm sure other people would find exec:
useful as well.
Quoted 4 lines
Sure. It would make sense for it to use file: instead of exec: though.
However, why is it not just using savevm? Saving the CPU state in the absence of checkpointing storage doesn't make a lot of sense.
This isn't for snapshotting, so checkpointing of storage is unneccessary. This is just straight save+restore, akin to hibernate-to-disk for a physical machine.
The savevm command only works with qcow files, which is not guarenteed to be available in this context.
We do intend to support real snapshotting of VMs at some point, for which "savevm" could be useful
Daniel
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Quoted 7 lines · Daniel P. Berrange
Quoted 2 lines
However, why is it not just using savevm? Saving the CPU state in the absence of checkpointing storage doesn't make a lot of sense.
This isn't for snapshotting, so checkpointing of storage is unneccessary. This is just straight save+restore, akin to hibernate-to-disk for a physical machine.
Quoted 5 lines
The savevm command only works with qcow files, which is not guarenteed to be available in this context.
We do intend to support real snapshotting of VMs at some point, for which "savevm" could be useful
Yes, we had a thread a couple of months ago about why "savevm" snapshotting in qcow2 is not always appropriate or useful.
-- Jamie
Quoted 3 lines · Daniel P. Berrange
This isn't for snapshotting, so checkpointing of storage is unneccessary. This is just straight save+restore, akin to hibernate-to-disk for a physical machine.
This is a fundamentally broken concept. You cannot just save the guest's memory state without saving the current state of the storage.
I know this exists in Xen, but no one can use it in a serious manner as it could very easily lead to data corruption.
Regards,
Anthony Liguori
Quoted 5 lines · Anthony Liguori
Quoted 2 lines · Daniel P. Berrange
This isn't for snapshotting, so checkpointing of storage is unneccessary. This is just straight save+restore, akin to hibernate-to-disk for a physical machine.
This is a fundamentally broken concept. You cannot just save the guest's memory state without saving the current state of the storage.
You're requiring the user to manage storage checkpointing themselves in this case -- but whether they're using LVM snapshotting or replacing the qcow2 backend with an empty file backed by the old store, the user may choose to do that themselves rather than pushing the work off to qemu (and forcing everything to be stored in a single file); I use (and wish not to lose) this functionality myself.
Quoted 5 lines · Anthony Liguori
Quoted 2 lines · Daniel P. Berrange
This isn't for snapshotting, so checkpointing of storage is unneccessary. This is just straight save+restore, akin to hibernate-to-disk for a physical machine.
This is a fundamentally broken concept. You cannot just save the guest's memory state without saving the current state of the storage.
Oh -- let me follow up on how this works in libvirt:
The "save" and "restore" commands shut down and start the VM when invoked; consequently, no storage changes are made while the VM is down. Restoring more than once off the same "save" is not an intended use case.
Quoted 10 lines · Charles Duffy
Quoted 5 lines · Anthony Liguori
Quoted 2 lines · Daniel P. Berrange
This isn't for snapshotting, so checkpointing of storage is unneccessary. This is just straight save+restore, akin to hibernate-to-disk for a physical machine.
This is a fundamentally broken concept. You cannot just save the guest's memory state without saving the current state of the storage.
Oh -- let me follow up on how this works in libvirt:
The "save" and "restore" commands shut down and start the VM when invoked; consequently, no storage changes are made while the VM is down. Restoring more than once off the same "save" is not an intended use case.
I see, that makes more sense then.
Regards,
Anthony Liguori
Quoted 2 lines
Quoted 10 lines · Anthony Liguori
Quoted 8 lines · Charles Duffy
Howdy.
KVM's live migration support used to support an exec: protoco, allowing either a completely arbitrary transport or a mechanism for storing system state to a separate file for later resurrection, being used in the latter by libvirt's qemu driver. I notice that this support no longer exists in the current codebase.
Would a patch reimplementing this support be welcome?
Quoted 2 lines
Absolutely. I wasn't aware that libvirt used the exec: protocol. I'm somewhat surprised by that. What did it use it for?
We used it to implement save-to-file, exec'ing 'dd'. I'd rather prefer that we had a more explicit 'migrate to a file' capability rather than the hack of execing dd.
Daniel
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Quoted 4 lines · Daniel P. Berrange
We used it to implement save-to-file, exec'ing 'dd'. I'd rather prefer that we had a more explicit 'migrate to a file' capability rather than the hack of execing dd.
(qemu) acceptfd blah
receives an file descriptor from the monitor using SCM_RIGHTS and assigns it to the tag 'blah' (qemu) migrate fd:blah
migrates to the fd denominated by the tag 'blah'
(qemu) closefd blah
You can use literal numbers instead of tags to refer to file descriptors inherited from the environment:
(qemu) migrate fd:17
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 11 lines · Avi Kivity
Quoted 4 lines · Daniel P. Berrange
We used it to implement save-to-file, exec'ing 'dd'. I'd rather prefer that we had a more explicit 'migrate to a file' capability rather than the hack of execing dd.
(qemu) acceptfd blah
receives an file descriptor from the monitor usingSCM_RIGHTSand assigns it to the tag 'blah' (qemu) migrate fd:blah
migrates to the fd denominated by the tag 'blah'
(qemu) closefd blah
This could be generally useful for other things too (like char device redirection).
I'm not sure how many people would really use it though, you're talking about serious unix-fu here.
Regards,
Anthony Liguori
Quoted 4 lines
You can use literal numbers instead of tags to refer to file descriptors inherited from the environment:
(qemu) migrate fd:17
Quoted 14 lines · Anthony Liguori
Quoted 6 lines · Avi Kivity
Quoted 4 lines · Daniel P. Berrange
We used it to implement save-to-file, exec'ing 'dd'. I'd rather prefer that we had a more explicit 'migrate to a file' capability rather than the hack of execing dd.
Quoted 6 lines
(qemu) acceptfd blah
receives an file descriptor from the monitor usingSCM_RIGHTSand assigns it to the tag 'blah'
(qemu) migrate fd:blah
migrates to the fd denominated by the tag 'blah'
(qemu) closefd blah
Quoted 5 lines
This could be generally useful for other things too (like char device redirection).
I'm not sure how many people would really use it though, you're talking about serious unix-fu here.
It is useful from a security point of view - it means QEMU doesn't need to be given permissions to create files, merely append to an opened file handle.
On a related note, Avi pointed out to me that SCM_RIGHTS fd passing would be important for NIC hotplug to allow parity with -net arg on the command line. If the QEMU process is running unprivileged, it will not have rights to create TAP devices & giving it a setuid() network script is not desirable. The management app invoking QEMU could open the TAP device, and do any setup before passing the FD to the NIC hotplug command in the monitor.
Daniel
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Quoted 4 lines · Daniel P. Berrange
It is useful from a security point of view - it means QEMU doesn't need to be given permissions to create files, merely append to an opened file handle.
Quoted 8 lines
On a related note, Avi pointed out to me that
SCM_RIGHTSfd passing would be important for NIC hotplug to allow parity with -net arg on the command line. If the QEMU process is running unprivileged, it will not have rights to create TAP devices & giving it asetuid()network script is not desirable. The management app invoking QEMU could open the TAP device, and do any setup before passing the FD to the NIC hotplug command in the monitor.
Yup. If libvirt has a use case for it, then I'm more than happy to review patches.
I'm always looking for an excuse to use SCM_RIGHTS :-)
I think the monitor interface could use improvement. I think it would look better as:
(qemu) receivefd /path/to/unix/socket
/* waits until it receives an fd on /path/to/unix/socket */ fd=10
(qemu) closefd 10
Then all of the existing uses of fd= can be preserved.
I like the idea of using a temporary socket because you don't have to rely on the monitor being on a unix socket. This will be especially useful when we can support tunneling the monitor through VNC.
Regards,
Anthony Liguori
Quoted 2 lines
Daniel
Quoted 27 lines · Anthony Liguori
Quoted 4 lines · Daniel P. Berrange
It is useful from a security point of view - it means QEMU doesn't need to be given permissions to create files, merely append to an opened file handle.
Quoted 8 lines
On a related note, Avi pointed out to me that
SCM_RIGHTSfd passing would be important for NIC hotplug to allow parity with -net arg on the command line. If the QEMU process is running unprivileged, it will not have rights to create TAP devices & giving it asetuid()network script is not desirable. The management app invoking QEMU could open the TAP device, and do any setup before passing the FD to the NIC hotplug command in the monitor.Yup. If libvirt has a use case for it, then I'm more than happy to review patches.
I'm always looking for an excuse to use
SCM_RIGHTS:-)I think the monitor interface could use improvement. I think it would look better as:
(qemu) receivefd /path/to/unix/socket
/* waits until it receives an fd on /path/to/unix/socket */ fd=10
(qemu) closefd 10
Quoted 5 lines
Then all of the existing uses of fd= can be preserved.
I like the idea of using a temporary socket because you don't have to rely on the monitor being on a unix socket. This will be especially useful when we can support tunneling the monitor through VNC.
Yes, except that I would wouldn't want to pass "/path/to/unix/socket" via the monitor - that allows any process which can access that path to potentially open the socket & intercept the credentials.
If I wasn't using a UNIX socket for the monitor already, then I'd want to be able to pass a FD to a unix socket on the command line so I know who's on the other end of it.
eg, if i was using a hypothetical VNC server transport for the monitor, then perhaps allow
--monitor vnc,scmrightsfd=7
Or, an explicit --scmrights arg for it
Daniel
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Quoted 28 lines · Daniel P. Berrange
Quoted 26 lines · Anthony Liguori
Quoted 4 lines · Daniel P. Berrange
It is useful from a security point of view - it means QEMU doesn't need to be given permissions to create files, merely append to an opened file handle.
Quoted 9 lines
On a related note, Avi pointed out to me that
SCM_RIGHTSfd passing would be important for NIC hotplug to allow parity with -net arg on the command line. If the QEMU process is running unprivileged, it will not have rights to create TAP devices & giving it asetuid()network script is not desirable. The management app invoking QEMU could open the TAP device, and do any setup before passing the FD to the NIC hotplug command in the monitor.Yup. If libvirt has a use case for it, then I'm more than happy to review patches.
I'm always looking for an excuse to use
SCM_RIGHTS:-)I think the monitor interface could use improvement. I think it would look better as:
(qemu) receivefd /path/to/unix/socket
/* waits until it receives an fd on /path/to/unix/socket */ fd=10
(qemu) closefd 10
Quoted 9 lines
Quoted 4 lines
Then all of the existing uses of fd= can be preserved.
I like the idea of using a temporary socket because you don't have to rely on the monitor being on a unix socket. This will be especially useful when we can support tunneling the monitor through VNC.
Yes, except that I would wouldn't want to pass "/path/to/unix/socket" via the monitor - that allows any process which can access that path to potentially open the socket & intercept the credentials.
I don't really see this as a problem.
Quoted 8 lines
If I wasn't using a UNIX socket for the monitor already, then I'd
want to be able to pass a FD to a unix socket on the command line
so I know who's on the other end of it. eg, if i was using a hypothetical VNC server transport for the monitor, then perhaps allow--monitor vnc,scmrightsfd=7
Or, an explicit --scmrights arg for it
Yeah, the later sounds more reasonable, but I don't really know that I agree that the only safe thing to do is here pass an fd on exec. Please describe an attack scenario where a user could access /path/to/unix/socket that isn't trusted?
Regards,
Anthony Liguori
Quoted 2 lines
Daniel
Quoted 10 lines · Anthony Liguori
I think the monitor interface could use improvement. I think it would look better as:
(qemu) receivefd /path/to/unix/socket
/* waits until it receives an fd on /path/to/unix/socket */ fd=10
(qemu) closefd 10Then all of the existing uses of fd= can be preserved.
Ouch, my fd tags are much better as they don't require the user to read the fd number.
Quoted 1 line
I like the idea of using a temporary socket because you don't have to rely on the monitor being on a unix socket. This will be especially useful when we can support tunneling the monitor through VNC.
I can't really see a user creating an fd and passing it to qemu through a unix domain socket. This is for management apps.
Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.
Quoted 9 lines · Anthony Liguori
Quoted 5 lines
(qemu) acceptfd blah
receives an file descriptor from the monitor usingSCM_RIGHTSand assigns it to the tag 'blah' (qemu) migrate fd:blah
migrates to the fd denominated by the tag 'blah'
(qemu) closefd blahThis could be generally useful for other things too (like char device redirection).
I'm not sure how many people would really use it though, you're talking about serious unix-fu here.
While SCM_RIGHTS does not feature on prime-time television, it's hardly complex. I mean, compare with tty and sessions and group leaders and all that goo.
Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.
Quoted 5 lines · Anthony Liguori
Quoted 2 lines · Charles Duffy
KVM's live migration support used to support an exec: protoco, allowing either a completely arbitrary transport or a mechanism for storing system state to a separate file for later resurrection, being used in the latter by libvirt's qemu driver. I notice that this support no longer exists in the current codebase. Would a patch reimplementing this support be welcome?
Absolutely.
Please see attached patch.
I'm new to the codebase (and a bit rusty on my C), so I expect some rework to be needed on this one; let me know what needs doing, and I'll try to update it as time permits.
Makefile.target +1 -1
@@ -596,7 +596,7 @@ endif ifdef CONFIG_WIN32 OBJS+=block-raw-win32.o else -OBJS+=block-raw-posix.o +OBJS+=block-raw-posix.o migration-exec.o endif LIBS+=-lz
hw/hw.h +2 -0
@@ -35,6 +35,8 @@ QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer, QEMUFileRateLimit *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); +QEMUFile *qemu_popen_cmd (const char *command,const char *mode);void qemu_fflush (QEMUFile *f);int qemu_fclose (QEMUFile *f);void qemu_put_buffer (QEMUFile *f,const uint8_t *buf,int size);
migration-exec.c new file +295 -0
295 lines not on this page · raw message
migration.c +8 -0
@@ -26,6 +26,10 @@ void qemu_start_incoming_migration(const char *uri)if (strstart (uri,"tcp:" , &p))tcp_start_incoming_migration (p); +#if !defined(WIN32 ) + else if (strstart(uri, "exec:", &p)) + exec_start_incoming_migration(p); +#endif else fprintf(stderr, "unknown migration protocol: %s\n", uri); }
@@ -37,6 +41,10 @@ void do_migrate(int detach, const char *uri)if (strstart (uri,"tcp:" , &p)) s =tcp_start_outgoing_migration (p, max_throttle, detach); +#if !defined(WIN32 ) + else if (strstart(uri, "exec:", &p)) + s =exec_start_outgoing_migration (p, max_throttle, detach); +#endif else term_printf("unknown migration protocol: %s\n", uri);
migration.h +6 -0
@@ -39,6 +39,12 @@ void do_migrate_set_speed(const char *value);void do_info_migrate (void ); +int exec_start_incoming_migration (const char *host_port); + +MigrationState *exec_start_outgoing_migration (const char *host_port, +int64_t bandwidth_limit, +int detach); +int tcp_start_incoming_migration (const char *host_port); MigrationState *tcp_start_outgoing_migration(const char *host_port,
vl.c +64 -0
76 lines not on this page · raw message
[Qemu-devel] Re: [PATCH] Re: Live migration - exec: support to be reintroduced? (r2)
The attached version refactors to reduce the amount of duplicate code between migrate-tcp and migrate-exec.
Makefile.target +1 -1
@@ -596,7 +596,7 @@ endif ifdef CONFIG_WIN32 OBJS+=block-raw-win32.o else -OBJS+=block-raw-posix.o +OBJS+=block-raw-posix.o migration-exec.o endif LIBS+=-lz
hw/hw.h +2 -0
@@ -35,6 +35,8 @@ QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer, QEMUFileRateLimit *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); +QEMUFile *qemu_popen_cmd (const char *command,const char *mode);void qemu_fflush (QEMUFile *f);int qemu_fclose (QEMUFile *f);void qemu_put_buffer (QEMUFile *f,const uint8_t *buf,int size);
migration-exec.c new file +141 -0
141 lines not on this page · raw message
migration-tcp.c +18 -170
248 lines not on this page · raw message
migration.c +177 -0
198 lines not on this page · raw message
migration.h +49 -0
66 lines not on this page · raw message
vl.c +64 -0
76 lines not on this page · raw message
[Qemu-devel] Re: [PATCH] Re: Live migration - exec: support to be reintroduced? (r2)
Left out a suggested comment and Signed-off-by last time.
---
Reintroduce migrate-to-exec: support
KVM's live migration support included support for exec: URLs, allowing system state to be written or received via an arbitrary popen()ed subprocess. This provides a convenient way to pipe state through a compression algorithm or an arbitrary network transport on its way to its destination, and a convenient way to write state to disk; libvirt's qemu driver currently uses migration to exec: targets for this latter purpose.
This version of the patch refactors now-common code from migrate-tcp.c into migrate.c.
Anthony Liguori
AppliedRe: [Qemu-devel] Re: [PATCH] Re: Live migration - exec: support to be reintroduced? (r2)
In reply to Charles DuffyQuoted 1 line · Charles Duffy
The attached version refactors to reduce the amount of duplicate code between migrate-tcp and migrate-exec.
Applied. Thanks.
Although I'd rather see a qemu_fopen_file() or something similar that took a FILE * instead of qemu_popen[_cmd](). A follow up patch would be appreciated.
Regards,
Anthony Liguori