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

Begin conversion so LV id is passed to activation unit instead of

struct logical_volume.
This commit is contained in:
Alasdair Kergon 2002-02-25 12:56:16 +00:00
parent ca73e23fd0
commit 413cc9189e
21 changed files with 237 additions and 152 deletions

View File

@ -12,6 +12,8 @@
#include "fs.h" #include "fs.h"
#include "lvm-string.h" #include "lvm-string.h"
#include "names.h" #include "names.h"
#include "pool.h"
#include "toolcontext.h"
#include <limits.h> #include <limits.h>
#include <linux/kdev_t.h> #include <linux/kdev_t.h>
@ -468,3 +470,65 @@ int lvs_in_vg_opened(struct volume_group *vg)
return count; return count;
} }
/* FIXME Currently lvid is "vgname/lv_uuid". Needs to be vg_uuid/lv_uuid. */
static struct logical_volume *_lv_from_lvid(struct cmd_context *cmd,
const char *lvid)
{
struct lv_list *lvl;
struct volume_group *vg;
char *vgname;
char *slash;
if (!(slash = strchr(lvid, '/'))) {
log_error("Invalid VG/LV identifier: %s", lvid);
return NULL;
}
vgname = pool_strdup(cmd->mem, lvid);
*strchr(vgname, '/') = '\0';
log_verbose("Finding volume group \"%s\"", vgname);
if (!(vg = cmd->fid->ops->vg_read(cmd->fid, vgname))) {
log_error("Volume group \"%s\" doesn't exist", vgname);
return NULL;
}
if (vg->status & EXPORTED_VG) {
log_error("Volume group \"%s\" is exported", vgname);
return NULL;
}
if (!(lvl = find_lv_in_vg_by_uuid(vg, slash + 1))) {
log_error("Can't find logical volume id %s", lvid);
return NULL;
}
return lvl->lv;
}
int lv_suspend_if_active(struct cmd_context *cmd, const char *lvid)
{
struct logical_volume *lv;
if (!(lv = _lv_from_lvid(cmd, lvid)))
return 0;
if (lv_active(lv))
lv_suspend(lv);
return 1;
}
int lv_resume_if_active(struct cmd_context *cmd, const char *lvid)
{
struct logical_volume *lv;
if (!(lv = _lv_from_lvid(cmd, lvid)))
return 0;
if (lv_active(lv))
lv_reactivate(lv);
return 1;
}

View File

@ -34,6 +34,13 @@ int lv_deactivate(struct logical_volume *lv);
int lv_suspend(struct logical_volume *lv); int lv_suspend(struct logical_volume *lv);
int lv_rename(const char *old_name, struct logical_volume *lv); int lv_rename(const char *old_name, struct logical_volume *lv);
/*
* These should eventually replace some of the above
* and maybe use config file to determine whether or not to activate
*/
int lv_suspend_if_active(struct cmd_context *cmd, const char *lvid);
int lv_resume_if_active(struct cmd_context *cmd, const char *lvid);
/* /*
* Snapshot volume need kernel specific initialisation. * Snapshot volume need kernel specific initialisation.
*/ */

View File

