[PATCH 0 of 3] First set of patches relating to image deletion

This is the first set of changes. There needs to be a follow up patch to enumerate the storage volumes - some way other than via the SDC association. Updates: -This fixes the image deletion code so that the user can pass one of the RASDs returned from SDC.

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1251232703 25200 # Node ID d047a30a9ea367e729cb265434c4dba89c11f495 # Parent 9af5eef7ea76c7e9d1657d2e8cd4df9ed126b596 (#2) Add DeleteResourceInPool() to RPCS mof Also, fix a typo in the description for the out parameter in CreateResourceInPool() Updates: -Change the Resource paramater to a EmbeddedObject instead of a CMPIReference. This will allow the user to grab the instance of the storage volume from SDC - the instances from SDC don't have the path set in the InstanceID attribute - they have that specified in the Address attribute Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r 9af5eef7ea76 -r d047a30a9ea3 schema/ResourcePoolConfigurationService.mof --- a/schema/ResourcePoolConfigurationService.mof Mon Aug 24 16:14:41 2009 -0700 +++ b/schema/ResourcePoolConfigurationService.mof Tue Aug 25 13:38:23 2009 -0700 @@ -17,9 +17,24 @@ [IN, Description ( "Reference to the pool to create the resources in." )] CIM_ResourcePool REF Pool, + [IN ( false ), OUT, Description ( "Reference to the resource created." )] + CIM_ResourceAllocationSettingData REF Resource + ); + + [Description ( "Delete a resource within a specified pool using the " + "specified allocation settings. If 0 is returned, the " + "function completed successfully." )] + uint32 DeleteResourceInPool( + [IN, Description ( "Reference to the resource to delete." ), + EmbeddedInstance ( "CIM_ResourceAllocationSettingData" )] + string Resource, + + [IN, Description ( "The pool to remove the resource from." )] + CIM_ResourcePool REF Pool, + [IN ( false ), OUT, Description ( "Reference to the job (may be null " "if job completed)." )] - CIM_ResourceAllocationSettingData REF Resource + CIM_ConcreteJob REF Job ); }; @@ -41,9 +56,24 @@ [IN, Description ( "Reference to the pool to create the resources in." )] CIM_ResourcePool REF Pool, + [IN ( false ), OUT, Description ( "Reference to the resource created." )] + CIM_ResourceAllocationSettingData REF Resource + ); + + [Description ( "Delete a resource within a specified pool using the " + "specified allocation settings. If 0 is returned, the " + "function completed successfully." )] + uint32 DeleteResourceInPool( + [IN, Description ( "Reference to the resource to delete." ), + EmbeddedInstance ( "CIM_ResourceAllocationSettingData" )] + string Resource, + + [IN, Description ( "The pool to remove the resource from." )] + CIM_ResourcePool REF Pool, + [IN ( false ), OUT, Description ( "Reference to the job (may be null " "if job completed)." )] - CIM_ResourceAllocationSettingData REF Resource + CIM_ConcreteJob REF Job ); }; @@ -65,9 +95,24 @@ [IN, Description ( "Reference to the pool to create the resources in." )] CIM_ResourcePool REF Pool, - [IN ( false ), OUT, Description ( "Reference to the job (may be null " - "if job completed)." )] + [IN ( false ), OUT, Description ( "Reference to the resource created." )] CIM_ResourceAllocationSettingData REF Resource ); + [Description ( "Delete a resource within a specified pool using the " + "specified allocation settings. If 0 is returned, the " + "function completed successfully." )] + uint32 DeleteResourceInPool( + [IN, Description ( "Reference to the resource to delete." ), + EmbeddedInstance ( "CIM_ResourceAllocationSettingData" )] + string Resource, + + [IN, Description ( "The pool to remove the resource from." )] + CIM_ResourcePool REF Pool, + + [IN ( false ), OUT, Description ( "Reference to the job (may be null " + "if job completed)." )] + CIM_ConcreteJob REF Job + ); + };

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1251232703 25200 # Node ID 2ca94acaa955045c3438053f3fa8f1277945f839 # Parent d047a30a9ea367e729cb265434c4dba89c11f495 Add delete_resource() to pool_parsing.c - this will call libvirt APIs... To delete a storage volume within a storage pool. Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r d047a30a9ea3 -r 2ca94acaa955 libxkutil/pool_parsing.c --- a/libxkutil/pool_parsing.c Tue Aug 25 13:38:23 2009 -0700 +++ b/libxkutil/pool_parsing.c Tue Aug 25 13:38:23 2009 -0700 @@ -358,6 +358,34 @@ return ret; } + +int delete_resource(virConnectPtr conn, + const char *rname, + int res_type) +{ + int ret = 0; + + if (res_type == CIM_RES_TYPE_IMAGE) { + virStorageVolPtr ptr = virStorageVolLookupByPath(conn, rname); + if (ptr == NULL) { + CU_DEBUG("Storage volume %s is not defined", rname); + goto out; + } + + ret = virStorageVolDelete(ptr, 0); + if (ret != 0) { + CU_DEBUG("Unable to delete storage volume %s", rname); + } else { + ret = 1; + } + + virStorageVolFree(ptr); + } + + out: + + return ret; +} #else int create_resource(virConnectPtr conn, const char *pname, @@ -367,6 +395,14 @@ CU_DEBUG("Creating resources within libvirt pools not supported"); return 0; } + +int delete_resource(virConnectPtr conn, + const char *rname, + int res_type) +{ + CU_DEBUG("Deleting resources within libvirt pools not supported"); + return 0; +} #endif /* diff -r d047a30a9ea3 -r 2ca94acaa955 libxkutil/pool_parsing.h --- a/libxkutil/pool_parsing.h Tue Aug 25 13:38:23 2009 -0700 +++ b/libxkutil/pool_parsing.h Tue Aug 25 13:38:23 2009 -0700 @@ -92,6 +92,8 @@ int create_resource(virConnectPtr conn, const char *pname, const char *xml, int res_type); +int delete_resource(virConnectPtr conn, const char *rname, int res_type); + #endif /*

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1251232703 25200 # Node ID a0297a6cdac8864acd43c873058beecaf54fca2b # Parent 2ca94acaa955045c3438053f3fa8f1277945f839 #2 Add delete_resource_in_pool to RPCS. This can be tested in a similar manner to how create_resource_in_pool() is tested. Create a storage volume within an existing pool prior to calling DeleteResourceInPool(). Updates: -Get the path to the image from the instance's Address attribute Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r 2ca94acaa955 -r a0297a6cdac8 src/Virt_ResourcePoolConfigurationService.c --- a/src/Virt_ResourcePoolConfigurationService.c Tue Aug 25 13:38:23 2009 -0700 +++ b/src/Virt_ResourcePoolConfigurationService.c Tue Aug 25 13:38:23 2009 -0700 @@ -959,6 +959,105 @@ return s; } +static CMPIStatus delete_resource_parse_args(const CMPIArgs *argsin, + CMPIInstance **resource, + CMPIObjectPath **pool) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + + if (cu_get_inst_arg(argsin, "Resource", resource) != CMPI_RC_OK) { + CU_DEBUG("Failed to get Resource arg"); + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_INVALID_PARAMETER, + "Missing argument `Resource'"); + goto out; + } + + if (cu_get_ref_arg(argsin, "Pool", pool) != CMPI_RC_OK) { + CU_DEBUG("Failed to get Pool reference arg"); + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_INVALID_PARAMETER, + "Missing argument `Pool'"); + goto out; + } + + out: + return s; +} + +static CMPIStatus delete_resource_in_pool(CMPIMethodMI *self, + const CMPIContext *context, + const CMPIResult *results, + const CMPIObjectPath *reference, + const CMPIArgs *argsin, + CMPIArgs *argsout) +{ + uint32_t rc = CIM_SVPC_RETURN_FAILED; + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *resource; + CMPIObjectPath *pool; + CMPIObjectPath *res; + const char *id = NULL; + virConnectPtr conn = NULL; + uint16_t type; + + CU_DEBUG("DeleteResourceInPool"); + + s = delete_resource_parse_args(argsin, &resource, &pool); + if (s.rc != CMPI_RC_OK) + goto out; + + res = CMGetObjectPath(resource, &s); + if ((res == NULL) && (s.rc != CMPI_RC_OK)) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to get ObjectPath of Resource instance"); + goto out; + } + + if (res_type_from_rasd_classname(CLASSNAME(res), &type) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to get resource type"); + goto out; + } + + if (type == CIM_RES_TYPE_DISK) + type = CIM_RES_TYPE_IMAGE; + + if (cu_get_str_prop(resource, "Address", &id) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Missing Address in resource RASD"); + goto out; + } + + conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s); + if (conn == NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "libvirt connection failed"); + goto out; + } + + if (delete_resource(conn, id, type) == 0) { + virt_set_status(_BROKER, &s, + CMPI_RC_ERR_FAILED, + conn, + "Unable to delete resource"); + goto out; + } + + out: + virConnectClose(conn); + + if (s.rc == CMPI_RC_OK) + rc = CIM_SVPC_RETURN_COMPLETED; + CMReturnData(results, &rc, CMPI_uint32); + + return s; +} + static CMPIStatus dummy_handler(CMPIMethodMI *self, const CMPIContext *context, const CMPIResult *results, @@ -1014,6 +1113,15 @@ } }; +static struct method_handler DeleteResourceInPool = { + .name = "DeleteResourceInPool", + .handler = delete_resource_in_pool, + .args = {{"Resource", CMPI_instance, true}, + {"Pool", CMPI_ref, true}, + ARG_END + } +}; + static struct method_handler *my_handlers[] = { &CreateResourcePool, &CreateChildResourcePool, @@ -1021,6 +1129,7 @@ &RemoveResourcesFromResourcePool, &DeleteResourcePool, &CreateResourceInPool, + &DeleteResourceInPool, NULL, };

+1 On 08/28/2009 08:13 PM, Kaitlin Rupert wrote:
This is the first set of changes. There needs to be a follow up patch to enumerate the storage volumes - some way other than via the SDC association.
Updates: -This fixes the image deletion code so that the user can pass one of the RASDs returned from SDC.
_______________________________________________ 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