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

Prepare tools to support clustered mirrors.

This commit is contained in:
Alasdair Kergon 2005-08-14 23:18:28 +00:00
parent fb9d44daf1
commit 07d318310b
12 changed files with 61 additions and 21 deletions

View File

@ -1,5 +1,8 @@
Version 2.01.15 -
=================================
Prepend 'cluster' activation parameter to mirror log when appropriate.
Pass exclusive flag to lv_activate and on to target activation code.
Prevent snapshot creation in a clustered VG for now.
Factor out adjusted_mirror_region_size() and generate_log_name_format().
Move compose_log_line() into mirror directory.
Factor out _get_library_path().

View File

@ -173,6 +173,7 @@ static int do_activate_lv(char *resource, int mode)
int oldmode;
int status;
int activate_lv;
int exclusive = 0;
struct lvinfo lvi;
/* Is it already open ? */
@ -189,8 +190,10 @@ static int do_activate_lv(char *resource, int mode)
return 0; /* Success, we did nothing! */
/* Do we need to activate exclusively? */
if (activate_lv == 2)
if ((activate_lv == 2) || (mode == LKM_EXMODE)) {
exclusive = 1;
mode = LKM_EXMODE;
}
/* OK, try to get the lock */
status = hold_lock(resource, mode, LKF_NOQUEUE);
@ -206,7 +209,7 @@ static int do_activate_lv(char *resource, int mode)
return EIO;
/* Now activate it */
if (!lv_activate(cmd, resource))
if (!lv_activate(cmd, resource, exclusive))
return EIO;
return 0;

View File

