[PATCH 0 of 3] Add get_device_by_name/ref to Device provider and Adopt interfaces in SDS and SD

Add functions get_device_by_ref and get_device_by_name to Device provider. Adopt these two interfaces in SD and SDS assoc providers.

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1204029552 -3600 # Node ID c9ac31ec5a89cd5b2d165c34d218412cbbb6c47d # Parent 8ce1fe84f5831b7f3e32832901845a749a429c78 Device: implement get_dev_by_ref and get_dev_by_name for usage in assocs Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r 8ce1fe84f583 -r c9ac31ec5a89 src/Virt_Device.c --- a/src/Virt_Device.c Tue Feb 26 10:08:24 2008 +0100 +++ b/src/Virt_Device.c Tue Feb 26 13:39:12 2008 +0100 @@ -268,7 +268,7 @@ static CMPIInstance *device_instance(con return instance; } -int device_type_from_classname(const char *classname) +uint16_t device_type_from_classname(const char *classname) { if (strstr(classname, "NetworkPort")) return VIRT_DEV_NET; @@ -419,79 +419,96 @@ static struct virt_device *find_dom_dev( return dev; } -CMPIInstance *instance_from_devid(const CMPIBroker *broker, - virConnectPtr conn, - const char *devid, - const char *ns, - int type) -{ +CMPIStatus get_device_by_name(const CMPIBroker *broker, + const CMPIObjectPath *reference, + const char *name, + const uint16_t type, + CMPIInstance **_inst) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; char *domain = NULL; char *device = NULL; CMPIInstance *instance = NULL; + virConnectPtr conn = NULL; virDomainPtr dom = NULL; struct virt_device *dev = NULL; - if (!parse_devid(devid, &domain, &device)) - return NULL; - - dom = virDomainLookupByName(conn, domain); - if (!dom) - goto out; - - dev = find_dom_dev(dom, device, type); - if (!dev) - goto out; - - instance = device_instance(broker, dev, dom, ns); - cleanup_virt_device(dev); - - out: - virDomainFree(dom); - free(domain); - free(device); - - return instance; -} - -CMPIStatus get_device(const CMPIBroker *broker, - const CMPIObjectPath *reference, - CMPIInstance **_inst) -{ - CMPIStatus s = {CMPI_RC_OK, NULL}; - virConnectPtr conn; - CMPIInstance *inst; - const char *cn; - const char *devid; - - cn = CLASSNAME(reference); - - conn = connect_by_classname(broker, cn, &s); + conn = connect_by_classname(broker, CLASSNAME(reference), &s); if (conn == NULL) { cu_statusf(broker, &s, CMPI_RC_ERR_NOT_FOUND, "No such instance"); goto out; - } - - if (cu_get_str_path(reference, "DeviceID", &devid) != CMPI_RC_OK) { + } + + if (parse_devid(name, &domain, &device) != 1) { + cu_statusf(broker, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance (%s)", + name); + goto out; + } + + dom = virDomainLookupByName(conn, domain); + if (dom == NULL) { + cu_statusf(broker, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance (%s)", + name); + goto err; + } + + dev = find_dom_dev(dom, device, type); + if (!dev) { + cu_statusf(broker, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance (%s)", + name); + goto err; + } + + instance = device_instance(broker, + dev, + dom, + NAMESPACE(reference)); + cleanup_virt_device(dev); + + *_inst = instance; + + err: + virDomainFree(dom); + free(domain); + free(device); + + out: + virConnectClose(conn); + + return s; +} + +CMPIStatus get_device_by_ref(const CMPIBroker *broker, + const CMPIObjectPath *reference, + CMPIInstance **_inst) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *inst = NULL; + const char *name = NULL; + + if (cu_get_str_path(reference, "DeviceID", &name) != CMPI_RC_OK) { cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, "No DeviceID specified"); goto out; } - - inst = instance_from_devid(broker, - conn, - devid, - NAMESPACE(reference), - device_type_from_classname(cn)); - if (inst == NULL) { - cu_statusf(broker, &s, - CMPI_RC_ERR_NOT_FOUND, - "No such instance (%s)", devid); - goto out; - } - + + s = get_device_by_name(broker, + reference, + name, + device_type_from_classname(CLASSNAME(reference)), + &inst); + if (s.rc != CMPI_RC_OK) + goto out; + s = cu_validate_ref(broker, reference, inst); if (s.rc != CMPI_RC_OK) goto out; @@ -499,24 +516,7 @@ CMPIStatus get_device(const CMPIBroker * *_inst = inst; out: - virConnectClose(conn); - return s; -} - -static CMPIStatus return_device(const CMPIResult *results, - const CMPIObjectPath *reference) -{ - CMPIStatus s = {CMPI_RC_OK, NULL}; - CMPIInstance *inst = NULL; - - s = get_device(_BROKER, reference, &inst); - if (s.rc != CMPI_RC_OK || inst == NULL) - return s; - - CMReturnInstance(results, inst); - - return s; } static CMPIStatus EnumInstanceNames(CMPIInstanceMI *self, @@ -542,7 +542,17 @@ static CMPIStatus GetInstance(CMPIInstan const CMPIObjectPath *reference, const char **properties) { - return return_device(results, reference); + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *inst = NULL; + + s = get_device_by_ref(_BROKER, reference, &inst); + if (s.rc != CMPI_RC_OK) + goto out; + + CMReturnInstance(results, inst); + + out: + return s; } DEFAULT_CI(); diff -r 8ce1fe84f583 -r c9ac31ec5a89 src/Virt_Device.h --- a/src/Virt_Device.h Tue Feb 26 10:08:24 2008 +0100 +++ b/src/Virt_Device.h Tue Feb 26 13:39:12 2008 +0100 @@ -46,30 +46,31 @@ int dom_devices(const CMPIBroker *broker * * @param broker A pointer to the CIM broker * @param reference The object path identifying the instance - * @param inst Contains the pointer to the instance in case + * @param _inst Contains the pointer to the instance in case * of success * @returns CMPIStatus of the operation */ -CMPIStatus get_device(const CMPIBroker *broker, - const CMPIObjectPath *reference, - CMPIInstance **_inst); +CMPIStatus get_device_by_ref(const CMPIBroker *broker, + const CMPIObjectPath *reference, + CMPIInstance **_inst); /** - * Return a device instance for a given devid + * Returns the device instance for a given name and type * * @param broker A pointer to the CIM broker - * @param conn The libvirt connection to use - * @param devid The device id - * @param reference the namespace - * @returns The instance, or NULL if not found + * @param reference The object path containing namespace info + * @param name The name "<vm>/<resource>" + * @param type The resource type + * @param _inst The instance pointer in case of success + * @returns The result as CMPIStatus */ -CMPIInstance *instance_from_devid(const CMPIBroker *broker, - virConnectPtr conn, - const char *devid, - const char *ns, - int type); +CMPIStatus get_device_by_name(const CMPIBroker *broker, + const CMPIObjectPath *reference, + const char *name, + const uint16_t type, + CMPIInstance **_inst); -int device_type_from_classname(const char *classname); +uint16_t device_type_from_classname(const char *classname); #endif

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1204029555 -3600 # Node ID cb5e9f764dc5acde83c436232a37cb39945a8bc1 # Parent c9ac31ec5a89cd5b2d165c34d218412cbbb6c47d SDS: validate client given object path of devices wbemain -ac CIM_SettingsDefineState 'http://localhost/root/virt:KVM_Memory.DeviceID="kvm1-f8/mem",CreationClassName="",SystemName="wrong",SystemCreationClassName=""' is returning an instance instead of NOT_FOUND Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r c9ac31ec5a89 -r cb5e9f764dc5 src/Virt_SettingsDefineState.c --- a/src/Virt_SettingsDefineState.c Tue Feb 26 13:39:12 2008 +0100 +++ b/src/Virt_SettingsDefineState.c Tue Feb 26 13:39:15 2008 +0100 @@ -39,119 +39,41 @@ const static CMPIBroker *_BROKER; -static CMPIInstance *find_rasd(struct inst_list *list, - const char *devid) -{ - int i; - CMPIInstance *inst; - - for (i = 0; i < list->cur; i++) { - const char *id; - int ret; - - inst = list->list[i]; - - ret = cu_get_str_prop(inst, "InstanceID", &id); - if (ret != CMPI_RC_OK) - continue; - - if (STREQ(id, devid)) - return inst; - } - - return NULL; -} - static CMPIStatus dev_to_rasd(const CMPIObjectPath *ref, struct std_assoc_info *info, struct inst_list *list) { CMPIStatus s = {CMPI_RC_OK, NULL}; - CMPIInstance *rasd; - struct inst_list rasds; - const char *id = NULL; - char *name = NULL; - char *devid = NULL; - int ret; - - if (!match_hypervisor_prefix(ref, info)) - return s; - - inst_list_init(&rasds); - - if (cu_get_str_path(ref, "DeviceID", &id) != CMPI_RC_OK) { + CMPIInstance *inst = NULL; + const char *name = NULL; + + if (!match_hypervisor_prefix(ref, info)) + return s; + + s = get_device_by_ref(_BROKER, ref, &inst); + if (s.rc != CMPI_RC_OK) + goto out; + + if (cu_get_str_path(ref, "DeviceID", &name) != CMPI_RC_OK) { cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, "Missing DeviceID"); goto out; - } - - ret = parse_fq_devid(id, &name, &devid); - if (!ret) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "Invalid DeviceID"); - goto out; - } - - ret = rasds_for_domain(_BROKER, - name, - device_type_from_classname(CLASSNAME(ref)), - ref, - info->properties, - &rasds); - - rasd = find_rasd(&rasds, id); - if (rasd != NULL) - inst_list_add(list, rasd); - - cu_statusf(_BROKER, &s, - CMPI_RC_OK, - ""); - out: - free(name); - free(devid); - - return s; -} - -static CMPIInstance *_get_typed_device(const char *id, - int type, - const CMPIObjectPath *ref, - CMPIStatus *s) -{ - virConnectPtr conn = NULL; - CMPIInstance *dev = NULL; - const char *typestr; - - conn = connect_by_classname(_BROKER, CLASSNAME(ref), s); - if (conn == NULL) - goto out; - - if (type == CIM_RASD_TYPE_DISK) - typestr = "LogicalDisk"; - else if (type == CIM_RASD_TYPE_MEM) - typestr = "Memory"; - else if (type == CIM_RASD_TYPE_PROC) - typestr = "Processor"; - else if (type == CIM_RASD_TYPE_NET) - typestr = "NetworkPort"; - else { - cu_statusf(_BROKER, s, - CMPI_RC_ERR_FAILED, - "Invalid device type (%i)", type); - goto out; - } - - dev = instance_from_devid(_BROKER, - conn, - id, - NAMESPACE(ref), - device_type_from_classname(typestr)); - out: - virConnectClose(conn); - - return dev; + } + + s = get_rasd_by_name(_BROKER, + ref, + name, + device_type_from_classname(CLASSNAME(ref)), + NULL, + &inst); + if (s.rc != CMPI_RC_OK) + goto out; + + inst_list_add(list, inst); + + out: + return s; } static CMPIStatus rasd_to_dev(const CMPIObjectPath *ref, @@ -159,15 +81,18 @@ static CMPIStatus rasd_to_dev(const CMPI struct inst_list *list) { CMPIStatus s = {CMPI_RC_OK, NULL}; - CMPIInstance *dev = NULL; CMPIInstance *inst = NULL; - const char *id = NULL; + const char *name = NULL; uint16_t type; if (!match_hypervisor_prefix(ref, info)) return s; - if (cu_get_str_path(ref, "InstanceID", &id) != CMPI_RC_OK) { + s = get_rasd_by_ref(_BROKER, ref, NULL, &inst); + if (s.rc != CMPI_RC_OK) + goto out; + + if (cu_get_str_path(ref, "InstanceID", &name) != CMPI_RC_OK) { cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, "Missing InstanceID"); @@ -180,16 +105,12 @@ static CMPIStatus rasd_to_dev(const CMPI "Missing ResourceType"); goto out; } - - s = get_rasd_by_name(_BROKER, ref, id, type, NULL, &inst); - if (s.rc != CMPI_RC_OK) - goto out; - - dev = _get_typed_device(id, type, ref, &s); - if (dev == NULL) - goto out; - - inst_list_add(list, dev); + + s = get_device_by_name(_BROKER, ref, name, type, &inst); + if (s.rc != CMPI_RC_OK) + goto out; + + inst_list_add(list, inst); out: return s;

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1204029556 -3600 # Node ID 59b90560cdd2dc2748589747294e6d4d658fb3b8 # Parent cb5e9f764dc5acde83c436232a37cb39945a8bc1 SD: adopt interface change of Device provider Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r cb5e9f764dc5 -r 59b90560cdd2 src/Virt_SystemDevice.c --- a/src/Virt_SystemDevice.c Tue Feb 26 13:39:15 2008 +0100 +++ b/src/Virt_SystemDevice.c Tue Feb 26 13:39:16 2008 +0100 @@ -184,7 +184,7 @@ static CMPIStatus dev_to_sys(const CMPIO if (!match_hypervisor_prefix(ref, info)) return s; - s = get_device(_BROKER, ref, &inst); + s = get_device_by_ref(_BROKER, ref, &inst); if (s.rc != CMPI_RC_OK) goto out;
participants (1)
-
Heidi Eckhart