# HG changeset patch
# User Heidi Eckhart <heidieck(a)linux.vnet.ibm.com>
# Date 1204720823 -3600
# Node ID e486d9c03b54fb4bf491f7d94e02845279bec775
# Parent eeb2c60ee909c70927f230735f8e1fc763d3eed3
Device: rename dom_device to enum_devices and make it configurable
Signed-off-by: Heidi Eckhart <heidieck(a)linux.vnet.ibm.com>
diff -r eeb2c60ee909 -r e486d9c03b54 src/Virt_Device.c
--- a/src/Virt_Device.c Wed Mar 05 10:46:19 2008 +0100
+++ b/src/Virt_Device.c Wed Mar 05 13:40:23 2008 +0100
@@ -282,83 +282,112 @@ uint16_t device_type_from_classname(cons
return VIRT_DEV_UNKNOWN;
}
-int dom_devices(const CMPIBroker *broker,
- virDomainPtr dom,
- const char *ns,
- int type,
- struct inst_list *list)
-{
+static CMPIStatus _get_devices(const CMPIBroker *broker,
+ const CMPIObjectPath *reference,
+ const virDomainPtr dom,
+ const uint16_t type,
+ struct inst_list *list)
+{
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+ struct virt_device *devs = NULL;
int count;
int i;
- struct virt_device *devs = NULL;
count = get_devices(dom, &devs, type);
if (count <= 0)
goto out;
-
+
for (i = 0; i < count; i++) {
CMPIInstance *dev = NULL;
-
- dev = device_instance(broker, &devs[i], dom, ns);
+
+ dev = device_instance(broker, &devs[i], dom, NAMESPACE(reference));
if (dev)
inst_list_add(list, dev);
-
+
cleanup_virt_device(&devs[i]);
}
out:
free(devs);
-
- return 1;
-}
-
-static int dom_list_devices(virConnectPtr conn,
- const CMPIObjectPath *ref,
- struct inst_list *list)
-{
- virDomainPtr *doms;
- int ndom;
+ return s;
+}
+
+static CMPIStatus _enum_devices(const CMPIBroker *broker,
+ const CMPIObjectPath *reference,
+ const virDomainPtr dom,
+ const uint16_t type,
+ struct inst_list *list)
+{
+ CMPIStatus s;
+
+ if (type == CIM_TYPE_ALL) {
+ s = _get_devices(broker, reference, dom, VIRT_DEV_VCPU, list);
+ s = _get_devices(broker, reference, dom, VIRT_DEV_MEM, list);
+ s = _get_devices(broker, reference, dom, VIRT_DEV_NET, list);
+ s = _get_devices(broker, reference, dom, VIRT_DEV_DISK, list);
+ }
+ else
+ s = _get_devices(broker, reference, dom, type, list);
+
+ return s;
+}
+
+CMPIStatus enum_devices(const CMPIBroker *broker,
+ const CMPIObjectPath *reference,
+ const char *domain,
+ const uint16_t type,
+ struct inst_list *list)
+{
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+ virConnectPtr conn = NULL;
+ virDomainPtr *doms = NULL;
+ int count = 1;
int i;
- int type;
-
- type = device_type_from_classname(CLASSNAME(ref));
-
- ndom = get_domain_list(conn, &doms);
- if (ndom == 0)
- return 1;
- else if (ndom < 0)
- return 0;
-
- for (i = 0; i < ndom; i++) {
- dom_devices(_BROKER, doms[i], NAMESPACE(ref), type, list);
- }
-
- return 1;
-}
-
-static CMPIStatus enum_devices(const CMPIObjectPath *reference,
- const CMPIResult *results,
- int names_only)
-{
- CMPIStatus s;
- virConnectPtr conn;
+
+ conn = connect_by_classname(broker, CLASSNAME(reference), &s);
+ if (conn == NULL)
+ goto out;
+
+ if (domain) {
+ doms = calloc(1, sizeof(virDomainPtr));
+ doms[0] = virDomainLookupByName(conn, domain);
+ }
+ else
+ count = get_domain_list(conn, &doms);
+
+
+ CU_DEBUG("added doms");
+
+ for (i = 0; i < count; i++) {
+ s = _enum_devices(broker, reference, doms[i], type, list);
+
+ virDomainFree(doms[i]);
+ }
+
+ out:
+ virConnectClose(conn);
+ free(doms);
+
+ return s;
+}
+
+static CMPIStatus return_enum_devices(const CMPIObjectPath *reference,
+ const CMPIResult *results,
+ int names_only)
+{
+ CMPIStatus s = {CMPI_RC_OK, NULL};
struct inst_list list;
if (!provider_is_responsible(_BROKER, reference, &s))
- return s;
+ goto out;
inst_list_init(&list);
- conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s);
- if (conn == NULL)
- return s;
-
- if (!dom_list_devices(conn, reference, &list)) {
- cu_statusf(_BROKER, &s,
- CMPI_RC_ERR_FAILED,
- "Failed to list domains");
- return s;
- }
+ s = enum_devices(_BROKER, reference, NULL,
+ device_type_from_classname(CLASSNAME(reference)),
+ &list);
+ if (s.rc != CMPI_RC_OK)
+ goto out;
if (list.cur == 0)
goto out;
@@ -371,11 +400,6 @@ static CMPIStatus enum_devices(const CMP
inst_list_free(&list);
out:
- cu_statusf(_BROKER, &s,
- CMPI_RC_OK,
- "");
- virConnectClose(conn);
-
return s;
}
@@ -524,7 +548,7 @@ static CMPIStatus EnumInstanceNames(CMPI
const CMPIResult *results,
const CMPIObjectPath *reference)
{
- return enum_devices(reference, results, 1);
+ return return_enum_devices(reference, results, true);
}
static CMPIStatus EnumInstances(CMPIInstanceMI *self,
@@ -533,7 +557,7 @@ static CMPIStatus EnumInstances(CMPIInst
const CMPIObjectPath *reference,
const char **properties)
{
- return enum_devices(reference, results, 0);
+ return return_enum_devices(reference, results, false);
}
static CMPIStatus GetInstance(CMPIInstanceMI *self,
diff -r eeb2c60ee909 -r e486d9c03b54 src/Virt_Device.h
--- a/src/Virt_Device.h Wed Mar 05 10:46:19 2008 +0100
+++ b/src/Virt_Device.h Wed Mar 05 13:40:23 2008 +0100
@@ -27,19 +27,18 @@
* Return a list of devices for a given domain
*
* @param broker A pointer to the CIM broker
- * @param dom The domain in question
- * @param ref The namespace
- * @param list A pointer to an array of CMPIInstance objects (should
- * be NULL initially)
- * @param cur The number of items in the list (0 initially)
- * @param max The size of the list (0 initially)
- * @returns Nonzero on success
+ * @param reference Defines the libvirt connection to use
+ * @param domain The domain id (NULL means for all domains)
+ * @param type The device type or CIM_TYPE_ALL to get
+ * all devices
+ * @param list A pointer to an array of CMPIInstance objects
+ * (should be NULL initially)
*/
-int dom_devices(const CMPIBroker *broker,
- virDomainPtr dom,
- const char *ns,
- int type,
- struct inst_list *list);
+CMPIStatus enum_devices(const CMPIBroker *broker,
+ const CMPIObjectPath *reference,
+ const char *domain,
+ const uint16_t type,
+ struct inst_list *list);
/**
* Returns the device instance defined by the reference