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

Convert some vg_reads into vg_lock_and_reads

This commit is contained in:
Alasdair Kergon 2007-11-15 02:20:03 +00:00
parent 223c62e7b7
commit e5f7352bef
15 changed files with 47 additions and 108 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.29 - Version 2.02.29 -
================================== ==================================
Convert some vg_reads into vg_lock_and_reads.
Avoid nested vg_reads when processing PVs in VGs and fix associated locking. Avoid nested vg_reads when processing PVs in VGs and fix associated locking.
Accept sizes with --readahead argument. Accept sizes with --readahead argument.
Store size arguments as sectors internally. Store size arguments as sectors internally.

View File

@ -308,6 +308,7 @@ int pv_write(struct cmd_context *cmd, struct physical_volume *pv,
int is_orphan_vg(const char *vg_name); int is_orphan_vg(const char *vg_name);
int is_orphan(pv_t *pv); int is_orphan(pv_t *pv);
vg_t *vg_lock_and_read(struct cmd_context *cmd, const char *vg_name, vg_t *vg_lock_and_read(struct cmd_context *cmd, const char *vg_name,
const char *vgid,
uint32_t lock_flags, uint32_t status_flags, uint32_t lock_flags, uint32_t status_flags,
uint32_t misc_flags); uint32_t misc_flags);

View File

@ -1922,6 +1922,7 @@ int vg_check_status(const struct volume_group *vg, uint32_t status)
* non-NULL - success; volume group handle * non-NULL - success; volume group handle
*/ */
vg_t *vg_lock_and_read(struct cmd_context *cmd, const char *vg_name, vg_t *vg_lock_and_read(struct cmd_context *cmd, const char *vg_name,
const char *vgid,
uint32_t lock_flags, uint32_t status_flags, uint32_t lock_flags, uint32_t status_flags,
uint32_t misc_flags) uint32_t misc_flags)
{ {
@ -1942,7 +1943,7 @@ vg_t *vg_lock_and_read(struct cmd_context *cmd, const char *vg_name,
return NULL; return NULL;
} }
if (!(vg = vg_read(cmd, vg_name, NULL, &consistent)) || if (!(vg = vg_read(cmd, vg_name, vgid, &consistent)) ||
((misc_flags & FAIL_INCONSISTENT) && !consistent)) { ((misc_flags & FAIL_INCONSISTENT) && !consistent)) {
log_error("Volume group \"%s\" not found", vg_name); log_error("Volume group \"%s\" not found", vg_name);
unlock_vg(cmd, vg_name); unlock_vg(cmd, vg_name);
@ -1953,10 +1954,10 @@ vg_t *vg_lock_and_read(struct cmd_context *cmd, const char *vg_name,
unlock_vg(cmd, vg_name); unlock_vg(cmd, vg_name);
return NULL; return NULL;
} }
return vg; return vg;
} }
/* /*
* Gets/Sets for external LVM library * Gets/Sets for external LVM library
*/ */

View File

@ -608,7 +608,7 @@ int lvconvert(struct cmd_context * cmd, int argc, char **argv)
log_verbose("Checking for existing volume group \"%s\"", lp.vg_name); log_verbose("Checking for existing volume group \"%s\"", lp.vg_name);
if (!(vg = vg_lock_and_read(cmd, lp.vg_name, LCK_VG_WRITE, if (!(vg = vg_lock_and_read(cmd, lp.vg_name, NULL, LCK_VG_WRITE,
CLUSTERED | EXPORTED_VG | LVM_WRITE, CLUSTERED | EXPORTED_VG | LVM_WRITE,
CORRECT_INCONSISTENT))) CORRECT_INCONSISTENT)))
return ECMD_FAILED; return ECMD_FAILED;

View File

@ -508,16 +508,16 @@ static int _lvcreate_params(struct lvcreate_params *lp, struct cmd_context *cmd,
return 1; return 1;
} }
static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp) static int _lvcreate(struct cmd_context *cmd, struct volume_group *vg,
struct lvcreate_params *lp)
{ {
uint32_t size_rest; uint32_t size_rest;
uint32_t status = 0; uint32_t status = 0;
uint64_t tmp_size; uint64_t tmp_size;
struct volume_group *vg;
struct logical_volume *lv, *org = NULL, *log_lv = NULL; struct logical_volume *lv, *org = NULL, *log_lv = NULL;
struct list *pvh, tags; struct list *pvh, tags;
const char *tag = NULL; const char *tag = NULL;
int consistent = 1, origin_active = 0; int origin_active = 0;
struct alloc_handle *ah = NULL; struct alloc_handle *ah = NULL;
char lv_name_buf[128]; char lv_name_buf[128];
const char *lv_name; const char *lv_name;
@ -526,17 +526,6 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp)
status |= lp->permission | VISIBLE_LV; status |= lp->permission | VISIBLE_LV;
/* does VG exist? */
log_verbose("Finding volume group \"%s\"", lp->vg_name);
if (!(vg = vg_read(cmd, lp->vg_name, NULL, &consistent))) {
log_error("Volume group \"%s\" doesn't exist", lp->vg_name);
return 0;
}
if (!vg_check_status(vg, CLUSTERED | EXPORTED_VG | LVM_WRITE))
return 0;
if (lp->lv_name && find_lv_in_vg(vg, lp->lv_name)) { if (lp->lv_name && find_lv_in_vg(vg, lp->lv_name)) {
log_error("Logical volume \"%s\" already exists in " log_error("Logical volume \"%s\" already exists in "
"volume group \"%s\"", lp->lv_name, lp->vg_name); "volume group \"%s\"", lp->lv_name, lp->vg_name);
@ -926,27 +915,24 @@ revert_new_lv:
int lvcreate(struct cmd_context *cmd, int argc, char **argv) int lvcreate(struct cmd_context *cmd, int argc, char **argv)
{ {
int r = ECMD_FAILED; int r = ECMD_PROCESSED;
struct lvcreate_params lp; struct lvcreate_params lp;
struct volume_group *vg;
memset(&lp, 0, sizeof(lp)); memset(&lp, 0, sizeof(lp));
if (!_lvcreate_params(&lp, cmd, argc, argv)) if (!_lvcreate_params(&lp, cmd, argc, argv))
return EINVALID_CMD_LINE; return EINVALID_CMD_LINE;
if (!lock_vol(cmd, lp.vg_name, LCK_VG_WRITE)) { log_verbose("Finding volume group \"%s\"", lp.vg_name);
log_error("Can't get lock for %s", lp.vg_name); if (!(vg = vg_lock_and_read(cmd, lp.vg_name, NULL, LCK_VG_WRITE,
CLUSTERED | EXPORTED_VG | LVM_WRITE,
CORRECT_INCONSISTENT)))
return ECMD_FAILED; return ECMD_FAILED;
}
if (!_lvcreate(cmd, &lp)) { if (!_lvcreate(cmd, vg, &lp))
stack; r = ECMD_FAILED;
goto out;
}
r = ECMD_PROCESSED;
out:
unlock_vg(cmd, lp.vg_name); unlock_vg(cmd, lp.vg_name);
return r; return r;
} }

View File

@ -101,8 +101,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 (!(vg = vg_lock_and_read(cmd, vg_name, NULL, LCK_VG_WRITE,
if (!(vg = vg_lock_and_read(cmd, vg_name, LCK_VG_WRITE,
CLUSTERED | EXPORTED_VG | LVM_WRITE, CLUSTERED | EXPORTED_VG | LVM_WRITE,
CORRECT_INCONSISTENT))) CORRECT_INCONSISTENT)))
return ECMD_FAILED; return ECMD_FAILED;

View File

@ -254,9 +254,9 @@ static int _lvresize_params(struct cmd_context *cmd, int argc, char **argv,
return 1; return 1;
} }
static int _lvresize(struct cmd_context *cmd, struct lvresize_params *lp) static int _lvresize(struct cmd_context *cmd, struct volume_group *vg,
struct lvresize_params *lp)
{ {
struct volume_group *vg;
struct logical_volume *lv; struct logical_volume *lv;
struct lvinfo info; struct lvinfo info;
uint32_t stripesize_extents = 0; uint32_t stripesize_extents = 0;
@ -268,7 +268,6 @@ static int _lvresize(struct cmd_context *cmd, struct lvresize_params *lp)
alloc_policy_t alloc; alloc_policy_t alloc;
struct logical_volume *lock_lv; struct logical_volume *lock_lv;
struct lv_list *lvl; struct lv_list *lvl;
int consistent = 1;
struct lv_segment *seg; struct lv_segment *seg;
uint32_t seg_extents; uint32_t seg_extents;
uint32_t sz, str; uint32_t sz, str;
@ -276,14 +275,6 @@ static int _lvresize(struct cmd_context *cmd, struct lvresize_params *lp)
char size_buf[SIZE_BUF]; char size_buf[SIZE_BUF];
char lv_path[PATH_MAX]; char lv_path[PATH_MAX];
if (!(vg = vg_read(cmd, lp->vg_name, NULL, &consistent))) {
log_error("Volume group %s doesn't exist", lp->vg_name);
return ECMD_FAILED;
}
if (!vg_check_status(vg, CLUSTERED | EXPORTED_VG | LVM_WRITE))
return ECMD_FAILED;
/* does LV exist? */ /* does LV exist? */
if (!(lvl = find_lv_in_vg(vg, lp->lv_name))) { if (!(lvl = find_lv_in_vg(vg, lp->lv_name))) {
log_error("Logical volume %s not found in volume group %s", log_error("Logical volume %s not found in volume group %s",
@ -649,6 +640,7 @@ static int _lvresize(struct cmd_context *cmd, struct lvresize_params *lp)
int lvresize(struct cmd_context *cmd, int argc, char **argv) int lvresize(struct cmd_context *cmd, int argc, char **argv)
{ {
struct lvresize_params lp; struct lvresize_params lp;
struct volume_group *vg;
int r; int r;
memset(&lp, 0, sizeof(lp)); memset(&lp, 0, sizeof(lp));
@ -657,12 +649,14 @@ int lvresize(struct cmd_context *cmd, int argc, char **argv)
return EINVALID_CMD_LINE; return EINVALID_CMD_LINE;
log_verbose("Finding volume group %s", lp.vg_name); log_verbose("Finding volume group %s", lp.vg_name);
if (!lock_vol(cmd, lp.vg_name, LCK_VG_WRITE)) { if (!(vg = vg_lock_and_read(cmd, lp.vg_name, NULL, LCK_VG_WRITE,
log_error("Can't get lock for %s", lp.vg_name); CLUSTERED | EXPORTED_VG | LVM_WRITE,
CORRECT_INCONSISTENT))) {
log_error("Volume group %s doesn't exist", lp.vg_name);
return ECMD_FAILED; return ECMD_FAILED;
} }
if (!(r = _lvresize(cmd, &lp))) if (!(r = _lvresize(cmd, vg, &lp)))
stack; stack;
unlock_vg(cmd, lp.vg_name); unlock_vg(cmd, lp.vg_name);

View File

@ -32,7 +32,6 @@ static int _pvchange_single(struct cmd_context *cmd, struct physical_volume *pv,
const char *orig_vg_name; const char *orig_vg_name;
char uuid[64] __attribute((aligned(8))); char uuid[64] __attribute((aligned(8)));
int consistent = 1;
int allocatable = 0; int allocatable = 0;
int tagarg = 0; int tagarg = 0;
@ -54,27 +53,14 @@ static int _pvchange_single(struct cmd_context *cmd, struct physical_volume *pv,
/* If in a VG, must change using volume group. */ /* If in a VG, must change using volume group. */
/* FIXME: handle PVs with no MDAs */ /* FIXME: handle PVs with no MDAs */
if (!is_orphan(pv)) { if (!is_orphan(pv)) {
log_verbose("Finding volume group of physical volume \"%s\"",
pv_name);
vg_name = pv_vg_name(pv); vg_name = pv_vg_name(pv);
if (!lock_vol(cmd, vg_name, LCK_VG_WRITE)) {
log_error("Can't get lock for %s", vg_name);
return 0;
}
if (!(vg = vg_read(cmd, vg_name, NULL, &consistent))) { log_verbose("Finding volume group %s of physical volume %s",
unlock_vg(cmd, vg_name); vg_name, pv_name);
log_error("Unable to find volume group of \"%s\"", if (!(vg = vg_lock_and_read(cmd, vg_name, NULL, LCK_VG_WRITE,
pv_name); CLUSTERED | EXPORTED_VG | LVM_WRITE,
return 0; CORRECT_INCONSISTENT)))
} return_0;
if (!vg_check_status(vg,
CLUSTERED | EXPORTED_VG | LVM_WRITE)) {
unlock_vg(cmd, vg_name);
return 0;
}
if (!(pvl = find_pv_in_vg(vg, pv_name))) { if (!(pvl = find_pv_in_vg(vg, pv_name))) {
unlock_vg(cmd, vg_name); unlock_vg(cmd, vg_name);

View File

@ -20,7 +20,6 @@ static int _pvdisplay_single(struct cmd_context *cmd,
struct physical_volume *pv, void *handle) struct physical_volume *pv, void *handle)
{ {
struct pv_list *pvl; struct pv_list *pvl;
int consistent = 0;
int ret = ECMD_PROCESSED; int ret = ECMD_PROCESSED;
uint64_t size; uint64_t size;
@ -29,21 +28,12 @@ static int _pvdisplay_single(struct cmd_context *cmd,
if (!is_orphan(pv) && !vg) { if (!is_orphan(pv) && !vg) {
vg_name = pv_vg_name(pv); vg_name = pv_vg_name(pv);
if (!lock_vol(cmd, vg_name, LCK_VG_READ)) { if (!(vg = vg_lock_and_read(cmd, vg_name, (char *)&pv->vgid,
log_error("Can't lock %s: skipping", vg_name); LCK_VG_READ, CLUSTERED, 0))) {
log_error("Skipping volume group %s", vg_name);
return ECMD_FAILED; return ECMD_FAILED;
} }
if (!(vg = vg_read(cmd, vg_name, (char *)&pv->vgid, &consistent))) {
log_error("Can't read %s: skipping", vg_name);
goto out;
}
if (!vg_check_status(vg, CLUSTERED)) {
ret = ECMD_FAILED;
goto out;
}
/* /*
* Replace possibly incomplete PV structure with new one * Replace possibly incomplete PV structure with new one
* allocated in vg_read() path. * allocated in vg_read() path.

View File

@ -54,7 +54,7 @@ static struct volume_group *_get_vg(struct cmd_context *cmd, const char *vgname)
dev_close_all(); dev_close_all();
if (!(vg = vg_lock_and_read(cmd, vgname, LCK_VG_WRITE, if (!(vg = vg_lock_and_read(cmd, vgname, NULL, LCK_VG_WRITE,
CLUSTERED | EXPORTED_VG | LVM_WRITE, CLUSTERED | EXPORTED_VG | LVM_WRITE,
CORRECT_INCONSISTENT | FAIL_INCONSISTENT))) CORRECT_INCONSISTENT | FAIL_INCONSISTENT)))
return NULL; return NULL;

View File

@ -86,28 +86,18 @@ static int _pvs_single(struct cmd_context *cmd, struct volume_group *vg,
struct physical_volume *pv, void *handle) struct physical_volume *pv, void *handle)
{ {
struct pv_list *pvl; struct pv_list *pvl;
int consistent = 0;
int ret = ECMD_PROCESSED; int ret = ECMD_PROCESSED;
const char *vg_name = NULL; const char *vg_name = NULL;
if (!is_orphan(pv) && !vg) { if (!is_orphan(pv) && !vg) {
vg_name = pv_vg_name(pv); vg_name = pv_vg_name(pv);
if (!lock_vol(cmd, vg_name, LCK_VG_READ)) { if (!(vg = vg_lock_and_read(cmd, vg_name, (char *)&pv->vgid,
log_error("Can't lock %s: skipping", vg_name); LCK_VG_READ, CLUSTERED, 0))) {
log_error("Skipping volume group %s", vg_name);
return ECMD_FAILED; return ECMD_FAILED;
} }
if (!(vg = vg_read(cmd, vg_name, (char *)&pv->vgid, &consistent))) {
log_error("Can't read %s: skipping", vg_name);
goto out;
}
if (!vg_check_status(vg, CLUSTERED)) {
ret = ECMD_FAILED;
goto out;
}
/* /*
* Replace possibly incomplete PV structure with new one * Replace possibly incomplete PV structure with new one
* allocated in vg_read() path. * allocated in vg_read() path.

View File

@ -427,24 +427,15 @@ int process_each_segment_in_pv(struct cmd_context *cmd,
const char *vg_name = NULL; const char *vg_name = NULL;
int ret_max = 0; int ret_max = 0;
int ret; int ret;
int consistent = 0;
if (!vg) { if (!vg) {
vg_name = pv_vg_name(pv); vg_name = pv_vg_name(pv);
if (!lock_vol(cmd, vg_name, LCK_VG_READ)) {
log_error("Can't lock %s: skipping", vg_name); if (!(vg = vg_lock_and_read(cmd, vg_name, NULL, LCK_VG_READ,
CLUSTERED, 0))) {
log_error("Skipping volume group %s", vg_name);
return ECMD_FAILED; return ECMD_FAILED;
} }
if (!(vg = vg_read(cmd, vg_name, NULL, &consistent))) {
log_error("Can't read %s: skipping", vg_name);
goto out;
}
if (!vg_check_status(vg, CLUSTERED)) {
ret = ECMD_FAILED;
goto out;
}
} }
list_iterate_items(pvseg, &pv->segments) { list_iterate_items(pvseg, &pv->segments) {

View File

@ -41,7 +41,7 @@ int vgextend(struct cmd_context *cmd, int argc, char **argv)
} }
log_verbose("Checking for volume group \"%s\"", vg_name); log_verbose("Checking for volume group \"%s\"", vg_name);
if (!(vg = vg_lock_and_read(cmd, vg_name, LCK_VG_WRITE | LCK_NONBLOCK, if (!(vg = vg_lock_and_read(cmd, vg_name, NULL, LCK_VG_WRITE | LCK_NONBLOCK,
CLUSTERED | EXPORTED_VG | CLUSTERED | EXPORTED_VG |
LVM_WRITE | RESIZEABLE_VG, LVM_WRITE | RESIZEABLE_VG,
CORRECT_INCONSISTENT | FAIL_INCONSISTENT))) { CORRECT_INCONSISTENT | FAIL_INCONSISTENT))) {

View File

@ -29,13 +29,13 @@ static 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 (!(vg_to = vg_lock_and_read(cmd, vg_name_to, LCK_VG_WRITE, if (!(vg_to = vg_lock_and_read(cmd, vg_name_to, NULL, LCK_VG_WRITE,
CLUSTERED | EXPORTED_VG | LVM_WRITE, CLUSTERED | EXPORTED_VG | LVM_WRITE,
CORRECT_INCONSISTENT | FAIL_INCONSISTENT))) CORRECT_INCONSISTENT | FAIL_INCONSISTENT)))
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 (!(vg_from = vg_lock_and_read(cmd, vg_name_from, if (!(vg_from = vg_lock_and_read(cmd, vg_name_from, NULL,
LCK_VG_WRITE | LCK_NONBLOCK, LCK_VG_WRITE | LCK_NONBLOCK,
CLUSTERED | EXPORTED_VG | LVM_WRITE, CLUSTERED | EXPORTED_VG | LVM_WRITE,
CORRECT_INCONSISTENT | FAIL_INCONSISTENT))) { CORRECT_INCONSISTENT | FAIL_INCONSISTENT))) {

View File

@ -234,7 +234,7 @@ int vgsplit(struct cmd_context *cmd, int argc, char **argv)
} }
log_verbose("Checking for volume group \"%s\"", vg_name_from); log_verbose("Checking for volume group \"%s\"", vg_name_from);
if (!(vg_from = vg_lock_and_read(cmd, vg_name_from, LCK_VG_WRITE, if (!(vg_from = vg_lock_and_read(cmd, vg_name_from, NULL, LCK_VG_WRITE,
CLUSTERED | EXPORTED_VG | CLUSTERED | EXPORTED_VG |
RESIZEABLE_VG | LVM_WRITE, RESIZEABLE_VG | LVM_WRITE,
CORRECT_INCONSISTENT | FAIL_INCONSISTENT))) CORRECT_INCONSISTENT | FAIL_INCONSISTENT)))