From Fedora Project Wiki

< LVM‎ | liblvm

Line 49: Line 49:
   char** config_options; /* default: NULL */
   char** config_options; /* default: NULL */
   char** config_values; /* default: NULL */
   char** config_values; /* default: NULL */
  char* last_error_message; /* default: NULL */
};
};



Revision as of 16:53, 2 December 2008

High Level API Proposal

liblvm/liblvm.h

#include "handle.h"
#include "units.h"
#include "physical_volume.h"

/*
 * lvm_init
 *   Initialize LVM
 */
lvm_handle lvm_init(const char *system_dir=NULL);

/*
 * lvm_release
 *   Release LVM
 */
int lvm_release(lvm_handle handle);

/*
 * lvm_reload_config
 * Reload configuration files
 */
int lvm_reload_config(lvm_handle handle);

/*
 * lvm_set_config_option
 *   Load an lvm config option into the existing configuration.
 *
 *   The formation of the option parameter is similar to the names
 *   in /etc/lvm/lvm.conf.
 *   An option within a section is specified with a '/' between
 *   the section name and option.  For example, the 'filter' option
 *   in the devices section is specified by 'devices/filter'
 */
int lvm_set_config_option(lvm_handle h, const char *option,
                          const char *value);
/*
 * lvm_remove_config_option
 */
int lvm_remove_config_option(lvm_handle h, const char *option);

liblvm/handle.h

struct _lvm_handle {
  char* config_file; /* default: NULL */
  char** config_options; /* default: NULL */
  char** config_values; /* default: NULL */
};

typedef struct _lvm_handle lvm_handle;

liblvm/physical_volume.h

#include "handle.h"

/*
 * lvm physical volume information
 */
struct lvm_physical_volume {
  char* pv_name;
  char* vg_name;
  uint64_t pv_size; /* bytes */
  uint64_t dev_size; /* bytes */
  uint64_t pe_size; /* bytes */
  uint64_t total_pe;
  uint64_t free_pe;
  char* uuid;
};

/*
 * lvm physical volume information list
 */
struct lvm_physical_volume_list {
  struct lvm_physical_volume *last, *next;
}

/*
 * private lvm pv object for physical volume creation and modification
 */
typedef struct lvm_pv_obj {
  char* phys_vol;
  uint64_t size;
  int64_t labelsector;
  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
 *   scans all supported LVM block devices in the system for physical volumes
 *   and gets attibutes of all physicalvolume
 *   returns: status
 */
int lvm_pv_scan(lvm_handle h, struct LVM_PYSICAL_VOLUME** pv_return,
                uint32_t* pv_count);

/*
 * lvm_pv_get
 *   gets attibutes of one physicalvolume by volume path
 *   returns: status
 */
int lvm_pv_get(lvm_handle h, struct lvm_physical_volume* pv_return,
               const char* phys_vol_path);


/*
 * lvm_pv_list
 *   gets attibutes of all physicalvolume by volume paths
 *   returns: status
 */
int lvm_pv_list(lvm_handle h, struct lvm_physical_volume_list* pv_return,
                const char** phys_vol_paths, uint32_t* pv_count);

/*
 * lvm_pv_remove
 *   removes a physicalvolume by volume path
 *   returns: status
 */
int lvm_pv_remove(lvm_handle h, const char* phys_vol_path);

/*
 * lvm_pv_create
 *   creates a physicalvolume object model with accessors and mutators
 */

/*
 * usage example: 
 * 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);
 */

lvm_pv_obj_t* lvm_pv_obj_create(const char* phys_vol);
/* accessors */
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);
int lvm_pv_create(lvm_handle h, lvm_pv_obj_t* pv_obj, int zero);

/*
 * lvm_pv_change
 *   changes physicalvolume parameters
 */
int lvm_pv_obj_get(const char* phys_vol, lvm_pv_obj_t* pv_obj_return);
int lvm_pv_change(lvm_handle h, lvm_pv_obj_t* pv_obj);

/*
 * lvm_pv_restore_from
 *  restore physicalvolume parameters, use lvm_pv_change afterwards
 */
int lvm_pv_obj_restore_from(const char* uuid,
                            lvm_pv_obj_t* pv_obj_return,
                            const char* restore_file);
/*
 * lvm_pv_fsck
 */
int lvm_pv_fsck(const char* phys_vol, int64_t labelsector);