2001-09-25 16:49:28 +04:00
/*
* Copyright ( C ) 2001 Sistina Software
*
2001-09-28 17:15:30 +04:00
* This file is released under the GPL .
2001-09-25 16:49:28 +04:00
*
2001-10-02 02:12:10 +04:00
* This is the in core representation of a volume group and its
2001-09-28 17:15:30 +04:00
* associated physical and logical volumes .
2001-09-25 16:49:28 +04:00
*/
2001-10-01 19:14:39 +04:00
# ifndef _LVM_METADATA_H
# define _LVM_METADATA_H
2001-09-25 16:49:28 +04:00
2001-10-02 02:12:10 +04:00
# include <sys/types.h>
2001-10-01 20:21:21 +04:00
# include "dev-cache.h"
2001-10-02 21:09:05 +04:00
# include "list.h"
2001-10-01 20:21:21 +04:00
2001-09-28 17:15:30 +04:00
# define ID_LEN 32
2001-10-02 21:09:05 +04:00
# define NAME_LEN 128
2001-10-02 02:12:10 +04:00
/* Various flags */
/* Note that the bits no longer necessarily correspond to LVM1 disk format */
2001-10-05 17:03:03 +04:00
# define ACTIVE 0x00000001 /* PV VG LV */
# define EXPORTED_VG 0x00000002 /* VG */ /* And PV too perhaps? */
# define EXTENDABLE_VG 0x00000004 /* VG */
# define ALLOCATED_PV 0x00000008 /* PV */
2001-10-02 02:12:10 +04:00
2001-10-05 17:03:03 +04:00
# define SPINDOWN_LV 0x00000010 /* LV */
# define BADBLOCK_ON 0x00000020 /* LV */
2001-10-02 02:12:10 +04:00
2001-10-05 17:03:03 +04:00
# define LVM_READ 0x00000100 /* LV VG */
# define LVM_WRITE 0x00000200 /* LV VG */
# define CLUSTERED 0x00000400 /* VG */
# define SHARED 0x00000800 /* VG */
2001-10-02 02:12:10 +04:00
2001-10-05 17:03:03 +04:00
# define ALLOC_STRICT 0x00001000 /* LV */
# define ALLOC_CONTIGUOUS 0x00002000 /* LV */
# define SNAPSHOT 0x00004000 /* LV */
# define SNAPSHOT_ORG 0x00008000 /* LV */
2001-10-02 02:12:10 +04:00
2001-10-02 21:09:05 +04:00
# define EXPORTED_TAG "PV_EXP" /* Identifier of exported PV */
# define IMPORTED_TAG "PV_IMP" /* Identifier of imported PV */
2001-09-28 17:15:30 +04:00
struct id {
2001-10-04 14:13:07 +04:00
uint8_t uuid [ ID_LEN ] ;
2001-09-28 17:15:30 +04:00
} ;
2001-09-25 16:49:28 +04:00
2001-09-28 17:15:30 +04:00
struct physical_volume {
struct id * id ;
struct device * dev ;
2001-10-05 17:03:03 +04:00
char * vg_name ; /* VG component of name only - not full path */
2001-10-02 21:09:05 +04:00
char * exported ;
2001-09-25 16:49:28 +04:00
2001-10-04 14:13:07 +04:00
uint32_t status ;
uint64_t size ;
2001-09-25 16:49:28 +04:00
2001-09-28 17:15:30 +04:00
/* physical extents */
2001-10-04 14:13:07 +04:00
uint64_t pe_size ;
uint64_t pe_start ;
uint32_t pe_count ;
uint32_t pe_allocated ;
2001-09-28 17:15:30 +04:00
} ;
2001-09-25 16:49:28 +04:00
2001-09-28 17:15:30 +04:00
struct pe_specifier {
struct physical_volume * pv ;
2001-10-04 14:13:07 +04:00
uint32_t pe ;
2001-09-28 17:15:30 +04:00
} ;
2001-09-25 16:49:28 +04:00
2001-09-28 17:15:30 +04:00
struct logical_volume {
/* disk */
struct id * id ;
2001-10-05 17:03:03 +04:00
char * name ; /* LV component of name only - not full path */
2001-09-25 16:49:28 +04:00
2001-10-04 14:13:07 +04:00
uint32_t status ;
uint32_t open ;
2001-09-25 16:49:28 +04:00
2001-10-04 14:13:07 +04:00
uint64_t size ;
uint32_t le_count ;
2001-09-25 16:49:28 +04:00
2001-09-28 17:15:30 +04:00
/* le -> pe mapping array */
struct pe_specifier * map ;
} ;
2001-09-25 16:49:28 +04:00
2001-09-28 17:15:30 +04:00
struct volume_group {
struct id * id ;
2001-10-05 17:03:03 +04:00
char * name ; /* VG component of name only - not full path */
2001-09-25 16:49:28 +04:00
2001-10-04 14:13:07 +04:00
uint32_t status ;
2001-10-03 16:34:08 +04:00
2001-10-04 14:13:07 +04:00
uint64_t extent_size ;
uint32_t extent_count ;
uint32_t free_count ;
2001-09-25 16:49:28 +04:00
2001-10-04 14:13:07 +04:00
uint32_t max_lv ;
uint32_t max_pv ;
2001-10-04 00:38:07 +04:00
2001-09-28 17:15:30 +04:00
/* physical volumes */
2001-10-04 14:13:07 +04:00
uint32_t pv_count ;
2001-09-28 17:15:30 +04:00
struct physical_volume * * pv ;
2001-09-25 16:49:28 +04:00
2001-09-28 17:15:30 +04:00
/* logical volumes */
2001-10-04 14:13:07 +04:00
uint32_t lv_count ;
2001-09-28 17:15:30 +04:00
struct logical_volume * * lv ;
} ;
2001-09-25 16:49:28 +04:00
2001-10-05 02:53:37 +04:00
struct name_list {
2001-10-02 21:09:05 +04:00
struct list_head list ;
2001-10-05 02:53:37 +04:00
char * name ;
2001-10-02 21:09:05 +04:00
} ;
struct pv_list {
struct list_head list ;
struct physical_volume pv ;
} ;
2001-10-02 02:12:10 +04:00
2001-09-28 17:15:30 +04:00
/* ownership of returned objects passes */
struct io_space {
2001-10-05 17:03:03 +04:00
/* Returns list of names of all vgs - vg component only, not full path*/
2001-10-05 02:53:37 +04:00
struct name_list * ( * get_vgs ) ( struct io_space * is ) ;
/* Returns list of fully-populated pv structures */
2001-10-02 21:09:05 +04:00
struct pv_list * ( * get_pvs ) ( struct io_space * is ) ;
2001-09-25 16:49:28 +04:00
2001-10-05 02:53:37 +04:00
/* Return PV with given name (may be full or relative path) */
2001-10-02 02:12:10 +04:00
struct physical_volume * ( * pv_read ) ( struct io_space * is ,
2001-10-05 02:53:37 +04:00
const char * pv_name ) ;
/* Write a PV structure to disk. */
2001-10-05 17:03:03 +04:00
/* Fails if the PV is in a VG ie pv->vg_name must be null */
2001-10-02 02:12:10 +04:00
int ( * pv_write ) ( struct io_space * is , struct physical_volume * pv ) ;
2001-09-25 16:49:28 +04:00
2001-10-05 17:03:03 +04:00
/* if vg_name doesn't contain any slash, this function adds prefix */
2001-10-01 20:21:21 +04:00
struct volume_group * ( * vg_read ) ( struct io_space * is ,
2001-09-28 17:15:30 +04:00
const char * vg_name ) ;
2001-10-05 02:53:37 +04:00
/* Write out complete VG metadata. */
2001-10-05 17:03:03 +04:00
/* Ensure *internal* consistency before writing anything.
2001-10-05 02:53:37 +04:00
* eg . PEs can ' t refer to PVs not part of the VG
* Order write sequence to aid recovery if process is aborted
2001-10-05 17:03:03 +04:00
* ( eg flush entire set of changes to each disk in turn )
* It is the responsibility of the caller to ensure external
* consistency , eg by calling pv_write ( ) if removing PVs from a VG
* or calling vg_write ( ) a second time if splitting a VG into two .
* vg_write ( ) must not read or write from any PVs not included
* in the volume_group structure it is handed .
2001-10-05 02:53:37 +04:00
*/
2001-10-01 20:21:21 +04:00
int ( * vg_write ) ( struct io_space * is , struct volume_group * vg ) ;
2001-10-05 02:53:37 +04:00
2001-10-02 02:12:10 +04:00
void ( * destroy ) ( struct io_space * is ) ;
2001-09-25 16:49:28 +04:00
2001-10-05 17:03:03 +04:00
/* Current volume group prefix. */
char * prefix = ' / dev / ' ;
2001-10-01 20:21:21 +04:00
struct dev_filter * filter ;
2001-09-28 17:15:30 +04:00
void * private ;
} ;
2001-09-25 16:49:28 +04:00
2001-10-02 02:12:10 +04:00
/* FIXME: Move to other files */
struct io_space * create_text_format ( struct dev_filter * filter ,
2001-09-28 17:15:30 +04:00
const char * text_file ) ;
2001-10-02 02:12:10 +04:00
struct io_space * create_lvm_v1_format ( struct dev_filter * filter ) ;
2001-09-25 16:49:28 +04:00
2001-10-05 02:53:37 +04:00
inline int write_backup ( struct io_space * orig , struct io_space * text )
{
}
2001-09-28 17:15:30 +04:00
int id_eq ( struct id * op1 , struct id * op2 ) ;
2001-10-05 02:53:37 +04:00
/* Create consistent new empty structures, populated with defaults */
2001-10-02 02:12:10 +04:00
struct volume_group * vg_create ( ) ;
struct physical_volume * pv_create ( ) ;
2001-09-28 17:15:30 +04:00
2001-10-02 02:12:10 +04:00
int vg_destroy ( struct volume_group * vg ) ;
2001-10-05 02:53:37 +04:00
/* Manipulate PV structures */
2001-10-02 02:12:10 +04:00
int pv_add ( struct volume_group * vg , struct physical_volume * pv ) ;
2001-10-03 16:34:08 +04:00
int pv_remove ( struct volume_group * vg , struct physical_volume * pv ) ;
2001-10-02 02:12:10 +04:00
struct physical_volume * pv_find ( struct volume_group * vg ,
2001-10-03 16:34:08 +04:00
const char * pv_name ) ;
2001-09-25 16:49:28 +04:00
2001-10-05 02:53:37 +04:00
/* Add an LV to a given VG */
2001-10-02 02:12:10 +04:00
int lv_add ( struct volume_group * vg , struct logical_volume * lv ) ;
2001-10-05 02:53:37 +04:00
/* Remove an LV from a given VG */
2001-10-03 16:34:08 +04:00
int lv_remove ( struct volume_group * vg , struct logical_volume * lv ) ;
2001-10-05 02:53:37 +04:00
2001-10-05 17:03:03 +04:00
/* ? Return the VG that contains a given LV (based on path given in lv_name) */
2001-10-05 02:53:37 +04:00
/* (or environment var?) */
struct volume_group * vg_find ( const char * lv_name ) ;
/* Find an LV within a given VG */
struct logical_volume * lv_find ( struct volume_group * vg , const char * lv_name ) ;
2001-09-28 17:15:30 +04:00
# endif