[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.

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1251232703 25200 # Node ID 1cb1a2dbdb0abb503898a851ab3b4d41ee85cab0 # Parent 9af5eef7ea76c7e9d1657d2e8cd4df9ed126b596 Add DeleteResourceInPool() to RPCS mof Also, fix a typo in the description for the out parameter in CreateResourceInPool() Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r 9af5eef7ea76 -r 1cb1a2dbdb0a 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,23 @@ [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." )] + CIM_ResourceAllocationSettingData REF 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 +55,23 @@ [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." )] + CIM_ResourceAllocationSettingData REF 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 +93,23 @@ [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." )] + CIM_ResourceAllocationSettingData REF 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 eb113fed5210d9d31e3b5eae684f27631c0a2ef2 # Parent 1cb1a2dbdb0abb503898a851ab3b4d41ee85cab0 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 1cb1a2dbdb0a -r eb113fed5210 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 1cb1a2dbdb0a -r eb113fed5210 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 f31abcfc4e9d141c8e83adfdffee50d45b9f1e1f # Parent eb113fed5210d9d31e3b5eae684f27631c0a2ef2 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(). Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r eb113fed5210 -r f31abcfc4e9d 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,94 @@ return s; } +static CMPIStatus delete_resource_parse_args(const CMPIArgs *argsin, + CMPIObjectPath **resource, + CMPIObjectPath **pool) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + + if (cu_get_ref_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}; + CMPIObjectPath *resource; + CMPIObjectPath *pool; + 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; + + if (res_type_from_rasd_classname(CLASSNAME(resource), &type) != + CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to get resource type"); + goto out; + } + + if (cu_get_str_path(resource, "InstanceID", &id) != CMPI_RC_OK) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Missing InstanceID 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 +1102,15 @@ } }; +static struct method_handler DeleteResourceInPool = { + .name = "DeleteResourceInPool", + .handler = delete_resource_in_pool, + .args = {{"Resource", CMPI_ref, true}, + {"Pool", CMPI_ref, true}, + ARG_END + } +}; + static struct method_handler *my_handlers[] = { &CreateResourcePool, &CreateChildResourcePool, @@ -1021,6 +1118,7 @@ &RemoveResourcesFromResourcePool, &DeleteResourcePool, &CreateResourceInPool, + &DeleteResourceInPool, NULL, };
participants (1)
-
Kaitlin Rupert