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>
cluster/dht: Remove dht dependency on glusterfsd-mgmt

glusterfs_ctx->notify can be used by any xlator to talk to
glusterfsd-mgmt.
Note- This is for any rpc communication initiated by the xlator,
      and not from glusterd.

Change-Id: Ic0e4af106fe1e98d797ca621facda8839b87598a
BUG: 835757
Signed-off-by: shishir gowda <sgowda@redhat.com>
Reviewed-on: http://review.gluster.com/3618
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Amar Tumballi <amarts@redhat.com>
Reviewed-by: Anand Avati <avati@redhat.com>
rpc: Fixed ping timer algo.

The purpose of the ping timer is to assert the absence of any evidence
the server is possibly alive.

The current implementation updates the 'last_sent' timer in the following
points in time,
- rpc_clnt_submit: when rpc messages are being queued at the transport
  layer. (wrong!, since we have no way to determine if server actually
  received the message)
- rpc_clnt_notify: when client receives pollout event on sending a message
  on the 'wire'. (correct, since it indicates ACK from server)

The fix removes the 'incorrect' update of 'last_sent'.

Change-Id: I56af7b15c3672673696977a7c50ee66eafa4ec55
Signed-off-by: Krishnan Parthasarathi <kp@gluster.com>
Reviewed-on: http://review.gluster.com/3625
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
glusterd, cli: handle uuid conflicts in probe gracefully

A commonly faced problem among glusterfs users is: after a fresh
installation of glusterfs in a virtual machine, the VM image is
cloned to make multiple instances of the server. This breaks
glusterd because right after glusterfs installation on the first
boot glusterd would have created the node UUID and this gets
inherited into the clone. The result is wierd behavior at the time
of peer probe where glusterd does not (yet) deal with UUID
collisions in a user friendly way.

With this patch the peer which got the probe request will compare
the uuid of the machine which send the probe request with its own
uuid and send the proper error to cli if the uuids are same.

Change-Id: I091741ec863431fb6480a09a3f4c68a0906a3339
BUG: 811493
Signed-off-by: Raghavendra Bhat <raghavendra@redhat.com>
Reviewed-on: http://review.gluster.com/3612
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Amar Tumballi <amarts@redhat.com>
Reviewed-by: Anand Avati <avati@redhat.com>
glusterd: Fix peer probe when username/password is missing

Prevent failure of building volumes dictionary during peer probe, when
username/password for a volume is missing. This situation can be caused by
migration of gluster from pre-3.3 to 3.3 and above.

Change-Id: Ib924ecd3d941ddaa5c7773e4d45b076c488b6421
BUG: 834229
Signed-off-by: Kaushal M <kaushal@redhat.com>
Reviewed-on: http://review.gluster.com/3619
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
posix: avoid unnecessary strncpy

When strlen(SRC) < LEN, using strncpy is misleading.
Use strcpy instead.

Change-Id: I76832353dc415de99f0583d085d5c2444d5fe8b0
BUG: 789278
Signed-off-by: Jim Meyering <meyering@redhat.com>
Reviewed-on: http://review.gluster.com/3587
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
bdb: fix erroneous strncpy in file name construction

Using strncpy like that fails to copy the trailing NUL byte of
dirent->d_name, which is required, since the result buffer,
entry_path is stat'ed in the code just below.  Besides, there is
no need for strncpy, since we know the source buffer will fit
in the possibly-just-realloc'd destination buffer: use memcpy
and +1 to include the trailing NUL.

Change-Id: I4d4cfb5b7df3c018516919f2d67c21c07de126cb
BUG: 789278
Signed-off-by: Jim Meyering <meyering@redhat.com>
Reviewed-on: http://review.gluster.com/3588
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
glusterd: avoid buffer overrun due to lack of NUL terminator

Assume that this use of strncpy is not spurious (i.e., that it does
sometimes truncate), and ensure that the result is NUL-terminated.
Otherwise, callers that treat ->filepath as a NUL-terminated
string could operate on a bogus file name and/or segfault.

Change-Id: I276bf8a4da330284cc0300e8da7113a48b9b9b37
BUG: 789278
Signed-off-by: Jim Meyering <meyering@redhat.com>
Reviewed-on: http://review.gluster.com/3590
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
features/worm: Allow worm option to be set throught volume set

'volume set <volname> worm on' adds the worm xlator on the bricks.

Read-only and worm cannot exist together, and a check is added.

Regular volumes can still be mounted with worm mount option.

If a volume is started before conversion to worm, the bricks need
to be restarted for the option to take force.

Updated feature.read-only option to features.read-only to keep it
consistent with other features based options.

