From Fedora Project Wiki

< LVM‎ | liblvm

Line 3: Line 3:
liblvm/liblvm.h
liblvm/liblvm.h
<pre>
<pre>
#include "error.h"
#include "handle.h"
#include "handle.h"
#include "units.h"
#include "units.h"
Line 18: Line 17:
  *  Release LVM
  *  Release LVM
  */
  */
lvm_error_status lvm_release(lvm_handle handle);
int lvm_release(lvm_handle handle);


/*
/*
Line 24: Line 23:
  * Reload configuration files
  * Reload configuration files
  */
  */
lvm_error_status lvm_reload_config(lvm_handle handle);
int lvm_reload_config(lvm_handle handle);
 
/*
* lvm_load_config_file
*  Load a lvm configuration file
*/
lvm_error_status lvm_load_config_file(lvm_handle h, const char *filename);


/*
/*
Line 42: Line 35:
  *  in the devices section is specified by 'devices/filter'
  *  in the devices section is specified by 'devices/filter'
  */
  */
lvm_error_status lvm_set_config_option(lvm_handle h, const char *option,
int lvm_set_config_option(lvm_handle h, const char *option,
                                      const char *value);
                          const char *value);
/*
/*
  * lvm_remove_config_option
  * lvm_remove_config_option
  */
  */
lvm_error_status lvm_remove_config_option(lvm_handle h, const char *option);
int lvm_remove_config_option(lvm_handle h, const char *option);
</pre>
</pre>


Line 61: Line 54:


typedef struct _lvm_handle lvm_handle;
typedef struct _lvm_handle lvm_handle;
</pre>
liblvm/error.h
<pre>
#include "handle.h"
enum _lvm_error_status {
        NO_ERROR = 0,
        INVALID_PV_NAME,
        INVALID_PV_SIZE,
        INVALID_DEV_SIZE,
        INVALID_PE_SIZE,
        INVALID_UUID,
        INVALID_LABEL_SECTOR,
        INVALID_METADATA_COPIES,
        INVALID_METADATA_SIZE,
        INVALID_PE_START,
        INVALID_EXTENT_COUNT,
        INVALID_EXTENT_SIZE,
       
        /* more to come */
};
typedef enum _lvm_error_status lvm_error_status;
/*
* lvm_strerror
*  Returns error string stored in the handle
*/
const char* lvm_strerror(lvm_handle h);
</pre>
</pre>


liblvm/physical_volume.h
liblvm/physical_volume.h
<pre>
<pre>
#incldue "error.h"
#include "handle.h"
#include "handle.h"


Line 111: Line 73:
   char* uuid;
   char* uuid;
};
};
/*
* lvm physical volume information list
*/
struct lvm_physical_volume_list {
  struct lvm_physical_volume *last, *next;
}


/*
/*
Line 121: Line 90:
   int metadata_copies;
   int metadata_copies;
   uint64_t metadata_size;
   uint64_t metadata_size;
  uint64_t pe_start;
   uint32_t extent_count;
   uint32_t extent_count;
   uint32_t extent_size;
   uint32_t extent_size;
Line 133: Line 101:
  *  returns: status
  *  returns: status
  */
  */
lvm_error_status lvm_pv_scan(lvm_handle h,
int lvm_pv_scan(lvm_handle h, struct LVM_PYSICAL_VOLUME** pv_return,
                            struct LVM_PYSICAL_VOLUME** pv_return,
                uint32_t* pv_count);
                            uint32_t* pv_count);


/*
/*
Line 142: Line 109:
  *  returns: status
  *  returns: status
  */
  */
lvm_error_status lvm_pv_get(lvm_handle h,
int lvm_pv_get(lvm_handle h, struct lvm_physical_volume* pv_return,
                            struct lvm_physical_volume* pv_return,
              const char* phys_vol_path);
                            const char* phys_vol_path);




Line 152: Line 118:
  *  returns: status
  *  returns: status
  */
  */
lvm_error_status lvm_pv_list(lvm_handle h,
int lvm_pv_list(lvm_handle h, struct lvm_physical_volume_list* pv_return,
                            struct lvm_physical_volume** pv_return,
                const char** phys_vol_paths, uint32_t* pv_count);
                            const char** phys_vol_paths, uint32_t* pv_count);


