protocol/client: Avoid double free of frame

When client_submit_request fails it calls cbk. The cleanups should
happen only in cbk. The code committed as part of
http://review.gluster.org/4357 violates this. Also found that
clnt_release_reopen_fd violates this as well.
This patch fixes these issue.

Change-Id: Ic02ba278724b03c65c00b686c39fd7846122618a
BUG: 821056
Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
Reviewed-on: http://review.gluster.org/4464
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
rpcsvc: Fix memory corruption caused by rpcsvc_dump returning non-zero

The convention followed is that any actor should return non-zero
value only if it has not attempted to send the reply back. If an
actor returns non-zero, rpcsvc_handle_rpc_call tries to send an
error reply. Since, rpcsvc_submit_generic frees the rpc_req, its wrong
to invoke it more than once on same rpc_req. When the transport is not
connected, rpcsvc_dump used to pass the non-zero value it got from
 transport to rpcsvc resulting in memory corruption. Hence this patch
makes rpcsvc_dump to return 0.

Change-Id: I1b6f28969ee546c44d193d3d33debccb65585b69
BUG: 903113
Signed-off-by: Raghavendra G <raghavendra@gluster.com>
Reviewed-on: http://review.gluster.org/4183
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
Reviewed-by: Raghavendra Bhat <raghavendra@redhat.com>
Reviewed-by: Jeff Darcy <jdarcy@redhat.com>
fuse(efence): zero sized memory was being allocated.

For the last call of getdents(), gf_malloc called with 0 size, which is then
caught by efence.

BUG: 782760
Change-Id: If289029117a62ecfcecc70480e5ac8f0e050487d
Signed-off-by: Anand Avati <avati@redhat.com>
Original-author: Varun Shastry <vshastry@redhat.com>
Reviewed-on: http://review.gluster.org/3846
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Amar Tumballi <amarts@redhat.com>
cluster/afr: Perform wakeup just before fop

There is no necessity for the delayed-post-op to wait until
the next fop phase on the fd completes. Change-log,
locks are inherited by the time next fop phase is attempted
so the wakeup can happen just before the fop phase is started.

Change-Id: I0b8e591f591b0f7565eb55265ab51f476ed2b165
BUG: 908302
Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
Reviewed-on: http://review.gluster.org/4073
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Jeff Darcy <jdarcy@redhat.com>
Reviewed-by: Anand Avati <avati@redhat.com>
cluster/afr: Avoid priv->eager_lock value update race

Change-Id: I7049c0c64e36a9dfa4cc0e0b34de7ec111d2f6c1
BUG: 908302
Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
Reviewed-on: http://review.gluster.org/4076
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Jeff Darcy <jdarcy@redhat.com>
Reviewed-by: Anand Avati <avati@redhat.com>
libglusterfs: Maintain open-fd-count in inode.

Change-Id: I643d02959f92e40f68a53baf165753ed20f8b3e0
BUG: 908146
Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
Reviewed-on: http://review.gluster.org/4468
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
storage/posix: Fix open-fd-count virtual xattr

Send open-fd-count maintained in inode.

Change-Id: I23db5d052bdeb4f67978ff618ed5a0bed7d1592d
BUG: 908146
Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
Reviewed-on: http://review.gluster.org/4469
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
tests: Added function to generate brick statedump

Change-Id: I5f394a028a3251ec673c8787b2c67691a8b57449
BUG: 908146
Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
Reviewed-on: http://review.gluster.org/4470
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
tests: Test the open-fd count for a file on brick

Change-Id: I59bc4974eff93e92c4f7041d3722ac60e88b0734
BUG: 908146
Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
Reviewed-on: http://review.gluster.org/4471
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
glusterd,glusterfsd,libgfapi: Client op-version

This patch introduces op-version support for glusterfs clients.
Now, a client sends its supported op-versions during the volfile fetch request
and glusterd will return the volfile only if the client can support the current
op-version of the cluster.

Change-Id: Iab1f1f1706802962bcf27058657c44e8a344d2f6
BUG: 907311
Signed-off-by: Kaushal M <kaushal@redhat.com>
Reviewed-on: http://review.gluster.org/4247
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Amar Tumballi <amarts@redhat.com>
Reviewed-by: Anand Avati <avati@redhat.com>
glusterd: Use client-op-versions during "volume set"

The supported op-versions of the client and the name of the requested volume,
are saved during server_getspec(). These are used during the staging of volume
set. If the option being set is not supported by any of the clients which
currently have the volume mounted, then set will fail.

Change-Id: I4e6b60b274d5200508762dc0204cfa848a6c0aa4
BUG: 907311
Signed-off-by: Kaushal M <kaushal@redhat.com>
Reviewed-on: http://review.gluster.org/4424
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Amar Tumballi <amarts@redhat.com>
Reviewed-by: Anand Avati <avati@redhat.com>
libglusterfs/core: dump frame and callstack creation times in statedump

Change-Id: I3772602ac264cbca490d77a0343038297faee7df
BUG: 844688
Signed-off-by: Raghavendra Bhat <raghavendra@redhat.com>
Reviewed-on: http://review.gluster.org/4087
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
rpcsvc/dump: return correct return value

