
+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_RES_TYPE_ALL) { + s = _get_devices(broker, + reference, + dom, + CIM_RES_TYPE_PROC, + list); + s = _get_devices(broker, + reference, + dom, + CIM_RES_TYPE_MEM, + list); + s = _get_devices(broker, + reference, + dom, + CIM_RES_TYPE_NET, + list); + s = _get_devices(broker, + reference, + dom, + CIM_RES_TYPE_DISK, + list); + }
Would it be better to have a list of all the resource types, and then call _get_devices() in a loop? This is probably fine as is, and I don't suspect we'll add more resource types in the future, so it's probably not worth worrying about. Thoughts?
+ +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;
Should inst_list_free(&list); go after the out:? Even if list.cur == 0, we still probably want to set list->list = NULL to be sure. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com