[PATCH] Xen proxy - adds getCapabilities call

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

 



Seems to me that it should be safe to allow non-root callers to use the getCapabilities call over the Xen proxy. This patch adds that feature.

Rich.

--
Emerging Technologies, Red Hat  http://et.redhat.com/~rjones/
64 Baker Street, London, W1U 7DF     Mobile: +44 7866 314 421

Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod
Street, Windsor, Berkshire, SL4 1TE, United Kingdom.
Registered in England and Wales under Company Registration No. 3798903
Directors: Michael Cunningham (USA), Charlie Peters (USA) and David
Owens (Ireland)
diff -urN --exclude=CVS --exclude=.git --exclude='*.pem' --exclude=demoCA --exclude=.gitignore --exclude='*.orig' --exclude='*.bak' libvirt-cvs/proxy/libvirt_proxy.c libvirt-open-noisy/proxy/libvirt_proxy.c
--- libvirt-cvs/proxy/libvirt_proxy.c	2007-04-04 15:39:43.000000000 +0100
+++ libvirt-open-noisy/proxy/libvirt_proxy.c	2007-04-30 12:19:18.000000000 +0100
@@ -587,6 +587,29 @@
 		req->len = sizeof(virProxyPacket) + sizeof(virNodeInfo);
 	    }
 	    break;
+
+	case VIR_PROXY_GET_CAPABILITIES:
+	    if (req->len != sizeof(virProxyPacket))
+	        goto comm_error;
+
+        xml = xenHypervisorGetCapabilities (conn);
+        if (!xml) {
+            req->data.arg = -1;
+            req->len = sizeof (virProxyPacket);
+        } else {
+            int xmllen = strlen (xml);
+            if (xmllen > (int) sizeof (request.extra.str)) {
+                req->data.arg = -2;
+                req->len = sizeof (virProxyPacket);
+            } else {
+                req->data.arg = 0;
+                memmove (request.extra.str, xml, xmllen);
+                req->len = sizeof (virProxyPacket) + xmllen;
+            }
+            free (xml);
+        }
+        break;
+
 	case VIR_PROXY_DOMAIN_XML:
 	    if (req->len != sizeof(virProxyPacket))
 	        goto comm_error;
diff -urN --exclude=CVS --exclude=.git --exclude='*.pem' --exclude=demoCA --exclude=.gitignore --exclude='*.orig' --exclude='*.bak' libvirt-cvs/src/proxy_internal.c libvirt-open-noisy/src/proxy_internal.c
--- libvirt-cvs/src/proxy_internal.c	2007-04-04 15:39:43.000000000 +0100
+++ libvirt-open-noisy/src/proxy_internal.c	2007-04-30 12:21:28.000000000 +0100
@@ -31,6 +31,7 @@
 static int xenProxyOpen(virConnectPtr conn, const char *name, int flags);
 static int xenProxyGetVersion(virConnectPtr conn, unsigned long *hvVer);
 static int xenProxyNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info);
+static char *xenProxyGetCapabilities(virConnectPtr conn);
 static int xenProxyListDomains(virConnectPtr conn, int *ids, int maxids);
 static int xenProxyNumOfDomains(virConnectPtr conn);
 static virDomainPtr xenProxyLookupByID(virConnectPtr conn, int id);
@@ -53,7 +54,7 @@
     xenProxyGetVersion, /* version */
     NULL, /* getMaxVcpus */
     xenProxyNodeGetInfo, /* nodeGetInfo */
-    NULL, /* getCapabilities */
+    xenProxyGetCapabilities, /* getCapabilities */
     xenProxyListDomains, /* listDomains */
     xenProxyNumOfDomains, /* numOfDomains */
     NULL, /* domainCreateLinux */
@@ -977,6 +976,55 @@
 }
 
 /**
+ * xenProxyGetCapabilities:
+ * @conn: pointer to the Xen Daemon block
+ * 
+ * Extract capabilities of the hypervisor.
+ *
+ * Returns capabilities in case of success (freed by caller)
+ * and NULL in case of failure.
+ */
+static char *
+xenProxyGetCapabilities (virConnectPtr conn)
+{
+    virProxyPacket req;
+    virProxyFullPacket ans;
+    int ret, xmllen;
+    char *xml;
+
+    if (!VIR_IS_CONNECT(conn)) {
+        virProxyError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
+        return NULL;
+    }
+    memset(&req, 0, sizeof(req));
+    req.command = VIR_PROXY_GET_CAPABILITIES;
+    req.data.arg = 0;
+    req.len = sizeof(req);
+    ret = xenProxyCommand(conn, &req, &ans, 0);
+    if (ret < 0) {
+        xenProxyClose(conn);
+        return NULL;
+    }
+    if (ans.data.arg == -1)
+        return NULL;
+    if (ans.len <= sizeof(virProxyPacket)) {
+        virProxyError(conn, VIR_ERR_OPERATION_FAILED, __FUNCTION__);
+        return NULL;
+    }
+
+    xmllen = ans.len - sizeof (virProxyPacket);
+    xml = malloc (xmllen+1);
+    if (!xml) {
+        virProxyError (conn, VIR_ERR_NO_MEMORY, __FUNCTION__);
+        return NULL;
+    }
+    memmove (xml, ans.extra.str, xmllen);
+    xml[xmllen] = '\0';
+
+    return xml;
+}
+
+/**
  * xenProxyDomainDumpXML:
  * @domain: a domain object
  * @flags: xml generation flags
diff -urN --exclude=CVS --exclude=.git --exclude='*.pem' --exclude=demoCA --exclude=.gitignore --exclude='*.orig' --exclude='*.bak' libvirt-cvs/src/proxy_internal.h libvirt-open-noisy/src/proxy_internal.h
--- libvirt-cvs/src/proxy_internal.h	2007-04-04 15:39:43.000000000 +0100
+++ libvirt-open-noisy/src/proxy_internal.h	2007-04-30 12:10:13.000000000 +0100
@@ -36,7 +36,8 @@
 	VIR_PROXY_MAX_MEMORY = 8,
 	VIR_PROXY_DOMAIN_INFO = 9,
 	VIR_PROXY_DOMAIN_XML = 10,
-	VIR_PROXY_DOMAIN_OSTYPE = 11
+	VIR_PROXY_DOMAIN_OSTYPE = 11,
+    VIR_PROXY_GET_CAPABILITIES = 12
 } virProxyCommand;
 
 /*

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]