[Libvirt-cim] [PATCH] Pool Refresh Patch2

Chip Vincent cvincent at linux.vnet.ibm.com
Tue Feb 28 18:11:14 UTC 2012


+1 and pushed.

On 02/24/2012 02:20 PM, Gareth S Bestor wrote:
> From: Gareth S. Bestor<bestor at us.ibm.com>
>
> This patches earlier patch (from Sharad) that added pool refresh function to
> libvirt-cim. Previously, a pool refresh would be initiated whenever the pool's
> CIM instance was retreived; this turns out to be too expensive for some
> consumers. This patch removes that, and instead makes pool refresh an
> explicit CIM operation that a CIM client can request on the
> KVM_ResourcePoolConfigurationService (eg when pool resources are added or
> removed or changes outside of CIM). The previous patch also initiated a
> refresh whenever libvirt-cim was used to add or remove a pool resource; this
> fuction has been kept, because it makes sense for the CIM pool to immediately
> reflect any changes when resources are added/removed via CIM.
> The new extrinsic method is called RefreshResourcesInPool[<pool>]
>
> Signed-off-by: Gareth S. Bestor<bestor at us.ibm.com>
> ---
>   schema/ResourcePoolConfigurationService.mof |   12 ++++
>   src/Virt_DevicePool.c                       |    4 -
>   src/Virt_ResourcePoolConfigurationService.c |   93 +++++++++++++++++++++++++++
>   3 files changed, 105 insertions(+), 4 deletions(-)
>
> diff --git a/schema/ResourcePoolConfigurationService.mof b/schema/ResourcePoolConfigurationService.mof
> index 9199f08..7fd1cbd 100644
> --- a/schema/ResourcePoolConfigurationService.mof
> +++ b/schema/ResourcePoolConfigurationService.mof
> @@ -76,6 +76,18 @@ class KVM_ResourcePoolConfigurationService : CIM_ResourcePoolConfigurationServic
>         CIM_ConcreteJob REF Job
>       );
>
> +    [Description ( "Refresh the list of resource within a specified pool to "
> +                   "reflect any external changes. If 0 is returned, the "
> +                   "function completed successfully." )]
> +    uint32 RefreshResourcesInPool(
> +      [IN, Description ( "The pool to refresh the resource in." )]
> +      CIM_ResourcePool REF Pool,
> +
> +      [IN ( false ), OUT, Description ( "Reference to the job (may be null "
> +                                        "if job completed)." )]
> +      CIM_ConcreteJob REF Job
> +    );
> +
>   };
>
>   [Provider("cmpi::Virt_ResourcePoolConfigurationService")]
> diff --git a/src/Virt_DevicePool.c b/src/Virt_DevicePool.c
> index fe5573f..def8454 100644
> --- a/src/Virt_DevicePool.c
> +++ b/src/Virt_DevicePool.c
> @@ -186,10 +186,6 @@ static bool diskpool_set_capacity(virConnectPtr conn,
>                   goto out;
>           }
>
> -        if ((virStoragePoolRefresh(pool, 0)) == -1)
> -                CU_DEBUG("Unable to refresh storage pool");
> -
> -
>           if (virStoragePoolGetInfo(pool,&info) == -1) {
>                   CU_DEBUG("Failed to get info for pool `%s'", _pool->tag);
>                   goto out;
> diff --git a/src/Virt_ResourcePoolConfigurationService.c b/src/Virt_ResourcePoolConfigurationService.c
> index 7e76032..751d016 100644
> --- a/src/Virt_ResourcePoolConfigurationService.c
> +++ b/src/Virt_ResourcePoolConfigurationService.c
> @@ -1075,6 +1075,90 @@ static CMPIStatus delete_resource_in_pool(CMPIMethodMI *self,
>           return s;
>   }
>
> +static CMPIStatus refresh_resources_parse_args(const CMPIArgs *argsin,
> +                                               CMPIObjectPath **pool)
> +{
> +        CMPIStatus s = {CMPI_RC_OK, NULL};
> +
> +        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 refresh_resources_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 *pool;
> +        virStoragePoolPtr poolPtr;
> +        char *pool_id = NULL;
> +        const char *id = NULL;
> +        virConnectPtr conn = NULL;
> +
> +        CU_DEBUG("RefreshResourcesInPool");
> +
> +        s = refresh_resources_parse_args(argsin,&pool);
> +        if (s.rc != CMPI_RC_OK)
> +                goto out;
> +
> +        if (cu_get_str_path(pool, "InstanceID",&id) != CMPI_RC_OK) {
> +                cu_statusf(_BROKER,&s,
> +                           CMPI_RC_ERR_FAILED,
> +                           "Missing InstanceID in resource pool");
> +                goto out;
> +        }
> +
> +        pool_id = name_from_pool_id(id);
> +        if (pool_id == NULL) {
> +                cu_statusf(_BROKER,&s,
> +                           CMPI_RC_ERR_INVALID_PARAMETER,
> +                           "Pool has invalid InstanceID");
> +                goto out;
> +        }
> +
> +        conn = connect_by_classname(_BROKER, CLASSNAME(reference),&s);
> +        if (conn == NULL) {
> +                cu_statusf(_BROKER,&s,
> +                           CMPI_RC_ERR_FAILED,
> +                           "Unable to connect to hypervisor");
> +                goto out;
> +        }
> +
> +        poolPtr = virStoragePoolLookupByName(conn, pool_id);
> +        if (poolPtr == NULL) {
> +                CU_DEBUG("Failed to lookup storage pool `%s'", pool_id);
> +                goto out;
> +        }
> +
> +        if ((virStoragePoolRefresh(poolPtr, 0)) == -1) {
> +                CU_DEBUG("Unable to refresh storage pool");
> +        }
> +        else
> +                CU_DEBUG("Refreshed resources in storage pool `%s'", pool_id);
> +        virStoragePoolFree(poolPtr);
> +
> + out:
> +        free(pool_id);
> +
> +        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,
> @@ -1139,6 +1223,14 @@ static struct method_handler DeleteResourceInPool = {
>           }
>   };
>
> +static struct method_handler RefreshResourcesInPool = {
> +        .name = "RefreshResourcesInPool",
> +        .handler = refresh_resources_in_pool,
> +        .args = {{"Pool", CMPI_ref, true},
> +                 ARG_END
> +        }
> +};
> +
>   static struct method_handler *my_handlers[] = {
>           &CreateResourcePool,
>           &CreateChildResourcePool,
> @@ -1147,6 +1239,7 @@ static struct method_handler *my_handlers[] = {
>           &DeleteResourcePool,
>           &CreateResourceInPool,
>           &DeleteResourceInPool,
> +&RefreshResourcesInPool,
>           NULL,
>   };
>


-- 
Chip Vincent
Open Virtualization
IBM Linux Technology Center
cvincent at linux.vnet.ibm.com




More information about the Libvirt-cim mailing list