summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Caulfield <pcaulfie@redhat.com>2001-12-06 13:13:07 +0000
committerPatrick Caulfield <pcaulfie@redhat.com>2001-12-06 13:13:07 +0000
commitcbe47da378bac5d00e5e1459ab7a064febc97aa0 (patch)
tree4f82e19d3cfc69e3b0bedb245be59cfde04a567d
parentdd34a165a1e0e901e3e2b7f76ffa931af7fe2f01 (diff)
downloadlvm2-cbe47da378bac5d00e5e1459ab7a064febc97aa0.tar.gz
Add return code to vg_unlock so it knows whether or not to reload the metadata.
Add locking to lvrename.
-rw-r--r--tools/lvcreate.c16
-rw-r--r--tools/lvremove.c2
-rw-r--r--tools/lvrename.c23
-rw-r--r--tools/lvresize.c2
4 files changed, 26 insertions, 17 deletions
diff --git a/tools/lvcreate.c b/tools/lvcreate.c
index 3e9626448..db7ad7a85 100644
--- a/tools/lvcreate.c
+++ b/tools/lvcreate.c
@@ -249,13 +249,18 @@ int lvcreate(int argc, char **argv)
if (!lv_activate(lv))
goto finish;
+ ret = 0;
+ finish:
+ /* TODO: Actually - this will do the activate as well */
+ unlock_vg(vg, ret);
+
if (zero) {
struct device *dev;
char *name;
if (!(name = dbg_malloc(NAME_LEN))) {
log_error("Name allocation failed - device not zeroed");
- goto finish;
+ return ECMD_FAILED;
}
snprintf(name, NAME_LEN, "%s%s/%s", fid->cmd->dev_dir,
@@ -265,21 +270,16 @@ int lvcreate(int argc, char **argv)
if (!(dev = dev_cache_get(name, NULL))) {
log_error("%s not found: device not zeroed", name);
- goto finish;
+ return ECMD_FAILED;
}
if (!(dev_open(dev, O_WRONLY)))
- goto finish;
+ return ECMD_FAILED;
dev_zero(dev, 0, 4096);
dev_close(dev);
} else
log_print("WARNING: %s not zeroed", lv->name);
- ret = 0;
-
- finish:
- unlock_vg(vg);
-
/******** FIXME backup
if ((ret = do_autobackup(vg_name, vg)))
return ret;
diff --git a/tools/lvremove.c b/tools/lvremove.c
index c821363c3..8b7cadebb 100644
--- a/tools/lvremove.c
+++ b/tools/lvremove.c
@@ -110,6 +110,6 @@ static int lvremove_single(struct volume_group *vg, struct logical_volume *lv)
ret = 0;
finish:
- unlock_vg(vg);
+ unlock_vg(vg, ret);
return ret;
}
diff --git a/tools/lvrename.c b/tools/lvrename.c
index 336e9c32d..bd54ff74f 100644
--- a/tools/lvrename.c
+++ b/tools/lvrename.c
@@ -26,6 +26,7 @@ int lvrename(int argc, char **argv)
char *lv_name_old, *lv_name_new;
char *vg_name, *vg_name_new;
char *st;
+ int ret = ECMD_FAILED;
struct volume_group *vg;
struct logical_volume *lv;
@@ -89,35 +90,41 @@ int lvrename(int argc, char **argv)
return ECMD_FAILED;
}
+ /* Prevent other commands from interleaving */
+ if (lock_vg(vg, 0) != 0) {
+ log_error("error locking volume group");
+ return ECMD_FAILED;
+ }
+
if (!(vg->status & ACTIVE)) {
log_error("Volume group %s must be active before changing a "
"logical volume", vg_name);
- return ECMD_FAILED;
+ goto finish;
}
if ((lvh = find_lv_in_vg(vg, lv_name_new))) {
log_error("Logical volume %s already exists in "
"volume group %s", lv_name_new, vg_name);
- return ECMD_FAILED;
+ goto finish;
}
if (!(lvh = find_lv_in_vg(vg, lv_name_old))) {
log_error("Existing logical volume %s not found in "
"volume group %s", lv_name_old, vg_name);
- return ECMD_FAILED;
+ goto finish;
}
lv = &list_item(lvh, struct lv_list)->lv;
if (!(lv->name = pool_strdup(fid->cmd->mem, lv_name_new))) {
log_error("Failed to allocate space for new name");
- return ECMD_FAILED;
+ goto finish;
}
/* store it on disks */
log_verbose("Writing out updated volume group");
if (!(fid->ops->vg_write(fid, vg))) {
- return ECMD_FAILED;
+ goto finish;
}
/* FIXME Update symlink. lv_reactivate? */
@@ -126,6 +133,8 @@ int lvrename(int argc, char **argv)
log_print("Renamed %s to %s in volume group %s%s",
lv_name_old, lv_name_new, fid->cmd->dev_dir, vg_name);
-
- return 0;
+ ret = 0;
+ finish:
+ unlock_vg(vg, ret);
+ return ret;
}
diff --git a/tools/lvresize.c b/tools/lvresize.c
index 4f9751b11..d7bb1342e 100644
--- a/tools/lvresize.c
+++ b/tools/lvresize.c
@@ -288,6 +288,6 @@ int lvresize(int argc, char **argv)
ret = 0;
finish:
- unlock_vg(vg);
+ unlock_vg(vg, ret);
return ret;
}