diff options
author | Alasdair Kergon <agk@redhat.com> | 2002-02-25 12:56:16 +0000 |
---|---|---|
committer | Alasdair Kergon <agk@redhat.com> | 2002-02-25 12:56:16 +0000 |
commit | 413cc9189e5a77a10ce227072855141cd7af79d7 (patch) | |
tree | 57a1288121d4c70292b06c23b05f3c6c1d346178 | |
parent | ca73e23fd08850c916b9bf5671adfc68384ae466 (diff) | |
download | lvm2-413cc9189e5a77a10ce227072855141cd7af79d7.tar.gz lvm2-413cc9189e5a77a10ce227072855141cd7af79d7.tar.xz lvm2-413cc9189e5a77a10ce227072855141cd7af79d7.zip |
Begin conversion so LV id is passed to activation unit instead of
struct logical_volume.
-rw-r--r-- | lib/activate/activate.c | 64 | ||||
-rw-r--r-- | lib/activate/activate.h | 7 | ||||
-rw-r--r-- | lib/locking/file_locking.c | 40 | ||||
-rw-r--r-- | lib/locking/locking.c | 48 | ||||
-rw-r--r-- | lib/locking/locking.h | 8 | ||||
-rw-r--r-- | lib/locking/locking_types.h | 3 | ||||
-rw-r--r-- | lib/metadata/metadata.c | 28 | ||||
-rw-r--r-- | lib/metadata/metadata.h | 5 | ||||
-rw-r--r-- | lib/uuid/uuid.h | 1 | ||||
-rw-r--r-- | tools/lvchange.c | 41 | ||||
-rw-r--r-- | tools/lvcreate.c | 4 | ||||
-rw-r--r-- | tools/lvrename.c | 6 | ||||
-rw-r--r-- | tools/lvresize.c | 18 | ||||
-rw-r--r-- | tools/pvchange.c | 18 | ||||
-rw-r--r-- | tools/toollib.c | 8 | ||||
-rw-r--r-- | tools/vgcreate.c | 18 | ||||
-rw-r--r-- | tools/vgextend.c | 14 | ||||
-rw-r--r-- | tools/vgmerge.c | 20 | ||||
-rw-r--r-- | tools/vgreduce.c | 12 | ||||
-rw-r--r-- | tools/vgremove.c | 4 | ||||
-rw-r--r-- | tools/vgrename.c | 22 |
21 files changed, 237 insertions, 152 deletions
diff --git a/lib/activate/activate.c b/lib/activate/activate.c index c215a3bd..8edd8606 100644 --- a/lib/activate/activate.c +++ b/lib/activate/activate.c @@ -12,6 +12,8 @@ #include "fs.h" #include "lvm-string.h" #include "names.h" +#include "pool.h" +#include "toolcontext.h" #include <limits.h> #include <linux/kdev_t.h> @@ -468,3 +470,65 @@ int lvs_in_vg_opened(struct volume_group *vg) 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; +} + diff --git a/lib/activate/activate.h b/lib/activate/activate.h index e041a2c2..d5d0bf79 100644 --- a/lib/activate/activate.h +++ b/lib/activate/activate.h @@ -35,6 +35,13 @@ int lv_suspend(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. */ int lv_setup_cow_store(struct logical_volume *lv); diff --git a/lib/locking/file_locking.c b/lib/locking/file_locking.c index 38e64860..cedddf6b 100644 --- a/lib/locking/file_locking.c +++ b/lib/locking/file_locking.c @@ -145,7 +145,7 @@ static int _lock_file(const char *file, int flags) 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]; @@ -157,40 +157,32 @@ int lock_resource(const char *resource, int flags) else lvm_snprintf(lockfile, sizeof(lockfile), "%s/V_%s", _lock_dir, resource); + if (!_lock_file(lockfile, flags)) + return 0; break; case LCK_LV: - /* No-op: see FIXME below */ - return 1; - default: - log_error("Unrecognised lock scope: %d", - flags & LCK_SCOPE_MASK); - return 0; - } - - if (!_lock_file(lockfile, flags)) - return 0; - - 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); + if (!lv_resume_if_active(cmd, resource)) + return 0; break; case LCK_WRITE: - if (lv_active_by_id(resource)) - lv_suspend_by_id(resource); + if (!lv_suspend_if_active(cmd, resource)) + return 0; break; default: break; } + break; + default: + log_error("Unrecognised lock scope: %d", + flags & LCK_SCOPE_MASK); + return 0; } -*******/ + + return 1; +} + int init_file_locking(struct locking_type *locking, struct config_file *cf) { diff --git a/lib/locking/locking.c b/lib/locking/locking.c index 5b84c078..98747434 100644 --- a/lib/locking/locking.c +++ b/lib/locking/locking.c @@ -60,7 +60,7 @@ static inline void _update_lock_count(int flags) /* * 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; } @@ -115,32 +115,18 @@ void fin_locking(void) /* * VG locking is by name - * LV locking is by struct logical_volume - * FIXME This should take a unique name or id for an LV + * LV locking is by VG_name/LV_uuid + * 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]; switch (flags & LCK_SCOPE_MASK) { - case LCK_VG: - /* - * Lock a volume group before changing on-disk metadata. - */ + case LCK_VG: /* Lock volume group before changing on-disk metadata. */ + case LCK_LV: /* Suspends LV if it's active. */ strncpy(resource, (char *) vol, sizeof(resource)); 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: log_error("Unrecognised lock scope: %d", flags & LCK_SCOPE_MASK); @@ -149,31 +135,11 @@ int lock_vol(const void *vol, int flags) _ignore_signals(); - if (!(_locking.lock_resource(resource, flags))) { + if (!(_locking.lock_resource(cmd, resource, flags))) { _enable_signals(); 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); _enable_signals(); diff --git a/lib/locking/locking.h b/lib/locking/locking.h index ed981585..0f1a1911 100644 --- a/lib/locking/locking.h +++ b/lib/locking/locking.h @@ -21,12 +21,12 @@ void fin_locking(void); * LCK_LV: * Lock/unlock an individual logical volume * Also suspends/resumes the LV if it's active. - * struct logical_volume *vol + * char *vol holds "VG_name/LV_uuid" * - * FIXME: Change to - * int lock_vol(const struct id *id, int flags); + * FIXME: Change to something like + * 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 diff --git a/lib/locking/locking_types.h b/lib/locking/locking_types.h index 4b677f7e..cefa1db2 100644 --- a/lib/locking/locking_types.h +++ b/lib/locking/locking_types.h @@ -8,7 +8,8 @@ #include "metadata.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); diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c index 3ea9e110..80a4fdce 100644 --- a/lib/metadata/metadata.c +++ b/lib/metadata/metadata.c @@ -10,6 +10,8 @@ #include "dev-cache.h" #include "metadata.h" #include "toolcontext.h" +#include "lvm-string.h" +#include "uuid.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; } +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 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; } + +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; +} diff --git a/lib/metadata/metadata.h b/lib/metadata/metadata.h index 8e6969d4..dc9cacf8 100644 --- a/lib/metadata/metadata.h +++ b/lib/metadata/metadata.h @@ -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 */ 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) */ /* or environment var */ diff --git a/lib/uuid/uuid.h b/lib/uuid/uuid.h index a84881cb..b6245d08 100644 --- a/lib/uuid/uuid.h +++ b/lib/uuid/uuid.h @@ -10,6 +10,7 @@ #include "lvm-types.h" #define ID_LEN 32 +#define ID_LEN_S "32" struct id { uint8_t uuid[ID_LEN]; diff --git a/tools/lvchange.c b/tools/lvchange.c index 25b2d4c5..2a7198a3 100644 --- a/tools/lvchange.c +++ b/tools/lvchange.c @@ -126,6 +126,7 @@ static int lvchange_permission(struct cmd_context *cmd, struct logical_volume *lv) { int lv_access; + char lvidbuf[128]; lv_access = arg_int_value(cmd, permission_ARG, 0); @@ -151,7 +152,10 @@ static int lvchange_permission(struct cmd_context *cmd, 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); 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); if (!cmd->fid->ops->vg_write(cmd->fid, lv->vg)) { /* FIXME: Attempt reversion? */ - lock_vol(lv, LCK_LV | LCK_NONE); + lock_vol(cmd, lvidbuf, LCK_LV | LCK_NONE); return 0; } backup(lv->vg); 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); return 0; } @@ -228,6 +232,7 @@ static int lvchange_contiguous(struct cmd_context *cmd, struct logical_volume *lv) { int lv_allocation = 0; + char lvidbuf[128]; if (strcmp(arg_str_value(cmd, contiguous_ARG, "n"), "n")) lv_allocation |= ALLOC_CONTIGUOUS; @@ -264,7 +269,10 @@ static int lvchange_contiguous(struct cmd_context *cmd, 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); 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); if (!cmd->fid->ops->vg_write(cmd->fid, lv->vg)) { /* FIXME: Attempt reversion? */ - lock_vol(lv, LCK_LV | LCK_NONE); + lock_vol(cmd, lvidbuf, LCK_LV | LCK_NONE); return 0; } backup(lv->vg); 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); return 0; } @@ -292,6 +300,7 @@ static int lvchange_readahead(struct cmd_context *cmd, struct logical_volume *lv) { int read_ahead = 0; + char lvidbuf[128]; 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, 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); 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); if (!cmd->fid->ops->vg_write(cmd->fid, lv->vg)) { /* FIXME: Attempt reversion? */ - lock_vol(lv, LCK_LV | LCK_NONE); + lock_vol(cmd, lvidbuf, LCK_LV | LCK_NONE); return 0; } backup(lv->vg); 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); return 0; } @@ -339,6 +351,8 @@ static int lvchange_readahead(struct cmd_context *cmd, static int lvchange_persistent(struct cmd_context *cmd, struct logical_volume *lv) { + char lvidbuf[128]; + if (!strcmp(arg_str_value(cmd, persistent_ARG, "n"), "n")) { if (!(lv->status & FIXED_MINOR)) { log_error("Minor number is already not persistent " @@ -363,7 +377,10 @@ static int lvchange_persistent(struct cmd_context *cmd, 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); 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); if (!cmd->fid->ops->vg_write(cmd->fid, lv->vg)) { /* FIXME: Attempt reversion? */ - lock_vol(lv, LCK_LV | LCK_NONE); + lock_vol(cmd, lvidbuf, LCK_LV | LCK_NONE); return 0; } backup(lv->vg); 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); return 0; } diff --git a/tools/lvcreate.c b/tools/lvcreate.c index 14052547..03c7021f 100644 --- a/tools/lvcreate.c +++ b/tools/lvcreate.c @@ -437,7 +437,7 @@ int lvcreate(struct cmd_context *cmd, int argc, char **argv) if (!_read_params(&lp, cmd, argc, argv)) 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); return 0; } @@ -473,6 +473,6 @@ int lvcreate(struct cmd_context *cmd, int argc, char **argv) r = 0; out: - lock_vol(lp.vg_name, LCK_VG | LCK_NONE); + lock_vol(cmd, lp.vg_name, LCK_VG | LCK_NONE); return r; } diff --git a/tools/lvrename.c b/tools/lvrename.c index f7d704f5..846feafb 100644 --- a/tools/lvrename.c +++ b/tools/lvrename.c @@ -87,7 +87,7 @@ int lvrename(struct cmd_context *cmd, int argc, char **argv) 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); return ECMD_FAILED; } @@ -152,7 +152,7 @@ int lvrename(struct cmd_context *cmd, int argc, char **argv) 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\"", lv_name_old, lv_name_new, vg_name); @@ -160,6 +160,6 @@ int lvrename(struct cmd_context *cmd, int argc, char **argv) return 0; error: - lock_vol(vg_name, LCK_VG | LCK_NONE); + lock_vol(cmd, vg_name, LCK_VG | LCK_NONE); return ECMD_FAILED; } diff --git a/tools/lvresize.c b/tools/lvresize.c index 5220d561..f34cd1a8 100644 --- a/tools/lvresize.c +++ b/tools/lvresize.c @@ -31,6 +31,7 @@ int lvresize(struct cmd_context *cmd, int argc, char **argv) uint32_t size_rest; sign_t sign = SIGN_NONE; char *lv_name, *vg_name; + char lvidbuf[128]; char *st; char *dummy; const char *cmd_name; @@ -104,7 +105,7 @@ int lvresize(struct cmd_context *cmd, int argc, char **argv) /* does VG exist? */ 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); return ECMD_FAILED; } @@ -331,7 +332,10 @@ int lvresize(struct cmd_context *cmd, int argc, char **argv) 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); goto error; } @@ -339,28 +343,28 @@ int lvresize(struct cmd_context *cmd, int argc, char **argv) /* store vg on disk(s) */ if (!cmd->fid->ops->vg_write(cmd->fid, vg)) { /* FIXME: Attempt reversion? */ - lock_vol(lv, LCK_LV | LCK_NONE); + lock_vol(cmd, lvidbuf, LCK_LV | LCK_NONE); goto error; } 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); 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); return 0; error: - lock_vol(vg_name, LCK_VG | LCK_NONE); + lock_vol(cmd, vg_name, LCK_VG | LCK_NONE); return ECMD_FAILED; error_cmdline: - lock_vol(vg_name, LCK_VG | LCK_NONE); + lock_vol(cmd, vg_name, LCK_VG | LCK_NONE); return EINVALID_CMD_LINE; } diff --git a/tools/pvchange.c b/tools/pvchange.c index 358d88a7..eb68fff5 100644 --- a/tools/pvchange.c +++ b/tools/pvchange.c @@ -98,32 +98,32 @@ int pvchange_single(struct cmd_context *cmd, struct physical_volume *pv) log_verbose("Finding volume group of physical volume \"%s\"", 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); return ECMD_FAILED; } 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\"", pv_name); return 0; } 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); return ECMD_FAILED; } 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); return ECMD_FAILED; } 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 ("Unable to find \"%s\" in volume group \"%s\"", 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", pv_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; } @@ -147,7 +147,7 @@ int pvchange_single(struct cmd_context *cmd, struct physical_volume *pv) log_error("Physical volume \"%s\" is already unallocatable", pv_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; } @@ -164,13 +164,13 @@ int pvchange_single(struct cmd_context *cmd, struct physical_volume *pv) log_verbose("Updating physical volume \"%s\"", pv_name); if (*pv->vg_name) { 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 " "volume group \"%s\"", pv_name, vg->name); return 0; } backup(vg); - lock_vol(pv->vg_name, LCK_VG | LCK_NONE); + lock_vol(cmd, pv->vg_name, LCK_VG | LCK_NONE); } else { if (!(cmd->fid->ops->pv_write(cmd->fid, pv))) { log_error("Failed to store physical volume \"%s\"", diff --git a/tools/toollib.c b/tools/toollib.c index 9b5402bf..9b99357e 100644 --- a/tools/toollib.c +++ b/tools/toollib.c @@ -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"); for (; opt < argc; 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); continue; } if ((ret = process_single(cmd, vg_name)) > ret_max) ret_max = ret; - lock_vol((void *) vg_name, LCK_VG | LCK_NONE); + lock_vol(cmd, (void *) vg_name, LCK_VG | LCK_NONE); } } else { 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) { 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); continue; } @@ -158,7 +158,7 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv, if (ret > ret_max) ret_max = ret; - lock_vol((void *) vg_name, LCK_VG | LCK_NONE); + lock_vol(cmd, (void *) vg_name, LCK_VG | LCK_NONE); } } diff --git a/tools/vgcreate.c b/tools/vgcreate.c index 5e2496fe..2124c168 100644 --- a/tools/vgcreate.c +++ b/tools/vgcreate.c @@ -92,32 +92,32 @@ int vgcreate(struct cmd_context *cmd, int argc, char **argv) log_error("Warning: Setting maxphysicalvolumes to %d", 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"); 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); - lock_vol("", LCK_VG | LCK_NONE); + lock_vol(cmd, "", LCK_VG | LCK_NONE); return ECMD_FAILED; } if (!archive(vg)) { - lock_vol(vg_name, LCK_VG | LCK_NONE); - lock_vol("", LCK_VG | LCK_NONE); + lock_vol(cmd, vg_name, LCK_VG | LCK_NONE); + lock_vol(cmd, "", LCK_VG | LCK_NONE); return ECMD_FAILED; } /* Store VG on disk(s) */ if (!cmd->fid->ops->vg_write(cmd->fid, vg)) { - lock_vol(vg_name, LCK_VG | LCK_NONE); - lock_vol("", LCK_VG | LCK_NONE); + lock_vol(cmd, vg_name, LCK_VG | LCK_NONE); + lock_vol(cmd, "", LCK_VG | LCK_NONE); return ECMD_FAILED; } - lock_vol(vg_name, LCK_VG | LCK_NONE); - lock_vol("", LCK_VG | LCK_NONE); + lock_vol(cmd, vg_name, LCK_VG | LCK_NONE); + lock_vol(cmd, "", LCK_VG | LCK_NONE); backup(vg); diff --git a/tools/vgextend.c b/tools/vgextend.c index bb4b4e27..0154a251 100644 --- a/tools/vgextend.c +++ b/tools/vgextend.c @@ -40,14 +40,14 @@ int vgextend(struct cmd_context *cmd, int argc, char **argv) argc--; 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"); return ECMD_FAILED; } log_verbose("Checking for volume group \"%s\"", vg_name); - if (!lock_vol(vg_name, LCK_VG | LCK_WRITE | LCK_NONBLOCK)) { - lock_vol("", LCK_VG | LCK_NONE); + if (!lock_vol(cmd, vg_name, LCK_VG | LCK_WRITE | LCK_NONBLOCK)) { + lock_vol(cmd, "", LCK_VG | LCK_NONE); log_error("Can't get lock for %s", vg_name); goto error; } @@ -96,15 +96,15 @@ int vgextend(struct cmd_context *cmd, int argc, char **argv) backup(vg); - lock_vol(vg_name, LCK_VG | LCK_NONE); - lock_vol("", LCK_VG | LCK_NONE); + lock_vol(cmd, vg_name, LCK_VG | LCK_NONE); + lock_vol(cmd, "", LCK_VG | LCK_NONE); log_print("Volume group \"%s\" successfully extended", vg_name); return 0; error: - lock_vol(vg_name, LCK_VG | LCK_NONE); - lock_vol("", LCK_VG | LCK_NONE); + lock_vol(cmd, vg_name, LCK_VG | LCK_NONE); + lock_vol(cmd, "", LCK_VG | LCK_NONE); return ECMD_FAILED; } diff --git a/tools/vgmerge.c b/tools/vgmerge.c index 8c487728..29a6dad5 100644 --- a/tools/vgmerge.c +++ b/tools/vgmerge.c @@ -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); - 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); return ECMD_FAILED; } if (!(vg_to = cmd->fid->ops->vg_read(cmd->fid, 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; } if (vg_to->status & EXPORTED_VG) { 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; } if (!(vg_to->status & LVM_WRITE)) { 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; } 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); - lock_vol(vg_name_to, LCK_VG | LCK_NONE); + lock_vol(cmd, vg_name_to, LCK_VG | LCK_NONE); return ECMD_FAILED; } @@ -190,15 +190,15 @@ int vgmerge_single(struct cmd_context *cmd, const char *vg_name_to, backup(vg_to); - lock_vol(vg_name_from, LCK_VG | LCK_NONE); - lock_vol(vg_name_to, LCK_VG | LCK_NONE); + lock_vol(cmd, vg_name_from, LCK_VG | LCK_NONE); + lock_vol(cmd, vg_name_to, LCK_VG | LCK_NONE); log_print("Volume group \"%s\" successfully merged into \"%s\"", vg_from->name, vg_to->name); return 0; error: - lock_vol(vg_name_from, LCK_VG | LCK_NONE); - lock_vol(vg_name_to, LCK_VG | LCK_NONE); + lock_vol(cmd, vg_name_from, LCK_VG | LCK_NONE); + lock_vol(cmd, vg_name_to, LCK_VG | LCK_NONE); return ECMD_FAILED; } diff --git a/tools/vgreduce.c b/tools/vgreduce.c index e64f4d4f..fd86f4e5 100644 --- a/tools/vgreduce.c +++ b/tools/vgreduce.c @@ -51,32 +51,32 @@ int vgreduce(struct cmd_context *cmd, int argc, char **argv) argc--; 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); return ECMD_FAILED; } if (!(vg = cmd->fid->ops->vg_read(cmd->fid, 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; } if (vg->status & EXPORTED_VG) { 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; } if (!(vg->status & LVM_WRITE)) { 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; } if (!(vg->status & RESIZEABLE_VG)) { 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; } @@ -84,7 +84,7 @@ int vgreduce(struct cmd_context *cmd, int argc, char **argv) /* and update in batch here? */ 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; diff --git a/tools/vgremove.c b/tools/vgremove.c index d7bd16fe..e999ca06 100644 --- a/tools/vgremove.c +++ b/tools/vgremove.c @@ -26,7 +26,7 @@ int vgremove(struct cmd_context *cmd, int argc, char **argv) { 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"); 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, &vgremove_single); - lock_vol("", LCK_VG | LCK_NONE); + lock_vol(cmd, "", LCK_VG | LCK_NONE); return ret; } diff --git a/tools/vgrename.c b/tools/vgrename.c index e702cfb5..e7e27afb 100644 --- a/tools/vgrename.c +++ b/tools/vgrename.c @@ -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); - 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); return ECMD_FAILED; } if (!(vg_old = cmd->fid->ops->vg_read(cmd->fid, 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; } 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); return ECMD_FAILED; } 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); return ECMD_FAILED; } @@ -98,7 +98,7 @@ int vgrename(struct cmd_context *cmd, int argc, char **argv) /***** FIXME Handle this with multiple LV renames! if (!force_ARG) { 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; } *****/ @@ -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); - if (!lock_vol(vg_name_new, LCK_VG | LCK_WRITE | LCK_NONBLOCK)) { - lock_vol(vg_name_old, LCK_VG | LCK_NONE); + if (!lock_vol(cmd, vg_name_new, LCK_VG | LCK_WRITE | LCK_NONBLOCK)) { + lock_vol(cmd, vg_name_old, LCK_VG | LCK_NONE); log_error("Can't get lock for %s", vg_name_new); return ECMD_FAILED; } @@ -158,8 +158,8 @@ int vgrename(struct cmd_context *cmd, int argc, char **argv) backup(vg_old); - lock_vol(vg_name_new, LCK_VG | LCK_NONE); - lock_vol(vg_name_old, LCK_VG | LCK_NONE); + lock_vol(cmd, vg_name_new, LCK_VG | LCK_NONE); + lock_vol(cmd, vg_name_old, LCK_VG | LCK_NONE); log_print("Volume group \"%s\" successfully renamed to \"%s\"", vg_name_old, vg_name_new); @@ -167,8 +167,8 @@ int vgrename(struct cmd_context *cmd, int argc, char **argv) return 0; error: - lock_vol(vg_name_new, LCK_VG | LCK_NONE); - lock_vol(vg_name_old, LCK_VG | LCK_NONE); + lock_vol(cmd, vg_name_new, LCK_VG | LCK_NONE); + lock_vol(cmd, vg_name_old, LCK_VG | LCK_NONE); return ECMD_FAILED; } |