[PATCH 6/8] Add lvm_pv_get_property() generic function to obtain value of any pv property.

Petr Rockai <[email protected]>
Newsgroups dev.linux.lists.lvm-devel
Message-ID <[email protected].>
Dave Wysochanski <[email protected]> writes:

> Add a generic PV property function to lvm2app, similar to VG function.
> Return lvm_property_value and require caller to check 'is_valid' flag
> and lvm_errno() for API error.

If you go with my suggestion from previous patch about "including"
lvm_errno in is_valid, the docs in this patch will need to be changed
accordingly.

> Signed-off-by: Dave Wysochanski <[email protected]>
Reviewed-by: Petr Rockai <[email protected]>

Other than that, good to go.

> diff --git a/liblvm/lvm2app.h b/liblvm/lvm2app.h
> index 8b244fc..ed22ed9 100644
> --- a/liblvm/lvm2app.h
> +++ b/liblvm/lvm2app.h
> @@ -1240,6 +1240,44 @@ uint64_t lvm_pv_get_size(const pv_t pv);
>  uint64_t lvm_pv_get_free(const pv_t pv);
>  
>  /**
> + * Get the value of a PV property
> + *
> + * \memberof pv_t
> + *
> + * \param   pv
> + * Physical volume handle.
> + *
> + * \param   name
> + * Name of property to query.  See pvs man page for full list of properties
> + * that may be queried.
> + *
> + * The memory allocated for a string property value is tied to the vg_t
> + * handle and will be released when lvm_vg_close() is called.
> + *
> + * Example:
> + *      lvm_property_value value;
> + *      char *prop_name = "pv_mda_count";
> + *
> + *      v = lvm_pv_get_property(pv, prop_name);
> + *      if (lvm_errno(libh) || !v.is_valid) {
> + *           // handle error
> + *           printf("Invalid property name or unable to query"
> + *                  "'%s'.\n", prop_name);
> + *           return;
> + *      }
> + *      if (v.is_string)
> + *           printf(", value = %s\n", v.value.string);
> + *	else
> + *           printf(", value = %"PRIu64"\n", v.value.integer);
> + *
> + * \return
> + * lvm_property_value structure that will contain the current
> + * value of the property.  Caller should check lvm_errno() as well
> + * as 'is_valid' flag before using the value.
> + */
> +struct lvm_property_value lvm_pv_get_property(const pv_t pv, const char *name);
> +
> +/**
>   * Resize physical volume to new_size bytes.
>   *
>   * \memberof pv_t
> diff --git a/liblvm/lvm_pv.c b/liblvm/lvm_pv.c
> index 0b6b6b1..efdccb5 100644
> --- a/liblvm/lvm_pv.c
> +++ b/liblvm/lvm_pv.c
> @@ -16,6 +16,7 @@
>  #include "lvm2app.h"
>  #include "metadata.h"
>  #include "lvm-string.h"
> +#include "lvm_misc.h"
>  
>  const char *lvm_pv_get_uuid(const pv_t pv)
>  {
> @@ -48,6 +49,11 @@ uint64_t lvm_pv_get_free(const pv_t pv)
>  	return (uint64_t) SECTOR_SIZE * pv_free(pv);
>  }
>  
> +struct lvm_property_value lvm_pv_get_property(const pv_t pv, const char *name)
> +{
> +	return get_property(pv, NULL, NULL, name);
> +}
> +
>  int lvm_pv_resize(const pv_t pv, uint64_t new_size)
>  {
>  	/* FIXME: add pv resize code here */
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.