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

[Xen-changelog] [qemu-xen-unstable] add per domain low level xenstore functions [PATCH 2/3]



commit ad202d4194eab87d3645f13e7726a4d609e42fe8
Author: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Date:   Tue Jul 21 15:29:43 2009 +0100

    add per domain low level xenstore functions [PATCH 2/3]
    
    add per domain low level xenstore functions (read/chmod/write/watch).
    
    This is a series of patch to complete the xenstore interface in qemu.
    
    1: create a callback mecanism for xenstore watches.
    2: add per domain low level xenstore functions (read/chmod/write/watch).
    3: add low level functions from the root (read/write).
    
    Signed-off-by: Jean Guyader <jean.guyader@xxxxxxxxxx>
---
 qemu-xen.h |    5 +++
 xenstore.c |  100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 105 insertions(+), 0 deletions(-)

diff --git a/qemu-xen.h b/qemu-xen.h
index 09d0539..5e30c61 100644
--- a/qemu-xen.h
+++ b/qemu-xen.h
@@ -96,6 +96,11 @@ int xenstore_unsubscribe_from_hotplug_status(struct 
xs_handle *handle,
 typedef void (*xenstore_callback) (const char *path, void *opaque);
 int xenstore_watch_new_callback(const char *path, xenstore_callback fptr, void 
*opaque);
 
+char *xenstore_dom_read(int domid, const char *key, unsigned int *len);
+int xenstore_dom_write(int domid, const char *key, const char *value);
+void xenstore_dom_watch(int domid, const char *key, xenstore_callback ftp, 
void *opaque);
+void xenstore_dom_chmod(int domid, const char *key, const char *perms);
+
  /* `danger' means that this parameter, variable or function refers to
   * an area of xenstore which is writeable by the guest and thus must
   * not be trusted by qemu code.  For variables containing xenstore
diff --git a/xenstore.c b/xenstore.c
index df5d940..1ad6dc9 100644
--- a/xenstore.c
+++ b/xenstore.c
@@ -1462,3 +1462,103 @@ 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_dom_read(int domid, const char *key, unsigned int *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;
+}
+
+void xenstore_dom_watch(int domid, const char *key, xenstore_callback fptr, 
void *opaque)
+{
+    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);
+    xenstore_watch_new_callback(buf, fptr, opaque);
+
+ out:
+    free(path);
+    free(buf);
+}
+
+void xenstore_dom_chmod(int domid, const char *key, const char *perms)
+{
+    char *buf = NULL, *path = NULL;
+    int rc = -1;
+       struct xs_permissions p;
+
+    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);
+
+       xs_strings_to_perms(&p, 1, perms);
+       xs_set_permissions(xsh, XBT_NULL, buf, &p, 1);
+
+ out:
+    free(path);
+    free(buf);
+}
+
+int xenstore_dom_write(int domid, const char *key, const 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;
+}
--
generated by git-patchbot for /home/xen/git/qemu-xen-unstable.git

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

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