fix e8d09b9ab9 resulted in rpcsvc_dump returning large non-zero
values to caller in case of success. This patch fixes that issue
by returning 0

Change-Id: I594703dada74da17b33c98b073627a3378d170c5
BUG: 903113
Signed-off-by: Raghavendra G <raghavendra@gluster.com>
Reviewed-on: http://review.gluster.org/4477
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
open-behind: translator to perform open calls in background

This is functionality peeled out of quick-read into a separate
translator.

Fops which modify the file (where it is required to perform the
operation on the true fd) will trigger and wait for the backend
open to succeed and use that fd.

Fops like fstat() readv() etc. will use anonymous FD (configurable)
when original fd is unopened at the backend.

Change-Id: Id9847fdbfdc82c1c8e956339156b6572539c1876
BUG: 846240
Signed-off-by: Anand Avati <avati@redhat.com>
Reviewed-on: http://review.gluster.org/4406
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Raghavendra Bhat <raghavendra@redhat.com>
Reviewed-by: Jeff Darcy <jdarcy@redhat.com>
nfs/nlm: use req's uid and gid for open_and_resume

Previously, NLM was setting the frame->root->{uid,gid}
to root by default. This causes permission problems with
root squashing for lock calls. Now, we obtain the uid and
gid from rpc request. And duplicate #defines are removed
from rpcsvc.h

Change-Id: I5d6c87aed8d04aab2619bb913408048c0a02d1e7
BUG: 906884
Signed-off-by: Rajesh Amaravathi <rajesh@redhat.com>
Reviewed-on: http://review.gluster.org/4466
Reviewed-by: Niels de Vos <ndevos@redhat.com>
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
rpc: get hostnames of client to allow FQDN based authentication

If FQDNs are used to authenticate clients, then from
this commit forth, the client ip(v4,6) is reverse looked up
using getnameinfo to get a hostname associated with it,
if any, thereby making FQDN-based rpc authentication possible.

Change-Id: I4c5241e7079a2560de79ca15f611e65c0b858f9b
BUG: 903553
Signed-off-by: Rajesh Amaravathi <rajesh@redhat.com>
Reviewed-on: http://review.gluster.org/4439
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
glusterd: synctaskize 'volume create' operation

.. and also move brickpath validation to volume create stage

Change-Id: Ia028677932ca5f6aa05dcf624f47033b62e7b212
BUG: 862834
Signed-off-by: Krutika Dhananjay <kdhananj@redhat.com>
Reviewed-on: http://review.gluster.org/4213
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Amar Tumballi <amarts@redhat.com>
Reviewed-by: Anand Avati <avati@redhat.com>
dht: better layout-optimization algorithm

This method deals with the case where swapping might gain a bigger overlap
for the xlator currently under consideration, but sacrifices even more from
the xlator we're swapping with. For example:

A = 0x00000000 - 0x44444443 (new 0x00000000 - 0x55555554)
B = 0x44444444 - 0x77777776 (new 0x55555555 - 0xaaaaaaa9)
C = 0x77777777 - 0xffffffff (new 0xaaaaaaaa - 0xffffffff)

Here, the new range for B has a bigger overlap with the old C than with the
old B (0x33333333 vs. 0x22222222 to be precise) so looking only at that
might lead us to swap. However, such a swap turns the new C's overlap from
0x55555556 (vs. old C) to *zero* (vs. old B).  In other words, we've gained
0x11111111 for B but lost 0x55555556 for C, so it's a bad idea.

The new algorithm accounts for all effects of the swap, so it not only avoids
bad swaps but can make some good ones that would have been missed previously.
For example, if swapping a range X with a later range Y would not increase the
overlap for X we would previously have skipped it even if the swap would
increase Y's overlap without affecting X's.  This is the normal case when we're
adding a new brick (which initially has zero overlap with any old range) so
finding more good swaps is probably even more important than avoiding bad ones.

Also, the logic in dht_overlap_calc was completely broken before, causing
integer overflows instead of providing correct values, so no matter what
higher-level algorithm was in place the GIGO effect would have resulted in
bad decisions.

Change-Id: If61ed513cfcb931916c6b51da293e3efbaaf385f
BUG: 853258
Signed-off-by: Jeff Darcy <jdarcy@redhat.com>
Reviewed-on: http://review.gluster.org/3908
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
fuse-bridge: use READDIRPLUS support when available

This patch makes use of READDIRPLUS call when support is available
in the kernel.

Change-Id: Iac78881179567856b55af1f46594a2b2859309f0
BUG: 908128
Signed-off-by: Anand V. Avati <avati@redhat.com>
Reviewed-on: http://review.gluster.org/3905
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Amar Tumballi <amarts@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
afr: serialize modification of {entrylk,inodelk}_lock_count

Typically this lock was not needed in practice, but with
http://review.gluster.org/3842, this code gets executed in multiple
threads for different servers and we lose a count. This results in
leaked lock and a hang for a future transaction.

Change-Id: I377ed20e44f2a45cff522289dfef181f0653eca2
BUG: 765564
Signed-off-by: Anand Avati <avati@redhat.com>
Reviewed-on: http://review.gluster.org/4480
Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
Tested-by: Gluster Build System <jenkins@build.gluster.com>