]> xenbits.xensource.com Git - xenclient/ioemu.git/commitdiff
- Add some useful function to write into xenstore.
authorJean Guyader <jean.guyader@eu.citrix.com>
Thu, 9 Oct 2008 16:53:57 +0000 (17:53 +0100)
committerVincent Hanquez <vincent@snarc.org>
Fri, 31 Oct 2008 12:10:55 +0000 (12:10 +0000)
xenstore.c

index d064df100fc16da914c397721bb96cce8d4a4f1d..9b7e59eec671c01778fdc3eeccb80243a77bc118 100644 (file)
@@ -71,7 +71,6 @@ static void insert_media(void *opaque)
 
 void xenstore_check_new_media_present(int timeout)
 {
-
     if (insert_timer == NULL)
         insert_timer = qemu_new_timer(rt_clock, insert_media, NULL);
     qemu_mod_timer(insert_timer, qemu_get_clock(rt_clock) + timeout);
@@ -1310,6 +1309,8 @@ static int store_dev_info(const char *devName, int domid,
 #endif
 }
 
+
+
 void xenstore_store_serial_port_info(int i, CharDriverState *chr,
                                     const char *devname) {
     char buf[16];
@@ -1319,3 +1320,105 @@ void xenstore_store_serial_port_info(int i, CharDriverState *chr,
     if (i == 0) /* serial 0 is also called the console */
         store_dev_info(devname, domid, chr, "/console");
 }
+
+char *xenstore_read_dom0_driver(const char *key)
+{
+    const char *path = "/local/domain/0/dom0_driver";
+    char *buf = NULL;
+    int len = 0;
+    char *val = NULL;
+    
+    if (pasprintf(&buf, "%s/%s", path, key) == -1)
+        return NULL;
+    val = xs_read(xsh, XBT_NULL, buf, &len);
+    free(buf);
+    return val;
+}
+
+int xenstore_write_dom0_driver(const char *key, int val)
+{
+    const char *path = "/local/domain/0/dom0_driver";
+    char *buf = NULL;
+    int len = 0;
+    char str[10];
+    int ret = 0;
+    
+    if (pasprintf(&buf, "%s/%s", path, key) == -1)
+        return 0;
+    sprintf(str, "%d", val);
+    ret = xs_write(xsh, XBT_NULL, buf, str, strlen(str));
+    free(buf);
+    return ret;
+}
+
+char *xenstore_dom_read(int domid, char *key, unsigned long *len)
+{
+    char *buf = NULL, *path = NULL, *value = NULL;
+
+    if (xsh == NULL)
+        goto out;
+
+    path = xs_get_domain_path(xsh, domid);
+    if (path == NULL) {
+        fprintf(logfile, "xs_get_domain_path(%d): error\n", domid);
+        goto out;
+    }
+
+    pasprintf(&buf, "%s/%s", path, key);
+    value = xs_read(xsh, XBT_NULL, buf, len);
+    if (value == NULL) {
+        fprintf(logfile, "xs_read(%s): read error\n", buf);
+        goto out;
+    }
+
+ out:
+    free(path);
+    free(buf);
+    return value;
+}
+
+int xenstore_dom_write(int domid, char *key, char *value)
+{
+    char *buf = NULL, *path = NULL;
+    int rc = -1;
+
+    if (xsh == NULL)
+        goto out;
+
+    path = xs_get_domain_path(xsh, domid);
+    if (path == NULL) {
+        fprintf(logfile, "xs_get_domain_path: error\n");
+        goto out;
+    }
+
+    pasprintf(&buf, "%s/%s", path, key);
+    rc = xs_write(xsh, XBT_NULL, buf, value, strlen(value));
+    if (rc == 0) {
+        fprintf(logfile, "xs_write(%s, %s): write error\n", buf, key);
+        goto out;
+    }
+
+ out:
+    free(path);
+    free(buf);
+    return rc;
+}
+
+
+int *xenstore_get_domids(int *len)
+{
+    int *tab = NULL;
+    char **e;
+
+    e = xs_directory(xsh, XBT_NULL, "/local/domain", len);
+    if (e == NULL)
+    {
+        len = 0;
+        return NULL;
+    }
+
+    tab = malloc(*len * sizeof (int));
+    for (int i = 0; i < *len; i++)
+        tab[i] = strtol(e[i], NULL, 10);
+    return tab;
+}