1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-31 21:18:26 +03:00

Add locking to PV commands.

This commit is contained in:
Patrick Caulfield 2001-12-07 09:37:18 +00:00
parent 3335b34c44
commit cbe3e5991b
2 changed files with 26 additions and 5 deletions

View File

@ -27,6 +27,7 @@ int pvchange(int argc, char **argv)
int opt = 0;
int done = 0;
int total = 0;
int ret = ECMD_FAILED;
struct physical_volume *pv;
char *pv_name;
@ -48,6 +49,12 @@ int pvchange(int argc, char **argv)
return EINVALID_CMD_LINE;
}
/* Prevent other commands from interleaving */
if (lock_lvm(0) != 0) {
log_error("error locking lvm");
return ECMD_FAILED;
}
if (argc) {
log_verbose("Using physical volume(s) on command line");
for (; opt < argc; opt++) {
@ -63,7 +70,7 @@ int pvchange(int argc, char **argv)
} else {
log_verbose("Scanning for physical volume names");
if (!(pvs = fid->ops->get_pvs(fid))) {
return ECMD_FAILED;
goto finish;
}
list_iterate(pvh, pvs) {
@ -80,8 +87,11 @@ int pvchange(int argc, char **argv)
log_print("%d physical volume(s) changed / %d physical volume(s) "
"not changed", done, total - done);
ret = 0;
finish:
unlock_lvm(ret);
return 0;
return ret;
}
int pvchange_single(struct physical_volume *pv)
@ -96,7 +106,7 @@ int pvchange_single(struct physical_volume *pv)
/* If in a VG, must change using volume group. Pointless. */
/* FIXME: Provide a direct pv_write_pv that *only* touches PV structs*/
if (*pv->vg_name) {
log_verbose("Finding volume group of physical volume %s",
log_verbose("Finding volume group of physical volume %s",
pv_name);
if (!(vg = fid->ops->vg_read(fid, pv->vg_name))) {
log_error("Unable to find volume group of %s", pv_name);
@ -144,7 +154,7 @@ int pvchange_single(struct physical_volume *pv)
}
} else {
if (!(fid->ops->pv_write(fid, pv))) {
log_error("Failed to store physical volume %s",
log_error("Failed to store physical volume %s",
pv_name);
return 0;
}

View File

@ -106,6 +106,7 @@ static void pvcreate_single(const char *pv_name)
int pvcreate(int argc, char **argv)
{
int i;
int ret = ECMD_FAILED;
if (!argc) {
log_error("Please enter a physical volume path");
@ -117,10 +118,20 @@ int pvcreate(int argc, char **argv)
return EINVALID_CMD_LINE;
}
/* Prevent other commands from interleaving */
if (lock_lvm(0) != 0) {
log_error("error locking lvm");
return ECMD_FAILED;
}
for (i = 0; i < argc; i++) {
pvcreate_single(argv[i]);
pool_empty(fid->cmd->mem);
}
return 0;
ret = 0;
finish:
unlock_lvm(ret);
return ret;
}