[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 3 of 5] tools/xc: rework xc_save.c:switch_qemu_logdirty
# HG changeset patch # User Olaf Hering <olaf@xxxxxxxxx> # Date 1362585910 -3600 # Node ID 1ea501d602649c58412f73e83e24115eb3d8fe44 # Parent 49b90990442aca9523acbf889cbb517ea44d20b4 tools/xc: rework xc_save.c:switch_qemu_logdirty Rework code in switch_qemu_logdirty, fix also memleak. Signed-off-by: Olaf Hering <olaf@xxxxxxxxx> diff -r 49b90990442a -r 1ea501d60264 tools/xcutils/xc_save.c --- a/tools/xcutils/xc_save.c +++ b/tools/xcutils/xc_save.c @@ -7,6 +7,7 @@ * */ +#define _GNU_SOURCE #include <unistd.h> #include <err.h> #include <stdlib.h> @@ -109,8 +110,10 @@ static int switch_qemu_logdirty(int domi { xc_interface *xch = si.xch; struct xs_handle *xs; - char *path, *p, *ret_str, *cmd_str, **watch; + char *path, *dir_p, *ret_str, **watch; + const char *cmd_str; unsigned int len; + int ret, again; struct timeval tv; fd_set fdset; @@ -118,65 +121,56 @@ static int switch_qemu_logdirty(int domi PERROR("Couldn't contact xenstore"); exit(1); } - if (!(path = strdup("/local/domain/0/device-model/"))) { - PERROR("can't get domain path in store"); + + ret = asprintf(&path, "/local/domain/0/device-model/%i/logdirty/ret", domid); + if (ret < 0) { + ERROR("Couldn't construct xenstore path"); exit(1); } - if (!(path = realloc(path, strlen(path) - + 10 - + strlen("/logdirty/cmd") + 1))) { - PERROR("no memory for constructing xenstore path"); - exit(1); - } - snprintf(path + strlen(path), 11, "%i", domid); - strcat(path, "/logdirty/"); - p = path + strlen(path); - + /* Pointer to directory */ + dir_p = path + ret - 3; /* Watch for qemu's return value */ - strcpy(p, "ret"); - if (!xs_watch(xs, path, "qemu-logdirty-ret")) - { - ERROR("can't set watch in store (%s)\n", path); + if (!xs_watch(xs, path, "qemu-logdirty-ret")) { + PERROR("can't set watch in store (%s)", path); exit(1); } - if (!(cmd_str = strdup( enable == 0 ? "disable" : "enable"))) { - PERROR("can't get logdirty cmd path in store"); + cmd_str = enable ? "enable" : "disable"; + + /* Tell qemu that we want it to start logging dirty pages to Xen */ + strcpy(dir_p, "cmd"); + if (!xs_write(xs, XBT_NULL, path, cmd_str, strlen(cmd_str))) { + PERROR("can't write to store path (%s)", path); exit(1); } - /* Tell qemu that we want it to start logging dirty page to Xen */ - strcpy(p, "cmd"); - if (!xs_write(xs, XBT_NULL, path, cmd_str, strlen(cmd_str))) { - PERROR("can't write to store path (%s)\n", path); - exit(1); - } + /* Restore initial path */ + strcpy(dir_p, "ret"); + /* Wait a while for qemu to signal that it has serviced logdirty command */ + do { + tv.tv_sec = 5; + tv.tv_usec = 0; + FD_ZERO(&fdset); + FD_SET(xs_fileno(xs), &fdset); + errno = 0; - /* Wait a while for qemu to signal that it has service logdirty command */ - read_again: - tv.tv_sec = 5; - tv.tv_usec = 0; - FD_ZERO(&fdset); - FD_SET(xs_fileno(xs), &fdset); - - if ((select(xs_fileno(xs) + 1, &fdset, NULL, NULL, &tv)) != 1) { - PERROR("timed out waiting for qemu logdirty response.\n"); - exit(1); - } - - watch = xs_read_watch(xs, &len); - free(watch); - - strcpy(p, "ret"); - ret_str = xs_read(xs, XBT_NULL, path, &len); - if (ret_str == NULL || strcmp(ret_str, cmd_str)) + if ((select(xs_fileno(xs) + 1, &fdset, NULL, NULL, &tv)) != 1) { + PERROR("timed out waiting for qemu logdirty response."); + exit(1); + } + + watch = xs_read_watch(xs, &len); + free(watch); + + ret_str = xs_read(xs, XBT_NULL, path, &len); + again = ret_str == NULL || strcmp(ret_str, cmd_str); + WPRINTF("Got '%s' from logdirty%s.\n", ret_str, again ? ", retrying" : ""); + free(ret_str); /* Watch fired but value is not yet right */ - goto read_again; + } while (again); free(path); - free(cmd_str); - free(ret_str); return 0; } _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |