From Fedora Project Wiki

< LVM‎ | liblvm

 
Line 1: Line 1:
== High Level API Proposal ==
== High Level API Proposal ==
<pre>
/********************************* lvm handle ********************************/
/*
* lvm_handle_t
*/
struct lib_context; /* internal context data */
typedef struct lib_context *lvm_handle_t;


liblvm/liblvm.h
/*
<pre>
* lvm_create
#include "handle.h"
*
#include "units.h"
* Description: Create an LVM handle used in many other APIs.
#include "physical_volume.h"
* Parameters:  system directory: path or NULL
* Returns:    NULL: Fail - unable to initialise handle.
*              non-NULL: Success - valid LVM handle returned
*/
lvm_handle_t lvm_create(const char *system_dir);
 
/*
* lvm_destroy
*
* Description: Destroy an LVM handle allocated with lvm_create
* Parameters:  libh (IN): handle obtained from lvm_create
*/
int lvm_destroy(lvm_handle_t libh);


/*
/*
  * lvm_init
  * lvm_mknodes
  *   Initialize LVM
  *  
* Description: (Re)Create device nodes for volume path.
*              The volume path can be a volume group, logical volume or NULL.
*              If volume is NULL, then all devides will be (re)created.
* Parameters:  libh (IN): handle obtained from lvm_create
* Returns:    Status
  */
  */
lvm_handle lvm_init(const char *system_dir=NULL);
int lvm_mknodes(lvm_handle_t libh, const char *volume);
 
/****************************** physical volume ******************************/


/*
/*
  * lvm_release
  * The lvm physical volume object.
*  Release LVM
  */
  */
int lvm_release(lvm_handle handle);
struct lvm_pv_obj;
typedef struct lvm_pv_obj *lvm_pv_obj_t; /* with mode inside (r/rw) */


/*
/*
  * lvm_reload_config
  * The lvm physical volume object list.
* Reload configuration files
  */
  */
int lvm_reload_config(lvm_handle handle);
typedef struct lvm_pv_list {
  dm_list list;
  lvm_pv_obj_t obj;
} *lvm_pv_list_t;


/*
/*
  * lvm_set_config_option
  * lvm_pv_obj_get
*  Load an lvm config option into the existing configuration.
  *
  *
  *   The formation of the option parameter is similar to the names
  * Description: Get object for a physical volume by volume path
  *   in /etc/lvm/lvm.conf.
  * Retuns:      lvm_pv_obj_t on success, otherwide NULL. errno is used to
  *   An option within a section is specified with a '/' between
  *             indicate the error.
  *   the section name and option. For example, the 'filter' option
  * Parameters: phys_vol: device
  *   in the devices section is specified by 'devices/filter'
  *             mode: "r" or "rw"
  */
  */
int lvm_set_config_option(lvm_handle h, const char *option,
lvm_pv_obj_t lvm_pv_obj_get(lvm_handle_t libh, const char *phys_vol,
                          const char *value);
                            const char *mode);
 
/*
/*
  * lvm_remove_config_option
  * Returns list of physical volumes.
* Retuns lvm_pv_obj_list_t on success, otherwide NULL. errno is used to
* indicate the error. The objects are read only.
  */
  */
int lvm_remove_config_option(lvm_handle h, const char *option);
lvm_pv_obj_list_t lvm_pv_obj_list(lvm_handle_t libh); /* rescan arg? */
</pre>
 
/* lvm_pv_obj_list_t lvm_pv_obj_scan(lvm_handle_t libh); */


liblvm/handle.h
/*
<pre>
* Creates object for a physical volume path. "Object is readonly."?
struct _lvm_handle {
* Retuns lvm_pv_obj_t on success, otherwide NULL. errno is used to indicate
  char* config_file; /* default: NULL */
* the error.
  char** config_options; /* default: NULL */
*/
  char** config_values; /* default: NULL */
lvm_pv_obj_t lvm_pv_obj_create(lvm_handle_t libh, const char *phys_vol);
};
 
/*
* Write physical volume obj to disk.
* Returns error code (see errno).
*/
int lvm_pv_obj_write(lvm_pv_obj_t pv_obj);
 
/*
* Closes and frees obj.
*/
int lvm_pv_obj_close(lvm_pv_obj_t pv_obj);
 
/*
* Closes and frees obj list.
*/
int lvm_pv_obj_list_close(lvm_pv_obj_list_t pv_obj_list);
 
/*
* Accessors and mutators for object attributes in memory.
*/
int lvm_pv_obj_set_attribute(lvm_pv_obj_t pv_obj, const char *attribute,
                            void *value);
void* lvm_pv_obj_get_attribute(lvm_pv_obj_t pv_obj, const char *attribute);


typedef struct _lvm_handle lvm_handle;
/*
</pre>
* Removes physical volume.
*/
int lvm_pv_obj_remove(lvm_pv_obj_t pv_obj);


liblvm/physical_volume.h
#ifdef FUTURE_FEATURE
<pre>
/*
#include "handle.h"
* Checks physical volume metadata for consistency.
*/
int lvm_pv_obj_check(lvm_pv_obj_t pv_obj);


/*
/*
  * lvm physical volume information
  * Loads physical volume attributes from a file using the UUID.
* Use lvm_pv_obj_write afterwards.
  */
  */
struct lvm_physical_volume {
lvm_pv_obj_t lvm_pv_obj_load_from(const char *uuid,
  char* pv_name;
                                  const char *restore_file);
  char* vg_name;
#endif /* FUTURE_FEATURE */
  uint64_t pv_size; /* bytes */
 
  uint64_t dev_size; /* bytes */
/******************************* volume group ********************************/
  uint64_t pe_size; /* bytes */
  uint64_t total_pe;
  uint64_t free_pe;
  char* uuid;
};


/*
/*
  * lvm physical volume information list
  * The lvm volume group object.
  */
  */
struct lvm_physical_volume_list {
struct lvm_vg_obj;
  struct lvm_physical_volume *last, *next;
typedef struct lvm_vg_obj *lvm_vg_obj_t; /* with mode inside (r/rw) */
}


/*
/*
  * private lvm pv object for physical volume creation and modification
  * The lvm volume group object list.
  */
  */
typedef struct lvm_pv_obj {
typedef struct lvm_vg_list {
   char* phys_vol;
   dm_list list;
   uint64_t size;
   lvm_vg_obj_t obj;
  int64_t labelsector;
} *lvm_vg_list_t;
  int metadata_copies;
  uint64_t metadata_size;
  uint32_t extent_count;
  uint32_t extent_size;
  const char* uuid; 
} lvm_pv_obj_t;


/*
/*
  * lvm_pv_scan
  * Gets object for a volume group by volume group name
  *   scans all supported LVM block devices in the system for physical volumes
  * Retuns lvm_vg_obj_t on success, otherwide NULL. errno is used to indicate
  *   and gets attibutes of all physicalvolume
  * the error.
  *   returns: status
  * mode: "r" or "rw"
  */
  */
int lvm_pv_scan(lvm_handle h, struct LVM_PYSICAL_VOLUME** pv_return,
lvm_vg_obj_t lvm_vg_obj_get(lvm_handle_t libh, const char *vol_group,
                uint32_t* pv_count);
                            const char *mode);


/*
/*
  * lvm_pv_get
  * Returns list of volumes groups.
  *   gets attibutes of one physicalvolume by volume path
  * Retuns lvm_vg_obj_list_t on success, otherwide NULL. errno is used to
  *   returns: status
  * indicate the error. The objects are read only.
  */
  */
int lvm_pv_get(lvm_handle h, struct lvm_physical_volume* pv_return,
lvm_vg_obj_list_t lvm_vg_obj_list(lvm_handle_t libh); /* rescan arg? */
              const char* phys_vol_path);


/* lvm_vg_obj_list_t lvm_vg_obj_scan(lvm_handle_t libh); */


/*
/*
  * lvm_pv_list
  * Creates object for a physical volume path. "Object is readonly."?
  *   gets attibutes of all physicalvolume by volume paths
  * Retuns lvm_pv_obj_t on success, otherwide NULL. errno is used to indicate
  *   returns: status
  * the error.
  */
  */
int lvm_pv_list(lvm_handle h, struct lvm_physical_volume_list* pv_return,
lvm_vg_obj_t lvm_vg_obj_create(lvm_handle_t libh, const char *vol_group,  
                const char** phys_vol_paths, uint32_t* pv_count);
                              lvm_pv_obj_t pv_obj);


/*
/*
  * lvm_pv_remove
  * Write volume group obj to disk.
*  removes a physicalvolume by volume path
  * Returns error code (see errno).
  *   returns: status
  */
  */
int lvm_pv_remove(lvm_handle h, const char* phys_vol_path);
int lvm_vg_obj_write(lvm_vg_obj_t vg_obj);


/*
/*
  * lvm_pv_create
  * Closes and frees obj.
*  creates a physicalvolume object model with accessors and mutators
  */
  */
int lvm_vg_obj_close(lvm_vg_obj_t vg_obj);


/*
/*
  * usage example:
  * Closes and frees obj list.
* lvm_pv_obj_t *pv = lvm_pv_obj_create("/dev/sda1");
* lvm_pv_obj_set_uuid(pv "WDhaBn-bSGn-EW98-DkI7-M8zB-R4S9-BPkFqS");
* status = lvm_pv_create(handle, pv, 1);
  */
  */
int lvm_vg_obj_list_close(lvm_vg_obj_list_t vg_obj_list);


lvm_pv_obj_t* lvm_pv_obj_create(const char* phys_vol);
/*
/* accessors */
* Accessors and mutators for object attributes in memory.
int lvm_pv_obj_set_attribute(lvm_pv_obj_t* pv_obj,  
*/
                            const char *attribute,
int lvm_vg_obj_set_attribute(lvm_vg_obj_t vg_obj, const char *attribute,
                             void *value);
                             void *value);
void* lvm_pv_obj_get_attribute(lvm_pv_obj_t* pv_obj,  
void* lvm_vg_obj_get_attribute(lvm_vg_obj_t vg_obj, const char *attribute);
                              const char *attribute);
 
int lvm_pv_create(lvm_handle h, lvm_pv_obj_t* pv_obj, int zero);
/*
* Removes volume group.
*/
int lvm_vg_obj_remove(lvm_vg_obj_t vg_obj);
 
/*
* List physical volumes in volume group.
*/
lvm_pv_obj_list_t lvm_vg_obj_list_pvs(lvm_vg_obj_t vg_obj);
 
/*
* Extend volume group by physical volume.
*/
int lvm_vg_obj_add_pv(lvm_vg_obj_t vg_obj, lvm_pv_obj_t pv_obj);
 
/*
* Remove physical volume from volume group.
*/
int lvm_vg_obj_remove_pv(lvm_vg_obj_t vg_obj, lvm_pv_obj_t pv_obj);


/*
/*
  * lvm_pv_change
  * Activate physical volume.
*  changes physicalvolume parameters
  */
  */
int lvm_pv_obj_get(const char* phys_vol, lvm_pv_obj_t* pv_obj_return);
int lvm_vg_obj_activate(lvm_vg_obj_t vg_obj);
int lvm_pv_change(lvm_handle h, lvm_pv_obj_t* pv_obj);


/*
/*
  * lvm_pv_restore_from
  * Deactivate physical volume.
*  restore physicalvolume parameters, use lvm_pv_change afterwards
  */
  */
int lvm_pv_obj_restore_from(const char* uuid,
int lvm_vg_obj_deactivate(lvm_vg_obj_t vg_obj);
                            lvm_pv_obj_t* pv_obj_return,
 
                            const char* restore_file);
/*
/*
  * lvm_pv_fsck
  * Check if physical volume is active.
  */
  */
int lvm_pv_fsck(const char* phys_vol, int64_t labelsector);
int lvm_vg_obj_is_active(lvm_vg_obj_t vg_obj);
 
/****************************** logical volume *******************************/
 
struct lvm_lv_obj;
typedef struct lvm_lv_obj *lvm_lv_obj_t; /* with mode inside (r/rw) */
 
typedef struct lvm_lv_list {
  dm_list list;
  lvm_lv_obj_t obj;
} *lvm_lv_list_t;
 
lvm_lv_obj_t lvm_lv_obj_get(lvm_handle_t libh, const char *logical_vol,
                            const char *mode);
lvm_lv_obj_list_t lvm_lv_obj_list(lvm_handle_t libh); /* rescan arg? */
/* lvm_lv_obj_list_t lvm_lv_obj_scan(lvm_handle_t libh); */
lvm_lv_obj_t lvm_lv_obj_create(lvm_handle_t libh, const char *logical_vol,
                              lvm_vg_obj_t vg_obj);
int lvm_lv_obj_write(lvm_lv_obj_t lv_obj);
int lvm_lv_obj_close(lvm_lv_obj_t lv_obj);
int lvm_lv_obj_list_close(lvm_lv_obj_list_t lv_obj_list);
int lvm_lv_obj_set_attribute(lvm_lv_obj_t lv_obj, const char *attribute,
                            void *value);
void* lvm_lv_obj_get_attribute(lvm_lv_obj_t lv_obj, const char *attribute);
int lvm_lv_obj_remove(lvm_lv_obj_t lv_obj);
 
/********************************* examples **********************************
 
Example 1
---------
 
lvm_handle_t handle;
lvm_pv_obj_t pv_obj;
 
handle = lvm_create(NULL);
 
pv_obj = lvm_pv_obj_get(handle, "/dev/sda1", "r");
if (pv_obj == NULL) {
  fprintf(stderr, strerror(errno));
  lvm_destroy(handle);
  exit(-1);
}
 
printf("PV Name: '%s'\n", lvm_pv_obj_get_attribute(pv_obj, "pv_name"));
printf("VG Name: '%s'\n", lvm_pv_obj_get_attribute(pv_obj, "vg_name"));
 
lvm_pv_obj_close(pv_obj);
lvm_destroy(handle);
 
 
Example 2
---------
lvm_handle_t handle;
lvm_pv_obj_t pv_obj;
 
handle = lvm_create(NULL);
 
pv_obj = lvm_pv_obj_create(handle, "/dev/sda2");
if (pv_obj == NULL) {
  fprintf(stderr, strerror(errno));
  lvm_destroy(handle);
  exit(-1);
}
 
status = lvm_pv_obj_set_attribute(pv_obj, "uuid", "FOOBAR");
if (status == -1) {
  fprintf(stderr, "UUID is not valid.\n");
  lvm_pv_obj_close(pv_obj);
  lvm_destroy(handle);
  exit(-1);
}
 
status = lvm_pv_obj_write(pv_obj);
if (status == -1) {
  fprintf(stderr, "Creation of device failed.\n");
  lvm_pv_obj_close(pv_obj);
  lvm_destroy(handle);
  exit(-1);
}
 
lvm_pv_obj_close(pv_obj);
lvm_destroy(handle);
 
 
Example 3
---------
 
lvm_handle_t handle;
lvm_pv_obj_list_t pv_obj_list;
lvm_pv_obj_t pv_obj;
 
handle = lvm_create(NULL);
 
pv_obj_list = lvm_pv_obj_list(handle);
if (pv_obj_list == NULL) {
  fprintf(stderr, strerror(errno));
  lvm_destroy(handle);
  exit(-1);
}
 
/*TODO: dm_list_iterate_items ... */
 
lvm_pv_obj_close(pv_obj);
lvm_destroy(handle);
 
*******************************************************************************
 
ANACONDA:
---------
 
pvcreate:
  pvcreate -ff -y -v <node>
 
pvlist:
  pvdisplay -C --noheadings --units b --nosuffix --separator : \
    --options pv_name,vg_name,dev_size
  returns: [(dev, vg, size)]
 
vgactivate:
  vgchange -ay -v [<volgroup>]
  vgmknodes(volgroup)
 
vgcreate:
  vgcreate -v -An --physicalextentsize <PESize>k <vgname> <nodes>
 
vgcheckactive:
  lvs --noheadings --units b --nosuffix --separator : \
    --options vg_name,lv_name,attr
  returns: True if there is an active logical volume, else False
 
vgdeactivate:
  vgchange -an -v [<volgroup>]
 
vglist:
  vgdisplay -C --noheadings --units b --nosuffix --separator : \
    --options vg_name,vg_size,vg_extent_size
  returns: [(vg, size, pesize)]
 
vgmknodes:
  vgmknodes -v [<volgroup>]
 
vgremove:
  pvs = [ pv[0] for pv in pvlist() if pv[1] == vgname ]
  vgdeactivate(vgname)
  vgremove -v vgname
  for pvname in pvs:
    pvremove -ff -y -v pvname
    pvcreate -ff -y -v pvname
    wipeOtherMetadataFromPV(pvname)
 
vgscan:
  vgscan -v
 
lvcreate:
  vgscan()
  lvcreate -v -L <size>M -n <lvname> -An <vgname>
 
lvlist:
  lvdisplay -C --noheadings --units b --nosuffix --separator : \
    --options vg_name,lv_name,lv_size,origin
  returns: [(vg, lv, size, origin)]
 
lvremove:
  lvremove -f -v /dev/<vgname>/<lvname>
 
partialvgs:
  vgdisplay -C -P --noheadings --units b --nosuffix --separator :
  returns: [(vg)] if vgs are partial
 
******************************************************************************/
 
</pre>
</pre>

Latest revision as of 15:24, 11 February 2009

High Level API Proposal

/********************************* lvm handle ********************************/

/*
 * lvm_handle_t
 */
struct lib_context; /* internal context data */
typedef struct lib_context *lvm_handle_t;

/*
 * lvm_create
 *
 * Description: Create an LVM handle used in many other APIs.
 * Parameters:  system directory: path or NULL
 * Returns:     NULL: Fail - unable to initialise handle.
 *              non-NULL: Success - valid LVM handle returned
 */
lvm_handle_t lvm_create(const char *system_dir);

/*
 * lvm_destroy
 *
 * Description: Destroy an LVM handle allocated with lvm_create
 * Parameters:  libh (IN): handle obtained from lvm_create
 */
int lvm_destroy(lvm_handle_t libh);

/*
 * lvm_mknodes
 * 
 * Description: (Re)Create device nodes for volume path.
 *              The volume path can be a volume group, logical volume or NULL.
 *              If volume is NULL, then all devides will be (re)created.
 * Parameters:  libh (IN): handle obtained from lvm_create
 * Returns:     Status
 */
int lvm_mknodes(lvm_handle_t libh, const char *volume);

/****************************** physical volume ******************************/

/*
 * The lvm physical volume object.
 */
struct lvm_pv_obj;
typedef struct lvm_pv_obj *lvm_pv_obj_t; /* with mode inside (r/rw) */

/*
 * The lvm physical volume object list.
 */
typedef struct lvm_pv_list {
  dm_list list;
  lvm_pv_obj_t obj;
} *lvm_pv_list_t;

/*
 * lvm_pv_obj_get
 *
 * Description: Get object for a physical volume by volume path
 * Retuns:      lvm_pv_obj_t on success, otherwide NULL. errno is used to
 *              indicate the error.
 * Parameters:  phys_vol: device
 *              mode: "r" or "rw"
 */
lvm_pv_obj_t lvm_pv_obj_get(lvm_handle_t libh, const char *phys_vol,
                            const char *mode);

/*
 * Returns list of physical volumes.
 * Retuns lvm_pv_obj_list_t on success, otherwide NULL. errno is used to 
 * indicate the error. The objects are read only.
 */
lvm_pv_obj_list_t lvm_pv_obj_list(lvm_handle_t libh); /* rescan arg? */

/* lvm_pv_obj_list_t lvm_pv_obj_scan(lvm_handle_t libh); */

/*
 * Creates object for a physical volume path. "Object is readonly."?
 * Retuns lvm_pv_obj_t on success, otherwide NULL. errno is used to indicate 
 * the error.
 */
lvm_pv_obj_t lvm_pv_obj_create(lvm_handle_t libh, const char *phys_vol);

/*
 * Write physical volume obj to disk.
 * Returns error code (see errno).
 */
int lvm_pv_obj_write(lvm_pv_obj_t pv_obj);

/*
 * Closes and frees obj.
 */
int lvm_pv_obj_close(lvm_pv_obj_t pv_obj);

/*
 * Closes and frees obj list.
 */
int lvm_pv_obj_list_close(lvm_pv_obj_list_t pv_obj_list);

/*
 * Accessors and mutators for object attributes in memory.
 */
int lvm_pv_obj_set_attribute(lvm_pv_obj_t pv_obj, const char *attribute,
                             void *value);
void* lvm_pv_obj_get_attribute(lvm_pv_obj_t pv_obj, const char *attribute);

/*
 * Removes physical volume.
 */
int lvm_pv_obj_remove(lvm_pv_obj_t pv_obj);

#ifdef FUTURE_FEATURE
/*
 * Checks physical volume metadata for consistency.
 */
int lvm_pv_obj_check(lvm_pv_obj_t pv_obj);

/*
 * Loads physical volume attributes from a file using the UUID.
 * Use lvm_pv_obj_write afterwards.
 */
lvm_pv_obj_t lvm_pv_obj_load_from(const char *uuid,
                                  const char *restore_file);
#endif /* FUTURE_FEATURE */

/******************************* volume group ********************************/

/*
 * The lvm volume group object.
 */
struct lvm_vg_obj;
typedef struct lvm_vg_obj *lvm_vg_obj_t; /* with mode inside (r/rw) */

/*
 * The lvm volume group object list.
 */
typedef struct lvm_vg_list {
  dm_list list;
  lvm_vg_obj_t obj;
} *lvm_vg_list_t;

/*
 * Gets object for a volume group by volume group name
 * Retuns lvm_vg_obj_t on success, otherwide NULL. errno is used to indicate 
 * the error.
 * mode: "r" or "rw"
 */
lvm_vg_obj_t lvm_vg_obj_get(lvm_handle_t libh, const char *vol_group,
                            const char *mode);

/*
 * Returns list of volumes groups.
 * Retuns lvm_vg_obj_list_t on success, otherwide NULL. errno is used to 
 * indicate the error. The objects are read only.
 */
lvm_vg_obj_list_t lvm_vg_obj_list(lvm_handle_t libh); /* rescan arg? */

/* lvm_vg_obj_list_t lvm_vg_obj_scan(lvm_handle_t libh); */

/*
 * Creates object for a physical volume path. "Object is readonly."?
 * Retuns lvm_pv_obj_t on success, otherwide NULL. errno is used to indicate 
 * the error.
 */
lvm_vg_obj_t lvm_vg_obj_create(lvm_handle_t libh, const char *vol_group, 
                               lvm_pv_obj_t pv_obj);

/*
 * Write volume group obj to disk.
 * Returns error code (see errno).
 */
int lvm_vg_obj_write(lvm_vg_obj_t vg_obj);

/*
 * Closes and frees obj.
 */
int lvm_vg_obj_close(lvm_vg_obj_t vg_obj);

/*
 * Closes and frees obj list.
 */
int lvm_vg_obj_list_close(lvm_vg_obj_list_t vg_obj_list);

/*
 * Accessors and mutators for object attributes in memory.
 */
int lvm_vg_obj_set_attribute(lvm_vg_obj_t vg_obj, const char *attribute,
                             void *value);
void* lvm_vg_obj_get_attribute(lvm_vg_obj_t vg_obj, const char *attribute);

/*
 * Removes volume group.
 */
int lvm_vg_obj_remove(lvm_vg_obj_t vg_obj);

/*
 * List physical volumes in volume group.
 */
lvm_pv_obj_list_t lvm_vg_obj_list_pvs(lvm_vg_obj_t vg_obj);

/*
 * Extend volume group by physical volume.
 */
int lvm_vg_obj_add_pv(lvm_vg_obj_t vg_obj, lvm_pv_obj_t pv_obj);

/*
 * Remove physical volume from volume group.
 */
int lvm_vg_obj_remove_pv(lvm_vg_obj_t vg_obj, lvm_pv_obj_t pv_obj);

/*
 * Activate physical volume.
 */
int lvm_vg_obj_activate(lvm_vg_obj_t vg_obj);

/*
 * Deactivate physical volume.
 */
int lvm_vg_obj_deactivate(lvm_vg_obj_t vg_obj);

/*
 * Check if physical volume is active.
 */
int lvm_vg_obj_is_active(lvm_vg_obj_t vg_obj);

/****************************** logical volume *******************************/

struct lvm_lv_obj;
typedef struct lvm_lv_obj *lvm_lv_obj_t; /* with mode inside (r/rw) */

typedef struct lvm_lv_list {
  dm_list list;
  lvm_lv_obj_t obj;
} *lvm_lv_list_t;

lvm_lv_obj_t lvm_lv_obj_get(lvm_handle_t libh, const char *logical_vol,
                            const char *mode);
lvm_lv_obj_list_t lvm_lv_obj_list(lvm_handle_t libh); /* rescan arg? */
/* lvm_lv_obj_list_t lvm_lv_obj_scan(lvm_handle_t libh); */
lvm_lv_obj_t lvm_lv_obj_create(lvm_handle_t libh, const char *logical_vol,
                               lvm_vg_obj_t vg_obj);
int lvm_lv_obj_write(lvm_lv_obj_t lv_obj);
int lvm_lv_obj_close(lvm_lv_obj_t lv_obj);
int lvm_lv_obj_list_close(lvm_lv_obj_list_t lv_obj_list);
int lvm_lv_obj_set_attribute(lvm_lv_obj_t lv_obj, const char *attribute,
                             void *value);
