[PATCH 0 of 3] Add configurable enum_devices() to Device provider and Adopt interface changes to SD & EAFP

This patch set implements the configurable enum_devices() interface to the Device provider. This slight interface change is adopted to the associations SystemDevice and ElementAllocatedFromPool. Both associations profit from the easy access to the device instances.

# HG changeset patch # User Heidi Eckhart <heidieck@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@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

HE> +static CMPIStatus _get_devices(const CMPIBroker *broker, HE> + const CMPIObjectPath *reference, HE> + const virDomainPtr dom, HE> + const uint16_t type, HE> + struct inst_list *list) HE> +{ HE> + CMPIStatus s = {CMPI_RC_OK, NULL}; HE> + struct virt_device *devs = NULL; HE> int count; HE> int i; HE> - struct virt_device *devs = NULL; Please don't rearrange lines as part of a patch that does more than just cleanups. HE> count = get_devices(dom, &devs, type); HE> if (count <= 0) HE> goto out; HE> - HE> + You're adding leading whitespace here. HE> for (i = 0; i < count; i++) { HE> CMPIInstance *dev = NULL; HE> - HE> - dev = device_instance(broker, &devs[i], dom, ns); HE> + HE> + dev = device_instance(broker, &devs[i], dom, NAMESPACE(reference)); HE> if (dev) HE> inst_list_add(list, dev); HE> - HE> + ...and here. -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms@us.ibm.com

Dan Smith wrote:
Please don't rearrange lines as part of a patch that does more than just cleanups.
...
You're adding leading whitespace here.
Thanks. I will fix this. -- Regards Heidi Eckhart Software Engineer IBM Linux Technology Center - Open Hypervisor

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1204720826 -3600 # Node ID d7dd02fed84faa2d851640208da564c4593c8ddb # Parent e486d9c03b54fb4bf491f7d94e02845279bec775 SD: adopt Device interface changes Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r e486d9c03b54 -r d7dd02fed84f src/Virt_SystemDevice.c --- a/src/Virt_SystemDevice.c Wed Mar 05 13:40:23 2008 +0100 +++ b/src/Virt_SystemDevice.c Wed Mar 05 13:40:26 2008 +0100 @@ -48,55 +48,6 @@ const static CMPIBroker *_BROKER; -#define DEV_TYPE_COUNT 4 -const static int device_types[DEV_TYPE_COUNT] = - {VIRT_DEV_NET, - VIRT_DEV_DISK, - VIRT_DEV_MEM, - VIRT_DEV_VCPU, - }; - -static int get_dom_devices(const char *name, - struct inst_list *list, - int type, - const char *host_cn, - const char *ns) -{ - virConnectPtr conn = NULL; - virDomainPtr dom = NULL; - CMPIStatus s; - int ret = 0; - - conn = connect_by_classname(_BROKER, host_cn, &s); - if (conn == NULL) - goto out; - - dom = virDomainLookupByName(conn, name); - if (dom == NULL) - goto out; - - ret = dom_devices(_BROKER, dom, ns, type, list); - - virDomainFree(dom); - out: - virConnectClose(conn); - - return ret; -} - -static int get_all_devices(const char *name, - struct inst_list *list, - const char *host_cn, - const char *ns) -{ - int i; - - for (i = 0; i < DEV_TYPE_COUNT; i++) - get_dom_devices(name, list, device_types[i], host_cn, ns); - - return i; -} - static CMPIStatus sys_to_dev(const CMPIObjectPath *ref, struct std_assoc_info *info, struct inst_list *list) @@ -104,7 +55,6 @@ static CMPIStatus sys_to_dev(const CMPIO const char *host = NULL; CMPIStatus s = {CMPI_RC_OK, NULL}; CMPIInstance *inst = NULL; - int ret; if (!match_hypervisor_prefix(ref, info)) return s; @@ -120,20 +70,7 @@ static CMPIStatus sys_to_dev(const CMPIO goto out; } - ret = get_all_devices(host, - list, - CLASSNAME(ref), - NAMESPACE(ref)); - - if (ret >= 0) { - cu_statusf(_BROKER, &s, - CMPI_RC_OK, - ""); - } else { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "Unable to get devices"); - } + s = enum_devices(_BROKER, ref, host, CIM_TYPE_ALL, list); out: return s;

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1204720826 -3600 # Node ID 65b9a1e504faa04a13cc8900a7d5258592497acc # Parent d7dd02fed84faa2d851640208da564c4593c8ddb EAFP: adopt Device interface changes Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r d7dd02fed84f -r 65b9a1e504fa src/Virt_ElementAllocatedFromPool.c --- a/src/Virt_ElementAllocatedFromPool.c Wed Mar 05 13:40:26 2008 +0100 +++ b/src/Virt_ElementAllocatedFromPool.c Wed Mar 05 13:40:26 2008 +0100 @@ -77,7 +77,7 @@ static CMPIStatus vdev_to_pool(const CMP goto out; type = class_to_type(ref); - if (type == 0) { + if (type == CIM_RES_TYPE_UNKNOWN) { cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, "Unknown device type"); @@ -138,47 +138,6 @@ static int filter_by_pool(struct inst_li return dest->cur; } -static int devs_from_pool(uint16_t type, - const CMPIObjectPath *ref, - const char *poolid, - struct inst_list *list) -{ - CMPIStatus s; - virConnectPtr conn = NULL; - virDomainPtr *doms = NULL; - int count; - int i; - const char *ns = NAMESPACE(ref); - const char *cn = CLASSNAME(ref); - - conn = connect_by_classname(_BROKER, cn, &s); - if (conn == NULL) - return 0; - - count = get_domain_list(conn, &doms); - - for (i = 0; i < count; i++) { - const char *name; - struct inst_list tmp; - - inst_list_init(&tmp); - - name = virDomainGetName(doms[i]); - - dom_devices(_BROKER, doms[i], ns, type, &tmp); - - filter_by_pool(list, &tmp, type, poolid); - - inst_list_free(&tmp); - virDomainFree(doms[i]); - } - - free(doms); - virConnectClose(conn); - - return count; -} - static CMPIStatus pool_to_vdev(const CMPIObjectPath *ref, struct std_assoc_info *info, struct inst_list *list) @@ -186,7 +145,8 @@ static CMPIStatus pool_to_vdev(const CMP const char *poolid; CMPIStatus s = {CMPI_RC_OK, NULL}; uint16_t type; - CMPIInstance *inst; + CMPIInstance *inst = NULL; + struct inst_list tmp; if (!match_hypervisor_prefix(ref, info)) return s; @@ -210,7 +170,15 @@ static CMPIStatus pool_to_vdev(const CMP goto out; } - devs_from_pool(type, ref, poolid, list); + inst_list_init(&tmp); + + s = enum_devices(_BROKER, ref, NULL, type, &tmp); + if (s.rc != CMPI_RC_OK) + goto out; + + filter_by_pool(list, &tmp, type, poolid); + + inst_list_free(&tmp); out: return s;
participants (2)
-
Dan Smith
-
Heidi Eckhart