[libvirt] [PATCH] add file descriptor migration
by Paolo Bonzini
This is the patch from Chris, with the accept removed and rebased above
my previous cleanup.
Signed-off-by: Paolo Bonzini <pbonzini(a)redhat.com>
Cc: Chris Lalancette <clalance(a)redhat.com>
Cc: Avi Kivity <avi(a)redhat.com>
---
Makefile | 2 +-
hw/hw.h | 1 +
migration-fd.c | 137 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
migration.c | 4 ++
migration.h | 7 +++
savevm.c | 28 +++++++++++
6 files changed, 178 insertions(+), 1 deletions(-)
create mode 100644 migration-fd.c
diff --git a/Makefile b/Makefile
index 5279504..c7ff0be 100644
--- a/Makefile
+++ b/Makefile
@@ -93,7 +93,7 @@ obj-y += qdev.o qdev-properties.o ssi.o
obj-$(CONFIG_BRLAPI) += baum.o
obj-$(CONFIG_WIN32) += tap-win32.o
-obj-$(CONFIG_POSIX) += migration-exec.o
+obj-$(CONFIG_POSIX) += migration-exec.o migration-fd.o
audio/audio.o audio/fmodaudio.o: QEMU_CFLAGS += $(FMOD_CFLAGS)
diff --git a/hw/hw.h b/hw/hw.h
index 322f077..91bf800 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -49,6 +49,7 @@ QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer,
QEMUFileRateLimit *rate_limit,
QEMUFileSetRateLimit *set_rate_limit);
QEMUFile *qemu_fopen(const char *filename, const char *mode);
+QEMUFile *qemu_fdopen(int fd, 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);
diff --git a/migration-fd.c b/migration-fd.c
new file mode 100644
index 0000000..794c2ac
--- /dev/null
+++ b/migration-fd.c
@@ -0,0 +1,137 @@
+/*
+ * QEMU live migration via generic fd
+ *
+ * Copyright Red Hat, Inc. 2009
+ *
+ * Authors:
+ * Chris Lalancette <clalance(a)redhat.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu-common.h"
+#include "qemu_socket.h"
+#include "migration.h"
+#include "monitor.h"
+#include "qemu-char.h"
+#include "sysemu.h"
+#include "buffered_file.h"
+#include "block.h"
+#include "qemu_socket.h"
+
+//#define DEBUG_MIGRATION_FD
+
+#ifdef DEBUG_MIGRATION_FD
+#define dprintf(fmt, ...) \
+ do { printf("migration-fd: " fmt, ## __VA_ARGS__); } while (0)
+#else
+#define dprintf(fmt, ...) \
+ do { } while (0)
+#endif
+
+static int fd_errno(FdMigrationState *s)
+{
+ return errno;
+}
+
+static int fd_write(FdMigrationState *s, const void * buf, size_t size)
+{
+ return write(s->fd, buf, size);
+}
+
+static int fd_close(FdMigrationState *s)
+{
+ dprintf("fd_close\n");
+ if (s->fd != -1) {
+ close(s->fd);
+ s->fd = -1;
+ }
+ return 0;
+}
+
+MigrationState *fd_start_outgoing_migration(Monitor *mon,
+ const char *fdname,
+ int64_t bandwidth_limit,
+ int detach)
+{
+ FdMigrationState *s;
+
+ s = qemu_mallocz(sizeof(*s));
+
+ s->fd = monitor_get_fd(mon, fdname);
+ if (s->fd == -1) {
+ dprintf("fd_migration: invalid file descriptor identifier\n");
+ goto err_after_alloc;
+ }
+
+ if (fcntl(s->fd, F_SETFD, O_NONBLOCK) == -1) {
+ dprintf("Unable to set nonblocking mode on file descriptor\n");
+ goto err_after_open;
+ }
+
+ s->get_error = fd_errno;
+ s->write = fd_write;
+ s->close = fd_close;
+ s->mig_state.cancel = migrate_fd_cancel;
+ s->mig_state.get_status = migrate_fd_get_status;
+ s->mig_state.release = migrate_fd_release;
+
+ s->state = MIG_STATE_ACTIVE;
+ s->mon_resume = NULL;
+ s->bandwidth_limit = bandwidth_limit;
+
+ if (!detach)
+ migrate_fd_monitor_suspend(s);
+
+ migrate_fd_connect(s);
+ return &s->mig_state;
+
+err_after_open:
+ close(s->fd);
+err_after_alloc:
+ qemu_free(s);
+ return NULL;
+}
+
+static void fd_accept_incoming_migration(void *opaque)
+{
+ QEMUFile *f = opaque;
+ int ret;
+
+ ret = qemu_loadvm_state(f);
+ if (ret < 0) {
+ fprintf(stderr, "load of migration failed\n");
+ goto err;
+ }
+ qemu_announce_self();
+ dprintf("successfully loaded vm state\n");
+ /* we've successfully migrated, close the fd */
+ qemu_set_fd_handler2(qemu_stdio_fd(f), NULL, NULL, NULL, NULL);
+ if (autostart)
+ vm_start();
+
+err:
+ qemu_fclose(f);
+}
+
+int fd_start_incoming_migration(const char *infd)
+{
+ int fd;
+ QEMUFile *f;
+
+ dprintf("Attempting to start an incoming migration via fd\n");
+
+ fd = strtol(infd, NULL, 0);
+ f = qemu_fdopen(fd, "rb");
+ if(f == NULL) {
+ dprintf("Unable to apply qemu wrapper to file descriptor\n");
+ return -errno;
+ }
+
+ qemu_set_fd_handler2(fd, NULL, fd_accept_incoming_migration, NULL,
+ (void *)(unsigned long)f);
+
+ return 0;
+}
diff --git a/migration.c b/migration.c
index ee64d41..0ca4399 100644
--- a/migration.c
+++ b/migration.c
@@ -43,6 +43,8 @@ void qemu_start_incoming_migration(const char *uri)
#if !defined(WIN32)
else if (strstart(uri, "exec:", &p))
exec_start_incoming_migration(p);
+ else if (strstart(uri, "fd:", &p))
+ fd_start_incoming_migration(p);
#endif
else
fprintf(stderr, "unknown migration protocol: %s\n", uri);
@@ -58,6 +60,8 @@ void do_migrate(Monitor *mon, int detach, const char *uri)
#if !defined(WIN32)
else if (strstart(uri, "exec:", &p))
s = exec_start_outgoing_migration(p, max_throttle, detach);
+ else if (strstart(uri, "fd:", &p))
+ s = fd_start_outgoing_migration(mon, p, max_throttle, detach);
#endif
else
monitor_printf(mon, "unknown migration protocol: %s\n", uri);
diff --git a/migration.h b/migration.h
index 37c7f8e..5033d02 100644
--- a/migration.h
+++ b/migration.h
@@ -73,6 +73,13 @@ MigrationState *tcp_start_outgoing_migration(const char *host_port,
int64_t bandwidth_limit,
int detach);
+int fd_start_incoming_migration(const char *path);
+
+MigrationState *fd_start_outgoing_migration(Monitor *mon,
+ const char *fdname,
+ int64_t bandwidth_limit,
+ int detach);
+
void migrate_fd_monitor_suspend(FdMigrationState *s);
void migrate_fd_error(FdMigrationState *s);
diff --git a/savevm.c b/savevm.c
index 975e7ab..4575653 100644
--- a/savevm.c
+++ b/savevm.c
@@ -285,6 +285,34 @@ int qemu_stdio_fd(QEMUFile *f)
return fd;
}
+QEMUFile *qemu_fdopen(int fd, const char *mode)
+{
+ QEMUFileStdio *s;
+
+ if (mode == NULL ||
+ (mode[0] != 'r' && mode[0] != 'w') ||
+ mode[1] != 'b' || mode[2] != 0) {
+ fprintf(stderr, "qemu_fdopen: Argument validity check failed\n");
+ return NULL;
+ }
+
+ s = qemu_mallocz(sizeof(QEMUFileStdio));
+ s->stdio_file = fdopen(fd, mode);
+ if (!s->stdio_file)
+ goto fail;
+
+ if(mode[0] == 'r') {
+ s->file = qemu_fopen_ops(s, NULL, stdio_get_buffer, stdio_fclose, NULL, NULL);
+ } else {
+ s->file = qemu_fopen_ops(s, stdio_put_buffer, NULL, stdio_fclose, NULL, NULL);
+ }
+ return s->file;
+
+fail:
+ qemu_free(s);
+ return NULL;
+}
+
QEMUFile *qemu_fopen_socket(int fd)
{
QEMUFileSocket *s = qemu_mallocz(sizeof(QEMUFileSocket));
--
1.6.2.5
15 years, 8 months
[libvirt] [PATCH] Split virDomainMigrate into functions.
by Chris Lalancette
Re-factor virDomainMigrate to split out the version 1 and version 2
protocols into their own functions. In reality, the two versions share
very little in common, so forcing them together in the same function was
just confusing. This will also make adding tunnelled migration easier.
Signed-off-by: Chris Lalancette <clalance(a)redhat.com>
---
src/libvirt.c | 258 ++++++++++++++++++++++++++++++++++-----------------------
1 files changed, 155 insertions(+), 103 deletions(-)
diff --git a/src/libvirt.c b/src/libvirt.c
index 9fd864d..6c1cc3d 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -2874,6 +2874,146 @@ error:
}
+static virDomainPtr
+virDomainMigrateVersion1 (virDomainPtr domain,
+ virConnectPtr dconn,
+ unsigned long flags,
+ const char *dname,
+ const char *uri,
+ unsigned long bandwidth)
+{
+ virDomainPtr ddomain = NULL;
+ char *uri_out = NULL;
+ char *cookie = NULL;
+ int cookielen = 0;
+
+ /* Prepare the migration.
+ *
+ * The destination host may return a cookie, or leave cookie as
+ * NULL.
+ *
+ * The destination host MUST set uri_out if uri_in is NULL.
+ *
+ * If uri_in is non-NULL, then the destination host may modify
+ * the URI by setting uri_out. If it does not wish to modify
+ * the URI, it should leave uri_out as NULL.
+ */
+ if (dconn->driver->domainMigratePrepare
+ (dconn, &cookie, &cookielen, uri, &uri_out, flags, dname,
+ bandwidth) == -1)
+ goto done;
+
+ if (uri == NULL && uri_out == NULL) {
+ virLibConnError (domain->conn, VIR_ERR_INTERNAL_ERROR,
+ _("domainMigratePrepare did not set uri"));
+ goto done;
+ }
+ if (uri_out)
+ uri = uri_out; /* Did domainMigratePrepare change URI? */
+ assert (uri != NULL);
+
+ /* Perform the migration. The driver isn't supposed to return
+ * until the migration is complete.
+ */
+ if (domain->conn->driver->domainMigratePerform
+ (domain, cookie, cookielen, uri, flags, dname, bandwidth) == -1)
+ goto done;
+
+ /* Get the destination domain and return it or error.
+ * 'domain' no longer actually exists at this point
+ * (or so we hope), but we still use the object in memory
+ * in order to get the name.
+ */
+ dname = dname ? dname : domain->name;
+ if (dconn->driver->domainMigrateFinish)
+ ddomain = dconn->driver->domainMigrateFinish
+ (dconn, dname, cookie, cookielen, uri, flags);
+ else
+ ddomain = virDomainLookupByName (dconn, dname);
+
+ done:
+ VIR_FREE (uri_out);
+ VIR_FREE (cookie);
+ return ddomain;
+}
+
+static virDomainPtr
+virDomainMigrateVersion2 (virDomainPtr domain,
+ virConnectPtr dconn,
+ unsigned long flags,
+ const char *dname,
+ const char *uri,
+ unsigned long bandwidth)
+{
+ virDomainPtr ddomain = NULL;
+ char *uri_out = NULL;
+ char *cookie = NULL;
+ char *dom_xml = NULL;
+ int cookielen = 0, ret;
+
+ /* Prepare the migration.
+ *
+ * The destination host may return a cookie, or leave cookie as
+ * NULL.
+ *
+ * The destination host MUST set uri_out if uri_in is NULL.
+ *
+ * If uri_in is non-NULL, then the destination host may modify
+ * the URI by setting uri_out. If it does not wish to modify
+ * the URI, it should leave uri_out as NULL.
+ */
+
+ /* In version 2 of the protocol, the prepare step is slightly
+ * different. We fetch the domain XML of the source domain
+ * and pass it to Prepare2.
+ */
+ if (!domain->conn->driver->domainDumpXML) {
+ virLibConnError (domain->conn, VIR_ERR_INTERNAL_ERROR, __FUNCTION__);
+ return NULL;
+ }
+ dom_xml = domain->conn->driver->domainDumpXML (domain,
+ VIR_DOMAIN_XML_SECURE);
+ if (!dom_xml)
+ return NULL;
+
+ ret = dconn->driver->domainMigratePrepare2
+ (dconn, &cookie, &cookielen, uri, &uri_out, flags, dname,
+ bandwidth, dom_xml);
+ VIR_FREE (dom_xml);
+ if (ret == -1)
+ goto done;
+
+ if (uri == NULL && uri_out == NULL) {
+ virLibConnError (domain->conn, VIR_ERR_INTERNAL_ERROR,
+ _("domainMigratePrepare2 did not set uri"));
+ goto done;
+ }
+ if (uri_out)
+ uri = uri_out; /* Did domainMigratePrepare2 change URI? */
+ assert (uri != NULL);
+
+ /* Perform the migration. The driver isn't supposed to return
+ * until the migration is complete.
+ */
+ ret = domain->conn->driver->domainMigratePerform
+ (domain, cookie, cookielen, uri, flags, dname, bandwidth);
+ if (ret == -1)
+ goto done;
+
+ /* In version 2 of the migration protocol, we pass the
+ * status code from the sender to the destination host,
+ * so it can do any cleanup if the migration failed.
+ */
+ dname = dname ? dname : domain->name;
+ ddomain = dconn->driver->domainMigrateFinish2
+ (dconn, dname, cookie, cookielen, uri, flags, ret);
+
+ done:
+ VIR_FREE (uri_out);
+ VIR_FREE (cookie);
+ return ddomain;
+}
+
/**
* virDomainMigrate:
* @domain: a domain object
@@ -2930,140 +3070,52 @@ virDomainMigrate (virDomainPtr domain,
const char *uri,
unsigned long bandwidth)
{
- virConnectPtr conn;
virDomainPtr ddomain = NULL;
- char *uri_out = NULL;
- char *cookie = NULL;
- char *dom_xml = NULL;
- int cookielen = 0, ret, version = 0;
DEBUG("domain=%p, dconn=%p, flags=%lu, dname=%s, uri=%s, bandwidth=%lu",
domain, dconn, flags, NULLSTR(dname), NULLSTR(uri), bandwidth);
virResetLastError();
+ /* First checkout the source */
if (!VIR_IS_CONNECTED_DOMAIN (domain)) {
virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
return NULL;
}
- conn = domain->conn; /* Source connection. */
- if (!VIR_IS_CONNECT (dconn)) {
- virLibConnError (conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
+ if (domain->conn->flags & VIR_CONNECT_RO) {
+ virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
goto error;
}
- if (domain->conn->flags & VIR_CONNECT_RO) {
- virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
+ /* Now checkout the destination */
+ if (!VIR_IS_CONNECT (dconn)) {
+ virLibConnError (domain->conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
goto error;
}
if (dconn->flags & VIR_CONNECT_RO) {
- /* NB, delibrately report error against source object, not dest here */
- virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
+ /* NB, deliberately report error against source object, not dest */
+ virLibDomainError (domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
goto error;
}
/* Check that migration is supported by both drivers. */
- if (VIR_DRV_SUPPORTS_FEATURE (conn->driver, conn,
+ if (VIR_DRV_SUPPORTS_FEATURE (domain->conn->driver, domain->conn,
VIR_DRV_FEATURE_MIGRATION_V1) &&
VIR_DRV_SUPPORTS_FEATURE (dconn->driver, dconn,
VIR_DRV_FEATURE_MIGRATION_V1))
- version = 1;
- else if (VIR_DRV_SUPPORTS_FEATURE (conn->driver, conn,
+ ddomain = virDomainMigrateVersion1 (domain, dconn, flags, dname, uri, bandwidth);
+ else if (VIR_DRV_SUPPORTS_FEATURE (domain->conn->driver, domain->conn,
VIR_DRV_FEATURE_MIGRATION_V2) &&
VIR_DRV_SUPPORTS_FEATURE (dconn->driver, dconn,
VIR_DRV_FEATURE_MIGRATION_V2))
- version = 2;
+ ddomain = virDomainMigrateVersion2 (domain, dconn, flags, dname, uri, bandwidth);
else {
- virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
+ virLibConnError (domain->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
goto error;
}
- /* Prepare the migration.
- *
- * The destination host may return a cookie, or leave cookie as
- * NULL.
- *
- * The destination host MUST set uri_out if uri_in is NULL.
- *
- * If uri_in is non-NULL, then the destination host may modify
- * the URI by setting uri_out. If it does not wish to modify
- * the URI, it should leave uri_out as NULL.
- */
- if (version == 1) {
- ret = dconn->driver->domainMigratePrepare
- (dconn, &cookie, &cookielen, uri, &uri_out, flags, dname,
- bandwidth);
- if (ret == -1) goto done;
- if (uri == NULL && uri_out == NULL) {
- virLibConnError (conn, VIR_ERR_INTERNAL_ERROR,
- _("domainMigratePrepare did not set uri"));
- goto done;
- }
- if (uri_out) uri = uri_out; /* Did domainMigratePrepare change URI? */
-
- assert (uri != NULL);
- }
- else /* if (version == 2) */ {
- /* In version 2 of the protocol, the prepare step is slightly
- * different. We fetch the domain XML of the source domain
- * and pass it to Prepare2.
- */
- if (!conn->driver->domainDumpXML) {
- virLibConnError (conn, VIR_ERR_INTERNAL_ERROR, __FUNCTION__);
- goto error;
- }
- dom_xml = conn->driver->domainDumpXML (domain,
- VIR_DOMAIN_XML_SECURE);
-
- if (!dom_xml)
- goto error;
-
- ret = dconn->driver->domainMigratePrepare2
- (dconn, &cookie, &cookielen, uri, &uri_out, flags, dname,
- bandwidth, dom_xml);
- VIR_FREE (dom_xml);
- if (ret == -1) goto done;
- if (uri == NULL && uri_out == NULL) {
- virLibConnError (conn, VIR_ERR_INTERNAL_ERROR,
- _("domainMigratePrepare2 did not set uri"));
- goto done;
- }
- if (uri_out) uri = uri_out; /* Did domainMigratePrepare2 change URI? */
+ if (ddomain == NULL)
+ goto error;
- assert (uri != NULL);
- }
-
- /* Perform the migration. The driver isn't supposed to return
- * until the migration is complete.
- */
- ret = conn->driver->domainMigratePerform
- (domain, cookie, cookielen, uri, flags, dname, bandwidth);
-
- if (version == 1) {
- if (ret == -1) goto done;
- /* Get the destination domain and return it or error.
- * 'domain' no longer actually exists at this point
- * (or so we hope), but we still use the object in memory
- * in order to get the name.
- */
- dname = dname ? dname : domain->name;
- if (dconn->driver->domainMigrateFinish)
- ddomain = dconn->driver->domainMigrateFinish
- (dconn, dname, cookie, cookielen, uri, flags);
- else
- ddomain = virDomainLookupByName (dconn, dname);
- } else /* if (version == 2) */ {
- /* In version 2 of the migration protocol, we pass the
- * status code from the sender to the destination host,
- * so it can do any cleanup if the migration failed.
- */
- dname = dname ? dname : domain->name;
- ddomain = dconn->driver->domainMigrateFinish2
- (dconn, dname, cookie, cookielen, uri, flags, ret);
- }
-
- done:
- VIR_FREE (uri_out);
- VIR_FREE (cookie);
return ddomain;
error:
--
1.6.0.6
15 years, 8 months
[libvirt] [PATCH] Fix QEMU domain status after restore.
by Chris Lalancette
When doing a restore, we were forgetting to update the state file
for the VM. That means that if you do a save/restore, then shut
down libvirtd, then start it back up, you'll see the state of the
guest as "paused", even though it is really running. We were
just forgetting a "virDomainSaveStatus" call in the restor path.
Signed-off-by: Chris Lalancette <clalance(a)redhat.com>
---
src/qemu_driver.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index 1fb2417..d789c4d 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -4099,6 +4099,7 @@ static int qemudDomainRestore(virConnectPtr conn,
}
VIR_FREE(info);
vm->state = VIR_DOMAIN_RUNNING;
+ virDomainSaveStatus(conn, driver->stateDir, vm);
}
ret = 0;
--
1.6.0.6
15 years, 8 months
[libvirt] [PATCH] Run 'cont' on successful migration finish.
by Chris Lalancette
As of qemu 0.10.6, qemu now honors the -S flag on incoming migration.
That means that when the migration completes, we have to issue a
'cont' command to get the VM running again. We do it unconditionally
since it won't hurt on older qemu.
Signed-off-by: Chris Lalancette <clalance(a)redhat.com>
---
src/qemu_driver.c | 11 +++++++++++
1 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index bcacd41..1fb2417 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -6600,7 +6600,18 @@ qemudDomainMigrateFinish2 (virConnectPtr dconn,
*/
if (retcode == 0) {
dom = virGetDomain (dconn, vm->def->name, vm->def->uuid);
+
+ /* run 'cont' on the destination, which allows migration on qemu
+ * >= 0.10.6 to work properly. This isn't strictly necessary on
+ * older qemu's, but it also doesn't hurt anything there
+ */
+ if (qemudMonitorCommand(vm, "cont", &info) < 0) {
+ qemudReportError(dconn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ "%s", _("resume operation failed"));
+ goto cleanup;
+ }
VIR_FREE(info);
+
vm->state = VIR_DOMAIN_RUNNING;
event = virDomainEventNewFromObj(vm,
VIR_DOMAIN_EVENT_RESUMED,
--
1.6.0.6
15 years, 8 months
[libvirt] [PATCH] Fix up a stray whitespace in virHashGrow.
by Chris Lalancette
Signed-off-by: Chris Lalancette <clalance(a)redhat.com>
---
src/hash.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/hash.c b/src/hash.c
index bde3a0b..9308c0c 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -141,7 +141,7 @@ virHashGrow(virHashTablePtr table, int size)
}
table->size = size;
- /* If the two loops are merged, there would be situations where
+ /* If the two loops are merged, there would be situations where
* a new entry needs to allocated and data copied into it from
* the main table. So instead, we run through the array twice, first
* copying all the elements in the main array (where we can't get
--
1.6.0.6
15 years, 8 months
[libvirt] [PATCH] Fix up a whitespace in comments in src/console.c
by Chris Lalancette
Signed-off-by: Chris Lalancette <clalance(a)redhat.com>
---
src/console.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/console.c b/src/console.c
index badb62c..4a1a80b 100644
--- a/src/console.c
+++ b/src/console.c
@@ -78,7 +78,7 @@ int vshRunConsole(const char *tty) {
return -1;
}
- /* Put STDIN into raw mode so that stuff typed
+ /* Put STDIN into raw mode so that stuff typed
does not echo to the screen (the TTY reads will
result in it being echoed back already), and
also ensure Ctrl-C, etc is blocked, and misc
--
1.6.0.6
15 years, 8 months
[libvirt] [PATCH] Minor cleanup of error path for c_oneVmInfo.
by Chris Lalancette
Signed-off-by: Chris Lalancette <clalance(a)redhat.com>
---
src/opennebula/one_client.c | 16 ++++++----------
1 files changed, 6 insertions(+), 10 deletions(-)
diff --git a/src/opennebula/one_client.c b/src/opennebula/one_client.c
index d1641bf..21f303a 100644
--- a/src/opennebula/one_client.c
+++ b/src/opennebula/one_client.c
@@ -176,6 +176,7 @@ int c_oneVmInfo(int vmid, char* ret_info,int length)
xmlrpc_value *resultP;
int return_code;
char *return_string;
+ int retval = -1;
resultP = xmlrpc_client_call(&one_client.env, one_client.url,
"one.vmget_info", "(si)", one_client.session, vmid);
@@ -188,18 +189,13 @@ int c_oneVmInfo(int vmid, char* ret_info,int length)
strncpy(ret_info, return_string, length-1);
ret_info[length-1] = '\0';
- xmlrpc_DECREF(resultP);
- free(return_string);
-
- return 0;
+ retval = 0;
}
- else
- {
- xmlrpc_DECREF(resultP);
- free(return_string);
- return -1;
- }
+ xmlrpc_DECREF(resultP);
+ free(return_string);
+
+ return retval;
}
void c_oneFree()
--
1.6.0.6
15 years, 8 months
[libvirt] [PATCH] Make openvzGetVPSUUID take a len.
by Chris Lalancette
Minor fix to openvzGetVPSUUID to make it take a length parameter.
This ensures that it doesn't make assumptions about the length
of the UUID buffer, and paves the way for removal of strncpy in
the future.
Signed-off-by: Chris Lalancette <clalance(a)redhat.com>
---
src/openvz_conf.c | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/openvz_conf.c b/src/openvz_conf.c
index 6e9af67..a172fe3 100644
--- a/src/openvz_conf.c
+++ b/src/openvz_conf.c
@@ -54,7 +54,7 @@
#define VIR_FROM_THIS VIR_FROM_OPENVZ
static char *openvzLocateConfDir(void);
-static int openvzGetVPSUUID(int vpsid, char *uuidstr);
+static int openvzGetVPSUUID(int vpsid, char *uuidstr, size_t len);
static int openvzLocateConfFile(int vpsid, char *conffile, int maxlen, const char *ext);
static int openvzAssignUUIDs(void);
@@ -469,7 +469,7 @@ int openvzLoadDomains(struct openvz_driver *driver) {
if (virAsprintf(&dom->def->name, "%i", veid) < 0)
goto no_memory;
- openvzGetVPSUUID(veid, uuidstr);
+ openvzGetVPSUUID(veid, uuidstr, sizeof(uuidstr));
ret = virUUIDParse(uuidstr, dom->def->uuid);
if (ret == -1) {
@@ -805,7 +805,7 @@ openvz_readline(int fd, char *ptr, int maxlen)
}
static int
-openvzGetVPSUUID(int vpsid, char *uuidstr)
+openvzGetVPSUUID(int vpsid, char *uuidstr, size_t len)
{
char conf_file[PATH_MAX];
char line[1024];
@@ -832,7 +832,7 @@ openvzGetVPSUUID(int vpsid, char *uuidstr)
sscanf(line, "%s %s\n", iden, uuidbuf);
if(STREQ(iden, "#UUID:")) {
- strncpy(uuidstr, uuidbuf, VIR_UUID_STRING_BUFLEN);
+ strncpy(uuidstr, uuidbuf, len);
break;
}
}
@@ -856,7 +856,7 @@ openvzSetDefinedUUID(int vpsid, unsigned char *uuid)
if (openvzLocateConfFile(vpsid, conf_file, PATH_MAX, "conf")<0)
return -1;
- if (openvzGetVPSUUID(vpsid, uuidstr))
+ if (openvzGetVPSUUID(vpsid, uuidstr, sizeof(uuidstr)))
return -1;
if (uuidstr[0] == 0) {
--
1.6.0.6
15 years, 8 months
[libvirt] [PATCH] Fix phyp escape_specialcharacters.
by Chris Lalancette
A couple of minor fixes to phyp escape_specialcharacters. Make it
a static function (since it's only used in phyp/phyp_driver.c), and
make it take a dstlen parameter. This paves the way for removing
strncpy in the future.
Signed-off-by: Chris Lalancette <clalance(a)redhat.com>
---
src/phyp/phyp_driver.c | 10 ++++++----
src/phyp/phyp_driver.h | 2 --
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
index cbfd31b..f457cf4 100644
--- a/src/phyp/phyp_driver.c
+++ b/src/phyp/phyp_driver.c
@@ -53,6 +53,8 @@
#define VIR_FROM_THIS VIR_FROM_PHYP
+static int escape_specialcharacters(char *src, char *dst, size_t dstlen);
+
/*
* URI: phyp://user@[hmc|ivm]/managed_system
* */
@@ -94,7 +96,7 @@ phypOpen(virConnectPtr conn,
return VIR_DRV_OPEN_ERROR;
}
- if (escape_specialcharacters(conn->uri->path, string) == -1) {
+ if (escape_specialcharacters(conn->uri->path, string, sizeof(string)) == -1) {
virRaiseError(conn, NULL, NULL, 0, VIR_FROM_PHYP,
VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0, "%s",
_("Error parsing 'path'. Invalid characters."));
@@ -1341,8 +1343,8 @@ init_uuid_db(virConnectPtr conn)
return;
}
-int
-escape_specialcharacters(char *src, char *dst)
+static int
+escape_specialcharacters(char *src, char *dst, size_t dstlen)
{
size_t len = strlen(src);
char temp_buffer[len];
@@ -1367,7 +1369,7 @@ escape_specialcharacters(char *src, char *dst)
}
temp_buffer[j] = '\0';
- if (strncpy(dst, temp_buffer, j) == NULL)
+ if (strncpy(dst, temp_buffer, dstlen) == NULL)
return -1;
return 0;
diff --git a/src/phyp/phyp_driver.h b/src/phyp/phyp_driver.h
index fd824b3..f16b6fe 100644
--- a/src/phyp/phyp_driver.h
+++ b/src/phyp/phyp_driver.h
@@ -62,5 +62,3 @@ char *phypGetBackingDevice(virConnectPtr conn, const char *managed_system,
int phypDiskType(virConnectPtr conn, char *backing_device);
SSH_SESSION *openSSHSession(virConnectPtr conn, virConnectAuthPtr auth);
-
-int escape_specialcharacters(char *src, char *dst);
--
1.6.0.6
15 years, 8 months
[libvirt] [PATCH] Fix up a few minor indentation issues.
by Chris Lalancette
Signed-off-by: Chris Lalancette <clalance(a)redhat.com>
---
src/xen_internal.c | 8 ++++----
src/xend_internal.c | 2 +-
src/xm_internal.c | 2 +-
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/xen_internal.c b/src/xen_internal.c
index b6bf10d..ae78f84 100644
--- a/src/xen_internal.c
+++ b/src/xen_internal.c
@@ -1147,7 +1147,7 @@ static const char *str_cap = "cap";
*/
int
xenHypervisorGetSchedulerParameters(virDomainPtr domain,
- virSchedParameterPtr params, int *nparams)
+ virSchedParameterPtr params, int *nparams)
{
xenUnifiedPrivatePtr priv;
@@ -1209,19 +1209,19 @@ xenHypervisorGetSchedulerParameters(virDomainPtr domain,
return(-1);
strncpy (params[0].field, str_weight, VIR_DOMAIN_SCHED_FIELD_LENGTH);
- params[0].field[VIR_DOMAIN_SCHED_FIELD_LENGTH-1] = '\0';
+ params[0].field[VIR_DOMAIN_SCHED_FIELD_LENGTH-1] = '\0';
params[0].type = VIR_DOMAIN_SCHED_FIELD_UINT;
params[0].value.ui = op_dom.u.getschedinfo.u.credit.weight;
strncpy (params[1].field, str_cap, VIR_DOMAIN_SCHED_FIELD_LENGTH);
- params[1].field[VIR_DOMAIN_SCHED_FIELD_LENGTH-1] = '\0';
+ params[1].field[VIR_DOMAIN_SCHED_FIELD_LENGTH-1] = '\0';
params[1].type = VIR_DOMAIN_SCHED_FIELD_UINT;
params[1].value.ui = op_dom.u.getschedinfo.u.credit.cap;
*nparams = 2;
break;
default:
- virXenErrorFunc(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__,
+ virXenErrorFunc(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__,
"Unknown scheduler", op_sys.u.getschedulerid.sched_id);
return -1;
}
diff --git a/src/xend_internal.c b/src/xend_internal.c
index 2585703..7bcee7d 100644
--- a/src/xend_internal.c
+++ b/src/xend_internal.c
@@ -4732,7 +4732,7 @@ static const char *str_cap = "cap";
*/
static int
xenDaemonGetSchedulerParameters(virDomainPtr domain,
- virSchedParameterPtr params, int *nparams)
+ virSchedParameterPtr params, int *nparams)
{
xenUnifiedPrivatePtr priv;
struct sexpr *root;
diff --git a/src/xm_internal.c b/src/xm_internal.c
index c869120..b7f9e67 100644
--- a/src/xm_internal.c
+++ b/src/xm_internal.c
@@ -1418,7 +1418,7 @@ xenXMDomainConfigParse(virConnectPtr conn, virConfPtr conf) {
no_memory:
virReportOOMError(conn);
/* fallthrough */
- cleanup:
+cleanup:
virDomainGraphicsDefFree(graphics);
virDomainNetDefFree(net);
virDomainDiskDefFree(disk);
--
1.6.0.6
15 years, 8 months