1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

o New function 'merge_segments'

o  Call said function at end of lv_extend
This commit is contained in:
Joe Thornber 2002-01-07 15:08:28 +00:00
parent f5549805b6
commit 16ab7a0da2
4 changed files with 84 additions and 1 deletions

View File

@ -37,6 +37,7 @@ SOURCES=\
label/label.c \
log/log.c \
metadata/lv_manip.c \
metadata/merge.c \
metadata/metadata.c \
metadata/pv_map.c \
mm/dbg_malloc.c \

View File

@ -9,6 +9,7 @@
#include "log.h"
#include "dbg_malloc.h"
#include "lvm-string.h"
#include "merge.h"
#include <assert.h>
@ -497,6 +498,12 @@ int lv_extend(struct logical_volume *lv,
return 0;
}
if (!merge_segments(lv)) {
log_err("Couldn't merge segments after extending "
"logical volume.");
return 0;
}
return 1;
}

55
lib/metadata/merge.c Normal file
View File

@ -0,0 +1,55 @@
/*
* Copyright (C) 2001 Sistina Software
*
* This file is released under the LGPL.
*/
#include "log.h"
#include "merge.h"
/*
* Returns success if the segments were
* successfully merged. If the do merge, 'first'
* will be adjusted to contain both areas.
*/
static int _merge(struct stripe_segment *first, struct stripe_segment *second)
{
int s;
uint32_t width;
if (!first ||
(first->stripes != second->stripes) ||
(first->stripe_size != second->stripe_size))
return 0;
for (s = 0; s < first->stripes; s++) {
width = first->len / first->stripes;
if ((first->area[s].pv != second->area[s].pv) ||
(first->area[s].pe + width != second->area[s].pe))
return 0;
}
/* we should merge */
first->len += second->len;
return 1;
}
int merge_segments(struct logical_volume *lv)
{
struct list *segh;
struct stripe_segment *current, *prev = NULL;
list_iterate (segh, &lv->segments) {
current = list_item(segh, struct stripe_segment);
if (_merge(prev, current))
list_del(&current->list);
else
prev = current;
}
return 1;
}

20
lib/metadata/merge.h Normal file
View File

@ -0,0 +1,20 @@
/*
* Copyright (C) 2001 Sistina Software
*
* This file is released under the LGPL.
*/
#ifndef _LVM_MERGE_H
#define _LVM_MERGE_H
#include "metadata.h"
/*
* Sometimes (eg, after an lvextend), it is
* possible to merge two adjacent segments into a
* single segment. This function trys to merge as
* many segments as possible.
*/
int merge_segments(struct logical_volume *lv);
#endif /* _LVM_MERGE_H */