summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Rajnoha <prajnoha@redhat.com>2014-11-28 14:46:18 +0100
committerPeter Rajnoha <prajnoha@redhat.com>2015-02-09 14:20:27 +0100
commit864a6427eb2b27b13421d94a08b912b1a0297319 (patch)
treed62eb8d25f586c01a92d74c8fcd900c4f1f481be
parent6ca6aef63b4f5dd1745d29d4efea0211b2ac4203 (diff)
downloadlvm2-864a6427eb2b27b13421d94a08b912b1a0297319.tar.gz
toollib: add init_processing_handle, init_selection_handle and destroy_processing_handle helper functions
The init_processing_handle, init_selection_handle and destroy_processing_handle are helper functions that allocate and initialize the handles used when processing items in process_each_* and related functions.
-rw-r--r--tools/toollib.c44
-rw-r--r--tools/toollib.h5
2 files changed, 49 insertions, 0 deletions
diff --git a/tools/toollib.c b/tools/toollib.c
index 9704d82fe..d36b77221 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1542,6 +1542,50 @@ static int _get_vgnameids_on_system(struct cmd_context *cmd,
return ECMD_PROCESSED;
}
+struct processing_handle *init_processing_handle(struct cmd_context *cmd)
+{
+ struct processing_handle *handle;
+
+ if (!(handle = dm_pool_zalloc(cmd->mem, sizeof(struct processing_handle)))) {
+ log_error("_init_processing_handle: failed to allocate memory for processing handle");
+ return NULL;
+ }
+
+ handle->direct_reporting = !arg_is_set(cmd, select_ARG);
+
+ return handle;
+}
+
+int init_selection_handle(struct cmd_context *cmd, struct processing_handle *handle)
+{
+ struct selection_handle *sh;
+
+ if (!(sh = dm_pool_zalloc(cmd->mem, sizeof(struct selection_handle)))) {
+ log_error("_init_selection_handle: failed to allocate memory for selection handle");
+ return 0;
+ }
+
+ if (!(sh->selection_rh = report_init_for_selection(cmd, &sh->report_type,
+ arg_str_value(cmd, select_ARG, NULL)))) {
+ dm_pool_free(cmd->mem, sh);
+ return_0;
+ }
+
+ handle->selection_handle = sh;
+ return 1;
+}
+
+void destroy_processing_handle(struct cmd_context *cmd, struct processing_handle *handle,
+ int deallocate_handle_root)
+{
+ if (handle) {
+ if (handle->selection_handle && handle->selection_handle->selection_rh)
+ dm_report_free(handle->selection_handle->selection_rh);
+ if (deallocate_handle_root)
+ dm_pool_free(cmd->mem, handle);
+ }
+}
+
int select_match_vg(struct cmd_context *cmd,
struct processing_handle *handle,
struct volume_group *vg)
diff --git a/tools/toollib.h b/tools/toollib.h
index 01ff619a5..e2245b065 100644
--- a/tools/toollib.h
+++ b/tools/toollib.h
@@ -137,6 +137,11 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
int stop_on_error, struct processing_handle *handle,
process_single_lv_fn_t process_single_lv);
+struct processing_handle *init_processing_handle(struct cmd_context *cmd);
+int init_selection_handle(struct cmd_context *cmd, struct processing_handle *handle);
+void destroy_processing_handle(struct cmd_context *cmd, struct processing_handle *handle,
+ int deallocate_handle_root);
+
int select_match_vg(struct cmd_context *cmd, struct processing_handle *handle,
struct volume_group *vg);
int select_match_lv(struct cmd_context *cmd, struct processing_handle *handle,