Skip to contentSkip to conversation

master - report: add support for time (basic)

PATCH Peter Rajnoha 1 participant 1 message Jun 30, 2015

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=ded279f826f0eec41b17a79b6e186daf920b613c
Commit:        ded279f826f0eec41b17a79b6e186daf920b613c
Parent:        89d355ea04560dba54aa8b7b5a20950b9eb3f653
Author:        Peter Rajnoha <[email protected]>
AuthorDate:    Thu May 21 15:19:03 2015 +0200
Committer:     Peter Rajnoha <[email protected]>
CommitterDate: Tue Jun 30 15:15:10 2015 +0200

report: add support for time (basic)

This patch adds support for time values used in reporting fields. The raw values are always stored as number of seconds since epoch.

The support that comes with this patch is the basic one which allows only for recognition of strictly formatted date and time in selection criteria (the format follows a subset of formats defined by ISO 8601):

date time timezone

date:
YYYY-MM-DD (or shortly YYYYMMDD)
YYYY-MM (shortly YYYYMM), auto DD=1
YYYY, auto MM=01 and DD=01

time:
hh:mm:ss (or shortly hhmmss)
hh:mm (or shortly hhmm), auto ss=0
hh (or shortly hh), auto mm=0, auto ss=0

timezone (always with + or - sign):
+hh:mm or -hh:mm (or shortly +hhmm or -hhmm)
+hh or -hh

Or directly the time (number of seconds) since Epoch (1970-01-01 00:00:00 UTC) when the number value is prefixed by "@":

@number_of_seconds_since_epoch

This patch also adds aliases for comparison operators used together with time values which are more intuitive to use:
since (as alias for >=)
after (as alias for >)
until (as alias for <=)
before (as alias for <)

For example:

$ lvmconfig --type full report/time_format
time_format="%Y-%m-%d %T %z %Z [%s]"
$ lvs -o name,time vg
  LV    Time
  lvol0 2015-06-28 21:25:41 +0200 CEST [1435519541]
  lvol1 2015-06-30 03:25:43 +0200 CEST [1435627543]
  lvol2 2015-04-26 14:52:20 +0200 CEST [1430052740]
  lvol3 2015-06-30 14:52:23 +0200 CEST [1435668743]
$ lvs vg -o name,time -S 'time since "2015-04-26 15:00" && time until "2015-06-30"'
  LV    Time
  lvol0 2015-06-28 21:25:41 +0200 CEST [1435519541]
  lvol1 2015-06-30 03:25:43 +0200 CEST [1435627543]
  lvol3 2015-06-30 14:52:23 +0200 CEST [1435668743]
$ lvs vg -o name,time -S 'time since "2015-04-26 15:00" && time until "2015-06-30 6:00"'
  LV    Time
  lvol0 2015-06-28 21:25:41 +0200 CEST [1435519541]
  lvol1 2015-06-30 03:25:43 +0200 CEST [1435627543]
$ lvs vg -o name,time -S 'time since @1435519541'
  LV    Time
  lvol0 2015-06-28 21:25:41 +0200 CEST [1435519541]
  lvol1 2015-06-30 03:25:43 +0200 CEST [1435627543]
  lvol3 2015-06-30 14:52:23 +0200 CEST [1435668743]

This is basic time recognition support that is directly a part of libdevmapper. Recognition of more free-form expressions will be a part of subsequent patches.

---
 WHATS_NEW_DM                 |    2 +
 lib/properties/prop_common.h |    3 +-
 lib/report/columns.h         |    2 +-
 lib/report/report.c          |    1 +
 libdm/libdevmapper.h         |    1 +
 libdm/libdm-report.c         |  608 ++++++++++++++++++++++++++++++++++++++++--
 6 files changed, 591 insertions(+), 26 deletions(-)
WHATS_NEW_DM +2 -0
index 75e572a..bef2e0d 100644
@@ -1,5 +1,7 @@
 Version 1.02.100 - 
 ================================
+  Add since, after, until and before time operators to be used in selection.
+  Add support for time in reports and selection: DM_REPORT_FIELD_TYPE_TIME.
   Support report reserved value ranges: DM_REPORT_FIELD_RESERVED_VALUE_RANGE.
   Support report reserved value names: DM_REPORT_FIELD_RESERVED_VALUE_NAMED.
   Add DM_CONFIG_VALUE_FMT_{INT_OCTAL,STRING_NO_QUOTES} config value format flag.
lib/properties/prop_common.h +2 -1
index 9cc963a..19b8f70 100644
@@ -127,8 +127,9 @@ static int _ ## NAME ## _get (const void *obj, struct lvm_property_type *prop) \
 #define BIN 3
 #define SIZ 4
 #define PCT 5
-#define STR_LIST 6
+#define TIM 6
 #define SNUM 7              /* Signed Number */
+#define STR_LIST 8
 
 #define FIELD_MODIFIABLE 0x00000001
 #define FIELD(type, strct, field_type, head, field, width, fn, id, desc, settable) \
lib/report/columns.h +1 -1
index 06282c5..1576c28 100644
@@ -84,7 +84,7 @@ FIELD(LVS, lv, STR, "Meta", lvid, 4, metadatalv, metadata_lv, "For thin and cach
 FIELD(LVS, lv, STR, "Pool", lvid, 4, poollv, pool_lv, "For thin volumes, the thin pool LV for this volume.", 0)
 FIELD(LVS, lv, STR_LIST, "LV Tags", tags, 7, tags, lv_tags, "Tags, if any.", 0)
 FIELD(LVS, lv, STR, "LProfile", lvid, 8, lvprofile, lv_profile, "Configuration profile attached to this LV.", 0)
-FIELD(LVS, lv, STR, "Time", lvid, 26, lvtime, lv_time, "Creation time of the LV, if known", 0)
+FIELD(LVS, lv, TIM, "Time", lvid, 26, lvtime, lv_time, "Creation time of the LV, if known", 0)
 FIELD(LVS, lv, STR, "Host", lvid, 10, lvhost, lv_host, "Creation host of the LV, if known.", 0)
 FIELD(LVS, lv, STR_LIST, "Modules", lvid, 7, modules, lv_modules, "Kernel device-mapper modules required for this LV.", 0)
 
lib/report/report.c +1 -0
index 1c741e4..025b896 100644
@@ -2064,6 +2064,7 @@ static const struct dm_report_object_type _devtypes_report_types[] = {
 #define BIN DM_REPORT_FIELD_TYPE_NUMBER
 #define SIZ DM_REPORT_FIELD_TYPE_SIZE
 #define PCT DM_REPORT_FIELD_TYPE_PERCENT
+#define TIM DM_REPORT_FIELD_TYPE_TIME
 #define STR_LIST DM_REPORT_FIELD_TYPE_STRING_LIST
 #define SNUM DM_REPORT_FIELD_TYPE_NUMBER
 #define FIELD(type, strct, sorttype, head, field, width, func, id, desc, writeable) \
libdm/libdevmapper.h +1 -0
index 38f42aa..7e30d8e 100644
@@ -1682,6 +1682,7 @@ struct dm_report_field;
 #define DM_REPORT_FIELD_TYPE_SIZE			0x00000040
 #define DM_REPORT_FIELD_TYPE_PERCENT			0x00000080
 #define DM_REPORT_FIELD_TYPE_STRING_LIST		0x00000100
+#define DM_REPORT_FIELD_TYPE_TIME			0x00000200
 
 /* For use with reserved values only! */
 #define DM_REPORT_FIELD_RESERVED_VALUE_MASK		0x0000000F
libdm/libdm-report.c +584 -24

739 lines not on this page · raw message