dev-prajnoha-report-select - report: add support for reserved value recognition in report selection string - add struct dm_report_reserved_value
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=6eb19550823de5a23ede17847ed7898be68e4942 Commit: 6eb19550823de5a23ede17847ed7898be68e4942 Parent: 82675bdffcba91900d5d6c1be3fe7c892b778b1e Author: Peter Rajnoha <[email protected]> AuthorDate: Fri May 30 15:02:21 2014 +0200 Committer: Peter Rajnoha <[email protected]> CommitterDate: Fri Jun 6 11:40:36 2014 +0200
report: add support for reserved value recognition in report selection string - add struct dm_report_reserved_value
Make dm_report_init_with_selection to accept an argument with an array of reserved values where each element contains a triple:
{dm report field type, reserved value, array of strings representing this value}
When the selection is parsed, we always check whether a string representation of some reserved value is not hit and if it is, we use the reserved value assigned for this string instead of trying to parse it as a value of certain field type.
This makes it possible to define selections like:
... --select lv_major=undefined (or -1 or unknown or undef or whatever string representations are registered for this reserved value in the future) ... --select lv_read_ahead=auto ... --select vg_mda_copies=unmanaged
With this, each time the field value of certain type is hit and when we compare it with the selection, we use the proper value for comparison.
For now, register these reserved values that are used at the moment (also more descriptive names are used for the values):
const uint64_t _reserved_number_undef_64 = UINT64_MAX; const uint64_t _reserved_number_unmanaged_64 = UINT64_MAX - 1; const uint64_t _reserved_size_auto_64 = UINT64_MAX;
{
{DM_REPORT_FIELD_TYPE_NUMBER, _reserved_number_undef_64, {"-1", "undefined", "undef", "unknown", NULL}}, {DM_REPORT_FIELD_TYPE_NUMBER, _reserved_number_unmanaged_64, {"unmanaged", NULL}}, {DM_REPORT_FIELD_TYPE_SIZE, _reserved_size_auto_64, {"auto", NULL}},
NULL
}
Same reserved value of different field types do not collide. All arrays are null-terminated.
--- lib/report/report.c | 69 ++++++++++++------- libdm/libdevmapper.h | 10 +++ libdm/libdm-report.c | 182 +++++++++++++++++++++++++++++++++++++++++++++----- tools/dmsetup.c | 2 +- 4 files changed, 220 insertions(+), 43 deletions(-)
lib/report/report.c +45 -24
@@ -37,10 +37,30 @@ struct lvm_report_object { };static const uint64_t _hundred64 =UINT64_C (100 ); -static const uint64_t _minusone64 =UINT64_C (-1 ); -static const int32_t _minusone32 =INT32_C (-1 );static const uint64_t _zero64 =UINT64_C (0 ); +static const uint64_t _reserved_number_undef_64 =UINT64_C (-1 ); +static const uint64_t _reserved_number_unamanaged_64 =UINT64_C (-2 ); +static const uint64_t _reserved_size_auto_64 =UINT64_C (-1 ); + +/* +* 32 bit signed is casted to 64 bit unsigned in dm_report_field internally! +* So when stored in the struct, the _reserved_number_undef_32 is actually +* equal to _reserved_number_undef_64. +*/ +static const int32_t _reserved_number_undef_32 =INT32_C (-1 ); + +static const char const *_reserved_number_undef_64_names[]={"-1" ,"undefined" ,"undef" ,"unknown" ,NULL }; +static const char const *_reserved_number_unamanaged_64_names[]={"unmanaged" ,NULL }; +static const char const *_reserved_size_auto_64_names[]={"auto" ,NULL }; + +static const struct dm_report_reserved_value _report_reserved_values[] = { + {DM_REPORT_FIELD_TYPE_NUMBER , &_reserved_number_undef_64, _reserved_number_undef_64_names}, + {DM_REPORT_FIELD_TYPE_NUMBER , &_reserved_number_unamanaged_64, _reserved_number_unamanaged_64_names}, + {DM_REPORT_FIELD_TYPE_SIZE , &_reserved_size_auto_64, _reserved_size_auto_64_names}, + {0 ,NULL ,NULL } +}; +static int _field_set_value (struct dm_report_field *field,const void *data,const void *sort) {dm_report_field_set_value (field, data, sort);
@@ -56,7 +76,7 @@ static int _field_set_percent(struct dm_report_field *field,uint64_t *sortval;if (percent ==PERCENT_INVALID ) -return _field_set_value (field,"" , &_minusone64); +return _field_set_value (field,"" , &_reserved_number_undef_64);if (!(repstr =dm_pool_alloc (mem,8 )) || !(sortval =dm_pool_alloc (mem,sizeof (uint64_t )))) {
@@ -203,7 +223,7 @@ static int _lvkmaj_disp(struct dm_report *rh, struct dm_pool *mem __attribute__(if ((major =lv_kernel_major (lv)) >=0 )return dm_report_field_int (rh, field, &major); -return dm_report_field_int32 (rh, field, &_minusone32); +return dm_report_field_int32 (rh, field, &_reserved_number_undef_32); } static int _lvkmin_disp(struct dm_report *rh, struct dm_pool *mem __attribute__((unused)),
@@ -216,7 +236,7 @@ static int _lvkmin_disp(struct dm_report *rh, struct dm_pool *mem __attribute__(if ((minor =lv_kernel_minor (lv)) >=0 )return dm_report_field_int (rh, field, &minor); -return dm_report_field_int32 (rh, field, &_minusone32); +return dm_report_field_int32 (rh, field, &_reserved_number_undef_32); } static int _lvstatus_disp(struct dm_report *rh __attribute__((unused)), struct dm_pool *mem,
@@ -502,7 +522,7 @@ static int _lvreadahead_disp(struct dm_report *rh, struct dm_pool *mem,const struct logical_volume *lv = (const struct logical_volume *) data;if (lv->read_ahead ==DM_READ_AHEAD_AUTO ) -return _field_set_value (field,"auto" , &_minusone64); +return _field_set_value (field,"auto" , &_reserved_size_auto_64);return _size32_disp (rh, mem, field, &lv->read_ahead, private); }
@@ -516,7 +536,7 @@ static int _lvkreadahead_disp(struct dm_report *rh, struct dm_pool *mem,uint32_t read_ahead =lv_kernel_read_ahead (lv);if (read_ahead ==UINT32_MAX ) -return dm_report_field_int32 (rh, field, &_minusone32); +return dm_report_field_int32 (rh, field, &_reserved_number_undef_32);return _size32_disp (rh, mem, field, &read_ahead, private); }
@@ -604,7 +624,7 @@ static int _thinzero_disp(struct dm_report *rh, struct dm_pool *mem,if (seg_is_thin_pool (seg))return _uint32_disp (rh, mem, field, &seg->zero_new_blocks, private); -return _field_set_value (field,"" , &_minusone64); +return _field_set_value (field,"" , &_reserved_number_undef_64); } static int _transactionid_disp(struct dm_report *rh, struct dm_pool *mem,
@@ -616,7 +636,7 @@ static int _transactionid_disp(struct dm_report *rh, struct dm_pool *mem,if (seg_is_thin_pool (seg))return dm_report_field_uint64 (rh, field, &seg->transaction_id); -return _field_set_value (field,"" , &_minusone64); +return _field_set_value (field,"" , &_reserved_number_undef_64); } static int _thinid_disp(struct dm_report *rh, struct dm_pool *mem,
@@ -628,7 +648,7 @@ static int _thinid_disp(struct dm_report *rh, struct dm_pool *mem,if (seg_is_thin_volume (seg))return dm_report_field_uint32 (rh, field, &seg->device_id); -return _field_set_value (field,"" , &_minusone64); +return _field_set_value (field,"" , &_reserved_number_undef_64); } static int _discards_disp(struct dm_report *rh, struct dm_pool *mem,
@@ -794,7 +814,7 @@ static int _vgmdacopies_disp(struct dm_report *rh, struct dm_pool *mem,uint32_t count =vg_mda_copies (vg);if (count ==VGMETADATACOPIES_UNMANAGED ) -return _field_set_value (field,"unmanaged" , &_minusone64); +return _field_set_value (field,"unmanaged" , &_reserved_number_unamanaged_64);return _uint32_disp (rh, mem, field, &count, private); }
@@ -903,7 +923,7 @@ static int _snpercent_disp(struct dm_report *rh __attribute__((unused)), struct*/ } -return _field_set_value (field,"" , &_minusone64); +return _field_set_value (field,"" , &_reserved_number_undef_64); } static int _copypercent_disp(struct dm_report *rh __attribute__((unused)),
@@ -923,7 +943,7 @@ static int _copypercent_disp(struct dm_report *rh __attribute__((unused)),return _field_set_percent (field, mem, percent); } -return _field_set_value (field,"" , &_minusone64); +return _field_set_value (field,"" , &_reserved_number_undef_64); } static int _raidsyncaction_disp(struct dm_report *rh __attribute__((unused)),
@@ -953,7 +973,7 @@ static int _raidmismatchcount_disp(struct dm_report *rh __attribute__((unused)),if (lv_is_raid (lv) &&lv_raid_mismatch_count (lv, &mismatch_count))return dm_report_field_uint64 (rh, field, &mismatch_count); -return _field_set_value (field,"" , &_minusone64); +return _field_set_value (field,"" , &_reserved_number_undef_64); } static int _raidwritebehind_disp(struct dm_report *rh __attribute__((unused)),
@@ -967,7 +987,7 @@ static int _raidwritebehind_disp(struct dm_report *rh __attribute__((unused)),if (lv_is_raid_type (lv) &&first_seg (lv)->writebehind)return dm_report_field_uint32 (rh, field, &first_seg (lv)->writebehind); -return _field_set_value (field,"" , &_minusone64); +return _field_set_value (field,"" , &_reserved_number_undef_64); } static int _raidminrecoveryrate_disp(struct dm_report *rh __attribute__((unused)),
@@ -982,7 +1002,7 @@ static int _raidminrecoveryrate_disp(struct dm_report *rh __attribute__((unused)return dm_report_field_uint32 (rh, field, &first_seg (lv)->min_recovery_rate); -return _field_set_value (field,"" , &_minusone64); +return _field_set_value (field,"" , &_reserved_number_undef_64); } static int _raidmaxrecoveryrate_disp(struct dm_report *rh __attribute__((unused)),
@@ -997,7 +1017,7 @@ static int _raidmaxrecoveryrate_disp(struct dm_report *rh __attribute__((unused)return dm_report_field_uint32 (rh, field, &first_seg (lv)->max_recovery_rate); -return _field_set_value (field,"" , &_minusone64); +return _field_set_value (field,"" , &_reserved_number_undef_64); }/* Called only with lv_is_thin_pool/volume */
@@ -1011,7 +1031,7 @@ static int _dtpercent_disp(int metadata, struct dm_pool *mem,/* Suppress data percent if not using driver */ /* cannot use lv_is_active_locally - need to check for layer -tpool */ if (!lv_info (lv->vg->cmd, lv,1 ,NULL ,0 ,0 )) -return _field_set_value (field,"" , &_minusone64); +return _field_set_value (field,"" , &_reserved_number_undef_64);if (lv_is_thin_pool (lv)) {if (!lv_thin_pool_percent (lv, metadata, &percent))
@@ -1036,7 +1056,7 @@ static int _datapercent_disp(struct dm_report *rh, struct dm_pool *mem,if (lv_is_thin_pool (lv) ||lv_is_thin_volume (lv))return _dtpercent_disp (0 , mem, field, data, private); -return _field_set_value (field,"" , &_minusone64); +return _field_set_value (field,"" , &_reserved_number_undef_64); } static int _metadatapercent_disp(struct dm_report *rh, struct dm_pool *mem,
@@ -1048,7 +1068,7 @@ static int _metadatapercent_disp(struct dm_report *rh, struct dm_pool *mem,if (lv_is_thin_pool (lv))return _dtpercent_disp (1 , mem, field, data, private); -return _field_set_value (field,"" , &_minusone64); +return _field_set_value (field,"" , &_reserved_number_undef_64); } static int _lvmetadatasize_disp(struct dm_report *rh, struct dm_pool *mem,
@@ -1063,7 +1083,7 @@ static int _lvmetadatasize_disp(struct dm_report *rh, struct dm_pool *mem,return _size64_disp (rh, mem, field, &size, private); } -return _field_set_value (field,"" , &_minusone64); +return _field_set_value (field,"" , &_reserved_number_undef_64); } static int _thincount_disp(struct dm_report *rh, struct dm_pool *mem,
@@ -1078,7 +1098,7 @@ static int _thincount_disp(struct dm_report *rh, struct dm_pool *mem,return _uint32_disp (rh, mem, field, &count, private); } -return _field_set_value (field,"" , &_minusone64); +return _field_set_value (field,"" , &_reserved_number_undef_64); } static int _lvtime_disp(struct dm_report *rh, struct dm_pool *mem,
@@ -1264,8 +1284,9 @@ void *report_init(struct cmd_context *cmd, const char *format, const char *keys, rh =dm_report_init_with_selection (report_type, devtypes_report ? _devtypes_report_types : _report_types, - devtypes_report ? _devtypes_fields : _fields, format, - separator, report_flags, keys, selection, cmd); + devtypes_report ? _devtypes_fields : _fields, + format, separator, report_flags, keys, + selection, _report_reserved_values, cmd);if (rh && field_prefixes)dm_report_set_output_field_name_prefix (rh,"lvm2_" );
libdm/libdevmapper.h +10 -0
@@ -1631,6 +1631,15 @@ struct dm_report_field_type {const char *desc;/* description of the field */ }; +struct dm_report_reserved_value { +const unsigned type;/* DM_REPORT_FIELD_TYPE_* */ +const void const *value;/* reserved value: +uint64_t for DM_REPORT_FIELD_TYPE_NUMBER +uint64_t for DM_REPORT_FIELD_TYPE_SIZE (number of 512-byte sectors) +const char * for DM_REPORT_FIELD_TYPE_STRING */ +const char **names;/* null-terminated array of names for this reserved value */ +}; +/* * dm_report_init output_flags */
@@ -1658,6 +1667,7 @@ struct dm_report *dm_report_init_with_selection(uint32_t *report_types,uint32_t output_flags, const char *sort_keys, const char *selection, + const struct dm_report_reserved_value reserved_values[], void *private_data);int dm_report_object (struct dm_report *rh,void *object); int dm_report_set_output_selection(struct dm_report *rh, uint32_t *report_types,
libdm/libdm-report.c +164 -18
276 lines not on this page · raw message
tools/dmsetup.c +1 -1
@@ -2934,7 +2934,7 @@ static int _report_init(const struct command *cmd)if (!(_report =dm_report_init_with_selection (&_report_type, _report_types, _report_fields, options, separator, flags, keys, - selection,NULL ))) + selection,NULL ,NULL ))) goto out;if ((_report_type &DR_TREE ) && !_build_whole_deptree (cmd)) {