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 ) ;
2016-06-06 22:04:17 +03:00
struct lvmcache_info * lvmcache_info_from_pvid ( const char * pvid , struct device * dev , int valid_only ) ;
2012-02-10 05:28:27 +04:00
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 ,
2016-04-08 12:36:02 +03:00
const char * devname ) ;
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 ) ;
lvmcache: process duplicate PVs directly
Previously, duplicate PVs were processed as a side effect
of processing the "chosen" PV in lvmcache. The duplicate
PV would be hacked into lvmcache temporarily in place of
the chosen PV.
In the old way, we had to always process the "chosen" PV
device, even if a duplicate of it was named on the command
line. This meant we were processing a different device than
was asked for. This could be worked around by naming
multiple duplicate devs on the command line in which case
they were swapped in and out of lvmcache for processing.
Now, the duplicate devs are processed directly in their
own processing loop. This means we can remove the old
hacks related to processing dups as a side effect of
processing the chosen device. We can now simply process
the device that was named on the command line.
When the same PVID exists on two or more devices, one device
is preferred and used in the VG, and the others are duplicates
and are not used in the VG. The preferred device exists in
lvmcache as usual. The duplicates exist in a specical list
of unused duplicate devices.
The duplicate devs have the "d" attribute and the "duplicate"
reporting field displays "duplicate" for them.
'pvs' warns about duplicates, but the formal output only
includes the single preferred PV.
'pvs -a' has the same warnings, and the duplicate devs are
included in the output.
'pvs <path>' has the same warnings, and displays the named
device, whether it is preferred or a duplicate.
2016-02-11 21:37:36 +03:00
const struct format_type * lvmcache_fmt_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
2015-01-14 23:38:05 +03:00
int lvmcache_found_duplicate_pvs ( void ) ;
lvmcache: process duplicate PVs directly
Previously, duplicate PVs were processed as a side effect
of processing the "chosen" PV in lvmcache. The duplicate
PV would be hacked into lvmcache temporarily in place of
the chosen PV.
In the old way, we had to always process the "chosen" PV
device, even if a duplicate of it was named on the command
line. This meant we were processing a different device than
was asked for. This could be worked around by naming
multiple duplicate devs on the command line in which case
they were swapped in and out of lvmcache for processing.
Now, the duplicate devs are processed directly in their
own processing loop. This means we can remove the old
hacks related to processing dups as a side effect of
processing the chosen device. We can now simply process
the device that was named on the command line.
When the same PVID exists on two or more devices, one device
is preferred and used in the VG, and the others are duplicates
and are not used in the VG. The preferred device exists in
lvmcache as usual. The duplicates exist in a specical list
of unused duplicate devices.
The duplicate devs have the "d" attribute and the "duplicate"
reporting field displays "duplicate" for them.
'pvs' warns about duplicates, but the formal output only
includes the single preferred PV.
'pvs -a' has the same warnings, and the duplicate devs are
included in the output.
'pvs <path>' has the same warnings, and displays the named
device, whether it is preferred or a duplicate.
2016-02-11 21:37:36 +03:00
int lvmcache_get_unused_duplicate_devs ( struct cmd_context * cmd , struct dm_list * head ) ;
lvmcache: improve duplicate PV handling
Wait to compare and choose alternate duplicate devices until
after all devices are scanned. During scanning, the first
duplicate dev is kept in lvmcache, and others are kept in a
new list (_found_duplicate_devs).
After all devices are scanned, compare all the duplicates
available for a given PVID and decide which is best.
If the dev used in lvmcache is changed, drop the old dev
from lvmcache entirely and rescan the replacement dev.
Previously the VG metadata from the old dev was kept in
lvmcache and only the dev was replaced.
A new config setting devices/allow_changes_with_duplicate_pvs
can be set to 0 which disallows modifying a VG or activating
LVs in it when the VG contains PVs with duplicate devices.
Set to 1 is the old behavior which allowed the VG to be
changed.
The logic for which of two devs is preferred has changed.
The primary goal is to choose a device that is currently
in use if the other isn't, e.g. by an active LV.
. prefer dev with fs mounted if the other doesn't, else
. prefer dev that is dm if the other isn't, else
. prefer dev in subsystem if the other isn't
If neither device is preferred by these rules, then don't
change devices in lvmcache, leaving the one that was found
first.
The previous logic for preferring a device was:
. prefer dev in subsystem if the other isn't, else
. prefer dev without holders if the other has holders, else
. prefer dev that is dm if the other isn't
2016-02-09 22:06:27 +03:00
int vg_has_duplicate_pvs ( struct volume_group * vg ) ;
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 ) ;
2016-04-29 22:42:14 +03:00
int lvmcache_dev_is_unchosen_duplicate ( struct device * dev ) ;
2016-05-13 00:19:57 +03:00
void lvmcache_remove_unchosen_duplicate ( struct device * dev ) ;
2016-06-06 23:39:51 +03:00
int lvmcache_pvid_in_unchosen_duplicates ( const char * pvid ) ;
2002-11-18 16:53:58 +03:00
# endif