mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
Port process_each_pv to new vg_read.
This commit is contained in:
parent
6ee7d2aa53
commit
21a98eda88
@ -95,6 +95,7 @@
|
||||
/* vg_read and vg_read_for_update flags */
|
||||
#define READ_ALLOW_INCONSISTENT 0x00010000U
|
||||
#define READ_ALLOW_EXPORTED 0x00020000U
|
||||
#define READ_WITHOUT_LOCK 0x00040000U
|
||||
|
||||
/* A meta-flag, useful with toollib for_each_* functions. */
|
||||
#define READ_FOR_UPDATE 0x00100000U
|
||||
|
@ -2897,7 +2897,8 @@ static vg_t *_vg_lock_and_read(struct cmd_context *cmd, const char *vg_name,
|
||||
lock_name = is_orphan_vg(vg_name) ? VG_ORPHANS : vg_name;
|
||||
already_locked = vgname_is_locked(lock_name);
|
||||
|
||||
if (!already_locked && !lock_vol(cmd, lock_name, lock_flags)) {
|
||||
if (!already_locked && !(misc_flags & READ_WITHOUT_LOCK) &&
|
||||
!lock_vol(cmd, lock_name, lock_flags)) {
|
||||
log_error("Can't get lock for %s", vg_name);
|
||||
return _vg_make_handle(cmd, vg, FAILED_LOCKING);
|
||||
}
|
||||
@ -2953,7 +2954,7 @@ static vg_t *_vg_lock_and_read(struct cmd_context *cmd, const char *vg_name,
|
||||
return _vg_make_handle(cmd, vg, failure);
|
||||
|
||||
bad:
|
||||
if (!already_locked)
|
||||
if (!already_locked && !(misc_flags & READ_WITHOUT_LOCK))
|
||||
unlock_vg(cmd, lock_name);
|
||||
|
||||
return _vg_make_handle(cmd, vg, failure);
|
||||
|
@ -113,6 +113,6 @@ int pvdisplay(struct cmd_context *cmd, int argc, char **argv)
|
||||
return EINVALID_CMD_LINE;
|
||||
}
|
||||
|
||||
return process_each_pv(cmd, argc, argv, NULL, LCK_VG_READ, 0, NULL,
|
||||
return process_each_pv(cmd, argc, argv, NULL, 0, 0, NULL,
|
||||
_pvdisplay_single);
|
||||
}
|
||||
|
@ -205,7 +205,7 @@ int pvresize(struct cmd_context *cmd, int argc, char **argv)
|
||||
params.done = 0;
|
||||
params.total = 0;
|
||||
|
||||
ret = process_each_pv(cmd, argc, argv, NULL, LCK_VG_WRITE, 0, ¶ms,
|
||||
ret = process_each_pv(cmd, argc, argv, NULL, READ_FOR_UPDATE, 0, ¶ms,
|
||||
_pvresize_single);
|
||||
|
||||
log_print("%d physical volume(s) resized / %d physical volume(s) "
|
||||
|
@ -378,12 +378,12 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
|
||||
report_handle, &_vgs_single);
|
||||
break;
|
||||
case LABEL:
|
||||
r = process_each_pv(cmd, argc, argv, NULL, LCK_NONE,
|
||||
r = process_each_pv(cmd, argc, argv, NULL, READ_WITHOUT_LOCK,
|
||||
1, report_handle, &_label_single);
|
||||
break;
|
||||
case PVS:
|
||||
if (args_are_pvs)
|
||||
r = process_each_pv(cmd, argc, argv, NULL, LCK_VG_READ,
|
||||
r = process_each_pv(cmd, argc, argv, NULL, 0,
|
||||
0, report_handle, &_pvs_single);
|
||||
else
|
||||
r = process_each_vg(cmd, argc, argv, 0,
|
||||
@ -395,7 +395,7 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
|
||||
break;
|
||||
case PVSEGS:
|
||||
if (args_are_pvs)
|
||||
r = process_each_pv(cmd, argc, argv, NULL, LCK_VG_READ,
|
||||
r = process_each_pv(cmd, argc, argv, NULL, 0,
|
||||
0, report_handle, &_pvsegs_single);
|
||||
else
|
||||
r = process_each_vg(cmd, argc, argv, 0,
|
||||
|
@ -615,7 +615,7 @@ static int _process_all_devs(struct cmd_context *cmd, void *handle,
|
||||
* This can pause alongide pvscan or vgscan process for a while.
|
||||
*/
|
||||
int process_each_pv(struct cmd_context *cmd, int argc, char **argv,
|
||||
struct volume_group *vg, uint32_t lock_type,
|
||||
struct volume_group *vg, uint32_t flags,
|
||||
int scan_label_only, void *handle,
|
||||
int (*process_single) (struct cmd_context * cmd,
|
||||
struct volume_group * vg,
|
||||
@ -625,7 +625,7 @@ int process_each_pv(struct cmd_context *cmd, int argc, char **argv,
|
||||
int opt = 0;
|
||||
int ret_max = ECMD_PROCESSED;
|
||||
int ret = 0;
|
||||
int lock_global = lock_type == LCK_VG_READ;
|
||||
int lock_global = !(flags & READ_WITHOUT_LOCK) && !(flags & READ_FOR_UPDATE);
|
||||
|
||||
struct pv_list *pvl;
|
||||
struct physical_volume *pv;
|
||||
@ -633,12 +633,11 @@ int process_each_pv(struct cmd_context *cmd, int argc, char **argv,
|
||||
struct dm_list tags;
|
||||
struct str_list *sll;
|
||||
char *tagname;
|
||||
int consistent = 1;
|
||||
int scanned = 0;
|
||||
|
||||
dm_list_init(&tags);
|
||||
|
||||
if (lock_global && !lock_vol(cmd, VG_GLOBAL, lock_type)) {
|
||||
if (lock_global && !lock_vol(cmd, VG_GLOBAL, LCK_READ)) {
|
||||
log_error("Unable to obtain global lock.");
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
@ -719,26 +718,11 @@ int process_each_pv(struct cmd_context *cmd, int argc, char **argv,
|
||||
if (!dm_list_empty(&tags) && (vgnames = get_vgnames(cmd, 0)) &&
|
||||
!dm_list_empty(vgnames)) {
|
||||
dm_list_iterate_items(sll, vgnames) {
|
||||
if (!lock_vol(cmd, sll->str, lock_type)) {
|
||||
log_error("Can't lock %s: skipping", sll->str);
|
||||
vg = vg_read(cmd, sll->str, NULL, flags);
|
||||
if (vg_read_error(vg)) {
|
||||
ret_max = ECMD_FAILED;
|
||||
continue;
|
||||
}
|
||||
if (!(vg = vg_read_internal(cmd, sll->str, NULL, &consistent))) {
|
||||
log_error("Volume group \"%s\" not found", sll->str);
|
||||
unlock_vg(cmd, sll->str);
|
||||
ret_max = ECMD_FAILED;
|
||||
continue;
|
||||
}
|
||||
if (!consistent) {
|
||||
unlock_and_release_vg(cmd, vg, sll->str);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!vg_check_status(vg, CLUSTERED)) {
|
||||
unlock_and_release_vg(cmd, vg, sll->str);
|
||||
continue;
|
||||
}
|
||||
|
||||
ret = process_each_pv_in_vg(cmd, vg, &tags,
|
||||
handle,
|
||||
|
@ -573,7 +573,7 @@ int vgreduce(struct cmd_context *cmd, int argc, char **argv)
|
||||
|
||||
/* FIXME: Pass private struct through to all these functions */
|
||||
/* and update in batch here? */
|
||||
ret = process_each_pv(cmd, argc, argv, vg, LCK_NONE, 0, NULL,
|
||||
ret = process_each_pv(cmd, argc, argv, vg, READ_FOR_UPDATE, 0, NULL,
|
||||
_vgreduce_single);
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user