]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
* src/libvir.c src/xen_internal.c src/xen_internal.h: completing the
authorDaniel Veillard <veillard@redhat.com>
Mon, 12 Dec 2005 13:22:20 +0000 (13:22 +0000)
committerDaniel Veillard <veillard@redhat.com>
Mon, 12 Dec 2005 13:22:20 +0000 (13:22 +0000)
  API implementation, only CreateLinux is now missing.
Daniel

ChangeLog
docs/index.html
src/libvir.c
src/xen_internal.c
src/xen_internal.h

index 98cc9acd9b95df60dddb12352c4834b46fd121cf..14f2f110424faae28596d1400aabc828178cf7f2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Mon Dec 12 14:21:18 CET 2005 Daniel Veillard <veillard@redhat.com>
+
+       * src/libvir.c src/xen_internal.c src/xen_internal.h: completing the
+         API implementation, only CreateLinux is now missing.
+
 Fri Dec  9 15:39:18 CET 2005 Daniel Veillard <veillard@redhat.com>
 
        * docs/search.php docs/index.py docs/*.xsl docs/html/*: fixed the
index 8818947946bc7bd9c605800c5523b70e8910cd7e..98229362f732bfbeb4d3cf28b6f31c5b91b70ff1 100644 (file)
@@ -1,8 +1,7 @@
 <?xml version="1.0" encoding="ISO-8859-1"?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
-  <head>
-    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
+  <head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
     <link rel="SHORTCUT ICON" href="/favicon.ico" />
     <style type="text/css">
 TD {font-family: Verdana,Arial,Helvetica}
index a2c9fabfa3432e01a876f6e12827afa5795ca563..4a8c97bdad1aa7d1a4e15ace2bf2745e7d799f50 100644 (file)
@@ -194,6 +194,30 @@ failed:
     return(NULL);
 }
 
+/**
+ * virConnectCheckStoreID:
+ * @conn: pointer to the hypervisor connection
+ * @id: the id number as returned from Xenstore
+ *
+ * the xenstore sometimes list non-running domains, double check
+ * from the hypervisor if we have direct access
+ *
+ * Returns -1 if the check failed, 0 if successful or not possible to check
+ */
+static int
+virConnectCheckStoreID(virConnectPtr conn, int id) {
+    if (conn->handle >= 0) {
+       dom0_getdomaininfo_t dominfo;
+       int tmp;
+
+       dominfo.domain = id;
+       tmp = xenHypervisorGetDomainInfo(conn->handle, id, &dominfo);
+       if (tmp < 0)
+           return(-1);
+    }
+    return(0);
+}
+
 /**
  * virDomainFreeName:
  * @domain: a domain object
@@ -317,6 +341,9 @@ virConnectListDomains(virConnectPtr conn, int *ids, int maxids) {
            ret = -1;
            goto done;
        }
+
+       if (virConnectCheckStoreID(conn, (int) id) < 0)
+           continue;
        ids[ret++] = (int) id;
     }
 
@@ -385,23 +412,6 @@ virDomainCreateLinux(virConnectPtr conn, const char *kernel_path,
     return(NULL);
 }
 
-/**
- * virDomainLookupByName:
- * @conn: pointer to the hypervisor connection
- * @name: name for the domain
- *
- * Try to lookup a domain on the given hypervisor
- *
- * Returns a new domain object or NULL in case of failure
- */
-virDomainPtr
-virDomainLookupByName(virConnectPtr conn, const char *name) {
-    if ((conn == NULL) || (conn->magic != VIR_CONNECT_MAGIC) || (name == NULL))
-        return(NULL);
-    TODO
-    return(NULL);
-}
-
 #if 0
 /* Not used ATM */
 /**
@@ -525,6 +535,74 @@ virDomainLookupByID(virConnectPtr conn, int id) {
     return(ret);
 }
 
+/**
+ * virDomainLookupByName:
+ * @conn: pointer to the hypervisor connection
+ * @name: name for the domain
+ *
+ * Try to lookup a domain on the given hypervisor
+ *
+ * Returns a new domain object or NULL in case of failure
+ */
+virDomainPtr
+virDomainLookupByName(virConnectPtr conn, const char *name) {
+    struct xs_transaction_handle* t;
+    virDomainPtr ret = NULL;
+    unsigned int num, i, len;
+    long id;
+    char **idlist = NULL, *endptr;
+    char prop[200], *tmp;
+    int found = 0;
+
+
+    if ((conn == NULL) || (conn->magic != VIR_CONNECT_MAGIC) || (name == NULL))
+        return(NULL);
+
+    t = xs_transaction_start(conn->xshandle);
+    if (t == NULL)
+        goto done;
+
+    idlist = xs_directory(conn->xshandle, t, "/local/domain", &num);
+    if (idlist == NULL)
+        goto done;
+
+    for (i = 0;i < num;i++) {
+        id = strtol(idlist[i], &endptr, 10);
+       if ((endptr == idlist[i]) || (*endptr != 0)) {
+           goto done;
+       }
+       if (virConnectCheckStoreID(conn, (int) id) < 0)
+           continue;
+        snprintf(prop, 199, "/local/domain/%s/name", idlist[i]);
+       prop[199] = 0;
+       tmp = xs_read(conn->xshandle, t, prop, &len);
+       if (tmp != NULL) {
+           found = !strcmp(name, tmp);
+           free(tmp);
+           if (found)
+               break;
+       }
+    }
+    if (found) {
+       ret = (virDomainPtr) malloc(sizeof(virDomain));
+       if (ret == NULL)
+           goto done;
+       ret->magic = VIR_DOMAIN_MAGIC;
+       ret->conn = conn;
+       ret->handle = id;
+       ret->path = xs_get_domain_path(conn->xshandle, (unsigned int) id);
+       ret->name = strdup(name);
+    }
+
+done:
+    if (t != NULL)
+       xs_transaction_end(conn->xshandle, t, 0);
+    if (idlist != NULL)
+        free(idlist);
+
+    return(ret);
+}
+
 /**
  * virDomainDestroy:
  * @domain: a domain object
@@ -655,10 +733,29 @@ virDomainGetID(virDomainPtr domain) {
  */
 unsigned long
 virDomainGetMaxMemory(virDomainPtr domain) {
+    unsigned long ret = 0;
+
     if ((domain == NULL) || (domain->magic != VIR_DOMAIN_MAGIC))
         return(0);
-    TODO
-    return(0);
+    if (domain->conn->flags & VIR_CONNECT_RO) {
+        char *tmp;
+
+       tmp = virDomainDoStoreQuery(domain, "memory/target");
+       if (tmp != NULL) {
+           ret = (unsigned long) atol(tmp);
+           free(tmp);
+       }
+    } else {
+        dom0_getdomaininfo_t dominfo;
+       int tmp;
+
+       dominfo.domain = domain->handle;
+        tmp = xenHypervisorGetDomainInfo(domain->conn->handle, domain->handle,
+                                        &dominfo);
+       if (tmp >= 0)
+           ret = dominfo.max_pages * 4;
+    }
+    return(ret);
 }
 
 /**
@@ -674,11 +771,38 @@ virDomainGetMaxMemory(virDomainPtr domain) {
  */
 int
 virDomainSetMaxMemory(virDomainPtr domain, unsigned long memory) {
+    int ret;
+    char s[256], v[30];
+    struct xs_transaction_handle* t;
+    
     if ((domain == NULL) || (domain->magic != VIR_DOMAIN_MAGIC) ||
         (memory < 4096))
         return(-1);
-    TODO
-    return(-1);
+    if (domain->conn->flags & VIR_CONNECT_RO)
+        return(-1);
+    ret = xenHypervisorSetMaxMemory(domain->conn->handle, domain->handle,
+                                    memory);
+    if (ret < 0)
+        return(-1);
+
+    /*
+     * try to update at the Xenstore level too
+     * Failing to do so should not be considered fatal though as long
+     * as the hypervisor call succeeded
+     */
+    snprintf(s, 255, "/local/domain/%d/memory/target", domain->handle);
+    s[255] = 0;
+    snprintf(v, 29, "%lu", memory);
+    v[30] = 0;
+
+    t = xs_transaction_start(domain->conn->xshandle);
+    if (t == NULL)
+        return(0);
+
+    xs_write(domain->conn->xshandle, t, &s[0], &v[0], strlen(v));
+    xs_transaction_end(domain->conn->xshandle, t, 0);
+
+    return(ret);
 }
 
 /**
index 2d085963fadcbf6f7e9595da3a0c7ecff0eb6369..67260b20540c09de6ba301923c261bd926fd3f1a 100644 (file)
@@ -249,3 +249,28 @@ xenHypervisorDestroyDomain(int handle, int domain) {
     return(0);
 }
 
+/**
+ * xenHypervisorSetMaxMemory:
+ * @handle: the handle to the Xen hypervisor
+ * @domain: the domain ID
+ * @memory: the max memory size in kilobytes.
+ *
+ * Do an hypervisor call to change the maximum amount of memory used
+ *
+ * Returns 0 in case of success, -1 in case of error.
+ */
+int
+xenHypervisorSetMaxMemory(int handle, int domain, unsigned long memory) {
+    dom0_op_t op;
+    int ret;
+
+    op.cmd = DOM0_SETDOMAINMAXMEM;
+    op.u.setdomainmaxmem.domain = (domid_t) domain;
+    op.u.setdomainmaxmem.max_memkb = memory;
+
+    ret = xenHypervisorDoOp(handle, &op);
+
+    if (ret < 0)
+        return(-1);
+    return(0);
+}
index 2d04e9e4ce443a305ba7fc9c63da5482c56d404d..eb048143745e00b275eb6ea6c1e2f673cc35e33d 100644 (file)
@@ -32,6 +32,9 @@ int           xenHypervisorPauseDomain        (int handle,
 int            xenHypervisorGetDomainInfo      (int handle,
                                                 int domain,
                                                 dom0_getdomaininfo_t *info);
+int            xenHypervisorSetMaxMemory       (int handle,
+                                                int domain,
+                                                unsigned long memory);
 
 #ifdef __cplusplus
 }