diff options
| author | Kaleb S. KEITHLEY <kkeithle@redhat.com> | 2012-06-13 09:13:04 -0400 | 
|---|---|---|
| committer | Anand Avati <avati@redhat.com> | 2012-06-29 14:08:14 -0700 | 
| commit | 5672e77d3102a990a2aa11e7e56ebfe6a0eee369 (patch) | |
| tree | c92612a433383c70a9e4557ddaffbcdc348e0921 /xlators/performance | |
| parent | d87bd36040128c6553e8ee06a363eeb60d16e72c (diff) | |
localtime and ctime are not MT-SAFE
There are a number of nit-level issues throughout the source with
the use of localtime and ctime. While they apparently aren't causing
too many problems, apart from the one in bz 828058, they ought to be
fixed.  Among the "real" problems that are fixed in this patch:
 1) general localtime and ctime not MT-SAFE. There's a non-zero chance
    that another thread calling localtime (or ctime) will over-write
    the static data about to be used in another thread
 2) localtime(& <64-bit-type>) or ctime(& <64-bit-type>) generally
    not a problem on 64-bit or little-endian 32-bit. But even though
    we probably have zero users on big-ending 32-bit platforms, it's
    still incorrect.
 3) multiple nested calls passed as params. Last one wins, i.e. over-
    writes result of prior calls.
 4) Inconsistent error handling. Most of these calls are for logging,
    tracing, or dumping. I submit that if an error somehow occurs in
    the call to localtime or ctime, the log/trace/dump still should
    still occur.
 5) Appliances should all have their clocks set to UTC, and all log
    entries, traces, and dumps should use GMT.
 6) fix strtok(), change to strtok_r()
Other things this patch fixes/changes (that aren't bugs per se):
 1) Change "%Y-%m-%d %H:%M:%S" and similar to their equivalent shorthand,
    e.g. "%F %T"
 2) change sizeof(timestr) to sizeof timestr. sizeof is an operator,
    not a function. You don't use i +(32), why use sizeof(<var>).
    (And yes, you do use parens with sizeof(<type>).)
 3) change 'char timestr[256]' to 'char timestr[32]' where appropriate.
    Per-thread stack is limited. Time strings are never longer than ~20
    characters, so why waste 220+ bytes on the stack?
Things this patch doesn't fix:
 1) hodgepodge of %Y-%m-%d %H:%M:%S versus %Y/%m/%d-%H%M%S and other
    variations. It's not clear to me whether this ever matters, not to
    mention 3rd party log filtering tools may already rely on a
    particular format. Still it would be nice to have a single manifest
    constant and have every call to localtime/strftime consistently use
    the same format.
Change-Id: I827cad7bf53e57b69c0173f67abe72884249c1a9
BUG: 832173
Signed-off-by: Kaleb S. KEITHLEY <kkeithle@redhat.com>
Reviewed-on: http://review.gluster.com/3568
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
Diffstat (limited to 'xlators/performance')
| -rw-r--r-- | xlators/performance/io-cache/src/io-cache.c | 7 | ||||
| -rw-r--r-- | xlators/performance/quick-read/src/quick-read.c | 7 | 
2 files changed, 6 insertions, 8 deletions
diff --git a/xlators/performance/io-cache/src/io-cache.c b/xlators/performance/io-cache/src/io-cache.c index 4dbb1aa01a9..85e876531a5 100644 --- a/xlators/performance/io-cache/src/io-cache.c +++ b/xlators/performance/io-cache/src/io-cache.c @@ -1816,7 +1816,6 @@ __ioc_cache_dump (ioc_inode_t *ioc_inode, char *prefix)          ioc_table_t *table                    = NULL;          ioc_page_t  *page                     = NULL;          int          i                        = 0; -        struct tm   *tm                       = NULL;          char         key[GF_DUMP_MAX_BUF_LEN] = {0, };          char         timestr[256]             = {0, }; @@ -1827,9 +1826,9 @@ __ioc_cache_dump (ioc_inode_t *ioc_inode, char *prefix)          table = ioc_inode->table;          if (ioc_inode->cache.tv.tv_sec) { -                tm = localtime (&ioc_inode->cache.tv.tv_sec); -                strftime (timestr, 256, "%Y-%m-%d %H:%M:%S", tm); -                snprintf (timestr + strlen (timestr), 256 - strlen (timestr), +                gf_time_fmt (timestr, sizeof timestr, +                             ioc_inode->cache.tv.tv_sec, gf_timefmt_FT); +                snprintf (timestr + strlen (timestr), sizeof timestr - strlen (timestr),                            ".%"GF_PRI_SUSECONDS, ioc_inode->cache.tv.tv_usec);                  gf_proc_dump_write ("last-cache-validation-time", "%s", diff --git a/xlators/performance/quick-read/src/quick-read.c b/xlators/performance/quick-read/src/quick-read.c index 05130878470..6e4ce816ec7 100644 --- a/xlators/performance/quick-read/src/quick-read.c +++ b/xlators/performance/quick-read/src/quick-read.c @@ -3435,7 +3435,6 @@ qr_inodectx_dump (xlator_t *this, inode_t *inode)          int32_t     ret      = -1;          char        key_prefix[GF_DUMP_MAX_BUF_LEN] = {0, };          char        buf[256]                        = {0, }; -        struct tm  *tm                              = NULL;          ret = inode_ctx_get (inode, this, &value);          if (ret != 0) {                  goto out; @@ -3453,9 +3452,9 @@ qr_inodectx_dump (xlator_t *this, inode_t *inode)          gf_proc_dump_write ("entire-file-cached", "%s", qr_inode->xattr ? "yes" : "no");          if (qr_inode->tv.tv_sec) { -                tm = localtime (&qr_inode->tv.tv_sec); -                strftime (buf, 256, "%Y-%m-%d %H:%M:%S", tm); -                snprintf (buf + strlen (buf), 256 - strlen (buf), +                gf_time_fmt (buf, sizeof buf, qr_inode->tv.tv_sec, +                             gf_timefmt_FT); +                snprintf (buf + strlen (buf), sizeof buf - strlen (buf),                            ".%"GF_PRI_SUSECONDS, qr_inode->tv.tv_usec);                  gf_proc_dump_write ("last-cache-validation-time", "%s", buf);  | 
