diff options
author | Anthony PERARD <anthony.perard@citrix.com> | 2011-12-01 18:09:42 +0000 |
---|---|---|
committer | Anthony PERARD <anthony.perard@citrix.com> | 2011-12-01 18:09:42 +0000 |
commit | cad46912ccfd2bd082d5ca9b93accff4ab1acc3a (patch) | |
tree | e5ba501a922abd3d03125f8cfdca8ada675fd98b /tools/libxl/libxl_qmp.c | |
parent | 5ca4745339164c9c3fb3f3c353a25ed11fe3616f (diff) | |
download | xen-cad46912ccfd2bd082d5ca9b93accff4ab1acc3a.tar.gz xen-cad46912ccfd2bd082d5ca9b93accff4ab1acc3a.tar.bz2 xen-cad46912ccfd2bd082d5ca9b93accff4ab1acc3a.zip |
libxl: libxl__qmp_migrate
This command works in two steps. First, a fd is sent to QEMU through the QMP
socket. And then, the second command "migrate" use the fd previously sent to
ask QEMU to save its states.
This comes with an alternative qmp_send function that can send a fd.
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Acked-by: Ian Jackson <ian.jackson.citrix.com>
Committed-by: Ian Jackson <ian.jackson.citrix.com>
Diffstat (limited to 'tools/libxl/libxl_qmp.c')
-rw-r--r-- | tools/libxl/libxl_qmp.c | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c index 4c261369d5..4bc0dc87ae 100644 --- a/tools/libxl/libxl_qmp.c +++ b/tools/libxl/libxl_qmp.c @@ -532,6 +532,52 @@ out: return rc; } +static int qmp_send_fd(libxl__gc *gc, libxl__qmp_handler *qmp, + libxl_key_value_list *args, + qmp_callback_t callback, void *opaque, + qmp_request_context *context, + int fd) +{ + struct msghdr msg = { 0 }; + struct cmsghdr *cmsg; + char control[CMSG_SPACE(sizeof (fd))]; + struct iovec iov; + char *buf = NULL; + + buf = qmp_send_prepare(gc, qmp, "getfd", args, callback, opaque, context); + + /* Response data */ + iov.iov_base = buf; + iov.iov_len = strlen(buf); + + /* compose the message */ + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + msg.msg_control = control; + msg.msg_controllen = sizeof (control); + + /* attach open fd */ + cmsg = CMSG_FIRSTHDR(&msg); + cmsg->cmsg_level = SOL_SOCKET; + cmsg->cmsg_type = SCM_RIGHTS; + cmsg->cmsg_len = CMSG_LEN(sizeof (fd)); + *(int *)CMSG_DATA(cmsg) = fd; + + msg.msg_controllen = cmsg->cmsg_len; + + if (sendmsg(qmp->qmp_fd, &msg, 0) < 0) { + LIBXL__LOG_ERRNO(qmp->ctx, LIBXL__LOG_ERROR, + "Failed to send a QMP message to QEMU."); + return ERROR_FAIL; + } + if (libxl_write_exactly(qmp->ctx, qmp->qmp_fd, "\r\n", 2, + "CRLF", "QMP socket")) { + return ERROR_FAIL; + } + + return qmp->last_id_used; +} + static int qmp_synchronous_send(libxl__qmp_handler *qmp, const char *cmd, libxl_key_value_list *args, qmp_callback_t callback, void *opaque, @@ -768,6 +814,69 @@ int libxl__qmp_pci_del(libxl__gc *gc, int domid, libxl_device_pci *pcidev) return qmp_device_del(gc, domid, id); } +static int qmp_getfd(libxl__gc *gc, libxl__qmp_handler *qmp, + int fd, const char *name) +{ + flexarray_t *parameters = NULL; + libxl_key_value_list args = NULL; + int rc = 0; + + parameters = flexarray_make(2, 1); + if (!parameters) + return ERROR_NOMEM; + flexarray_append_pair(parameters, "fdname", (char*)name); + args = libxl__xs_kvs_of_flexarray(gc, parameters, parameters->count); + if (!args) { + rc = ERROR_NOMEM; + goto out; + } + + if (qmp_send_fd(gc, qmp, &args, NULL, NULL, NULL, fd) < 0) { + rc = ERROR_FAIL; + } +out: + flexarray_free(parameters); + return rc; +} + +int libxl__qmp_migrate(libxl__gc *gc, int domid, int fd) +{ +#define MIGRATE_FD_NAME "dm-migrate" + libxl__qmp_handler *qmp = NULL; + flexarray_t *parameters = NULL; + libxl_key_value_list args = NULL; + int rc = 0; + + qmp = libxl__qmp_initialize(libxl__gc_owner(gc), domid); + if (!qmp) + return ERROR_FAIL; + + rc = qmp_getfd(gc, qmp, fd, MIGRATE_FD_NAME); + if (rc) + goto out; + + parameters = flexarray_make(2, 1); + if (!parameters) { + rc = ERROR_NOMEM; + goto out; + } + flexarray_append_pair(parameters, "uri", "fd:" MIGRATE_FD_NAME); + args = libxl__xs_kvs_of_flexarray(gc, parameters, parameters->count); + if (!args) { + rc = ERROR_NOMEM; + goto out2; + } + + rc = qmp_synchronous_send(qmp, "migrate", &args, + NULL, NULL, qmp->timeout); + +out2: + flexarray_free(parameters); +out: + libxl__qmp_close(qmp); + return rc; +} + int libxl__qmp_initializations(libxl_ctx *ctx, uint32_t domid) { libxl__qmp_handler *qmp = NULL; |