Change-Id: I1a8fab363aaf66e6da615dcffa328332ae39fa04
BUG: 811612
Signed-off-by: shishir gowda <shishirng@gluster.com>
Reviewed-on: http://review.gluster.com/3545
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Amar Tumballi <amarts@redhat.com>
Reviewed-by: Anand Avati <avati@redhat.com>
glusterd-rpc-ops: avoid buffer overrun for over-long key

strncpy explicitly does not NUL-terminate when source string
has length >= the length specified via strncpy's 3rd argument.
Assuming strncpy is justified (i.e., that it may truncate),
be sure to NUL-terminate its destination buffer.

Change-Id: Ia67bf136cdfae6d9850f673923c01baa3cdef9d8
BUG: 789278
Signed-off-by: Jim Meyering <meyering@redhat.com>
Reviewed-on: http://review.gluster.com/3592
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
xlators/nfs: don't test/set dirpath[-1] for a zero-length name

Change-Id: Ic6ccfc964c9739f067ccf14a95fd0e09baf0dd51
BUG: 789278
Signed-off-by: Jim Meyering <meyering@redhat.com>
Reviewed-on: http://review.gluster.com/3593
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
geo-rep: handle input without trailing newline; don't reference buf[-1]

Do not truncate final byte of a line that does not end in a newline.
Do not clobber stack (resbuf[-1]) for input that starts with a NUL byte.
Likewise in glusterd_urltransform.

Change-Id: Ifdcad02d908c8dcbc1a0eee78d318dd4e7860322
BUG: 789278
Signed-off-by: Jim Meyering <meyering@redhat.com>
Reviewed-on: http://review.gluster.com/3595
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
pidinfo: don't let a corrupt /proc/PID/status cause buf[-1] access

Change-Id: I5d10eb92af753513eb5e5e3d7d2ad3ace57917d7
BUG: 789278
Signed-off-by: Jim Meyering <meyering@redhat.com>
Reviewed-on: http://review.gluster.com/3597
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
libgf_rrindex: don't return &str[-1] for an empty string input

libgf_trim_to_prev_dir: handle empty path (i.e., don't access path[-1])
libgf_alloc_fd_ctx: assert that vpath is not empty

Change-Id: I8f9d233680f78107187132889916cdcf4262af72
BUG: 789278
Signed-off-by: Jim Meyering <meyering@redhat.com>
Reviewed-on: http://review.gluster.com/3598
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
libgf_init_vmpentry: assert strlen(vmp) > 0 to guard against using vmp[-1]

Change-Id: I091e6066fd470e9e0b67a00464b5713b86d3783c
BUG: 789278
Signed-off-by: Jim Meyering <meyering@redhat.com>
Reviewed-on: http://review.gluster.com/3599
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
libgf_count_path_components: don't access pathdup[-1] for empty input

Change-Id: I432f8c8fac907f625d79b2c5bb626a1f7013a73e
BUG: 789278
Signed-off-by: Jim Meyering <meyering@redhat.com>
Reviewed-on: http://review.gluster.com/3600
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
libgf_client_chdir: don't access path[-1] upon chdir("")

Admittedly, this code may not be reachable via
glusterfs_chdir, assuming libgf_client_path_lookup
with such a loc.path would fail.

Change-Id: I0b72ade0918da30d49bff756dcf04d1512d0177f
BUG: 789278
Signed-off-by: Jim Meyering <meyering@redhat.com>
Reviewed-on: http://review.gluster.com/3601
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
valid_ipv4_address: don't access addr[-1] for 0-length input string

valid_ipv6_address: Likewise.

Change-Id: I6225873a5e323f81de5f25335aceeee571629e28
BUG: 789278
Signed-off-by: Jim Meyering <meyering@redhat.com>
Reviewed-on: http://review.gluster.com/3602
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
mgmt/glusterd: Added spaces in the logs

Change-Id: Ic44e339219a845946e18c8c926fe993e09f86624
BUG: 820555
Signed-off-by: Venkatesh Somyajulu <vsomyaju@redhat.com>
Reviewed-on: http://review.gluster.com/3609
Reviewed-by: Kaushal M <kaushal@redhat.com>
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
get_mnt_opts: don't let empty option string cause (*mpt_optsp)[-1] reference

This looks like a "can't happen" case (depending on what add_option does),
so you may prefer to add an assertion instead.

Change-Id: Ibfdd34fca045e5213de836cca252bd96408b2136
BUG: 789278
Signed-off-by: Jim Meyering <meyering@redhat.com>
Reviewed-on: http://review.gluster.com/3604
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>