@ -130,11 +130,11 @@ int lv_activation_filter(struct cmd_context *cmd, const char *lvid_s,
{
return 1;
}
int lv_activate(struct cmd_context *cmd, const char *lvid_s)
int lv_activate(struct cmd_context *cmd, const char *lvid_s, int exclusive)
{
return 1;
}
int lv_activate_with_filter(struct cmd_context *cmd, const char *lvid_s)
int lv_activate_with_filter(struct cmd_context *cmd, const char *lvid_s, int exclusive)
{
return 1;
}
@ -701,7 +701,8 @@ int lv_activation_filter(struct cmd_context *cmd, const char *lvid_s,
return 1;
}
static int _lv_activate(struct cmd_context *cmd, const char *lvid_s, int filter)
static int _lv_activate(struct cmd_context *cmd, const char *lvid_s,
int exclusive, int filter)
{
struct logical_volume *lv;
struct lvinfo info;
@ -732,6 +733,9 @@ static int _lv_activate(struct cmd_context *cmd, const char *lvid_s, int filter)
if (info.exists && !info.suspended)
return 1;
if (exclusive)
lv->status |= ACTIVATE_EXCL;
memlock_inc();
r = _lv_activate_lv(lv);
memlock_dec();
@ -741,15 +745,15 @@ static int _lv_activate(struct cmd_context *cmd, const char *lvid_s, int filter)
}
/* Activate LV */
int lv_activate(struct cmd_context *cmd, const char *lvid_s)
int lv_activate(struct cmd_context *cmd, const char *lvid_s, int exclusive)
{
return _lv_activate(cmd, lvid_s, 0);
return _lv_activate(cmd, lvid_s, exclusive, 0);
}
/* Activate LV only if it passes filter */
int lv_activate_with_filter(struct cmd_context *cmd, const char *lvid_s)
int lv_activate_with_filter(struct cmd_context *cmd, const char *lvid_s, int exclusive)
{
return _lv_activate(cmd, lvid_s, 1);
return _lv_activate(cmd, lvid_s, exclusive, 1);
}
int lv_mknodes(struct cmd_context *cmd, const struct logical_volume *lv)

View File

@ -46,8 +46,9 @@ int lv_suspend(struct cmd_context *cmd, const char *lvid_s);
int lv_suspend_if_active(struct cmd_context *cmd, const char *lvid_s);
int lv_resume(struct cmd_context *cmd, const char *lvid_s);
int lv_resume_if_active(struct cmd_context *cmd, const char *lvid_s);
int lv_activate(struct cmd_context *cmd, const char *lvid_s);
int lv_activate_with_filter(struct cmd_context *cmd, const char *lvid_s);
int lv_activate(struct cmd_context *cmd, const char *lvid_s, int exclusive);
int lv_activate_with_filter(struct cmd_context *cmd, const char *lvid_s,
int exclusive);
int lv_deactivate(struct cmd_context *cmd, const char *lvid_s);
int lv_mknodes(struct cmd_context *cmd, const struct logical_volume *lv);

View File

@ -57,6 +57,7 @@ static struct flag _lv_flags[] = {
{MIRRORED, NULL},
{VIRTUAL, NULL},
{SNAPSHOT, NULL},
{ACTIVATE_EXCL, NULL},
{0, NULL}
};

View File

@ -243,7 +243,7 @@ static int _file_lock_resource(struct cmd_context *cmd, const char *resource,
break;
case LCK_READ:
log_debug("Locking LV %s (R)", resource);
if (!lv_activate_with_filter(cmd, resource))
if (!lv_activate_with_filter(cmd, resource, 0))
return 0;
break;
case LCK_WRITE:
@ -253,7 +253,7 @@ static int _file_lock_resource(struct cmd_context *cmd, const char *resource,
break;
case LCK_EXCL:
log_debug("Locking LV %s (EX)", resource);
if (!lv_activate_with_filter(cmd, resource))
if (!lv_activate_with_filter(cmd, resource, 1))
return 0;
break;
default:

View File

@ -58,11 +58,11 @@ static int _no_lock_resource(struct cmd_context *cmd, const char *resource,
case LCK_UNLOCK:
return lv_resume_if_active(cmd, resource);
case LCK_READ:
return lv_activate_with_filter(cmd, resource);
return lv_activate_with_filter(cmd, resource, 0);
case LCK_WRITE:
return lv_suspend_if_active(cmd, resource);
case LCK_EXCL:
return lv_activate_with_filter(cmd, resource);
return lv_activate_with_filter(cmd, resource, 1);
default:
break;
}

View File

@ -57,6 +57,7 @@
#define VIRTUAL 0x00010000 /* LV - internal use only */
#define MIRROR_LOG 0x00020000 /* LV */
#define MIRROR_IMAGE 0x00040000 /* LV */
#define ACTIVATE_EXCL 0x00080000 /* LV - internal use only */
#define LVM_READ 0x00000100 /* LV VG */
#define LVM_WRITE 0x00000200 /* LV VG */

View File

@ -171,10 +171,19 @@ static int _compose_log_line(struct dev_manager *dm, struct lv_segment *seg,
{
int tw;
char devbuf[10];
const char *clustered = "";
/*
* Use clustered mirror log for non-exclusive activation
* in clustered VG.
*/
if ((!(seg->lv->status & ACTIVATE_EXCL) &&
(seg->lv->vg->status & CLUSTERED)))
clustered = "cluster ";
if (!seg->log_lv)
tw = lvm_snprintf(params, paramsize, "core 1 %u %u ",
region_size, areas);
tw = lvm_snprintf(params, paramsize, "%score 1 %u %u ",
clustered, region_size, areas);
else {
if (!build_dev_string(dm, seg->log_lv->lvid.s, devbuf,
sizeof(devbuf), "log")) {
@ -183,8 +192,8 @@ static int _compose_log_line(struct dev_manager *dm, struct lv_segment *seg,
}
/* FIXME add sync parm? */
tw = lvm_snprintf(params, paramsize, "disk 2 %s %u %u ",
devbuf, region_size, areas);
tw = lvm_snprintf(params, paramsize, "%sdisk 2 %s %u %u ",
clustered, devbuf, region_size, areas);
}
if (tw < 0) {

View File

@ -506,6 +506,11 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp)
"device-mapper kernel driver");
return 0;
}
/* FIXME Allow exclusive activation. */
if (vg->status & CLUSTERED) {
log_error("Clustered snapshots are not yet supported.");
return 0;
}
if (!(org = find_lv(vg, lp->origin))) {
log_err("Couldn't find origin volume '%s'.",
lp->origin);

View File

@ -238,8 +238,9 @@ static int _update_metadata(struct cmd_context *cmd, struct volume_group *vg,
/* Activate the temporary mirror LV */
/* Only the first mirror segment gets activated as a mirror */
/* FIXME: Add option to use a log */
if (first_time) {
if (!activate_lv(cmd, lv_mirr->lvid.s)) {
if (!activate_lv_excl(cmd, lv_mirr->lvid.s)) {
if (!test_mode())
log_error("ABORTING: Temporary mirror "
"activation failed. "
@ -317,7 +318,7 @@ static int _set_up_pvmove(struct cmd_context *cmd, const char *pv_name,
}
/* Ensure mirror LV is active */
if (!activate_lv(cmd, lv_mirr->lvid.s)) {
if (!activate_lv_excl(cmd, lv_mirr->lvid.s)) {
log_error
("ABORTING: Temporary mirror activation failed.");
unlock_vg(cmd, pv->vg_name);

View File

@ -182,6 +182,7 @@ static int _vgchange_clustered(struct cmd_context *cmd,
struct volume_group *vg)
{
int clustered = !strcmp(arg_str_value(cmd, clustered_ARG, "n"), "y");
struct lv_list *lvl;
if (clustered && (vg->status & CLUSTERED)) {
log_error("Volume group \"%s\" is already clustered",
@ -195,6 +196,17 @@ static int _vgchange_clustered(struct cmd_context *cmd,
return ECMD_FAILED;
}
if (clustered) {
list_iterate_items(lvl, &vg->lvs) {
if (lvl->lv->origin_count || lvl->lv->snapshot) {
log_error("Volume group %s contains snapshots "
"that are not yet supported.",
vg->name);
return ECMD_FAILED;
}
}
}
if (!archive(vg))
return ECMD_FAILED;