[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 5/5] xc_save: simplify switch_qemu_logdirty() by use stack strings



Signed-off-by: Lai Jiangshan <laijs@xxxxxxxxxxxxxx>
---
 tools/xcutils/xc_save.c |   35 +++++++++++++----------------------
 1 files changed, 13 insertions(+), 22 deletions(-)

diff --git a/tools/xcutils/xc_save.c b/tools/xcutils/xc_save.c
index 1304433..521bbae 100644
--- a/tools/xcutils/xc_save.c
+++ b/tools/xcutils/xc_save.c
@@ -101,40 +101,33 @@ static int suspend(void* data)
  * the new active buffer.  xc_save can then process and clear the old
  * active buffer. */
 
-
 static int switch_qemu_logdirty(int domid, unsigned int enable, void *data)
 {
     struct xs_handle *xs;
-    char *path, *p, *ret_str, *cmd_str, **watch;
+    char *ret_str, *cmd_str, **watch;
     unsigned int len;
     struct timeval tv;
     fd_set fdset;
 
+#define PATH_FMT       "/local/domain/0/device-model/%d/logdirty/%s"
+#define PATH_LEN       (sizeof(PATH_FMT) + 10 + sizeof("cmd"))
+    char path_cmd[PATH_LEN], path_ret[PATH_LEN];
+
+    snprintf(path_cmd, PATH_LEN, PATH_FMT, domid, "cmd");
+    snprintf(path_ret, PATH_LEN, PATH_FMT, domid, "ret");
+
     if ((xs = xs_daemon_open()) == NULL)
         errx(1, "Couldn't contact xenstore");
-    if (!(path = strdup("/local/domain/0/device-model/")))
-        errx(1, "can't get domain path in store");
-    if (!(path = realloc(path, strlen(path) 
-                         + 10 
-                         + strlen("/logdirty/cmd") + 1)))
-        errx(1, "no memory for constructing xenstore path");
-    snprintf(path + strlen(path), 11, "%i", domid);
-    strcat(path, "/logdirty/");
-    p = path + strlen(path);
-
 
     /* Watch for qemu's return value */
-    strcpy(p, "ret");
-    if (!xs_watch(xs, path, "qemu-logdirty-ret"))
-        errx(1, "can't set watch in store (%s)\n", path);
+    if (!xs_watch(xs, path_ret, "qemu-logdirty-ret"))
+        errx(1, "can't set watch in store (%s)\n", path_ret);
 
     cmd_str = enable == 0 ? "disable" : "enable";
 
     /* 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)))
-        errx(1, "can't write  to store path (%s)\n",
-             path);
+    if (!xs_write(xs, XBT_NULL, path_cmd, cmd_str, strlen(cmd_str)))
+        errx(1, "can't write  to store path (%s)\n", path_cmd);
 
     /* Wait a while for qemu to signal that it has service logdirty command */
  read_again:
@@ -149,13 +142,11 @@ static int switch_qemu_logdirty(int domid, unsigned int 
enable, void *data)
     watch = xs_read_watch(xs, &len);
     free(watch);
 
-    strcpy(p, "ret");
-    ret_str = xs_read(xs, XBT_NULL, path, &len);
+    ret_str = xs_read(xs, XBT_NULL, path_ret, &len);
     if (ret_str == NULL || strcmp(ret_str, cmd_str))
         /* Watch fired but value is not yet right */
         goto read_again;
 
-    free(path);
     free(ret_str);
 
     return 0;
-- 
1.7.1


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.