mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-02 01:18:26 +03:00
reporting: prepare id string only for json output
When processing LVs for a command we stored '*object_id' & '*group_id' as printable string that was however only used with json reporting. Refactor code so we simply store there 'struct id*' that is just converted into printable string when json reporting is really used. Also check for 'sigint()' right before loop processing begins which is primary purpose of this test.
This commit is contained in:
parent
48148e7e65
commit
78c1007aee
@ -862,13 +862,13 @@ void log_set_report_object_type(log_report_object_type_t object_type)
|
||||
_log_report.object_type = object_type;
|
||||
}
|
||||
|
||||
void log_set_report_object_group_and_group_id(const char *group, const char *id)
|
||||
void log_set_report_object_group_and_group_id(const char *group, const struct id *id)
|
||||
{
|
||||
_log_report.object_group = group;
|
||||
_log_report.object_group_id = id;
|
||||
}
|
||||
|
||||
void log_set_report_object_name_and_id(const char *name, const char *id)
|
||||
void log_set_report_object_name_and_id(const char *name, const struct id *id)
|
||||
{
|
||||
_log_report.object_name = name;
|
||||
_log_report.object_id = id;
|
||||
|
@ -106,9 +106,9 @@ typedef struct log_report {
|
||||
log_report_context_t context;
|
||||
log_report_object_type_t object_type;
|
||||
const char *object_name;
|
||||
const char *object_id;
|
||||
const struct id *object_id;
|
||||
const char *object_group;
|
||||
const char *object_group_id;
|
||||
const struct id *object_group_id;
|
||||
} log_report_t;
|
||||
|
||||
#define LOG_STATUS_NAME "status"
|
||||
@ -121,8 +121,8 @@ void log_restore_report_state(log_report_t log_report);
|
||||
void log_set_report(struct dm_report *report);
|
||||
void log_set_report_context(log_report_context_t context);
|
||||
void log_set_report_object_type(log_report_object_type_t object_type);
|
||||
void log_set_report_object_group_and_group_id(const char *group, const char *group_id);
|
||||
void log_set_report_object_name_and_id(const char *name, const char *id);
|
||||
void log_set_report_object_group_and_group_id(const char *group, const struct id *group_id);
|
||||
void log_set_report_object_name_and_id(const char *name, const struct id *id);
|
||||
|
||||
const char *log_get_report_context_name(log_report_context_t context);
|
||||
const char *log_get_report_object_type_name(log_report_object_type_t object_type);
|
||||
|
@ -4636,15 +4636,26 @@ int report_devtypes(void *handle)
|
||||
|
||||
int report_cmdlog(void *handle, const char *type, const char *context,
|
||||
const char *object_type_name, const char *object_name,
|
||||
const char *object_id, const char *object_group,
|
||||
const char *object_group_id, const char *msg,
|
||||
const struct id *object_id, const char *object_group,
|
||||
const struct id *object_group_id, const char *msg,
|
||||
int current_errno, int ret_code)
|
||||
{
|
||||
char object_uuid[64] __attribute__((aligned(8))) = { 0 };
|
||||
char object_group_uuid[64] __attribute__((aligned(8))) = { 0 };
|
||||
|
||||
struct cmd_log_item log_item = {_log_seqnum++, type, context, object_type_name,
|
||||
object_name ? : "", object_id ? : "",
|
||||
object_group ? : "", object_group_id ? : "",
|
||||
object_name ? : "", object_uuid,
|
||||
object_group ? : "", object_group_uuid,
|
||||
msg ? : "", current_errno, ret_code};
|
||||
|
||||
if (object_id &&
|
||||
!id_write_format(object_id, object_uuid, sizeof(object_uuid)))
|
||||
stack;
|
||||
|
||||
if (object_group_id &&
|
||||
!id_write_format(object_group_id, object_group_uuid, sizeof(object_group_uuid)))
|
||||
stack;
|
||||
|
||||
if (handle)
|
||||
return dm_report_object(handle, &log_item);
|
||||
|
||||
|
@ -117,8 +117,8 @@ int report_object(void *handle, int selection_only, const struct volume_group *v
|
||||
int report_devtypes(void *handle);
|
||||
int report_cmdlog(void *handle, const char *type, const char *context,
|
||||
const char *object_type_name, const char *object_name,
|
||||
const char *object_id, const char *object_group,
|
||||
const char *object_group_id, const char *msg,
|
||||
const struct id *object_id, const char *object_group,
|
||||
const struct id *object_group_id, const char *msg,
|
||||
int current_errno, int ret_code);
|
||||
void report_reset_cmdlog_seqnum(void);
|
||||
#define REPORT_OBJECT_CMDLOG_NAME "status"
|
||||
|
117
tools/toollib.c
117
tools/toollib.c
@ -2306,6 +2306,11 @@ 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()) {
|
||||
ret_max = ECMD_FAILED;
|
||||
goto_out;
|
||||
}
|
||||
|
||||
vg_name = vgnl->vg_name;
|
||||
vg_uuid = vgnl->vgid;
|
||||
skip = 0;
|
||||
@ -2315,16 +2320,11 @@ static int _process_vgnameid_list(struct cmd_context *cmd, uint32_t read_flags,
|
||||
uuid[0] = '\0';
|
||||
if (is_orphan_vg(vg_name)) {
|
||||
log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_ORPHAN);
|
||||
log_set_report_object_name_and_id(vg_name + sizeof(VG_ORPHANS), uuid);
|
||||
log_set_report_object_name_and_id(vg_name + sizeof(VG_ORPHANS), NULL);
|
||||
} else {
|
||||
if (vg_uuid && !id_write_format((const struct id*)vg_uuid, uuid, sizeof(uuid)))
|
||||
stack;
|
||||
log_set_report_object_name_and_id(vg_name, uuid);
|
||||
}
|
||||
|
||||
if (sigint_caught()) {
|
||||
ret_max = ECMD_FAILED;
|
||||
goto_out;
|
||||
log_set_report_object_name_and_id(vg_name, (const struct id*)vg_uuid);
|
||||
}
|
||||
|
||||
log_very_verbose("Processing VG %s %s", vg_name, uuid);
|
||||
@ -3382,8 +3382,6 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
|
||||
process_single_lv_fn_t process_single_lv)
|
||||
{
|
||||
log_report_t saved_log_report_state = log_get_report_state();
|
||||
char lv_uuid[64] __attribute__((aligned(8)));
|
||||
char vg_uuid[64] __attribute__((aligned(8)));
|
||||
int ret_max = ECMD_PROCESSED;
|
||||
int ret = 0;
|
||||
int whole_selected = 0;
|
||||
@ -3396,9 +3394,9 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
|
||||
int lv_arg_pos;
|
||||
struct lv_list *lvl;
|
||||
struct dm_str_list *sl;
|
||||
struct dm_list final_lvs;
|
||||
DM_LIST_INIT(final_lvs);
|
||||
struct lv_list *final_lvl;
|
||||
struct dm_list found_arg_lvnames;
|
||||
DM_LIST_INIT(found_arg_lvnames);
|
||||
struct glv_list *glvl, *tglvl;
|
||||
int do_report_ret_code = 1;
|
||||
|
||||
@ -3406,13 +3404,6 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
|
||||
|
||||
log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_LV);
|
||||
|
||||
vg_uuid[0] = '\0';
|
||||
if (!id_write_format(&vg->id, vg_uuid, sizeof(vg_uuid)))
|
||||
stack;
|
||||
|
||||
dm_list_init(&final_lvs);
|
||||
dm_list_init(&found_arg_lvnames);
|
||||
|
||||
if (tags_in && !dm_list_empty(tags_in))
|
||||
tags_supplied = 1;
|
||||
|
||||
@ -3436,20 +3427,16 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
|
||||
(tags_supplied && str_list_match_list(tags_in, &vg->tags, NULL)))
|
||||
process_all = 1;
|
||||
|
||||
log_set_report_object_group_and_group_id(vg->name, vg_uuid);
|
||||
log_set_report_object_group_and_group_id(vg->name, &vg->id);
|
||||
|
||||
dm_list_iterate_items(lvl, &vg->lvs) {
|
||||
lv_uuid[0] = '\0';
|
||||
if (!id_write_format(&lvl->lv->lvid.id[1], lv_uuid, sizeof(lv_uuid)))
|
||||
stack;
|
||||
|
||||
log_set_report_object_name_and_id(lvl->lv->name, lv_uuid);
|
||||
|
||||
if (sigint_caught()) {
|
||||
ret_max = ECMD_FAILED;
|
||||
goto_out;
|
||||
}
|
||||
|
||||
log_set_report_object_name_and_id(lvl->lv->name, &lvl->lv->lvid.id[1]);
|
||||
|
||||
if (lv_is_snapshot(lvl->lv))
|
||||
continue;
|
||||
|
||||
@ -3543,16 +3530,13 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
|
||||
label_scan_invalidate_lvs(cmd, &final_lvs);
|
||||
|
||||
dm_list_iterate_items(lvl, &final_lvs) {
|
||||
lv_uuid[0] = '\0';
|
||||
if (!id_write_format(&lvl->lv->lvid.id[1], lv_uuid, sizeof(lv_uuid)))
|
||||
stack;
|
||||
|
||||
log_set_report_object_name_and_id(lvl->lv->name, lv_uuid);
|
||||
|
||||
if (sigint_caught()) {
|
||||
ret_max = ECMD_FAILED;
|
||||
goto_out;
|
||||
}
|
||||
|
||||
log_set_report_object_name_and_id(lvl->lv->name, &lvl->lv->lvid.id[1]);
|
||||
|
||||
/*
|
||||
* FIXME: Once we have index over vg->removed_lvs, check directly
|
||||
* LV presence there and remove LV_REMOVE flag/lv_is_removed fn
|
||||
@ -3618,17 +3602,14 @@ 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) {
|
||||
lv_uuid[0] = '\0';
|
||||
if (!id_write_format(&glvl->glv->historical->lvid.id[1], lv_uuid, sizeof(lv_uuid)))
|
||||
stack;
|
||||
|
||||
log_set_report_object_name_and_id(glvl->glv->historical->name, lv_uuid);
|
||||
|
||||
if (sigint_caught()) {
|
||||
ret_max = ECMD_FAILED;
|
||||
goto_out;
|
||||
}
|
||||
|
||||
log_set_report_object_name_and_id(glvl->glv->historical->name,
|
||||
&glvl->glv->historical->lvid.id[1]);
|
||||
|
||||
if (glvl->glv->historical->fresh)
|
||||
continue;
|
||||
|
||||
@ -4007,6 +3988,11 @@ static int _process_lv_vgnameid_list(struct cmd_context *cmd, uint32_t read_flag
|
||||
log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_VG);
|
||||
|
||||
dm_list_iterate_items(vgnl, vgnameids_to_process) {
|
||||
if (sigint_caught()) {
|
||||
ret_max = ECMD_FAILED;
|
||||
goto_out;
|
||||
}
|
||||
|
||||
vg_name = vgnl->vg_name;
|
||||
vg_uuid = vgnl->vgid;
|
||||
skip = 0;
|
||||
@ -4017,12 +4003,7 @@ static int _process_lv_vgnameid_list(struct cmd_context *cmd, uint32_t read_flag
|
||||
if (vg_uuid && !id_write_format((const struct id*)vg_uuid, uuid, sizeof(uuid)))
|
||||
stack;
|
||||
|
||||
log_set_report_object_name_and_id(vg_name, uuid);
|
||||
|
||||
if (sigint_caught()) {
|
||||
ret_max = ECMD_FAILED;
|
||||
goto_out;
|
||||
}
|
||||
log_set_report_object_name_and_id(vg_name, (const struct id*)vg_uuid);
|
||||
|
||||
/*
|
||||
* arg_lvnames contains some elements that are just "vgname"
|
||||
@ -4500,7 +4481,6 @@ static int _process_pvs_in_vg(struct cmd_context *cmd,
|
||||
process_single_pv_fn_t process_single_pv)
|
||||
{
|
||||
log_report_t saved_log_report_state = log_get_report_state();
|
||||
char pv_uuid[64] __attribute__((aligned(8)));
|
||||
char vg_uuid[64] __attribute__((aligned(8)));
|
||||
int handle_supplied = handle != NULL;
|
||||
struct physical_volume *pv;
|
||||
@ -4530,22 +4510,19 @@ static int _process_pvs_in_vg(struct cmd_context *cmd,
|
||||
}
|
||||
|
||||
if (!is_orphan_vg(vg->name))
|
||||
log_set_report_object_group_and_group_id(vg->name, vg_uuid);
|
||||
log_set_report_object_group_and_group_id(vg->name, &vg->id);
|
||||
|
||||
dm_list_iterate_items(pvl, &vg->pvs) {
|
||||
pv = pvl->pv;
|
||||
pv_name = pv_dev_name(pv);
|
||||
pv_uuid[0]='\0';
|
||||
if (!id_write_format(&pv->id, pv_uuid, sizeof(pv_uuid)))
|
||||
stack;
|
||||
|
||||
log_set_report_object_name_and_id(pv_name, pv_uuid);
|
||||
|
||||
if (sigint_caught()) {
|
||||
ret_max = ECMD_FAILED;
|
||||
goto_out;
|
||||
}
|
||||
|
||||
pv = pvl->pv;
|
||||
pv_name = pv_dev_name(pv);
|
||||
|
||||
log_set_report_object_name_and_id(pv_name, &pv->id);
|
||||
|
||||
process_pv = process_all_pvs;
|
||||
dil = NULL;
|
||||
|
||||
@ -4640,7 +4617,6 @@ static int _process_pvs_in_vgs(struct cmd_context *cmd, uint32_t read_flags,
|
||||
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 volume_group *error_vg;
|
||||
struct vgnameid_list *vgnl;
|
||||
@ -4658,25 +4634,22 @@ static int _process_pvs_in_vgs(struct cmd_context *cmd, uint32_t read_flags,
|
||||
log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_VG);
|
||||
|
||||
dm_list_iterate_items(vgnl, all_vgnameids) {
|
||||
if (sigint_caught()) {
|
||||
ret_max = ECMD_FAILED;
|
||||
goto_out;
|
||||
}
|
||||
|
||||
vg_name = vgnl->vg_name;
|
||||
vg_uuid = vgnl->vgid;
|
||||
skip = 0;
|
||||
notfound = 0;
|
||||
is_lockd = lvmcache_vg_is_lockd_type(cmd, vg_name, vg_uuid);
|
||||
|
||||
uuid[0] = '\0';
|
||||
if (is_orphan_vg(vg_name)) {
|
||||
log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_ORPHAN);
|
||||
log_set_report_object_name_and_id(vg_name + sizeof(VG_ORPHANS), uuid);
|
||||
log_set_report_object_name_and_id(vg_name + sizeof(VG_ORPHANS), NULL);
|
||||
} else {
|
||||
if (vg_uuid && !id_write_format((const struct id*)vg_uuid, uuid, sizeof(uuid)))
|
||||
stack;
|
||||
log_set_report_object_name_and_id(vg_name, uuid);
|
||||
}
|
||||
|
||||
if (sigint_caught()) {
|
||||
ret_max = ECMD_FAILED;
|
||||
goto_out;
|
||||
log_set_report_object_name_and_id(vg_name, (const struct id*)vg_uuid);
|
||||
}
|
||||
do_lockd:
|
||||
if (is_lockd && !lockd_vg(cmd, vg_name, NULL, 0, &lockd_state)) {
|
||||
@ -4882,8 +4855,6 @@ int process_each_pv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
|
||||
process_single_pv_fn_t process_single_pv)
|
||||
{
|
||||
log_report_t saved_log_report_state = log_get_report_state();
|
||||
char pv_uuid[64] __attribute__((aligned(8)));
|
||||
char vg_uuid[64] __attribute__((aligned(8)));
|
||||
int whole_selected = 0;
|
||||
int ret_max = ECMD_PROCESSED;
|
||||
int ret;
|
||||
@ -4892,25 +4863,17 @@ int process_each_pv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
|
||||
|
||||
log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_PV);
|
||||
|
||||
vg_uuid[0] = '\0';
|
||||
if (!id_write_format(&vg->id, vg_uuid, sizeof(vg_uuid)))
|
||||
stack;
|
||||
|
||||
if (!is_orphan_vg(vg->name))
|
||||
log_set_report_object_group_and_group_id(vg->name, vg_uuid);
|
||||
log_set_report_object_group_and_group_id(vg->name, &vg->id);
|
||||
|
||||
dm_list_iterate_items(pvl, &vg->pvs) {
|
||||
pv_uuid[0] = '\0';
|
||||
if (!id_write_format(&pvl->pv->id, pv_uuid, sizeof(pv_uuid)))
|
||||
stack;
|
||||
|
||||
log_set_report_object_name_and_id(pv_dev_name(pvl->pv), pv_uuid);
|
||||
|
||||
if (sigint_caught()) {
|
||||
ret_max = ECMD_FAILED;
|
||||
goto_out;
|
||||
}
|
||||
|
||||
log_set_report_object_name_and_id(pv_dev_name(pvl->pv), &pvl->pv->id);
|
||||
|
||||
ret = process_single_pv(cmd, vg, pvl->pv, handle);
|
||||
_update_selection_result(handle, &whole_selected);
|
||||
if (ret != ECMD_PROCESSED)
|
||||
|
Loading…
Reference in New Issue
Block a user