mirror of
git://sourceware.org/git/lvm2.git
synced 2025-02-25 21:57:45 +03:00
a few more changes/fixes to recent code
This commit is contained in:
parent
8c3af822ec
commit
4b0950aba5
@ -41,6 +41,9 @@ struct pv_segment;
|
||||
#define PV_MIN_SIZE ( 512L * 1024L >> SECTOR_SHIFT) /* 512 KB in sectors */
|
||||
#define MAX_RESTRICTED_LVS 255 /* Used by FMT_RESTRICTED_LVIDS */
|
||||
|
||||
/* Layer suffix */
|
||||
#define MIRROR_SYNC_LAYER "_mimagetmp"
|
||||
|
||||
/* Various flags */
|
||||
/* Note that the bits no longer necessarily correspond to LVM1 disk format */
|
||||
|
||||
|
@ -1030,7 +1030,8 @@ revert_new_lv:
|
||||
static struct logical_volume *_create_mirror_log(struct logical_volume *lv,
|
||||
struct alloc_handle *ah,
|
||||
alloc_policy_t alloc,
|
||||
const char *lv_name)
|
||||
const char *lv_name,
|
||||
const char *suffix)
|
||||
{
|
||||
struct logical_volume *log_lv;
|
||||
char *log_name;
|
||||
@ -1042,7 +1043,7 @@ static struct logical_volume *_create_mirror_log(struct logical_volume *lv,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (dm_snprintf(log_name, len, "%s_mlog", lv->name) < 0) {
|
||||
if (dm_snprintf(log_name, len, "%s%s", lv->name, suffix) < 0) {
|
||||
log_error("log_name allocation failed.");
|
||||
return NULL;
|
||||
}
|
||||
@ -1075,7 +1076,9 @@ static struct logical_volume *_set_up_mirror_log(struct cmd_context *cmd,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(log_lv = _create_mirror_log(lv, ah, alloc, lv->name))) {
|
||||
if (!(log_lv = _create_mirror_log(lv, ah, alloc, lv->name,
|
||||
strstr(lv->name, MIRROR_SYNC_LAYER)
|
||||
? "_mlogtmp_%d" : "_mlog"))) {
|
||||
log_error("Failed to create mirror log.");
|
||||
return NULL;
|
||||
}
|
||||
|
@ -272,6 +272,24 @@ static int _lvkmin_disp(struct dm_report *rh, struct dm_pool *mem __attribute((u
|
||||
return dm_report_field_uint64(rh, field, &_minusone);
|
||||
}
|
||||
|
||||
static int _lv_mimage_in_sync(struct logical_volume *lv)
|
||||
{
|
||||
float percent;
|
||||
struct lv_segment *seg = first_seg(lv);
|
||||
|
||||
if (!(lv->status & MIRROR_IMAGE) || !seg->mirror_seg)
|
||||
return_0;
|
||||
|
||||
if (!lv_mirror_percent(lv->vg->cmd, seg->mirror_seg->lv, 0,
|
||||
&percent, NULL))
|
||||
return_0;
|
||||
|
||||
if (percent >= 100.0)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _lvstatus_disp(struct dm_report *rh __attribute((unused)), struct dm_pool *mem,
|
||||
struct dm_report_field *field,
|
||||
const void *data, void *private __attribute((unused)))
|
||||
@ -294,7 +312,10 @@ static int _lvstatus_disp(struct dm_report *rh __attribute((unused)), struct dm_
|
||||
else
|
||||
repstr[0] = 'm';
|
||||
}else if (lv->status & MIRROR_IMAGE)
|
||||
repstr[0] = 'i';
|
||||
if (_lv_mimage_in_sync(lv))
|
||||
repstr[0] = 'i';
|
||||
else
|
||||
repstr[0] = 'I';
|
||||
else if (lv->status & MIRROR_LOG)
|
||||
repstr[0] = 'l';
|
||||
else if (lv->status & VIRTUAL)
|
||||
|
@ -47,7 +47,7 @@ The lv_attr bits are:
|
||||
.RS
|
||||
.IP 1 3
|
||||
Volume type: (m)irrored, (M)irrored without initial sync, (o)rigin, (p)vmove, (s)napshot,
|
||||
invalid (S)napshot, (v)irtual
|
||||
invalid (S)napshot, (v)irtual, mirror (i)mage, mirror (I)mage out-of-sync
|
||||
.IP 2 3
|
||||
Permissions: (w)riteable, (r)ead-only
|
||||
.IP 3 3
|
||||
|
@ -227,6 +227,50 @@ static int _read_params(struct lvconvert_params *lp, struct cmd_context *cmd,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _insert_lvconvert_layer(struct cmd_context *cmd,
|
||||
struct logical_volume *lv)
|
||||
{
|
||||
char *format, *layer_name;
|
||||
size_t len;
|
||||
int i;
|
||||
|
||||
/*
|
||||
* We would like to give the same number for this layer
|
||||
* and the newly added mimage.
|
||||
* However, LV name of newly added mimage is determined *after*
|
||||
* the LV name of this layer is determined.
|
||||
*
|
||||
* So, use generate_lv_name() to generate mimage name first
|
||||
* and take the number from it.
|
||||
*/
|
||||
|
||||
len = strlen(lv->name) + 32;
|
||||
if (!(format = alloca(len)) ||
|
||||
!(layer_name = alloca(len)) ||
|
||||
dm_snprintf(format, len, "%s_mimage_%%d", lv->name) < 0) {
|
||||
log_error("lvconvert: layer name allocation failed.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!generate_lv_name(lv->vg, format, layer_name, len) ||
|
||||
sscanf(layer_name, format, &i) != 1) {
|
||||
log_error("lvconvert: layer name generation failed.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (dm_snprintf(layer_name, len, MIRROR_SYNC_LAYER "_%d", i) < 0) {
|
||||
log_error("layer name allocation failed.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!insert_layer_for_lv(cmd, lv, 0, layer_name)) {
|
||||
log_error("Failed to insert resync layer");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int lvconvert_mirrors(struct cmd_context * cmd, struct logical_volume * lv,
|
||||
struct lvconvert_params *lp)
|
||||
{
|
||||
@ -376,9 +420,14 @@ static int lvconvert_mirrors(struct cmd_context * cmd, struct logical_volume * l
|
||||
return 1;
|
||||
}
|
||||
} else if (lp->mirrors > existing_mirrors) {
|
||||
if (lv->status & MIRROR_NOTSYNCED) {
|
||||
log_error("Not adding mirror to mirrored LV "
|
||||
"without initial resync");
|
||||
return 0;
|
||||
}
|
||||
/* FIXME: can't have multiple mlogs. force corelog. */
|
||||
corelog = 1;
|
||||
if (!insert_layer_for_lv(cmd, lv, 0, "_resync%d")) {
|
||||
if (!_insert_lvconvert_layer(cmd, lv)) {
|
||||
log_error("Failed to insert resync layer");
|
||||
return 0;
|
||||
}
|
||||
|
@ -525,7 +525,7 @@ static int _lvcreate(struct cmd_context *cmd, struct volume_group *vg,
|
||||
uint32_t status = 0;
|
||||
uint64_t tmp_size;
|
||||
struct logical_volume *lv, *org = NULL;
|
||||
struct list *pvh, tags;
|
||||
struct list *pvh;
|
||||
const char *tag = NULL;
|
||||
int origin_active = 0;
|
||||
char lv_name_buf[128];
|
||||
@ -744,6 +744,16 @@ static int _lvcreate(struct cmd_context *cmd, struct volume_group *vg,
|
||||
}
|
||||
}
|
||||
|
||||
if (lp->mirrors > 1) {
|
||||
init_mirror_in_sync(lp->nosync);
|
||||
|
||||
if (lp->nosync) {
|
||||
log_warn("WARNING: New mirror won't be synchronised. "
|
||||
"Don't read what you didn't write!");
|
||||
status |= MIRROR_NOTSYNCED;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(lv = lv_create_empty(lv_name ? lv_name : "lvol%d", NULL,
|
||||
status, lp->alloc, 0, vg))) {
|
||||
stack;
|
||||
@ -774,18 +784,6 @@ static int _lvcreate(struct cmd_context *cmd, struct volume_group *vg,
|
||||
return_0;
|
||||
|
||||
if (lp->mirrors > 1) {
|
||||
init_mirror_in_sync(lp->nosync);
|
||||
|
||||
if (lp->nosync) {
|
||||
log_warn("WARNING: New mirror won't be synchronised. "
|
||||
"Don't read what you didn't write!");
|
||||
status |= MIRROR_NOTSYNCED;
|
||||
}
|
||||
|
||||
list_init(&tags);
|
||||
if (tag)
|
||||
str_list_add(cmd->mem, &tags, tag);
|
||||
|
||||
if (!lv_add_mirrors(cmd, lv, lp->mirrors - 1, lp->stripes,
|
||||
adjusted_mirror_region_size(
|
||||
vg->extent_size,
|
||||
|
@ -1222,12 +1222,6 @@ int apply_lvname_restrictions(const char *name)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strstr(name, "_resync")) {
|
||||
log_error("Names including \"_resync\" are reserved. "
|
||||
"Please choose a different LV name.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user