2010-09-30 17:16:55 +04:00
/*
2010-10-01 00:47:18 +04:00
* Copyright ( C ) 2001 - 2004 Sistina Software , Inc . All rights reserved .
2013-07-05 19:10:47 +04:00
* Copyright ( C ) 2004 - 2013 Red Hat , Inc . All rights reserved .
2010-09-30 17:16:55 +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
* of the GNU Lesser General Public License v .2 .1 .
*
* You should have received a copy of the GNU Lesser General Public License
* 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
2010-09-30 17:16:55 +04:00
*/
2010-10-25 16:01:59 +04:00
# ifndef _LVM_VG_H
# define _LVM_VG_H
2010-09-30 17:16:55 +04:00
2018-05-14 12:30:20 +03:00
# include "lib/uuid/uuid.h"
2018-06-08 14:31:45 +03:00
# include "device_mapper/all.h"
2012-01-26 02:26:33 +04:00
2010-09-30 17:16:55 +04:00
struct cmd_context ;
struct format_instance ;
2013-07-05 19:10:47 +04:00
struct logical_volume ;
2010-09-30 17:16:55 +04:00
typedef enum {
ALLOC_INVALID ,
ALLOC_CONTIGUOUS ,
ALLOC_CLING ,
2010-11-09 15:34:40 +03:00
ALLOC_CLING_BY_TAGS , /* Internal - never written or displayed. */
2010-09-30 17:16:55 +04:00
ALLOC_NORMAL ,
ALLOC_ANYWHERE ,
ALLOC_INHERIT
} alloc_policy_t ;
2011-11-05 02:49:53 +04:00
# define MAX_EXTENT_COUNT (UINT32_MAX)
2010-09-30 17:16:55 +04:00
struct volume_group {
struct cmd_context * cmd ;
struct dm_pool * vgmem ;
struct format_instance * fid ;
2015-03-04 03:30:26 +03:00
const struct format_type * original_fmt ; /* Set when processing backup files */
2011-08-11 21:24:23 +04:00
struct lvmcache_vginfo * vginfo ;
2010-09-30 17:16:55 +04:00
uint32_t seqno ; /* Metadata sequence number */
2015-03-05 23:00:44 +03:00
unsigned skip_validate_lock_args : 1 ;
2021-02-26 03:01:29 +03:00
unsigned needs_backup : 1 ;
2021-03-05 18:21:50 +03:00
unsigned needs_write_and_commit : 1 ;
2019-06-19 00:10:06 +03:00
uint32_t write_count ; /* count the number of vg_write calls */
2010-09-30 17:16:55 +04:00
2013-03-17 19:27:44 +04:00
/*
2015-11-25 01:29:18 +03:00
* The parsed committed ( on - disk ) copy of this VG ; is NULL if this VG is committed
* version ( i . e . vg_committed = = NULL * implies * this is the committed copy ,
* there is no guarantee that if this VG is the same as the committed one
2021-03-06 01:04:44 +03:00
* this will be NULL ) . The pointer is maintained by calls to vg_write & vg_commit
2013-03-17 19:27:44 +04:00
*/
2021-03-06 01:04:44 +03:00
struct dm_config_tree * committed_cft ;
2015-11-25 01:29:18 +03:00
struct volume_group * vg_committed ;
2017-11-14 04:09:58 +03:00
struct volume_group * vg_precommitted ;
2013-03-17 19:27:44 +04:00
2010-09-30 17:16:55 +04:00
alloc_policy_t alloc ;
2013-06-25 14:28:36 +04:00
struct profile * profile ;
2010-09-30 17:16:55 +04:00
uint64_t status ;
struct id id ;
2010-12-20 16:40:46 +03:00
const char * name ;
const char * old_name ; /* Set during vgrename and vgcfgrestore */
2015-02-24 02:03:52 +03:00
const char * system_id ;
system_id: make new VGs read-only for old lvm versions
Previous versions of lvm will not obey the restrictions
imposed by the new system_id, and would allow such a VG
to be written. So, a VG with a new system_id is further
changed to force previous lvm versions to treat it as
read-only. This is done by removing the WRITE flag from
the metadata status line of these VGs, and putting a new
WRITE_LOCKED flag in the flags line of the metadata.
Versions of lvm that recognize WRITE_LOCKED, also obey the
new system_id. For these lvm versions, WRITE_LOCKED is
identical to WRITE, and the rules associated with matching
system_id's are imposed.
A new VG lock_type field is also added that causes the same
WRITE/WRITE_LOCKED transformation when set. A previous
version of lvm will also see a VG with lock_type as read-only.
Versions of lvm that recognize WRITE_LOCKED, must also obey
the lock_type setting. Until the lock_type feature is added,
lvm will fail to read any VG with lock_type set and report an
error about an unsupported lock_type. Once the lock_type
feature is added, lvm will allow VGs with lock_type to be
used according to the rules imposed by the lock_type.
When both system_id and lock_type settings are removed, a VG
is written with the old WRITE status flag, and without the
new WRITE_LOCKED flag. This allows old versions of lvm to
use the VG as before.
2015-03-04 20:30:53 +03:00
const char * lock_type ;
2015-03-05 23:00:44 +03:00
const char * lock_args ;
2010-09-30 17:16:55 +04:00
uint32_t extent_size ;
uint32_t extent_count ;
uint32_t free_count ;
uint32_t max_lv ;
uint32_t max_pv ;
/* physical volumes */
uint32_t pv_count ;
struct dm_list pvs ;
2011-06-01 23:29:31 +04:00
/*
* List of physical volumes that were used in vgextend but do not carry
* a PV label yet . They need to be pvcreate ' d at vg_write time .
*/
2016-02-16 21:43:24 +03:00
struct dm_list pv_write_list ; /* struct pv_list */
2011-06-01 23:29:31 +04:00
2010-09-30 17:16:55 +04:00
/*
* logical volumes
* The following relationship should always hold :
* dm_list_size ( lvs ) = user visible lv_count + snapshot_count + other invisible LVs
*
* Snapshots consist of 2 instances of " struct logical_volume " :
* - cow ( lv_name is visible to the user )
* - snapshot ( lv_name is ' snapshotN ' )
*
* Mirrors consist of multiple instances of " struct logical_volume " :
* - one for the mirror log
* - one for each mirror leg
* - one for the user - visible mirror LV
*/
struct dm_list lvs ;
2016-03-01 17:18:42 +03:00
struct dm_list historical_lvs ;
2010-09-30 17:16:55 +04:00
struct dm_list tags ;
/*
* FIXME : Move the next fields into a different struct ?
*/
2015-03-23 15:32:00 +03:00
/*
* List of removed logical volumes by _lv_reduce .
*/
struct dm_list removed_lvs ;
2016-03-01 17:26:57 +03:00
/*
* List of removed historical logical volumes by historical_glv_remove .
*/
struct dm_list removed_historical_lvs ;
2010-09-30 17:16:55 +04:00
/*
* List of removed physical volumes by pvreduce .
* They have to get cleared on vg_commit .
*/
struct dm_list removed_pvs ;
uint32_t open_mode ; /* FIXME: read or write - check lock type? */
uint32_t mda_copies ; /* target number of mdas for this VG */
2012-01-19 19:31:45 +04:00
struct dm_hash_table * hostnames ; /* map of creation hostnames */
2013-07-05 19:10:47 +04:00
struct logical_volume * pool_metadata_spare_lv ; /* one per VG */
2015-03-05 23:00:44 +03:00
struct logical_volume * sanlock_lv ; /* one per VG */
2021-03-05 18:21:50 +03:00
struct dm_list msg_list ;
2010-09-30 17:16:55 +04:00
} ;
2011-03-10 15:43:29 +03:00
struct volume_group * alloc_vg ( const char * pool_name , struct cmd_context * cmd ,
const char * vg_name ) ;
2011-08-11 00:25:29 +04:00
/*
* release_vg ( ) must be called on every struct volume_group allocated
* by vg_create ( ) or vg_read_internal ( ) to free it when no longer required .
*/
void release_vg ( struct volume_group * vg ) ;
2012-02-13 15:03:59 +04:00
void free_orphan_vg ( struct volume_group * vg ) ;
2011-08-11 00:25:29 +04:00
2010-09-30 18:08:33 +04:00
char * vg_fmt_dup ( const struct volume_group * vg ) ;
char * vg_name_dup ( const struct volume_group * vg ) ;
char * vg_system_id_dup ( const struct volume_group * vg ) ;
2015-03-05 23:00:44 +03:00
char * vg_lock_type_dup ( const struct volume_group * vg ) ;
char * vg_lock_args_dup ( const struct volume_group * vg ) ;
2010-09-30 17:16:55 +04:00
uint32_t vg_seqno ( const struct volume_group * vg ) ;
uint64_t vg_status ( const struct volume_group * vg ) ;
int vg_set_alloc_policy ( struct volume_group * vg , alloc_policy_t alloc ) ;
2014-10-24 21:29:04 +04:00
int vg_set_system_id ( struct volume_group * vg , const char * system_id ) ;
2015-03-05 23:00:44 +03:00
int vg_set_lock_type ( struct volume_group * vg , const char * lock_type ) ;
2010-09-30 17:16:55 +04:00
uint64_t vg_size ( const struct volume_group * vg ) ;
uint64_t vg_free ( const struct volume_group * vg ) ;
uint64_t vg_extent_size ( const struct volume_group * vg ) ;
2014-10-14 21:12:15 +04:00
int vg_check_new_extent_size ( const struct format_type * fmt , uint32_t new_extent_size ) ;
2010-09-30 17:16:55 +04:00
int vg_set_extent_size ( struct volume_group * vg , uint32_t new_extent_size ) ;
uint64_t vg_extent_count ( const struct volume_group * vg ) ;
uint64_t vg_free_count ( const struct volume_group * vg ) ;
uint64_t vg_pv_count ( const struct volume_group * vg ) ;
uint64_t vg_max_pv ( const struct volume_group * vg ) ;
int vg_set_max_pv ( struct volume_group * vg , uint32_t max_pv ) ;
uint64_t vg_max_lv ( const struct volume_group * vg ) ;
int vg_set_max_lv ( struct volume_group * vg , uint32_t max_lv ) ;
uint32_t vg_mda_count ( const struct volume_group * vg ) ;
uint32_t vg_mda_used_count ( const struct volume_group * vg ) ;
uint32_t vg_mda_copies ( const struct volume_group * vg ) ;
int vg_set_mda_copies ( struct volume_group * vg , uint32_t mda_copies ) ;
2013-07-02 16:34:52 +04:00
char * vg_profile_dup ( const struct volume_group * vg ) ;
2011-08-11 00:26:41 +04:00
2010-09-30 17:16:55 +04:00
/*
* Returns visible LV count - number of LVs from user perspective
*/
unsigned vg_visible_lvs ( const struct volume_group * vg ) ;
2011-08-11 00:26:41 +04:00
2010-09-30 17:16:55 +04:00
/*
* Count snapshot LVs .
*/
unsigned snapshot_count ( const struct volume_group * vg ) ;
uint64_t vg_mda_size ( const struct volume_group * vg ) ;
uint64_t vg_mda_free ( const struct volume_group * vg ) ;
2010-09-30 17:52:55 +04:00
char * vg_attr_dup ( struct dm_pool * mem , const struct volume_group * vg ) ;
2010-09-30 18:07:47 +04:00
char * vg_uuid_dup ( const struct volume_group * vg ) ;
2010-09-30 18:08:19 +04:00
char * vg_tags_dup ( const struct volume_group * vg ) ;
2010-09-30 17:16:55 +04:00
2010-10-25 16:01:59 +04:00
# endif /* _LVM_VG_H */