[PATCH 0 of 3] Add call to libvirt to create storage volume

This set also has creates a StorageVolume instance to return to the user. Ideally, the bit of code in patch 3 should be in Virt_RASD, but that takes some signigicant amount of reshuffiling in the Virt_RASD provider. This will be fixed after this set of patches goes in. This is the last set of patches to get basic image creation working.

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1245187550 25200 # Node ID 3fbc29cee5f7391a16a2d68d31eda3d732f4a70e # Parent d47e71adaa6285b43f19d2c6eef184c50d8439d7 Add call to libvirt virStorageVolCreateXML() This call creates the storage volume / image that can be used by future guests. Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r d47e71adaa62 -r 3fbc29cee5f7 libxkutil/pool_parsing.c --- a/libxkutil/pool_parsing.c Tue Aug 11 16:54:03 2009 -0700 +++ b/libxkutil/pool_parsing.c Tue Jun 16 14:25:50 2009 -0700 @@ -329,6 +329,46 @@ return ret; } +#if VIR_USE_LIBVIRT_STORAGE +int create_resource(virConnectPtr conn, + const char *pname, + const char *xml, + int res_type) +{ + int ret = 0; + + if (res_type == CIM_RES_TYPE_IMAGE) { + virStoragePoolPtr ptr = virStoragePoolLookupByName(conn, pname); + if (ptr == NULL) { + CU_DEBUG("Storage pool %s is not defined", pname); + goto out; + } + + virStorageVolPtr vptr = virStorageVolCreateXML(ptr, xml, 0); + if (vptr == NULL) + goto out; + + virStorageVolFree(vptr); + virStoragePoolFree(ptr); + + ret = 1; + } + + out: + + return ret; +} +#else +int create_resource(virConnectPtr conn, + const char *pname, + const char *xml, + int res_type) +{ + CU_DEBUG("Creating resources within libvirt pools not supported"); + return 0; +} +#endif + /* * Local Variables: * mode: C diff -r d47e71adaa62 -r 3fbc29cee5f7 libxkutil/pool_parsing.h --- a/libxkutil/pool_parsing.h Tue Aug 11 16:54:03 2009 -0700 +++ b/libxkutil/pool_parsing.h Tue Jun 16 14:25:50 2009 -0700 @@ -89,6 +89,8 @@ int define_pool(virConnectPtr conn, const char *xml, int res_type); int destroy_pool(virConnectPtr conn, const char *name, int res_type); +int create_resource(virConnectPtr conn, const char *pname, + const char *xml, int res_type); #endif

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1250140070 25200 # Node ID 7159cbef9779e747201235c2d6495568065e10b9 # Parent 3fbc29cee5f7391a16a2d68d31eda3d732f4a70e Call create_resource() from RPCS Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r 3fbc29cee5f7 -r 7159cbef9779 src/Virt_ResourcePoolConfigurationService.c --- a/src/Virt_ResourcePoolConfigurationService.c Tue Jun 16 14:25:50 2009 -0700 +++ b/src/Virt_ResourcePoolConfigurationService.c Wed Aug 12 22:07:50 2009 -0700 @@ -771,6 +771,36 @@ return msg; } +static CMPIInstance *connect_and_create_res(char *xml, + const CMPIObjectPath *ref, + struct virt_pool_res *res, + CMPIStatus *s) +{ + virConnectPtr conn; + CMPIInstance *inst = NULL; + + conn = connect_by_classname(_BROKER, CLASSNAME(ref), s); + if (conn == NULL) { + CU_DEBUG("libvirt connection failed"); + return NULL; + } + + if (create_resource(conn, res->pool_id, xml, res->type) == 0) { + virt_set_status(_BROKER, s, + CMPI_RC_ERR_FAILED, + conn, + "Unable to create storage volume"); + goto out; + } + + /* FIXME: Get instance result here */ + + out: + virConnectClose(conn); + + return inst; +} + static CMPIStatus create_resource_in_pool(CMPIMethodMI *self, const CMPIContext *context, const CMPIResult *results, @@ -787,6 +817,8 @@ const char *id = NULL; char *pool_id = NULL; char *xml = NULL; + CMPIInstance *inst = NULL; + CMPIObjectPath *result; CU_DEBUG("CreateResourceInPool"); @@ -839,7 +871,22 @@ CU_DEBUG("New resource XML:\n%s", xml); - /*FIXME: Add resource here */ + inst = connect_and_create_res(xml, reference, res, &s); + if (s.rc != CMPI_RC_OK) + goto out; + + if (inst == NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to create new resource"); + goto out; + } + + result = CMGetObjectPath(inst, &s); + if ((result != NULL) && (s.rc == CMPI_RC_OK)) { + CMSetNameSpace(result, NAMESPACE(reference)); + CMAddArg(argsout, "Resource", &result, CMPI_ref); + } out: free(pool_id);

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1250140071 25200 # Node ID 8f508c5e32df61f7b5866ec0f4dfd3bf81f6e071 # Parent 7159cbef9779e747201235c2d6495568065e10b9 Add get_resource_rasd() to return StorageVolumeRASD that represents new image Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r 7159cbef9779 -r 8f508c5e32df src/Virt_ResourcePoolConfigurationService.c --- a/src/Virt_ResourcePoolConfigurationService.c Wed Aug 12 22:07:50 2009 -0700 +++ b/src/Virt_ResourcePoolConfigurationService.c Wed Aug 12 22:07:51 2009 -0700 @@ -771,6 +771,60 @@ return msg; } +static CMPIInstance *get_resource_rasd(struct virt_pool_res *res, + const CMPIObjectPath *ref, + CMPIStatus *s) +{ + CMPIInstance *inst = NULL; + + if (res->type != CIM_RES_TYPE_IMAGE) { + cu_statusf(_BROKER, s, + CMPI_RC_ERR_FAILED, + "Only storage volume resources supported"); + + goto out; + } + + inst = get_typed_instance(_BROKER, + CLASSNAME(ref), + "StorageVolumeResourceAllocationSettingData", + NAMESPACE(ref)); + if (inst == NULL) { + cu_statusf(_BROKER, s, + CMPI_RC_ERR_FAILED, + "Unable to get resource instance"); + + goto out; + } + + CMSetProperty(inst, "InstanceID", + (CMPIValue *)res->res.storage_vol.path, CMPI_chars); + + CMSetProperty(inst, "Path", + (CMPIValue *)res->res.storage_vol.path, CMPI_chars); + + CMSetProperty(inst, "ResourceType", + (CMPIValue *)&(res->type), CMPI_uint16); + + CMSetProperty(inst, "FormatType", + (CMPIValue *)&(res->res.storage_vol.format_type), + CMPI_uint16); + + CMSetProperty(inst, "VolumeName", + (CMPIValue *)res->res.storage_vol.vol_name, CMPI_chars); + CMSetProperty(inst, "AllocationQuantity", + (CMPIValue *)&(res->res.storage_vol.alloc), CMPI_uint16); + + CMSetProperty(inst, "Capacity", + (CMPIValue *)&(res->res.storage_vol.cap), CMPI_uint16); + + CMSetProperty(inst, "AllocationUnits", + (CMPIValue *)res->res.storage_vol.cap_units, CMPI_chars); + + out: + return inst; +} + static CMPIInstance *connect_and_create_res(char *xml, const CMPIObjectPath *ref, struct virt_pool_res *res, @@ -793,7 +847,13 @@ goto out; } - /* FIXME: Get instance result here */ + inst = get_resource_rasd(res, ref, s); + if (s->rc != CMPI_RC_OK) { + CU_DEBUG("Failed to get new resource instance"); + cu_statusf(_BROKER, s, + CMPI_RC_ERR_FAILED, + "Failed to lookup resulting resource"); + } out: virConnectClose(conn);

+1 On 08/13/2009 02:08 AM, Kaitlin Rupert wrote:
This set also has creates a StorageVolume instance to return to the user. Ideally, the bit of code in patch 3 should be in Virt_RASD, but that takes some signigicant amount of reshuffiling in the Virt_RASD provider. This will be fixed after this set of patches goes in.
This is the last set of patches to get basic image creation working.
_______________________________________________ Libvirt-cim mailing list Libvirt-cim@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-cim
-- Richard Maciel, MSc IBM Linux Technology Center rmaciel@linux.vnet.ibm.com
participants (2)
-
Kaitlin Rupert
-
Richard Maciel