void* lvm_lv_obj_get_attribute(lvm_lv_obj_t lv_obj, const char *attribute);
int lvm_lv_obj_remove(lvm_lv_obj_t lv_obj);

/********************************* examples **********************************

Example 1
---------

lvm_handle_t handle;
lvm_pv_obj_t pv_obj;

handle = lvm_create(NULL);

pv_obj = lvm_pv_obj_get(handle, "/dev/sda1", "r");
if (pv_obj == NULL) {
  fprintf(stderr, strerror(errno));
  lvm_destroy(handle);
  exit(-1);
}

printf("PV Name: '%s'\n", lvm_pv_obj_get_attribute(pv_obj, "pv_name"));
printf("VG Name: '%s'\n", lvm_pv_obj_get_attribute(pv_obj, "vg_name"));

lvm_pv_obj_close(pv_obj);
lvm_destroy(handle);


Example 2
---------
lvm_handle_t handle;
lvm_pv_obj_t pv_obj;

handle = lvm_create(NULL);

pv_obj = lvm_pv_obj_create(handle, "/dev/sda2");
if (pv_obj == NULL) {
  fprintf(stderr, strerror(errno));
  lvm_destroy(handle);
  exit(-1);
}

status = lvm_pv_obj_set_attribute(pv_obj, "uuid", "FOOBAR");
if (status == -1) {
  fprintf(stderr, "UUID is not valid.\n");
  lvm_pv_obj_close(pv_obj);
  lvm_destroy(handle);
  exit(-1);
}

status = lvm_pv_obj_write(pv_obj);
if (status == -1) {
  fprintf(stderr, "Creation of device failed.\n");
  lvm_pv_obj_close(pv_obj);
  lvm_destroy(handle);
  exit(-1);
}

lvm_pv_obj_close(pv_obj);
lvm_destroy(handle);


Example 3
---------

lvm_handle_t handle;
lvm_pv_obj_list_t pv_obj_list;
lvm_pv_obj_t pv_obj;

handle = lvm_create(NULL);

pv_obj_list = lvm_pv_obj_list(handle);
if (pv_obj_list == NULL) {
  fprintf(stderr, strerror(errno));
  lvm_destroy(handle);
  exit(-1);
}

/*TODO: dm_list_iterate_items ... */

lvm_pv_obj_close(pv_obj);
lvm_destroy(handle);

*******************************************************************************

ANACONDA:
---------

pvcreate:
  pvcreate -ff -y -v <node>

pvlist:
  pvdisplay -C --noheadings --units b --nosuffix --separator : \
    --options pv_name,vg_name,dev_size
  returns: [(dev, vg, size)]

vgactivate:
  vgchange -ay -v [<volgroup>]
  vgmknodes(volgroup)

vgcreate:
  vgcreate -v -An --physicalextentsize <PESize>k <vgname> <nodes>

vgcheckactive:
  lvs --noheadings --units b --nosuffix --separator : \
    --options vg_name,lv_name,attr
  returns: True if there is an active logical volume, else False

vgdeactivate:
  vgchange -an -v [<volgroup>]

vglist:
  vgdisplay -C --noheadings --units b --nosuffix --separator : \
    --options vg_name,vg_size,vg_extent_size
  returns: [(vg, size, pesize)]

vgmknodes:
  vgmknodes -v [<volgroup>]

vgremove:
  pvs = [ pv[0] for pv in pvlist() if pv[1] == vgname ]
  vgdeactivate(vgname)
  vgremove -v vgname
  for pvname in pvs:
    pvremove -ff -y -v pvname
    pvcreate -ff -y -v pvname
    wipeOtherMetadataFromPV(pvname)

vgscan:
  vgscan -v

lvcreate:
  vgscan()
  lvcreate -v -L <size>M -n <lvname> -An <vgname>

lvlist:
  lvdisplay -C --noheadings --units b --nosuffix --separator : \
    --options vg_name,lv_name,lv_size,origin
  returns: [(vg, lv, size, origin)]

lvremove:
  lvremove -f -v /dev/<vgname>/<lvname>

partialvgs:
  vgdisplay -C -P --noheadings --units b --nosuffix --separator :
  returns: [(vg)] if vgs are partial

******************************************************************************/