diff --git a/tools/toollib.c b/tools/toollib.c index 127dd6696..529088c1a 100644 --- a/tools/toollib.c +++ b/tools/toollib.c @@ -1801,3 +1801,61 @@ int change_tag(struct cmd_context *cmd, struct volume_group *vg, return 1; } +int process_each_label(struct cmd_context *cmd, int argc, char **argv, void *handle, + process_single_label_fn_t process_single_label) +{ + struct label *label; + struct dev_iter *iter; + struct device *dev; + + int ret_max = ECMD_PROCESSED; + int ret = 0; + int opt = 0; + + if (argc) { + for (; opt < argc; opt++) { + if (!(dev = dev_cache_get(argv[opt], cmd->filter))) { + log_error("Failed to find device " + "\"%s\"", argv[opt]); + ret_max = ECMD_FAILED; + continue; + } + + if (!label_read(dev, &label, 0)) + continue; + + ret = process_single_label(cmd, label, handle); + + if (ret > ret_max) + ret_max = ret; + + if (sigint_caught()) + break; + } + + return ret_max; + } + + if (!(iter = dev_iter_create(cmd->filter, 1))) { + log_error("dev_iter creation failed"); + return ECMD_FAILED; + } + + while ((dev = dev_iter_get(iter))) + { + if (!label_read(dev, &label, 0)) + continue; + + ret = process_single_label(cmd, label, handle); + + if (ret > ret_max) + ret_max = ret; + + if (sigint_caught()) + break; + } + + dev_iter_destroy(iter); + + return ret_max; +} diff --git a/tools/toollib.h b/tools/toollib.h index aa6f699d2..d8091230c 100644 --- a/tools/toollib.h +++ b/tools/toollib.h @@ -38,6 +38,9 @@ typedef int (*process_single_pv_fn_t) (struct cmd_context *cmd, struct volume_group *vg, struct physical_volume *pv, void *handle); +typedef int (*process_single_label_fn_t) (struct cmd_context *cmd, + struct label *label, + void *handle); typedef int (*process_single_lv_fn_t) (struct cmd_context *cmd, struct logical_volume *lv, void *handle); @@ -58,6 +61,9 @@ int process_each_pv(struct cmd_context *cmd, int argc, char **argv, int scan_label_only, void *handle, process_single_pv_fn_t process_single_pv); +int process_each_label(struct cmd_context *cmd, int argc, char **argv, + void *handle, process_single_label_fn_t process_single_label); + int process_each_segment_in_pv(struct cmd_context *cmd, struct volume_group *vg, struct physical_volume *pv,