2002-01-07 15:08:28 +00:00
/*
* Copyright ( C ) 2001 Sistina Software
*
* This file is released under the LGPL .
*/
2002-11-18 14:04:08 +00:00
# include "lib.h"
2002-01-10 18:12:26 +00:00
# include "metadata.h"
2002-01-07 15:08:28 +00:00
/*
* Returns success if the segments were
* successfully merged . If the do merge , ' first '
* will be adjusted to contain both areas .
*/
2002-11-18 14:04:08 +00:00
static int _merge ( struct lv_segment * first , struct lv_segment * second )
2002-01-07 15:08:28 +00:00
{
2002-12-19 23:25:55 +00:00
unsigned int s ;
2002-01-07 15:08:28 +00:00
uint32_t width ;
if ( ! first | |
2002-11-18 14:04:08 +00:00
( first - > type ! = SEG_STRIPED ) | |
( first - > type ! = second - > type ) | |
2003-04-24 22:23:24 +00:00
( first - > area_count ! = second - > area_count ) | |
2002-01-07 15:08:28 +00:00
( first - > stripe_size ! = second - > stripe_size ) )
return 0 ;
2003-04-24 22:23:24 +00:00
for ( s = 0 ; s < first - > area_count ; s + + ) {
width = first - > area_len ;
2002-01-07 15:08:28 +00:00
2003-04-24 22:23:24 +00:00
/* FIXME Relax this to first type != second type ? */
if ( first - > area [ s ] . type ! = AREA_PV | |
second - > area [ s ] . type ! = AREA_PV )
return 0 ;
if ( ( first - > area [ s ] . u . pv . pv ! = second - > area [ s ] . u . pv . pv ) | |
( first - > area [ s ] . u . pv . pe + width ! = second - > area [ s ] . u . pv . pe ) )
2002-01-07 15:08:28 +00:00
return 0 ;
}
/* we should merge */
first - > len + = second - > len ;
2003-04-24 22:46:47 +00:00
first - > area_len + = second - > area_len ;
2002-01-07 15:08:28 +00:00
return 1 ;
}
2002-01-10 11:18:08 +00:00
int lv_merge_segments ( struct logical_volume * lv )
2002-01-07 15:08:28 +00:00
{
struct list * segh ;
2002-11-18 14:04:08 +00:00
struct lv_segment * current , * prev = NULL ;
2002-01-07 15:08:28 +00:00
2002-04-24 18:20:51 +00:00
list_iterate ( segh , & lv - > segments ) {
2002-11-18 14:04:08 +00:00
current = list_item ( segh , struct lv_segment ) ;
2002-01-07 15:08:28 +00:00
if ( _merge ( prev , current ) )
list_del ( & current - > list ) ;
else
prev = current ;
}
return 1 ;
}
2002-01-10 23:21:07 +00:00
int lv_check_segments ( struct logical_volume * lv )
{
return 1 ;
}