// automatically generated. Do not modify static void testSRs(xen_session *session) { printf("\nGet all the SR Records\n"); xen_sr_set *sr_set; bool d = xen_sr_get_all(session, &sr_set); if (d) { size_t i = 0; for (; i < sr_set->size; ++i) { xen_sr_record *sr_record; xen_sr_get_record(session, &sr_record, sr_set->contents[i]); char *handle = (char*) sr_record->handle; char *opaque = (char*) sr_set->contents[i]; if (strcmp(handle, opaque) == 0) printf("identical: %s\n", opaque); else printf("record->handle[%s] v.s. set->contents[%d][%s]\n", opaque, i, handle); xen_sr_record_free(sr_record); } } else { print_error(session); } xen_sr_set_free(sr_set); printf("\n==============================================\n\n"); }
/**************************************************************************** * disk_rasd_from_vbd * * This function builds a new Xen_Disk CIM instance based on the information * in the VBD record * * Returns 1 on Success and 0 on failure. *****************************************************************************/ int disk_rasd_from_vbd( const CMPIBroker* broker, xen_utils_session *session, CMPIInstance *inst, xen_vm_record *vm_rec, xen_vbd_record *vbd_rec, xen_vdi_record *vdi_rec ) { char buf[MAX_INSTANCEID_LEN]; xen_sr_record *sr_rec = NULL; unsigned long long physical_utilization = 1, limit = 1, virtual_quantity = 1; DMTF_ResourceType rasd_type = DMTF_ResourceType_Storage_Extent; uint64_t block_size = 1; bool autoalloc = false; DMTF_MappingBehavior behaviour = DMTF_MappingBehavior_Dedicated; char *alloc_unit = "byte"; Access access = Access_Unknown; RESET_XEN_ERROR(session->xen); if (vm_rec == NULL) { _SBLIM_TRACE(_SBLIM_TRACE_LEVEL_ERROR, ("--- Orphaned VBD")); return 0; } _CMPICreateNewDeviceInstanceID(buf, MAX_INSTANCEID_LEN, vm_rec->uuid, vbd_rec->uuid); if (vdi_rec) { if (vdi_rec->sharable) behaviour = DMTF_MappingBehavior_Hard_Affinity; physical_utilization = vdi_rec->physical_utilisation; limit = vdi_rec->virtual_size; virtual_quantity = vdi_rec->virtual_size; if (vdi_rec->sr->is_record) sr_rec = vdi_rec->sr->u.handle; else xen_sr_get_record(session->xen, &sr_rec, vdi_rec->sr->u.handle); } if (vbd_rec->mode == XEN_VBD_MODE_RW) access = Access_Read_Write_Supported; else access = Access_Readable; DMTF_ConsumerVisibility virtualized = DMTF_ConsumerVisibility_Virtualized; if (vbd_rec->type == XEN_VBD_TYPE_CD) { rasd_type = DMTF_ResourceType_DVD_drive; alloc_unit = "count"; virtual_quantity = 1; } /* Set the CMPIInstance properties from the resource data. */ /* Key Proerpty first */ CMSetProperty(inst, "InstanceID",(CMPIValue *)buf, CMPI_chars); /* Rest of the keys follow */ CMSetProperty(inst, "Caption",(CMPIValue *)"Extended Settings for a Xen Virtual Disk", CMPI_chars); CMSetProperty(inst, "ResourceType",(CMPIValue *)&rasd_type, CMPI_uint16); CMSetProperty(inst, "ResourceSubType",(CMPIValue *)"DMTF:xen:vbd", CMPI_chars); /* required by DMTF */ CMSetProperty(inst, "Access",(CMPIValue *)&access, CMPI_uint16); CMSetProperty(inst, "AddressOnParent",(CMPIValue *)vbd_rec->userdevice, CMPI_chars); CMSetProperty(inst, "AllocationUnits",(CMPIValue *)alloc_unit, CMPI_chars); CMSetProperty(inst, "AutomaticAllocation",(CMPIValue *)&autoalloc, CMPI_boolean); CMSetProperty(inst, "AutomaticDeallocation", (CMPIValue *)&autoalloc, CMPI_boolean); CMSetProperty(inst, "ConsumerVisibility", (CMPIValue *)&virtualized, CMPI_uint16); CMSetProperty(inst, "VirtualQuantity",(CMPIValue *)&virtual_quantity, CMPI_uint64); CMSetProperty(inst, "VirtualQuantityUnits",(CMPIValue *)alloc_unit, CMPI_chars); CMSetProperty(inst, "Reservation",(CMPIValue *)&limit, CMPI_uint64); CMSetProperty(inst, "Limit",(CMPIValue *)&limit, CMPI_uint64); CMSetProperty(inst, "VirtualResourceBlockSize",(CMPIValue *)&block_size, CMPI_uint64); CMSetProperty(inst, "HostResourceBlockSize",(CMPIValue *)&block_size, CMPI_uint64); /* Setup the Configuration properties */ if (vdi_rec) { CMSetProperty(inst, "ElementName",(CMPIValue *)vdi_rec->name_label, CMPI_chars); CMSetProperty(inst, "Description",(CMPIValue *)vdi_rec->name_description, CMPI_chars); /* HostResource requires string in WBEM URI Format */ CMPIObjectPath *disk_ref = disk_image_create_ref(broker, DEFAULT_NS, session, sr_rec->uuid, vdi_rec->uuid); if (disk_ref) { /* conver objectpath to string form */ char *disks_uri = xen_utils_CMPIObjectPath_to_WBEM_URI(broker, disk_ref); if (disks_uri) { CMPIArray *arr = CMNewArray(broker, 1, CMPI_chars, NULL); CMSetArrayElementAt(arr, 0, (CMPIValue *) disks_uri, CMPI_chars); CMSetProperty(inst, "HostResource", &arr, CMPI_charsA); } } CMSetProperty(inst, "HostExtentName",(CMPIValue *)vdi_rec->uuid, CMPI_chars); NameFormat name_format = NameFormat_Other; CMSetProperty(inst, "HostExtentNameFormat",(CMPIValue *)&name_format, CMPI_uint16); CMSetProperty(inst, "OtherHostExtentNameFormat",(CMPIValue *)"Xen VDI UUID", CMPI_chars); NameNamespace name_namespace = NameNamespace_Other; CMSetProperty(inst, "HostExtentNameNamespace",(CMPIValue *)&name_namespace, CMPI_uint16); CMSetProperty(inst, "OtherHostExtentNameNamespace",(CMPIValue *)"Xen UUID", CMPI_chars); } CMSetProperty(inst, "MappingBehavior",(CMPIValue *)&behaviour, CMPI_uint16); if (sr_rec) CMSetProperty(inst, "PoolID", sr_rec->uuid, CMPI_chars); // Derived class properties CMSetProperty(inst, "Bootable",(CMPIValue *)&vbd_rec->bootable, CMPI_boolean); // Others not used //CMSetProperty(inst, "Address",(CMPIValue *)<value>, CMPI_chars); //CMPIArray *arr = CMNewArray(broker, 1, CMPI_chars, NULL); //CMSetArrayElementAt(arr, 0, (CMPIValue *) buf, CMPI_chars); //CMSetProperty(inst, "Connection", &arr, CMPI_charsA); //CMSetProperty(inst, "ChangeableType",(CMPIValue *)&<value>, CMPI_uint16); //CMSetProperty(inst, "ConfigurationName",(CMPIValue *)<value>, CMPI_chars); //CMSetProperty(inst, "Generation",(CMPIValue *)&<value>, CMPI_uint64); //CMSetProperty(inst, "OtherResourceType", (CMPIValue *)<value>, CMPI_chars); //CMSetProperty(inst, "HostExtentStartingAddress",(CMPIValue *)&<value>, CMPI_uint64); //CMSetProperty(inst, "MaxConsumableResource",(CMPIValue *)<value>, CMPI_uint64); //CMSetProperty(inst, "CurrentlyConsumedResource",(CMPIValue *)<value>, CMPI_uint64); //CMSetProperty(inst, "ConsumedResourceUnit",(CMPIValue *)<value>, CMPI_chars); //CMSetProperty(inst, "Parent",(CMPIValue *)<value>, CMPI_chars); /* This is going to be useful for diff disks WBEM URI */ //CMSetProperty(inst, "Weight",(CMPIValue *)&<value>, CMPI_uint32); /* Free time */ if (sr_rec && vdi_rec && !vdi_rec->sr->is_record) xen_sr_record_free(sr_rec); return CMPI_RC_OK; }