summaryrefslogtreecommitdiffstats
path: root/xlators/protocol/client/src
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/protocol/client/src')
-rw-r--r--xlators/protocol/client/src/Makefile.am8
-rw-r--r--xlators/protocol/client/src/client-handshake.c264
-rw-r--r--xlators/protocol/client/src/client-helpers.c73
-rw-r--r--xlators/protocol/client/src/client-lk.c360
-rw-r--r--xlators/protocol/client/src/client-rpc-fops.c530
-rw-r--r--xlators/protocol/client/src/client.c177
-rw-r--r--xlators/protocol/client/src/client.h56
7 files changed, 868 insertions, 600 deletions
diff --git a/xlators/protocol/client/src/Makefile.am b/xlators/protocol/client/src/Makefile.am
index a62a68a5f..cf89d42da 100644
--- a/xlators/protocol/client/src/Makefile.am
+++ b/xlators/protocol/client/src/Makefile.am
@@ -2,7 +2,7 @@
xlator_LTLIBRARIES = client.la
xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/protocol
-client_la_LDFLAGS = -module -avoidversion
+client_la_LDFLAGS = -module -avoid-version
client_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la \
$(top_builddir)/rpc/rpc-lib/src/libgfrpc.la \
@@ -13,6 +13,8 @@ client_la_SOURCES = client.c client-helpers.c client-rpc-fops.c \
noinst_HEADERS = client.h client-mem-types.h
-AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS) \
- -I$(top_srcdir)/libglusterfs/src -shared -nostartfiles $(GF_CFLAGS) \
+AM_CPPFLAGS = $(GF_CPPFLAGS) \
+ -I$(top_srcdir)/libglusterfs/src \
-I$(top_srcdir)/rpc/xdr/src -I$(top_srcdir)/rpc/rpc-lib/src/
+
+AM_CFLAGS = -Wall $(GF_CFLAGS)
diff --git a/xlators/protocol/client/src/client-handshake.c b/xlators/protocol/client/src/client-handshake.c
index 3242cf0ae..5668fea53 100644
--- a/xlators/protocol/client/src/client-handshake.c
+++ b/xlators/protocol/client/src/client-handshake.c
@@ -25,6 +25,7 @@
#include "portmap-xdr.h"
#include "rpc-common-xdr.h"
+#define CLIENT_REOPEN_MAX_ATTEMPTS 1024
extern rpc_clnt_prog_t clnt3_3_fop_prog;
extern rpc_clnt_prog_t clnt_pmap_prog;
@@ -52,7 +53,7 @@ rpc_client_ping_timer_expired (void *data)
rpc_clnt_connection_t *conn = NULL;
int disconnect = 0;
int transport_activity = 0;
- struct timeval timeout = {0, };
+ struct timespec timeout = {0, };
struct timeval current = {0, };
struct rpc_clnt *clnt = NULL;
xlator_t *this = NULL;
@@ -100,7 +101,7 @@ rpc_client_ping_timer_expired (void *data)
"ping timer expired but transport activity "
"detected - not bailing transport");
timeout.tv_sec = conf->opt.ping_timeout;
- timeout.tv_usec = 0;
+ timeout.tv_nsec = 0;
conn->ping_timer =
gf_timer_call_after (this->ctx, timeout,
@@ -139,7 +140,7 @@ client_start_ping (void *data)
clnt_conf_t *conf = NULL;
rpc_clnt_connection_t *conn = NULL;
int32_t ret = -1;
- struct timeval timeout = {0, };
+ struct timespec timeout = {0, };
call_frame_t *frame = NULL;
int frame_count = 0;
@@ -195,7 +196,7 @@ client_start_ping (void *data)
}
timeout.tv_sec = conf->opt.ping_timeout;
- timeout.tv_usec = 0;
+ timeout.tv_nsec = 0;
conn->ping_timer =
gf_timer_call_after (this->ctx, timeout,
@@ -240,7 +241,7 @@ client_ping_cbk (struct rpc_req *req, struct iovec *iov, int count,
{
xlator_t *this = NULL;
rpc_clnt_connection_t *conn = NULL;
- struct timeval timeout = {0, };
+ struct timespec timeout = {0, };
call_frame_t *frame = NULL;
clnt_conf_t *conf = NULL;
@@ -280,7 +281,7 @@ client_ping_cbk (struct rpc_req *req, struct iovec *iov, int count,
timeout.tv_sec = conf->opt.ping_timeout;
- timeout.tv_usec = 0;
+ timeout.tv_nsec = 0;
gf_timer_call_cancel (this->ctx,
conn->ping_timer);
@@ -415,9 +416,6 @@ clnt_fd_lk_reacquire_failed (xlator_t *this, clnt_fd_ctx_t *fdctx,
{
fdctx->remote_fd = -1;
fdctx->lk_heal_state = GF_LK_HEAL_DONE;
-
- list_add_tail (&fdctx->sfd_pos,
- &conf->saved_fds);
}
pthread_mutex_unlock (&conf->lock);
@@ -603,7 +601,7 @@ clnt_release_reopen_fd_cbk (struct rpc_req *req, struct iovec *iov,
clnt_fd_lk_reacquire_failed (this, fdctx, conf);
- decrement_reopen_fd_count (this, conf);
+ fdctx->reopen_done (fdctx, this);
frame->local = NULL;
STACK_DESTROY (frame->root);
@@ -633,10 +631,11 @@ clnt_release_reopen_fd (xlator_t *this, clnt_fd_ctx_t *fdctx)
clnt_release_reopen_fd_cbk, NULL,
NULL, 0, NULL, 0, NULL,
(xdrproc_t)xdr_gfs3_releasedir_req);
+ return 0;
out:
if (ret) {
- decrement_reopen_fd_count (this, conf);
clnt_fd_lk_reacquire_failed (this, fdctx, conf);
+ fdctx->reopen_done (fdctx, this);
if (frame) {
frame->local = NULL;
STACK_DESTROY (frame->root);
@@ -754,13 +753,10 @@ client_reacquire_lock_cbk (struct rpc_req *req, struct iovec *iov,
pthread_mutex_lock (&conf->lock);
{
fdctx->lk_heal_state = GF_LK_HEAL_DONE;
-
- list_add_tail (&fdctx->sfd_pos,
- &conf->saved_fds);
}
pthread_mutex_unlock (&conf->lock);
- decrement_reopen_fd_count (this, conf);
+ fdctx->reopen_done (fdctx, this);
}
ret = 0;
@@ -869,8 +865,7 @@ client_reacquire_lock (xlator_t *this, clnt_fd_ctx_t *fdctx)
if (client_fd_lk_list_empty (fdctx->lk_ctx, _gf_false)) {
gf_log (this->name, GF_LOG_DEBUG,
"fd lock list is empty");
- decrement_reopen_fd_count (this,
- (clnt_conf_t *)this->private);
+ fdctx->reopen_done (fdctx, this);
} else {
lk_ctx = fdctx->lk_ctx;
@@ -885,14 +880,66 @@ out:
return ret;
}
+void
+client_default_reopen_done (clnt_fd_ctx_t *fdctx, xlator_t *this)
+{
+ gf_log_callingfn (this->name, GF_LOG_WARNING,
+ "This function should never be called");
+}
+
+void
+client_reopen_done (clnt_fd_ctx_t *fdctx, xlator_t *this)
+{
+ clnt_conf_t *conf = NULL;
+ gf_boolean_t destroy = _gf_false;
+
+ conf = this->private;
+
+ pthread_mutex_lock (&conf->lock);
+ {
+ fdctx->reopen_attempts = 0;
+ if (!fdctx->released)
+ list_add_tail (&fdctx->sfd_pos, &conf->saved_fds);
+ else
+ destroy = _gf_true;
+ fdctx->reopen_done = client_default_reopen_done;
+ }
+ pthread_mutex_unlock (&conf->lock);
+
+ if (destroy)
+ client_fdctx_destroy (this, fdctx);
+}
+
+void
+client_child_up_reopen_done (clnt_fd_ctx_t *fdctx, xlator_t *this)
+{
+ clnt_conf_t *conf = NULL;
+ uint64_t fd_count = 0;
+
+ conf = this->private;
+
+ LOCK (&conf->rec_lock);
+ {
+ fd_count = --(conf->reopen_fd_count);
+ }
+ UNLOCK (&conf->rec_lock);
+
+ client_reopen_done (fdctx, this);
+ if (fd_count == 0) {
+ gf_log (this->name, GF_LOG_INFO,
+ "last fd open'd/lock-self-heal'd - notifying CHILD-UP");
+ client_set_lk_version (this);
+ client_notify_parents_child_up (this);
+ }
+}
+
int
client3_3_reopen_cbk (struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
int32_t ret = -1;
gfs3_open_rsp rsp = {0,};
- int attempt_lock_recovery = _gf_false;
- uint64_t fd_count = 0;
+ gf_boolean_t attempt_lock_recovery = _gf_false;
clnt_local_t *local = NULL;
clnt_conf_t *conf = NULL;
clnt_fd_ctx_t *fdctx = NULL;
@@ -900,12 +947,10 @@ client3_3_reopen_cbk (struct rpc_req *req, struct iovec *iov, int count,
xlator_t *this = NULL;
frame = myframe;
- if (!frame || !frame->this)
- goto out;
-
this = frame->this;
+ conf = this->private;
local = frame->local;
- conf = frame->this->private;
+ fdctx = local->fdctx;
if (-1 == req->rpc_status) {
gf_log (frame->this->name, GF_LOG_WARNING,
@@ -938,32 +983,23 @@ client3_3_reopen_cbk (struct rpc_req *req, struct iovec *iov, int count,
goto out;
}
- fdctx = local->fdctx;
- if (!fdctx) {
- gf_log (frame->this->name, GF_LOG_WARNING, "fdctx not found");
- ret = -1;
- goto out;
- }
-
pthread_mutex_lock (&conf->lock);
{
fdctx->remote_fd = rsp.fd;
if (!fdctx->released) {
- if (!client_fd_lk_list_empty (fdctx->lk_ctx, _gf_false)) {
+ if (conf->lk_heal &&
+ !client_fd_lk_list_empty (fdctx->lk_ctx,
+ _gf_false)) {
attempt_lock_recovery = _gf_true;
fdctx->lk_heal_state = GF_LK_HEAL_IN_PROGRESS;
- } else {
- list_add_tail (&fdctx->sfd_pos,
- &conf->saved_fds);
}
- fdctx = NULL;
}
}
pthread_mutex_unlock (&conf->lock);
ret = 0;
- if (conf->lk_heal && attempt_lock_recovery) {
+ if (attempt_lock_recovery) {
/* Delay decrementing the reopen fd count untill all the
locks corresponding to this fd are acquired.*/
gf_log (this->name, GF_LOG_DEBUG, "acquiring locks "
@@ -973,23 +1009,15 @@ client3_3_reopen_cbk (struct rpc_req *req, struct iovec *iov, int count,
clnt_reacquire_lock_error (this, local->fdctx, conf);
gf_log (this->name, GF_LOG_WARNING, "acquiring locks "
"failed on %s", local->loc.path);
- ret = 0;
}
- } else {
- fd_count = decrement_reopen_fd_count (frame->this, conf);
}
out:
- if (fdctx) {
- clnt_release_reopen_fd (this, fdctx);
- } else if ((ret < 0) && frame && frame->this && conf) {
- decrement_reopen_fd_count (frame->this, conf);
- }
+ if (!attempt_lock_recovery)
+ fdctx->reopen_done (fdctx, this);
- if (frame) {
- frame->local = NULL;
- STACK_DESTROY (frame->root);
- }
+ frame->local = NULL;
+ STACK_DESTROY (frame->root);
client_local_wipe (local);
@@ -1008,11 +1036,10 @@ client3_3_reopendir_cbk (struct rpc_req *req, struct iovec *iov, int count,
call_frame_t *frame = NULL;
frame = myframe;
- if (!frame || !frame->this)
- goto out;
+ local = frame->local;
+ fdctx = local->fdctx;
+ conf = frame->this->private;
- local = frame->local;
- conf = frame->this->private;
if (-1 == req->rpc_status) {
gf_log (frame->this->name, GF_LOG_WARNING,
@@ -1045,46 +1072,24 @@ client3_3_reopendir_cbk (struct rpc_req *req, struct iovec *iov, int count,
goto out;
}
- fdctx = local->fdctx;
- if (!fdctx) {
- gf_log (frame->this->name, GF_LOG_WARNING, "fdctx not found");
- ret = -1;
- goto out;
- }
-
pthread_mutex_lock (&conf->lock);
{
fdctx->remote_fd = rsp.fd;
-
- if (!fdctx->released) {
- list_add_tail (&fdctx->sfd_pos, &conf->saved_fds);
- fdctx = NULL;
- }
}
pthread_mutex_unlock (&conf->lock);
- decrement_reopen_fd_count (frame->this, conf);
- ret = 0;
-
out:
- if (fdctx)
- client_fdctx_destroy (frame->this, fdctx);
-
- if ((ret < 0) && frame && frame->this && conf)
- decrement_reopen_fd_count (frame->this, conf);
-
- if (frame) {
- frame->local = NULL;
- STACK_DESTROY (frame->root);
- }
+ fdctx->reopen_done (fdctx, frame->this);
+ frame->local = NULL;
+ STACK_DESTROY (frame->root);
client_local_wipe (local);
return 0;
}
-int
-protocol_client_reopendir (xlator_t *this, clnt_fd_ctx_t *fdctx)
+static int
+protocol_client_reopendir (clnt_fd_ctx_t *fdctx, xlator_t *this)
{
int ret = -1;
gfs3_opendir_req req = {{0,},};
@@ -1092,9 +1097,6 @@ protocol_client_reopendir (xlator_t *this, clnt_fd_ctx_t *fdctx)
call_frame_t *frame = NULL;
clnt_conf_t *conf = NULL;
- if (!this || !fdctx)
- goto out;
-
conf = this->private;
local = mem_get0 (this->local_pool);
@@ -1120,7 +1122,7 @@ protocol_client_reopendir (xlator_t *this, clnt_fd_ctx_t *fdctx)
gf_log (frame->this->name, GF_LOG_DEBUG,
"attempting reopen on %s", local->loc.path);
- frame->local = local; local = NULL;
+ frame->local = local;
ret = client_submit_request (this, &req, frame, conf->fops,
GFS3_OP_OPENDIR,
@@ -1128,11 +1130,11 @@ protocol_client_reopendir (xlator_t *this, clnt_fd_ctx_t *fdctx)
NULL, 0, NULL, 0, NULL,
(xdrproc_t)xdr_gfs3_opendir_req);
if (ret) {
- gf_log (THIS->name, GF_LOG_ERROR,
+ gf_log (this->name, GF_LOG_ERROR,
"failed to send the re-opendir request");
}
- return ret;
+ return 0;
out:
if (frame) {
@@ -1143,16 +1145,14 @@ out:
if (local)
client_local_wipe (local);
- if ((ret < 0) && this && conf) {
- decrement_reopen_fd_count (this, conf);
- }
+ fdctx->reopen_done (fdctx, this);
return 0;
}
-int
-protocol_client_reopen (xlator_t *this, clnt_fd_ctx_t *fdctx)
+static int
+protocol_client_reopenfile (clnt_fd_ctx_t *fdctx, xlator_t *this)
{
int ret = -1;
gfs3_open_req req = {{0,},};
@@ -1160,9 +1160,6 @@ protocol_client_reopen (xlator_t *this, clnt_fd_ctx_t *fdctx)
call_frame_t *frame = NULL;
clnt_conf_t *conf = NULL;
- if (!this || !fdctx)
- goto out;
-
conf = this->private;
frame = create_frame (this, this->ctx->pool);
@@ -1192,17 +1189,16 @@ protocol_client_reopen (xlator_t *this, clnt_fd_ctx_t *fdctx)
gf_log (frame->this->name, GF_LOG_DEBUG,
"attempting reopen on %s", local->loc.path);
- local = NULL;
ret = client_submit_request (this, &req, frame, conf->fops,
GFS3_OP_OPEN, client3_3_reopen_cbk, NULL,
NULL, 0, NULL, 0, NULL,
(xdrproc_t)xdr_gfs3_open_req);
if (ret) {
- gf_log (THIS->name, GF_LOG_ERROR,
+ gf_log (this->name, GF_LOG_ERROR,
"failed to send the re-open request");
}
- return ret;
+ return 0;
out:
if (frame) {
@@ -1213,14 +1209,65 @@ out:
if (local)
client_local_wipe (local);
- if ((ret < 0) && this && conf) {
- decrement_reopen_fd_count (this, conf);
- }
+ fdctx->reopen_done (fdctx, this);
return 0;
}
+static void
+protocol_client_reopen (clnt_fd_ctx_t *fdctx, xlator_t *this)
+{
+ if (fdctx->is_dir)
+ protocol_client_reopendir (fdctx, this);
+ else
+ protocol_client_reopenfile (fdctx, this);
+}
+
+gf_boolean_t
+__is_fd_reopen_in_progress (clnt_fd_ctx_t *fdctx)
+{
+ if (fdctx->reopen_done == client_default_reopen_done)
+ return _gf_false;
+ return _gf_true;
+}
+
+void
+client_attempt_reopen (fd_t *fd, xlator_t *this)
+{
+ clnt_conf_t *conf = NULL;
+ clnt_fd_ctx_t *fdctx = NULL;
+ gf_boolean_t reopen = _gf_false;
+
+ if (!fd || !this)
+ goto out;
+
+ conf = this->private;
+ pthread_mutex_lock (&conf->lock);
+ {
+ fdctx = this_fd_get_ctx (fd, this);
+ if (!fdctx)
+ goto unlock;
+ if (__is_fd_reopen_in_progress (fdctx))
+ goto unlock;
+ if (fdctx->remote_fd != -1)
+ goto unlock;
+
+ if (fdctx->reopen_attempts == CLIENT_REOPEN_MAX_ATTEMPTS) {
+ reopen = _gf_true;
+ fdctx->reopen_done = client_reopen_done;
+ list_del_init (&fdctx->sfd_pos);
+ } else {
+ fdctx->reopen_attempts++;
+ }
+ }
+unlock:
+ pthread_mutex_unlock (&conf->lock);
+ if (reopen)
+ protocol_client_reopen (fdctx, this);
+out:
+ return;
+}
int
client_post_handshake (call_frame_t *frame, xlator_t *this)
@@ -1245,6 +1292,7 @@ client_post_handshake (call_frame_t *frame, xlator_t *this)
if (fdctx->remote_fd != -1)
continue;
+ fdctx->reopen_done = client_child_up_reopen_done;
list_del_init (&fdctx->sfd_pos);
list_add_tail (&fdctx->sfd_pos, &reopen_head);
count++;
@@ -1263,10 +1311,7 @@ client_post_handshake (call_frame_t *frame, xlator_t *this)
list_for_each_entry_safe (fdctx, tmp, &reopen_head, sfd_pos) {
list_del_init (&fdctx->sfd_pos);
- if (fdctx->is_dir)
- protocol_client_reopendir (this, fdctx);
- else
- protocol_client_reopen (this, fdctx);
+ protocol_client_reopen (fdctx, this);
}
} else {
gf_log (this->name, GF_LOG_DEBUG,
@@ -1554,13 +1599,14 @@ client_setvolume (xlator_t *this, struct rpc_clnt *rpc)
client_get_lk_ver (conf));
}
- req.dict.dict_len = dict_serialized_length (options);
- if (req.dict.dict_len < 0) {
+ ret = dict_serialized_length (options);
+ if (ret < 0) {
gf_log (this->name, GF_LOG_ERROR,
"failed to get serialized length of dict");
ret = -1;
goto fail;
}
+ req.dict.dict_len = ret;
req.dict.dict_val = GF_CALLOC (1, req.dict.dict_len,
gf_client_mt_clnt_req_buf_t);
ret = dict_serialize (options, req.dict.dict_val);
@@ -1690,16 +1736,21 @@ client_query_portmap_cbk (struct rpc_req *req, struct iovec *iov, int count, voi
ret = -1;
gf_log (this->name, ((!conf->portmap_err_logged) ?
GF_LOG_ERROR : GF_LOG_DEBUG),
- "failed to get the port number for remote subvolume");
+ "failed to get the port number for remote subvolume. "
+ "Please run 'gluster volume status' on server to see "
+ "if brick process is running.");
conf->portmap_err_logged = 1;
goto out;
}
conf->portmap_err_logged = 0;
+ conf->disconnect_err_logged = 0;
config.remote_port = rsp.port;
rpc_clnt_reconfig (conf->rpc, &config);
+
conf->skip_notify = 1;
+ conf->quick_reconnect = 1;
out:
if (frame)
@@ -1709,7 +1760,6 @@ out:
/* Need this to connect the same transport on different port */
/* ie, glusterd to glusterfsd */
rpc_transport_disconnect (conf->rpc->conn.trans);
- rpc_clnt_reconnect (conf->rpc->conn.trans);
}
return ret;
diff --git a/xlators/protocol/client/src/client-helpers.c b/xlators/protocol/client/src/client-helpers.c
index 77b416c47..5d9f00fdc 100644
--- a/xlators/protocol/client/src/client-helpers.c
+++ b/xlators/protocol/client/src/client-helpers.c
@@ -16,7 +16,6 @@
#include "client.h"
#include "fd.h"
-
int
client_fd_lk_list_empty (fd_lk_ctx_t *lk_ctx, gf_boolean_t try_lock)
{
@@ -276,3 +275,75 @@ clnt_readdir_rsp_cleanup (gfs3_readdir_rsp *rsp)
return 0;
}
+
+int
+client_get_remote_fd (xlator_t *this, fd_t *fd, int flags, int64_t *remote_fd)
+{
+ clnt_fd_ctx_t *fdctx = NULL;
+ clnt_conf_t *conf = NULL;
+
+ GF_VALIDATE_OR_GOTO (this->name, fd, out);
+ GF_VALIDATE_OR_GOTO (this->name, remote_fd, out);
+
+ conf = this->private;
+ pthread_mutex_lock (&conf->lock);
+ {
+ fdctx = this_fd_get_ctx (fd, this);
+ if (!fdctx)
+ *remote_fd = GF_ANON_FD_NO;
+ else if (__is_fd_reopen_in_progress (fdctx))
+ *remote_fd = -1;
+ else
+ *remote_fd = fdctx->remote_fd;
+ }
+ pthread_mutex_unlock (&conf->lock);
+
+ if ((flags & FALLBACK_TO_ANON_FD) && (*remote_fd == -1))
+ *remote_fd = GF_ANON_FD_NO;
+
+ return 0;
+out:
+ return -1;
+}
+
+gf_boolean_t
+client_is_reopen_needed (fd_t *fd, xlator_t *this, int64_t remote_fd)
+{
+ clnt_fd_ctx_t *fdctx = NULL;
+
+ fdctx = this_fd_get_ctx (fd, this);
+ if (fdctx && (fdctx->remote_fd == -1) &&
+ (remote_fd == GF_ANON_FD_NO))
+ return _gf_true;
+ return _gf_false;
+}
+
+int
+client_fd_fop_prepare_local (call_frame_t *frame, fd_t *fd, int64_t remote_fd)
+{
+ xlator_t *this = NULL;
+ clnt_conf_t *conf = NULL;
+ clnt_local_t *local = NULL;
+ int ret = 0;
+
+ this = frame->this;
+ conf = this->private;
+
+ if (!frame || !fd) {
+ ret = -EINVAL;
+ goto out;
+ }
+
+ frame->local = mem_get0 (this->local_pool);
+ if (frame->local == NULL) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ local = frame->local;
+ local->fd = fd_ref (fd);
+ local->attempt_reopen = client_is_reopen_needed (fd, this, remote_fd);
+ return 0;
+out:
+ return ret;
+}
diff --git a/xlators/protocol/client/src/client-lk.c b/xlators/protocol/client/src/client-lk.c
index 5611c7b83..1fd8f0d50 100644
--- a/xlators/protocol/client/src/client-lk.c
+++ b/xlators/protocol/client/src/client-lk.c
@@ -16,9 +16,6 @@
static void
__insert_and_merge (clnt_fd_ctx_t *fdctx, client_posix_lock_t *lock);
-static int
-client_send_recovery_lock (call_frame_t *frame, xlator_t *this,
- client_posix_lock_t *lock);
static void
__dump_client_lock (client_posix_lock_t *lock)
{
@@ -430,21 +427,6 @@ delete_granted_locks_fd (clnt_fd_ctx_t *fdctx)
return ret;
}
-static void
-client_mark_bad_fd (fd_t *fd, clnt_fd_ctx_t *fdctx)
-{
- xlator_t *this = NULL;
-
- this = THIS;
- if (fdctx)
- fdctx->remote_fd = -1;
-
- gf_log (this->name, GF_LOG_WARNING,
- "marking the file descriptor (%p) bad", fd);
-
- this_fd_set_ctx (fd, this, NULL, fdctx);
-}
-
int32_t
client_cmd_to_gf_cmd (int32_t cmd, int32_t *gf_cmd)
{
@@ -553,348 +535,6 @@ out:
}
-static int
-construct_reserve_unlock (struct gf_flock *lock, call_frame_t *frame,
- client_posix_lock_t *client_lock)
-{
- GF_ASSERT (lock);
- GF_ASSERT (frame);
-
- lock->l_type = F_UNLCK;
- lock->l_start = 0;
- lock->l_whence = SEEK_SET;
- lock->l_len = 0; /* Whole file */
- lock->l_pid = (uint64_t)(unsigned long)frame->root;
- lock->l_owner = client_lock->owner;
-
- frame->root->lk_owner = client_lock->owner;
-
- return 0;
-}
-
-static int
-construct_reserve_lock (client_posix_lock_t *client_lock, call_frame_t *frame,
- struct gf_flock *lock)
-{
- GF_ASSERT (client_lock);
-
- memcpy (lock, &(client_lock->user_flock), sizeof (struct gf_flock));
-
- frame->root->lk_owner = client_lock->owner;
-
- return 0;
-}
-
-uint64_t
-decrement_reopen_fd_count (xlator_t *this, clnt_conf_t *conf)
-{
- uint64_t fd_count = 0;
-
- LOCK (&conf->rec_lock);
- {
- fd_count = --(conf->reopen_fd_count);
- }
- UNLOCK (&conf->rec_lock);
-
- if (fd_count == 0) {
- gf_log (this->name, GF_LOG_INFO,
- "last fd open'd/lock-self-heal'd - notifying CHILD-UP");
- client_set_lk_version (this);
- client_notify_parents_child_up (this);
- }
-
- return fd_count;
-}
-
-int32_t
-client_remove_reserve_lock_cbk (call_frame_t *frame,
- void *cookie,
- xlator_t *this,
- int32_t op_ret,
- int32_t op_errno,
- struct gf_flock *lock, dict_t *xdata)
-{
- clnt_local_t *local = NULL;
- clnt_conf_t *conf = NULL;
-
- uint64_t fd_count = 0;
-
- local = frame->local;
- conf = this->private;
-
- if (op_ret < 0) {
- gf_log (this->name, GF_LOG_WARNING,
- "removing reserver lock on fd failed: %s",
- strerror(op_errno));
- goto cleanup;
- }
-
- gf_log (this->name, GF_LOG_DEBUG,
- "Removing reserve lock was successful.");
-
-cleanup:
- frame->local = NULL;
-
- client_mark_bad_fd (local->client_lock->fd, local->fdctx);
-
- destroy_client_lock (local->client_lock);
- client_local_wipe (local);
- STACK_DESTROY (frame->root);
-
- fd_count = decrement_reopen_fd_count (this, conf);
- gf_log (this->name, GF_LOG_TRACE,
- "Need to attempt lock recovery on %lld open fds",
- (unsigned long long) fd_count);
- return 0;
-}
-
-static void
-client_remove_reserve_lock (xlator_t *this, call_frame_t *frame,
- client_posix_lock_t *lock)
-{
- struct gf_flock unlock;
-
- construct_reserve_unlock (&unlock, frame, lock);
-
- STACK_WIND (frame, client_remove_reserve_lock_cbk,
- this, this->fops->lk,
- lock->fd, F_RESLK_UNLCK, &unlock, NULL);
-}
-
-static client_posix_lock_t *
-get_next_recovery_lock (xlator_t *this, clnt_local_t *local)
-{
- client_posix_lock_t *lock = NULL;
-
- pthread_mutex_lock (&local->mutex);
- {
- if (list_empty (&local->lock_list)) {
- gf_log (this->name, GF_LOG_DEBUG,
- "lock-list empty");
- goto unlock;
- }
-
- lock = list_entry ((local->lock_list).next, typeof (*lock), list);
- list_del_init (&lock->list);
- }
-unlock:
- pthread_mutex_unlock (&local->mutex);
-
- return lock;
-
-}
-
-int32_t
-client_reserve_lock_cbk (call_frame_t *frame,
- void *cookie,
- xlator_t *this,
- int32_t op_ret,
- int32_t op_errno,
- struct gf_flock *lock, dict_t *xdata)
-{
-
- clnt_local_t *local = NULL;
- clnt_conf_t *conf = NULL;
-
- uint64_t fd_count = 0;
-
- local = frame->local;
- conf = this->private;
-
- /* Got the reserve lock. Check if lock is grantable and proceed
- with the real lk call */
-
- if (op_ret >= 0) {
- /* Lock is grantable if flock reflects a successful getlk() call*/
- if (lock->l_type == F_UNLCK && lock->l_pid) {
- gf_log (this->name, GF_LOG_INFO,
- "Got the reservelk, but the lock is not grantable. ");
- client_remove_reserve_lock (this, frame, local->client_lock);
- goto out;
- }
-
- gf_log (this->name, GF_LOG_DEBUG, "reserve lock succeeded");
- client_send_recovery_lock (frame, this, local->client_lock);
- goto out;
- }
-
- /* Somebody else has a reserve lk. Lock conflict detected.
- Mark fd as bad */
-
- gf_log (this->name, GF_LOG_WARNING,
- "reservelk OP failed. aborting lock recovery");
-
- client_mark_bad_fd (local->client_lock->fd,
- local->fdctx);
- destroy_client_lock (local->client_lock);
- frame->local = NULL;
- client_local_wipe (local);
- STACK_DESTROY (frame->root);
-
- fd_count = decrement_reopen_fd_count (this, conf);
- gf_log (this->name, GF_LOG_DEBUG,
- "need to attempt lock recovery on %"PRIu64" open fds",
- fd_count);
-
-out:
- return 0;
-}
-
-int32_t
-client_recovery_lock_cbk (call_frame_t *frame,
- void *cookie,
- xlator_t *this,
- int32_t op_ret,
- int32_t op_errno,
- struct gf_flock *lock, dict_t *xdata)
-{
- clnt_local_t *local = NULL;
- clnt_fd_ctx_t *fdctx = NULL;
- clnt_conf_t *conf = NULL;
- client_posix_lock_t *next_lock = NULL;
-
- struct gf_flock reserve_flock;
- uint64_t fd_count = 0;
-
- local = frame->local;
- conf = this->private;
-
- if (op_ret < 0) {
- gf_log (this->name, GF_LOG_ERROR,
- "lock recovery failed: %s",
- strerror(op_errno));
-
- client_mark_bad_fd (local->client_lock->fd,
- local->fdctx);
- goto cleanup;
-
- /* Lock recovered. Continue with reserve lock for next lock */
- } else {
- gf_log (this->name, GF_LOG_DEBUG,
- "lock recovered successfully - continuing with next lock.");
-
- next_lock = get_next_recovery_lock (this, local);
- if (!next_lock) {
- gf_log (this->name, GF_LOG_DEBUG,
- "all locks recovered on fd");
- goto cleanup;
- }
-
- construct_reserve_lock (next_lock, frame, &reserve_flock);
- local->fdctx = fdctx;
- local->client_lock = next_lock;
-
- STACK_WIND (frame, client_reserve_lock_cbk,
- this, this->fops->lk,
- next_lock->fd, F_RESLK_LCK, &reserve_flock, NULL);
- goto out;
-
- }
-
-cleanup:
-
- frame->local = NULL;
- client_local_wipe (local);
-
- if (local->client_lock)
- destroy_client_lock (local->client_lock);
-
- STACK_DESTROY (frame->root);
-
- fd_count = decrement_reopen_fd_count (this, conf);
-
- gf_log (this->name, GF_LOG_DEBUG,
- "need to attempt lock recovery on %"PRIu64" open fds",
- fd_count);
-
-out:
- return 0;
-}
-
-static int
-client_send_recovery_lock (call_frame_t *frame, xlator_t *this,
- client_posix_lock_t *lock)
-{
- frame->root->lk_owner = lock->owner;
-
- /* Send all locks as F_SETLK to prevent the frame
- from blocking if there is a conflict */
-
- STACK_WIND (frame, client_recovery_lock_cbk,
- this, this->fops->lk,
- lock->fd, F_SETLK,
- &(lock->user_flock), NULL);
-
- return 0;
-}
-
-static int
-client_lockrec_init (clnt_fd_ctx_t *fdctx, clnt_local_t *local)
-{
-
- INIT_LIST_HEAD (&local->lock_list);
- pthread_mutex_init (&local->mutex, NULL);
-
- pthread_mutex_lock (&fdctx->mutex);
- {
- list_splice_init (&fdctx->lock_list, &local->lock_list);
- }
- pthread_mutex_unlock (&fdctx->mutex);
-
- return 0;
-}
-
-
-int
-client_attempt_lock_recovery (xlator_t *this, clnt_fd_ctx_t *fdctx)
-{
- call_frame_t *frame = NULL;
- clnt_local_t *local = NULL;
- client_posix_lock_t *lock = NULL;
-
- struct gf_flock reserve_flock;
- int ret = 0;
-
- local = mem_get0 (this->local_pool);
- if (!local) {
- ret = -ENOMEM;
- goto out;
- }
-
- client_lockrec_init (fdctx, local);
-
- lock = get_next_recovery_lock (this, local);
- if (!lock) {
- gf_log (this->name, GF_LOG_DEBUG,
- "no locks found on fd");
- ret = -1;
- goto out;
- }
-
- frame = create_frame (this, this->ctx->pool);
- if (!frame) {
- gf_log (this->name, GF_LOG_ERROR,
- "creating of frame failed, lock recovery failed");
- ret = -1;
- goto out;
- }
-
- construct_reserve_lock (lock, frame, &reserve_flock);
-
- frame->local = local;
- local->fdctx = fdctx;
- local->client_lock = lock;
-
- STACK_WIND (frame, client_reserve_lock_cbk,
- this, this->fops->lk,
- lock->fd, F_RESLK_LCK, &reserve_flock, NULL);
-
-out:
- return ret;
-
-
-}
-
int32_t
client_dump_locks (char *name, inode_t *inode,
dict_t *dict)
diff --git a/xlators/protocol/client/src/client-rpc-fops.c b/xlators/protocol/client/src/client-rpc-fops.c
index d541c35eb..6355450c3 100644
--- a/xlators/protocol/client/src/client-rpc-fops.c
+++ b/xlators/protocol/client/src/client-rpc-fops.c
@@ -185,8 +185,7 @@ out:
gf_log (this->name, GF_LOG_WARNING,
"remote operation failed: %s. Path: (%s to %s)",
strerror (gf_error_to_errno (rsp.op_errno)),
- (local) ? local->loc.path : "--",
- (local) ? local->loc2.path: "--");
+ local->loc.path, local->loc2.path);
}
CLIENT_STACK_UNWIND (symlink, frame, rsp.op_ret,
@@ -252,11 +251,9 @@ client3_3_mknod_cbk (struct rpc_req *req, struct iovec *iov, int count,
out:
if (rsp.op_ret == -1) {
gf_log (this->name, GF_LOG_WARNING,
- "remote operation failed: %s. Path: %s (%s)",
+ "remote operation failed: %s. Path: %s",
strerror (gf_error_to_errno (rsp.op_errno)),
- (local) ? local->loc.path : "--",
- (local && local->loc.inode) ?
- uuid_utoa (local->loc.inode->gfid) : "--");
+ local->loc.path);
}
CLIENT_STACK_UNWIND (mknod, frame, rsp.op_ret,
@@ -320,11 +317,9 @@ client3_3_mkdir_cbk (struct rpc_req *req, struct iovec *iov, int count,
out:
if (rsp.op_ret == -1) {
gf_log (this->name, GF_LOG_WARNING,
- "remote operation failed: %s. Path: %s (%s)",
+ "remote operation failed: %s. Path: %s",
strerror (gf_error_to_errno (rsp.op_errno)),
- (local) ? local->loc.path : "--",
- (local && local->loc.inode) ?
- uuid_utoa (local->loc.inode->gfid) : "--");
+ local->loc.path);
}
CLIENT_STACK_UNWIND (mkdir, frame, rsp.op_ret,
@@ -396,6 +391,7 @@ client_add_fd_to_saved_fds (xlator_t *this, fd_t *fd, loc_t *loc, int32_t flags,
fdctx->flags = flags;
fdctx->lk_ctx = fd_lk_ctx_ref (fd->lk_ctx);
fdctx->lk_heal_state = GF_LK_HEAL_DONE;
+ fdctx->reopen_done = client_default_reopen_done;
INIT_LIST_HEAD (&fdctx->sfd_pos);
INIT_LIST_HEAD (&fdctx->lock_list);
@@ -465,9 +461,7 @@ out:
gf_log (this->name, GF_LOG_WARNING,
"remote operation failed: %s. Path: %s (%s)",
strerror (gf_error_to_errno (rsp.op_errno)),
- (local) ? local->loc.path : "--",
- (local && local->loc.inode) ?
- uuid_utoa (local->loc.inode->gfid) : "--");
+ local->loc.path, loc_gfid_utoa (&local->loc));
}
CLIENT_STACK_UNWIND (open, frame, rsp.op_ret,
@@ -575,8 +569,9 @@ client3_3_readlink_cbk (struct rpc_req *req, struct iovec *iov, int count,
out:
if (rsp.op_ret == -1) {
- gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s",
- strerror (gf_error_to_errno (rsp.op_errno)));
+ gf_log (this->name, (gf_error_to_errno(rsp.op_errno) == ENOENT)?
+ GF_LOG_DEBUG:GF_LOG_WARNING, "remote operation failed:"
+ " %s", strerror (gf_error_to_errno (rsp.op_errno)));
}
CLIENT_STACK_UNWIND (readlink, frame, rsp.op_ret,
@@ -636,9 +631,13 @@ client3_3_unlink_cbk (struct rpc_req *req, struct iovec *iov, int count,
out:
if (rsp.op_ret == -1) {
- gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s",
+ gf_log (this->name,
+ ((gf_error_to_errno (rsp.op_errno) == ENOENT)
+ ? GF_LOG_DEBUG : GF_LOG_WARNING),
+ "remote operation failed: %s",
strerror (gf_error_to_errno (rsp.op_errno)));
}
+
CLIENT_STACK_UNWIND (unlink, frame, rsp.op_ret,
gf_error_to_errno (rsp.op_errno), &preparent,
&postparent, xdata);
@@ -830,11 +829,13 @@ client3_3_writev_cbk (struct rpc_req *req, struct iovec *iov, int count,
int ret = 0;
xlator_t *this = NULL;
dict_t *xdata = NULL;
+ clnt_local_t *local = NULL;
this = THIS;
frame = myframe;
+ local = frame->local;
if (-1 == req->rpc_status) {
rsp.op_ret = -1;
@@ -863,6 +864,9 @@ out:
if (rsp.op_ret == -1) {
gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s",
strerror (gf_error_to_errno (rsp.op_errno)));
+ } else if (rsp.op_ret >= 0) {
+ if (local->attempt_reopen)
+ client_attempt_reopen (local->fd, this);
}
CLIENT_STACK_UNWIND (writev, frame, rsp.op_ret,
gf_error_to_errno (rsp.op_errno), &prestat,
@@ -1089,14 +1093,14 @@ client3_3_getxattr_cbk (struct rpc_req *req, struct iovec *iov, int count,
out:
if (rsp.op_ret == -1) {
- gf_log (this->name, (((op_errno == ENOTSUP) || (op_errno == ENODATA)) ?
+ gf_log (this->name, (((op_errno == ENOTSUP) ||
+ (op_errno == ENODATA) ||
+ (op_errno == ENOENT)) ?
GF_LOG_DEBUG : GF_LOG_WARNING),
"remote operation failed: %s. Path: %s (%s). Key: %s",
strerror (op_errno),
- (local) ? local->loc.path : "--",
- (local && local->loc.inode) ?
- uuid_utoa (local->loc.inode->gfid) : "--",
- (local) ? local->name : "(null)");
+ local->loc.path, loc_gfid_utoa (&local->loc),
+ (local->name) ? local->name : "(null)");
}
CLIENT_STACK_UNWIND (getxattr, frame, rsp.op_ret, op_errno, dict, xdata);
@@ -1539,16 +1543,17 @@ int
client3_3_finodelk_cbk (struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
- call_frame_t *frame = NULL;
- gf_common_rsp rsp = {0,};
- int ret = 0;
- xlator_t *this = NULL;
- dict_t *xdata = NULL;
-
+ call_frame_t *frame = NULL;
+ gf_common_rsp rsp = {0,};
+ int ret = 0;
+ xlator_t *this = NULL;
+ dict_t *xdata = NULL;
+ clnt_local_t *local = NULL;
- this = THIS;
frame = myframe;
+ this = frame->this;
+ local = frame->local;
if (-1 == req->rpc_status) {
rsp.op_ret = -1;
@@ -1572,6 +1577,9 @@ out:
(EAGAIN != gf_error_to_errno (rsp.op_errno))) {
gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s",
strerror (gf_error_to_errno (rsp.op_errno)));
+ } else if (rsp.op_ret == 0) {
+ if (local->attempt_reopen)
+ client_attempt_reopen (local->fd, this);
}
CLIENT_STACK_UNWIND (finodelk, frame, rsp.op_ret,
gf_error_to_errno (rsp.op_errno), xdata);
@@ -1733,9 +1741,7 @@ out:
gf_log (this->name, GF_LOG_WARNING,
"remote operation failed: %s. Path: %s (%s)",
strerror (gf_error_to_errno (rsp.op_errno)),
- (local) ? local->loc.path : "--",
- (local && local->loc.inode) ?
- uuid_utoa (local->loc.inode->gfid) : "--");
+ local->loc.path, loc_gfid_utoa (&local->loc));
}
CLIENT_STACK_UNWIND (xattrop, frame, rsp.op_ret,
@@ -1803,6 +1809,9 @@ out:
gf_log (this->name, GF_LOG_WARNING,
"remote operation failed: %s",
strerror (gf_error_to_errno (op_errno)));
+ } else if (rsp.op_ret == 0) {
+ if (local->attempt_reopen)
+ client_attempt_reopen (local->fd, this);
}
CLIENT_STACK_UNWIND (fxattrop, frame, rsp.op_ret,
gf_error_to_errno (op_errno), dict, xdata);
@@ -1927,6 +1936,172 @@ out:
return 0;
}
+int
+client3_3_fallocate_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ call_frame_t *frame = NULL;
+ gfs3_fallocate_rsp rsp = {0,};
+ struct iatt prestat = {0,};
+ struct iatt poststat = {0,};
+ int ret = 0;
+ xlator_t *this = NULL;
+ dict_t *xdata = NULL;
+
+
+ this = THIS;
+
+ frame = myframe;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+ ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_fallocate_rsp);
+ if (ret < 0) {
+ gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+ if (-1 != rsp.op_ret) {
+ gf_stat_to_iatt (&rsp.statpre, &prestat);
+ gf_stat_to_iatt (&rsp.statpost, &poststat);
+ }
+
+ GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val),
+ (rsp.xdata.xdata_len), ret,
+ rsp.op_errno, out);
+
+out:
+ if (rsp.op_ret == -1) {
+ gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s",
+ strerror (gf_error_to_errno (rsp.op_errno)));
+ }
+ CLIENT_STACK_UNWIND (fallocate, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno), &prestat,
+ &poststat, xdata);
+
+ free (rsp.xdata.xdata_val);
+
+ if (xdata)
+ dict_unref (xdata);
+
+ return 0;
+}
+
+int
+client3_3_discard_cbk(struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ call_frame_t *frame = NULL;
+ gfs3_discard_rsp rsp = {0,};
+ struct iatt prestat = {0,};
+ struct iatt poststat = {0,};
+ int ret = 0;
+ xlator_t *this = NULL;
+ dict_t *xdata = NULL;
+
+ this = THIS;
+
+ frame = myframe;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+ ret = xdr_to_generic(*iov, &rsp, (xdrproc_t) xdr_gfs3_discard_rsp);
+ if (ret < 0) {
+ gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+ if (-1 != rsp.op_ret) {
+ gf_stat_to_iatt (&rsp.statpre, &prestat);
+ gf_stat_to_iatt (&rsp.statpost, &poststat);
+ }
+
+ GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val),
+ (rsp.xdata.xdata_len), ret,
+ rsp.op_errno, out);
+
+out:
+ if (rsp.op_ret == -1) {
+ gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s",
+ strerror (gf_error_to_errno (rsp.op_errno)));
+ }
+ CLIENT_STACK_UNWIND (discard, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno), &prestat,
+ &poststat, xdata);
+
+ free (rsp.xdata.xdata_val);
+
+ if (xdata)
+ dict_unref (xdata);
+
+ return 0;
+}
+
+int
+client3_3_zerofill_cbk(struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ call_frame_t *frame = NULL;
+ gfs3_zerofill_rsp rsp = {0,};
+ struct iatt prestat = {0,};
+ struct iatt poststat = {0,};
+ int ret = 0;
+ xlator_t *this = NULL;
+ dict_t *xdata = NULL;
+
+ this = THIS;
+
+ frame = myframe;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+ ret = xdr_to_generic(*iov, &rsp, (xdrproc_t) xdr_gfs3_zerofill_rsp);
+ if (ret < 0) {
+ gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+ if (-1 != rsp.op_ret) {
+ gf_stat_to_iatt (&rsp.statpre, &prestat);
+ gf_stat_to_iatt (&rsp.statpost, &poststat);
+ }
+
+ GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val),
+ (rsp.xdata.xdata_len), ret,
+ rsp.op_errno, out);
+
+out:
+ if (rsp.op_ret == -1) {
+ gf_log (this->name, GF_LOG_WARNING,
+ "remote operation failed: %s",
+ strerror (gf_error_to_errno (rsp.op_errno)));
+ }
+ CLIENT_STACK_UNWIND (zerofill, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno), &prestat,
+ &poststat, xdata);
+
+ free (rsp.xdata.xdata_val);
+
+ if (xdata)
+ dict_unref (xdata);
+
+ return 0;
+}
int
client3_3_setattr_cbk (struct rpc_req *req, struct iovec *iov, int count,
@@ -2044,11 +2219,9 @@ client3_3_create_cbk (struct rpc_req *req, struct iovec *iov, int count,
out:
if (rsp.op_ret == -1) {
gf_log (this->name, GF_LOG_WARNING,
- "remote operation failed: %s. Path: %s (%s)",
+ "remote operation failed: %s. Path: %s",
strerror (gf_error_to_errno (rsp.op_errno)),
- (local) ? local->loc.path : "--",
- (local && local->loc.inode) ?
- uuid_utoa (local->loc.inode->gfid) : "--");
+ local->loc.path);
}
CLIENT_STACK_UNWIND (create, frame, rsp.op_ret,
@@ -2443,10 +2616,7 @@ out:
gf_log (this->name, GF_LOG_WARNING,
"remote operation failed: %s (%s -> %s)",
strerror (gf_error_to_errno (rsp.op_errno)),
- (local) ? ((local->loc.path)? local->loc.path :
- uuid_utoa (local->loc.inode->gfid)) : "--",
- (local) ? ((local->loc2.path)? local->loc2.path :
- local->loc2.name) : "--");
+ local->loc.path, local->loc2.path);
}
CLIENT_STACK_UNWIND (link, frame, rsp.op_ret,
@@ -2516,9 +2686,7 @@ out:
gf_log (this->name, GF_LOG_WARNING,
"remote operation failed: %s. Path: %s (%s)",
strerror (gf_error_to_errno (rsp.op_errno)),
- (local) ? local->loc.path : "--",
- (local && local->loc.inode) ?
- uuid_utoa (local->loc.inode->gfid) : "--");
+ local->loc.path, loc_gfid_utoa (&local->loc));
}
CLIENT_STACK_UNWIND (opendir, frame, rsp.op_ret,
gf_error_to_errno (rsp.op_errno), fd, xdata);
@@ -2598,10 +2766,8 @@ out:
if (rsp.op_errno != ENOENT)
gf_log (this->name, GF_LOG_WARNING,
"remote operation failed: %s. Path: %s (%s)",
- strerror (rsp.op_errno),
- (local) ? local->loc.path : "--",
- (local && local->loc.inode) ?
- uuid_utoa (local->loc.inode->gfid) : "--");
+ strerror (rsp.op_errno), local->loc.path,
+ loc_gfid_utoa (&local->loc));
else
gf_log (this->name, GF_LOG_TRACE, "not found on remote node");
@@ -2675,6 +2841,9 @@ out:
gf_log (this->name, GF_LOG_WARNING,
"remote operation failed: %s",
strerror (gf_error_to_errno (rsp.op_errno)));
+ } else if (rsp.op_ret >= 0) {
+ if (local->attempt_reopen)
+ client_attempt_reopen (local->fd, this);
}
CLIENT_STACK_UNWIND (readv, frame, rsp.op_ret,
gf_error_to_errno (rsp.op_errno), vector, rspcount,
@@ -2754,7 +2923,7 @@ client_fdctx_destroy (xlator_t *this, clnt_fd_ctx_t *fdctx)
if (fdctx->is_dir) {
gfs3_releasedir_req req = {{0,},};
req.fd = fdctx->remote_fd;
- gf_log (this->name, GF_LOG_DEBUG, "sending releasedir on fd");
+ gf_log (this->name, GF_LOG_TRACE, "sending releasedir on fd");
client_submit_request (this, &req, fr, &clnt3_3_fop_prog,
GFS3_OP_RELEASEDIR,
client3_3_releasedir_cbk,
@@ -2763,7 +2932,7 @@ client_fdctx_destroy (xlator_t *this, clnt_fd_ctx_t *fdctx)
} else {
gfs3_release_req req = {{0,},};
req.fd = fdctx->remote_fd;
- gf_log (this->name, GF_LOG_DEBUG, "sending release on fd");
+ gf_log (this->name, GF_LOG_TRACE, "sending release on fd");
client_submit_request (this, &req, fr, &clnt3_3_fop_prog,
GFS3_OP_RELEASE,
client3_3_release_cbk, NULL,
@@ -2903,6 +3072,7 @@ client3_3_lookup (call_frame_t *frame, xlator_t *this,
goto unwind;
loc_copy (&local->loc, args->loc);
+ loc_path (&local->loc, NULL);
frame->local = local;
if (args->loc->parent) {
@@ -3111,7 +3281,8 @@ client3_3_ftruncate (call_frame_t *frame, xlator_t *this,
conf = this->private;
- CLIENT_GET_REMOTE_FD(conf, args->fd, remote_fd, op_errno, unwind);
+ CLIENT_GET_REMOTE_FD (this, args->fd, DEFAULT_REMOTE_FD,
+ remote_fd, op_errno, unwind);
req.offset = args->offset;
req.fd = remote_fd;
@@ -3418,6 +3589,7 @@ client3_3_symlink (call_frame_t *frame, xlator_t *this,
goto unwind;
loc_copy (&local->loc, args->loc);
+ loc_path (&local->loc, NULL);
if (!uuid_is_null (args->loc->parent->gfid))
memcpy (req.pargfid, args->loc->parent->gfid, 16);
@@ -3567,7 +3739,9 @@ client3_3_link (call_frame_t *frame, xlator_t *this,
}
loc_copy (&local->loc, args->oldloc);
+ loc_path (&local->loc, NULL);
loc_copy (&local->loc2, args->newloc);
+ loc_path (&local->loc2, NULL);
frame->local = local;
req.newbname = (char *)args->newloc->name;
@@ -3622,6 +3796,7 @@ client3_3_mknod (call_frame_t *frame, xlator_t *this,
goto unwind;
loc_copy (&local->loc, args->loc);
+ loc_path (&local->loc, NULL);
frame->local = local;
if (!uuid_is_null (args->loc->parent->gfid))
@@ -3689,6 +3864,7 @@ client3_3_mkdir (call_frame_t *frame, xlator_t *this,
goto unwind;
loc_copy (&local->loc, args->loc);
+ loc_path (&local->loc, NULL);
frame->local = local;
if (!uuid_is_null (args->loc->parent->gfid))
@@ -3757,6 +3933,7 @@ client3_3_create (call_frame_t *frame, xlator_t *this,
local->flags = args->flags;
loc_copy (&local->loc, args->loc);
+ loc_path (&local->loc, NULL);
frame->local = local;
if (!uuid_is_null (args->loc->parent->gfid))
@@ -3826,6 +4003,7 @@ client3_3_open (call_frame_t *frame, xlator_t *this,
local->fd = fd_ref (args->fd);
local->flags = args->flags;
loc_copy (&local->loc, args->loc);
+ loc_path (&local->loc, NULL);
frame->local = local;
if (!uuid_is_null (args->loc->inode->gfid))
@@ -3871,13 +4049,13 @@ client3_3_readv (call_frame_t *frame, xlator_t *this,
clnt_args_t *args = NULL;
int64_t remote_fd = -1;
clnt_conf_t *conf = NULL;
+ clnt_local_t *local = NULL;
int op_errno = ESTALE;
gfs3_read_req req = {{0,},};
int ret = 0;
struct iovec rsp_vec = {0, };
struct iobuf *rsp_iobuf = NULL;
struct iobref *rsp_iobref = NULL;
- clnt_local_t *local = NULL;
if (!frame || !this || !data)
goto unwind;
@@ -3885,7 +4063,14 @@ client3_3_readv (call_frame_t *frame, xlator_t *this,
args = data;
conf = this->private;
- CLIENT_GET_REMOTE_FD(conf, args->fd, remote_fd, op_errno, unwind);
+ CLIENT_GET_REMOTE_FD (this, args->fd, FALLBACK_TO_ANON_FD,
+ remote_fd, op_errno, unwind);
+ ret = client_fd_fop_prepare_local (frame, args->fd, remote_fd);
+ if (ret) {
+ op_errno = -ret;
+ goto unwind;
+ }
+ local = frame->local;
req.size = args->size;
req.offset = args->offset;
@@ -3923,15 +4108,8 @@ client3_3_readv (call_frame_t *frame, xlator_t *this,
goto unwind;
}
- local = mem_get0 (this->local_pool);
- if (local == NULL) {
- op_errno = ENOMEM;
- goto unwind;
- }
-
local->iobref = rsp_iobref;
rsp_iobref = NULL;
- frame->local = local;
GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val),
req.xdata.xdata_len, op_errno, unwind);
@@ -3942,17 +4120,12 @@ client3_3_readv (call_frame_t *frame, xlator_t *this,
local->iobref,
(xdrproc_t)xdr_gfs3_read_req);
if (ret) {
+ //unwind is done in the cbk
gf_log (this->name, GF_LOG_WARNING, "failed to send the fop");
}
GF_FREE (req.xdata.xdata_val);
- if (rsp_iobuf)
- iobuf_unref (rsp_iobuf);
-
- if (rsp_iobref)
- iobref_unref (rsp_iobref);
-
return 0;
unwind:
if (rsp_iobuf)
@@ -3976,7 +4149,7 @@ client3_3_writev (call_frame_t *frame, xlator_t *this, void *data)
clnt_conf_t *conf = NULL;
gfs3_write_req req = {{0,},};
int op_errno = ESTALE;
- int ret = 0;
+ int ret = 0;
if (!frame || !this || !data)
goto unwind;
@@ -3984,7 +4157,13 @@ client3_3_writev (call_frame_t *frame, xlator_t *this, void *data)
args = data;
conf = this->private;
- CLIENT_GET_REMOTE_FD(conf, args->fd, remote_fd, op_errno, unwind);
+ CLIENT_GET_REMOTE_FD (this, args->fd, FALLBACK_TO_ANON_FD,
+ remote_fd, op_errno, unwind);
+ ret = client_fd_fop_prepare_local (frame, args->fd, remote_fd);
+ if (ret) {
+ op_errno = -ret;
+ goto unwind;
+ }
req.size = args->size;
req.offset = args->offset;
@@ -4048,7 +4227,8 @@ client3_3_flush (call_frame_t *frame, xlator_t *this,
args = data;
conf = this->private;
- CLIENT_GET_REMOTE_FD(conf, args->fd, remote_fd, op_errno, unwind);
+ CLIENT_GET_REMOTE_FD (this, args->fd, DEFAULT_REMOTE_FD,
+ remote_fd, op_errno, unwind);
conf = this->private;
@@ -4107,7 +4287,8 @@ client3_3_fsync (call_frame_t *frame, xlator_t *this,
args = data;
conf = this->private;
- CLIENT_GET_REMOTE_FD(conf, args->fd, remote_fd, op_errno, unwind);
+ CLIENT_GET_REMOTE_FD (this, args->fd, DEFAULT_REMOTE_FD,
+ remote_fd, op_errno, unwind);
req.fd = remote_fd;
req.data = args->flags;
@@ -4155,7 +4336,8 @@ client3_3_fstat (call_frame_t *frame, xlator_t *this,
args = data;
conf = this->private;
- CLIENT_GET_REMOTE_FD(conf, args->fd, remote_fd, op_errno, unwind);
+ CLIENT_GET_REMOTE_FD (this, args->fd, DEFAULT_REMOTE_FD,
+ remote_fd, op_errno, unwind);
req.fd = remote_fd;
memcpy (req.gfid, args->fd->inode->gfid, 16);
@@ -4210,6 +4392,7 @@ client3_3_opendir (call_frame_t *frame, xlator_t *this,
local->fd = fd_ref (args->fd);
loc_copy (&local->loc, args->loc);
+ loc_path (&local->loc, NULL);
frame->local = local;
if (!uuid_is_null (args->loc->inode->gfid))
@@ -4264,7 +4447,8 @@ client3_3_fsyncdir (call_frame_t *frame, xlator_t *this, void *data)
args = data;
conf = this->private;
- CLIENT_GET_REMOTE_FD(conf, args->fd, remote_fd, op_errno, unwind);
+ CLIENT_GET_REMOTE_FD (this, args->fd, DEFAULT_REMOTE_FD,
+ remote_fd, op_errno, unwind);
req.fd = remote_fd;
req.data = args->flags;
@@ -4433,7 +4617,8 @@ client3_3_fsetxattr (call_frame_t *frame, xlator_t *this,
args = data;
conf = this->private;
- CLIENT_GET_REMOTE_FD(conf, args->fd, remote_fd, op_errno, unwind);
+ CLIENT_GET_REMOTE_FD (this, args->fd, DEFAULT_REMOTE_FD,
+ remote_fd, op_errno, unwind);
req.fd = remote_fd;
req.flags = args->flags;
@@ -4497,7 +4682,8 @@ client3_3_fgetxattr (call_frame_t *frame, xlator_t *this,
args = data;
conf = this->private;
- CLIENT_GET_REMOTE_FD(conf, args->fd, remote_fd, op_errno, unwind);
+ CLIENT_GET_REMOTE_FD (this, args->fd, DEFAULT_REMOTE_FD,
+ remote_fd, op_errno, unwind);
local = mem_get0 (this->local_pool);
if (!local) {
@@ -4613,6 +4799,7 @@ client3_3_getxattr (call_frame_t *frame, xlator_t *this,
}
loc_copy (&local->loc, args->loc);
+ loc_path (&local->loc, NULL);
if (args->name)
local->name = gf_strdup (args->name);
@@ -4777,6 +4964,8 @@ client3_3_xattrop (call_frame_t *frame, xlator_t *this,
else
memcpy (req.gfid, args->loc->gfid, 16);
+ loc_copy (&local->loc, args->loc);
+ loc_path (&local->loc, NULL);
GF_ASSERT_AND_GOTO_WITH_ERROR (this->name,
!uuid_is_null (*((uuid_t*)req.gfid)),
unwind, op_errno, EINVAL);
@@ -4840,11 +5029,11 @@ client3_3_fxattrop (call_frame_t *frame, xlator_t *this,
clnt_args_t *args = NULL;
int64_t remote_fd = -1;
clnt_conf_t *conf = NULL;
+ clnt_local_t *local = NULL;
gfs3_fxattrop_req req = {{0,},};
int op_errno = ESTALE;
int ret = 0;
int count = 0;
- clnt_local_t *local = NULL;
struct iobref *rsp_iobref = NULL;
struct iobuf *rsp_iobuf = NULL;
struct iovec *rsphdr = NULL;
@@ -4856,19 +5045,20 @@ client3_3_fxattrop (call_frame_t *frame, xlator_t *this,
args = data;
conf = this->private;
- CLIENT_GET_REMOTE_FD(conf, args->fd, remote_fd, op_errno, unwind);
+ CLIENT_GET_REMOTE_FD (this, args->fd, FALLBACK_TO_ANON_FD,
+ remote_fd, op_errno, unwind);
+ ret = client_fd_fop_prepare_local (frame, args->fd, remote_fd);
+ if (ret) {
+ op_errno = -ret;
+ goto unwind;
+ }
+
+ local = frame->local;
req.fd = remote_fd;
req.flags = args->flags;
memcpy (req.gfid, args->fd->inode->gfid, 16);
- local = mem_get0 (this->local_pool);
- if (!local) {
- op_errno = ENOMEM;
- goto unwind;
- }
- frame->local = local;
-
rsp_iobref = iobref_new ();
if (rsp_iobref == NULL) {
op_errno = ENOMEM;
@@ -4916,12 +5106,6 @@ client3_3_fxattrop (call_frame_t *frame, xlator_t *this,
GF_FREE (req.xdata.xdata_val);
- if (rsp_iobuf)
- iobuf_unref (rsp_iobuf);
-
- if (rsp_iobref)
- iobref_unref (rsp_iobref);
-
return 0;
unwind:
CLIENT_STACK_UNWIND (fxattrop, frame, -1, op_errno, NULL, NULL);
@@ -5013,7 +5197,8 @@ client3_3_fremovexattr (call_frame_t *frame, xlator_t *this,
conf = this->private;
- CLIENT_GET_REMOTE_FD(conf, args->fd, remote_fd, op_errno, unwind);
+ CLIENT_GET_REMOTE_FD (this, args->fd, DEFAULT_REMOTE_FD,
+ remote_fd, op_errno, unwind);
memcpy (req.gfid, args->fd->inode->gfid, 16);
req.name = (char *)args->name;
@@ -5066,7 +5251,8 @@ client3_3_lk (call_frame_t *frame, xlator_t *this,
goto unwind;
}
- CLIENT_GET_REMOTE_FD(conf, args->fd, remote_fd, op_errno, unwind);
+ CLIENT_GET_REMOTE_FD (this, args->fd, DEFAULT_REMOTE_FD,
+ remote_fd, op_errno, unwind);
ret = client_cmd_to_gf_cmd (args->cmd, &gf_cmd);
if (ret) {
@@ -5216,15 +5402,20 @@ client3_3_finodelk (call_frame_t *frame, xlator_t *this,
int64_t remote_fd = -1;
clnt_conf_t *conf = NULL;
int op_errno = ESTALE;
- int ret = 0;
+ int ret = 0;
if (!frame || !this || !data)
goto unwind;
args = data;
conf = this->private;
-
- CLIENT_GET_REMOTE_FD(conf, args->fd, remote_fd, op_errno, unwind);
+ CLIENT_GET_REMOTE_FD (this, args->fd, FALLBACK_TO_ANON_FD,
+ remote_fd, op_errno, unwind);
+ ret = client_fd_fop_prepare_local (frame, args->fd, remote_fd);
+ if (ret) {
+ op_errno = -ret;
+ goto unwind;
+ }
if (args->cmd == F_GETLK || args->cmd == F_GETLK64)
gf_cmd = GF_LK_GETLK;
@@ -5357,7 +5548,8 @@ client3_3_fentrylk (call_frame_t *frame, xlator_t *this,
args = data;
conf = this->private;
- CLIENT_GET_REMOTE_FD(conf, args->fd, remote_fd, op_errno, unwind);
+ CLIENT_GET_REMOTE_FD (this, args->fd, DEFAULT_REMOTE_FD,
+ remote_fd, op_errno, unwind);
req.fd = remote_fd;
req.cmd = args->cmd_entrylk;
@@ -5410,7 +5602,8 @@ client3_3_rchecksum (call_frame_t *frame, xlator_t *this,
args = data;
conf = this->private;
- CLIENT_GET_REMOTE_FD(conf, args->fd, remote_fd, op_errno, unwind);
+ CLIENT_GET_REMOTE_FD (this, args->fd, DEFAULT_REMOTE_FD,
+ remote_fd, op_errno, unwind);
req.len = args->len;
req.offset = args->offset;
@@ -5466,7 +5659,8 @@ client3_3_readdir (call_frame_t *frame, xlator_t *this,
args = data;
conf = this->private;
- CLIENT_GET_REMOTE_FD(conf, args->fd, remote_fd, op_errno, unwind);
+ CLIENT_GET_REMOTE_FD (this, args->fd, DEFAULT_REMOTE_FD,
+ remote_fd, op_errno, unwind);
readdir_rsp_size = xdr_sizeof ((xdrproc_t) xdr_gfs3_readdir_rsp, &rsp)
+ args->size;
@@ -5575,7 +5769,8 @@ client3_3_readdirp (call_frame_t *frame, xlator_t *this,
args = data;
conf = this->private;
- CLIENT_GET_REMOTE_FD(conf, args->fd, remote_fd, op_errno, unwind);
+ CLIENT_GET_REMOTE_FD (this, args->fd, DEFAULT_REMOTE_FD,
+ remote_fd, op_errno, unwind);
readdirp_rsp_size = xdr_sizeof ((xdrproc_t) xdr_gfs3_readdirp_rsp, &rsp)
+ args->size;
@@ -5728,7 +5923,8 @@ client3_3_fsetattr (call_frame_t *frame, xlator_t *this, void *data)
args = data;
conf = this->private;
- CLIENT_GET_REMOTE_FD(conf, args->fd, remote_fd, op_errno, unwind);
+ CLIENT_GET_REMOTE_FD (this, args->fd, DEFAULT_REMOTE_FD,
+ remote_fd, op_errno, unwind);
req.fd = remote_fd;
req.valid = args->valid;
@@ -5756,7 +5952,140 @@ unwind:
return 0;
}
+int32_t
+client3_3_fallocate(call_frame_t *frame, xlator_t *this, void *data)
+{
+ clnt_args_t *args = NULL;
+ int64_t remote_fd = -1;
+ clnt_conf_t *conf = NULL;
+ gfs3_fallocate_req req = {{0},};
+ int op_errno = ESTALE;
+ int ret = 0;
+
+ if (!frame || !this || !data)
+ goto unwind;
+
+ args = data;
+ conf = this->private;
+
+ CLIENT_GET_REMOTE_FD (this, args->fd, DEFAULT_REMOTE_FD,
+ remote_fd, op_errno, unwind);
+
+ req.fd = remote_fd;
+ req.flags = args->flags;
+ req.offset = args->offset;
+ req.size = args->size;
+ memcpy(req.gfid, args->fd->inode->gfid, 16);
+
+ GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val),
+ req.xdata.xdata_len, op_errno, unwind);
+
+ ret = client_submit_request (this, &req, frame, conf->fops,
+ GFS3_OP_FALLOCATE,
+ client3_3_fallocate_cbk, NULL,
+ NULL, 0, NULL, 0,
+ NULL, (xdrproc_t)xdr_gfs3_fallocate_req);
+ if (ret) {
+ gf_log (this->name, GF_LOG_WARNING, "failed to send the fop");
+ }
+
+ GF_FREE (req.xdata.xdata_val);
+
+ return 0;
+unwind:
+ CLIENT_STACK_UNWIND (fallocate, frame, -1, op_errno, NULL, NULL, NULL);
+ GF_FREE (req.xdata.xdata_val);
+
+ return 0;
+}
+
+int32_t
+client3_3_discard(call_frame_t *frame, xlator_t *this, void *data)
+{
+ clnt_args_t *args = NULL;
+ int64_t remote_fd = -1;
+ clnt_conf_t *conf = NULL;
+ gfs3_discard_req req = {{0},};
+ int op_errno = ESTALE;
+ int ret = 0;
+ if (!frame || !this || !data)
+ goto unwind;
+
+ args = data;
+ conf = this->private;
+
+ CLIENT_GET_REMOTE_FD (this, args->fd, DEFAULT_REMOTE_FD,
+ remote_fd, op_errno, unwind);
+
+ req.fd = remote_fd;
+ req.offset = args->offset;
+ req.size = args->size;
+ memcpy(req.gfid, args->fd->inode->gfid, 16);
+
+ GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val),
+ req.xdata.xdata_len, op_errno, unwind);
+
+ ret = client_submit_request(this, &req, frame, conf->fops,
+ GFS3_OP_DISCARD, client3_3_discard_cbk,
+ NULL, NULL, 0, NULL, 0, NULL,
+ (xdrproc_t) xdr_gfs3_discard_req);
+ if (ret)
+ gf_log (this->name, GF_LOG_WARNING, "failed to send the fop");
+
+ GF_FREE (req.xdata.xdata_val);
+
+ return 0;
+unwind:
+ CLIENT_STACK_UNWIND(discard, frame, -1, op_errno, NULL, NULL, NULL);
+ GF_FREE (req.xdata.xdata_val);
+
+ return 0;
+}
+
+int32_t
+client3_3_zerofill(call_frame_t *frame, xlator_t *this, void *data)
+{
+ clnt_args_t *args = NULL;
+ int64_t remote_fd = -1;
+ clnt_conf_t *conf = NULL;
+ gfs3_zerofill_req req = {{0},};
+ int op_errno = ESTALE;
+ int ret = 0;
+
+ if (!frame || !this || !data)
+ goto unwind;
+
+ args = data;
+ conf = this->private;
+
+ CLIENT_GET_REMOTE_FD (this, args->fd, DEFAULT_REMOTE_FD,
+ remote_fd, op_errno, unwind);
+
+ req.fd = remote_fd;
+ req.offset = args->offset;
+ req.size = args->size;
+ memcpy(req.gfid, args->fd->inode->gfid, 16);
+
+ GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val),
+ req.xdata.xdata_len, op_errno, unwind);
+
+ ret = client_submit_request(this, &req, frame, conf->fops,
+ GFS3_OP_ZEROFILL, client3_3_zerofill_cbk,
+ NULL, NULL, 0, NULL, 0, NULL,
+ (xdrproc_t) xdr_gfs3_zerofill_req);
+ if (ret)
+ gf_log (this->name, GF_LOG_WARNING, "failed to send the fop");
+
+ GF_FREE (req.xdata.xdata_val);
+
+ return 0;
+unwind:
+ CLIENT_STACK_UNWIND(zerofill, frame, -1, op_errno, NULL, NULL, NULL);
+ GF_FREE (req.xdata.xdata_val);
+
+ return 0;
+}
/* Table Specific to FOPS */
@@ -5803,6 +6132,9 @@ rpc_clnt_procedure_t clnt3_3_fop_actors[GF_FOP_MAXVALUE] = {
[GF_FOP_SETATTR] = { "SETATTR", client3_3_setattr },
[GF_FOP_FSETATTR] = { "FSETATTR", client3_3_fsetattr },
[GF_FOP_READDIRP] = { "READDIRP", client3_3_readdirp },
+ [GF_FOP_FALLOCATE] = { "FALLOCATE", client3_3_fallocate },
+ [GF_FOP_DISCARD] = { "DISCARD", client3_3_discard },
+ [GF_FOP_ZEROFILL] = { "ZEROFILL", client3_3_zerofill},
[GF_FOP_RELEASE] = { "RELEASE", client3_3_release },
[GF_FOP_RELEASEDIR] = { "RELEASEDIR", client3_3_releasedir },
[GF_FOP_GETSPEC] = { "GETSPEC", client3_getspec },
@@ -5855,6 +6187,10 @@ char *clnt3_3_fop_names[GFS3_OP_MAXVALUE] = {
[GFS3_OP_RELEASE] = "RELEASE",
[GFS3_OP_RELEASEDIR] = "RELEASEDIR",
[GFS3_OP_FREMOVEXATTR] = "FREMOVEXATTR",
+ [GFS3_OP_FALLOCATE] = "FALLOCATE",
+ [GFS3_OP_DISCARD] = "DISCARD",
+ [GFS3_OP_ZEROFILL] = "ZEROFILL",
+
};
rpc_clnt_prog_t clnt3_3_fop_prog = {
diff --git a/xlators/protocol/client/src/client.c b/xlators/protocol/client/src/client.c
index 16c7dee5e..1f7d13ea4 100644
--- a/xlators/protocol/client/src/client.c
+++ b/xlators/protocol/client/src/client.c
@@ -130,7 +130,7 @@ client_register_grace_timer (xlator_t *this, clnt_conf_t *conf)
conf->grace_timer =
gf_timer_call_after (this->ctx,
- conf->grace_tv,
+ conf->grace_ts,
client_grace_timeout,
conf->rpc);
}
@@ -815,12 +815,16 @@ client_create (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,
goto out;
args.loc = loc;
- args.flags = flags;
args.mode = mode;
args.fd = fd;
args.umask = umask;
args.xdata = xdata;
+ if (!conf->filter_o_direct)
+ args.flags = flags;
+ else
+ args.flags = (flags & ~O_DIRECT);
+
proc = &conf->fops->proctable[GF_FOP_CREATE];
if (!proc) {
gf_log (this->name, GF_LOG_ERROR,
@@ -854,10 +858,14 @@ client_open (call_frame_t *frame, xlator_t *this, loc_t *loc,
goto out;
args.loc = loc;
- args.flags = flags;
args.fd = fd;
args.xdata = xdata;
+ if (!conf->filter_o_direct)
+ args.flags = flags;
+ else
+ args.flags = (flags & ~O_DIRECT);
+
proc = &conf->fops->proctable[GF_FOP_OPEN];
if (!proc) {
gf_log (this->name, GF_LOG_ERROR,
@@ -1953,6 +1961,110 @@ out:
return 0;
}
+int32_t
+client_fallocate(call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t mode,
+ off_t offset, size_t len, dict_t *xdata)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf || !conf->fops)
+ goto out;
+
+ args.fd = fd;
+ args.flags = mode;
+ args.offset = offset;
+ args.size = len;
+ args.xdata = xdata;
+
+ proc = &conf->fops->proctable[GF_FOP_FALLOCATE];
+ if (!proc) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "rpc procedure not found for %s",
+ gf_fop_list[GF_FOP_FALLOCATE]);
+ goto out;
+ }
+ if (proc->fn)
+ ret = proc->fn (frame, this, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (fallocate, frame, -1, ENOTCONN, NULL, NULL, NULL);
+
+ return 0;
+}
+
+int32_t
+client_discard(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
+ size_t len, dict_t *xdata)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf || !conf->fops)
+ goto out;
+
+ args.fd = fd;
+ args.offset = offset;
+ args.size = len;
+ args.xdata = xdata;
+
+ proc = &conf->fops->proctable[GF_FOP_DISCARD];
+ if (!proc) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "rpc procedure not found for %s",
+ gf_fop_list[GF_FOP_DISCARD]);
+ goto out;
+ }
+ if (proc->fn)
+ ret = proc->fn (frame, this, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT(discard, frame, -1, ENOTCONN, NULL, NULL, NULL);
+
+ return 0;
+}
+
+int32_t
+client_zerofill(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
+ size_t len, dict_t *xdata)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf || !conf->fops)
+ goto out;
+
+ args.fd = fd;
+ args.offset = offset;
+ args.size = len;
+ args.xdata = xdata;
+
+ proc = &conf->fops->proctable[GF_FOP_ZEROFILL];
+ if (!proc) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "rpc procedure not found for %s",
+ gf_fop_list[GF_FOP_ZEROFILL]);
+ goto out;
+ }
+ if (proc->fn)
+ ret = proc->fn (frame, this, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT(zerofill, frame, -1, ENOTCONN,
+ NULL, NULL, NULL);
+
+ return 0;
+}
+
int32_t
client_getspec (call_frame_t *frame, xlator_t *this, const char *key,
@@ -2042,7 +2154,7 @@ client_rpc_notify (struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event,
gf_log (this->name, GF_LOG_DEBUG, "got RPC_CLNT_CONNECT");
if ((ret < 0) || (strcasecmp (handshake, "on"))) {
- ret = client_handshake (this, conf->rpc);
+ ret = client_handshake (this, rpc);
if (ret)
gf_log (this->name, GF_LOG_WARNING,
"handshake msg returned %d", ret);
@@ -2084,9 +2196,19 @@ client_rpc_notify (struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event,
client_register_grace_timer (this, conf);
if (!conf->skip_notify) {
- if (conf->connected)
- gf_log (this->name, GF_LOG_INFO,
- "disconnected");
+ if (conf->connected) {
+ gf_log (this->name,
+ ((!conf->disconnect_err_logged)
+ ? GF_LOG_INFO : GF_LOG_DEBUG),
+ "disconnected from %s. Client process "
+ "will keep trying to connect to "
+ "glusterd until brick's port is "
+ "available",
+ conf->rpc->conn.trans->peerinfo.identifier);
+
+ if (conf->portmap_err_logged)
+ conf->disconnect_err_logged = 1;
+ }
/* If the CHILD_DOWN event goes to parent xlator
multiple times, the logic of parent xlator notify
@@ -2110,6 +2232,15 @@ client_rpc_notify (struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event,
conf->connected = 0;
conf->skip_notify = 0;
+ if (conf->quick_reconnect) {
+ conf->quick_reconnect = 0;
+ rpc_clnt_start (rpc);
+
+ } else {
+ rpc->conn.config.remote_port = 0;
+
+ }
+
break;
default:
@@ -2193,6 +2324,9 @@ build_client_config (xlator_t *this, clnt_conf_t *conf)
gf_log (this->name, GF_LOG_WARNING,
"option 'remote-subvolume' not given");
+ GF_OPTION_INIT ("filter-O_DIRECT", conf->filter_o_direct,
+ bool, out);
+
ret = 0;
out:
return ret;
@@ -2316,14 +2450,14 @@ client_init_grace_timer (xlator_t *this, dict_t *options,
ret = dict_get_int32 (options, "grace-timeout", &grace_timeout);
if (!ret)
- conf->grace_tv.tv_sec = grace_timeout;
+ conf->grace_ts.tv_sec = grace_timeout;
else
- conf->grace_tv.tv_sec = 10;
+ conf->grace_ts.tv_sec = 10;
- conf->grace_tv.tv_usec = 0;
+ conf->grace_ts.tv_nsec = 0;
gf_log (this->name, GF_LOG_DEBUG, "Client grace timeout "
- "value = %"PRIu64, conf->grace_tv.tv_sec);
+ "value = %"PRIu64, conf->grace_ts.tv_sec);
ret = 0;
out:
@@ -2377,6 +2511,9 @@ reconfigure (xlator_t *this, dict_t *options)
}
}
+ GF_OPTION_RECONF ("filter-O_DIRECT", conf->filter_o_direct,
+ options, bool, out);
+
ret = client_init_grace_timer (this, options, conf);
if (ret)
goto out;
@@ -2646,6 +2783,9 @@ struct xlator_fops fops = {
.fxattrop = client_fxattrop,
.setattr = client_setattr,
.fsetattr = client_fsetattr,
+ .fallocate = client_fallocate,
+ .discard = client_discard,
+ .zerofill = client_zerofill,
.getspec = client_getspec,
};
@@ -2701,16 +2841,27 @@ struct volume_options options[] = {
{ .key = {"lk-heal"},
.type = GF_OPTION_TYPE_BOOL,
.default_value = "off",
+ .description = "Enables or disables the lock heal."
},
{ .key = {"grace-timeout"},
.type = GF_OPTION_TYPE_INT,
.min = 10,
- .max = 1800
+ .max = 1800,
+ .description = "Sets the grace-timeout value. Valid range 10-1800."
},
{.key = {"tcp-window-size"},
.type = GF_OPTION_TYPE_SIZET,
.min = GF_MIN_SOCKET_WINDOW_SIZE,
- .max = GF_MAX_SOCKET_WINDOW_SIZE
+ .max = GF_MAX_SOCKET_WINDOW_SIZE,
+ .description = "Specifies the window size for tcp socket."
+ },
+ { .key = {"filter-O_DIRECT"},
+ .type = GF_OPTION_TYPE_BOOL,
+ .default_value = "disable",
+ .description = "If enabled, in open() and creat() calls, O_DIRECT "
+ "flag will be filtered at the client protocol level so server will "
+ "still continue to cache the file. This works similar to NFS's "
+ "behavior of O_DIRECT",
},
{ .key = {NULL} },
};
diff --git a/xlators/protocol/client/src/client.h b/xlators/protocol/client/src/client.h
index 9d8a818aa..afab2d74f 100644
--- a/xlators/protocol/client/src/client.h
+++ b/xlators/protocol/client/src/client.h
@@ -34,27 +34,27 @@ typedef enum {
GF_LK_HEAL_DONE,
} lk_heal_state_t;
-#define CLIENT_GET_REMOTE_FD(conf, fd, remote_fd, op_errno, label) \
+typedef enum {
+ DEFAULT_REMOTE_FD = 0,
+ FALLBACK_TO_ANON_FD = 1
+} clnt_remote_fd_flags_t;
+
+#define CLIENT_GET_REMOTE_FD(xl, fd, flags, remote_fd, op_errno, label) \
do { \
- clnt_fd_ctx_t *fdctx = NULL; \
- pthread_mutex_lock (&conf->lock); \
- { \
- fdctx = this_fd_get_ctx (fd, THIS); \
- } \
- pthread_mutex_unlock (&conf->lock); \
- if (!fdctx) { \
- remote_fd = -2; \
- } else { \
- remote_fd = fdctx->remote_fd; \
+ int _ret = 0; \
+ _ret = client_get_remote_fd (xl, fd, flags, &remote_fd);\
+ if (_ret < 0) { \
+ op_errno = errno; \
+ goto label; \
} \
if (remote_fd == -1) { \
- gf_log (THIS->name, GF_LOG_WARNING, " (%s) " \
+ gf_log (xl->name, GF_LOG_WARNING, " (%s) " \
"remote_fd is -1. EBADFD", \
uuid_utoa (fd->inode->gfid)); \
op_errno = EBADFD; \
goto label; \
} \
- } while (0);
+ } while (0)
#define CLIENT_STACK_UNWIND(op, frame, params ...) do { \
clnt_local_t *__local = frame->local; \
@@ -93,6 +93,10 @@ typedef struct clnt_conf {
which was sent earlier */
char portmap_err_logged; /* flag used to prevent
excessive logging */
+ char disconnect_err_logged; /* flag used to prevent
+ excessive disconnect
+ logging */
+
char need_different_port; /* flag used to change the
portmap path in case of
'tcp,rdma' on server */
@@ -100,7 +104,7 @@ typedef struct clnt_conf {
uint16_t lk_version; /* this variable is used to distinguish
client-server transaction while
performing lock healing */
- struct timeval grace_tv;
+ struct timespec grace_ts;
gf_timer_t *grace_timer;
gf_boolean_t grace_timer_needed; /* The state of this flag will
be used to decide whether
@@ -109,6 +113,13 @@ typedef struct clnt_conf {
means dont register, true
means register */
char parent_down;
+ gf_boolean_t quick_reconnect; /* When reconnecting after
+ portmap query, do not let
+ the reconnection happen after
+ the usual 3-second wait
+ */
+ gf_boolean_t filter_o_direct; /* if set, filter O_DIRECT from
+ the flags list of open() */
} clnt_conf_t;
typedef struct _client_fd_ctx {
@@ -123,7 +134,9 @@ typedef struct _client_fd_ctx {
pthread_mutex_t mutex;
lk_heal_state_t lk_heal_state;
uuid_t gfid;
+ void (*reopen_done) (struct _client_fd_ctx*, xlator_t *);
struct list_head lock_list; /* List of all granted locks on this fd */
+ int32_t reopen_attempts;
} clnt_fd_ctx_t;
typedef struct _client_posix_lock {
@@ -151,7 +164,8 @@ typedef struct client_local {
int32_t cmd;
struct list_head lock_list;
pthread_mutex_t mutex;
- char *name;
+ char *name;
+ gf_boolean_t attempt_reopen;
} clnt_local_t;
typedef struct client_args {
@@ -203,9 +217,6 @@ int client_submit_request (xlator_t *this, void *req,
struct iovec *rsp_payload, int rsp_count,
struct iobref *rsp_iobref, xdrproc_t xdrproc);
-int protocol_client_reopendir (xlator_t *this, clnt_fd_ctx_t *fdctx);
-int protocol_client_reopen (xlator_t *this, clnt_fd_ctx_t *fdctx);
-
int unserialize_rsp_dirent (struct gfs3_readdir_rsp *rsp, gf_dirent_t *entries);
int unserialize_rsp_direntp (xlator_t *this, fd_t *fd,
struct gfs3_readdirp_rsp *rsp, gf_dirent_t *entries);
@@ -216,7 +227,6 @@ int client_attempt_lock_recovery (xlator_t *this, clnt_fd_ctx_t *fdctx);
int32_t delete_granted_locks_owner (fd_t *fd, gf_lkowner_t *owner);
int client_add_lock_for_recovery (fd_t *fd, struct gf_flock *flock,
gf_lkowner_t *owner, int32_t cmd);
-uint64_t decrement_reopen_fd_count (xlator_t *this, clnt_conf_t *conf);
int32_t delete_granted_locks_fd (clnt_fd_ctx_t *fdctx);
int32_t client_cmd_to_gf_cmd (int32_t cmd, int32_t *gf_cmd);
void client_save_number_fds (clnt_conf_t *conf, int count);
@@ -236,4 +246,12 @@ int client_mark_fd_bad (xlator_t *this);
int client_set_lk_version (xlator_t *this);
int client_fd_lk_list_empty (fd_lk_ctx_t *lk_ctx, gf_boolean_t use_try_lock);
+void client_default_reopen_done (clnt_fd_ctx_t *fdctx, xlator_t *this);
+void client_attempt_reopen (fd_t *fd, xlator_t *this);
+int client_get_remote_fd (xlator_t *this, fd_t *fd, int flags,
+ int64_t *remote_fd);
+int client_fd_fop_prepare_local (call_frame_t *frame, fd_t *fd,
+ int64_t remote_fd);
+gf_boolean_t
+__is_fd_reopen_in_progress (clnt_fd_ctx_t *fdctx);
#endif /* !_CLIENT_H */