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-10 16:05:27 +0100
commita91bc7a19b8f439fa1d21101ad5c11d72413d4c0 (patch)
tree767b8b9a28f15fe7d0cd7945a003342b05444c05
parentc3180c4a05ea947b379e9e9bc51e50d0ca329980 (diff)
downloadlvm2-a91bc7a19b8f439fa1d21101ad5c11d72413d4c0.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.c53
-rw-r--r--tools/toollib.h5
2 files changed, 58 insertions, 0 deletions
diff --git a/tools/toollib.c b/tools/toollib.c
index 13cb034fd..0ce3c5047 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1542,6 +1542,59 @@ 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;
+ }
+
+ /*
+ * For any reporting tool, the internal_report_for_select is reset to 0
+ * automatically because the internal reporting/selection is simply not
+ * needed - the reporting/selection is already a part of the code path
+ * used there.
+ *
+ * *The internal report for select is only needed for non-reporting tools!*
+ */
+ handle->internal_report_for_select = 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, int *selected)
{
diff --git a/tools/toollib.h b/tools/toollib.h
index ead36d3ec..405011759 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 *selected);
int select_match_lv(struct cmd_context *cmd, struct processing_handle *handle,