[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[lvm-devel] [PATCH 11/20] toollib: Implement process_each_label.



---
 tools/toollib.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tools/toollib.h |  6 ++++++
 2 files changed, 65 insertions(+)

diff --git a/tools/toollib.c b/tools/toollib.c
index 24d8cbf..e6785fb 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1703,3 +1703,62 @@ 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;
+
+		log_error("processing %s", dev_name(dev));
+		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 cfcb934..f43e0f8 100644
--- a/tools/toollib.h
+++ b/tools/toollib.h
@@ -34,6 +34,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);
@@ -54,6 +57,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,
-- 
1.8.2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]