2001-10-04 21:48:55 +04:00
/*
2004-03-30 23:35:44 +04:00
* Copyright ( C ) 2001 - 2004 Sistina Software , Inc . All rights reserved .
2007-08-21 00:55:30 +04:00
* Copyright ( C ) 2004 - 2006 Red Hat , Inc . All rights reserved .
2001-10-04 21:48:55 +04:00
*
2004-03-30 23:35:44 +04:00
* This file is part of LVM2 .
*
* This copyrighted material is made available to anyone wishing to use ,
* modify , copy , or redistribute it subject to the terms and conditions
2007-08-21 00:55:30 +04:00
* of the GNU Lesser General Public License v .2 .1 .
2004-03-30 23:35:44 +04:00
*
2007-08-21 00:55:30 +04:00
* You should have received a copy of the GNU Lesser General Public License
2004-03-30 23:35:44 +04:00
* along with this program ; if not , write to the Free Software Foundation ,
2016-01-21 13:49:46 +03:00
* Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 USA
2001-10-04 21:48:55 +04:00
*/
# ifndef DISK_REP_FORMAT1_H
# define DISK_REP_FORMAT1_H
2001-10-08 13:45:16 +04:00
# include "metadata.h"
2004-03-08 20:25:59 +03:00
# include "toolcontext.h"
2001-10-08 13:45:16 +04:00
# define MAX_PV 256
# define MAX_LV 256
# define MAX_VG 99
2003-11-06 19:58:38 +03:00
# define LVM_BLK_MAJOR 58
2002-11-18 17:01:16 +03:00
# define MAX_PV_SIZE ((uint32_t) -1) /* 2TB in sectors - 1 */
# define PE_SIZE_PV_SIZE_REL 5 /* PV size must be at least 5 times PE size */
# define MAX_LE_TOTAL 65534 /* 2^16 - 2 */
2002-01-25 16:41:13 +03:00
# define MAX_PE_TOTAL ((uint32_t) -2)
2002-01-25 02:35:56 +03:00
2001-10-08 20:08:16 +04:00
# define UNMAPPED_EXTENT 0
2001-10-08 13:45:16 +04:00
2001-10-09 18:26:45 +04:00
/* volume group */
# define VG_ACTIVE 0x01 /* vg_status */
# define VG_EXPORTED 0x02 /* " */
# define VG_EXTENDABLE 0x04 /* " */
# define VG_READ 0x01 /* vg_access */
# define VG_WRITE 0x02 /* " */
# define VG_CLUSTERED 0x04 /* " */
# define VG_SHARED 0x08 /* " */
/* logical volume */
# define LV_ACTIVE 0x01 /* lv_status */
# define LV_SPINDOWN 0x02 /* " */
2002-02-01 20:54:39 +03:00
# define LV_PERSISTENT_MINOR 0x04 /* " */
2001-10-09 18:26:45 +04:00
# define LV_READ 0x01 /* lv_access */
# define LV_WRITE 0x02 /* " */
# define LV_SNAPSHOT 0x04 /* " */
# define LV_SNAPSHOT_ORG 0x08 /* " */
# define LV_BADBLOCK_ON 0x01 /* lv_badblock */
# define LV_STRICT 0x01 /* lv_allocation */
# define LV_CONTIGUOUS 0x02 /* " */
/* physical volume */
# define PV_ACTIVE 0x01 /* pv_status */
# define PV_ALLOCATABLE 0x02 /* pv_allocatable */
2002-01-29 20:23:33 +03:00
# define EXPORTED_TAG "PV_EXP" /* Identifier for exported PV */
# define IMPORTED_TAG "PV_IMP" /* Identifier for imported PV */
2001-10-04 21:48:55 +04:00
struct data_area {
uint32_t base ;
uint32_t size ;
2002-11-18 17:01:16 +03:00
} __attribute__ ( ( packed ) ) ;
2001-10-04 21:48:55 +04:00
struct pv_disk {
2006-05-10 01:23:51 +04:00
int8_t id [ 2 ] ;
2002-11-18 17:01:16 +03:00
uint16_t version ; /* lvm version */
struct data_area pv_on_disk ;
struct data_area vg_on_disk ;
struct data_area pv_uuidlist_on_disk ;
struct data_area lv_on_disk ;
struct data_area pe_on_disk ;
2006-05-10 01:23:51 +04:00
int8_t pv_uuid [ NAME_LEN ] ;
int8_t vg_name [ NAME_LEN ] ;
int8_t system_id [ NAME_LEN ] ; /* for vgexport/vgimport */
2002-11-18 17:01:16 +03:00
uint32_t pv_major ;
uint32_t pv_number ;
uint32_t pv_status ;
uint32_t pv_allocatable ;
uint32_t pv_size ;
uint32_t lv_cur ;
uint32_t pe_size ;
uint32_t pe_total ;
uint32_t pe_allocated ;
2001-10-04 21:48:55 +04:00
/* only present on version == 2 pv's */
uint32_t pe_start ;
2002-11-18 17:01:16 +03:00
} __attribute__ ( ( packed ) ) ;
2001-10-04 21:48:55 +04:00
struct lv_disk {
2006-05-10 01:23:51 +04:00
int8_t lv_name [ NAME_LEN ] ;
int8_t vg_name [ NAME_LEN ] ;
2002-11-18 17:01:16 +03:00
uint32_t lv_access ;
uint32_t lv_status ;
uint32_t lv_open ;
uint32_t lv_dev ;
uint32_t lv_number ;
uint32_t lv_mirror_copies ; /* for future use */
uint32_t lv_recovery ; /* " */
uint32_t lv_schedule ; /* " */
uint32_t lv_size ;
uint32_t lv_snapshot_minor ; /* minor number of original */
uint16_t lv_chunk_size ; /* chunk size of snapshot */
uint16_t dummy ;
uint32_t lv_allocated_le ;
uint32_t lv_stripes ;
uint32_t lv_stripesize ;
uint32_t lv_badblock ; /* for future use */
uint32_t lv_allocation ;
uint32_t lv_io_timeout ; /* for future use */
uint32_t lv_read_ahead ;
} __attribute__ ( ( packed ) ) ;
2001-10-04 21:48:55 +04:00
struct vg_disk {
2006-05-10 01:23:51 +04:00
int8_t vg_uuid [ ID_LEN ] ; /* volume group UUID */
int8_t vg_name_dummy [ NAME_LEN - ID_LEN ] ; /* rest of v1 VG name */
2002-11-18 17:01:16 +03:00
uint32_t vg_number ; /* volume group number */
uint32_t vg_access ; /* read/write */
uint32_t vg_status ; /* active or not */
uint32_t lv_max ; /* maximum logical volumes */
uint32_t lv_cur ; /* current logical volumes */
uint32_t lv_open ; /* open logical volumes */
uint32_t pv_max ; /* maximum physical volumes */
uint32_t pv_cur ; /* current physical volumes FU */
uint32_t pv_act ; /* active physical volumes */
uint32_t dummy ;
uint32_t vgda ; /* volume group descriptor arrays FU */
uint32_t pe_size ; /* physical extent size in sectors */
uint32_t pe_total ; /* total of physical extents */
uint32_t pe_allocated ; /* allocated physical extents */
uint32_t pvg_total ; /* physical volume groups FU */
} __attribute__ ( ( packed ) ) ;
2001-10-04 21:48:55 +04:00
struct pe_disk {
uint16_t lv_num ;
uint16_t le_num ;
2002-11-18 17:01:16 +03:00
} __attribute__ ( ( packed ) ) ;
2001-10-04 21:48:55 +04:00
struct uuid_list {
2008-11-04 01:14:30 +03:00
struct dm_list list ;
2010-07-09 19:34:40 +04:00
char uuid [ NAME_LEN ] __attribute__ ( ( aligned ( 8 ) ) ) ;
2001-10-04 21:48:55 +04:00
} ;
2001-10-08 13:45:16 +04:00
struct lvd_list {
2008-11-04 01:14:30 +03:00
struct dm_list list ;
2001-10-31 20:59:52 +03:00
struct lv_disk lvd ;
2001-10-08 13:45:16 +04:00
} ;
2001-10-04 21:48:55 +04:00
struct disk_list {
2008-11-04 01:14:30 +03:00
struct dm_list list ;
2005-10-17 03:03:59 +04:00
struct dm_pool * mem ;
2001-10-05 19:20:40 +04:00
struct device * dev ;
2001-10-08 12:47:27 +04:00
2010-07-09 19:34:40 +04:00
struct pv_disk pvd __attribute__ ( ( aligned ( 8 ) ) ) ;
struct vg_disk vgd __attribute__ ( ( aligned ( 8 ) ) ) ;
struct dm_list uuids __attribute__ ( ( aligned ( 8 ) ) ) ;
struct dm_list lvds __attribute__ ( ( aligned ( 8 ) ) ) ;
struct pe_disk * extents __attribute__ ( ( aligned ( 8 ) ) ) ;
2001-10-04 21:48:55 +04:00
} ;
2001-10-10 13:25:04 +04:00
/*
* Layout constants .
*/
# define METADATA_ALIGN 4096UL
2006-08-17 23:15:27 +04:00
# define LVM1_PE_ALIGN (65536UL >> SECTOR_SHIFT) /* PE alignment */
2001-10-10 13:25:04 +04:00
# define METADATA_BASE 0UL
# define PV_SIZE 1024UL
# define VG_SIZE 4096UL
/*
* Functions to calculate layout info .
*/
int calculate_layout ( struct disk_list * dl ) ;
2002-11-18 17:01:16 +03:00
int calculate_extent_count ( struct physical_volume * pv , uint32_t extent_size ,
2003-12-09 20:51:39 +03:00
uint32_t max_extent_count , uint64_t pe_start ) ;
2001-10-10 13:25:04 +04:00
/*
* Low level io routines which read / write
* disk_lists .
*/
2002-01-16 21:10:08 +03:00
2002-12-20 02:25:55 +03:00
struct disk_list * read_disk ( const struct format_type * fmt , struct device * dev ,
2005-10-17 03:03:59 +04:00
struct dm_pool * mem , const char * vg_name ) ;
2001-10-05 19:20:40 +04:00
2002-12-20 02:25:55 +03:00
int read_pvs_in_vg ( const struct format_type * fmt , const char * vg_name ,
2002-04-24 22:20:51 +04:00
struct dev_filter * filter ,
2008-11-04 01:14:30 +03:00
struct dm_pool * mem , struct dm_list * results ) ;
2001-10-04 21:48:55 +04:00
2013-03-25 17:30:40 +04:00
int write_disks ( const struct format_type * fmt , struct dm_list * pvds ,
int write_vg_metadata ) ;
2001-10-05 19:20:40 +04:00
2001-10-09 18:26:45 +04:00
/*
2001-10-10 13:25:04 +04:00
* Functions to translate to between disk and in
2001-10-09 18:26:45 +04:00
* core structures .
*/
2006-10-19 16:53:47 +04:00
int import_pv ( const struct format_type * fmt , struct dm_pool * mem ,
struct device * dev , struct volume_group * vg ,
2006-04-13 01:23:04 +04:00
struct physical_volume * pv , struct pv_disk * pvd ,
struct vg_disk * vgd ) ;
2005-10-17 03:03:59 +04:00
int export_pv ( struct cmd_context * cmd , struct dm_pool * mem ,
2004-03-08 20:25:59 +03:00
struct volume_group * vg ,
2002-01-29 20:23:33 +03:00
struct pv_disk * pvd , struct physical_volume * pv ) ;
2001-10-09 18:26:45 +04:00
2005-10-17 03:03:59 +04:00
int import_vg ( struct dm_pool * mem ,
2008-09-19 10:42:00 +04:00
struct volume_group * vg , struct disk_list * dl ) ;
2001-10-09 18:26:45 +04:00
int export_vg ( struct vg_disk * vgd , struct volume_group * vg ) ;
2009-05-14 01:24:12 +04:00
int import_lv ( struct cmd_context * cmd , struct dm_pool * mem ,
struct logical_volume * lv , struct lv_disk * lvd ) ;
2001-10-09 18:26:45 +04:00
2004-05-05 01:25:57 +04:00
int import_extents ( struct cmd_context * cmd , struct volume_group * vg ,
2008-11-04 01:14:30 +03:00
struct dm_list * pvds ) ;
2002-12-20 02:25:55 +03:00
int export_extents ( struct disk_list * dl , uint32_t lv_num ,
2002-11-18 17:01:16 +03:00
struct logical_volume * lv , struct physical_volume * pv ) ;
2001-10-09 18:26:45 +04:00
2005-10-17 03:03:59 +04:00
int import_pvs ( const struct format_type * fmt , struct dm_pool * mem ,
2010-04-06 18:04:20 +04:00
struct volume_group * vg , struct dm_list * pvds ) ;
2001-10-09 18:26:45 +04:00
2008-11-04 01:14:30 +03:00
int import_lvs ( struct dm_pool * mem , struct volume_group * vg , struct dm_list * pvds ) ;
2001-10-09 18:26:45 +04:00
int export_lvs ( struct disk_list * dl , struct volume_group * vg ,
2001-11-14 16:52:38 +03:00
struct physical_volume * pv , const char * dev_dir ) ;
2001-10-09 18:26:45 +04:00
2005-10-17 03:03:59 +04:00
int import_snapshots ( struct dm_pool * mem , struct volume_group * vg ,
2008-11-04 01:14:30 +03:00
struct dm_list * pvds ) ;
2002-02-13 14:43:29 +03:00
2001-10-09 18:26:45 +04:00
int export_uuids ( struct disk_list * dl , struct volume_group * vg ) ;
2008-11-04 01:14:30 +03:00
void export_numbers ( struct dm_list * pvds , struct volume_group * vg ) ;
2001-10-11 14:55:19 +04:00
2008-11-04 01:14:30 +03:00
void export_pv_act ( struct dm_list * pvds ) ;
2004-05-04 22:38:11 +04:00
int munge_pvd ( struct device * dev , struct pv_disk * pvd ) ;
2006-04-11 02:09:00 +04:00
int read_vgd ( struct device * dev , struct vg_disk * vgd , struct pv_disk * pvd ) ;
2001-10-09 18:26:45 +04:00
2001-10-11 18:10:18 +04:00
/* blech */
2002-04-24 22:20:51 +04:00
int get_free_vg_number ( struct format_instance * fid , struct dev_filter * filter ,
const char * candidate_vg , int * result ) ;
2008-11-04 01:14:30 +03:00
int export_vg_number ( struct format_instance * fid , struct dm_list * pvds ,
2002-04-24 22:20:51 +04:00
const char * vg_name , struct dev_filter * filter ) ;
2001-10-11 18:10:18 +04:00
2015-03-04 03:44:15 +03:00
int generate_lvm1_system_id ( struct cmd_context * cmd , char * s , const char * prefix ) ;
2001-10-04 21:48:55 +04:00
# endif