2012-02-23 17:11:07 +04:00
/*
2012-02-28 22:22:52 +04:00
* Copyright ( C ) 2012 Red Hat , Inc .
2012-02-23 17:11:07 +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
2012-02-23 17:11:07 +04:00
*/
# ifndef _LVM_METAD_H
# define _LVM_METAD_H
2012-09-26 16:44:03 +04:00
# include "config-util.h"
2012-08-11 12:37:28 +04:00
2018-02-12 16:41:27 +03:00
# include <stdint.h>
2012-02-23 17:11:07 +04:00
struct volume_group ;
struct cmd_context ;
struct dm_config_tree ;
2012-08-23 18:12:45 +04:00
enum activation_change ;
2012-02-23 17:11:07 +04:00
2012-12-12 15:51:28 +04:00
typedef int ( * activation_handler ) ( struct cmd_context * cmd ,
2014-03-14 15:07:41 +04:00
const char * vgname , const char * vgid ,
2014-03-14 13:44:14 +04:00
int partial , int changed ,
2012-08-23 18:12:45 +04:00
enum activation_change activate ) ;
2012-06-27 16:59:34 +04:00
2012-02-28 22:22:52 +04:00
# ifdef LVMETAD_SUPPORT
2012-02-23 17:11:07 +04:00
/*
2016-04-14 01:00:01 +03:00
* lvmetad_connect : connect to lvmetad
* lvmetad_disconnect : disconnect from lvmetad
* lvmetad_make_unused : disconnect from lvmetad and refresh cmd filter
* lvmetad_used : check if lvmetad is being used ( i . e . is connected )
2012-02-23 17:11:07 +04:00
*/
2016-04-14 01:00:01 +03:00
int lvmetad_connect ( struct cmd_context * cmd ) ;
void lvmetad_disconnect ( void ) ;
void lvmetad_make_unused ( struct cmd_context * cmd ) ;
int lvmetad_used ( void ) ;
2012-02-23 17:11:07 +04:00
2012-08-13 21:44:10 +04:00
/*
* Configure the socket that lvmetad_init will use to connect to the daemon .
*/
void lvmetad_set_socket ( const char * ) ;
2013-11-26 17:51:23 +04:00
/*
* Check if lvmetad socket is present ( either the one set by lvmetad_set_socket
2016-04-14 01:00:01 +03:00
* or the default one if not set ) .
2013-11-26 17:51:23 +04:00
*/
int lvmetad_socket_present ( void ) ;
2016-04-21 17:50:59 +03:00
/*
* Check if lvmetad pidfile is present , indicating that the lvmetad
* process is running or not .
*/
int lvmetad_pidfile_present ( void ) ;
2012-08-13 21:44:10 +04:00
/*
* Set the " lvmetad validity token " ( currently only consists of the lvmetad
* filter . See lvm . conf .
*/
void lvmetad_set_token ( const struct dm_config_value * filter ) ;
2012-10-12 18:50:38 +04:00
/*
* Release allocated token .
*/
void lvmetad_release_token ( void ) ;
2013-01-05 07:07:43 +04:00
// FIXME What's described here doesn't appear to be implemented yet.
2012-02-23 17:11:07 +04:00
/*
* Send a new version of VG metadata to lvmetad . This is normally called after
* vg_write but before vg_commit . After vg_commit , lvmetad_vg_commit is called
* to seal the transaction . The result of lvmetad_vg_update is that the new
* metadata is stored tentatively in lvmetad , but it is not used until
* lvmetad_vg_commit . The request is validated immediately and lvmetad_vg_commit
* only constitutes a pointer update .
*/
lvmetad: two phase vg_update
Previously, a command sent lvmetad new VG metadata in vg_commit().
In vg_commit(), devices are suspended, so any memory allocation
done by the command while sending to lvmetad, or by lvmetad while
updating its cache could deadlock if memory reclaim was triggered.
Now lvmetad is updated in unlock_vg(), after devices are resumed.
The new method for updating VG metadata in lvmetad is in two phases:
1. In vg_write(), before devices are suspended, the command sends
lvmetad a short message ("set_vg_info") telling it what the new
VG seqno will be. lvmetad sees that the seqno is newer than
the seqno of its cached VG, so it sets the INVALID flag for the
cached VG. If sending the message to lvmetad fails, the command
fails before the metadata is committed and the change is not made.
If sending the message succeeds, vg_commit() is called.
2. In unlock_vg(), after devices are resumed, the command sends
lvmetad the standard vg_update message with the new metadata.
lvmetad sees that the seqno in the new metadata matches the
seqno it saved from set_vg_info, and knows it has the latest
copy, so it clears the INVALID flag for the cached VG.
If a command fails between 1 and 2 (after committing the VG on disk,
but before sending lvmetad the new metadata), the cached VG retains
the INVALID flag in lvmetad. A subsequent command will read the
cached VG from lvmetad, see the INVALID flag, ignore the cached
copy, read the VG from disk instead, update the lvmetad copy
with the latest copy from disk, (this clears the INVALID flag
in lvmetad), and use the correct VG metadata for the command.
(This INVALID mechanism already existed for use by lvmlockd.)
2016-06-08 22:42:03 +03:00
int lvmetad_vg_update_pending ( struct volume_group * vg ) ;
int lvmetad_vg_update_finish ( struct volume_group * vg ) ;
2012-02-23 17:11:07 +04:00
/*
* Inform lvmetad that a VG has been removed . This is not entirely safe , but is
* only needed during vgremove , which does not wipe PV labels and therefore
* cannot mark the PVs as gone .
*/
2016-06-09 00:02:45 +03:00
int lvmetad_vg_remove_pending ( struct volume_group * vg ) ;
int lvmetad_vg_remove_finish ( struct volume_group * vg ) ;
2012-02-23 17:11:07 +04:00
/*
* Notify lvmetad that a PV has been found . It is not an error if the PV is
* already marked as present in lvmetad . If a non - NULL vg pointer is supplied ,
* it is taken to represent the metadata read from the MDA ( s ) present on that
* PV . It * is * an error if : the VG is already known to lvmetad , the sequence
* number on the cached and on the discovered PV match but the metadata content
* does not .
*/
pvscan: use process_each_vg for autoactivate
This refactors the code for autoactivation. Previously,
as each PV was found, it would be sent to lvmetad, and
the VG would be autoactivated using a non-standard VG
processing function (the "activation_handler") called via
a function pointer from within the lvmetad notification path.
Now, any scanning that the command needs to do (scanning
only the named device args, or scanning all devices when
there are no args), is done first, before any activation
is attempted. During the scans, the VG names are saved.
After scanning is complete, process_each_vg is used to do
autoactivation of the saved VG names. This makes pvscan
activation much more similar to activation done with
vgchange or lvchange.
The separate autoactivate phase also means that if lvmetad
is disabled (either before or during the scan), the command
can continue with the activation step by simply not using
lvmetad and reverting to disk scanning to do the
activation.
2016-04-28 17:37:03 +03:00
int lvmetad_pv_found ( struct cmd_context * cmd , const struct id * pvid , struct device * dev ,
2012-02-23 17:11:07 +04:00
const struct format_type * fmt , uint64_t label_sector ,
pvscan: use process_each_vg for autoactivate
This refactors the code for autoactivation. Previously,
as each PV was found, it would be sent to lvmetad, and
the VG would be autoactivated using a non-standard VG
processing function (the "activation_handler") called via
a function pointer from within the lvmetad notification path.
Now, any scanning that the command needs to do (scanning
only the named device args, or scanning all devices when
there are no args), is done first, before any activation
is attempted. During the scans, the VG names are saved.
After scanning is complete, process_each_vg is used to do
autoactivation of the saved VG names. This makes pvscan
activation much more similar to activation done with
vgchange or lvchange.
The separate autoactivate phase also means that if lvmetad
is disabled (either before or during the scan), the command
can continue with the activation step by simply not using
lvmetad and reverting to disk scanning to do the
activation.
2016-04-28 17:37:03 +03:00
struct volume_group * vg ,
struct dm_list * found_vgnames ,
struct dm_list * changed_vgnames ) ;
2012-02-23 17:11:07 +04:00
/*
2012-03-03 22:32:53 +04:00
* Inform the daemon that the device no longer exists .
2012-02-23 17:11:07 +04:00
*/
pvscan: use process_each_vg for autoactivate
This refactors the code for autoactivation. Previously,
as each PV was found, it would be sent to lvmetad, and
the VG would be autoactivated using a non-standard VG
processing function (the "activation_handler") called via
a function pointer from within the lvmetad notification path.
Now, any scanning that the command needs to do (scanning
only the named device args, or scanning all devices when
there are no args), is done first, before any activation
is attempted. During the scans, the VG names are saved.
After scanning is complete, process_each_vg is used to do
autoactivation of the saved VG names. This makes pvscan
activation much more similar to activation done with
vgchange or lvchange.
The separate autoactivate phase also means that if lvmetad
is disabled (either before or during the scan), the command
can continue with the activation step by simply not using
lvmetad and reverting to disk scanning to do the
activation.
2016-04-28 17:37:03 +03:00
int lvmetad_pv_gone ( dev_t devno , const char * pv_name ) ;
int lvmetad_pv_gone_by_dev ( struct device * dev ) ;
2012-02-23 17:11:07 +04:00
/*
* Request a list of all PVs available to lvmetad . If requested , this will also
* read labels off all the PVs to populate lvmcache .
*/
int lvmetad_pv_list_to_lvmcache ( struct cmd_context * cmd ) ;
2012-03-03 00:46:36 +04:00
/*
* Lookup an individual PV .
* If found is not NULL , it is set according to whether or not the PV is found ,
* otherwise if the PV is not found an error is returned .
*/
int lvmetad_pv_lookup ( struct cmd_context * cmd , struct id pvid , int * found ) ;
int lvmetad_pv_lookup_by_dev ( struct cmd_context * cmd , struct device * dev , int * found ) ;
2012-02-23 17:11:07 +04:00
/*
* Request a list of all VGs available to lvmetad and use it to fill in
* lvmcache . .
*/
int lvmetad_vg_list_to_lvmcache ( struct cmd_context * cmd ) ;
2015-05-06 00:24:50 +03:00
/*
* Request a list of vgid / vgname pairs for all VGs known to lvmetad .
* Does not do vg_lookup ' s on each VG , and does not populate lvmcache .
*/
int lvmetad_get_vgnameids ( struct cmd_context * cmd , struct dm_list * vgnameids ) ;
2012-02-26 12:50:13 +04:00
/*
* Find a VG by its ID or its name in the lvmetad cache . Gives NULL if the VG is
* not found .
*/
struct volume_group * lvmetad_vg_lookup ( struct cmd_context * cmd ,
const char * vgname , const char * vgid ) ;
2012-02-23 17:11:07 +04:00
/*
2012-03-03 22:32:53 +04:00
* Scan a single device and update lvmetad with the result ( s ) .
2012-02-23 17:11:07 +04:00
*/
2012-09-10 00:05:59 +04:00
int lvmetad_pvscan_single ( struct cmd_context * cmd , struct device * dev ,
pvscan: use process_each_vg for autoactivate
This refactors the code for autoactivation. Previously,
as each PV was found, it would be sent to lvmetad, and
the VG would be autoactivated using a non-standard VG
processing function (the "activation_handler") called via
a function pointer from within the lvmetad notification path.
Now, any scanning that the command needs to do (scanning
only the named device args, or scanning all devices when
there are no args), is done first, before any activation
is attempted. During the scans, the VG names are saved.
After scanning is complete, process_each_vg is used to do
autoactivation of the saved VG names. This makes pvscan
activation much more similar to activation done with
vgchange or lvchange.
The separate autoactivate phase also means that if lvmetad
is disabled (either before or during the scan), the command
can continue with the activation step by simply not using
lvmetad and reverting to disk scanning to do the
activation.
2016-04-28 17:37:03 +03:00
struct dm_list * found_vgnames ,
struct dm_list * changed_vgnames ) ;
2012-02-23 17:11:07 +04:00
pvscan: use process_each_vg for autoactivate
This refactors the code for autoactivation. Previously,
as each PV was found, it would be sent to lvmetad, and
the VG would be autoactivated using a non-standard VG
processing function (the "activation_handler") called via
a function pointer from within the lvmetad notification path.
Now, any scanning that the command needs to do (scanning
only the named device args, or scanning all devices when
there are no args), is done first, before any activation
is attempted. During the scans, the VG names are saved.
After scanning is complete, process_each_vg is used to do
autoactivation of the saved VG names. This makes pvscan
activation much more similar to activation done with
vgchange or lvchange.
The separate autoactivate phase also means that if lvmetad
is disabled (either before or during the scan), the command
can continue with the activation step by simply not using
lvmetad and reverting to disk scanning to do the
activation.
2016-04-28 17:37:03 +03:00
int lvmetad_pvscan_all_devs ( struct cmd_context * cmd , int do_wait ) ;
2012-08-13 21:44:10 +04:00
2015-06-10 17:27:12 +03:00
int lvmetad_vg_clear_outdated_pvs ( struct volume_group * vg ) ;
2014-11-07 21:51:42 +03:00
void lvmetad_validate_global_cache ( struct cmd_context * cmd , int force ) ;
2016-01-29 01:40:26 +03:00
int lvmetad_token_matches ( struct cmd_context * cmd ) ;
2015-06-10 17:27:12 +03:00
2015-11-30 20:54:56 +03:00
int lvmetad_vg_is_foreign ( struct cmd_context * cmd , const char * vgname , const char * vgid ) ;
2016-01-29 01:54:36 +03:00
int lvmetad_is_disabled ( struct cmd_context * cmd , const char * * reason ) ;
2016-01-29 20:30:57 +03:00
void lvmetad_set_disabled ( struct cmd_context * cmd , const char * reason ) ;
2016-04-06 23:37:52 +03:00
void lvmetad_clear_disabled ( struct cmd_context * cmd ) ;
2016-01-29 01:54:36 +03:00
2012-02-28 22:22:52 +04:00
# else /* LVMETAD_SUPPORT */
2018-02-12 16:41:27 +03:00
static inline int lvmetad_connect ( struct cmd_context * cmd ) { return 0 ; }
static inline void lvmetad_disconnect ( void ) { }
static inline void lvmetad_make_unused ( struct cmd_context * cmd ) { }
static inline int lvmetad_used ( void ) { return 0 ; }
static inline void lvmetad_set_socket ( const char * thing ) { }
static inline int lvmetad_socket_present ( void ) { return 0 ; }
static inline int lvmetad_pidfile_present ( void ) { return 0 ; }
static inline void lvmetad_set_token ( const struct dm_config_value * filter ) { }
static inline void lvmetad_release_token ( void ) { }
static inline int lvmetad_vg_update_pending ( struct volume_group * vg ) { return 1 ; }
static inline int lvmetad_vg_update_finish ( struct volume_group * vg ) { return 1 ; }
static inline int lvmetad_vg_remove_pending ( struct volume_group * vg ) { return 1 ; }
static inline int lvmetad_vg_remove_finish ( struct volume_group * vg ) { return 1 ; }
static inline int lvmetad_pv_found ( struct cmd_context * cmd , const struct id * pvid , struct device * dev ,
const struct format_type * fmt , uint64_t label_sector ,
struct volume_group * vg ,
struct dm_list * found_vgnames ,
struct dm_list * changed_vgnames ) { return 1 ; }
static inline int lvmetad_pv_gone ( dev_t devno , const char * pv_name ) { return 1 ; }
static inline int lvmetad_pv_gone_by_dev ( struct device * dev ) { return 1 ; }
static inline int lvmetad_pv_list_to_lvmcache ( struct cmd_context * cmd ) { return 1 ; }
static inline int lvmetad_pv_lookup ( struct cmd_context * cmd , struct id pvid , int * found ) { return 0 ; }
static inline int lvmetad_pv_lookup_by_dev ( struct cmd_context * cmd , struct device * dev , int * found ) { return 0 ; }
static inline int lvmetad_vg_list_to_lvmcache ( struct cmd_context * cmd ) { return 1 ; }
static inline int lvmetad_get_vgnameids ( struct cmd_context * cmd , struct dm_list * vgnameids ) { return 0 ; }
static inline struct volume_group * lvmetad_vg_lookup ( struct cmd_context * cmd ,
const char * vgname , const char * vgid ) { return NULL ; }
static inline int lvmetad_pvscan_single ( struct cmd_context * cmd , struct device * dev ,
struct dm_list * found_vgnames ,
struct dm_list * changed_vgnames ) { return 0 ; }
static inline int lvmetad_pvscan_all_devs ( struct cmd_context * cmd , int do_wait ) { return 0 ; }
static inline int lvmetad_vg_clear_outdated_pvs ( struct volume_group * vg ) { return 0 ; }
static inline void lvmetad_validate_global_cache ( struct cmd_context * cmd , int force ) { }
static inline int lvmetad_token_matches ( struct cmd_context * cmd ) { return 1 ; }
static inline int lvmetad_vg_is_foreign ( struct cmd_context * cmd , const char * vgname , const char * vgid ) { return 0 ; }
static inline int lvmetad_is_disabled ( struct cmd_context * cmd , const char * * reason ) { return 0 ; }
static inline void lvmetad_set_disabled ( struct cmd_context * cmd , const char * reason ) { }
static inline void lvmetad_clear_disabled ( struct cmd_context * cmd ) { }
2012-02-23 17:11:07 +04:00
2012-02-28 22:22:52 +04:00
# endif /* LVMETAD_SUPPORT */
# endif