@ -145,7 +145,7 @@ static int _lock_file(const char *file, int flags)
return r; return r;
} }
int lock_resource(const char *resource, int flags) int lock_resource(struct cmd_context *cmd, const char *resource, int flags)
{ {
char lockfile[PATH_MAX]; char lockfile[PATH_MAX];
@ -157,40 +157,32 @@ int lock_resource(const char *resource, int flags)
else else
lvm_snprintf(lockfile, sizeof(lockfile), lvm_snprintf(lockfile, sizeof(lockfile),
"%s/V_%s", _lock_dir, resource); "%s/V_%s", _lock_dir, resource);
if (!_lock_file(lockfile, flags))
return 0;
break; break;
case LCK_LV: case LCK_LV:
/* No-op: see FIXME below */ switch (flags & LCK_TYPE_MASK) {
return 1; case LCK_NONE:
if (!lv_resume_if_active(cmd, resource))
return 0;
break;
case LCK_WRITE:
if (!lv_suspend_if_active(cmd, resource))
return 0;
break;
default:
break;
}
break;
default: default:
log_error("Unrecognised lock scope: %d", log_error("Unrecognised lock scope: %d",
flags & LCK_SCOPE_MASK); flags & LCK_SCOPE_MASK);
return 0; return 0;
} }
if (!_lock_file(lockfile, flags))
return 0;
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)
{ {

View File

@ -60,7 +60,7 @@ static inline void _update_lock_count(int flags)
/* /*
* No locking - currently does nothing. * No locking - currently does nothing.
*/ */
int no_lock_resource(const char *resource, int flags) int no_lock_resource(struct cmd_context *cmd, const char *resource, int flags)
{ {
return 1; return 1;
} }
@ -115,32 +115,18 @@ void fin_locking(void)
/* /*
* VG locking is by name * VG locking is by name
* LV locking is by struct logical_volume * LV locking is by VG_name/LV_uuid
* FIXME This should take a unique name or id for an LV * FIXME This should take a VG_uuid instead of VG_name
*/ */
int lock_vol(const void *vol, int flags) int lock_vol(struct cmd_context *cmd, const char *vol, int flags)
{ {
struct logical_volume *lv;
char resource[258]; char resource[258];
switch (flags & LCK_SCOPE_MASK) { switch (flags & LCK_SCOPE_MASK) {
case LCK_VG: case LCK_VG: /* Lock volume group before changing on-disk metadata. */
/* case LCK_LV: /* Suspends LV if it's active. */
* Lock a volume group before changing on-disk metadata.
*/
strncpy(resource, (char *) vol, sizeof(resource)); strncpy(resource, (char *) vol, sizeof(resource));
break; break;
case LCK_LV:
/*
* 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);
@ -149,31 +135,11 @@ int lock_vol(const void *vol, int flags)
_ignore_signals(); _ignore_signals();
if (!(_locking.lock_resource(resource, flags))) { if (!(_locking.lock_resource(cmd, resource, flags))) {
_enable_signals(); _enable_signals();
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();

View File

@ -21,12 +21,12 @@ void fin_locking(void);
* LCK_LV: * LCK_LV:
* Lock/unlock an individual logical volume * Lock/unlock an individual logical volume
* Also suspends/resumes the LV if it's active. * Also suspends/resumes the LV if it's active.
* struct logical_volume *vol * char *vol holds "VG_name/LV_uuid"
* *
* FIXME: Change to * FIXME: Change to something like
* int lock_vol(const struct id *id, int flags); * int lock_vol(struct cmd_context *cmd, const struct id *id, int flags);
*/ */
int lock_vol(const void *vol, int flags); int lock_vol(struct cmd_context *cmd, const char *vol, int flags);
/* /*
* Lock type * Lock type

View File

@ -8,7 +8,8 @@
#include "metadata.h" #include "metadata.h"
#include "config.h" #include "config.h"
typedef int (*lock_resource_fn)(const char *resource, int flags); typedef int (*lock_resource_fn)(struct cmd_context *cmd, const char *resource,
int flags);
typedef void (*fin_lock_fn)(void); typedef void (*fin_lock_fn)(void);

View File

@ -10,6 +10,8 @@
#include "dev-cache.h" #include "dev-cache.h"
#include "metadata.h" #include "metadata.h"
#include "toolcontext.h" #include "toolcontext.h"
#include "lvm-string.h"
#include "uuid.h"
#include <string.h> #include <string.h>
@ -288,6 +290,20 @@ struct lv_list *find_lv_in_vg(struct volume_group *vg, const char *lv_name)
return NULL; return NULL;
} }
struct lv_list *find_lv_in_vg_by_uuid(struct volume_group *vg, const char *uuid)
{
struct list *lvh;
struct lv_list *lvl;
list_iterate(lvh, &vg->lvs) {
lvl = list_item(lvh, struct lv_list);
if (!strncmp(lvl->lv->id.uuid, uuid, ID_LEN))
return lvl;
}
return NULL;
}
struct logical_volume *find_lv(struct volume_group *vg, const char *lv_name) struct logical_volume *find_lv(struct volume_group *vg, const char *lv_name)
{ {
struct lv_list *lvl = find_lv_in_vg(vg, lv_name); struct lv_list *lvl = find_lv_in_vg(vg, lv_name);
@ -307,3 +323,15 @@ struct physical_volume *find_pv(struct volume_group *vg, struct device *dev)
} }
return NULL; return NULL;
} }
char *lvid(struct logical_volume *lv, char *buf, int size)
{
/* FIXME Create uuid.h functions for all uuid manipulation */
if (lvm_snprintf(buf, size, "%s/%." ID_LEN_S "s", lv->vg->name,
lv->id.uuid) < 0) {
log_error("Buffer too small to hold LV id: %s", buf);
return NULL;
}
return buf;
}

View File

@ -303,6 +303,11 @@ struct pv_list *find_pv_in_vg(struct volume_group *vg, const char *pv_name);
/* Find an LV within a given VG */ /* Find an LV within a given VG */
struct lv_list *find_lv_in_vg(struct volume_group *vg, const char *lv_name); struct lv_list *find_lv_in_vg(struct volume_group *vg, const char *lv_name);
struct lv_list *find_lv_in_vg_by_uuid(struct volume_group *vg,
const char *uuid);
/* Get unique LV identifier - currently "<VG uuid>/<LV uuid>" */
char *lvid(struct logical_volume *lv, char *buf, int size);
/* Return the VG that contains a given LV (based on path given in lv_name) */ /* Return the VG that contains a given LV (based on path given in lv_name) */
/* or environment var */ /* or environment var */

View File

@ -10,6 +10,7 @@
#include "lvm-types.h" #include "lvm-types.h"
#define ID_LEN 32 #define ID_LEN 32
#define ID_LEN_S "32"
struct id { struct id {
uint8_t uuid[ID_LEN]; uint8_t uuid[ID_LEN];

View File

@ -126,6 +126,7 @@ static int lvchange_permission(struct cmd_context *cmd,
struct logical_volume *lv) struct logical_volume *lv)
{ {
int lv_access; int lv_access;
char lvidbuf[128];
lv_access = arg_int_value(cmd, permission_ARG, 0); lv_access = arg_int_value(cmd, permission_ARG, 0);
@ -151,7 +152,10 @@ static int lvchange_permission(struct cmd_context *cmd,
lv->name); lv->name);
} }
if (!lock_vol(lv, LCK_LV | LCK_WRITE)) { if (!lvid(lv, lvidbuf, sizeof(lvidbuf)))
return 0;
if (!lock_vol(cmd, lvidbuf, LCK_LV | LCK_WRITE)) {
log_error("Failed to lock %s", lv->name); log_error("Failed to lock %s", lv->name);
return 0; return 0;
} }
@ -159,14 +163,14 @@ static int lvchange_permission(struct cmd_context *cmd,
log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name); log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name);
if (!cmd->fid->ops->vg_write(cmd->fid, lv->vg)) { if (!cmd->fid->ops->vg_write(cmd->fid, lv->vg)) {
/* FIXME: Attempt reversion? */ /* FIXME: Attempt reversion? */
lock_vol(lv, LCK_LV | LCK_NONE); lock_vol(cmd, lvidbuf, LCK_LV | LCK_NONE);
return 0; 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 (!lock_vol(lv, LCK_LV | LCK_NONE)) { if (!lock_vol(cmd, lvidbuf, LCK_LV | LCK_NONE)) {
log_error("Problem reactivating %s", lv->name); log_error("Problem reactivating %s", lv->name);
return 0; return 0;
} }
@ -228,6 +232,7 @@ static int lvchange_contiguous(struct cmd_context *cmd,
struct logical_volume *lv) struct logical_volume *lv)
{ {
int lv_allocation = 0; int lv_allocation = 0;
char lvidbuf[128];
if (strcmp(arg_str_value(cmd, contiguous_ARG, "n"), "n")) if (strcmp(arg_str_value(cmd, contiguous_ARG, "n"), "n"))
lv_allocation |= ALLOC_CONTIGUOUS; lv_allocation |= ALLOC_CONTIGUOUS;
@ -264,7 +269,10 @@ static int lvchange_contiguous(struct cmd_context *cmd,
lv->name); lv->name);
} }
if (!lock_vol(lv, LCK_LV | LCK_WRITE)) { if (!lvid(lv, lvidbuf, sizeof(lvidbuf)))
return 0;
if (!lock_vol(cmd, lvidbuf, LCK_LV | LCK_WRITE)) {
log_error("Failed to lock %s", lv->name); log_error("Failed to lock %s", lv->name);
return 0; return 0;
} }
@ -272,14 +280,14 @@ static int lvchange_contiguous(struct cmd_context *cmd,
log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name); log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name);
if (!cmd->fid->ops->vg_write(cmd->fid, lv->vg)) { if (!cmd->fid->ops->vg_write(cmd->fid, lv->vg)) {
/* FIXME: Attempt reversion? */ /* FIXME: Attempt reversion? */
lock_vol(lv, LCK_LV | LCK_NONE); lock_vol(cmd, lvidbuf, LCK_LV | LCK_NONE);
return 0; return 0;
} }
backup(lv->vg); backup(lv->vg);
log_very_verbose("Reactivating \"%s\" in kernel", lv->name); log_very_verbose("Reactivating \"%s\" in kernel", lv->name);
if (!lock_vol(lv, LCK_LV | LCK_NONE)) { if (!lock_vol(cmd, lvidbuf, LCK_LV | LCK_NONE)) {
log_error("Problem reactivating %s", lv->name); log_error("Problem reactivating %s", lv->name);
return 0; return 0;
} }
@ -292,6 +300,7 @@ static int lvchange_readahead(struct cmd_context *cmd,
struct logical_volume *lv) struct logical_volume *lv)
{ {
int read_ahead = 0; int read_ahead = 0;
char lvidbuf[128];
read_ahead = arg_int_value(cmd, readahead_ARG, 0); read_ahead = arg_int_value(cmd, readahead_ARG, 0);
@ -313,7 +322,10 @@ static int lvchange_readahead(struct cmd_context *cmd,
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);
if (!lock_vol(lv, LCK_LV | LCK_WRITE)) { if (!lvid(lv, lvidbuf, sizeof(lvidbuf)))
return 0;
if (!lock_vol(cmd, lvidbuf, LCK_LV | LCK_WRITE)) {
log_error("Failed to lock %s", lv->name); log_error("Failed to lock %s", lv->name);
return 0; return 0;
} }
@ -321,14 +333,14 @@ static int lvchange_readahead(struct cmd_context *cmd,
log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name); log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name);
if (!cmd->fid->ops->vg_write(cmd->fid, lv->vg)) { if (!cmd->fid->ops->vg_write(cmd->fid, lv->vg)) {
/* FIXME: Attempt reversion? */ /* FIXME: Attempt reversion? */
lock_vol(lv, LCK_LV | LCK_NONE); lock_vol(cmd, lvidbuf, LCK_LV | LCK_NONE);
return 0; return 0;
} }
backup(lv->vg); backup(lv->vg);
log_very_verbose("Reactivating \"%s\" in kernel", lv->name); log_very_verbose("Reactivating \"%s\" in kernel", lv->name);
if (!lock_vol(lv, LCK_LV | LCK_NONE)) { if (!lock_vol(cmd, lvidbuf, LCK_LV | LCK_NONE)) {
log_error("Problem reactivating %s", lv->name); log_error("Problem reactivating %s", lv->name);
return 0; return 0;
} }
@ -339,6 +351,8 @@ static int lvchange_readahead(struct cmd_context *cmd,
static int lvchange_persistent(struct cmd_context *cmd, static int lvchange_persistent(struct cmd_context *cmd,
struct logical_volume *lv) struct logical_volume *lv)
{ {
char lvidbuf[128];
if (!strcmp(arg_str_value(cmd, persistent_ARG, "n"), "n")) { if (!strcmp(arg_str_value(cmd, persistent_ARG, "n"), "n")) {
if (!(lv->status & FIXED_MINOR)) { if (!(lv->status & FIXED_MINOR)) {
log_error("Minor number is already not persistent " log_error("Minor number is already not persistent "
@ -363,7 +377,10 @@ static int lvchange_persistent(struct cmd_context *cmd,
lv->minor, lv->name); lv->minor, lv->name);
} }
if (!lock_vol(lv, LCK_LV | LCK_WRITE)) { if (!lvid(lv, lvidbuf, sizeof(lvidbuf)))
return 0;
if (!lock_vol(cmd, lvidbuf, LCK_LV | LCK_WRITE)) {
log_error("Failed to lock %s", lv->name); log_error("Failed to lock %s", lv->name);
return 0; return 0;
} }
@ -371,14 +388,14 @@ static int lvchange_persistent(struct cmd_context *cmd,
log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name); log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name);
if (!cmd->fid->ops->vg_write(cmd->fid, lv->vg)) { if (!cmd->fid->ops->vg_write(cmd->fid, lv->vg)) {
/* FIXME: Attempt reversion? */ /* FIXME: Attempt reversion? */
lock_vol(lv, LCK_LV | LCK_NONE); lock_vol(cmd, lvidbuf, LCK_LV | LCK_NONE);
return 0; return 0;
} }
backup(lv->vg); backup(lv->vg);
log_very_verbose("Reactivating \"%s\" in kernel", lv->name); log_very_verbose("Reactivating \"%s\" in kernel", lv->name);
if (!lock_vol(lv, LCK_LV | LCK_NONE)) { if (!lock_vol(cmd, lvidbuf, LCK_LV | LCK_NONE)) {
log_error("Problem reactivating %s", lv->name); log_error("Problem reactivating %s", lv->name);
return 0; return 0;
} }

View File

@ -437,7 +437,7 @@ int lvcreate(struct cmd_context *cmd, int argc, char **argv)
if (!_read_params(&lp, cmd, argc, argv)) if (!_read_params(&lp, cmd, argc, argv))
return -EINVALID_CMD_LINE; return -EINVALID_CMD_LINE;
if (!lock_vol(lp.vg_name, LCK_VG | LCK_WRITE)) { if (!lock_vol(cmd, lp.vg_name, LCK_VG | LCK_WRITE)) {
log_error("Can't get lock for %s", lp.vg_name); log_error("Can't get lock for %s", lp.vg_name);
return 0; return 0;
} }
@ -473,6 +473,6 @@ int lvcreate(struct cmd_context *cmd, int argc, char **argv)
r = 0; r = 0;
out: out:
lock_vol(lp.vg_name, LCK_VG | LCK_NONE); lock_vol(cmd, lp.vg_name, LCK_VG | LCK_NONE);
return r; return r;
} }

View File

@ -87,7 +87,7 @@ int lvrename(struct cmd_context *cmd, int argc, char **argv)
log_verbose("Checking for existing volume group \"%s\"", vg_name); log_verbose("Checking for existing volume group \"%s\"", vg_name);
if (!lock_vol(vg_name, LCK_VG | LCK_WRITE)) { if (!lock_vol(cmd, vg_name, LCK_VG | LCK_WRITE)) {
log_error("Can't get lock for %s", vg_name); log_error("Can't get lock for %s", vg_name);
return ECMD_FAILED; return ECMD_FAILED;
} }
@ -152,7 +152,7 @@ int lvrename(struct cmd_context *cmd, int argc, char **argv)
backup(lv->vg); backup(lv->vg);
lock_vol(vg_name, LCK_VG | LCK_NONE); lock_vol(cmd, vg_name, LCK_VG | LCK_NONE);
log_print("Renamed \"%s\" to \"%s\" in volume group \"%s\"", log_print("Renamed \"%s\" to \"%s\" in volume group \"%s\"",
lv_name_old, lv_name_new, vg_name); lv_name_old, lv_name_new, vg_name);
@ -160,6 +160,6 @@ int lvrename(struct cmd_context *cmd, int argc, char **argv)
return 0; return 0;
error: error:
lock_vol(vg_name, LCK_VG | LCK_NONE); lock_vol(cmd, vg_name, LCK_VG | LCK_NONE);
return ECMD_FAILED; return ECMD_FAILED;
} }

View File

@ -31,6 +31,7 @@ int lvresize(struct cmd_context *cmd, int argc, char **argv)
uint32_t size_rest; uint32_t size_rest;
sign_t sign = SIGN_NONE; sign_t sign = SIGN_NONE;
char *lv_name, *vg_name; char *lv_name, *vg_name;
char lvidbuf[128];
char *st; char *st;
char *dummy; char *dummy;
const char *cmd_name; const char *cmd_name;
@ -104,7 +105,7 @@ int lvresize(struct cmd_context *cmd, int argc, char **argv)
/* does VG exist? */ /* does VG exist? */
log_verbose("Finding volume group %s", vg_name); log_verbose("Finding volume group %s", vg_name);
if (!lock_vol(vg_name, LCK_VG | LCK_WRITE)) { if (!lock_vol(cmd, vg_name, LCK_VG | LCK_WRITE)) {
log_error("Can't get lock for %s", vg_name); log_error("Can't get lock for %s", vg_name);
return ECMD_FAILED; return ECMD_FAILED;
} }
@ -331,7 +332,10 @@ int lvresize(struct cmd_context *cmd, int argc, char **argv)
goto error; goto error;
} }
if (!lock_vol(lv, LCK_LV | LCK_WRITE)) { if (!lvid(lv, lvidbuf, sizeof(lvidbuf)))
goto error;
if (!lock_vol(cmd, lvidbuf, LCK_LV | LCK_WRITE)) {
log_error("Can't get lock for %s", lv_name); log_error("Can't get lock for %s", lv_name);
goto error; goto error;
} }
@ -339,28 +343,28 @@ int lvresize(struct cmd_context *cmd, int argc, char **argv)
/* 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? */ /* FIXME: Attempt reversion? */
lock_vol(lv, LCK_LV | LCK_NONE); lock_vol(cmd, lvidbuf, LCK_LV | LCK_NONE);
goto error; goto error;
} }
backup(vg); backup(vg);
if (!lock_vol(lv, LCK_LV | LCK_NONE)) { if (!lock_vol(cmd, lvidbuf, LCK_LV | LCK_NONE)) {
log_error("Problem reactivating %s", lv_name); log_error("Problem reactivating %s", lv_name);
goto error; goto error;
} }
lock_vol(vg_name, LCK_VG | LCK_NONE); lock_vol(cmd, vg_name, LCK_VG | LCK_NONE);
log_print("Logical volume %s successfully resized", lv_name); log_print("Logical volume %s successfully resized", lv_name);
return 0; return 0;
error: error:
lock_vol(vg_name, LCK_VG | LCK_NONE); lock_vol(cmd, vg_name, LCK_VG | LCK_NONE);
return ECMD_FAILED; return ECMD_FAILED;
error_cmdline: error_cmdline:
lock_vol(vg_name, LCK_VG | LCK_NONE); lock_vol(cmd, vg_name, LCK_VG | LCK_NONE);
return EINVALID_CMD_LINE; return EINVALID_CMD_LINE;
} }

