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>
xdr_vector_round_up: don't let vcount <= 0 cause invalid array reference

Change-Id: I6a69f20fddb7271fe47f80acb97d2198e9998ccc
BUG: 789278
Signed-off-by: Jim Meyering <meyering@redhat.com>
Reviewed-on: http://review.gluster.com/3605
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
Mark /var/lib/glusterd as owned by glusterfs, subdirs belong to -server

Change-Id: Ib1df8da7e8abdcd3edece45bd39fe238f28838f1
BUG: 829734
Signed-off-by: Niels de Vos <ndevos@redhat.com>
Reviewed-on: http://review.gluster.com/3539
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
Reviewed-by: Anand Avati <avati@redhat.com>
cluster/afr: fix for read-subvolume option does not work

changed order of prevered read child in afr_select_read_child_from_policy
when a read child is set over config option read-subvolume it shoudl be first to return

Change-Id: I1c5a8171379bb2bad76f6653e9d68a9349d55142
BUG: 833750
Original-author: domwo <glusterfs@wollina.de>
Signed-off-by: domwo <glusterfs@wollina.de>
Signed-off-by: Jeff Darcy <jdarcy@redhat.com>
Reviewed-on: http://review.gluster.com/3614
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
cluster/afr: add a new option to select read-subvol by index

read subvolume is a nice option to set prefred read child if you have a
replication over 2 datacenter.  if you have 2 datacenter and have a
distributed replication where one set of servers are in datacenter one
and the other (the replicated) are in the other datacenter
read-subvolume it not very handy since it goes over name and the
subvolume name is different for each replication pair.  i added a new
option called read-subvolume-index which take the number of the
subvolume to choose.  0 fo first , 1 for second and so on subvolume in
every replication.  this option can now be used in the --xlator-option
mount option to choose the prefered read child for all replication at
once.  For Example on all clients in datacenter one you can use
--xlator-option=volumename-replication-*.read-subvolume-index=0 to
prefer read from the servers in datacenter one.  when you expand or
shrink the volume no changes are needed to the client config since the
wildcard will set this option automatic on reconfigure.

Change-Id: I3b47432f77037c380ff4a6296636c6f8fc953db9
BUG: 837420
Original-author: domwo <glusterfs@wollina.de>
Signed-off-by: domwo <glusterfs@wollina.de>
Signed-off-by: Jeff Darcy <jdarcy@redhat.com>
Reviewed-on: http://review.gluster.com/3615
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
cluster/afr: cleanup lk_owner and PID mess

Historically PID (frame->root->pid) was used by the locks translator
to identify a locker (and make decisions about which locks contend
or cooperate/merge). Since the introduction of lock_owner parameter
the usage of PID (for locks) was deprecated and is now unused. This
patch nukes the usage of PID in AFR

The usage of lk_owner has also ended up being a mess, because of the
differentiation required between ->lk() and ->inodelk(), (->lk() needs
to be identified by the process (roughly) and ->inodelk() needs to be
identified by the transaction) and also because of optimizations like
eager locking (locks are no more identified by the transaction as they
now get inherited by the next transaction).

The scheme (and technique) now is:

- All FOPs (the third phase of the transaction) happen with the lk_owner
  which is set by the topmost layer (FUSE, NFS etc.)

- All entrylks are issued with lk_owner set to the frame->root address.

- Inodelks which will not be subject to eager locking are issued with
  lk_owner set to frame->root.

- Inodelks which are subject to eager locking are issued with lk_owner
  set to the address of fd_t (which are the only type of frames which
  get subject to the eager locking optimization)

- At the start of the transaction, the transaction frame's lk_owner is
  set to the either frame->root or fd_t (and never unmodified) depending
  on the type of transaction.

- Just before the third phase (FOP phase) the set lk_owner is "saved"
  away and overwritten by the lk_owner submitted by the top layer (FUSE
  or NFS)

- Right after the third phase, the saved lk_owner is "restored" to resume
  the transaction into the POST-OP and eventually UNLOCK using the same
  lk_owner which was used during the LOCK phase.

Change-Id: I6ab8e4d6b65ae4185fa85ad3fded8e9188b2f929
BUG: 836033
Signed-off-by: Anand Avati <avati@redhat.com>
Reviewed-on: http://review.gluster.com/3620
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Pranith Kumar Karampuri <pranithk@gluster.com>