Skip to contentSkip to conversation

master - conf: make time format configurable

PATCH Peter Rajnoha 1 participant 1 message Jun 29, 2015

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=125cd06698bc1c52b812faa1686988b92cc2e192
Commit:        125cd06698bc1c52b812faa1686988b92cc2e192
Parent:        6f793d34ca8993d1e70df58340d7c1897b368a09
Author:        Peter Rajnoha <[email protected]>
AuthorDate:    Mon May 25 16:13:07 2015 +0200
Committer:     Peter Rajnoha <[email protected]>
CommitterDate: Mon Jun 29 14:30:35 2015 +0200

conf: make time format configurable

Make it possible to define format for time that is displayed. The way the format is defined is equal to the way that is used for strftime function, although not all formatting options as used in strftime are available for LVM2 - the set is restricted (e.g. we do not allow newline to be printed). The lvm.conf comments contain the whole list that LVM2 accepts for time format together with brief description (copied from strftime man page).

For example:
(defaults used - the format is the same as used before this patch)

$ lvs -o+time vg/lvol0 vg/lvol1
  LV    VG   Attr       LSize Time
  lvol0 vg   -wi-a----- 4.00m 2015-06-25 16:18:34 +0200
  lvol1 vg   -wi-a----- 4.00m 2015-06-29 09:17:11 +0200

(using 'time_format = "@%s"' in lvm.conf - number of seconds since the Epoch)

$ lvs -o+time vg/lvol0 vg/lvol1
  LV    VG   Attr       LSize Time
  lvol0 vg   -wi-a----- 4.00m @1435241914
  lvol1 vg   -wi-a----- 4.00m @1435562231
---
 WHATS_NEW                    |    1 +
 conf/example.conf.in         |   73 ++++++++++++++++++++++++++++++++++++++++++
 lib/commands/toolcontext.c   |   52 ++++++++++++++++++++++++++++++
 lib/commands/toolcontext.h   |    2 +
 lib/config/config_settings.h |   73 ++++++++++++++++++++++++++++++++++++++++++
 lib/config/defaults.h        |    1 +
 lib/display/display.c        |    2 +-
 lib/metadata/lv.c            |    7 ++--
 lib/metadata/lv.h            |    2 +-
 lib/report/properties.c      |    2 +-
 lib/report/report.c          |    2 +-
 11 files changed, 209 insertions(+), 8 deletions(-)
WHATS_NEW +1 -0
index 813eb5e..9a7ebe1 100644
@@ -1,5 +1,6 @@
 Version 2.02.123 - 
 =================================
+  Add report/time_format lvm.conf option to define time format for report.
   Fix makefile shell compare == when building lvmetad lvmpolld (2.02.120).
   Add --type full to lvmconfig for full configuration tree view.
   Add undocumented environment variables to lvm man page. (2.02.119)
conf/example.conf.in +73 -0

79 lines not on this page · raw message

lib/commands/toolcontext.c +52 -0

64 lines not on this page · raw message