View File

@ -98,32 +98,32 @@ int pvchange_single(struct cmd_context *cmd, struct physical_volume *pv)
log_verbose("Finding volume group of physical volume \"%s\"", log_verbose("Finding volume group of physical volume \"%s\"",
pv_name); pv_name);
if (!lock_vol(pv->vg_name, LCK_VG | LCK_WRITE)) { if (!lock_vol(cmd, pv->vg_name, LCK_VG | LCK_WRITE)) {
log_error("Can't get lock for %s", pv->vg_name); log_error("Can't get lock for %s", pv->vg_name);
return ECMD_FAILED; return ECMD_FAILED;
} }
if (!(vg = cmd->fid->ops->vg_read(cmd->fid, pv->vg_name))) { if (!(vg = cmd->fid->ops->vg_read(cmd->fid, pv->vg_name))) {
lock_vol(pv->vg_name, LCK_VG | LCK_NONE); lock_vol(cmd, pv->vg_name, LCK_VG | LCK_NONE);
log_error("Unable to find volume group of \"%s\"", log_error("Unable to find volume group of \"%s\"",
pv_name); pv_name);
return 0; return 0;
} }
if (vg->status & EXPORTED_VG) { if (vg->status & EXPORTED_VG) {
lock_vol(pv->vg_name, LCK_VG | LCK_NONE); lock_vol(cmd, pv->vg_name, LCK_VG | LCK_NONE);
log_error("Volume group \"%s\" is exported", vg->name); log_error("Volume group \"%s\" is exported", vg->name);
return ECMD_FAILED; return ECMD_FAILED;
} }
if (!(vg->status & LVM_WRITE)) { if (!(vg->status & LVM_WRITE)) {
lock_vol(pv->vg_name, LCK_VG | LCK_NONE); lock_vol(cmd, pv->vg_name, LCK_VG | LCK_NONE);
log_error("Volume group \"%s\" is read-only", vg->name); log_error("Volume group \"%s\" is read-only", vg->name);
return ECMD_FAILED; return ECMD_FAILED;
} }
if (!(pvl = find_pv_in_vg(vg, pv_name))) { if (!(pvl = find_pv_in_vg(vg, pv_name))) {
lock_vol(pv->vg_name, LCK_VG | LCK_NONE); lock_vol(cmd, pv->vg_name, LCK_VG | LCK_NONE);
log_error log_error
("Unable to find \"%s\" in volume group \"%s\"", ("Unable to find \"%s\" in volume group \"%s\"",
pv_name, vg->name); pv_name, vg->name);
@ -139,7 +139,7 @@ int pvchange_single(struct cmd_context *cmd, struct physical_volume *pv)
log_error("Physical volume \"%s\" is already allocatable", log_error("Physical volume \"%s\" is already allocatable",
pv_name); pv_name);
if (*pv->vg_name) if (*pv->vg_name)
lock_vol(pv->vg_name, LCK_VG | LCK_NONE); lock_vol(cmd, pv->vg_name, LCK_VG | LCK_NONE);
return 0; return 0;
} }
@ -147,7 +147,7 @@ int pvchange_single(struct cmd_context *cmd, struct physical_volume *pv)
log_error("Physical volume \"%s\" is already unallocatable", log_error("Physical volume \"%s\" is already unallocatable",
pv_name); pv_name);
if (*pv->vg_name) if (*pv->vg_name)
lock_vol(pv->vg_name, LCK_VG | LCK_NONE); lock_vol(cmd, pv->vg_name, LCK_VG | LCK_NONE);
return 0; return 0;
} }
@ -164,13 +164,13 @@ int pvchange_single(struct cmd_context *cmd, struct physical_volume *pv)
log_verbose("Updating physical volume \"%s\"", pv_name); log_verbose("Updating physical volume \"%s\"", pv_name);
if (*pv->vg_name) { if (*pv->vg_name) {
if (!(cmd->fid->ops->vg_write(cmd->fid, vg))) { if (!(cmd->fid->ops->vg_write(cmd->fid, vg))) {
lock_vol(pv->vg_name, LCK_VG | LCK_NONE); lock_vol(cmd, pv->vg_name, LCK_VG | LCK_NONE);
log_error("Failed to store physical volume \"%s\" in " log_error("Failed to store physical volume \"%s\" in "
"volume group \"%s\"", pv_name, vg->name); "volume group \"%s\"", pv_name, vg->name);
return 0; return 0;
} }
backup(vg); backup(vg);
lock_vol(pv->vg_name, LCK_VG | LCK_NONE); lock_vol(cmd, pv->vg_name, LCK_VG | LCK_NONE);
} else { } else {
if (!(cmd->fid->ops->pv_write(cmd->fid, pv))) { if (!(cmd->fid->ops->pv_write(cmd->fid, pv))) {
log_error("Failed to store physical volume \"%s\"", log_error("Failed to store physical volume \"%s\"",

View File

@ -134,13 +134,13 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
log_verbose("Using volume group(s) on command line"); log_verbose("Using volume group(s) on command line");
for (; opt < argc; opt++) { for (; opt < argc; opt++) {
vg_name = argv[opt]; vg_name = argv[opt];
if (!lock_vol((void *) vg_name, LCK_VG | lock_type)) { if (!lock_vol(cmd, (void *) vg_name, LCK_VG | lock_type)) {
log_error("Can't lock %s: skipping", vg_name); log_error("Can't lock %s: skipping", vg_name);
continue; continue;
} }
if ((ret = process_single(cmd, vg_name)) > ret_max) if ((ret = process_single(cmd, vg_name)) > ret_max)
ret_max = ret; ret_max = ret;
lock_vol((void *) vg_name, LCK_VG | LCK_NONE); lock_vol(cmd, (void *) vg_name, LCK_VG | LCK_NONE);
} }
} else { } else {
log_verbose("Finding all volume groups"); log_verbose("Finding all volume groups");
@ -150,7 +150,7 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
} }
list_iterate(vgh, vgs) { list_iterate(vgh, vgs) {
vg_name = list_item(vgh, struct name_list)->name; vg_name = list_item(vgh, struct name_list)->name;
if (!lock_vol((void *) vg_name, LCK_VG | lock_type)) { if (!lock_vol(cmd, (void *) vg_name, LCK_VG | lock_type)) {
log_error("Can't lock %s: skipping", vg_name); log_error("Can't lock %s: skipping", vg_name);
continue; continue;
} }
@ -158,7 +158,7 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
if (ret > ret_max) if (ret > ret_max)
ret_max = ret; ret_max = ret;
lock_vol((void *) vg_name, LCK_VG | LCK_NONE); lock_vol(cmd, (void *) vg_name, LCK_VG | LCK_NONE);
} }
} }

View File

@ -92,32 +92,32 @@ int vgcreate(struct cmd_context *cmd, int argc, char **argv)
log_error("Warning: Setting maxphysicalvolumes to %d", log_error("Warning: Setting maxphysicalvolumes to %d",
vg->max_pv); vg->max_pv);
if (!lock_vol("", LCK_VG | LCK_WRITE)) { if (!lock_vol(cmd, "", LCK_VG | LCK_WRITE)) {
log_error("Can't get lock for orphan PVs"); log_error("Can't get lock for orphan PVs");
return ECMD_FAILED; return ECMD_FAILED;
} }
if (!lock_vol(vg_name, LCK_VG | LCK_WRITE | LCK_NONBLOCK)) { if (!lock_vol(cmd, vg_name, LCK_VG | LCK_WRITE | LCK_NONBLOCK)) {
log_error("Can't get lock for %s", vg_name); log_error("Can't get lock for %s", vg_name);
lock_vol("", LCK_VG | LCK_NONE); lock_vol(cmd, "", LCK_VG | LCK_NONE);
return ECMD_FAILED; return ECMD_FAILED;
} }
if (!archive(vg)) { if (!archive(vg)) {
lock_vol(vg_name, LCK_VG | LCK_NONE); lock_vol(cmd, vg_name, LCK_VG | LCK_NONE);
lock_vol("", LCK_VG | LCK_NONE); lock_vol(cmd, "", LCK_VG | LCK_NONE);
return ECMD_FAILED; return ECMD_FAILED;
} }
/* 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)) {
lock_vol(vg_name, LCK_VG | LCK_NONE); lock_vol(cmd, vg_name, LCK_VG | LCK_NONE);
lock_vol("", LCK_VG | LCK_NONE); lock_vol(cmd, "", LCK_VG | LCK_NONE);
return ECMD_FAILED; return ECMD_FAILED;
} }
lock_vol(vg_name, LCK_VG | LCK_NONE); lock_vol(cmd, vg_name, LCK_VG | LCK_NONE);
lock_vol("", LCK_VG | LCK_NONE); lock_vol(cmd, "", LCK_VG | LCK_NONE);
backup(vg); backup(vg);

View File

@ -40,14 +40,14 @@ int vgextend(struct cmd_context *cmd, int argc, char **argv)
argc--; argc--;
argv++; argv++;
if (!lock_vol("", LCK_VG | LCK_WRITE)) { if (!lock_vol(cmd, "", LCK_VG | LCK_WRITE)) {
log_error("Can't get lock for orphan PVs"); log_error("Can't get lock for orphan PVs");
return ECMD_FAILED; return ECMD_FAILED;
} }
log_verbose("Checking for volume group \"%s\"", vg_name); log_verbose("Checking for volume group \"%s\"", vg_name);
if (!lock_vol(vg_name, LCK_VG | LCK_WRITE | LCK_NONBLOCK)) { if (!lock_vol(cmd, vg_name, LCK_VG | LCK_WRITE | LCK_NONBLOCK)) {
lock_vol("", LCK_VG | LCK_NONE); lock_vol(cmd, "", LCK_VG | LCK_NONE);
log_error("Can't get lock for %s", vg_name); log_error("Can't get lock for %s", vg_name);
goto error; goto error;
} }
@ -96,15 +96,15 @@ int vgextend(struct cmd_context *cmd, int argc, char **argv)
backup(vg); backup(vg);
lock_vol(vg_name, LCK_VG | LCK_NONE); lock_vol(cmd, vg_name, LCK_VG | LCK_NONE);
lock_vol("", LCK_VG | LCK_NONE); lock_vol(cmd, "", LCK_VG | LCK_NONE);
log_print("Volume group \"%s\" successfully extended", vg_name); log_print("Volume group \"%s\" successfully extended", vg_name);
return 0; return 0;
error: error:
lock_vol(vg_name, LCK_VG | LCK_NONE); lock_vol(cmd, vg_name, LCK_VG | LCK_NONE);
lock_vol("", LCK_VG | LCK_NONE); lock_vol(cmd, "", LCK_VG | LCK_NONE);
return ECMD_FAILED; return ECMD_FAILED;
} }

View File

@ -60,33 +60,33 @@ int vgmerge_single(struct cmd_context *cmd, const char *vg_name_to,
} }
log_verbose("Checking for volume group \"%s\"", vg_name_to); log_verbose("Checking for volume group \"%s\"", vg_name_to);
if (!lock_vol(vg_name_to, LCK_VG | LCK_WRITE)) { if (!lock_vol(cmd, vg_name_to, LCK_VG | LCK_WRITE)) {
log_error("Can't get lock for %s", vg_name_to); log_error("Can't get lock for %s", vg_name_to);
return ECMD_FAILED; return ECMD_FAILED;
} }
if (!(vg_to = cmd->fid->ops->vg_read(cmd->fid, vg_name_to))) { if (!(vg_to = cmd->fid->ops->vg_read(cmd->fid, vg_name_to))) {
log_error("Volume group \"%s\" doesn't exist", vg_name_to); log_error("Volume group \"%s\" doesn't exist", vg_name_to);
lock_vol(vg_name_to, LCK_VG | LCK_NONE); lock_vol(cmd, vg_name_to, LCK_VG | LCK_NONE);
return ECMD_FAILED; return ECMD_FAILED;
} }
if (vg_to->status & EXPORTED_VG) { if (vg_to->status & EXPORTED_VG) {
log_error("Volume group \"%s\" is exported", vg_to->name); log_error("Volume group \"%s\" is exported", vg_to->name);
lock_vol(vg_name_to, LCK_VG | LCK_NONE); lock_vol(cmd, vg_name_to, LCK_VG | LCK_NONE);
return ECMD_FAILED; return ECMD_FAILED;
} }
if (!(vg_to->status & LVM_WRITE)) { if (!(vg_to->status & LVM_WRITE)) {
log_error("Volume group \"%s\" is read-only", vg_to->name); log_error("Volume group \"%s\" is read-only", vg_to->name);
lock_vol(vg_name_to, LCK_VG | LCK_NONE); lock_vol(cmd, vg_name_to, LCK_VG | LCK_NONE);
return ECMD_FAILED; return ECMD_FAILED;
} }
log_verbose("Checking for volume group \"%s\"", vg_name_from); log_verbose("Checking for volume group \"%s\"", vg_name_from);
if (!lock_vol(vg_name_from, LCK_VG | LCK_WRITE | LCK_NONBLOCK)) { if (!lock_vol(cmd, vg_name_from, LCK_VG | LCK_WRITE | LCK_NONBLOCK)) {
log_error("Can't get lock for %s", vg_name_from); log_error("Can't get lock for %s", vg_name_from);
lock_vol(vg_name_to, LCK_VG | LCK_NONE); lock_vol(cmd, vg_name_to, LCK_VG | LCK_NONE);
return ECMD_FAILED; return ECMD_FAILED;
} }
@ -190,15 +190,15 @@ int vgmerge_single(struct cmd_context *cmd, const char *vg_name_to,
backup(vg_to); backup(vg_to);
lock_vol(vg_name_from, LCK_VG | LCK_NONE); lock_vol(cmd, vg_name_from, LCK_VG | LCK_NONE);
lock_vol(vg_name_to, LCK_VG | LCK_NONE); lock_vol(cmd, vg_name_to, LCK_VG | LCK_NONE);
log_print("Volume group \"%s\" successfully merged into \"%s\"", log_print("Volume group \"%s\" successfully merged into \"%s\"",
vg_from->name, vg_to->name); vg_from->name, vg_to->name);
return 0; return 0;
error: error:
lock_vol(vg_name_from, LCK_VG | LCK_NONE); lock_vol(cmd, vg_name_from, LCK_VG | LCK_NONE);
lock_vol(vg_name_to, LCK_VG | LCK_NONE); lock_vol(cmd, vg_name_to, LCK_VG | LCK_NONE);
return ECMD_FAILED; return ECMD_FAILED;
} }

View File

@ -51,32 +51,32 @@ int vgreduce(struct cmd_context *cmd, int argc, char **argv)
argc--; argc--;
log_verbose("Finding volume group \"%s\"", vg_name); log_verbose("Finding volume group \"%s\"", vg_name);
if (!lock_vol(vg_name, LCK_VG | LCK_WRITE)) { if (!lock_vol(cmd, vg_name, LCK_VG | LCK_WRITE)) {
log_error("Can't get lock for %s", vg_name); log_error("Can't get lock for %s", vg_name);
return ECMD_FAILED; return ECMD_FAILED;
} }
if (!(vg = cmd->fid->ops->vg_read(cmd->fid, vg_name))) { if (!(vg = cmd->fid->ops->vg_read(cmd->fid, vg_name))) {
log_error("Volume group \"%s\" doesn't exist", vg_name); log_error("Volume group \"%s\" doesn't exist", vg_name);
lock_vol(vg_name, LCK_VG | LCK_NONE); lock_vol(cmd, vg_name, LCK_VG | LCK_NONE);
return ECMD_FAILED; return ECMD_FAILED;
} }
if (vg->status & EXPORTED_VG) { if (vg->status & EXPORTED_VG) {
log_error("Volume group \"%s\" is exported", vg->name); log_error("Volume group \"%s\" is exported", vg->name);
lock_vol(vg_name, LCK_VG | LCK_NONE); lock_vol(cmd, vg_name, LCK_VG | LCK_NONE);
return ECMD_FAILED; return ECMD_FAILED;
} }
if (!(vg->status & LVM_WRITE)) { if (!(vg->status & LVM_WRITE)) {
log_error("Volume group \"%s\" is read-only", vg_name); log_error("Volume group \"%s\" is read-only", vg_name);
lock_vol(vg_name, LCK_VG | LCK_NONE); lock_vol(cmd, vg_name, LCK_VG | LCK_NONE);
return ECMD_FAILED; return ECMD_FAILED;
} }
if (!(vg->status & RESIZEABLE_VG)) { if (!(vg->status & RESIZEABLE_VG)) {
log_error("Volume group \"%s\" is not reducable", vg_name); log_error("Volume group \"%s\" is not reducable", vg_name);
lock_vol(vg_name, LCK_VG | LCK_NONE); lock_vol(cmd, vg_name, LCK_VG | LCK_NONE);
return ECMD_FAILED; return ECMD_FAILED;
} }
@ -84,7 +84,7 @@ int vgreduce(struct cmd_context *cmd, int argc, char **argv)
/* and update in batch here? */ /* and update in batch here? */
ret = process_each_pv(cmd, argc, argv, vg, vgreduce_single); ret = process_each_pv(cmd, argc, argv, vg, vgreduce_single);
lock_vol(vg_name, LCK_VG | LCK_NONE); lock_vol(cmd, vg_name, LCK_VG | LCK_NONE);
return ret; return ret;

View File

@ -26,7 +26,7 @@ int vgremove(struct cmd_context *cmd, int argc, char **argv)
{ {
int ret; int ret;
if (!lock_vol("", LCK_VG | LCK_WRITE)) { if (!lock_vol(cmd, "", LCK_VG | LCK_WRITE)) {
log_error("Can't get lock for orphan PVs"); log_error("Can't get lock for orphan PVs");
return ECMD_FAILED; return ECMD_FAILED;
} }
@ -34,7 +34,7 @@ int vgremove(struct cmd_context *cmd, int argc, char **argv)
ret = process_each_vg(cmd, argc, argv, LCK_WRITE | LCK_NONBLOCK, ret = process_each_vg(cmd, argc, argv, LCK_WRITE | LCK_NONBLOCK,
&vgremove_single); &vgremove_single);
lock_vol("", LCK_VG | LCK_NONE); lock_vol(cmd, "", LCK_VG | LCK_NONE);
return ret; return ret;
} }

View File

@ -69,25 +69,25 @@ int vgrename(struct cmd_context *cmd, int argc, char **argv)
log_verbose("Checking for existing volume group \"%s\"", vg_name_old); log_verbose("Checking for existing volume group \"%s\"", vg_name_old);
if (!lock_vol(vg_name_old, LCK_VG | LCK_WRITE)) { if (!lock_vol(cmd, vg_name_old, LCK_VG | LCK_WRITE)) {
log_error("Can't get lock for %s", vg_name_old); log_error("Can't get lock for %s", vg_name_old);
return ECMD_FAILED; return ECMD_FAILED;
} }
if (!(vg_old = cmd->fid->ops->vg_read(cmd->fid, vg_name_old))) { if (!(vg_old = cmd->fid->ops->vg_read(cmd->fid, vg_name_old))) {
log_error("Volume group \"%s\" doesn't exist", vg_name_old); log_error("Volume group \"%s\" doesn't exist", vg_name_old);
lock_vol(vg_name_old, LCK_VG | LCK_NONE); lock_vol(cmd, vg_name_old, LCK_VG | LCK_NONE);
return ECMD_FAILED; return ECMD_FAILED;
} }
if (vg_old->status & EXPORTED_VG) { if (vg_old->status & EXPORTED_VG) {
lock_vol(vg_name_old, LCK_VG | LCK_NONE); lock_vol(cmd, vg_name_old, LCK_VG | LCK_NONE);
log_error("Volume group \"%s\" is exported", vg_old->name); log_error("Volume group \"%s\" is exported", vg_old->name);
return ECMD_FAILED; return ECMD_FAILED;
} }
if (!(vg_old->status & LVM_WRITE)) { if (!(vg_old->status & LVM_WRITE)) {
lock_vol(vg_name_old, LCK_VG | LCK_NONE); lock_vol(cmd, vg_name_old, LCK_VG | LCK_NONE);
log_error("Volume group \"%s\" is read-only", vg_old->name); log_error("Volume group \"%s\" is read-only", vg_old->name);
return ECMD_FAILED; return ECMD_FAILED;
} }
@ -98,7 +98,7 @@ int vgrename(struct cmd_context *cmd, int argc, char **argv)
/***** FIXME Handle this with multiple LV renames! /***** FIXME Handle this with multiple LV renames!
if (!force_ARG) { if (!force_ARG) {
log_error("Use -f to force the rename"); log_error("Use -f to force the rename");
lock_vol(vg_name_old, LCK_VG | LCK_NONE); lock_vol(cmd, vg_name_old, LCK_VG | LCK_NONE);
return ECMD_FAILED; return ECMD_FAILED;
} }
*****/ *****/
@ -106,8 +106,8 @@ int vgrename(struct cmd_context *cmd, int argc, char **argv)
log_verbose("Checking for new volume group \"%s\"", vg_name_new); log_verbose("Checking for new volume group \"%s\"", vg_name_new);
if (!lock_vol(vg_name_new, LCK_VG | LCK_WRITE | LCK_NONBLOCK)) { if (!lock_vol(cmd, vg_name_new, LCK_VG | LCK_WRITE | LCK_NONBLOCK)) {
lock_vol(vg_name_old, LCK_VG | LCK_NONE); lock_vol(cmd, vg_name_old, LCK_VG | LCK_NONE);
log_error("Can't get lock for %s", vg_name_new); log_error("Can't get lock for %s", vg_name_new);
return ECMD_FAILED; return ECMD_FAILED;
} }
@ -158,8 +158,8 @@ int vgrename(struct cmd_context *cmd, int argc, char **argv)
backup(vg_old); backup(vg_old);
lock_vol(vg_name_new, LCK_VG | LCK_NONE); lock_vol(cmd, vg_name_new, LCK_VG | LCK_NONE);
lock_vol(vg_name_old, LCK_VG | LCK_NONE); lock_vol(cmd, vg_name_old, LCK_VG | LCK_NONE);
log_print("Volume group \"%s\" successfully renamed to \"%s\"", log_print("Volume group \"%s\" successfully renamed to \"%s\"",
vg_name_old, vg_name_new); vg_name_old, vg_name_new);
@ -167,8 +167,8 @@ int vgrename(struct cmd_context *cmd, int argc, char **argv)
return 0; return 0;
error: error:
lock_vol(vg_name_new, LCK_VG | LCK_NONE); lock_vol(cmd, vg_name_new, LCK_VG | LCK_NONE);
lock_vol(vg_name_old, LCK_VG | LCK_NONE); lock_vol(cmd, vg_name_old, LCK_VG | LCK_NONE);
return ECMD_FAILED; return ECMD_FAILED;
} }