# HG changeset patch # User root@hyperion.shrike # Node ID 363759cd16297f7cf4bdeb79615f651b76d1988a # Parent c7c88e6f3f673e2e26079ca76bc9b411fdf778dd This patch updates the Xen_NetworkPort_Resource.c and .h files to read the device information. I also changed all references to 'nic' to 'vif' to keep it unifotm. The patch basically follows the Xen_Disk_Resource.c patch that came in yesterday. Signed-off-by: Rajagopalan Subrahmanian diff -r c7c88e6f3f67 -r 363759cd1629 src/Xen_NetworkPort_Resource.c --- a/src/Xen_NetworkPort_Resource.c Tue Dec 19 05:32:28 2006 -0500 +++ b/src/Xen_NetworkPort_Resource.c Tue Dec 19 14:24:08 2006 -0500 @@ -17,11 +17,13 @@ // Authors: Dr. Gareth S. Bestor, // Tokunbo Adeshiyan, // Contributors: Jim Fehlig, +// Rajagopalan Subrahmanian // Description: // ============================================================================ #include #include +#include #include #include @@ -35,6 +37,8 @@ #include "cmpimacs.h" #include "xen_utils.h" +/* Include _SBLIM_TRACE() logging support */ +#include "cmpitrace.h" // ---------------------------------------------------------------------------- @@ -52,7 +56,7 @@ int Xen_NetworkPort_getResources( _RESOU } /* Start iterating from the first block device of the first Xen domain name. */ - (*resources)->currentnicnum = 0; + (*resources)->currentvifnum = 0; return 1; } @@ -85,15 +89,29 @@ int Xen_NetworkPort_getNextResource( _RE /* Get the current domain. */ if (!xen_utils_get_current_domain_resource(resources->domains, resource)) return 0; - - /* Move to the next nic device for next time. */ - /* if nicnum exceeds the number of nic devices in this domain then goto the next domain. */ - resources->currentnicnum++; - if (resources->currentnicnum == (*resource)->vifs->size) { - XEN_UTILS_INC_DOMAIN_RESOURCE_COUNT(resources->domains); - resources->currentnicnum = 0; - } - + if ((*resource)->power_state == XEN_VM_POWER_STATE_HALTED) + goto NextDomain; + + /* Move to the next vif device for next time. */ + /* if vifnum exceeds the number of vif devices in this domain then goto the next domain. */ + resources->currentvifnum++; + if (resources->currentvifnum <= (*resource)->vifs->size) return 1; +NextDomain: + /* All vifs in this domain have been exhausted, or the Domain is powered off. */ + /* Start serving up vifs for the next domain, if it exists */ + Xen_NetworkPort_freeResource(*resource); + XEN_UTILS_INC_DOMAIN_RESOURCE_COUNT(resources->domains); + if (!XEN_UTILS_MORE_DOMAIN_RESOURCES(resources->domains)) + return 0; + + /* Get the next domain resource. */ + if (!xen_utils_get_current_domain_resource(resources->domains, resource)) return 0; + + /* Only serve up block devices if the domain is not inactive */ + if ((*resource)->power_state == XEN_VM_POWER_STATE_HALTED) + goto NextDomain; + /* Start at the first vif for this 'next' domain. */ + resources->currentvifnum = 1; return 1; } @@ -103,7 +121,7 @@ int Xen_NetworkPort_getResourceForObject int Xen_NetworkPort_getResourceForObjectPath( _RESOURCES * resources, _RESOURCE ** resource, const CMPIObjectPath * objectpath ) { CMPIStatus status = {CMPI_RC_OK, NULL}; /* Return status of CIM operations. */ - + char *keyvalue; if (resources == NULL) return 0; if (CMIsNullObject(objectpath)) return 0; @@ -116,20 +134,41 @@ int Xen_NetworkPort_getResourceForObject if ((domainname == NULL) || (*domainname == '\0')) return 0; /* Get the domain data for the target domain name. */ - xen_vm vm; - if (!xen_vm_get_by_uuid(resources->domains->xen, &vm, domainname)) { + xen_vm_set *vms; + if (!xen_vm_get_by_name_label(resources->domains->xen, &vms, keyvalue)) { /* Error is in session object! */ *resource = NULL; return 0; } - - if (!xen_vm_get_record(resources->domains->xen, resource, vm)) { - /* Error description in session object! */ - xen_vm_free(vm); - return 0; - } - - xen_vm_free(vm); + + assert(vms->size == 1);// Ensure that there's only one + if (!xen_vm_get_record(resources->domains->xen, resource, vms->contents[0])) { + /* Error description in session object! */ + xen_vm_set_free(vms); + return 0; + } + + xen_vm_set_free(vms); + /* Set the currentvifnum from the DeviceID */ + namedata = CMGetKey(objectpath, "DeviceID", &status); + if ((status.rc != CMPI_RC_OK) || CMIsNullValue(namedata)) { + Xen_NetworkPort_freeResource(*resource); + return 0; + } + + keyvalue = CMGetCharPtr(namedata.value.string); + if ((keyvalue == NULL) || (*keyvalue == '\0')) { + Xen_NetworkPort_freeResource(*resource); + return 0; + } + + char *p; + if ((p = strstr(keyvalue, "Vif")) == NULL) { + Xen_NetworkPort_freeResource(*resource); + return 0; + } + else + resources->currentvifnum = atoi(p + 3); return 1; } @@ -148,20 +187,21 @@ int Xen_NetworkPort_setInstanceFromResou int Xen_NetworkPort_setInstanceFromResource( _RESOURCE * resource, const CMPIInstance * instance, const CMPIBroker * broker, _RESOURCES * resources ) { //CMPIArray * ips = CMNewArray(broker, 1, CMPI_chars, NULL); - + if (resource == NULL) return 0; if (CMIsNullObject(instance)) return 0; - - int nicnum = resources->currentnicnum; - xen_vif_record_opt *vif_rec_opt = resource->vifs->contents[nicnum]; + int vifnum = resources->currentvifnum; + + xen_vif_record_opt *vif_rec_opt = resource->vifs->contents[vifnum-1]; xen_vif_record *vif_rec; + + if (vif_rec_opt==NULL) return 0; if (vif_rec_opt->is_record) { vif_rec = vif_rec_opt->u.record; } else { if (!xen_vif_get_record(resources->domains->xen, &vif_rec, vif_rec_opt->u.handle)) { - fprintf(stderr, "xen_vif_get_record() failed\n"); return 0; } } @@ -172,13 +212,13 @@ int Xen_NetworkPort_setInstanceFromResou CMSetProperty(instance, "CreationClassName",(CMPIValue *)"Xen_NetworkPort", CMPI_chars); char deviceid[1024]; - sprintf(deviceid, "Nic%d", resources->currentnicnum); + sprintf(deviceid, "Vif%d", resources->currentvifnum); CMSetProperty(instance, "DeviceID",(CMPIValue *)deviceid, CMPI_chars); CMSetProperty(instance, "Caption",(CMPIValue *)"Network Port", CMPI_chars); CMSetProperty(instance, "Description",(CMPIValue *)"Network Port", CMPI_chars); CMSetProperty(instance, "Name",(CMPIValue *)deviceid, CMPI_chars); - //CMSetProperty(instance, "NICConfigInfo",(CMPIValue *)resource->vif[nicnum].params, CMPI_chars); + //CMSetProperty(instance, "NICConfigInfo",(CMPIValue *)resource->vif[vifnum].params, CMPI_chars); int link_tech = 2; /* 2 == Ethernet */ CMSetProperty(instance, "LinkTechnology",(CMPIValue *)&link_tech, CMPI_uint16); diff -r c7c88e6f3f67 -r 363759cd1629 src/Xen_NetworkPort_Resource.h --- a/src/Xen_NetworkPort_Resource.h Tue Dec 19 05:32:28 2006 -0500 +++ b/src/Xen_NetworkPort_Resource.h Tue Dec 19 14:24:08 2006 -0500 @@ -17,6 +17,7 @@ // Authors: Dr. Gareth S. Bestor, // Tokunbo Adeshiyan, // Contributors: Jim Fehlig, +// Rajagopalan Subrahmanian // Description: // ============================================================================ @@ -34,7 +35,7 @@ ACCESSING/ITERATING/ADDING/REMOVING RESOURCES INSTANCES. */ typedef struct { xen_domain_resources *domains; - unsigned int currentnicnum; + unsigned int currentvifnum; } _RESOURCES; /*** CUSTOMIZE FOR EACH PROVIDER ***/