diff options
author | Peter Rajnoha <prajnoha@redhat.com> | 2016-05-20 13:26:02 +0200 |
---|---|---|
committer | Peter Rajnoha <prajnoha@redhat.com> | 2016-06-02 14:38:14 +0200 |
commit | 2c35e3baf19f74f1bbde4a74089092c4434473dd (patch) | |
tree | 75516a0bca6726532f99ce4e9274d63afe38dce7 | |
parent | c6147a77f139c4c70fe65ab967cfba34469e80dd (diff) | |
download | lvm2-2c35e3baf19f74f1bbde4a74089092c4434473dd.tar.gz |
log: annotate processing code with log_set_report_{context,object_type,id_and_name}
-rw-r--r-- | tools/toollib.c | 121 |
1 files changed, 93 insertions, 28 deletions
diff --git a/tools/toollib.c b/tools/toollib.c index 4b463ff7b..174435414 100644 --- a/tools/toollib.c +++ b/tools/toollib.c @@ -1736,6 +1736,7 @@ struct processing_handle *init_processing_handle(struct cmd_context *cmd, struct } else handle->saved_log_report_state = log_get_report_state(); + log_set_report_context(LOG_REPORT_CONTEXT_PROCESSING); return handle; } @@ -1847,6 +1848,7 @@ static int _process_vgnameid_list(struct cmd_context *cmd, uint32_t read_flags, struct processing_handle *handle, process_single_vg_fn_t process_single_vg) { + log_report_t saved_log_report_state = log_get_report_state(); char uuid[64] __attribute__((aligned(8))); struct volume_group *vg; struct vgnameid_list *vgnl; @@ -1861,6 +1863,8 @@ static int _process_vgnameid_list(struct cmd_context *cmd, uint32_t read_flags, int process_all = 0; int already_locked; + log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_VG); + /* * If no VG names or tags were supplied, then process all VGs. */ @@ -1871,9 +1875,6 @@ static int _process_vgnameid_list(struct cmd_context *cmd, uint32_t read_flags, * FIXME If one_vgname, only proceed if exactly one VG matches tags or selection. */ dm_list_iterate_items(vgnl, vgnameids_to_process) { - if (sigint_caught()) - return_ECMD_FAILED; - vg_name = vgnl->vg_name; vg_uuid = vgnl->vgid; skip = 0; @@ -1882,7 +1883,14 @@ static int _process_vgnameid_list(struct cmd_context *cmd, uint32_t read_flags, if (vg_uuid && !id_write_format((const struct id*)vg_uuid, uuid, sizeof(uuid))) stack; - log_very_verbose("Processing VG %s %s", vg_name, vg_uuid ? uuid : ""); + log_set_report_object_id_and_name(uuid, vg_name); + + if (sigint_caught()) { + ret_max = ECMD_FAILED; + goto_out; + } + + log_very_verbose("Processing VG %s %s", vg_name, uuid); if (!lockd_vg(cmd, vg_name, NULL, 0, &lockd_state)) { ret_max = ECMD_FAILED; @@ -1924,8 +1932,11 @@ endvg: stack; } + log_set_report_object_id_and_name(NULL, NULL); /* the VG is selected if at least one LV is selected */ _set_final_selection_result(handle, whole_selected); +out: + log_restore_report_state(saved_log_report_state); return ret_max; } @@ -2099,6 +2110,7 @@ int process_each_vg(struct cmd_context *cmd, struct processing_handle *handle, process_single_vg_fn_t process_single_vg) { + log_report_t saved_log_report_state = log_get_report_state(); int handle_supplied = handle != NULL; struct dm_list arg_tags; /* str_list */ struct dm_list arg_vgnames; /* str_list */ @@ -2109,6 +2121,7 @@ int process_each_vg(struct cmd_context *cmd, int ret_max = ECMD_PROCESSED; int ret; + log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_VG); log_debug("Processing each VG"); /* Disable error in vg_read so we can print it from ignore_vg. */ @@ -2220,6 +2233,7 @@ out: if (!handle_supplied) destroy_processing_handle(cmd, handle); + log_restore_report_state(saved_log_report_state); return ret_max; } @@ -2271,6 +2285,7 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg, struct processing_handle *handle, process_single_lv_fn_t process_single_lv) { + log_report_t saved_log_report_state = log_get_report_state(); int ret_max = ECMD_PROCESSED; int ret = 0; int whole_selected = 0; @@ -2285,6 +2300,8 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg, struct lv_list *final_lvl; struct glv_list *glvl, *tglvl; + log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_LV); + dm_list_init(&final_lvs); if (!vg_check_status(vg, EXPORTED_VG)) { @@ -2316,6 +2333,8 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg, process_all = 1; dm_list_iterate_items(lvl, &vg->lvs) { + log_set_report_object_id_and_name(lvl->lv->lvid.s, lvl->lv->name); + if (sigint_caught()) { ret_max = ECMD_FAILED; goto_out; @@ -2399,6 +2418,8 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg, } dm_list_iterate_items(lvl, &final_lvs) { + log_set_report_object_id_and_name(lvl->lv->lvid.s, lvl->lv->name); + if (sigint_caught()) { ret_max = ECMD_FAILED; goto_out; @@ -2431,6 +2452,8 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg, _historical_lv.vg = vg; dm_list_iterate_items_safe(glvl, tglvl, &vg->historical_lvs) { + log_set_report_object_id_and_name(glvl->glv->historical->lvid.s, glvl->glv->historical->name); + process_lv = process_all; if (lvargs_supplied && @@ -2473,6 +2496,7 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg, * this leads to miscalculation that depends on the order of args. */ dm_list_iterate_items(sl, arg_lvnames) { + log_set_report_object_id_and_name(NULL, sl->str); log_error("Failed to find logical volume \"%s/%s\"", vg->name, sl->str); if (ret_max < ECMD_FAILED) @@ -2484,6 +2508,8 @@ out: destroy_processing_handle(cmd, handle); else _set_final_selection_result(handle, whole_selected); + + log_restore_report_state(saved_log_report_state); return ret_max; } @@ -2626,6 +2652,7 @@ static int _process_lv_vgnameid_list(struct cmd_context *cmd, uint32_t read_flag struct processing_handle *handle, process_single_lv_fn_t process_single_lv) { + log_report_t saved_log_report_state = log_get_report_state(); char uuid[64] __attribute__((aligned(8))); struct volume_group *vg; struct vgnameid_list *vgnl; @@ -2643,15 +2670,24 @@ static int _process_lv_vgnameid_list(struct cmd_context *cmd, uint32_t read_flag int notfound; int already_locked; - dm_list_iterate_items(vgnl, vgnameids_to_process) { - if (sigint_caught()) - return_ECMD_FAILED; + log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_VG); + dm_list_iterate_items(vgnl, vgnameids_to_process) { vg_name = vgnl->vg_name; vg_uuid = vgnl->vgid; skip = 0; notfound = 0; + if (vg_uuid && !id_write_format((const struct id*)vg_uuid, uuid, sizeof(uuid))) + stack; + + log_set_report_object_id_and_name(uuid, vg_name); + + if (sigint_caught()) { + ret_max = ECMD_FAILED; + goto_out; + } + /* * arg_lvnames contains some elements that are just "vgname" * which means process all lvs in the vg. Other elements @@ -2677,14 +2713,12 @@ static int _process_lv_vgnameid_list(struct cmd_context *cmd, uint32_t read_flag if (!str_list_add(cmd->mem, &lvnames, dm_pool_strdup(cmd->mem, lvn + 1))) { log_error("strlist allocation failed."); - return ECMD_FAILED; + ret_max = ECMD_FAILED; + goto out; } } } - if (vg_uuid && !id_write_format((const struct id*)vg_uuid, uuid, sizeof(uuid))) - stack; - log_very_verbose("Processing VG %s %s", vg_name, vg_uuid ? uuid : ""); if (!lockd_vg(cmd, vg_name, NULL, 0, &lockd_state)) { @@ -2717,7 +2751,8 @@ endvg: if (!lockd_vg(cmd, vg_name, "un", 0, &lockd_state)) stack; } - +out: + log_restore_report_state(saved_log_report_state); return ret_max; } @@ -2731,6 +2766,7 @@ int process_each_lv(struct cmd_context *cmd, struct processing_handle *handle, process_single_lv_fn_t process_single_lv) { + log_report_t saved_log_report_state = log_get_report_state(); int handle_supplied = handle != NULL; struct dm_list arg_tags; /* str_list */ struct dm_list arg_vgnames; /* str_list */ @@ -2742,6 +2778,8 @@ int process_each_lv(struct cmd_context *cmd, int ret_max = ECMD_PROCESSED; int ret; + log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_LV); + /* Disable error in vg_read so we can print it from ignore_vg. */ cmd->vg_read_print_access_error = 0; @@ -2849,6 +2887,7 @@ out: if (!handle_supplied) destroy_processing_handle(cmd, handle); + log_restore_report_state(saved_log_report_state); return ret_max; } @@ -3167,6 +3206,8 @@ static int _process_pvs_in_vg(struct cmd_context *cmd, struct processing_handle *handle, process_single_pv_fn_t process_single_pv) { + log_report_t saved_log_report_state = log_get_report_state(); + char uuid[64] __attribute__((aligned(8))); int handle_supplied = handle != NULL; struct physical_volume *pv; struct pv_list *pvl; @@ -3176,6 +3217,8 @@ static int _process_pvs_in_vg(struct cmd_context *cmd, int ret_max = ECMD_PROCESSED; int ret = 0; + log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_PV); + if (!handle && (!(handle = init_processing_handle(cmd, NULL)))) { ret_max = ECMD_FAILED; goto_out; @@ -3188,14 +3231,18 @@ static int _process_pvs_in_vg(struct cmd_context *cmd, } dm_list_iterate_items(pvl, &vg->pvs) { + pv = pvl->pv; + pv_name = pv_dev_name(pv); + if (!id_write_format(&pv->id, uuid, sizeof(uuid))) + stack; + + log_set_report_object_id_and_name(uuid, pv_name); + if (sigint_caught()) { ret_max = ECMD_FAILED; goto_out; } - pv = pvl->pv; - pv_name = pv_dev_name(pv); - process_pv = process_all_pvs; /* Remove each arg_devices entry as it is processed. */ @@ -3248,6 +3295,7 @@ static int _process_pvs_in_vg(struct cmd_context *cmd, out: if (!handle_supplied) destroy_processing_handle(cmd, handle); + log_restore_report_state(saved_log_report_state); return ret_max; } @@ -3272,6 +3320,8 @@ static int _process_pvs_in_vgs(struct cmd_context *cmd, uint32_t read_flags, struct processing_handle *handle, process_single_pv_fn_t process_single_pv) { + log_report_t saved_log_report_state = log_get_report_state(); + char uuid[64] __attribute__((aligned(8))); struct volume_group *vg; struct vgnameid_list *vgnl; const char *vg_name; @@ -3283,15 +3333,24 @@ static int _process_pvs_in_vgs(struct cmd_context *cmd, uint32_t read_flags, int notfound; int already_locked; - dm_list_iterate_items(vgnl, all_vgnameids) { - if (sigint_caught()) - return_ECMD_FAILED; + log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_VG); + dm_list_iterate_items(vgnl, all_vgnameids) { vg_name = vgnl->vg_name; vg_uuid = vgnl->vgid; skip = 0; notfound = 0; + if (vg_uuid && !id_write_format((const struct id*)vg_uuid, uuid, sizeof(uuid))) + stack; + + log_set_report_object_id_and_name(uuid, vg_name); + + if (sigint_caught()) { + ret_max = ECMD_FAILED; + goto_out; + } + if (!lockd_vg(cmd, vg_name, NULL, 0, &lockd_state)) { ret_max = ECMD_FAILED; continue; @@ -3334,9 +3393,10 @@ endvg: /* Quit early when possible. */ if (!process_all_pvs && dm_list_empty(arg_tags) && dm_list_empty(arg_devices)) - return ret_max; + goto_out; } - +out: + log_restore_report_state(saved_log_report_state); return ret_max; } @@ -3346,6 +3406,7 @@ int process_each_pv(struct cmd_context *cmd, struct processing_handle *handle, process_single_pv_fn_t process_single_pv) { + log_report_t saved_log_report_state = log_get_report_state(); struct dm_list arg_tags; /* str_list */ struct dm_list arg_pvnames; /* str_list */ struct dm_list arg_devices; /* device_id_list */ @@ -3359,6 +3420,7 @@ int process_each_pv(struct cmd_context *cmd, int ret_max = ECMD_PROCESSED; int ret; + log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_PV); log_debug("Processing each PV"); /* @@ -3393,8 +3455,8 @@ int process_each_pv(struct cmd_context *cmd, * names/paths into arg_devices which can be used to match below. */ if ((ret = _get_arg_pvnames(cmd, argc, argv, &arg_pvnames, &arg_tags)) != ECMD_PROCESSED) { - stack; - return ret; + ret_max = ret; + goto_out; } orphans_locked = lvmcache_vgname_is_locked(VG_ORPHANS); @@ -3404,8 +3466,10 @@ int process_each_pv(struct cmd_context *cmd, process_all_devices = process_all_pvs && (cmd->command->flags & ENABLE_ALL_DEVS) && all_is_set; /* Needed for a current listing of the global VG namespace. */ - if (!only_this_vgname && !lockd_gl(cmd, "sh", 0)) - return_ECMD_FAILED; + if (!only_this_vgname && !lockd_gl(cmd, "sh", 0)) { + ret_max = ECMD_FAILED; + goto_out; + } /* * This full scan would be done by _get_all_devices() if @@ -3421,8 +3485,8 @@ int process_each_pv(struct cmd_context *cmd, } if (!get_vgnameids(cmd, &all_vgnameids, only_this_vgname, 1)) { - stack; - return ret; + ret_max = ret; + goto_out; } /* @@ -3431,8 +3495,8 @@ int process_each_pv(struct cmd_context *cmd, * any devs remaining in all_devices are processed. */ if ((ret = _get_all_devices(cmd, &all_devices) != ECMD_PROCESSED)) { - stack; - return ret; + ret_max = ret; + goto_out; } if ((ret = _get_arg_devices(cmd, &arg_pvnames, &arg_devices)) != ECMD_PROCESSED) @@ -3558,6 +3622,7 @@ skip_missed: if (ret > ret_max) ret_max = ret; out: + log_restore_report_state(saved_log_report_state); return ret_max; } |