2004-05-11 20:01:58 +04:00
/*
2007-08-21 00:55:30 +04:00
* Copyright ( C ) 2004 - 2007 Red Hat , Inc . All rights reserved .
2004-05-11 20:01:58 +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-05-11 20:01:58 +04:00
*
2007-08-21 00:55:30 +04:00
* You should have received a copy of the GNU Lesser General Public License
2004-05-11 20:01:58 +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
*/
# include "lib.h"
# include "toolcontext.h"
2004-09-16 22:40:56 +04:00
# include "segtype.h"
2004-05-11 20:01:58 +04:00
# include "display.h"
# include "config.h"
# include "str_list.h"
# include "activate.h"
2006-10-03 21:55:20 +04:00
# include "str_list.h"
2004-05-11 20:01:58 +04:00
2006-04-19 19:33:07 +04:00
static const char * _errseg_name ( const struct lv_segment * seg )
2004-05-11 20:01:58 +04:00
{
return seg - > segtype - > name ;
}
2006-04-19 19:33:07 +04:00
static int _errseg_merge_segments ( struct lv_segment * seg1 , struct lv_segment * seg2 )
2004-05-11 20:01:58 +04:00
{
seg1 - > len + = seg2 - > len ;
seg1 - > area_len + = seg2 - > area_len ;
return 1 ;
}
# ifdef DEVMAPPER_SUPPORT
2010-07-09 19:34:40 +04:00
static int _errseg_add_target_line ( struct dev_manager * dm __attribute__ ( ( unused ) ) ,
struct dm_pool * mem __attribute__ ( ( unused ) ) ,
struct cmd_context * cmd __attribute__ ( ( unused ) ) ,
void * * target_state __attribute__ ( ( unused ) ) ,
struct lv_segment * seg __attribute__ ( ( unused ) ) ,
2011-06-17 18:14:19 +04:00
const struct lv_activate_opts * laopts __attribute__ ( ( unused ) ) ,
2005-11-09 16:08:41 +03:00
struct dm_tree_node * node , uint64_t len ,
2010-07-09 19:34:40 +04:00
uint32_t * pvmove_mirror_count __attribute__ ( ( unused ) ) )
2004-05-11 20:01:58 +04:00
{
2005-11-09 16:08:41 +03:00
return dm_tree_node_add_error_target ( node , len ) ;
2004-05-11 20:01:58 +04:00
}
2009-02-28 23:04:24 +03:00
static int _errseg_target_present ( struct cmd_context * cmd ,
2010-07-09 19:34:40 +04:00
const struct lv_segment * seg __attribute__ ( ( unused ) ) ,
unsigned * attributes __attribute__ ( ( unused ) ) )
2004-05-11 20:01:58 +04:00
{
2006-04-19 19:33:07 +04:00
static int _errseg_checked = 0 ;
static int _errseg_present = 0 ;
2004-05-11 20:01:58 +04:00
2005-11-09 01:52:26 +03:00
/* Reported truncated in older kernels */
2006-04-19 19:33:07 +04:00
if ( ! _errseg_checked & &
2009-02-28 23:04:24 +03:00
( target_present ( cmd , " error " , 0 ) | |
target_present ( cmd , " erro " , 0 ) ) )
2006-04-19 19:33:07 +04:00
_errseg_present = 1 ;
2004-05-11 20:01:58 +04:00
2006-04-19 19:33:07 +04:00
_errseg_checked = 1 ;
return _errseg_present ;
2004-05-11 20:01:58 +04:00
}
# endif
2006-10-03 21:55:20 +04:00
static int _errseg_modules_needed ( struct dm_pool * mem ,
2010-07-09 19:34:40 +04:00
const struct lv_segment * seg __attribute__ ( ( unused ) ) ,
2008-11-04 01:14:30 +03:00
struct dm_list * modules )
2006-10-03 21:55:20 +04:00
{
if ( ! str_list_add ( mem , modules , " error " ) ) {
log_error ( " error module string list allocation failed " ) ;
return 0 ;
}
return 1 ;
}
2008-01-30 17:00:02 +03:00
2010-12-20 16:32:49 +03:00
static void _errseg_destroy ( struct segment_type * segtype )
2004-05-11 20:01:58 +04:00
{
2010-12-20 16:32:49 +03:00
dm_free ( segtype ) ;
2004-05-11 20:01:58 +04:00
}
static struct segtype_handler _error_ops = {
2006-05-10 01:23:51 +04:00
. name = _errseg_name ,
. merge_segments = _errseg_merge_segments ,
2004-05-11 20:01:58 +04:00
# ifdef DEVMAPPER_SUPPORT
2006-05-10 01:23:51 +04:00
. add_target_line = _errseg_add_target_line ,
. target_present = _errseg_target_present ,
2004-05-11 20:01:58 +04:00
# endif
2006-10-03 21:55:20 +04:00
. modules_needed = _errseg_modules_needed ,
2006-05-10 01:23:51 +04:00
. destroy = _errseg_destroy ,
2004-05-11 20:01:58 +04:00
} ;
struct segment_type * init_error_segtype ( struct cmd_context * cmd )
{
2011-03-26 00:59:42 +03:00
struct segment_type * segtype = dm_zalloc ( sizeof ( * segtype ) ) ;
2004-05-11 20:01:58 +04:00
2005-11-09 01:52:26 +03:00
if ( ! segtype )
return_NULL ;
2004-05-11 20:01:58 +04:00
segtype - > cmd = cmd ;
segtype - > ops = & _error_ops ;
segtype - > name = " error " ;
segtype - > private = NULL ;
2005-11-09 01:52:26 +03:00
segtype - > flags = SEG_CAN_SPLIT | SEG_VIRTUAL | SEG_CANNOT_BE_ZEROED ;
2004-05-11 20:01:58 +04:00
2004-09-14 21:37:51 +04:00
log_very_verbose ( " Initialised segtype: %s " , segtype - > name ) ;
2004-05-11 20:01:58 +04:00
return segtype ;
}