1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

activation: Add lv_is_active_remotely.

This commit is contained in:
Alasdair G Kergon 2016-01-19 22:01:59 +00:00
parent c812c2dbc7
commit 2304286f68

View File

@ -389,6 +389,10 @@ int lv_is_active_locally(const struct logical_volume *lv)
{
return 0;
}
int lv_is_active_remotely(const struct logical_volume *lv)
{
return 0;
}
int lv_is_active_but_not_locally(const struct logical_volume *lv)
{
return 0;
@ -1334,12 +1338,14 @@ int lvs_in_vg_opened(const struct volume_group *vg)
* _lv_is_active
* @lv: logical volume being queried
* @locally: set if active locally (when provided)
* @remotely: set if active remotely (when provided)
* @exclusive: set if active exclusively (when provided)
*
* Determine whether an LV is active locally or in a cluster.
* In addition to the return code which indicates whether or
* not the LV is active somewhere, two other values are set
* to yield more information about the status of the activation:
*
* return locally exclusively status
* ====== ======= =========== ======
* 0 0 0 not active
@ -1352,9 +1358,10 @@ int lvs_in_vg_opened(const struct volume_group *vg)
* Returns: 0 or 1
*/
static int _lv_is_active(const struct logical_volume *lv,
int *locally, int *exclusive)
int *locally, int *remotely, int *exclusive)
{
int r, l, e; /* remote, local, and exclusive */
int skip_cluster_query = 0;
r = l = e = 0;
@ -1367,11 +1374,14 @@ static int _lv_is_active(const struct logical_volume *lv,
goto out;
}
/* Active locally, and the caller doesn't care about exclusive */
if (l && !exclusive)
/* Active locally, and the caller doesn't care about exclusive or remotely */
if (l && !exclusive && !remotely)
skip_cluster_query = 1;
if (skip_cluster_query)
goto out;
if ((r = cluster_lock_held(lv->lvid.s, "", &e)) >= 0)
if ((r = cluster_lock_held(lv->lvid.s, NODE_REMOTE, &e)) >= 0)
goto out;
/*
@ -1387,6 +1397,9 @@ static int _lv_is_active(const struct logical_volume *lv,
e = 0;
/* Also set remotely as a precaution, as we don't know */
r = 1;
/*
* We used to attempt activate_lv_excl_local(lv->vg->cmd, lv) here,
* but it's unreliable.
@ -1397,53 +1410,65 @@ out:
*locally = l;
if (exclusive)
*exclusive = e;
if (remotely)
*remotely = r;
log_very_verbose("%s is %sactive%s%s",
log_very_verbose("%s is %sactive%s%s%s%s",
display_lvname(lv),
(r || l) ? "" : "not ",
(exclusive && e) ? " exclusive" : "",
e ? (l ? " locally" : " remotely") : "");
l ? " locally" : "",
(!skip_cluster_query && l && r) ? " and" : "",
(!skip_cluster_query && r) ? " remotely" : "");
return r || l;
}
int lv_is_active(const struct logical_volume *lv)
{
return _lv_is_active(lv, NULL, NULL);
return _lv_is_active(lv, NULL, NULL, NULL);
}
int lv_is_active_locally(const struct logical_volume *lv)
{
int l;
return _lv_is_active(lv, &l, NULL) && l;
return _lv_is_active(lv, &l, NULL, NULL) && l;
}
int lv_is_active_remotely(const struct logical_volume *lv)
{
int r;
return _lv_is_active(lv, NULL, &r, NULL) && r;
}
int lv_is_active_but_not_locally(const struct logical_volume *lv)
{
int l;
return _lv_is_active(lv, &l, NULL) && !l;
return _lv_is_active(lv, &l, NULL, NULL) && !l;
}
int lv_is_active_exclusive(const struct logical_volume *lv)
{
int e;
return _lv_is_active(lv, NULL, &e) && e;
return _lv_is_active(lv, NULL, NULL, &e) && e;
}
int lv_is_active_exclusive_locally(const struct logical_volume *lv)
{
int l, e;
return _lv_is_active(lv, &l, &e) && l && e;
return _lv_is_active(lv, &l, NULL, &e) && l && e;
}
int lv_is_active_exclusive_remotely(const struct logical_volume *lv)
{
int l, e;
return _lv_is_active(lv, &l, &e) && !l && e;
return _lv_is_active(lv, &l, NULL, &e) && !l && e;
}
#ifdef DMEVENTD