2001-12-11 12:18:56 +00:00
/*
2004-03-30 19:35:44 +00:00
* Copyright ( C ) 2001 - 2004 Sistina Software , Inc . All rights reserved .
* Copyright ( C ) 2004 Red Hat , Inc . All rights reserved .
2001-12-11 12:18:56 +00:00
*
2004-03-30 19:35:44 +00: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 General Public License v .2 .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software Foundation ,
* Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
2001-12-11 12:18:56 +00:00
*/
2002-11-18 14:04:08 +00:00
# include "lib.h"
2001-12-11 12:18:56 +00:00
# include "metadata.h"
# include "import-export.h"
2001-12-20 11:52:54 +00:00
# include "lvm-string.h"
2001-12-11 12:18:56 +00:00
/*
* Bitsets held in the ' status ' flags get
* converted into arrays of strings .
*/
struct flag {
2002-12-19 23:25:55 +00:00
const int mask ;
const char * description ;
2001-12-11 12:18:56 +00:00
} ;
static struct flag _vg_flags [ ] = {
{ EXPORTED_VG , " EXPORTED " } ,
2002-01-10 15:09:51 +00:00
{ RESIZEABLE_VG , " RESIZEABLE " } ,
2002-01-29 17:23:33 +00:00
{ PARTIAL_VG , " PARTIAL " } ,
2003-05-06 12:02:36 +00:00
{ PVMOVE , " PVMOVE " } ,
2002-01-15 17:37:23 +00:00
{ LVM_READ , " READ " } ,
{ LVM_WRITE , " WRITE " } ,
2001-12-11 12:18:56 +00:00
{ CLUSTERED , " CLUSTERED " } ,
{ SHARED , " SHARED " } ,
2005-10-31 20:18:50 +00:00
{ PRECOMMITTED , NULL } ,
2001-12-11 12:18:56 +00:00
{ 0 , NULL }
} ;
static struct flag _pv_flags [ ] = {
2002-01-10 15:09:51 +00:00
{ ALLOCATABLE_PV , " ALLOCATABLE " } ,
2002-01-29 17:23:33 +00:00
{ EXPORTED_VG , " EXPORTED " } ,
2001-12-11 12:18:56 +00:00
{ 0 , NULL }
} ;
static struct flag _lv_flags [ ] = {
2001-12-20 11:52:54 +00:00
{ LVM_READ , " READ " } ,
{ LVM_WRITE , " WRITE " } ,
2002-02-01 17:54:39 +00:00
{ FIXED_MINOR , " FIXED_MINOR " } ,
2002-07-11 15:28:49 +00:00
{ VISIBLE_LV , " VISIBLE " } ,
2003-05-06 12:02:36 +00:00
{ PVMOVE , " PVMOVE " } ,
{ LOCKED , " LOCKED " } ,
2006-05-11 20:03:40 +00:00
{ MIRROR_NOTSYNCED , " NOTSYNCED " } ,
2005-06-03 14:49:51 +00:00
{ MIRROR_IMAGE , NULL } ,
2005-06-01 16:51:55 +00:00
{ MIRROR_LOG , NULL } ,
2004-05-04 21:25:57 +00:00
{ MIRRORED , NULL } ,
2004-05-11 16:01:58 +00:00
{ VIRTUAL , NULL } ,
2005-04-07 12:39:44 +00:00
{ SNAPSHOT , NULL } ,
2005-08-14 23:18:28 +00:00
{ ACTIVATE_EXCL , NULL } ,
2001-12-11 12:18:56 +00:00
{ 0 , NULL }
} ;
2001-12-20 11:52:54 +00:00
static struct flag * _get_flags ( int type )
2001-12-11 12:18:56 +00:00
{
switch ( type ) {
case VG_FLAGS :
return _vg_flags ;
case PV_FLAGS :
return _pv_flags ;
case LV_FLAGS :
return _lv_flags ;
}
log_err ( " Unknown flag set requested. " ) ;
return NULL ;
}
/*
* Converts a bitset to an array of string values ,
* using one of the tables defined at the top of
* the file .
*/
int print_flags ( uint32_t status , int type , char * buffer , size_t size )
{
2001-12-31 15:14:44 +00:00
int f , first = 1 ;
2001-12-11 12:18:56 +00:00
struct flag * flags ;
if ( ! ( flags = _get_flags ( type ) ) ) {
stack ;
return 0 ;
}
2003-09-17 20:35:57 +00:00
if ( ! emit_to_buffer ( & buffer , & size , " [ " ) )
2001-12-11 12:18:56 +00:00
return 0 ;
for ( f = 0 ; flags [ f ] . mask ; f + + ) {
if ( status & flags [ f ] . mask ) {
2004-05-05 18:15:47 +00:00
status & = ~ flags [ f ] . mask ;
/* Internal-only flag? */
if ( ! flags [ f ] . description )
continue ;
2001-12-20 11:52:54 +00:00
if ( ! first ) {
2003-09-17 20:35:57 +00:00
if ( ! emit_to_buffer ( & buffer , & size , " , " ) )
2001-12-20 11:52:54 +00:00
return 0 ;
} else
2001-12-11 12:18:56 +00:00
first = 0 ;
2004-05-05 18:15:47 +00:00
if ( ! emit_to_buffer ( & buffer , & size , " \" %s \" " ,
flags [ f ] . description ) )
2001-12-11 12:18:56 +00:00
return 0 ;
}
}
2003-09-17 20:35:57 +00:00
if ( ! emit_to_buffer ( & buffer , & size , " ] " ) )
2001-12-11 12:18:56 +00:00
return 0 ;
if ( status )
2002-01-29 17:23:33 +00:00
log_error ( " Metadata inconsistency: Not all flags successfully "
" exported. " ) ;
2001-12-11 12:18:56 +00:00
return 1 ;
}
2002-11-18 14:04:08 +00:00
int read_flags ( uint32_t * status , int type , struct config_value * cv )
2001-12-11 12:18:56 +00:00
{
int f ;
uint32_t s = 0 ;
struct flag * flags ;
if ( ! ( flags = _get_flags ( type ) ) ) {
stack ;
return 0 ;
}
2002-11-18 14:04:08 +00:00
if ( cv - > type = = CFG_EMPTY_ARRAY )
goto out ;
2001-12-11 12:18:56 +00:00
2002-11-18 14:04:08 +00:00
while ( cv ) {
if ( cv - > type ! = CFG_STRING ) {
log_err ( " Status value is not a string. " ) ;
return 0 ;
}
2002-08-01 12:51:48 +00:00
2002-11-18 14:04:08 +00:00
for ( f = 0 ; flags [ f ] . description ; f + + )
if ( ! strcmp ( flags [ f ] . description , cv - > v . str ) ) {
s | = flags [ f ] . mask ;
break ;
2001-12-11 12:18:56 +00:00
}
2002-11-18 14:04:08 +00:00
if ( ! flags [ f ] . description ) {
log_err ( " Unknown status flag '%s'. " , cv - > v . str ) ;
return 0 ;
2001-12-11 12:18:56 +00:00
}
2002-11-18 14:04:08 +00:00
cv = cv - > next ;
2001-12-11 12:18:56 +00:00
}
2002-11-18 14:04:08 +00:00
out :
2001-12-11 12:18:56 +00:00
* status = s ;
return 1 ;
}