/*
/*
Line 161: Line 126:
  *  returns: status
  *  returns: status
  */
  */
lvm_error_status lvm_pv_remove(lvm_handle h, const char* phys_vol_path);
int lvm_pv_remove(lvm_handle h, const char* phys_vol_path);


/*
/*
Line 177: Line 142:
lvm_pv_obj_t* lvm_pv_obj_create(const char* phys_vol);
lvm_pv_obj_t* lvm_pv_obj_create(const char* phys_vol);
/* accessors */
/* accessors */
lvm_error_status lvm_pv_obj_set_volume(lvm_pv_obj_t* pv_obj,
int lvm_pv_obj_set_attribute(lvm_pv_obj_t* pv_obj,  
                                      const char* phys_vol);
                            const char *attribute,
lvm_error_status lvm_pv_obj_set_size(lvm_pv_obj_t* pv_obj, uint64t size);
                            void *value);
lvm_error_status lvm_pv_obj_set_labelsector(lvm_pv_obj_t* pv_obj,
void* lvm_pv_obj_get_attribute(lvm_pv_obj_t* pv_obj,  
                                            int64_t labelsector);
                              const char *attribute);
lvm_error_status lvm_pv_obj_set_metadata_copies(lvm_pv_obj_t* pv_obj,
int lvm_pv_create(lvm_handle h, lvm_pv_obj_t* pv_obj, int zero);
                                                int metadata_copies);
lvm_error_status lvm_pv_obj_set_metadata_size(lvm_pv_obj_t* pv_obj,
                                              uint64_t metadata_size);
lvm_error_status lvm_pv_obj_set_pe_start(lvm_pv_obj_t* pv_obj,
                                        uint64_t pe_start);
lvm_error_status lvm_pv_obj_set_extent_count(lvm_pv_obj_t* pv_obj,
                                            uint32_t extent_count);
lvm_error_status lvm_pv_obj_set_extent_size(lvm_pv_obj_t* pv_obj,
                                            uint32_t extent_size);
lvm_error_status lvm_pv_obj_set_uuid(lvm_pv_obj_t* pv_obj, const char* uuid);
lvm_error_status lvm_pv_obj_set_volume(lvm_pv_obj_t* pv_obj,
                                      const char* phys_vol);
/* mutators */
uint64_t lvm_pv_obj_get_size(lvm_pv_obj_t* pv_obj);
int64_t lvm_pv_obj_get_labelsector(lvm_pv_obj_t* pv_obj);
int lvm_pv_obj_get_metadata_copies(lvm_pv_obj_t* pv_obj);
uint64_t lvm_pv_obj_get_metadata_size(lvm_pv_obj_t* pv_obj);
uint64_t lvm_pv_obj_get_pe_start(lvm_pv_obj_t* pv_obj);
uint32_t lvm_pv_obj_get_extent_count(lvm_pv_obj_t* pv_obj);
uint32_t lvm_pv_obj_get_extent_size(lvm_pv_obj_t* pv_obj);
const char* lvm_pv_obj_get_uuid(lvm_pv_obj_t* pv_obj);
const char* lvm_error_status lvm_pv_obj_get_volume(lvm_pv_obj_t* pv_obj);
 
lvm_error_status lvm_pv_create(lvm_handle h, lvm_pv_obj_t* pv_obj, int zero);


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


/*
/*
Line 220: Line 160:
  *  restore physicalvolume parameters, use lvm_pv_change afterwards
  *  restore physicalvolume parameters, use lvm_pv_change afterwards
  */
  */
lvm_error_status lvm_pv_obj_restore_from(const char* uuid,
int lvm_pv_obj_restore_from(const char* uuid,
                                        lvm_pv_obj_t* pv_obj_return,
                            lvm_pv_obj_t* pv_obj_return,
                                        const char* restore_file);
                            const char* restore_file);
/*
/*
  * lvm_pv_fsck
  * lvm_pv_fsck
  */
  */
lvm_error_status lvm_pv_fsck(const char* phys_vol, int64_t labelsector);
int lvm_pv_fsck(const char* phys_vol, int64_t labelsector);
</pre>
</pre>

Revision as of 16:49, 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 */

  char* last_error_message; /* 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);