2001-09-25 12:49:28 +00:00
/*
2001-10-12 10:32:06 +00:00
* Copyright ( C ) 2001 Sistina Software ( UK ) Limited .
2001-09-25 12:49:28 +00:00
*
2001-11-27 16:37:33 +00:00
* This file is released under the LGPL .
2001-09-25 12:49:28 +00:00
*
2001-10-01 22:12:10 +00:00
* This is the in core representation of a volume group and its
2001-09-28 13:15:30 +00:00
* associated physical and logical volumes .
2001-09-25 12:49:28 +00:00
*/
2001-10-01 15:14:39 +00:00
# ifndef _LVM_METADATA_H
# define _LVM_METADATA_H
2001-09-25 12:49:28 +00:00
2002-11-18 14:04:08 +00:00
# include "ctype.h"
2001-10-01 16:21:21 +00:00
# include "dev-cache.h"
2001-10-02 17:09:05 +00:00
# include "list.h"
2001-10-12 10:32:06 +00:00
# include "uuid.h"
2002-12-19 23:25:55 +00:00
2002-11-18 14:04:08 +00:00
# include <sys/types.h>
# include <asm/page.h>
2001-10-01 16:21:21 +00:00
2001-10-02 17:09:05 +00:00
# define NAME_LEN 128
2001-12-03 16:27:16 +00:00
# define MAX_STRIPES 128
2002-11-18 14:04:08 +00:00
# define SECTOR_SHIFT 9L
# define SECTOR_SIZE ( 1L << SECTOR_SHIFT )
# define STRIPE_SIZE_MIN ( PAGE_SIZE >> SECTOR_SHIFT) /* PAGESIZE in sectors */
# define STRIPE_SIZE_MAX ( 512L * 1024L >> SECTOR_SHIFT) /* 512 KB in sectors */
# define PV_MIN_SIZE ( 512L * 1024L >> SECTOR_SHIFT) /* 512 KB in sectors */
# define PE_ALIGN (65536UL >> SECTOR_SHIFT) /* PE alignment */
2001-10-01 22:12:10 +00:00
/* Various flags */
/* Note that the bits no longer necessarily correspond to LVM1 disk format */
2002-11-18 14:04:08 +00:00
# define PARTIAL_VG 0x00000001 /* VG */
# define EXPORTED_VG 0x00000002 /* VG PV */
# define RESIZEABLE_VG 0x00000004 /* VG */
2002-07-11 14:36:45 +00:00
2002-11-18 14:04:08 +00:00
/* May any free extents on this PV be used or must they be left free? */
# define ALLOCATABLE_PV 0x00000008 /* PV */
2001-10-01 22:12:10 +00:00
2002-11-18 14:04:08 +00:00
# define SPINDOWN_LV 0x00000010 /* LV */
# define BADBLOCK_ON 0x00000020 /* LV */
# define VISIBLE_LV 0x00000040 /* LV */
# define FIXED_MINOR 0x00000080 /* LV */
/* FIXME Remove when metadata restructuring is completed */
# define SNAPSHOT 0x00001000 /* LV - temp internal use only */
2002-04-24 18:20:51 +00:00
2002-11-18 14:04:08 +00:00
# define LVM_READ 0x00000100 /* LV VG */
# define LVM_WRITE 0x00000200 /* LV VG */
# define CLUSTERED 0x00000400 /* VG */
# define SHARED 0x00000800 /* VG */
2001-10-01 22:12:10 +00:00
2002-11-18 14:04:08 +00:00
/* Format features flags */
# define FMT_SEGMENTS 0x00000001 /* Arbitrary segment params? */
# define FMT_MDAS 0x00000002 /* Proper metadata areas? */
2002-07-11 14:21:49 +00:00
typedef enum {
2002-11-18 14:04:08 +00:00
ALLOC_DEFAULT ,
2002-07-11 14:21:49 +00:00
ALLOC_NEXT_FREE ,
ALLOC_CONTIGUOUS
} alloc_policy_t ;
2002-11-18 14:04:08 +00:00
typedef enum {
SEG_STRIPED ,
SEG_SNAPSHOT ,
SEG_MIRROR
} segment_type_t ;
2001-11-26 12:49:29 +00:00
2001-11-12 12:16:57 +00:00
struct cmd_context ;
2002-11-18 14:04:08 +00:00
struct format_handler ;
struct labeller ;
2001-11-12 12:16:57 +00:00
2002-04-24 18:20:51 +00:00
struct format_type {
2002-11-18 14:04:08 +00:00
struct list list ;
2002-04-24 18:20:51 +00:00
struct cmd_context * cmd ;
struct format_handler * ops ;
2002-11-18 14:04:08 +00:00
struct labeller * labeller ;
2002-04-24 18:20:51 +00:00
const char * name ;
2002-11-18 14:04:08 +00:00
const char * alias ;
2002-04-24 18:20:51 +00:00
uint32_t features ;
2002-11-18 14:04:08 +00:00
void * library ;
2002-04-24 18:20:51 +00:00
void * private ;
} ;
2002-11-18 14:04:08 +00:00
struct physical_volume {
struct id id ;
struct device * dev ;
2002-12-19 23:25:55 +00:00
const struct format_type * fmt ;
const char * vg_name ;
2002-11-18 14:04:08 +00:00
uint32_t status ;
uint64_t size ;
/* physical extents */
2002-12-19 23:25:55 +00:00
uint32_t pe_size ;
2002-11-18 14:04:08 +00:00
uint64_t pe_start ;
uint32_t pe_count ;
uint32_t pe_alloc_count ;
} ;
struct metadata_area ;
struct format_instance ;
/* Per-format per-metadata area operations */
struct metadata_area_ops {
struct volume_group * ( * vg_read ) ( struct format_instance * fi ,
const char * vg_name ,
struct metadata_area * mda ) ;
/*
* Write out complete VG metadata . You must ensure internal
* consistency before calling . eg . PEs can ' t refer to PVs not
* part of the VG .
*
* It is also 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 ( ) should not read or write from any PVs not included
* in the volume_group structure it is handed .
* ( format1 currently breaks this rule . )
*/
int ( * vg_write ) ( struct format_instance * fid , struct volume_group * vg ,
struct metadata_area * mda ) ;
int ( * vg_commit ) ( struct format_instance * fid ,
struct volume_group * vg , struct metadata_area * mda ) ;
int ( * vg_remove ) ( struct format_instance * fi , struct volume_group * vg ,
struct metadata_area * mda ) ;
} ;
2002-04-24 18:20:51 +00:00
struct metadata_area {
struct list list ;
2002-11-18 14:04:08 +00:00
struct metadata_area_ops * ops ;
2002-04-24 18:20:51 +00:00
void * metadata_locn ;
} ;
struct format_instance {
2002-12-19 23:25:55 +00:00
const struct format_type * fmt ;
2002-04-24 18:20:51 +00:00
struct list metadata_areas ; /* e.g. metadata locations */
} ;
2001-09-28 13:15:30 +00:00
struct volume_group {
2001-11-12 12:16:57 +00:00
struct cmd_context * cmd ;
2002-04-24 18:20:51 +00:00
struct format_instance * fid ;
2002-11-18 14:04:08 +00:00
uint32_t seqno ; /* Metadata sequence number */
2001-11-12 12:16:57 +00:00
2001-10-08 16:08:16 +00:00
struct id id ;
2001-10-12 10:32:06 +00:00
char * name ;
2002-01-29 17:23:33 +00:00
char * system_id ;
2001-09-25 12:49:28 +00:00
2002-11-18 14:04:08 +00:00
uint32_t status ;
2001-10-03 12:34:08 +00:00
2002-11-18 14:04:08 +00:00
uint32_t extent_size ;
uint32_t extent_count ;
uint32_t free_count ;
2001-09-25 12:49:28 +00:00
2002-11-18 14:04:08 +00:00
uint32_t max_lv ;
uint32_t max_pv ;
2001-10-03 20:38:07 +00:00
2002-11-18 14:04:08 +00:00
/* physical volumes */
uint32_t pv_count ;
2001-10-31 12:47:01 +00:00
struct list pvs ;
2001-09-25 12:49:28 +00:00
2002-11-18 14:04:08 +00:00
/* logical volumes */
uint32_t lv_count ;
2001-10-31 12:47:01 +00:00
struct list lvs ;
2002-02-12 16:31:31 +00:00
/* snapshots */
uint32_t snapshot_count ;
struct list snapshots ;
2001-09-28 13:15:30 +00:00
} ;
2001-09-25 12:49:28 +00:00
2002-11-18 14:04:08 +00:00
struct lv_segment {
2001-11-27 16:37:33 +00:00
struct list list ;
struct logical_volume * lv ;
2002-11-18 14:04:08 +00:00
segment_type_t type ;
2001-11-27 16:37:33 +00:00
uint32_t le ;
uint32_t len ;
2002-11-18 14:04:08 +00:00
/* FIXME Fields depend on segment type */
2001-11-27 16:37:33 +00:00
uint32_t stripe_size ;
uint32_t stripes ;
2002-11-18 14:04:08 +00:00
struct logical_volume * origin ;
struct logical_volume * cow ;
uint32_t chunk_size ;
2001-11-27 16:37:33 +00:00
/* There will be one area for each stripe */
2002-11-18 14:04:08 +00:00
struct {
2001-11-27 16:37:33 +00:00
struct physical_volume * pv ;
uint32_t pe ;
} area [ 0 ] ;
} ;
2001-10-31 17:59:52 +00:00
struct logical_volume {
2002-03-05 20:03:09 +00:00
union lvid lvid ;
2002-11-18 14:04:08 +00:00
char * name ;
2001-10-31 17:59:52 +00:00
struct volume_group * vg ;
2002-11-18 14:04:08 +00:00
uint32_t status ;
2002-07-11 14:21:49 +00:00
alloc_policy_t alloc ;
2001-10-31 17:59:52 +00:00
uint32_t read_ahead ;
2002-02-01 17:54:39 +00:00
int32_t minor ;
2001-10-31 17:59:52 +00:00
2002-11-18 14:04:08 +00:00
uint64_t size ;
uint32_t le_count ;
2001-10-31 17:59:52 +00:00
2001-11-26 16:18:48 +00:00
struct list segments ;
2001-10-31 17:59:52 +00:00
} ;
2002-02-12 16:31:31 +00:00
struct snapshot {
2002-11-18 14:04:08 +00:00
struct id id ;
2002-02-12 16:31:31 +00:00
int persistent ; /* boolean */
uint32_t chunk_size ; /* in 512 byte sectors */
struct logical_volume * origin ;
struct logical_volume * cow ;
} ;
2001-10-04 22:53:37 +00:00
struct name_list {
2001-10-31 12:47:01 +00:00
struct list list ;
2001-10-08 16:08:16 +00:00
char * name ;
2001-10-02 17:09:05 +00:00
} ;
struct pv_list {
2001-10-31 12:47:01 +00:00
struct list list ;
2002-01-21 16:05:23 +00:00
struct physical_volume * pv ;
2002-11-18 14:04:08 +00:00
struct list * mdas ;
2001-10-02 17:09:05 +00:00
} ;
2001-10-01 22:12:10 +00:00
2001-10-08 09:45:16 +00:00
struct lv_list {
2001-10-31 12:47:01 +00:00
struct list list ;
2002-01-21 16:49:32 +00:00
struct logical_volume * lv ;
2001-10-08 09:45:16 +00:00
} ;
2002-02-12 16:31:31 +00:00
struct snapshot_list {
struct list list ;
struct snapshot * snapshot ;
} ;
2002-11-18 14:04:08 +00:00
struct mda_list {
struct list list ;
struct device_area mda ;
} ;
2001-11-12 12:16:57 +00:00
2001-10-10 09:25:04 +00:00
/*
* Ownership of objects passes to caller .
*/
2001-11-12 12:16:57 +00:00
struct format_handler {
2001-10-10 09:25:04 +00:00
/*
2002-11-18 14:04:08 +00:00
* Scan any metadata areas that aren ' t referenced in PV labels
2001-10-10 09:25:04 +00:00
*/
2002-12-19 23:25:55 +00:00
int ( * scan ) ( const struct format_type * fmt ) ;
2001-09-25 12:49:28 +00:00
2001-10-10 09:25:04 +00:00
/*
* Return PV with given path .
*/
2002-12-19 23:25:55 +00:00
int ( * pv_read ) ( const struct format_type * fmt , const char * pv_name ,
2002-11-18 14:04:08 +00:00
struct physical_volume * pv , struct list * mdas ) ;
2001-10-04 22:53:37 +00:00
2001-10-10 09:25:04 +00:00
/*
2001-11-12 12:16:57 +00:00
* Tweak an already filled out a pv ready for importing into a
* vg . eg . pe_count is format specific .
2001-10-10 09:25:04 +00:00
*/
2002-12-19 23:25:55 +00:00
int ( * pv_setup ) ( const struct format_type * fmt ,
2002-11-18 14:04:08 +00:00
uint64_t pe_start , uint32_t extent_count ,
uint32_t extent_size ,
int pvmetadatacopies ,
uint64_t pvmetadatasize , struct list * mdas ,
struct physical_volume * pv , struct volume_group * vg ) ;
2001-10-10 09:25:04 +00:00
/*
2001-11-12 12:16:57 +00:00
* Write a PV structure to disk . Fails if the PV is in a VG ie
* pv - > vg_name must be null .
2001-10-10 09:25:04 +00:00
*/
2002-12-19 23:25:55 +00:00
int ( * pv_write ) ( const struct format_type * fmt ,
struct physical_volume * pv , struct list * mdas ,
int64_t label_sector ) ;
2001-09-25 12:49:28 +00:00
2002-01-24 17:15:49 +00:00
/*
* Tweak an already filled out a lv eg , check there
* aren ' t too many extents .
*/
2002-11-18 14:04:08 +00:00
int ( * lv_setup ) ( struct format_instance * fi ,
struct logical_volume * lv ) ;
2002-01-24 17:15:49 +00:00
2001-10-12 14:25:53 +00:00
/*
2001-11-12 12:16:57 +00:00
* Tweak an already filled out vg . eg , max_pv is format
* specific .
2001-10-12 14:25:53 +00:00
*/
2002-11-18 14:04:08 +00:00
int ( * vg_setup ) ( struct format_instance * fi , struct volume_group * vg ) ;
2001-10-04 22:53:37 +00:00
2002-04-24 18:20:51 +00:00
/*
* Create format instance with a particular metadata area
*/
2002-12-19 23:25:55 +00:00
struct format_instance * ( * create_instance ) ( const struct format_type *
fmt , const char * vgname ,
2002-11-18 14:04:08 +00:00
void * context ) ;
2002-04-24 18:20:51 +00:00
/*
* Destructor for format instance
*/
2002-11-18 14:04:08 +00:00
void ( * destroy_instance ) ( struct format_instance * fid ) ;
2001-10-04 22:53:37 +00:00
2001-10-10 09:25:04 +00:00
/*
2002-04-24 18:20:51 +00:00
* Destructor for format type
2001-10-10 09:25:04 +00:00
*/
2002-12-19 23:25:55 +00:00
void ( * destroy ) ( const struct format_type * fmt ) ;
2001-09-28 13:15:30 +00:00
} ;
2001-09-25 12:49:28 +00:00
2001-10-12 10:32:06 +00:00
/*
* Utility functions
*/
2002-04-24 18:20:51 +00:00
int vg_write ( struct volume_group * vg ) ;
2002-11-18 14:04:08 +00:00
struct volume_group * vg_read ( struct cmd_context * cmd , const char * vg_name ,
int * consistent ) ;
2002-04-24 18:20:51 +00:00
struct volume_group * vg_read_by_vgid ( struct cmd_context * cmd , const char * vgid ) ;
2002-11-18 14:04:08 +00:00
struct physical_volume * pv_read ( struct cmd_context * cmd , const char * pv_name ,
struct list * mdas , uint64_t * label_sector ) ;
2002-04-24 18:20:51 +00:00
struct list * get_pvs ( struct cmd_context * cmd ) ;
2002-11-18 14:04:08 +00:00
/* Set full_scan to 1 to re-read every (filtered) device label */
struct list * get_vgs ( struct cmd_context * cmd , int full_scan ) ;
int pv_write ( struct cmd_context * cmd , struct physical_volume * pv ,
struct list * mdas , int64_t label_sector ) ;
2002-04-24 18:20:51 +00:00
2002-11-18 14:04:08 +00:00
/* pe_start and pe_end relate to any existing data so that new metadata
* areas can avoid overlap */
2002-12-19 23:25:55 +00:00
struct physical_volume * pv_create ( const struct format_type * fmt ,
2002-11-18 14:04:08 +00:00
struct device * dev ,
2002-02-15 01:26:16 +00:00
struct id * id ,
2002-11-18 14:04:08 +00:00
uint64_t size ,
uint64_t pe_start ,
uint32_t existing_extent_count ,
uint32_t existing_extent_size ,
int pvmetadatacopies ,
uint64_t pvmetadatasize , struct list * mdas ) ;
2001-11-12 12:16:57 +00:00
2002-04-24 18:20:51 +00:00
struct volume_group * vg_create ( struct cmd_context * cmd , const char * name ,
2002-12-19 23:25:55 +00:00
uint32_t extent_size , uint32_t max_pv ,
uint32_t max_lv , int pv_count , char * * pv_names ) ;
2002-04-24 18:20:51 +00:00
int vg_remove ( struct volume_group * vg ) ;
2002-12-19 23:25:55 +00:00
int vg_rename ( struct cmd_context * cmd , struct volume_group * vg ,
const char * new_name ) ;
2002-11-18 14:04:08 +00:00
int vg_extend ( struct format_instance * fi , struct volume_group * vg ,
int pv_count , char * * pv_names ) ;
2001-10-12 10:32:06 +00:00
2001-11-05 16:41:38 +00:00
/*
2001-11-06 19:02:26 +00:00
* Create a new LV within a given volume group .
*
2001-11-05 16:41:38 +00:00
*/
2002-01-24 17:15:49 +00:00
struct logical_volume * lv_create ( struct format_instance * fi ,
const char * name ,
2001-11-05 16:41:38 +00:00
uint32_t status ,
2002-07-11 14:21:49 +00:00
alloc_policy_t alloc ,
2001-11-05 16:41:38 +00:00
uint32_t stripes ,
uint32_t stripe_size ,
2001-11-06 10:29:56 +00:00
uint32_t extents ,
2001-11-05 16:41:38 +00:00
struct volume_group * vg ,
2001-11-06 11:19:33 +00:00
struct list * acceptable_pvs ) ;
2002-02-08 11:13:47 +00:00
int lv_reduce ( struct format_instance * fi ,
2002-01-24 17:15:49 +00:00
struct logical_volume * lv , uint32_t extents ) ;
2001-11-06 11:19:33 +00:00
2002-01-24 17:15:49 +00:00
int lv_extend ( struct format_instance * fi ,
struct logical_volume * lv ,
2001-11-26 15:31:46 +00:00
uint32_t stripes ,
uint32_t stripe_size ,
2002-11-18 14:04:08 +00:00
uint32_t extents , struct list * allocatable_pvs ) ;
2001-10-12 10:32:06 +00:00
2001-11-14 18:38:07 +00:00
/* lv must be part of vg->lvs */
int lv_remove ( struct volume_group * vg , struct logical_volume * lv ) ;
2001-11-12 19:28:50 +00:00
2001-10-04 22:53:37 +00:00
/* Manipulate PV structures */
2001-10-01 22:12:10 +00:00
int pv_add ( struct volume_group * vg , struct physical_volume * pv ) ;
2001-10-03 12:34:08 +00:00
int pv_remove ( struct volume_group * vg , struct physical_volume * pv ) ;
2002-11-18 14:04:08 +00:00
struct physical_volume * pv_find ( struct volume_group * vg , const char * pv_name ) ;
2001-10-04 22:53:37 +00:00
2001-10-29 13:52:23 +00:00
/* Find a PV within a given VG */
2002-01-21 14:28:12 +00:00
struct pv_list * find_pv_in_vg ( struct volume_group * vg , const char * pv_name ) ;
2002-11-18 14:04:08 +00:00
struct physical_volume * find_pv_in_vg_by_uuid ( struct volume_group * vg ,
struct id * id ) ;
2001-10-04 22:53:37 +00:00
/* Find an LV within a given VG */
2002-01-21 14:28:12 +00:00
struct lv_list * find_lv_in_vg ( struct volume_group * vg , const char * lv_name ) ;
2002-11-18 14:04:08 +00:00
struct lv_list * find_lv_in_vg_by_lvid ( struct volume_group * vg ,
2002-12-19 23:25:55 +00:00
const union lvid * lvid ) ;
2001-10-29 13:52:23 +00:00
/* Return the VG that contains a given LV (based on path given in lv_name) */
/* or environment var */
struct volume_group * find_vg_with_lv ( const char * lv_name ) ;
2002-11-18 14:04:08 +00:00
/* Find LV with given lvid (used during activation) */
struct logical_volume * lv_from_lvid ( struct cmd_context * cmd ,
const char * lvid_s ) ;
2001-10-29 13:52:23 +00:00
/* FIXME Merge these functions with ones above */
2001-11-27 16:37:33 +00:00
struct physical_volume * find_pv ( struct volume_group * vg , struct device * dev ) ;
2001-10-29 13:52:23 +00:00
struct logical_volume * find_lv ( struct volume_group * vg , const char * lv_name ) ;
2001-09-28 13:15:30 +00:00
2001-11-12 12:16:57 +00:00
/*
2001-11-14 13:52:38 +00:00
* Remove a dev_dir if present .
2001-11-12 12:16:57 +00:00
*/
const char * strip_dir ( const char * vg_name , const char * dir ) ;
2001-10-15 18:39:40 +00:00
2002-01-10 11:18:08 +00:00
/*
* Checks that an lv has no gaps or overlapping segments .
*/
int lv_check_segments ( struct logical_volume * lv ) ;
/*
* Sometimes ( eg , after an lvextend ) , it is possible to merge two
* adjacent segments into a single segment . This function trys
* to merge as many segments as possible .
*/
int lv_merge_segments ( struct logical_volume * lv ) ;
2002-02-12 16:31:31 +00:00
/*
* Useful functions for managing snapshots .
*/
2002-12-19 23:25:55 +00:00
int lv_is_origin ( const struct logical_volume * lv ) ;
int lv_is_cow ( const struct logical_volume * lv ) ;
2002-02-12 16:31:31 +00:00
2002-12-19 23:25:55 +00:00
struct snapshot * find_cow ( const struct logical_volume * lv ) ;
struct snapshot * find_origin ( const struct logical_volume * lv ) ;
struct list * find_snapshots ( const struct logical_volume * lv ) ;
2002-02-21 10:16:33 +00:00
2002-02-21 18:31:48 +00:00
int vg_add_snapshot ( struct logical_volume * origin ,
2002-02-12 16:31:31 +00:00
struct logical_volume * cow ,
2002-11-18 14:04:08 +00:00
int persistent , struct id * id , uint32_t chunk_size ) ;
2002-02-12 16:31:31 +00:00
int vg_remove_snapshot ( struct volume_group * vg , struct logical_volume * cow ) ;
2002-11-18 14:04:08 +00:00
static inline int validate_vgname ( const char * n )
{
register char c ;
register int len = 0 ;
if ( ! n | | ! * n )
return 0 ;
/* Hyphen used as VG-LV separator - ambiguity if LV starts with it */
if ( * n = = ' - ' )
return 0 ;
while ( ( len + + , c = * n + + ) )
if ( ! isalnum ( c ) & & c ! = ' . ' & & c ! = ' _ ' & & c ! = ' - ' & & c ! = ' + ' )
return 0 ;
if ( len > NAME_LEN )
return 0 ;
return 1 ;
}
2002-02-12 16:31:31 +00:00
2001-09-28 13:15:30 +00:00
# endif