mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
report: select: use _check_report_selection in dm_report_object to report only objects that satisfy the report selection
This is rebased and edited version of the original design and patch proposed by Jun'ichi Nomura: http://www.redhat.com/archives/dm-devel/2007-April/msg00025.html This activates the actual selection process in dm_report_object.
This commit is contained in:
parent
d33280a978
commit
bc6458de87
@ -953,19 +953,20 @@ static int _check_report_selection(struct dm_report *rh, struct dm_list *fields)
|
||||
int dm_report_object(struct dm_report *rh, void *object)
|
||||
{
|
||||
struct field_properties *fp;
|
||||
struct row *row;
|
||||
struct row *row = NULL;
|
||||
struct dm_report_field *field;
|
||||
void *data = NULL;
|
||||
int len;
|
||||
int r = 0;
|
||||
|
||||
if (!rh) {
|
||||
log_error(INTERNAL_ERROR "dm_report handler is NULL.");
|
||||
return 0;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!(row = dm_pool_zalloc(rh->mem, sizeof(*row)))) {
|
||||
log_error("dm_report_object: struct row allocation failed");
|
||||
return 0;
|
||||
goto out;
|
||||
}
|
||||
|
||||
row->rh = rh;
|
||||
@ -976,25 +977,25 @@ int dm_report_object(struct dm_report *rh, void *object)
|
||||
rh->keys_count))) {
|
||||
log_error("dm_report_object: "
|
||||
"row sort value structure allocation failed");
|
||||
return 0;
|
||||
goto out;
|
||||
}
|
||||
|
||||
dm_list_init(&row->fields);
|
||||
dm_list_add(&rh->rows, &row->list);
|
||||
|
||||
/* For each field to be displayed, call its report_fn */
|
||||
dm_list_iterate_items(fp, &rh->field_props) {
|
||||
if (!(field = dm_pool_zalloc(rh->mem, sizeof(*field)))) {
|
||||
log_error("dm_report_object: "
|
||||
"struct dm_report_field allocation failed");
|
||||
return 0;
|
||||
goto out;
|
||||
}
|
||||
field->props = fp;
|
||||
|
||||
if (!(data = _report_get_field_data(rh, fp, object))) {
|
||||
log_error("dm_report_object: no data for field %s",
|
||||
log_error("dm_report_object: "
|
||||
"no data assigned to field %s",
|
||||
rh->fields[fp->field_num].id);
|
||||
return 0;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!rh->fields[fp->field_num].report_fn(rh, rh->mem,
|
||||
@ -1003,24 +1004,38 @@ int dm_report_object(struct dm_report *rh, void *object)
|
||||
log_error("dm_report_object: "
|
||||
"report function failed for field %s",
|
||||
rh->fields[fp->field_num].id);
|
||||
return 0;
|
||||
goto out;
|
||||
}
|
||||
|
||||
dm_list_add(&row->fields, &field->list);
|
||||
}
|
||||
|
||||
if (!_check_report_selection(rh, &row->fields)) {
|
||||
r = 1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
dm_list_add(&rh->rows, &row->list);
|
||||
|
||||
dm_list_iterate_items(field, &row->fields) {
|
||||
len = (int) strlen(field->report_string);
|
||||
if (len > field->props->width)
|
||||
if ((len > field->props->width))
|
||||
field->props->width = len;
|
||||
|
||||
if ((rh->flags & RH_SORT_REQUIRED) &&
|
||||
(field->props->flags & FLD_SORT_KEY)) {
|
||||
(*row->sort_fields)[field->props->sort_posn] = field;
|
||||
}
|
||||
dm_list_add(&row->fields, &field->list);
|
||||
}
|
||||
|
||||
if (!(rh->flags & DM_REPORT_OUTPUT_BUFFERED))
|
||||
return dm_report_output(rh);
|
||||
|
||||
return 1;
|
||||
r = 1;
|
||||
out:
|
||||
if (!r)
|
||||
dm_pool_free(rh->mem, row);
|
||||
return r;
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user