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 ,
* Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
2002-11-18 16:53:58 +03:00
*/
# ifndef _LVM_CACHE_H
# define _LVM_CACHE_H
# include "dev-cache.h"
# 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
2003-07-05 02:34:56 +04:00
# define CACHE_INVALID 0x00000001
# define CACHE_LOCKED 0x00000002
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 ;
2011-01-10 16:13:42 +03:00
struct config_tree ;
2004-05-05 01:25:57 +04:00
2006-04-11 21:42:15 +04:00
/* One per VG */
2003-07-05 02:34:56 +04:00
struct lvmcache_vginfo {
2008-11-04 01:14:30 +03:00
struct dm_list list ; /* Join these vginfos together */
struct dm_list infos ; /* List head for lvmcache_infos */
2005-04-06 17:47:41 +04:00
const struct format_type * fmt ;
2002-11-18 16:53:58 +03:00
char * vgname ; /* "" == orphan */
2006-04-11 21:42:15 +04:00
uint32_t status ;
2002-11-18 16:53:58 +03:00
char vgid [ ID_LEN + 1 ] ;
2005-04-06 17:47:41 +04:00
char _padding [ 7 ] ;
2006-04-12 21:54:11 +04:00
struct lvmcache_vginfo * next ; /* Another VG with same name? */
2006-04-13 21:32:24 +04:00
char * creation_host ;
2011-03-30 17:14:34 +04:00
size_t vgmetadata_size ;
2008-03-17 19:51:31 +03:00
char * vgmetadata ; /* Copy of VG metadata as format_text string */
2011-01-10 16:13:42 +03:00
struct config_tree * cft ; /* Config tree created from vgmetadata */
2011-01-10 16:15:57 +03:00
/* Lifetime is directly tied to vgmetadata */
2008-03-17 19:51:31 +03:00
unsigned precommitted ; /* Is vgmetadata live or precommitted? */
2002-11-18 16:53:58 +03:00
} ;
2006-04-11 21:42:15 +04:00
/* One per device */
2003-07-05 02:34:56 +04:00
struct lvmcache_info {
2008-11-04 01:14:30 +03:00
struct dm_list list ; /* Join VG members together */
struct dm_list mdas ; /* list head for metadata areas */
struct dm_list das ; /* list head for data areas */
2003-07-05 02:34:56 +04:00
struct lvmcache_vginfo * vginfo ; /* NULL == unknown */
2002-11-18 16:53:58 +03:00
struct label * label ;
2002-12-20 02:25:55 +03:00
const struct format_type * fmt ;
2002-11-18 16:53:58 +03:00
struct device * dev ;
uint64_t device_size ; /* Bytes */
uint32_t status ;
} ;
2003-07-05 02:34:56 +04:00
int lvmcache_init ( void ) ;
2008-04-08 16:49:21 +04:00
void lvmcache_destroy ( struct cmd_context * cmd , int retain_orphans ) ;
2002-11-18 16:53:58 +03:00
2005-03-08 16:46:17 +03:00
/* Set full_scan to 1 to reread every filtered device label or
* 2 to rescan / dev for new devices */
2003-07-05 02:34:56 +04:00
int lvmcache_label_scan ( struct cmd_context * cmd , int full_scan ) ;
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 ,
const char * vgname , const char * vgid ,
2006-04-13 21:32:24 +04:00
uint32_t vgstatus , const char * hostname ) ;
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 */
2010-12-11 01:39:52 +03:00
const struct format_type * fmt_from_vgname ( const char * vgname , const char * vgid , unsigned revalidate_labels ) ;
2006-04-12 21:54:11 +04:00
struct lvmcache_vginfo * vginfo_from_vgname ( const char * vgname ,
const char * vgid ) ;
2003-07-05 02:34:56 +04:00
struct lvmcache_vginfo * vginfo_from_vgid ( const char * vgid ) ;
2008-01-30 02:45:48 +03:00
struct lvmcache_info * info_from_pvid ( const char * pvid , int valid_only ) ;
2006-04-14 01:08:29 +04:00
const char * vgname_from_vgid ( struct dm_pool * mem , const char * vgid ) ;
2010-10-25 17:02:26 +04:00
struct device * device_from_pvid ( struct cmd_context * cmd , const struct id * pvid ,
2010-03-17 05:11:18 +03:00
unsigned * scan_done_once ) ;
2010-05-19 15:52:07 +04:00
const char * pvid_from_devname ( struct cmd_context * cmd ,
const char * dev_name ) ;
2010-05-19 15:52:21 +04:00
char * lvmcache_vgname_from_pvid ( struct cmd_context * cmd , const char * pvid ) ;
2003-07-05 02:34:56 +04:00
int vgs_locked ( void ) ;
2005-10-27 21:41:41 +04:00
int vgname_is_locked ( const char * vgname ) ;
2002-11-18 16:53:58 +03:00
/* Returns list of struct str_lists 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
2006-04-13 01:23:04 +04:00
/* Returns list of struct str_lists 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
2006-04-21 23:12:41 +04:00
/* Returns list of struct str_lists 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. */
struct volume_group * lvmcache_get_vg ( 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
2002-11-18 16:53:58 +03:00
# endif