lib/commands/toolcontext.h +2 -0
index 66bea5f..46d83b3 100644
@@ -95,6 +95,8 @@ struct cmd_context {
 	unsigned ignore_clustered_vgs:1;
 	unsigned threaded:1;		/* Set if running within a thread e.g. clvmd */
 
+	const char *time_format;
+
 	unsigned independent_metadata_areas:1;	/* Active formats have MDAs outside PVs */
 	unsigned unknown_system_id:1;
 	unsigned include_foreign_vgs:1;
lib/config/config_settings.h +73 -0

79 lines not on this page · raw message

lib/config/defaults.h +1 -0
index d764ec9..3745639 100644
@@ -197,6 +197,7 @@
 #define DEFAULT_REP_QUOTED 1
 #define DEFAULT_REP_SEPARATOR " "
 #define DEFAULT_REP_LIST_ITEM_SEPARATOR ","
+#define DEFAULT_TIME_FORMAT "%Y-%m-%d %T %z"
 
 #define DEFAULT_LVS_COLS "lv_name,vg_name,lv_attr,lv_size,pool_lv,origin,data_percent,metadata_percent,move_pv,mirror_log,copy_percent,convert_lv"
 #define DEFAULT_VGS_COLS "vg_name,pv_count,lv_count,snap_count,vg_attr,vg_size,vg_free"
lib/display/display.c +1 -1
index 8f075d9..059bc8f 100644
@@ -489,7 +489,7 @@ int lvdisplay_full(struct cmd_context *cmd,
 	log_print("LV UUID                %s", uuid);
 	log_print("LV Write Access        %s", access_str);
 	log_print("LV Creation host, time %s, %s",
-		  lv_host_dup(cmd->mem, lv), lv_time_dup(cmd->mem, lv));
+		  lv_host_dup(cmd->mem, lv), lv_time_dup(cmd->mem, lv, 1));
 
 	if (lv_is_origin(lv)) {
 		log_print("LV snapshot status     source of");
lib/metadata/lv.c +3 -4
index 9a99c8d..2a87edd 100644
@@ -873,17 +873,16 @@ int lv_set_creation(struct logical_volume *lv,
 	return 1;
 }
 
-char *lv_time_dup(struct dm_pool *mem, const struct logical_volume *lv)
+char *lv_time_dup(struct dm_pool *mem, const struct logical_volume *lv, int iso_mode)
 {
 	char buffer[50];
 	struct tm *local_tm;
 	time_t ts = (time_t)lv->timestamp;
+	const char *format = iso_mode ? DEFAULT_TIME_FORMAT : lv->vg->cmd->time_format;
 
 	if (!ts ||
 	    !(local_tm = localtime(&ts)) ||
-	    /* FIXME: make this lvm.conf configurable */
-	    !strftime(buffer, sizeof(buffer),
-		      "%Y-%m-%d %T %z", local_tm))
+	    !strftime(buffer, sizeof(buffer), format, local_tm))
 		buffer[0] = 0;
 
 	return dm_pool_strdup(mem, buffer);
lib/metadata/lv.h +1 -1
index 4475085..f7bbb1e 100644
@@ -91,7 +91,7 @@ char *lvseg_monitor_dup(struct dm_pool *mem, const struct lv_segment *seg);
 char *lvseg_tags_dup(const struct lv_segment *seg);
 char *lvseg_devices(struct dm_pool *mem, const struct lv_segment *seg);
 char *lvseg_seg_pe_ranges(struct dm_pool *mem, const struct lv_segment *seg);
-char *lv_time_dup(struct dm_pool *mem, const struct logical_volume *lv);
+char *lv_time_dup(struct dm_pool *mem, const struct logical_volume *lv, int iso_mode);
 char *lv_host_dup(struct dm_pool *mem, const struct logical_volume *lv);
 int lv_set_creation(struct logical_volume *lv,
 		    const char *hostname, uint64_t timestamp);
lib/report/properties.c +1 -1
index b0a91a7..5cd3c4d 100644
@@ -342,7 +342,7 @@ GET_LV_NUM_PROPERTY_FN(metadata_percent, _metadata_percent(lv))
 #define _metadata_percent_set prop_not_implemented_set
 GET_LV_NUM_PROPERTY_FN(lv_metadata_size, lv_metadata_size(lv) * SECTOR_SIZE)
 #define _lv_metadata_size_set prop_not_implemented_set
-GET_LV_STR_PROPERTY_FN(lv_time, lv_time_dup(lv->vg->vgmem, lv))
+GET_LV_STR_PROPERTY_FN(lv_time, lv_time_dup(lv->vg->vgmem, lv, 0))
 #define _lv_time_set prop_not_implemented_set
 GET_LV_STR_PROPERTY_FN(lv_host, lv_host_dup(lv->vg->vgmem, lv))
 #define _lv_host_set prop_not_implemented_set
lib/report/report.c +1 -1
index a107669..30b3767 100644
@@ -1474,7 +1474,7 @@ static int _lvtime_disp(struct dm_report *rh, struct dm_pool *mem,
 	char *repstr;
 	uint64_t *sortval;
 
-	if (!(repstr = lv_time_dup(mem, lv)) ||
+	if (!(repstr = lv_time_dup(mem, lv, 0)) ||
 	    !(sortval = dm_pool_alloc(mem, sizeof(uint64_t)))) {
 		log_error("Failed to allocate buffer for time.");
 		return 0;