2002-11-18 16:53:58 +03:00
/*
2004-03-30 23:35:44 +04:00
* Copyright ( C ) 2001 - 2004 Sistina Software , Inc . All rights reserved .
2008-03-17 19:51:31 +03:00
* Copyright ( C ) 2004 - 2008 Red Hat , Inc . All rights reserved .
2002-11-18 16:53:58 +03: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
2002-11-18 16:53:58 +03:00
*/
# ifndef _LVM_CACHE_H
# define _LVM_CACHE_H
# include "dev-cache.h"
2013-06-12 14:08:56 +04:00
# include "dev-type.h"
2002-11-18 16:53:58 +03:00
# include "uuid.h"
# include "label.h"
2010-05-19 06:36:33 +04:00
# include "locking.h"
2002-11-18 16:53:58 +03:00
2010-05-19 06:36:33 +04:00
# define ORPHAN_PREFIX VG_ORPHANS
# define ORPHAN_VG_NAME(fmt) ORPHAN_PREFIX "_" fmt
2002-11-18 16:53:58 +03:00
/* LVM specific per-volume info */
/* Eventual replacement for struct physical_volume perhaps? */
2004-05-05 01:25:57 +04:00
struct cmd_context ;
struct format_type ;
struct volume_group ;
2012-02-10 05:28:27 +04:00
struct physical_volume ;
2011-08-30 18:55:15 +04:00
struct dm_config_tree ;
2012-02-10 05:28:27 +04:00
struct format_instance ;
struct metadata_area ;
2012-02-23 17:11:07 +04:00
struct disk_locn ;
2004-05-05 01:25:57 +04:00
2012-02-10 05:28:27 +04:00
struct lvmcache_vginfo ;
2002-11-18 16:53:58 +03:00
2015-07-24 23:20:37 +03:00
/*
* vgsummary represents a summary of the VG that is read
* without a lock . The info does not come through vg_read ( ) ,
* but through reading mdas . It provides information about
* the VG that is needed to lock the VG and then read it fully
* with vg_read ( ) , after which the VG summary should be checked
* against the full VG metadata to verify it was correct ( since
* it was read without a lock . )
*
* Once read , vgsummary information is saved in lvmcache_vginfo .
*/
2015-03-19 02:43:02 +03:00
struct lvmcache_vgsummary {
const char * vgname ;
struct id vgid ;
uint64_t vgstatus ;
char * creation_host ;
2015-11-30 20:32:17 +03:00
const char * system_id ;
2015-07-24 23:20:37 +03:00
const char * lock_type ;
2015-03-19 02:43:02 +03:00
uint32_t mda_checksum ;
size_t mda_size ;
} ;
2003-07-05 02:34:56 +04:00
int lvmcache_init ( void ) ;
2012-02-23 21:59:32 +04:00
void lvmcache_allow_reads_with_lvmetad ( void ) ;
2012-02-23 17:11:07 +04:00
2014-03-22 01:26:39 +04:00
void lvmcache_destroy ( struct cmd_context * cmd , int retain_orphans , int reset ) ;
2002-11-18 16:53:58 +03:00
2015-12-01 23:09:01 +03:00
/*
* lvmcache_label_scan ( ) will scan labels the first time it ' s
* called , but not on subsequent calls , unless
* lvmcache_force_next_label_scan ( ) is called first
* to force the next lvmcache_label_scan ( ) to scan again .
*/
void lvmcache_force_next_label_scan ( void ) ;
int lvmcache_label_scan ( struct cmd_context * cmd ) ;
2002-11-18 16:53:58 +03:00
/* Add/delete a device */
2003-07-05 02:34:56 +04:00
struct lvmcache_info * lvmcache_add ( struct labeller * labeller , const char * pvid ,
struct device * dev ,
2006-04-11 21:42:15 +04:00
const char * vgname , const char * vgid ,
uint32_t vgstatus ) ;
2008-04-08 16:49:21 +04:00
int lvmcache_add_orphan_vginfo ( const char * vgname , struct format_type * fmt ) ;
2003-07-05 02:34:56 +04:00
void lvmcache_del ( struct lvmcache_info * info ) ;
2002-11-18 16:53:58 +03:00
/* Update things */
2006-04-11 21:42:15 +04:00
int lvmcache_update_vgname_and_id ( struct lvmcache_info * info ,
2015-03-19 02:43:02 +03:00
struct lvmcache_vgsummary * vgsummary ) ;
2008-03-17 19:51:31 +03:00
int lvmcache_update_vg ( struct volume_group * vg , unsigned precommitted ) ;
2003-07-05 02:34:56 +04:00
void lvmcache_lock_vgname ( const char * vgname , int read_only ) ;
void lvmcache_unlock_vgname ( const char * vgname ) ;
2009-09-03 01:34:11 +04:00
int lvmcache_verify_lock_order ( const char * vgname ) ;
2002-11-18 16:53:58 +03:00
/* Queries */
2012-02-23 17:11:07 +04:00
const struct format_type * lvmcache_fmt_from_vgname ( struct cmd_context * cmd , const char * vgname , const char * vgid , unsigned revalidate_labels ) ;
2015-03-19 02:43:02 +03:00
int lvmcache_lookup_mda ( struct lvmcache_vgsummary * vgsummary ) ;
2012-02-10 05:28:27 +04:00
2011-08-11 21:24:23 +04:00
/* Decrement and test if there are still vg holders in vginfo. */
2012-02-10 05:28:27 +04:00
int lvmcache_vginfo_holders_dec_and_test_for_zero ( struct lvmcache_vginfo * vginfo ) ;
struct lvmcache_vginfo * lvmcache_vginfo_from_vgname ( const char * vgname ,
2006-04-12 21:54:11 +04:00
const char * vgid ) ;
2012-02-10 05:28:27 +04:00
struct lvmcache_vginfo * lvmcache_vginfo_from_vgid ( const char * vgid ) ;
struct lvmcache_info * lvmcache_info_from_pvid ( const char * pvid , int valid_only ) ;
const char * lvmcache_vgname_from_vgid ( struct dm_pool * mem , const char * vgid ) ;
vg_read: look up vgid from name
After recent changes to process_each, vg_read() is usually
given both the vgname and vgid for the intended VG.
However, in some cases vg_read() is given a vgid with
no vgname, or is given a vgname with no vgid.
When given a vgid with no vgname, vg_read() uses lvmcache
to look up the vgname using the vgid. If the vgname is
not found, vg_read() fails.
When given a vgname with no vgid, vg_read() should also
use lvmcache to look up the vgid using the vgname.
If the vgid is not found, vg_read() fails.
If the lvmcache lookup finds multiple vgids for the
vgname, then the lookup fails, causing vg_read() to fail
because the intended VG is uncertain.
Usually, both vgname and vgid for the intended VG are passed
to vg_read(), which means the lvmcache translations
between vgname and vgid are not done.
2015-12-01 00:12:01 +03:00
const char * lvmcache_vgid_from_vgname ( struct cmd_context * cmd , const char * vgname ) ;
2012-02-10 05:28:27 +04:00
struct device * lvmcache_device_from_pvid ( struct cmd_context * cmd , const struct id * pvid ,
2011-06-01 23:29:31 +04:00
unsigned * scan_done_once , uint64_t * label_sector ) ;
2012-02-10 05:28:27 +04:00
const char * lvmcache_pvid_from_devname ( struct cmd_context * cmd ,
2010-05-19 15:52:07 +04:00
const char * dev_name ) ;
2010-05-19 15:52:21 +04:00
char * lvmcache_vgname_from_pvid ( struct cmd_context * cmd , const char * pvid ) ;
2012-02-23 17:11:07 +04:00
const char * lvmcache_vgname_from_info ( struct lvmcache_info * info ) ;
2012-02-10 05:28:27 +04:00
int lvmcache_vgs_locked ( void ) ;
int lvmcache_vgname_is_locked ( const char * vgname ) ;
2002-11-18 16:53:58 +03:00
2012-02-23 17:11:07 +04:00
void lvmcache_seed_infos_from_lvmetad ( struct cmd_context * cmd ) ;
2014-05-29 11:41:03 +04:00
/* Returns list of struct dm_str_list containing pool-allocated copy of vgnames */
2010-03-16 19:57:03 +03:00
/* If include_internal is not set, return only proper vg names. */
struct dm_list * lvmcache_get_vgnames ( struct cmd_context * cmd ,
int include_internal ) ;
2002-11-18 16:53:58 +03:00
2014-05-29 11:41:03 +04:00
/* Returns list of struct dm_str_list containing pool-allocated copy of vgids */
2010-03-16 19:57:03 +03:00
/* If include_internal is not set, return only proper vg ids. */
struct dm_list * lvmcache_get_vgids ( struct cmd_context * cmd ,
int include_internal ) ;
2006-04-13 01:23:04 +04:00
2015-05-06 00:24:50 +03:00
int lvmcache_get_vgnameids ( struct cmd_context * cmd , int include_internal ,
struct dm_list * vgnameids ) ;
2014-05-29 11:41:03 +04:00
/* Returns list of struct dm_str_list containing pool-allocated copy of pvids */
2008-11-04 01:14:30 +03:00
struct dm_list * lvmcache_get_pvids ( struct cmd_context * cmd , const char * vgname ,
2006-04-21 23:12:41 +04:00
const char * vgid ) ;
2008-04-02 02:40:13 +04:00
/* Returns cached volume group metadata. */
2012-02-23 17:11:07 +04:00
struct volume_group * lvmcache_get_vg ( struct cmd_context * cmd , const char * vgname ,
const char * vgid , unsigned precommitted ) ;
2010-01-05 19:06:42 +03:00
void lvmcache_drop_metadata ( const char * vgname , int drop_precommitted ) ;
void lvmcache_commit_metadata ( const char * vgname ) ;
2008-04-02 02:40:13 +04:00
2012-02-10 05:28:27 +04:00
int lvmcache_pvid_is_locked ( const char * pvid ) ;
int lvmcache_fid_add_mdas ( struct lvmcache_info * info , struct format_instance * fid ,
const char * id , int id_len ) ;
int lvmcache_fid_add_mdas_pv ( struct lvmcache_info * info , struct format_instance * fid ) ;
int lvmcache_fid_add_mdas_vg ( struct lvmcache_vginfo * vginfo , struct format_instance * fid ) ;
int lvmcache_populate_pv_fields ( struct lvmcache_info * info ,
struct physical_volume * pv ,
int scan_label_only ) ;
int lvmcache_check_format ( struct lvmcache_info * info , const struct format_type * fmt ) ;
void lvmcache_del_mdas ( struct lvmcache_info * info ) ;
void lvmcache_del_das ( struct lvmcache_info * info ) ;
2013-05-28 14:37:22 +04:00
void lvmcache_del_bas ( struct lvmcache_info * info ) ;
2012-02-10 05:28:27 +04:00
int lvmcache_add_mda ( struct lvmcache_info * info , struct device * dev ,
uint64_t start , uint64_t size , unsigned ignored ) ;
int lvmcache_add_da ( struct lvmcache_info * info , uint64_t start , uint64_t size ) ;
2013-05-28 14:37:22 +04:00
int lvmcache_add_ba ( struct lvmcache_info * info , uint64_t start , uint64_t size ) ;
2012-02-10 05:28:27 +04:00
2016-02-11 18:25:36 +03:00
void lvmcache_set_ext_version ( struct lvmcache_info * info , uint32_t version ) ;
uint32_t lvmcache_ext_version ( struct lvmcache_info * info ) ;
2015-03-09 14:52:07 +03:00
void lvmcache_set_ext_flags ( struct lvmcache_info * info , uint32_t flags ) ;
uint32_t lvmcache_ext_flags ( struct lvmcache_info * info ) ;
2012-02-10 05:28:27 +04:00
const struct format_type * lvmcache_fmt ( struct lvmcache_info * info ) ;
struct label * lvmcache_get_label ( struct lvmcache_info * info ) ;
void lvmcache_update_pv ( struct lvmcache_info * info , struct physical_volume * pv ,
const struct format_type * fmt ) ;
int lvmcache_update_das ( struct lvmcache_info * info , struct physical_volume * pv ) ;
2013-05-28 14:37:22 +04:00
int lvmcache_update_bas ( struct lvmcache_info * info , struct physical_volume * pv ) ;
2012-02-10 05:28:27 +04:00
int lvmcache_foreach_mda ( struct lvmcache_info * info ,
int ( * fun ) ( struct metadata_area * , void * ) ,
void * baton ) ;
int lvmcache_foreach_da ( struct lvmcache_info * info ,
2012-02-23 17:11:07 +04:00
int ( * fun ) ( struct disk_locn * , void * ) ,
2012-02-10 05:28:27 +04:00
void * baton ) ;
2013-05-28 14:37:22 +04:00
int lvmcache_foreach_ba ( struct lvmcache_info * info ,
2013-02-14 18:35:57 +04:00
int ( * fun ) ( struct disk_locn * , void * ) ,
void * baton ) ;
2012-02-10 05:28:27 +04:00
int lvmcache_foreach_pv ( struct lvmcache_vginfo * vg ,
int ( * fun ) ( struct lvmcache_info * , void * ) , void * baton ) ;
uint64_t lvmcache_device_size ( struct lvmcache_info * info ) ;
void lvmcache_set_device_size ( struct lvmcache_info * info , uint64_t size ) ;
struct device * lvmcache_device ( struct lvmcache_info * info ) ;
void lvmcache_make_valid ( struct lvmcache_info * info ) ;
int lvmcache_is_orphan ( struct lvmcache_info * info ) ;
int lvmcache_uncertain_ownership ( struct lvmcache_info * info ) ;
2013-02-05 19:43:16 +04:00
unsigned lvmcache_mda_count ( struct lvmcache_info * info ) ;
2012-02-10 05:28:27 +04:00
int lvmcache_vgid_is_cached ( const char * vgid ) ;
2013-02-05 19:43:16 +04:00
uint64_t lvmcache_smallest_mda_size ( struct lvmcache_info * info ) ;
2012-02-10 05:28:27 +04:00
toollib: override the PV device with duplicates
When multiple duplicate devices are specified on the
command line, the PV is processed once for each of them,
but pv->dev is the device used each time.
This overrides the PV device to reflect the duplicate
device that was specified on the command line. This is
done by hacking the lvmcache to replace pv->dev with the
device of the duplicate being processed. (It would be
preferable to override pv->dev without munging the content
of the cache, and without sprinkling special cases throughout
the code.)
This override only applies when multiple duplicate devices are
specified on the command line. When only a single duplicate
device of pv->dev is specified, the priority is to display the
cached pv->dev, so pv->dev is not overridden by the named
duplicate device.
In the examples below, loop3 is the cached device referenced
by pv->dev, and is given priority for processing. Only after
loop3 is processed/displayed, will other duplicate devices
loop0/loop1 appear (when requested on the command line.)
With two duplicate devices, loop0 and loop3:
# pvs
Found duplicate PV XhLbpVo0hmuwrMQLjfxuAvPFUFZqD4vr: using /dev/loop3 not /dev/loop0
PV VG Fmt Attr PSize PFree
/dev/loop3 loopa lvm2 a-- 12.00m 12.00m
# pvs /dev/loop3
Found duplicate PV XhLbpVo0hmuwrMQLjfxuAvPFUFZqD4vr: using /dev/loop3 not /dev/loop0
PV VG Fmt Attr PSize PFree
/dev/loop3 loopa lvm2 a-- 12.00m 12.00m
# pvs /dev/loop0
Found duplicate PV XhLbpVo0hmuwrMQLjfxuAvPFUFZqD4vr: using /dev/loop3 not /dev/loop0
PV VG Fmt Attr PSize PFree
/dev/loop3 loopa lvm2 a-- 12.00m 12.00m
# pvs -o+dev_size /dev/loop0 /dev/loop3
Found duplicate PV XhLbpVo0hmuwrMQLjfxuAvPFUFZqD4vr: using /dev/loop3 not /dev/loop0
PV VG Fmt Attr PSize PFree DevSize
/dev/loop0 loopa lvm2 a-- 12.00m 12.00m 16.00m
/dev/loop3 loopa lvm2 a-- 12.00m 12.00m 32.00m
With three duplicate devices, loop0, loop1, loop3:
# pvs -o+dev_size
Found duplicate PV XhLbpVo0hmuwrMQLjfxuAvPFUFZqD4vr: using /dev/loop1 not /dev/loop0
Found duplicate PV XhLbpVo0hmuwrMQLjfxuAvPFUFZqD4vr: using /dev/loop3 not /dev/loop1
PV VG Fmt Attr PSize PFree DevSize
/dev/loop3 loopa lvm2 a-- 12.00m 12.00m 32.00m
# pvs -o+dev_size /dev/loop3
Found duplicate PV XhLbpVo0hmuwrMQLjfxuAvPFUFZqD4vr: using /dev/loop1 not /dev/loop0
Found duplicate PV XhLbpVo0hmuwrMQLjfxuAvPFUFZqD4vr: using /dev/loop3 not /dev/loop1
PV VG Fmt Attr PSize PFree DevSize
/dev/loop3 loopa lvm2 a-- 12.00m 12.00m 32.00m
# pvs -o+dev_size /dev/loop0
Found duplicate PV XhLbpVo0hmuwrMQLjfxuAvPFUFZqD4vr: using /dev/loop1 not /dev/loop0
Found duplicate PV XhLbpVo0hmuwrMQLjfxuAvPFUFZqD4vr: using /dev/loop3 not /dev/loop1
PV VG Fmt Attr PSize PFree DevSize
/dev/loop3 loopa lvm2 a-- 12.00m 12.00m 32.00m
# pvs -o+dev_size /dev/loop1
Found duplicate PV XhLbpVo0hmuwrMQLjfxuAvPFUFZqD4vr: using /dev/loop1 not /dev/loop0
Found duplicate PV XhLbpVo0hmuwrMQLjfxuAvPFUFZqD4vr: using /dev/loop3 not /dev/loop1
PV VG Fmt Attr PSize PFree DevSize
/dev/loop3 loopa lvm2 a-- 12.00m 12.00m 32.00m
# pvs -o+dev_size /dev/loop3 /dev/loop0
Found duplicate PV XhLbpVo0hmuwrMQLjfxuAvPFUFZqD4vr: using /dev/loop1 not /dev/loop0
Found duplicate PV XhLbpVo0hmuwrMQLjfxuAvPFUFZqD4vr: using /dev/loop3 not /dev/loop1
PV VG Fmt Attr PSize PFree DevSize
/dev/loop0 loopa lvm2 a-- 12.00m 12.00m 16.00m
/dev/loop3 loopa lvm2 a-- 12.00m 12.00m 32.00m
# pvs -o+dev_size /dev/loop3 /dev/loop1
Found duplicate PV XhLbpVo0hmuwrMQLjfxuAvPFUFZqD4vr: using /dev/loop1 not /dev/loop0
Found duplicate PV XhLbpVo0hmuwrMQLjfxuAvPFUFZqD4vr: using /dev/loop3 not /dev/loop1
PV VG Fmt Attr PSize PFree DevSize
/dev/loop1 loopa lvm2 a-- 12.00m 12.00m 32.00m
/dev/loop3 loopa lvm2 a-- 12.00m 12.00m 32.00m
# pvs -o+dev_size /dev/loop0 /dev/loop1
Found duplicate PV XhLbpVo0hmuwrMQLjfxuAvPFUFZqD4vr: using /dev/loop1 not /dev/loop0
Found duplicate PV XhLbpVo0hmuwrMQLjfxuAvPFUFZqD4vr: using /dev/loop3 not /dev/loop1
PV VG Fmt Attr PSize PFree DevSize
/dev/loop1 loopa lvm2 a-- 12.00m 12.00m 32.00m
/dev/loop3 loopa lvm2 a-- 12.00m 12.00m 32.00m
# pvs -o+dev_size /dev/loop0 /dev/loop1 /dev/loop3
Found duplicate PV XhLbpVo0hmuwrMQLjfxuAvPFUFZqD4vr: using /dev/loop1 not /dev/loop0
Found duplicate PV XhLbpVo0hmuwrMQLjfxuAvPFUFZqD4vr: using /dev/loop3 not /dev/loop1
PV VG Fmt Attr PSize PFree DevSize
/dev/loop0 loopa lvm2 a-- 12.00m 12.00m 16.00m
/dev/loop1 loopa lvm2 a-- 12.00m 12.00m 32.00m
/dev/loop3 loopa lvm2 a-- 12.00m 12.00m 32.00m
2015-01-14 01:16:22 +03:00
void lvmcache_replace_dev ( struct cmd_context * cmd , struct physical_volume * pv ,
struct device * dev ) ;
2015-01-14 23:38:05 +03:00
int lvmcache_found_duplicate_pvs ( void ) ;
2015-05-06 22:49:44 +03:00
void lvmcache_set_preferred_duplicates ( const char * vgid ) ;
2015-07-24 18:06:58 +03:00
int lvmcache_contains_lock_type_sanlock ( struct cmd_context * cmd ) ;
2015-10-19 21:58:43 +03:00
void lvmcache_get_max_name_lengths ( struct cmd_context * cmd ,
unsigned * pv_max_name_len , unsigned * vg_max_name_len ) ;
2015-11-30 20:54:56 +03:00
int lvmcache_vg_is_foreign ( struct cmd_context * cmd , const char * vgname , const char * vgid ) ;
2015-10-19 21:58:43 +03:00
2015-12-01 23:09:01 +03:00
void lvmcache_lock_ordering ( int enable ) ;
2002-11-18 16:53:58 +03:00
# endif