From: Olaf Hering <olaf@aepfle.de>
To: xen-devel@lists.xen.org
Cc: Ian.Campbell@citrix.com
Subject: [PATCH 3 of 9] tools/xc: rework xc_save.c:switch_qemu_logdirty
Date: Thu, 28 Mar 2013 15:43:30 +0100 [thread overview]
Message-ID: <99d809a358d9748d9704.1364481810@probook.site> (raw)
In-Reply-To: <patchbomb.1364481807@probook.site>
# HG changeset patch
# User Olaf Hering <olaf@aepfle.de>
# Date 1364481337 -3600
# Node ID 99d809a358d9748d97044cc5721a028cffbcf5fe
# Parent 2b4e40439417fa09c3a6a49565a161c6dc4ddc15
tools/xc: rework xc_save.c:switch_qemu_logdirty
Rework code in switch_qemu_logdirty, fix also memleak.
v2:
- use DPRINTF to print watchpoint result
Signed-off-by: Olaf Hering <olaf@aepfle.de>
diff -r 2b4e40439417 -r 99d809a358d9 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);
+ DPRINTF("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;
}
next prev parent reply other threads:[~2013-03-28 14:43 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-28 14:43 [PATCH 0 of 9] set migrate constraints from cmdline, better xend.log logging Olaf Hering
2013-03-28 14:43 ` [PATCH 1 of 9] tools/xc: print messages from xc_save with xc_report Olaf Hering
2013-03-28 14:43 ` [PATCH 2 of 9] tools/xc: document printf calls in xc_restore Olaf Hering
2013-03-28 14:43 ` Olaf Hering [this message]
2013-04-08 17:12 ` [PATCH 3 of 9] tools/xc: rework xc_save.c:switch_qemu_logdirty Ian Jackson
2013-03-28 14:43 ` [PATCH 4 of 9] tools: set migration constraints from cmdline Olaf Hering
2013-04-08 17:16 ` Ian Jackson
2013-03-28 14:43 ` [PATCH 5 of 9] tools: add xm migrate --log_progress option Olaf Hering
2013-03-28 14:43 ` [PATCH 6 of 9] tools/xend: move assert to exception block Olaf Hering
2013-04-08 17:13 ` Ian Jackson
2013-03-28 14:43 ` [PATCH 7 of 9] tools/libxc: print stats if migration is aborted Olaf Hering
2013-03-28 14:43 ` [PATCH 8 of 9] tools: set number of dirty pages during migration Olaf Hering
2013-03-28 14:43 ` [PATCH 9 of 9] tools: notify restore to hangup during migration --abort_if_busy Olaf Hering
2013-04-08 17:14 ` Ian Jackson
2013-04-08 17:12 ` [PATCH 0 of 9] set migrate constraints from cmdline, better xend.log logging Ian Jackson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=99d809a358d9748d9704.1364481810@probook.site \
--to=olaf@aepfle.de \
--cc=Ian.Campbell@citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).