From 21a98eda88fb5ce73fe8feb3a832533dd5e468ba Mon Sep 17 00:00:00 2001 From: Petr Rockai Date: Wed, 15 Jul 2009 05:50:22 +0000 Subject: Port process_each_pv to new vg_read. --- lib/metadata/metadata-exported.h | 1 + lib/metadata/metadata.c | 5 +++-- tools/pvdisplay.c | 2 +- tools/pvresize.c | 2 +- tools/reporter.c | 6 +++--- tools/toollib.c | 26 +++++--------------------- tools/vgreduce.c | 2 +- 7 files changed, 15 insertions(+), 29 deletions(-) diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h index 4a46152a..9d8d5425 100644 --- a/lib/metadata/metadata-exported.h +++ b/lib/metadata/metadata-exported.h @@ -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 diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c index c8166ad8..7f85d7ce 100644 --- a/lib/metadata/metadata.c +++ b/lib/metadata/metadata.c @@ -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); diff --git a/tools/pvdisplay.c b/tools/pvdisplay.c index c8c4a884..531f37a7 100644 --- a/tools/pvdisplay.c +++ b/tools/pvdisplay.c @@ -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); } diff --git a/tools/pvresize.c b/tools/pvresize.c index 964d6a54..eafbd56d 100644 --- a/tools/pvresize.c +++ b/tools/pvresize.c @@ -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) " diff --git a/tools/reporter.c b/tools/reporter.c index d1368d4c..e391ee20 100644 --- a/tools/reporter.c +++ b/tools/reporter.c @@ -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, diff --git a/tools/toollib.c b/tools/toollib.c index 0df5d664..75ce4c0f 100644 --- a/tools/toollib.c +++ b/tools/toollib.c @@ -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, diff --git a/tools/vgreduce.c b/tools/vgreduce.c index f22363ed..be48993d 100644 --- a/tools/vgreduce.c +++ b/tools/vgreduce.c @@ -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); } -- cgit