mirror of
git://sourceware.org/git/lvm2.git
synced 2025-04-25 02:51:16 +03:00
Try out using LV locking for reactivation.
This commit is contained in:
parent
3698eaa2d2
commit
6a8fd4fa6e
@ -159,7 +159,7 @@ int lock_resource(const char *resource, int flags)
|
|||||||
"%s/V_%s", _lock_dir, resource);
|
"%s/V_%s", _lock_dir, resource);
|
||||||
break;
|
break;
|
||||||
case LCK_LV:
|
case LCK_LV:
|
||||||
/* No-op for now */
|
/* No-op: see FIXME below */
|
||||||
return 1;
|
return 1;
|
||||||
default:
|
default:
|
||||||
log_error("Unrecognised lock scope: %d",
|
log_error("Unrecognised lock scope: %d",
|
||||||
@ -173,6 +173,24 @@ int lock_resource(const char *resource, int flags)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****** FIXME This is stuck a layer above until activate unit
|
||||||
|
can take labels and read its own metadata
|
||||||
|
|
||||||
|
if ((flags & LCK_SCOPE_MASK) == LCK_LV) {
|
||||||
|
switch (flags & LCK_TYPE_MASK) {
|
||||||
|
case LCK_NONE:
|
||||||
|
if (lv_active_by_id(resource))
|
||||||
|
lv_resume_by_id(resource);
|
||||||
|
break;
|
||||||
|
case LCK_WRITE:
|
||||||
|
if (lv_active_by_id(resource))
|
||||||
|
lv_suspend_by_id(resource);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*******/
|
||||||
|
|
||||||
int init_file_locking(struct locking_type *locking, struct config_file *cf)
|
int init_file_locking(struct locking_type *locking, struct config_file *cf)
|
||||||
{
|
{
|
||||||
|
@ -120,6 +120,7 @@ void fin_locking(void)
|
|||||||
*/
|
*/
|
||||||
int lock_vol(const void *vol, int flags)
|
int lock_vol(const void *vol, int flags)
|
||||||
{
|
{
|
||||||
|
struct logical_volume *lv;
|
||||||
char resource[258];
|
char resource[258];
|
||||||
|
|
||||||
switch (flags & LCK_SCOPE_MASK) {
|
switch (flags & LCK_SCOPE_MASK) {
|
||||||
@ -133,6 +134,13 @@ int lock_vol(const void *vol, int flags)
|
|||||||
/*
|
/*
|
||||||
* Suspends LV if it's active.
|
* Suspends LV if it's active.
|
||||||
*/
|
*/
|
||||||
|
lv = (struct logical_volume *) vol;
|
||||||
|
if (lvm_snprintf(resource, sizeof(resource), "%s/%s",
|
||||||
|
lv->vg->name, lv->name) < 0) {
|
||||||
|
log_error("Lock resource name too long: %s", resource);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
log_error("Unrecognised lock scope: %d",
|
log_error("Unrecognised lock scope: %d",
|
||||||
flags & LCK_SCOPE_MASK);
|
flags & LCK_SCOPE_MASK);
|
||||||
@ -146,6 +154,26 @@ int lock_vol(const void *vol, int flags)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****** FIXME
|
||||||
|
This should move down into lock_resource when the activation calls
|
||||||
|
can handle struct ids and read their own metadata.
|
||||||
|
******/
|
||||||
|
|
||||||
|
if ((flags & LCK_SCOPE_MASK) == LCK_LV) {
|
||||||
|
switch (flags & LCK_TYPE_MASK) {
|
||||||
|
case LCK_NONE:
|
||||||
|
if (lv_active(lv))
|
||||||
|
lv_reactivate(lv);
|
||||||
|
break;
|
||||||
|
case LCK_WRITE:
|
||||||
|
if (lv_active(lv))
|
||||||
|
lv_suspend(lv);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_update_lock_count(flags);
|
_update_lock_count(flags);
|
||||||
_enable_signals();
|
_enable_signals();
|
||||||
|
|
||||||
|
@ -151,15 +151,25 @@ static int lvchange_permission(struct cmd_context *cmd,
|
|||||||
lv->name);
|
lv->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name);
|
if (!lock_vol(lv, LCK_LV | LCK_WRITE)) {
|
||||||
if (!cmd->fid->ops->vg_write(cmd->fid, lv->vg))
|
log_error("Failed to lock %s", lv->name);
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name);
|
||||||
|
if (!cmd->fid->ops->vg_write(cmd->fid, lv->vg)) {
|
||||||
|
/* FIXME: Attempt reversion? */
|
||||||
|
lock_vol(lv, LCK_LV | LCK_NONE);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
backup(lv->vg);
|
backup(lv->vg);
|
||||||
|
|
||||||
log_very_verbose("Updating permissions for \"%s\" in kernel", lv->name);
|
log_very_verbose("Updating permissions for \"%s\" in kernel", lv->name);
|
||||||
if (!lv_update_write_access(lv))
|
if (!lock_vol(lv, LCK_LV | LCK_NONE)) {
|
||||||
return 0;
|
log_error("Problem reactivating %s", lv->name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -254,14 +264,28 @@ static int lvchange_contiguous(struct cmd_context *cmd,
|
|||||||
lv->name);
|
lv->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
log_verbose("Updating logical volume \"%s\" on disk(s)", lv->name);
|
if (!lock_vol(lv, LCK_LV | LCK_WRITE)) {
|
||||||
|
log_error("Failed to lock %s", lv->name);
|
||||||
if (!cmd->fid->ops->vg_write(cmd->fid, lv->vg))
|
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name);
|
||||||
|
if (!cmd->fid->ops->vg_write(cmd->fid, lv->vg)) {
|
||||||
|
/* FIXME: Attempt reversion? */
|
||||||
|
lock_vol(lv, LCK_LV | LCK_NONE);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
backup(lv->vg);
|
backup(lv->vg);
|
||||||
|
|
||||||
|
log_very_verbose("Reactivating \"%s\" in kernel", lv->name);
|
||||||
|
if (!lock_vol(lv, LCK_LV | LCK_NONE)) {
|
||||||
|
log_error("Problem reactivating %s", lv->name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lvchange_readahead(struct cmd_context *cmd,
|
static int lvchange_readahead(struct cmd_context *cmd,
|
||||||
@ -285,16 +309,30 @@ static int lvchange_readahead(struct cmd_context *cmd,
|
|||||||
}
|
}
|
||||||
|
|
||||||
lv->read_ahead = read_ahead;
|
lv->read_ahead = read_ahead;
|
||||||
|
|
||||||
log_verbose("Setting read ahead to %u for \"%s\"", read_ahead,
|
log_verbose("Setting read ahead to %u for \"%s\"", read_ahead,
|
||||||
lv->name);
|
lv->name);
|
||||||
|
|
||||||
log_verbose("Updating logical volume \"%s\" on disk(s)", lv->name);
|
if (!lock_vol(lv, LCK_LV | LCK_WRITE)) {
|
||||||
|
log_error("Failed to lock %s", lv->name);
|
||||||
if (!cmd->fid->ops->vg_write(cmd->fid, lv->vg))
|
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name);
|
||||||
|
if (!cmd->fid->ops->vg_write(cmd->fid, lv->vg)) {
|
||||||
|
/* FIXME: Attempt reversion? */
|
||||||
|
lock_vol(lv, LCK_LV | LCK_NONE);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
backup(lv->vg);
|
backup(lv->vg);
|
||||||
|
|
||||||
|
log_very_verbose("Reactivating \"%s\" in kernel", lv->name);
|
||||||
|
if (!lock_vol(lv, LCK_LV | LCK_NONE)) {
|
||||||
|
log_error("Problem reactivating %s", lv->name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -325,12 +363,25 @@ static int lvchange_persistent(struct cmd_context *cmd,
|
|||||||
lv->minor, lv->name);
|
lv->minor, lv->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
log_verbose("Updating logical volume \"%s\" on disk(s)", lv->name);
|
if (!lock_vol(lv, LCK_LV | LCK_WRITE)) {
|
||||||
|
log_error("Failed to lock %s", lv->name);
|
||||||
if (!cmd->fid->ops->vg_write(cmd->fid, lv->vg))
|
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name);
|
||||||
|
if (!cmd->fid->ops->vg_write(cmd->fid, lv->vg)) {
|
||||||
|
/* FIXME: Attempt reversion? */
|
||||||
|
lock_vol(lv, LCK_LV | LCK_NONE);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
backup(lv->vg);
|
backup(lv->vg);
|
||||||
|
|
||||||
|
log_very_verbose("Reactivating \"%s\" in kernel", lv->name);
|
||||||
|
if (!lock_vol(lv, LCK_LV | LCK_NONE)) {
|
||||||
|
log_error("Problem reactivating %s", lv->name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,6 @@ int lvresize(struct cmd_context *cmd, int argc, char **argv)
|
|||||||
struct list *pvh, *segh;
|
struct list *pvh, *segh;
|
||||||
struct lv_list *lvl;
|
struct lv_list *lvl;
|
||||||
int opt = 0;
|
int opt = 0;
|
||||||
int active;
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
LV_ANY = 0,
|
LV_ANY = 0,
|
||||||
@ -332,20 +331,24 @@ int lvresize(struct cmd_context *cmd, int argc, char **argv)
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
active = lv_active(lv);
|
if (!lock_vol(lv, LCK_LV | LCK_WRITE)) {
|
||||||
|
log_error("Can't get lock for %s", lv_name);
|
||||||
/********* FIXME Suspend lv ***********/
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
/* store vg on disk(s) */
|
/* store vg on disk(s) */
|
||||||
if (!cmd->fid->ops->vg_write(cmd->fid, vg))
|
if (!cmd->fid->ops->vg_write(cmd->fid, vg)) {
|
||||||
|
/* FIXME: Attempt reversion? */
|
||||||
|
lock_vol(lv, LCK_LV | LCK_NONE);
|
||||||
goto error;
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
backup(vg);
|
backup(vg);
|
||||||
|
|
||||||
if (active && !lv_reactivate(lv))
|
if (!lock_vol(lv, LCK_LV | LCK_NONE)) {
|
||||||
|
log_error("Problem reactivating %s", lv_name);
|
||||||
goto error;
|
goto error;
|
||||||
|
}
|
||||||
/********* FIXME Resume *********/
|
|
||||||
|
|
||||||
lock_vol(vg_name, LCK_VG | LCK_NONE);
|
lock_vol(vg_name, LCK_VG | LCK_NONE);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user