mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
Add vg_lock_and_read() external library function.
This commit is contained in:
parent
8a0de6c333
commit
891c3d298b
@ -1,5 +1,6 @@
|
||||
Version 2.02.28 -
|
||||
================================
|
||||
Add vg_lock_and_read() external library function.
|
||||
Fix loading of persistent cache if cache_dir is used. (2.02.23)
|
||||
Eliminate uses of strdup+basename. Use last_path_component instead.
|
||||
Use gcc's printf attribute wherever possible.
|
||||
|
@ -292,6 +292,8 @@ struct list *get_vgids(struct cmd_context *cmd, int full_scan);
|
||||
int pv_write(struct cmd_context *cmd, struct physical_volume *pv,
|
||||
struct list *mdas, int64_t label_sector);
|
||||
int is_orphan(pv_t *pv);
|
||||
vg_t *vg_lock_and_read(struct cmd_context *cmd, const char *vg_name,
|
||||
uint32_t lock_flags, uint32_t status_flags);
|
||||
|
||||
/* pe_start and pe_end relate to any existing data so that new metadata
|
||||
* areas can avoid overlap */
|
||||
|
@ -1792,6 +1792,41 @@ int vg_check_status(struct volume_group *vg, uint32_t status)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* vg_lock_and_read - Attempt to lock a volume group, read, and check status
|
||||
* @cmd - command context
|
||||
* @vg_name - name of the volume group to lock and read
|
||||
* @lock_flags - locking flags to use
|
||||
* @status_flags - status flags to check
|
||||
*
|
||||
* Returns:
|
||||
* NULL - failure
|
||||
* non-NULL - success; volume group handle
|
||||
*/
|
||||
vg_t *vg_lock_and_read(struct cmd_context *cmd, const char *vg_name,
|
||||
uint32_t lock_flags, uint32_t status_flags)
|
||||
{
|
||||
struct volume_group *vg;
|
||||
int consistent = 1;
|
||||
|
||||
if (!lock_vol(cmd, vg_name, lock_flags)) {
|
||||
log_error("Can't get lock for %s", vg_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(vg = vg_read(cmd, vg_name, NULL, &consistent)) || !consistent) {
|
||||
log_error("Volume group \"%s\" not found", vg_name);
|
||||
unlock_vg(cmd, vg_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!vg_check_status(vg, status_flags)) {
|
||||
unlock_vg(cmd, vg_name);
|
||||
return NULL;
|
||||
}
|
||||
return vg;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Gets/Sets for external LVM library
|
||||
|
@ -50,26 +50,13 @@ static const char *_extract_lvname(struct cmd_context *cmd, const char *vgname,
|
||||
|
||||
static struct volume_group *_get_vg(struct cmd_context *cmd, const char *vgname)
|
||||
{
|
||||
int consistent = 1;
|
||||
struct volume_group *vg;
|
||||
|
||||
dev_close_all();
|
||||
|
||||
if (!lock_vol(cmd, vgname, LCK_VG_WRITE)) {
|
||||
log_error("Can't get lock for %s", vgname);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(vg = vg_read(cmd, vgname, NULL, &consistent)) || !consistent) {
|
||||
log_error("Volume group \"%s\" doesn't exist", vgname);
|
||||
unlock_vg(cmd, vgname);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!vg_check_status(vg, CLUSTERED | EXPORTED_VG | LVM_WRITE)) {
|
||||
unlock_vg(cmd, vgname);
|
||||
return NULL;
|
||||
}
|
||||
if (!(vg = vg_lock_and_read(cmd, vgname, LCK_VG_WRITE,
|
||||
CLUSTERED | EXPORTED_VG | LVM_WRITE)))
|
||||
return NULL;
|
||||
|
||||
return vg;
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ int vgextend(struct cmd_context *cmd, int argc, char **argv)
|
||||
{
|
||||
char *vg_name;
|
||||
struct volume_group *vg = NULL;
|
||||
int consistent = 1;
|
||||
|
||||
if (!argc) {
|
||||
log_error("Please enter volume group name and "
|
||||
@ -48,21 +47,12 @@ int vgextend(struct cmd_context *cmd, int argc, char **argv)
|
||||
}
|
||||
|
||||
log_verbose("Checking for volume group \"%s\"", vg_name);
|
||||
if (!lock_vol(cmd, vg_name, LCK_VG_WRITE | LCK_NONBLOCK)) {
|
||||
unlock_vg(cmd, ORPHAN);
|
||||
log_error("Can't get lock for %s", vg_name);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!(vg = vg_read(cmd, vg_name, NULL, &consistent)) || !consistent) {
|
||||
log_error("Volume group \"%s\" not found.", vg_name);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!vg_check_status(vg, CLUSTERED | EXPORTED_VG |
|
||||
LVM_WRITE | RESIZEABLE_VG))
|
||||
goto error;
|
||||
|
||||
if (!(vg = vg_lock_and_read(cmd, vg_name, LCK_VG_WRITE | LCK_NONBLOCK,
|
||||
CLUSTERED | EXPORTED_VG |
|
||||
LVM_WRITE | RESIZEABLE_VG))) {
|
||||
unlock_vg(cmd, ORPHAN);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
/********** FIXME
|
||||
log_print("maximum logical volume size is %s",
|
||||
(dummy = lvm_show_size(LVM_LV_SIZE_MAX(vg) / 2, LONG)));
|
||||
|
@ -22,7 +22,6 @@ static int _vgmerge_single(struct cmd_context *cmd, const char *vg_name_to,
|
||||
struct lv_list *lvl1, *lvl2;
|
||||
struct pv_list *pvl;
|
||||
int active;
|
||||
int consistent = 1;
|
||||
|
||||
if (!strcmp(vg_name_to, vg_name_from)) {
|
||||
log_error("Duplicate volume group name \"%s\"", vg_name_from);
|
||||
@ -30,38 +29,18 @@ static 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(cmd, vg_name_to, LCK_VG_WRITE)) {
|
||||
log_error("Can't get lock for %s", vg_name_to);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
if (!(vg_to = vg_read(cmd, vg_name_to, NULL, &consistent)) || !consistent) {
|
||||
log_error("Volume group \"%s\" doesn't exist", vg_name_to);
|
||||
unlock_vg(cmd, vg_name_to);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
if (!vg_check_status(vg_to, CLUSTERED | EXPORTED_VG | LVM_WRITE)) {
|
||||
unlock_vg(cmd, vg_name_to);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
if (!(vg_to = vg_lock_and_read(cmd, vg_name_to, LCK_VG_WRITE,
|
||||
CLUSTERED | EXPORTED_VG | LVM_WRITE)))
|
||||
return ECMD_FAILED;
|
||||
|
||||
log_verbose("Checking for volume group \"%s\"", vg_name_from);
|
||||
if (!lock_vol(cmd, vg_name_from, LCK_VG_WRITE | LCK_NONBLOCK)) {
|
||||
log_error("Can't get lock for %s", vg_name_from);
|
||||
if (!(vg_from = vg_lock_and_read(cmd, vg_name_from,
|
||||
LCK_VG_WRITE | LCK_NONBLOCK,
|
||||
CLUSTERED | EXPORTED_VG | LVM_WRITE))) {
|
||||
unlock_vg(cmd, vg_name_to);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
consistent = 1;
|
||||
if (!(vg_from = vg_read(cmd, vg_name_from, NULL, &consistent)) || !consistent) {
|
||||
log_error("Volume group \"%s\" doesn't exist", vg_name_from);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!vg_check_status(vg_from, CLUSTERED | EXPORTED_VG | LVM_WRITE))
|
||||
goto error;
|
||||
|
||||
if ((active = lvs_in_vg_activated(vg_from))) {
|
||||
log_error("Logical volumes in \"%s\" must be inactive",
|
||||
vg_name_from);
|
||||
|
@ -240,22 +240,10 @@ int vgsplit(struct cmd_context *cmd, int argc, char **argv)
|
||||
}
|
||||
|
||||
log_verbose("Checking for volume group \"%s\"", vg_name_from);
|
||||
if (!lock_vol(cmd, vg_name_from, LCK_VG_WRITE)) {
|
||||
log_error("Can't get lock for %s", vg_name_from);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
if (!(vg_from = vg_read(cmd, vg_name_from, NULL, &consistent)) || !consistent) {
|
||||
log_error("Volume group \"%s\" doesn't exist", vg_name_from);
|
||||
unlock_vg(cmd, vg_name_from);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
if (!vg_check_status(vg_from, CLUSTERED | EXPORTED_VG |
|
||||
RESIZEABLE_VG | LVM_WRITE)) {
|
||||
unlock_vg(cmd, vg_name_from);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
if (!(vg_to = vg_lock_and_read(cmd, vg_name_from, LCK_VG_WRITE,
|
||||
CLUSTERED | EXPORTED_VG |
|
||||
RESIZEABLE_VG | LVM_WRITE)))
|
||||
return ECMD_FAILED;
|
||||
|
||||
log_verbose("Checking for volume group \"%s\"", vg_name_to);
|
||||
if (!lock_vol(cmd, vg_name_to, LCK_VG_WRITE | LCK_NONBLOCK)) {
|
||||
|
Loading…
Reference in New Issue
Block a user